Add async particles drawing (GPU emitters are sync)

This commit is contained in:
Wojtek Figat
2025-08-05 22:53:09 +02:00
parent baf0cfce8e
commit b1710c4d01
5 changed files with 53 additions and 2 deletions

View File

@@ -649,8 +649,22 @@ void CleanupGPUParticlesSorting()
GPUParticlesSorting = nullptr;
}
void DrawEmitterGPU(RenderContext& renderContext, ParticleBuffer* buffer, DrawCall& drawCall, DrawPass drawModes, StaticFlags staticFlags, ParticleEmitterInstance& emitterData, const RenderModulesIndices& renderModulesIndices, int8 sortOrder)
void DrawEmitterGPU(RenderContext& renderContext, ParticleBuffer* buffer, DrawCall& drawCall, DrawPass drawModes, StaticFlags staticFlags, const RenderModulesIndices& renderModulesIndices, int8 sortOrder)
{
if (!IsInMainThread())
{
// Clone draw call data the hard way
byte drawCallCopy[sizeof(DrawCall)];
Platform::MemoryCopy(&drawCallCopy, &drawCall, sizeof(DrawCall));
// When rendering in async, delay GPU particles drawing to be in sync by moving drawing into delayed callback post scene drawing to use GPUContext safely
// Move drawing into delayed callback post scene drawing to use GPUContext safely
renderContext.List->AddDelayedDraw([buffer, drawCallCopy, drawModes, staticFlags, renderModulesIndices, sortOrder](RenderContext& renderContext)
{
DrawEmitterGPU(renderContext, buffer, *(DrawCall*)drawCallCopy, drawModes, staticFlags, renderModulesIndices, sortOrder);
});
return;
}
const auto context = GPUDevice::Instance->GetMainContext();
auto emitter = buffer->Emitter;
@@ -1092,7 +1106,7 @@ void Particles::DrawParticles(RenderContext& renderContext, ParticleEffect* effe
break;
#if COMPILE_WITH_GPU_PARTICLES
case ParticlesSimulationMode::GPU:
DrawEmitterGPU(renderContext, buffer, drawCall, drawModes, staticFlags, emitterData, renderModulesIndices, sortOrder);
DrawEmitterGPU(renderContext, buffer, drawCall, drawModes, staticFlags, renderModulesIndices, sortOrder);
break;
#endif
}