shader: define v_cvt_rpi/flr_i32_f32 for NaN, infinity and overflow in pixel_aot #1878
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1885"
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 Asimmimx on 2026-11-24T20:07:06Z.
Change
Fixes #1772.
tools/pixel_aot.pynow definesv_cvt_flr_i32_f32andv_cvt_rpi_i32_f32for every binary32 input, so runtime sources are no longer refused.cvt_flr_i32_f32/cvt_rpi_i32_f32(the lazy HLSL helpers): a NaN gives0x7fffffffwhen its sign bit is clear and0x80000000when it is set (quiet or signalling). Both infinities and out-of-range values saturate to0x7fffffff/0x80000000. The helpers replace the NaN word before any float operation, clamp the rounded value to[-2^31, 2^31 - 128](2^31 - 1 is not a binary32) and select0x7fffffffforx >= 2^31. No HLSL cast reads a NaN or an out-of-range value any more. Before this change,int(floor(x))andint(f + ...)were undefined casts for those inputs. Finite in-range results are bit-identical to the old helpers, andrpistill computes the floor of the exactx + 0.5.require_proven_i32_f32_rangeis removed. Its docstring said it refused unproven runtime inputs and NaN, infinite or out-of-range constants "until a native RDNA reference establishes exceptional behavior". It guarded nothing else, since it already accepted subnormal constants. Its two call sites are removed, and the comments that cited it (cvt_f64_f32_source_bits, thev_cvt_f64_f32branch, the e64 branch) are updated. The other refusals are unchanged: clamp, omod, decimal or float literals, bare-0x..., reversed modifiers, DPP and SDWA, pending scalar or sample reads, and WQM.tools/scan_unsupported_shaders.py: the e32 and e64 patterns forv_cvt_i32_f32now also coverflr_i32andrpi_i32. The scanner previously left both opcodes unsupported for the same reason.docs/experiments.md: the flr/rpi paragraph is rewritten, and two stale "flr/rpi remain rejected" mentions in the neighbouring cvt paragraphs are removed.This follows R0Y00's condition on #540: "Before extending to NaN, infinities, or out-of-range values, we need an independent native reference that can observe those results as raw words, including values around ±0.5 and both integer endpoints." #1772 cites two such references: Marvisak/VIctory#605 (comment) (gfx1036, HIP inline asm) and xcl-dev/xcl#639 (comment) (gfx1036 and RDNA 4 gfx1201, OpenCL inline asm). Both include ±0.5, 0.49999997, ±2^31, both infinities and NaNs of both signs. Below I add a third native readback, on gfx1032.
Caveat: gfx1032, gfx1036 and gfx1201 are desktop RDNA 2 and RDNA 4 parts, not gfx1013 or Scarlett.
Verification
Commit
122e2db2(rebased onmaindf40e4bc). Windows 11 Pro 10.0.26300.9974, MSVC (VS dev shell viatools/dev.ps1), Windows SDK 10.0.26100.0, DXC 1.8.2502.11, Python fromout/pe-env.1414:008c), driver 10.0.26100.9818, D3D12 debug layer enabled,debug_errors=0 debug_warnings=0. Passed.1002:73ff, RDNA 2, gfx1032), driver 32.0.21045.29003, D3D12 debug layer enabled,debug_errors=0 debug_warnings=0. Passed.Python checks (
out/pe-env/Scripts/python.exe -B), all passed:tests/pixel_aot_check.py(no arguments: translator controls), exit 0tests/rdna2_tools_check.py:OK (skipped=18). The skips are the existing LLVM-dependent cases.tests/form_coverage_check.py:form coverage checks passedtests/docs_links_check.py:Checked 18 Markdown files and 376 links.tests/bidi_controls_check.py:Checked 1326 tracked source, script and build/CI files: no bidirectional controls.tests/pso_readiness_check.py,tests/shader_census_check.py: passedNot run:
tests/pixel_aot_check.py binary. Only LLVM 19.1.1 (WinLibs) is installed here, and CI pins LLVM 15. This PR adds no binary round-trip fixtures; the existing ones are unchanged.What the draw test now covers (
check_cvt_flr_rpi_draw)The existing finite rows, modifier rows and mutations are kept. They are added to:
CVT_FLR_RPI_EXCEPTIONAL:±qNaN,±sNaN,±NaNwith all payload bits,±inf,±2^31,±(2^31 + 256),2^31 - 128,±2^63,±FLT_MAX,0.49999997,±0.5,-0.50000006,±(2^23 + 1)and2^24 - 1. The Python references must reproduce the table before any draw.|-qNaN|,-(+qNaN),-|+sNaN|,-(-NaN),|-inf|,-(+inf)and-|±(2^31+256)|, for both opcodes.pixel_mismatch:0for NaN, which is whatv_cvt_i32_f32gives;absornegon a NaN source;0x80000000u - sign), and the2^31saturation select dropped.cvt_flr_i32_f32helper swapped in, the draw test fails on WARP (Expected ['pass', ...], got ['mismatch', ...]).Evidence and follow-up
Native gfx1032 readback (RX 6600, dev-time probe, not committed). I ran
v_cvt_flr_i32_f32andv_cvt_rpi_i32_f32as inline assembly in an OpenCL C kernel, loaded through ctypes. Devicegfx1032, boardAMD Radeon RX 6600, OpenCL driver3652.0 (PAL,LC). Each input ran under all four MODE.IEEE / MODE.DX10_CLAMP settings, with f32 denormals flushed or kept, for eight modes. MODE was read back after eachs_setregand gave0xc0, 0x2c0, 0x1c0, 0x3c0, 0xf0, 0x2f0, 0x1f0, 0x3f0. Every row ofCVT_FLR_RPI_EXCEPTIONALmatched in all eight modes, including the rows the table marks "by rule":±(2^31 + 256),2^31 - 128,±2^63and±FLT_MAX.flrdepend on MODE, which matches the gfx1036 report. The draws keep the harness's existing assumption,F32_DENORM_MODE = "preserve"; this PR does not change it. The console's FLOAT_MODE is not measured.0x00000000from both opcodes, and infinities and out-of-range values saturated. So the old undefined casts were not adapter-divergent on these two adapters. They gave 0 for NaN, which differs from the native0x7fffffff/0x80000000in 6 of 26 rows per opcode. With the new helpers, 0 of 26 rows differ on both adapters.tests/pixel_aot_check.py, with hand-worked expected words. No game data.git merge-treeagainst the open pixel_aot PRs #1790, #1680, #1670, #1644, #1638, #1612, #1584, #1572, #1568, #1466, #713, #532, #531 and #528.mainin the same files, with the same number of conflict regions with or without this commit.v_cvt_pkrtz_f16_f32) has one of this PR's changed lines inside an existing conflict region: the cvt e32/e64 branches inlower()and scanner lines 170-171.Checklist
AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:24:04Z.
Review: COMMENTED
Peer review of head
122e2db27708d4374a133ce12a98cffd8240dd48(PRODUCTION_REVIEW_ONLY, technical comment only).No P1 and no P2 found in the lowering or in its tests. One open question for the maintainers about the evidence the new behavior rests on (below).
What the change does:
v_cvt_flr_i32_f32andv_cvt_rpi_i32_f32(e32 and e64 with abs/neg) stop requiring a statically proven input. The two helpers now define NaN, infinities and out-of-range inputs, andtools/scan_unsupported_shaders.pyaccepts the same spellings. I read all five changed files.Helper review (
cvt_flr_i32_f32,cvt_rpi_i32_f32in tools/pixel_aot.py):(bits & 0x7fffffff) > 0x7f800000) and the NaN is replaced by 0 before any float operation. A NaN returns0x7fffffff + (bits >> 31):0x7fffffffwith the sign clear,0x80000000with it set, quiet or signalling.x >= 2^31selects0x7fffffffbefore the cast, so no HLSL cast sees a NaN or an out-of-range value. +inf and -inf,+-2^31,+-FLT_MAXall land on the intended limits.rpi, an infinity givesx - floor(x) = NaN, the comparison is false, and the clamp and the>= 2^31select still give the saturated values. For large integers (2^23 + 1)x - fis 0, so they are unchanged;0x3effffffstays 0.require_proven_i32_f32_rangeand its two call sites leaves no dangling use (mathandknown_ssa_bitsare still used elsewhere in the file).rdna2_tools_checkentries and scanner entries are consistent with each other.Question for the maintainers (not a defect in the code): the exceptional-input table (NaN by sign, saturation) comes from measurements on other RDNA parts, cited in issue #1772 (an RDNA 2 desktop APU and an RDNA 4 card) and in the docs (an RX 6600). The issue itself says none of these is gfx1013 or the console, and I cannot reproduce or inspect those measurements from here. Before this PR the two opcodes refused runtime inputs; after it, a title shader that feeds a NaN to them gets a defined result chosen from those measurements. If the console part differs, the failure would be silent. That is a project decision, so I am leaving it to you rather than judging it.
Mutations of the helpers in tools/pixel_aot.py, one at a time (each restored with
git checkout -- .):return nan ? 0x7fffffffu : word):tests/pixel_aot_check.pyfails (rc=1) on Linux.asfloat(bits)): fails (rc=1) on Linux.x >= 2^31saturation select dropped: the Linux check does not catch it (rc=0). On Windows Server 2025 with the mutated tree,pixel_aot_cvt_flr_rpi_warpfails ("case=3..7 and 12 mismatch", pixel_mismatch at 0,0), so the draw test pins it.rpihalf-way comparison changed from>=to>: passes the Linux check (rc=0). Only the WARP draw test covers values at exactly 0.5.Commands run:
git diff --check <merge-base>...HEADclean;tests/docs_links_check.py,tests/bidi_controls_check.py,tests/pixel_aot_check.py,tests/rdna2_tools_check.py(148 tests, 18 skipped),tests/form_coverage_check.py: all pass; the mutations above.122e2db2, targetoffscreen_check, regex^(pixel_aot_cvt_flr_rpi_warp|pixel_aot_warp|rdna2_tools_check)$:--preset dev): 3/3 passed/O2(--preset release): 3/3 passedtests/pixel_aot_check.pyandtests/docs_links_check.py: okmainhas no content conflicts (git merge-tree).AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T20:30:07Z.
Review: COMMENTED
Peer review of head
122e2db27708d4374a133ce12a98cffd8240dd48(TIER_D_ISOLATED_SHADER_OPS, technical comment).No P1 and no P2 found. I read the diff of
tools/pixel_aot.py,tools/scan_unsupported_shaders.pyand the three test/doc files, and I agree with the earlier review on the helper logic (NaN word replaced before any float op, clamp to [-2^31, 2147483520],x >= 2^31selects 0x7fffffff, finite in-range results unchanged, no dangling use of the removed function).Note: the exceptional-input table comes from RDNA 2 (gfx1036) and RDNA 4 measurements cited in #1772, not from gfx1013 or the console. That is a project decision and I did not verify the hardware source.
Commands run locally:
git diff --check origin/main...HEAD: rc=0python3 tests/docs_links_check.py: rc=0 (18 files, 376 links)python3 tests/bidi_controls_check.py: rc=0python3 tests/pixel_aot_check.py: rc=0python3 tests/rdna2_tools_check.py: rc=0offscreen_check, regex^(pixel_aot_cvt_flr_rpi_warp|pixel_aot_warp|rdna2_tools_check)$: Debug 3/3 passed, Release /O2 3/3 passed,tests/form_coverage_check.pyokMutations (each restored with
git checkout -- .):cvt_flr_i32_f32:pixel_aot_check.pyrc=1 (caught by a source-text assertion, so this one is wording-level evidence only)rpihalf-way test>=changed to>: Linux check rc=0 (not caught on Linux)x >= 2^31saturation select dropped incvt_flr_i32_f32: Linux check rc=0; on Windows Server 2025 with the mutated tree,pixel_aot_cvt_flr_rpi_warpfails rc=1 (draw status mismatch, e.g. expected 0x00000000 got 0x80000000), so the WARP draw test pins the saturation logicAI-assisted; commands listed were executed locally.