Shaders: support 32-lane wave64 lowering for partial-dispatch compute shaders #22

Open
davi713albano-coder wants to merge 1 commit from upstream-pr/22 into main
davi713albano-coder commented 2026-11-25 18:57:24 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by davi713albano-coder on 2026-11-25T18:57:24Z.


Summary

Addresses part of the 32-lane GPU (NVIDIA) ray-tracing builder block reported in #14 and #15 (Shader wants wave lane count of 64 but maximum wave lane count for device is 32, D3D12 debug id 622):

  • Previously Lower::new skipped wave64-to-wave32 lowering whenever partial == true (if !partial && wave == 64 && host_max_wave() == 32 ...), because Lower::run implemented partial-dispatch thread masking with an early Ret in the prologue that would deadlock group barriers (wave_base, exchange_halves, split_lds).
  • As a result, XboxBvhBuilder's Box32/Box16 rehydration kernels (box_rehydration in crates/victory-shader/src/emit/mod.rs) always emitted WaveSize(64) and failed CreateComputePipelineState with E_INVALIDARG on 32-lane GPUs.

Changes

  • Allow partial wave64 compute shaders to enter 32-lane lowering on host_max_wave() == 32 (crates/victory-shader/src/emit/lower.rs).
  • Keep the existing early-return prologue unchanged when self.halves.is_none() (native 64-lane hosts such as Radeon or non-wave64 shaders).
  • When self.halves.is_some() (console wave64 emulated across two 32-lane host waves), compute partial_active = (limit == 0) || (group * width + thread < limit) in the entry block without returning early (enter_partial_dispatch / with_partial in crates/victory-shader/src/emit/packed_mask.rs), keeping inactive tail threads alive through group barriers while masking:
    • instruction guards (Lower::guard: stores, atomics, VGPR writes, guest-memory fault reporting, v_readfirstlane_b32),
    • v_cmp_* / v_cmpx_* lane bits (lane_bits_for),
    • active-lane ballots (mask_dword when st.active.contains(&lo) — EXEC, VCC, s_bcnt1_i32_b64, s_ff1_i32_b64, v_mbcnt_*),
    • scc_some, wave_wide, wave_reduce, active_f64_sum, and scalar guest-memory loads (memory_smem).
  • Add regression test partial_thread_dispatch_on_32_lane_host_emits_wave32_and_masks_wave_counts_and_writes in crates/victory-shader/src/emit/wave64_tests.rs verifying PSV0 declares WaveSize(32), Microsoft DXIL validation passes, and (on 32-lane hardware) cross-lane s_bcnt1_i32_b64 exec counts and stores match across tail boundaries (0, 1, 7, 31, 32, 33, 45, 63, 64).

Note on hardware testing

Verified full CI (windows-latest: clippy, clippy --all-features, cargo test --workspace --locked, xtask asset-policy check, and dxil.dll validation) and Screen. Live 32-lane hardware verification (e.g., on RTX 3060 Ti / RTX 4070 from #14 / #15) is still needed and welcomed — this specifically resolves the two box_rehydration WaveSize(64) refusals; any remaining non-partial 64-lane pipelines on 32-lane hosts are separate.

No title data used. AI-assisted.

<!-- greyfinch-sync:DexNom/VIctory:issue:5497323695 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/22). Originally posted by [davi713albano-coder](https://github.com/davi713albano-coder) on 2026-11-25T18:57:24Z. --- ### Summary Addresses part of the 32-lane GPU (NVIDIA) ray-tracing builder block reported in #14 and #15 (`Shader wants wave lane count of 64 but maximum wave lane count for device is 32`, D3D12 debug id 622): - Previously `Lower::new` skipped wave64-to-wave32 lowering whenever `partial == true` (`if !partial && wave == 64 && host_max_wave() == 32 ...`), because `Lower::run` implemented partial-dispatch thread masking with an early `Ret` in the prologue that would deadlock group barriers (`wave_base`, `exchange_halves`, `split_lds`). - As a result, `XboxBvhBuilder`'s `Box32`/`Box16` rehydration kernels (`box_rehydration` in `crates/victory-shader/src/emit/mod.rs`) always emitted `WaveSize(64)` and failed `CreateComputePipelineState` with `E_INVALIDARG` on 32-lane GPUs. ### Changes - Allow `partial` wave64 compute shaders to enter 32-lane lowering on `host_max_wave() == 32` (`crates/victory-shader/src/emit/lower.rs`). - Keep the existing early-return prologue unchanged when `self.halves.is_none()` (native 64-lane hosts such as Radeon or non-wave64 shaders). - When `self.halves.is_some()` (console wave64 emulated across two 32-lane host waves), compute `partial_active = (limit == 0) || (group * width + thread < limit)` in the entry block without returning early (`enter_partial_dispatch` / `with_partial` in `crates/victory-shader/src/emit/packed_mask.rs`), keeping inactive tail threads alive through group barriers while masking: - instruction guards (`Lower::guard`: stores, atomics, VGPR writes, guest-memory fault reporting, `v_readfirstlane_b32`), - `v_cmp_*` / `v_cmpx_*` lane bits (`lane_bits_for`), - active-lane ballots (`mask_dword` when `st.active.contains(&lo)` — `EXEC`, `VCC`, `s_bcnt1_i32_b64`, `s_ff1_i32_b64`, `v_mbcnt_*`), - `scc_some`, `wave_wide`, `wave_reduce`, `active_f64_sum`, and scalar guest-memory loads (`memory_smem`). - Add regression test `partial_thread_dispatch_on_32_lane_host_emits_wave32_and_masks_wave_counts_and_writes` in `crates/victory-shader/src/emit/wave64_tests.rs` verifying `PSV0` declares `WaveSize(32)`, Microsoft DXIL validation passes, and (on 32-lane hardware) cross-lane `s_bcnt1_i32_b64 exec` counts and stores match across tail boundaries (`0, 1, 7, 31, 32, 33, 45, 63, 64`). ### Note on hardware testing Verified full `CI` (`windows-latest`: `clippy`, `clippy --all-features`, `cargo test --workspace --locked`, `xtask` asset-policy check, and `dxil.dll` validation) and `Screen`. Live 32-lane hardware verification (e.g., on RTX 3060 Ti / RTX 4070 from #14 / #15) is still needed and welcomed — this specifically resolves the two `box_rehydration` `WaveSize(64)` refusals; any remaining non-`partial` 64-lane pipelines on 32-lane hosts are separate. No title data used. AI-assisted.
FIJI1299 commented 2026-11-25 19:17:54 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by FIJI1299 on 2026-11-25T19:17:54Z.


Verified commit 92897d2 on live 32-lane (wave32) NVIDIA hardware (following up on the 32-lane NVIDIA reports in #14 and #15):

Environment

  • OS: Windows 11 (Build 26100)
  • CPU: AMD Ryzen 5 9600X 6-Core Processor
  • RAM: 32 GB
  • GPU: NVIDIA GeForce RTX 5070 (12 GB VRAM, driver 621.40, native wave32)
  • DXC: 1.8.2502.11 (Windows SDK 10.0.26100.0)

Results

  • victory-shader test suite (cargo test -p victory-shader --lib -- --test-threads=1): 238 passed, 0 failed, 4 ignored (366.25s), including all wave64 lowering tests (wave64_tests.rs).
  • victory-gpu test suite (cargo test -p victory-gpu --lib -- --test-threads=1): 188 passed, 0 failed, 3 ignored (4.68s).
  • Not tested: Retail title box_rehydration runtime execution (no game data on this machine).
<!-- greyfinch-sync:DexNom/VIctory:comment:7172102838 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/22#issuecomment-7172102838). Originally posted by [FIJI1299](https://github.com/FIJI1299) on 2026-11-25T19:17:54Z. --- Verified commit `92897d2` on live 32-lane (`wave32`) NVIDIA hardware (following up on the 32-lane NVIDIA reports in #14 and #15): ### Environment * **OS:** Windows 11 (Build 26100) * **CPU:** AMD Ryzen 5 9600X 6-Core Processor * **RAM:** 32 GB * **GPU:** NVIDIA GeForce RTX 5070 (12 GB VRAM, driver `621.40`, native `wave32`) * **DXC:** `1.8.2502.11` (Windows SDK `10.0.26100.0`) ### Results * **`victory-shader` test suite (`cargo test -p victory-shader --lib -- --test-threads=1`):** **238 passed, 0 failed, 4 ignored** (`366.25s`), including all `wave64` lowering tests (`wave64_tests.rs`). * **`victory-gpu` test suite (`cargo test -p victory-gpu --lib -- --test-threads=1`):** **188 passed, 0 failed, 3 ignored** (`4.68s`). * **Not tested:** Retail title `box_rehydration` runtime execution (no game data on this machine).
Artking175 commented 2026-11-25 21:04:23 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Artking175 on 2026-11-25T21:04:23Z.


I checked the full builder set on RTX 2060 (Windows 10, driver 531.41). With pinned 92897d2, the same Agility 1.614.1 / DXIL validator / loader overlay and VICTORY_HOST_MAX_WAVE=32 as the control, translate --jobs 1 --validate --pipelines --list XboxBvhBuilder.dll returned:

Build DXIL emitted and validated D3D12 PSOs
main 2e01ab4 49/52 47/52
#22 92897d2 49/52 49/52
#35 46fa699a 52/52 52/52

The two recovered PSOs are for container hashes 3297538b1176c897 and 138a77fa89f35ae4. The other three still stop in #22 at a first-lane read where not every lane runs. The earlier partial-dispatch fixture separately passed the RTX 2060 hardware readback with nine counts. This measures offline coverage of the two changes. Full #35 check.

<!-- greyfinch-sync:DexNom/VIctory:comment:7174574094 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/22#issuecomment-7174574094). Originally posted by [Artking175](https://github.com/Artking175) on 2026-11-25T21:04:23Z. --- I checked the full builder set on RTX 2060 (Windows 10, driver 531.41). With pinned `92897d2`, the same Agility 1.614.1 / DXIL validator / loader overlay and `VICTORY_HOST_MAX_WAVE=32` as the control, `translate --jobs 1 --validate --pipelines --list XboxBvhBuilder.dll` returned: | Build | DXIL emitted and validated | D3D12 PSOs | | --- | ---: | ---: | | main `2e01ab4` | 49/52 | 47/52 | | #22 `92897d2` | 49/52 | 49/52 | | #35 `46fa699a` | 52/52 | 52/52 | The two recovered PSOs are for container hashes `3297538b1176c897` and `138a77fa89f35ae4`. The other three still stop in #22 at `a first-lane read where not every lane runs`. The earlier partial-dispatch fixture separately passed the RTX 2060 hardware readback with nine counts. This measures offline coverage of the two changes. [Full #35 check](https://github.com/DexNom/VIctory/pull/35#issuecomment-7174445783).
j-fuxa commented 2026-11-26 01:41:07 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by j-fuxa on 2026-11-26T01:41:07Z.


Console thread ids for console wave32 programs in 2-D/3-D groups

Not about the partial-dispatch change itself. It is posted here because it sits beside wave_base / halves in crates/victory-shader/src/emit/lower.rs (main at 64bd58f5).

What we found. thread_id (and the fallback at the end of console_thread) builds the console flat thread id as waveReadLaneFirst(flattenedThreadIdInGroup) rounded down to the wave size, plus the lane index. The comment above it calls this a bijection "while each host wave holds a wave-aligned run of flat ids". On the 32-lane hosts we tried, that does not hold for 2-D groups. An RTX 4060 Laptop and a Radeon 780M both fill them with rows of 24+ threads taken from 16x2 tiles. wave_base already avoids this ("NVIDIA's 8 x 8 groups"), but only when halves is set (wave == 32 && native.wave64). A console wave32 program that uses console lanes, in a group larger than one host wave, still takes the rounding path.

Evidence. A compute program that stores each thread's console id, built with the old rounding. Ids stored out of total, identical on both GPUs: 32x2 32/64, 32x8 128/256, 64x4 128/256, 32x32 512/1024, 32x2x2 64/128, 10x10 68/100. 12x12 and 24x8 failed pipeline creation on the 4060 ("Not enough memory resources") and stored 96/144 and 128/192 on the 780M. In the title's shader archive three programs were wrong this way, all 32x2 sky ambient-map compute passes. 1-D groups are not affected. The wave tests we looked at (wave64_tests.rs, lower_tests.rs) use 1-D groups, so they would not show it.

What fixed it for us. A groupshared ticket, used only for console-lane programs in groups larger than one host wave. Zero a counter, barrier, each full host wave's first lane takes a block of wave-size ids with an atomic add, the partial wave takes the last block, and the console id is base + lane. 221 compute programs in the archive take it.

Caveats. The numbers come from our own fork. For this repo we only read the code; we did not build it, and we did not test a discrete Radeon GPU. Separately, wave_base adds a constant 32 per host wave. If a group size is not a multiple of 32 and the short wave takes its ticket before a full one, later ids can pass the group size. The form we settled on avoids that: each wave does atomicAdd(counter, WaveActiveCountBits(true)) and its lanes use base + WavePrefixCountBits(true) (DXIL opcode 135, dx.op.waveAllOp).

<!-- greyfinch-sync:DexNom/VIctory:comment:7180022071 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/22#issuecomment-7180022071). Originally posted by [j-fuxa](https://github.com/j-fuxa) on 2026-11-26T01:41:07Z. --- **Console thread ids for console wave32 programs in 2-D/3-D groups** Not about the partial-dispatch change itself. It is posted here because it sits beside `wave_base` / `halves` in `crates/victory-shader/src/emit/lower.rs` (main at 64bd58f5). **What we found.** `thread_id` (and the fallback at the end of `console_thread`) builds the console flat thread id as `waveReadLaneFirst(flattenedThreadIdInGroup)` rounded down to the wave size, plus the lane index. The comment above it calls this a bijection "while each host wave holds a wave-aligned run of flat ids". On the 32-lane hosts we tried, that does not hold for 2-D groups. An RTX 4060 Laptop and a Radeon 780M both fill them with rows of 24+ threads taken from 16x2 tiles. `wave_base` already avoids this ("NVIDIA's 8 x 8 groups"), but only when `halves` is set (`wave == 32 && native.wave64`). A console wave32 program that uses console lanes, in a group larger than one host wave, still takes the rounding path. **Evidence.** A compute program that stores each thread's console id, built with the old rounding. Ids stored out of total, identical on both GPUs: 32x2 32/64, 32x8 128/256, 64x4 128/256, 32x32 512/1024, 32x2x2 64/128, 10x10 68/100. 12x12 and 24x8 failed pipeline creation on the 4060 ("Not enough memory resources") and stored 96/144 and 128/192 on the 780M. In the title's shader archive three programs were wrong this way, all 32x2 sky ambient-map compute passes. 1-D groups are not affected. The wave tests we looked at (`wave64_tests.rs`, `lower_tests.rs`) use 1-D groups, so they would not show it. **What fixed it for us.** A groupshared ticket, used only for console-lane programs in groups larger than one host wave. Zero a counter, barrier, each full host wave's first lane takes a block of wave-size ids with an atomic add, the partial wave takes the last block, and the console id is base + lane. 221 compute programs in the archive take it. **Caveats.** The numbers come from our own fork. For this repo we only read the code; we did not build it, and we did not test a discrete Radeon GPU. Separately, `wave_base` adds a constant 32 per host wave. If a group size is not a multiple of 32 and the short wave takes its ticket before a full one, later ids can pass the group size. The form we settled on avoids that: each wave does `atomicAdd(counter, WaveActiveCountBits(true))` and its lanes use `base + WavePrefixCountBits(true)` (DXIL opcode 135, `dx.op.waveAllOp`).
Artking175 commented 2026-11-26 05:22:33 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by Artking175 on 2026-11-26T05:22:33Z.


I tested the multidimensional console-wave32 report on RayTime main 64bd58f with an RTX 2060 (Turing, driver 531.41, Windows 10, Agility 1.614.1). The synthetic shader uses v_readlane_b32 so it takes the console-lane path. It atomically increments one counter per computed flat console thread ID and checks for duplicate, missing and out-of-range IDs.

All ten geometries produced exactly one increment per expected ID with no writes into the padding. That includes 32×2, 32×8, 32×32, 64×4, 8×8, 32×2×2, 10×10, 12×12, 24×8 and a 64×1 control. Each shader validated and created a hardware PSO. I could not reproduce the collision on this Turing setup. The RTX 4060 Laptop and Radeon 780M results remain a separate hardware case.

<!-- greyfinch-sync:DexNom/VIctory:comment:7183429182 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/22#issuecomment-7183429182). Originally posted by [Artking175](https://github.com/Artking175) on 2026-11-26T05:22:33Z. --- I tested the multidimensional console-wave32 report on RayTime main `64bd58f` with an RTX 2060 (Turing, driver 531.41, Windows 10, Agility 1.614.1). The synthetic shader uses `v_readlane_b32` so it takes the console-lane path. It atomically increments one counter per computed flat console thread ID and checks for duplicate, missing and out-of-range IDs. All ten geometries produced exactly one increment per expected ID with no writes into the padding. That includes 32×2, 32×8, 32×32, 64×4, 8×8, 32×2×2, 10×10, 12×12, 24×8 and a 64×1 control. Each shader validated and created a hardware PSO. I could not reproduce the collision on this Turing setup. The RTX 4060 Laptop and Radeon 780M results remain a separate hardware case.
andrewDoing commented 2026-11-26 23:04:31 +00:00 (Migrated from github.com)

Imported from DexNom/VIctory. Originally posted by andrewDoing on 2026-11-26T23:04:31Z.


Independent physical RTX 5070 verification at 92897d2: required Windows SDK DXIL validation and actual PSO creation, asserted the shader PSV minimum/maximum wave size was 32, and executed one wave64 console group for all 65 count settings 0–64. All 4,160 GPU output DWORDs matched expected active-lane popcounts or inactive zero; count 0 means unrestricted. No title Box16/Box32 captures or gameplay were tested.

Verification was AI-assisted with GPT-6.2 Astra.

<!-- greyfinch-sync:DexNom/VIctory:comment:7205231615 --> Imported from [DexNom/VIctory](https://github.com/DexNom/VIctory/pull/22#issuecomment-7205231615). Originally posted by [andrewDoing](https://github.com/andrewDoing) on 2026-11-26T23:04:31Z. --- Independent physical RTX 5070 verification at `92897d2`: required Windows SDK DXIL validation and actual PSO creation, asserted the shader PSV minimum/maximum wave size was 32, and executed one wave64 console group for all 65 count settings 0–64. All 4,160 GPU output DWORDs matched expected active-lane popcounts or inactive zero; count 0 means unrestricted. No title Box16/Box32 captures or gameplay were tested. Verification was AI-assisted with GPT-6.2 Astra.
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/22:upstream-pr/22'
git switch 'upstream-pr/22'

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/22'
git switch 'upstream-pr/22'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/22'
git switch 'upstream-pr/22'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/22'
git switch 'main'
git merge --squash 'upstream-pr/22'
git switch 'main'
git merge --ff-only 'upstream-pr/22'
git switch 'main'
git merge 'upstream-pr/22'
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
DexNom/VIctory!22
No description provided.