Skip to content

[upstream #1777] Recompiler: VOP3 forms of VOP1/VOP2 16-bit ops ignore op_sel - #357

Open
ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1777
Open

ufoptg wants to merge 1 commit into
mainfrom
upstream-pr/1777

Conversation

@ufoptg

@ufoptg ufoptg commented Nov 25, 2026

Copy link
Copy Markdown
Owner

RDNA2 ignores op_sel on the VOP3 encodings of VOP2 (opcodes 0x100–0x13F) and VOP1 (0x180–0x1FF) instructions. Their 16-bit operations read the low halves of the sources and write the low half of VDST, keeping the high half, 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. For example, v_mul_f16 with OP_SEL 0b1001 multiplied src0's high half and wrote VDST's high half; the hardware multiplies the low halves and writes the low half. Same subject as xcl-dev#1293, which covers the 16-bit compares.

How it was measured: on RDNA2 silicon (gfx1036, the Radeon iGPU of a Ryzen 7 9700X, driver 32.0.21034.41), through OpenCL inline asm. LLVM assembles the plain VOP3 form, and each OP_SEL bit (dword0 [14:11]) is then patched into the dwords and run with .long:

  • Ignored: all 31 16-bit opcodes in these ranges give the same dword with any one OP_SEL bit set as with none. The inputs are chosen so that reading or writing a high half would change the result.
  • Honoured: the VOP3-only controls change exactly as op_sel says. They are v_fma_f16, v_max3_f16, v_med3_f16, v_mad_u16, v_add_nc_u16, v_mul_lo_u16, v_lshlrev_b16, v_max_u16, v_pack_b32_f16 and v_cvt_pknorm_u16_f16.
  • LLVM agrees: LLVM's GFX10 tests in this repository (tests/data/llvm-amdgpu/gfx10_vop3.txt) set OP_SEL on none of their 2372 encodings in these ranges.

What is in it

  • crates/xcl/src/gpu/rdna2.rs: op_sel(d) returns 0 for ENC_VOP3 opcodes 0x100–0x13F and 0x180–0x1FF, and the OP_SEL field otherwise. It also has a test, op_sel_as_rdna2_runs_it, that checks which encodings keep OP_SEL: VOP3-only, VOPC in VOP3, VOP3P, and the shader-hash v_nop.
  • crates/xcl/src/gpu/recomp/emit.rs, crates/xcl/src/gpu/dxil/lower_valu.rs: mods() takes Mods.opsel from it. The valu16 doc comment is updated.
  • crates/xcl/src/gpu/recomp/tests.rs:
    • gpu_vop3_forms_of_vop1_vop2_16_bit_ops_ignore_op_sel has 80 rows, every expected dword the measured one: each of the 31 opcodes with its OP_SEL bits, plus the VOP3-only controls.
    • Three tests expected the op_sel forms and now expect the measured results:
      • gpu_valu_16_and_64_bit (v_mul_f16, now 0x0000_42C0, the value the iGPU gives for these inputs);
      • cvt_norm_f16_instructions (HLSL text);
      • gpu_more_atomics_sub_dword_scratch_valu (v_cvt_norm_i16_f16 now goes to its own VGPR, so the VOP3 v_cvt_norm_u16_f16 result is still checked).
  • Left as they are: the 16-bit compares (VOPC in VOP3, 0x000–0x0FF). Recompiler: 16-bit compares read their low halves whatever op_sel says (#1293) xcl-dev/xcl#1296 and Recompiler: ignore VOP3 op_sel on 16-bit VOPC compares (#1293) xcl-dev/xcl#1572 change them in the HLSL backend.

The retail title isn't affected. A scan of its whole shader pack (26 698 programs, 44.4M instructions, the same totals as xcl shaders --json) finds no ENC_VOP3 VOP1/VOP2/VOPC instruction with OP_SEL set, apart from the two shader-hash v_nops at the start of each program. So it runs the same code as before.

Tested

  • NVIDIA GeForce RTX 4080 SUPER 16 GB (driver 621.24, 32-lane waves) and AMD Radeon(TM) Graphics (gfx1036 iGPU, picked with XCL_ADAPTER=radeon), Ryzen 7 9700X, Windows 11 Pro 26200, Rust 1.98.0; tests debug, title release.
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the RTX 4080 SUPER: 891 passed, 0 failed, 42 ignored (on 8a576f94, based on main b9b6ea62).
  • SKIPPED on this adapter: gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask (no wave64), gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware (no wave64), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (cannot disable the driver cache without Windows Developer Mode).
  • The five tests above, on both GPUs and both backends (HLSL, and XCL_DIRECT_DXIL=1): all pass. With op_sel() returning the raw field (main's behaviour), all five fail. With either backend's mods() line reverted, that backend's GPU tests fail.
  • Retail title 1.0.2.1: the 60 s smoke runs below.

Regression run

main b9b6ea62:

xcl-smoke v1
commit: b9b6ea62080cc62fc19e212033372d01c6214e5c
gpu: NVIDIA GeForce RTX 4080 SUPER
title: 2f5362b1
seconds: 60
exit: 0x0
frames shown: 1645 (PresentX 1645)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15879 MB

this PR 8a576f94:

xcl-smoke v1
commit: 8a576f94b207af37886fea57c0ee94cc7d35cb6d
gpu: NVIDIA GeForce RTX 4080 SUPER
title: 2f5362b1
seconds: 60
exit: 0x0
frames shown: 1521 (PresentX 1521)
presents per 2 s (last 3): 47 61 60
device removals: 0
crashes: 0
peak commit: 15745 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5):
    • wrote the silicon probes and ran them on the iGPU;
    • counted the retail shader pack;
    • wrote the change, the tests (expected values generated from the probe results) and this description;
    • ran the tests and the regression runs.
  • Five further Claude Opus 5.5 agents reviewed it (four reviewers and a verifier). Their findings: no CPU-only coverage, stale doc comments, 10 opcodes not yet measured (now measured), and the open PRs above. All are addressed above.

🤖 Generated with Claude Code


Mirror of xcl-dev#1777 (auto-synced, do not edit).

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

2 participants