fix(victory-shader): keep wave64-on-wave32 TGSM within 32 KiB on 32-lane hosts #295

Merged
mauroalvare merged 6 commits from upstream-pr/295 into main 2026-11-27 19:38:44 +00:00
mauroalvare commented 2026-11-26 01:43:40 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-26T01:43:40Z.


Vice-Tay

On a 32-lane host, Vice-Tay now reuses one group-shared dword for the thread-numbering prologue when the shader declares the full 32 KiB. The prologue finishes using it before the emulated shader's LDS accesses. If cross-half exchange needs more group-shared memory than D3D12 supports, lowering reports the limit explicitly.

The NVIDIA test exercised a split wave that reads across halves at the limit. A second regression covers a shader whose exchange storage exceeds the limit.

Earlier Neptune description

Change

In VIctory's RDNA2-to-DXIL translator (third_party/victory/crates/victory-shader/src/emit/lower.rs), the non-paired wave64-on-wave32 compute lowering (used on 32-lane hosts such as NVIDIA GPUs) could push thread-group shared memory (TGSM) past D3D12's hard 32 KiB (8,192 dwords) limit:

  1. halves (wave_base's LDS counter) unconditionally appended 1 dword (s.lds_dwords += 1), turning a 32 KiB console shader into 32,772 bytes (8,193 dwords), rejected by dxil.dll and D3D12 CreateComputePipelineState. The paired form already reuses slot 0 when s.lds_dwords == 8192 because wave_base() emits a post-counter group_sync whenever slot < cs.lds_bytes() / 4; the non-paired path now does the same.
  2. exchange unconditionally added 2 * group.div_ceil(64) dwords even when s.lds_dwords was already at or near 8,192 (and even when group <= 32 or LOCAL_WAVES, where exchange_halves never touches LDS). Because emit_forms still returned Ok((_, Some(32))) with invalid >32 KiB DXIL, emit_any never fell back to the paired form (which needs zero exchange dwords and fits in 32 KiB). Checking s.lds_dwords + exchange_dwords <= 8192 keeps wave = 64 when exchange does not fit, letting emit_any fall back to the valid paired form.

Linked issue: Refs #213

Verification

Base SHA: c4c93bdc413191a9dc909998d2d53080a3f0c880 (LooperSalty/AnyXboxX:main)
Hardware: Windows 11, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 621.40), dxil.dll 10.0.26100.0, Rust 1.98.1 (MSVC).

Before the fix (both new tests failing on base c4c93bd):

cargo test --locked -p victory-shader wave64_full_32kib_lds -- --test-threads=1 --nocapture
-> FAILED: DXIL validation failed: "error: Total Thread Group Shared Memory storage is 32772, exceeded 32768."
-> FAILED: expected fallback to paired form when exchange overflows 32 KiB LDS (emitted 32,788-byte TGSM)

After the fix (from third_party/victory):

cargo test --locked -p victory-shader wave64_full_32kib_lds -- --test-threads=1 --nocapture
-> test result: ok. 2 passed; 0 failed; 0 ignored (both validated by dxil.dll and executed on RTX 5070 Ti)
cargo test --locked -p victory-shader -- --test-threads=1
-> test result: ok. 244 passed; 0 failed; 2 ignored
cargo check --locked -p victory
-> Finished `dev` profile (no new warnings)
cargo xtask policy
-> asset policy: 199 files ok

Oracle and test data

Both new regression tests in third_party/victory/crates/victory-shader/src/emit/wave64_tests.rs synthesize minimal GFX10 wave64 compute shaders with 32 KiB (32,768 bytes) of LDS:

  • wave64_full_32kib_lds_without_exchange_fits_on_32_lane_host: 64 threads writing 3*t + 1 to LDS[4*t] (including LDS[0]) and reading mirror lane 63 - t across halves; validated with dxil.dll and checked dword-for-dword on RTX 5070 Ti.
  • wave64_full_32kib_lds_with_exchange_falls_back_to_paired_on_32_lane_host: 128 threads writing 5*t + 7 to LDS[4*t], reading t ^ 32, and computing s_bcnt1_i32_b64 + v_mbcnt_lo/hi; verifies fallback to paired form, dxil.dll validation, and all 512 output dwords on RTX 5070 Ti.

No game, console, or SDK files were used.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: unchanged (not applicable).
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (synthetic tests only).
  • Code taken from another project: none.

