Animation WIP merge #321
|
@ -449,13 +449,13 @@ namespace SHADE
|
||||||
if (CURR_INSTANCES > 0)
|
if (CURR_INSTANCES > 0)
|
||||||
{
|
{
|
||||||
drawData.emplace_back(vk::DrawIndexedIndirectCommand
|
drawData.emplace_back(vk::DrawIndexedIndirectCommand
|
||||||
{
|
{
|
||||||
.indexCount = subBatch.Mesh->IndexCount,
|
.indexCount = subBatch.Mesh->IndexCount,
|
||||||
.instanceCount = CURR_INSTANCES,
|
.instanceCount = CURR_INSTANCES,
|
||||||
.firstIndex = subBatch.Mesh->FirstIndex,
|
.firstIndex = subBatch.Mesh->FirstIndex,
|
||||||
.vertexOffset = subBatch.Mesh->FirstVertex,
|
.vertexOffset = subBatch.Mesh->FirstVertex,
|
||||||
.firstInstance = nextInstanceIndex
|
.firstInstance = nextInstanceIndex
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
nextInstanceIndex += CURR_INSTANCES;
|
nextInstanceIndex += CURR_INSTANCES;
|
||||||
|
|
||||||
|
@ -520,7 +520,6 @@ namespace SHADE
|
||||||
const auto& BONE_MATRICES = animator->GetBoneMatrices();
|
const auto& BONE_MATRICES = animator->GetBoneMatrices();
|
||||||
boneMatrixData.insert(boneMatrixData.end(), BONE_MATRICES.cbegin(), BONE_MATRICES.cend());
|
boneMatrixData.insert(boneMatrixData.end(), BONE_MATRICES.cbegin(), BONE_MATRICES.cend());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,23 +557,7 @@ namespace SHADE
|
||||||
// - Material Properties Buffer
|
// - Material Properties Buffer
|
||||||
rebuildMaterialBuffers(frameIndex, descPool);
|
rebuildMaterialBuffers(frameIndex, descPool);
|
||||||
// - Bone Buffers
|
// - Bone Buffers
|
||||||
if (!boneMatrixIndices.empty())
|
rebuildBoneBuffers(frameIndex, descPool);
|
||||||
{
|
|
||||||
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"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark this frame as no longer dirty
|
// Mark this frame as no longer dirty
|
||||||
|
@ -605,7 +588,7 @@ namespace SHADE
|
||||||
if (matPropsDescSet[frameIndex])
|
if (matPropsDescSet[frameIndex])
|
||||||
{
|
{
|
||||||
cmdBuffer->BindDescriptorSet
|
cmdBuffer->BindDescriptorSet
|
||||||
(
|
(
|
||||||
matPropsDescSet[frameIndex],
|
matPropsDescSet[frameIndex],
|
||||||
SH_PIPELINE_TYPE::GRAPHICS,
|
SH_PIPELINE_TYPE::GRAPHICS,
|
||||||
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
SHGraphicsConstants::DescriptorSetIndex::PER_INSTANCE,
|
||||||
|
@ -615,7 +598,13 @@ 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);
|
||||||
// TODO: Bind storage buffer
|
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();
|
||||||
|
@ -673,4 +662,62 @@ namespace SHADE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SHBatch::rebuildBoneBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
|
||||||
|
{
|
||||||
|
// Using Declarations
|
||||||
|
using BuffUsage = vk::BufferUsageFlagBits;
|
||||||
|
|
||||||
|
// 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] },
|
||||||
|
{ 0 }
|
||||||
|
);
|
||||||
|
|
||||||
|
#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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,5 +141,6 @@ namespace SHADE
|
||||||
/*-----------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------*/
|
||||||
void setAllDirtyFlags();
|
void setAllDirtyFlags();
|
||||||
void rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
void rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||||
|
void rebuildBoneBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue