Shader recompiler: f16 denormal sources read as zero on Intel because the f16 unpack has no DenormPreserve 16 #2822

Closed
opened 2026-10-10 16:12:03 +00:00 by Silverash-i8 · 2 comments
Silverash-i8 commented 2026-10-10 16:12:03 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T16:12:03Z.


On Intel's Windows driver, f16 denormal sources read as zero, because GLSLstd450UnpackHalf2x16 (EmitF16BitsToF32) flushes them unless the module declares DenormPreserve 16. The recompiler only declares the 16-bit float controls in the native f32 to f16 path (EmitNativeF32ToF16BitsRte), not when it unpacks f16 to f32. This is the agc_driver_vopc_compare failure listed in #2114.

Setup: Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release, main 57f96fd2. Intel Graphics in a Core Ultra 9 275HX (Arrow Lake, device 0x7d67, driver 32.0.101.8991), which reports shaderDenormPreserveFloat16, shaderSignedZeroInfNanPreserveFloat16 and shaderRoundingModeRTEFloat16, so NativeF16Rte is true there.

What fails

#2114 describes compare 36 as a NaN case, but on this iGPU it isn't. I changed Check locally to log every mismatch instead of stopping at the first one. All 24 mismatches across the edge-case passes are the smallest f16 denormal 0x0001 (2^-24) against 0x0000 or 0x8000, in every f16 compare that can tell them apart:

Compare Instruction Example
36, 46 !(a >= b) a=0x0000 b=0x0001: got 0, want 1
37, 47 !(a < b || a > b) a=0x0001 b=0x0000: got 1, want 0
38, 48 !(a > b) / !(a <= b) a=0x0001 b=0x8000
39, 40, 43 !(a <= b), !(a < b), a < b || a > b same pairs

No NaN pair mismatches. 2^-24 is a normal f32, so the f32 compare isn't what flushes it; it's the unpack. Shaders without a float mode keep f16 denormals (FLOAT_MODE 0xc0, bits 7:6), which is what the test expects.

Fix

Silverash-i8/AnyPS5-fork:fix/f16-unpack-denorm-preserve, one commit 7158e9e8 on main 57f96fd2, 12 lines added and 7 removed in 3 files. The capability and execution mode block moves out of EmitNativeF32ToF16BitsRte into EmitNativeF16Modes, which emits Float16, RoundingModeRTE 16, DenormPreserve 16 and SignedZeroInfNanPreserve 16 once per module when NativeF16Rte holds. EmitF16BitsToF32 calls it too. Devices without those float controls are unchanged, and a float mode that flushes f16 denormals is still applied by the translation's explicit flushes.

Results

  • agc_driver_vopc_compare, _f64 and _table: pass 3/3 on the iGPU and on the RTX 5060 Laptop GPU (32.0.16.1742). With the same probe, 0 mismatches on both.
  • Full ctest (--parallel 6, iGPU with APS5_NO_PIPELINE_LTO=1 to keep the #2777 race out): 709/709 on the RTX 5060. On the iGPU vopc_compare drops out of the failures and nothing new related to this fails; mesh (#2815), f64_fma_subnormals and fp16_overflow (#2114), lds_beyond_device_limit (#2805) and vop1_float_unary (#2114) fail as on main.
  • agc_driver_gated_dispatch_capture failed in that parallel run, with 0xc0000374 (heap corruption). It also failed under parallel load on a branch without this change (there on its 10 s limit), and passes 10/10 run on its own here, so it isn't this change. The heap corruption under load is worth its own look though, and I'll dig into it separately.

tools/check_conventions.py and tools/check_skips.py --job windows pass. There's no new test: agc_driver_vopc_compare already has the denormal pairs.

The UHD 770 numbers in #2114 show the same compare 36 failure. It would be good to know if this fixes it there too, since I can only test Arrow Lake.

AI-assisted (Claude Code); every number above is from runs on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5793000675 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2822). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-10T16:12:03Z. --- On Intel's Windows driver, f16 denormal sources read as zero, because `GLSLstd450UnpackHalf2x16` (`EmitF16BitsToF32`) flushes them unless the module declares `DenormPreserve 16`. The recompiler only declares the 16-bit float controls in the native f32 to f16 path (`EmitNativeF32ToF16BitsRte`), not when it unpacks f16 to f32. This is the `agc_driver_vopc_compare` failure listed in #2114. **Setup:** Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release, `main` 57f96fd2. Intel Graphics in a Core Ultra 9 275HX (Arrow Lake, device 0x7d67, driver 32.0.101.8991), which reports `shaderDenormPreserveFloat16`, `shaderSignedZeroInfNanPreserveFloat16` and `shaderRoundingModeRTEFloat16`, so `NativeF16Rte` is true there. ### What fails #2114 describes compare 36 as a NaN case, but on this iGPU it isn't. I changed `Check` locally to log every mismatch instead of stopping at the first one. All 24 mismatches across the edge-case passes are the smallest f16 denormal `0x0001` (2^-24) against `0x0000` or `0x8000`, in every f16 compare that can tell them apart: | Compare | Instruction | Example | |---|---|---| | 36, 46 | `!(a >= b)` | a=0x0000 b=0x0001: got 0, want 1 | | 37, 47 | `!(a < b \|\| a > b)` | a=0x0001 b=0x0000: got 1, want 0 | | 38, 48 | `!(a > b)` / `!(a <= b)` | a=0x0001 b=0x8000 | | 39, 40, 43 | `!(a <= b)`, `!(a < b)`, `a < b \|\| a > b` | same pairs | No NaN pair mismatches. 2^-24 is a normal f32, so the f32 compare isn't what flushes it; it's the unpack. Shaders without a float mode keep f16 denormals (`FLOAT_MODE` 0xc0, bits 7:6), which is what the test expects. ### Fix [`Silverash-i8/AnyPS5-fork:fix/f16-unpack-denorm-preserve`](https://github.com/Silverash-i8/AnyPS5-fork/tree/fix/f16-unpack-denorm-preserve), one commit `7158e9e8` on `main` 57f96fd2, 12 lines added and 7 removed in 3 files. The capability and execution mode block moves out of `EmitNativeF32ToF16BitsRte` into `EmitNativeF16Modes`, which emits `Float16`, `RoundingModeRTE 16`, `DenormPreserve 16` and `SignedZeroInfNanPreserve 16` once per module when `NativeF16Rte` holds. `EmitF16BitsToF32` calls it too. Devices without those float controls are unchanged, and a float mode that flushes f16 denormals is still applied by the translation's explicit flushes. ### Results - `agc_driver_vopc_compare`, `_f64` and `_table`: pass 3/3 on the iGPU and on the RTX 5060 Laptop GPU (32.0.16.1742). With the same probe, 0 mismatches on both. - Full ctest (`--parallel 6`, iGPU with `APS5_NO_PIPELINE_LTO=1` to keep the #2777 race out): 709/709 on the RTX 5060. On the iGPU `vopc_compare` drops out of the failures and nothing new related to this fails; `mesh` (#2815), `f64_fma_subnormals` and `fp16_overflow` (#2114), `lds_beyond_device_limit` (#2805) and `vop1_float_unary` (#2114) fail as on `main`. - `agc_driver_gated_dispatch_capture` failed in that parallel run, with `0xc0000374` (heap corruption). It also failed under parallel load on a branch without this change (there on its 10 s limit), and passes 10/10 run on its own here, so it isn't this change. The heap corruption under load is worth its own look though, and I'll dig into it separately. `tools/check_conventions.py` and `tools/check_skips.py --job windows` pass. There's no new test: `agc_driver_vopc_compare` already has the denormal pairs. The UHD 770 numbers in #2114 show the same compare 36 failure. It would be good to know if this fixes it there too, since I can only test Arrow Lake. AI-assisted (Claude Code); every number above is from runs on this machine.
ThatsLeo commented 2026-10-10 20:29:34 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by ThatsLeo on 2026-10-10T20:29:34Z.


Results on Mesa ANV, carried over from #2861 as asked. Fedora 44, GCC 16.2.1, Release, Intel Arc (Meteor Lake, Core Ultra 7 155H), Mesa 26.2.3, which reports shaderDenormPreserveFloat16, shaderRoundingModeRTEFloat16 and shaderSignedZeroInfNanPreserveFloat16 (lavapipe reports no shaderDenormPreserveFloat16). ANV fails the same way: every mismatch is 0x0001 against 0x0000 or 0x8000.