AI assistance: investigated, implemented, tested on RTX 5070 Ti, and drafted with Antigravity (Gemini).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:issue:5502416395 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/295). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-26T01:43:40Z. --- ## Vice-Tay On a 32-lane host, Vice-Tay now reuses one group-shared dword for the thread-numbering prologue when the shader declares the full 32 KiB. The prologue finishes using it before the emulated shader's LDS accesses. If cross-half exchange needs more group-shared memory than D3D12 supports, lowering reports the limit explicitly. The NVIDIA test exercised a split wave that reads across halves at the limit. A second regression covers a shader whose exchange storage exceeds the limit. <details> <summary>Earlier Neptune description</summary> ## Change In VIctory's RDNA2-to-DXIL translator (`third_party/victory/crates/victory-shader/src/emit/lower.rs`), the non-paired wave64-on-wave32 compute lowering (used on 32-lane hosts such as NVIDIA GPUs) could push thread-group shared memory (TGSM) past D3D12's hard 32 KiB (8,192 dwords) limit: 1. `halves` (`wave_base`'s LDS counter) unconditionally appended 1 dword (`s.lds_dwords += 1`), turning a 32 KiB console shader into 32,772 bytes (`8,193` dwords), rejected by `dxil.dll` and D3D12 `CreateComputePipelineState`. The paired form already reuses slot 0 when `s.lds_dwords == 8192` because `wave_base()` emits a post-counter `group_sync` whenever `slot < cs.lds_bytes() / 4`; the non-paired path now does the same. 2. `exchange` unconditionally added `2 * group.div_ceil(64)` dwords even when `s.lds_dwords` was already at or near 8,192 (and even when `group <= 32` or `LOCAL_WAVES`, where `exchange_halves` never touches LDS). Because `emit_forms` still returned `Ok((_, Some(32)))` with invalid >32 KiB DXIL, `emit_any` never fell back to the paired form (which needs zero exchange dwords and fits in 32 KiB). Checking `s.lds_dwords + exchange_dwords <= 8192` keeps `wave = 64` when `exchange` does not fit, letting `emit_any` fall back to the valid paired form. Linked issue: Refs #213 ## Verification Base SHA: `c4c93bdc413191a9dc909998d2d53080a3f0c880` (`LooperSalty/AnyXboxX:main`) Hardware: Windows 11, Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver `621.40`), `dxil.dll` `10.0.26100.0`, Rust `1.98.1` (MSVC). Before the fix (both new tests failing on base `c4c93bd`): ``` cargo test --locked -p victory-shader wave64_full_32kib_lds -- --test-threads=1 --nocapture -> FAILED: DXIL validation failed: "error: Total Thread Group Shared Memory storage is 32772, exceeded 32768." -> FAILED: expected fallback to paired form when exchange overflows 32 KiB LDS (emitted 32,788-byte TGSM) ``` After the fix (from `third_party/victory`): ``` cargo test --locked -p victory-shader wave64_full_32kib_lds -- --test-threads=1 --nocapture -> test result: ok. 2 passed; 0 failed; 0 ignored (both validated by dxil.dll and executed on RTX 5070 Ti) cargo test --locked -p victory-shader -- --test-threads=1 -> test result: ok. 244 passed; 0 failed; 2 ignored cargo check --locked -p victory -> Finished `dev` profile (no new warnings) cargo xtask policy -> asset policy: 199 files ok ``` ## Oracle and test data Both new regression tests in `third_party/victory/crates/victory-shader/src/emit/wave64_tests.rs` synthesize minimal GFX10 wave64 compute shaders with 32 KiB (32,768 bytes) of LDS: - `wave64_full_32kib_lds_without_exchange_fits_on_32_lane_host`: 64 threads writing `3*t + 1` to `LDS[4*t]` (including `LDS[0]`) and reading mirror lane `63 - t` across halves; validated with `dxil.dll` and checked dword-for-dword on RTX 5070 Ti. - `wave64_full_32kib_lds_with_exchange_falls_back_to_paired_on_32_lane_host`: 128 threads writing `5*t + 7` to `LDS[4*t]`, reading `t ^ 32`, and computing `s_bcnt1_i32_b64` + `v_mbcnt_lo/hi`; verifies fallback to paired form, `dxil.dll` validation, and all 512 output dwords on RTX 5070 Ti. No game, console, or SDK files were used. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: unchanged (not applicable). - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (synthetic tests only). - [x] Code taken from another project: none. *AI assistance: investigated, implemented, tested on RTX 5070 Ti, and drafted with Antigravity (Gemini).* </details>
LooperSalty commented 2026-11-27 13:03:12 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T13:03:12Z.


