fix(agc): drop stale depth planes a uniform fill overwrites #10882
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10882"
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 orezraey on 2026-10-25T07:11:56Z.
What
A depth target drawn on the host leaves its plane stale: the results live in the host depth image and are stored to guest memory when something reads that memory. A uniform buffer fill over the whole plane (a depth clear done as a memory fill) is such a read:
storeBufferFillcallsStorageTexture::FlushPending, which callsFlushDepthPlanes, so the stale plane was stored in full, and the fill then overwrote every byte of it. DEATHLOOP (PPSA01670) clears two 3840x2160 D32 planes this way every frame, 32 MiB each.DiscardFilledDepthPlanes(new, called bystoreBufferFillfor uniform fills before its flushes): a stale single-sample depth plane that the fill covers entirely, with a valueNoteDepthMetadataFillwould turn into a plane clear (a depth in 0..1, or a D16 pair; no HTILE fill over the target), drops its stale units instead of storing them and notes the plane clear itself (NotePlaneFill), so the host image is cleared to the filled value at its next use. Partial fills, fills of other values, planes that are syncing, and fills that a native multisample colour target absorbs (they never reach guest memory) are stored as before.FlushDepthPlanesdoes, so a later read of a stencil plane still stores it after a fill discards a depth plane.agc_driver_depth_plane_fill_discardcovers a stencil-only surface beside the discarded plane and a surface with both planes stale.enqueueDmaPacket) does not reachpreparePacketMemory, soNoteDepthMetadataFillis not called for those fills.planeFillDepthis the plane test bothNoteDepthMetadataFilland the drop use, so they cannot disagree.overlapsStalePlanecheck, without the surfaces lock.agc_driver_depth_plane_fill_discard: a stale 384x200 Z_X plane is kept by a shorter fill, a fill starting past it, a fill of -1.0 and a NaN fill; a fill of 1.0 around it drops it with no store counted, and a draw at 0.5 then passes LESS (the plane was cleared to 1.0) with noNoteDepthMetadataFillcall; an exact fill drops it once; a fill of 0.0 makes the same draw fail LESS. It then callsDriver::storeBufferFillitself (throughDriverTestAccess) with a fill of 0.75 over a stale plane: no store is counted, the plane holds 0.75, a draw at 0.5 passes LESS and a later read stores nothing. With thestoreBufferFillcall removed, that part fails with "the driver's fill of 0.75 over the whole stale plane stored the plane first".This PR makes no frame-time claim; see the captures below.
Tested
Windows 11 Pro 26200, AMD Ryzen 7 9700X, NVIDIA GeForce RTX 5070 Ti (driver 616.64), WinLibs GCC, Release. Head
591da8f4df, which containsmaine67cc81869.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "depth|fill|storage|stencil" -V, 3 runs at591da8f4dfand 1 ate67cc81869: 99 of 102 pass each time on the head and 98 of 101 onmain, 0VUID-and no missing-layer message in any log. The extra test isagc_driver_depth_plane_fill_discard. The 3 not counted were not built for those runs (agc_driver_stencil_plane_memory,guest_np_cpp_web_api_title_cloud_storage,guest_system_service_usb_storage);agc_driver_stencil_plane_memorywas then built and passes 3 of 3 on the head with the same variables, 0VUID-.DiscardFilledDepthPlanes: the stencil-only case with "a read of a stencil-only surface's plane stored nothing after another surface's depth plane was discarded", and, with that case removed, the same-surface case with "a read of the stencil plane stored nothing after its surface's depth plane was discarded".tools/check_conventions.py --base origin/main: passes.agc_driver_depth_plane_fill_discard_testsbuilds at591da8f4df; the test skips 3 of 3 runs and fails withANYPS5_REQUIRE_VULKAN=1, so its GPU paths did not run on Linux here.Earlier results at
aa144ce8f5onmain6c7a3256f2:ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ctest --test-dir build -R "depth|fill|storage" -V, 3 runs ataa144ce8f5: 80 of 81 pass each time, 0VUID-, no missing-layer message. The failure isagc_driver_depth_plane_partial_store("repeated lookups of the first layer of an unchanged array proved no refresh"), which fails the same way onmain(c8d34aa8f4: 79 of 80, 0VUID-). The extra test isagc_driver_depth_plane_fill_discard.ctestataa144ce8f5: 2305 tests; the failures areagc_driver_depth_plane_partial_store,agc_host_import_cut_lifetime(both fail the same way onmainhere) andselect_tests(a temp-directory symlink error intools/tests/test_select_tests.py).tools/check_conventions.py --base origin/main: passes.DEATHLOOP (PPSA01670), the beach at the start of the game (sprint and dodge tutorial), same machine and scripted input.
maincannot reach this scene yet, so both builds aremain+ #10414 + #10507 + #10743 + a port of #6192, without (based26dce2835) and with (change88b55a05ee) this PR's first three commits. The last commit (aa144ce8f5) only keeps planes under fills that a multisample colour target absorbs, which DEATHLOOP's depth clears are not; it was not re-captured. Captures as the Performance report form says:APS5_TRACE_SECONDS=840:60only, log not redirected, runs alternating base and change. The traces and the summary lines are assets of this release on my fork.The frame time does not change beyond run-to-run noise: this scene is CPU-bound. GPU busy per present is 1.3 to 2.1 ms lower in each change run than in the base runs.
Behaviour count, from separate runs with
APS5_PROFILE_DRAW=1(not the captures above): the[storage]lines reportdepth plane storewrite-backs of about 111 to 128 GiB per 330 s run on the title menus with the base build and none with the change. With temporary caller logging added locally (not in this PR), every one of those stores came fromstoreBufferFill(reasonbuffer fill) over the two 0x1fe0000-byte planes. The menus look the same with both builds.aps5-summary.jsonllines of the six runs, in run orderChecklist
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)DepthSurface.hppandDepthSurface.cpplines where this PR addsDiscardFilledDepthPlanes(merge order only); #9533 and #9717 have merged