Skip to content

Shaders: a program that stores reads title memory through the UAVs it writes; glc accesses are coherent - #3584

Open
lhnizdo wants to merge 1 commit into
Marvisak:mainfrom
lhnizdo:shader/title-loads-see-writes
Open

lhnizdo wants to merge 1 commit into
Marvisak:mainfrom
lhnizdo:shader/title-loads-see-writes

Conversation

@lhnizdo

@lhnizdo lhnizdo commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Title memory was read through each page's raw SRV and written through its UAV. A read through the SRV doesn't have to see this dispatch's writes. On an RTX 2080, a load after the program's own store to the same address returned the value from before the dispatch. On the console, a program reads the same memory it writes, and a glc access passes the compute unit's cache, so it sees what this wave and other groups stored.

  • Reads: a program with vector-memory stores or atomics (Lower::writes_memory) also reads title memory through the page's UAV. Read-only programs still read through the SRV.
  • Coherence: a glc access (SMEM, MUBUF or FLAT) gets a globally coherent handle.

lower.rs grows by 1,114 bytes, to 521,677.

Where it showed

GTA VI's console BVH builder (XboxBvhBuilder.dll), on an RTX 2080. Its treelet-optimization pass, ffd93c8a, works like this:

  • each lane climbs from a leaf, merging boxes on the way up;
  • an atomic counter per node lets only the second lane to arrive go on;
  • the wave then rebuilds each treelet from those boxes, which it reads back with glc.

The boxes came back as they were before the dispatch, mostly zero. So treelet formation stopped after its first step, and nodes rewired by other groups were also read stale. The trees came out broken: in one 23,011-leaf tree, about 2,300 children no longer pointed back to their parents and 150 nodes formed cycles. The refit after it then never reached the root, and the device was removed.

Measured

A captured dispatch of ffd93c8a, with the exact inputs the game gave it, replayed on the 2080. The input tree is valid every time.

translation after the dispatch
before broken: 2,241–2,397 children not pointing back, 164–282 nodes not reaching the root (7 runs)
reads through the UAV only 228 children not pointing back
this PR (UAV reads + coherent glc) valid, 0 broken links (2 of 2 runs)

