Repository navigation
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_f16with OP_SEL0b1001multiplied 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: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_f16andv_cvt_pknorm_u16_f16.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-hashv_nop.crates/xcl/src/gpu/recomp/emit.rs,crates/xcl/src/gpu/dxil/lower_valu.rs:mods()takesMods.opselfrom it. Thevalu16doc comment is updated.crates/xcl/src/gpu/recomp/tests.rs:gpu_vop3_forms_of_vop1_vop2_16_bit_ops_ignore_op_selhas 80 rows, every expected dword the measured one: each of the 31 opcodes with its OP_SEL bits, plus the VOP3-only controls.gpu_valu_16_and_64_bit(v_mul_f16, now0x0000_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_f16now goes to its own VGPR, so the VOP3v_cvt_norm_u16_f16result is still checked).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-hashv_nops at the start of each program. So it runs the same code as before.Tested
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=4on the RTX 4080 SUPER: 891 passed, 0 failed, 42 ignored (on8a576f94, based onmainb9b6ea62).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).XCL_DIRECT_DXIL=1): all pass. Withop_sel()returning the raw field (main's behaviour), all five fail. With either backend'smods()line reverted, that backend's GPU tests fail.Regression run
mainb9b6ea62:this PR
8a576f94:Not tested
The Xbox Series GPU itself. The measurements are from one RDNA2 part (gfx1036) and one driver.
AMD RDNA3/RDNA4 or Intel as hosts. They only run the translated HLSL/DXIL, so the result doesn't depend on their own op_sel rules.
The VOPC compares: v_cmp_lt_f16, v_cmp_lt_u16 and v_cmp_class_f16 ignore op_sel on the same iGPU, but this PR leaves them alone. This matters for Recompiler: honour OP_SEL[1] for SRC1 in v_cmp_class_f16 xcl-dev/xcl#1214, which honours op_sel in
v_cmp_class_f16. It also matters for Recompiler: 16-bit compares read their low halves whatever op_sel says (#1293) xcl-dev/xcl#1296's note that class was not measured. Neither Recompiler: 16-bit compares read their low halves whatever op_sel says (#1293) xcl-dev/xcl#1296 nor Recompiler: ignore VOP3 op_sel on 16-bit VOPC compares (#1293) xcl-dev/xcl#1572 changes the DXIL backend'svopc.Not run merged with them: these open PRs' tests set OP_SEL on opcodes in these ranges and expect it to select halves:
v_sat_pk_u8_i16with OP_SEL[3]. Silicon writes0x0000_0503and zeroes the high half, as main does.v_sqrt_f16,v_rcp_f16.v_cvt_f32_f16.v_cos_f16.v_fmac_f16.v_cvt_i16_f16.A
git merge-treecheck against all open PRs finds no textual conflict.Wine / vkd3d-proton.
AI use
🤖 Generated with Claude Code
Mirror of xcl-dev#1777 (auto-synced, do not edit).