Skip to content

rdna2spirv: a constant operand of the packed 16-bit integer ops is its 32-bit value (measured on RDNA2) - #2224

Open
Vonsek wants to merge 5 commits into
ItsNotRexed:mainfrom
Vonsek:claude/hw-pk-int-const
Open

Vonsek wants to merge 5 commits into
ItsNotRexed:mainfrom
Vonsek:claude/hw-pk-int-const

Conversation

@Vonsek

@Vonsek Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-HW-PK-INT-CONST (claim)

What and why

The packed 16-bit integer ops (v_pk_add/sub_u16/i16, v_pk_mul_lo_u16, v_pk_mad_u16/i16, v_pk_max/min_u16/i16) raised Unsupported: ... high half of a constant for a constant whose high half op_sel/op_sel_hi would read. The row in docs/design.md said that half was not measured. With the default op_sel_hi:[1,..] that is every constant operand, so v_pk_add_u16 v0, v1, 1 did not translate.

Measured natively on an RDNA2 iGPU (gfx1036, AMD driver 26.10.1) with raw kernels through tools/hw_oracle, wave32 and wave64 identical. The constant is its 32-bit value, split into halves like a register:

constant low half high half
1 0x0001 0x0000
-1 0xffff 0xffff
-16 0xfff0 0xffff
1.0 0x0000 0x3f80 (f32 bits, not the f16 value the f16 packed ops read)
0.15915494 0xf983 0x3e22
literal 0x12345678 0x5678 0x1234

op_sel / op_sel_hi pick the half as for a register (op_sel:[0,1] op_sel_hi:[1,0] swaps them). Checked with v_pk_add_u16 (also 64, -1.0, 0.5), v_pk_mad_u16/i16 with a constant in each source, v_pk_sub_i16, v_pk_mul_lo_u16 and v_pk_max/min_u16/i16. src_u already returns that 32-bit value, so the fix only removes the rejection. The packed shifts already read constants that way and matched the hardware.

  • runtime/test/shaders/cs_w32_pk_int_const.asm: eight ops with constants, hand-derived words in the header.
  • tests/semantic/test_pk_int_const.py (+ fixture) runs it on the CPU against a Python reference.
  • tests/semantic/test_alu_pk_int16.py used to assert the rejection. It now checks four measured values (5, -1, 1.0, and a literal with swapped halves).
  • docs/design.md: the packed integer row now has the measurement.

Tested

  • python -I scripts/run_gpu_tests.py --filter cs_w32_pk_int_const: PASS 8/8 words on an NVIDIA GeForce RTX 5080 (driver 616.92) and on the AMD Radeon RDNA2 iGPU (Ryzen 9 9950X3D, driver 26.10.1). vk_compute_test reports the devices as NVIDIA GeForce RTX 5080 (subgroup 32..32) and AMD Radeon(TM) Graphics (subgroup 32..64).
  • On main the test fails with missing .spv (translation failed) (v_pk_add_u16 high half of a constant), and test_pk_int_const errors.
  • Negative control: making the half extraction always read bit 0 (self.cu(16 * sl[i]) → self.cu(0)) fails the GPU test on both GPUs (262148 131074 0 ...) and fails all 8 words of the semantic test.
  • python -m unittest discover -s tests/semantic: 1675 tests OK. regen_fixtures.py --check is clean and tests/test_shader_checks.py passes. tests/test_docs_design_rows.py has the same 3 failures as on main (repeated topics already there).
  • Not run: a corpus count (needs game files).

AI-assisted.

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.

…s 32-bit value

v_pk_add/sub_u16/i16, v_pk_mul_lo_u16, v_pk_mad_u16/i16 and v_pk_max/min_u16/i16
rejected a constant whose high half op_sel/op_sel_hi would read, which with the
default op_sel_hi is every constant operand. Measured natively on RDNA2 (gfx1036,
raw kernels through tools/hw_oracle, wave32 = wave64): the constant is its 32-bit
value split into halves, an integer inline constant sign-extended, a float inline
constant as its f32 bits (1.0 gives 0x0000 / 0x3f80), a literal as written. That
is what src_u already gives, so the rejection goes.

GPU test cs_w32_pk_int_const (eight ops, rejected on main), semantic fixture and
test, design.md row with the measurement; test_alu_pk_int16 now checks the
measured values instead of the rejection.

AI-assisted.
@Sanonymous01

Copy link
Copy Markdown
Contributor

Tested c570d788 on an AMD RDNA2 iGPU (gfx1036), AMD Windows driver 32.0.21044.64, Windows 11: pass (AI-assisted).

  • runtime/test/shaders/check.py with LEONIDA_VK_DEVICE=AMD: cs_w32_pk_int_const ok. The failures elsewhere in that run (cs_bvh*, cs_imgatomic*, cs_resinfo, ps_ssharp) are outside this PR's files and come from my older local runtime build.

  • tests/semantic: 1,675 OK; test_pk_int_const.py 3/3; test_alu_pk_int16.py OK; regen_fixtures.py --check clean.

  • An independent hardware cross-check, wider than the PR's cases. I had measured the same thing for SHADER-352 with my own raw kernels through tools/hw_oracle:

    • all eleven ops;
    • twelve constants: 0, 1, -1, 64, -16, 1.0, -1.0, 0.5, -4.0, 0.15915494, and the literals 0x12345678 and 0xffff8001;
    • the constant in every source position (src2 included for v_pk_mad_*), with all four op_sel/op_sel_hi combinations of that operand.

    That is 1,248 programs, and wave32 = wave64 on every word. The model "a constant is its 32-bit value, split like a register" gives all 1,248 words. This PR's translator gives all 1,248 too, where main raises Unsupported on 936 of them.

  • Corpus count, from my own 1.0.2.1 copy (numbers only): the 26,503 shaders contain no packed 16-bit integer op at all, so no game shader changes.

Same conclusion as yours, so I'm leaving SHADER-352 to this PR rather than opening a second one.

@emirduran707

Copy link
Copy Markdown
Contributor

Tested c570d78 on AMD Radeon RX 9060 XT (RDNA4), AMD driver 26.10.44 (LLPC, Vulkan driver 2.0.395), Windows 11 Pro 10.0.26300, subgroup 32..64: pass.

  • python -I scripts/run_gpu_tests.py --build <build> --filter cs_w32_pk_int_const: 1/1 pass, words 327684 262146 1065353216 1450709556 1075839024 4 4294967280 3221225472. Same with LEONIDA_W64_EMULATE=1.
  • Whole suite (native wave64), with this PR's translator: 186 shaders translated, 186 pass spirv-val; 168/181 passed, 13 skipped, 0 failed. The skips are the 12 fixtures the d3d12_* tests run, and ps_w64x_readlane (skipped on main too, see check.py: judge ps_w64x_readlane where vk_harness required 64 (its line has no "required") #2085; not from this PR).
  • build.py + check.py: 200 shaders translated, 200 pass spirv-val; 157 of 161 pass, 4 skipped (the 3 mesh fixtures and ps_w64x_readlane); cs_w32_pk_int_const ok.
  • CPU: python -I -m unittest discover -s tests/semantic -p test_pk_int_const.py 3 OK, -p test_alu_pk_int16.py 8 OK, tests/test_shader_checks.py 60 OK, tests/test_run_gpu_tests.py 30 OK, tests/semantic/regen_fixtures.py --check clean.

Test programs: an MSVC 14.44 build of 4eb6155, this PR's base. The PR changes no C++ or CMake, so they are what its head builds; the translator, runner and check.py are this PR's. llvm-mc 21.1.8 (native), Vulkan SDK 1.4.363.0.

This is the translated fixture on an RDNA4 card, next to the RDNA2 iGPU runs above; it says nothing about RDNA4's own behaviour for these opcodes (no hw_oracle run here). No game files. AI-assisted (Claude Code).

@Rainmaker33

Copy link
Copy Markdown

Tested c570d78 on NVIDIA GeForce RTX 3090 (Ampere, subgroup 32..32), driver 610.88 (Vulkan 1.4.341), Windows 11 Pro 26300: pass.

The PR's diff applied cleanly to main 4eb6155. VS 2022, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8; harness programs from a CMake build of that main; overlay layers off.

  • scripts/run_gpu_tests.py: 137/181 pass, 44 skipped (wave64), no failures (main: 136/180). cs_w32_pk_int_const: 327684 262146 1065353216 1450709556 1075839024 4 4294967280 3221225472.
  • tests/semantic/test_alu_pk_int16.py and test_pk_int_const.py: OK.

Conflicts:
	docs/design.md

AI-assisted.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Merged main (4e12716) again; CPU checks and the PR's GPU tests pass on Radeon RDNA2 iGPU. AI-assisted.

@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Rechecked in real wave64 with the hw_oracle fix in #2961: same words.

AI-assisted.

Conflicts:
	docs/design.md (kept this PR's packed 16-bit row, which now names its GPU test, over main's "Not GPU-verified" note)
	runtime/test/shaders/check.py
	scripts/run_gpu_tests.py
	tests/semantic/regen_fixtures.py

AI-assisted.
@mrp1no

mrp1no commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Tested ca08408 on the 29 FSPX programs of my own 1.0.2.1 package (amd_fidelityfx_upscaler_xbox.dll, unpacked by make_game.py). I ran tools/rdna2spirv.py --no-asm --wave64-emulate with the same disassembly for both trees (llvm-mc 23.1.5, CPU only):

main 1628210 this PR
translated 24/29 25/29
pass spirv-val 24 25
refused: v_pk_add_u16 high half of a constant 1 0
other refusals (unchanged) 2 normalized encoding, 1 image_store 2D a16 d16 (#3095), 1 v_fma_mix_f32 field (#2977) same

So this PR's rule picks up the one FSPX program that refused on a packed 16-bit constant, and the module it produces is valid. Nothing else changes. I didn't run that program on a GPU.

Counts only, no shader names or data. AI-assisted (Claude Code).

AAyberkU pushed a commit to AAyberkU/Leonida that referenced this pull request Nov 22, 2026
…ger VALU

A separate ISA model for the v_pk_* integer ops (op_sel, op_sel_hi, clamp) and the 16-bit VOP3 integer ops (op_sel on sources and the destination half, the kept other half, clamp), with VGPR, SGPR, inline-constant and literal sources within the constant-bus rules, compared one lane at a time with rdna2spirv run in tests/semantic/spirv_mini_interp.py, optionally with the hardware through tools/hw_oracle. A constant whose high half a packed op reads (ItsNotRexed#2224) only with --known.

AI-assisted.
mrp1no added a commit to mrp1no/Leonida that referenced this pull request Nov 22, 2026
…ograms store

Both FSPX instructions take S1 from an inline constant with op_sel_hi[1] = 0,
the broadcast of its low half. The test now runs that form too (-6: 70
restored, 85 with the defaults). The design row says the constant reads as its
32-bit value, as ItsNotRexed#2224 measured for packed 16-bit ops, and that this isn't
measured on v_dot4_i32_i8 itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/design.md
tools/rdna2spirv.py
tests/semantic/test_alu_pk_int16.py

main now translates packed int16 constant op_sel (ef3261c); this branch keeps
only the GPU fixture cs_w32_pk_int_const and its semantic test, which pass
against main's translation.

AI-assisted.
@Vonsek

Vonsek commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Merged main. The translator change in this PR is now on main (ef3261c, packed int16 constant op_sel), so I took main's tools/rdna2spirv.py, design.md row and test_alu_pk_int16.py. What is left is the GPU fixture cs_w32_pk_int_const and tests/semantic/test_pk_int_const.py; both pass against main's translation (fixture on the Radeon iGPU, gfx1036). AI-assisted.

mrp1no added a commit to mrp1no/Leonida that referenced this pull request Nov 22, 2026
…tsNotRexed#3372)

@TheMrBeez ran v_dot4_i32_i8 on gfx1036 (raw hw_oracle kernels, wave32 and
wave64) with 13 operand/select combinations. S1 was a VGPR or an inline
constant (-16, -6, 7, 64). Every result equals the translator's: a constant
reads as its sign-extended 32-bit value, and op_sel/op_sel_hi pick its halves
like a VGPR's. The design row and the test comment now say measured instead of
inferred from ItsNotRexed#2224.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mrp1no added a commit to mrp1no/Leonida that referenced this pull request Nov 22, 2026
…ograms store

Both FSPX instructions take S1 from an inline constant with op_sel_hi[1] = 0,
the broadcast of its low half. The test now runs that form too (-6: 70
restored, 85 with the defaults). The design row says the constant reads as its
32-bit value, as ItsNotRexed#2224 measured for packed 16-bit ops, and that this isn't
measured on v_dot4_i32_i8 itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mrp1no added a commit to mrp1no/Leonida that referenced this pull request Nov 22, 2026
…tsNotRexed#3372)

@TheMrBeez ran v_dot4_i32_i8 on gfx1036 (raw hw_oracle kernels, wave32 and
wave64) with 13 operand/select combinations. S1 was a VGPR or an inline
constant (-16, -6, 7, 64). Every result equals the translator's: a constant
reads as its sign-extended 32-bit value, and op_sel/op_sel_hi pick its halves
like a VGPR's. The design row and the test comment now say measured instead of
inferred from ItsNotRexed#2224.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
runtime/test/shaders/check.py
scripts/run_gpu_tests.py
tests/semantic/regen_fixtures.py

AI-assisted.
@crastinator

Copy link
Copy Markdown
Contributor

Tested f2c7c98 merged into main aa2988cc (clean merge) on AMD Radeon RX 6700 XT (Navi 22, gfx1031, subgroup 32..64), RADV Mesa 26.3.1, CachyOS, Linux 7.3.5, GCC 16.2.1, llvm-mc 23.1.5: pass.

  • New test passes natively: cs_w32_pk_int_const (327684 262146 1065353216 1450709556 1075839024 4 4294967280 3221225472).
  • Whole run_gpu_tests.py: 197/211 native, 197/211 with LEONIDA_W64_EMULATE=1 (the skips are the D3D12-only fixtures and ps_w64x_readlane, as on main). ctest 47/47.
  • tests/semantic/test_pk_int_const.py: 3 passed, 10 subtests passed.

No game files. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested f2c7c98 merged with main 2d3369a on Linux (Python 3.12.16) and Windows 11 (Python 3.13.1): pass (the translator change is already on main, so this is now a test and fixture PR).

  • -I -m unittest discover -s tests/semantic -p test_pk_int_const.py: 3 tests OK on both. tests/test_shader_checks.py 83 and tests/test_run_gpu_tests.py 41 pass on both; tests/test_docs_*.py pass on both.
  • Negative control (mutation): the v_pk_* BitFieldExtract offset forced to 0 instead of 16 * op_sel in tools/rdna2spirv.py: 8 failures in test_pk_int_const.py. Reverted afterwards.
  • The GPU fixture cs_w32_pk_int_const was not run.

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.

7 participants