fix(gta-core-five): render to temp RTV then CopyResource to shared to eliminate flicker #3619
+218
−158
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Goal of this PR
Eliminate intermittent checkerboard flickering while using the gamerender texture in NUI WebGL caused by direct writes to the shared backbuffer texture. The use of the texture is required if resource creators what to use css rules like backdrop filters or use WebGL shaders.
Example of such resources:
Example of usage in JS/React (remains unchanged after this PR) can be found in the fivem-glsl.
Mentions of this issue:
(If preview of the issues is necessary I shall deliver it upon request)
How is this PR achieving the goal
The rendering path is adjusted so that the backbuffer SRV is first drawn into a private non-shared render target (RTV).
Afterwards, the full frame is GPU-copied (
CopyResource) into the shared texture consumed by the overlay/presenter.This avoids synchronization hazards and guarantees integrity of the shared texture content without visible flickering.
Root-cause hypothesis
Concurrent use of the shared texture. The old path rendered directly into the DXGI-shared texture that the overlay/presenter samples from. With no keyed mutex or explicit cross-queue fence between producer and consumer, the driver was free to schedule work in an order that exposed partially written frames.
Driver tiling/fast-clear & partial writes. On some GPUs/drivers, RT writes are tiled and may interact with fast-clears/compression. Under contention, the consumer could read tiles/columns that weren’t written yet (observed as “missing columns” / checkerboard).
Implicit state transitions aren’t a sync guarantee. D3D11’s implicit RT<->SRV transitions don’t serialize cross-context/cross-proce* access. The shared-handle resource lacked a keyed mutex; the consumer could legally sample while the producer was still drawing.
Performance impact
Negligible GPU overhead: Adds a single full-frame blit into a private RTV and one CopyResource per frame. From my research these are highly optimized GPU operations and do not involve CPU stalls.
Minimal VRAM usage: Allocates one extra render target the size of the backbuffer. This is temporary and matches existing texture allocations, so memory footprint increase is negligible on modern GPUs.
No observable FPS drop: No FPS drop in comparison with the current Canary build of the FiveM client.
Sidenote: This is truly just my hypothesis.
Sidenote 2: Also removed warnings inside the file dating years back.
This PR applies to the following area(s)
Successfully tested on
Game builds: 3258, 1604
Platforms: Windows
Checklist
Edit: The PR message was edited by AI to improve its style and fix typos but the code in majority is my human work.