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

Open
Yorivel wants to merge 2 commits from upstream-pr/500 into main
Yorivel commented 2026-11-25 01:47:15 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Yorivel on 2026-11-25T01:47:15Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:issue:5483535687 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/500). Originally posted by [Yorivel](https://github.com/Yorivel) on 2026-11-25T01:47:15Z. --- ## 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)
ArturoWolff commented 2026-11-25 06:06:37 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ArturoWolff on 2026-11-25T05:11:28Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153533190 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7153533190). Originally posted by [ArturoWolff](https://github.com/ArturoWolff) on 2026-11-25T05:11:28Z. --- 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://github.com/fxceless/victory-fork/issues/599#issuecomment-7152302455); 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.
im-a-cat commented 2026-11-25 08:08:59 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by im-a-cat on 2026-11-25T07:21:55Z.


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.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7155778383 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7155778383). Originally posted by [im-a-cat](https://github.com/im-a-cat) on 2026-11-25T07:21:55Z. --- 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.
avt0m4t48 commented 2026-11-25 15:08:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T14:24:32Z.


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.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7165232077 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7165232077). Originally posted by [avt0m4t48](https://github.com/avt0m4t48) on 2026-11-25T14:24:32Z. --- 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.
Dathinel commented 2026-11-25 21:05:56 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Dathinel on 2026-11-25T20:50:14Z.


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

<!-- greyfinch-sync:fxceless/victory-fork:comment:7174254389 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7174254389). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T20:50:14Z. --- 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).
Filip722 commented 2026-11-27 00:01:22 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by Filip722 on 2026-11-27T00:01:22Z.


On the RTX 5060 Laptop with GE-Proton11-14 and vkd3d-proton 3.2.0, I tested a conservative port of the disjoint-counter proof on main 4c604661. It preserves the existing flag proof, guards address resolution, and only permits non-returning integer adds. Four focused regressions passed in the Windows-target binary under Proton.

With the conservative change off and on, all three selected shaders emitted and validated DXIL. Native compute pipeline creation returned 0x80070057 for 369cbe906ea72764 and both controls, 02384a60fda6f2d0 and 2da4beb386509b77.

The 64-thread visibility shader uses two returning integer adds in the otherwise disjoint counter region. A separate diagnostic found explicit SSA operand uses of their returned values. A proof that requires dead returns still leaves this shader on its existing path. That gives a concrete compatibility constraint for following up on the guard review.

Assisted by Codex (GPT-6.2-Sol High).

<!-- greyfinch-sync:fxceless/victory-fork:comment:7206102554 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/500#issuecomment-7206102554). Originally posted by [Filip722](https://github.com/Filip722) on 2026-11-27T00:01:22Z. --- On the RTX 5060 Laptop with GE-Proton11-14 and vkd3d-proton 3.2.0, I tested a conservative port of the disjoint-counter proof on main `4c604661`. It preserves the existing flag proof, guards address resolution, and only permits non-returning integer adds. Four focused regressions passed in the Windows-target binary under Proton. With the conservative change off and on, all three selected shaders emitted and validated DXIL. Native compute pipeline creation returned `0x80070057` for `369cbe906ea72764` and both controls, `02384a60fda6f2d0` and `2da4beb386509b77`. The 64-thread visibility shader uses two returning integer adds in the otherwise disjoint counter region. A separate diagnostic found explicit SSA operand uses of their returned values. A proof that requires dead returns still leaves this shader on its existing path. That gives a concrete compatibility constraint for following up on the guard review. Assisted by Codex (GPT-6.2-Sol High).
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/500:upstream-pr/500'
git switch 'upstream-pr/500'

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/500'
git switch 'upstream-pr/500'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/500'
git switch 'upstream-pr/500'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/500'
git switch 'main'
git merge --squash 'upstream-pr/500'
git switch 'main'
git merge --ff-only 'upstream-pr/500'
git switch 'main'
git merge 'upstream-pr/500'
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
fxceless/victory-fork!500
No description provided.