Animation WIP merge #321

Merged
XiaoQiDigipen merged 76 commits from SP3-17-animation-system into main 2023-01-30 17:35:57 +08:00
12 changed files with 185 additions and 124 deletions
Showing only changes of commit 7da89def50 - Show all commits

View File

@ -10,7 +10,8 @@ layout(location = 2) in vec3 aNormal;
layout(location = 3) in vec3 aTangent; layout(location = 3) in vec3 aTangent;
layout(location = 4) in mat4 worldTransform; layout(location = 4) in mat4 worldTransform;
layout(location = 8) in uvec2 integerData; layout(location = 8) in uvec2 integerData;
layout(location = 9) in uvec4 aBoneIndices;
layout(location = 10) in vec4 aBoneWeights;
layout(location = 0) out struct layout(location = 0) out struct
{ {

Binary file not shown.

View File

@ -202,7 +202,7 @@ namespace SHADE
auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface
( (
mappings.at(SHPredefinedDescriptorTypes::MATERIALS), mappings.at(SHPredefinedDescriptorTypes::MATERIALS),
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA
); );
if (!interface) if (!interface)
return; return;

View File

@ -65,13 +65,13 @@ namespace SHADE
, transformDataBuffer { rhs.transformDataBuffer } , transformDataBuffer { rhs.transformDataBuffer }
, instancedIntegerBuffer { rhs.instancedIntegerBuffer } , instancedIntegerBuffer { rhs.instancedIntegerBuffer }
, matPropsBuffer { rhs.matPropsBuffer } , matPropsBuffer { rhs.matPropsBuffer }
, matPropsDescSet { rhs.matPropsDescSet } , instanceDataDescSet { rhs.instanceDataDescSet }
{ {
rhs.drawDataBuffer = {}; rhs.drawDataBuffer = {};
rhs.transformDataBuffer = {}; rhs.transformDataBuffer = {};
rhs.instancedIntegerBuffer = {}; rhs.instancedIntegerBuffer = {};
rhs.matPropsBuffer = {}; rhs.matPropsBuffer = {};
rhs.matPropsDescSet = {}; rhs.instanceDataDescSet = {};
} }
SHBatch& SHBatch::operator=(SHBatch&& rhs) SHBatch& SHBatch::operator=(SHBatch&& rhs)
@ -97,14 +97,14 @@ namespace SHADE
transformDataBuffer = rhs.transformDataBuffer ; transformDataBuffer = rhs.transformDataBuffer ;
instancedIntegerBuffer = rhs.instancedIntegerBuffer ; instancedIntegerBuffer = rhs.instancedIntegerBuffer ;
matPropsBuffer = rhs.matPropsBuffer ; matPropsBuffer = rhs.matPropsBuffer ;
matPropsDescSet = rhs.matPropsDescSet ; instanceDataDescSet = rhs.instanceDataDescSet ;
// Unset values // Unset values
rhs.drawDataBuffer = {}; rhs.drawDataBuffer = {};
rhs.transformDataBuffer = {}; rhs.transformDataBuffer = {};
rhs.instancedIntegerBuffer = {}; rhs.instancedIntegerBuffer = {};
rhs.matPropsBuffer = {}; rhs.matPropsBuffer = {};
rhs.matPropsDescSet = {}; rhs.instanceDataDescSet = {};
return *this; return *this;
} }
@ -122,8 +122,8 @@ namespace SHADE
instancedIntegerBuffer[i].Free(); instancedIntegerBuffer[i].Free();
if (matPropsBuffer[i]) if (matPropsBuffer[i])
matPropsBuffer[i].Free(); matPropsBuffer[i].Free();
if (matPropsDescSet[i]) if (instanceDataDescSet[i])
matPropsDescSet[i].Free(); instanceDataDescSet[i].Free();
} }
} }
@ -289,7 +289,7 @@ namespace SHADE
} }
// Transfer to GPU // Transfer to GPU
rebuildMaterialBuffers(frameIndex, descPool); rebuildDescriptorSetBuffers(frameIndex, descPool);
// This frame is updated // This frame is updated
matBufferDirty[frameIndex] = false; matBufferDirty[frameIndex] = false;
@ -421,7 +421,7 @@ namespace SHADE
const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface const Handle<SHShaderBlockInterface> SHADER_INFO = pipeline->GetPipelineLayout()->GetShaderBlockInterface
( (
descMappings.at(SHPredefinedDescriptorTypes::MATERIALS), descMappings.at(SHPredefinedDescriptorTypes::MATERIALS),
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
vk::ShaderStageFlagBits::eFragment vk::ShaderStageFlagBits::eFragment
); );
const bool EMPTY_MAT_PROPS = !SHADER_INFO; const bool EMPTY_MAT_PROPS = !SHADER_INFO;
@ -557,10 +557,8 @@ namespace SHADE
BuffUsage::eVertexBuffer, BuffUsage::eVertexBuffer,
"Batch Instance Data Buffer" "Batch Instance Data Buffer"
); );
// - Material Properties Buffer // - Material and bone buffers/descriptor sets
rebuildMaterialBuffers(frameIndex, descPool); rebuildDescriptorSetBuffers(frameIndex, descPool);
// - Bone Buffers
rebuildBoneBuffers(frameIndex, descPool);
} }
// Mark this frame as no longer dirty // Mark this frame as no longer dirty
@ -588,15 +586,14 @@ namespace SHADE
cmdBuffer->BindPipeline(pipeline); cmdBuffer->BindPipeline(pipeline);
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::TRANSFORM, transformDataBuffer[frameIndex], 0);
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::INTEGER_DATA, instancedIntegerBuffer[frameIndex], 0);
if (matPropsDescSet[frameIndex])
{
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
auto const& descMappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
if (instanceDataDescSet[frameIndex])
{
cmdBuffer->BindDescriptorSet cmdBuffer->BindDescriptorSet
( (
matPropsDescSet[frameIndex], instanceDataDescSet[frameIndex],
SH_PIPELINE_TYPE::GRAPHICS, SH_PIPELINE_TYPE::GRAPHICS,
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
descMappings.at(SHPredefinedDescriptorTypes::MATERIALS), descMappings.at(SHPredefinedDescriptorTypes::MATERIALS),
dynamicOffset dynamicOffset
); );
@ -604,13 +601,6 @@ namespace SHADE
if (boneMatrixBuffer[frameIndex] && boneFirstIndexBuffer[frameIndex]) if (boneMatrixBuffer[frameIndex] && boneFirstIndexBuffer[frameIndex])
{ {
cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::BONE_INDICES, boneFirstIndexBuffer[frameIndex], 0); cmdBuffer->BindVertexBuffer(SHGraphicsConstants::VertexBufferBindings::BONE_INDICES, boneFirstIndexBuffer[frameIndex], 0);
cmdBuffer->BindDescriptorSet
(
boneMatricesDescSet[frameIndex],
SH_PIPELINE_TYPE::GRAPHICS,
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
dynamicOffset
);
} }
cmdBuffer->DrawMultiIndirect(drawDataBuffer[frameIndex], static_cast<uint32_t>(drawData.size())); cmdBuffer->DrawMultiIndirect(drawDataBuffer[frameIndex], static_cast<uint32_t>(drawData.size()));
cmdBuffer->EndLabeledSegment(); cmdBuffer->EndLabeledSegment();
@ -651,107 +641,109 @@ namespace SHADE
isCPUBuffersDirty = true; isCPUBuffersDirty = true;
} }
void SHBatch::rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) void SHBatch::rebuildDescriptorSetBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
{ {
if (matPropsData && !drawData.empty()) // Using Declarations and constants
{ using BuffUsage = vk::BufferUsageFlagBits;
SHVkUtil::EnsureBufferAndCopyHostVisibleData using PreDefDescLayoutType = SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes;
( static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0;
device, matPropsBuffer[frameIndex], matPropsData.get(), static_cast<uint32_t>(matPropsDataSize),
vk::BufferUsageFlagBits::eStorageBuffer,
"Batch Material Data"
);
if (!matPropsDescSet[frameIndex]) // Flags
bool descSetUpdateRequired = false;
/* Create Descriptor Sets if Needed */
PreDefDescLayoutType layoutTypes = {};
if (matPropsData)
layoutTypes |= PreDefDescLayoutType::MATERIALS;
if (!boneMatrixData.empty())
layoutTypes |= PreDefDescLayoutType::BONES;
if (matPropsData || !boneMatrixData.empty())
{
// Make sure that we have a descriptor set if we don't already have one
if (!instanceDataDescSet[frameIndex])
{ {
matPropsDescSet[frameIndex] = descPool->Allocate instanceDataDescSet[frameIndex] = descPool->Allocate
( (
SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::MATERIALS), SHGraphicsPredefinedData::GetPredefinedDescSetLayouts(layoutTypes),
{ 0 } { 0 }
); );
#ifdef _DEBUG #ifdef _DEBUG
const auto& DESC_SETS = matPropsDescSet[frameIndex]->GetVkHandle(); const auto& DESC_SETS = instanceDataDescSet[frameIndex]->GetVkHandle();
for (auto descSet : DESC_SETS) for (auto descSet : DESC_SETS)
{ {
SET_VK_OBJ_NAME(device, vk::ObjectType::eDescriptorSet, descSet, "[Descriptor Set] Batch Material Data"); SET_VK_OBJ_NAME(device, vk::ObjectType::eDescriptorSet, descSet, "[Descriptor Set] Batch Material Data");
} }
#endif #endif
} }
}
static constexpr uint32_t MATERIAL_DESC_SET_INDEX = 0; /* Material Data */
if (matPropsData && !drawData.empty())
{
// Update GPU buffer
SHVkUtil::EnsureBufferAndCopyHostVisibleData
(
device, matPropsBuffer[frameIndex], matPropsData.get(), static_cast<uint32_t>(matPropsDataSize),
BuffUsage::eStorageBuffer,
"Batch Material Data"
);
// Update descriptor set buffer
std::array<Handle<SHVkBuffer>, 1> bufferList = { matPropsBuffer[frameIndex] }; std::array<Handle<SHVkBuffer>, 1> bufferList = { matPropsBuffer[frameIndex] };
matPropsDescSet[frameIndex]->ModifyWriteDescBuffer instanceDataDescSet[frameIndex]->ModifyWriteDescBuffer
( (
MATERIAL_DESC_SET_INDEX, MATERIAL_DESC_SET_INDEX,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
bufferList, bufferList,
0, static_cast<uint32_t>(matPropsDataSize) 0, static_cast<uint32_t>(matPropsDataSize)
); );
matPropsDescSet[frameIndex]->UpdateDescriptorSetBuffer
descSetUpdateRequired = true;
}
/* Animation Bone Data */
if (!boneMatrixData.empty())
{
// Update GPU Buffers
const uint32_t BONE_IDX_DATA_BYTES = static_cast<uint32_t>(boneMatrixIndices.size() * sizeof(uint32_t));
SHVkUtil::EnsureBufferAndCopyHostVisibleData
(
device, boneFirstIndexBuffer[frameIndex], boneMatrixIndices.data(), BONE_IDX_DATA_BYTES,
BuffUsage::eVertexBuffer,
"Batch Bone Indices Buffer"
);
const uint32_t BONE_MTX_DATA_BYTES = static_cast<uint32_t>(boneMatrixData.size() * sizeof(uint32_t));
SHVkUtil::EnsureBufferAndCopyHostVisibleData
(
device, boneMatrixBuffer[frameIndex], boneMatrixData.data(), BONE_MTX_DATA_BYTES,
BuffUsage::eStorageBuffer,
"Batch Bone Matrix Buffer"
);
// Update descriptor set buffer
std::array<Handle<SHVkBuffer>, 1> bufferList = { boneMatrixBuffer[frameIndex] };
instanceDataDescSet[frameIndex]->ModifyWriteDescBuffer
( (
MATERIAL_DESC_SET_INDEX, MATERIAL_DESC_SET_INDEX,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA SHGraphicsConstants::DescriptorSetBindings::PER_INST_BONE_DATA,
bufferList,
static_cast<uint32_t>(matPropsDataSize),
static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix))
); );
descSetUpdateRequired = true;
} }
}
void SHBatch::rebuildBoneBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool) // Build and prepare the descriptor set if necessary
{ if (descSetUpdateRequired)
// Using Declarations {
using BuffUsage = vk::BufferUsageFlagBits; // Update the descriptor set buffer
instanceDataDescSet[frameIndex]->UpdateDescriptorSetBuffer
// Nothing to rebuild
if (boneMatrixData.empty())
return;
// Update GPU Buffers
const uint32_t BONE_IDX_DATA_BYTES = static_cast<uint32_t>(boneMatrixIndices.size() * sizeof(uint32_t));
SHVkUtil::EnsureBufferAndCopyHostVisibleData
(
device, boneFirstIndexBuffer[frameIndex], boneMatrixIndices.data(), BONE_IDX_DATA_BYTES,
BuffUsage::eVertexBuffer,
"Batch Bone Index Buffer"
);
const uint32_t BONE_MTX_DATA_BYTES = static_cast<uint32_t>(boneMatrixData.size() * sizeof(uint32_t));
SHVkUtil::EnsureBufferAndCopyHostVisibleData
(
device, boneMatrixBuffer[frameIndex], boneMatrixData.data(), BONE_MTX_DATA_BYTES,
BuffUsage::eStorageBuffer,
"Batch Bone Matrix Buffer"
);
// Update descriptor set buffer
if (!boneMatricesDescSet[frameIndex])
{
boneMatricesDescSet[frameIndex] = descPool->Allocate
( (
{ SHGraphicsGlobalData::GetDescSetLayouts()[SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE] }, MATERIAL_DESC_SET_INDEX,
{ 0 } SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA
); );
#ifdef _DEBUG
const auto& DESC_SETS = boneMatricesDescSet[frameIndex]->GetVkHandle();
for (auto descSet : DESC_SETS)
{
SET_VK_OBJ_NAME(device, vk::ObjectType::eDescriptorSet, descSet, "[Descriptor Set] Batch Bone Data");
}
#endif
} }
std::array<Handle<SHVkBuffer>, 1> bufferList = { boneMatrixBuffer[frameIndex] };
boneMatricesDescSet[frameIndex]->ModifyWriteDescBuffer
(
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA,
bufferList,
0, static_cast<uint32_t>(boneMatrixData.size() * sizeof(SHMatrix))
);
boneMatricesDescSet[frameIndex]->UpdateDescriptorSetBuffer
(
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA
);
// TODO: Need to merge this with the material one
} }
} }

