feat(shader): apply f16 and f64 output modifiers when denormals flushed #15243

Merged
Kikoarl merged 4 commits from upstream-pr/15243 into main 2026-11-07 12:39:22 +00:00
Kikoarl commented 2026-11-02 22:02:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-11-02T22:02:08Z.


What

core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp threw output modifier on an f16 or f64 result with f16/f64 output denormals flushed is not implemented when an instruction with precision f16 (scalar or packed) or f64 had an output modifier (mul:2, mul:4, div:2) in a shader with output denormals flushed in its FLOAT_MODE.

This implements the output modifier scaling for f16 and f64 under FLOAT_MODE denormal flush semantics matching AMD RDNA2 (gfx1035/gfx1036):

  • For f16, applies mul:2, mul:4 (exponent addition) and div:2 (exponent subtraction) in scaleF16Result and scaleF16Bits. On intermediate values exceeding the half float range, respects the F32 finite boundary so intermediate values correctly scale back into valid F16 range.
  • Denormal flush preserves the sign bit (sign), ensuring -0.0 and negative denormals flush to negative zero rather than being converted to +0.0.
  • In Float64Instructions.cpp, float64Operation explicitly clears destination.omod = 0u for non-U64 operations before calling writeOperand, ensuring f64-to-f32 conversions such as v_cvt_f32_f64 correctly ignore output modifiers on hardware.
  • Updates Float16Modifiers.cpp execution test to verify scaled output results under flushed float mode (including ternary scaled outputs v_min3_f16, v_max3_f16, v_med3_f16, and v_div_fixup_f16) instead of asserting refusal.
  • Documents the behavior in docs/dev/debt/shader.md. Reduces unsupported_throws in tools/progress.py from 149 to 148.

Tested

  • AMD Radeon RX 9070 XT on AMD Windows driver (5/5 negative control by @bunbeans2-arch on 4f00ef87f0).
  • AMD Radeon RX 6300 (RADV NAVI24, Linux, by @TechLevelZero, line 484 of log gist, agc_driver_float16_modifiers Passed 2.98 sec).
  • Linux x86_64, Intel UHD Graphics 770, llvmpipe.
  • ctest --test-dir /tmp/anyps5_build -R "vector_half_double_output_modifiers" -V passed (1/1 tests passed, 0.00s).
  • Execution tests: ctest --test-dir /tmp/anyps5_build -R "^(agc_driver_float16_modifiers|agc_driver_f64_rounding)$" -V passed.
  • Full vector test suite ctest --test-dir /tmp/anyps5_build -R "^vector_" passed.
  • python3 tools/check_conventions.py --base origin/main clean (0 errors; expected debt-length warning at 1,687 chars preserving existing context while detailing hardware evidence).
  • python3 tools/progress.py confirms unsupported_throws decreases from 149 to 148.

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 under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 9070 XT (Windows), AMD Radeon RX 6300 (RADV NAVI24, Linux), Intel(R) UHD Graphics 770, llvmpipe
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5128125866 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15243). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-11-02T22:02:08Z. --- ### What `core/shader/recompiler/Translation/src/TranslationContext/OperandAccess.cpp` threw `output modifier on an f16 or f64 result with f16/f64 output denormals flushed is not implemented` when an instruction with precision `f16` (scalar or packed) or `f64` had an output modifier (`mul:2`, `mul:4`, `div:2`) in a shader with output denormals flushed in its `FLOAT_MODE`. This implements the output modifier scaling for `f16` and `f64` under `FLOAT_MODE` denormal flush semantics matching AMD RDNA2 (gfx1035/gfx1036): - For `f16`, applies `mul:2`, `mul:4` (exponent addition) and `div:2` (exponent subtraction) in `scaleF16Result` and `scaleF16Bits`. On intermediate values exceeding the half float range, respects the F32 finite boundary so intermediate values correctly scale back into valid F16 range. - Denormal flush preserves the sign bit (`sign`), ensuring `-0.0` and negative denormals flush to negative zero rather than being converted to `+0.0`. - In `Float64Instructions.cpp`, `float64Operation` explicitly clears `destination.omod = 0u` for non-U64 operations before calling `writeOperand`, ensuring f64-to-f32 conversions such as `v_cvt_f32_f64` correctly ignore output modifiers on hardware. - Updates `Float16Modifiers.cpp` execution test to verify scaled output results under flushed float mode (including ternary scaled outputs `v_min3_f16`, `v_max3_f16`, `v_med3_f16`, and `v_div_fixup_f16`) instead of asserting refusal. - Documents the behavior in `docs/dev/debt/shader.md`. Reduces `unsupported_throws` in `tools/progress.py` from 149 to 148. ### Tested - AMD Radeon RX 9070 XT on AMD Windows driver (5/5 negative control by @bunbeans2-arch on `4f00ef87f0`). - AMD Radeon RX 6300 (RADV NAVI24, Linux, by @TechLevelZero, line 484 of log gist, `agc_driver_float16_modifiers Passed 2.98 sec`). - Linux x86_64, Intel UHD Graphics 770, llvmpipe. - `ctest --test-dir /tmp/anyps5_build -R "vector_half_double_output_modifiers" -V` passed (1/1 tests passed, 0.00s). - Execution tests: `ctest --test-dir /tmp/anyps5_build -R "^(agc_driver_float16_modifiers|agc_driver_f64_rounding)$" -V` passed. - Full vector test suite `ctest --test-dir /tmp/anyps5_build -R "^vector_"` passed. - `python3 tools/check_conventions.py --base origin/main` clean (0 errors; expected `debt-length` warning at 1,687 chars preserving existing context while detailing hardware evidence). - `python3 tools/progress.py` confirms `unsupported_throws` decreases from 149 to 148. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 9070 XT (Windows), AMD Radeon RX 6300 (RADV NAVI24, Linux), Intel(R) UHD Graphics 770, llvmpipe - [x] AI-assisted: yes
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!15243
No description provided.