Repository navigation
rdna2spirv: VOP3 clamp on v_mul/mad_u32_u24 and v_mul/mad_i32_i24 saturates (EGEN-INT24-CLAMP) - #2536
evilclanker9000 wants to merge 6 commits into
Conversation
…-CLAMP) v_mul_u32_u24, v_mad_u32_u24, v_mul_i32_i24 and v_mad_i32_i24 with the VOP3 clamp bit saturate the exact product (+ S2) on RDNA2: u24 to [0, 0xffffffff], i24 to the i32 range. The translator ignored the bit and kept the low 32 bits. Measured on a gfx1036 with raw wave32 kernels. Adds GPU test cs_int24_clamp, its semantic fixture and test, and a docs/design.md contract row. AI-assisted.
|
Overlaps an earlier claim by @quackottu in #1380 (comment 7078408059, which proposes refusing these forms as Unsupported). Asked there whether to keep, narrow or close this one. |
|
Independent check on RDNA4: I measured the same four ops with One small thing: |
|
Tested e07c2df 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
|
|
Tested |
|
Full retail corpus measurement for SHADER-232: 0 of 26,503 shader entries contain one of the four clamped forms in the Xbox 1.0.2.1 shader archive. The corresponding unclamped instructions are common: 230,775 decoded occurrences across 13,400 distinct entries.
I joined all 26,503 listings to the package index and counted instruction mnemonics with either encoding suffix, checking modifiers before the listing comment. LLVM 21.1.8 targeting gfx1013 decoded 25,030 listings cleanly and reported invalid words in 1,473. The occurrence table counts decoded instructions. To cover the undecoded words for the clamp question, I independently assembled the four clamped VOP3 forms on gfx1013 and scanned every aligned word in every header-defined FSSM code range for the corresponding opcode and clamp bit. All 26,503 entries had a code range; there were zero candidate words, even before excluding literals and instruction continuations. For prioritization, the saturation rule has a hardware-tested ISA use case, while the changed branch has no input in this shader archive. This count excludes executable-embedded shaders and other package versions. Aggregate counts only. AI-assisted analysis. |
|
RDNA2 data point to go with the gfx1201 run above: the rule matches the hardware on AMD Radeon RDNA2 iGPU (Ryzen 7 7800X3D,
llvm-mc rejects (AI-assisted: probe written and run by a second model on this machine; I read its results. No game files.) |
|
Tested on Windows 11 with two GPUs on one machine (MSVC 14.51, llvm-mc 23.1.6): pass. |
|
Tested e07c2df on an RTX 5090 (driver 616.92), Windows 11, Vulkan SDK 1.4.363. The GPU test programs were built from the same tree:
AI-assisted (Claude Code). |
Conflicts: docs/design.md runtime/test/shaders/check.py scripts/run_gpu_tests.py AI-assisted.
|
Tested
No game files. AI-assisted (Claude Code). |
docs/design.md AI-assisted.
docs/design.md runtime/test/shaders/check.py scripts/run_gpu_tests.py tests/semantic/regen_fixtures.py AI-assisted.
|
Tested 52790ac on NVIDIA RTX 4080, driver 610.88, Windows 11: pass This is the head rebased on
AI-assisted. |
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested
AI-assisted (Claude Code). Synthetic shaders only, no game files. |
docs/design.md AI-assisted.
|
Apple M2 / MoltenVK validation of head
No code changes, no game data; synthetic fixture and counts only. AI-assisted. |
|
Tested 34068d6 (merge base 7b7d73f) on NVIDIA GeForce RTX 5080, Linux 580.65.06: pass Tested the PR head merged with current main
Line-by-line against my main run (results that differ from main):
Not run: the full AI-assisted (Claude Code). |
|
Tested
New in this PR:
Every other test has the same result as on |
|
Tested 34068d6 merged with main 98fa503 on Linux (Python 3.12.16) and Windows (RTX 4080 SUPER, UHD 770): pass. test_value_semantics and test_run_gpu_tests 2/2 ok. run_gpu_tests.py cs_int24_clamp 1/1 on RTX 4080 SUPER and on UHD 770. Negative control with main's tools/rdna2spirv.py: test_value_semantics fails (1 failure) and cs_int24_clamp fails on the GPU (0xfe000000 ... mismatch). |
|
Tested
Not run: AI-assisted (Claude Code). |
runtime/test/shaders/check.py scripts/run_gpu_tests.py tests/semantic/regen_fixtures.py AI-assisted.
|
Tested 8917c8a on Intel UHD Graphics 630 (CFL GT2), Mesa ANV, subgroup 8..32: run_gpu_tests.py --filter cs_int24 prints "PASS cs_int24_clamp 0xffffffff 0xffffffff 0xffffffff 0x7fffffff 0x80000000 0x7fffffff 0x80000000 0xfffffff2" and "1/1 passed". With tools/rdna2spirv.py from 561b65a swapped in, it fails with "0xfe000000 0x0 0xfe000001 0x7f000000 0x7ffffffe 0x0 0x800000 0xfffffff2". With LEONIDA_VK_DEVICE=NoSuchDevice it fails with "no Vulkan physical device matches". test_value_semantics.Int24Clamp runs 2 tests OK. The full tests/semantic suite was not run. AI-assisted. |
shayderrr
left a comment
There was a problem hiding this comment.
Summary: rdna2spirv: VOP3 clamp on v_mul/mad_u32_u24 and v_mul/mad_i32_i24 saturates (EGEN-INT24-CLAMP) touches docs/design.md, runtime/test/shaders/check.py, runtime/test/shaders/cs_int24_clamp.asm (plus 5 more). Adds or updates s24, s32, u24. New tests include test_words, test_words_follow_from_the_values.
Why merge: Addresses a concrete failure mode with a focused change and regression coverage. The patch stays inside the affected code path, so it is low risk and prevents bad output or failures in real use.
Verdict: Approve
|
Summary: rdna2spirv: VOP3 clamp on v_mul/mad_u32_u24 and v_mul/mad_i32_i24 saturates (EGEN-INT24-CLAMP) touches Why merge: Addresses a concrete failure mode with a focused change and regression coverage. The patch stays inside the affected code path, so it is low risk and prevents bad output or failures in real use. Verdict: Approve |
Requested by Lucas · project thread
Claimed in the coordination issue as: EGEN-INT24-CLAMP (claim)
What and why
The translator ignored the VOP3
clampbit onv_mul_u32_u24,v_mad_u32_u24,v_mul_i32_i24andv_mad_i32_i24and always wrote the low 32 bits. On RDNA2 the bit saturates the exact value: the 48-bit product of the 24-bit fields, plus S2 for mad, goes to [0, 0xFFFFFFFF] for u24 and to [0x80000000, 0x7FFFFFFF] for i24. For examplev_mad_u32_u24 v0, 0xffffff, 0xffffff, -1 clampgave 0xfe000000 instead of 0xffffffff, andv_mul_i32_i24_e64 v0, 0x800000, 0x800000 clampgave 0 instead of 0x7fffffff.The fix adds one branch for the four ops when
clampis set: the extended multiply gives (lo, hi), S2 is added with its carry (and, signed, its sign word) into hi, and the result is saturated when hi is not the zero/sign extension of lo. Withoutclampnothing changes.Before writing the fix I checked the expected behaviour on hardware with
tools/hw_oracleon a gfx1036 (Radeon iGPU of a Ryzen 9 9950X3D), raw wave32 kernels: four hand-picked rows per op, then 16 programs of 32 random lanes (each op with and without clamp), all matching the model above. On the same assemblerclampis rejected onv_mul_hi_u32_u24,v_add3_u32,v_lshl_add_u32,v_xad_u32,v_mul_lo_u32andv_mul_hi_u32, so those are left alone.New contract row in
docs/design.md("Integer clamp on the 24-bit multiplies").Tested
runtime/test/shaders/cs_int24_clamp.asm(expected words derived by hand in its header): unsigned product and add overflow, the add-only carry, signed positive and negative overflow, an add-only signed overflow, and one in-range negative result.scripts/run_gpu_tests.py --filter cs_int24, NVIDIA RTX 5080 (driver 616.92): 1/1 pass.tools/rdna2spirv.pyfrommainthe test fails on the RTX 5080 with0xfe000000 0x0 0xfe000001 0x7f000000 0x7ffffffe 0x0 0x800000 0xfffffff2(the old words listed in the header).... 0x7ffffffe 0x80000000 0x7ffffffe ...); reverted.Int24Clampintests/semantic/test_value_semantics.pyruns the same fixture on one wave32 group inspirv_mini_interp.run_workgroupagainst hand constants and a plain-Python reference; it fails onmainand passes with the fix.spirv_mini_interp) against the hardware-checked model: 0 differences with the fix, 159 onmain.clampset, which translated before as well; the new branch passesspirv-valin the GPU test.python -m unittest discover -s tests/semanticOK,python tests/semantic/regen_fixtures.py --checkclean,python -I tests/test_shader_checks.pyOK.Checklist
docs/design.md, with how it was confirmed.AI-assisted.