Recompiler: wave32 src_vccz / src_execz and SDWA f16 inline constants #191

Manually merged
github merged 1 commit from gh-pr/191/head into gh-pr/191/base 2026-11-26 04:14:35 +00:00
Owner

@⁠RandomGithub12309 on GitHub · 2026-11-23 20:01 UTC · original
RandomGithub12309:fix/recomp-wave32-vccz-sdwa-f16 → main · +174 −39 · 2 files · 1 commits · merged 2026-11-23 20:51 UTC

Addresses two unfixed operand-decoding gaps noted in #105:

  • Wave32 src_vccz (251), src_execz (252), and 32-bit saveexec / wrexec:
    • Add Em::mask_zero so code32, code64, and sopp (s_cbranch_vccz / vccnz / execz / execnz) check only vcc_lo / exec_lo when !self.opt.wave64 instead of (lo | hi) == 0u (in wave32 vcc_hi is a general-purpose SGPR).
    • Add 251 and 252 handling in code64.
    • Branch on !self.opt.wave64 || name.ends_with("_b32") before read64 / sreg(127) in salu saveexec / wrexec, allowing 32-bit scalar sources such as m0 or src_vccz.
  • SDWA f16 inline constants and VSRC1:
    • Forward src_f16 into code32 for SDWA S0 == 1 and S1 == 1 instead of hardcoding false (which emitted binary32 constants whose low 16 bits were wrong, e.g. 0x3F800000 -> 0.0h).
    • Skip pre-reading VSRC1 in Variant::Sdwa inside Em::sources so scalar S1 == 1 operands do not register bogus VGPRs.
    • Pass src_f16 = false in valu16 for integer-source v_cvt_f16_u16 and v_cvt_f16_i16.

Verification

  • Added HLSL and GPU tests (wave32_src_vccz_execz_and_saveexec_b32_hlsl, sdwa_f16_inline_constants_hlsl, gpu_wave32_and_wave64_src_vccz_execz, gpu_sdwa_f16_inline_constants); verified all 4 failed on main (956a476) before the fix and pass after.
  • Ran .\scripts\test.ps1 on Windows 11 x64 with an NVIDIA GeForce RTX 5050 Laptop GPU (540 passed; 0 failed in xcl lib tests, 2 wave64-only GPU tests skipped; all e2e/oracle test targets passed; XCL_SAMPLE_* env vars not set).
**@⁠RandomGithub12309** on GitHub · 2026-11-23 20:01 UTC · [original](https://github.com/xcl-dev/xcl/pull/191) `RandomGithub12309:fix/recomp-wave32-vccz-sdwa-f16` → `main` · +174 −39 · 2 files · 1 commits · merged 2026-11-23 20:51 UTC Addresses two unfixed operand-decoding gaps noted in #105: - **Wave32 `src_vccz` (`251`), `src_execz` (`252`), and 32-bit `saveexec` / `wrexec`:** - Add `Em::mask_zero` so `code32`, `code64`, and `sopp` (`s_cbranch_vccz` / `vccnz` / `execz` / `execnz`) check only `vcc_lo` / `exec_lo` when `!self.opt.wave64` instead of `(lo | hi) == 0u` (in wave32 `vcc_hi` is a general-purpose SGPR). - Add `251` and `252` handling in `code64`. - Branch on `!self.opt.wave64 || name.ends_with("_b32")` before `read64` / `sreg(127)` in `salu` `saveexec` / `wrexec`, allowing 32-bit scalar sources such as `m0` or `src_vccz`. - **SDWA `f16` inline constants and `VSRC1`:** - Forward `src_f16` into `code32` for SDWA `S0 == 1` and `S1 == 1` instead of hardcoding `false` (which emitted binary32 constants whose low 16 bits were wrong, e.g. `0x3F800000` -> `0.0h`). - Skip pre-reading `VSRC1` in `Variant::Sdwa` inside `Em::sources` so scalar `S1 == 1` operands do not register bogus VGPRs. - Pass `src_f16 = false` in `valu16` for integer-source `v_cvt_f16_u16` and `v_cvt_f16_i16`. ### Verification - Added HLSL and GPU tests (`wave32_src_vccz_execz_and_saveexec_b32_hlsl`, `sdwa_f16_inline_constants_hlsl`, `gpu_wave32_and_wave64_src_vccz_execz`, `gpu_sdwa_f16_inline_constants`); verified all 4 failed on `main` (`956a476`) before the fix and pass after. - Ran `.\scripts\test.ps1` on Windows 11 x64 with an NVIDIA GeForce RTX 5050 Laptop GPU (`540 passed; 0 failed` in `xcl` lib tests, 2 wave64-only GPU tests skipped; all e2e/oracle test targets passed; `XCL_SAMPLE_*` env vars not set).
- Use wave-size-aware mask_zero() for src_vccz (251), src_execz (252), and s_cbranch_* in code32/code64/sopp so wave32 checks only vcc_lo/exec_lo (#105).
- Handle 32-bit saveexec/wrexec before read64/sreg(127) so wave32 / _b32 forms accept 32-bit scalar sources such as m0 or src_vccz.
- Forward src_f16 into SDWA S0/S1 code32 decoding, skip registering VSRC1 as a VGPR in SDWA before checking S1, and pass src_f16=false for v_cvt_f16_u16 / v_cvt_f16_i16 (#105).
- Add HLSL and GPU regression tests covering wave32/wave64 src_vccz/src_execz, s_and_saveexec_b32, and SDWA f16 inline constants.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:14:32 +00:00
github manually merged commit 62e0e2596e into gh-pr/191/base 2026-11-26 04:14:35 +00:00
Author
Owner

@⁠mastrr9 on GitHub · 2026-11-23 20:27 UTC · original

Independent Windows + RTX 5080 GPU verification of 62e0e2596 (merge-base 956a476bf) on NVIDIA GeForce RTX 5080 (Blackwell desktop, driver 617.42, D3D12 SM 6.6 + mesh shaders, 32-wide waves, Windows 11, Ryzen 7 9800X3D, Rust 1.100.0, DXC 1.9.2602.17, no XCL_SAMPLE_*, no game files):

Build & Tests

  • cargo build --workspace && cargo test --workspace -- --test-threads=4: 573 passed, 0 failed, 39 ignored (git diff --check clean; 2 expected no wave64 skips).
  • All 4 new wave32 / SDWA tests passed on RTX 5080: wave32_src_vccz_execz_and_saveexec_b32_hlsl, sdwa_f16_inline_constants_hlsl, gpu_wave32_and_wave64_src_vccz_execz, and gpu_sdwa_f16_inline_constants.

Code check

  • mask_zero(lo) cleanly unifies src_vccz (251), src_execz (252), and s_cbranch_vccz/execz so wave32 tests lo == 0u only (and _b32 saveexec/wrexec no longer reads s127).
  • SDWA sources() forwarding src_f16 to code32() for scalar inline constants while excluding v_cvt_f16_u16/v_cvt_f16_i16 in valu16() looks exact. No issues found.

(AI-assisted)

**@⁠mastrr9** on GitHub · 2026-11-23 20:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/191#issuecomment-7113100397) Independent Windows + RTX 5080 GPU verification of `62e0e2596` (merge-base `956a476bf`) on **NVIDIA GeForce RTX 5080** (Blackwell desktop, driver `617.42`, D3D12 SM 6.6 + mesh shaders, 32-wide waves, Windows 11, Ryzen 7 9800X3D, Rust `1.100.0`, DXC `1.9.2602.17`, no `XCL_SAMPLE_*`, no game files): ### Build & Tests - `cargo build --workspace && cargo test --workspace -- --test-threads=4`: **573 passed, 0 failed, 39 ignored** (`git diff --check` clean; 2 expected `no wave64` skips). - All 4 new wave32 / SDWA tests passed on RTX 5080: `wave32_src_vccz_execz_and_saveexec_b32_hlsl`, `sdwa_f16_inline_constants_hlsl`, `gpu_wave32_and_wave64_src_vccz_execz`, and `gpu_sdwa_f16_inline_constants`. ### Code check - `mask_zero(lo)` cleanly unifies `src_vccz` (`251`), `src_execz` (`252`), and `s_cbranch_vccz/execz` so wave32 tests `lo == 0u` only (and `_b32` `saveexec`/`wrexec` no longer reads `s127`). - SDWA `sources()` forwarding `src_f16` to `code32()` for scalar inline constants while excluding `v_cvt_f16_u16`/`v_cvt_f16_i16` in `valu16()` looks exact. No issues found. *(AI-assisted)*
Author
Owner

@⁠WarmMilkCodes on GitHub · 2026-11-23 20:35 UTC · original

Tested #191 62e0e25 merged onto main 956a476 on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): pass

cargo test --workspace --no-fail-fast -- --test-threads=4, no XCL_SAMPLE_* data:

main this
passed 568 572
failed 1 1
GPU tests skipped 0 0

No new failures vs main. The PR's 4 new tests pass on RDNA2 (native 64-wide subgroups available, so the wave64 paths run unsplit here). The one failure on both, gpu_wave64_ps_whole_wave_reductions, is the 32-lane PS case on this card (#155).

**@⁠WarmMilkCodes** on GitHub · 2026-11-23 20:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/191#issuecomment-7113284298) Tested #191 `62e0e25` merged onto main `956a476` on AMD Radeon RX 6600 XT (RDNA2), driver 32.0.21045.29003, Windows 11 23H2 (22631.6199): pass `cargo test --workspace --no-fail-fast -- --test-threads=4`, no `XCL_SAMPLE_*` data: | | main | this | |---|---|---| | passed | 568 | 572 | | failed | 1 | 1 | | GPU tests skipped | 0 | 0 | No new failures vs main. The PR's 4 new tests pass on RDNA2 (native 64-wide subgroups available, so the wave64 paths run unsplit here). The one failure on both, `gpu_wave64_ps_whole_wave_reductions`, is the 32-lane PS case on this card (#155).
Author
Owner

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

Linux / Wine / Turing run of 62e0e2596 (merge-base 956a476, the current main, so PR head = merge result). This adds an older GPU generation and a different D3D12 path, vkd3d-proton → dxil-spirv → NVIDIA Vulkan, to the Windows RTX 5050/5080 runs above.

Setup: Ubuntu 24.04, GeForce RTX 2060 (Turing, 32-lane waves), NVIDIA 595.91.07. Wine 11.21 Staging (wow64). vkd3d-proton master 30b0eb9 with the vtable-identity checks relaxed as in #175. DXVK 3.1.1 dxgi. XCL cross-built for x86_64-pc-windows-gnu (mingw-w64 13), release. DXC 1.7.2308. No game files, no XCL_SAMPLE_*.

The 4 new tests, at the PR head and on a control: main's emit.rs with this PR's tests.rs.

Test main + new tests PR head
wave32_src_vccz_execz_and_saveexec_b32_hlsl FAIL (s_and_saveexec_b32: op unsupported) pass
sdwa_f16_inline_constants_hlsl FAIL pass
gpu_wave32_and_wave64_src_vccz_execz FAIL (s_and_saveexec_b32: op) pass
gpu_sdwa_f16_inline_constants FAIL: v_add_f16_sdwa 1.0 + 2.0 gives 0x4000 (the f32 constant's low half, 0.0h, + 2.0) instead of 0x4200 pass

Both GPU tests ran on the RTX 2060: the device was found and neither test skipped.

The whole gpu::recomp::tests group, as a regression check (--test-threads=1):

passed failed ignored
main + new tests 96 9 17
PR head 100 5 17

The 4-test difference is exactly the table above. The other 5 fail identically on both, so they come from this stack, not the PR. All 5 read title or process memory through the memory windows and get zeros: 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.

Code: I read the diff and agree with the review above. One note for anyone checking the hardware later: v_cvt_f16_u16 / v_cvt_f16_i16 with a float inline constant now take the f32 pattern's low 16 bits (0x3F800000 & 0xFFFF = 0 for 1.0). That matches how LLVM treats 16-bit integer operands as far as I know, but I haven't verified it on AMD hardware, and NVIDIA can't show it.

Not covered: native 64-lane hardware (AMD); this GPU runs only 32-lane waves; Windows; the e2e and integration test binaries; any title.

**@⁠Kalmarv** on GitHub · 2026-11-23 20:39 UTC · [original](https://github.com/xcl-dev/xcl/pull/191#issuecomment-7113369426) Linux / Wine / Turing run of `62e0e2596` (merge-base `956a476`, the current `main`, so PR head = merge result). This adds an older GPU generation and a different D3D12 path, vkd3d-proton → dxil-spirv → NVIDIA Vulkan, to the Windows RTX 5050/5080 runs above. **Setup:** Ubuntu 24.04, **GeForce RTX 2060 (Turing, 32-lane waves)**, NVIDIA 595.91.07. Wine 11.21 Staging (wow64). vkd3d-proton `master` 30b0eb9 with the vtable-identity checks relaxed as in #175. DXVK 3.1.1 `dxgi`. XCL cross-built for `x86_64-pc-windows-gnu` (mingw-w64 13), release. DXC 1.7.2308. No game files, no `XCL_SAMPLE_*`. **The 4 new tests**, at the PR head and on a control: `main`'s `emit.rs` with this PR's `tests.rs`. | Test | `main` + new tests | PR head | |---|---|---| | `wave32_src_vccz_execz_and_saveexec_b32_hlsl` | FAIL (`s_and_saveexec_b32: op` unsupported) | pass | | `sdwa_f16_inline_constants_hlsl` | FAIL | pass | | `gpu_wave32_and_wave64_src_vccz_execz` | FAIL (`s_and_saveexec_b32: op`) | pass | | `gpu_sdwa_f16_inline_constants` | FAIL: `v_add_f16_sdwa 1.0 + 2.0` gives `0x4000` (the f32 constant's low half, 0.0h, + 2.0) instead of `0x4200` | pass | Both GPU tests ran on the RTX 2060: the device was found and neither test skipped. **The whole `gpu::recomp::tests` group, as a regression check** (`--test-threads=1`): | | passed | failed | ignored | |---|---|---|---| | `main` + new tests | 96 | 9 | 17 | | PR head | 100 | 5 | 17 | The 4-test difference is exactly the table above. The other 5 fail identically on both, so they come from this stack, not the PR. All 5 read title or process memory through the memory windows and get zeros: `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`. **Code:** I read the diff and agree with the review above. One note for anyone checking the hardware later: `v_cvt_f16_u16` / `v_cvt_f16_i16` with a *float* inline constant now take the f32 pattern's low 16 bits (`0x3F800000 & 0xFFFF` = 0 for 1.0). That matches how LLVM treats 16-bit integer operands as far as I know, but I haven't verified it on AMD hardware, and NVIDIA can't show it. **Not covered:** native 64-lane hardware (AMD); this GPU runs only 32-lane waves; Windows; the e2e and integration test binaries; any title.
Author
Owner

@⁠ivall on GitHub · 2026-11-23 20:52 UTC · original

Merged (main 2abc562). Checked on an RX 9070 (RDNA4) with the 11 PRs merged together on main 38b05b7: cargo build --workspace && cargo test --workspace -- --test-threads=4 - 547 unit tests passed, 0 failed (19 ignored); the integration and e2e tests passed too.

**@⁠ivall** on GitHub · 2026-11-23 20:52 UTC · [original](https://github.com/xcl-dev/xcl/pull/191#issuecomment-7113683180) Merged (main 2abc562). Checked on an RX 9070 (RDNA4) with the 11 PRs merged together on main 38b05b7: `cargo build --workspace && cargo test --workspace -- --test-threads=4` - 547 unit tests passed, 0 failed (19 ignored); the integration and e2e tests passed too.
This discussion has been locked. Commenting is limited to contributors.
No description provided.