Skip to content

rdna2spirv: op_sel destination bit on a dword result shifts it left by 16 (v_pack_b32_f16, v_alignbit/alignbyte) - #2470

Open
evilclanker9000 wants to merge 7 commits into
ItsNotRexed:mainfrom
evilclanker9000:claude/hw-opsel-dst32
Open

evilclanker9000 wants to merge 7 commits into
ItsNotRexed:mainfrom
evilclanker9000:claude/hw-opsel-dst32

Conversation

@evilclanker9000

Copy link
Copy Markdown
Contributor

Requested by Lucas · project thread

Claimed in the coordination issue as: EGEN-HW-OPSEL-DST32, #2078 (comment)

What and why

v_pack_b32_f16, v_alignbit_b32 and v_alignbyte_b32 have a 32-bit result but still take VOP3 op_sel (llvm-mc gfx1013 accepts it on them). On RDNA2 the destination bit writes the result shifted left by 16: the result's low half goes to D's high half and D's low half becomes 0. The translator ignored the bit and wrote the plain result.

Measured natively on an AMD Radeon iGPU (gfx1036, Windows driver 26.10.1) with raw kernels through tools/hw_oracle, wave32 and wave64 giving the same words:

instruction hardware translator before
v_alignbit_b32 d, 0x12345678, 0xfffffff0, 4 op_sel:[0,0,0,1] 0xffff0000 0x8fffffff
v_alignbyte_b32 d, 0x12345678, 0xfffffff0, 4 op_sel:[0,0,0,1] 0xfff00000 0xfffffff0
v_pack_b32_f16 d, 0x8003fffe, 0x7fff0005 op_sel:[1,1,1] 0x80030000 0x7fff8003
v_pack_b32_f16 d, -v(0x12345678), |v(0x00020003)| op_sel:[1,0,1] 0x92340000 0x00039234
v_pack_b32_f16 d, 1.0, v(0x00020003) op_sel:[0,1,1] 0x3c000000 0x00023c00

A source op_sel bit on v_alignbit_b32 / v_alignbyte_b32 also changes the result on this GPU (bit 1 shifts by S2[31:16]; bit 0 gave neither half of S2, for example a shift of 31 for S2 = 0x8003fffe). That is not modelled, so those forms are now Unsupported instead of silently ignored.

Changes:

  • tools/rdna2spirv.py: Gen.opsel_dst32 shifts the result when the destination bit is set; used by the three ops. Source op_sel on alignbit/alignbyte raises Unsupported.
  • runtime/test/shaders/ps_opsel_dst32.asm: one word per case (pack with S0 high half, alignbit by a constant and by a register, alignbyte by a register), expected words derived from the ISA plus the measured rule in its header; registered in check.py and scripts/run_gpu_tests.py.
  • The same shader as a semantic fixture, with hand constants and a Python reference in tests/semantic/test_value_semantics.py, plus a check that source op_sel on alignbit/alignbyte is refused.
  • docs/design.md: a contract row with the measurement.

The same destination rule holds for v_mad_u32_u16 / v_mad_i32_i16, which the translator refuses today; that is a separate PR (EGEN-HW-MAD-U32-U16).

Tested

  • Hardware words above: gfx1036 through tools/hw_oracle (wave32 and wave64). The fixture's own body also ran natively there and gave its four expected words in both wave sizes.
  • python -I scripts/run_gpu_tests.py --filter ps_opsel_dst32: PASS 4096/4096 pixels exact on NVIDIA GeForce RTX 5080 (driver 616.92) and on the AMD Radeon iGPU (gfx1036, driver 26.10.1), selected with LEONIDA_VK_DEVICE (vk_harness printed device: NVIDIA GeForce RTX 5080 and device: AMD Radeon(TM) Graphics).
  • Red on main: with main's translator the test fails on both GPUs, 4096/4096 mismatches (got 0xdef01234, 0x89abcdef, 0x56789abc, 0xe26af37b, the unshifted results).
  • Negative control: shifting by 8 instead of 16 in opsel_dst32 fails on both GPUs, 4096/4096 mismatches (got 0xf0123400, 0xabcdef00, 0x789abc00, 0x6af37b00). Reverted.
  • python -m unittest discover -s tests/semantic: OK. python tests/semantic/regen_fixtures.py --check: clean. python -I tests/test_shader_checks.py: OK.

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.

…y 16

v_pack_b32_f16, v_alignbit_b32 and v_alignbyte_b32 take VOP3 op_sel although
their result is 32 bits. Measured on RDNA2 (gfx1036, raw kernels through
tools/hw_oracle, wave32 and wave64): the destination bit writes the result
shifted left by 16 (low half 0, old D not kept). The translator ignored it.
A source op_sel bit on alignbit/alignbyte also changes the result there and
is now refused rather than ignored.

GPU test ps_opsel_dst32 (4096/4096 on RTX 5080 and the gfx1036 iGPU), the
same shader as a semantic fixture, and a docs/design.md row
(EGEN-HW-OPSEL-DST32).

AI-assisted.
@tylerstraub

Copy link
Copy Markdown
Contributor

Tested 97ca4b317a0c205121d91aa4dee88cd1cfe0a1ca on NVIDIA GeForce RTX 5090, 595.99.02 (Linux).

Independent AREA52 check of 97ca4b317a0c205121d91aa4dee88cd1cfe0a1ca on Linux 7.0.0-43 (RTX 5090, NVIDIA 595.99.02, LLVM 21.1.8, SPIRV-Tools 2026.1).

  • Synthetic Vulkan fragment test ps_opsel_dst32 passed SPIR-V validation and matched all 4,096 pixels. The four 32-bit words at each pixel were 12340000 cdef0000 9abc0000 f37b0000.
  • Reversing only the translator diff with the same fixture still passed SPIR-V validation and mismatched all 4,096 pixels. Each pixel contained def01234 89abcdef 56789abc e26af37b.
  • The targeted CPU semantic test and fixture regeneration check passed.

This covers the translated Vulkan path on NVIDIA. Native RDNA2 behavior and Windows were outside this run.

AI-assisted verification.

@Marukooh

Copy link
Copy Markdown
Contributor

Tested 97ca4b3 on an NVIDIA GeForce RTX 5070 Ti (Blackwell), NVIDIA 620.73.04, CachyOS Linux. Built the harness from this PR and ran scripts/run_gpu_tests.py --filter ps_opsel_dst32 with LEONIDA_W64_EMULATE=0 and =1. In both runs the shader passed Vulkan SPIR-V validation and matched all 4,096 pixels. The 33 test_value_semantics.py tests also passed. AI-assisted.

@emirduran707

Copy link
Copy Markdown
Contributor

Tested 97ca4b3 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. The two checks above are NVIDIA on Linux; this one is AMD on Windows.

  • python -I scripts/run_gpu_tests.py --build <build> --filter ps_opsel_dst32: PASS ps_opsel_dst32 4096/4096 pixels exact. Same with LEONIDA_W64_EMULATE=1.
  • Whole suite (native wave64) with this PR's translator: 191 shaders translated, 191 pass spirv-val; 171/186 passed, 15 skipped, 0 failed (main 4947579 here: 170/185, 15 skipped). The skips are the 14 fixtures the d3d12_* tests run, and ps_w64x_readlane (see check.py: judge ps_w64x_readlane where vk_harness required 64 (its line has no "required") #2085).
  • build.py + check.py: 205 shaders translated, 205 pass spirv-val; 160 of 164 pass, 4 skipped; ps_opsel_dst32 ok.
  • CPU: python -I -m unittest discover -s tests/semantic -p test_value_semantics.py 33 OK, tests/test_shader_checks.py 60 OK, tests/test_run_gpu_tests.py 30 OK, tests/semantic/regen_fixtures.py --check clean. I did not run the whole tests/semantic suite.

Test programs: an MSVC 14.44 build of 4947579, this PR's base; the PR changes no C++ or CMake. llvm-mc 21.1.8 (native), Vulkan SDK 1.4.363.0. I did not repeat the red-on-main run or the negative control. This is the translated fixture on RDNA4, not a native measurement. No game files. AI-assisted (Claude Code).

@0xTehuti

Copy link
Copy Markdown
Contributor

Hardware Validation: NVIDIA Turing (RTX 2070 SUPER)

Tested \ps_opsel_dst32\ on physical hardware:

  • OS: Windows 11 Pro x64 (Build 26100)
  • GPU: NVIDIA GeForce RTX 2070 SUPER (Driver 595.79, Vulkan 1.4.329)
  • Validation: Khronos Validation Layers active (\LEONIDA_VK_VALIDATION=1, 0 VUID errors)

Results:


  • dna2spirv.py: 1/1 shaders translated cleanly, passed \spirv-val.

  • un_gpu_tests.py --filter ps_opsel_dst32: PASS (4096/4096 pixels exact).
  • \ ests/semantic/test_value_semantics.py: 33/33 tests OK (1.95s).
  • Verified exact hardware match on \�_alignbit_b32, \�_alignbyte_b32, and \�_pack_b32_f16\ destination \op_sel\ shifting by 16 bits on Turing, behaving identically to the reported Blackwell (RTX 5080) and RDNA 2 runs.

LGTM! AI-assisted (Leonida multi-agent team).

@throny

throny commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Real-corpus incidence for 97ca4b31 (my own Xbox Series 1.0.2.1 copy, all 26,503 disassembled shaders, gfx1013; Windows 11, Python 3.13, CPU only). Counts only.

Opcode Sites Files Sites with the op_sel dst bit set Sites with op_sel on a source
v_pack_b32_f16 35,332 5,976 0 3,144 (main already handles these)
v_alignbit_b32 1,104 1,059 0 0
v_alignbyte_b32 9 5 0 0

So no corpus shader reaches opsel_dst32, and the new v_alignbit/v_alignbyte op_sel on a source refusal affects 0 shaders and can't cost a translation. The corpus doesn't exercise the change, so the value of merging rests on the fixtures and GPU tests.

python -m unittest discover -s tests/semantic at the PR head: 2,569 tests, OK.

AI-assisted (Claude Code).

…t32-merge

# Conflicts:
#	docs/design.md
#	runtime/test/shaders/check.py
#	scripts/run_gpu_tests.py
#	tests/semantic/regen_fixtures.py
#	tests/semantic/test_value_semantics.py
@lunisahdidouch

Copy link
Copy Markdown

Tested 97ca4b3 on an RX 9070 (RDNA4), AMD 26.11.1 (LLPC), Vulkan 1.4.359, Windows 11: pass

New ps_opsel_dst32 passes, 4096/4096 pixels exact. Full run_gpu_tests.py: 171/186 passed, 15 skipped, nothing failed, everything else matches main 4947579. tests/semantic passes (2569 tests, OK).

AI-assisted

@evilclanker9000

Copy link
Copy Markdown
Contributor Author

Rechecked in game MODE (IEEE off, DX10_CLAMP on, f32 denorm flush): same words. AI-assisted.

docs/design.md
runtime/test/shaders/check.py
scripts/run_gpu_tests.py
tests/semantic/regen_fixtures.py
tests/semantic/test_value_semantics.py

AI-assisted.
tests/semantic/test_value_semantics.py
tools/rdna2spirv.py

AI-assisted.
@TreXito

TreXito commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 37f0e73e (the rebased head) on NVIDIA GeForce RTX 3060 Ti (subgroup 32..32), driver 580.173.02, Linux (kernel 6.18), Python 3.14: pass.

  • scripts/run_gpu_tests.py: 165/211 passed, 46 skipped, 0 failed. ps_opsel_dst32: 4096/4096 pixels exact.
  • ctest: 47/47 passed.
  • pytest tests/semantic/test_value_semantics.py: 41 passed, 292 subtests passed. With main's tools/ (aa2988c): 10 failed, 41 passed, which matches the "red on main" line.

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

@throny

throny commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 37f0e73 on NVIDIA RTX 4080, driver 610.88, Windows 11: pass

This is the head rebased on aa2988cc. Ran (MSVC 19.44 / VS 2022 BuildTools, Ninja, RelWithDebInfo, Vulkan SDK 1.4.363.0, native llvm-mc 23.1.6; this PR has no runtime C++ change, so the test programs were built from the aa2988cc tree):

  • python -I scripts/run_gpu_tests.py --build <build>: 165/211 passed, 46 skipped, 0 failed. ps_opsel_dst32 4096/4096 pixels exact.
  • test_value_semantics (run from tests/semantic): 41 tests OK.

AI-assisted.

tools/rdna2spirv.py

AI-assisted.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a3cbb3c (merge base 7b7d73f) on NVIDIA GeForce RTX 5080, Linux 580.65.06: pass

Tested the PR head merged with current main 7b7d73f8 (clean merge, not pushed). Runtime harnesses built from main 7b7d73f8, llvm-mc 21, Python 3.13, Vulkan SDK 1.4.363, Linux native.

Check main 7b7d73f8 this PR
run_gpu_tests.py native 170/217 passed, 47 skipped 171/218 passed, 47 skipped
run_gpu_tests.py with LEONIDA_W64_EMULATE=1 201/217 passed, 16 skipped 202/218 passed, 16 skipped
failed (native / emulated) 0 / 0 0 / 0
tests/semantic/regen_fixtures.py --check ok ok
pytest tests/semantic/test_value_semantics.py tests/test_find_hash_lookup.py tests/test_first_look_shim_report.py tests/test_shader_checks.py tests/test_run_gpu_tests.py tests/test_cf_diff.py 162 passed, 315 subtests passed (3 shared files) 207 passed, 1 skipped, 608 subtests passed in 11.40s

Line-by-line against my main run (results that differ from main):

  • native:
    • ps_opsel_dst32 main: - pr: PASS 4096/4096 pixels exact
  • emulated:
    • ps_opsel_dst32 main: - pr: PASS 4096/4096 pixels exact

Not run: the full unittest discover -s tests/semantic (about 6 minutes, and main alone has failures there); only the test files this PR touches plus the shared checker tests ran. No other GPU vendor, no Windows. No game files.

AI-assisted (Claude Code).

@bobcatchris

Copy link
Copy Markdown
Contributor

Apple M2 / MoltenVK validation of head a3cbb3c0 (hardware reports Apple M2 / Mac14,3, not M1), macOS 26.4, MoltenVK 1.4.2, subgroup 4..32, llvm-mc 23.1.6. Python/translator-only change; one harness built from base 3eb4410b and shared for the A/B.

  • New GPU fixture ps_opsel_dst32 PASS: ps_opsel_dst32 4096/4096 pixels exact
  • Full suite: 217 shaders translated, 217 pass spirv-val; 153/218 passed, 58 skipped, 7 failed (known MoltenVK expected set), versus base 3eb4410b at 152/217, 58 skipped, 7 failed. No common test changed status.

No code changes, no game data; synthetic fixture and counts only.

AI-assisted.

@tunczzz

tunczzz commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested a3cbb3c0 (merge base 3eb4410b) on an NVIDIA GeForce RTX 5070 Ti (Blackwell, subgroup 32..32), driver 616.56, Windows 11 10.0.26300. Translator and fixtures came from this head; runtime test programs were built from main 98fa503f (MSVC 19.44, Vulkan-Headers fetched by CMake, loader from the NVIDIA driver); spirv-as/spirv-val and llvm-mc 21 came from WSL Ubuntu. Result: pass.

Not run: LEONIDA_W64_EMULATE=1, other vendors, Linux. No game files.

AI-assisted (Claude Code).

tests/semantic/test_value_semantics.py

AI-assisted.
@gertify

gertify commented Nov 23, 2026

Copy link
Copy Markdown

Tested ba23bed on Intel UHD Graphics 630 (CFL GT2), Mesa ANV, subgroup 8..32: run_gpu_tests.py --filter ps_opsel_dst32 prints "PASS ps_opsel_dst32 4096/4096 pixels exact" and "1/1 passed". With tools/rdna2spirv.py from 561b65a swapped in, the same row fails with "4096/4096 mismatches; first at (0,0): got ['0xdef01234', '0x89abcdef', '0x56789abc', '0xe26af37b'], want ['0x12340000', '0xcdef0000', '0x9abc0000', '0xf37b0000']". With LEONIDA_VK_DEVICE=NoSuchDevice it fails with "no Vulkan physical device matches". test_value_semantics runs 43 tests OK, tests/test_shader_checks.py 82 tests OK and regen_fixtures.py --check exits 0. The wave64 cases were not run.

AI-assisted.

benthomashull-commits added a commit to benthomashull-commits/Leonida that referenced this pull request Nov 23, 2026
… result shifts it left by 16 (v_pack_b32_f16, v_alignbit/alignbyte)

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.