Skip to content

Recompiler: honour OP_SEL[1] for SRC1 in v_cmp_class_f16 - #1214

Open
b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/v-cmp-class-f16-opsel1
Open

b3IKK wants to merge 1 commit into
xcl-dev:mainfrom
b3IKK:recomp/v-cmp-class-f16-opsel1

Conversation

@b3IKK

@b3IKK b3IKK commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

In V_CMP_CLASS_F16 (rdna2_spec.rs), SRC1 is a 16-bit operand so OP_SEL[1] == 1 selects its upper 16-bit half as the class mask. The emitter applied half(0, &ua) to SRC0 but passed ub unchanged, ignoring OP_SEL[1].

This selects SRC1 via half(1, &ub).

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: use half(1, &ub) for V_CMP_CLASS_F16 SRC1.
  • crates/xcl/src/gpu/recomp/tests.rs: add GPU test gpu_cmp_class_f16_honours_opsel1 covering OP_SEL[1] = 0/1 and OP_SEL = 3 across wave32 and split wave64 (verified failing before the fix).

Tested

  • hardware (GPU + driver, CPU), Windows build, Rust version, debug / release: NVIDIA GeForce RTX 5080 (driver 32.0.16.1088), AMD Ryzen 9 9950X3D, Windows 11 10.0.26300, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1)
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4): 742 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2 no wave64 — gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask, gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)
  • cargo test -p xcl --lib gpu_cmp_class_f16_honours_opsel1: 1 passed, 0 failed across wave32 and split wave64 (failed on the GPU before the fix)

Regression run

main:

xcl-smoke v1
commit: 47efa2ecea0a12934719ae69b81930cf02a4b1c3
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1226 (PresentX 1226)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15341 MB

PR:

xcl-smoke v1
commit: b7254898babb4babf1c988ca5ca131e53cd269e5
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1645 (PresentX 1646)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14602 MB

Not tested

  • AMD GPUs and native wave64 hardware
  • other titles (Minecraft Preview, Unicorn Overlord, Fortnite, XDefiant) and Linux / Wine

AI use

  • OpenCode, Gemini 4 Neon: audited emit.rs, wrote the fix and GPU test, ran the test suite and scripts/smoke.ps1 regression runs, and drafted this PR description.

In V_CMP_CLASS_F16 (rdna2_spec.rs), SRC1 is a 16-bit operand so
OP_SEL[1] == 1 selects its upper 16-bit half as the class mask.
The emitter applied half(0, &ua) to SRC0 but passed ub unchanged,
ignoring OP_SEL[1].

Select SRC1 via half(1, &ub), with a GPU test covering OP_SEL[1]=0/1
and OP_SEL=3 across wave32 and split wave64.

Assisted-by: OpenCode (Gemini 4 Neon)
@DavidM1911

Copy link
Copy Markdown
Contributor

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

  • cargo test -p xcl --lib recomp: 190 passed, 0 failed, 18 ignored (new GPU checks included).

Thanks!

@bjarngard

Copy link
Copy Markdown

Test report for head b725489 (AMD, native wave64)

Tested

  • AMD Radeon(TM) Graphics (Ryzen 9 9950X iGPU, RDNA2, native wave64), driver 32.0.21043.5001; Windows 11 build 26300; Rust 1.99.1 MSVC; DXC 1.9.2602.17; debug
  • XCL_ADAPTER=radeon cargo test --workspace --no-fail-fast -- --test-threads=4: 742 passed, 0 failed, 41 ignored, no SKIPPED
  • With XCL_REQUIRE_GPU=wave64: gpu_cmp_class_f16_honours_opsel1 passed

Not tested: retail titles, RDNA3/RDNA4.

AI use: the tests were run and this report was written by an AI agent, Claude Code (Claude Opus 5.5), on the hardware above. The numbers are copied from the actual test output.

@regiumlepidi

Copy link
Copy Markdown

RTX 5070 Ti: b725489 merged into main 8e87fc7 passes its test on the default path; it still fails with XCL_DIRECT_DXIL=1

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (32-lane waves), driver 617.42; Ryzen 7 9800X3D; Windows 11 Pro 26H2, build 26300.9974; Rust 1.100.0 MSVC; Windows SDK 10.0.26100.0, DXC 1.8.2502.11; debug; no XCL_SAMPLE_*
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --nocapture, one run per cell; PR head b7254898babb4babf1c988ca5ca131e53cd269e5 merged locally into 8e87fc7b62a87ea589ccb9ea6182f514016cf7db, no conflicts (passed / failed / ignored):
tree default XCL_DIRECT_DXIL=1
main 8e87fc7 986 / 4 / 45 985 / 5 / 45
merge 987 / 4 / 45 985 / 6 / 45
  • Default path: gpu_cmp_class_f16_honours_opsel1 passes. The 4 failures are fuzz_validate_and_gpu_0 to _3 (DXIL GPU fuzz tests reproducibly fail with E_OUTOFMEMORY on RTX 5060 #1905, this driver), as on main
  • XCL_DIRECT_DXIL=1: those 4, offline_compute_pipeline_is_reused_by_a_second_process (fails on main too) and gpu_cmp_class_f16_honours_opsel1: wave32 v_cmp_class_f16 OP_SEL[1]=1 reads high half of SRC1, left (0, 0), right (4294967295, 0). The PR's diff touches only recomp/emit.rs and recomp/tests.rs
  • Negative control, only the PR's tests.rs change applied to main 8e87fc7: the new test fails on both paths with the same values
  • 26 SKIPPED lines in each run (18 no wave64, 1 const mask + wave64, 3 per-lane form refused, Developer Mode, d3d12SDKLayers.dll, heap windows, debug layer); none names the new tests

Not tested

  • the wave64 half of the test (gpu_waves() runs wave32 only here), release build, any retail title, other GPUs or drivers

Direct translator patch
gpu_cmp_class_f16_honours_opsel1 fails with XCL_DIRECT_DXIL=1 because the direct translator has the same bug: dxil/lower_valu.rs shifts the whole 32-bit SRC1 instead of the half OP_SEL[1] picks. The patch below mirrors this PR there. With this PR's commit and the patch on main 8e87fc7, the new tests pass on both paths, and cargo test --workspace --locked --no-fail-fast -- --test-threads=4 gives 987 / 4 / 45 (default) and 986 / 5 / 45 (direct); the failures are the same as on main. Take it into this PR if you like, or say if you would rather it go in a separate PR stacked on this one.

Patch (applies with git apply on this PR merged into main 8e87fc7)
diff --git a/crates/xcl/src/gpu/dxil/lower_valu.rs b/crates/xcl/src/gpu/dxil/lower_valu.rs
index beafdcd..430969a 100644
--- a/crates/xcl/src/gpu/dxil/lower_valu.rs
+++ b/crates/xcl/src/gpu/dxil/lower_valu.rs
@@ -1200,7 +1200,9 @@ impl Lw {
                         h = self.xor(h, k);
                     }
                     let cls = self.fclass16(h);
-                    let s = self.bin(BinOp::LShr, ub, cls);
+                    // the class mask is a 16-bit operand too: OP_SEL[1] picks its half
+                    let mask = half(self, 1, ub);
+                    let s = self.bin(BinOp::LShr, mask, cls);
                     let s = self.andc(s, 1);
                     let cond = self.nz(s);
                     return self.vopc_write(d, cmpx, outs, cond);

AI use

  • Claude Code with Claude Opus 5.5: read the diff, ran the tests, wrote the patch and this report.

@JJAutoCompare

Copy link
Copy Markdown

XCL PR #1214 verification

Tested

  • PR #1214 was open at b7254898babb4babf1c988ca5ca131e53cd269e5 before and after testing. The STOR-WINLAB checkout was clean and detached at that SHA.
  • STOR-WINLAB, AMD Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Windows 11 Enterprise Evaluation 25H2 build 26200.9974, Rust and Cargo 1.100.0 on stable-x86_64-pc-windows-msvc, DXC 1.9.2609.5 (01b62ad47). Unoptimized test profile, two jobs, incremental compilation disabled, dev/test debuginfo disabled.
  • Built outside the GPU mutex with cargo +stable-x86_64-pc-windows-msvc test --locked -j 2 -p xcl --lib --no-run --message-format=json (exit 0). The assigned target was L:/XclTooling/pr1801-e00963f-t3-3c561aa2/target. Both TEMP and TMP pointed to L:/XclTooling/pr1214/run-b725489-20261125-080053-770/temp.
  • Executed the pinned binary under & 'L:/XclTooling/Invoke-ArcTest.ps1' -Test { ... } with XCL_ADAPTER=A770, XCL_DXC_DIR=%LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64, XCL_DIRECT_DXIL=0, and XCL_SPLIT_WAVE64=0. The fixture compiles translated HLSL to cs_6_6 with DXC. Used process-scoped RemoteSigned.
& 'L:/XclTooling/pr1214/run-b725489-20261125-080053-770/xcl-pr1214-lib-tests.exe' --exact gpu::recomp::tests::gpu_cmp_class_f16_honours_opsel1 --nocapture --test-threads=1

1 passed, 0 failed, 0 ignored, 0 explicit GPU skips, 719 filtered out, 0.68 s, exit 0. Both the Cargo artifact and pinned executable had SHA-256 09D9C6BB6C0A04BF0A4A45075C4FF3E19C9599CEBF74CD9D43CD5A95D0952579 before waiting and inside the lock. The wrapper confirmed release and exited 0. The target slot is free.

Each lane was seeded with v0=0x0000_3C00 (low half +1.0h), v1=0x0100_0000 (high-half positive-normal class bit 8, low half zero), and v2=0x3C00_0000 (high half +1.0h, low half +0.0h). All three wave32 GPU readback assertions passed.

OP_SEL SRC0 / SRC1 SGPR pair Lane mask (low, high)
2 v0 low / v1 high s0, s1 (0xFFFF_FFFF, 0x0000_0000)
0 v0 low / v1 low s2, s3 (0x0000_0000, 0x0000_0000)
3 v2 high / v1 high s4, s5 (0xFFFF_FFFF, 0x0000_0000)

The before/after discussion snapshots contained one independent exact-head report for the fixture on AMD and two NVIDIA reports on merges with main. I found no equivalent exact-head A770 report. AMD report · Triage #1607

Not tested

Native wave64, split wave64, direct DXIL (including stacked PR #1980), other adapters, a negative control, the full workspace suite, and retail smoke. The A770 exposes hardware wave sizes 8–32, and the exact-head fixture enters its wave64 branch only when native wave64 is available.

AI use

T3 Code / Codex (gpt-6.2-sol) verified the live head, inspected the fixture, ran the checked-in test, and wrote this report. No source edits, commits, or GitHub writes.

Logs

  • L:/XclTooling/pr1214/run-b725489-20261125-080053-770/environment.log
  • L:/XclTooling/pr1214/run-b725489-20261125-080053-770/build.log
  • L:/XclTooling/pr1214/run-b725489-20261125-080053-770/build.jsonl
  • L:/XclTooling/pr1214/run-b725489-20261125-080053-770/arc.stdout.log
  • L:/XclTooling/pr1214/run-b725489-20261125-080053-770/arc.stderr.log
  • L:/XclTooling/pr1214/run-b725489-20261125-080053-770/postcheck.log
  • L:/XclTooling/pr1214/run-b725489-20261125-080053-770/pr-before.html, pr-after.html, triage.html

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