Shaders: VICTORY_LDS_EXACT=1 orders LDS in a lane-branch region by the dwords it touches (369cbe906ea72764 on 32-lane GPUs) #500

Open
github-bot wants to merge 2 commits from github-bot/gh-500 into main AGit
Owner

@⁠Yorivel on GitHub · 2026-11-25 01:47 UTC · original
Yorivel:fix/lds-exact-regions → main · +148 −2 · 1 files · 2 commits · open

Problem

On a 32-lane host (NVIDIA), a wave64 compute program with LDS and a group over 32 threads is split into two host waves. lds_meetings puts group barriers at the edges of lane-branch regions, and refuses the program when one region both reads and writes LDS. Every non-read counts as a write there, atomics included, and addresses are not looked at.

369cbe906ea72764 (GTA VI prologue, group 64, no cross-lane ops) is refused only for that reason (VICTORY_WAVE_WHY=1: [LDS in a group over 32, an LDS read and write in one lane-branch region]). It then falls back to WaveSize(64), and CreateComputePipelineState refuses it with E_INVALIDARG on every run. Its LDS use is a fixed set of counters:

  • a thread-0 block initialises slots;
  • one loop region only does ds_add to slots at bytes 8/12/16/20;
  • a second loop region reads slot 0 and does ds_add to bytes 16/20;
  • a thread-0 block reads the totals.

No read in a region touches a dword a write in the same region touches, so the barriers at the region edges already keep the console's order.

Change (opt-in: VICTORY_LDS_EXACT=1)

lds_meetings refuses a region only where two accesses may touch the same dword and need an order:

  • Addresses: a Ds address that is a v_mov_b32/s_mov_b32 of an inline constant or literal, plus the instruction's offset, is known. read2/write2 scale by the element size (×64 for st64) and wide forms cover their dwords. Any other address is taken to touch every dword, so the old answer stands there.
  • Kinds: a read, a write, or an order-free atomic: add/sub/min/max/and/or/xor, the _rtn form being the same kind.
  • What conflicts: a read with a write or atomic on the same dword; a write with anything on the same dword; atomics of different kinds on the same dword. Atomics of one kind need no order among themselves, since the dword ends the same in any order. wrxchg, cmpst, inc/dec (wrapping) and src2 forms stay writes.

The default path is unchanged. Unit tests are in lds_exact_tests.

Results (RTX 4090, driver 621.40, Windows 11, diag build)

  • Offline, VICTORY_HOST_MAX_WAVE=32 victory translate --validate --pipelines: 369cbe906ea72764 emits, validates and creates a host pipeline. The other wave64 refusals of this scene (2da4beb386509b77, 2cc4c197ee29e291, 02384a60fda6f2d0, 6b82bc7d22016cb5) still keep 64 lanes: they also read masks as data, use v_mbcnt/v_readlane, or index LDS per lane.
  • In game: its pipeline is created and the scene runs to the first gameplay room without errors or device faults, at the usual ~250 ms/frame. A frame capture shows it as a 1×1×1 dispatch next to the ray-tracing structure builder's stages (off by default). I can't point to a visible change, so I'm not claiming one.

Tested together with #461, #190 and #156, which bring 5dc3b25986622949 and 6f225b641c5b0708 to WaveSize(32) here as well.

🤖 Generated with Claude Code