Each fix cherry-picked alone onto main 56fb1b3b, full ctest:

vopc_compare (3 runs) Intel Arc lavapipe
main fails 5 failed / 708 1 failed
7158e9e8 (this issue, DenormPreserve 16) 3/3 4 failed 1 failed
58f596ee (#1463, integer decode) 3/3 4 failed 1 failed
e59865e0 (#2861, subnormals as fraction × 2^-24) 3/3 4 failed 1 failed

The remaining failures are the same in every row: agc_driver_mesh (#2815), agc_driver_f64_fma_subnormals (#2860), agc_driver_lds_beyond_device_limit (#2805) and agc_driver_vop1_float_unary (#1250) on Arc, agc_driver_f64_fma_subnormals on lavapipe. So on ANV all three fix the compare with no regression. The difference is where they apply: 7158e9e8 relies on the device preserving f16 denormals, while the integer decodes (#1463, e59865e0) do not depend on float controls, and #1463 also covers the AMD byte-selector case. e59865e0 adds nothing over #1463, so I'm not proposing it further.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6101864388 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2822#issuecomment-6101864388). Originally posted by [ThatsLeo](https://github.com/ThatsLeo) on 2026-10-10T20:29:34Z. --- Results on Mesa ANV, carried over from #2861 as asked. Fedora 44, GCC 16.2.1, Release, Intel Arc (Meteor Lake, Core Ultra 7 155H), Mesa 26.2.3, which reports `shaderDenormPreserveFloat16`, `shaderRoundingModeRTEFloat16` and `shaderSignedZeroInfNanPreserveFloat16` (lavapipe reports no `shaderDenormPreserveFloat16`). ANV fails the same way: every mismatch is `0x0001` against `0x0000` or `0x8000`. Each fix cherry-picked alone onto `main` `56fb1b3b`, full `ctest`: | | `vopc_compare` (3 runs) | Intel Arc | lavapipe | |---|---|---|---| | `main` | fails | 5 failed / 708 | 1 failed | | `7158e9e8` (this issue, `DenormPreserve 16`) | 3/3 | 4 failed | 1 failed | | `58f596ee` (#1463, integer decode) | 3/3 | 4 failed | 1 failed | | `e59865e0` (#2861, subnormals as fraction × 2^-24) | 3/3 | 4 failed | 1 failed | The remaining failures are the same in every row: `agc_driver_mesh` (#2815), `agc_driver_f64_fma_subnormals` (#2860), `agc_driver_lds_beyond_device_limit` (#2805) and `agc_driver_vop1_float_unary` (#1250) on Arc, `agc_driver_f64_fma_subnormals` on lavapipe. So on ANV all three fix the compare with no regression. The difference is where they apply: `7158e9e8` relies on the device preserving f16 denormals, while the integer decodes (#1463, `e59865e0`) do not depend on float controls, and #1463 also covers the AMD byte-selector case. `e59865e0` adds nothing over #1463, so I'm not proposing it further. AI-assisted: yes.
Silverash-i8 commented 2026-10-11 05:28:49 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-11T05:28:49Z.


#1463 is merged now, which fixes this. On Windows 11 with the Arrow Lake iGPU (driver 101.8991), agc_driver_vopc_compare failed on plain main and passed with #1463 applied, along with half_expansion from #1505 and the other f16 tests (details on #1463). Closing; my fix/f16-unpack-denorm-preserve branch is superseded.

Thanks @ThatsLeo for the Mesa ANV runs.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6105837146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/2822#issuecomment-6105837146). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-11T05:28:49Z. --- #1463 is merged now, which fixes this. On Windows 11 with the Arrow Lake iGPU (driver 101.8991), `agc_driver_vopc_compare` failed on plain `main` and passed with #1463 applied, along with `half_expansion` from #1505 and the other f16 tests (details on #1463). Closing; my `fix/f16-unpack-denorm-preserve` branch is superseded. Thanks @ThatsLeo for the Mesa ANV runs. AI-assisted (Claude Code).
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
boykopovar/AnyPS5#2822
No description provided.