perf(agc): reuse unchanged colour and depth attachments across draws #17738
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17738"
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 chitters2004 on 2026-11-09T13:45:56Z.
What
Reuses the previous draw's prepared colour and depth attachments when nothing they depend on has changed.
On the record thread, the driver remembers the attachments the previous draw prepared, keyed by:
ColorTargetandDepthTargetdescriptors (exact field equality, padding excluded);TargetProofcovering the collect epoch, proof serial, pending serial, unwatch serial, allocation generation, depth surface serial and releases, multisample claim serial, recorder and device.If the next draw's keys match, the driver skips the lookup, refresh and claim work for those attachments.
APS5_VERIFY_TARGET_MEMO=1runs the full preparation beside every hit and throws on any difference.APS5_NO_TARGET_MEMO=1turns the memo off.A repeated colour or depth attachment does not call
ClaimMultisampleTargetMemory. The multisample claim serial (guarded range generation plus claim releases) makes a released claim force full preparation:A colour attachment is remembered only when its DCC and chain DCC collections are tracked and its CMASK proof holds, because ordinary preparation rescans untracked metadata on every draw. This is checked once when the memo is built.
Storage texture cache eviction gives recently used entries a second chance before evicting them.
Known gaps are in
docs/dev/debt/libSceAgcDriver.md:Tested
Windows 11 (10.0.26320), Ryzen 7 5800X, NVIDIA GeForce RTX 3080, driver 621.14. Tested commit
e01ca4970con maind03beaf110. The mutant results below were measured on the earlier commit98a4c89f07and are not rerun one01ca4970c; the Vulkan gate was rerun one01ca4970c.Head
2f652d9cbaise01ca4970cmerged withmainf439f7f3a0(both sides kept inTexture.hpp,DepthSurface.cppand the debt file); the results below are frome01ca4970cand are not rerun on the merge.Head
562ed081ddis that merge plus44ebd4dec8(the target memo kept in a host thread slot) and562ed081dd(test only: the baseline fixture unwatches its memory itself, so the saved baseline exists on every platform). Rerun on562ed081dd:VUID-, layer loaded. All 39agc_driver_color_memotests pass. The two failures,agc_driver_msaa_dcc_clear_4andagc_driver_native_depth_publication, fail the same way onmainf439f7f3a0on this machine (2 of 2 runs there, 3 of 3 here, also withAPS5_NO_TARGET_MEMO=1).ctest -R '^agc_driver_color_memo'on Ubuntu 24.04 (WSL2), GCC 13.3, Release, Mesa lavapipe (llvmpipe, LLVM 20.1.2) withANYPS5_REQUIRE_VULKAN=1: 39/39 in 3 of 3 runs, and 39/39 in 3 of 3 runs withAPS5_WRITE_WATCH_IMPORTS=watch(host imports stay write-watched, the case that failed on NVIDIA Linux). Before562ed081ddthe three baseline tests failed in both modes. Not run on an NVIDIA or AMD Linux driver.Head
2e05397415is562ed081ddmerged withmain07ae6afcee. The only conflict was inTexture.cpp, where #15569 and this PR each added functions at the same place; both are kept. #15569's GPU-ordered refresh skip marks every layer changed and uploads, which this PR's refresh-work count sees, and its ordered flush skip leaves pending textures pending, so the pending serial the memo keys on is unchanged. Not rerun on the merge; CI builds and tests it.Focused Vulkan gate. Ran with
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, plain and withAPS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1. The validation layer loaded in every run (no missing-layer line), and no subprocess.logfile containsVUID-.VUID-e01ca4970c)d03beaf110)The 44 extra tests on this PR are the new target memo scenarios, each run in enabled, disabled and verify modes.
Regression test for the claim fix.
agc_driver_color_memo_claim_*sets up an absorbed fill over an aliased multisampled target between two repeated draws. A later read must retire the target. The test fails when the claim serial is left out of the proof.Regression tests for untracked metadata.
agc_driver_color_memo_untracked-dcc_*andagc_driver_color_memo_untracked-cmask_*draw repeatedly to a target whose DCC keys or CMASK lie in untracked memory, then fill the metadata with a clear. The next draw must look the target up again and resolve the clear. Both fail when the metadata check is left out.Mutants. I built one diagnostic build with twelve mutants behind
APS5_R3_MUTANT. Each mutant removes or weakens one conjunct of the key or admission. All twelve fail the enabled-mode memo tests with the expected assertion, and the unmutated build passes. The mutants are:Performance
GTA V (PPSA04263, save
play1-first-autosave), 3840x2160, RTX 3080, driver 621.14, Windows 11 (10.0.26320), Ryzen 7 5800X. WindowAPS5_TRACE_SECONDS=235:30withAPS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1. Maind03beaf110(A) against this PRe01ca4970c(B). One discarded warm-up boot of the PR build, then three timed A/B pairs in the order A B, B A, A B. Every run is a fresh boot from the same save with a preflight check and a timing claim; all linesdirty: false; every capture dropped trace events (the summary lines carry the phase totals).d03beaf110e01ca4970ce01ca4970cd03beaf110d03beaf110e01ca4970c(mean = window ms / presents.) Pair deltas B minus A: -11.76, -10.38, -9.60 ms/frame, mean -10.58 ms (-8.4 %), range -11.76 to -9.60. A alone ranges 125.06 to 126.26 (1.19 ms) and B alone 113.30 to 115.99 (2.69 ms), so the effect is about four times the spread of either side. At 3,040 draws per frame (the replay's count; draws are not in the trace) that is -3.5 us per draw (-3.87 to -3.16).
The saving sits in the zone the PR targets:
Driver.Draw.preparefalls by 8.4, 9.2 and 10.2 ms/frame (mean -9.3), most of the frame-time delta;Driver.Drawfalls 8.7 to 9.9 andGraphics.Draw9.1 to 10.8. GPU busy is unchanged (33.0 to 33.2 ms per present): the scene is CPU bound (the queue worker is busy about 94 % of the frame, the GPU 27 %), so the draw preparation saving shows up in the frame interval.Deviations:
performance_compare.pytakes one summary per side, so the comparison is per pair (compare-*.txtin the release), not pooled. An earlier set of four pairs onebb2a9ccda(superseded, mean -10.43 ms) is in the same release for reference; the numbers above are frome01ca4970conly.The two summary lines below are the first pair (the remaining runs, traces, digests and compares are in the release https://github.com/chitters2004/AnyPS5/releases/tag/pr-r3-t5):
{"commit":"d03beaf11059","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":""},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4146,"ms":30015.554},"presents":240,"frame_ms":{"p50":124.98,"p90":128.78,"p99":131.47,"max":133.763},"gpu_busy_ms_per_present":33.041,"worker_busy_pct":{"queue worker 0x0":94.477},"top_phases_ms_per_frame":{"Driver.Packet":111.923,"Graphics.Draw":95.723,"Driver.Packet.draw":81.117,"Driver.Draw":80.507,"Graphics.Draw.draw_and_resource_release":74.635,"Driver.DrawFinish":71.542,"Driver.Draw.prepare":64.603,"Driver.DrawFinish.draw_enqueued":38.793},"owned_draw_counts":{"OwnedDraw.arm_attempt":720,"OwnedDraw.arm_blocks_requested":720,"OwnedDraw.arm_refused":720,"OwnedDraw.evicted_other":2807},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.52,"events_lost":1171478,"totals_full":false},"draw committer":{"events_full_after_s":10.819,"events_lost":468372,"totals_full":false},"draw finisher":{"events_full_after_s":15.783,"events_lost":239529,"totals_full":false}},"trace":"aps5-trace-d03beaf11059-27292.json.gz"}
{"commit":"e01ca4970cf4","dirty":false,"env":{"APS5_ADDRESS_COPY_MAX_MIB":"512","APS5_DRAW_PIPELINE":"1","APS5_DUMP_FRAMES":"80","APS5_DUMP_FRAMES_EVERY":"300","APS5_LOG_TIMESTAMPS":"1","APS5_NO_PAD_INPUT":"1","APS5_PAD_INPUT_FILE":"","APS5_PIPELINED_DRAWS":"32","APS5_PIPELINE_DISPATCH":"1","APS5_TRACE_DIR":"","APS5_TRACE_SECONDS":"235:30","APS5_TRACE_SUMMARY_EVERY":"10","APS5_VIDEOOUT_TELEMETRY_DIR":""},"gpu":"NVIDIA GeForce RTX 3080","driver":"NVIDIA 621.14","os":"Windows 10.0.26320","cpu":"AMD Ryzen 7 5800X 8-Core Processor","cpu_threads":16,"memory_mib":32676,"title_id":"PPSA04263","title":"Grand Theft Auto V","content_version":"01.011.001","resolution":"3840x2160","window":{"spec":"seconds 235:30","first_present":4326,"ms":30024.859},"presents":265,"frame_ms":{"p50":112.672,"p90":116.913,"p99":137.596,"max":139.552},"gpu_busy_ms_per_present":33.068,"worker_busy_pct":{"queue worker 0x0":94.739},"top_phases_ms_per_frame":{"Driver.Packet":101.627,"Graphics.Draw":84.962,"Driver.Packet.draw":72.403,"Driver.Draw":71.813,"Graphics.Draw.draw_and_resource_release":64.042,"Driver.DrawFinish":62.485,"Driver.Draw.prepare":56.199,"Driver.DrawFinish.draw_enqueued":31.32},"owned_draw_counts":{"OwnedDraw.arena_check":903,"OwnedDraw.arm_attempt":1238,"OwnedDraw.arm_blocks_requested":2010,"OwnedDraw.arm_refused":795,"OwnedDraw.arm_success":443,"OwnedDraw.check_blocks_requested":2235,"OwnedDraw.evicted_other":2329,"OwnedDraw.evicted_other_by_owned":1,"OwnedDraw.invalidated":299,"OwnedDraw.proof_check":923,"OwnedDraw.reused":181},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":6.384,"events_lost":978854,"totals_full":false},"draw committer":{"events_full_after_s":12.555,"events_lost":367949,"totals_full":false},"draw finisher":{"events_full_after_s":18.69,"events_lost":164188,"totals_full":false}},"trace":"aps5-trace-e01ca4970cf4-8992.json.gz"}
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)🤖 Generated with Claude Code