Fix whole-wave min reduction over a partial wave (WaveActive* recognition) #1847

Closed
llegate26 wants to merge 6 commits from upstream-pr/1857 into main
llegate26 commented 2026-11-24 21:58:07 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by llegate26 on 2026-11-24T21:58:07Z.


What is in it

  • Recognise the whole-wave reduction idiom (seed v_cndmask_b32 + 3× DPP8 xor 1/2/4 + DPP16 row_mirror + v_permlanex16 + v_readlane 32/0) and emit WaveActiveMin/WaveActiveMax/WaveActiveBitOr over the launched lanes, suppressing only the within-half DPP steps.
  • Keeps the v_readlane lane 32 + op + lane 0 steps that combine the two 32-lane halves of a wave64 (cross-half).
  • Adds gpu_wave64_ps_partial_wave_min (synthetic, no game data) and negative tests for the recogniser.

Tested

  • hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA RTX 5070 Ti, Windows 11, Rust 1.100.0, debug (cargo test profile).
  • cargo test --workspace -- --test-threads=4: 1060 passed, 4 failed, 26 ignored. The 4 failures are fuzz_validate_and_gpu_* failing with CreateComputePipelineState: 0x8007000E (out of memory) — pre-existing, unrelated to this change.

Regression run

  • Not run: scripts/smoke.ps1 needs a real title (no title data in this environment).

Not tested

  • The retail smoke (scripts/smoke.ps1) on a real title.
  • Full retail GTA VI (out of scope; no game data).

AI use

  • DeepSeek Harness (an AI coding agent): diagnosed the bug, wrote the recognition + WaveActive* emission, and wrote and ran the synthetic tests.
<!-- greyfinch-sync:ivall/xcl:issue:5481019049 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857). Originally posted by [llegate26](https://github.com/llegate26) on 2026-11-24T21:58:07Z. --- <!-- Recognise the whole-wave reduction idiom and emit `WaveActiveMin`/`Max`/`BitOr` over the launched lanes, so a `v_min_u32` reduction over a partial wave returns the true minimum instead of 0 (the DPP/permlane/readlane steps read unlaunched lanes as 0, not the identity). --> **What is in it** - Recognise the whole-wave reduction idiom (seed `v_cndmask_b32` + 3× DPP8 xor 1/2/4 + DPP16 row_mirror + `v_permlanex16` + `v_readlane` 32/0) and emit `WaveActiveMin`/`WaveActiveMax`/`WaveActiveBitOr` over the launched lanes, suppressing only the within-half DPP steps. - Keeps the `v_readlane` lane 32 + op + lane 0 steps that combine the two 32-lane halves of a wave64 (cross-half). - Adds `gpu_wave64_ps_partial_wave_min` (synthetic, no game data) and negative tests for the recogniser. **Tested** - hardware (GPU + driver, CPU), Rust version, debug / release: NVIDIA RTX 5070 Ti, Windows 11, Rust 1.100.0, debug (cargo test profile). - `cargo test --workspace -- --test-threads=4`: 1060 passed, 4 failed, 26 ignored. The 4 failures are `fuzz_validate_and_gpu_*` failing with `CreateComputePipelineState: 0x8007000E` (out of memory) — pre-existing, unrelated to this change. **Regression run** - Not run: `scripts/smoke.ps1` needs a real title (no title data in this environment). **Not tested** - The retail smoke (`scripts/smoke.ps1`) on a real title. - Full retail GTA VI (out of scope; no game data). **AI use** - DeepSeek Harness (an AI coding agent): diagnosed the bug, wrote the recognition + `WaveActive*` emission, and wrote and ran the synthetic tests.
upipibi commented 2026-11-24 23:08:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-24T22:07:07Z.


Checked on Ampere: RTX 3070 8 GB (32-lane waves, so wave64 compute is split over two host waves), driver 616.56, Windows 11, debug.

gpu_wave64_ps_partial_wave_min and gpu_wave64_ps_whole_wave_reductions pass on ae53d84.

A regression in split-wave64 compute. recognize_whole_wave_reductions runs for every program, not only graphics. In a wave64 compute program on a 32-lane GPU, WaveActiveMin covers one 32-lane host wave. The v_readlane …, 32 step it skips is what joined the two halves. I ran your whole_wave_reduce idiom as a 64-thread wave64 compute program: seed 1000 - tid, every lane in the mask, so the minimum (937) is in lane 63, and every lane stores s40:

Tree Lanes 0..31 Lanes 32..63
base b9b6ea6 937 937
ae53d84 969 969

969 is the minimum of lanes 0..31 only. A wave64 PS on these GPUs has no populated upper half (upper_lanes), so the PS tests can't show this. Limiting the recognition to that case, or skipping it when the console wave is split (runner::split_wave64() / the emitter's x64 mode), would keep compute correct.

