Animation WIP merge #321
|
@ -37,40 +37,50 @@ namespace SHADE
|
|||
/* SHBatch - Constructors/Destructors */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
SHBatch::SHBatch(Handle<SHVkPipeline> pipeline)
|
||||
: pipeline{ pipeline }
|
||||
: pipeline{ pipeline }
|
||||
{
|
||||
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 }
|
||||
, pipeline { rhs.pipeline }
|
||||
, referencedMatInstances { std::move(rhs.referencedMatInstances) }
|
||||
, matBufferDirty { std::move(rhs.matBufferDirty) }
|
||||
, subBatches { std::move(rhs.subBatches) }
|
||||
, isDirty { std::move(rhs.isDirty) }
|
||||
, drawData { std::move(rhs.drawData) }
|
||||
, transformData { std::move(rhs.transformData) }
|
||||
, instancedIntegerData { std::move(rhs.instancedIntegerData) }
|
||||
, matPropsData { std::move(rhs.matPropsData) }
|
||||
, matPropsDataSize { rhs.matPropsDataSize }
|
||||
, singleMatPropAlignedSize { rhs.singleMatPropAlignedSize }
|
||||
, singleMatPropSize { rhs.singleMatPropSize }
|
||||
, isCPUBuffersDirty { rhs.isCPUBuffersDirty }
|
||||
, drawDataBuffer { rhs.drawDataBuffer }
|
||||
, transformDataBuffer { rhs.transformDataBuffer }
|
||||
, instancedIntegerBuffer { rhs.instancedIntegerBuffer }
|
||||
, matPropsBuffer { rhs.matPropsBuffer }
|
||||
, instanceDataDescSet { rhs.instanceDataDescSet }
|
||||
: device { rhs.device }
|
||||
, isAnimated { rhs.isAnimated }
|
||||
, pipeline { rhs.pipeline }
|
||||
, referencedMatInstances { std::move(rhs.referencedMatInstances) }
|
||||
, matBufferDirty { std::move(rhs.matBufferDirty) }
|
||||
, subBatches { std::move(rhs.subBatches) }
|
||||
, isDirty { std::move(rhs.isDirty) }
|
||||
, drawData { std::move(rhs.drawData) }
|
||||
, transformData { std::move(rhs.transformData) }
|
||||
, instancedIntegerData { std::move(rhs.instancedIntegerData) }
|
||||
, matPropsData { std::move(rhs.matPropsData) }
|
||||
, 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.drawDataBuffer = {};
|
||||
rhs.transformDataBuffer = {};
|
||||
rhs.instancedIntegerBuffer = {};
|
||||
rhs.matPropsBuffer = {};
|
||||
rhs.boneMatrixBuffer = {};
|
||||
rhs.boneMatrixFirstIndexBuffer = {};
|
||||
rhs.instanceDataDescSet = {};
|
||||
}
|
||||
|
||||
|
@ -79,31 +89,38 @@ namespace SHADE
|
|||
if (this == &rhs)
|
||||
return *this;
|
||||
|
||||
device = rhs.device ;
|
||||
pipeline = rhs.pipeline ;
|
||||
referencedMatInstances = std::move(rhs.referencedMatInstances);
|
||||
matBufferDirty = std::move(rhs.matBufferDirty) ;
|
||||
subBatches = std::move(rhs.subBatches) ;
|
||||
isDirty = std::move(rhs.isDirty) ;
|
||||
drawData = std::move(rhs.drawData) ;
|
||||
transformData = std::move(rhs.transformData) ;
|
||||
instancedIntegerData = std::move(rhs.instancedIntegerData) ;
|
||||
matPropsData = std::move(rhs.matPropsData) ;
|
||||
matPropsDataSize = rhs.matPropsDataSize ;
|
||||
singleMatPropAlignedSize = rhs.singleMatPropAlignedSize ;
|
||||
singleMatPropSize = rhs.singleMatPropSize ;
|
||||
isCPUBuffersDirty = rhs.isCPUBuffersDirty ;
|
||||
drawDataBuffer = rhs.drawDataBuffer ;
|
||||
transformDataBuffer = rhs.transformDataBuffer ;
|
||||
instancedIntegerBuffer = rhs.instancedIntegerBuffer ;
|
||||
matPropsBuffer = rhs.matPropsBuffer ;
|
||||
instanceDataDescSet = rhs.instanceDataDescSet ;
|
||||
device = rhs.device ;
|
||||
isAnimated = rhs.isAnimated ;
|
||||
pipeline = rhs.pipeline ;
|
||||
referencedMatInstances = std::move(rhs.referencedMatInstances);
|
||||
matBufferDirty = std::move(rhs.matBufferDirty) ;
|
||||
subBatches = std::move(rhs.subBatches) ;
|
||||
isDirty = std::move(rhs.isDirty) ;
|
||||
drawData = std::move(rhs.drawData) ;
|
||||
transformData = std::move(rhs.transformData) ;
|
||||
instancedIntegerData = std::move(rhs.instancedIntegerData) ;
|
||||
matPropsData = std::move(rhs.matPropsData) ;
|
||||
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
|
||||
rhs.drawDataBuffer = {};
|
||||
rhs.transformDataBuffer = {};
|
||||
rhs.instancedIntegerBuffer = {};
|
||||
rhs.matPropsBuffer = {};
|
||||
rhs.drawDataBuffer = {};
|
||||
rhs.transformDataBuffer = {};
|
||||
rhs.instancedIntegerBuffer = {};
|
||||
rhs.matPropsBuffer = {};
|
||||
rhs.boneMatrixBuffer = {};
|
||||
rhs.boneMatrixFirstIndexBuffer = {};
|
||||
rhs.instanceDataDescSet = {};
|
||||
|
||||
return *this;
|
||||
|
@ -363,21 +380,19 @@ namespace SHADE
|
|||
|
||||
// Populate on the CPU
|
||||
for (auto& subBatch : subBatches)
|
||||
for (auto rendId : subBatch.Renderables)
|
||||
for (auto rendId : subBatch.Renderables)
|
||||
{
|
||||
auto* renderable = SHComponentManager::GetComponent<SHRenderable>(rendId);
|
||||
instancedIntegerData.emplace_back(SHInstancedIntegerData
|
||||
{
|
||||
auto* renderable = SHComponentManager::GetComponent<SHRenderable>(rendId);
|
||||
instancedIntegerData.emplace_back(SHInstancedIntegerData
|
||||
{
|
||||
rendId,
|
||||
renderable->GetLightLayer()
|
||||
}
|
||||
);
|
||||
}
|
||||
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)
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue