feat(shader): implement v_qsad_pk_u16_u8, v_mqsad_pk_u16_u8 and v_mqsad_u32_u8 #437

Merged
adriadam10 merged 2 commits from upstream-pr/437 into main 2026-10-04 06:41:54 +00:00
adriadam10 commented 2026-10-03 07:11:23 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-03T07:11:23Z.


What

v_qsad_pk_u16_u8 (VOP3 0x172), v_mqsad_pk_u16_u8 (0x173) and v_mqsad_u32_u8 (0x175) threw "VOP3 opcode is not
implemented". Found by the ISA coverage sweep.

  • All three slide a 4-byte window over the 64-bit src0 (window k = src0 >> 8k, k = 0..3) and compute a byte SAD
    against src1. The mqsad forms skip bytes where the src1 (reference) byte is 0, like v_msad_u8.
  • _pk_u16_u8: each SAD is added to the matching 16-bit half of the 64-bit src2 and packed into a 64-bit result.
    mqsad_u32_u8: each SAD is added to the matching dword of the 128-bit src2, 128-bit result.
  • Measured on RDNA2 hardware: the sums wrap (16-bit and 32-bit), no saturation, no carry into the next field.
  • The byte-SAD loop of subwordSad moved to a helper (byteSad) shared by the existing SAD ops and the new ones.

Tested

  • New execution test Vop3QuadSad (32 lanes, expected values captured on an RDNA2 GPU, Radeon 660M): the three ops
    with VGPR accumulators, qsad with an inline 0 accumulator, and accumulators chosen to wrap. A Python model of the
    semantics above matched all 512 measured values before the C++ was written.
  • Fails on main ("VOP3 opcode is not implemented"); passes on Linux with RADV and lavapipe.
  • Negative checks, each fails the test: no window shift ("qsad lo"), no 16-bit wrap ("qsad lo"), upper half of the
    128-bit accumulator not offset ("mqsad_u32 2"), mqsad_pk without the mask ("mqsad_pk lo").
  • Full Release build + ctest: 128/129. The failure is agc_driver_pixel_helper_lanes (wave64 case) on this
    machine's RADV, and it fails the same way on main without this change.

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:4724813033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/437). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-03T07:11:23Z. --- ### What `v_qsad_pk_u16_u8` (VOP3 0x172), `v_mqsad_pk_u16_u8` (0x173) and `v_mqsad_u32_u8` (0x175) threw "VOP3 opcode is not implemented". Found by the ISA coverage sweep. - All three slide a 4-byte window over the 64-bit `src0` (window k = `src0 >> 8k`, k = 0..3) and compute a byte SAD against `src1`. The `mqsad` forms skip bytes where the `src1` (reference) byte is 0, like `v_msad_u8`. - `_pk_u16_u8`: each SAD is added to the matching 16-bit half of the 64-bit `src2` and packed into a 64-bit result. `mqsad_u32_u8`: each SAD is added to the matching dword of the 128-bit `src2`, 128-bit result. - Measured on RDNA2 hardware: the sums wrap (16-bit and 32-bit), no saturation, no carry into the next field. - The byte-SAD loop of `subwordSad` moved to a helper (`byteSad`) shared by the existing SAD ops and the new ones. ### Tested - New execution test `Vop3QuadSad` (32 lanes, expected values captured on an RDNA2 GPU, Radeon 660M): the three ops with VGPR accumulators, `qsad` with an inline 0 accumulator, and accumulators chosen to wrap. A Python model of the semantics above matched all 512 measured values before the C++ was written. - Fails on `main` ("VOP3 opcode is not implemented"); passes on Linux with RADV and lavapipe. - Negative checks, each fails the test: no window shift ("qsad lo"), no 16-bit wrap ("qsad lo"), upper half of the 128-bit accumulator not offset ("mqsad_u32 2"), `mqsad_pk` without the mask ("mqsad_pk lo"). - Full Release build + `ctest`: 128/129. The failure is `agc_driver_pixel_helper_lanes` (wave64 case) on this machine's RADV, and it fails the same way on `main` without this change. ### 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
github-actions[bot] commented 2026-10-03 07:11:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-03T07:11:45Z.


Progress report (870bdd8 → 01bae4d)

📈 GPU shader instructions: 73.41% (+0.25%, +3 implemented instructions)

✅ 3 implemented
Encoding Name
VOP3 V_MQSAD_PK_U16_U8
VOP3 V_MQSAD_U32_U8
VOP3 V_QSAD_PK_U16_U8
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5966654257 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/437#issuecomment-5966654257). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-03T07:11:45Z. --- <!-- progress-report --> ### Progress report (870bdd8 → 01bae4d) 📈 **GPU shader instructions**: 73.41% (+0.25%, +3 implemented instructions) <details> <summary>✅ 3 implemented</summary> | Encoding | Name | | - | - | | VOP3 | `V_MQSAD_PK_U16_U8` | | VOP3 | `V_MQSAD_U32_U8` | | VOP3 | `V_QSAD_PK_U16_U8` | </details>
oneandonlydean commented 2026-10-04 05:44:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T05:44:50Z.


The quad SAD maths checks out for me, including the per-field wrap. One small thing: embeddedFetchDstSize in EmbeddedVertexFetch.cpp still reports one register for these, but v_qsad_pk_u16_u8/v_mqsad_pk_u16_u8 write two and v_mqsad_u32_u8 writes four. The vertex fetch analysis then only clears the first register's tracked lanes, so a vertex shader that reuses v[d+1..] after one of these could keep a stale fetch. #435 adds its op to the same function; could you add these three the same way? Then it's ready from my side.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977034000 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/437#issuecomment-5977034000). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T05:44:50Z. --- The quad SAD maths checks out for me, including the per-field wrap. One small thing: `embeddedFetchDstSize` in EmbeddedVertexFetch.cpp still reports one register for these, but `v_qsad_pk_u16_u8`/`v_mqsad_pk_u16_u8` write two and `v_mqsad_u32_u8` writes four. The vertex fetch analysis then only clears the first register's tracked lanes, so a vertex shader that reuses v[d+1..] after one of these could keep a stale fetch. #435 adds its op to the same function; could you add these three the same way? Then it's ready from my side.
adriadam10 commented 2026-10-04 06:23:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-04T06:23:42Z.


Good catch, thanks. embeddedFetchDstSize is now a switch: v_qsad_pk_u16_u8 and v_mqsad_pk_u16_u8 report 2 registers next to v_mad_u64_u32, and v_mqsad_u32_u8 reports 4. #435 changes the same line, so whichever lands second needs a one-line rebase (I'll handle it on #435). Rebased onto main; agc_driver_vop3_quad_sad passes on RADV and lavapipe, and agc_driver_graphics passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977283621 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/437#issuecomment-5977283621). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-04T06:23:42Z. --- Good catch, thanks. `embeddedFetchDstSize` is now a switch: `v_qsad_pk_u16_u8` and `v_mqsad_pk_u16_u8` report 2 registers next to `v_mad_u64_u32`, and `v_mqsad_u32_u8` reports 4. #435 changes the same line, so whichever lands second needs a one-line rebase (I'll handle it on #435). Rebased onto main; `agc_driver_vop3_quad_sad` passes on RADV and lavapipe, and `agc_driver_graphics` passes.
oneandonlydean commented 2026-10-04 06:29:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T06:29:22Z.


Thanks for the quick update, that covers it. I'll test it here and merge once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5977319694 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/437#issuecomment-5977319694). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-04T06:29:22Z. --- Thanks for the quick update, that covers it. I'll test it here and merge once CI is green.
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!437
No description provided.