SHPipelineLibrary now sets the pipeline layouts correctly

This commit is contained in:
Kah Wei 2023-01-13 18:14:40 +08:00
parent d1ab595126
commit 74d6e5cee7
8 changed files with 75 additions and 39 deletions

View File

@ -581,7 +581,11 @@ namespace SHADE
return; return;
// Bind all required objects before drawing // Bind all required objects before drawing
static std::array dynamicOffset{ 0U, static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix)) }; std::vector<uint32_t> dynamicOffset{ 0 };
if (!boneMatrixData.empty())
{
dynamicOffset.emplace_back(0);
}
cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index)); cmdBuffer->BeginLabeledSegment("SHBatch for Pipeline #" + std::to_string(pipeline.GetId().Data.Index));
cmdBuffer->BindPipeline(pipeline); cmdBuffer->BindPipeline(pipeline);
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
@ -649,17 +653,14 @@ namespace SHADE
static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0; static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0;
/* Create Descriptor Sets if Needed */ /* Create Descriptor Sets if Needed */
std::vector<uint32_t> varDescCounts;
PreDefDescLayoutType layoutTypes = {}; PreDefDescLayoutType layoutTypes = {};
if (matPropsData) if (matPropsData)
{ {
layoutTypes |= PreDefDescLayoutType::MATERIALS; layoutTypes = PreDefDescLayoutType::MATERIALS;
varDescCounts.push_back(0);
} }
if (!boneMatrixData.empty()) if (!boneMatrixData.empty())
{ {
layoutTypes |= PreDefDescLayoutType::BONES; layoutTypes = PreDefDescLayoutType::MATERIAL_AND_BONES;
varDescCounts.push_back(0);
} }
if (matPropsData || !boneMatrixData.empty()) if (matPropsData || !boneMatrixData.empty())
@ -670,7 +671,7 @@ namespace SHADE
instanceDataDescSet[frameIndex] = descPool->Allocate instanceDataDescSet[frameIndex] = descPool->Allocate
( (
SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(layoutTypes), SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(layoutTypes),
varDescCounts { 0 }
); );
#ifdef _DEBUG #ifdef _DEBUG
const auto& DESC_SETS = instanceDataDescSet[frameIndex]->GetVkHandle(); const auto& DESC_SETS = instanceDataDescSet[frameIndex]->GetVkHandle();

View File

