perf(agc): order a storage flush behind its GPU writer when the write-back is a GPU copy #15569
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15569"
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 milescoviello on 2026-11-03T19:13:19Z.
What
A label's readback store (
StoreReadbackBeforeLabel) and a storage refresh (StorageTexture::refresh) flush the pending storage images over their range before they go on.FlushPendingwaited on the CPU for the images' GPU writers first. When every flushed image lives in a host import, its write-back is a copy the recorder records into the import. That copy runs after the image's writer and before anything recorded later, including the label, so the wait adds nothing to the order. Ghost of Tsushima (PPSA02225) paid about 55 ms for it once a frame. A sampled 4K storage surface overlapped six pending images of a transient heap, and its refresh drained the whole recorder.How
StoreReadbackBeforeLabeland an eligiblerefreshset a thread-local scope. Inside it,FlushPendingskips the wait for the GPU writer when the recorder is active, the call is not in a completion, and every image it flushes has a host import (HostImportFor). The write-backs are then recorded behind their writers as before.APS5_NO_FLUSH_GPU_ORDERED=1andAPS5_NO_REFRESH_GPU_ORDERED=1restore the waits.Tested
agc_driver_label_ordered_flush: a computeimage_storeinto an imported 128x128 R32UI surface, a small storage image (64 KiB, the size a label stores before it), followed directly by aRELEASE_MEMlabel while the store is still pending on the GPU. When the label lands, the stored texels must be in guest memory. 8 runs per test; the test checks that the surface is small.b6007f69a9,StorageTexture::TakeOrderedSkipCounts()counts the skips taken, and the tests check them:agc_driver_label_ordered_flushcovers the label half (at least one flush skip) and the refresh half. For the refresh half, a 256x64 linear R32UI view of the block reads after a 128x128 tiled store over the whole block is left pending. The view isn't an alias, so its refresh flushes the store, and every texel read must equal the stored value and guest memory. The half requires at least one refresh skip.agc_driver_label_ordered_flush_disabled(APS5_NO_FLUSH_GPU_ORDERED=1 APS5_NO_REFRESH_GPU_ORDERED=1) and_unimported(APS5_NO_HOST_IMPORT=1) run the same scenarios. They require zero skips and the same results.agc_driver_ordered_refresh_failureinjects aFlushPendingfailure inside an armed refresh (SetFlushFailureForTest). It checks that the flag is cleared on the thread and that the next flush waits.Recorder::Syncper frame fromStorageTexture::refresh -> FlushPending(APS5_TRACE_LONG_SYNCS).main086c0686c8against the samemain+ this PR, measured by @TripyFox (comment). Windows 11, RTX 5090 (NVIDIA 621.01), 3840x2160, warm shader cache, three interleaved 240 s pairs withAPS5_TRACE_SUMMARY_EVERY=10 APS5_TRACE_BENCH=1:mainrun is slower than the slowest PR run.APS5_NO_FLUSH_GPU_ORDERED=1gives back most of it;APS5_NO_REFRESH_GPU_ORDERED=1gives back about 1 ms.2da15973cegives the same size: p50 -6 ms in every compared interval.mainb11c7bf84fagainstb6007f6merged onto it (comment). OnlylibSceAgcDriver.prxdiffers between the builds. The setup was 240 s runs with a warm cache, two interleaved rounds, and medians of the 10 s intervals from 40 s to 240 s, withAPS5_TRACE_SUMMARY_EVERY=10 APS5_TRACE_BENCH=1:main, round 1main, round 2tools/performance_compare.pyon the two summary lines below (interval from 100 s, round 1): frame p50 -8.3 ms (-9.1 %), p99 -22.9 ms, GPU busy -0.6 ms. The only configuration difference it lists iswindow.first_present.main:.json.gztraces are attached.b6007f69a9: the four tests above plusagc_driver_direct_write_completion,agc_driver_linear_target_direct_write_completion,agc_driver_fill_completion_labels,agc_driver_linear_target_completion_pointsandagc_driver_memory_value_fill.b6007f69a9: 8 of 9 pass in each of 3 runs, including all four new tests. The failure isagc_driver_direct_write_completion, which also fails onmain1c8c0efc8cthere in each of 3 runs (#15564, fixed by #15610)VK_LOADER_DEBUG=layer, base1c8c0efc8cvs headb6007f69a9VUID-. This replaces a 1.4.363 run whose layer load can't be confirmed: the layer directory it used was gone, and withoutVK_LOADER_DEBUGa missing layer leaves no trace in the log (#17896)Overlap: #12070 also changes
FlushPending's writer wait: it skips waiting for an image's own stamped writes. Both skip the wait on different conditions, so they compose. The second to land rebases the wait condition. No open PR changesStoreReadbackBeforeLabelor the refresh compare.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.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T22:47:28Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The ordered flush is correct where I could check it, and the new test reaches the new path. The PR is a
perfchange, though, and it lacks the summary lines frommainand from the change and the traces that the rules require.What I ran
Head
d3f7307afdf8752297fc8219277117a2d44e9dc5merged intomain49021a4c907b7f493429dfe269416bbec2de96e1with--no-ff(merged tree13013875e03d5a12b8def62b4a51e6ebbea6e6fb). Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).Results
git diff --checkcheck_conventions.pymain(agc_driver_division, denormal-mode tests,vector_constant_factor_tininess, oneunwrap_selftest)agc_driver_label_ordered_flushagc_driver_linear_target_direct_write_completionskipped on lavapipeagc_driver_label_ordered_flushVUID-linesVUID-VkSamplerCreateInfo-addressMode*lines only inagc_driver_image_gather_volume, which was not inmain's baseline pass. The PR does not touch sampler creation, so I don't count them against itFlushPending)ordered=1 active=1 skip=1 n=1in all 8 runs; label landed after the stored texelsProbe output (temporary fprintf before
if (orderedSkip), removed afterwards)Negative control
I restored
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cppfrommain, rebuiltagc_driver_label_ordered_flush_testsand ran it three times: it passes onmain. That is expected. Onmainthe CPU waits for the writer, so the label order already holds. The test guards against the skip breaking the order; it doesn't fail without the change. A temporary probe in the merged build showed that the test reaches the new skip in each of its 8 runs. I then restored the merged file and rebuilt;git status --porcelainis empty.Findings
Blocking
perf(agc)and still carriesperf numbers missing. CONTRIBUTING.md requires theaps5-summary.jsonllines ofmainand of the change from the same machine and scene, the two traces, andtools/trace_digest.pyoutput. The bot comment asks for the same. The description gives fps and p50 from a "local stack (the same change on an older base, with other GoT experiments)", which doesn't isolate this change. Fix: capture PPSA02225 on currentmainand on this branch the way the Performance report form describes, then paste both summary lines, attach the traces and add the digest.Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:4690requiresRecorder::Active() != nullptrand a host import for each flushed image. The write-back records into the recorder only whenrecorderFor(context)matches the image's device (Texture.cpp:70-72). Otherwise it goes to a standaloneCommandBatch(Texture.cpp:6783-6807), which isn't ordered behind the writer. The first range loop inStoreReadbackBeforeLabeldoesn't filter by device, and the tests create several Vulkan devices. Suggest addingtexture->context.device == Recorder::Active()->Device()to theall_ofpredicate, so a cross-device flush keeps the wait.Unblocksline. The rule's form isUnblocks: PPSA01325 #3232, with the Game bring-up discussion. The line here names no discussion, and it describes a speed-up rather than a stop or a wrong result. Add the discussion number, or usenoneif no bring-up entry tracks this.f37b080(a merge of upstreammainthat resolvesTexture.cpparoundpruneAdoptedSources()). I reviewedd3f7307merged intomain, as prepared, so that conflict resolution was not reviewed here.Not verified
cpuLeftUnchanged,ChangedBlocks) may read guest bytes that an earlier recorded write-back is still copying into. I found no test covering this.mainis ordered by the CPU wait.To get this to a good state
mainand this change, same scene and machine), the traces and thetrace_digest.pyoutput, so theperf numbers missinglabel clears.Unblocksline.f37b080after the merge resolution.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T23:07:21Z.
Review: CHANGES_REQUESTED
Re-checked — changes still requested
Since my last review, the author merged upstream
maininto the branch (f37b080). That merge resolves theTexture.cppconflict aroundpruneAdoptedSources()correctly, and the tests pass. Theperfevidence is still missing. The newest head,2da1597(a device check on the ordered skip), was not part of the tree prepared for this review.What changed since my last review
f37b080: a merge of upstreammain. InStorageTexture::refresh, the ordered-flush scope wrapsFlushPending, andpruneAdoptedSources()follows the scope. That is the same position as onmain, where it directly followsFlushPending(core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:2339). The four earlier commits are unchanged (delta.patch).2da1597("take the ordered flush only for images on the active recorder's device") is listed in pr.md as the current head. It was not in the prepared tree, and its object is not in the repository here, so I could not review it.What I ran
Head
f37b080fed2a31fe64cf1ecd3e88778a3ba6593fmerged intomain1c8c0efc8c41314402e6966da5bef6ea3d639d10with--no-ff(merged tree16285379dde5714fadf0c8bb93a6248ad1222d13). Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pymain.agc_driver_alpha_to_coverage_sample_mask_exportpassed on a rerunagc_driver_label_ordered_flushwith validationVUID-linesagc_driver_linear_target_direct_write_completionwas skipped on lavapipeVUID-VkSamplerCreateInfo-addressMode*lines appear only inagc_driver_image_gather_volume, whichmain's baseline did not run. The PR doesn't touch sampler creation, so I don't count them against itTexture.cpprestored frommain, the test passes 3 times out of 3, as expected (see last review). After restoring the merged file it passes again, andgit status --porcelainis emptyPrevious findings
aps5-summary.jsonllines frommainand from the change, no traces and notrace_digest.pyoutput, and the PR still carriesperf numbers missing.all_ofpredicate atcore/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:4696tests onlyHostImportFor. The author pushed2da1597, whose message says it adds this check. I couldn't see that commit, so I can't confirm it.Unblocksline. Still open. It names no Game bring-up discussion, and it describes a speed-up rather than a stop or a wrong result.f37b080. The resolution keepspruneAdoptedSources()right after the flush, as onmain, and the focused tests pass on the merged tree.New findings
Blocking
None.
Non-blocking
None.
Not verified
2da1597: it was not available in the prepared tree.mainthe CPU wait already provides the order, so the negative control passes there.To get this to a good state
mainand on this branch, on the same machine and scene, following the Performance report form. Paste both summary lines, attach the traces and add thetrace_digest.pyoutput.Unblocksline, or writenone.2da1597in the next pass.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T23:18:56Z.
Review: DISMISSED
Re-checked — changes still requested
2da1597adds the device check on the ordered skip, andUnblocksnow readsnone. Both earlier non-blocking findings are resolved. Theperfevidence is still missing.What changed since my last review
2da1597:FlushPendingkeeps the active recorder inorderedRecorderand addstexture->context.device == orderedRecorder->Device()to the skip'sall_ofpredicate (core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:4696-4697).Recorder::Device()returns the recorder'scontext.device(core/libs/prx/libSceAgcDriver/Graphics/include/Recorder.hpp:457). The four earlier commits and the merge are unchanged (delta.patch).Unblocksline is nownone.main1c8c0efc8cplus #9742, and the plan is three base runs alternating with three runs of the change. The summary lines, traces and digest are not in the description yet.What I ran
Head
2da15973ce0a3fa5e4d9e574d6ee1df640544dadmerged intomain1c8c0efc8c41314402e6966da5bef6ea3d639d10with--no-ff(merged tree8299001b2297bfe2faec19be0c646a7b41e71798). Debian 13 VM, GCC 14.2.0, Release, Ninja, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pymain.agc_driver_alpha_to_coverage_sample_mask_exportpassed on a rerunagc_driver_linear_target_direct_write_completionwas skipped on lavapipe. 0VUID-lines, and no "was not found but was requested" messageagc_driver_label_ordered_flush, with validationVK_LAYER_KHRONOS_validation, with 0VUID-linesAPS5_TRACE_FLUSH=1[flush] image …+0x10000 for readback before label, so the test reaches the ordered pathAPS5_NO_FLUSH_GPU_ORDERED=1VUID-VkSamplerCreateInfo-addressMode*lines appear only inagc_driver_image_gather_volume.main's baseline did not run that test, and the PR doesn't touch sampler creation, so I don't count them against it (same as last time)git status --porcelainThe test is unchanged since my last review, so I did not repeat the negative control. That control passed with
main'sTexture.cpp, as expected, because there the CPU wait already provides the order.Previous findings
aps5-summary.jsonllines from a base and from the change, no traces and notrace_digest.pyoutput, and the PR still carriesperf numbers missing. The author says the captures are in progress.2da1597. The predicate now requirestexture->context.device == orderedRecorder->Device(). An image of another device falls through to the old wait loop, and the refresh'sorderedSkippedis only set whenFlushPendingactually skipped.Unblocksline. Resolved. It now readsnone.New findings
Blocking
None.
Non-blocking
None.
Not verified
2da1597passes on an RTX 4070 Ti; the GT 1030 run was still in progress.mainthe CPU wait already provides the order, so the test passes there too.To get this to a good state
trace_digest.pyoutput. The base the author describes (main+ #9742, with only this PR's 3 files differing) is fine, as long as the two lines carry different commits.