VS / PS whole-wave reductions as wave operations (partial waves, every GPU) #152

Closed
github-bot wants to merge 4 commits from gh-pr/152/head into gh-pr/152/base
Owner

@⁠Foniass on GitHub · 2026-11-23 16:49 UTC · original
Foniass:nvidia/wave-reductions → main · +1465 −70 · 7 files · 4 commits · closed without merging

Follow-up to #133, as asked there: whole-wave reductions in VS / PS are recognised as a whole and emitted as wave operations.

Problem (every GPU)

  • The reduction: the pack's pixel shaders (and one VS) take a min / max / or over a wave in whole-wave mode. They write the op's identity into the lanes outside a mask, then run three DPP8 steps, row_mirror, v_permlanex16 and v_readlane 32 / 0.
  • What goes wrong: in a partial wave (a triangle edge), the console runs that code in its inactive lanes too, but the PC only runs launched lanes. Reads of the others gave 0, so a min over a partial wave came out 0.
  • Helper lanes: an or over a 3-quad wave with helper lanes in the mask missed them (0x33 instead of 0x37).

Change

  • Matcher (recomp/reductions.rs): it recognises the whole sequence, with these checks:

    • the mask is the saved EXEC (or that ANDed with something);
    • the constant is the op's identity;
    • no branch lands inside;
    • EXEC is restored right after.

    The pack's DPP8 selects aren't xor permutations, so it follows the set of lanes each lane has read and requires whole rows after the mirror. Anything else keeps the old steps.

  • Emitted: xcl_wave_<op>(x, mask) gives the op over the mask's lanes for each 16-lane row of the hardware wave. From those rows, every register (vA, vB, sH, sT) is written as the console leaves it.

    • Pixel shaders: each lane first takes the op over its quad through quad reads, since wave operations skip helper lanes. Afterwards helper lanes take their quad's result, because the console leaves the result in every lane and the helpers feed derivatives. The second part came from review: on the RTX 5070 Ti, WaveActive* returns 0 in helper lanes.
    • Wave32 programs in a 64-lane wave: they use rows 0–1 or 2–3, chosen by xcl_half.
  • Scope: wave64 VS / PS, and also wave32 PS, which has the same reduction and the same partial-wave bug (926 programs). Compute and mesh keep the steps (see below).

  • Switch: XCL_NO_WAVE_REDUCTIONS=1 gives the old translation for comparison.

  • Test runner: draws share one command queue per device instead of making one per draw. gpu_sparse_vram_descriptors_buffers_and_xmem brings up the D3D12.X backend (real::init), whose hooks then sit on the adapter's device, and the per-draw queues made through them were not given back. With several test threads, the draw-heavy tests here ended in E_OUTOFMEMORY at CreateCommandQueue, depending on order.

Census (retail_wave_reductions_census, ignored)

recognised sites (programs) min max or
wave64 VS / PS all 1 082 (436) 325 322 435
wave32 PS all 2 106 (926) 588 588 930
  • #133's lane-32 constants: they are all inside these reductions. 110 of those programs still get the 32-lane form, for their spill slots.
  • retail_wave64_graphics_lane_forms: the native HLSL changes for exactly the 1 362 programs with a reduction; the 25 336 others are byte-identical (per-program digests, checked against XCL_NO_WAVE_REDUCTIONS=1, which reproduces main's digests). The other modes' 32-lane digest stays 09d45ad13eddc30d, and the 32-lane form now differs for 287 programs. DXC compiles all 1 362, with 0 errors.
  • Shader cache: those programs start from a cold DXIL cache once.

Tests (RTX 5070 Ti, 32-lane waves)

  • gpu_ps_partial_wave_reductions: wave64 and wave32; min / max / or over the odd pixels and over whole quads; whole target, 3 quads and 55 pixels. sT, sH, vA and vB of every pixel are checked against a CPU model of the console wave. With the old translation every partial-wave min is 0.
  • gpu_vs_partial_wave_reductions: a wave of 3 vertices.
  • gpu_ps_reduction_result_in_helper_lanes: the result in helper lanes, read through quad_perm; 46 of 54 cases differed before the helper fix.
  • gpu_ps_reductions_in_branches_and_loops: the retail structure (s_wqm, a kill, s_and_saveexec / s_cbranch_execz, a min, an or in a loop) in five shapes.
  • reductions::tests: matcher unit tests, for accepted and rejected variants.
  • Workspace: cargo test --workspace --release with XCL_SAMPLE_RPF: 576 passed, 0 failed (2 no wave64 skips, as on main). Lib tests with XCL_SPLIT_WAVE64=1: 543 passed.
  • Minecraft (NVIDIA): menu and a world render as on main, 60 fps.
  • 64-lane hardware (RX 9070): not run here. The two partial-wave tests would cover wave64 PS in 64-lane waves and the xcl_half path.

Not covered

  • Compute / mesh: they keep the steps. The same reduction is at 4 371 of 4 607 wave32 CS sites, 94 of 1 148 wave64 CS sites and all 17 wave64 MS sites. On a 32-lane GPU a wave64 console wave is two hardware waves there, so the result would need the split form's exchange.
  • Overlap with #134 (masks hold helper lanes): a mask taken from a v_cmp after s_wqm has no helper-lane bits on the PC (WaveActiveBallot), so the quad-read step only helps when the mask is the saved EXEC. Only 10 wave32 PS sites in the pack may take the mask that way. #134 addresses that in general, and the two shouldn't conflict.

🤖 Generated with Claude Code

**@⁠Foniass** on GitHub · 2026-11-23 16:49 UTC · [original](https://github.com/xcl-dev/xcl/pull/152) `Foniass:nvidia/wave-reductions` → `main` · +1465 −70 · 7 files · 4 commits · closed without merging Follow-up to #133, as asked there: whole-wave reductions in VS / PS are recognised as a whole and emitted as wave operations. ### Problem (every GPU) - **The reduction:** the pack's pixel shaders (and one VS) take a min / max / or over a wave in whole-wave mode. They write the op's identity into the lanes outside a mask, then run three DPP8 steps, row_mirror, `v_permlanex16` and `v_readlane` 32 / 0. - **What goes wrong:** in a partial wave (a triangle edge), the console runs that code in its inactive lanes too, but the PC only runs launched lanes. Reads of the others gave 0, so a min over a partial wave came out 0. - **Helper lanes:** an or over a 3-quad wave with helper lanes in the mask missed them (0x33 instead of 0x37). ### Change - **Matcher** (`recomp/reductions.rs`): it recognises the whole sequence, with these checks: - the mask is the saved EXEC (or that ANDed with something); - the constant is the op's identity; - no branch lands inside; - EXEC is restored right after. The pack's DPP8 selects aren't xor permutations, so it follows the set of lanes each lane has read and requires whole rows after the mirror. Anything else keeps the old steps. - **Emitted:** `xcl_wave_<op>(x, mask)` gives the op over the mask's lanes for each 16-lane row of the hardware wave. From those rows, every register (vA, vB, sH, sT) is written as the console leaves it. - **Pixel shaders:** each lane first takes the op over its quad through quad reads, since wave operations skip helper lanes. Afterwards helper lanes take their quad's result, because the console leaves the result in every lane and the helpers feed derivatives. The second part came from review: on the RTX 5070 Ti, `WaveActive*` returns 0 in helper lanes. - **Wave32 programs in a 64-lane wave:** they use rows 0–1 or 2–3, chosen by `xcl_half`. - **Scope:** wave64 VS / PS, and also wave32 PS, which has the same reduction and the same partial-wave bug (926 programs). Compute and mesh keep the steps (see below). - **Switch:** `XCL_NO_WAVE_REDUCTIONS=1` gives the old translation for comparison. - **Test runner:** draws share one command queue per device instead of making one per draw. `gpu_sparse_vram_descriptors_buffers_and_xmem` brings up the D3D12.X backend (`real::init`), whose hooks then sit on the adapter's device, and the per-draw queues made through them were not given back. With several test threads, the draw-heavy tests here ended in E_OUTOFMEMORY at `CreateCommandQueue`, depending on order. ### Census (`retail_wave_reductions_census`, ignored) | | recognised sites (programs) | min | max | or | |---|---|---|---|---| | wave64 VS / PS | all 1 082 (436) | 325 | 322 | 435 | | wave32 PS | all 2 106 (926) | 588 | 588 | 930 | - **#133's lane-32 constants:** they are all inside these reductions. 110 of those programs still get the 32-lane form, for their spill slots. - **`retail_wave64_graphics_lane_forms`:** the native HLSL changes for exactly the 1 362 programs with a reduction; the 25 336 others are byte-identical (per-program digests, checked against `XCL_NO_WAVE_REDUCTIONS=1`, which reproduces `main`'s digests). The other modes' 32-lane digest stays `09d45ad13eddc30d`, and the 32-lane form now differs for 287 programs. DXC compiles all 1 362, with 0 errors. - **Shader cache:** those programs start from a cold DXIL cache once. ### Tests (RTX 5070 Ti, 32-lane waves) - **`gpu_ps_partial_wave_reductions`:** wave64 and wave32; min / max / or over the odd pixels and over whole quads; whole target, 3 quads and 55 pixels. sT, sH, vA and vB of every pixel are checked against a CPU model of the console wave. With the old translation every partial-wave min is 0. - **`gpu_vs_partial_wave_reductions`:** a wave of 3 vertices. - **`gpu_ps_reduction_result_in_helper_lanes`:** the result in helper lanes, read through `quad_perm`; 46 of 54 cases differed before the helper fix. - **`gpu_ps_reductions_in_branches_and_loops`:** the retail structure (`s_wqm`, a kill, `s_and_saveexec` / `s_cbranch_execz`, a min, an or in a loop) in five shapes. - **`reductions::tests`:** matcher unit tests, for accepted and rejected variants. - **Workspace:** `cargo test --workspace --release` with `XCL_SAMPLE_RPF`: 576 passed, 0 failed (2 `no wave64` skips, as on `main`). Lib tests with `XCL_SPLIT_WAVE64=1`: 543 passed. - **Minecraft (NVIDIA):** menu and a world render as on `main`, 60 fps. - **64-lane hardware (RX 9070):** not run here. The two partial-wave tests would cover wave64 PS in 64-lane waves and the `xcl_half` path. ### Not covered - **Compute / mesh:** they keep the steps. The same reduction is at 4 371 of 4 607 wave32 CS sites, 94 of 1 148 wave64 CS sites and all 17 wave64 MS sites. On a 32-lane GPU a wave64 console wave is two hardware waves there, so the result would need the split form's exchange. - **Overlap with #134** (masks hold helper lanes): a mask taken from a `v_cmp` after `s_wqm` has no helper-lane bits on the PC (`WaveActiveBallot`), so the quad-read step only helps when the mask is the saved EXEC. Only 10 wave32 PS sites in the pack may take the mask that way. #134 addresses that in general, and the two shouldn't conflict. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The console runs whole-wave code in every lane of the wave, inactive ones
too; the PC runs only the lanes it launched. The pack's whole-wave code in
VS / PS is the compiler's form of a wave reduction (min_u32, max_u32,
or_b32): s_or_saveexec -1, v_cndmask of x / the op's identity by a mask
within the saved EXEC, three DPP8 steps, row_mirror, v_permlanex16, then
v_readlane 32 and 0 (wave64) or 0 (wave32), EXEC restored. In a partial
wave (a primitive's edge, the last vertices of a draw) the steps read lanes
that were never launched: 0 on NVIDIA, so a min gave 0, on every GPU and at
both wave sizes.

reductions.rs recognises that sequence as a whole: exactly those
instructions (s_waitcnt / s_nop / v_nop between them), the mask the saved
EXEC or s_and of it, the constant the op's identity, DPP8 selects that with
the row_mirror take in the whole row (followed as the set of lanes each
lane has read; the pack's selects are not lane-xor permutations: [2,2,0,0,
6,6,4,4] and [4,4,4,4,0,0,0,0] after the pair step), no branch into it,
EXEC restored right after. Anything else is left as it was.

The emitter replaces it, from the v_cndmask to the last v_readlane, with
xcl_wave_<op>(x, mask): the op over the mask's lanes per 16-lane row of the
hardware wave (WaveActiveMin(row == k ? q : identity)), and from the rows
every value the steps leave - sH, sT, vA (wave64: the wave's in lanes
0..31, the upper half's in 32..63) and vB (the other row's) - in every lane.
Lanes that were not launched are never in the mask; wave operations leave
out helper lanes, so in a PS q is first the op over the quad through quad
reads (a mask from EXEC after s_wqm holds helper lanes). A 64-lane wave of
a wave32 program holds two console waves: rows 0-1 / 2-3 by xcl_half.

The form is the same at every wave size, so it also changes the HLSL of
GPUs with 64-lane waves, for VS / PS with a reduction only. Reads inside a
recognised reduction no longer need upper_lanes' 32-lane form. Compute-like
modes keep the steps (a wave64 console wave is two hardware waves there on
32-lane GPUs). XCL_NO_WAVE_REDUCTIONS=1 translates each step on its own, as
before.

Tests: reductions::tests (the pack's sequences at both wave sizes and
variants recognised; other identities, masks not within the saved EXEC,
other ops, steps that leave lanes out, other DPP16 controls, permlane16,
other lanes, extra whole-wave instructions, branches into it left alone),
whole_wave_reductions_translate_to_wave_operations (HLSL of every VS / PS
form, DXC), and on the GPU gpu_ps_partial_wave_reductions (wave64 and
wave32; min / max / or over the odd pixels and over the quads' lanes; whole
target, 3 quads, 55 pixels; sT, sH, vA, vB of every pixel against a console
wave of the same lanes) and gpu_vs_partial_wave_reductions (3 vertices).
On an RTX 5070 Ti both GPU tests fail with XCL_NO_WAVE_REDUCTIONS=1: every
partial-wave min (sT, vA, vB) is 0, the or over the quads' lanes of 3 quads
misses two helper pixels, the VS min and vB are 0. Full waves are right
either way.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
retail_wave_reductions_census (ignored) lists the pack's whole-wave
sections by mode and wave size, recognised by op or left by reason:
- wave64 VS / PS: all 1 082 sites in 436 programs (min 325, max 322, or
  435 sites); every lane >= 32 read as a constant (#133) is inside one, 110
  of those programs still get the 32-lane form for spill slots.
- wave32 PS: all 2 106 sites in 926 programs (min 588, max 588, or 930).
- compute / mesh, where the translation keeps the steps: the same form at
  4 371 of 4 607 wave32 CS sites, 94 of 1 148 wave64 CS, 17 of 17 wave64 MS;
  the rest are sums (add u32 / f32 / f16, prefix sums with row shifts), a
  float min / max with its identity from a VGPR, v_and_b32.

retail_wave64_graphics_lane_forms also compiles the native form of every
VS / PS with a recognised reduction, and XCL_FORMS_LIST writes each
program's digests. Against XCL_NO_WAVE_REDUCTIONS=1 (digests ac67db269b7452be
/ 09d45ad13eddc30d, as main) the native HLSL changes for exactly the 1 362
VS / PS with a reduction (436 wave64, 926 wave32; digest 2adc8e0b13d2f20e)
and for no other of the 26 698 programs; the other modes' 32-lane digest is
unchanged; the 32-lane form differs for 287 programs (spill slots, 613
before). DXC compiles all of them.

docs/wave64-on-wave32.md ("Whole-wave reductions") and HANDOFF.md describe
the form, the numbers and what is left.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Wave operations leave helper lanes out; on the RTX 5070 Ti WaveActiveMin / Max
/ BitOr return 0 there. The console leaves the result in every lane, helpers
included, and the helpers' copies feed the derivatives of what is computed
from it (quad_perm, ds_swizzle, implicit-LOD samples: 429 of the retail PS with
a reduction read one after it). The pixel helpers now take each lane's result
through the quad (a helper contributes the op's identity), so every lane of a
quad holds the wave's result.

gpu_ps_reduction_result_in_helper_lanes: sT, vA and vB after a min / max / or,
read by the live pixels through quad_perm, wave64 and wave32, three triangle
shapes (46 of 54 cases differed before). gpu_ps_reductions_in_branches_and_loops:
the retail structure (live pixels saved, s_wqm, a kill, s_and_saveexec /
s_cbranch_execz, a min, an or in a loop) in five shapes. Both came from review.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
draw_on_multi made a command queue and fence for every draw. Once a test has
brought up the D3D12.X backend (gpu_sparse_vram_descriptors_buffers_and_xmem
calls hle::d3d12x::real::init) its hooks are on the device the process gets for
the adapter, and queues made through them were not given back: with the
draw-heavy reduction tests running next to it, CreateCommandQueue failed with
E_OUTOFMEMORY (only with several test threads, depending on order). The draws
now share one queue and fence per device.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:12:51 +00:00
github-bot closed this pull request 2026-11-26 04:12:51 +00:00
Author
Owner

@⁠WarmMilkCodes on GitHub · 2026-11-23 18:56 UTC · original

Tested #152 4ba00d9 merged onto main 956a476 on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): fail – one of the new tests

cargo test --workspace --no-fail-fast -- --test-threads=4: 576 passed, 2 failed (main: 568 / 1). The 8 new tests run; 7 pass. gpu_wave64_ps_whole_wave_reductions fails on main too on this card (the 32-lane PS case, #155).

New failure: gpu_ps_partial_wave_reductions, and only for min_u32:

min_u32 max_u32 or_b32
whole target ok ok ok
3 quads (wave32 / wave64) wrong ok ok
55 pixels (wave32 / wave64) wrong ok ok

Every wrong value is 0, in sT, vA and vB, e.g. wave32, 3 quads, over the odd pixels: min_u32 sT: pixel 2 (lane 4): 0x0, want 0x2 and wave64, 55 pixels: … pixel 38 (lane 0): 0x0, want 0x28. Pixels per wave here: 3 quads → [6], 55 pixels → [31, 24], whole target → 8 × 32.

Since max and or have identity 0, a stray 0 is invisible to them, so this looks like a lane outside the mask (a helper or an unlaunched lane of a partial quad) contributing 0 instead of the identity – probably in the quad step for helper lanes. On this AMD driver, quad reads of those lanes seem to return 0 rather than what the step expects. Full output available.

**@⁠WarmMilkCodes** on GitHub · 2026-11-23 18:56 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7110870999) Tested #152 `4ba00d9` merged onto main `956a476` on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): **fail** – one of the new tests `cargo test --workspace --no-fail-fast -- --test-threads=4`: 576 passed, 2 failed (main: 568 / 1). The 8 new tests run; 7 pass. `gpu_wave64_ps_whole_wave_reductions` fails on main too on this card (the 32-lane PS case, #155). **New failure: `gpu_ps_partial_wave_reductions`**, and only for **min_u32**: | | min_u32 | max_u32 | or_b32 | |---|---|---|---| | whole target | ok | ok | ok | | 3 quads (wave32 / wave64) | **wrong** | ok | ok | | 55 pixels (wave32 / wave64) | **wrong** | ok | ok | Every wrong value is **0**, in sT, vA and vB, e.g. `wave32, 3 quads, over the odd pixels: min_u32 sT: pixel 2 (lane 4): 0x0, want 0x2` and `wave64, 55 pixels: … pixel 38 (lane 0): 0x0, want 0x28`. Pixels per wave here: 3 quads → [6], 55 pixels → [31, 24], whole target → 8 × 32. Since max and or have identity 0, a stray 0 is invisible to them, so this looks like a lane outside the mask (a helper or an unlaunched lane of a partial quad) contributing 0 instead of the identity – probably in the quad step for helper lanes. On this AMD driver, quad reads of those lanes seem to return 0 rather than what the step expects. Full output available.
Author
Owner

@⁠WarmMilkCodes on GitHub · 2026-11-23 19:10 UTC · original

Follow-up on the gpu_ps_partial_wave_reductions failure on RX 6600 XT (RDNA2, driver 32.0.21045.29003): found the cause and a one-line change that makes it pass here.

What happens: the reduction call is not in divergent control flow (checked the dumped HLSL: uint4 t9 = xcl_wave_min_u32(v13, s10, 0u); at top level), but the final step

uint4 h = IsHelperLane() ? (uint4)0xFFFFFFFFu : t;
return min(min(QuadReadLaneAt(h, 0u), QuadReadLaneAt(h, 1u)), min(QuadReadLaneAt(h, 2u), QuadReadLaneAt(h, 3u)));

returns 0 in live lanes whose quad has a helper lane: a live lane's QuadReadLaneAt(h, k) of a helper lane doesn't see the identity the helper set there – plausibly because AMD's compiler leaves whole-quad mode around the WaveActive* results, so the helpers' h is never written. Max and or have identity 0, so only min shows it – exactly the pattern in my earlier comment.

Change tried (in wave_reduction_fn, pixel branch): a live lane keeps its own t, which is already the wave's result; only helper lanes take their quad's:

-        let _ = writeln!(s, "    return {c};\n}}");
+        let _ = writeln!(s, "    uint4 c = {c};\n    return IsHelperLane() ? c : t;\n}}");

Result on RX 6600 XT: gpu_ps_partial_wave_reductions goes from 42 wrong results (every one 0, min only) to pass (1 passed; 0 failed), all shapes, wave32 and wave64, both masks.

Caveat: a helper lane's own copy still comes from quad reads, so on AMD it may still be off – which matters only for derivatives of the result in partly covered quads, and the test checks live pixels only. Not tested on NVIDIA; the change shouldn't alter live lanes there, since t is what c reduces to when no helper interferes.

**@⁠WarmMilkCodes** on GitHub · 2026-11-23 19:10 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7111193210) Follow-up on the `gpu_ps_partial_wave_reductions` failure on RX 6600 XT (RDNA2, driver 32.0.21045.29003): found the cause and a one-line change that makes it pass here. **What happens:** the reduction call is not in divergent control flow (checked the dumped HLSL: `uint4 t9 = xcl_wave_min_u32(v13, s10, 0u);` at top level), but the final step ```hlsl uint4 h = IsHelperLane() ? (uint4)0xFFFFFFFFu : t; return min(min(QuadReadLaneAt(h, 0u), QuadReadLaneAt(h, 1u)), min(QuadReadLaneAt(h, 2u), QuadReadLaneAt(h, 3u))); ``` returns **0** in live lanes whose quad has a helper lane: a live lane's `QuadReadLaneAt(h, k)` of a helper lane doesn't see the identity the helper set there – plausibly because AMD's compiler leaves whole-quad mode around the `WaveActive*` results, so the helpers' `h` is never written. Max and or have identity 0, so only min shows it – exactly the pattern in my earlier comment. **Change tried (in `wave_reduction_fn`, pixel branch):** a live lane keeps its own `t`, which is already the wave's result; only helper lanes take their quad's: ```diff - let _ = writeln!(s, " return {c};\n}}"); + let _ = writeln!(s, " uint4 c = {c};\n return IsHelperLane() ? c : t;\n}}"); ``` **Result on RX 6600 XT:** `gpu_ps_partial_wave_reductions` goes from **42 wrong results** (every one 0, min only) to **pass** (`1 passed; 0 failed`), all shapes, wave32 and wave64, both masks. Caveat: a helper lane's own copy still comes from quad reads, so on AMD it may still be off – which matters only for derivatives of the result in partly covered quads, and the test checks live pixels only. Not tested on NVIDIA; the change shouldn't alter live lanes there, since `t` is what `c` reduces to when no helper interferes.
Author
Owner

@⁠srcamarda on GitHub · 2026-11-23 20:21 UTC · original · edited 2026-11-23 20:35 UTC

Tested on an RX 7800 XT (RDNA3, driver 32.0.32029.2010, Windows 11 26300). This driver runs wave64 PS in 32-lane waves.

  • This PR alone: lib 541 passed, 2 failed: gpu_wave64_ps_whole_wave_reductions (fails on main too; #155 fixes it) and gpu_ps_partial_wave_reductions (new): "42 results wrong".
  • Merged with #155 (one conflict, a comment line in recomp/mod.rs): gpu_wave64_ps_whole_wave_reductions passes, gpu_ps_partial_wave_reductions still fails, 42 results.

The 42 are exactly the min_u32 cases, for wave32 and wave64, 3 quads and 55 pixels, over the odd pixels and over the quads' lanes, and all four results (sT, sH, vA, vB). Every wrong value is 0. max, or and the sum all pass. Examples:

wave32, 3 quads, over the odd pixels: min_u32 vA (wave of pixel 0): 2 pixels wrong, e.g. pixel 2 (lane 4): 0x0, want 0x2
wave32, 55 pixels, over the quads' lanes: min_u32 vB (wave of pixel 38): 12 pixels wrong, e.g. pixel 38 (lane 0): 0x0, want 0x45
wave64, 55 pixels, over the quads' lanes: min_u32 sH …

Edit:
Tested @⁠WarmMilkCodes' one-line change on RDNA3: RX 7800 XT. It fixes gpu_ps_partial_wave_reductions here too.

-        let _ = writeln!(s, "    return {c};\n}}");
+        let _ = writeln!(s, "    uint4 c = {c};\n    return IsHelperLane() ? c : t;\n}}");
gpu_ps_partial_wave_reductions cargo test -p xcl --lib with XCL_SPLIT_WAVE64=1
4ba00d9 as is 42 results wrong (all min_u32, all 0) – –
4ba00d9 + the change pass 542 passed, 1 failed, 20 ignored 543 passed, 0 failed
  • All the reduction tests pass with the change: gpu_ps_partial_wave_reductions, gpu_vs_partial_wave_reductions, gpu_ps_reductions_in_branches_and_loops, whole_wave_reductions_translate_to_wave_operations and the reductions::tests matcher tests.
  • The one plain failure is gpu_wave64_ps_whole_wave_reductions ([2, 928, 2] vs [2, 464, 2]), the 32-lane PS case that fails on main too and is fixed by #155. With XCL_SPLIT_WAVE64=1 it passes, so nothing else fails.
**@⁠srcamarda** on GitHub · 2026-11-23 20:21 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7112950682) · edited 2026-11-23 20:35 UTC Tested on an **RX 7800 XT** (RDNA3, driver 32.0.32029.2010, Windows 11 26300). This driver runs wave64 PS in 32-lane waves. - This PR alone: lib 541 passed, 2 failed: `gpu_wave64_ps_whole_wave_reductions` (fails on `main` too; #155 fixes it) and `gpu_ps_partial_wave_reductions` (new): "42 results wrong". - Merged with #155 (one conflict, a comment line in `recomp/mod.rs`): `gpu_wave64_ps_whole_wave_reductions` passes, **`gpu_ps_partial_wave_reductions` still fails, 42 results**. The 42 are exactly the `min_u32` cases, for wave32 and wave64, 3 quads and 55 pixels, over the odd pixels and over the quads' lanes, and all four results (sT, sH, vA, vB). Every wrong value is 0. max, or and the sum all pass. Examples: ``` wave32, 3 quads, over the odd pixels: min_u32 vA (wave of pixel 0): 2 pixels wrong, e.g. pixel 2 (lane 4): 0x0, want 0x2 wave32, 55 pixels, over the quads' lanes: min_u32 vB (wave of pixel 38): 12 pixels wrong, e.g. pixel 38 (lane 0): 0x0, want 0x45 wave64, 55 pixels, over the quads' lanes: min_u32 sH … ``` Edit: Tested @⁠WarmMilkCodes' one-line change on **RDNA3: RX 7800 XT**. It fixes `gpu_ps_partial_wave_reductions` here too. ```diff - let _ = writeln!(s, " return {c};\n}}"); + let _ = writeln!(s, " uint4 c = {c};\n return IsHelperLane() ? c : t;\n}}"); ``` | | `gpu_ps_partial_wave_reductions` | `cargo test -p xcl --lib` | with `XCL_SPLIT_WAVE64=1` | |---|---|---|---| | `4ba00d9` as is | **42 results wrong** (all `min_u32`, all 0) | – | – | | `4ba00d9` + the change | pass | 542 passed, 1 failed, 20 ignored | **543 passed, 0 failed** | - All the reduction tests pass with the change: `gpu_ps_partial_wave_reductions`, `gpu_vs_partial_wave_reductions`, `gpu_ps_reductions_in_branches_and_loops`, `whole_wave_reductions_translate_to_wave_operations` and the `reductions::tests` matcher tests. - The one plain failure is `gpu_wave64_ps_whole_wave_reductions` (`[2, 928, 2]` vs `[2, 464, 2]`), the 32-lane PS case that fails on `main` too and is fixed by #155. With `XCL_SPLIT_WAVE64=1` it passes, so nothing else fails.
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-23 20:42 UTC · original

@⁠Foniass, a note on the compute side that this PR's "Not covered" names, and an offer.

I measured the same gap (lanes EXEC turns on but the wave never launched) for wave64 compute groups on main 956a476, RTX 5070 Ti, split form. A program that widens EXEC and then runs VALU code only sees the launched lanes:

group s_not_b64 exec, exec then v_cmp_eq_u32 vcc, v0, v0: bits of VCC s_or_saveexec_b64 s, -1 then the same compare v_mov under EXEC = -1, v_readlane of lane 63
40 24 expected, 0 measured 64, 40 7, 7 (an undefined read that happened to be right)
42 22, 0 64, 42 7, 7 (same)
20 44, 0 64, 20 7, 0
10 54, 0 64, 10 7, 0
96, second wave 32, 0 64, 32 7, 0

s_wqm_b64 exec, exec followed by the compare gives 42 instead of 44 in the 42-thread group and 10 instead of 12 in the 10-thread one. Full waves are right. The expected values are the ISA definition, not a console measurement, and the results are the same with XCL_X64_ALL_MASKS=1 and XCL_WAVE64_SPIN=1. I have not run 64-lane hardware.

For compute there is a way that needs no matcher: launch the missing lanes. Declare numthreads rounded up to whole console waves (64 for a 40-thread group, thread ids derived from the index as the split form already does) and start with EXEC = ballot(thread index < the console's thread count). The padding lanes then exist and are inactive, as on the console, so whole-wave code, compares, v_readlane and DPP see them. It costs up to 63 idle threads per group and changes nothing for groups that are already whole waves.

I can send that as a separate PR. It would only touch the compute entry, so it should compose with this one: your reductions keep VS / PS, and a compute reduction would simply run its steps in real lanes. It does nothing for mesh.

Would you rather do the compute part yourself, as the follow-up you describe? If so I will leave it and hand over the tests (24 mask programs in partial groups of 40 / 42 / 20 / 10 / 96 threads, plus the case above). Otherwise I will open the PR and link it here.

AI-assisted (Claude); tested on an RTX 5070 Ti, NVIDIA 610.74.

**@⁠Kalmarv** on GitHub · 2026-11-23 20:42 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7113450434) @⁠Foniass, a note on the compute side that this PR's "Not covered" names, and an offer. I measured the same gap (lanes EXEC turns on but the wave never launched) for wave64 compute groups on main `956a476`, RTX 5070 Ti, split form. A program that widens EXEC and then runs VALU code only sees the launched lanes: | group | `s_not_b64 exec, exec` then `v_cmp_eq_u32 vcc, v0, v0`: bits of VCC | `s_or_saveexec_b64 s, -1` then the same compare | `v_mov` under EXEC = -1, `v_readlane` of lane 63 | |---|---|---|---| | 40 | 24 expected, 0 measured | 64, 40 | 7, 7 (an undefined read that happened to be right) | | 42 | 22, 0 | 64, 42 | 7, 7 (same) | | 20 | 44, 0 | 64, 20 | 7, 0 | | 10 | 54, 0 | 64, 10 | 7, 0 | | 96, second wave | 32, 0 | 64, 32 | 7, 0 | `s_wqm_b64 exec, exec` followed by the compare gives 42 instead of 44 in the 42-thread group and 10 instead of 12 in the 10-thread one. Full waves are right. The expected values are the ISA definition, not a console measurement, and the results are the same with `XCL_X64_ALL_MASKS=1` and `XCL_WAVE64_SPIN=1`. I have not run 64-lane hardware. For compute there is a way that needs no matcher: launch the missing lanes. Declare `numthreads` rounded up to whole console waves (64 for a 40-thread group, thread ids derived from the index as the split form already does) and start with EXEC = ballot(thread index < the console's thread count). The padding lanes then exist and are inactive, as on the console, so whole-wave code, compares, `v_readlane` and DPP see them. It costs up to 63 idle threads per group and changes nothing for groups that are already whole waves. I can send that as a separate PR. It would only touch the compute entry, so it should compose with this one: your reductions keep VS / PS, and a compute reduction would simply run its steps in real lanes. It does nothing for mesh. Would you rather do the compute part yourself, as the follow-up you describe? If so I will leave it and hand over the tests (24 mask programs in partial groups of 40 / 42 / 20 / 10 / 96 threads, plus the case above). Otherwise I will open the PR and link it here. AI-assisted (Claude); tested on an RTX 5070 Ti, NVIDIA 610.74.
Author
Owner

@⁠Kalmarv on GitHub · 2026-11-23 20:59 UTC · original

Linux / Turing run of 4ba00d9 merged onto main 956a476 (merge d1417aa, clean; only HANDOFF.md auto-merged). Ubuntu 24.04, GeForce RTX 2060 (Turing, 32-lane waves), NVIDIA 595.91.07, Wine 11.21 Staging (wow64), vkd3d-proton master 30b0eb9 (relaxed as in #175), DXVK 3.1.1 dxgi; XCL cross-built for x86_64-pc-windows-gnu, release; DXC 1.7.2308. So the D3D12 path is vkd3d-proton → dxil-spirv → NVIDIA Vulkan, which translates the wave, quad and helper-lane operations itself.

gpu::recomp filter, --test-threads=1:

passed failed ignored
main 956a476 160 5 18
this PR merged 169 5 19

No new failures. The new tests pass here: gpu_ps_partial_wave_reductions (including the min_u32 cases that fail on RDNA2/RDNA3 above), gpu_vs_partial_wave_reductions, gpu_ps_reduction_result_in_helper_lanes, gpu_ps_reductions_in_branches_and_loops, whole_wave_reductions_translate_to_wave_operations and the 4 reductions::tests. retail_wave_reductions_census is ignored, needing samples. gpu_wave64_ps_whole_wave_reductions passes as well.

The 5 failures on every build are this stack's memory-window reads, which return zeros (explained in #175), and are the same on main: gpu_memory_windows_above_4_gib, gpu_unified_memory_arena, gpu_mesh_mode_reads_memory_windows, gpu_sparse_vram_descriptors_buffers_and_xmem, gpu_bvh64_intersect_ray_across_memory_windows_and_grazing. The 2 skips on every build are no wave64 (gpu_geometry_*).

So the helper-lane quad reads in the min_u32 final step come out right through dxil-spirv on NVIDIA. That matches the RTX 3090 Windows result: the min_u32 failure looks specific to AMD's driver, not to the HLSL.

Not covered: AMD under Linux (RADV); #155 combined; the e2e binaries; any title.

AI-assisted (Claude Code).

**@⁠Kalmarv** on GitHub · 2026-11-23 20:59 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7113851556) Linux / Turing run of `4ba00d9` **merged onto `main` `956a476`** (merge `d1417aa`, clean; only `HANDOFF.md` auto-merged). Ubuntu 24.04, **GeForce RTX 2060 (Turing, 32-lane waves)**, NVIDIA 595.91.07, Wine 11.21 Staging (wow64), vkd3d-proton `master` 30b0eb9 (relaxed as in #175), DXVK 3.1.1 `dxgi`; XCL cross-built for `x86_64-pc-windows-gnu`, release; DXC 1.7.2308. So the D3D12 path is vkd3d-proton → dxil-spirv → NVIDIA Vulkan, which translates the wave, quad and helper-lane operations itself. `gpu::recomp` filter, `--test-threads=1`: | | passed | failed | ignored | |---|---|---|---| | `main` 956a476 | 160 | 5 | 18 | | this PR merged | 169 | 5 | 19 | No new failures. The new tests pass here: `gpu_ps_partial_wave_reductions` (including the `min_u32` cases that fail on RDNA2/RDNA3 above), `gpu_vs_partial_wave_reductions`, `gpu_ps_reduction_result_in_helper_lanes`, `gpu_ps_reductions_in_branches_and_loops`, `whole_wave_reductions_translate_to_wave_operations` and the 4 `reductions::tests`. `retail_wave_reductions_census` is ignored, needing samples. `gpu_wave64_ps_whole_wave_reductions` passes as well. The 5 failures on every build are this stack's memory-window reads, which return zeros (explained in #175), and are the same on `main`: `gpu_memory_windows_above_4_gib`, `gpu_unified_memory_arena`, `gpu_mesh_mode_reads_memory_windows`, `gpu_sparse_vram_descriptors_buffers_and_xmem`, `gpu_bvh64_intersect_ray_across_memory_windows_and_grazing`. The 2 skips on every build are `no wave64` (`gpu_geometry_*`). So the helper-lane quad reads in the `min_u32` final step come out right through dxil-spirv on NVIDIA. That matches the RTX 3090 Windows result: the `min_u32` failure looks specific to AMD's driver, not to the HLSL. **Not covered:** AMD under Linux (RADV); `#155` combined; the e2e binaries; any title. AI-assisted (Claude Code).
Author
Owner

@⁠ic3bear-ai on GitHub · 2026-11-24 00:34 UTC · original

#152 on an RTX 3070: the helper-lane change on NVIDIA, and where the reduction coverage ends

Setup: NVIDIA GeForce RTX 3070 8 GB (driver 616.92, D3D12 wave range 32..32), Ryzen 5 5600X, Windows 11 build 26200, Rust 1.95.0, debug build, DXC 1.8.2502.11.

1. The helper-lane change works on NVIDIA. This is the one-line change proposed above for the AMD min_u32 failure, which was untested on NVIDIA. I rebuilt it from the description ("live lanes keep their own t, only helper lanes take the quad result"): uint4 c = <quad op>; return IsHelperLane() ? c : t;.

cargo test --workspace --no-fail-fast -- --test-threads=4 on 4ba00d9 merged locally into main a6f5f7a:

tree passed failed ignored SKIPPED
main a6f5f7a 676 0 41 2
main + #152 + the extra test below 685 1 42 2
the same + the helper-lane change 685 1 42 2
  • All of #152's own tests pass with and without the change, gpu_ps_reduction_result_in_helper_lanes included. #152 as posted passing here agrees with the RTX 3090 result above (same driver).
  • The one failure in both runs is the extra test below (point 2). The extra test has no helper lanes, so it doesn't tell the two variants apart.
  • SKIPPED in all three runs: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • Two small merge conflicts with current main:
    • a comment line in recomp/mod.rs;
    • draw_console_views in recomp/tests.rs, which main added and this PR's draw_console_as touches. I kept both sides; draw_console_views got a wave64 parameter.

2. An extra check, written separately from this PR's code and tests. A GPU test against its own CPU model of the console wave64: the 64 lanes stepped through as the ISA defines each instruction, unlaunched lanes holding the identity. The model is checked against a plain fold over the masked lanes. Source below.

  • Program: the pack's sequence (s_or_saveexec -1, v_cndmask with the identity, DPP8 xor 1/2/4, row_mirror, v_permlanex16, v_readlane 32 / 0), run as a wave64 PS.
  • Draws: whole quads only, so no helper lanes: partial waves of 1, 2, 3, 4 and 8 quads, and half the target.
  • Ops: min_u32 and and (identity −1); max_u32, or and add (identity 0).
  • Masks: every pixel, odd pixels, pixels < 216, none.
wrong pixels (of 4000)
main 392
main + #152 (either variant) 184: only and (160) and add (24)
  • min_u32, max_u32 and or_b32 are exact with #152 in every case above.
  • and and add aren't among the ops #152 recognises, so in a VS / PS they keep the step-by-step translation and stay wrong in partial waves. The commit message says sums keep the old steps in compute; this is the same in a pixel shader. If no title uses them, that's fine. I'm only showing where the coverage ends.
  • On main the identity-0 ops are wrong too, without helper lanes. The description reports or over a 3-quad wave with helper lanes. Here, in a 3-quad wave with whole quads only (lanes 0..11), max_u32, or and add are all wrong on main. On the console, lanes 12..15 pick up the total of lanes 8..15 in the DPP8 steps and pass it to lanes 0..3 through row_mirror. On the PC those lanes don't exist, so lane 0 gets only lanes 0..7. docs/wave64-on-wave32.md says max / or / sum are right in partial waves; #152 fixes max and or.

Not tested:

  • GPUs with 64-lane waves;
  • helper lanes and vertex shaders in the extra test;
  • the helper-lane change as written by its author (I rebuilt it from the description);
  • the retail pack and any game.
The extra test (paste into recomp/tests.rs; it needs the draw_console of this PR)
/// The whole-wave reduction of the retail pixel shaders (`upper_lanes`) with `op`: v13 of the
/// lanes in s[18:19], `identity` (operand code) in the others, DPP8 xor 1 / 2 / 4, row_mirror,
/// the other row through `v_permlanex16`, `v_readlane` 32, `v_readlane` 0 into s`out`.
fn ind_whole_wave_reduction(op: &str, identity: u64, out: u64) -> Vec<u8> {
    let mut c = vec![
        ins("S_OR_SAVEEXEC_B64", "ENC_SOP1", &[("SDST", 30), ("SSRC0", 193)], None),
        ins("S_AND_B64", "ENC_SOP2", &[("SDST", 10), ("SSRC0", 18), ("SSRC1", 30)], None),
        ins("V_CNDMASK_B32", "ENC_VOP3", &[("VDST", 6), ("SRC0", identity), ("SRC1", V + 13), ("SRC2", 10)], None),
    ];
    let names = ["LANE_SEL_0", "LANE_SEL_1", "LANE_SEL_2", "LANE_SEL_3", "LANE_SEL_4", "LANE_SEL_5", "LANE_SEL_6", "LANE_SEL_7"];
    for sel in [[1u64, 0, 3, 2, 5, 4, 7, 6], [2, 3, 0, 1, 6, 7, 4, 5], [4, 5, 6, 7, 0, 1, 2, 3]] {
        let mut f = vec![("VDST", 6u64), ("SRC0", 0xE9), ("VSRC0", 6), ("VSRC1", 6)];
        f.extend(names.iter().copied().zip(sel));
        c.push(ins(op, "VOP2_VOP_DPP8", &f, None));
    }
    c.extend([
        ins(op, "VOP2_VOP_DPP16", &[("VDST", 6), ("SRC0", 0xFA), ("VSRC0", 6), ("VSRC1", 6), ("DPP_CTRL", 0x140), ("ROW_MASK", 0xF), ("BANK_MASK", 0xF)], None),
        ins("V_PERMLANEX16_B32", "ENC_VOP3", &[("VDST", 7), ("SRC0", V + 6), ("SRC1", 128), ("SRC2", 128)], None),
        ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", V + 7), ("VSRC1", 6)], None),
        ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", 10), ("SRC0", V + 6), ("SRC1", 128 + 32)], None),
        ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", 10), ("VSRC1", 6)], None),
        ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", out), ("SRC0", V + 6), ("SRC1", 128)], None),
        ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 126), ("SSRC0", 30)], None),
    ]);
    c.concat()
}

/// `ind_whole_wave_reduction` run on the CPU over a console wave64, lane by lane as the ISA
/// defines each step (independent of the translation): `v13` of the 64 lanes, `mask` the
/// lanes of s[18:19]; EXEC is all ones throughout, so every DPP / permlane source is active.
fn console_whole_wave_reduction(op: fn(u32, u32) -> u32, identity: u32, v13: &[u32; 64], mask: u64) -> u32 {
    let mut v6: [u32; 64] = std::array::from_fn(|l| if mask >> l & 1 == 1 { v13[l] } else { identity });
    // VOP2 DPP: dst = op(src0 of the selected lane, src1 of the lane)
    for x in [1, 2, 4] {
        let o = v6;
        v6 = std::array::from_fn(|l| op(o[(l & !7) | ((l & 7) ^ x)], o[l]));
    }
    let o = v6;
    v6 = std::array::from_fn(|l| op(o[(l & !15) | (15 - (l & 15))], o[l]));
    // v_permlanex16 with selects 0: lane 0 of the other row of the same 32-lane half
    let v7: [u32; 64] = std::array::from_fn(|l| v6[(l & 32) | ((l & 16) ^ 16)]);
    v6 = std::array::from_fn(|l| op(v7[l], v6[l]));
    let s10 = v6[32];
    v6 = std::array::from_fn(|l| op(s10, v6[l]));
    v6[0]
}

