From c1a3a6acf16840e5047ab1e583ddc1a3bc01d2e0 Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sat, 17 Sep 2022 23:32:03 +0800 Subject: [PATCH] Created global descriptor set layouts --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 78 ++++++++++++++++++- .../MiddleEnd/Interface/SHGraphicsSystem.h | 3 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 6 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.h | 4 +- 4 files changed, 82 insertions(+), 9 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index e19aee57..893ea182 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -40,7 +40,6 @@ namespace SHADE SHVkInstance::Init(true, true, true); // Get Physical Device and Construct Logical Device - // TODO: Provide configuration for these options physicalDevice = SHVkInstance::CreatePhysicalDevice(SH_PHYSICAL_DEVICE_TYPE::BEST); device = SHVkInstance::CreateLogicalDevice({ SHQueueParams(SH_Q_FAM::GRAPHICS, SH_QUEUE_SELECT::DEDICATED), SHQueueParams(SH_Q_FAM::TRANSFER, SH_QUEUE_SELECT::DEDICATED) }, physicalDevice); @@ -153,8 +152,10 @@ namespace SHADE semaHandle = device->CreateSemaphore(); } + + ConfigureDefaultVertexInputState(); - //pipelineLibrary.Init(device, &defaultVertexInputState, ); + pipelineLibrary.Init(device, &defaultVertexInputState, &globalDescSetLayouts); } /***************************************************************************/ @@ -361,6 +362,79 @@ namespace SHADE window = wind; } + void SHGraphicsSystem::ConfigureGlobalDescLayouts(void) noexcept + { + SHVkDescriptorSetLayout::Binding genericDataBinding + { + .Type = vk::DescriptorType::eUniformBufferDynamic, + .Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute, + .BindPoint = 0, + .DescriptorCount = 1, + }; + + SHVkDescriptorSetLayout::Binding texturesBinding + { + .Type = vk::DescriptorType::eCombinedImageSampler, + .Stage = vk::ShaderStageFlagBits::eVertex | vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eCompute, + .BindPoint = 1, + .DescriptorCount = 2000, // we can have up to 2000 textures for now + .flags = vk::DescriptorBindingFlagBits::eVariableDescriptorCount, + }; + + // For global data (generic data and textures) + Handle staticGlobalLayout = device->CreateDescriptorSetLayout({genericDataBinding, texturesBinding}); + + + + + + SHVkDescriptorSetLayout::Binding lightBinding + { + .Type = vk::DescriptorType::eStorageBufferDynamic, + .Stage = vk::ShaderStageFlagBits::eFragment, + .BindPoint = 0, + .DescriptorCount = 1, + }; + + // For Dynamic global data (lights) + Handle dynamicGlobalLayout = device->CreateDescriptorSetLayout({ lightBinding }); + + + + + + SHVkDescriptorSetLayout::Binding cameraDataBinding + { + .Type = vk::DescriptorType::eUniformBufferDynamic, + .Stage = vk::ShaderStageFlagBits::eVertex, + .BindPoint = 0, + .DescriptorCount = 1, + }; + + // For High frequency global data (camera) + Handle cameraDataGlobalLayout = device->CreateDescriptorSetLayout({ cameraDataBinding }); + + + + + + SHVkDescriptorSetLayout::Binding materialDataBinding + { + .Type = vk::DescriptorType::eStorageBufferDynamic, + .Stage = vk::ShaderStageFlagBits::eFragment, + .BindPoint = 0, + .DescriptorCount = 1, + }; + + // For High frequency global data (camera) + Handle materialDataPerInstanceLayout = device->CreateDescriptorSetLayout({ materialDataBinding }); + + globalDescSetLayouts.push_back(staticGlobalLayout); + globalDescSetLayouts.push_back(dynamicGlobalLayout); + globalDescSetLayouts.push_back(cameraDataGlobalLayout); + globalDescSetLayouts.push_back(materialDataPerInstanceLayout); + } + void SHGraphicsSystem::ConfigureDefaultVertexInputState(void) noexcept { defaultVertexInputState.AddBinding(false, false, {SHVertexAttribute(SHAttribFormat::FLOAT_3D)}); // positions at binding 0 diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h index 55238ce6..4f20afd4 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.h @@ -156,7 +156,7 @@ namespace SHADE SHPipelineLibrary pipelineLibrary; - std::vector globalDescSetLayouts; + std::vector> globalDescSetLayouts; // Middle End Resources ResourceManager resourceManager; @@ -179,6 +179,7 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ /* Private member functions */ /*-----------------------------------------------------------------------------*/ + void ConfigureGlobalDescLayouts (void) noexcept; void ConfigureDefaultVertexInputState (void) noexcept; }; } \ No newline at end of file diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index 45bb87ba..ed3900d5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -5,12 +5,12 @@ namespace SHADE { - Handle SHPipelineLibrary::CreateDrawPipeline(std::pair, Handle> const& vsFsPair, Handle renderpass, uint32_t subpass, SHVertexInputState const& vertexInput, std::vector> const& globalDescSetLayouts) noexcept + Handle SHPipelineLibrary::CreateDrawPipeline(std::pair, Handle> const& vsFsPair, Handle renderpass, uint32_t subpass) noexcept { SHPipelineLayoutParams params { .shaderModules = {vsFsPair.first, vsFsPair.second}, - .globalDescSetLayouts = globalDescSetLayouts + .globalDescSetLayouts = *globalDescSetLayouts }; // Create the pipeline layout @@ -18,7 +18,7 @@ namespace SHADE // Create the pipeline and configure the default vertex input state auto newPipeline = logicalDevice->CreatePipeline(pipelineLayout, nullptr, renderpass, subpass, SH_PIPELINE_TYPE::GRAPHICS); - newPipeline->GetPipelineState().SetVertexInputState(vertexInput); + newPipeline->GetPipelineState().SetVertexInputState(*vertexInputState); // Actually construct the pipeline newPipeline->ConstructPipeline(); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h index fe69e87b..264caca5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h @@ -46,9 +46,7 @@ namespace SHADE Handle CreateDrawPipeline ( std::pair, Handle> const& vsFsPair, Handle renderpass, - uint32_t subpass, - SHVertexInputState const& vertexInput, - std::vector> const& globalDescSetLayouts + uint32_t subpass ) noexcept; Handle GetDrawPipline (std::pair, Handle> const& vsFsPair) noexcept; bool CheckDrawPipelineExistence (std::pair, Handle> const& vsFsPair) noexcept;