Skip to content

leonida-shader: guard 32-lane host tests by the adapter's wave width - #2964

Open
aznohonza wants to merge 4 commits into
ProjectLeonida:mainfrom
aznohonza:gpu/warp-wave-guards
Open

aznohonza wants to merge 4 commits into
ProjectLeonida:mainfrom
aznohonza:gpu/warp-wave-guards

Conversation

@aznohonza

Copy link
Copy Markdown
Contributor

Re-created from the original #2920. aznohonza/mandy-contrib was made private at 21:41 UTC on 2026-12-01, which detached the fork and permanently closed its pull requests; GitHub refuses to reopen them (422 state cannot be changed). Same branch, same head 00a0681069b64b150fb287f6c8e0ee696e27caea. The original review thread is at #2920.


LEONIDA_WARP=1 makes Host::new(false) return the software adapter, so tests that ask for "hardware only" still run on it. The software adapter takes 4-lane waves, while the translator lowers these programs for 32-lane host waves, so eight of the leonida-shader tests fail with that switch.

Host::takes_waves_of(lanes) asks the adapter (D3D12_OPTIONS1) which program wave widths it accepts, and the tests that assume 32 skip a device that does not:

  • valu_tests: run_cases_on takes the required width (None keeps the old behaviour). The quadmask and the two cross-wave LDS tests use a 32-lane path, and the whole-wave f64 test checks its own loop.
  • pack_tests: the five host sites guard for 32 and print SKIP: the adapter does not run 32-lane waves.
  • wave64_tests: host_32() is the hardware lookup plus the width check; all 14 sites use it, and the two manual D3D12_OPTIONS1 queries now use the helper.

Verification:

  • cargo xwin check --target x86_64-pc-windows-msvc --workspace --all-targets --locked passes, and -p leonida-shader --tests --features host passes too.
  • This box has no D3D12 device, so the runs themselves were not repeated. A 32-lane adapter runs every test as before; a 4-lane one now skips them with a named reason.
  • No test changes its assertions when it runs; no game data; no new switch.

Claimed in #2570 (RS-WARP-TEST-WAVES). AI-assisted.

