Added potential fix for Vulkan buffer creation crashes from SHBatch #265

Merged
Pycorax merged 1 commits from Fix-BatchCrash into main 2022-11-23 19:33:20 +08:00
1 changed files with 34 additions and 31 deletions

View File

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