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)
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
setAllDirtyFlags();
}
SHBatch::SHBatch(SHBatch&& rhs)
: device { rhs.device }
, isAnimated { rhs.isAnimated }
, pipeline { rhs.pipeline }
, referencedMatInstances { std::move(rhs.referencedMatInstances) }
, matBufferDirty { std::move(rhs.matBufferDirty) }
@ -60,17 +64,23 @@ namespace SHADE
, matPropsDataSize { rhs.matPropsDataSize }
, singleMatPropAlignedSize { rhs.singleMatPropAlignedSize }
, singleMatPropSize { rhs.singleMatPropSize }
, boneMatrixData { std::move(rhs.boneMatrixData) }
, boneMatrixIndices { std::move(rhs.boneMatrixIndices) }
, isCPUBuffersDirty { rhs.isCPUBuffersDirty }
, drawDataBuffer { rhs.drawDataBuffer }
, transformDataBuffer { rhs.transformDataBuffer }
, instancedIntegerBuffer { rhs.instancedIntegerBuffer }
, matPropsBuffer { rhs.matPropsBuffer }
, boneMatrixBuffer { rhs.boneMatrixBuffer }
, boneMatrixFirstIndexBuffer { rhs.boneMatrixFirstIndexBuffer }
, instanceDataDescSet { rhs.instanceDataDescSet }
{
rhs.drawDataBuffer = {};
rhs.transformDataBuffer = {};
rhs.instancedIntegerBuffer = {};
rhs.matPropsBuffer = {};
rhs.boneMatrixBuffer = {};
rhs.boneMatrixFirstIndexBuffer = {};
rhs.instanceDataDescSet = {};
}
@ -80,6 +90,7 @@ namespace SHADE
return *this;
device = rhs.device ;
isAnimated = rhs.isAnimated ;
pipeline = rhs.pipeline ;
referencedMatInstances = std::move(rhs.referencedMatInstances);
matBufferDirty = std::move(rhs.matBufferDirty) ;
@ -92,11 +103,15 @@ namespace SHADE
matPropsDataSize = rhs.matPropsDataSize ;
singleMatPropAlignedSize = rhs.singleMatPropAlignedSize ;
singleMatPropSize = rhs.singleMatPropSize ;
boneMatrixData = std::move(rhs.boneMatrixData) ;
boneMatrixIndices = std::move(rhs.boneMatrixIndices) ;
isCPUBuffersDirty = rhs.isCPUBuffersDirty ;
drawDataBuffer = rhs.drawDataBuffer ;
transformDataBuffer = rhs.transformDataBuffer ;
instancedIntegerBuffer = rhs.instancedIntegerBuffer ;
matPropsBuffer = rhs.matPropsBuffer ;
boneMatrixBuffer = rhs.boneMatrixBuffer ;
boneMatrixFirstIndexBuffer = rhs.boneMatrixFirstIndexBuffer ;
instanceDataDescSet = rhs.instanceDataDescSet ;
// Unset values
@ -104,6 +119,8 @@ namespace SHADE
rhs.transformDataBuffer = {};
rhs.instancedIntegerBuffer = {};
rhs.matPropsBuffer = {};
rhs.boneMatrixBuffer = {};
rhs.boneMatrixFirstIndexBuffer = {};
rhs.instanceDataDescSet = {};
return *this;
@ -370,14 +387,12 @@ namespace SHADE
{
rendId,
renderable->GetLightLayer()
}
);
});
}
// Transfer to GPU
if (instancedIntegerBuffer[frameIndex] && !drawData.empty())
instancedIntegerBuffer[frameIndex]->WriteToMemory(instancedIntegerData.data(), static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)), 0, 0);
}
void SHBatch::UpdateAnimationBuffer(uint32_t frameIndex)

View File

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