fix(agc): prepare a rect-list draw's missing rectangle at draw from its prepared stages #1928

Merged
fisherjoey merged 2 commits from upstream-pr/1928 into main 2026-10-10 06:05:23 +00:00
fisherjoey commented 2026-10-09 00:16:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T00:16:15Z.


Closes #1927

What

A rect-list draw needs a prepared rectangle for its (front, vertex variant, fragment variant). Rectangles are built only when the title resolves the graphics ABI through sceAgcCreateInterpolantMapping. A fragment variant prepared at the draw (the null pixel program, or a shader deferred at registration) therefore has none, and the draw throws prepared rectangle artifacts are missing.

There are two commits:

  1. refactor(agc): look up a rect-list draw's rectangle through DrawRectangle moves the lookup into DrawRectangle(front, fragment, vertexId, fragmentId, target). Behaviour is unchanged.
  2. fix(agc): prepare a rect-list draw's missing rectangle at draw from its prepared stages: when the lookup misses, DrawRectangle logs it, calls ResolvePreparedGraphics(front, fragment, 17, target) and looks it up again. Any other failure still throws.

Tested

Linux (Nobara 44, GCC), RTX 5070 Ti, NVIDIA 595.91.07.

The new check in tests/execution/PreparedGraphics.cpp prepares a fragment variant that was never linked to the front through the ABI, then draws a rectangle with it through DrawRectangle.

ctest -R agc_driver_prepared_graphics
main 1be6f9f1 + commit 1 (lookup moved, no behaviour change) + the test fails: AGC driver: prepared rectangle artifacts are missing
this branch passes, logging Rect-list draw of shader ... has no rectangle for fragment shader ...; preparing it at draw

The test can't run on main without commit 1. The draw path has no function a test can call short of a full GPU draw, and the ctest suite has no harness for that. Commit 1 adds that function without changing behaviour, so the test builds and fails there because of the bug, not because it doesn't compile. I can squash the two commits if you prefer one.

The agc_driver_prepared_shaders* tests and pixel_ancillary also pass on the combined branch.

Stray, with #1902: without this change it aborts on the first rect-list draw that uses the null pixel program. With it, the log shows Rect-list draw of shader 0x200bbe0000 has no rectangle for fragment shader ...; preparing it at draw and the run continues to a later, unrelated error.

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
  • No notes, investigation .md files or images added to the repository
  • Generic behaviour, not specific to one title
  • Depends on: none to build or test. In a title it shows up once #1902 prepares the null pixel program at draw.
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4794342692 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T00:16:15Z. --- Closes #1927 ### What A rect-list draw needs a prepared rectangle for its (front, vertex variant, fragment variant). Rectangles are built only when the title resolves the graphics ABI through `sceAgcCreateInterpolantMapping`. A fragment variant prepared at the draw (the null pixel program, or a shader deferred at registration) therefore has none, and the draw throws `prepared rectangle artifacts are missing`. There are two commits: 1. `refactor(agc): look up a rect-list draw's rectangle through DrawRectangle` moves the lookup into `DrawRectangle(front, fragment, vertexId, fragmentId, target)`. Behaviour is unchanged. 2. `fix(agc): prepare a rect-list draw's missing rectangle at draw from its prepared stages`: when the lookup misses, `DrawRectangle` logs it, calls `ResolvePreparedGraphics(front, fragment, 17, target)` and looks it up again. Any other failure still throws. ### Tested Linux (Nobara 44, GCC), RTX 5070 Ti, NVIDIA 595.91.07. The new check in `tests/execution/PreparedGraphics.cpp` prepares a fragment variant that was never linked to the front through the ABI, then draws a rectangle with it through `DrawRectangle`. | | `ctest -R agc_driver_prepared_graphics` | |---|---| | `main` 1be6f9f1 + commit 1 (lookup moved, no behaviour change) + the test | fails: `AGC driver: prepared rectangle artifacts are missing` | | this branch | passes, logging `Rect-list draw of shader ... has no rectangle for fragment shader ...; preparing it at draw` | The test can't run on `main` without commit 1. The draw path has no function a test can call short of a full GPU draw, and the ctest suite has no harness for that. Commit 1 adds that function without changing behaviour, so the test builds and fails there because of the bug, not because it doesn't compile. I can squash the two commits if you prefer one. The `agc_driver_prepared_shaders*` tests and `pixel_ancillary` also pass on the combined branch. Stray, with #1902: without this change it aborts on the first rect-list draw that uses the null pixel program. With it, the log shows `Rect-list draw of shader 0x200bbe0000 has no rectangle for fragment shader ...; preparing it at draw` and the run continues to a later, unrelated error. ### 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 - [x] Unimplemented paths throw - [x] No notes, investigation `.md` files or images added to the repository - [x] Generic behaviour, not specific to one title - [x] Depends on: none to build or test. In a title it shows up once #1902 prepares the null pixel program at draw. - [x] AI-assisted: yes
klosixgaming-arch commented 2026-10-09 00:46:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-09T00:46:20Z.

