Skip to content

Shaders: cover a partial Wave32 in the exit-mask regression - #17

Merged
r4tedx merged 2 commits into
r4tedx:shader/wave-per-groupfrom
mohammadallami75-ops:tests/wave32-partial-exit-mask
Nov 25, 2026
Merged

r4tedx merged 2 commits into
r4tedx:shader/wave-per-groupfrom
mohammadallami75-ops:tests/wave32-partial-exit-mask

Conversation

@mohammadallami75-ops

Copy link
Copy Markdown

Problem

A Wave32 shader that assembles an exit mask across a divergent loop could count only the bit its own thread observed. The fork already fixes that by using console control flow for joined masks that are read as numbers. This PR extends the existing Wave32 fixture to cover a 48-thread group, where all 32 threads in the first wave must return 32 and all 16 in the trailing wave must return 16. The change is test-only.

Hardware verification

Windows 11, GeForce RTX 2080 SUPER (driver 621.01, Wave32), three groups per case, synthetic code only. Both revisions passed DXIL validation. The CPU reference checks every lane after GPU readback.

Threads per group Before 05c7cbb Fixed c734600
32 0/96 correct 96/96 correct
48 0/144 correct 144/144 correct
64 0/192 correct 192/192 correct

The old translation returned 1 throughout. A separate DXC cs_6_6 control used [WaveSize(32)], [numthreads(48,1,1)], and a bounded 48-iteration sum of WaveActiveCountBits(lane == i), with lane from SV_GroupIndex. It returned 32 and 16 as expected on all 144 reads with the same dispatch and readback harness on both revisions.

The shader crate suite reported 165 passed, zero failed, and one ignored. The new test uses adapters that can run native Wave32 and needs no compiler at runtime. The earlier WARP partial-wave result remains inconclusive. Game behavior and frame rate were unmeasured.

Refs Marvisak#1498. Thanks to r4tedx for the broadened joined-mask implementation and existing Wave32 fixture, and to andrewpozdnakov7-jpg for identifying the partial-wave hardware check.

AI-assisted.

Reuse the divergent-loop fixture in 48-thread groups and check all lane outputs against a CPU reference. This covers the trailing 16-thread wave from Marvisak#1498.

AI-assisted.

@r4tedx r4tedx left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the 48-thread case. The expected values check out: with Victory's contiguous Wave32 layout each group stores 32 copies of 32 then 16 copies of 16 at group * 48 + thread, so three groups give 144 values, matching the CPU reference and the readback size. cargo check/clippy -p victory-shader --tests, rustfmt and git diff --check against c734600 all pass.

Two changes before I take it in:

  1. Honor software-only mode before opening a device. The new case goes through adapters() and Host::on(), which enumerate and open hardware adapters; the VICTORY_WARP check lives in Host::new(), which this path bypasses. Please add an early skip when VICTORY_WARP=1 for the hardware-only tests in this module, so VICTORY_WARP=1 cargo test -p victory-shader split_tests never touches a hardware adapter (split_tests.rs ~1351, host.rs ~101).
  2. Require a positive Wave32 result. Host::target() returns Target::ANY when the feature query fails or WaveOps is unavailable, and ANY.runs(32) is true, so on such an adapter the test reaches pipeline creation and panics. Gate it on a successful query that reports WaveOps and a wave-size range containing 32 (split_tests.rs ~1363, host.rs ~168).

Verification note: on WARP (forced through Host::new(true) in a scratch copy) the reported range was 4..=4, so the new 48-thread dispatch was skipped and its early return counted as ok; the 31 existing cases that fail on WARP fail the same way on the base. The new case is therefore unverified on hardware from our side. Synthetic test only; no title data used.

AI-assisted.

Skip hardware enumeration in split tests when VICTORY_WARP=1. Require an explicit D3D12 wave-operation range containing 32 for the partial-wave fixture, while retaining the permissive target fallback for existing callers.

AI-assisted.
@mohammadallami75-ops

Copy link
Copy Markdown
Author

Thanks for the review. Both changes are in d96a6cb.

  • Every hardware adapter loop in split_tests checks VICTORY_WARP=1 before calling DXGI. With that flag set, the original head a921a56 still dispatched the 48-thread fixture on the RTX 2080 SUPER. The updated split suite reported 36 passed with the hardware paths explicitly skipped.
  • The partial Wave32 case now requires a successful D3D12 feature query, WaveOps support and a reported range that contains 32. The general Host::target() fallback remains available to existing callers.

In normal hardware mode the RTX 2080 SUPER (driver 621.01) returned all 144 expected values across three groups, with 32 for the first 32 lanes and 16 for the trailing 16 in each group. The full shader suite passed 165 tests with one ignored. Shader-test Clippy, formatting for both edited files, git diff --check and the asset policy also passed.

These are synthetic checks. I exercised the positive Wave32 path on the RTX. The failed-query path was verified by code inspection. Game behavior and frame rate remain unmeasured.

AI-assisted.

@r4tedx r4tedx left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for d96a6cb. Both requested changes are in:

  • hardware_adapters() returns no adapters when VICTORY_WARP=1, before any DXGI enumeration, and all six hardware loops in split_tests.rs now go through it, so a WARP-only run no longer creates a hardware device.
  • The partial Wave32 case is gated on Host::reported_target(), which is None unless the device reports wave operations, so Target::ANY no longer lets it run without a reported 32-lane wave. target() keeps its old behaviour for other callers.

Two optional notes:

  • The comment at the gate says WARP can miscount a partial wave, but WARP never reaches that loop because adapters() filters out software adapters. It may read better as "skipped where the device reports no 32-lane wave".
  • On a device reporting 32..64, asserting wave_size(&cs.dxil) == Some(32) (as in_half_lane_reads_match_the_console_on_every_adapter does) would confirm the case runs as a native Wave32.

Neither blocks this. Approving the code; not merged yet. Reviewed by reading the code only: no tests were run here and no title data was used.

AI-assisted.

@r4tedx
r4tedx merged commit 6551f22 into r4tedx:shader/wave-per-group Nov 25, 2026
1 check passed
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.

2 participants