Light flickering in scene capture render due to RHI thread race condition

We have a scene in a pocket world with a mesh lit by a number of point and spot lights being rendered by a ASceneCapturePocketLevelActor. We are seeing an issue where all lights in the scene capture flicker off intermittently for a frame. From debugging, I can see that the lights are not being culled or excluded from rendering by the engine. InternalRenderLight is calling StencilingGeometry::DrawSphere(RHICmdList) for the correct number of lights every frame.

The flickering stops when the RHI thread is disabled (r.RHIThread.Enable 0).

The flickering also stops when I set r.GTSyncType 0. We usually have r.GTSyncType 1 to reduce lag.

The flickering still happens with:

r.RDG.ImmediateMode 1

r.rdg.debug.flushgpu 1

r.rdg.debug.extendresourcelifetimes 1

r.rdg.debug.disabletransientresources 1

r.rhi.cmdbypass 1

Vsync on or off

Only a single light in the pocket world

So I am guessing that there is a synchronisation issue between the RHI thread and the game or render thread that is causing the draw calls for the lights to get corrupted. I have tried to eliminate any dependency that the data used by the draw call might have with data that could be modified by the game or render thread, without success. I am running out of ideas for how to debug this further, so any suggestions would be appreciated.

[Attachment Removed]

Hi there,

Thank you for the information.

Based on your description, it may be worth checking whether the FSceneViewState or the view uniforms used for the Scene Capture are being reused across frames or modified after submission.

Additionally, manually performing the Scene Capture could help identify the exact cause of the flickering.

Best regards,

Henry Liu

[Attachment Removed]

Thanks for the suggestions.

As a workaround, we found that replacing CaptureComponent->CaptureScene() with CaptureComponent->CaptureSceneDeferred() in ASceneCapturePocketLevelActor.Capture() fixes the flickering.

(Though it did result in an assert in FSceneRenderer.RenderDistanceFieldAOScreenGrid but that was simple enough to deal with.)

[Attachment Removed]

Thanks for the update.

Glad you’ve found an alternative approach. Deferring scene captures rather than forcing them mid-frame, can help prevent captures from occurring at unsafe points within the frame.

I will close this case now, but feel free to respond here if you have any follow-up questions.

Cheers,

[Attachment Removed]