/// The retail reduction (`ind_whole_wave_reduction`) in a wave64 PS whose waves are partial – the
/// PC GPU does not launch every lane – compared with a console wave of the same lanes
/// (`console_whole_wave_reduction`). On the console the lanes outside the launched ones exist
/// and hold the identity the whole-wave `v_cndmask` puts there; the DPP8 / row_mirror /
/// `v_permlanex16` steps read them. Each draw covers whole quads only (a corner of the target,
/// the hypotenuse outside it), so no helper lanes take part: 1, 2, 3, 4, 8 quads and half the
/// target. Ops with identity -1 (min_u32, and) and 0 (max_u32, or, add); masks: every pixel,
/// odd pixels, pixels < 216, none. Exports the result's low / high 16 bits.
#[test]
fn gpu_wave64_ps_partial_wave_reductions() {
    use std::collections::BTreeMap;
    if !gpu_ready() {
        return;
    }
    // (name, opcode, identity operand code, identity, CPU op)
    let ops: [(&str, &str, u64, u32, fn(u32, u32) -> u32); 5] = [
        ("min_u32", "V_MIN_U32", 193, u32::MAX, |a, b| a.min(b)),
        ("and", "V_AND_B32", 193, u32::MAX, |a, b| a & b),
        ("max_u32", "V_MAX_U32", 128, 0, |a, b| a.max(b)),
        ("or", "V_OR_B32", 128, 0, |a, b| a | b),
        ("add", "V_ADD_NC_U32", 128, 0, |a, b| a.wrapping_add(b)),
    ];
    // the lanes of s[18:19] (VCC of a compare of v12, the pixel number): (name, compare, pixel predicate)
    let masks: [(&str, Vec<u8>, fn(u32) -> bool); 4] = [
        ("all", ins("V_CMP_LE_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 12)], None), |_| true),
        ("odd", [ins("V_AND_B32", "ENC_VOP2", &[("VDST", 14), ("SRC0", 129), ("VSRC1", 12)], None), ins("V_CMP_NE_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 14)], None)].concat(), |p| p % 2 == 1),
        ("below 216", ins("V_CMP_GT_U32", "ENC_VOPC", &[("SRC0", 255), ("VSRC1", 12)], Some(216)), |p| p < 216),
        ("none", ins("V_CMP_GT_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 12)], None), |_| false),
    ];
    // the corner (x, y) a triangle covers from, to the target's edges
    let corners = [(14.0, 14.0), (12.0, 14.0), (10.0, 14.0), (12.0, 12.0), (8.0, 12.0), (0.0, 8.0)];
    let mut bad = Vec::new();
    let mut checked = 0;
    for (oname, opcode, id_code, identity, op) in ops {
        for (mname, cmp, pred) in &masks {
            let code = program_of(&[
                // v12 = pixel number y·16 + x, v13 = (v12 + 1) | v12 << 20 (bits that differ per pixel, for and / or)
                ins("V_CVT_U32_F32", "ENC_VOP1", &[("VDST", 10), ("SRC0", V + 2)], None),
                ins("V_CVT_U32_F32", "ENC_VOP1", &[("VDST", 11), ("SRC0", V + 3)], None),
                ins("V_LSHL_ADD_U32", "ENC_VOP3", &[("VDST", 12), ("SRC0", V + 11), ("SRC1", 128 + 4), ("SRC2", V + 10)], None),
                ins("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 13), ("SRC0", 129), ("VSRC1", 12)], None),
                ins("V_LSHL_OR_B32", "ENC_VOP3", &[("VDST", 13), ("SRC0", V + 12), ("SRC1", 128 + 20), ("SRC2", V + 13)], None),
                cmp.clone(),
                ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 18), ("SSRC0", 106)], None),
                // the wave: its first lane's pixel number; the lane
                ins("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 62), ("SRC0", V + 12)], None),
                ins("V_MBCNT_LO_U32_B32", "ENC_VOP3", &[("VDST", 15), ("SRC0", 193), ("SRC1", 128)], None),
                ins("V_MBCNT_HI_U32_B32", "ENC_VOP3", &[("VDST", 15), ("SRC0", 193), ("SRC1", V + 15)], None),
                ind_whole_wave_reduction(opcode, id_code, 40),
                ins("V_BFE_U32", "ENC_VOP3", &[("VDST", 20), ("SRC0", 40), ("SRC1", 128), ("SRC2", 128 + 16)], None),
                ins("V_BFE_U32", "ENC_VOP3", &[("VDST", 21), ("SRC0", 40), ("SRC1", 128 + 16), ("SRC2", 128 + 16)], None),
                ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 20), ("SRC0", V + 20)], None),
                ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 21), ("SRC0", V + 21)], None),
                ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 22), ("SRC0", 242)], None),
                ins("V_LSHL_ADD_U32", "ENC_VOP3", &[("VDST", 23), ("SRC0", 62), ("SRC1", 128 + 6), ("SRC2", V + 15)], None),
                ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 23), ("SRC0", V + 23)], None),
                ins("EXP", "ENC_EXP", &[("TGT", 0), ("EN", 0xF), ("VSRC0", 20), ("VSRC1", 21), ("VSRC2", 22), ("VSRC3", 23), ("DONE", 1), ("VM", 1)], None),
            ]);
            for (x, y) in corners {
                let px = draw_console(None, Some(&code), &[[x, y], [x, 48.0], [48.0, y]]);
                // by wave (its first lane's pixel number): (pixel number, lane, result)
                let mut waves: BTreeMap<u32, Vec<(u32, u32, u32)>> = BTreeMap::new();
                for (id, p) in px.iter().enumerate() {
                    let inside = id % 16 >= x as usize && id / 16 >= y as usize;
                    assert_eq!(p[2] == 1.0, inside, "corner ({x},{y}): pixel {id} drawn");
                    if inside {
                        waves.entry(p[3] as u32 >> 6).or_default().push((id as u32, p[3] as u32 & 63, p[0] as u32 | (p[1] as u32) << 16));
                    }
                }
                for (first, w) in &waves {
                    let mut v13 = [0xDEAD_BEEFu32; 64];
                    let mut mask = 0u64;
                    for &(id, lane, _) in w {
                        assert_eq!(v13[lane as usize], 0xDEAD_BEEF, "wave of pixel {first}: lane {lane} twice");
                        v13[lane as usize] = (id + 1) | id << 20;
                        if pred(id) {
                            mask |= 1 << lane;
                        }
                    }
                    let want = console_whole_wave_reduction(op, identity, &v13, mask);
                    // the model against the operation it implements: a fold over the lanes of the mask
                    let fold = (0..64).filter(|l| mask >> l & 1 == 1).fold(identity, |a, l| op(a, v13[l]));
                    assert_eq!(want, fold, "the CPU model of the console wave");
                    for &(id, lane, got) in w {
                        checked += 1;
                        if got != want {
                            bad.push(format!("{oname} / {mname} / corner ({x},{y}): pixel {id} (lane {lane} of a wave of {}) = {got:#x}, console {want:#x}", w.len()));
                        }
                    }
                }
            }
        }
    }
    println!("{checked} pixels checked, {} wrong", bad.len());
    for b in &bad {
        println!("{b}");
    }
    assert!(bad.is_empty(), "{} of {checked} pixels differ from the console wave (listed above), first: {}", bad.len(), bad[0]);
}

Report written with Claude Code (Claude Opus 5.5), from runs on the hardware above. I checked the results before posting.

**@⁠ic3bear-ai** on GitHub · 2026-11-24 00:34 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7118205754) **#152 on an RTX 3070: the helper-lane change on NVIDIA, and where the reduction coverage ends** **Setup:** NVIDIA GeForce RTX 3070 8 GB (driver 616.92, D3D12 wave range 32..32), Ryzen 5 5600X, Windows 11 build 26200, Rust 1.95.0, debug build, DXC 1.8.2502.11. **1. The helper-lane change works on NVIDIA.** This is the one-line change proposed above for the AMD `min_u32` failure, which was untested on NVIDIA. I rebuilt it from the description ("live lanes keep their own `t`, only helper lanes take the quad result"): `uint4 c = <quad op>; return IsHelperLane() ? c : t;`. `cargo test --workspace --no-fail-fast -- --test-threads=4` on `4ba00d9` merged locally into `main` `a6f5f7a`: | tree | passed | failed | ignored | SKIPPED | |---|---|---|---|---| | `main` `a6f5f7a` | 676 | 0 | 41 | 2 | | `main` + #152 + the extra test below | 685 | 1 | 42 | 2 | | the same + the helper-lane change | 685 | 1 | 42 | 2 | - All of #152's own tests pass with and without the change, `gpu_ps_reduction_result_in_helper_lanes` included. #152 as posted passing here agrees with the RTX 3090 result above (same driver). - The one failure in both runs is the extra test below (point 2). The extra test has no helper lanes, so it doesn't tell the two variants apart. - SKIPPED in all three runs: `gpu_geometry_wave32_prefix_count_over_a_mask` and `gpu_wave32_program_in_wave64_hardware` (no wave64). - Two small merge conflicts with current `main`: - a comment line in `recomp/mod.rs`; - `draw_console_views` in `recomp/tests.rs`, which main added and this PR's `draw_console_as` touches. I kept both sides; `draw_console_views` got a `wave64` parameter. **2. An extra check, written separately from this PR's code and tests.** A GPU test against its own CPU model of the console wave64: the 64 lanes stepped through as the ISA defines each instruction, unlaunched lanes holding the identity. The model is checked against a plain fold over the masked lanes. Source below. - **Program:** the pack's sequence (`s_or_saveexec -1`, `v_cndmask` with the identity, DPP8 xor 1/2/4, row_mirror, `v_permlanex16`, `v_readlane` 32 / 0), run as a wave64 PS. - **Draws:** whole quads only, so no helper lanes: partial waves of 1, 2, 3, 4 and 8 quads, and half the target. - **Ops:** min_u32 and and (identity −1); max_u32, or and add (identity 0). - **Masks:** every pixel, odd pixels, pixels < 216, none. | | wrong pixels (of 4000) | |---|---| | `main` | 392 | | `main` + #152 (either variant) | 184: only `and` (160) and `add` (24) | - **min_u32, max_u32 and or_b32 are exact with #152** in every case above. - **`and` and `add`** aren't among the ops #152 recognises, so in a VS / PS they keep the step-by-step translation and stay wrong in partial waves. The commit message says sums keep the old steps in compute; this is the same in a pixel shader. If no title uses them, that's fine. I'm only showing where the coverage ends. - **On `main` the identity-0 ops are wrong too, without helper lanes.** The description reports `or` over a 3-quad wave with helper lanes. Here, in a 3-quad wave with whole quads only (lanes 0..11), max_u32, or and add are all wrong on `main`. On the console, lanes 12..15 pick up the total of lanes 8..15 in the DPP8 steps and pass it to lanes 0..3 through row_mirror. On the PC those lanes don't exist, so lane 0 gets only lanes 0..7. `docs/wave64-on-wave32.md` says max / or / sum are right in partial waves; #152 fixes max and or. **Not tested:** - GPUs with 64-lane waves; - helper lanes and vertex shaders in the extra test; - the helper-lane change as written by its author (I rebuilt it from the description); - the retail pack and any game. <details><summary>The extra test (paste into <code>recomp/tests.rs</code>; it needs the <code>draw_console</code> of this PR)</summary> ```rust /// The whole-wave reduction of the retail pixel shaders (`upper_lanes`) with `op`: v13 of the /// lanes in s[18:19], `identity` (operand code) in the others, DPP8 xor 1 / 2 / 4, row_mirror, /// the other row through `v_permlanex16`, `v_readlane` 32, `v_readlane` 0 into s`out`. fn ind_whole_wave_reduction(op: &str, identity: u64, out: u64) -> Vec<u8> { let mut c = vec![ ins("S_OR_SAVEEXEC_B64", "ENC_SOP1", &[("SDST", 30), ("SSRC0", 193)], None), ins("S_AND_B64", "ENC_SOP2", &[("SDST", 10), ("SSRC0", 18), ("SSRC1", 30)], None), ins("V_CNDMASK_B32", "ENC_VOP3", &[("VDST", 6), ("SRC0", identity), ("SRC1", V + 13), ("SRC2", 10)], None), ]; let names = ["LANE_SEL_0", "LANE_SEL_1", "LANE_SEL_2", "LANE_SEL_3", "LANE_SEL_4", "LANE_SEL_5", "LANE_SEL_6", "LANE_SEL_7"]; for sel in [[1u64, 0, 3, 2, 5, 4, 7, 6], [2, 3, 0, 1, 6, 7, 4, 5], [4, 5, 6, 7, 0, 1, 2, 3]] { let mut f = vec![("VDST", 6u64), ("SRC0", 0xE9), ("VSRC0", 6), ("VSRC1", 6)]; f.extend(names.iter().copied().zip(sel)); c.push(ins(op, "VOP2_VOP_DPP8", &f, None)); } c.extend([ ins(op, "VOP2_VOP_DPP16", &[("VDST", 6), ("SRC0", 0xFA), ("VSRC0", 6), ("VSRC1", 6), ("DPP_CTRL", 0x140), ("ROW_MASK", 0xF), ("BANK_MASK", 0xF)], None), ins("V_PERMLANEX16_B32", "ENC_VOP3", &[("VDST", 7), ("SRC0", V + 6), ("SRC1", 128), ("SRC2", 128)], None), ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", V + 7), ("VSRC1", 6)], None), ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", 10), ("SRC0", V + 6), ("SRC1", 128 + 32)], None), ins(op, "ENC_VOP2", &[("VDST", 6), ("SRC0", 10), ("VSRC1", 6)], None), ins("V_READLANE_B32", "ENC_VOP3", &[("VDST", out), ("SRC0", V + 6), ("SRC1", 128)], None), ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 126), ("SSRC0", 30)], None), ]); c.concat() } /// `ind_whole_wave_reduction` run on the CPU over a console wave64, lane by lane as the ISA /// defines each step (independent of the translation): `v13` of the 64 lanes, `mask` the /// lanes of s[18:19]; EXEC is all ones throughout, so every DPP / permlane source is active. fn console_whole_wave_reduction(op: fn(u32, u32) -> u32, identity: u32, v13: &[u32; 64], mask: u64) -> u32 { let mut v6: [u32; 64] = std::array::from_fn(|l| if mask >> l & 1 == 1 { v13[l] } else { identity }); // VOP2 DPP: dst = op(src0 of the selected lane, src1 of the lane) for x in [1, 2, 4] { let o = v6; v6 = std::array::from_fn(|l| op(o[(l & !7) | ((l & 7) ^ x)], o[l])); } let o = v6; v6 = std::array::from_fn(|l| op(o[(l & !15) | (15 - (l & 15))], o[l])); // v_permlanex16 with selects 0: lane 0 of the other row of the same 32-lane half let v7: [u32; 64] = std::array::from_fn(|l| v6[(l & 32) | ((l & 16) ^ 16)]); v6 = std::array::from_fn(|l| op(v7[l], v6[l])); let s10 = v6[32]; v6 = std::array::from_fn(|l| op(s10, v6[l])); v6[0] } /// The retail reduction (`ind_whole_wave_reduction`) in a wave64 PS whose waves are partial – the /// PC GPU does not launch every lane – compared with a console wave of the same lanes /// (`console_whole_wave_reduction`). On the console the lanes outside the launched ones exist /// and hold the identity the whole-wave `v_cndmask` puts there; the DPP8 / row_mirror / /// `v_permlanex16` steps read them. Each draw covers whole quads only (a corner of the target, /// the hypotenuse outside it), so no helper lanes take part: 1, 2, 3, 4, 8 quads and half the /// target. Ops with identity -1 (min_u32, and) and 0 (max_u32, or, add); masks: every pixel, /// odd pixels, pixels < 216, none. Exports the result's low / high 16 bits. #[test] fn gpu_wave64_ps_partial_wave_reductions() { use std::collections::BTreeMap; if !gpu_ready() { return; } // (name, opcode, identity operand code, identity, CPU op) let ops: [(&str, &str, u64, u32, fn(u32, u32) -> u32); 5] = [ ("min_u32", "V_MIN_U32", 193, u32::MAX, |a, b| a.min(b)), ("and", "V_AND_B32", 193, u32::MAX, |a, b| a & b), ("max_u32", "V_MAX_U32", 128, 0, |a, b| a.max(b)), ("or", "V_OR_B32", 128, 0, |a, b| a | b), ("add", "V_ADD_NC_U32", 128, 0, |a, b| a.wrapping_add(b)), ]; // the lanes of s[18:19] (VCC of a compare of v12, the pixel number): (name, compare, pixel predicate) let masks: [(&str, Vec<u8>, fn(u32) -> bool); 4] = [ ("all", ins("V_CMP_LE_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 12)], None), |_| true), ("odd", [ins("V_AND_B32", "ENC_VOP2", &[("VDST", 14), ("SRC0", 129), ("VSRC1", 12)], None), ins("V_CMP_NE_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 14)], None)].concat(), |p| p % 2 == 1), ("below 216", ins("V_CMP_GT_U32", "ENC_VOPC", &[("SRC0", 255), ("VSRC1", 12)], Some(216)), |p| p < 216), ("none", ins("V_CMP_GT_U32", "ENC_VOPC", &[("SRC0", 128), ("VSRC1", 12)], None), |_| false), ]; // the corner (x, y) a triangle covers from, to the target's edges let corners = [(14.0, 14.0), (12.0, 14.0), (10.0, 14.0), (12.0, 12.0), (8.0, 12.0), (0.0, 8.0)]; let mut bad = Vec::new(); let mut checked = 0; for (oname, opcode, id_code, identity, op) in ops { for (mname, cmp, pred) in &masks { let code = program_of(&[ // v12 = pixel number y·16 + x, v13 = (v12 + 1) | v12 << 20 (bits that differ per pixel, for and / or) ins("V_CVT_U32_F32", "ENC_VOP1", &[("VDST", 10), ("SRC0", V + 2)], None), ins("V_CVT_U32_F32", "ENC_VOP1", &[("VDST", 11), ("SRC0", V + 3)], None), ins("V_LSHL_ADD_U32", "ENC_VOP3", &[("VDST", 12), ("SRC0", V + 11), ("SRC1", 128 + 4), ("SRC2", V + 10)], None), ins("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 13), ("SRC0", 129), ("VSRC1", 12)], None), ins("V_LSHL_OR_B32", "ENC_VOP3", &[("VDST", 13), ("SRC0", V + 12), ("SRC1", 128 + 20), ("SRC2", V + 13)], None), cmp.clone(), ins("S_MOV_B64", "ENC_SOP1", &[("SDST", 18), ("SSRC0", 106)], None), // the wave: its first lane's pixel number; the lane ins("V_READFIRSTLANE_B32", "ENC_VOP1", &[("VDST", 62), ("SRC0", V + 12)], None), ins("V_MBCNT_LO_U32_B32", "ENC_VOP3", &[("VDST", 15), ("SRC0", 193), ("SRC1", 128)], None), ins("V_MBCNT_HI_U32_B32", "ENC_VOP3", &[("VDST", 15), ("SRC0", 193), ("SRC1", V + 15)], None), ind_whole_wave_reduction(opcode, id_code, 40), ins("V_BFE_U32", "ENC_VOP3", &[("VDST", 20), ("SRC0", 40), ("SRC1", 128), ("SRC2", 128 + 16)], None), ins("V_BFE_U32", "ENC_VOP3", &[("VDST", 21), ("SRC0", 40), ("SRC1", 128 + 16), ("SRC2", 128 + 16)], None), ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 20), ("SRC0", V + 20)], None), ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 21), ("SRC0", V + 21)], None), ins("V_MOV_B32", "ENC_VOP1", &[("VDST", 22), ("SRC0", 242)], None), ins("V_LSHL_ADD_U32", "ENC_VOP3", &[("VDST", 23), ("SRC0", 62), ("SRC1", 128 + 6), ("SRC2", V + 15)], None), ins("V_CVT_F32_U32", "ENC_VOP1", &[("VDST", 23), ("SRC0", V + 23)], None), ins("EXP", "ENC_EXP", &[("TGT", 0), ("EN", 0xF), ("VSRC0", 20), ("VSRC1", 21), ("VSRC2", 22), ("VSRC3", 23), ("DONE", 1), ("VM", 1)], None), ]); for (x, y) in corners { let px = draw_console(None, Some(&code), &[[x, y], [x, 48.0], [48.0, y]]); // by wave (its first lane's pixel number): (pixel number, lane, result) let mut waves: BTreeMap<u32, Vec<(u32, u32, u32)>> = BTreeMap::new(); for (id, p) in px.iter().enumerate() { let inside = id % 16 >= x as usize && id / 16 >= y as usize; assert_eq!(p[2] == 1.0, inside, "corner ({x},{y}): pixel {id} drawn"); if inside { waves.entry(p[3] as u32 >> 6).or_default().push((id as u32, p[3] as u32 & 63, p[0] as u32 | (p[1] as u32) << 16)); } } for (first, w) in &waves { let mut v13 = [0xDEAD_BEEFu32; 64]; let mut mask = 0u64; for &(id, lane, _) in w { assert_eq!(v13[lane as usize], 0xDEAD_BEEF, "wave of pixel {first}: lane {lane} twice"); v13[lane as usize] = (id + 1) | id << 20; if pred(id) { mask |= 1 << lane; } } let want = console_whole_wave_reduction(op, identity, &v13, mask); // the model against the operation it implements: a fold over the lanes of the mask let fold = (0..64).filter(|l| mask >> l & 1 == 1).fold(identity, |a, l| op(a, v13[l])); assert_eq!(want, fold, "the CPU model of the console wave"); for &(id, lane, got) in w { checked += 1; if got != want { bad.push(format!("{oname} / {mname} / corner ({x},{y}): pixel {id} (lane {lane} of a wave of {}) = {got:#x}, console {want:#x}", w.len())); } } } } } } println!("{checked} pixels checked, {} wrong", bad.len()); for b in &bad { println!("{b}"); } assert!(bad.is_empty(), "{} of {checked} pixels differ from the console wave (listed above), first: {}", bad.len(), bad[0]); } ``` </details> Report written with Claude Code (Claude Opus 5.5), from runs on the hardware above. I checked the results before posting.
Author
Owner

@⁠Alpha325 on GitHub · 2026-11-24 01:30 UTC · original

Independent RDNA4 check on 4ba00d9796c3deec01be4497830e0ef96620485c, with and without @⁠WarmMilkCodes’ proposed helper-lane change (return IsHelperLane() ? c : t;).

Setup: Radeon RX 9060 XT, driver 32.0.32029.2010, Windows 11 build 26200.9974, Rust 1.100.0 MSVC x64, DXC 1.9.2602.17, release. Synthetic fixtures only.

cargo test --offline --locked --release -j 4 -p xcl --lib reduction -- --test-threads=1 --nocapture

  • Clean PR: 10 passed, 1 failed, 1 ignored. gpu_ps_partial_wave_reductions reported 24 failing groups, all min_u32, covering 68 mismatched pixel comparisons in wave32 cases and 78 in wave64 cases.
  • PR plus the proposed one-line change: 11 passed, 0 failed, 1 ignored. The partial-wave test passed, and the helper-lane readback test still reported zero differences.
  • The separate whole-wave pixel test reported four waves of 64 pixels on both builds.

This confirms the proposed change fixes the reported failure on RDNA4 for these fixtures. I did not run the full workspace suite.

AI use: OpenAI Codex (GPT-6.2 Sol) ran both builds and drafted this report.

**@⁠Alpha325** on GitHub · 2026-11-24 01:30 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7119171876) Independent RDNA4 check on `4ba00d9796c3deec01be4497830e0ef96620485c`, with and without @⁠WarmMilkCodes’ proposed helper-lane change (`return IsHelperLane() ? c : t;`). **Setup:** Radeon RX 9060 XT, driver `32.0.32029.2010`, Windows 11 build `26200.9974`, Rust 1.100.0 MSVC x64, DXC 1.9.2602.17, release. Synthetic fixtures only. `cargo test --offline --locked --release -j 4 -p xcl --lib reduction -- --test-threads=1 --nocapture` - **Clean PR:** 10 passed, 1 failed, 1 ignored. `gpu_ps_partial_wave_reductions` reported 24 failing groups, all `min_u32`, covering 68 mismatched pixel comparisons in wave32 cases and 78 in wave64 cases. - **PR plus the proposed one-line change:** 11 passed, 0 failed, 1 ignored. The partial-wave test passed, and the helper-lane readback test still reported zero differences. - The separate whole-wave pixel test reported four waves of 64 pixels on both builds. This confirms the proposed change fixes the reported failure on RDNA4 for these fixtures. I did not run the full workspace suite. **AI use:** OpenAI Codex (GPT-6.2 Sol) ran both builds and drafted this report.
Author
Owner

@⁠raylitebull on GitHub · 2026-11-24 10:43 UTC · original

Closing as a stale, conflicting ~1,500-line pre-template PR (touching HANDOFF.md and missing required CONTRIBUTING.md sections). Feel free to open a fresh, scoped PR against current main if still needed.

**@⁠raylitebull** on GitHub · 2026-11-24 10:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/152#issuecomment-7129159155) Closing as a stale, conflicting ~1,500-line pre-template PR (touching `HANDOFF.md` and missing required `CONTRIBUTING.md` sections). Feel free to open a fresh, scoped PR against current `main` if still needed.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.