Review: APPROVED


Small, correct, and the test strategy is the right one for a code path that otherwise can only be reached by a full GPU draw.

  • Commit 1 (move the lookup into DrawRectangle) is behaviour-preserving and gives a callable seam for the test — good reasoning, and the test genuinely fails on main+commit-1 and passes on this branch.
  • The fallback only fires on a lookup miss, calls ResolvePreparedGraphics, then re-looks-up; any other failure still throws. No silent stub, no guessing.
  • Interacts correctly with #1902 (null pixel program prepared at draw).

One note (non-blocking): the fallback hard-codes 17 as the primitiveType passed to ResolvePreparedGraphics. Everywhere else the primitive type comes from the decoded draw state. If a rect-list draw can legitimately be issued with a different primitive type, preparing with 17 may produce a rectangle that doesn't match. Please confirm rect-list draws are always type 17 (or pull the real value from the packet if not) — that's the only thing I'd want grounded before this is a long-term fix rather than a workaround.

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5464516480 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#pullrequestreview-5464516480). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-09T00:46:20Z. **Review:** APPROVED --- Small, correct, and the test strategy is the right one for a code path that otherwise can only be reached by a full GPU draw. - Commit 1 (move the lookup into `DrawRectangle`) is behaviour-preserving and gives a callable seam for the test — good reasoning, and the test genuinely fails on `main`+commit-1 and passes on this branch. - The fallback only fires on a lookup miss, calls `ResolvePreparedGraphics`, then re-looks-up; any other failure still throws. No silent stub, no guessing. - Interacts correctly with #1902 (null pixel program prepared at draw). One note (non-blocking): the fallback hard-codes `17` as the `primitiveType` passed to `ResolvePreparedGraphics`. Everywhere else the primitive type comes from the decoded draw state. If a rect-list draw can legitimately be issued with a different primitive type, preparing with `17` may produce a rectangle that doesn't match. Please confirm rect-list draws are always type `17` (or pull the real value from the packet if not) — that's the only thing I'd want grounded before this is a long-term fix rather than a workaround. Written with AI assistance.
fisherjoey commented 2026-10-09 02:01:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-09T02:01:07Z.


#1825 and #1732 change the same lines in Draw.cpp. Both call ResolvePreparedGraphics(..., 17u, ...) before the PreparedRectangle lookup, but only when the vertex program is unregistered (programs[0].snapshot->header.empty()). This PR covers a different trigger: the vertex program is registered and the fragment variant was prepared at the draw (the null pixel program from #1902, or a shader deferred by #1836).

So the changes don't duplicate each other, but they will conflict. Whichever lands first, I'm happy to rebase so both cases go through one helper (DrawRectangle here, which builds the rectangle when the lookup misses), or to drop that part if the other PR's version covers it once merged.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6072723577 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6072723577). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-09T02:01:07Z. --- #1825 and #1732 change the same lines in `Draw.cpp`. Both call `ResolvePreparedGraphics(..., 17u, ...)` before the `PreparedRectangle` lookup, but only when the vertex program is unregistered (`programs[0].snapshot->header.empty()`). This PR covers a different trigger: the vertex program is registered and the fragment variant was prepared at the draw (the null pixel program from #1902, or a shader deferred by #1836). So the changes don't duplicate each other, but they will conflict. Whichever lands first, I'm happy to rebase so both cases go through one helper (`DrawRectangle` here, which builds the rectangle when the lookup misses), or to drop that part if the other PR's version covers it once merged. AI-assisted: yes
MarcZX10 commented 2026-10-09 03:37:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:37:11Z.


I verified the primitive-type question against the current decoder: Graphics::DecodeState sets rectList only for primitive values 7 or 17. ResolvePreparedGraphics uses the value only to set rectangleRequested when it is either 7 or 17; rectangle generation does not distinguish them. So passing 17 from this fallback is equivalent for any draw that reached the rect-list path.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6073760576 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6073760576). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T03:37:11Z. --- I verified the primitive-type question against the current decoder: `Graphics::DecodeState` sets `rectList` only for primitive values 7 or 17. `ResolvePreparedGraphics` uses the value only to set `rectangleRequested` when it is either 7 or 17; rectangle generation does not distinguish them. So passing 17 from this fallback is equivalent for any draw that reached the rect-list path.
MarcZX10 commented 2026-10-09 03:49:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T03:49:16Z.

Review: APPROVED


Reviewed the full diff and current head. The helper move is behavior-preserving, the fallback only runs on a missing rectangle, and the execution test exercises the prepared-fragment case. I checked that primitive values 7 and 17 both enter the rect-list path and generate the same rectangle request. Linux and Windows checks and Conventions are green. The author has also documented the distinct overlapping triggers in #1732/#1825 and offered to rebase as needed.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5465514059 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#pullrequestreview-5465514059). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T03:49:16Z. **Review:** APPROVED --- Reviewed the full diff and current head. The helper move is behavior-preserving, the fallback only runs on a missing rectangle, and the execution test exercises the prepared-fragment case. I checked that primitive values 7 and 17 both enter the rect-list path and generate the same rectangle request. Linux and Windows checks and Conventions are green. The author has also documented the distinct overlapping triggers in #1732/#1825 and offered to rebase as needed.
Raghav314 commented 2026-10-09 07:44:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Raghav314 on 2026-10-09T07:44:41Z.