**@⁠Yorivel** on GitHub · 2026-11-25 01:47 UTC · [original](https://github.com/fxceless/victory-fork/pull/500) `Yorivel:fix/lds-exact-regions` → `main` · +148 −2 · 1 files · 2 commits · open ## Problem On a 32-lane host (NVIDIA), a wave64 compute program with LDS and a group over 32 threads is split into two host waves. `lds_meetings` puts group barriers at the edges of lane-branch regions, and refuses the program when one region both reads and writes LDS. Every non-read counts as a write there, atomics included, and addresses are not looked at. `369cbe906ea72764` (GTA VI prologue, group 64, no cross-lane ops) is refused only for that reason (`VICTORY_WAVE_WHY=1`: `[LDS in a group over 32, an LDS read and write in one lane-branch region]`). It then falls back to `WaveSize(64)`, and `CreateComputePipelineState` refuses it with `E_INVALIDARG` on every run. Its LDS use is a fixed set of counters: - a thread-0 block initialises slots; - one loop region only does `ds_add` to slots at bytes 8/12/16/20; - a second loop region reads slot 0 and does `ds_add` to bytes 16/20; - a thread-0 block reads the totals. No read in a region touches a dword a write in the same region touches, so the barriers at the region edges already keep the console's order. ## Change (opt-in: `VICTORY_LDS_EXACT=1`) `lds_meetings` refuses a region only where two accesses may touch the same dword and need an order: - **Addresses:** a `Ds` address that is a `v_mov_b32`/`s_mov_b32` of an inline constant or literal, plus the instruction's offset, is known. `read2`/`write2` scale by the element size (×64 for `st64`) and wide forms cover their dwords. Any other address is taken to touch every dword, so the old answer stands there. - **Kinds:** a read, a write, or an order-free atomic: `add`/`sub`/`min`/`max`/`and`/`or`/`xor`, the `_rtn` form being the same kind. - **What conflicts:** a read with a write or atomic on the same dword; a write with anything on the same dword; atomics of different kinds on the same dword. Atomics of one kind need no order among themselves, since the dword ends the same in any order. `wrxchg`, `cmpst`, `inc`/`dec` (wrapping) and `src2` forms stay writes. The default path is unchanged. Unit tests are in `lds_exact_tests`. ## Results (RTX 4090, driver 621.40, Windows 11, diag build) - Offline, `VICTORY_HOST_MAX_WAVE=32 victory translate --validate --pipelines`: `369cbe906ea72764` emits, validates and creates a host pipeline. The other wave64 refusals of this scene (`2da4beb386509b77`, `2cc4c197ee29e291`, `02384a60fda6f2d0`, `6b82bc7d22016cb5`) still keep 64 lanes: they also read masks as data, use `v_mbcnt`/`v_readlane`, or index LDS per lane. - In game: its pipeline is created and the scene runs to the first gameplay room without errors or device faults, at the usual ~250 ms/frame. A frame capture shows it as a 1×1×1 dispatch next to the ray-tracing structure builder's stages (off by default). I can't point to a visible change, so I'm not claiming one. Tested together with #461, #190 and #156, which bring `5dc3b25986622949` and `6f225b641c5b0708` to `WaveSize(32)` here as well. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
lds_meetings refused a wave64 program on a 32-lane host whenever one
lane-branch region both read and wrote LDS. With the switch it refuses only
where a read and a write (or atomics of different kinds) may touch the same
dword; addresses that are a moved constant plus the instruction's offset
are known, any other is taken to touch every dword, and order-free atomics
of one kind (add, min...) need no order among themselves.

369cbe906ea72764 (RTX 4090, GTA VI prologue) builds with it: its regions
read slot 0 and add to slots 16/20, or only add.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:44:48 +00:00
Author
Owner

@⁠ArturoWolff on GitHub · 2026-11-25 05:11 UTC · original · edited 2026-11-25 05:21 UTC

Linux check isolating #500 from the other three PRs in the RTX 4090 report: on 310c6eb plus 60b651e, I replayed two compute containers matched by size and runtime hash to our earlier Proton frame 2250. In that earlier run both host pipelines returned 0x80070057.

Same native translator binary, host wave limit 32; only VICTORY_LDS_EXACT changed. Microsoft's Linux dxv accepted all four outputs; dxc -dumpbin reported:

Compute hash Switch off Switch on
369cbe906ea72764 WaveSize 64, 6,300 bytes WaveSize 32, 8,768 bytes
02384a60fda6f2d0 WaveSize 64, 6,736 bytes byte-identical, still WaveSize 64

That independently pins the first shader's wave-size change to this PR alone. The second is also the shader we saw explicitly refused on stock 310c6eb in #599; this switch leaves its shader binary unchanged. I don't have a Linux pipeline result to add to your Windows one: the bounded GE-Proton/llvmpipe probe timed out during device initialization, before pipeline creation. No dispatch or game launch here.

Warm-cache reproduction: the first setting wins. The table above is fresh translation. I then ran the same target through the production shader_cache::host_shader module, using a fresh process per invocation and the same disposable disk cache across each pair. Native Linux, wave limit fixed at 32, device view-heap probe stubbed. After priming with 0, switching to 1 hit the 6,300-byte entry; a direct translation in that same process produced 8,768 bytes. Reversing the order in a separate directory hit 8,768 bytes with 0 instead of 6,300. This can mask a real A/B in either direction; it doesn't tell us whether it affected your particular run.

Tested fix: add "VICTORY_LDS_EXACT", beside "VICTORY_WAVE_OWN_BITS", in crates/victory-gpu/src/shader_cache.rs (build()). With just that change to the cache module, both 0 → 1 → 0 and 1 → 0 → 1 gave miss, miss, hit, and every result matched direct translation byte-for-byte. Same class as #199, different switch. Separate cache directories suffice for comparisons until this is keyed; no need to delete an existing cache.

AI disclosure: Hermes Agent ran the translator and cache comparisons, tested the one-line fix, and wrote this comment on ArturoWolff’s behalf.

**@⁠ArturoWolff** on GitHub · 2026-11-25 05:11 UTC · [original](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7153533190) · edited 2026-11-25 05:21 UTC Linux check isolating #500 from the other three PRs in the RTX 4090 report: on `310c6eb` plus `60b651e`, I replayed two compute containers matched by size and runtime hash to our earlier Proton frame 2250. In that earlier run both host pipelines returned `0x80070057`. Same native translator binary, host wave limit 32; only `VICTORY_LDS_EXACT` changed. Microsoft's Linux `dxv` accepted all four outputs; `dxc -dumpbin` reported: | Compute hash | Switch off | Switch on | |---|---|---| | `369cbe906ea72764` | WaveSize 64, 6,300 bytes | WaveSize 32, 8,768 bytes | | `02384a60fda6f2d0` | WaveSize 64, 6,736 bytes | byte-identical, still WaveSize 64 | That independently pins the first shader's wave-size change to this PR alone. The second is also the shader we saw explicitly refused on stock `310c6eb` in [#599](https://git.gtahub.st/github/fxceless--victory-fork/issues/599); this switch leaves its shader binary unchanged. I don't have a Linux pipeline result to add to your Windows one: the bounded GE-Proton/llvmpipe probe timed out during device initialization, before pipeline creation. No dispatch or game launch here. **Warm-cache reproduction: the first setting wins.** The table above is fresh translation. I then ran the same target through the production `shader_cache::host_shader` module, using a fresh process per invocation and the same disposable disk cache across each pair. Native Linux, wave limit fixed at 32, device view-heap probe stubbed. After priming with `0`, switching to `1` hit the 6,300-byte entry; a direct translation in that same process produced 8,768 bytes. Reversing the order in a separate directory hit 8,768 bytes with `0` instead of 6,300. This can mask a real A/B in either direction; it doesn't tell us whether it affected your particular run. Tested fix: add `"VICTORY_LDS_EXACT",` beside `"VICTORY_WAVE_OWN_BITS",` in `crates/victory-gpu/src/shader_cache.rs` (`build()`). With just that change to the cache module, both `0 → 1 → 0` and `1 → 0 → 1` gave miss, miss, hit, and every result matched direct translation byte-for-byte. Same class as #199, different switch. Separate cache directories suffice for comparisons until this is keyed; no need to delete an existing cache. AI disclosure: Hermes Agent ran the translator and cache comparisons, tested the one-line fix, and wrote this comment on ArturoWolff’s behalf.
Author
Owner

@⁠im-a-cat on GitHub · 2026-11-25 07:21 UTC · original

Checked merging #500 onto current fxceless/main (a26859f, stacked locally with #47, #461, #190, and #592):

  • All 221 non-ignored tests in victory-shader pass on Windows 11 / RTX 4060 Ti (including lds_exact_tests::kinds and lds_exact_tests::conflicts).
  • Update on the warm-cache note above: on current main (>= 8dd30ab), crates/victory-shader/build.rs automatically collects every "VICTORY_*" literal from crates/victory-shader/src into VICTORY_SHADER_SWITCHES, which translation_fingerprint() hashes into shader_cache::build(). Once rebased/merged on current main, VICTORY_LDS_EXACT enters the shader cache key automatically without touching shader_cache.rs.
  • Small stacking note: lds_meetings in emit/lower.rs conflicts trivially with #592 at the reads[r] && writes[r] loop (both compose cleanly), and stacking #190 + #500 + #592 onto a26859f (514,840 B) puts lower.rs at 532,765 B, over xtask policy's 524,288 B per-file limit.
**@⁠im-a-cat** on GitHub · 2026-11-25 07:21 UTC · [original](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7155778383) Checked merging `#500` onto current `fxceless/main` (`a26859f`, stacked locally with `#47`, `#461`, `#190`, and `#592`): - All 221 non-ignored tests in `victory-shader` pass on Windows 11 / RTX 4060 Ti (including `lds_exact_tests::kinds` and `lds_exact_tests::conflicts`). - Update on the warm-cache note above: on current `main` (`>= 8dd30ab`), `crates/victory-shader/build.rs` automatically collects every `"VICTORY_*"` literal from `crates/victory-shader/src` into `VICTORY_SHADER_SWITCHES`, which `translation_fingerprint()` hashes into `shader_cache::build()`. Once rebased/merged on current `main`, `VICTORY_LDS_EXACT` enters the shader cache key automatically without touching `shader_cache.rs`. - Small stacking note: `lds_meetings` in `emit/lower.rs` conflicts trivially with `#592` at the `reads[r] && writes[r]` loop (both compose cleanly), and stacking `#190` + `#500` + `#592` onto `a26859f` (`514,840` B) puts `lower.rs` at `532,765` B, over `xtask policy`'s `524,288` B per-file limit.
Author
Owner

@⁠avt0m4t48 on GitHub · 2026-11-25 14:24 UTC · original

I reproduced a false disjoint-address result on 60b651e with VICTORY_LDS_EXACT=1. The synthetic program initializes v1=0 for every lane, writes v1=4 under lane < s0, restores EXEC, then runs a read from v1 and a write to address 0 under lane < s1.

When s1 > s0, the additional reading lanes still have address 0. The existing analysis reported [(Read, Some([1])), (Write, Some([0]))] and lds_meetings approved the split. Separate host waves can then observe an order the console's single wave would avoid.

The test and small candidate change skip guarded VGPR definitions in the constant-address map. The synthetic read becomes unknown and the analysis refuses the split. A control with the same move made unconditionally still takes the disjoint-address path. The Linux shader suite passed 174 tests with two ignored. This verifies the regional analysis on synthetic programs. I did not run the reported retail shader or measure how many existing programs the conservative check would retain.

Regression and candidate

AI-assisted using Codex.

**@⁠avt0m4t48** on GitHub · 2026-11-25 14:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7165232077) I reproduced a false disjoint-address result on `60b651e` with `VICTORY_LDS_EXACT=1`. The synthetic program initializes `v1=0` for every lane, writes `v1=4` under `lane < s0`, restores EXEC, then runs a read from `v1` and a write to address 0 under `lane < s1`. When `s1 > s0`, the additional reading lanes still have address 0. The existing analysis reported `[(Read, Some([1])), (Write, Some([0]))]` and `lds_meetings` approved the split. Separate host waves can then observe an order the console's single wave would avoid. The test and small candidate change skip guarded VGPR definitions in the constant-address map. The synthetic read becomes unknown and the analysis refuses the split. A control with the same move made unconditionally still takes the disjoint-address path. The Linux shader suite passed 174 tests with two ignored. This verifies the regional analysis on synthetic programs. I did not run the reported retail shader or measure how many existing programs the conservative check would retain. [Regression and candidate](https://github.com/avt0m4t48/victory-fork/commit/bccb31a3afa39c667513c701934476eff7607de3) AI-assisted using Codex.
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 20:50 UTC · original · edited 2026-11-25 20:51 UTC

