refactor(agc): split prepareDraw's read-only plan from its record-time work #14051
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/14051"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by vingelvatten on 2026-10-31T17:06:15Z.
What
Step 2 of the draw-side series in #7895 (the outline of 21 October, endorsed by @oneandonlydean): make the read-only part of
prepareDrawexplicit and movable, still on the committer and still in the same order relative to every record-time effect.planDraw→DrawPlanCachedFragmentOutputs,PipelineStages), the mesh group count and limits, the tessellation patch check, the viewport, depth-bounds and sample-mask checks, the vertex input layout, and the resource-cache key (DrawResourceKey). It reads the state, the draw parameters and the compiled stages only: no guest memory, no recorder, no registry, nothing another draw left behind. It does touch three memoizations, each synchronized and order-insensitive:CachedFragmentOutputs(its own mutex, the memo of validated outputs),VertexInputCache::TryGet(its own mutex; a lookup can move an LRU entry, insert, evict or set a bypass bit) and the resource-key memoDrawResourceKeypublishes on the program (atomic, idempotent). A plan built on any thread, in any order, gets the same values from them; what they change is cache state, never the plan's output.prepareDrawInputsDrawInputsand everything downstream (recordDraw,recordDrawCommands, the recipe path) are unchanged.resolveDrawResourcescacheableis still decided here because it needsrecordable, which needs the resident targets.prepareDrawbuilds the plan right after the timer starts (afterBoundKeptBytes, as #8992 arranged) and then runs the same sequence as today.DrawWithRecipebuilds the plan from the recipe's fragment outputs, stages and vertex layout asprepareDrawInputsdid for it before.drawTessellationGeometryis untouched: each of its two draws gets its own plan throughDraw.What changes in behaviour, deliberately:
DrawResourceKeyis built for every draw whose stages allow a cache key, not only for recordable ones (a synchronous draw used to skip it). The key is idempotent on the program and cheap;cacheablestill gates the cache lookup.validate, the layout tovertexand the key build tolookup(DrawTimer::chargemoves the key's time out of the phase it would otherwise land in), so[draws]andAPS5_TRACE_DRAWSkeep their meaning.Debug aid:
APS5_VERIFY_DRAW_PLAN=1(off by default) builds the plan a second time at the end ofprepareDraw, after every record-time effect, and requires it to equal the plan the draw used (the content of the layout, the key and the scalar fields; not the memo hit flags, which a second lookup may legitimately change). It is a consistency check that the plan reads nothing the record-time work changes; it is not a thread-safety proof, and it does not cover the three memoizations' internal state (the LRU position or a bypass bit), which the plan's output does not depend on. The draw-pipeline test set gets_plan_verifyvariants with that switch on top of the pipelined settings.No speed claim: the plan is a small share of the committer (the
validateandpipelinephases together are a few percent at Astro Bot's Crash Site). The point is the seam: step 3 and the preparer thread onfeat/agc-draw-prepare-aheadcan takeplanDrawas the work that leaves the committer, and the adopt-time check sits whereprepareDrawInputsbegins.Tested
Windows 11 Pro 26300, Ryzen 7 7800X3D, 31 GB; WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Based onmaind60ebec0c2(6 November; rebased four times asmainmoved: after #12862 split the test registrations and #13894 changed the mesh group limit, after #14857 moved theGraphics.Drawtrace marks intoprepareDrawInputs, after #13858 split the resource-cache candidate from the cacheable decision for its address-draw reuse, and after #15705 addeddrawStagingEnabledbeside the resolve step); head241a32be3a. Thevalidatetrace mark sits inprepareDrawInputsafter the three checks that stay there, so the slice still covers all of a draw's validation. For #13858 the plan carriescandidate(the stages allow a cache key) next tokeyed(candidateand notNeverReusable), soresolveDrawResourcesdecidescandidateandcacheablefrom the plan exactly as before. Themainarm of every comparison is a build of that same commit from a second worktree, so the two trees differ only by this change.NVIDIA RTX 4070 Ti SUPER (617.42), focused draw tests (
agc_driver_.*(draw|stencil|indirect|multisample|msaa|target|pass|pipelined|finisher|recipe|plan_verify)|^agc_driver_graphics) withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:main187 tests, 100% passed, 4 skipped (agc_driver_msaa_dcc_compared_import_{2,4,8},agc_driver_stencil_ref_export); branch 209 tests (the same 187 plus the 22_plan_verifyvariants), 100% passed, the same 4 skipped. Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS; both hold the same 4 lines ofVUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605fromagc_driver_srgb8_color_target_tests; no new VUID.AMD Radeon Graphics (Ryzen 7 7800X3D iGPU, RDNA2 gfx1036, AMD driver 32.0.21045.16010 / 2.0.353), same set and switches:
main187 tests, 100% passed, 4 skipped (agc_driver_msaa_dcc_compared_import_{2,4,8},agc_driver_mesh_draw_relocation); branch 209 tests, 100% passed, the same 4 skipped. 0 layer-missing lines; both logs hold the same 6 lines of the sRGB8 blend VUID; no new VUID.lavapipe (llvmpipe, LLVM 21.1.8, Mesa 25.x, WSL Ubuntu 26.04 x86-64), same focused set and switches,
ctest -j 4:main188 tests, 100% passed, 7 skipped; branch 210 tests, 100% passed, the same 7 skipped (agc_driver_msaa_dcc_{srgb_clear,clear,compared_import}_2,agc_driver_linear_target_direct_write_completion,agc_driver_mesh_draw_relocation,agc_driver_recorded_draw_staging,agc_driver_sample_order_recipe_depth_locations). 0 layer-missing lines; both logs hold the same 6 lines of the sRGB8 blend VUID; no new VUID.ASTRO BOT PPSA21567 01.018.000,
app.exe -lvl hub_crashsite, no input, warm shader cache,APS5_HOST_IMPORT_MIB=13312(without it the title aborts about 110 s in on this machine with a pinned guest allocation, see #12157),APS5_PROFILE_DRAW=1 APS5_TRACE_SUMMARY_EVERY=10, guest 3840x2160 in a 2226x1252 window, RTX 4070 Ti SUPER, one title on the GPU. Two run folders that differ only inlibs/:mainab6f5d32edand this head. Three alternated pairs in the order main, branch, branch, main, main, branch, 200 s each, the last eight 10 s windows of each run averaged. The first run (main) is discarded: the newmainbuild has a new shader-cache key, so that run compiled pipelines for its whole 200 s and never left the menus (371 presents per 10 s, 89k commits at 4.5 ms); the five later runs are steady.[draw] pipelinedcommits per 10 smainab6f5d32edThree earlier pair sets on the previous base (
main73f4f7e06e, heads before the rebase) gave 74.4 vs 75.1, 74.0 vs 73.0 and 74.5 vs 74.3 presents per 10 s, so the branch lands on both sides ofmain: run-to-run noise. The[draws]phase totals per 10 s are the same on both arms forvertex(899 vs 903 ms),lookup(1474 vs 1473 ms),pipeline(135 vs 128 ms) andrecord(988 vs 974 ms).validatereads 109 ms onmainand 135 ms on the branch: the difference is the three extrasteady_clock::now()reads per draw thatDrawTimer::chargeand the secondPhaseValidatemark cost underAPS5_PROFILE_DRAW(about 0.1 µs at 245k draws per 10 s); without the switch the plan reads no clock at all.python tools/check_conventions.py --base origin/main: all checks passed.python tools/env_reference.py --check: 0 undocumented (the staleAPS5_PAD_SPEAKER_FALLBACK_DBrow ismain's)Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)planDraw), pending its author's confirmation on #10678Overlap
#10678 (
perf(agc): build a pipelined draw's resource-cache key before it reaches the committer) adds acontentKeyparameter throughDrawandresolveDrawResources. With this PR the key lives inDrawPlan. Proposed order, asked of its author on #10678: this PR lands first, because it is a refactor with no behaviour change and it gives the early key a home; #10678 then shrinks to passing the finisher's key intoplanDrawand taking it whenKeyForDevicematches (about ten lines instead of its current plumbing). If #10678 lands first instead, this PR rebases:planDrawtakes the given key whenKeyForDevicematches and builds it otherwise. johandavidcm'sfeat/agc-draw-prepare-ahead(not a PR yet) prepares the fragment outputs, stages, vertex layout and set layouts on a preparer thread; with this PR that work isplanDraw.🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-31T17:32:23Z.
Review: DISMISSED
Reviewed — changes requested
The checklist leaves this PR's overlap with open #10678 at
Depends on: none, and neither PR's discussion records an agreed landing order.What I ran
Reviewed head
aa0880e4ebc0b1a705118028eb68fa93d69fd7a8. GitHub reports base474030e58424fefdb65e5df9f3820810fbb4553c; I also checked the merge preview against the newer livemaintip0f302813cebfc09e3e0b6f8fced15262d186879e, which merged cleanly. Environment: Debian 12, Linux 6.1, Python 3.11.2, GCC 12.2.0. No local build or C++ tests were run.Results
git diff --check)main0f302813cebfc09e3e0b6f8fced15262d186879emainmain; preview tree4678f46d088f119e2d4da4131c8f24e070d70972_plan_verifyvariants were skippedUnedited check output
Findings
Blocking
DrawResourceKeyconstruction intoplanDrawand passes it throughresolveDrawResources; #10678 changes that same resource-resolution path to accept a finisher-builtcontentKey. The PR body itself says whichever lands second must rebase, but its checklist saysDepends on: none, and I found no agreement with #10678's author in either PR's discussion. The repository requires authors of overlapping PRs to agree which lands first and declare the dependency. Please agree on the order, then update the later PR'sDepends onentry accordingly.Non-blocking
planDrawcallsVertexInputCache::TryGet. That call can move an LRU entry, insert or evict cache entries, or set a bypass bit; the cache mutex protects those updates, so this is not by itself evidence of a data race. However, the description says the plan uses “no shared cache,” and the repeat-plan verifier compares plan outputs without checking those cache mutations. Please describe this synchronized cache interaction in the plan contract and verifier rationale, or move the cache operation outside the read-only stage if that property is required for the preparer boundary.Sources
0f30281planDrawcache lookup, pinned to this headVertexInputCache::TryGetand mutatingget, pinned to livemainNot verified
_plan_verifyvariants; Linux and specialized hosted jobs were skipped. I did not reproduce the author-reported RTX 4070 Ti SUPER, RDNA2 iGPU, or lavapipe runs.To get this to a good state
Please agree with the #10678 author on landing order and update the dependency checklist on the later PR. Please also clarify the cache interaction in the plan contract. I will rerun the same checks on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-06T14:39:47Z.
Review: CHANGES_REQUESTED
mainmoved under this head and it now conflicts incore/libs/prx/libSceAgcDriver/Graphics/src/Draw.cpp(three hunks, all aroundresolveDrawResourcesand its call inprepareDraw). It needs a design decision, not a mechanical rebase:resolveDrawResources:mainnow computesconst bool candidate = recordable && !noDrawResourceCache && !noTextureCache && all PipelineVariantId() != 0and thenresolved.cacheable = candidate && !ShaderResources::NeverReusable(shaders).address(addressStages,AddressDrawReuse::NotReadOnly/NotSpaceOnly) is derived fromcandidate, so it also applies to stages that areNeverReusable.plan.keyedfoldsNeverReusableinto the same flag, so the address-reuse classification would change for those draws.DrawPlanneeds to carry the candidate condition and theNeverReusablecondition separately (and thenoDrawResourceCache/noTextureCachestatics thatmain's code still reads inresolveDrawResources, which this PR removes).prepareDraw: keepmain'sstopAfterResolveblock andNoteDepthSurfaceWriteafterresolveDrawResourceswhen passingplan.main's new helpers (AddressStages,snapshotsInTable,verifyServedSpace,drawStagingEnabled) sit right aboveresolveDrawResources, which is where the conflict markers land.After the rebase, please rerun the focused draw tests with the
_plan_verifyvariants on the new head, since the key's inputs changed onmain.The landing order with #10678 is still only agreed in comments;
Depends onstaysnoneas you wrote it, so that is fine once it is confirmed there.