Recompiler: translate v_qsad_pk_u16_u8 and v_mqsad_{pk_u16,u32}_u8 in both backends (takes over #909) #2334

Manually merged
github merged 2 commits from gh-pr/2334/head into gh-pr/2334/base 2026-11-26 05:27:53 +00:00
Owner

@⁠NWProgramming00 on GitHub · 2026-11-25 14:57 UTC · original
NWProgramming00:recomp/qsad → main · +311 −1 · 4 files · 2 commits · merged 2026-11-25 18:37 UTC

Both backends refused v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8. This takes over #909 by @⁠bigiello, which its author closed along with their other open PRs on 24.11 while it was waiting only for a regression run. Their commit is kept as it was, with its authorship. On top of it, this adds the same translation to the direct DXIL backend, checks both backends against RDNA2 hardware, and adds the regression run.

What is in it

  • 95f6c1a (@⁠bigiello, unchanged from #909): Em::valu_qsad and a pk_sad_u16 prelude helper in crates/xcl/src/gpu/recomp/emit.rs, plus the tests qsad_and_mqsad_operand_forms_and_validation and gpu_qsad_and_mqsad.
  • c0eaeff: Lw::valu_qsad in crates/xcl/src/gpu/dxil/lower_wide.rs, dispatched from lower_valu.rs.
    • It follows valu_qsad: the four 4-byte windows of the 64-bit SRC0 against SRC1, with mqsad skipping SRC1's zero bytes.
    • Each SAD is added to its 16-bit (_pk_u16) or 32-bit (_u32) element of SRC2, saturating per element with CLAMP.
    • It refuses the same operand forms as the HLSL backend.
    • gpu_qsad_and_mqsad now runs both backends in wave32 and wave64.

Tested

  • Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB (wave64 as two halves) and an AMD Radeon RDNA2 iGPU (gfx1036, native wave64, XCL_ADAPTER=radeon). Rust 1.100 MSVC, release.
  • xcl against the gfx1036. All three instructions, with and without CLAMP, ran on 832 lanes. The inputs were edge bytes, zero bytes in SRC1, accumulators near 0xFFFF / 0xFFFFFFFF, and random words. I compared all 8 result words per lane with the gfx1036's own results, which come from running the instructions there directly through HIP:
    • HLSL backend: no differences on either adapter.
    • direct DXIL: no differences on either adapter.
    • This repeats @⁠4usphs's hardware check on #909 for the HLSL backend, now on both backends.
  • gpu_qsad_and_mqsad passes on both adapters. It fails with each of six deliberate mistakes:
    • the zero-byte mask of mqsad dropped (direct DXIL);
    • CLAMP ignored on the 16-bit elements (direct DXIL);
    • CLAMP ignored on the 32-bit elements (direct DXIL);
    • a wrong window shift (direct DXIL);
    • the high accumulator read from the low word (direct DXIL);
    • pk_sad_u16 without saturation (HLSL).
  • The whole suite: cargo build --release --workspace, then cargo test --release --workspace --no-fail-fast -- --test-threads=4, with and without XCL_DIRECT_DXIL=all, against base 06c9f55 on the same machine:
Adapter Mode base 06c9f55 this PR (c0eaeff)
RTX 5070 Ti default 1261 passed, 4 failed, 46 ignored 1263 passed, 4 failed, 46 ignored
RTX 5070 Ti XCL_DIRECT_DXIL=all 1260 passed, 5 failed, 46 ignored 1262 passed, 5 failed, 46 ignored
Radeon gfx1036 default 1264 passed, 1 failed, 46 ignored 1266 passed, 1 failed, 46 ignored
Radeon gfx1036 XCL_DIRECT_DXIL=all 1263 passed, 2 failed, 46 ignored 1265 passed, 2 failed, 46 ignored

The +2 are #909's two tests. The same tests fail on both sides, and all of them are tracked:

  • fuzz_validate_and_gpu_0..3 on NVIDIA (#1905);
  • fuzz_validate_and_gpu_1 on RDNA2 (#2115);
  • offline_compute_pipeline_is_reused_by_a_second_process with direct DXIL (#1674).

Regression run
Base (main 06c9f55), NVIDIA GeForce RTX 5070 Ti:

xcl-smoke v1
commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 819 (PresentX 820)
presents per 2 s (last 3): 13 28 28
device removals: 0
crashes: 0
peak commit: 16053 MB

This PR (c0eaeff), same card:

xcl-smoke v1
commit: c0eaeff7046ebb8e5384673c661920d7a9d76cff
gpu: NVIDIA GeForce RTX 5070 Ti
title: title-a
seconds: 60
exit: 0x0
frames shown: 881 (PresentX 881)
presents per 2 s (last 3): 9 60 60
device removals: 0
crashes: 0
peak commit: 15656 MB

Not tested

  • RDNA3 / RDNA4 and Intel here. @⁠SlopTart ran #909's head on RDNA3 under Linux.
  • Whether a retail program uses these instructions.

AI use

  • #909's commit says it was written with Antigravity.
  • Claude Code (Claude Opus 5.5) did the rest: it ported the lowering to direct DXIL, measured the hardware, extended the test, ran the comparisons, the mutation checks and the suites, and wrote this description.

🤖 Generated with Claude Code

**@⁠NWProgramming00** on GitHub · 2026-11-25 14:57 UTC · [original](https://github.com/xcl-dev/xcl/pull/2334) `NWProgramming00:recomp/qsad` → `main` · +311 −1 · 4 files · 2 commits · merged 2026-11-25 18:37 UTC Both backends refused `v_qsad_pk_u16_u8`, `v_mqsad_pk_u16_u8` and `v_mqsad_u32_u8`. This takes over #909 by @⁠bigiello, which its author closed along with their other open PRs on 24.11 while it was waiting only for a regression run. Their commit is kept as it was, with its authorship. On top of it, this adds the same translation to the direct DXIL backend, checks both backends against RDNA2 hardware, and adds the regression run. **What is in it** - `95f6c1a` (@⁠bigiello, unchanged from #909): `Em::valu_qsad` and a `pk_sad_u16` prelude helper in `crates/xcl/src/gpu/recomp/emit.rs`, plus the tests `qsad_and_mqsad_operand_forms_and_validation` and `gpu_qsad_and_mqsad`. - `c0eaeff`: `Lw::valu_qsad` in `crates/xcl/src/gpu/dxil/lower_wide.rs`, dispatched from `lower_valu.rs`. - It follows `valu_qsad`: the four 4-byte windows of the 64-bit SRC0 against SRC1, with `mqsad` skipping SRC1's zero bytes. - Each SAD is added to its 16-bit (`_pk_u16`) or 32-bit (`_u32`) element of SRC2, saturating per element with CLAMP. - It refuses the same operand forms as the HLSL backend. - `gpu_qsad_and_mqsad` now runs both backends in wave32 and wave64. **Tested** - Windows 11, NVIDIA GeForce RTX 5070 Ti 16 GB (wave64 as two halves) and an AMD Radeon RDNA2 iGPU (gfx1036, native wave64, `XCL_ADAPTER=radeon`). Rust 1.100 MSVC, release. - **xcl against the gfx1036.** All three instructions, with and without CLAMP, ran on 832 lanes. The inputs were edge bytes, zero bytes in SRC1, accumulators near 0xFFFF / 0xFFFFFFFF, and random words. I compared all 8 result words per lane with the gfx1036's own results, which come from running the instructions there directly through HIP: - HLSL backend: no differences on either adapter. - direct DXIL: no differences on either adapter. - This repeats @⁠4usphs's hardware check on #909 for the HLSL backend, now on both backends. - **`gpu_qsad_and_mqsad` passes on both adapters.** It fails with each of six deliberate mistakes: - the zero-byte mask of `mqsad` dropped (direct DXIL); - CLAMP ignored on the 16-bit elements (direct DXIL); - CLAMP ignored on the 32-bit elements (direct DXIL); - a wrong window shift (direct DXIL); - the high accumulator read from the low word (direct DXIL); - `pk_sad_u16` without saturation (HLSL). - **The whole suite:** `cargo build --release --workspace`, then `cargo test --release --workspace --no-fail-fast -- --test-threads=4`, with and without `XCL_DIRECT_DXIL=all`, against base `06c9f55` on the same machine: | Adapter | Mode | base `06c9f55` | this PR (`c0eaeff`) | |---|---|---|---| | RTX 5070 Ti | default | 1261 passed, 4 failed, 46 ignored | 1263 passed, 4 failed, 46 ignored | | RTX 5070 Ti | `XCL_DIRECT_DXIL=all` | 1260 passed, 5 failed, 46 ignored | 1262 passed, 5 failed, 46 ignored | | Radeon gfx1036 | default | 1264 passed, 1 failed, 46 ignored | 1266 passed, 1 failed, 46 ignored | | Radeon gfx1036 | `XCL_DIRECT_DXIL=all` | 1263 passed, 2 failed, 46 ignored | 1265 passed, 2 failed, 46 ignored | The +2 are #909's two tests. The same tests fail on both sides, and all of them are tracked: - `fuzz_validate_and_gpu_0..3` on NVIDIA (#1905); - `fuzz_validate_and_gpu_1` on RDNA2 (#2115); - `offline_compute_pipeline_is_reused_by_a_second_process` with direct DXIL (#1674). **Regression run** Base (`main` `06c9f55`), NVIDIA GeForce RTX 5070 Ti: ``` xcl-smoke v1 commit: 06c9f5505f63f10c5ec49ef932d75b2c28177324 gpu: NVIDIA GeForce RTX 5070 Ti title: title-a seconds: 60 exit: 0x0 frames shown: 819 (PresentX 820) presents per 2 s (last 3): 13 28 28 device removals: 0 crashes: 0 peak commit: 16053 MB ``` This PR (`c0eaeff`), same card: ``` xcl-smoke v1 commit: c0eaeff7046ebb8e5384673c661920d7a9d76cff gpu: NVIDIA GeForce RTX 5070 Ti title: title-a seconds: 60 exit: 0x0 frames shown: 881 (PresentX 881) presents per 2 s (last 3): 9 60 60 device removals: 0 crashes: 0 peak commit: 15656 MB ``` **Not tested** - RDNA3 / RDNA4 and Intel here. @⁠SlopTart ran #909's head on RDNA3 under Linux. - Whether a retail program uses these instructions. **AI use** - #909's commit says it was written with Antigravity. - Claude Code (Claude Opus 5.5) did the rest: it ported the lowering to direct DXIL, measured the hardware, extended the test, ran the comparisons, the mutation checks and the suites, and wrote this description. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Add translation for the three remaining quad-byte SAD VOP3 instructions:
v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8, and v_mqsad_u32_u8. Previously
the packed u16 forms routed into the 16-bit VALU path because of '_u16'
in their mnemonics and v_mqsad_u32_u8 failed on 64/128-bit operands.

- Add Em::valu_qsad in emit.rs before the 16-bit VALU dispatch, reusing
  sad_u8, msad_u8, and sat_u32 plus a pk_sad_u16 prelude helper.
- Capture 64-bit SRC0 and 32-bit SRC1 in temporaries before writing
  destinations so overlapping VDST/SRC registers and EXEC masking stay
  exact across wave32 and wave64, and reject out-of-range VGPR spans or
  non-VGPR SRC2 on v_mqsad_u32_u8.
- Add translation/validation and D3D12 GPU tests covering window
  shifts, zero-byte masking, CLAMP wrap vs saturation, SGPR/VCC/inline
  sources, overlapped registers, and EXEC masks (ISA coverage VOP3
  287/298 -> 290/298, overall 1042 -> 1045 / 1157).

Assisted-by: Antigravity (exact model name not exposed to agent)
v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8 now lower in the
direct DXIL translator too, following valu_qsad in recomp/emit.rs: the
four 4-byte windows of the 64-bit SRC0 against SRC1 (mqsad skips SRC1's
zero bytes), each added to its 16- or 32-bit element of SRC2, saturating
per element with CLAMP. The same operand checks are refused.

gpu_qsad_and_mqsad now runs both backends, in wave32 and wave64.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:27:52 +00:00
github manually merged commit c0eaeff704 into gh-pr/2334/base 2026-11-26 05:27:53 +00:00
Author
Owner

@⁠nnonno91 on GitHub · 2026-11-25 15:06 UTC · original

Independent exact-head verification of c0eaeff7046ebb8e5384673c661920d7a9d76cff on Radeon integrated graphics and RTX 5090.

Tested

  • Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, unoptimized profile. AMD Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742. SDK DXC/DXIL 1.8.2502.11.
  • cargo test --locked -p xcl --lib qsad_and_mqsad -- --nocapture --test-threads=1 with XCL_ADAPTER=AMD Radeon and XCL_ADAPTER=NVIDIA GeForce RTX 5090 in separate processes. Both gave 2 passed, 0 failed, 0 ignored and no skips.
  • Both translation paths passed the wave32 and logical wave64 GPU fixtures, including the three instructions, saturation and wrap cases, overlapping operands and the check that inactive lanes retain their original values. Operand-form and translation validation also passed.

Not tested

The separate HIP hardware capture, retail inputs, the parent and the full workspace suite.

AI use

OpenAI Codex (GPT-6.2 Sol) ran the checks and wrote this report.

**@⁠nnonno91** on GitHub · 2026-11-25 15:06 UTC · [original](https://github.com/xcl-dev/xcl/pull/2334#issuecomment-7166318122) Independent exact-head verification of `c0eaeff7046ebb8e5384673c661920d7a9d76cff` on Radeon integrated graphics and RTX 5090. **Tested** - Windows 11 25H2 build 26200.9974, Ryzen 7 9800X3D, Rust 1.100.0 MSVC, unoptimized profile. AMD Radeon(TM) Graphics driver 32.0.21042.62 and RTX 5090 driver 32.0.16.1742. SDK DXC/DXIL 1.8.2502.11. - `cargo test --locked -p xcl --lib qsad_and_mqsad -- --nocapture --test-threads=1` with `XCL_ADAPTER=AMD Radeon` and `XCL_ADAPTER=NVIDIA GeForce RTX 5090` in separate processes. Both gave 2 passed, 0 failed, 0 ignored and no skips. - Both translation paths passed the wave32 and logical wave64 GPU fixtures, including the three instructions, saturation and wrap cases, overlapping operands and the check that inactive lanes retain their original values. Operand-form and translation validation also passed. **Not tested** The separate HIP hardware capture, retail inputs, the parent and the full workspace suite. **AI use** OpenAI Codex (GPT-6.2 Sol) ran the checks and wrote this report.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 15:41 UTC · original

Independent focused check of exact head c0eaeff7046ebb8e5384673c661920d7a9d76cff on Windows 11 build 26200, discrete AMD Radeon RX 6800M (driver 30.0.13002.13003), Rust 1.99 MSVC, DXC/DXIL 1.9.2609.5.

With XCL_ADAPTER=6800M and XCL_REQUIRE_GPU=wave64, cargo test --locked -p xcl --lib qsad_and_mqsad -- --test-threads=1 --show-output on the clean PR head gave 2 passed, 0 failed, 0 ignored, 0 explicit skips. The GPU fixture runs both HLSL/DXC and direct DXIL in wave32 and wave64, checking all three QSAD/MQSAD instructions, CLAMP and wrap results, overlapping operands, and EXEC-inactive lanes. The operand-form validation test also passed.

A temporary diagnostic print in the fixture confirmed AMD Radeon RX 6800M and native wave64: true; its run also passed 2/2. I restored that print and repeated the clean-head run above; the checkout is clean. The diagnostic only identified the device and wave capability, and is not part of the PR.

This adds a discrete RDNA2 and older driver to the author and other reviewers' checks. I did not perform a separate HIP hardware capture, full workspace suite, or retail-title smoke comparison for this PR.

AI use: OpenAI Codex (GPT-6) ran the checks and prepared this report.

**@⁠luckyteagirl** on GitHub · 2026-11-25 15:41 UTC · [original](https://github.com/xcl-dev/xcl/pull/2334#issuecomment-7167232699) Independent focused check of exact head `c0eaeff7046ebb8e5384673c661920d7a9d76cff` on Windows 11 build 26200, discrete AMD Radeon RX 6800M (driver `30.0.13002.13003`), Rust 1.99 MSVC, DXC/DXIL 1.9.2609.5. With `XCL_ADAPTER=6800M` and `XCL_REQUIRE_GPU=wave64`, `cargo test --locked -p xcl --lib qsad_and_mqsad -- --test-threads=1 --show-output` on the clean PR head gave **2 passed, 0 failed, 0 ignored, 0 explicit skips**. The GPU fixture runs both HLSL/DXC and direct DXIL in wave32 and wave64, checking all three QSAD/MQSAD instructions, CLAMP and wrap results, overlapping operands, and EXEC-inactive lanes. The operand-form validation test also passed. A temporary diagnostic print in the fixture confirmed `AMD Radeon RX 6800M` and `native wave64: true`; its run also passed 2/2. I restored that print and repeated the clean-head run above; the checkout is clean. The diagnostic only identified the device and wave capability, and is not part of the PR. This adds a discrete RDNA2 and older driver to the author and other reviewers' checks. I did not perform a separate HIP hardware capture, full workspace suite, or retail-title smoke comparison for this PR. **AI use:** OpenAI Codex (GPT-6) ran the checks and prepared this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 18:04 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 18:04 UTC · [original](https://github.com/xcl-dev/xcl/pull/2334#issuecomment-7170407374) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This discussion has been locked. Commenting is limited to contributors.
No description provided.