Skip to content

shader: support 32-lane host wave execution for console wave64 comput… - #3301

Open
AdvaitPalve11 wants to merge 1 commit into
Marvisak:mainfrom
AdvaitPalve11:feat/shader-wave32-compatibility
Open

AdvaitPalve11 wants to merge 1 commit into
Marvisak:mainfrom
AdvaitPalve11:feat/shader-wave32-compatibility

Conversation

@AdvaitPalve11

Copy link
Copy Markdown
Contributor

…e shaders

Xbox Series X|S consoles (AMD RDNA 2) frequently run compute shaders in Wave64 mode (wave64: true). In the host DXIL container emission:

  • container::psv set MinimumWaveLaneCount and MaximumWaveLaneCount strictly to (64, 64).
  • Shader::finish emitted DXIL entry-point tag 11 (kDxilWaveSizeTag) with 64.

On PC hardware with 32-lane execution units (NVIDIA GeForce RTX 20/30/40/50 series and Intel Arc), D3D12 CreateComputePipelineState unconditionally rejects pipelines requiring WaveSize(64) with 0x80070057 (E_INVALIDARG) because WaveLaneCountMax is 32.

Fix this by:

  1. Setting PSV0 runtime info MinimumWaveLaneCount to 32.min(wave_size) and MaximumWaveLaneCount to wave_size, exposing the [32, 64] range to D3D12 runtime validators.
  2. Clamping tag 11 entry-point wave size metadata to 32.min(n) so 32-lane hardware adapters accept compute PSOs while preserving valid lane sizing.
  3. Clamping wave stride to 32.min(wave_size) when reconstructing flat thread IDs in lower::thread_id, ensuring consecutive 32-lane host warps (e.g. lanes 32..63 in warp 1) receive non-overlapping, contiguous thread IDs (base & !31) + lane.
  4. Updating synthetic test annotations for WaveSize(64) execution on hardware devices.

…e shaders

Xbox Series X|S consoles (AMD RDNA 2) frequently run compute shaders in
Wave64 mode (wave64: true). In the host DXIL container emission:
- container::psv set MinimumWaveLaneCount and MaximumWaveLaneCount
  strictly to (64, 64).
- Shader::finish emitted DXIL entry-point tag 11 (kDxilWaveSizeTag)
  with 64.

On PC hardware with 32-lane execution units (NVIDIA GeForce RTX 20/30/40/50
series and Intel Arc), D3D12 CreateComputePipelineState unconditionally
rejects pipelines requiring WaveSize(64) with 0x80070057 (E_INVALIDARG)
because WaveLaneCountMax is 32.

Fix this by:
1. Setting PSV0 runtime info MinimumWaveLaneCount to 32.min(wave_size)
   and MaximumWaveLaneCount to wave_size, exposing the [32, 64] range
   to D3D12 runtime validators.
2. Clamping tag 11 entry-point wave size metadata to 32.min(n) so 32-lane
   hardware adapters accept compute PSOs while preserving valid lane sizing.
3. Clamping wave stride to 32.min(wave_size) when reconstructing flat
   thread IDs in lower::thread_id, ensuring consecutive 32-lane host
   warps (e.g. lanes 32..63 in warp 1) receive non-overlapping, contiguous
   thread IDs (base & !31) + lane.
4. Updating synthetic test annotations for WaveSize(64) execution on
   hardware devices.

@AurumCarlos AurumCarlos left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the pipelines get created, but I don't think the shaders stay correct.

  • The lowering still assumes 64 host lanes per console wave. Programs with wave_size = 64 are lowered with console-lane semantics (console_lanes: 64-lane EXEC/VCC masks, ballots and cross-lane reads, and thread_id built from waveReadLaneFirst + lane index). Declaring WaveSize(32) lets the driver split each console wave into two independent host waves, so every cross-lane op sees only half the wave, silently. That's why 64-lane programs are refused on 32-lane hosts today, and why the wave64-on-32 work (#3179, #189/#192, issue #2688) pairs or widens waves instead. Clamping thread_id's stride hides the symptom in one place but not in the masks.
  • It also changes AMD. Tag 11 is now 32 for every wave64 program, so RDNA hosts that ran them natively at 64 lanes would run them split too.
  • PSV and the entry tag disagree: PSV says [32, 64] while tag 11 says exactly 32. The test only got a comment change, so nothing checks a wave64 program's results on a 32-lane adapter.

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran local verification on Windows 11 x64 (RTX 5090 + dxil.dll validator):

  • cargo test -p victory-shader --lib emit::synthetic_tests:: -- --test-threads=1 --skip gathers_at_a_level_match_the_hardware: 8 passed, 2 failed — both Wave64 permute tests fail DXIL validation:
    • emit::synthetic_tests::wave64_permutes_check_exec_within_each_half
    • emit::synthetic_tests::wave64_permutes_stay_within_each_32_lane_half
    • Exact error: DXIL container mismatch for 'PSVRuntimeInfo' between 'PSV0' part (WaveSize=32) and DXIL module (MinimumExpectedWaveLaneCount: 32, MaximumExpectedWaveLaneCount: 64) — container.rs writes (min=32, max=64) into PSV0 while shader.rs writes single-value WaveSize(32) into DXIL metadata (note: wave-size ranges [WaveSize(min, max)] require SM 6.8 dx.entryPoints tag 23, not SM 6.6 tag 11).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I tested exact fbbca42 and 63bcca43 with a synthetic console Wave64 shader that broadcasts the thread ID from lane 8 and lane 40. Each dispatch stores a result for all 64 threads. Verified app-local Agility 1.620.2/WARP 1.0.22 and dxil.dll 1.9.2609.5, three fresh runs per revision.

  • 63bcca43: 64/64 correct for each lane in all three runs.
  • Exact PR head: the validator rejects the container before pipeline creation. The single-value wave-size tag requests 32 while the PSV range is 32–64. It reports a PSVRuntimeInfo mismatch in all three runs. Microsoft SM 6.6 wave-size metadata
  • Diagnostic control only, with both PSV limits set to the same 32 as the tag: validation and execution succeed, but each case returns only 32/64 correct. The guest lane-8 read is the direct control: the first half broadcasts 8 and the second half broadcasts 40. Lane 8 is a valid index in both physical waves.

The opt-in regression 96c7b78 is the test alone on this PR. The metadata-only control is local. To preserve guest Wave64 behavior on a Wave32 device, the lowering needs to share values across the two halves or decline the shaders that require that exchange. #1890 contains a related split-wave path and independent Wave32 hardware evidence. Strict shader Clippy and policy passed for the regression code.

Please retain the test's Git author if you reuse it, or add Co-authored-by: andrewpozdnakov7-jpg <andrewpozdnakov7-jpg@users.noreply.github.com> if folding it into another commit. AI-assisted with Codex.

@zed6000

zed6000 commented Nov 26, 2026

Copy link
Copy Markdown

The same mismatch shows up on the title's own shaders. Census of the whole shaders.rpf (victory translate --validate --list, the Windows SDK 10.0.26100 dxil.dll), this PR merged onto main 63bcca4, compared program by program:

  • 383 compute programs that validate on main fail on this PR, all with DXIL container mismatch for 'PSVRuntimeInfo' between 'PSV0' part. No program goes the other way.
  • These are the programs lower.rs gives a WaveSize because they depend on the console's lane layout (console_lanes), or because they are one wave with LDS. So a 32-lane host wave would also change their results, as the 32-of-64 control above shows.

AMD RDNA hosts run 64-lane waves, so there the clamp only removes programs that main already handles.

The repository's own tests on an RX 7900 XTX (driver 32.0.32029.2010): cargo test -p victory-shader --lib on this PR merged onto main gives 299 passed, 3 failed. The failures are ds_bpermute_wave64_preserves_32_lane_half, wave64_permutes_check_exec_within_each_half and wave64_permutes_stay_within_each_32_lane_half, each with the same PSVRuntimeInfo mismatch (WaveSize=32 against an expected lane count of 32 to 64). On main (with only #2936 merged, which does not touch this code) all 302 pass.

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes based on static audit and local verification against origin/main (63bcca43) on Windows x64 (RTX 5090 + dxil.dll and WARP):

