Recompiler: implement S_QUADMASK_B32 and S_QUADMASK_B64 #1463
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1473"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by hajduzsolt on 2026-11-24T16:38:15Z.
What is in it
crates/xcl/src/gpu/recomp/emit.rs:s_quadmask_b32insalu, computing an 8-bit quad mask from SSRC0 into SDST and setting SCC if non-zero.s_quadmask_b64insalu64, packing low and high 8-bit quad masks into the low dword of the 64-bit SDST with the high dword cleared to 0 and SCC set if non-zero.quadmaskbranchless bit-compression helper in the HLSL preamble.crates/xcl/src/gpu/recomp/tests.rs:scalar_quadmask_b32_and_b64unit test verifying generated HLSL translation and DXC compilation.gpu_scalar_quadmaskhardware execution test on AMD Radeon RX 9070 XT verifying zero masks, multi-quad bit patterns, full masks, 64-bit pair packing, and SCC flags.Tested
cargo test --workspace -- --test-threads=2: passedcargo test -p xcl --lib quadmask: 2 passed, 0 failedRegression run
main:
PR:
Not tested
AI use
Imported from ivall/xcl. Originally posted by nnonno91 on 2026-11-24T16:43:41Z.
Quad-mask results on native and split waves at
be1fa02Both new quad-mask tests passed on integrated AMD Radeon graphics and the RTX 5090. I also ran a temporary probe that compared both opcodes with a CPU implementation of AMD’s quad-mask rule. It checked each of the 64 single-bit positions plus six other masks, including zero, all ones, and a high-word-only pattern. The probe checked result bits, SCC, and clearing the upper destination dword for
S_QUADMASK_B64.Tested
be1fa02b4d90d43cdcd9ad5dfb3d32e2c5e9973e, Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Radeon(TM) Graphics (32.0.21042.62), RTX 5090 (617.42), Rust 1.100.0 MSVC, DXC 1.8.2502.11, debug/test profiles.cargo test --locked -p xcl --lib quadmask -- --nocapture --test-threads=1reported 2 passed, 0 failed on each adapter, with no skips.probe_quadmask_all_input_bit_positionsusing the same Cargo test invocation passed 70 input patterns per mode. AMD ran wave32 and native wave64. NVIDIA ran wave32 and split wave64. All results matched the CPU reference.cargo build --workspace --lockedandcargo test --workspace --locked --no-fail-fast -- --test-threads=4 --show-outputpassed on the RTX 5090. Total 772 passed, 0 failed, 41 ignored. The count includes twono wave64skips:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware.Not tested
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T18:53:11Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~21 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodifiedmain.)Thanks!
upstream-sync referenced this pull request2026-11-25 06:04:27 +00:00
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T16:08:06Z.
NVIDIA test report for
be1fa02: RTX 3070 8 GB (Ampere, driver 616.56), Windows 11 26100, Rust 1.100.0, debug. Head tested as-is on its baseb7aa9f3.cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4: 715 passed, 0 failed, 21 ignored; 2 SKIPPED (no wave64: gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware), neither a test this PR adds.gpu::recomp::tests::gpu_scalar_quadmaskandscalar_quadmask_b32_and_b64, each with--exact --test-threads=1 --nocapture, 3 runs: 3/3 passed each, 0 SKIPPED; DXC 1.8.2502.11 loaded, so the HLSL compile ran.Lib tests only; no title run.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ivall/xcl. Originally posted by BBareth on 2026-11-30T19:20:36Z.
merge-check claim
head:
be1fa02b4dImported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T19:27:12Z.
merge-check claim
head:
be1fa02b4dImported from ivall/xcl. Originally posted by BBareth on 2026-11-30T19:40:28Z.
merge-check
base:
ff0c364b3dhead:
be1fa02b4dmerge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 1 failed, 51 ignored; 28 SKIPPED lines, as on the base; failing:
gpu::recomp::tests::gpu_scalar_quadmask, which is this PR's own new test:called Result::unwrap() on an Err value: "s_quadmask_b32 s1, s10: SALU"attests.rs:354. The other new test,scalar_quadmask_b32_and_b64(translation to HLSL and a DXC compile), passed. The base alone, run in the same batch: 2888 passed, 1 failed, 51 ignored, 28 SKIPPED lines; its one failure,hle::d3d12x::pso_async::used_tests::emission_resolves_the_retained_recipe_after_title_address_reuse, passed in this merged run and in the six others of the batch, so it is intermittent on the base and not this PR's.review: one blocking finding. The PR adds
s_quadmask_b32/s_quadmask_b64to the HLSL emitter only (emit.rs), but on currentmainrunner::run_codegoes through the direct DXIL lowering, whose scalar arm does not know the two instructions and returnsSALU(gpu/dxil/lower.rs, the fall-through of the SALU match). So the PR's GPU test fails on the merged tree, and a title program with S_QUADMASK would still be refused on the default path. The HLSL side itself reads correct:quadmask()gathers one bit per 4-bit group (0x0F00F010 -> 0x4A checked by hand), the 64-bit form puts the high half's 8 bits at bit 8 and writes 0 to the upper destination register, SCC is result != 0. Needed: the same two instructions in the direct DXIL lowering (or the GPU test pinned to the path that has them, with the limitation stated).performance: none: two new match arms and one helper function in the generated HLSL prelude.
verdict: not yet: the PR's own GPU test
gpu_scalar_quadmaskfails on the merged tree (direct DXIL lowering refuses S_QUADMASK)hardware / tool and model: RTX 5070 Ti 16 GB, driver 621.24 (32.0.16.2124); i7-12700K; Windows 11 26200. Claude Code, Claude Fable 5.2 read the diff, ran the build and the suite and wrote this check.
Imported from ivall/xcl. Originally posted by saintwolf on 2026-11-30T19:44:02Z.
merge-check
base:
ff0c364b3dhead:
be1fa02b4dmerge: clean (trial merge be601a0a87f30fecf6b2abd924a1e5549e23aedf; git diff --check clean; +59/-0 in crates/xcl/src/gpu/recomp/emit.rs and tests.rs)
build: cargo build --workspace -> ok (39 lib + 19 test warnings, all pre-existing; none from the changed lines)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2890 passed, 1 failed, 51 ignored (base
ff0c364bis 2889; the new scalar_quadmask_b32_and_b64 passes, the new gpu_scalar_quadmask fails); failing: gpu::recomp::tests::gpu_scalar_quadmask (the PR's new test; it does not exist on the base, so it cannot fail there). The same run with XCL_DIRECT_DXIL=0: 2890 passed, 1 failed, 51 ignored - both new tests pass there, and the single failure is offline_compute_pipeline_is_reused_by_a_second_process (crates/xcl/tests/gpu_compute_e2e.rs, a D3D12.X driver-cache e2e this PR does not touch; it fails on the baseff0c364bin the same environment with the same panic at the same line, and passes in the default-environment run above). SKIPPED: 27, the standard set for this card, in both runs.review: (1) The PR's new GPU test fails in the default compute-backend configuration. With XCL_DIRECT_DXIL unset, compute kernels route to the direct DXIL backend by default (gpu/dxil/kernel.rs:46-62:
0none,1compute, anything else (unset,all) both), and runner::run_code has no HLSL fallback by design (runner.rs:818-822, "an unsupported instruction is an error (no fallback)"). The direct backend's SALU tables (the 32-bit match at gpu/dxil/lower.rs:1486-1666 with catch-allerr(d, "SALU")at lower.rs:1666, and the 64-bit table's catch-all at lower.rs:1921) have no s_quadmask_b32/b64, so the test's run_code returns Err("s_quadmask_b32 s1, s10: SALU") and the unwrap at tests.rs:354 panics. Measured on this card: default environment, gpu_scalar_quadmask FAILED (deterministic: three runs, targeted and full suite); with XCL_DIRECT_DXIL=0 it passes (1/1 targeted, ok in the full-suite run - see the tests line for that run's one pre-existing failure). The runtime is not affected: pso.rs falls back from the direct path to the HLSL path on a refusal (direct_fallback, pso.rs:1277-1283; the Err arm falls through to the HLSL translate at pso.rs:1466-1469), so a game kernel using S_QUADMASK works in the default environment through the logged fallback after this PR. The thread's reports (RTX 5090 + AMD iGPU: 2/2 on the new tests and 772/0/41 for the full suite; RTX 3070: 715/0/21 and the new tests 3/3 standalone) are green without mentioning XCL_DIRECT_DXIL; on this card, where the variable is unset, the GPU test passes only with XCL_DIRECT_DXIL=0. The sibling CPU test already omits direct_check() for the same reason (tests.rs:311-323). What is missing: the two ops in the direct backend's SALU tables (the per-quad any-lane-set fold the HLSL arm uses), or the test routed to the HLSL form when the direct backend refuses it (the routed_to_hlsl convention, tests.rs:79-83), or the GPU test restricted to the HLSL path. (2) The HLSL change itself is correct: quadmask() (emit.rs:6973) folds each 4-lane quad to one bit (m | m>>1 | m>>2 | m>>3, then & 0x11111111) and repacks the eight scattered quad bits down to bits 0-7 by staged shift-and; I hand-traced it against the AMD S_QUADMASK rule and recomputed the test vectors (0x0F00_F010 -> quads 1,3,6 -> 0x4A; 0x8765_4321 -> 0xFF; B64 (0x10, 0x800) -> (0x0402, 0) with the upper destination dword 0). The arms mirror the adjacent s_wqm_b32/s_wqm_b64 exactly (SCC = result != 0; for B64 the high word is 0 by construction, so scc = t0 != 0); the helper sits in the static preamble (always emitted, dead-code-eliminated, zero cost for programs that do not use the op); the encoder has both opcodes (rdna2_spec.rs:588-589, opcodes 44/45). With XCL_DIRECT_DXIL=0 the GPU test passes on this card with every result vector and SCC bit correct, and the CPU translate/DXC test passes in both configurations. (3) Dupe: open #814 (mastrr9, created 2026-11-24T05:48Z, 10h49m before this PR's 16:38Z, +51/-0 in the same two files, head343bd2f3, MERGEABLE) implements the same two opcodes with the same quadmask helper and semantically the same arms, plus s_bitreplicate_b64_b32; it is not in the #3041 queue and in no #1607 group; if both land they collide in the same match arms, so one needs to drop the overlap. (4) Thread: nnonno91's temporary CPU-reference probe (each of the 64 single-bit positions plus six edge masks, result bits + SCC + B64 upper-dword clear, on AMD iGPU in wave32 and native wave64 and on the RTX 5090 in wave32 and split wave64, all matching), DavidM1911's lib all-pass on an RTX 3060 Ti with the branch merged into current main, upipibi's new tests 3/3 standalone on an RTX 3070.performance: none meaningful: one scalar helper in the static preamble (dead-code-eliminated for programs that do not use the op) and two translator match arms; the runtime's default behavior is unchanged - a kernel that uses S_QUADMASK takes the existing, already-logged direct-to-HLSL fallback until the direct backend learns the op.
verdict: not yet: the PR's new GPU test fails in the default compute-backend configuration: with XCL_DIRECT_DXIL unset (the default), run_code routes to the direct DXIL backend, whose SALU tables lack S_QUADMASK_B32/B64, so the standard suite reports 1 failed on a GPU machine (with XCL_DIRECT_DXIL=0 both new tests pass, and the runtime handles the op through its existing direct-to-HLSL fallback). Add the two ops to the SALU tables in gpu/dxil/lower.rs, or route the test to the HLSL form.
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T05:53:02Z.
Triage (#1607) – head
be1fa02#814 (opened earlier) adds the same
quadmask()helper character for character, plus the sames_quadmask_b32/s_quadmask_b64arms inrecomp/emit.rs. It also implementss_bitreplicate_b64_b32, with a translation test and a GPU test. The only difference here is the SCC expression for b64 (t0 != 0instead ofnz), which gives the same result because the high word is 0. This PR's GPU test values are correct (0x4A, 0xFF, 0x402) and could be added to #814.Recommendation: close (duplicate of #814).
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by throny on 2026-12-01T15:57:54Z.
Closing as superseded: the same change is in #814 (open, mergeable, required checks green). From Foniass's rechecked close list on #1607, checked again by script just now. If something here is still missing, say so and reopen it, or ask and I will.
AI use: Claude Code (Claude Opus 5.5).
Pull request closed