@ -26,7 +26,14 @@ namespace SHADE
{SHPredefinedDescriptorTypes::STATIC_DATA, 0}, {SHPredefinedDescriptorTypes::STATIC_DATA, 0},
{SHPredefinedDescriptorTypes::CAMERA, 1}, {SHPredefinedDescriptorTypes::CAMERA, 1},
{SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH, 2}, {SHPredefinedDescriptorTypes::PER_INSTANCE_BATCH, 2},
}); });
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descMappings.AddMappings
({
{SHPredefinedDescriptorTypes::STATIC_DATA, 0},
{SHPredefinedDescriptorTypes::CAMERA, 1},
{SHPredefinedDescriptorTypes::PER_INSTANCE_ANIM_BATCH, 2},
});
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings
({ ({
@ -129,14 +136,7 @@ namespace SHADE
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA, .BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
.DescriptorCount = 1, .DescriptorCount = 1,
}; };
SHVkDescriptorSetLayout::Binding boneDataBinding Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding });
{
.Type = vk::DescriptorType::eStorageBufferDynamic,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA,
.DescriptorCount = 1,
};
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding, boneDataBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals"); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material Globals");
// font bitmap data (texture) // font bitmap data (texture)
@ -160,17 +160,16 @@ namespace SHADE
Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding }); Handle<SHVkDescriptorSetLayout> fontDataDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ fontBitmapBinding, fontMatrixBinding });
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data"); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, fontDataDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Font Data");
// Bone matrix data // For per instance data (transforms, materials, etc.)
SHVkDescriptorSetLayout::Binding boneMatrixBinding SHVkDescriptorSetLayout::Binding boneDataBinding
{ {
.Type = vk::DescriptorType::eStorageBuffer, .Type = vk::DescriptorType::eStorageBufferDynamic,
.Stage = vk::ShaderStageFlagBits::eVertex, .Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::BONE_MATRIX_DATA, .BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA,
.DescriptorCount = 1, .DescriptorCount = 1,
}; };
Handle<SHVkDescriptorSetLayout> materialBoneDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding, boneDataBinding });
Handle<SHVkDescriptorSetLayout> boneMatricesDescSetLayout = logicalDevice->CreateDescriptorSetLayout({ boneMatrixBinding }); SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, materialBoneDataPerInstanceLayout->GetVkHandle(), "[Descriptor Set Layout] Material and Bone Globals");
SET_VK_OBJ_NAME(logicalDevice, vk::ObjectType::eDescriptorSetLayout, boneMatricesDescSetLayout->GetVkHandle(), "[Descriptor Set Layout] Bone Matrix Data");
predefinedLayouts.push_back(staticGlobalLayout); predefinedLayouts.push_back(staticGlobalLayout);
predefinedLayouts.push_back(lightDataDescSetLayout); predefinedLayouts.push_back(lightDataDescSetLayout);
@ -178,7 +177,7 @@ namespace SHADE
predefinedLayouts.push_back(materialDataPerInstanceLayout); predefinedLayouts.push_back(materialDataPerInstanceLayout);
predefinedLayouts.push_back(fontDataDescSetLayout); predefinedLayouts.push_back(fontDataDescSetLayout);
predefinedLayouts.push_back({}); predefinedLayouts.push_back({});
predefinedLayouts.push_back(boneMatricesDescSetLayout); predefinedLayouts.push_back(materialBoneDataPerInstanceLayout);
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts
( (
@ -187,6 +186,13 @@ namespace SHADE
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS
); );
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descSetLayouts = GetPredefinedDescSetLayouts
(
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA |
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::CAMERA |
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIAL_AND_BONES
);
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts = GetPredefinedDescSetLayouts perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts = GetPredefinedDescSetLayouts
( (
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA | SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::STATIC_DATA |

View File

@ -23,18 +23,19 @@ namespace SHADE
// This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData // This enum is mainly to initialize a bit field to retrieve bit fields from SHPRedefinedData
enum class PredefinedDescSetLayoutTypes : uint64_t enum class PredefinedDescSetLayoutTypes : uint64_t
{ {
STATIC_DATA = 0b0000001, STATIC_DATA = 0b00000001,
LIGHTS = 0b0000010, LIGHTS = 0b00000010,
CAMERA = 0b0000100, CAMERA = 0b00000100,
MATERIALS = 0b0001000, MATERIALS = 0b00001000,
FONT = 0b0010000, FONT = 0b00010000,
SHADOW = 0b0100000, SHADOW = 0b00100000,
BONES = 0b1000000, MATERIAL_AND_BONES = 0b01000000
}; };
enum class SystemType enum class SystemType
{ {
BATCHING = 0, BATCHING = 0,
BATCHING_ANIM,
TEXT_RENDERING, TEXT_RENDERING,
RENDER_GRAPH_NODE_COMPUTE, RENDER_GRAPH_NODE_COMPUTE,
NUM_TYPES NUM_TYPES

View File

@ -12,7 +12,7 @@ namespace SHADE
LIGHTS, LIGHTS,
CAMERA, CAMERA,
PER_INSTANCE_BATCH, PER_INSTANCE_BATCH,
BONES, PER_INSTANCE_ANIM_BATCH,
FONT, FONT,
RENDER_GRAPH_RESOURCE, RENDER_GRAPH_RESOURCE,
RENDER_GRAPH_NODE_COMPUTE_RESOURCE, RENDER_GRAPH_NODE_COMPUTE_RESOURCE,

View File

@ -173,7 +173,7 @@ namespace SHADE
*/ */
/***************************************************************************/ /***************************************************************************/
static constexpr uint32_t BONE_MATRIX_DATA = 0; static constexpr uint32_t BONE_MATRIX_DATA = 1;
}; };
struct VertexBufferBindings struct VertexBufferBindings

View File

@ -8,12 +8,12 @@
namespace SHADE namespace SHADE
{ {
Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass) noexcept Handle<SHVkPipeline> SHPipelineLibrary::CreateGraphicsPipelines(std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, Handle<SHVkRenderpass> renderpass, Handle<SHSubpass> subpass, SHGraphicsPredefinedData::SystemType systemType) noexcept
{ {
SHPipelineLayoutParams params SHPipelineLayoutParams params
{ {
.shaderModules = {vsFsPair.first, vsFsPair.second}, .shaderModules = {vsFsPair.first, vsFsPair.second},
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts .predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(systemType).descSetLayouts
}; };
// Create the pipeline layout // Create the pipeline layout

View File

@ -3,6 +3,7 @@
#include <unordered_map> #include <unordered_map>
#include "Graphics/Shaders/SHVkShaderModule.h" #include "Graphics/Shaders/SHVkShaderModule.h"
#include "Graphics/Pipeline/SHVkPipeline.h" #include "Graphics/Pipeline/SHVkPipeline.h"
#include "Graphics/MiddleEnd/GlobalData/SHGraphicsPredefinedData.h"
namespace SHADE namespace SHADE
{ {
@ -32,7 +33,8 @@ namespace SHADE
Handle<SHVkPipeline> CreateGraphicsPipelines ( Handle<SHVkPipeline> CreateGraphicsPipelines (
std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair, std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair,
Handle<SHVkRenderpass> renderpass, Handle<SHVkRenderpass> renderpass,
Handle<SHSubpass> subpass Handle<SHSubpass> subpass,
SHGraphicsPredefinedData::SystemType systemType
) noexcept; ) noexcept;
Handle<SHVkPipeline> GetGraphicsPipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept; Handle<SHVkPipeline> GetGraphicsPipeline (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;
bool CheckGraphicsPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept; bool CheckGraphicsPipelineExistence (std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>> const& vsFsPair) noexcept;

View File

@ -583,11 +583,37 @@ namespace SHADE
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetGraphicsPipeline(vsFsPair); Handle<SHVkPipeline> pipeline = pipelineLibrary.GetGraphicsPipeline(vsFsPair);
if (!pipeline) if (!pipeline)
{ {
// default to batching system type
SHGraphicsPredefinedData::SystemType systemType{ SHGraphicsPredefinedData::SystemType::BATCHING };
auto const& REFLECTED_SETS = vsFsPair.first->GetReflectedData().GetDescriptorBindingInfo().GetReflectedSets();
// look for animation set binding in the shader (set 2 binding 1)
for (auto const& set : REFLECTED_SETS)
{
auto const mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING_ANIM);
// Look for set 2
if (set->set == mappings.at(SHPredefinedDescriptorTypes::PER_INSTANCE_ANIM_BATCH))
{
for (int i = 0; i < set->binding_count; i++)
{
// look for binding 1. if found use BATCHING_ANIM system type
if (set->bindings[i]->binding == SHGraphicsConstants::DescriptorSetBindings::BONE_MATRIX_DATA)
{
systemType = SHGraphicsPredefinedData::SystemType::BATCHING_ANIM;
break;
}
}
break;
}
}
pipeline = pipelineLibrary.CreateGraphicsPipelines pipeline = pipelineLibrary.CreateGraphicsPipelines
( (
vsFsPair, vsFsPair,
renderpass, renderpass,
subpass subpass,
systemType
); );
} }