Blocking issues

  1. [P1] DXIL metadata and PSV0 wave-size bounds contradict each other (fails DXIL validation):
    • crates/victory-shader/src/emit/container.rs:199 writes PSV0 MinimumWaveLaneCount / MaximumWaveLaneCount as (32.min(n), n) ((32, 64) for wave_size = 64), whereas crates/victory-shader/src/emit/shader.rs:885 writes SM 6.6 entry-point tag 11 (kDxilWaveSizeTag) with a single scalar 32.min(n) (32).
    • Running the shader test suite locally on both VICTORY_WARP=0 and VICTORY_WARP=1 fails dxil.dll validation (0 passed, 3 failed):
      • emit::lower::tests::ds_bpermute_wave64_preserves_32_lane_half
      • emit::synthetic_tests::wave64_permutes_check_exec_within_each_half
      • emit::synthetic_tests::wave64_permutes_stay_within_each_32_lane_half
      • Error: DXIL container mismatch for 'PSVRuntimeInfo' between 'PSV0' part:('... WaveSize=32 ...') and DXIL module:('... MinimumExpectedWaveLaneCount: 32\n MaximumExpectedWaveLaneCount: 64 ...').
    • In addition, clamping tag 11 unconditionally to 32 forces Wave64-capable hardware onto split 32-lane waves as well.
  2. [P1] Clamping thread_id stride does not preserve Wave64 guest semantics across split 32-lane host waves:
    • Even if PSV0 and DXIL metadata both declared 32 lanes, only adjusting thread_id in crates/victory-shader/src/emit/lower.rs:2937 leaves cross-lane and 64-lane mask operations operating only on a single 32-lane physical wave: lane_bit (lower.rs:2644), numeric EXEC/VCC masks (lower.rs:1843), s_bcnt1_i32_b64 (lower.rs:3720), v_mbcnt_lo/v_mbcnt_hi (lower.rs:7794), v_readfirstlane_b32 (lower.rs:6650), v_readlane_b32/v_writelane_b32 (lower.rs:6688), wave::sections reductions/prefix sums (wave.rs:131, lower.rs:1245), and barrier-free intra-wave LDS communication between lanes 0..31 and 32..63 (lower.rs:566, 3380, 3436, 3531).

Additional note

  • [P2] crates/victory-shader/src/emit/synthetic_tests.rs:407 silently skips any host.compute_pipeline(&shader) failure, and the existing wave64_permutes_* tests only verify intra-half behavior rather than cross-half (0..31 <-> 32..63) communication on 32-lane devices.

Synthetic tests only; no game data used.

@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the victory-shader library suite at fbbca42 on an NVIDIA Blackwell desktop part:

System

  • GPU: NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only, 16 GB), driver 32.0.16.2124
  • CPU: Intel Core i5-12400F, 64 GB RAM
  • OS: Windows 11 Pro build 26200 x64
  • Toolchain: Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5 (shared env)
  • Build: debug; VICTORY_D3D12_ADAPTER=NVIDIA

Results

  • cargo test -p victory-shader --lib -- --test-threads=1: aborted with 0xc0000005 STATUS_ACCESS_VIOLATION in emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index, before any test result: line.
  • cargo test -p victory-shader --lib -- --test-threads=1 --skip heap_direct_texture_reads_mark_their_heap_index: 298 passed, 3 failed, 3 ignored, 1 filtered out (exit 101). The three failures were a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros and gathers_at_a_level_match_the_hardware.

What this adds
The thread has a synthetic Wave64 broadcast test on this PR head and a title-wide census, but no report from an RTX 5070 Ti. The crashing test is the one documented in issue #2571 as killing the process on a real GPU. I re-ran the three failing tests individually on unmodified main 63bcca4 with the same adapter and all three fail there too (0 passed, 1 failed each), so I do not attribute them to this PR. The Wave64 compute PSO path itself was not exercised by these tests.

Not tested
The synthetic Wave64 broadcast and title shaders from the thread's reports, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used.

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.

7 participants