Skip to content

Recompiler: 16-bit compares read their low halves whatever op_sel says (#1293) - #1296

Open
tiagonogueiraa-bit wants to merge 1 commit into
xcl-dev:mainfrom
tiagonogueiraa-bit:vopc16-opsel
Open

tiagonogueiraa-bit wants to merge 1 commit into
xcl-dev:mainfrom
tiagonogueiraa-bit:vopc16-opsel

Conversation

@tiagonogueiraa-bit

@tiagonogueiraa-bit tiagonogueiraa-bit commented Nov 24, 2026 •

Copy link
Copy Markdown

On RDNA2, 16-bit compares (v_cmp_* / v_cmpx_* over f16, u16, i16) take both sources from the low halves and ignore op_sel. This was measured on gfx1036 in Marvisak/VIctory#833. vopc honoured op_sel, so op_sel:[1,0] on 0x4000_3C00 < 0x3C00_3E00 compared 2.0 < 1.5 instead of 1.0 < 1.5. v_cmp_class_f16 was not measured and keeps op_sel, as the issue suggests. Fixes #1293.

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs (vopc): the 16-bit halves come from the low 16 bits except for class.
  • crates/xcl/src/gpu/recomp/tests.rs: gpu_cmp_16_ignores_op_sel, one f16, u16 and i16 compare each, with op_sel set and high halves that give the opposite answer.

Tested

  • macOS, Rust stable: cargo check -p xcl --lib --tests --target x86_64-pc-windows-msvc passes with no errors (C stubbed, not linked).
  • On the CPU, not a GPU: I translated the test's program with gpu::recomp from main and from this branch and ran the emitted HLSL as C++ on one lane with the test's registers. On main all four compares are false, so the test fails. With this change all four are true.
  • GPU runs by others on this head 8b247b0:
    • @vitor127wt (RTX 5070 Ti, Wine + vkd3d-proton): gpu_cmp_16_ignores_op_sel passes in the workspace suite and run on its own. The suite's failures under Wine are also failures on the base 930e8b4. (report)
    • @DavidM1911 (RTX 3060 Ti, Windows 11, merged with main): cargo test -p xcl --lib recomp, 190 passed, 0 failed, 18 ignored. (report)
      Later, the whole lib with --test-threads=1: all passed, 0 failed, 21 ignored. (report)
  • @ySKELLETONX (AMD RX 7600 XT, RDNA3, native Windows 11): scripts/test.ps1 752 passed, 0 failed, 41 ignored, no SKIPPED. With the emit.rs change reverted, gpu_cmp_16_ignores_op_sel fails at wave64 v_cmp_lt_f16 op_sel:[1,0]. (report)

Regression run
By @IvyNotFound: scripts/smoke.ps1 -Seconds 60, XCL_PRESS_A_AT=15, unedited, from the report.

main:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1331 (PresentX 1332)
presents per 2 s (last 3): 19 43 38
device removals: 0
crashes: 0
peak commit: 26748 MB

PR:

xcl-smoke v1
commit: 8b247b0f1068fcca07b0752a46ffea160f83b46d
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1320 (PresentX 1320)
presents per 2 s (last 3): 8 22 47
device removals: 0
crashes: 0
peak commit: 26630 MB

Not tested

AI use

  • Claude Code with Claude Opus 5.5. It wrote the change, the test and this description, and ran the macOS checks above.

🤖 Generated with Claude Code

xcl-dev#1293)

On RDNA2, v_cmp_* / v_cmpx_* over f16, u16 and i16 take both sources from
the low 16 bits and ignore op_sel. This was measured on gfx1036 in
Marvisak/VIctory#833, with v_add_nc_u16 under the same bits honouring
them as the control. vopc selected the high half for each set bit, so
op_sel:[1,0] on 0x4000_3C00 < 0x3C00_3E00 compared 2.0 < 1.5 instead of
1.0 < 1.5. v_cmp_class_f16 was not measured and keeps op_sel.

gpu_cmp_16_ignores_op_sel runs one f16, u16 and i16 compare each, with
op_sel bits set, whose high halves give the opposite answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib lib recomp: 190 passed, 18 ignored, 0 failed.

Thanks!

@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

@DavidM1911 thank you! Two details would make this count for the merge:

  • the commit you tested: the head is 8b247b0. Which main commit was it merged with?
  • that gpu::recomp::tests::gpu_cmp_16_ignores_op_sel actually ran on the GPU rather than printing SKIPPED. Running cargo test -p xcl --lib gpu_cmp_16_ignores_op_sel -- --nocapture shows it.

If you get the chance, the whole suite (cargo test --workspace -- --test-threads=4, with its counts) is what CONTRIBUTING asks for.

Written with Claude Code (Claude Opus 5.5).

@vitor127wt

Copy link
Copy Markdown

Test report on RTX 5070 Ti under Wine

Following up on #1243. I tested the exact PR head 8b247b0f1068fcca07b0752a46ffea160f83b46d in a separate checkout and build directory. gpu::recomp::tests::gpu_cmp_16_ignores_op_sel passed in the workspace suite and in an isolated rerun with --exact gpu::recomp::tests::gpu_cmp_16_ignores_op_sel --nocapture --test-threads=1 (1 passed, 0 failed, 0 ignored, 0 skipped). The test log confirmed the RTX 5070 Ti and DXC were in use.

Tested

  • RTX 5070 Ti (16,303 MiB reported), NVIDIA Linux driver 620.73.04, Ryzen 7 9700X, 32 GB DDR5. CachyOS x86-64, kernel 7.3.5-2-cachyos, Wine 11.22, DXVK v2.7.1-498-ga6764047e587178, vkd3d-proton 3.1.0 from Proton-CachyOS (0bb64c56c8f0dcc), DXC 1.9.2609.5. Rust 1.100.0 and cargo-xwin 0.24.1, Windows MSVC debug target.
  • cargo xwin build --offline --locked --target x86_64-pc-windows-msvc --workspace succeeded. cargo xwin test --offline --locked --target x86_64-pc-windows-msvc --workspace --no-fail-fast -- --test-threads=4 ran under Wine and reported 686 passed, 66 failed, 41 ignored (exit 101). Four capability skips are included in the harness's passed count and listed below.
  • The same test command on the common base 930e8b49c1c2ec683d22c724a398b39111cd0e56 reported 683 passed, 68 failed, 41 ignored, with the same four skips. All 66 failure names from the PR also appeared on the base. The two additional base failures were gpu_nonfused_mad_and_mac_prevent_fma_contraction (device removed) and never_picks_xcl_itself (file copy error). The baseline build used an on-disk target directory after a linker error on tmpfs.
SKIPPED gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask: no wave64
SKIPPED gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware: no wave64
SKIPPED gpu::texture::tests::gpu_console_textures_upload_every_mip_and_slice: no GPU
SKIPPED gpu::texture::tests::gpu_upload_batches_reuse_the_queues_upload_buffer: no GPU

Not tested

Native Windows, AMD hardware and retail-title smoke runs. Retail sample environment variables were unset.

AI use

Codex (GPT-6, exact variant unavailable) cross-built and ran the tests, compared the failure lists and drafted this report.

@tiagonogueiraa-bit
tiagonogueiraa-bit marked this pull request as ready for review November 24, 2026 14:59
@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you, @vitor127wt! I added your run to Tested and marked the PR ready for review.

Written with Claude Code (Claude Opus 5.5).

@ySKELLETONX

Copy link
Copy Markdown

Test report on head 8b247b0 (asked for in #1243). AI-written (Claude Code, Claude Opus 5.5) from real runs; checked by me.

Tested

  • AMD Radeon RX 7600 XT (RDNA3, driver 32.0.32015.2008), Ryzen 7 5700X3D, Windows 11 Pro 10.0.26300, rustc 1.100.0, debug build, DXC from Windows SDK 10.0.26100
  • scripts/test.ps1 (cargo test --workspace -- --test-threads=4): 752 passed, 0 failed, 41 ignored; no SKIPPED lines
  • gpu::recomp::tests::gpu_cmp_16_ignores_op_sel: ok
  • With this PR's emit.rs change reverted (test kept, base 930e8b4): gpu_cmp_16_ignores_op_sel fails at tests.rs:7195 (wave64 v_cmp_lt_f16 op_sel:[1,0]), so the test catches the change.

Not tested

  • The hardware behaviour itself: the runner checks the translation on the host GPU, so this run does not confirm the gfx1036 measurement.
  • NVIDIA, WARP, any retail title (no smoke runs).

@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you, @ySKELLETONX: the native Windows suite plus the revert check is what this PR was missing. It's in Tested now. The only thing left is an xcl-smoke pair (main and 8b247b0, same title and time) from anyone who has a title.

Written with Claude Code (Claude Opus 5.5).

gustavsi added a commit to gustavsi/xcl that referenced this pull request Nov 24, 2026
…vall#1286-ivall#1291, ivall#1294, ivall#1296-ivall#1297, ivall#1300

Prevent background shader preloading and concurrent DXC/RADV compiles from exhausting host RAM under Wine, and integrate 11 open upstream PRs:
- dxc.rs & real.rs: check free physical RAM (ullAvailPhys.min(ullAvailPageFile)) under Wine instead of swap-inclusive ullAvailPageFile, avoid bypassing the guard after 60 s under Wine, and serialize giant (>= 4 MiB DXIL) driver compiles with BIG_COMPILES under Wine.
- pso_async.rs: cap background preload workers to 1 under Wine.
- title_textures.rs: use real::create_raw_fence in submit_on_title_queue and read coherent-window hash bytes safely via with_title_bytes.
- Integrate upstream PRs ivall#968 (sparse::queue lock-free for late_release), ivall#1286 (v_dot2_f32_f16 NEG_HI abs), ivall#1287 (XMA >8 channels), ivall#1288 (Sleep pauses during PSO bind waits), ivall#1289 (pipeline stream bounds check), ivall#1290 (root signature MAX_ARGS cap), ivall#1291 (console UAV clears ivall#53/ivall#54), ivall#1294 (shadowed PENDING accuracy), ivall#1296 (16-bit compare low halves), ivall#1297 (fence_x pre-cell signal arming), ivall#1300 (log driver compute PSO refusal).

Verified on RX 9060 XT under GE-Proton11-14 (MemoryMax=12G, 80 s): committed RAM stays flat at 4830 MB (down from 27.6 GB OOM), 1493 frames shown, exit 0x0.

Assisted-by: Antigravity (Google DeepMind)
@IvyNotFound

Copy link
Copy Markdown

Regression runs for 8b247b0 on Windows, the xcl-smoke pair this PR still needs. Same retail title, same 60 s, unedited, made with scripts/smoke.ps1 -Seconds 60 and XCL_PRESS_A_AT=15. The PR head as is (base 930e8b4) and main 930e8b4, clean trees, one after the other.

  • NVIDIA GeForce RTX 5080 16 GB (32-lane waves), driver 621.24; Ryzen 7 7800X3D; Windows 11 25H2 (26200.9974); rustc 1.100.0 MSVC; DXC 1.9.2602.17; release.

main:

xcl-smoke v1
commit: 930e8b49c1c2ec683d22c724a398b39111cd0e56
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1331 (PresentX 1332)
presents per 2 s (last 3): 19 43 38
device removals: 0
crashes: 0
peak commit: 26748 MB

this PR:

xcl-smoke v1
commit: 8b247b0f1068fcca07b0752a46ffea160f83b46d
gpu: NVIDIA GeForce RTX 5080
title: game
seconds: 60
exit: 0x0
frames shown: 1320 (PresentX 1320)
presents per 2 s (last 3): 8 22 47
device removals: 0
crashes: 0
peak commit: 26630 MB

Not tested: the suite at this head (see the other reports here); AMD.

AI use: Claude Code, Claude Opus 5.5 ran the runs and wrote this comment.

@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you, @IvyNotFound! Both blocks are under Regression run exactly as posted, with credit. With them the PR has everything CONTRIBUTING asks for.

Written with Claude Code (Claude Opus 5.5).

@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib -- --test-threads=1: all passed, 0 failed, 21 ignored. (Parallel runs intermittently abort with 0xc0000005 — same harness flake seen on unmodified main.)

Thanks!

@tiagonogueiraa-bit

Copy link
Copy Markdown
Author

Thank you @DavidM1911, the whole-lib run is in Tested, next to your earlier recomp one.

CalvyPZ pushed a commit to CalvyPZ/xcl that referenced this pull request Nov 24, 2026
RDNA2 runs the VOP3 encodings of VOP2 (opcodes 0x100-0x13F) and VOP1
(0x180-0x1FF) instructions without op_sel: they read the low halves of
their sources and write the low half of VDST, keeping the high one,
whatever OP_SEL holds. Only the VOP3-only 16-bit opcodes (v_fma_f16,
v_mad_u16, v_add_nc_u16, v_pack_b32_f16, ...) honour it. Both backends
honoured it for every 16-bit op, so v_mul_f16 with OP_SEL 0b1001, for
example, multiplied src0's high half and wrote VDST's high half.

Measured on RDNA2 silicon (gfx1036, the Radeon iGPU of a Ryzen 7 9700X,
through OpenCL inline asm with the OP_SEL bits patched into the dwords):
all 31 16-bit opcodes in these ranges give the same dword with any one
OP_SEL bit set as with none, while the VOP3-only controls change as
op_sel says. LLVM's GFX10 tests (tests/data/llvm-amdgpu/gfx10_vop3.txt)
set OP_SEL on none of the 2372 encodings in these ranges.

rdna2::op_sel returns 0 for these encodings, and the mods() of both
backends take Mods.opsel from it. The 16-bit compares (VOPC in VOP3,
0x000-0x0FF) are left as they are (xcl-dev#1296, xcl-dev#1572). The three tests that
expected the op_sel forms now expect the measured results, a GPU test
checks 80 measured cases, and a decoder test pins which encodings keep
OP_SEL.

The retail title's shader pack has no such instruction with OP_SEL set
(none of its 44.4M instructions apart from the shader-hash v_nops), so
it runs the same code as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@milesah3ad

Copy link
Copy Markdown

The direct DXIL backend counterpart of this fix, from @regiumlepidi's parity sweep on #1269: gpu_cmp_16_ignores_op_sel pass with XCL_DIRECT_DXIL=1 with the patch below. Without it they fail on the direct path.

vopc in gpu/dxil/lower_valu.rs took each 16-bit source from the half op_sel named, so v_cmp_lt_f16 op_sel:[1,0] compared the high half (your test: (0, 0) against (0xFFFFFFFF, 0)). The patch applies op_sel to class only, as your HLSL change does. (#1214 / #1980 change class's src1 handling in the same function, so whichever lands second may need a small rebase.)

How to take it: this PR predates the direct backend on main, so rebase it onto main first (your commit rebases cleanly onto 7994cd1), then git am the patch below. Feel free to fold it into your PR with a Co-Authored-By: milesah3ad <360542007+milesah3ad@users.noreply.github.com> line. I didn't open a separate PR, so this doesn't add another review.

patch (1 commit, for git am)
From 1646dfef4a84f8dab7d15ac5efa2be50ebd7f579 Mon Sep 17 00:00:00 2001
From: milesah3ad <360542007+milesah3ad@users.noreply.github.com>
Date: Tue, 24 Nov 2026 18:54:27 -0600
Subject: [PATCH] Direct DXIL: 16-bit compares read their low halves whatever
 op_sel says

vopc took each 16-bit compare source from the half op_sel named, but
RDNA2's 16-bit compares read both sources from the low halves (measured
on gfx1036, #1293), so v_cmp_lt_f16 with op_sel:[1,0] compared the
wrong half. As #1296 does on the HLSL path, op_sel now applies to
v_cmp_class_f16 only, which was not measured and keeps it.

gpu_cmp_16_ignores_op_sel now passes with XCL_DIRECT_DXIL=1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YPhfiWsdJcDBLYSS8edLyS
---
 crates/xcl/src/gpu/dxil/lower_valu.rs | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/crates/xcl/src/gpu/dxil/lower_valu.rs b/crates/xcl/src/gpu/dxil/lower_valu.rs
index beafdcd..eb8596e 100644
--- a/crates/xcl/src/gpu/dxil/lower_valu.rs
+++ b/crates/xcl/src/gpu/dxil/lower_valu.rs
@@ -1187,7 +1187,9 @@ impl Lw {
             return err(d, "VOPC");
         }
         let (mut ua, mut ub) = (u[0].w(), u[1].w());
-        let half = |s: &mut Self, i: u64, v: Value| if m.opsel >> i & 1 == 1 { s.lshrc(v, 16) } else { s.andc(v, 0xFFFF) };
+        // RDNA2's 16-bit compares read both sources from the low halves whatever op_sel says
+        // (measured on gfx1036, #1293); class was not measured and keeps op_sel (as #1296)
+        let half = |s: &mut Self, i: u64, v: Value| if opn == "class" && m.opsel >> i & 1 == 1 { s.lshrc(v, 16) } else { s.andc(v, 0xFFFF) };
         let ty = match ty {
             "f16" => {
                 if opn == "class" {
-- 
2.48.1.windows.1

Tested

Not tested: wave64 hardware (the wave64 cases SKIP here), AMD, any title, the full workspace suite (lib only).

AI use: Claude Code (Claude Opus 5.5) wrote the fix and ran the tests on the machine above. I checked the results.

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.

Recompiler: 16-bit compares honor op_sel; RDNA2 hardware ignores it (measured on gfx1036, see VIctory#833/#926)

6 participants