The full leonida-shader suite on the software adapter still has four failures on barycentric/rect; they are the DXIL validator refusing the shader (#2864), not wave width. With #2864's commit on this head the crate is 415 passed, 0 failed, 5 ignored on WARP.

The software adapter runs 4-lane waves, so the tests that lower for the
card's 32 fail under LEONIDA_WARP=1 even when they ask for "hardware":
that switch makes Host::new(false) return WARP too. Ask the made host
whether it takes waves of 32 and skip it otherwise.

`run_cases_on` takes the required width; the quadmask and the two
cross-wave LDS tests use a 32-lane path, and the whole-wave f64 test
checks its own loop. The pack tests and the wave64 helpers guard their
host; the two manual OPTIONS1 queries now use `takes_waves_of`.

Verified by compiling the crate and the workspace for
x86_64-pc-windows-msvc; this box has no D3D12 device, so the runs
themselves were not repeated.

AI-assisted: yes
KelboLive's review of ProjectLeonida#2920: two `host_32()` sites still returned
silently, and `takes_waves_of` no longer asked whether the adapter has
wave operations at all (the old manual check did). Both now say their
reason, and the query includes `WaveOps`.

AI-assisted: yes

@KelboLive KelboLive 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.

Identical to #2920 (00a068106), which I reviewed — the guard shape is right (32/32 here, 4/4 on WARP, Arc 16..32 still runs), and merge-tree against current main is clean. No re-review needed; the two nits from there are non-blocking: two sites still skip silently (wave64_tests.rs:1358, :1954), and takes_waves_of drops the WaveOps check the old block had.

@merzleckeier

Copy link
Copy Markdown
Contributor

The wave-width guard admits the physical readbacks and skips the four-lane fixture.

I tested 00a0681069b64b150fb287f6c8e0ee696e27caea integrated onto main c4ca5761508f136c5530482093bb3053b0bad4fa, using Wine 11.22 / VKD3D-Proton 3.1.0. The pack, scalar quad and partial-dispatch selections each completed on RTX 4070 SUPER (620.73.4) and AMD Raphael (RADV 26.3.1).

  • On the physical adapters, OPTIONS1 reported WaveOps and ranges of 32–32 and 32–64, respectively. All 11 guard requests per adapter admitted the tests. Both adapters passed the packed group ID and LDS checks and read back the partial-dispatch counts 45, 1, 33, 0. The main controls also passed.
  • For a negative control I replaced only the min/max fields with 4–4 after the successful real OPTIONS1 query. All 11 requests per adapter declined the guarded tests. In these runs libtest still reported them as passed, while the tests logged their early skips.

The observed source on this head also requires waves.WaveOps.as_bool() in takes_waves_of. The injected range exercises the width branch on physical devices. Native WARP was outside this fixture. AI-assisted, independently verified against the raw results.

@aznohonza

Copy link
Copy Markdown
Contributor Author

Thanks — the device matrix matches what the guard is for.

On the two nits: I think they are from the earlier head. At 00a068106 both sites print the named skip (wave64_tests.rs:1358 and :1954 carry eprintln!("no SM 6.6 device that runs 32-lane waves; not run")), and takes_waves_of (emit/host.rs:155) requires waves.WaveOps.as_bool() before the width range. That was a06018f3e, included in the head you reviewed. Nothing else changed on this branch.

AI-assisted.

@ammonium231

Copy link
Copy Markdown
Contributor

RTX 3090 / 621.47, 00a0681 merged onto main 5d06e47 (hardware waves 32..32): cargo test -p leonida-shader --locked is 420 passed, 0 failed, 5 ignored on both trees. 32-lane hardware cases ran. WARP 32-lane cases now skip, and they didn't run on main either.

@imShangLi

Copy link
Copy Markdown
Contributor

VERIFY-2964 — Linux, Fedora 45, Rust 1.98.1 (the pinned toolchain), no GPU device, no game files

Verdict: MIXED. The change is a clean, correct refactor that I reviewed statically and found sound — it removes a real panic path and unifies four inconsistent adapter guards behind one method. But every file it touches is #[cfg(... windows ...)], so neither the new method nor any of its tests compile or run on Linux; the repository's own red_green.py returns "no red" here and I have no runtime evidence for it. This is a static review only.

Head 00a0681069b64b150fb287f6c8e0ee696e27caea, base the current main (origin/main 8422def759cda12c89f918438eeb8d53dd5972a6), merge base 60f7dcd904cfc5874a1da62c4297a14e62bca74a, 4 files, +151/−83:

  • d3d12/crates/leonida-shader/src/emit/host.rs (+19/−0)
  • d3d12/crates/leonida-shader/src/emit/pack_tests.rs (+20/−0)
  • d3d12/crates/leonida-shader/src/emit/valu_tests.rs (+71/−22)
  • d3d12/crates/leonida-shader/src/emit/wave64_tests.rs (+41/−61)

1. What it changes

It adds one method to the host D3D12 adapter and routes every 32-lane host test through it.

In host.rs it adds the reusable query (the heart of the change):

/// Whether this adapter runs programs of `lanes`-lane waves: it must do
/// wave operations at all. The software adapter runs 4, so a test that
/// assumes the card's 32 asks first.
pub(super) fn takes_waves_of(&self, lanes: u32) -> bool {
    let mut waves = D3D12_FEATURE_DATA_D3D12_OPTIONS1::default();
    let known = unsafe { self.device.CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, ...) }.is_ok();
    known
        && waves.WaveOps.as_bool()
        && (waves.WaveLaneCountMin..=waves.WaveLaneCountMax).contains(&lanes)
}

Before, the same idea was done four different ways inline in the tests, and not all of them were safe:

  • wave64_tests.rs's both_host_waves_observe_the_lds_flag_after_the_join called CheckFeatureSupport(...).expect("query host wave sizes") — a panic if the feature query fails — then checked WaveLaneCountMax != 32.
  • a_first_lane_read_of_a_wave_alike_sum_under_a_wave_alike_loop did a different inline query checking only (WaveLaneCountMin..=WaveLaneCountMax).contains(&32).
  • valu_tests.rs's run_cases_on had a single ran == 0 escape hatch that only covered "hardware-only, no hardware", not a width mismatch.

