shader: lower compute v_cvt_u32_f32 with RDNA2 saturation #1898
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1905"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by henriazz10 on 2026-11-24T20:44:40Z.
Change
Refs #721. This is the
v_cvt_u32_f32slice (item 5) claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7143412663. It touches onlytools/compute_store_aot.py,tests/compute_store_check.py,CMakeLists.txtanddocs/experiments.md.v_cvt_u32_f32_e32 vD, S0converts a binary32 source to an unsigned 32-bit integer with RDNA2 saturation: NaN and values<= 0.0give0, values>= 2^32(including+inf) give0xffffffff, and values in(0, 2^32)truncate toward zero.cvt_u32_f32helper only when called, clamping finite values to4294967040.0f(2^32 - 256) beforeuint()so even speculatively evaluated casts stay in range.S0accepts a VGPR holding a known word, a ready SGPR, a 32-bit literal, an integer inline constant or an inline float constant (FLOAT_INLINE), including NaN, infinity and denormal constants.s30), pending SGPR (s12), unknown VGPR (v40), unaccepted float literal (1.5), out-of-range integer literal (0x100000000);v255(v256);v_cvt_u32_f32_e64, barev_cvt_u32_f32), input modifiers (-v1,|v1|), output modifiers (clamp,mul:2) and register range (v[1:2]).Verification
Commit
0c560c21, rebased onto27cf223d(after #1904 merged). The draws,controls()and the LLVM 15 round trip were re-run on0c560c21. Windows 11, DXC 10.0.26100.0, Python 3.12 (out/pe-env), debug layer enabled.offscreen_checkwas built from an earliermain; this PR does not change it.groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0x2w-llvm15Dockerbinary_exit=0docs_links_check.pyChecked 18 Markdown files and 376 links.)bidi_controls_check.pyChecked 1330 tracked source, script and build/CI files: no bidirectional controls.)git diff --check HEAD~1cvt_u32_f32_binary()decodes the assembled fixture back to the samev_cvt_u32_f32_e32lines and requires the same translation.Negative control. With
tools/compute_store_aot.pyfromorigin/main(b80058f0),cvt_u32_f32_controls()fails withValueError: Unsupported compute instruction: v_cvt_u32_f32_e32 v4, v1.Evidence
The fixture is source-built in LLVM 15 spelling (
CVT_U32_F32, 32 threads, stride 16, 128 active words and 128..319 sentinel). It covers0.75,1.5,3.0..3*2^29,2^32 - 256,2^32,> 2^32,FLT_MAX,+inf,sNaN,qNaN,-0.0,-denorm,-inf,-1.0,4.0and an SGPR5.0, comparing all 320 words against an independent Python model (cvt_u32_f32_word).cvt_u32_f32_controls()checks the emittedcvt_u32_f32helper, helper omission when unused, integer inline0, NaN/denormal constants and all rejection conditions.0;2^32: word65;0xffffffff: word3;128.2^32saturation dropped;4.0replaced by2.0;0.75replaced by1.0.Checklist
docs/experiments.md).AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:57:12Z.
Review: COMMENTED
Review of head
74446809f5(TIER_D_ISOLATED_SHADER_OPS; files: CMakeLists.txt, docs/experiments.md, tests/compute_store_check.py, tools/compute_store_aot.py).Commands executed locally:
74446809f5: Debug (--preset dev) 66/66 passed, Release /O2 (--preset release) 66/66 passed, including compute_store_aot_cvt_u32_f32_warpMutations of tool logic (each reverted with git checkout -- .):
P1: 0. P2: 0. The lowering matches the documented saturation (NaN and <= 0 give 0, >= 2^32 gives 0xffffffff, otherwise truncate), and the clamp below 2^32 keeps speculative casts in range.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:10:18Z.
Review: COMMENTED
Review of head
bc349a3e9fc04365085e8ac432fae12aac4ba54a(technical comment only, no merge from this pass).Blocked: the branch conflicts with current main, and the head has moved. GitHub reports
CONFLICTING/DIRTY.git merge-tree --write-tree --name-only origin/main <head>reports a content conflict intests/compute_store_check.py; the other files merge cleanly. The last review on record is for74446809, so this head has no receipt. Please rebase on main and resolve it, then ask for a new review.Commands run (Linux):
git fetch origin pull/1905/head,git merge-tree --write-tree --name-only origin/main <head>(rc=1),python3 x2w_pipe.py safe-merge-check(verdict BLOCK: conflict, receipt missing).No receipt and no merge.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T21:23:22Z.
Review: COMMENTED
Review of head
0c560c218eScope: TIER_D_ISOLATED_SHADER_OPS. Files: CMakeLists.txt (one new ctest entry plus its SKIP_RETURN_CODE for the hardware variant, nothing else), docs/experiments.md, tests/compute_store_check.py, tools/compute_store_aot.py. Author henriazz10. New head after the rebase; the earlier reviews on
74446809andbc349a3eare superseded. Merge state: MERGEABLE, no conflict (git merge-tree --write-tree --name-only origin/main HEAD: rc=0).Semantics read against the RDNA2 definition of v_cvt_u32_f32: NaN -> 0, values <= 0 -> 0, values >= 2^32 (including +inf) -> 0xffffffff, otherwise truncation toward zero. The helper forces NaN to 0, clamps finite values to [0, 4294967040.0f] (the largest binary32 below 2^32, so no value is lost) and saturates at 2^32 before uint(). Operands are limited to known words, modifiers/_e64/range are refused, and the helper is emitted only when used. The independent Python model in the test agrees.
Commands executed locally:
Mutation checks (logic in tools/compute_store_aot.py, each reverted with git checkout -- .):
Note: the helper body itself is checked on the device side, where the test recompiles HLSL with the 2^32 saturation dropped and with 4.0 replaced by 2.0 and requires each to fail (this ran in the Win2025 passes above).
Findings: P1=0, P2=0.
AI-assisted; commands listed were executed locally.