Skip to content

rdna2spirv: harden operand/modifier validation for 16-bit int min3/max3/med3 (#8683) - #8811

Open
DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/rdna2-int16-minmax-med3-validation
Open

DenRakEiw wants to merge 1 commit into
ItsNotRexed:mainfrom
DenRakEiw:fix/rdna2-int16-minmax-med3-validation

Conversation

@DenRakEiw

Copy link
Copy Markdown
Contributor

Closes #8683 (claim: #8683 (comment)).

Summary

Hardens operand and modifier validation for the six RDNA2 16-bit integer three-operand min/max/median instructions (�_min3_i16, �_min3_u16, �_max3_i16, �_max3_u16, �_med3_i16, �_med3_u16) in ools/rdna2spirv.py:

  • Destination validation for both dhi=0 and dhi=1: Requires �[0][k] == vgpr and �[0].get(n, 1) == 1, fixing silent SGPR/special/multi-register destination acceptance when dhi == 0 (and multi-VGPR destination acceptance for both dhi == 0 and dhi == 1).
  • Arity, source width, and operand modifiers: Requires len(a) == 4, single-register sources (
    == 1), and rejects
    eg, �bs, and sext on �[0..3] (while preserving plain negative integer immediates like -16 and -1).
  • Encoding & instruction modifiers: Rejects _dpp and _sdwa suffixes, and allows only op_sel:... (at most once) and clamp (at most once) in mods, rejecting mul:2, mul:4, div:2, op_sel_hi:...,
    eg_lo:...,
    eg_hi:..., duplicates, and unknown modifiers with Unsupported. Valid _e64, op_sel:..., and clamp forms are preserved.

Tests

Added ests/semantic/test_int16_minmax_med3_validation.py covering negative validation tests across all 6 ops plus positive controls (dhi=0, dhi=1, _e64, clamp, negative integer immediates) verified with spirv-as, spirv-val --target-env vulkan1.2, and spirv_mini_interp:

  • python -I -m unittest discover -s tests/semantic -p test_int16_minmax_med3_validation.py -v (with Vulkan SDK spirv-as/spirv-val required): 7 tests OK
  • python -I -m unittest discover -s tests/semantic -p test_alu_min3_max3_med3_16.py -v: 19 tests OK
  • python -I -m compileall -q tools tests: OK
  • git diff --check origin/main..HEAD: clean

AI-assisted (Gemini 4 Neon).

@abnalstlll-byte abnalstlll-byte 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.

Verified on Windows 11 (Python 3.14.7).

  • Hardens validation for 16-bit integer three-operand instructions (\�_min3_i16/u16, \�_max3_i16/u16, \�_med3_i16/u16):
    • Validates VGPR destinations across both \dhi=0\ and \dhi=1.
    • Rejects illegal operand modifiers (
      eg, \�bs, \sext), DPP, and SDWA forms while preserving valid 16-bit modifiers (\op_sel, \clamp).
  • All 7 tests in \ ests/semantic/test_int16_minmax_med3_validation.py\ pass cleanly.
  • Clean-room check and \git diff --check\ pass.

LGTM!

@supidooo

Copy link
Copy Markdown

Verified head e705edca on native Windows 10 Pro (build 19045), Python 3.10.9, and NVIDIA GeForce RTX 4060 Ti (Ada, subgroup 32..32, driver 621.24, Vulkan 1.4.357):

  • python -I scripts/check_no_game_data.py on both changed files: clean (exit 0).
  • python -I -m unittest discover -s tests/semantic -p "test_int16_minmax_med3_validation.py" -v: 7/7 OK (2.195s; spirv-as/spirv-val not on PATH in this environment).
  • python -I -m unittest discover -s tests/semantic -p "test_alu_min3_max3_med3_16.py" -v: 19/19 OK (3.607s).
  • Negative control on main (867d922f): running test_int16_minmax_med3_validation.py against main produced 186 failures + 6 errors (the 6 arity-3 cases raised ValueError: not enough values to unpack (expected 3, got 2) on main instead of Unsupported).
  • GPU readback on RTX 4060 Ti (tools/rdna2spirv.py --assembler python --no-validate + runtime/build/vk_compute_test.exe, VKC_SUBGROUP_SIZE=32): a synthetic compute shader running all 48 positive-control cases (all 6 ops v_{min,max,med}3_{i,u}16 across dhi=0, dhi=1, _e64, clamp, and negative integer immediates -16/-1 with sentinel 0xa55a5aa5) returned 48/48 exact words.

Small PR-body heads-up: the first line of the PR description says Closes #8683, which will auto-close the active contributor coordination issue #8683 when merged — changing that to Claim: / Refs #8683 avoids closing the coordination thread.

No game files used. AI-assisted.

@slint6614-dev

Copy link
Copy Markdown
Contributor

AMD RDNA2 GPU-suite check of e705edca5 (AI-assisted): full scripts/run_gpu_tests.py with this branch's translator, against the same run on main 867d922f. Ryzen 5 9600X iGPU "AMD Radeon(TM) Graphics" (gfx1036, the console's RDNA2 family), native wave32/wave64, AMD Adrenalin 26.11.2 (Vulkan driver 2.0.353), Windows 11 26300, Python 3.12; test programs from a fresh RelWithDebInfo build of main 867d922.

Same per-fixture results as main: 247 translated, 247 pass spirv-val; 224/241 passed, 17 skipped, 0 failed on both. No fixture changes status (this suite has no fixture aimed at the new rule, so the rule itself is covered only by the semantic test).

@comtek21516

Copy link
Copy Markdown

Tested e705edca5 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.

Coordinating who works on what (53) (moved to #8868)

5 participants