Test (add next to gpu_wave64_ps_partial_wave_min)
#[test]
fn review_wave64_cs_whole_wave_min_spans_both_halves() {
    if !gpu_ready() {
        return;
    }
    use super::{dxc, CsInterface};
    let code = program_of(&[
        ins("V_SUB_NC_U32", "ENC_VOP2", &[("VDST", 13), ("SRC0", 255), ("VSRC1", 0)], Some(1000)), // v13 = 1000 - tid
        ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 18), ("SSRC0", 126)], None),                          // s[18:19] = exec
        whole_wave_reduce("V_MIN_U32", 193, 40),
        ins("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 130), ("VSRC1", 0)], None),       // v1 = tid * 4
        ins("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 7), ("SRC0", 0), ("VSRC1", 1)], None),           // v7 = s0 + tid*4
        ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 5), ("SRC0", 40)], None),                           // v5 = s40
        ins("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 7), ("DATA", 5), ("SADDR", 0x7D)], None),
    ]);
    let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 2, tgid: [false, false, false], tg_size: false, tid_components: 1 };
    let o = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() });
    let t = translate(&code, &o).unwrap();
    assert!(t.complete(), "{:?}", t.unsupported_why);
    let dxil = dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl));
    let base = 0x100usize;
    let mut io = vec![0u32; 128];
    io[0] = base as u32;
    let out = runner::dispatch(&dxil, [1, 1, 1], &io, &vec![0u32; (base + 64 * 4) / 4]).unwrap();
    let got: Vec<u32> = (0..64).map(|tid| out[(base + tid * 4) / 4]).collect();
    eprintln!("split={} WaveActive in HLSL={} lanes 0..31: {:?}, lanes 32..63: {:?}", runner::split_wave64(), t.hlsl.contains("WaveActiveMin"), &got[..4], &got[32..36]);
    assert!(got.iter().all(|&v| v == 937), "whole-wave min: {got:?}");
}

AI-assisted (Claude Code). Synthetic tests only.

