fix(agc): honour primitive restart in mesh-path triangle strips #2757

Merged
TheAggie merged 1 commit from upstream-pr/2757 into main 2026-10-10 22:46:33 +00:00
TheAggie commented 2026-10-10 13:07:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by TheAggie on 2026-10-10T13:07:20Z.


What

A geometry (NGG) triangle-strip draw on the mesh path ignored primitive restart. The mesh prologue gives every primitive the next index positions and never checks for the restart index. So a triangle spanning a restart fetched vertex 0xFFFF and was drawn to wherever that read landed. The strip parity also never reset at a restart: after an odd-length strip, every following triangle's winding flipped, and face culling dropped it.

#1968 already leaves the restart index out of a draw's vertex range. This PR handles the strips themselves:

  • For an indexed strip draw on the mesh path with restart enabled and the restart index present, the draw records each index position's strip start: one past the last restart at or before it. The table is built from the index bytes the draw already reads (its copy, or the guest memory an in-place import reads). It goes into the mesh argument buffer after the arguments, and bit 8 of draw word 3 flags it. Direct draws get an argument buffer for it too.
  • A new IR op, MeshRestartStart, reads the table at a position (clamped to its length).
  • In the mesh prologue, a primitive reads the strip start of its last vertex. If that start lies past the primitive's first vertex, the primitive spans a restart and its three vertex offsets collapse to one (a degenerate triangle). Otherwise its parity counts from its strip's start, or from the draw's first index when no restart came before.
  • The restart vertex itself fetches vertex 0 instead of 0xFFFF.

Fans keep their existing rule (primitive restart in a triangle fan geometry draw is unsupported); lists are unchanged.

Found running RetroArch's Dolphin core (PPSA99169) through RADV: GameCube quads arrive as four-index strips separated by restarts, and drew as streaks to the screen origin.

Tested

Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti.

  • New GPU test in agc_driver_mesh. It draws quads as four-index strips, each followed by a restart, with front faces culled, using 16- and 32-bit indices plus an indirect draw that starts mid-buffer. Every quad must render whole and the gaps between them must stay clear. With the table flag turned off it fails: 16-bit triangle strips with restarts: a triangle crossed the restart after quad 0.
  • Rebased onto main cf8b129e2. Full suite: 551 of 554 pass, 1 skipped. The two failures, agc_driver_prepared_shaders_debug_failure and guest_memory, fail the same way on clean main cf8b129e2 on this machine. It was run from the generated CTestTestfile.cmake commands because antivirus blocks ctest.exe on this machine.
  • tools/check_conventions.py passes.
  • RetroArch with the Dolphin core (GameCube 240p Test Suite) drew its menu without the streaks, on a local branch that also carries other unmerged changes Dolphin needs. That was before this rebase onto main, and RetroArch can't reach Dolphin on main alone.

