Skip to content

rdna2spirv: validate dst, operands, and modifiers on 8 32-bit int VALU ops - #8945

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/rdna2-int32-valu-validation
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/rdna2-int32-valu-validation

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Claim: #8868 (comment)

Summary

Adds _check_int32_valu in ools/rdna2spirv.py and applies it to the 8 32-bit integer 2-source VALU ops:

  • VOP3-only: �_mul_lo_u32, �_mul_hi_u32, �_mul_hi_i32, �_bcnt_u32_b32
  • VOP2/VOP3: �_min_u32, �_max_u32, �_min_i32, �_max_i32

Validation enforced (raising Unsupported):

  • Exact arity (len(a) == 3: �dst, src0, src1).
  • Single-VGPR destination (�[0][k] == vgpr and
    == 1), rejecting SGPRs, special registers (�cc_lo,
    ull, exec_lo, m0), and multi-register destinations.
  • Single-register sources (
    == 1, rejecting multi-register ranges and register lists).
  • Rejects
    eg/�bs/sext operand modifiers (preserving plain negative integer immediates, and preserving valid SDWA sext(...) on sources of VOP2 min/max ops).
  • Rejects _dpp and _sdwa on the 4 VOP3-only ops; preserves valid _sdwa (only dst_sel/dst_unused/src0_sel/src1_sel with valid values) and _dpp (only DPP control modifiers) on �_min_u32, �_max_u32, �_min_i32, �_max_i32.
  • Rejects any non-empty modifiers (clamp, mul:, div:, op_sel:*, unknown modifiers) on non-SDWA/non-DPP forms and any non-SDWA/non-DPP modifiers on SDWA/DPP min/max forms.

Testing

  • Added ests/semantic/test_int32_valu_validation.py (12 test methods covering negative validation cases across all 8 ops + positive controls verified with spirv-as, spirv-val --target-env vulkan1.2, and spirv_mini_interp).
  • Ran on Windows 11 with Vulkan SDK 1.4.363.0:
    • est_int32_valu_validation.py: 12 tests OK
      
    • est_alu_int*.py: 36 tests OK
      
    • est_alu_sdwa*.py: 2 tests OK
      
    • est_alu_mul*.py: 57 tests OK
      
    • est_alu_bcnt*.py: 6 tests OK
      
    • est_valu_minmax_i32_u32.py: 15 tests OK
      
    • est_valu_mul_hi.py: 8 tests OK
      
    • dpp.py: 7 tests OK
    • python -I -m compileall -q tools tests: clean
    • git diff --check origin/main..HEAD: clean

AI-assisted (Gemini 4 Neon).

@DaviDreamerz

DaviDreamerz commented Nov 23, 2026 •

Copy link
Copy Markdown

Tested 30af313f6 on Windows 11 (build 26300), Python 3.15.2, Vulkan SDK 1.4.363.0 (spirv-as/spirv-val on PATH), llvm-mc 23.1.6: pass.

CPU-only translator change, so no GPU is involved here. No game files (LEONIDA_GAME_DIR unset); synthetic fixtures only.

  • python -I -m unittest discover -s tests/semantic -p test_int32_valu_validation.py: 12 tests OK, no skips
  • Related suites: test_alu_int* 36 OK, test_valu_minmax_i32_u32 15 OK, test_valu_mul_hi 8 OK
  • Full translator suite, python -I scripts/run_semantic_tests.py tests/semantic: 448 files, 5,969 tests, 2 files failed in 64 s — the same two that fail on unmodified 867d922f0 (test_image_atomics_guard, test_image_store_d16), so no regression from this change
  • Negative control: with only tools/rdna2spirv.py reverted to 867d922f0 in the same tree, test_int32_valu_validation.py fails with 332 failures and 28 errors ("Unsupported not raised"), so the new test really exercises _check_int32_valu

AI-assisted: yes.

@Rainmaker33

Copy link
Copy Markdown

Tested 30af313f (applied on main 867d922) on an RTX 3090, driver 610.88, Windows 11, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8: pass. This adds a GPU run to the CPU check above.

  • python -I tests/semantic/test_int32_valu_validation.py: 12 tests, OK.
  • run_gpu_tests.py, whole suite translated by this branch: 192/241, 48 skipped (wave64), identical per test to main here. The one failure, ms_wave_info_s3, is the same on main.

AI-assisted (Claude Code).