Tested this with Hades II (PPSA36082), together with a fix for the null program miss (the registration fix I described on #1902). The fallback kicks in once while the level loads, for the null fragment program, and the game goes on to gameplay without problems.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6076708722 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6076708722). Originally posted by [Raghav314](https://github.com/Raghav314) on 2026-10-09T07:44:41Z. --- Tested this with Hades II (PPSA36082), together with a fix for the null program miss (the registration fix I described on #1902). The fallback kicks in once while the level loads, for the null fragment program, and the game goes on to gameplay without problems.
XairRrR commented 2026-10-09 11:55:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-09T11:55:26Z.


Uncharted: Legacy of Thieves Collection (PPSA05684) stops here once its fragment variants are prepared at the draw (locally: the null pixel program and its own shaders, see #1902):

AGC driver: prepared rectangle artifacts are missing

I fixed it locally the same way (build the rectangle pair from the prepared stages at the draw and keep it with the snapshot) to reach the title's main menu. Separately, the fault buffer of the built control/evaluation shaders could collide with another stage's binding group; that fix is #2198. I have not run this branch itself with the title.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080349804 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6080349804). Originally posted by [XairRrR](https://github.com/XairRrR) on 2026-10-09T11:55:26Z. --- Uncharted: Legacy of Thieves Collection (PPSA05684) stops here once its fragment variants are prepared at the draw (locally: the null pixel program and its own shaders, see #1902): ``` AGC driver: prepared rectangle artifacts are missing ``` I fixed it locally the same way (build the rectangle pair from the prepared stages at the draw and keep it with the snapshot) to reach the title's main menu. Separately, the fault buffer of the built control/evaluation shaders could collide with another stage's binding group; that fix is #2198. I have not run this branch itself with the title.
EdouardSence commented 2026-10-09 12:31:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EdouardSence on 2026-10-09T12:31:37Z.


Two more titles hit the case this PR fixes, on Linux with an RX 9070 XT (RADV).

  • Ratchet & Clank: Rift Apart (PPSA01474), on main 43972e69 + #1673, #1339, #1836, #1837, #1893, #2105, #2184, #2226, #2219, #1902:
    • Without this PR, the run stops about 20 s in on prepared rectangle artifacts are missing.
    • With it, the log shows Rect-list draw of shader 0x116643b200 has no rectangle for fragment shader 0x7f33…1700; preparing it at draw four times. The fragment shader is the null pixel program that #1902 prepares at draw.
    • The run goes on to an unrelated stop (color views of several array slices are unsupported, #2102).
  • Astro Bot (PPSA21567) hits the same miss after #1902. I reported it on #1902 before I found this PR: the null pixel variant 66d was prepared at draw, with only (30a, 30b) and (30a, 30c) rectangles registered.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6080943420 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6080943420). Originally posted by [EdouardSence](https://github.com/EdouardSence) on 2026-10-09T12:31:37Z. --- Two more titles hit the case this PR fixes, on Linux with an RX 9070 XT (RADV). - **Ratchet & Clank: Rift Apart (PPSA01474)**, on `main` 43972e69 + #1673, #1339, #1836, #1837, #1893, #2105, #2184, #2226, #2219, #1902: - Without this PR, the run stops about 20 s in on `prepared rectangle artifacts are missing`. - With it, the log shows `Rect-list draw of shader 0x116643b200 has no rectangle for fragment shader 0x7f33…1700; preparing it at draw` four times. The fragment shader is the null pixel program that #1902 prepares at draw. - The run goes on to an unrelated stop (`color views of several array slices are unsupported`, #2102). - **Astro Bot (PPSA21567)** hits the same miss after #1902. I reported it on #1902 before I found this PR: the null pixel variant `66d` was prepared at draw, with only `(30a, 30b)` and `(30a, 30c)` rectangles registered. *Tested and written by Claude (AI assistant) on a contributor's machine.*
orbz22 commented 2026-10-09 12:44:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by orbz22 on 2026-10-09T12:44:50Z.


Astro's Playroom (PPSA01325) hits this on Windows with NVIDIA, right after #1902.

Setup: main 745b775e + #1836 + #1837 + #1395 (rebased locally) + #1902, plus a local workaround for vertex fetch exceeds descriptor record count (no PR yet).

  • Without this PR, a rect-list draw stops with AGC driver: prepared rectangle artifacts are missing.
  • With this PR (def0be10) it logs Rect-list draw of shader 0x400201900 has no rectangle for fragment shader 0x7ff9c095b700; preparing it at draw and the draw goes through.
  • The next stop is a compute shader reading through a null SRT pointer: compute shader 0x5001c6a00: AGC driver: guest memory is not readable at 0x28 (range 0x28+0x4). That is the #757-#759 stack.

Windows 11, RTX 3060 Laptop (NVIDIA 616.92), WinLibs GCC 15.2.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6081146665 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6081146665). Originally posted by [orbz22](https://github.com/orbz22) on 2026-10-09T12:44:50Z. --- Astro's Playroom (PPSA01325) hits this on Windows with NVIDIA, right after #1902. Setup: `main` 745b775e + #1836 + #1837 + #1395 (rebased locally) + #1902, plus a local workaround for `vertex fetch exceeds descriptor record count` (no PR yet). - Without this PR, a rect-list draw stops with `AGC driver: prepared rectangle artifacts are missing`. - With this PR (def0be10) it logs `Rect-list draw of shader 0x400201900 has no rectangle for fragment shader 0x7ff9c095b700; preparing it at draw` and the draw goes through. - The next stop is a compute shader reading through a null SRT pointer: `compute shader 0x5001c6a00: AGC driver: guest memory is not readable at 0x28 (range 0x28+0x4)`. That is the #757-#759 stack. Windows 11, RTX 3060 Laptop (NVIDIA 616.92), WinLibs GCC 15.2. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
NahuelGenchi commented 2026-10-09 14:47:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-09T14:47:32Z.


Tested with Sonic Origins (PPSA05324) on Linux, R9 380 (RADV). Its depth/stencil clears are rect-list draws without a pixel program, so they stopped at prepared rectangle artifacts are missing once #1902 prepared the null pixel variants. With this PR, the log shows three Rect-list draw of shader ... has no rectangle for fragment shader ...; preparing it at draw lines, the clears run, and the title presents its SEGA logo. Testing branch: main d70b8998 + #2022, #2219, #1902, #1837, #425 and #1544.

Bring-up thread: #2021

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6083265879 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6083265879). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-09T14:47:32Z. --- Tested with Sonic Origins (PPSA05324) on Linux, R9 380 (RADV). Its depth/stencil clears are rect-list draws without a pixel program, so they stopped at `prepared rectangle artifacts are missing` once #1902 prepared the null pixel variants. With this PR, the log shows three `Rect-list draw of shader ... has no rectangle for fragment shader ...; preparing it at draw` lines, the clears run, and the title presents its SEGA logo. Testing branch: `main` d70b8998 + #2022, #2219, #1902, #1837, #425 and #1544. Bring-up thread: #2021
tv7 commented 2026-10-10 01:51:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by tv7 on 2026-10-10T01:51:50Z.


Tested on Windows with Marvel's Wolverine (PPSA03671), after #1902.

Setup: Windows 11 Pro (10.0.26200), RTX 3070, GCC 15.2.0 UCRT (WinLibs), Release. This PR (def0be10) merged onto main 54f28f2d3 with #1836, #1893, #1709, #1837, #1940, #2022, #2219, #1902, and a local change that lets sceKernelSignalSema accept a count of 0. It merged without conflicts.

Without this PR: the first presentation fails with AGC driver: prepared rectangle artifacts are missing.

With this PR: the rect-list draws pass. The next stop is a compute shader deferred at registration: GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x00001140(GetBufferResource(ReadConst(GetSrtResource, Immediate), ..., probably #757's case.

Limits: one title, one run each way. No frame is presented yet.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6092384636 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6092384636). Originally posted by [tv7](https://github.com/tv7) on 2026-10-10T01:51:50Z. --- Tested on Windows with Marvel's Wolverine (PPSA03671), after #1902. **Setup:** Windows 11 Pro (10.0.26200), RTX 3070, GCC 15.2.0 UCRT (WinLibs), Release. This PR (def0be10) merged onto main 54f28f2d3 with #1836, #1893, #1709, #1837, #1940, #2022, #2219, #1902, and a local change that lets `sceKernelSignalSema` accept a count of 0. It merged without conflicts. **Without this PR:** the first presentation fails with `AGC driver: prepared rectangle artifacts are missing`. **With this PR:** the rect-list draws pass. The next stop is a compute shader deferred at registration: `GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x00001140(GetBufferResource(ReadConst(GetSrtResource, Immediate), ...`, probably #757's case. **Limits:** one title, one run each way. No frame is presented yet.
adriadam10 commented 2026-10-10 06:05:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:05:20Z.


Checked the lookup move is behaviour-preserving, the fallback only runs on a missing rectangle (any other failure still throws), and primitive types 7/17 take the same rect-list path. Build + ctest of libSceAgcDriver green (273/273, agc_driver_prepared_graphics passes), CI green on this head, and several title runs in the thread confirm it. Merging.

Note: #2261 touches the same lines in Draw.cpp; whichever lands second needs a rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094482643 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1928#issuecomment-6094482643). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:05:20Z. --- Checked the lookup move is behaviour-preserving, the fallback only runs on a missing rectangle (any other failure still throws), and primitive types 7/17 take the same rect-list path. Build + ctest of libSceAgcDriver green (273/273, `agc_driver_prepared_graphics` passes), CI green on this head, and several title runs in the thread confirm it. Merging. Note: #2261 touches the same lines in `Draw.cpp`; whichever lands second needs a rebase.
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!1928
No description provided.