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;
// 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->BindPipeline(pipeline);
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
@ -649,17 +653,14 @@ namespace SHADE
static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0;
/* Create Descriptor Sets if Needed */
std::vector<uint32_t> varDescCounts;
PreDefDescLayoutType layoutTypes = {};
if (matPropsData)
{
layoutTypes |= PreDefDescLayoutType::MATERIALS;
varDescCounts.push_back(0);
layoutTypes = PreDefDescLayoutType::MATERIALS;
}
if (!boneMatrixData.empty())
{
layoutTypes |= PreDefDescLayoutType::BONES;
varDescCounts.push_back(0);
layoutTypes = PreDefDescLayoutType::MATERIAL_AND_BONES;
}
if (matPropsData || !boneMatrixData.empty())
@ -670,7 +671,7 @@ namespace SHADE
instanceDataDescSet[frameIndex] = descPool->Allocate
(
SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(layoutTypes),
varDescCounts
{ 0 }
);
#ifdef _DEBUG
const auto& DESC_SETS = instanceDataDescSet[frameIndex]->GetVkHandle();

View File

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

View File

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

View File

@ -12,7 +12,7 @@ namespace SHADE
LIGHTS,
CAMERA,
PER_INSTANCE_BATCH,
BONES,
PER_INSTANCE_ANIM_BATCH,
FONT,
RENDER_GRAPH_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

View File

@ -8,12 +8,12 @@
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
{
.shaderModules = {vsFsPair.first, vsFsPair.second},
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(SHGraphicsPredefinedData::SystemType::BATCHING).descSetLayouts
.predefinedDescSetLayouts = SHGraphicsPredefinedData::GetSystemData(systemType).descSetLayouts
};
// Create the pipeline layout

View File

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