Rebase on current main (fa6b209e) is needed: recent merges into main now conflict with this PR. Please rebase and push so the PR can be reviewed again.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7218998236 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/295#issuecomment-7218998236). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T13:03:12Z. --- Rebase on current main (fa6b209e) is needed: recent merges into main now conflict with this PR. Please rebase and push so the PR can be reviewed again.
mauroalvare commented 2026-11-27 17:01:58 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:01:58Z.


Updated this PR to a4453083. The LDS-limit tests now coexist with #317's first-lane coverage. The targeted shader suite passed, including the 32 KiB case and the explicit overflow error.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7223948336 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/295#issuecomment-7223948336). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:01:58Z. --- Updated this PR to `a4453083`. The LDS-limit tests now coexist with #317's first-lane coverage. The targeted shader suite passed, including the 32 KiB case and the explicit overflow error.
LooperSalty commented 2026-11-27 17:31:08 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by LooperSalty on 2026-11-27T17:31:08Z.


One question: does this change the translation of any wave64 shader that translated before (rather than only turning an earlier failure into a fitting layout or an explicit error)? If so, TRANSLATOR_VERSION (victory-shader/src/lib.rs) needs a bump so older caches are not reused; #456 uses 3, #485 4, #306 asks for 5.

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224495996 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/295#issuecomment-7224495996). Originally posted by [LooperSalty](https://github.com/LooperSalty) on 2026-11-27T17:31:08Z. --- One question: does this change the translation of any wave64 shader that translated before (rather than only turning an earlier failure into a fitting layout or an explicit error)? If so, `TRANSLATOR_VERSION` (`victory-shader/src/lib.rs`) needs a bump so older caches are not reused; #456 uses 3, #485 4, #306 asks for 5.
mauroalvare commented 2026-11-27 17:57:25 +00:00 (Migrated from github.com)

Imported from LooperSalty/AnyXboxX. Originally posted by mauroalvare on 2026-11-27T17:57:25Z.


Good catch — checked shader_cache.rs, and cache.get_or_convert caches the output of victory_shader::translate() before D3D12 PSO creation. For shaders with lds_dwords < 8192 the emitted DXIL is unchanged, but a wave64 compute shader right at the 32 KiB LDS limit previously returned Ok(dxil) with an invalid > 32 KiB TGSM allocation and got written to disk cache, whereas with this PR it now either borrows LDS[0] to fit in 32 KiB or returns Err(ShaderError::Unsupported).

Bumped TRANSLATOR_VERSION to 8 in 717f7fb (leaving 3 for #456, 4 for #485, 5 for #306, 6 for #321, 7 for #327; happy to re-bump on rebase if another lands first). Re-verified wave64_thread_ticket_fits_at_the_d3d12_lds_limit, wave64_exchange_reports_an_lds_overflow, and cargo xtask policy (286 files ok).

<!-- greyfinch-sync:LooperSalty/AnyXboxX:comment:7224965246 --> Imported from [LooperSalty/AnyXboxX](https://github.com/LooperSalty/AnyXboxX/pull/295#issuecomment-7224965246). Originally posted by [mauroalvare](https://github.com/mauroalvare) on 2026-11-27T17:57:25Z. --- Good catch — checked `shader_cache.rs`, and `cache.get_or_convert` caches the output of `victory_shader::translate()` before D3D12 PSO creation. For shaders with `lds_dwords < 8192` the emitted DXIL is unchanged, but a wave64 compute shader right at the 32 KiB LDS limit previously returned `Ok(dxil)` with an invalid `> 32 KiB` TGSM allocation and got written to disk cache, whereas with this PR it now either borrows `LDS[0]` to fit in 32 KiB or returns `Err(ShaderError::Unsupported)`. Bumped `TRANSLATOR_VERSION` to `8` in `717f7fb` (leaving `3` for #456, `4` for #485, `5` for #306, `6` for #321, `7` for #327; happy to re-bump on rebase if another lands first). Re-verified `wave64_thread_ticket_fits_at_the_d3d12_lds_limit`, `wave64_exchange_reports_an_lds_overflow`, and `cargo xtask policy` (286 files ok).
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
LooperSalty/AnyXboxX!295
No description provided.