fix(shader): accept clamp and omod on every f16 VOP3 result op #664

Merged
adriadam10 merged 1 commit from upstream-pr/664 into main 2026-10-06 05:35:05 +00:00
adriadam10 commented 2026-10-05 12:39:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T12:39:18Z.


What

Closes the clamp/omod modifiers of the f16 VOP3 result ops in one go (follow-up of #323, which made f16 results honour clamp). Before, each op either refused the modifier or the decoder dropped it:

op clamp omod
v_add/sub/subrev/mul/min/max_f16 applied (writeF16, #323) ignored
v_fma_f16, v_max3/min3/med3_f16 applied (writeF16) ignored
v_div_fixup_f16 applied on the bits ignored
v_ldexp_f16, v_frexp_mant_f16 applied on the bits ignored
v_cvt_norm_i16/u16_f16 ignored ignored

Not touched, still throw: v_pack_b32_f16, v_cvt_pknorm_*_f16, v_fmac_f16 in VOP3, v_cvt_i16/u16_f16 forms and the VOP3P packed ops keep their current behaviour.

  • The clamp on the f16 bits (NaN, negative and -0 give +0, above 1.0 gives 1.0) is one helper, clampF16Bits, used by v_div_fixup_f16, v_ldexp_f16 and v_frexp_mant_f16.
  • omod is accepted and ignored, as the existing TechnicalDebt entry for the output modifier already says (the hardware ignores it while f16 denormals are enabled; with them flushed it applies it, not modelled).

Behaviour measured on HW

gfx1035 (Radeon 660M). 2048 rows per op, special values plus random bits, IEEE=0/1, DENORM16=3:

  • clamp = the f16 clamp above applied to the unmodified result: 0 mismatches on every op of the table except v_cvt_norm_*_f16.
  • mul:2, mul:4, div:2 = the unmodified result, 0 mismatches. With DENORM16=0 and IEEE=0 the hardware applies them (506/2048 equal for v_add_f16), already documented.
  • v_cvt_norm_i16/u16_f16: clamp and omod both ignored (2048/2048 equal to unmodified).

Tested

Linux (CachyOS), RADV and lavapipe.

  • New Float16Modifiers.cpp execution test: 16 instructions (clamp, omod and both on 14 ops), 32 rows, expected values from the hardware. NaN results are compared as "any NaN".
  • Fails without the fix: the clamp without its pieces, and each op refused by the decoder on main.
  • Float16TernaryClamp.cpp (same PR, first commit's scope) keeps covering the ternary forms with op_sel/neg/abs.
  • Release build, full ctest: all pass except agc_driver_pixel_helper_lanes, agc_driver_pixel_lds and agc_driver_pixel_lds_lane_slots, which fail on RADV on main too (wave32 pixel tests, no f16 ops).
  • Found while measuring, not changed here: on an sNaN input v_min_f16/v_max_f16/v_max3_f16 return the other operand where the hardware returns the quiet NaN. The new test avoids sNaN inputs.

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:4745026398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/664). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T12:39:18Z. --- ### What Closes the clamp/omod modifiers of the f16 VOP3 result ops in one go (follow-up of #323, which made f16 results honour clamp). Before, each op either refused the modifier or the decoder dropped it: | op | clamp | omod | |---|---|---| | `v_add/sub/subrev/mul/min/max_f16` | applied (`writeF16`, #323) | ignored | | `v_fma_f16`, `v_max3/min3/med3_f16` | applied (`writeF16`) | ignored | | `v_div_fixup_f16` | applied on the bits | ignored | | `v_ldexp_f16`, `v_frexp_mant_f16` | applied on the bits | ignored | | `v_cvt_norm_i16/u16_f16` | ignored | ignored | Not touched, still throw: `v_pack_b32_f16`, `v_cvt_pknorm_*_f16`, `v_fmac_f16` in VOP3, `v_cvt_i16/u16_f16` forms and the VOP3P packed ops keep their current behaviour. - The clamp on the f16 bits (NaN, negative and -0 give +0, above 1.0 gives 1.0) is one helper, `clampF16Bits`, used by `v_div_fixup_f16`, `v_ldexp_f16` and `v_frexp_mant_f16`. - `omod` is accepted and ignored, as the existing TechnicalDebt entry for the output modifier already says (the hardware ignores it while f16 denormals are enabled; with them flushed it applies it, not modelled). #### Behaviour measured on HW gfx1035 (Radeon 660M). 2048 rows per op, special values plus random bits, `IEEE=0`/`1`, `DENORM16=3`: - `clamp` = the f16 clamp above applied to the unmodified result: 0 mismatches on every op of the table except `v_cvt_norm_*_f16`. - `mul:2`, `mul:4`, `div:2` = the unmodified result, 0 mismatches. With `DENORM16=0` and `IEEE=0` the hardware applies them (506/2048 equal for `v_add_f16`), already documented. - `v_cvt_norm_i16/u16_f16`: `clamp` and `omod` both ignored (2048/2048 equal to unmodified). ### Tested Linux (CachyOS), RADV and lavapipe. - New `Float16Modifiers.cpp` execution test: 16 instructions (clamp, omod and both on 14 ops), 32 rows, expected values from the hardware. NaN results are compared as "any NaN". - Fails without the fix: the clamp without its pieces, and each op refused by the decoder on `main`. - `Float16TernaryClamp.cpp` (same PR, first commit's scope) keeps covering the ternary forms with op_sel/neg/abs. - Release build, full `ctest`: all pass except `agc_driver_pixel_helper_lanes`, `agc_driver_pixel_lds` and `agc_driver_pixel_lds_lane_slots`, which fail on RADV on `main` too (wave32 pixel tests, no f16 ops). - Found while measuring, not changed here: on an sNaN input `v_min_f16`/`v_max_f16`/`v_max3_f16` return the other operand where the hardware returns the quiet NaN. The new test avoids sNaN inputs. ### 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 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
adriadam10 commented 2026-10-05 17:07:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T17:07:41Z.


Rebased on main (conflict with #501, which grouped v_cvt_pk_u8_f32 with v_ldexp_f16: v_cvt_pk_u8_f32 keeps rejecting clamp/omod, v_ldexp_f16 accepts them as in this PR). Float16Modifiers, Float16TernaryClamp and Vop3LegacySourceModifiers pass on RADV and lavapipe.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5999286860 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/664#issuecomment-5999286860). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T17:07:41Z. --- Rebased on main (conflict with #501, which grouped `v_cvt_pk_u8_f32` with `v_ldexp_f16`: `v_cvt_pk_u8_f32` keeps rejecting clamp/omod, `v_ldexp_f16` accepts them as in this PR). Float16Modifiers, Float16TernaryClamp and Vop3LegacySourceModifiers pass on RADV and lavapipe.
adriadam10 commented 2026-10-05 18:31:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-05T18:31:27Z.


Rebased on main after #507 (usesSignedSaturateClamp renamed to usesIntegerSaturateClamp); execution tests pass again.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6000647613 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/664#issuecomment-6000647613). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-05T18:31:27Z. --- Rebased on main after #507 (`usesSignedSaturateClamp` renamed to `usesIntegerSaturateClamp`); execution tests pass again.
oneandonlydean commented 2026-10-05 19:45:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T19:45:38Z.


Thanks. #507 landed and renamed usesSignedSaturateClamp to usesIntegerSaturateClamp, so this now conflicts on the return line of supportsNativeVop3Clamp. Keeping your early return and main's new name resolves it:

    if (isNativeVop3F16TernaryOpcode(opcode)) {
        return true;
    }
    return supportsNativeVop3ResultModifiers(opcode) || usesInexactClampControl(opcode) || usesIntegerSaturateClamp(opcode) ||
        isF32DivisionStepOpcode(opcode) || isCubeOpcode(opcode);

I tested that resolution with the rest of the batch: agc_driver_float16_modifiers and agc_driver_float16_ternary_clamp fail on main's code, pass with the change, and pass 20 times in a row. The full ctest passes apart from one unrelated test. Ready to merge after the rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6001771715 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/664#issuecomment-6001771715). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T19:45:38Z. --- Thanks. #507 landed and renamed `usesSignedSaturateClamp` to `usesIntegerSaturateClamp`, so this now conflicts on the return line of `supportsNativeVop3Clamp`. Keeping your early return and main's new name resolves it: ```cpp if (isNativeVop3F16TernaryOpcode(opcode)) { return true; } return supportsNativeVop3ResultModifiers(opcode) || usesInexactClampControl(opcode) || usesIntegerSaturateClamp(opcode) || isF32DivisionStepOpcode(opcode) || isCubeOpcode(opcode); ``` I tested that resolution with the rest of the batch: `agc_driver_float16_modifiers` and `agc_driver_float16_ternary_clamp` fail on main's code, pass with the change, and pass 20 times in a row. The full ctest passes apart from one unrelated test. Ready to merge after the rebase.
oneandonlydean commented 2026-10-05 20:07:56 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T20:07:56Z.


Sorry, please ignore my rebase note above: this branch is already on top of #507 and uses usesIntegerSaturateClamp, and I was looking at an older head. It merges cleanly with main as it is.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6002070526 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/664#issuecomment-6002070526). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-05T20:07:56Z. --- Sorry, please ignore my rebase note above: this branch is already on top of #507 and uses `usesIntegerSaturateClamp`, and I was looking at an older head. It merges cleanly with main as it is.
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!664
No description provided.