tombox-xshader: declare UAVs accessed with GLC or DLC globallycoherent #199
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
library
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/omonkeyz--xbox-emulator!199
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/199/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@GDAgent on GitHub · 2026-11-23 00:55 UTC · original
GDAgent:fix/xshader-glc-coherent→main· +87 −3 · 3 files · 1 commits · closed without mergingLibrary / area:
tombox-xshader(hlsl.rsUAV declarations,tests/exec_mem/ds.rs,tests/exec_mem/mimg.rs)Exports changed (exports.txt rows): none
Source of the behaviour: RDNA2 ISA: buffer and image accesses with GLC or DLC set bypass the per-CU (L0/L1) caches, so a wave sees data written by waves of other thread groups. D3D12/HLSL: a UAV is only coherent across thread groups when declared
globallycoherent.Persistent-thread kernels depend on this: a work-queue consumer polls node data that another group publishes and loops until it appears. The translation dropped both bits and declared every UAV as a plain
RWStructuredBuffer/RWBuffer/RWTexture*, which D3D12 only makes coherent within a thread group, so a consumer could keep reading a stale value and never leave its loop.Changes:
globallycoherentwhen the same shader both reads it with a GLC/DLC load (MUBUF/MTBUF GLC bit 14 or DLC bit 15, MIMG GLC bit 13 or DLC bit 7) and writes it (any store or atomic). In that case, groups of one dispatch talk to each other through the resource. Data written by an earlier dispatch is already made visible by the UAV barrier between dispatches, so a read-only GLC load keeps a plain declaration.Effect on one title's shader archive (35382 translated shaders, HLSL compared with
main): 45 compute shaders getgloballycoherentdeclarations (119 in total), including the persistent culling kernel below with the same 3 coherent UAVs as before. Marking every GLC/DLC-accessed UAV, as the first version of this PR did, gave 153 shaders (48 of them pixel shaders) 269 declarations. The other 35337 shaders translate byte-identically tomain.Tests:
exec_mem::ds::glc_and_dlc_buffer_accesses_are_globally_coherent: plain, GLC, DLC and GLC+DLC loads of a buffer the shader also stores to; a GLC atomic that must not mark the UAV; a GLC load of a buffer that is never written (stays plain); a GLC load plus an atomic on the same buffer (every view of it marked).exec_mem::mimg::image_glc_and_dlc_accesses_are_globally_coherent: plain, GLC and DLC image loads followed by animage_store, and a GLC load without a store (stays plain).cargo test -p tombox-xshader --no-fail-faston currentmain(d8d37e4): 346 passed, 0 failed (WARP).Not verified in a title: this came from a GPU hang (
DXGI_ERROR_DEVICE_HUNG) in The Matrix Awakens inside a persistent culling kernel whose loads carry GLC and DLC. The translated kernel now declares those UAVsgloballycoherentand compiles, but it is not shown that this alone ends the hang: the runs since then used a loop guard, and the same kernel also needs its 64 lanes in one wave (separate PR). No measurement of the cost ofgloballycoherentin a title.cargo test -p tombox-xshaderpassesmissingwith a note@omonkeyz on GitHub · 2026-11-23 01:10 UTC · original
Thanks, the change looks correct, and it passes the gate here. It's on hold for now, not rejected. Declaring these UAVs globallycoherent can cost GPU time, and Trackmania is in the middle of a performance bisect. It will merge after that, with its own A/B run. Is a cheaper rule possible? For example, mark a UAV only when it is both written and read with GLC/DLC in the same shader, or only when the GLC/DLC load sits inside a loop that polls. If you can narrow it, please push it to this branch with a test that covers the case that stays coherent.
@GDAgent on GitHub · 2026-11-23 10:01 UTC · original
Rebased on
d8d37e4, narrowed, and pushed ase930f7c. I went with your first option, slightly widened so it stays correct:A UAV is now
globallycoherentonly when the same shader reads it with a GLC/DLC load and also writes it (any store or atomic). That is the case where groups of one dispatch talk to each other through the resource. Data written by an earlier dispatch is already made visible by the UAV barrier between dispatches, so a read-only GLC load keeps a plain declaration. I count atomics as writes, because a producer can publish through an atomic rather than a GLC store. GLC on the atomic itself still doesn't mark anything.I measured it on one title's shader archive (35382 translated shaders), comparing the HLSL with
main:globallycoherentdeclarations (119 in total).main.The tests now pin the cases that stay coherent and the ones that don't:
image_storeis marked. A plain load with a store is not, and a GLC load without a store is not.cargo test -p tombox-xshaderpasses: 346 passed, 0 failed. I didn't do the polling-loop variant: the written-and-read rule is easier to test, and on this archive it already leaves only the compute shaders that both publish and read the same resource. There's no title A/B from me.@omonkeyz on GitHub · 2026-11-23 14:08 UTC · original
Applied locally on main with your authorship kept (cherry-picked,
e543de8); the tombox-xshader suite passes in a sandbox (exec 155/155 on WARP). It ships in the next release; this PR will be closed when that is pushed. Thanks.@kiwe147 on GitHub · 2026-11-23 18:57 UTC · original
Tested head
e930f7c3c6, applied withgit apply(whitespace ignored, the line endings of my checkout differ) onmainf89e410, together with #229, #232 (one tree; the PRs touch different files). It applied without conflicts and built.Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, NVIDIA GeForce RTX 3080 (driver 621.24), MSVC, Rust 1.91.1.
tombox-xshaderlib +opcodes,synthetic,mesh,linkage,mixed_table,ps_linkage,centroid,gcn_dims,amp,xshader_cli,isa_sweepexecsuite on WARPTOMBOX_EXEC_HW=1(RTX 3080)No new failure against
mainf89e410in any of these. This is one combined tree, not a run of this PR alone.AI-assisted: yes (Claude Code)
@omonkeyz on GitHub · 2026-11-25 13:09 UTC · original
Applied on main in
e543de8(cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.Pull request closed