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

Open
github-bot wants to merge 1 commit from github-bot/gh-3584 into main AGit
Owner

@⁠lhnizdo on GitHub · 2026-11-27 19:07 UTC · original
lhnizdo:shader/title-loads-see-writes → main · +143 −2 · 2 files · 1 commits · open

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

**@⁠lhnizdo** on GitHub · 2026-11-27 19:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/3584) `lhnizdo:shader/title-loads-see-writes` → `main` · +143 −2 · 2 files · 1 commits · open ## 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
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 <[email protected]>
Claude-Session: https://claude.ai/code/session_018sSQTfPXZpSkjMMNa7RB5G
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 19:12:36 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-27 19:31 UTC · original

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.

**@⁠pickles976** on GitHub · 2026-11-27 19:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7226612370) 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.
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 19:37 UTC · original

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** on GitHub · 2026-11-27 19:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7226712182) 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).
Author
Owner

@⁠kilolimaVI on GitHub · 2026-11-27 19:58 UTC · original

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

**@⁠kilolimaVI** on GitHub · 2026-11-27 19:58 UTC · [original](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7227052756) 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).
Author
Owner

@⁠JurajSimicevic on GitHub · 2026-11-27 20:37 UTC · original

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.

**@⁠JurajSimicevic** on GitHub · 2026-11-27 20:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/3584#issuecomment-7227692384) **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.
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3584/head:github-bot/gh-3584'
git switch 'github-bot/gh-3584'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3584'
git switch 'github-bot/gh-3584'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3584'
git switch 'github-bot/gh-3584'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3584'
git switch 'main'
git merge --squash 'github-bot/gh-3584'
git switch 'main'
git merge --ff-only 'github-bot/gh-3584'
git switch 'main'
git merge 'github-bot/gh-3584'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3584
No description provided.