diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index cb2806aa..c92ad808 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -411,11 +411,12 @@ namespace SHADE instancedIntegerData.reserve(numTotalElements); instancedIntegerData.clear(); + auto const& descMappings = SHPredefinedData::GetBatchingSystemData().descMappings; // - Material Properties Data const Handle 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, 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(matPropsDataSize) ); matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer ( - SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, + MATERIAL_DESC_SET_INDEX, SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA ); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp new file mode 100644 index 00000000..c2b7c042 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.cpp @@ -0,0 +1,17 @@ +#include "SHpch.h" +#include "SHDescriptorMappings.h" + +namespace SHADE +{ + void SHDescriptorMappings::AddMappings(std::initializer_list> inMappings) noexcept + { + for (auto& map : inMappings) + mappings.emplace(map); + } + + SHDescriptorMappings::MapType const& SHDescriptorMappings::GetMappings(void) const noexcept + { + return mappings; + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h new file mode 100644 index 00000000..67480e7e --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHDescriptorMappings.h @@ -0,0 +1,29 @@ +#pragma once + +#include +#include "Graphics/MiddleEnd/Interface/SHGraphicsConstants.h" + +namespace SHADE +{ + class SHDescriptorMappings + { + public: + using MapType = std::unordered_map; + + private: + //! To map an enum value from descriptor set types to set indices + MapType mappings; + + public: + /*-----------------------------------------------------------------------*/ + /* PUBLIC MEMBER FUNCTIONS */ + /*-----------------------------------------------------------------------*/ + void AddMappings (std::initializer_list> inMappings) noexcept; + + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + MapType const& GetMappings (void) const noexcept; + }; + +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp new file mode 100644 index 00000000..2d6cc9e1 --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.cpp @@ -0,0 +1,30 @@ +#include "SHpch.h" +#include "SHGlobalDescriptorSets.h" + +namespace SHADE +{ + + Handle SHGlobalDescriptorSets::lightDescriptorSet; + + /***************************************************************************/ + /*! + + \brief + Sets the Handle to descriptor set for lights. + + \param lightDescSet + The handle to set to. + + */ + /***************************************************************************/ + void SHGlobalDescriptorSets::SetLightDescriptorSet(Handle lightDescSet) noexcept + { + lightDescriptorSet = lightDescSet; + } + + Handle SHGlobalDescriptorSets::GetLightDescriptorSet(void) noexcept + { + return lightDescriptorSet; + } + +} \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h new file mode 100644 index 00000000..ce6c42bb --- /dev/null +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHGlobalDescriptorSets.h @@ -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 lightDescriptorSet; + + public: + /*-----------------------------------------------------------------------*/ + /* SETTERS AND GETTERS */ + /*-----------------------------------------------------------------------*/ + static void SetLightDescriptorSet (Handle lightDescSet) noexcept; + + static Handle GetLightDescriptorSet (void) noexcept; + + }; +} diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp index d93e073b..ac7fac17 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.cpp @@ -13,7 +13,41 @@ namespace SHADE /*-----------------------------------------------------------------------------------*/ std::vector> SHPredefinedData::predefinedLayouts; SHVertexInputState SHPredefinedData::defaultVertexInputState; - Handle 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 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 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 fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); - SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); + //Handle 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> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept + std::vector> SHPredefinedData::GetPredefinedDescSetLayouts(SHEnumWrapper types) noexcept { std::vector> layoutsFound; for (uint8_t i = 0; i < SHGraphicsConstants::numPredefinedDescSetLayoutTypes; ++i) @@ -156,9 +203,20 @@ namespace SHADE return defaultVertexInputState; } - Handle 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; } } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h index 5f13a100..b19a1e0b 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/GlobalData/SHPredefinedData.h @@ -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> descSetLayouts; + + //! pipeline layout used for binding descriptor sets in the system + static Handle dummyPipelineLayout; + + //! Descriptor type mappings for the system + SHDescriptorMappings descMappings; + }; + private: //! Global descriptor set layouts. Used to allocate descriptor sets static std::vector> 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 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 logicalDevice) noexcept; static void InitDescSetLayouts (Handle logicalDevice) noexcept; static void InitDefaultVertexInputState (void) noexcept; @@ -42,8 +64,10 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */ /*-----------------------------------------------------------------------*/ - static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; - static SHVertexInputState const& GetDefaultViState (void) noexcept; - static Handle GetDummyPipelineLayout (void) noexcept; + static std::vector> GetPredefinedDescSetLayouts (SHEnumWrapper types) noexcept; + static SHVertexInputState const& GetDefaultViState (void) noexcept; + static PerSystem const& GetBatchingSystemData(void) noexcept; + static PerSystem const& GetTextSystemData(void) noexcept; + static PerSystem const& GetRenderGraphNodeComputeData(void) noexcept; }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h index e0b76555..c80b9de5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsConstants.h @@ -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 { diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index c9e7f2d2..6881d7a8 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -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(device, pipelineLayout, nullptr, renderPass, subpass); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 9e6f1bd7..9b16a279 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -13,7 +13,7 @@ namespace SHADE SHPipelineLayoutParams params { .shaderModules = {vsFsPair.first, vsFsPair.second}, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts() + .globalDescSetLayouts = SHPredefinedData::GetBatchingSystemData().descSetLayouts }; // Create the pipeline layout diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp index f0e375e6..f117b26c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/TextRendering/SHTextRenderingSubSystem.cpp @@ -103,7 +103,7 @@ namespace SHADE SHPipelineLayoutParams plParams { .shaderModules = {textVS, textFS}, - .globalDescSetLayouts = SHPredefinedData::GetPredefinedDescSetLayouts() + .predefinedDescSetLayouts = SHPredefinedData::GetTextSystemData().descSetLayouts }; pipelineLayout = logicalDevice->CreatePipelineLayout(plParams); diff --git a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h index 010bed0e..3288d196 100644 --- a/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h +++ b/SHADE_Engine/src/Graphics/Pipeline/SHPipelineLayoutParams.h @@ -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> const& globalDescSetLayouts = {}; + std::vector> 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 diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp index aca987d8..ea574158 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderGraphNodeCompute.cpp @@ -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]; + + //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 = 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(); - 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(SH_RENDER_GRAPH_RESOURCE_FLAGS::COLOR_PRESENT)) ? frameIndex : 0; SHVkDescriptorSetGroup::viewSamplerLayout vsl = std::make_tuple(resources[i]->GetImageView(imageIndex), Handle{}, 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; } } diff --git a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp index b8717925..4c575c99 100644 --- a/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp +++ b/SHADE_Engine/src/Graphics/RenderGraph/SHRenderToSwapchainImageSystem.cpp @@ -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);