fix(shader): apply f32 abs and neg source modifiers on the sign bit #765

Merged
khasinski merged 1 commit from upstream-pr/765 into main 2026-10-06 02:12:54 +00:00
khasinski commented 2026-10-05 22:04:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by khasinski on 2026-10-05T22:04:35Z.


What

Found while testing #663 on NVIDIA: its new agc_driver_division_output_modifiers test fails there with

division output modifiers: lane 10 v_div_fixup_f32 v13, -v4, |v5|, v6 div:2 is 0x7fffffff, expected 0x7ff00000

vDivFixupF32 works on integer bits and returns denominator | 0x400000 for a NaN denominator. But readOperand applied abs and neg on F32 operands as FPAbs32/FPNeg32 (FAbs / OpFNegate in SPIR-V), and on NVIDIA FAbs of 0x7ff00000 returns the driver's canonical NaN 0x7fffffff. The payload is gone before the fixup runs. RADV and lavapipe keep the payload, so CI passes.

F32 operands now clear or flip the sign bit, the code path readOperand already uses for U32 operands. The F32 branch only bitcasts the result. IEEE 754 defines abs and negate as sign-bit operations that never change a NaN payload, so the bit form is exact for every input. The shader disk cache key changes with the source hash.

The f16 source modifiers in SubwordPacking.cpp use the same FPAbs32/FPNeg32 pattern and may lose f16 NaN payloads on NVIDIA in the same way. This PR does not change them, and I did not test them.

Tested

Linux (Ubuntu 26.04, GCC 15.2.0), Release, BUILD_TESTING=ON. Vulkan drivers selected with VK_DRIVER_FILES:

  • RTX 5090 (595.91.07): #663 alone fails with the lane 10 mismatch above. #663 merged with this change passes.
  • Full ctest on main (bc24783e) with this change: NVIDIA 315/318, RADV (Ryzen 9 9950X3D iGPU, RDNA2) 315/318, lavapipe 318/318. The failing tests are the same as on main without this change: on NVIDIA agc_driver_f32_output_modifier (#638), 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.

No new test: #663's agc_driver_division_output_modifiers covers this on NVIDIA. No current test on main passes a NaN with a payload through an abs/neg operand on a path that keeps the bits.

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 (#663 needs this on NVIDIA)
  • AI-assisted: yes (Claude Code); tested on my hardware
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4751302647 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/765). Originally posted by [khasinski](https://github.com/khasinski) on 2026-10-05T22:04:35Z. --- ### What Found while testing #663 on NVIDIA: its new `agc_driver_division_output_modifiers` test fails there with division output modifiers: lane 10 v_div_fixup_f32 v13, -v4, |v5|, v6 div:2 is 0x7fffffff, expected 0x7ff00000 `vDivFixupF32` works on integer bits and returns `denominator | 0x400000` for a NaN denominator. But `readOperand` applied `abs` and `neg` on F32 operands as `FPAbs32`/`FPNeg32` (`FAbs` / `OpFNegate` in SPIR-V), and on NVIDIA `FAbs` of `0x7ff00000` returns the driver's canonical NaN `0x7fffffff`. The payload is gone before the fixup runs. RADV and lavapipe keep the payload, so CI passes. F32 operands now clear or flip the sign bit, the code path `readOperand` already uses for U32 operands. The F32 branch only bitcasts the result. IEEE 754 defines `abs` and `negate` as sign-bit operations that never change a NaN payload, so the bit form is exact for every input. The shader disk cache key changes with the source hash. The f16 source modifiers in `SubwordPacking.cpp` use the same `FPAbs32`/`FPNeg32` pattern and may lose f16 NaN payloads on NVIDIA in the same way. This PR does not change them, and I did not test them. ### Tested Linux (Ubuntu 26.04, GCC 15.2.0), Release, `BUILD_TESTING=ON`. Vulkan drivers selected with `VK_DRIVER_FILES`: - RTX 5090 (595.91.07): #663 alone fails with the lane 10 mismatch above. #663 merged with this change passes. - Full `ctest` on `main` (bc24783e) with this change: NVIDIA 315/318, RADV (Ryzen 9 9950X3D iGPU, RDNA2) 315/318, lavapipe 318/318. The failing tests are the same as on `main` without this change: on NVIDIA `agc_driver_f32_output_modifier` (#638), `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`. No new test: #663's `agc_driver_division_output_modifiers` covers this on NVIDIA. No current test on `main` passes a NaN with a payload through an `abs`/`neg` operand on a path that keeps the bits. 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 (#663 needs this on NVIDIA) - [x] AI-assisted: yes (Claude Code); tested on my hardware
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!765
No description provided.