View File

@ -133,15 +133,14 @@ namespace SHADE
TripleBuffer transformDataBuffer; TripleBuffer transformDataBuffer;
TripleBuffer instancedIntegerBuffer; TripleBuffer instancedIntegerBuffer;
TripleBuffer matPropsBuffer; TripleBuffer matPropsBuffer;
TripleDescSet matPropsDescSet;
TripleBuffer boneMatrixBuffer; TripleBuffer boneMatrixBuffer;
TripleBuffer boneFirstIndexBuffer; TripleBuffer boneFirstIndexBuffer;
TripleDescSet boneMatricesDescSet; TripleDescSet instanceDataDescSet;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
void setAllDirtyFlags(); void setAllDirtyFlags();
void rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool); void rebuildDescriptorSetBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
void rebuildBoneBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
}; };
} }

View File

@ -20,14 +20,21 @@ namespace SHADE
//SHGraphicsPredefinedData::PerSystem SHGraphicsPredefinedData::renderGraphNodeComputeData; //SHGraphicsPredefinedData::PerSystem SHGraphicsPredefinedData::renderGraphNodeComputeData;
void SHGraphicsPredefinedData::InitDescMappings(void) noexcept void SHGraphicsPredefinedData::InitDescMappings(void) noexcept
{ {
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descMappings.AddMappings perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descMappings.AddMappings
({ ({
{SHPredefinedDescriptorTypes::STATIC_DATA, 0}, {SHPredefinedDescriptorTypes::STATIC_DATA, 0},
{SHPredefinedDescriptorTypes::CAMERA, 1}, {SHPredefinedDescriptorTypes::CAMERA, 1},
{SHPredefinedDescriptorTypes::MATERIALS, 2}, {SHPredefinedDescriptorTypes::MATERIALS, 2},
}); });
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING_ANIM)].descMappings.AddMappings
({
{SHPredefinedDescriptorTypes::STATIC_DATA, 0},
{SHPredefinedDescriptorTypes::CAMERA, 1},
{SHPredefinedDescriptorTypes::MATERIALS, 2},
{SHPredefinedDescriptorTypes::BONES, 3},
});
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descMappings.AddMappings
({ ({
@ -48,9 +55,13 @@ namespace SHADE
void SHGraphicsPredefinedData::InitDummyPipelineLayouts(Handle<SHVkLogicalDevice> logicalDevice) noexcept void SHGraphicsPredefinedData::InitDummyPipelineLayouts(Handle<SHVkLogicalDevice> logicalDevice) noexcept
{ {
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts }); for (int i = 0; i < SYSTEM_TYPE_COUNT; ++i)
perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::TEXT_RENDERING)].descSetLayouts }); {
perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy(SHPipelineLayoutParamsDummy{ perSystemData[SHUtilities::ConvertEnum(SystemType::RENDER_GRAPH_NODE_COMPUTE)].descSetLayouts }); perSystemData[i].dummyPipelineLayout = logicalDevice->CreatePipelineLayoutDummy
(
SHPipelineLayoutParamsDummy { perSystemData[i].descSetLayouts }
);
}
} }
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
@ -122,8 +133,8 @@ namespace SHADE
SHVkDescriptorSetLayout::Binding materialDataBinding SHVkDescriptorSetLayout::Binding materialDataBinding
{ {
.Type = vk::DescriptorType::eStorageBufferDynamic, .Type = vk::DescriptorType::eStorageBufferDynamic,
.Stage = vk::ShaderStageFlagBits::eFragment | vk::ShaderStageFlagBits::eVertex, .Stage = vk::ShaderStageFlagBits::eFragment,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, .BindPoint = SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
.DescriptorCount = 1, .DescriptorCount = 1,
}; };
Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding }); Handle<SHVkDescriptorSetLayout> materialDataPerInstanceLayout = logicalDevice->CreateDescriptorSetLayout({ materialDataBinding });
@ -150,12 +161,25 @@ 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
SHVkDescriptorSetLayout::Binding boneMatrixBinding
{
.Type = vk::DescriptorType::eStorageBuffer,
.Stage = vk::ShaderStageFlagBits::eVertex,
.BindPoint = SHGraphicsConstants::DescriptorSetBindings::BONE_MATRIX_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");
predefinedLayouts.push_back(staticGlobalLayout); predefinedLayouts.push_back(staticGlobalLayout);
predefinedLayouts.push_back(lightDataDescSetLayout); predefinedLayouts.push_back(lightDataDescSetLayout);
predefinedLayouts.push_back(cameraDataGlobalLayout); predefinedLayouts.push_back(cameraDataGlobalLayout);
predefinedLayouts.push_back(materialDataPerInstanceLayout); predefinedLayouts.push_back(materialDataPerInstanceLayout);
predefinedLayouts.push_back(fontDataDescSetLayout); predefinedLayouts.push_back(fontDataDescSetLayout);
predefinedLayouts.push_back({});
predefinedLayouts.push_back(boneMatricesDescSetLayout);
perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts perSystemData[SHUtilities::ConvertEnum(SystemType::BATCHING)].descSetLayouts = GetPredefinedDescSetLayouts
( (
@ -164,6 +188,14 @@ 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::MATERIALS |
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes::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 |
@ -181,12 +213,14 @@ namespace SHADE
void SHGraphicsPredefinedData::InitDefaultVertexInputState(void) noexcept void SHGraphicsPredefinedData::InitDefaultVertexInputState(void) noexcept
{ {
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // positions at binding 0
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_2D) }); // UVs at binding 1
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Normals at binding 2 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Normals at binding 2
defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Tangents at binding 3 defaultVertexInputState.AddBinding(false, false, { SHVertexAttribute(SHAttribFormat::FLOAT_3D) }); // Tangents at binding 3
defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }); // Transform at binding 4 - 7 (4 slots) defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::MAT_4D) }); // Transform at binding 4 - 7 (4 slots)
defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8 defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_2D) }); // Instanced integer data at index 8
defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::UINT32_4D) }); // Instanced bone indices at index 9
defaultVertexInputState.AddBinding(true, true, { SHVertexAttribute(SHAttribFormat::FLOAT_4D) }); // Instanced bone weights at index 10
} }
void SHGraphicsPredefinedData::Init(Handle<SHVkLogicalDevice> logicalDevice) noexcept void SHGraphicsPredefinedData::Init(Handle<SHVkLogicalDevice> logicalDevice) noexcept
@ -232,12 +266,24 @@ namespace SHADE
return static_cast<SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes>(static_cast<uint64_t>(lhs) | static_cast<uint64_t>(rhs)); return static_cast<SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes>(static_cast<uint64_t>(lhs) | static_cast<uint64_t>(rhs));
} }
SHADE::SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator|=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept
{
lhs = lhs | rhs;
return lhs;
}
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator&(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator&(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept
{ {
return static_cast<SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes>(static_cast<uint64_t>(lhs) & static_cast<uint64_t>(rhs)); return static_cast<SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes>(static_cast<uint64_t>(lhs) & static_cast<uint64_t>(rhs));
} }
SHADE::SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator&=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept
{
lhs = lhs & rhs;
return lhs;
}
//SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetBatchingSystemData(void) noexcept //SHGraphicsPredefinedData::PerSystem const& SHGraphicsPredefinedData::GetBatchingSystemData(void) noexcept
//{ //{
// return batchingSystemData; // return batchingSystemData;

View File

@ -23,20 +23,24 @@ 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 = 0x01, STATIC_DATA = 0b0000001,
LIGHTS = 0x02, LIGHTS = 0b0000010,
CAMERA = 0x04, CAMERA = 0b0000100,
MATERIALS = 0x08, MATERIALS = 0b0001000,
FONT = 0x10, FONT = 0b0010000,
SHADOW = 0b0100000,
BONES = 0b1000000,
}; };
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
}; };
static constexpr int SYSTEM_TYPE_COUNT = static_cast<int>(SystemType::NUM_TYPES);
struct PerSystem struct PerSystem
{ {
@ -98,5 +102,7 @@ namespace SHADE
}; };
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator| (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept; SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator| (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator|=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator& (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept; SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes operator& (SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& operator&=(SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes& lhs, SHGraphicsPredefinedData::PredefinedDescSetLayoutTypes rhs) noexcept;
} }

View File

@ -12,6 +12,7 @@ namespace SHADE
LIGHTS, LIGHTS,
CAMERA, CAMERA,
MATERIALS, MATERIALS,
BONES,
FONT, FONT,
RENDER_GRAPH_RESOURCE, RENDER_GRAPH_RESOURCE,
RENDER_GRAPH_NODE_COMPUTE_RESOURCE, RENDER_GRAPH_NODE_COMPUTE_RESOURCE,

View File

@ -138,7 +138,15 @@ namespace SHADE
DescriptorSet binding for per instance material values. DescriptorSet binding for per instance material values.
*/ */
/***************************************************************************/ /***************************************************************************/
static constexpr uint32_t BATCHED_PER_INST_DATA = 0; static constexpr uint32_t PER_INST_MATERIAL_DATA = 0;
/***************************************************************************/
/*!
\brief
DescriptorSet binding for per instance bone values.
*/
/***************************************************************************/
static constexpr uint32_t PER_INST_BONE_DATA = 1;
/***************************************************************************/ /***************************************************************************/
/*! /*!
@ -158,6 +166,14 @@ namespace SHADE
/***************************************************************************/ /***************************************************************************/
static constexpr uint32_t FONT_MATRIX_DATA = 1; static constexpr uint32_t FONT_MATRIX_DATA = 1;
/***************************************************************************/
/*!
\brief
Descriptor set binding for bone matrix data.
*/
/***************************************************************************/
static constexpr uint32_t BONE_MATRIX_DATA = 0;
}; };
struct VertexBufferBindings struct VertexBufferBindings

