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 from upstream-pr/3584 into main
lhnizdo commented 2026-11-27 19:07:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-27T19:07:11Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:5531814666 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3584). Originally posted by [lhnizdo](https://github.com/lhnizdo) on 2026-11-27T19:07:11Z. --- ## 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.com/claude-code) https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
pickles976 commented 2026-11-27 19:31:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pickles976 on 2026-11-27T19:31:30Z.


Matched Wine/NVIDIA verification: the synthetic store/readback fixture passes on both production head 0c1e615ee5 and parent 63bcca43c6. 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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226612370 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7226612370). Originally posted by [pickles976](https://github.com/pickles976) on 2026-11-27T19:31:30Z. --- Matched Wine/NVIDIA verification: the synthetic store/readback fixture passes on both production head 0c1e615ee5767068518eb795878a08f27603aa95 and parent 63bcca43c6a00a758510398fa43096ce7e4f7df0. 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 commented 2026-11-27 19:37:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T19:37:35Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7226712182 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7226712182). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T19:37:35Z. --- 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 commented 2026-11-27 19:58:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kilolimaVI on 2026-11-27T19:58:35Z.


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).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7227052756 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7227052756). Originally posted by [kilolimaVI](https://github.com/kilolimaVI) on 2026-11-27T19:58:35Z. --- 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 commented 2026-11-27 20:37:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by JurajSimicevic on 2026-11-27T20:37:58Z.


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

  • On the 5080, a_program_reads_back_what_it_stored_to_title_memory without this PR's lower.rs change reads back [7, 4103, 8199, …] instead of [8, 4104, 8200, …]. That is the same failure as on the RTX 2080 and the 780M. With 0c1e615 it passes.
  • Tree: 63bcca4 + #2098, #2626, #2464, #2118, #439, #2121, #2958, #3312, then this PR. lower.rs merges cleanly. The new test only needs the Parts fields the other PRs add (target, console_cf, per_lane_only).
  • victory-shader --lib --features host, run serially on the 5080: the same two tests fail with and without this PR (a_heap_buffer_read_by_element_takes_the_views_stride and gathers_at_a_level_match_the_hardware). One more test, heap_direct_texture_reads_mark_their_heap_index, crashes the run on this tree either way, so I left it out of both runs.
  • In the world: opening prison cell, Series X profile, medians of 30 frame lines after 7 minutes. The frame is 517 ms with this PR against 530 ms without, and the GPU 145 ms against 150 ms, so there is no measurable cost. The warm-up re-made 29 of the 28,164 pipelines.
  • I saw no visible change in this scene. Two runs of the same build already differ in the yard's haze here, so one frame per build would not show it either way.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7227692384 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7227692384). Originally posted by [JurajSimicevic](https://github.com/JurajSimicevic) on 2026-11-27T20:37:58Z. --- **Native Windows, RTX 5080 (Blackwell, driver 617.42): the test fails without the change and passes with it, also on a large stack.** - On the 5080, `a_program_reads_back_what_it_stored_to_title_memory` without this PR's `lower.rs` change reads back `[7, 4103, 8199, …]` instead of `[8, 4104, 8200, …]`. That is the same failure as on the RTX 2080 and the 780M. With `0c1e615` it passes. - Tree: `63bcca4` + #2098, #2626, #2464, #2118, #439, #2121, #2958, #3312, then this PR. `lower.rs` merges cleanly. The new test only needs the `Parts` fields the other PRs add (`target`, `console_cf`, `per_lane_only`). - `victory-shader --lib --features host`, run serially on the 5080: the same two tests fail with and without this PR (`a_heap_buffer_read_by_element_takes_the_views_stride` and `gathers_at_a_level_match_the_hardware`). One more test, `heap_direct_texture_reads_mark_their_heap_index`, crashes the run on this tree either way, so I left it out of both runs. - In the world: opening prison cell, Series X profile, medians of 30 frame lines after 7 minutes. The frame is 517 ms with this PR against 530 ms without, and the GPU 145 ms against 150 ms, so there is no measurable cost. The warm-up re-made 29 of the 28,164 pipelines. - I saw no visible change in this scene. Two runs of the same build already differ in the yard's haze here, so one frame per build would not show it either way. AI-assisted.
lhnizdo commented 2026-11-28 21:52:28 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by lhnizdo on 2026-11-28T21:52:28Z.


Thanks @kilolimaVI, @JurajSimicevic and @pickles976 for the runs.

With these, a_program_reads_back_what_it_stored_to_title_memory now fails without the change and passes with it on three architectures:

  • Radeon 780M (RDNA3);
  • RTX 5080 (Blackwell);
  • RTX 2080 (Turing).

Each fails the same way, every dword reading back one less than stored. The Wine/vkd3d-proton setup doesn't show the stale read even on main, which I take as that stack resolving the SRV/UAV aliasing differently, not as a counter-example.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246335629 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7246335629). Originally posted by [lhnizdo](https://github.com/lhnizdo) on 2026-11-28T21:52:28Z. --- Thanks @kilolimaVI, @JurajSimicevic and @pickles976 for the runs. With these, `a_program_reads_back_what_it_stored_to_title_memory` now fails without the change and passes with it on three architectures: - Radeon 780M (RDNA3); - RTX 5080 (Blackwell); - RTX 2080 (Turing). Each fails the same way, every dword reading back one less than stored. The Wine/vkd3d-proton setup doesn't show the stale read even on `main`, which I take as that stack resolving the SRV/UAV aliasing differently, not as a counter-example. AI-assisted (Claude Code).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3584:upstream-pr/3584'
git switch 'upstream-pr/3584'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3584'
git switch 'upstream-pr/3584'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3584'
git switch 'upstream-pr/3584'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3584'
git switch 'main'
git merge --squash 'upstream-pr/3584'
git switch 'main'
git merge --ff-only 'upstream-pr/3584'
git switch 'main'
git merge 'upstream-pr/3584'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
Marvisak/VIctory!3584
No description provided.