feat(recompiler): convert f32 to f16 natively when the device rounds 16-bit floats to nearest even #1252

Merged
MathiasDevelopes merged 1 commit from upstream-pr/1252 into main 2026-10-09 22:39:16 +00:00
MathiasDevelopes commented 2026-10-07 19:53:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MathiasDevelopes on 2026-10-07T19:53:28Z.


What

The integer emulation of round-to-nearest-even f32→f16 conversion (#317) is exact but heavy: a compute shader with ~3600 conversions (2.27M SPIR-V words) never finished compiling on NVIDIA. When the device enables shaderFloat16 and guarantees shaderRoundingModeRTEFloat16, shaderDenormPreserveFloat16 and shaderSignedZeroInfNanPreserveFloat16, the driver advertises Float16, RoundingModeRTE and DenormPreserve, and the recompiler emits OpFConvert under the 16-bit RoundingModeRTE, DenormPreserve and SignedZeroInfNanPreserve execution modes. NaNs keep the emulated quiet NaN with the high payload bits. Devices without these guarantees (e.g. RADV's truncating packHalf2x16, the reason for #317) keep the emulation.

Graphics validation now accepts the three float-controls execution modes for 16-, 32- and 64-bit floats, so vertex and pixel shaders with a native conversion still draw.

Related: #981 plans per-shader float controls from RSRC1 FLOAT_MODE; this change only sets 16-bit modes on shaders that convert to f16 and leaves the 32/64-bit defaults alone.

Tested

Windows 11, NVIDIA.

  • New agc_float16_conversion: v_cvt_f16_f32 recompiled with and without the capabilities. Native gets OpFConvert plus the 16-bit modes; without RTE it stays emulated.
  • New check in agc_driver_graphics: vertex and pixel modules with the 16/32/64-bit float-controls modes validate, and an 8-bit width is rejected. It fails without the validator change.
  • agc_driver_float16_rounding (RDNA2-captured, from #317) and the other f16 execution tests pass with the native path.
  • Full ctest: 396/396 pass; tools/check_conventions.py passes.
  • A title whose compute shader never finished compiling now compiles it in ~26 s and renders.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4777715246 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1252). Originally posted by [MathiasDevelopes](https://github.com/MathiasDevelopes) on 2026-10-07T19:53:28Z. --- ### What The integer emulation of round-to-nearest-even f32→f16 conversion (#317) is exact but heavy: a compute shader with ~3600 conversions (2.27M SPIR-V words) never finished compiling on NVIDIA. When the device enables `shaderFloat16` and guarantees `shaderRoundingModeRTEFloat16`, `shaderDenormPreserveFloat16` and `shaderSignedZeroInfNanPreserveFloat16`, the driver advertises `Float16`, `RoundingModeRTE` and `DenormPreserve`, and the recompiler emits `OpFConvert` under the 16-bit `RoundingModeRTE`, `DenormPreserve` and `SignedZeroInfNanPreserve` execution modes. NaNs keep the emulated quiet NaN with the high payload bits. Devices without these guarantees (e.g. RADV's truncating `packHalf2x16`, the reason for #317) keep the emulation. Graphics validation now accepts the three float-controls execution modes for 16-, 32- and 64-bit floats, so vertex and pixel shaders with a native conversion still draw. Related: #981 plans per-shader float controls from RSRC1 FLOAT_MODE; this change only sets 16-bit modes on shaders that convert to f16 and leaves the 32/64-bit defaults alone. ### Tested Windows 11, NVIDIA. - New `agc_float16_conversion`: `v_cvt_f16_f32` recompiled with and without the capabilities. Native gets `OpFConvert` plus the 16-bit modes; without RTE it stays emulated. - New check in `agc_driver_graphics`: vertex and pixel modules with the 16/32/64-bit float-controls modes validate, and an 8-bit width is rejected. It fails without the validator change. - `agc_driver_float16_rounding` (RDNA2-captured, from #317) and the other f16 execution tests pass with the native path. - Full `ctest`: 396/396 pass; `tools/check_conventions.py` passes. - A title whose compute shader never finished compiling now compiles it in ~26 s and renders. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
copilot-pull-request-reviewer[bot] commented 2026-10-07 19:53:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-07T19:53:34Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5447571092 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1252#pullrequestreview-5447571092). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-07T19:53:34Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
hashaam1217 commented 2026-10-08 02:33:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by hashaam1217 on 2026-10-08T02:33:50Z.


Checked on Linux with the native path active. CI cannot exercise it: llvmpipe (Mesa 25.2.8) reports shaderDenormPreserveFloat16 = 0, so it stays on the emulation.

  • Both GPUs here advertise shaderFloat16, shaderRoundingModeRTEFloat16, shaderDenormPreserveFloat16 and shaderSignedZeroInfNanPreserveFloat16: Intel Iris Xe (Alder Lake GT2, Mesa 25.2.8 ANV) and NVIDIA RTX 3060 Laptop (595.91.07).
  • On Intel the native conversion is what runs. With INTEL_DEBUG=cs, the agc_driver_float16_rounding shader has 18 f2f16 in its NIR (0 on main) and compiles to 121 GEN instructions instead of 209. Its RDNA2-captured expectations pass on both GPUs.
  • Merged onto df16c4c2:
    • NVIDIA full suite: 409/409, none skipped.
    • Intel full suite (without flat_store): fails the same 35 tests as main.
    • The new agc_float16_conversion passes on both.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6050991632 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1252#issuecomment-6050991632). Originally posted by [hashaam1217](https://github.com/hashaam1217) on 2026-10-08T02:33:50Z. --- Checked on Linux with the native path active. CI cannot exercise it: llvmpipe (Mesa 25.2.8) reports `shaderDenormPreserveFloat16 = 0`, so it stays on the emulation. - Both GPUs here advertise `shaderFloat16`, `shaderRoundingModeRTEFloat16`, `shaderDenormPreserveFloat16` and `shaderSignedZeroInfNanPreserveFloat16`: Intel Iris Xe (Alder Lake GT2, Mesa 25.2.8 ANV) and NVIDIA RTX 3060 Laptop (595.91.07). - On Intel the native conversion is what runs. With `INTEL_DEBUG=cs`, the `agc_driver_float16_rounding` shader has 18 `f2f16` in its NIR (0 on main) and compiles to 121 GEN instructions instead of 209. Its RDNA2-captured expectations pass on both GPUs. - Merged onto df16c4c2: - NVIDIA full suite: 409/409, none skipped. - Intel full suite (without `flat_store`): fails the same 35 tests as main. - The new `agc_float16_conversion` passes on both.
adriadam10 commented 2026-10-09 22:39:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-09T22:39:12Z.


Checked on RADV (Radeon 660M, advertises RTE/DenormPreserve/SignedZeroInfNanPreserve for 16-bit floats): full ctest passes with the native path active, including the RDNA2-captured agc_driver_float16_rounding. The new agc_float16_conversion and the agc_driver_graphics float-controls check fail without the change. The native NaN result matches the emulated one bit for bit by construction. Also confirmed by @hashaam1217 on Intel and NVIDIA. CI green; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6090451297 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1252#issuecomment-6090451297). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-09T22:39:12Z. --- Checked on RADV (Radeon 660M, advertises RTE/DenormPreserve/SignedZeroInfNanPreserve for 16-bit floats): full ctest passes with the native path active, including the RDNA2-captured `agc_driver_float16_rounding`. The new `agc_float16_conversion` and the `agc_driver_graphics` float-controls check fail without the change. The native NaN result matches the emulated one bit for bit by construction. Also confirmed by @hashaam1217 on Intel and NVIDIA. CI green; merging.
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
boykopovar/AnyPS5!1252
No description provided.