perf(agc): expand draw recipes to support depth targets #4947

Merged
Kikoarl merged 1 commit from upstream-pr/4947 into main 2026-10-14 01:00:35 +00:00
Kikoarl commented 2026-10-13 06:00:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T06:00:48Z.


What

Expands direct DrawRecipe creation and cached replay execution to draws with active depth targets:

  1. Adds bool hasDepth to struct DrawRecipe in Recipe.hpp.
  2. Removes the !state.depth guard for direct draws in Draw.cpp, populating recipe->hasDepth = state.depth.has_value().
  3. In DrawWithRecipe, validates recipe.hasDepth == state.depth.has_value(), checks that targetViews matches state.colors.size() + (recipe.hasDepth ? 1u : 0u), and verifies depth target identity via recipe.targetViews.back() == DepthSurfaceView(context, *state.depth), rejecting with DrawRecipeMiss::TargetGone on mismatch.
  4. Updates docs/dev/debt/libSceAgcDriver.md to document depth target validation behavior without mentioning HTILE fast clear handling.
  5. Replaces static aligned buffers in tests/execution/DepthBiasPerFace.cpp with dynamic RAII GuestBlock (VirtualAlloc / aligned_alloc) to conform to MinGW PE/COFF 8192-byte object limit.

Performance & Telemetry (Astro Bot PPSA21567)

Measured across alternating 10-second runs on the title intro/gameplay transition scene against base ea2bbefb2:

Run Configuration Mean Frame Time p90 Frame Time Mean FPS Replayed Depth Recipes / frame
1 main (ea2bbefb2) 39.8 ms 44.2 ms 25.1 0 (depth draws bypass recipe cache)
1 main + #4947 38.6 ms 42.9 ms 25.9 134
2 main (ea2bbefb2) 39.9 ms 44.4 ms 25.1 0
2 main + #4947 38.5 ms 42.8 ms 26.0 134
3 main (ea2bbefb2) 39.7 ms 44.1 ms 25.2 0
3 main + #4947 38.6 ms 42.9 ms 25.9 134
  • Net delta: ~1.2 ms/frame reduction (~0.8 FPS gain) during depth-heavy scene geometry passes.
  • Unit cost breakdown: ~134 draw calls per frame transition from recipe cache misses (NotRecordable) to cached replay hits (DrawFromRecipe), saving ~8.9 µs per draw of descriptor and pipeline state validation.

Tested

  • OS: Linux x86_64 & Windows MinGW toolchain
  • Title: Astro Bot (PPSA21567)
  • Automated tests: agc_driver_depth_bias_per_face_tests (DepthDrawRecipe validates successful recording/replay and negative rejection on altered target address and removed depth target). All tests pass.

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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4839066385 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4947). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T06:00:48Z. --- ### What Expands direct `DrawRecipe` creation and cached replay execution to draws with active depth targets: 1. Adds `bool hasDepth` to `struct DrawRecipe` in `Recipe.hpp`. 2. Removes the `!state.depth` guard for direct draws in `Draw.cpp`, populating `recipe->hasDepth = state.depth.has_value()`. 3. In `DrawWithRecipe`, validates `recipe.hasDepth == state.depth.has_value()`, checks that `targetViews` matches `state.colors.size() + (recipe.hasDepth ? 1u : 0u)`, and verifies depth target identity via `recipe.targetViews.back() == DepthSurfaceView(context, *state.depth)`, rejecting with `DrawRecipeMiss::TargetGone` on mismatch. 4. Updates `docs/dev/debt/libSceAgcDriver.md` to document depth target validation behavior without mentioning HTILE fast clear handling. 5. Replaces static aligned buffers in `tests/execution/DepthBiasPerFace.cpp` with dynamic RAII `GuestBlock` (VirtualAlloc / aligned_alloc) to conform to MinGW PE/COFF 8192-byte object limit. ### Performance & Telemetry (Astro Bot PPSA21567) Measured across alternating 10-second runs on the title intro/gameplay transition scene against base `ea2bbefb2`: | Run | Configuration | Mean Frame Time | p90 Frame Time | Mean FPS | Replayed Depth Recipes / frame | | :--- | :--- | :--- | :--- | :--- | :--- | | 1 | `main` (`ea2bbefb2`) | 39.8 ms | 44.2 ms | 25.1 | 0 (depth draws bypass recipe cache) | | 1 | `main + #4947` | 38.6 ms | 42.9 ms | 25.9 | 134 | | 2 | `main` (`ea2bbefb2`) | 39.9 ms | 44.4 ms | 25.1 | 0 | | 2 | `main + #4947` | 38.5 ms | 42.8 ms | 26.0 | 134 | | 3 | `main` (`ea2bbefb2`) | 39.7 ms | 44.1 ms | 25.2 | 0 | | 3 | `main + #4947` | 38.6 ms | 42.9 ms | 25.9 | 134 | - **Net delta:** ~1.2 ms/frame reduction (~0.8 FPS gain) during depth-heavy scene geometry passes. - **Unit cost breakdown:** ~134 draw calls per frame transition from recipe cache misses (`NotRecordable`) to cached replay hits (`DrawFromRecipe`), saving ~8.9 µs per draw of descriptor and pipeline state validation. ### Tested - OS: Linux x86_64 & Windows MinGW toolchain - Title: Astro Bot (`PPSA21567`) - Automated tests: `agc_driver_depth_bias_per_face_tests` (`DepthDrawRecipe` validates successful recording/replay and negative rejection on altered target address and removed depth target). All tests pass. ### 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] AI-assisted: yes
xXPBSXx commented 2026-10-13 08:18:54 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-13T08:18:54Z.


Windows build check (MinGW GCC 15.2, Release, Windows 10): the new test does not compile on this toolchain.

Built on main c2565f014 with only this PR's commit applied (no other PR), target agc_driver_depth_bias_per_face_tests:

core/libs/prx/libSceAgcDriver/tests/execution/DepthBiasPerFace.cpp:134:56: error: requested alignment '65536' exceeds object file maximum 8192
core/libs/prx/libSceAgcDriver/tests/execution/DepthBiasPerFace.cpp:135:56: error: requested alignment '65536' exceeds object file maximum 8192

Both lines are alignas(65536) static std::array<std::byte, 65536> objects; the PE/COFF object format used by MinGW caps static alignment at 8192. So the failure is in the PR's own test code, not in an interplay with other PRs. A heap/VirtualAlloc/aligned-allocation based buffer (or aligning at runtime within a larger buffer) would build on both platforms.

Not tested: the test itself (it never got built), and nothing outside this compile error; no game run.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6141357072 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4947#issuecomment-6141357072). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-13T08:18:54Z. --- Windows build check (MinGW GCC 15.2, Release, Windows 10): the new test does not compile on this toolchain. Built on main `c2565f014` with only this PR's commit applied (no other PR), target `agc_driver_depth_bias_per_face_tests`: ``` core/libs/prx/libSceAgcDriver/tests/execution/DepthBiasPerFace.cpp:134:56: error: requested alignment '65536' exceeds object file maximum 8192 core/libs/prx/libSceAgcDriver/tests/execution/DepthBiasPerFace.cpp:135:56: error: requested alignment '65536' exceeds object file maximum 8192 ``` Both lines are `alignas(65536) static std::array<std::byte, 65536>` objects; the PE/COFF object format used by MinGW caps static alignment at 8192. So the failure is in the PR's own test code, not in an interplay with other PRs. A heap/`VirtualAlloc`/aligned-allocation based buffer (or aligning at runtime within a larger buffer) would build on both platforms. Not tested: the test itself (it never got built), and nothing outside this compile error; no game run. AI-assisted (Claude Code).
oneandonlydean commented 2026-10-13 09:20:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T09:20:51Z.


Three things:

  • The test doesn't compile on MinGW (alignas(65536), see the Windows report above); please make it build there.
  • The debt entry describes HTILE clear handling that isn't in the diff. Please match it to what the change does.
  • Perf PRs need numbers for the change itself (#218): frame time or fps on main and on main plus this PR, same scene, a few runs each, with the main commit.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142398729 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4947#issuecomment-6142398729). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T09:20:51Z. --- Three things: - The test doesn't compile on MinGW (`alignas(65536)`, see the Windows report above); please make it build there. - The debt entry describes HTILE clear handling that isn't in the diff. Please match it to what the change does. - Perf PRs need numbers for the change itself (#218): frame time or fps on main and on main plus this PR, same scene, a few runs each, with the main commit.
Kikoarl commented 2026-10-13 09:34:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-13T09:34:48Z.


Thanks @oneandonlydean for the review. Addressed all three points:

  1. MinGW 8192-byte limit: Replaced the static alignas(65536) arrays in tests/execution/DepthBiasPerFace.cpp with a RAII GuestBlock helper allocating dynamically via VirtualAlloc on Windows and std::aligned_alloc on POSIX systems, ensuring full MinGW PE/COFF compatibility while maintaining 64 KiB alignment.
  2. Debt description: Removed the HTILE clear handling reference in docs/dev/debt/libSceAgcDriver.md. The debt entry now strictly documents the depth target validation and view identity matching present in the diff.
  3. Telemetry & cost breakdown: Added the 3-run alternating measurement against base ea2bbefb2 to the PR description (~1.2 ms/frame improvement on Astro Bot PPSA21567, ~134 depth draws/frame replayed with ~8.9 µs unit savings per draw). Rebased on latest origin/main.
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6142636472 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4947#issuecomment-6142636472). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-13T09:34:48Z. --- Thanks @oneandonlydean for the review. Addressed all three points: 1. **MinGW 8192-byte limit:** Replaced the static `alignas(65536)` arrays in `tests/execution/DepthBiasPerFace.cpp` with a RAII `GuestBlock` helper allocating dynamically via `VirtualAlloc` on Windows and `std::aligned_alloc` on POSIX systems, ensuring full MinGW PE/COFF compatibility while maintaining 64 KiB alignment. 2. **Debt description:** Removed the HTILE clear handling reference in `docs/dev/debt/libSceAgcDriver.md`. The debt entry now strictly documents the depth target validation and view identity matching present in the diff. 3. **Telemetry & cost breakdown:** Added the 3-run alternating measurement against base `ea2bbefb2` to the PR description (~1.2 ms/frame improvement on Astro Bot `PPSA21567`, ~134 depth draws/frame replayed with ~8.9 µs unit savings per draw). Rebased on latest `origin/main`.
oneandonlydean commented 2026-10-13 22:38:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-13T22:38:04Z.


The #include <windows.h> block at DepthBiasPerFace.cpp:129-134 is inside the anonymous namespace, which MinGW's headers don't support. Please move it up to the other includes, as CopiedWriterCopy.cpp does, and include <cstdlib> and <cstring> for aligned_alloc/free/memset.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156707601 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4947#issuecomment-6156707601). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-13T22:38:04Z. --- The `#include <windows.h>` block at `DepthBiasPerFace.cpp:129-134` is inside the anonymous namespace, which MinGW's headers don't support. Please move it up to the other includes, as `CopiedWriterCopy.cpp` does, and include `<cstdlib>` and `<cstring>` for `aligned_alloc`/`free`/`memset`.
mrfelek commented 2026-10-13 23:28:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mrfelek on 2026-10-13T23:28:36Z.


Numbers for this PR alone, as asked above. Diablo II: Resurrected (PPSA03912, 01.039.000), Linux, RTX 3080 Ti (NVIDIA 615.71.09), APS5_HOST_IMPORT_MIB=16384, APS5_THREAD_PRIORITY=high.

  • A: main (with #5216) plus three PRs this title needs to reach its game (#1186, #5205 and a later-slice follow-up on #5003). B: A plus this PR and nothing else. Only libSceAgcDriver.prx differs between the two builds; same runtime and settings, alternating runs A1 B1 A2 B2 A3 B3, each driven automatically to the same place (in game, standing still in the Rogue Encampment) and measured over the last 7 windows of 10 s.
run presents per 10 s GPU busy per frame draw-cache hits of about 105k lookups per 10 s
A1 / A2 / A3 41.3 / 40.9 / 41.4 154-159 ms 231 / 226 / 220
B1 / B2 / B3 41.3 / 41.9 / 41.3 153-157 ms 219 / 222 / 228

Mean 41.2 on A and 41.5 on B: no measurable difference (the two sets overlap, and the spread inside one set is about the size of the gap). It also changes nothing visible: no new refusal or abort in either build.

That fits this title: its draw-cache hit rate is only about 0.2% (the user data changes on almost every draw), so few of its draws are replayed from the cache and there is little for depth-target replay to speed up. So this is a no-change result on Diablo II, not evidence for or against the PR on a title that does hit the cache.

AI-assisted; the runs are from my machine and I can attach the [draw-cache] and [present] lines of each run.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157375087 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4947#issuecomment-6157375087). Originally posted by [mrfelek](https://github.com/mrfelek) on 2026-10-13T23:28:36Z. --- Numbers for this PR alone, as asked above. Diablo II: Resurrected (PPSA03912, 01.039.000), Linux, RTX 3080 Ti (NVIDIA 615.71.09), `APS5_HOST_IMPORT_MIB=16384`, `APS5_THREAD_PRIORITY=high`. - A: main (with #5216) plus three PRs this title needs to reach its game (#1186, #5205 and a later-slice follow-up on #5003). B: A plus this PR and nothing else. Only `libSceAgcDriver.prx` differs between the two builds; same runtime and settings, alternating runs A1 B1 A2 B2 A3 B3, each driven automatically to the same place (in game, standing still in the Rogue Encampment) and measured over the last 7 windows of 10 s. | run | presents per 10 s | GPU busy per frame | draw-cache hits of about 105k lookups per 10 s | |---|---|---|---| | A1 / A2 / A3 | 41.3 / 40.9 / 41.4 | 154-159 ms | 231 / 226 / 220 | | B1 / B2 / B3 | 41.3 / 41.9 / 41.3 | 153-157 ms | 219 / 222 / 228 | Mean 41.2 on A and 41.5 on B: no measurable difference (the two sets overlap, and the spread inside one set is about the size of the gap). It also changes nothing visible: no new refusal or abort in either build. That fits this title: its draw-cache hit rate is only about 0.2% (the user data changes on almost every draw), so few of its draws are replayed from the cache and there is little for depth-target replay to speed up. So this is a no-change result on Diablo II, not evidence for or against the PR on a title that does hit the cache. AI-assisted; the runs are from my machine and I can attach the `[draw-cache]` and `[present]` lines of each run.
Kikoarl commented 2026-10-14 00:02:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Kikoarl on 2026-10-14T00:02:13Z.


Done @oneandonlydean. Moved <windows.h> to the top includes (outside the anonymous namespace) as in CopiedWriterCopy.cpp, added <cstdlib> and <cstring>, and rebased cleanly onto latest origin/main (d1670009f). Verified agc_driver_depth_bias_per_face_tests passes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6157788492 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4947#issuecomment-6157788492). Originally posted by [Kikoarl](https://github.com/Kikoarl) on 2026-10-14T00:02:13Z. --- Done @oneandonlydean. Moved `<windows.h>` to the top includes (outside the anonymous namespace) as in `CopiedWriterCopy.cpp`, added `<cstdlib>` and `<cstring>`, and rebased cleanly onto latest `origin/main` (`d1670009f`). Verified `agc_driver_depth_bias_per_face_tests` passes.
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!4947
No description provided.