Fixed move constructor and assignment for SHBatch and added a check for if a batch is animated

This commit is contained in:
Kah Wei 2023-01-17 21:54:53 +08:00
parent 2d898851c5
commit 20ffd67fcc
2 changed files with 77 additions and 58 deletions

View File

@ -42,12 +42,16 @@ namespace SHADE
if (!pipeline) if (!pipeline)
throw std::invalid_argument("Attempted to create a SHBatch with an invalid SHPipeline!"); throw std::invalid_argument("Attempted to create a SHBatch with an invalid SHPipeline!");
// Check the pipeline and flag it depending on whether or not it is animated
isAnimated = checkIfIsAnimatedPipeline(pipeline);
// Mark all as dirty // Mark all as dirty
setAllDirtyFlags(); setAllDirtyFlags();
} }
SHBatch::SHBatch(SHBatch&& rhs) SHBatch::SHBatch(SHBatch&& rhs)
: device { rhs.device } : device { rhs.device }
, isAnimated { rhs.isAnimated }
, pipeline { rhs.pipeline } , pipeline { rhs.pipeline }
, referencedMatInstances { std::move(rhs.referencedMatInstances) } , referencedMatInstances { std::move(rhs.referencedMatInstances) }
, matBufferDirty { std::move(rhs.matBufferDirty) } , matBufferDirty { std::move(rhs.matBufferDirty) }
@ -60,17 +64,23 @@ namespace SHADE
, matPropsDataSize { rhs.matPropsDataSize } , matPropsDataSize { rhs.matPropsDataSize }
, singleMatPropAlignedSize { rhs.singleMatPropAlignedSize } , singleMatPropAlignedSize { rhs.singleMatPropAlignedSize }
, singleMatPropSize { rhs.singleMatPropSize } , singleMatPropSize { rhs.singleMatPropSize }
, boneMatrixData { std::move(rhs.boneMatrixData) }
, boneMatrixIndices { std::move(rhs.boneMatrixIndices) }
, isCPUBuffersDirty { rhs.isCPUBuffersDirty } , isCPUBuffersDirty { rhs.isCPUBuffersDirty }
, drawDataBuffer { rhs.drawDataBuffer } , drawDataBuffer { rhs.drawDataBuffer }
, transformDataBuffer { rhs.transformDataBuffer } , transformDataBuffer { rhs.transformDataBuffer }
, instancedIntegerBuffer { rhs.instancedIntegerBuffer } , instancedIntegerBuffer { rhs.instancedIntegerBuffer }
, matPropsBuffer { rhs.matPropsBuffer } , matPropsBuffer { rhs.matPropsBuffer }
, boneMatrixBuffer { rhs.boneMatrixBuffer }
, boneMatrixFirstIndexBuffer { rhs.boneMatrixFirstIndexBuffer }
, instanceDataDescSet { rhs.instanceDataDescSet } , instanceDataDescSet { rhs.instanceDataDescSet }
{ {
rhs.drawDataBuffer = {}; rhs.drawDataBuffer = {};
rhs.transformDataBuffer = {}; rhs.transformDataBuffer = {};
rhs.instancedIntegerBuffer = {}; rhs.instancedIntegerBuffer = {};
rhs.matPropsBuffer = {}; rhs.matPropsBuffer = {};
rhs.boneMatrixBuffer = {};
rhs.boneMatrixFirstIndexBuffer = {};
rhs.instanceDataDescSet = {}; rhs.instanceDataDescSet = {};
} }
@ -80,6 +90,7 @@ namespace SHADE
return *this; return *this;
device = rhs.device ; device = rhs.device ;
isAnimated = rhs.isAnimated ;
pipeline = rhs.pipeline ; pipeline = rhs.pipeline ;
referencedMatInstances = std::move(rhs.referencedMatInstances); referencedMatInstances = std::move(rhs.referencedMatInstances);
matBufferDirty = std::move(rhs.matBufferDirty) ; matBufferDirty = std::move(rhs.matBufferDirty) ;
@ -92,11 +103,15 @@ namespace SHADE
matPropsDataSize = rhs.matPropsDataSize ; matPropsDataSize = rhs.matPropsDataSize ;
singleMatPropAlignedSize = rhs.singleMatPropAlignedSize ; singleMatPropAlignedSize = rhs.singleMatPropAlignedSize ;
singleMatPropSize = rhs.singleMatPropSize ; singleMatPropSize = rhs.singleMatPropSize ;
boneMatrixData = std::move(rhs.boneMatrixData) ;
boneMatrixIndices = std::move(rhs.boneMatrixIndices) ;
isCPUBuffersDirty = rhs.isCPUBuffersDirty ; isCPUBuffersDirty = rhs.isCPUBuffersDirty ;
drawDataBuffer = rhs.drawDataBuffer ; drawDataBuffer = rhs.drawDataBuffer ;
transformDataBuffer = rhs.transformDataBuffer ; transformDataBuffer = rhs.transformDataBuffer ;
instancedIntegerBuffer = rhs.instancedIntegerBuffer ; instancedIntegerBuffer = rhs.instancedIntegerBuffer ;
matPropsBuffer = rhs.matPropsBuffer ; matPropsBuffer = rhs.matPropsBuffer ;
boneMatrixBuffer = rhs.boneMatrixBuffer ;
boneMatrixFirstIndexBuffer = rhs.boneMatrixFirstIndexBuffer ;
instanceDataDescSet = rhs.instanceDataDescSet ; instanceDataDescSet = rhs.instanceDataDescSet ;
// Unset values // Unset values
@ -104,6 +119,8 @@ namespace SHADE
rhs.transformDataBuffer = {}; rhs.transformDataBuffer = {};
rhs.instancedIntegerBuffer = {}; rhs.instancedIntegerBuffer = {};
rhs.matPropsBuffer = {}; rhs.matPropsBuffer = {};
rhs.boneMatrixBuffer = {};
rhs.boneMatrixFirstIndexBuffer = {};
rhs.instanceDataDescSet = {}; rhs.instanceDataDescSet = {};
return *this; return *this;
@ -370,14 +387,12 @@ namespace SHADE
{ {
rendId, rendId,
renderable->GetLightLayer() renderable->GetLightLayer()
} });
);
} }
// Transfer to GPU // Transfer to GPU
if (instancedIntegerBuffer[frameIndex] && !drawData.empty()) if (instancedIntegerBuffer[frameIndex] && !drawData.empty())
instancedIntegerBuffer[frameIndex]->WriteToMemory(instancedIntegerData.data(), static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)), 0, 0); instancedIntegerBuffer[frameIndex]->WriteToMemory(instancedIntegerData.data(), static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)), 0, 0);
} }
void SHBatch::UpdateAnimationBuffer(uint32_t frameIndex) void SHBatch::UpdateAnimationBuffer(uint32_t frameIndex)

View File

@ -97,6 +97,7 @@ namespace SHADE
bool IsEmpty() const noexcept { return subBatches.empty(); } bool IsEmpty() const noexcept { return subBatches.empty(); }
Handle<SHVkBuffer> GetTransformBuffer(uint32_t frameIndex) const noexcept; Handle<SHVkBuffer> GetTransformBuffer(uint32_t frameIndex) const noexcept;
Handle<SHVkBuffer> GetMDIBuffer(uint32_t frameIndex) const noexcept; Handle<SHVkBuffer> GetMDIBuffer(uint32_t frameIndex) const noexcept;
bool IsAnimated() const noexcept { return isAnimated; }
private: private:
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -111,6 +112,8 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
// Resources // Resources
Handle<SHVkLogicalDevice> device; Handle<SHVkLogicalDevice> device;
// Config
bool isAnimated; // Whether the material supports animation
// Batch Properties // Batch Properties
Handle<SHVkPipeline> pipeline; Handle<SHVkPipeline> pipeline;
std::unordered_set<Handle<SHMaterialInstance>> referencedMatInstances; std::unordered_set<Handle<SHMaterialInstance>> referencedMatInstances;
@ -126,7 +129,7 @@ namespace SHADE
Byte matPropsDataSize = 0; Byte matPropsDataSize = 0;
Byte singleMatPropAlignedSize = 0; Byte singleMatPropAlignedSize = 0;
Byte singleMatPropSize = 0; Byte singleMatPropSize = 0;
std::vector<SHMatrix> boneMatrixData; std::vector<SHMatrix> boneMatrixData; // 0th element is always an identity matrix
std::vector<uint32_t> boneMatrixIndices; std::vector<uint32_t> boneMatrixIndices;
bool isCPUBuffersDirty = true; bool isCPUBuffersDirty = true;
// GPU Buffers // GPU Buffers
@ -143,5 +146,6 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
void setAllDirtyFlags(); void setAllDirtyFlags();
void rebuildDescriptorSetBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool); void rebuildDescriptorSetBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool);
static bool checkIfIsAnimatedPipeline(Handle<SHVkPipeline> pipeline);
}; };
} }