Skip to content

feat(shader): accept every SDWA selector on VOP2 integer ops - #509

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/sdwa-vop2-integer
Oct 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:feat/sdwa-vop2-integer

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

VOP2 SDWA on integer ops threw for most selector combinations:

  • v_min_i32, v_max_i32, v_sub_co_ci_u32, v_subrev_co_ci_u32 had no SDWA rule, so any non-DWORD selector threw VOP2 SDWA modifier is not supported for opcode.
  • On v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}, v_max_u32, v_lshrrev_b32, v_ashrrev_i32, v_lshlrev_b32, v_add_co_ci_u32 and v_subrev_nc_u32, any dst_sel other than DWORD threw. On v_and/or/xor/xnor_b32, byte dst_sel threw.

All of them now take every src0_sel/src1_sel (with sext) and every dst_sel with UNUSED_PAD, UNUSED_SEXT or UNUSED_PRESERVE, like v_add_nc_u32 and v_min_u32 already did. The five integer profiles in the decoder are merged into one. The translator needed no change: these ops already read their sources through applyBitSourceModifiers and write through writeRawU32, which apply the selectors. On the carry ops, the carry is computed from the selected 32-bit operands. Only the VGPR write depends on dst_sel.

clamp on these ops and the reserved dst_unused value 3 still throw.

Behaviour measured on HW (RDNA2, gfx1035)

I ran the 13 forms in the test (all 13 ops, with byte and word selectors, sext on either source, and all three dst_unused modes, plus the carry-out of the three carry ops) on 2048 rows of edge words and random values. The Python model matches all 32768 results. The model zero- or sign-extends the selected source field, computes the 32-bit op, then writes the destination field: zero the rest, sign-extend upward with the lower bits zero, or keep the rest.

Tested

New execution test agc_driver_sdwa_integer_selectors_tests: 32 rows with expected values from the hardware (the model matches every cell). Rows are picked so each op gets both signs of each selected source, both values of the carry and the top bit of the written field. For min/max both comparison outcomes are covered, and for shifts the counts 0, 1-15 and 16-31.

It passes on RADV and lavapipe. It fails without each part of the change: no rule for v_min_i32, no rule for v_sub_co_ci_u32 and a DWORD-only destination for the integer profile all throw again, and dropping sext on the sources gives wrong values (4 mutations). The full Release ctest passes except agc_driver_pixel_helper_lanes, which also fails on main on local RADV.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks, checked against the RDNA2 ISA SDWA description: the source field is extracted (sign-extended with sext), the op runs at 32 bits, and dst_sel/dst_unused place the low bits of the result. The translator already reads these ops through applyBitSourceModifiers and writes through writeRawU32, so the decoder change is all that was missing, and forms main already accepted decode the same way. I disassembled the test with llvm-mc and wrote my own model of it; it matches all 512 expected values, including the carry-outs. The new test fails on main and the full ctest passes with it on my machine. Ready to merge from my side; I'll run it through my PPSA21564 check before merging, together with #510.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Gated on PPSA21564 with #510 on top: no visual or FPS change.

@oneandonlydean
oneandonlydean merged commit 070ed19 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 feat/sdwa-vop2-integer 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* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants