Refactored Graphics #297

Merged
Xenosas1337 merged 13 commits from SP3-1-Rendering into main 2023-01-01 12:35:09 +08:00
14 changed files with 329 additions and 118 deletions
Showing only changes of commit 5f2fa7fdf5 - Show all commits

View File

@ -411,11 +411,12 @@ namespace SHADE
instancedIntegerData.reserve(numTotalElements);
instancedIntegerData.clear();
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
// - Material Properties Data
const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface
(
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS),
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
vk::ShaderStageFlagBits::eFragment
);
@ -570,11 +571,14 @@ namespace SHADE
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
if (matPropsDescSet[frameIndex])
{
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
cmdBuffer->BindDescriptorSet
(
matPropsDescSet[frameIndex],
SH_PIPELINE_TYPE::GRAPHICS,
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS),
dynamicOffset
);
}
@ -607,7 +611,7 @@ namespace SHADE
{
matPropsDescSet[frameIndex] = descPool->Allocate
(
{ SHPredefinedData::GetPredefinedDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] },
SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS),
{ 0 }
);
#ifdef _DEBUG
@ -618,17 +622,21 @@ namespace SHADE
}
#endif
}
auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings;
uint32_t const MATERIAL_DESC_SET_INDEX = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::MATERIALS);
std::array<Handle<SHVkBuffer>, 1> bufferList = { matPropsBuffer[frameIndex] };
matPropsDescSet[frameIndex]->ModifyWriteDescBuffer
(
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
MATERIAL_DESC_SET_INDEX,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
bufferList,
0, static_cast<uint32_t>(matPropsDataSize)
);
matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer
(
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
MATERIAL_DESC_SET_INDEX,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA
);
}

View File

@ -0,0 +1,17 @@
#include "SHpch.h"
#include "SHDescriptorMappings.h"
namespace SHADE
{
void SHDescriptorMappings::AddMappings(std::initializer_list<std::pair<SHGraphicsConstants::DescriptorSetTypes, uint32_t>> inMappings) noexcept
{
for (auto& map : inMappings)
mappings.emplace(map);
}
SHDescriptorMappings::MapType const& SHDescriptorMappings::GetMappings(void) const noexcept
{
return mappings;
}
}

View File

@ -0,0 +1,29 @@
#pragma once
#include <unordered_map>
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
namespace SHADE
{
class SHDescriptorMappings
{
public:
using MapType = std::unordered_map<SHGraphicsConstants::DescriptorSetTypes, uint32_t>;
private:
//! To map an enum value from descriptor set types to set indices
MapType mappings;
public:
/*-----------------------------------------------------------------------*/
/* PUBLIC MEMBER FUNCTIONS */
/*-----------------------------------------------------------------------*/
void AddMappings (std::initializer_list<std::pair<SHGraphicsConstants::DescriptorSetTypes, uint32_t>> inMappings) noexcept;
/*-----------------------------------------------------------------------*/
/* SETTERS AND GETTERS */
/*-----------------------------------------------------------------------*/
MapType const& GetMappings (void) const noexcept;
};
}

View File

@ -0,0 +1,30 @@
#include "SHpch.h"
#include "SHGlobalDescriptorSets.h"
namespace SHADE
{
Handle<SHVkDescriptorSetGroup> SHGlobalDescriptorSets::lightDescriptorSet;
/***************************************************************************/
/*!
\brief
Sets the Handle to descriptor set for lights.
\param lightDescSet
The handle to set to.
*/
/***************************************************************************/
void SHGlobalDescriptorSets::SetLightDescriptorSet(Handle<SHVkDescriptorSetGroup> lightDescSet) noexcept
{
lightDescriptorSet = lightDescSet;
}
Handle<SHVkDescriptorSetGroup> SHGlobalDescriptorSets::GetLightDescriptorSet(void) noexcept
{
return lightDescriptorSet;
}
}

View File

@ -0,0 +1,24 @@
#pragma once
#include "Graphics/Descriptors/SHVkDescriptorSetGroup.h"
#include "Resource/SHHandle.h"
namespace SHADE
{
// This class is mainly for descriptors that are truly global, meaning they only come from 1 place and they are shared between many systems
class SHGlobalDescriptorSets
{
private:
//! Light data descriptor set
static Handle<SHVkDescriptorSetGroup> lightDescriptorSet;
public:
/*-----------------------------------------------------------------------*/
/* SETTERS AND GETTERS */
/*-----------------------------------------------------------------------*/
static void SetLightDescriptorSet (Handle<SHVkDescriptorSetGroup> lightDescSet) noexcept;
static Handle<SHVkDescriptorSetGroup> GetLightDescriptorSet (void) noexcept;
};
}

View File

@ -13,7 +13,41 @@ namespace SHADE
/*-----------------------------------------------------------------------------------*/
std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::predefinedLayouts;
SHVertexInputState SHPredefinedData::defaultVertexInputState;
Handle<SHVkPipelineLayout> SHPredefinedData::dummyPipelineLayout;
SHPredefinedData::PerSystem SHPredefinedData::batchingSystemData;
SHPredefinedData::PerSystem SHPredefinedData::textSystemData;
SHPredefinedData::PerSystem SHPredefinedData::renderGraphNodeComputeData;
void SHPredefinedData::InitDescMappings(void) noexcept
{
batchingSystemData.descMappings.AddMappings
({
{SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0},
{SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1},
{SHGraphicsConstants::DescriptorSetTypes::MATERIALS, 2},
});
textSystemData.descMappings.AddMappings
({
{SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0},
{SHGraphicsConstants::DescriptorSetTypes::CAMERA, 1},
{SHGraphicsConstants::DescriptorSetTypes::FONT, 2},
});
renderGraphNodeComputeData.descMappings.AddMappings
({
{SHGraphicsConstants::DescriptorSetTypes::STATIC_DATA, 0},
{SHGraphicsConstants::DescriptorSetTypes::LIGHTS, 1},
{SHGraphicsConstants::DescriptorSetTypes::CAMERA, 2},
{SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE, 3},
{SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE, 4},
});
}
void SHPredefinedData::InitDummyPipelineLayouts(Handle<SHVkLogicalDevice> logicalDevice) noexcept
{
batchingSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ batchingSystemData.descSetLayouts });
textSystemData.dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ textSystemData.descSetLayouts });
}
/*-----------------------------------------------------------------------------------*/
/* Function Definitions */
@ -91,35 +125,46 @@ namespace SHADE
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals");
// font bitmap data (texture)
SHVkDescriptorSetLayout::Binding fontBitmapBinding
{
.Type = vk::DescriptorType::eCombinedImageSampler,
.Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
.DescriptorCount = 1,
};
//// font bitmap data (texture)
//SHVkDescriptorSetLayout::Binding fontBitmapBinding
//{
// .Type = vk::DescriptorType::eCombinedImageSampler,
// .Stage = vk::ShaderStageFlagBits::eFragment,
// .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_BITMAP_DATA,
// .DescriptorCount = 1,
//};
// font data in the form of matrices
SHVkDescriptorSetLayout::Binding fontMatrixBinding
{
.Type = vk::DescriptorType::eStorageBuffer,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
.DescriptorCount = 1,
};
//// font data in the form of matrices
//SHVkDescriptorSetLayout::Binding fontMatrixBinding
//{
// .Type = vk::DescriptorType::eStorageBuffer,
// .Stage = vk::ShaderStageFlagBits::eVertex,
// .BindPoint = SHGraphicsConstants::DescriptorSetBindings::FONT_MATRIX_DATA,
// .DescriptorCount = 1,
//};
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data");
//Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding });
//SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data");
predefinedLayouts.push_back(staticGlobalLayout);
predefinedLayouts.push_back(lightDataDescSetLayout);
predefinedLayouts.push_back(cameraDataGlobalLayout);
predefinedLayouts.push_back(materialDataPerInstanceLayout);
predefinedLayouts.push_back(fontDataDescSetLayout);
//predefinedLayouts.push_back(fontDataDescSetLayout);
dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{predefinedLayouts});
batchingSystemData.descSetLayouts = GetPredefinedDescSetLayouts
(
SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA |
SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA |
SHGraphicsConstants::PredefinedDescSetLayoutTypes::MATERIALS
);
textSystemData.descSetLayouts = GetPredefinedDescSetLayouts
(
SHGraphicsConstants::PredefinedDescSetLayoutTypes::STATIC_DATA |
SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA
);
}
void SHPredefinedData::InitDefaultVertexInputState(void) noexcept
@ -136,9 +181,11 @@ namespace SHADE
{
InitDescSetLayouts(logicalDevice);
InitDefaultVertexInputState();
InitDescMappings();
InitDummyPipelineLayouts (logicalDevice);
}
std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper<SHGraphicsConstants::SHPredefinedDescSetLayoutTypes> types) noexcept
std::vector<Handle<SHVkDescriptorSetLayout>> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper<SHGraphicsConstants::PredefinedDescSetLayoutTypes> types) noexcept
{
std::vector<Handle<SHVkDescriptorSetLayout>> layoutsFound;
for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i)
@ -156,9 +203,20 @@ namespace SHADE
return defaultVertexInputState;
}
Handle<SHVkPipelineLayout> SHPredefinedData::GetDummyPipelineLayout(void) noexcept
SHPredefinedData::PerSystem const& SHPredefinedData::GetBatchingSystemData(void) noexcept
{
return dummyPipelineLayout;
return batchingSystemData;
}
SHPredefinedData::PerSystem const& SHPredefinedData::GetTextSystemData(void) noexcept
{
return textSystemData;
}
SHPredefinedData::PerSystem const& SHPredefinedData::GetRenderGraphNodeComputeData(void) noexcept
{
return renderGraphNodeComputeData;
}
}

View File

@ -3,6 +3,7 @@
#include "SH_API.h"
#include "Graphics/Pipeline/SHPipelineState.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h"
#include "Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h"
#include "Tools/Utilities/SHUtilities.h"
namespace SHADE
@ -12,8 +13,22 @@ namespace SHADE
class SHVkDescriptorSetGroup;
class SHVkPipelineLayout;
class SH_API SHPredefinedData
{
public:
struct PerSystem
{
//! vector of descriptor set layouts used by a system
std::vector<Handle<SHVkDescriptorSetLayout>> descSetLayouts;
//! pipeline layout used for binding descriptor sets in the system
static Handle<SHVkPipelineLayout> dummyPipelineLayout;
//! Descriptor type mappings for the system
SHDescriptorMappings descMappings;
};
private:
//! Global descriptor set layouts. Used to allocate descriptor sets
static std::vector<Handle<SHVkDescriptorSetLayout>> predefinedLayouts;
@ -21,10 +36,17 @@ namespace SHADE
//! Default vertex input state (used by everything).
static SHVertexInputState defaultVertexInputState;
//! Since we want to bind global data but can't do so without a pipeline layout,
//! we create a dummy pipeline layout to use it for binding.
static Handle<SHVkPipelineLayout> dummyPipelineLayout;
//! predefined data for the batching system
static PerSystem batchingSystemData;
//! predefined data for the text system
static PerSystem textSystemData;
//! predefined data for the render graph node computes
static PerSystem renderGraphNodeComputeData;
static void InitDescMappings (void) noexcept;
static void InitDummyPipelineLayouts (Handle<SHVkLogicalDevice> logicalDevice) noexcept;
static void InitDescSetLayouts (Handle<SHVkLogicalDevice> logicalDevice) noexcept;
static void InitDefaultVertexInputState (void) noexcept;
@ -42,8 +64,10 @@ namespace SHADE
/*-----------------------------------------------------------------------*/
/* SETTERS AND GETTERS */
/*-----------------------------------------------------------------------*/
static std::vector<Handle<SHVkDescriptorSetLayout>> GetPredefinedDescSetLayouts (SHEnumWrapper<SHGraphicsConstants::SHPredefinedDescSetLayoutTypes> types) noexcept;
static std::vector<Handle<SHVkDescriptorSetLayout>> GetPredefinedDescSetLayouts (SHEnumWrapper<SHGraphicsConstants::PredefinedDescSetLayoutTypes> types) noexcept;
static SHVertexInputState const& GetDefaultViState (void) noexcept;
static Handle<SHVkPipelineLayout> GetDummyPipelineLayout (void) noexcept;
static PerSystem const& GetBatchingSystemData(void) noexcept;
static PerSystem const& GetTextSystemData(void) noexcept;
static PerSystem const& GetRenderGraphNodeComputeData(void) noexcept;
};
}

