ffx_dispatch_aot: v_cvt_u32_f32 / v_cvt_i32_f32 lower to unguarded HLSL casts #433

Closed
opened 2026-11-22 03:10:22 +00:00 by JB2WIN · 2 comments
JB2WIN commented 2026-11-22 03:10:22 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-22T03:10:22Z.


Problem

tools/ffx_dispatch_aot.py maps the two float-to-integer conversions straight to HLSL casts:

"cvt_i32_f32": "uint(int(asfloat({0})))", "cvt_u32_f32": "uint(asfloat({0}))",

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 LLVM
lowers them to fptoui/fptosi, which return poison there. On WARP and an RTX 3080, a bare uint(x) gave
u32(+Inf) = 0 instead of 0xFFFFFFFF in the pixel_aot fixture for #360 stage 3.

Evidence so far

  • Measured only through pixel_aot's helpers. ffx_dispatch_aot is not measured: its check
    (tests/ffx_dispatch_aot_check.py) needs LLVM 15 (llvm-mc), which I don't have on Windows.
  • I haven't checked whether any translated FidelityFX dispatch actually feeds NaN or out-of-range values to these
    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 the
largest binary32 below 2^32 or 2^31, explicit saturation), and add an eval_generated case in
tests/ffx_dispatch_aot_check.py with NaN, ±Inf, 2^32 and -2^31 inputs.

Completion condition

ffx_dispatch_aot_check.py covers NaN, ±Inf and the saturation boundaries for both conversions, and the generated
HLSL contains no cast of an unclamped operand.

Drafted with AI assistance.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6537747155 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/439). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-22T03:10:22Z. --- ## Problem `tools/ffx_dispatch_aot.py` maps the two float-to-integer conversions straight to HLSL casts: ```python "cvt_i32_f32": "uint(int(asfloat({0})))", "cvt_u32_f32": "uint(asfloat({0}))", ``` 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 LLVM lowers them to `fptoui`/`fptosi`, which return poison there. On WARP and an RTX 3080, a bare `uint(x)` gave u32(+Inf) = 0 instead of 0xFFFFFFFF in the pixel_aot fixture for #360 stage 3. ## Evidence so far - Measured only through `pixel_aot`'s helpers. `ffx_dispatch_aot` is not measured: its check (`tests/ffx_dispatch_aot_check.py`) needs LLVM 15 (`llvm-mc`), which I don't have on Windows. - I haven't checked whether any translated FidelityFX dispatch actually feeds NaN or out-of-range values to these 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 the largest binary32 below 2^32 or 2^31, explicit saturation), and add an `eval_generated` case in `tests/ffx_dispatch_aot_check.py` with NaN, ±Inf, 2^32 and -2^31 inputs. ## Completion condition `ffx_dispatch_aot_check.py` covers NaN, ±Inf and the saturation boundaries for both conversions, and the generated HLSL contains no cast of an unclamped operand. > Drafted with AI assistance.
R0Y00 commented 2026-11-24 06:48:22 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:27:28Z.


@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_aot for 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, unsigned 4294967040.0f converts to 0xffffff00, while 4294967296.0f saturates to 0xffffffff. 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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073547442 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/439#issuecomment-7073547442). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T03:27:28Z. --- @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_aot` for 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, unsigned `4294967040.0f` converts to `0xffffff00`, while `4294967296.0f` saturates to `0xffffffff`. 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 commented 2026-11-24 06:48:23 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Jess-Doit on 2026-11-22T03:41:07Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073706708 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/439#issuecomment-7073706708). Originally posted by [Jess-Doit](https://github.com/Jess-Doit) on 2026-11-22T03:41:07Z. --- 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.
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#433
No description provided.