fix(recompiler): recognize plain no-carry draw offset adds #6919

Merged
yabanana merged 3 commits from upstream-pr/6919 into main 2026-10-19 13:39:56 +00:00
yabanana commented 2026-10-16 18:32:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by yabanana on 2026-10-16T18:32:45Z.


What

Recognize plain, single-word VOP2 v_add_nc_u32 additions of a draw-offset user SGPR to the vertex or instance index. The analyzer currently leaves these offsets unknown, so an otherwise eligible indexed indirect draw falls back to CPU processing. Reuse the existing offset analysis and its shared-register, prior-read and conflict checks.

This changes offset recognition, not arithmetic lowering. v_add_nc_u32 produces the unsigned sum without a carry output: AMD RDNA 2 ISA, section 12.7, VOP2 opcode 37 (ISA reference, PDF page 134). VOP3 and modified forms remain outside this fold.

Add decoded wave32/wave64 regression cases, encoded rejection cases for VOP3 saturation, SDWA, vector offsets, mismatched index registers, non-user scalar registers and subtraction, plus shared-offset and read-before-add controls. Extend the existing indexed indirect GPU test with a no-carry shader and exact vertex/instance-index readback, including an explicit execution marker.

Related to #5806. No captured title shader or game was tested, and this does not establish that the issue is resolved or claim a performance improvement.

Tested

  • Native Apple ARM64, macOS 27.2, Apple Clang 21: the new analyzer regression fails on the base and passes with the fix under AddressSanitizer and UndefinedBehaviorSanitizer.
  • Ubuntu 24.04 amd64, GCC 13.3, executed on an ARM64 host through QEMU 10.2.3 (-cpu max), using Mesa llvmpipe LLVM 20.1.2 (256 bits), Mesa 25.2.8. Software Vulkan was required and selected; the no-carry GPU case executed and exact readback matched.
  • Final-head CTest: 7/7 passed, none skipped: agc_embedded_vertex_fetch, agc_embedded_vertex_fetch_aliasing, agc_driver_draw_offset_indices, agc_driver_flip, agc_driver_flip_compute, agc_driver_address_space_teardown, and agc_driver_pipeline_optimized_readback_d32 (exact RGBA comparison before/after pipeline optimization). The indexed indirect test printed no-carry indexed indirect GPU readback checked.
  • python3 tools/check_conventions.py --base origin/main and git diff --check origin/main passed.