The pull request deletes both inline CheckFeatureSupport blocks (and their now-unneeded use windows::...D3D12_OPTIONS1 imports), adds a lanes: Option<u32> parameter to run_cases_on with run_cases/run_cases_32 wrappers, and makes the skip non-fatal:

if let Some(lanes) = lanes && !host.takes_waves_of(lanes) {
    eprintln!("{label}: the adapter does not run {lanes}-lane waves; skipped");
    continue;
}
...
if ran == 0 {
    if let Some(lanes) = lanes { eprintln!("no SM 6.6 device that runs {lanes}-lane waves; not run"); return; }
    ...
}

pack_tests.rs gets the same if !host.takes_waves_of(32) { eprintln!("SKIP: ..."); return; } guard in its five Host::new(false) tests. wave64_tests.rs introduces a host_32() helper and switches ~14 tests from Host::new(false) to it.

2. The new test checks the property that matters

This is a test-only change plus one production helper; there is no new assertion that fails on main. The property it adds is: a test that assumes the card's 32-lane waves must ask the adapter first, and skip rather than run wrong or panic. That property is only observable on Windows with a non-32-lane adapter (e.g. a software adapter that runs 4-lane waves) or when the feature query fails. The concrete defects it removes are the .expect("query host wave sizes") panic and the panic!("{label}: compute_pipeline failed") that a WARP pipeline creation of a WaveSize(32) program would hit (the code's own comment says "WARP does not support fixed WaveSize(32) on SM 6.6"). I could not execute any of this on Linux — Host::new needs a D3D12 device and takes_waves_of needs CheckFeatureSupport, neither of which exists off Windows.

3. What the tests do here

python3 -I scripts/red_green.py pr2964 --no-fetch --crate leonida-shader --work-dir .../rg-2964 (verdict no red, exit 1):

side crate suite result
red (base origin/main + this PR's tests only) 252 passed, 0 failed, 2 ignored
green (origin/main + this PR merged) 252 passed, 0 failed, 2 ignored
base origin/main on its own 252 passed, 0 failed, 2 ignored

Nothing failed on either side and no test moved red→green, because none of the four changed files is compiled on Linux: emit/mod.rs gates them all off.

#[cfg(all(windows, any(test, feature = "host")))]  pub mod host;
#[cfg(all(test, windows))]   mod pack_tests;
#[cfg(all(test, windows))]   mod valu_tests;
#[cfg(all(test, windows))]   mod wave64_tests;

So the crate's Linux suite is byte-for-byte unaffected by this pull request, and the red/green tool has nothing to discriminate. That "252 on both" is a true statement about Linux, but it is not a verification of this PR — it is the absence of one.

4. Any failure I saw, and why it is not this pull request

No failure attributable to this pull request. Two things I want to state plainly so they are not misread:

  • The pull request's own branch head (00a06810, a merge of origin/main into gpu/warp-wave-guards) runs 246 Linux tests, not 252, because that branch predates ~6 Linux tests that main has since gained. red_green.py tests against current main (where the green side is 252), so this is a stale-branch artifact, not a regression the PR causes.
  • source_hash_tests (the shared-CARGO_TARGET_DIR trap in the brief) never appeared: I gave this run its own --work-dir, and both sides ran in one worktree with one target dir as the tool intends.

5. What I did not check

  • A GPU or any D3D12 device. No hardware, no WARP, no software adapter. Every test this PR touches is Windows-only and was not executed here.
  • Windows, and therefore the actual behaviour of the change. I never compiled the PR for Windows. I did not type-check takes_waves_of or the rewritten run_cases_on/host_32 — on Linux these files are not compiled at all, so a syntax or type error in them would not be caught by any Linux build. My "it is correct" is a reading of the diff, not a compiler's.
  • The panics it claims to remove. I did not reproduce the .expect("query host wave sizes") panic or the WARP compute_pipeline panic, nor confirm the new guards prevent them — that needs a Windows box with a non-32-lane adapter.
  • A specific driver or the shader corpus. Not applicable to this PR and not run.
  • The GPU (run_gpu_tests.py) or Wine/Proton (run_wine_tests.py) suites. Not run; they are Windows/Wine paths.

Net: on static review this meets the repository's bar — it fixes the root cause (one shared query instead of stacked inline guards), removes a panic, keeps the code simple and modular, and adds no workaround. I just could not run it here.

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.

5 participants