perf(agc): keep depth plane copies resident instead of remaking them on each use #10837
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10837"
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 Raghav314 on 2026-10-25T03:46:24Z.
What
Depth plane copies (the sampleable copies made when a title samples several slices, or an integer view, of a depth surface) were remade on almost every use in Grand Theft Auto V's Fidelity mode. Two causes, one commit each:
DepthPlaneCopybuilt itsOwnedImagewithout recording the memory's size or type, so an evicted copy's block was freed withvkFreeMemoryinstead of being kept, and the next copy allocated fresh memory. The constructor also reset the buffer pool, so its staging buffer bypassed the pool too. The copy now allocates throughOwnedImage::Allocate, like the other texture copies, and leaves the pool alone.[baseArray, last](a newlayerCounton the depthTextureconstructor, previouslyVK_REMAINING_ARRAY_LAYERS), so out-of-range layer indices still clamp to the texture's own last layer. In GTA V the working set drops to 9 copies and 91.5 MiB, and in steady state no copies are made or evicted.Tested
Linux 7.3.0-3-cachyos, NVIDIA GeForce RTX 4090, driver 615.78.08, Release build with SPIR-V tools off. Grand Theft Auto V (PPSA04264) 01.011.001, Fidelity mode, 3840x2160, standing still at the same spot in game. Captured as the Performance report form describes: warm caches (each build had run the scene before and the title was restarted),
APS5_TRACE_SECONDS=110:30and no otherAPS5_TRACE_*orAPS5_PROFILE_*switch, base and change on the same machine in the same session.52a8bed576ce9c6cbd6aSummary lines:
The traces are attached. Digests of both are below.
aps5-trace-52a8bed576e5-1400825.json.gz
aps5-trace-ce9c6cbd6ab6-1401969.json.gz
Focused tests on main and on this PR, same machine and GPU, with
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:agc_driver_depth_plane_buffer_memory_tests,_fill_,_guest_layers_,_partial_store_,_sampling_,agc_driver_depth_compare_copy_tests,agc_driver_depth_copy_draw_tests,agc_driver_depth_surface_from_storage_tests,agc_driver_depth_storage_reuse_tests,agc_driver_image_plane_address_on_cube_tests,agc_driver_depth_bits_guest_memory_tests. All pass on both, no log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-error.New cases in
DepthPlaneGuestLayers.cpp, both failing on main's code:PooledPlaneCopies: two same-shape surfaces alternating under a 1 MiB budget. Main allocates device memory 18 times over three rounds; this PR allocates none.SharedLayerRanges: after sampling layers 0-3 of four depth surfaces, sampling 0-2, 0-1, 1-2 and 0-3 again records no depth surface copies and no plane copy fills, and each view covers exactly its range. Main makes three surface copies and a fill for the 0-2 range.trace_digest: main
seconds 110:30 from present 2635: 71 presents, frame p50 424.3 / p90 443.5 / p99 467.9 / max 467.9 ms, GPU busy 254.0 ms per present
NVIDIA GeForce RTX 4090, NVIDIA 615.78.08, Linux 7.3.0-3-cachyos, 3840x2160, commit
52a8bed576, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 1402.3, Driver.Packet.memory_wait 876.8, Driver.WorkerWait 620.7, Driver.WorkerWait.idle_and_completion_poll 620.7, Driver.Packet.dispatch 406.6, Driver.Dispatch 374.7, Resources.Complete 291.9, Vulkan.Dispatch 291.0, Vulkan.Dispatch.shader_resources 289.8, batch 253.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest: this PR
seconds 110:30 from present 2782: 105 presents, frame p50 285.9 / p90 305.4 / p99 330.1 / max 347.1 ms, GPU busy 230.4 ms per present
NVIDIA GeForce RTX 4090, NVIDIA 615.78.08, Linux 7.3.0-3-cachyos, 3840x2160, commit
ce9c6cbd6a, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 873.3, Driver.Packet.memory_wait 556.0, Driver.WorkerWait 491.7, Driver.WorkerWait.idle_and_completion_poll 491.7, Driver.Packet.dispatch 251.4, Driver.Dispatch 231.7, batch 230.4, Recorder.WaitSerial 104.5, Driver.Packet.draw 59.4, Driver.Draw 59.1
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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 MarcZX10 on 2026-10-25T03:54:18Z.
Review: APPROVED
Reviewed head
ce9c6cbd6ab65fa81354cc9ed275d9181a3ca053. The copy now gets image memory throughOwnedImage::Allocate, so release returns it to the device pool; the cache keeps one copy sized for the largest layer request and creates views with the requested array range. The new tests cover memory reuse after eviction and reuse across smaller layer ranges. I syntax-compiled the changedDepthSurface.cpp,Texture.cpp, andDepthPlaneGuestLayers.cppusing this project's Linux compile flags; all passed. Conventions, intake, labels, and report checks pass. Product build/test CI was skipped. The paired RTX 4090 trace and validation results in the PR body are detailed and appropriately scoped; I could not run the Vulkan tests on this host because its CPU lacks the runtime's required instruction set. I found no blocking code issue.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-25T04:34:44Z.
Review: COMMENTED
One merge-order clarification after reviewing #10844: its PR body includes a second GTA V comparison made from this head plus #10844's commit (
136d978b27), while correctly saying #10844 applies tomainindependently. That makes the second measurement useful combined evidence, but it does not make this PR depend on #10844. Please keep the merge-order description explicit if either PR lands first: the combined result is a cherry-pick composition, not a required dependency or a measurement of this head alone. I found no code blocker in this review; the existing exact-head approval remains applicable.