View File

@ -102,7 +102,7 @@ namespace SHADE
( (
mappings.at (SHPredefinedDescriptorTypes::MATERIALS), mappings.at (SHPredefinedDescriptorTypes::MATERIALS),
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
vk::ShaderStageFlagBits::eFragment vk::ShaderStageFlagBits::eFragment
); );
} }

View File

@ -83,7 +83,7 @@ namespace SHADE
( (
SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING).at(SHPredefinedDescriptorTypes::MATERIALS),
//SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE, //SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA, SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA,
vk::ShaderStageFlagBits::eFragment vk::ShaderStageFlagBits::eFragment
); );
} }

View File

@ -325,7 +325,7 @@ namespace SHADE
{ {
auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(spec.fragShader); auto fragShader = SHResourceManager::LoadOrGet<SHVkShaderModule>(spec.fragShader);
auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING); auto const& mappings = SHGraphicsPredefinedData::GetMappings(SHGraphicsPredefinedData::SystemType::BATCHING);
auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::BATCHED_PER_INST_DATA); auto interface = fragShader->GetReflectedData().GetDescriptorBindingInfo().GetShaderBlockInterface(mappings.at(SHPredefinedDescriptorTypes::MATERIALS), SHGraphicsConstants::DescriptorSetBindings::PER_INST_MATERIAL_DATA);
int const varCount = static_cast<int>(interface->GetVariableCount()); int const varCount = static_cast<int>(interface->GetVariableCount());
for (int i = 0; i < varCount; ++i) for (int i = 0; i < varCount; ++i)