perf(agc): reuse the open render pass's attachments when the next draw's targets are unchanged #16115
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16115"
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 Nesyth on 2026-11-05T17:42:49Z.
What
Every draw looks up its color and depth attachments again. For each color target
refreshResidentTargetfinds the resident image in the storage cache and refreshes it (StorageTexture::Refresh), then takes its attachment view. The depth target goes throughDepthSurfaceViewWithStencilWriteIntent. In a run of draws into the same targets inside one render pass the answer does not change.This PR keeps the attachments of the last recorded draw on each thread (
AttachmentMemoinGraphics/src/Draw.cpp). The next draw takes them instead of the lookup when all of these hold:Id()), its render pass is still open, andRecorder::RenderPassGeneration()is unchanged. The generation moves when a pass ends (endOpenRenderPass) and when a new batch opens (ensureOpen).GuestMemory::ProofSerial()andStorageTexture::PendingSerial()are unchanged.sameColorTarget,sameDepthTarget), and so do depth write, stencil test and the stencil write intent.Version(), is still the storage cache's (StorageImageCached) and serves the target's DCC keys (StorageImageServesKeys), the checksDrawWithRecipemakes on its stored targets.DepthSurfacesSerial()andDepthSurfacesReleased()are unchanged.Only plain resident targets are kept: no multisampled, staged, partial-write or non-resident color target, a single-sample depth target, and no
APS5_DUMP_TARGETS. A draw that is not recorded clears the memo.The memo serves draws only while
ShaderResources::EpochProofs()holds, that is withAPS5_DRAW_PIPELINE. That is whenStorageTexture::refreshitself skips its work because the collect epoch, the proof serial and the pending serial are unchanged, and the memo relies on the same three. WithoutAPS5_DRAW_PIPELINEnothing changes.APS5_NO_PASS_ATTACHMENT_MEMO=1turns the memo off. It is a runtime switch (RuntimeSwitch::NoPassAttachmentMemo), soAPS5_ABcan toggle it.APS5_VERIFY_PASS_ATTACHMENTS=1runs the full lookup for every draw the memo would serve, compares the images and views, and prints the first twenty that differ.APS5_PIPELINE_STATSorAPS5_PROFILE_DRAW, a[pass-attachments]line every 10 s counts hits, misses by reason, stores and verified hits, as the[finisher]line does.The memo lives in
HostThreadLocal, like the shape memo, and holds weak references to the images, so it keeps no image alive and an entry from another device or recorder never matches. Both variables have rows indocs/dev/ENVIRONMENT.md, and theAPS5_DRAW_PIPELINEparagraph ofdocs/dev/ARCHITECTURE.mddescribes the memo.docs/dev/TRACING.mdnow says thatAPS5_ABtakes any runtime switch, not onlyAPS5_NO_BARRIER_BATCH.agc_driver_draw_cache_reuse_pass_attachments_verifyis a new registration ofagc_driver_draw_cache_reuse_testsin draw-pipeline mode withAPS5_VERIFY_PASS_ATTACHMENTS=1.Tested
Windows 11 Pro 26300, Radeon RX 7900 XTX (AMD Software 26.10.1), Ryzen 7 7800X3D, MinGW-w64 GCC 15.2, Ninja, Release,
BUILD_TESTING=ON, this head rebased on currentmain4741457fed.main4741457fed(ninja -C build): clean.agc_driver_recorder,agc_driver_graphics, every_draw_pipelineregistration and theagc_driver_draw_cache_reusetests, 52 tests,ANYPS5_REQUIRE_VULKAN=1,-j4: 100% pass, 0 failed._draw_pipelinetests also pass withAPS5_NO_PASS_ATTACHMENT_MEMO=1and withAPS5_VERIFY_PASS_ATTACHMENTS=1(the registered..._pass_attachments_verifytest): 0 differences.main4741457fedwithAPS5_DRAW_PIPELINE=1in both arms. Within one run:APS5_AB=30:APS5_NO_PASS_ATTACHMENT_MEMO, 30 s phases from 190 s, 20 phases, each B phase against its neighbouring A phases. Draws per present swing with the scene, so frame time is fitted against commits per present with a common slope (residual SD 2.0 ms, n 19).The memo answered 256,477 lookups per 10 s and missed 59,514: 33,708 without a memo, 10,941 after the pass ended, 9,355 on moved serials, 4,977 on changed targets, 533 on the depth surface. No errors in the run.
Performance report
Captures of PPSA04264 on
main4741457fedand on this head, same scene, machine and settings (APS5_DRAW_PIPELINE=1, trace window 240-300 s). The two traces, both digests and a second pair of boots are in the report comment.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)Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T20:07:47Z.
Review: COMMENTED
Windows check of head
52db2c4523on the NVIDIA laptop GPU (driver 610) and the Intel iGPU in the same machine. Windows 11 x64, WinLibs GCC 15.2.0 r7, Release,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.Merged onto
main6b733c4ef2(clean), alternating withmainfrom the same build directory:^agc_driver_draw_cache_reuse_indirect$, NVIDIA^agc_driver_draw_cache_reuse, NVIDIAmainpass_attachments_verifyOne failure earlier, not reproduced since. On
main4e44ed59b2with this PR merged, 1 of 3 NVIDIA runs failedagc_driver_draw_cache_reuse_indirectwith:mainpassed all 3 of its runs in that batch. The 20 alternating runs above didn't reproduce it on either side, and this machine stalls now and then, so I can't tie it to the change. It's theThirdDrawHitsTheCachecount check, so if anything in the reused-pass path can skip a lookup under different timing, that would be the place to look.Not run with
VK_LAYER_KHRONOS_validation.AI-assisted: yes.