Skip to content

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

Merged
ivall merged 1 commit into
xcl-dev:mainfrom
RandomGithub12309:fix/recomp-wave32-vccz-sdwa-f16
Nov 23, 2026
Merged

ivall merged 1 commit into
xcl-dev:mainfrom
RandomGithub12309:fix/recomp-wave32-vccz-sdwa-f16

Conversation

@RandomGithub12309

Copy link
Copy Markdown
Contributor

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 (xcl-dev#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 (xcl-dev#105).
- Add HLSL and GPU regression tests covering wave32/wave64 src_vccz/src_execz, s_and_saveexec_b32, and SDWA f16 inline constants.
theaustinayers added a commit to theaustinayers/xcl that referenced this pull request Nov 23, 2026
…09) applied

xcl-dev#192: XGTextureAddressComputer xcl-dev#10 as GetResourceTiling, read from the console library's code - replaces the local version, which was not checked against it. xcl-dev#191: recompiler wave32 src_vccz / src_execz and SDWA f16 inline constants. Their authors' work, applied as it is. 200 s run through the title's menus: no change in the picture, no regression.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@mastrr9

mastrr9 commented Nov 23, 2026

Copy link
Copy Markdown

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)

@WarmMilkCodes

Copy link
Copy Markdown
Contributor

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).

@Kalmarv

Kalmarv commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

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.

@ivall

ivall commented Nov 23, 2026

Copy link
Copy Markdown
Collaborator

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.

Decodere added a commit to Decodere/xcl that referenced this pull request Nov 25, 2026
In `Lw::sources` (`dxil/lower_valu.rs`), the initial operand loop
skipped `SRC0` for non-plain variants but did not skip `VSRC1` for
`Variant::Sdwa` (unlike HLSL `recomp/emit.rs` after merged PR xcl-dev#191).
Before the SDWA match arm replaced `u[1]` using `S1` + `VSRC1`, the
initial loop called `self.read` -> `self.vreg(vsrc1)` on the raw 8-bit
`VSRC1` encoding. When `S1 == 1` (scalar SGPR or inline constant such as
`242` = `1.0f` or `138` = `10`), that polluted `self.init.touched` with
bogus VGPRs (`v242`, `v138`, `v4`) and inflated `top_vgpr()`, bloating
any `v_movrel*` / `v_swaprel_b32` select chains in the shader.

Skip `VSRC1` for `Variant::Sdwa` in the initial operand loop (parity
with `xcl-dev#191`) and add DXIL disassembly + RTX 4060 GPU regression tests.

Part of xcl-dev#1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
raylitebull pushed a commit that referenced this pull request Nov 25, 2026
In crates/xcl/src/gpu/dxil/lower.rs, Lw::salu unconditionally called read64 on _b64 saveexec/wrexec forms even in wave32 (!self.wave64) and unconditionally read sreg(127) (EXEC_HI) before branching on (!self.wave64 || name.ends_with("_b32")). On 32-bit-only source encodings such as m0 (SSRC0 = 124), wave32 S_AND_SAVEEXEC_B64 failed translation with Err("...: op"), and on SGPR sources it spuriously touched s[n+1] and EXEC_HI (s127).

Move source reads and EXEC_HI handling inside the wave32/_b32 vs wave64 _b64 branches to mirror HLSL (#191), and add unit/disassembly and wave32 RTX 4060 GPU regression tests in lower.rs.

Part of #1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants