Skip to content

rdna2spirv: validate operands, encodings, and modifiers on packed-conversion VALU ops - #9204

Closed
DenRakEiw wants to merge 1 commit into
ProjectLeonida:mainfrom
DenRakEiw:fix/rdna2-cvt-pk-validation
Closed

DenRakEiw wants to merge 1 commit into
ProjectLeonida:mainfrom
DenRakEiw:fix/rdna2-cvt-pk-validation

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #9065 (comment)

Summary

Adds centralized operand, encoding, and modifier validation (Gen._validate_cvt_pk) for the 7 packed-conversion VALU ops in ools/rdna2spirv.py:

  • �_cvt_pk_u16_u32, �_cvt_pk_i16_i32 (VOP3-only integer)
  • �_cvt_pknorm_i16_f32, �_cvt_pknorm_u16_f32 (VOP3-only f32 -> norm16x2)
  • �_cvt_pknorm_i16_f16, �_cvt_pknorm_u16_f16 (VOP3-only f16 -> norm16x2)
  • �_cvt_pkrtz_f16_f32 (VOP2 _e32 opcode

@Grimkaaah Grimkaaah left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Linux CPU review

What changed: packed-conversion VALU ops get operand/encoding/modifier validation + positive controls (test_cvt_pk_validation).

Checked: tests/semantic/test_cvt_pk_validation.py — 5 passed.

Looks correct; no game files.

@RAINighty

Copy link
Copy Markdown

Tested 53e3da30e merged with main 6312c057f (clean merge) on Windows 11 (10.0.26300), Python 3.13.15 in UTF-8 mode (PYTHONUTF8=1; venv with the pinned tests/requirements.txt), with llvm-mc 21.1.8 (AMDGPU) and SPIRV-Tools v2026.4 on PATH: pass.

  • tests/semantic/test_cvt_pk_validation.py with this PR: passes (Ran 5 tests in 0.649s, OK). On main: a new file, so there is nothing to run there.
  • Negative control: this PR's test with main's version of tools/rdna2spirv.py fails (Ran 5 tests in 0.750s, FAILED (failures=131, errors=7)), so the new test does catch the problem.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@adamraskin

Copy link
Copy Markdown
Contributor

Tested 53e3da3 on Windows 11 Home 26300, CPU and two GPUs, NVIDIA RTX 5090 (621.24, LEONIDA_W64_EMULATE=1) and AMD Radeon iGPU of a Ryzen 7 9800X3D (gfx1036, 25.10.42 / Vulkan driver 2.0.353): pass

Based on main 867d922. One RelWithDebInfo build of main's test programs (MSVC 19.44) for both sides. Synthetic only, no game files.

  • python -m unittest discover -s tests/semantic -p test_cvt_pk_validation.py: OK. With only tools/rdna2spirv.py put back to main: 131 failures and 7 errors, so the tests catch the change.
  • python -I scripts/run_semantic_tests.py tests/semantic: 448 files, 5,962 tests, 2 files failed (test_image_atomics_guard, test_image_store_d16), the known baseline (tests/semantic: three image test files red on main (stale after #4473 and #6805; LLVM_MC on Windows) #7284), the same 2 as main.
  • GPU A/B so that no fixture is newly refused: run_gpu_tests.py --llvm-mc <llvm-mc 21.1.8> --assembler python over every runtime/test/shaders source. main and this PR both translate 247/247. Radeon 223/241 passed, 17 skipped, and RTX 5090 222/241, 17 skipped, on both sides. The per-test PASS/FAIL/SKIP list is identical to main on each GPU. (The one 5090-only failure, ms_wave_info_s3 under wave64 emulation, is on main too.)

Not run: spirv-val (not installed here), Linux, macOS, the game corpus.

-AI Assisted

@mrbean56

Copy link
Copy Markdown

Tested 53e3da30ea on Linux (Debian 13), Python 3.13.5: pass, mutation caught.

  • pytest tests/semantic/test_cvt_pk_validation.py -q: 5 passed, 234 subtests (three with an interrupted prior run: the clean tree passes, the 58-failure count below is from the mutation).
  • Mutation: deleting the new self._validate_cvt_pk(...) call in the v_cvt_pk_u16_u32/v_cvt_pk_i16_i32 branch makes 58 subtests fail, so the integer pair's encoding/operand/source/modifier rejections are bound by execution.
  • The refactor itself: the three hand-rolled modifier checks are now one helper, with per-op flags. allow_clamp is on only for the two v_cvt_pknorm_*_f32 ops (where clamp is a measured hardware no-op), allow_opsel only for v_cvt_pknorm_*_f16, allow_e32 only for v_cvt_pkrtz_f16_f32.
  • Checked the encoding claims against llvm-mc 19.1 -mcpu=gfx1030: v_cvt_pknorm_i16_f16_e32 and v_cvt_pk_u16_u32_e32 → "e32 variant of this instruction is not supported"; v_cvt_pkrtz_f16_f32_e32 assembles to VOP2 0x5e; v_cvt_pkrtz_f16_f32 ... clamp assembles as VOP3. The allow_e32 map matches the ISA.
  • One behavior change to confirm is intended: v_cvt_pkrtz_f16_f32 v0, v1, v2 clamp (VOP3) is now refused. Before this patch the branch did not look at mods, so the modifier was ignored and the module was emitted unclamped. Rejecting is the safer default, but it is a change for input that used to translate; the PR text should say so.
  • The mods loop also rejects duplicate clamp/op_sel: tokens, which the old checks missed.

No GPU, no game data. AI-assisted.

@AsgerCode

Copy link
Copy Markdown

Tested 53e3da3 on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass, but it conflicts with #7683 (see below)

The two reviews above cover the suite, the negative control and the GPU A/B. This adds the LLVM forms, hand listings and the overlap.

What I ran:

  • python -I scripts/run_semantic_tests.py tests/semantic (1800 s limit): 448 files, 5,962 tests, 2 files failed: test_image_atomics_guard (47) and test_image_store_d16 (1), the known main failures.
  • test_cvt_pk_validation.py: 5 tests, OK (1 skipped: spirv-as/spirv-val are not installed here, so only the interpreter values ran). With main's tools/: 131 failures, 7 errors.
  • The 66 tests/test_*.py files that reference rdna2spirv (pytest, 300 s each): the same 4 files fail as on main. No new failure.
  • Merge with current main (867d922, the base): clean.

Valid forms: I took all 252 lines for the seven ops in LLVM's gfx10_asm_vop2.s (v_cvt_pkrtz_f16_f32_e32/_e64) and gfx10_asm_vop3.s (the other six). Each one went through translate() as a one-instruction pixel shader. main and this branch give identical SPIR-V for 241 lines and both refuse the same 11 (operand ttmp11, refused before this PR). The lines include SGPR, m0, exec_hi and vcc_hi sources, the inline constants -1, 0.5 and -4.0, the _e32 literal 0xaf123456, -v1/|v1| on the float ops, clamp on v_cvt_pknorm_*_f32, and op_sel:[0,0,0] to [1,1,1] on v_cvt_pknorm_*_f16. Hand-made extras gave the same SPIR-V and the same interpreter values on both sides: v_cvt_pk_u16_u32 v3, -1, 0x12345, v_cvt_pk_i16_i32 v3, -4.0, m0, v_cvt_pkrtz_f16_f32_e64 v3, -|v1|, s2, v_cvt_pknorm_i16_f16 v3, v1, -1.

Invalid forms that main translated and this branch refuses: v_cvt_pk_u16_u32 with -v1, |v1|, op_sel:[1,0,0], a fourth operand, or _e32; v_cvt_pknorm_u16_f16_e32; v_cvt_pkrtz_f16_f32 with _sdwa, _dpp, or _e32 and -v1. v_cvt_pk_u16_u32 v3, v1 now gives Unsupported instead of IndexError.

Conflict with #7683 (v_cvt_pkrtz_f16_f32 applies its VOP3 clamp and omod to each f16 half):

Other overlap: #9190 (a VALU destination must be a VGPR) merges cleanly with this PR. On the merged tree, both new tests pass.

Nit: the PR description stops after "(VOP2 _e32 opcode". It has a tab and vertical tabs where `t and `v were (for example a tab in place of the "t" of "tools"). This looks like PowerShell backtick escapes in a double-quoted string. Reviewers cannot see the rest of the summary.

AI-assisted (Claude Code).

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