<!-- greyfinch-sync:ivall/xcl:comment:7145826405 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7145826405). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-24T22:07:07Z. --- Checked on Ampere: RTX 3070 8 GB (32-lane waves, so wave64 compute is split over two host waves), driver 616.56, Windows 11, debug. `gpu_wave64_ps_partial_wave_min` and `gpu_wave64_ps_whole_wave_reductions` pass on `ae53d84`. **A regression in split-wave64 compute.** `recognize_whole_wave_reductions` runs for every program, not only graphics. In a wave64 compute program on a 32-lane GPU, `WaveActiveMin` covers one 32-lane host wave. The `v_readlane …, 32` step it skips is what joined the two halves. I ran your `whole_wave_reduce` idiom as a 64-thread wave64 compute program: seed `1000 - tid`, every lane in the mask, so the minimum (937) is in lane 63, and every lane stores `s40`: | Tree | Lanes 0..31 | Lanes 32..63 | |---|---|---| | base `b9b6ea6` | 937 | 937 | | `ae53d84` | **969** | **969** | 969 is the minimum of lanes 0..31 only. A wave64 PS on these GPUs has no populated upper half (`upper_lanes`), so the PS tests can't show this. Limiting the recognition to that case, or skipping it when the console wave is split (`runner::split_wave64()` / the emitter's x64 mode), would keep compute correct. <details><summary>Test (add next to <code>gpu_wave64_ps_partial_wave_min</code>)</summary> ```rust #[test] fn review_wave64_cs_whole_wave_min_spans_both_halves() { if !gpu_ready() { return; } use super::{dxc, CsInterface}; let code = program_of(&[ ins("V_SUB_NC_U32", "ENC_VOP2", &[("VDST", 13), ("SRC0", 255), ("VSRC1", 0)], Some(1000)), // v13 = 1000 - tid ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 18), ("SSRC0", 126)], None), // s[18:19] = exec whole_wave_reduce("V_MIN_U32", 193, 40), ins("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 130), ("VSRC1", 0)], None), // v1 = tid * 4 ins("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 7), ("SRC0", 0), ("VSRC1", 1)], None), // v7 = s0 + tid*4 ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 5), ("SRC0", 40)], None), // v5 = s40 ins("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 7), ("DATA", 5), ("SADDR", 0x7D)], None), ]); let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 2, tgid: [false, false, false], tg_size: false, tid_components: 1 }; let o = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() }); let t = translate(&code, &o).unwrap(); assert!(t.complete(), "{:?}", t.unsupported_why); let dxil = dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl)); let base = 0x100usize; let mut io = vec![0u32; 128]; io[0] = base as u32; let out = runner::dispatch(&dxil, [1, 1, 1], &io, &vec![0u32; (base + 64 * 4) / 4]).unwrap(); let got: Vec<u32> = (0..64).map(|tid| out[(base + tid * 4) / 4]).collect(); eprintln!("split={} WaveActive in HLSL={} lanes 0..31: {:?}, lanes 32..63: {:?}", runner::split_wave64(), t.hlsl.contains("WaveActiveMin"), &got[..4], &got[32..36]); assert!(got.iter().all(|&v| v == 937), "whole-wave min: {got:?}"); } ``` </details> AI-assisted (Claude Code). Synthetic tests only.
Anon64 commented 2026-11-24 23:08:15 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Anon64 on 2026-11-24T22:21:15Z.


Regression run for this PR: head ae53d84, based on main b9b6ea6. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, XCL_NETWORK=0, A pressed every 4 s from 20 s, scripts/smoke.ps1 on a retail title for 60 s, back to back with the main run.

main b9b6ea6:

xcl-smoke v1
commit: b9b6ea62080cc62fc19e212033372d01c6214e5c
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1496 (PresentX 1496)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 88754 MB

this PR:

xcl-smoke v1
commit: ae53d8435f346dbe66d47a78bd647060fe74eea9
gpu: NVIDIA GeForce RTX 3060
title: retail-title
seconds: 60
exit: 0x0
frames shown: 1523 (PresentX 1523)
presents per 2 s (last 3): 51 3 24
device removals: 0
crashes: 0
peak commit: 65273 MB

No device removals or crashes; 102 % of main's frames, 74 % of its peak commit.

Peak commit on b9b6ea6 is mostly the pipeline preload's DXC compiles on this machine (#1035, fixed on later main by #1321), and it varies a lot from run to run.

Not tested: the whole suite; whether the title reaches the changed reductions in these 60 s.

Written with Claude Code (Claude Opus 5.5) from runs on this machine.

<!-- greyfinch-sync:ivall/xcl:comment:7146125305 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7146125305). Originally posted by [Anon64](https://github.com/Anon64) on 2026-11-24T22:21:15Z. --- Regression run for this PR: head `ae53d84`, based on `main` `b9b6ea6`. RTX 3060 12 GB (581.80, wave32), Windows 11 26200, release, `XCL_NETWORK=0`, A pressed every 4 s from 20 s, `scripts/smoke.ps1` on a retail title for 60 s, back to back with the `main` run. main `b9b6ea6`: ``` xcl-smoke v1 commit: b9b6ea62080cc62fc19e212033372d01c6214e5c gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1496 (PresentX 1496) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 88754 MB ``` this PR: ``` xcl-smoke v1 commit: ae53d8435f346dbe66d47a78bd647060fe74eea9 gpu: NVIDIA GeForce RTX 3060 title: retail-title seconds: 60 exit: 0x0 frames shown: 1523 (PresentX 1523) presents per 2 s (last 3): 51 3 24 device removals: 0 crashes: 0 peak commit: 65273 MB ``` No device removals or crashes; 102 % of main's frames, 74 % of its peak commit. Peak commit on `b9b6ea6` is mostly the pipeline preload's DXC compiles on this machine (#1035, fixed on later `main` by #1321), and it varies a lot from run to run. **Not tested:** the whole suite; whether the title reaches the changed reductions in these 60 s. Written with Claude Code (Claude Opus 5.5) from runs on this machine.
WebIdentity1 commented 2026-11-24 23:08:34 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by WebIdentity1 on 2026-11-24T22:51:12Z.


Scoped fix for the split-wave64 compute regression that @upipibi found on #1857, verified on an RTX 3090 at exact head ae53d8435f346dbe66d47a78bd647060fe74eea9. I adapted their public fixture and kept the patch on this author-owned PR.

Tested — native Windows 10 19045, RTX 3090 driver 591.74, Rust 1.98.1 MSVC, XCL_ADAPTER=3090; direct DXIL and forced split unset. Public synthetic shader only.

  • The same gpu_wave64_cs_whole_wave_min_spans_both_halves test on the unmodified head: 0 passed / 1 failed, adapter printed NVIDIA GeForce RTX 3090, split=true, WaveActiveMin=true; all 64 lanes read 969 instead of 937. The intrinsic sees only the first host wave32; the suppressed readlane steps had joined both halves.
  • With the local guard, that test passed 1/0, split=true, WaveActiveMin=false, and all 64 lanes read 937. The three gpu_wave64_ps_ controls passed 3/0, including the PR's partial-wave pixel minimum of 2. The rewrite remains enabled there.
  • cargo build --locked --workspace: exit 0 on both snapshots. cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output: control 889 passed / 2 failed / 42 ignored, fix 890 / 1 / 42, across 20 targets with six explicit SKIPPED lines each. The common failure is the existing gpu_clamp_and_omod_per_instruction on this driver; the extra control failure is this new test. No fix-only failure.
  • Both 295-file source snapshots matched SHA-256 manifests before and after the Windows runs. The guard matches Em::x64()'s mode predicate, so the original cross-half sequence stays intact only where a console wave spans two hardware waves.

No commit or competing PR from me; please incorporate the small guard and regression if useful:

Two-file patch (40 insertions, one deletion)
diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs
index f36cf65..a19931d 100644
--- a/crates/xcl/src/gpu/recomp/mod.rs
+++ b/crates/xcl/src/gpu/recomp/mod.rs
@@ -1559,7 +1559,15 @@ pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> {
         }
     }
     let mut em = emit::Em::new(opt.clone());
-    let (reductions, skip) = recognize_whole_wave_reductions(&insts);
+    // A split wave64 compute/mesh/geometry wave spans two host wave32s. WaveActive*
+    // only reduces one half, while the original readlane steps join both halves.
+    let split_x64 = opt.wave64 && opt.split_wave64
+        && matches!(opt.mode, Mode::Kernel | Mode::Compute(_) | Mode::Mesh(_) | Mode::Geometry(_));
+    let (reductions, skip) = if split_x64 {
+        (BTreeMap::new(), BTreeSet::new())
+    } else {
+        recognize_whole_wave_reductions(&insts)
+    };
     em.reductions = reductions;
     em.skip = skip;
     em.configure_round_modes(&insts, branches == 0);
diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs
index 27a8a9f..a59abbc 100644
--- a/crates/xcl/src/gpu/recomp/tests.rs
+++ b/crates/xcl/src/gpu/recomp/tests.rs
@@ -2285,6 +2285,37 @@ fn gpu_wave64_ps_partial_wave_min() {
     }
 }
 