A lockstep wave32 reference interpreter of the program (a CPU model of the console's wave) agrees: with one group, the GPU's output is byte-identical to the interpreter's with this change, and differs without it.

Other things I ruled out on the same capture first. With SRV reads kept, none of these helped:

  • a device fence before every memory instruction;
  • a fence before every LDS instruction;
  • a group sync after the climb;
  • removing the loop limit.

In the game (RTX 2080, Windows 10, my dump, on my stack with #2920): the BVH builder now runs with ffd93c8a in and the refit on, with no caps and no builder program dropped. It ran for 6 minutes without a device loss: all 53 builder programs run, about 5,200 draws a frame, 23,002 instances and 57,253 BVH nodes at the stop. Before this change the device was lost in the builder's first frame unless ffd93c8a was dropped. The scene's remaining artefacts (a green cast, blocky patches at the bottom) were there with ffd93c8a dropped too.

Test

memory_tests::a_program_reads_back_what_it_stored_to_title_memory:

  • 64 threads each load a dword, store it plus 1, load it again with glc, and store what they read.
  • On the RTX 2080, before this change, every thread read the old value (7, 4103, … instead of 8, 4104, …). With it, all of them read their own store.
  • The coherence part (other groups' writes) has no synthetic test. Its evidence is the replay above.

Whole victory-shader --lib --features host suite: 299 passed, 4 failed, the same 4 as main on this card. cargo clippy -p victory-shader --all-targets --all-features -- -D warnings is clean.

AI-assisted (Claude Code). Synthetic tests only, no game data in the tree.

🤖 Generated with Claude Code

https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G

… writes; glc accesses are coherent

Title memory was read through each page's raw SRV and written through its
UAV. A read through the SRV need not see this dispatch's writes: on an
RTX 2080 a load after the program's own store to the same address gave
the value from before the dispatch. The console reads the same memory it
writes, and a `glc` access passes the compute unit's cache, so it sees
stores of this wave and of other groups.

- A program with vector-memory stores or atomics (`Lower::writes_memory`)
  reads title memory through the page's UAV too.
- A `glc` access (SMEM, MUBUF, FLAT) gets a globally coherent handle.
- Read-only programs still read through the SRV.

Found in GTA VI's console BVH builder: its treelet pass (`ffd93c8a`) reads,
with `glc`, the boxes its own refit has just written. It read them as
they were before the dispatch, so treelet formation stopped early, and
other groups' rewired nodes were read stale too. The trees came out
broken: about 2,300 children not pointing back to their parents in a
23,011-leaf tree. The refit after it then never reached the root, and the
device was removed.

On a captured dispatch of that program, replayed on the RTX 2080, the
trees come out valid with both changes (0 broken links). With UAV reads
alone, 228 links are broken. A lockstep wave32 reference interpreter of
the program gives the same bytes as the GPU for one group.

Test: `memory_tests::a_program_reads_back_what_it_stored_to_title_memory`.
64 threads each load a dword, store it plus 1, load it again with `glc`
and store what they read. On the RTX 2080 every thread read the old value
before this change, and reads its own store with it. The whole
`victory-shader --lib --features host` suite: 299 passed, 4 failed (the
same 4 as `main` on this card). Clippy is clean.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
@pickles976

Copy link
Copy Markdown

Matched Wine/NVIDIA verification: the synthetic store/readback fixture passes on both production head 0c1e615 and parent 63bcca4. This does not reproduce the reported native-Windows RTX 2080 stale-read result on this stack.

Linux 6.17, i7-13620H/16 GiB, RTX 4060 Laptop 8 GiB/NVIDIA 590.48.1, Wine 11.0, diagnostic-relaxed-vtable vkd3d-proton 2576c0b4adfae4a+ (not stock certification), DXVK NVIDIA masking disabled. Both worktrees carry the identical test-only strengthened fixture; production unchanged. SDK DXIL validator, non-software physical NVIDIA adapter and dedicated VRAM are mandatory, without WARP fallback or silent skips.

Command on each source: cargo-victory-wine.sh test -p victory-shader --features host --lib a_program_reads_back_what_it_stored_to_title_memory -- --nocapture --test-threads=1. Fresh intended-worktree Compiling lines: parent 5.93 s, head 5.81 s. Parent 1/1 pass in 0.77 s; head 1/1 pass in 0.76 s; zero ignored. Each executes the owner's original 64-thread, one-group instruction sequence and compares every word of both returned UAVs: 512 memory words and 256 write-mark words, 768 total, zero mismatches including untouched sentinels.

Local evidence directories under .compat-runtime/logs/:

  • verify-verify-victory3584-parent-coherence-20261127T192759Z/
  • verify-verify-victory3584-head-coherence-20261127T192806Z/
    Each retains console.log, result.json, command and resource samples. Sampled GPU peak <=164 MiB, available RAM >=11230 MiB, disk >=12.144 GiB; unchanged safety limits.

This single-group fixture does not establish cross-group glc ordering, the captured treelet program's integrity, or gameplay. No original BVH dispatched or title launched. A small publishable, non-spinning multi-wave/tree-integrity regression that distinguishes this parent on Wine would be the most useful next gate; retaining the same source-container identity and translation mode would help compare it with our local title corpus. The independent scalar/lane-loop backend promotion block remains separate.

@kilolimaVI

Copy link
Copy Markdown

Hardware run, head 0c1e615: Windows 11, Radeon 780M (RDNA3 iGPU), toolchain 1.98.1.

  • a_program_reads_back_what_it_stored_to_title_memory: passes, 0/5 failures over 5 runs.
  • cargo test -p victory-shader on the 780M: 303 passed, 0 failed.

AI-assisted (Claude).

@kilolimaVI

Copy link
Copy Markdown

Before/after on the same 780M: with this PR's test file on main 63bcca4, a_program_reads_back_what_it_stored_to_title_memory fails on hardware: every dword read back is one less than stored ([7, 4103, 8199, ...], want [8, 4104, 8200, ...]); with the PR it passes (0/5 failures above).

AI-assisted (Claude).

@JurajSimicevic

Copy link
Copy Markdown

Native Windows, RTX 5080 (Blackwell, driver 617.42): the test fails without the change and passes with it, also on a large stack.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants