perf(agc): clear the mirror of a depth plane instead of dispatching the UAV clear over it #7449
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7449"
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 AlxcBTW on 2026-10-18T07:01:11Z.
What
#7178 left out the two whole-plane copies around the 15-word 8x8x1 image clear kernel when it clears a depth plane, but the dispatch itself was still recorded: a compute pass that stores one colour dword to every texel of the plane's colour mirror (
DepthSurface::Storageno longer fills the mirror,StoreBackclears the depth image instead). At the title that is 64 MiB of stores per clear (a 16384x2048 plane at 16 bits), and up to 128 MiB on the larger planes in gameplay, that nobody reads.VulkanDevice::recordDispatchnow recordsvkCmdClearColorImageon the mirror in place of the dispatch when that dispatch is one of the clears #7178 takes, that is, when all of this holds:Driver::dispatchmatched the kernel (MatchStorageImageClear) over a registered depth surface and installed theDepthPlaneClearscope on the recording thread, and the dispatch is direct (no indirect arguments);DepthSurface::SkipsClearDispatch), the clear covers the whole plane, the mirror has the view's address, format, tile mode, dimension and the plane's extent, and the colour dword is still the one that was matched (the checksStoreOverwritealready made, now one functionOverwriteOfthat both use; the only new condition is that the mirror's width and height equal the plane's, whichStorageViewMatcheshas already ensured when the mirror is made);ClearColorForTexelgives an exact clear value for the colour in the mirror's format.Then the pre-dispatch barrier is recorded (never merged away) with the transfer stage as its destination, the clear is recorded in place of
vkCmdDispatch, and the trailing barrier also covers transfer writes. Everything else around it is as before: the descriptor set and pipeline are bound, the GPU timing and the notes of written images are made, andMarkGpuWritesmarks the mirror as written.Storagestill leaves out the copy-in andStoreBackstill replaces the copy-out by a clear of the depth image (both #7178, unchanged), and a pending fill of #7131 is applied inStoragebefore any of it (ApplyFastClear), so nothing about fills changes. A dispatch that does not qualify is recorded as before.The path is on by default.
APS5_NO_DEPTH_CLEAR_DISPATCH_SKIP=1records the dispatch again (like the otherAPS5_NO_*switches: set at all means off). The entry "Reused depth storage" indocs/dev/debt/libSceAgcDriver.mdsays so, anddocs/dev/ENVIRONMENT.mdhas a row forAPS5_NO_DEPTH_CLEAR_DISPATCH_SKIP.Why the result is the same bytes:
cto every texel its threads cover. #7178's matcher fixed the kernel's words, the group sizes and the registers, and the whole-plane condition makes that every texel of the mirror (the T# extent is the plane's extent). So after the dispatch the mirror is the constantstore(c), and a clear of the whole image to the value that stores the same bits writes the same bytes.ClearColorForTexelfor the mirror's format, which refuses NaN and denormals. The values the depth HLE takes are 0 or 1 through a 16-bit unorm view, 0 or 0xffff through a 16-bit uint view, and 0 or a normal float in (0, 1] through a 32-bit float or integer view; for these a device clear and the image store of the kernel give identical bytes (unorm 1.0 and 0.0 are 0xffff and 0 for any rounding, integer and float 32-bit values are bit copies).-0.0is read as raw 0 by #7178 and clears to 0.MarkGpuWritesruns as before), so guest memory gets the same bytes. The depth image is cleared exactly as #7178 does, inStoreBack.Limits: equivalence to console behaviour is not measured on console hardware. The lab verify mode that compared both paths on a device is not in this PR; the argument above and the test below are.
Tested
main(bad09497c, base0c6a5bd59) and the ENVIRONMENT.md row, at d4d6c1048 (the PR headfa32376e3plus the CI scaffolding commit; run 39677504672, ctest regexagc_): 876 of 876 passed with 60 of them skipped for lack of a device capability, among themagc_driver_depth_clear_hle(passed, 2.26 s, not skipped). Not run on Windows.agc_driver_depth_clear_hle(tests/execution/DepthClearHle.cpp) has four new cases, each run with the switch on and off on the same sequence of clears and the same expectations: a 64x32 D32F plane (producer 0.5; clears to 1.0 and 0.25 full, 0.75 on the left half, 2.0 and 0.125 full) and a 64x32 D16 plane (an R16 unorm view cleared to 1.0, 0.0 and 0.5). After the clears the depth tests of the harness' triangle must pass as the value says, the guest memory after the flush (the mirror's write-back) and the depth image (read back texel by texel through the mirror) must hold the cleared value in every texel, and the counters must say which dispatches were left out: 3 of 5 for the 32-bit plane (not the half plane, not 2.0) and 2 of 3 for the 16-bit plane (not 0.5), with the mirror clears adding up to 3 x 8 KiB and 2 x 4 KiB, and 0 with the switch off. The 16-bit case skips itself, as the existing 16-bit case does, on a device without the format. The case with the switch off is the comparison with the dispatch path: both modes must end with the same bytes.lab/clear-kernel, on an older base than this PR: the lab stack best10, a run of lab changes of which this is the only difference between the arms), not on this PR's head; the PR head differs from it by the switch (the lab version was behindAPS5_LAB_CLEAR_KERNEL), the sharedOverwriteOfcheck with the width and height compare, the colour re-read when the dispatch is replaced, and the lab verify mode that is not in the PR. Job 99,APS5_PROFILE_GPU=1on all rows, arm a without the change, arm b with it, trace digest figures:At the title the mean FPS is 9.31 without and 9.93 with the change (+0.62, +6.7 %) and the mean GPU busy per present 77.5 ms against 72.2 ms (-5.3 ms); both rows of each arm agree, which makes the title figure the one I claim. The gameplay rows are memory-noisy (this machine has 31 GiB and the spread inside arm a alone is 4.7 to 8.6 FPS): mean FPS 6.57 without and 6.03 with, mean GPU busy 73.5 ms against 63.2 ms; I claim nothing for gameplay from them. Counters at the end of the b rows (cumulative per process): the clear was taken for 1546 of 1546 and 1534 of 1534 clear dispatches over a depth plane at the title and for 1685 of 1685, 2250 of 2250 and 1580 of 1580 in gameplay, with no decline for coverage, view or format. The verify row (gameplay, kernel recorded, then a copy of its result cleared and compared with it on a sample) compared 201 of 1493 clears texel by texel (every texel of each plane, 16,777,216 to 67,108,864 per plane), with 0 differing clears and 0 differing texels; there is no verify row for the title. Pictures were not compared. Traces are on the lab machine and I can attach them on request.
python3 tools/check_conventions.py --base origin/mainpasses. Based on0c6a5bd59(merged into the branch).tools/pr_overlap.pylists #6146 (the "Reused depth storage" line of the debt document) and #7390 (the lines ofrecordDispatcharound the dispatch); neither implements the same function.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 LeandroLP23 on 2026-10-18T16:33:36Z.
AMD on Windows: the tests this PR names pass on an RDNA 3.5 GPU.
Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release.
main6efb7261bwith this PR (17efa3696) merged, together with #7296, #7446, #7377, #7445, #6708, #6748, #6785, #6706, #6613, #7391, #7489, #7484, #7514. They were built once, so the result is for the combination; each merge was clean.agc_driver_depth_clear_hle: pass, 3 runs of 3.agc_*test on the combined build: 713 of 716 pass. The 3 that fail,agc_driver_host_import_lifetime,agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl, fail the same way on unchangedmainhere, so none comes from these PRs.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-18T19:51:59Z.
Thanks, the equivalence argument and the on/off cases are convincing. One robustness point in
recordDispatch:PlanDepthClearDispatchSkipandRecordDepthClearDispatchSkipeach takesurfacesMutex()and evaluateSkipsClearDispatchseparately, and the leading barrier (with the transfer stage as its destination) is recorded between them. If the second evaluation disagrees with the first,RecordDepthClearDispatchSkipthrows "the mirror of a depth clear dispatch belongs to no depth surface any more". That can happen if the colour dword in guest memory changes in between, or another thread retires the surface or replaces its mirror. That makes a guest-visible race an abort, and the PR text and the debt line say "a changed value keeps the dispatch", which isn't what happens after the plan.Could the plan return what the record needs: the surface (or the mirror plus its
VkClearColorValue) decided under one lock, so the record doesn't re-decide? Holding the lock across both, or having the record fall back to the dispatch, would also work, but the fallback would need the compute-stage barrier. Then the only re-read of the colour is the one before the plan, and the debt line can say so.Imported from boykopovar/AnyPS5. Originally posted by savvaniss on 2026-10-19T06:36:05Z.
Intel and AMD Windows data:
agc_driver_depth_clear_hlepasses with this PR on an Intel UHD 770 and an AMD RX 9070 XT.Windows 11 Pro 26300, WinLibs GCC 15.2.0 r7, Release, every execution test built,
ANYPS5_NO_SHADER_CACHE=1, serial CTest. Intel UHD Graphics 770 (8086:a780), driver 32.0.101.7088. AMD Radeon RX 9070 XT (1002:7550), driver 32.0.31041.1004, withVkCacheemptied first. This head17efa3696merged intomain07377573f.agc_driver_depth_clear_hleThe test files don't build on
mainwithout the rest of the PR, so there is no before-run.This is a correctness check only; I measured no speed.
I also ran full CTest with this PR and the 13 other open AGC and shader PRs I tested in the same batch merged together (#7668, #7659, #7504, #7432, #7426, #7413, #7480, #7465, #7466, #7464, #7489, #7673, #7560). Neither GPU showed a failure beyond
main's own: the five image-table tests (#6647) andagc_driver_sample_multisample_target(#6957) on the UHD 770, andagc_driver_layered_volume_vertex_no_gpl(#4768) on the RX 9070 XT.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T09:15:32Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One conflict inVulkanDevice.cpp: your mirror-clear skip kept beforemain's newer indirect-buffer dispatch form. OneENVIRONMENT.mdrow added forAPS5_NO_DEPTH_CLEAR_DISPATCH_SKIP.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; the depth tests pass (25/25); conventions pass; full suite green apart from the four knownmainregressions (#5444 Mesa, #7584 BDA, #7766, #7784), none from this PR.To pick it up:
Head is
9e09b06cb.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T21:16:59Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:57:47Z.
Review: COMMENTED
Three gaps in the evidence, all of them things the AGC rules ask for.
1. The speed numbers are not from this change. The Minecraft Dungeons II rows are measured on
lab/clear-kernel924e2474c, on an older base, behindAPS5_LAB_CLEAR_KERNEL, and the PR text itself lists what differs from the PR head (theOverwriteOfwidth/height compare, the colour re-read at dispatch replacement, the verify mode). All rows also run withAPS5_PROFILE_GPU=1. The only figure claimed is the title row (+6.7 % FPS, -5.3 ms GPU busy) from two runs per arm; the gameplay rows go the other way (6.57 to 6.03 FPS) and are set aside as noise. Please givetools/trace_digest.pysummaries ofmainand of this PR head from the same machine and scene, without the profile switch.2. No validation-layer run on a real GPU.
RecordMirrorClearaddsvkCmdClearColorImageon the mirror inVK_IMAGE_LAYOUT_GENERAL, with newTRANSFERstage masks in the pre and post barriers inrecordDispatch. Nothing in the diff touches the mirror's usage flags, so isVK_IMAGE_USAGE_TRANSFER_DST_BITalready set on every storage mirror thatSkipsClearDispatchcan accept? The 876 lavapipe tests ran withoutVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, and the NVIDIA runs are game rows only ("GPU tests not run there"). Please run the focusedagc_driver_depth_clear_hletests onmainand on this head withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationon one GPU, and show no newVUID-lines.3. Per-dispatch lock.
DepthClearDispatchSkipActive()checks the thread-local scope first, so ordinary dispatches stay cheap, but a matching clear takessurfacesMutex()and scans every surface twice (PlanDepthClearDispatchSkip, thenRecordDepthClearDispatchSkip), withSkipsClearDispatchrecomputingOverwriteOfandClearColorForTexelin both. Resolving the surface once in the plan step and handing it to the record step would avoid the second scan.Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T20:17:14Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change based on the code and test evidence reviewed; the author’s reported CI run passed, but I did not run checks locally.
What I ran
Reviewed head
fa32376e3a6562ea19b32fd5f9d4b6bf43ad5f1f. Read the prepared description, commits, manifest and diff, plus targeted source and test ranges throughrepo_read.py. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The changed files listed in
manifest.jsonwere all included in the review bundle; I read the relevant changed functions and test sections, not every line of every changed file. The reported lavapipe CI, Windows behavior, console equivalence, and performance results were not independently verified. Excluded files: none reported in the review bundle.To get this to a good state
Nothing is required.
Pull request closed