Not tested on AMD, Intel, Linux or macOS.

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

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4811422544 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2757). Originally posted by [TheAggie](https://github.com/TheAggie) on 2026-10-10T13:07:20Z. --- ### What A geometry (NGG) triangle-strip draw on the mesh path ignored primitive restart. The mesh prologue gives every primitive the next index positions and never checks for the restart index. So a triangle spanning a restart fetched vertex 0xFFFF and was drawn to wherever that read landed. The strip parity also never reset at a restart: after an odd-length strip, every following triangle's winding flipped, and face culling dropped it. #1968 already leaves the restart index out of a draw's vertex range. This PR handles the strips themselves: - For an indexed strip draw on the mesh path with restart enabled and the restart index present, the draw records each index position's strip start: one past the last restart at or before it. The table is built from the index bytes the draw already reads (its copy, or the guest memory an in-place import reads). It goes into the mesh argument buffer after the arguments, and bit 8 of draw word 3 flags it. Direct draws get an argument buffer for it too. - A new IR op, `MeshRestartStart`, reads the table at a position (clamped to its length). - In the mesh prologue, a primitive reads the strip start of its last vertex. If that start lies past the primitive's first vertex, the primitive spans a restart and its three vertex offsets collapse to one (a degenerate triangle). Otherwise its parity counts from its strip's start, or from the draw's first index when no restart came before. - The restart vertex itself fetches vertex 0 instead of 0xFFFF. Fans keep their existing rule (`primitive restart in a triangle fan geometry draw is unsupported`); lists are unchanged. Found running RetroArch's Dolphin core (PPSA99169) through RADV: GameCube quads arrive as four-index strips separated by restarts, and drew as streaks to the screen origin. ### Tested Windows 11 Pro (26200), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release, NVIDIA GeForce RTX 5070 Ti. - New GPU test in `agc_driver_mesh`. It draws quads as four-index strips, each followed by a restart, with front faces culled, using 16- and 32-bit indices plus an indirect draw that starts mid-buffer. Every quad must render whole and the gaps between them must stay clear. With the table flag turned off it fails: `16-bit triangle strips with restarts: a triangle crossed the restart after quad 0`. - Rebased onto `main` cf8b129e2. Full suite: 551 of 554 pass, 1 skipped. The two failures, `agc_driver_prepared_shaders_debug_failure` and `guest_memory`, fail the same way on clean `main` cf8b129e2 on this machine. It was run from the generated `CTestTestfile.cmake` commands because antivirus blocks `ctest.exe` on this machine. - `tools/check_conventions.py` passes. - RetroArch with the Dolphin core (GameCube 240p Test Suite) drew its menu without the streaks, on a local branch that also carries other unmerged changes Dolphin needs. That was before this rebase onto `main`, and RetroArch can't reach Dolphin on `main` alone. Not tested on AMD, Intel, Linux or macOS. ### 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 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 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Silverash-i8 commented 2026-10-10 16:31:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Silverash-i8 on 2026-10-10T16:31:37Z.


Native Windows run, on NVIDIA and Intel, in case it helps since this was found on RADV.

Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release. RTX 5060 Laptop GPU (32.0.16.1742) and an Arrow Lake iGPU (Core Ultra 9 275HX, 32.0.101.8991) in the same machine. 8c06af0a cherry-picked onto main 57f96fd2 without conflicts. Intel mesh draws render nothing on main (#2815), so I added that fix (377829ec) on top to be able to run the mesh test there at all; it doesn't change anything on NVIDIA, where mesh stages run at 32 lanes anyway. The iGPU runs use APS5_NO_PIPELINE_LTO=1 to keep the #2777 race out.

  • agc_driver_mesh, including the new 16-bit, 32-bit, indirect and front-culled strips with restarts: passes 3/3 on both GPUs.
  • Full ctest (--parallel 6): 709/709 on the RTX 5060. On the iGPU the only failures are the five that fail on main and have their own fixes (f64_fma_subnormals, fp16_overflow, vop1_float_unary, vopc_compare in #2114 and #2822, lds_beyond_device_limit in #2805).

AI-assisted (Claude Code); the numbers above are from runs on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6099722146 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2757#issuecomment-6099722146). Originally posted by [Silverash-i8](https://github.com/Silverash-i8) on 2026-10-10T16:31:37Z. --- Native Windows run, on NVIDIA and Intel, in case it helps since this was found on RADV. Windows 11 Home (26200), WinLibs GCC 15.2.0 r7, Release. RTX 5060 Laptop GPU (32.0.16.1742) and an Arrow Lake iGPU (Core Ultra 9 275HX, 32.0.101.8991) in the same machine. 8c06af0a cherry-picked onto `main` 57f96fd2 without conflicts. Intel mesh draws render nothing on `main` (#2815), so I added that fix (377829ec) on top to be able to run the mesh test there at all; it doesn't change anything on NVIDIA, where mesh stages run at 32 lanes anyway. The iGPU runs use `APS5_NO_PIPELINE_LTO=1` to keep the #2777 race out. - `agc_driver_mesh`, including the new 16-bit, 32-bit, indirect and front-culled strips with restarts: passes 3/3 on both GPUs. - Full ctest (`--parallel 6`): 709/709 on the RTX 5060. On the iGPU the only failures are the five that fail on `main` and have their own fixes (`f64_fma_subnormals`, `fp16_overflow`, `vop1_float_unary`, `vopc_compare` in #2114 and #2822, `lds_beyond_device_limit` in #2805). AI-assisted (Claude Code); the numbers above are from runs on this machine.
adriadam10 commented 2026-10-10 22:46:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:46:30Z.


Checked on Linux (RADV): agc_driver_mesh passes on the PR merged onto current main, and fails with the non-test changes reverted. The restart table, the new MeshRestartStart op and the prologue changes are consistent with the draw path (direct, in-place import and indirect). No conflict with the merged #2253. Also confirmed by @Silverash-i8 on Windows (RTX 5060 and Intel iGPU); merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6102998145 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2757#issuecomment-6102998145). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T22:46:30Z. --- Checked on Linux (RADV): `agc_driver_mesh` passes on the PR merged onto current `main`, and fails with the non-test changes reverted. The restart table, the new `MeshRestartStart` op and the prologue changes are consistent with the draw path (direct, in-place import and indirect). No conflict with the merged #2253. Also confirmed by @Silverash-i8 on Windows (RTX 5060 and Intel iGPU); merging.
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!2757
No description provided.