Skip to content

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

Open
davi713albano-coder wants to merge 1 commit into
DexNom:mainfrom
davi713albano-coder:dexnom/partial-dispatch-wave32
Open

davi713albano-coder wants to merge 1 commit into
DexNom:mainfrom
davi713albano-coder:dexnom/partial-dispatch-wave32

Conversation

@davi713albano-coder

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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.

notquiteog added a commit to notquiteog/victory-nvidia that referenced this pull request Nov 26, 2026
… as the first uncompleted op (DexNom#22) (by FictionHub)

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@j-fuxa

j-fuxa commented Nov 26, 2026

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants