Skip to content

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

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
Kikoarl:perf/agc-draw-recipe-depth-expansion
Oct 14, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
Kikoarl:perf/agc-draw-recipe-depth-expansion

Conversation

@Kikoarl

@Kikoarl Kikoarl commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added docs agc libSceAgc* labels Oct 13, 2026
@xXPBSXx

xXPBSXx commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Collaborator

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 (perf(shader): cut hot-path overhead in recompile cache lookups #218): frame time or fps on main and on main plus this PR, same scene, a few runs each, with the main commit.

@oneandonlydean oneandonlydean self-assigned this Oct 13, 2026
@Kikoarl
Kikoarl force-pushed the perf/agc-draw-recipe-depth-expansion branch from ce8315c to 3d8e3fa Compare October 13, 2026 09:34
@Kikoarl

Kikoarl commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

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

Copy link
Copy Markdown
Collaborator

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

mrfelek commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

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.

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
Kikoarl force-pushed the perf/agc-draw-recipe-depth-expansion branch from 3d8e3fa to 3ebad90 Compare October 14, 2026 00:01
@Kikoarl

Kikoarl commented Oct 14, 2026

Copy link
Copy Markdown
Contributor Author

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.

@oneandonlydean
oneandonlydean merged commit 604ce71 into boykopovar:main Oct 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants