Skip to content

feat(shader): implement legacy float multiply-add ops - #308

Merged
boykopovar merged 1 commit into
boykopovar:mainfrom
asimplestray:feat/shader-vop3-mad
Oct 2, 2026
Merged

boykopovar merged 1 commit into
boykopovar:mainfrom
asimplestray:feat/shader-vop3-mad

Conversation

@asimplestray

@asimplestray asimplestray commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

What

Implements 2 VOP3 opcodes:

  • V_MAD_LEGACY_F32 (0x140) reuses the FMA translation; V_MULLIT_F32 (0x150) reuses the multiply translation.
  • Encodings verified against LLVM's GFX10 disassembler tests.

Note: the integer multiply-add family from the original revision (V_MAD_I16/U16, V_MAD_I32_I16/U32_U16, V_MUL_LO_U16, V_ADD/SUB_NC_I32, V_ASHRREV_I64) has since landed in main via other work, so this PR keeps only the two remaining float ops.

Tested

Linux (GCC, BUILD_TESTING=ON, ANYPS5_ENABLE_SPIRV_TOOLS=OFF): full build, ctest 110/110 pass, including the new vector_mad_legacy test (decode opcode + family + ALU classification plus translation emitting the expected IR op for both encodings).

Checklist

  • Based on current main; no other open PR implements the same opcodes (checked open shader PRs)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (decoding unknown opcodes still throws)
  • 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 (none added)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

Progress report (313de1c → 20f12cc)

📈 GPU shader instructions: 59.78% (+0.17%, +2 implemented instructions)

✅ 2 implemented
Encoding Name
VOP3 V_MAD_LEGACY_F32
VOP3 V_MULLIT_F32

@adriadam10

Copy link
Copy Markdown
Collaborator

Heads-up on overlap: #257 (opened 2026-10-01) already implements v_add_nc_i32 / v_sub_nc_i32 (including clamp as signed saturation), v_mul_lo_u16, v_mad_u16, v_mad_i16, v_mad_u32_u16, v_mad_i32_i16 and v_ashrrev_i64. It has an execution test comparing every lane on RADV/lavapipe. One thing it caught: the u32_u16 / i32_i16 forms must not take the 16-bit destination select in applyNativeVop3I16TernarySelectors, or the result gets truncated to 16 bits. Worth checking here too.

On v_mad_legacy_f32, two semantic details that FPFma32 misses:

  • It is a legacy multiply: if either factor is ±0 the product is +0, even when the other is inf or NaN. I measured that for v_mul_legacy_f32 on an RDNA2 GPU, and it's the defining property of the legacy family.
  • It is a mad, not an fma: the product is rounded before the add, like v_mad_f32. fix(shader): keep fused multiply-adds fused and v_mad/v_mac_f32 rounded twice #263 adds an unfused FPMad32 for exactly that.

I had v_mad_legacy_f32 in an upcoming PR next to v_mul/mac_legacy_f32, and I've dropped it there since yours came first.

@asimplestray asimplestray changed the title feat(shader): implement VOP3 integer multiply-add family feat(shader): implement legacy float multiply-add ops Oct 2, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 2, 2026
@boykopovar
boykopovar merged commit 7d40a57 into boykopovar:main Oct 2, 2026
3 checks passed
oneandonlydean added a commit to oneandonlydean/AnyPS5 that referenced this pull request Oct 3, 2026
…oykopovar#304 boykopovar#305 boykopovar#306 boykopovar#322 boykopovar#409 boykopovar#416, boykopovar#276 boykopovar#277 boykopovar#275 boykopovar#307, shader ops boykopovar#226 boykopovar#255 boykopovar#260 boykopovar#280 boykopovar#308 boykopovar#309 boykopovar#311 boykopovar#318 boykopovar#320 boykopovar#324 boykopovar#326 boykopovar#379 boykopovar#384 boykopovar#399, boykopovar#261, kernel boykopovar#335 boykopovar#341 boykopovar#349 boykopovar#355, libs boykopovar#227 boykopovar#244 boykopovar#245 boykopovar#273 boykopovar#274 boykopovar#279 boykopovar#286 boykopovar#287 boykopovar#289 boykopovar#296 boykopovar#300 boykopovar#328 boykopovar#358 boykopovar#402) into astrobot

Where our PR merged in a revised form, main's version is taken; where
astrobot carries the same work plus later local commits, astrobot's code
stays and main's additions appear once.

Conflicts:
- AvPlayer (Export.cpp both libs, include/AvPlayer.hpp, src/Player.cpp,
  src/Source.cpp, AvPlayerLibrary.cmake, CMakeLists.txt, SceTypes.hpp,
  tests/GuestAvPlayer.cpp): main's boykopovar#307 (our reviewed squash, which carries
  9c8e7fd e9ea5c8 adcede3 fb4eeb9 953057c ac456ee). It links the
  shared ffmpeg-core target, so astrobot's second FFmpeg build goes:
  3rdparty/FFmpeg submodule, core/libs/FFmpeg.cmake and src/Exports.cpp.
- libScePngEnc: main's boykopovar#227 (supersedes OverkillLabs' encoder).
- libScePad Export.cpp: main's boykopovar#287 tilt correction (supersedes 49d45f5).
- libSceAudioPropagation Export.cpp: astrobot's object model, which
  defines every function boykopovar#289 declares as a stub.
- libSceSaveData.native Export.cpp: both (SaveDataHoldWrites and boykopovar#289's
  unknown exports).
- VideoOutDriver.cpp: astrobot's (2546bd1 counters around boykopovar#416's
  lastFlipVblank store, same value). tests/Flip.cpp: boykopovar#416's pacing test and
  boykopovar#417's after-GPU test both kept.
- boykopovar#278 files (DisplayFormat, VulkanDevice, GpuColorTransfer,
  ResidentPresent, agc CMakeLists): main's comment-free boykopovar#278 plus
  astrobot's P5 present-direct (b29728d), which removed DetileImage,
  ResidentPresent.hpp and the recorder-test hook; the resident present test
  stays its own executable.
- VulkanDevice.cpp/.hpp: astrobot's GDS, local memory probe, sample dumps
  and P5 code; boykopovar#303/boykopovar#409 comments as main has them; main's shader clock
  (boykopovar#324) and DepthSurface-free includes.
- RequestSerializer.cpp: version stays 8 (6 mesh passthrough, 7
  nonConstantImageOffsets, 8 astrobot's later field). boykopovar#303's auto-merged
  second write and read of nonConstantImageOffsets removed.
- SpirvEmitter.hpp, SpirvEmitterState.hpp, Recompiler.hpp/.cpp, StageIO.hpp,
  SpirvOptimizer.cpp, InstructionTranslator.cpp, ShaderReplay.cpp: local
  fields kept, boykopovar#303/boykopovar#305 comments as main has them.
- SpirvAluEmitterMath.cpp: v_readlane keeps the split-wave path and takes
  boykopovar#322's wrap at the wave size for the others.
- SpirvEmitter.cpp: astrobot's single-lane layout check.
- SpirvFlowEmitter.cpp: boykopovar#304 as merged (the second lane emits a shared
  value itself when the first lane defined nothing).
- SpirvImageEmitter.cpp: main's Offset operand placed before MinLod.
- boykopovar#304: main's WaveUniformValues (SpirvAnalysis.cpp) replaces astrobot's
  copy in SpirvWaveExchange.cpp.
- Recorder.hpp/.cpp, Draw.hpp, Graphics Draw.cpp, ShaderResources.cpp:
  astrobot's boykopovar#276/boykopovar#277 with its later snapshot work (per-use budgets,
  stale-snapshot refresh, profile counters, boykopovar#410, boykopovar#424, fan GS); boykopovar#409/boykopovar#306
  comments as main has them.
- PacketMemory.cpp: boykopovar#409 as merged plus astrobot's two opt-outs.
- tests: ShaderMemory.cpp takes boykopovar#303's and boykopovar#304's new tests; Recorder.cpp
  takes boykopovar#409's afterRecordedWorkTests and drops main's copies of the
  boykopovar#276/boykopovar#277 tests astrobot already has; Structurizer.cpp keeps boykopovar#413's case.

boykopovar#143 (NGG passthrough) stays as on astrobot: upstream did not touch its
files since the boykopovar#258 revert.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants