Skip to content

fix(shader): v_mullit_f32 legacy rules, v_cvt_pk_u8_f32 rounding and VOP3 neg/abs - #501

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
adriadam10:fix/vop3-legacy-mods
Oct 5, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
adriadam10:fix/vop3-legacy-mods

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

VOP3 neg/abs on v_mullit_f32 (all three sources) and v_cvt_pk_u8_f32 (src0) used to throw. Enabling them showed that both ops differed from hardware even without modifiers, so this PR fixes that as well:

  • v_mullit_f32 was a plain v_mul_f32 that ignored src2. It now follows the measured rules.
  • v_cvt_pk_u8_f32 truncated. It now rounds to nearest even, like the hardware (1.5 → 2, 2.5 → 2, 3.5 → 4).

Anything still unmodelled keeps throwing: clamp/omod on both ops, and neg/abs on src1/src2 of v_cvt_pk_u8_f32 (llvm-mc rejects those too).

Behaviour measured on HW

The ISA guide doesn't spell these out, so I measured them on an RDNA2 GPU (gfx1035; llvm-mc gives the same VOP3 opcode 0x150/0x15e on gfx1013). Modifiers apply before every check below.

  • v_mullit_f32 d, s0, s1, s2:
    1. If s1 is −MAX_FLOAT, −inf or NaN, or s2 is NaN, ±0 or negative, the result is 0xff7fffff (−MAX_FLOAT). The −MAX test is exact: 0xff7ffffe multiplies normally.
    2. Otherwise, if s0 or s1 is ±0, the result is +0, even for 0 × inf, 0 × NaN and −0 × x.
    3. Otherwise, if s0 is NaN, the result is s0 quieted (| 0x400000), sign kept.
    4. Otherwise, the result is the IEEE product (overflow → ±inf).
  • v_cvt_pk_u8_f32: NaN and values ≤ 0 → 0, values ≥ 255 → 255, otherwise round to nearest even.

These results don't depend on the IEEE or DENORM mode, with two exceptions: IEEE=0 keeps sNaN s0 unquieted, and flushed f32 denormals make a positive-denormal s2 count as 0. The implementation follows the default compute mode (IEEE=1, denormals kept), and the test has no sNaN or denormal rows.

To stay exact on any driver, everything is done on the bits:

  • The FMul only sees non-NaN, non-zero operands. The NaN result is chosen on the bits.
  • Rounding uses a truncating convert, an exact FSub for the fraction, and compares. RoundEven isn't in Vulkan's precision table.

v_mad_legacy_f32 is not included: on gfx1030+ its opcode 0x140 is v_fma_legacy_f32, so I can't measure it on my GPU, and its translation stays as it is on main.

Tested

Linux, RADV + lavapipe (local Mesa and CI's Ubuntu Mesa 25.2.8):

  • New execution test agc_driver_vop3_legacy_source_modifiers_tests: 32 lanes × 10 forms, expected values taken from the hardware. The rows cover the specials (±0, ±inf, qNaN with payloads, ±MAX, −MAX−1ulp), rounding ties, and both clamp edges.
  • The model matched the hardware on a 4096-row sweep (36952 checks, 0 mismatches).
  • Each piece of the fix fails the test when reverted (12 negative checks: −MAX/NaN/sign rules, legacy zero, NaN bits, src2 modifiers, decoder accept, truncation, ties, 255 guard).
  • Full Release ctest passes, apart from agc_driver_pixel_helper_lanes, which already fails on main with local RADV (not touched here).

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

@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 4, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, checked against the RDNA2 ISA guide (V_MULLIT_F32 only says "specific INF, NaN, overflow rules", and the older GCN description has the same -MAX_FLOAT conditions you measured) and the code follows your rules exactly: the -MAX test catches -MAX, -inf and negative NaNs, the FMul never sees a NaN or zero operand, and the u8 rounding is exact (truncate, exact fraction, ties to even, 255 guard). The new modifier block for v_cvt_pk_u8_f32 sits before the generic path, so src1/src2 modifiers, clamp and omod still throw. A small note, not blocking: the sNaN s0 quieting and the positive-denormal s2 case follow IEEE=1 with denormals kept, while the recompiler doesn't read the mode; a TechnicalDebt line would make that visible. This changes results of unmodified v_cvt_pk_u8_f32 and v_mullit_f32, so I'll run it through my PPSA21564 check before merging; ready to merge from my side.

@adriadam10

Copy link
Copy Markdown
Collaborator Author

Added the TechnicalDebt line under "Functional": v_mullit_f32 follows the hardware measured at IEEE=1 with denormals kept (sNaN src0 quieted, positive denormal src2 counts as positive), and the recompiler does not read MODE. Also rebased on current main; agc_driver_vop3_legacy_source_modifiers_tests still passes on RADV and lavapipe.

@adriadam10
adriadam10 force-pushed the fix/vop3-legacy-mods branch from caf75e0 to 3707e39 Compare October 4, 2026 21:09
@github-actions github-actions Bot added the docs label Oct 4, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, the TechnicalDebt line says exactly what the code assumes (IEEE=1 with denormals kept, sNaN src0 quieted, positive denormal src2 positive) and the rebase left the fix commit unchanged.

agc_driver_vop3_legacy_source_modifiers still passes on my NVIDIA machine with the new head on current main, and fails on main's code.

I'll run it through my PPSA21564 check next and merge it after that if it's clean.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

#498 landed today, and it now conflicts with this one in checkNativeVop3Modifiers: #498 added an if (opcode == RdnaOpcode::VLdexpF16) block in the same place as your VCvtPkU8F32 block, and the two bodies are identical. Keeping both fixes it, either as two blocks or as one condition:

if (opcode == RdnaOpcode::VLdexpF16 || opcode == RdnaOpcode::VCvtPkU8F32) {

I tried the combined form here on current main and the full ctest passes, agc_driver_vop3_legacy_source_modifiers included. Could you rebase? I also checked the 5,688 PPSA21564 shaders I have dumped: none use v_mullit_f32 or v_cvt_pk_u8_f32, so this doesn't need my PPSA21564 check after all, and I'll merge it once it's rebased.

adriadam10 and others added 2 commits October 5, 2026 10:53
…VOP3 neg/abs

Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@adriadam10
adriadam10 force-pushed the fix/vop3-legacy-mods branch from 3707e39 to 9e6362d Compare October 5, 2026 08:57
@adriadam10

Copy link
Copy Markdown
Collaborator Author

Rebased on current main after #498:

  • checkNativeVop3Modifiers: kept both opcodes in one condition, VLdexpF16 || VCvtPkU8F32, as suggested.
  • agc_driver_vop3_legacy_source_modifiers and the other agc_driver_vop3*/agc_shader* tests pass on RADV.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 5, 2026
@oneandonlydean
oneandonlydean merged commit 4c57426 into boykopovar:main Oct 5, 2026
3 checks passed
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 5, 2026
Takes upstream's merged versions of our boykopovar#586 boykopovar#611 boykopovar#612 boykopovar#505 boykopovar#490 boykopovar#619
boykopovar#503 boykopovar#627 boykopovar#628 boykopovar#618 and drops astrobot's local copies, plus gate-batch-3
(boykopovar#469 boykopovar#500 boykopovar#504 boykopovar#509 boykopovar#510 boykopovar#514 boykopovar#525 boykopovar#526 boykopovar#528), round o/p (boykopovar#617 boykopovar#620
boykopovar#621 boykopovar#622 boykopovar#623 boykopovar#624 boykopovar#501 boykopovar#508 boykopovar#629 boykopovar#630 boykopovar#631).

Conflicts:
- SpirvAnalysis.hpp/.cpp, SpirvBufferAccess.cpp: upstream's boykopovar#586/boykopovar#612.
  The 64-bit LDS atomics keep the full array (f27d6e5 no longer needed).
- SpirvMemoryInstructions.cpp: upstream's constant slot plus offset;
  astrobot's split-wave append/consume kept.
- GuestTextureResource.cpp, TextureTiling.cpp and their tests: upstream's
  boykopovar#490/boykopovar#503 (astrobot had no other change there).
- MaskedSelect.cpp test, ShaderMemory.cpp LDS test: upstream's.
- State.cpp: upstream's boykopovar#505 export count and boykopovar#469 null pixel program;
  astrobot's depth export rejection and depth target model kept.
- Pipeline.cpp: upstream's pipeline key; astrobot's depth attachment and
  blend check (a trailing unused attachment stays valid, as
  colorGapPipelineTests expects).
- Draw.cpp, Recorder.cpp, ShaderResources.cpp: astrobot's (renderPassKey
  with depth, moved sample functions, residency maintenance), which
  already hold the merged boykopovar#505/boykopovar#628/boykopovar#490 changes.
- ShaderInputState.cpp: both register sets.
- State.hpp: the duplicate exportIndex member from the auto-merge removed.
- CMakeLists.txt: astrobot's test list (a superset of upstream's).
- tests/Graphics.cpp: upstream's CompactedExportTests replaces astrobot's
  inline copy; tests/Recorder.cpp: upstream's viewPastLastMipTests added.
@adriadam10
adriadam10 deleted the fix/vop3-legacy-mods branch October 6, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants