fix(agc): resolve indexed indirect draws on a queue that never set INDEX_BUFFER_SIZE #7679

Closed
spiff637 wants to merge 4 commits from upstream-pr/7679 into main
spiff637 commented 2026-10-18 22:12:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by spiff637 on 2026-10-18T22:12:04Z.


What

An indexed indirect draw (DRAW_INDEX_INDIRECT 0x25, DRAW_INDEX_INDIRECT_MULTI 0x38) on a queue that has not received INDEX_BUFFER_SIZE (0x13) or INDEX_ATTRIBUTES_INDIRECT (0x91) since its last reset threw INDEX_BUFFER_SIZE has not been set.

Marvel's Spider-Man 2 (PPSA08338) never emits either packet. Probing every 0x13 and every suspend-point queue reset over a whole run found none, so no written size is being lost. Per draw it writes VGT_INDEX_TYPE (uconfig 0x243 = 0x400, 16-bit indices) and INDEX_BASE, then issues DRAW_INDEX_INDIRECT_MULTI. It stopped about 110–194 s in, on both a 2026-10-13 base (84b0d2f24) and current main.

The change:

  • QueueState::indexBufferSize becomes std::optional<std::uint32_t>. A size written by 0x13 or by a 0x91 record behaves as before. An explicit 0 still throws, now as INDEX_BUFFER_SIZE is zero.
  • When the size was never written, resolveIndirectDraw marks the draw indexLimitKnown = false and keeps the base and alignment checks.
  • ClassifyIndirectDraw sends such a draw to the CPU record path (new path IndexLimitUnknown, profiler name "index limit unknown"). The mesh GPU-side case goes there too, so the GPU path's whole-range check and copy is never reached without a limit.
  • On the record path, each record's firstIndex/indexCount range skips the clamp against the declared limit. Instead it must not overflow, and it goes through #6606's per-record readability check. Reads stay bounded by min(count at countAddress, packet count) records; nothing beyond a record's own range is read.
  • What still throws: an unreadable active record, address overflow, a null or misaligned base, an explicit size of 0, and the existing type checks.
  • The assumption is recorded in docs/dev/debt/libSceAgcDriver.md. The console's initial INDEX_BUFFER_SIZE, and whether the DRAW_INDEX_2/DRAW_INDEX_OFFSET_2 MAX_SIZE sets it, are not measured.

The branch is #6606's head (925f9a84b) merged with main (0d1c299a9), plus one commit. Until #6606 is merged, the diff also shows its commits.

Tested

  • Windows 11 Enterprise 10.0.26200, NVIDIA GeForce RTX 3080, driver 617.42.
  • tests/Pm4.cpp: 0x25 and 0x38 without 0x13 resolve with an unknown limit; an explicit 0x13 of 0 still throws; a written size keeps a known limit.
  • SparseIndirectIndices: three new registrations.
    • agc_driver_sparse_indirect_indices_no_size sends 0x38 with no 0x13 and matches the reference triangle.
    • ..._no_size_unreadable and ..._no_size_unreadable_record check that an unreadable active record still throws.
  • Restoring the old throw in resolveIndirectDraw makes agc_driver_pm4 and the three no_size tests fail. Disabling only the IndexLimitUnknown classification makes the three no_size tests fail.
  • ctest -R ^agc_: 732 of 733 pass, 3 skipped. agc_driver_bda_device fails identically on main on this machine (vkWaitForFences graphics: Vulkan result -4).
  • tools/check_conventions.py --base origin/main and tools/check_test_registration.py build pass.
  • Marvel's Spider-Man 2 (PPSA08338):
    • Built on main with #7505 and #6606 plus this change, the INDEX_BUFFER_SIZE abort is gone.
    • The title then stops at 155 s on a different site, GetImageResource dword 0 is not a valid runtime value (a record → pointer → V# → T# chain, #6191).

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: #6606
  • Fixes: none
  • Unblocks: PPSA08338 (no Game bring-up discussion yet)
  • GPUs tested: NVIDIA GeForce RTX 3080, driver 617.42, Windows 11 Enterprise 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

https://claude.ai/code/session_01HAtTu2pw6GTkMNwsjBDatU

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4913279818 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7679). Originally posted by [spiff637](https://github.com/spiff637) on 2026-10-18T22:12:04Z. --- ### What An indexed indirect draw (`DRAW_INDEX_INDIRECT` 0x25, `DRAW_INDEX_INDIRECT_MULTI` 0x38) on a queue that has not received `INDEX_BUFFER_SIZE` (0x13) or `INDEX_ATTRIBUTES_INDIRECT` (0x91) since its last reset threw `INDEX_BUFFER_SIZE has not been set`. Marvel's Spider-Man 2 (PPSA08338) never emits either packet. Probing every 0x13 and every suspend-point queue reset over a whole run found none, so no written size is being lost. Per draw it writes `VGT_INDEX_TYPE` (uconfig 0x243 = 0x400, 16-bit indices) and `INDEX_BASE`, then issues `DRAW_INDEX_INDIRECT_MULTI`. It stopped about 110–194 s in, on both a 2026-10-13 base (`84b0d2f24`) and current `main`. The change: - `QueueState::indexBufferSize` becomes `std::optional<std::uint32_t>`. A size written by 0x13 or by a 0x91 record behaves as before. An explicit 0 still throws, now as `INDEX_BUFFER_SIZE is zero`. - When the size was never written, `resolveIndirectDraw` marks the draw `indexLimitKnown = false` and keeps the base and alignment checks. - `ClassifyIndirectDraw` sends such a draw to the CPU record path (new path `IndexLimitUnknown`, profiler name "index limit unknown"). The mesh GPU-side case goes there too, so the GPU path's whole-range check and copy is never reached without a limit. - On the record path, each record's `firstIndex`/`indexCount` range skips the clamp against the declared limit. Instead it must not overflow, and it goes through #6606's per-record readability check. Reads stay bounded by `min(count at countAddress, packet count)` records; nothing beyond a record's own range is read. - What still throws: an unreadable active record, address overflow, a null or misaligned base, an explicit size of 0, and the existing type checks. - The assumption is recorded in `docs/dev/debt/libSceAgcDriver.md`. The console's initial INDEX_BUFFER_SIZE, and whether the `DRAW_INDEX_2`/`DRAW_INDEX_OFFSET_2` MAX_SIZE sets it, are not measured. The branch is #6606's head (`925f9a84b`) merged with `main` (`0d1c299a9`), plus one commit. Until #6606 is merged, the diff also shows its commits. ### Tested - Windows 11 Enterprise 10.0.26200, NVIDIA GeForce RTX 3080, driver 617.42. - `tests/Pm4.cpp`: 0x25 and 0x38 without 0x13 resolve with an unknown limit; an explicit 0x13 of 0 still throws; a written size keeps a known limit. - `SparseIndirectIndices`: three new registrations. - `agc_driver_sparse_indirect_indices_no_size` sends 0x38 with no 0x13 and matches the reference triangle. - `..._no_size_unreadable` and `..._no_size_unreadable_record` check that an unreadable active record still throws. - Restoring the old throw in `resolveIndirectDraw` makes `agc_driver_pm4` and the three `no_size` tests fail. Disabling only the `IndexLimitUnknown` classification makes the three `no_size` tests fail. - `ctest -R ^agc_`: 732 of 733 pass, 3 skipped. `agc_driver_bda_device` fails identically on `main` on this machine (`vkWaitForFences graphics: Vulkan result -4`). - `tools/check_conventions.py --base origin/main` and `tools/check_test_registration.py build` pass. - **Marvel's Spider-Man 2 (PPSA08338):** - Built on `main` with #7505 and #6606 plus this change, the INDEX_BUFFER_SIZE abort is gone. - The title then stops at 155 s on a different site, `GetImageResource dword 0 is not a valid runtime value` (a record → pointer → V# → T# chain, #6191). ### 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 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: #6606 - [x] Fixes: none - [x] Unblocks: PPSA08338 (no Game bring-up discussion yet) - [x] GPUs tested: NVIDIA GeForce RTX 3080, driver 617.42, Windows 11 Enterprise 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01HAtTu2pw6GTkMNwsjBDatU
github-actions[bot] commented 2026-10-18 22:12:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-18T22:12:22Z.


Thank you for your contribution! Authors with no pull requests merged into main can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6255789100 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7679#issuecomment-6255789100). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-18T22:12:22Z. --- Thank you for your contribution! Authors with no pull requests merged into `main` can have 1 open pull request at a time, authors with at least 1 merged can have 20, and from 20 merged there is no limit. This PR has been automatically closed and labeled "open PR limit" because that limit was reached. This is not a judgment of the quality of your changes: reopen it once one of your open pull requests is merged or closed.

Pull request closed

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!7679
No description provided.