fix(agc): flush depth planes only over the layers an array target's lookup refreshes #9443
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9443"
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 janzezno on 2026-10-21T22:20:00Z.
What
Pulse (PPSA99993, ps5-opengl) runs its title menu at 17 FPS on
main, with the GPU busy 41 ms per frame on a scene that needs under 1 ms. Every color draw stores the game's depth plane to guest memory and waits for it.The cause is the leftover half of the phantom-slice problem from #6189. ps5-opengl declares each color target as a 2-slice array and only renders slice 0, and Pulse's depth buffer sits in the memory of the unused slice 1 (color target
0x255600000, depth plane0x256600000, 16 MiB apart, each slice 8.4 MiB). #6202, carried by #6718, made the target's lookup refresh only the layers the draw uses, which removed the per-draw whole-image uploads. ButcachedStorageTexturestill runsFlushDepthPlanesover the whole declared array before the lookup. That line came in with #7154 (@DavidSamir bisected the regression to its merge50e0624d7in this comment). So each draw into slice 0 stores the depth plane over slice 1, which the previous draw left stale on the GPU, then syncs on that store. Onmain0c6a5bd593, 59,819[flush] image 0x256600000+0x870000 for depth plane storelines were logged in 35 s, one per draw. A 6 sperfprofile (taken on thatmainwith #9402, which does not touch this path) had a third of the process's CPU samples underFlushDepthPlanescalled fromCachedStorageLayers.With this change, a layered lookup (
CachedStorageLayers) no longer flushes over the whole array incachedStorageTexture.RefreshLayersflushes the depth planes itself, before anything can return early:refresh(first, last). That has to come first:refresh()returns early when its refresh proof holds, and the proof only looks at guest memory, which a depth plane the GPU just wrote has not changed yet.Refresh()flushes the whole image's depth planes first. That covers the same proof shortcut, and a full refresh that hands over DCC clear keys, which skipsFlushPending.FlushPending(..., "storage image creation").Lookups without layers, written lookups and
APS5_NO_TEXTURE_CACHEkeep the whole-range flush.agc_driver_depth_plane_partial_storegains a case: a cached 3-layer array image with a GPU-written depth plane over its second layer, looked up with the GPU mutex held as the draw path does. Where guest memory is write-watched, repeated lookups first take a refresh proof (the test requires one), so the lookups after the depth write go through that shortcut.mainthis fails witha lookup of the first layer of an array stored the depth plane over its second layer.refresh(), this fails under the refresh proof witha lookup of the first two layers of a three-layer array did not store the depth plane over its second layer.The lookup imports the array. Where the host import probe finds that imports lose their write protection (RADV, and lavapipe as @jotitadev found), imported ranges are compared instead of watched, so the refresh-proof half is skipped there; only drivers that keep imports watched (NVIDIA) would run it. So the same test is also registered as
agc_driver_depth_plane_partial_store_unimported, withAPS5_NO_HOST_IMPORT=1, asagc_driver_array_layer_target_cpuis. Without host imports the guest memory stays in the write watch on any driver, so both write-watched cases run there. ForcingAPS5_WRITE_WATCH_IMPORTS=watchinstead would not be sound on those drivers, since a GPU read clears the protection.Overlap:
pr_overlapon1e20650e84reports no pull request it could compare. #6743 adds a test registration next toagc_driver_array_layer_target_cpu; the new registration sits before that block, so the two do not touch. Of the 80 pull requests it could not compare, two change these functions: #6202, whose change is already onmainthrough #6718, and #6194, which counts evictions in the eviction loop ofcachedStorageTexture, away from the flush line this change edits.Tested
Arch Linux, AMD Radeon RX 7900 GRE (RADV NAVI31, Mesa 26.2.5), Ryzen 5 7500F, Release, on
main1e20650e84.Pulse PPSA99993 (homebrew catalog, sha256
9103d3d6…), title menu, no input, run withtools/title_run.pyfrom #7264, trace window seconds 15–25 after the first present (APS5_TRACE_SECONDS=15:10):mainSummary lines:
tools/trace_digest.pyof both traces (attached):main
seconds 15:10 from present 259: 172 presents, frame p50 58.3 / p90 59.1 / p99 60.0 / max 64.0 ms, GPU busy 41.2 ms per present
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit
1e20650e84, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 54.5, Graphics.Draw 54.4, Graphics.Draw.draw_and_resource_release 54.2, Driver.Packet.draw 50.1, Driver.Draw 50.0, Driver.Draw.draw_enqueued 49.5, Recorder.Sync 47.4, batch 41.2, Driver.EndSubmission 1.9, Driver.WorkerWait 1.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
this PR
seconds 15:10 from present 900: 600 presents, frame p50 16.7 / p90 16.7 / p99 16.7 / max 16.9 ms, GPU busy 0.6 ms per present
AMD Radeon RX 7900 GRE (RADV NAVI31), radv Mesa 26.2.5-arch1.1, Linux 7.2.11-arch1-1, 1920x1080, commit
26f6779362, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): VideoOut.Flip 15.8, VideoOut.Flip.vblank_wait 15.4, Driver.WorkerWait 13.2, Driver.WorkerWait.idle_and_completion_poll 13.2, Recorder.Sync 1.2, Driver.Packet 1.1, Driver.EndSubmission 0.9, Graphics.Draw 0.6, Graphics.Draw.draw_and_resource_release 0.6, batch 0.6
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Also tested:
ctest --test-dir build -R 'agc|shader|recompiler' -V -j6withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, onmainand on this change: 970 of 971 and 971 of 972 (the new_unimportedentry), with theagc_driver_tessellationsegfault (#5444) on both. Both logs have the same two VUIDs with the same counts (VkPipelineColorBlendStateCreateInfo-pAttachments-00605×26,VkWriteDescriptorSet-descriptorType-00337×32), so the change adds no validation errors, and neither log reports the validation layer missing. A first run of the change also failedagc_shader_disk_cache_large_file: its 2 GiB write failed on a nearly full tmpfs/tmp. After freeing space the whole suite was rerun with the result above.1e20650e84: with only the test onmain, both entries fail at the lookup of layer 0. With this change but without the flush before the scopedrefresh(),agc_driver_depth_plane_partial_storepasses (it reports both write-watched cases as not exercised) and_unimportedfails at the lookup of layers 0 and 1. With this change both pass, also withAPS5_DRAW_PIPELINE=1, whose epoch proofs inStorageTexture::refresh()are new onmainsince the previous base; the flush runs before that check.0c6a5bd593: the DEMO song, entered withtools/pad_input.py(down, cross), ran at about 38–40 presents/s onmainand 60 with this PR, with notes, sabers, score and combo rendering the same; the last menu frame was identical pixel for pixel; and the other ps5-opengl titles were unchanged over 40 s per side: OliSe Player PPSA01153 (60 FPS, 0.1 ms GPU) and PS5MC PPSA99420 (60 FPS, 5.3 ms GPU), with no depth-plane stores on either side, and OpenNOW PPSA99082, which idles on its sign-in screen and presents only on input.python3 tools/check_conventions.py --base upstream/mainpasses.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 janzezno on 2026-10-21T22:22:02Z.
Traces of the two windows whose summary lines are in the description, Pulse PPSA99993 title menu, seconds 15–25 after the first present (
APS5_TRACE_SECONDS=15:10), RX 7900 GRE (RADV, Mesa 26.2.5):main(0c6a5bd593): aps5-trace-0c6a5bd5938f-790477.json.gz9fa9b10a5b): aps5-trace-9fa9b10a5b08-840854.json.gzImported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:39:24Z.
Review: DISMISSED
The implementation moves the flush to the layer ranges actually refreshed and preserves full-range handling for whole refreshes, written lookups, missing/unsafe layer metadata and
APS5_NO_TEXTURE_CACHE. I checked the same-file overlap warning with #9012: itsShaderResources.cppedits concern periodic template audits at separate hunks. The PR’s before/after Pulse traces and summaries are attached, and its 31-test same-GPU main/change Vulkan run confirms the validation layer loaded and no newVUID-errors; the extra write-watch run documents the branch that CTest cannot exercise by default. The reported 3-game checks and unchanged titles are clearly scoped.The tested head is based on
0c6a5bd593, while current main is110a18ba01. Please update the branch and refresh the focused validation comparison, trace pair, conventions and overlap check against current main before treating the current-main checklist as satisfied. Hosted full product jobs are skipped. I did not run local performance or GPU tests.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T07:52:13Z.
Review: COMMENTED
Ran this on NVIDIA and lavapipe. One thing worth knowing: on lavapipe, which is what CI uses, the second new assertion never runs.
Setup: Ubuntu 26.04, GCC 15.2, Release, head
9fa9b10a5merged ontomaind6eafa54d.ANYPS5_GPUpicks the device,ANYPS5_REQUIRE_VULKAN=1, ctest-j1.DepthPlanePartialStore.cpp):agc_driver_depth_plane_partial_storefails on both GPUs witha lookup of the first layer of an array stored the depth plane over its second layer.^agc.*(depth_plane|array|storage)(40 tests) also passes on both.refresh(): I took the PR and removed only the newFlushDepthPlanescall beforerefresh(firstLayer, lastLayer)inRefreshLayers. On the 3070 the test then fails witha lookup of the first two layers of a three-layer array did not store the depth plane over its second layer. On lavapipe it passes 3 of 3, and the log showsguest memory is not write-watched here: lookups of array layers through a refresh proof are not exercised, plus the matching skip line for the older partly-stored-plane case. SoWriteWatched()orWatched()over the array is false on that device, and the refresh-proof branch is skipped.So the test does guard both halves of the fix, but the second half only on a device where guest memory is write-watched (here, the 3070). The Linux CI job runs the GPU tests on lavapipe. If its lavapipe behaves like mine, CI would not catch someone removing that flush.
GPUs tested: NVIDIA GeForce RTX 3070 (driver 595.99.02), Mesa lavapipe 26.0.3 (LLVM 21.1.8), Ubuntu 26.04
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by janzezno on 2026-10-22T15:23:53Z.
Traces of the two windows whose summary lines are in the description, Pulse PPSA99993 title menu, seconds 15–25 after the first present (
APS5_TRACE_SECONDS=15:10), RX 7900 GRE (RADV, Mesa 26.2.5), onmainb7d1d47a5f:main(b7d1d47a5f): aps5-trace-b7d1d47a5f9f-61358.json.gzthis PR (
593daedbc7): aps5-trace-593daedbc702-93127.json.gzImported from boykopovar/AnyPS5. Originally posted by janzezno on 2026-10-22T15:24:16Z.
@jotitadev thanks, that's a real gap, and not only on lavapipe: RADV here skips that branch too. The lookup imports the array, and where the import probe reports that host imports resolve write protection (RADV here:
4 of 4 scratch pages written after a GPU read), imported ranges are compared instead of watched, soWatched()is false over the array. Your 3070 keeps imports watched, which is why only it ran the refresh-proof half.Forcing
APS5_WRITE_WATCH_IMPORTS=watchis not sound on those drivers, since a GPU read clears the protection. That is also why the older case failed under it in the description. So the test now also runs asagc_driver_depth_plane_partial_store_unimported, withAPS5_NO_HOST_IMPORT=1, the same wayagc_driver_array_layer_target_cpudoes. Without host imports the guest memory stays in the write watch on any driver, so both write-watched cases run and neither skip line is printed. On RADV, on currentmainb7d1d47a5f:mainplus only the test: both entries fail witha lookup of the first layer of an array stored the depth plane over its second layer.refresh():agc_driver_depth_plane_partial_storestill passes (both skip lines), while_unimportedfails witha lookup of the first two layers of a three-layer array did not store the depth plane over its second layer.If you have a moment, could you run
_unimportedon lavapipe? It should print neitherguest memory is not write-watched hereline there.@MarcZX10 rebased onto
b7d1d47a5f(no conflicts); the head is now593daedbc7. The validation-layer comparison, the Pulse trace pair (attached above),check_conventionsandpr_overlapwere redone on that base, and the description is updated with the results.pr_overlapalso showed #6743 adding a test registration where the new one first went, so the new one now sits beforeagc_driver_array_layer_target_cpuinstead.Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-23T02:06:46Z.
Review: COMMENTED
Apple GPU / MoltenVK run of
593daedbc7, following up on my lavapipe note. MoltenVK keeps host imports watched, as NVIDIA does. So here the refresh-proof half runs in both registrations, and both catch the missing flush beforerefresh(). (I couldn't rerun lavapipe for_unimportedon this machine.)Machine: Apple M2 Max, macOS 27.2, x86_64 under Rosetta 2. Vulkan loader + MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), and again against MoltenVK main + SPIRV-Cross #2704. Release,
BUILD_TESTING=ON.Base/method: PR #8658
feat/macos-port@c5fa39620a(currentmainplus the macOS port), notmain, becausemaindoes not build on macOS. This PR's diff at593daedbc7(git diff merge-base..head -- . ':!docs') applied cleanly. Full rebuild before each stage.Import probe on this device, both drivers:
With this PR (
--repeat until-fail:3, both drivers):agc_driver_depth_plane_partial_storeandagc_driver_depth_plane_partial_store_unimportedpass 3/3. In-Voutput, neither one printsguest memory is not write-watched here. (For this stage the tree also had #7705 and #9717/#9533. They touch other tests.)Mutation (this PR alone, with the
FlushDepthPlanes(scopeBegin, ...)line beforerefresh(firstLayer, lastLayer)removed fromRefreshLayers): both registrations fail on both drivers:So on Apple, unlike RADV and lavapipe, the original
agc_driver_depth_plane_partial_storecatches it too._unimportedcatches it the same way.Full
^agcsuite (877 tests), both drivers: the same failures as the #8658 base for this PR's tests. The other new failures in that tree come from #7705's and #9533's tests, which I reported on those PRs.GPUs tested: Apple M2 Max (MoltenVK 1.4.2; and MoltenVK main + SPIRV-Cross #2704).
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.