+/// A reduction over a wave64 compute program must include both wave32 halves when the
+/// adapter runs the console wave in the split form. Reproducer from @upipibi on #1857.
+#[test]
+fn gpu_wave64_cs_whole_wave_min_spans_both_halves() {
+    if !gpu_ready() {
+        return;
+    }
+    use super::{dxc, CsInterface};
+    let code = program_of(&[
+        ins("V_SUB_NC_U32", "ENC_VOP2", &[("VDST", 13), ("SRC0", 255), ("VSRC1", 0)], Some(1000)),
+        ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 18), ("SSRC0", 126)], None),
+        whole_wave_reduce("V_MIN_U32", 193, 40),
+        ins("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 130), ("VSRC1", 0)], None),
+        ins("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 7), ("SRC0", 0), ("VSRC1", 1)], None),
+        ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 5), ("SRC0", 40)], None),
+        ins("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 7), ("DATA", 5), ("SADDR", 0x7D)], None),
+    ]);
+    let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 2, tgid: [false, false, false], tg_size: false, tid_components: 1 };
+    let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() });
+    let t = translate(&code, &opt).unwrap();
+    assert!(t.complete(), "{:?}", t.unsupported_why);
+    let dxil = dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl));
+    let base = 0x100usize;
+    let mut io = vec![0u32; 128];
+    io[0] = base as u32;
+    let out = runner::dispatch(&dxil, [1, 1, 1], &io, &vec![0u32; (base + 64 * 4) / 4]).unwrap();
+    let got: Vec<u32> = (0..64).map(|tid| out[(base + tid * 4) / 4]).collect();
+    eprintln!("adapter={} split={} WaveActiveMin={} lanes 0..31: {:?}, lanes 32..63: {:?}", runner::adapter().unwrap(), opt.split_wave64, t.hlsl.contains("WaveActiveMin"), &got[..4], &got[32..36]);
+    assert!(got.iter().all(|&v| v == 937), "whole-wave min: {got:?}");
+}
+
 /// SGPR spill slots in lanes 0..47 of a VGPR (`spill_slots`) in a wave64 PS: slots ≥ 32 do
 /// not exist in a 32-lane wave, and a slot in a lane that was not launched is lost in a
 /// partial wave (a primitive's edge). Drawn over the whole target and as a 6-pixel triangle.

Not tested: current-main integration, retail smoke/gameplay, driver compile cost, peak memory, AMD native-wave64, or other reduction idioms. This does not establish merge readiness; the PR description check is still red.

AI use: Codex desktop (GPT-6) adapted @upipibi's fixture, prepared the local patch, ran the Windows tests and drafted this report from the retained logs.

<!-- greyfinch-sync:ivall/xcl:comment:7146720397 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7146720397). Originally posted by [WebIdentity1](https://github.com/WebIdentity1) on 2026-11-24T22:51:12Z. --- **Scoped fix for the split-wave64 compute regression that @upipibi found on #1857, verified on an RTX 3090 at exact head `ae53d8435f346dbe66d47a78bd647060fe74eea9`.** I adapted [their public fixture](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7145826405) and kept the patch on this author-owned PR. **Tested** — native Windows 10 19045, RTX 3090 driver 591.74, Rust 1.98.1 MSVC, `XCL_ADAPTER=3090`; direct DXIL and forced split unset. Public synthetic shader only. - The same `gpu_wave64_cs_whole_wave_min_spans_both_halves` test on the unmodified head: **0 passed / 1 failed**, adapter printed `NVIDIA GeForce RTX 3090`, `split=true`, `WaveActiveMin=true`; all 64 lanes read **969** instead of **937**. The intrinsic sees only the first host wave32; the suppressed readlane steps had joined both halves. - With the local guard, that test passed **1/0**, `split=true`, `WaveActiveMin=false`, and all 64 lanes read **937**. The three `gpu_wave64_ps_` controls passed **3/0**, including the PR's partial-wave pixel minimum of **2**. The rewrite remains enabled there. - `cargo build --locked --workspace`: exit 0 on both snapshots. `cargo test --locked --workspace --no-fail-fast -- --test-threads=4 --show-output`: control **889 passed / 2 failed / 42 ignored**, fix **890 / 1 / 42**, across 20 targets with six explicit `SKIPPED` lines each. The common failure is the existing `gpu_clamp_and_omod_per_instruction` on this driver; the extra control failure is this new test. No fix-only failure. - Both 295-file source snapshots matched SHA-256 manifests before and after the Windows runs. The guard matches `Em::x64()`'s mode predicate, so the original cross-half sequence stays intact only where a console wave spans two hardware waves. No commit or competing PR from me; please incorporate the small guard and regression if useful: <details><summary>Two-file patch (40 insertions, one deletion)</summary> ```diff diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index f36cf65..a19931d 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -1559,7 +1559,15 @@ pub fn translate(code: &[u8], opt: &Options) -> Result<Translation, String> { } } let mut em = emit::Em::new(opt.clone()); - let (reductions, skip) = recognize_whole_wave_reductions(&insts); + // A split wave64 compute/mesh/geometry wave spans two host wave32s. WaveActive* + // only reduces one half, while the original readlane steps join both halves. + let split_x64 = opt.wave64 && opt.split_wave64 + && matches!(opt.mode, Mode::Kernel | Mode::Compute(_) | Mode::Mesh(_) | Mode::Geometry(_)); + let (reductions, skip) = if split_x64 { + (BTreeMap::new(), BTreeSet::new()) + } else { + recognize_whole_wave_reductions(&insts) + }; em.reductions = reductions; em.skip = skip; em.configure_round_modes(&insts, branches == 0); diff --git a/crates/xcl/src/gpu/recomp/tests.rs b/crates/xcl/src/gpu/recomp/tests.rs index 27a8a9f..a59abbc 100644 --- a/crates/xcl/src/gpu/recomp/tests.rs +++ b/crates/xcl/src/gpu/recomp/tests.rs @@ -2285,6 +2285,37 @@ fn gpu_wave64_ps_partial_wave_min() { } } +/// A reduction over a wave64 compute program must include both wave32 halves when the +/// adapter runs the console wave in the split form. Reproducer from @upipibi on #1857. +#[test] +fn gpu_wave64_cs_whole_wave_min_spans_both_halves() { + if !gpu_ready() { + return; + } + use super::{dxc, CsInterface}; + let code = program_of(&[ + ins("V_SUB_NC_U32", "ENC_VOP2", &[("VDST", 13), ("SRC0", 255), ("VSRC1", 0)], Some(1000)), + ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 18), ("SSRC0", 126)], None), + whole_wave_reduce("V_MIN_U32", 193, 40), + ins("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 1), ("SRC0", 130), ("VSRC1", 0)], None), + ins("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 7), ("SRC0", 0), ("VSRC1", 1)], None), + ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 5), ("SRC0", 40)], None), + ins("GLOBAL_STORE_DWORD", "ENC_FLAT_GLBL", &[("ADDR", 7), ("DATA", 5), ("SADDR", 0x7D)], None), + ]); + let cs = CsInterface { threads: [64, 1, 1], user_sgprs: 2, tgid: [false, false, false], tg_size: false, tid_components: 1 }; + let opt = on_gpu(Options { mode: Mode::Compute(cs), wave64: true, ..Default::default() }); + let t = translate(&code, &opt).unwrap(); + assert!(t.complete(), "{:?}", t.unsupported_why); + let dxil = dxc::compile(&t.hlsl, "main", "cs_6_6", &[]).unwrap_or_else(|e| panic!("{e}\n{}", t.hlsl)); + let base = 0x100usize; + let mut io = vec![0u32; 128]; + io[0] = base as u32; + let out = runner::dispatch(&dxil, [1, 1, 1], &io, &vec![0u32; (base + 64 * 4) / 4]).unwrap(); + let got: Vec<u32> = (0..64).map(|tid| out[(base + tid * 4) / 4]).collect(); + eprintln!("adapter={} split={} WaveActiveMin={} lanes 0..31: {:?}, lanes 32..63: {:?}", runner::adapter().unwrap(), opt.split_wave64, t.hlsl.contains("WaveActiveMin"), &got[..4], &got[32..36]); + assert!(got.iter().all(|&v| v == 937), "whole-wave min: {got:?}"); +} + /// SGPR spill slots in lanes 0..47 of a VGPR (`spill_slots`) in a wave64 PS: slots ≥ 32 do /// not exist in a 32-lane wave, and a slot in a lane that was not launched is lost in a /// partial wave (a primitive's edge). Drawn over the whole target and as a 6-pixel triangle. ``` </details> **Not tested:** current-main integration, retail smoke/gameplay, driver compile cost, peak memory, AMD native-wave64, or other reduction idioms. This does not establish merge readiness; the PR description check is still red. **AI use:** Codex desktop (GPT-6) adapted @upipibi's fixture, prepared the local patch, ran the Windows tests and drafted this report from the retained logs.
futurepro62 commented 2026-11-24 23:08:37 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-24T22:41:45Z.


Full-suite run, since this PR has no test report yet. Tested exact head ae53d84 (on its base b9b6ea6).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu: 889 passed, 0 failed, 42 ignored. SKIPPED (no wave64): gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware.
  • The new tests ran and passed: gpu_wave64_ps_partial_wave_min.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4: 890 passed, 0 failed, 42 ignored. SKIPPED: heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • On NVIDIA, --skip leaves out five tests where this PR's base has them. They fail on main 689f2db too, not because of this PR: under XCL_REQUIRE_GPU=mesh, runner::skip_test turns their skips into failures. These are heap_window_out_of_memory_falls_back_to_the_switch_form (#1651) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:ivall/xcl:comment:7146535758 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7146535758). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-24T22:41:45Z. --- Full-suite run, since this PR has no test report yet. Tested exact head `ae53d84` (on its base `b9b6ea6`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 616.64, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed. - `cargo build --workspace`, then `XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu`: **889 passed, 0 failed, 42 ignored**. SKIPPED (no wave64): `gpu_geometry_wave32_prefix_count_over_a_mask`, `gpu_wave32_program_in_wave64_hardware`. - The new tests ran and passed: `gpu_wave64_ps_partial_wave_min`. - Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, `XCL_ADAPTER=radeon`), `cargo test --workspace -- --test-threads=4`: **890 passed, 0 failed, 42 ignored**. SKIPPED: `heap_window_out_of_memory_falls_back_to_the_switch_form` (no heap windows). - On NVIDIA, `--skip` leaves out five tests where this PR's base has them. They fail on main `689f2db` too, not because of this PR: under `XCL_REQUIRE_GPU=mesh`, `runner::skip_test` turns their skips into failures. These are `heap_window_out_of_memory_falls_back_to_the_switch_form` (#1651) and the four `gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu` tests ([follow-up on #1651](https://github.com/xcl-dev/xcl/issues/1651#issuecomment-7146069648)). The AMD run does not set `XCL_REQUIRE_GPU`. **Not tested** - a release build, a game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
DavidM1911 commented 2026-11-25 02:08:48 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T01:28:46Z.


Verification on RTX 3060 Ti (Windows 11): merge conflict with current main — needs a rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7149592053 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7149592053). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-25T01:28:46Z. --- Verification on RTX 3060 Ti (Windows 11): **merge conflict with current `main`** — needs a rebase before it can be tested.
raylitebull commented 2026-11-25 02:09:06 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T02:01:43Z.


CI workflow approved for 762c36e.

Review note on 762c36e: recomp/mod.rs still calls recognize_whole_wave_reductions(&insts) unconditionally, so split-wave64 compute/mesh/geometry dispatches on 32-lane GPUs still hit the cross-half regression pointed out above (missing upper-half contribution). Guarding it when opt.wave64 && opt.split_wave64 && matches!(opt.mode, Mode::Kernel | Mode::Compute(_) | Mode::Mesh(_) | Mode::Geometry(_)), fixing the PR description check, and getting fresh AMD + NVIDIA verification on the updated head are needed before merge.

<!-- greyfinch-sync:ivall/xcl:comment:7150233917 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7150233917). Originally posted by [raylitebull](https://github.com/raylitebull) on 2026-11-25T02:01:43Z. --- `CI` workflow approved for `762c36e`. Review note on `762c36e`: `recomp/mod.rs` still calls `recognize_whole_wave_reductions(&insts)` unconditionally, so split-wave64 compute/mesh/geometry dispatches on 32-lane GPUs still hit the cross-half regression pointed out above (missing upper-half contribution). Guarding it when `opt.wave64 && opt.split_wave64 && matches!(opt.mode, Mode::Kernel | Mode::Compute(_) | Mode::Mesh(_) | Mode::Geometry(_))`, fixing the `PR description` check, and getting fresh **AMD + NVIDIA** verification on the updated head are needed before merge.
upipibi commented 2026-11-25 03:05:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by upipibi on 2026-11-25T02:37:00Z.


Re-checked 762c36e on the RTX 3070 (driver 616.56, 32-lane waves, so the split form): gpu_wave64_ps_partial_wave_min and recognize_rejects_wrong_reduction_variants pass with XCL_DIRECT_DXIL=0 and 1.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ivall/xcl:comment:7150954476 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7150954476). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T02:37:00Z. --- Re-checked `762c36e` on the RTX 3070 (driver 616.56, 32-lane waves, so the split form): `gpu_wave64_ps_partial_wave_min` and `recognize_rejects_wrong_reduction_variants` pass with `XCL_DIRECT_DXIL=0` and `1`. AI-assisted (Claude Code).
DavidM1911 commented 2026-11-26 01:05:40 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T00:34:59Z.


