shader: lower gfx1013 v_cvt_u32_f32 and v_cvt_i32_f32 in pixel_aot #432
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/438"
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 JB2WIN on 2026-11-22T03:10:18Z.
Change
Stage 3 of #360:
tools/pixel_aot.pylowers the plain e32 float-to-integer conversionsv_cvt_u32_f32_e32andv_cvt_i32_f32_e32. The source can be a VGPR, an SGPR or a hex literal. Two HLSL helpers, emitted once beforemain, implement the issue's reading of the RDNA 2 ISA: truncate toward zero, NaN gives 0, and out-of-range valuessaturate. The cast only ever sees an operand that is NaN-free and clamped to the largest binary32 below 2^32 or
2^31, because an out-of-range or NaN
uint()/int()is undefined in HLSL and poison in LLVM. The result word goesout through the lossless integer readback from #363.
Stacked on #392 (stage 1), which is itself stacked on #363. The branch carries #363 as rebased (
d0683ed) and aconflict-free rebase of #392's commit. When #392 is rebased, I'll realign onto it. Please merge those first, and I'll rebase this. The issue's
"stage 2" (the e64 forms of stage 1) is separate work and not part of this PR.
Refs #360. This change was AI-assisted (Claude Code).
Refused and tested as rejections: e64 spellings (including
|x|,-x,clampandomod), DPP, SDWA, floatinline constants, decimal integer inline constants,
v_cvt_rpi_i32_f32andv_cvt_flr_i32_f32, a scalar read beforeits load completes, a write that overlaps an outstanding sample, and a non-entry exec mask. Decimal inline constants
are refused because
fp_operandreads them as bit patterns, and I have not checked that reading for an f32 sourceagainst the ISA. Hex sources are read as 32-bit literal bit patterns. LLVM's disassembly prints integer inline
constants in decimal, so in translated disassembly a hex token is always a literal. A hand-written
0x1would beread as the bit pattern 1, not as the inline constant 1.
A float export of a conversion result is translated as well, as with
v_mov_b32literals: the register bits passthrough. No draw checks that path.
docs/experiments.mdsays so.tools/scan_unsupported_shaders.pygets the matching pattern, written with the same literal spacing as thetranslator regex, and
TestRdna2Scannercovers it.Verification
Commit under test:
17a654a(this change on top ofe726864, the #392 head). After #363 was rebased, this branchwas rebased onto #363
d0683edplus #392's single commit, and is now763e743. That rebased stack passed the fullsuite (156/156, same three skips) and merges cleanly into current
main. Environment: Windows 11 26200, VS Build Tools 2026 /MSVC 19.51, SDK 10.0.26100.8249 (DXC 1.8.2502.11), Python 3.13.
ctest --preset dev --no-tests=error -R '^(pixel_aot_|rdna2_tools_check$|pso_readiness)'main(c2fc84c), fullctest --preset dev --no-tests=errorbvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warppython -B tests/form_coverage_check.pyctest --preset dev --no-tests=errorcpu_aot_exe_entryfailing (the #281 hang, see below). Skips in both:bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp, the same as before the changeThe draws cover 18 binary32 words in 9 pairs: both zeros, 1.5, -2.75, -0.5, -1.0, a quiet NaN and a negative NaN
with payload, both infinities, 2^32, 4294967040, 2^31, 2147483520, -2^31, the next value below -2^31, the smallest
subnormal and 0.99999994. A further draw reads 3.75, -3.75, 1e10 and -1e10 from SGPRs. The issue's -2^31-1 is not
representable in binary32, so the next binary32 below -2^31 stands in for it.
Negative control: swapping the two conversions on the -0.5/-1.0 pair must give
pixel_mismatch, and it does.Dev-time mutants (not in CI), evaluated per row on both adapters. A local script, not part of this PR, imports
tests/pixel_aot_check.py(translate_int,compile_shader,write_case), patchespixel_aot.CVT_HELPERSinmemory, and runs every pair through
offscreen_check.exe <backend> --check-pixel-casewithout stopping at the firstmismatch. During the mutant runs DXC printed "Declared output SV_Target0 not fully written" a few times, which I
couldn't match to specific compiles. The unmutated final runs printed no such warning.
uint(x): the pairs containing +Inf and 2^32 fail on both, because u32(+Inf)and u32(2^32) give 0 instead of 0xFFFFFFFF.
conversion gives 0x80000000 instead of 0.
Known flakes (unrelated to this change): this branch's base
e726864predates #394. On this host,cpu_aot_exe_entryfails in most runs (the #281 hang), andcpu_native_exe_chainandcpu_native_exe_startfailin some, at the rates below. On current
main(c2fc84c, with #394),cpu_aot_exe_entryandcpu_native_exe_chainpassed 20/20 on the same host. That measurement doesn't show which commit fixed them. The failures seen were 15 s and 60 s test timeouts, plus one"does not run the TLS callback" assertion. The rates are about the same with and without this change (n=20 each, not
a significance test). All three run the native
cpu_exe_*EXEs (cf. #281). None of themimports
pixel_aotor the scanner, and this change touches no C++, MASM or CMake.Over 20 single-test runs on this host:
e726864cpu_aot_exe_entrycpu_native_exe_chaincpu_native_exe_startEvidence and follow-up
check_binaryfixture (the Ubuntupixel-binaryjob runs it).F32_TRUNC_ASSUMPTION) comes from the issue's ISA reading.It was not re-checked against the ISA document and not measured on the console. Result words
0x00000001..0x007FFFFF are binary32 subnormal patterns, and the harness compiles with
-denorm preserve. Whetheran FTZ build would flush them is not tested.
docs/coverage/*.tsvlists every LLVM form and is regenerated bytools/form_reference.py, so it has nothing to change.dashboard.svgneeds recorded runs plus a--sourceline,so I left it to maintainers, as stage 1 did. Please say if you want either one regenerated in this PR.
v_cvt_f32_u32/i32_e32either. That belongs to#392 and is not touched here.
tools/ffx_dispatch_aot.py:64-65lowers the same conversions for the FidelityFX dispatch translatorwith a bare
uint(asfloat(x))and no saturation or NaN handling. That could be a follow-up issue.Checklist
docs/experiments.md; no README row lists individual pixel_aot instructions).🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T10:38:21Z.
I reviewed the remaining stage-three coverage at
d351029. #392 has landed. #545 is preparing the plain unsigned e32 lowering, so once it lands, please rebase #438 onto that main and keep your signed e32 change and the independent integer readback cases. The shared src/ffx_float_to_int.hlsli already exposes cvt_i32_f32(uint bits), so the signed path can use it alongside #545's unsigned path. Please preserve the signed endpoints and adjacent representable inputs, NaN, infinities, negative fractional truncation, the SGPR draw, and the signed/unsigned swap mutation. The signed path can keep its existing entry-mask scope.Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-22T10:48:28Z.
Updated after #363 and #392 landed. I merged
maininto the branch with a normal merge (f64b856, no force push, so yourd351029stays in the history). The stage-3 change is ported onto main's current structure: the helpers now go throughSALU_HELPERS, the code usestranslate_int/integer_rtfrom #363, and the draw lives incheck_e64_render(draw-e64).git diff upstream/main HEADis now only this change: 5 files, +207.Verification on the merged head (Windows 11 26200, RTX 3080 driver 32.0.16.2124 + WARP):
ctest --preset dev --no-tests=error -R "^(pixel_aot_|rdna2_tools_check$|pso_readiness)": 18/18 passed.pixel_aot_e64_hardwarewent from 7.35 s to 8.77 s.ctest --preset dev --no-tests=error: 254/254 passed; skipsbvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warp.tests/pixel_aot_check.py binarywith LLVM 15.0.7, run locally: passed.pixel_mismatch. A mutant without the NaN/saturation guards failsdraw-e64on the RTX 3080.On semantics, following @MoonYueya's correction in #360: the truncate / NaN→0 / saturate rule is not confirmed by the ISA text I could reach. It follows the rule you set for both translators in #439. Overlap with #540 is noted there.
This comment is AI-assisted.