ffx: define float-to-integer conversion at NaN and saturation boundaries #443

Merged
descent81 merged 2 commits from upstream-pr/449 into main 2026-11-22 04:36:35 +00:00
descent81 commented 2026-11-22 04:06:57 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by descent81 on 2026-11-22T04:06:57Z.


Fixes #439.

The dispatch translator used bare HLSL casts for both float-to-integer instructions. The new helpers convert NaN to zero and clamp the operand to a finite, representable value before the cast. Positive overflow selects the integer maximum explicitly, since that maximum is not exactly representable in binary32.

Verification

  • The LLVM 15 test assembles both instructions and checks the translated register values for 19 inputs, including signed zeros, NaNs, infinities and adjacent representable values at the integer boundaries.
  • A source-owned CTest checks the emitted ALU expressions and production HLSL helpers on WARP. All 19 pairs also matched on RTX 4060.
  • Rebuilt the four locally pinned FSR4 shaders. The D3D12 provider-loop replay matched all 256 final pixels per run on both backends, with zero debug errors or warnings.

The previous casts also matched in this D3D11 harness on these drivers. The change removes undefined cast inputs. Whether a normal dispatch supplies exceptional values remains unmeasured.

Reproduce after a dev build:

ctest --preset dev --no-tests=error -R '^ffx_float_to_int_warp$' -V
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6538267967 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/449). Originally posted by [descent81](https://github.com/descent81) on 2026-11-22T04:06:57Z. --- Fixes #439. The dispatch translator used bare HLSL casts for both float-to-integer instructions. The new helpers convert NaN to zero and clamp the operand to a finite, representable value before the cast. Positive overflow selects the integer maximum explicitly, since that maximum is not exactly representable in binary32. ## Verification - The LLVM 15 test assembles both instructions and checks the translated register values for 19 inputs, including signed zeros, NaNs, infinities and adjacent representable values at the integer boundaries. - A source-owned CTest checks the emitted ALU expressions and production HLSL helpers on WARP. All 19 pairs also matched on RTX 4060. - Rebuilt the four locally pinned FSR4 shaders. The D3D12 provider-loop replay matched all 256 final pixels per run on both backends, with zero debug errors or warnings. The previous casts also matched in this D3D11 harness on these drivers. The change removes undefined cast inputs. Whether a normal dispatch supplies exceptional values remains unmeasured. Reproduce after a dev build: ```powershell ctest --preset dev --no-tests=error -R '^ffx_float_to_int_warp$' -V ```
upstream-sync closed this pull request 2026-11-24 06:43:05 +00:00
R0Y00 commented 2026-11-24 06:48:24 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T04:21:48Z.


The 19 runtime pairs cover the agreed boundaries, but the old casts also pass this readback. The independent report in #439 found a distinguishing case: converting immediate +Inf and folding the result into a UAV store made DXC reject the old shader with “Assignment of undefined values to UAV.” Please add that immediate case through the FFX emitter to the Windows regression, verify the guarded shader compiles and reads back 0xffffffff / 0x7fffffff, and record the old-cast result with the compiler version. The existing runtime cases should stay.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7074132277 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/449#issuecomment-7074132277). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T04:21:48Z. --- The 19 runtime pairs cover the agreed boundaries, but the old casts also pass this readback. The independent report in #439 found a distinguishing case: converting immediate +Inf and folding the result into a UAV store made DXC reject the old shader with “Assignment of undefined values to UAV.” Please add that immediate case through the FFX emitter to the Windows regression, verify the guarded shader compiles and reads back 0xffffffff / 0x7fffffff, and record the old-cast result with the compiler version. The existing runtime cases should stay.
Sign in to join this conversation.
No reviewers
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!443
No description provided.