fix(agc): count a pixel stage's colour attachments against maxPerStageResources #1607

Merged
saarthakpant merged 1 commit from upstream-pr/1607 into main 2026-10-10 07:25:20 +00:00
saarthakpant commented 2026-10-08 14:15:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by saarthakpant on 2026-10-08T14:15:33Z.


What

Fixes the TechnicalDebt entry "Per-stage descriptor count": a pixel shader's colour attachments were not counted against maxPerStageResources, so a pixel stage whose buffers and images fit the limit could still give a pipeline that exceeds it.

The Vulkan spec's definition of maxPerStageResources says that for the fragment stage, the framebuffer colour attachments also count against the limit.

  • The graphics ShaderResources build takes the draw's colour attachment count (state.colors.size(), the list Pipeline.cpp builds its colour attachments from). The fragment stage's resource total starts at that count, so its buffers and images are added on top of it. Going over the limit throws "shader descriptors exceed per-stage limits" as before. Vertex and compute stages start at 0, as before.
  • The draw resource cache key carries the attachment count, so a build cached for fewer attachments is never reused by a draw with more, which would skip the check.
  • The vertex+pixel convenience constructor (used only by tests) draws into its one target, so it counts 1 attachment.
  • The TechnicalDebt entry is removed.

#1580 edits the same Require checks in ShaderResources::buildPrepare for a different reason (update-after-bind limits), so whichever PR lands second needs a small rebase. Because this change seeds the fragment stage's total before those checks, the attachments would count against maxPerStageUpdateAfterBindResources too, which the spec also requires.

Tested

Windows 11, WinLibs GCC 15.2.0 (15.2.0posix-14.0.0-ucrt-r7), AMD Radeon RX 9070 XT. Built with -DBUILD_TESTING=ON, then ran the full ctest suite.

  • agc_driver_graphics has a new case on the mock device, with maxPerStageResources = 2:
    • A pixel stage with 2 buffers is accepted with 0 attachments and throws with 1.
    • A vertex stage with 2 buffers and 1 attachment is still accepted.
    • 3 attachments with no bindings throw.
    • With the fragment seeding removed, the new case fails ("expected graphics rejection: shader descriptors exceed per-stage limits").
  • Full ctest rebased on current main (b58b1ccf): everything that covers this change passes, including agc_driver_graphics and agc_pipeline_cache. The suite has 641 tests, and the failures on this machine (RX 9070 XT, exFAT drive) are outside this change. guest_access, guest_filesystem and guest_file_timestamps fail on the filesystem. Six f16 ALU tests lose the sign of a negative zero: agc_driver_float16_misc, agc_driver_float16_modifiers, agc_driver_ldexp_f16_inline_constants, agc_driver_sdwa_float_selectors, agc_driver_sdwa_ldexp_f16 and agc_driver_vop2_modifier_forms. All of these except the newly added agc_driver_ldexp_f16_inline_constants were confirmed to fail the same way on main without this change. The video_out_flip_* window tests are intermittent here: they usually skip and occasionally abort with heap corruption, with or without this change.
  • tools/check_conventions.py --base origin/main passes.

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:4788149673 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1607). Originally posted by [saarthakpant](https://github.com/saarthakpant) on 2026-10-08T14:15:33Z. --- ### What Fixes the TechnicalDebt entry "Per-stage descriptor count": a pixel shader's colour attachments were not counted against `maxPerStageResources`, so a pixel stage whose buffers and images fit the limit could still give a pipeline that exceeds it. The Vulkan spec's definition of `maxPerStageResources` says that for the fragment stage, the framebuffer colour attachments also count against the limit. - The graphics `ShaderResources` build takes the draw's colour attachment count (`state.colors.size()`, the list `Pipeline.cpp` builds its colour attachments from). The fragment stage's resource total starts at that count, so its buffers and images are added on top of it. Going over the limit throws "shader descriptors exceed per-stage limits" as before. Vertex and compute stages start at 0, as before. - The draw resource cache key carries the attachment count, so a build cached for fewer attachments is never reused by a draw with more, which would skip the check. - The vertex+pixel convenience constructor (used only by tests) draws into its one target, so it counts 1 attachment. - The TechnicalDebt entry is removed. #1580 edits the same `Require` checks in `ShaderResources::buildPrepare` for a different reason (update-after-bind limits), so whichever PR lands second needs a small rebase. Because this change seeds the fragment stage's total before those checks, the attachments would count against `maxPerStageUpdateAfterBindResources` too, which the spec also requires. ### Tested Windows 11, WinLibs GCC 15.2.0 (`15.2.0posix-14.0.0-ucrt-r7`), AMD Radeon RX 9070 XT. Built with `-DBUILD_TESTING=ON`, then ran the full ctest suite. - `agc_driver_graphics` has a new case on the mock device, with `maxPerStageResources` = 2: - A pixel stage with 2 buffers is accepted with 0 attachments and throws with 1. - A vertex stage with 2 buffers and 1 attachment is still accepted. - 3 attachments with no bindings throw. - With the fragment seeding removed, the new case fails ("expected graphics rejection: shader descriptors exceed per-stage limits"). - Full ctest rebased on current `main` (b58b1ccf): everything that covers this change passes, including `agc_driver_graphics` and `agc_pipeline_cache`. The suite has 641 tests, and the failures on this machine (RX 9070 XT, exFAT drive) are outside this change. `guest_access`, `guest_filesystem` and `guest_file_timestamps` fail on the filesystem. Six f16 ALU tests lose the sign of a negative zero: `agc_driver_float16_misc`, `agc_driver_float16_modifiers`, `agc_driver_ldexp_f16_inline_constants`, `agc_driver_sdwa_float_selectors`, `agc_driver_sdwa_ldexp_f16` and `agc_driver_vop2_modifier_forms`. All of these except the newly added `agc_driver_ldexp_f16_inline_constants` were confirmed to fail the same way on `main` without this change. The `video_out_flip_*` window tests are intermittent here: they usually skip and occasionally abort with heap corruption, with or without this change. - `tools/check_conventions.py --base origin/main` passes. ### 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
oneandonlydean commented 2026-10-10 03:18:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T03:18:47Z.


This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6093231119 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1607#issuecomment-6093231119). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T03:18:47Z. --- This conflicts with main after today's merges; could you rebase? It passed testing and is otherwise ready.
oneandonlydean commented 2026-10-10 05:16:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-10T05:16:37Z.


Please rebase 8e6704a1 onto main and force-push instead of merging main into the branch (61d5bfe9); PR branches need to stay linear. The conflict resolution in ShaderResources.cpp is fine as it is.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094126701 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1607#issuecomment-6094126701). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-10T05:16:37Z. --- Please rebase 8e6704a1 onto main and force-push instead of merging main into the branch (61d5bfe9); PR branches need to stay linear. The conflict resolution in `ShaderResources.cpp` is fine as it is.
saarthakpant commented 2026-10-10 06:44:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by saarthakpant on 2026-10-10T06:44:46Z.


Rebased onto main and force-pushed: the branch is now a single linear commit, 5b9fdd11.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094774222 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1607#issuecomment-6094774222). Originally posted by [saarthakpant](https://github.com/saarthakpant) on 2026-10-10T06:44:46Z. --- Rebased onto main and force-pushed: the branch is now a single linear commit, 5b9fdd11.
github-actions[bot] commented 2026-10-10 06:47:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-10T06:47:55Z.


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
#1492 docs/dev/TechnicalDebt.md L349
#2380 docs/dev/TechnicalDebt.md L349-350
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094804484 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1607#issuecomment-6094804484). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-10T06:47:55Z. --- <!-- 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 | |---|---|---|---| | #1492 | `docs/dev/TechnicalDebt.md` [L349](https://github.com/boykopovar/AnyPS5/blob/5fd101099d10a8b3166ee681190cbe4c201e56c1/docs/dev/TechnicalDebt.md#L349) | | | | #2380 | `docs/dev/TechnicalDebt.md` [L349-350](https://github.com/boykopovar/AnyPS5/blob/5fd101099d10a8b3166ee681190cbe4c201e56c1/docs/dev/TechnicalDebt.md#L349-L350) | | |
adriadam10 commented 2026-10-10 07:25:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T07:25:17Z.


Rebase is linear now (single commit 5b9fdd11) and merges cleanly onto current main. Checked: ctest for libSceAgcDriver green on the merge result (agc_driver_graphics, agc_driver_prepared_graphics, agc_recorder_kept_bytes), the new case fails without the fragment-stage seeding, and the checks on the head are green; merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6095098392 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1607#issuecomment-6095098392). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T07:25:17Z. --- Rebase is linear now (single commit 5b9fdd11) and merges cleanly onto current main. Checked: ctest for libSceAgcDriver green on the merge result (`agc_driver_graphics`, `agc_driver_prepared_graphics`, `agc_recorder_kept_bytes`), the new case fails without the fragment-stage seeding, and the checks on the head are green; 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!1607
No description provided.