Repository navigation
rdna2spirv: VOP3 clamp on v_mad_u64_u32 / v_mad_i64_i32 saturates the 64-bit result, measured on RDNA2 - #2763
evilclanker9000 wants to merge 5 commits into
Conversation
… 64-bit result These forms were refused. Measured on RDNA2 (gfx1036, raw kernels through tools/hw_oracle, wave32 with a one-SGPR sdst and wave64): when the exact 65-bit sum does not fit, clamp saturates D to 2^64 - 1 (u64) or to INT64_MIN / INT64_MAX by the exact sign (i64). sdst still gets bit 64 of the exact sum, as without clamp. GPU test ps_mad64_clamp (4096/4096 on RTX 5080 and the gfx1036 iGPU), the same shader as a semantic fixture, the measured cases with and without clamp against a Python reference, and a docs/design.md row (EGEN-HW-MAD64-CLAMP). AI-assisted.
# Conflicts: # tests/semantic/test_value_semantics.py
|
Code read of
AI-assisted review (Claude Code). |
|
Tested 06df900 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 Hardware: Radeon iGPU, gfx1036 (Ryzen 7 9800X3D), AMD driver 32.0.13036.4, Windows 10 22H2, through Cases: 600 independent
No game files. AI-assisted (Claude Code). |
|
Rechecked in real wave64 with the hw_oracle fix in #2961: same words. AI-assisted. |
Kam471
left a comment
There was a problem hiding this comment.
Verified on the PR head: tests/semantic/test_alu_mad64.py -> 43 OK; test_value_semantics.py -> 35 OK; full semantic discover 4139 OK (534 s); regen_fixtures.py --check exit 0; test_shader_checks.py 69 OK. The EXPECTED_MAD64_CLAMP vector is hardware-anchored and its arithmetic checks out independently. Author-claimed GPU runs were not re-run (no AMD device here). Approve.
Nit: the reference test comment says "(null sdst too)" but every case uses s10.
|
Tested
Translator: 1 shader translated, spirv-val clean. NVIDIA Blackwell (RTX 50-series) coverage. AI-assisted. |
|
Tested 06df900 on Windows 11 Home 26300: pass for this PR's test. AI-assisted (Claude Code). Hardware: AMD Ryzen 5 7600X; iGPU AMD Radeon(TM) Graphics (RDNA2 gfx1036, subgroup 32..64), AMD driver 24.10.24 (Vulkan driver 2.0.302); NVIDIA GeForce RTX 5060 Ti, driver 610.88 (subgroup 32..32). MSVC 14.44, Vulkan SDK 1.4.363.0, llvm-mc 21.1.8, Python 3.12.10. Test programs built at 06df900. Implicit layers off. No game files.
Whole suite ( So the clamp itself is only checked on NVIDIA here; this iGPU can't run pixel tests that need more than 128 push-constant bytes.
|
|
Tested
No game files. AI-assisted (Claude Code). |
|
Tested at the head on Windows 11 / Python 3.13.0: the new tests 2/2, The rule is correct ( Nit: the GPU fixture only exercises overflowing clamps; the "fits unchanged"/no-clamp paths are CPU-only ( Approve. AI-assisted review, no game files, no GPU. |
tests/semantic/test_value_semantics.py AI-assisted.
docs/design.md runtime/test/shaders/check.py scripts/run_gpu_tests.py tests/semantic/regen_fixtures.py AI-assisted.
|
Tested 11a3ba4 (a re-test at the new head) on AMD Radeon RX 9070 XT (RADV GFX1201, wave32/64) and the Ryzen 7 9800X3D iGPU (RADV RAPHAEL_MENDOCINO, gfx1036), Mesa 26.2.6, Linux 7.3.4: pass, no regressions.
No game files. AI-assisted. |
|
Tested 11a3ba4 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 ps_mad64_clamp 1/1 on RTX 4080 SUPER and UHD 770. Negative control with main's tools/rdna2spirv.py: test_value_semantics errors (9 errors) and the GPU case fails to translate (no .spv). |
docs/design.md tests/semantic/regen_fixtures.py tests/semantic/test_value_semantics.py AI-assisted.
|
Tested 72fde18 on Steam Deck LCD (Jupiter), AMD Custom GPU 0405 "Van Gogh", RADV Mesa 26.2.0-devel (git-5c65d4fc31), Vulkan 1.4.350, SteamOS 3.9.5 (holo), kernel 7.2.7-valve2-2-neptune-72-g31504582a073: pass.
No runtime C++ changes in this PR; tested from the PR worktree against the existing runtime build. AI-assisted (OpenCode). |
|
Tested
No game files. AI-assisted (Claude Code). |
Requested by Lucas · project thread
Claimed in the coordination issue as: EGEN-HW-MAD64-CLAMP, #2516 (comment)
What and why
The translator refused
v_mad_u64_u32/v_mad_i64_i32with the VOP3clampbit (Unsupported: <op> operands). The assembler takes it, in wave32 with a one-SGPR sdst as in wave64. I measured it natively on an AMD Radeon iGPU (gfx1036, Windows driver 26.10.1) with raw kernels throughtools/hw_oracle, 14 cases, wave32 and wave64 giving the same words:clampsaturates D: to0xffffffff_fffffffffor u64, to INT64_MIN (0x80000000_00000000) or INT64_MAX (0x7fffffff_ffffffff) by the exact sign for i64. A sum that fits is unchanged.0xffffffff * 0xffffffff + (2^64 - 1)with clamp gives D =0xffffffff_ffffffffand sdst 1;(-2^31)^2 + INT64_MAXgives D = INT64_MAX and sdst 0.With the change the translator gives every measured D word.
Changes:
tools/rdna2spirv.py: thev_mad_u64_u32/v_mad_i64_i32branch acceptsclamp. u64 overflows when bit 64 is set; i64 when bit 64 (the exact sign) differs from the wrapped sum's bit 63, and then takes INT64_MIN or INT64_MAX by that sign. sdst is computed as before.runtime/test/shaders/ps_mad64_clamp.asm: a u64 overflow, an i64 underflow and an i64 overflow under clamp in wave32 with one-SGPR sdsts, D's words and the three sdst lane bits folded into four outputs, each derived in the header; registered incheck.pyandscripts/run_gpu_tests.py.tests/semantic/test_value_semantics.py, plus the measured cases with and without clamp (D and the sdst bit) against the reference.docs/design.md: a contract row with the measurement.Tested
python -I scripts/run_gpu_tests.py --filter ps_mad64:ps_mad64_clampPASS 4096/4096 pixels exact on NVIDIA GeForce RTX 5080 (driver 616.92) and on the AMD Radeon iGPU (gfx1036, driver 26.10.1), selected withLEONIDA_VK_DEVICE(device names confirmed withtools/vk_subgroup_info.py). The fixture's body also ran natively on gfx1036 (tools/hw_oracle, wave32) and gave0xffffffff, 0x80000000, 0x7fffffff, 0x00000003.missing .spv (translation failed)) on either GPU.0x7ffffffffor0x80000000and0x80000000for0x7fffffff), and fails the semantic tests. 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.python -I tools/int_hw_probe.py(translator side): unchanged.AI-assisted.
Checklist
docs/design.md, with how it was confirmed.