Re-verification on RTX 3060 Ti (Windows 11): still a merge conflict with current main on the new head — needs another rebase before it can be tested.

<!-- greyfinch-sync:ivall/xcl:comment:7178905875 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7178905875). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-26T00:34:59Z. --- Re-verification on RTX 3060 Ti (Windows 11): still a **merge conflict with current `main`** on the new head — needs another rebase before it can be tested.
github-actions[bot] commented 2026-11-30 08:40:27 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-30T08:40:27Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7273200684 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7273200684). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-30T08:40:27Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 07:00:24 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T07:00:24Z.


Triage (#1607) – head 762c36e

Main already fixes this. Commit fb0931d ("Recompiler: rebuild partial-wave graphics reductions") recognizes the same whole-wave min/max/or idiom (identity v_cndmask, DPP8 xor 1/2/4, row_mirror, v_permlanex16, v_readlane 32 and 0), checks the saved-EXEC provenance, and rebuilds it with wave operations over the launched lanes. gpu_wave64_ps_whole_wave_reductions in recomp/tests.rs covers a partial wave. This PR's recognize_whole_wave_reductions also does not check EXEC, and it skips the v_permlanex16 write without checking whether that register is read later. Separately, the description names DeepSeek as the model that wrote the code, and CONTRIBUTING.md does not accept PRs written with it.
Recommendation: close (superseded by main commit fb0931d).

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7303534020 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7303534020). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T07:00:24Z. --- **Triage (#1607)** – head 762c36e Main already fixes this. Commit fb0931d ("Recompiler: rebuild partial-wave graphics reductions") recognizes the same whole-wave min/max/or idiom (identity `v_cndmask`, DPP8 xor 1/2/4, row_mirror, `v_permlanex16`, `v_readlane` 32 and 0), checks the saved-EXEC provenance, and rebuilds it with wave operations over the launched lanes. `gpu_wave64_ps_whole_wave_reductions` in `recomp/tests.rs` covers a partial wave. This PR's `recognize_whole_wave_reductions` also does not check EXEC, and it skips the `v_permlanex16` write without checking whether that register is read later. Separately, the description names DeepSeek as the model that wrote the code, and CONTRIBUTING.md does not accept PRs written with it. Recommendation: close (superseded by main commit fb0931d). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
throny commented 2026-12-01 12:49:25 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by throny on 2026-12-01T12:49:25Z.


Closing as superseded: this change is already on main (fb0931da). main fb0931da graphics_reductions recognises the same cndmask+DPP8 xor steps+row_mirror+permlanex16+readlane 32/0 idiom (min/max/and/or, wave32 and wave64, saved-EXEC provenance) and rebuilds with wave ops; partial-wave GPU tests exist; superset of the PR

Two independent checks found this: Foniass's close list on #1607 and ours against current main. If something here is still missing on main, say so and reopen it, or ask and I will.

AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

<!-- greyfinch-sync:ivall/xcl:comment:7311697983 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1857#issuecomment-7311697983). Originally posted by [throny](https://github.com/throny) on 2026-12-01T12:49:25Z. --- Closing as superseded: this change is already on `main` (fb0931da). main fb0931da graphics_reductions recognises the same cndmask+DPP8 xor steps+row_mirror+permlanex16+readlane 32/0 idiom (min/max/and/or, wave32 and wave64, saved-EXEC provenance) and rebuilds with wave ops; partial-wave GPU tests exist; superset of the PR Two independent checks found this: Foniass's close list on #1607 and ours against current `main`. If something here is still missing on `main`, say so and reopen it, or ask and I will. AI use: Claude Code (Claude Opus 5.5); the per-PR comparison was done by Claude Sonnet 5.5 sub-agents.

Pull request closed

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
xcl-dev/xcl!1847
No description provided.