No physical GPU, Windows or title runtime was tested. Full upstream Linux/Windows builds remain subject to maintainer dispatch.

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 under Silent stubs in their library's technical debt file
  • 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
  • Unblocks: none
  • GPUs tested: Mesa llvmpipe LLVM 20.1.2 (256 bits), Mesa 25.2.8, Vulkan 1.4.318, Ubuntu 24.04 amd64 under QEMU 10.2.3; software GPU only
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4892684009 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6919). Originally posted by [yabanana](https://github.com/yabanana) on 2026-10-16T18:32:45Z. --- ### What Recognize plain, single-word VOP2 `v_add_nc_u32` additions of a draw-offset user SGPR to the vertex or instance index. The analyzer currently leaves these offsets unknown, so an otherwise eligible indexed indirect draw falls back to CPU processing. Reuse the existing offset analysis and its shared-register, prior-read and conflict checks. This changes offset recognition, not arithmetic lowering. `v_add_nc_u32` produces the unsigned sum without a carry output: AMD RDNA 2 ISA, section 12.7, VOP2 opcode 37 ([ISA reference](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf), PDF page 134). VOP3 and modified forms remain outside this fold. Add decoded wave32/wave64 regression cases, encoded rejection cases for VOP3 saturation, SDWA, vector offsets, mismatched index registers, non-user scalar registers and subtraction, plus shared-offset and read-before-add controls. Extend the existing indexed indirect GPU test with a no-carry shader and exact vertex/instance-index readback, including an explicit execution marker. Related to #5806. No captured title shader or game was tested, and this does not establish that the issue is resolved or claim a performance improvement. ### Tested - Native Apple ARM64, macOS 27.2, Apple Clang 21: the new analyzer regression fails on the base and passes with the fix under AddressSanitizer and UndefinedBehaviorSanitizer. - Ubuntu 24.04 amd64, GCC 13.3, executed on an ARM64 host through QEMU 10.2.3 (`-cpu max`), using Mesa llvmpipe LLVM 20.1.2 (256 bits), Mesa 25.2.8. Software Vulkan was required and selected; the no-carry GPU case executed and exact readback matched. - Final-head CTest: **7/7 passed**, none skipped: `agc_embedded_vertex_fetch`, `agc_embedded_vertex_fetch_aliasing`, `agc_driver_draw_offset_indices`, `agc_driver_flip`, `agc_driver_flip_compute`, `agc_driver_address_space_teardown`, and `agc_driver_pipeline_optimized_readback_d32` (exact RGBA comparison before/after pipeline optimization). The indexed indirect test printed `no-carry indexed indirect GPU readback checked`. - `python3 tools/check_conventions.py --base origin/main` and `git diff --check origin/main` passed. No physical GPU, Windows or title runtime was tested. Full upstream Linux/Windows builds remain subject to maintainer dispatch. ### Checklist - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Unblocks: none - [x] GPUs tested: Mesa llvmpipe LLVM 20.1.2 (256 bits), Mesa 25.2.8, Vulkan 1.4.318, Ubuntu 24.04 amd64 under QEMU 10.2.3; software GPU only - [x] AI-assisted: yes
keravyn-ops commented 2026-10-17 10:52:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T10:52:32Z.


AMD / Windows run of this PR at c1745992d: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.

Test suite only, no title run. Every ctest entry built from the test targets this PR changes passes (2):

  • agc_driver_draw_offset_indices (0.69 s): draw offset index tests passed
  • agc_embedded_vertex_fetch (0.07 s)

AI-assisted: yes (runs made on the device above).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6233039808 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6919#issuecomment-6233039808). Originally posted by [keravyn-ops](https://github.com/keravyn-ops) on 2026-10-17T10:52:32Z. --- AMD / Windows run of this PR at c1745992d: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release. Test suite only, no title run. Every ctest entry built from the test targets this PR changes passes (2): - `agc_driver_draw_offset_indices` (0.69 s): `draw offset index tests passed` - `agc_embedded_vertex_fetch` (0.07 s) AI-assisted: yes (runs made on the device above).
jotitadev commented 2026-10-17 13:35:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-17T13:35:44Z.

Review: COMMENTED


A run on a hardware GPU, since the description has only llvmpipe under QEMU.

Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release, BUILD_TESTING=ON. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged onto main 12a71f3f5 (clean). ANYPS5_NO_SHADER_CACHE=1, -j1 --timeout 30.

Run RTX 3070 lavapipe
agc_driver_draw_offset_indices, agc_embedded_vertex_fetch, agc_embedded_vertex_fetch_aliasing, agc_driver_pipeline_optimized_readback_d32 pass 3/3 pass
same, with EmbeddedVertexFetch.cpp from main agc_driver_draw_offset_indices fails: the fetch adds of s16 and s17 were not folded into the draw (vertex -1, instance -1); agc_embedded_vertex_fetch fails (no-carry offsets: loads=1 vertex=-1 instance=-1, wave32 and wave64) same failures

The no-carry GPU case runs on the 3070 and is not skipped. With ctest -V the record is classified to the GPU, all six vertex/instance pairs read back as expected (for example vertex 0 instance 0: after the fetch adds 702 59455; expected 702 59455), and the test prints no-carry indexed indirect GPU readback checked. Same output on lavapipe.

Not run: Windows, AMD, any title.

GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), Ubuntu 26.04

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5557980427 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6919#pullrequestreview-5557980427). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-17T13:35:44Z. **Review:** COMMENTED --- A run on a hardware GPU, since the description has only llvmpipe under QEMU. **Machine:** Ubuntu 26.04, i7-8700, GCC 15.2, Release, `BUILD_TESTING=ON`. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged onto `main` `12a71f3f5` (clean). `ANYPS5_NO_SHADER_CACHE=1`, `-j1 --timeout 30`. | Run | RTX 3070 | lavapipe | |---|---|---| | `agc_driver_draw_offset_indices`, `agc_embedded_vertex_fetch`, `agc_embedded_vertex_fetch_aliasing`, `agc_driver_pipeline_optimized_readback_d32` | pass 3/3 | pass | | same, with `EmbeddedVertexFetch.cpp` from `main` | `agc_driver_draw_offset_indices` fails: `the fetch adds of s16 and s17 were not folded into the draw (vertex -1, instance -1)`; `agc_embedded_vertex_fetch` fails (`no-carry offsets: loads=1 vertex=-1 instance=-1`, wave32 and wave64) | same failures | The no-carry GPU case runs on the 3070 and is not skipped. With `ctest -V` the record is `classified to the GPU`, all six vertex/instance pairs read back as expected (for example `vertex 0 instance 0: after the fetch adds 702 59455; expected 702 59455`), and the test prints `no-carry indexed indirect GPU readback checked`. Same output on lavapipe. Not run: Windows, AMD, any title. GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02) and lavapipe (Mesa 26.0.3), Ubuntu 26.04 Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
github-actions[bot] commented 2026-10-18 16:27:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T16:27:15Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7591 core/shader/recompiler/Translation/src/EmbeddedVertexFetch.cpp L359
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6252282254 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6919#issuecomment-6252282254). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T16:27:15Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7591](https://www.github.com/boykopovar/AnyPS5/pull/7591) | `core/shader/recompiler/Translation/src/EmbeddedVertexFetch.cpp` [L359](https://github.com/boykopovar/AnyPS5/blob/39ff29696008eed0f94b3f2bb1cd65b0837cb161/core/shader/recompiler/Translation/src/EmbeddedVertexFetch.cpp#L359) | | |
adriadam10 commented 2026-10-19 13:41:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T13:41:12Z.


Checked the v_add_nc_u32 encodings in the new tests (VOP2 opcode 37, vdst/vsrc1/src0 fields), that carryObserved has nothing to observe for a carry-less add, and that VOP3/SDWA/vector-offset/mismatched-index/non-user-SGPR/subtraction forms stay rejected. Also covered by independent RTX 3070 and Radeon 780M runs in the thread. Merged.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6268634671 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6919#issuecomment-6268634671). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T13:41:12Z. --- Checked the `v_add_nc_u32` encodings in the new tests (VOP2 opcode 37, vdst/vsrc1/src0 fields), that `carryObserved` has nothing to observe for a carry-less add, and that VOP3/SDWA/vector-offset/mismatched-index/non-user-SGPR/subtraction forms stay rejected. Also covered by independent RTX 3070 and Radeon 780M runs in the thread. Merged.
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!6919
No description provided.