perf(agc): resolve a resident depth surface's view without rebuilding its geometry #17007
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17007"
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-08T05:15:25Z.
What
DepthSurfaceViewWithStencilWriteIntentfinds the resident depth surface of a draw and returns its image view. The view is created once with the surface; what a repeated draw paid for was the bookkeeping around that lookup. Each call described the mirrored depth and stencil plane layouts again withDescribeSurface, which builds a mip-layout vector, up to four times (WrittenUnits,SyncStencilFromMemory,stalePlaneRange/staleStencilRange, the stale marking), and the mirror sync built a per-unit change vector even when no unit had changed. On the GTA V replay that is 4.69 heap allocations per draw inside this call.DepthSurfaceholds the guest size of its mirrored depth and stencil planes after the first use (MirrorBytes,StencilMirrorBytes). The surface'stargetisconst, so the sizes cannot go stale; a new image, extent, format or aliasing target is a newDepthSurface.WrittenUnitsbuilds its per-unit vector only when a unit is found written; an empty result means that nothing changed. Both callers already guard onanyUnitor the size.Behaviour is unchanged. One source file plus a test. About 4 us per draw of guest-memory coherence checking remains in the same call (HTILE store-back check, owner map updates, claim and settle checks); skipping those needs an epoch gate and is a separate design change, not part of this PR.
Overlap, rechecked on 2026-11-08 against
main78976e2657(this branch still merges cleanly, and no commit onmainsincef9c96f23f0touchesDepthSurface.cpp) and earlier againstmain0f147e329fwithtools/pr_overlap.py(it fails closed: it cannot confirm 21 open pull requests that touchDepthSurface.cpp, so they were compared by hand, and #15058 is still open) and, on 2026-11-07 againstmain87473937d3, by hand: #15058 (lgqdaxia, "refresh depth planes over compared shared memory") rewritesWrittenUnits(it adds a parameter and a compare step to the same function) and conflicts textually with theWrittenUnitshunks here; the two are independent in behaviour, and whichever lands second needs a mechanical rebase. #16644 (freneza, partially resident depth and stencil planes) adds its own test next to ours intests/DepthSurfaceReuse.cpp, a one-line textual conflict with no shared behaviour. The other open pull requests that touchDepthSurface.cpp(native multisample depth, #15707, #16365, #16364 and others) change other functions.Tested
Head
8603023ab599onmainf9c96f23f024(one commit; the GTA V A/B timing below was measured on this head and on this base). The mutant and Windows lavapipe runs below ran onc4773b6018, whose two changed files are byte-identical to the head's (only its parent210676ad86differs). Windows 11, RTX 3080 (driver 621.14), Ryzen 7 5800X. No other GPU.Tests (
agc_graphics_profile_draw,tests/DepthSurfaceReuse.cpp), all with the real driver code over the mocked Vulkan device and guest memory that the write watch tracks:TestRepeatedDepthViewAllocations: 16 repeated draws into a resident D32S8 surface reuse its image and view and allocate nothing. glibc only (it countsoperator new); other platforms skip the allocation assertion.TestStencilWriteBeyondPlane(every platform with a write-watched arena): a CPU write one byte past the stencil plane, inside memory that the depth plane size would cover, must not refresh the stencil mirror. This pinsStencilMirrorBytesto the stencil plane.TestRetireStaleSurfaceWithoutWrittenUnits(same condition): a stale surface whose depth memory was unmapped and whose stencil was written by the CPU is retired by a lookup it cannot serve, with an empty written-unit vector; the lookup returns no texture and the surface's image is freed once the next surface is created. This pins the empty-vector handling ofWrittenUnitsinretireStoringStale.Mutants (one change each, built on the head by the fork CI
mutantsjob,ctestregex of the focused AGC set plusdepth):WrittenUnitsnever reports a written unitagc_driver_depth_plane_cpu_write_after_page_unwatch,..._partial_unwatch,..._memo,agc_driver_depth_plane_partial_store_unimported,..._image_copy,..._buffer_copy(run 42425319720)marksizes the vector tounit + 1agc_driver_depth_plane_partial_store_unimported,..._image_copy,..._buffer_copy(same run)StencilMirrorBytessized from the depth planeagc_graphics_profile_drawfails inTestStencilWriteBeyondPlane(run 42432952297)unit < written.size()guard removedagc_graphics_profile_drawsegfaults inTestRetireStaleSurfaceWithoutWrittenUnits(same run)Red and green locally on Windows with the same test: M3 fails with "a CPU write just past the stencil plane must not refresh the stencil mirror", M4 crashes with an access violation, and the unmutated head passes (
Graphics validation tests passed).Fork CI (Linux lavapipe on the head, run 42436384999, head vs
mainf9c96f23f024: 286 of 286 passed on both, noVUID-line. Windows lavapipe onc4773b6018, run 42432994805, against its parent): the same tests fail onmainand on the head (agc_driver_frame_replay_cold_pipelines,agc_driver_recorder,guest_memoryexit code 0xc0000409;agc_driver_native_depth_separate_stenciltimes out at 30 s on the head and did so onmainin an earlier run of the same kind) and the same 8VUID-vkCmdDispatch-groupCountX-00386lines appear in both logs, so the change adds none.Vulkan gate, RTX 3080 (local builds in one tree, Release,
BUILD_TESTING=ON;ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -Rthe focused AGC set plusdepthandagc_graphics_profile_draw): the head8603023ab5292 of 292 passed, and its exact parentmainf9c96f23f0292 of 292 passed, both on the same machine and GPU. NoVUID-line in either log or sub-log, no missing-layer line, no new failure. (CI bundle gates on the earlier bases0f147e329fand210676ad86also passed 292 of 292.)Frame replay, identical frames (3-frame GTA V capture, 9,364 draws,
agc_frame_replay --repeat 5, passes 2 to 5, template-hit rows, per-scope timers in the replay kit, the fix toggled by an environment variable inside one binary): heap allocations inside depth view resolution 4.69 per draw -> 0.97 (0.74 of the 0.97 is the caller'stargetViewsvector growth, 0.21 the HTILE check, 0.02 the owner maps); the call's instrumented time 6.16 -> 4.00 us per draw. The unchanged scopes also moved between the two runs (claim 0.47/0.34 us), so about 25 % run-to-run drift applies; the directly changed scopes account for about 1.2 us.pixels_identical1.0,max_channel_diff0,frames_compared3 for both arms (the replay prints the comparison of the last pass only).Performance, GTA V (PPSA04263, content 01.011.001), standing scene, 3840x2160, default settings, pipelined draws (
APS5_DRAW_PIPELINE=1 APS5_PIPELINED_DRAWS=32 APS5_PIPELINE_DISPATCH=1), 30 s trace window from 235 s after launch (APS5_TRACE_SECONDS=235:30), after one discarded warm-up boot of each build on its shader cache. Interleaved A, B, A, B, one machine, 2026-11-08, saveplay1-first-autosave. A ismainf9c96f23f0, B is the head8603023ab5; each was configured and built separately (libstarget, Release, ccache), so each summary line carries its own commit and none is dirty (prxhashes over the whole set: A5897c7a78f86e975, B0a5fe2dfef67c001). This replaces the earlier 2026-11-07 captures, whose two lines both named8a720bde3320.Graphics.Drawms/frameDriver.Draw.preparems/framef9c96f23f0248603023ab599f9c96f23f0248603023ab599The two lines of each pair, as
tools/performance_compare.pyreads them (A, B, A, B):{"commit":"f9c96f23f024","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":4079,"ms":30033.609},"presents":224,"frame_ms":{"p50":133.269,"p90":138.937,"p99":156.360,"max":160.064},"gpu_busy_ms_per_present":33.398,"worker_busy_pct":{"queue worker 0x0":95.056},"top_phases_ms_per_frame":{"Driver.Packet":121.113,"Graphics.Draw":102.771,"Driver.Packet.draw":91.378,"Driver.Draw":90.773,"Driver.DrawFinish":78.483,"Graphics.Draw.draw_and_resource_release":77.972,"Driver.Draw.prepare":71.607,"Driver.DrawFinish.draw_enqueued":42.913},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.375,"events_lost":1208577,"totals_full":false},"draw committer":{"events_full_after_s":11.139,"events_lost":442239,"totals_full":false},"draw finisher":{"events_full_after_s":14.910,"events_lost":264149,"totals_full":false}},"trace":"aps5-trace-f9c96f23f024-18488.json.gz"}
{"commit":"8603023ab599","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":4103,"ms":30047.327},"presents":226,"frame_ms":{"p50":132.359,"p90":137.969,"p99":159.538,"max":174.549},"gpu_busy_ms_per_present":33.473,"worker_busy_pct":{"queue worker 0x0":95.006},"top_phases_ms_per_frame":{"Driver.Packet":119.920,"Graphics.Draw":101.871,"Driver.Packet.draw":89.664,"Driver.Draw":89.048,"Driver.DrawFinish":77.192,"Graphics.Draw.draw_and_resource_release":77.077,"Driver.Draw.prepare":70.016,"Driver.DrawFinish.draw_enqueued":41.387},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.373,"events_lost":1200833,"totals_full":false},"draw committer":{"events_full_after_s":11.227,"events_lost":437413,"totals_full":false},"draw finisher":{"events_full_after_s":15.019,"events_lost":259820,"totals_full":false}},"trace":"aps5-trace-8603023ab599-4264.json.gz"}
{"commit":"f9c96f23f024","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":4069,"ms":30080.770},"presents":231,"frame_ms":{"p50":129.740,"p90":134.007,"p99":141.250,"max":154.310},"gpu_busy_ms_per_present":33.037,"worker_busy_pct":{"queue worker 0x0":95.071},"top_phases_ms_per_frame":{"Driver.Packet":117.353,"Graphics.Draw":99.146,"Driver.Packet.draw":88.009,"Driver.Draw":87.424,"Driver.DrawFinish":75.749,"Graphics.Draw.draw_and_resource_release":75.491,"Driver.Draw.prepare":68.914,"Driver.DrawFinish.draw_enqueued":41.568},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.384,"events_lost":1193114,"totals_full":false},"draw committer":{"events_full_after_s":11.217,"events_lost":437923,"totals_full":false},"draw finisher":{"events_full_after_s":15.347,"events_lost":249237,"totals_full":false}},"trace":"aps5-trace-f9c96f23f024-28812.json.gz"}
{"commit":"8603023ab599","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":4133,"ms":30042.016},"presents":227,"frame_ms":{"p50":131.867,"p90":137.003,"p99":145.960,"max":164.884},"gpu_busy_ms_per_present":33.388,"worker_busy_pct":{"queue worker 0x0":94.735},"top_phases_ms_per_frame":{"Driver.Packet":119.103,"Graphics.Draw":101.231,"Driver.Packet.draw":89.484,"Driver.Draw":88.876,"Driver.DrawFinish":77.212,"Graphics.Draw.draw_and_resource_release":76.525,"Driver.Draw.prepare":70.012,"Driver.DrawFinish.draw_enqueued":41.684},"trace_dropped":true,"trace_dropped_threads":{"queue worker 0x0":{"events_full_after_s":5.376,"events_lost":1205302,"totals_full":false},"draw committer":{"events_full_after_s":11.152,"events_lost":442662,"totals_full":false},"draw finisher":{"events_full_after_s":15.105,"events_lost":255695,"totals_full":false}},"trace":"aps5-trace-8603023ab599-24348.json.gz"}
Change minus main, mean ms/frame: pair 1 -1.1, pair 2 +2.1, mean +0.5 (+0.4 %);
Driver.Draw.prepare-1.6 and +1.1 ms/frame, mean -0.2. The sign flips between the pairs and the spread between the twomaincaptures is 3.9 ms (the two head captures differ by 0.6 ms), so this capture shows no frame-time change that can be told apart from run-to-run variation; it does not reproduce the -6.5 ms/frame of the 2026-11-07 captures (those ran on the earlier base87473937d3;mainitself is now 3 to 10 ms/frame faster in this scene). Per draw, at about 3,040 draws per frame (the replay's count; the boots did not count draws, to keep profiling off): -0.4 us in pair 1, +0.7 us in pair 2, mean +0.2 us, against the 1.2 to 2.2 us the replay measured on the same call; 1.2 us per draw would be 3.6 ms per frame, which this A/B can only resolve if themainspread were smaller than it is. The draw count per frame was not measured in these boots, so the per-draw figures assume the replay's count. The scene is CPU-bound on the draw committer (queue worker 95 % busy in all four captures, GPU busy 33 ms per present of 130 to 134), so a per-draw saving would show in frame time if it were large enough. The allocation count is the provable part of this PR, not the frame time.tools/performance_compare.pyoutput for both pairs and the fulltools/trace_digest.pyoutput of each capture are attached. Traces dropped events (queue worker buffer full after about 5 s), as in earlier captures of this scene; phase totals come from the summary, not the event trace.Deviations from the Performance report form:
APS5_DUMP_FRAMES=80,APS5_DUMP_FRAMES_EVERY=300,APS5_NO_PAD_INPUT=1, the pad input file,APS5_LOG_TIMESTAMPS=1,APS5_TRACE_SUMMARY_EVERY=10andAPS5_ADDRESS_COPY_MAX_MIB=512were set, and a navigation script drove the title to the standing scene; the shader cache directories were per build hash; no boot was repeated and none was discarded except the two warm-ups, which are not samples.Traces and summary lines: https://github.com/chitters2004/AnyPS5/releases/tag/pr-dview-traces.
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