RTX 3050 Laptop (4 GB), Windows, Series S profile. In our baseline log, compute 369cbe906ea72764 was reported as translated and then refused by D3D12. It accounted for 0.8–1.5 dropped dispatches per frame in each of the last 30 reporting intervals. Two useful controls, 02384a60fda6f2d0 and 2da4beb386509b77, also appeared in all 30.

There is an important attribution issue for anyone testing this PR in a stack. DexNom/VIctory#40 reports creating the particle visibility pipeline on a 5060 Ti through a different fallback, while both control pipelines remained refused. Comet#68 independently tracks a per-frame refusal of the particle pipeline. For a local A/B, keep the wide fallback fixed in both runs, match cache warm-up, and compare creation and dispatch for those three hashes. A successful PSO alone cannot establish a visual or FPS gain.

On f8ea5d9 with a local, more conservative variant of #500, we also tested nine synthetic programs under all four combinations of VICTORY_LDS_FLAGS and VICTORY_LDS_EXACT on the 3050. With both enabled, the flag and three disjoint-counter cases ran at Wave32 and matched all 64 output words for each of 18 input combinations. The five other cases retained Wave64, including a partially overwritten address across a basic-block boundary. The shader suite passed 226 tests with four ignored. These results cover the guarded variant; the particle pipeline still needs an enabled-run measurement on this card.

Cache check on the guarded build: all four switch combinations produced distinct translation fingerprints, and repeating the first reproduced its fingerprint. The disk shader cache includes this fingerprint in its key, so the same directory can be used for the correctness comparison. Warm both variants equally if measuring timing.

AI-assisted (Codex).

**@⁠Dathinel** on GitHub · 2026-11-25 20:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7174254389) · edited 2026-11-25 20:51 UTC RTX 3050 Laptop (4 GB), Windows, Series S profile. In our baseline log, compute `369cbe906ea72764` was reported as translated and then refused by D3D12. It accounted for 0.8–1.5 dropped dispatches per frame in each of the last 30 reporting intervals. Two useful controls, `02384a60fda6f2d0` and `2da4beb386509b77`, also appeared in all 30. There is an important attribution issue for anyone testing this PR in a stack. [DexNom/VIctory#40](https://github.com/DexNom/VIctory/pull/40) reports creating the particle visibility pipeline on a 5060 Ti through a different fallback, while both control pipelines remained refused. [Comet#68](https://github.com/Fyntra-Development/Comet/issues/68) independently tracks a per-frame refusal of the particle pipeline. For a local A/B, keep the wide fallback fixed in both runs, match cache warm-up, and compare creation **and dispatch** for those three hashes. A successful PSO alone cannot establish a visual or FPS gain. On `f8ea5d9` with a local, more conservative variant of #500, we also tested nine synthetic programs under all four combinations of `VICTORY_LDS_FLAGS` and `VICTORY_LDS_EXACT` on the 3050. With both enabled, the flag and three disjoint-counter cases ran at Wave32 and matched all 64 output words for each of 18 input combinations. The five other cases retained Wave64, including a partially overwritten address across a basic-block boundary. The shader suite passed 226 tests with four ignored. These results cover the guarded variant; the particle pipeline still needs an enabled-run measurement on this card. Cache check on the guarded build: all four switch combinations produced distinct translation fingerprints, and repeating the first reproduced its fingerprint. The disk shader cache includes this fingerprint in its key, so the same directory can be used for the correctness comparison. Warm both variants equally if measuring timing. AI-assisted (Codex).
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-500'
git switch 'github-bot/gh-500'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-500'
git switch 'github-bot/gh-500'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-500'
git switch 'main'
git merge --squash 'github-bot/gh-500'
git switch 'main'
git merge --ff-only 'github-bot/gh-500'
git switch 'main'
git merge 'github-bot/gh-500'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.