@tanbentam tanbentam left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tested 30af313f6 on Windows 11, CPython 3.12.10 (CPU-only, synthetic shaders, no game files; spirv-as/spirv-val not installed on this host): pass.

  • Applies cleanly onto main 867d922f0; scripts/check_no_game_data.py passes on both files.
  • Negative control (new test against unmodified main 867d922f0): fails with 332 failures, 28 errors (13 skipped).
  • With the fix:
    • test_int32_valu_validation.py: 12/12 OK (13 spirv-val subtests skipped ? no Vulkan SDK installed here)
    • Regression suites (all OK): test_valu_minmax_i32_u32.py (15), test_valu_mul_hi.py (8), test_alu_int*.py (36), test_alu_mul*.py (57), test_alu_bcnt*.py (6), test_alu_sdwa*.py (2), *dpp*.py (7) ? 131/131 passed.
  • Code read: _check_int32_valu inspects orig_a before SDWA/DPP wrappers rewrite a, preserves valid SDWA sext(...) and DPP controls on v_min/max_{u32,i32}, and cleanly rejects bad destination/source/modifier forms across all 8 ops.
  • Minor non-blocking note: the PR description itself has a few PowerShell backtick-escape artifacts (e.g. \u000b_mul_lo_u32), while the code and tests are clean.

AI-assisted.

@DaviDreamerz

Copy link
Copy Markdown

GPU follow-up on the same head 30af313f6, same machine (RTX 4070 Ti SUPER, NVIDIA 621.24, Windows 11), comparing this tree with main 867d922f0 on the same test programs:

  • python -I scripts/run_gpu_tests.py --build runtime/build: 192/241 passed, 48 skipped in both trees; comparing every PASS/SKIP/FAIL line (241), 0 status differences.
  • The only failure is ms_wave_info_s3 in both, so it is pre-existing here and not from this change.
  • Test programs from 867d922f0 (this PR's base), scripts and fixtures from each tree; no game files (LEONIDA_GAME_DIR unset).

AI-assisted: yes.

@WALID1618Y

Copy link
Copy Markdown
Contributor

Tested 30af313f6 on NVIDIA GeForce RTX 3050 (driver 621.24 / 32.0.16.2124, Vulkan 1.4.357, Windows x64, Python 3.13.14): pass

Environment notes: pre-built runtime-windows CI binaries from e68c5c9c9 (tools/rdna2spirv.py unchanged between e68c5c9c9 and 867d922f0), --assembler python (tools/spirv_asm.py), --disasm-dir tests/semantic/fixtures/disasm (no llvm-mc), spirv-val skipped (--no-validate). Synthetic/fixture shaders only, no game files. AI-assisted.

Semantic tests:

  • Red-before (LEONIDA_TOOLS_DIR -> base tools/): python -m unittest discover -s tests/semantic -p test_int32_valu_validation.py -v -> Ran 12 tests, FAILED (failures=332, errors=28, skipped=13)
  • Green-after (30af313f6): python -m unittest discover -s tests/semantic -p test_int32_valu_validation.py -v -> Ran 12 tests, OK (skipped=13) (spirv-val not on PATH)

RTX 3050 GPU regression suite (30af313f6 — verifies no false-positive rejections on translated fixtures including DPP/SDWA/int32 ops):

  • Native (scripts/run_gpu_tests.py --build runtime-windows --disasm-dir tests/semantic/fixtures/disasm --assembler python): 81/96 passed, 15 skipped (32-wide device wave64 compute skips; matches baseline)
  • LEONIDA_W64_EMULATE=1 with --filter cs_w --require-pass: 30/30 passed

@RAINighty

Copy link
Copy Markdown

Tested 30af313f6 merged with main 867d922f0 (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_int32_valu_validation.py with this PR: passes (Ran 12 tests in 1.181s, 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 12 tests in 1.553s, FAILED (failures=332, errors=28)), so the new test does catch the problem.
  • Code not reviewed beyond running it. No GPU or game files.

AI-assisted (Claude Code).

@comtek21516

Copy link
Copy Markdown

Tested 30af313f6 merged onto main at 867d922f0 on Quadro RTX 4000 (Turing, subgroup 32..32), NVIDIA 615.71.09, Ubuntu 22.04.5 (kernel 5.15), g++ 13.4, llvm-mc 21.1.8, Vulkan SDK 1.4.363.1, Python 3.12.16: pass.

Not run: the full tests/semantic suite, and no corpus count (no game files here), so whether a game shader uses one of the forms that are now refused is not covered. 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