ffx_dispatch_aot: v_cvt_u32_f32 / v_cvt_i32_f32 lower to unguarded HLSL casts #439
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#439
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@JB2WIN on GitHub · 2026-11-22 03:10 UTC · original
Problem
tools/ffx_dispatch_aot.pymaps the two float-to-integer conversions straight to HLSL casts:Per the RDNA 2 ISA reading recorded in #360 (stage 3), these instructions truncate toward zero, map NaN to 0 and
saturate out-of-range inputs. HLSL leaves
uint()/int()undefined for NaN and out-of-range values, and LLVMlowers them to
fptoui/fptosi, which return poison there. On WARP and an RTX 3080, a bareuint(x)gaveu32(+Inf) = 0 instead of 0xFFFFFFFF in the pixel_aot fixture for #360 stage 3.
Evidence so far
pixel_aot's helpers.ffx_dispatch_aotis not measured: its check(
tests/ffx_dispatch_aot_check.py) needs LLVM 15 (llvm-mc), which I don't have on Windows.conversions. If none does, the bare casts are harmless in practice, but they are still undefined.
Proposal
Reuse the clamped helpers from the #360 stage-3 PR (
cvt_u32_f32/cvt_i32_f32: NaN-free operand clamped to thelargest binary32 below 2^32 or 2^31, explicit saturation), and add an
eval_generatedcase intests/ffx_dispatch_aot_check.pywith NaN, ±Inf, 2^32 and -2^31 inputs.Completion condition
ffx_dispatch_aot_check.pycovers NaN, ±Inf and the saturation boundaries for both conversions, and the generatedHLSL contains no cast of an unclamped operand.
@R0Y00 on GitHub · 2026-11-22 03:27 UTC · original
@JB2WIN, please proceed with the FFX fix. Both translators should implement the same gfx1013 conversion rule: truncate toward zero, return zero for NaN, and saturate out-of-range values to the target integer’s minimum or maximum. For unsigned conversion the lower bound is zero.
Please execute the code emitted by
ffx_dispatch_aotfor both instructions and compare the resulting integer bits with independently specified expectations. Include signed fractional inputs, NaN, both infinities, and adjacent representable binary32 values on either side of each saturation threshold. For example, unsigned4294967040.0fconverts to0xffffff00, while4294967296.0fsaturates to0xffffffff. Include a negative control that produces a wrong result on a discriminating row. Record the FFX command, commit and observed results separately from the pixel-path measurements.@Jess-Doit on GitHub · 2026-11-22 03:41 UTC · original
Independent check of the FidelityFX compute path on Windows 10 22H2 (19045.6456), GTX 1060 6 GB (32.0.15.6094) and in-box WARP (10.0.19041.5794), with DXC 1.9.2602.17.
I assembled source-built gfx1013 v_cvt_u32_f32 and v_cvt_i32_f32 instructions, then ran the disassembly and machine code through ffx_dispatch_aot.translate("rcas", instructions, code). I added raw buffer input and integer UAV readback and compiled the emitted HLSL with dxc -T cs_6_0 -E main -I tests -Fo <output.cso> <generated.hlsl>.
On main at
fb4fb85, all 19 runtime inputs matched on both adapters. Six immediate inputs failed DXIL validation when the conversion was folded into the output store. The +Inf fixture (0x7f800000) failed with "Assignment of undefined values to UAV." The other failures were -Inf, NaN, 2^32, 2^31 and the float immediately below -2^31.On a local guarded-cast patch over
1ec51e0, all six immediate fixtures compiled, and each adapter matched all 19 runtime pairs and all six immediate pairs. For +Inf, the outputs were 0xffffffff unsigned and 0x7fffffff signed. The runtime inputs included fractional values and the adjacent binary32 values around the saturation thresholds. The successful runs had zero D3D12 debug errors or warnings.These results are from the local patch. I can run the same fixture on the submitted PR when it is available.
AI-assisted.