Merge pull request #265 from SHADE-DP/Fix-BatchCrash

Added potential fix for Vulkan buffer creation crashes from SHBatch
This commit is contained in:
XiaoQiDigipen 2022-11-23 19:33:20 +08:00 committed by GitHub
commit c32aa1e00c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 31 deletions

View File

@ -340,7 +340,7 @@ namespace SHADE
}
// Transfer to GPU
if (transformDataBuffer[frameIndex])
if (transformDataBuffer[frameIndex] && !drawData.empty())
transformDataBuffer[frameIndex]->WriteToMemory(transformData.data(), static_cast<uint32_t>(transformData.size() * sizeof(SHMatrix)), 0, 0);
}
@ -369,7 +369,7 @@ namespace SHADE
}
// Transfer to GPU
if (instancedIntegerBuffer[frameIndex])
if (instancedIntegerBuffer[frameIndex] && !drawData.empty())
instancedIntegerBuffer[frameIndex]->WriteToMemory(instancedIntegerData.data(), static_cast<uint32_t>(instancedIntegerData.size() * sizeof(SHInstancedIntegerData)), 0, 0);
}
@ -507,7 +507,9 @@ namespace SHADE
isCPUBuffersDirty = false;
}
// Send all buffered data to the GPU buffers
// Send all buffered data to the GPU buffers if there is anything to render
if (!drawData.empty())
{
using BuffUsage = vk::BufferUsageFlagBits;
// - Draw Data
const uint32_t DRAW_DATA_BYTES = static_cast<uint32_t>(drawData.size() * sizeof(vk::DrawIndexedIndirectCommand));
@ -534,6 +536,7 @@ namespace SHADE
);
// - Material Properties Buffer
rebuildMaterialBuffers(frameIndex, descPool);
}
// Mark this frame as no longer dirty
isDirty[frameIndex] = false;
@ -551,7 +554,7 @@ namespace SHADE
}
// Nothing to draw
if (subBatches.empty())
if (drawData.empty())
return;
// Bind all required objects before drawing
@ -586,7 +589,7 @@ namespace SHADE
void SHBatch::rebuildMaterialBuffers(uint32_t frameIndex, Handle<SHVkDescriptorPool> descPool)
{
if (matPropsData)
if (matPropsData && !drawData.empty())
{
SHVkUtil::EnsureBufferAndCopyHostVisibleData
(