View File

@ -27,13 +27,28 @@ namespace SHADE
public:
static constexpr uint8_t numPredefinedDescSetLayoutTypes = 64;
enum class SHPredefinedDescSetLayoutTypes : uint64_t
// This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData
enum class PredefinedDescSetLayoutTypes : uint64_t
{
STATIC_DATA = 0x01,
LIGHTS = 0x02,
CAMERA = 0x04,
MATERIALS = 0x08,
FONT = 0x10,
};
// This enum is different from the one above in that it is used to initialize a hash table to
// with the values here as keys and set indices as values. It is worth noting that some values here
// are not in the above table. This is because those values don't have predefined descriptor set layouts.
// Their layouts and set indices are instead created through introspection in the pipeline layout.
enum class DescriptorSetTypes
{
STATIC_DATA,
LIGHTS,
CAMERA,
MATERIALS,
FONT,
RENDER_GRAPH_RESOURCE,
RENDER_GRAPH_NODE_COMPUTE_RESOURCE,
};
struct RenderGraphIndices
@ -42,68 +57,68 @@ namespace SHADE
static constexpr uint32_t EDITOR = 0;
};
//struct DescriptorSetIndex
//{
// /***************************************************************************/
// /*!
// \brief
// DescriptorSet Index for static global values like generic data, and
// texture samplers
// */
// /***************************************************************************/
// static constexpr uint32_t STATIC_GLOBALS = 0;
// /***************************************************************************/
// /*!
// \brief
// DescriptorSet Index for dynamic global values like lights.
// */
// /***************************************************************************/
// static constexpr uint32_t DYNAMIC_GLOBALS = 1;
// /***************************************************************************/
// /*!
// \brief
// DescriptorSet Index for high frequency changing global values like
// camera matrices.
// */
// /***************************************************************************/
// static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2;
// /***************************************************************************/
// /*!
// \brief
// DescriptorSet Index for per-instance/material changing values.
// */
// /***************************************************************************/
// static constexpr uint32_t PER_INSTANCE = 3;
// /***************************************************************************/
// /*!
// \brief
// DescriptorSet Index for render graph resources. Unlike the sets from
// 1 to 3 and 6, this set index does not have hard coded bindings and is
// NOT part of the layouts included in the global data.
// */
// /***************************************************************************/
// static constexpr uint32_t RENDERGRAPH_RESOURCE = 4;
// /***************************************************************************/
// /*!
// \brief
// DescriptorSet Index for render graph node compute resources. For data
// that we wish to pass to compute shaders in the render graph, this is
// the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have
// hard coded bindings and is NOT part of the layouts included in the global
// data.
// */
// /***************************************************************************/
// static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5;
struct DescriptorSetIndex
{
/***************************************************************************/
/*!
\brief
DescriptorSet Index for static global values like generic data, and
texture samplers
*/
/***************************************************************************/
static constexpr uint32_t STATIC_GLOBALS = 0;
/***************************************************************************/
/*!
\brief
DescriptorSet Index for dynamic global values like lights.
*/
/***************************************************************************/
static constexpr uint32_t DYNAMIC_GLOBALS = 1;
/***************************************************************************/
/*!
\brief
DescriptorSet Index for high frequency changing global values like
camera matrices.
*/
/***************************************************************************/
static constexpr uint32_t HIGH_FREQUENCY_GLOBALS = 2;
/***************************************************************************/
/*!
\brief
DescriptorSet Index for per-instance/material changing values.
*/
/***************************************************************************/
static constexpr uint32_t PER_INSTANCE = 3;
/***************************************************************************/
/*!
\brief
DescriptorSet Index for render graph resources. Unlike the sets from
1 to 3 and 6, this set index does not have hard coded bindings and is
NOT part of the layouts included in the global data.
*/
/***************************************************************************/
static constexpr uint32_t RENDERGRAPH_RESOURCE = 4;
/***************************************************************************/
/*!
\brief
DescriptorSet Index for render graph node compute resources. For data
that we wish to pass to compute shaders in the render graph, this is
the set to use. Unlike the sets from 1 to 3 and 6, this set index does not have
hard coded bindings and is NOT part of the layouts included in the global
data.
*/
/***************************************************************************/
static constexpr uint32_t RENDERGRAPH_NODE_COMPUTE_RESOURCE = 5;
// /***************************************************************************/
// /*!
// \brief
// To store font data.
//
// */
// /***************************************************************************/
// static constexpr uint32_t FONT_DATA = 4;
//};
/***************************************************************************/
/*!
\brief
To store font data.
*/
/***************************************************************************/
static constexpr uint32_t FONT_DATA = 4;
};
struct DescriptorSetBindings
{

View File

@ -903,7 +903,7 @@ namespace SHADE
void SHGraphicsSystem::BuildFonts(void) noexcept
{
fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::FONT)[0], resourceManager);
fontLibrary.BuildFonts(device, graphicsQueue, graphicsCmdPool, descPool, SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::FONT)[0], resourceManager);
}
#pragma endregion ADD_REMOVE
@ -1137,7 +1137,7 @@ namespace SHADE
device, SHPipelineLayoutParams
{
.shaderModules = { (instanced ? debugMeshVertShader : debugVertShader) , debugFragShader },
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::SHPredefinedDescSetLayoutTypes::CAMERA)
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsConstants::PredefinedDescSetLayoutTypes::CAMERA)
}
);
auto pipeline = resourceManager.Create<SHVkPipeline>(device, pipelineLayout, nullptr, renderPass, subpass);

View File

@ -13,7 +13,7 @@ namespace SHADE
SHPipelineLayoutParams params
{
.shaderModules = {vsFsPair.first, vsFsPair.second},
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts()
.globalDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts
};
// Create the pipeline layout

View File

@ -103,7 +103,7 @@ namespace SHADE
SHPipelineLayoutParams plParams
{
.shaderModules = {textVS, textFS},
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts()
.predefinedDescSetLayouts = SHPredefinedData::GetTextSystemData().descSetLayouts
};
pipelineLayout = logicalDevice->CreatePipelineLayout(plParams);

View File

@ -25,7 +25,7 @@ namespace SHADE
//! used just for textures or lights for example). In that case, we still
//! want to use the layout to initialize the pipeline layout but we do not
//! want to use it for allocating descriptor sets.
std::vector<Handle<SHVkDescriptorSetLayout>> const& globalDescSetLayouts = {};
std::vector<Handle<SHVkDescriptorSetLayout>> const& predefinedDescSetLayouts = {};
//! Since both SPIRV-Reflect and GLSL don't provide ways to describe UBOs or
//! SSBOs as dynamic, we need to do it ourselves. This will store bindings

View File

@ -27,7 +27,7 @@ namespace SHADE
SHPipelineLayoutParams pipelineLayoutParams
{
.shaderModules = {computeShaderModule},
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(),
.predefinedDescSetLayouts = SHPredefinedData::GetRenderGraphNodeComputeData().descSetLayouts,
.dynamicBufferBindings = std::move(dynamicBufferBindings),
};
@ -45,10 +45,13 @@ namespace SHADE
// save the resources
resources = std::move (subpassComputeResources);
auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings;
auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline();
//Get the descriptor set layouts required to allocate. We only want the ones for allocate because
//global descriptors are already bound in the main system.
auto const& graphResourceLayout = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE];
auto const& graphResourceLayout = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE)];
// Allocate descriptor sets to hold the images for reading (STORAGE_IMAGE)
for (uint32_t i = 0; i < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++i)
@ -60,14 +63,12 @@ namespace SHADE
#endif
}
auto const& layouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline();
if (layouts.size() == SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE + 1)
// check if all layouts are there
if (layouts.size() == descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE) + 1)
{
// create compute resources
computeResource = graphStorage->resourceHub->Create<ComputeResource>();
auto computeResourceLayout = layouts[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE];
auto computeResourceLayout = layouts[descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE)];
computeResource->descSet = graphStorage->descriptorPool->Allocate({ computeResourceLayout }, { 1 });
#ifdef _DEBUG
for (auto set : computeResource->descSet->GetVkHandle())
@ -91,12 +92,14 @@ namespace SHADE
// bind the compute pipeline
cmdBuffer->BindPipeline(computePipeline);
auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings;
// bind descriptor sets
cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, {});
cmdBuffer->BindDescriptorSet(graphResourceDescSets[frameIndex], SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE), {});
if (computeResource)
{
cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_NODE_COMPUTE_RESOURCE, computeResource->dynamicOffsets[frameIndex]);
cmdBuffer->BindDescriptorSet(computeResource->descSet, SH_PIPELINE_TYPE::COMPUTE, descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_NODE_COMPUTE_RESOURCE), computeResource->dynamicOffsets[frameIndex]);
}
// dispatch compute
@ -109,8 +112,11 @@ namespace SHADE
void SHRenderGraphNodeCompute::HandleResize(void) noexcept
{
auto const& descMappings = SHPredefinedData::GetRenderGraphNodeComputeData().descMappings;
uint32_t renderGraphResourceSetIndex = descMappings.GetMappings().at(SHGraphicsConstants::DescriptorSetTypes::RENDER_GRAPH_RESOURCE);
// Get the layout for the render graph resource. We can index it this way because the container returned is a container of layouts that includes the global ones
auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE];
auto pipelineDescSetLayouts = computePipeline->GetPipelineLayout()->GetDescriptorSetLayoutsPipeline()[renderGraphResourceSetIndex];
// everything below here needs resizing
for (uint32_t frameIndex = 0; frameIndex < SHGraphicsConstants::NUM_FRAME_BUFFERS; ++frameIndex)
@ -123,8 +129,8 @@ namespace SHADE
uint32_t imageIndex = (resources[i]->resourceTypeFlags & static_cast<uint32_t>(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? frameIndex : 0;
SHVkDescriptorSetGroup::viewSamplerLayout vsl = std::make_tuple(resources[i]->GetImageView(imageIndex), Handle<SHVkSampler>{}, vk::ImageLayout::eGeneral);
graphResourceDescSets[frameIndex]->ModifyWriteDescImage(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint, { &vsl, 1 });
graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(SHGraphicsConstants::DescriptorSetIndex::RENDERGRAPH_RESOURCE, binding.BindPoint);
graphResourceDescSets[frameIndex]->ModifyWriteDescImage(renderGraphResourceSetIndex, binding.BindPoint, { &vsl, 1 });
graphResourceDescSets[frameIndex]->UpdateDescriptorSetImages(renderGraphResourceSetIndex, binding.BindPoint);
++i;
}
}

View File

@ -24,7 +24,7 @@ namespace SHADE
auto pipelineLayout = logicalDevice->CreatePipelineLayout(SHPipelineLayoutParams
{
.shaderModules = {shaderModules.first, shaderModules.second},
.globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts(),
.predefinedDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts
});
pipeline = logicalDevice->CreateGraphicsPipeline(pipelineLayout, nullptr, renderGraphNode->GetRenderpass(), subpass);