fix(shader): apply f32 output modifiers on the exponent bits #638

Merged
khasinski merged 1 commit from upstream-pr/638 into main 2026-10-06 00:26:57 +00:00
khasinski commented 2026-10-05 10:19:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by khasinski on 2026-10-05T10:19:56Z.


What

agc_driver_f32_output_modifier fails on NVIDIA on main (53dc19cf):

AGC graphics: f32 output modifier: lane 3 v_mul_f32_e64 v11, v4, v5 div:2 is 0x7f7fffff, expected 0x7f800000

FLT_MAX * 2.0 overflows to +inf, and div:2 of +inf is +inf. With every lane printed instead of the first, this is the only mismatch: v_add_f32 ... div:2 and v_fma_f32 ... div:2 on the same overflowing inputs are correct. The output modifier was emitted as a second OpFMul by the constant 0.5 (or 2, 4); the NVIDIA driver behaves as if it folds it into the instruction's own multiply (no intermediate overflow), although both multiplies are decorated NoContraction; I did not inspect the generated SASS. CI does not see this, since lavapipe does not fold it.

The modifier now scales a normal result through its exponent field instead of a multiply:

  • mul:2, mul:4: add 1 or 2 to the exponent; signed infinity when it overflows.
  • div:2: subtract 1 from the exponent; results below 2^-125 keep the existing signed-zero flush.
  • Infinities and NaNs pass through unchanged; the existing zero flush of denormal inputs is kept.

An exhaustive CPU comparison of the old expression (IEEE multiply plus the existing selects) and the new one over all 2^32 inputs finds no difference for any of the three modifiers, so results change only where a driver folded the multiply. The shader disk cache key changes with the source hash.

Tested

Linux (Ubuntu 26.04, GCC 15.2.0), Release, BUILD_TESTING=ON, full ctest on three Vulkan drivers selected with VK_DRIVER_FILES:

Driver main This PR
NVIDIA RTX 5090, 595.91.07 281/284, agc_driver_f32_output_modifier fails 282/284, it passes
RADV, Ryzen 9 9950X3D iGPU (RDNA2) 281/284 281/284, same tests
lavapipe 284/284 284/284

The remaining failures also fail on main and are unrelated to this change: on NVIDIA agc_driver_lds_atomics64 and agc_driver_scalar_sop1, on RADV agc_driver_pixel_helper_lanes, agc_driver_pixel_lds and agc_driver_pixel_lds_lane_slots. I will report them separately.

No title tested.

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 (Claude Code); reviewed and tested by me
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4743425819 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/638). Originally posted by [khasinski](https://github.com/khasinski) on 2026-10-05T10:19:56Z. --- ### What `agc_driver_f32_output_modifier` fails on NVIDIA on `main` (53dc19cf): AGC graphics: f32 output modifier: lane 3 v_mul_f32_e64 v11, v4, v5 div:2 is 0x7f7fffff, expected 0x7f800000 `FLT_MAX * 2.0` overflows to +inf, and `div:2` of +inf is +inf. With every lane printed instead of the first, this is the only mismatch: `v_add_f32 ... div:2` and `v_fma_f32 ... div:2` on the same overflowing inputs are correct. The output modifier was emitted as a second `OpFMul` by the constant 0.5 (or 2, 4); the NVIDIA driver behaves as if it folds it into the instruction's own multiply (no intermediate overflow), although both multiplies are decorated `NoContraction`; I did not inspect the generated SASS. CI does not see this, since lavapipe does not fold it. The modifier now scales a normal result through its exponent field instead of a multiply: - `mul:2`, `mul:4`: add 1 or 2 to the exponent; signed infinity when it overflows. - `div:2`: subtract 1 from the exponent; results below 2^-125 keep the existing signed-zero flush. - Infinities and NaNs pass through unchanged; the existing zero flush of denormal inputs is kept. An exhaustive CPU comparison of the old expression (IEEE multiply plus the existing selects) and the new one over all 2^32 inputs finds no difference for any of the three modifiers, so results change only where a driver folded the multiply. The shader disk cache key changes with the source hash. ### Tested Linux (Ubuntu 26.04, GCC 15.2.0), Release, `BUILD_TESTING=ON`, full `ctest` on three Vulkan drivers selected with `VK_DRIVER_FILES`: | Driver | `main` | This PR | |---|---|---| | NVIDIA RTX 5090, 595.91.07 | 281/284, `agc_driver_f32_output_modifier` fails | 282/284, it passes | | RADV, Ryzen 9 9950X3D iGPU (RDNA2) | 281/284 | 281/284, same tests | | lavapipe | 284/284 | 284/284 | The remaining failures also fail on `main` and are unrelated to this change: on NVIDIA `agc_driver_lds_atomics64` and `agc_driver_scalar_sop1`, on RADV `agc_driver_pixel_helper_lanes`, `agc_driver_pixel_lds` and `agc_driver_pixel_lds_lane_slots`. I will report them separately. No title tested. ### 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 (Claude Code); reviewed and tested by me
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!638
No description provided.