perf(agc): wait on a flush only for writers over the image layers it stores #8887
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8887"
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 SleglJan on 2026-10-21T04:45:32Z.
What
FlushPendingwaits for the newest unfinished batch that writes in the flushed range (#6364), under the GPU mutex: it submits the openbatch, or finishes the in-flight ones up to that writer. Its write-backs, though, store only the pending layers the range overlaps, or
every pending layer when the image stores whole (DCC keys not uncompressed) or may widen a partial store. A writer elsewhere in the range
cannot be overwritten by those stores, so waiting for it only drains the queue.
The flush now asks for writers over the 64 KiB blocks of the layers it stores, the granularity of the write-back's own unit publishes:
it, so the check stays sufficient if the write-back comes to store such an image whole (as #8707 proposes while another live image overlaps it);
its pages only at completion, so the publish could not tell its writes from fresh shadow units otherwise;
APS5_FLUSH_WAIT_WHOLE_RANGE=1checks the whole range as before (row in docs/dev/ENVIRONMENT.md).tests/execution/StorageFlushOrdering.cppgains three cases, each with a GPU fill noted in the open batch:image's texel and the fill land;
stored;
tests/Recorder.cppgainsagc_storage_flush_wait_mip_chain: a three-mip DCC image with uncompressed keys, flushed over its first unit,completes the batch of a writer over its last pending unit. Its runner reports a device without host imports, or with an alignment that does
not divide 64 KiB, as Skipped (exit code 77).
ANYPS5_TEST_HOST_IMPORT_ALIGNMENT(row in docs/dev/ENVIRONMENT.md) stands in for thedevice's alignment in the recorder tests, so both skips can be exercised on one device; a value that is not a number or not a multiple of
the device's alignment fails the run.
Why it is safe
decision for the stored blocks is unchanged.
Sync, which finishes the later batches first; the flush now rebuilds its wait set after every reap and finish and waits again when a later writer appears, so it no longer relies on thatSync.import; the per-layer check passes
the same notes to each range, and
APS5_FLUSH_WAIT_WHOLE_RANGE=1ismain's check including that skip. Not measured: the waits thischange adds where two drawn linear targets, or a drawn target and a label or GPU fill, share one 64 KiB block;
mainchecks thetarget's exact bytes there, this change its rounded block.
diagnostic (the title with a local patch for #6172). The check it evaluated is this change without the DCC mip clause and without the wait over live shadowed units (3bc40d969e, rebuilt after every reap in ec47dad254), both of which only add waits:
falls in the time this change would have skipped.
APS5_FLUSH_WAIT_WHOLE_RANGE=1on the RTX 3080,agc_driver_storage_flush_orderingfails at its first new case (the writeroutside the pending layers; the test stops there) and
agc_storage_flush_wait_mip_chainfails, so the tests tell the two checks apart.The second flush ordering case waits under both checks.
Tested
mainf2d874c1fd; the one conflict was in the recorder tests'main(), wheremainnow passesbinaryTestto theDeviceconstructor on the line this PR'sTestConfigurationErrorcatch follows, resolved by keeping both. On an AMD Radeon RX 9070 XT (RADV, Mesa 26.2.4-arch3.1, Linux 7.2.10, CachyOS; power cap 243 W),-R '^agc': 1,148 passed, 17 skipped, 2 failed of 1,167, the failuresagc_driver_tessellation(SEGFAULT; its output ends with the device setup's lines) andagc_idle_publish_wait("the idle publish's bytes are wrong");mainf2d874c1fdbuilt the same way on this device: 1,147 passed, 17 skipped, 2 failed of 1,166, the same two names and the same 17 skipped names; the one test this PR adds,agc_storage_flush_wait_mip_chain, is the count's difference.agc_driver_storage_flush_orderingpasses, but its shadowed-unit case skips on this card ("the write-back did not retile both units into the unit shadow: the shadowed-unit case is skipped"), so this card does not exercise the shadowed-unit case;agc_storage_flush_wait_mip_chainruns ("flush wait over a DCC mip chain: ok"). On lavapipe (Mesa 26.2.4, LLVM 23.1.1, in the container of the 1f15e200f7 entry below,-j16): 1,035 passed, 90 skipped, 42 failed of 1,167, the 40 thatmain0836dfdf4ffails there (40 of 1,143, same names) plusagc_driver_f64_fma_denormal_modesandagc_driver_f64_div_scale_denormal_modes,main's new tests from #13845 and #13846;mainf2d874c1fdbuilt the same way there fails the same 42 names of 1,166 with 90 skipped.agc_driver_storage_flush_orderingpasses with the shadowed-unit case run, and fails with "storage flush ordering, shadowed unit under a writer outside the flushed image's layers: the flush did not wait for the writer over the shadowed unit it publishes" when the live units are left out of the wait set;-R '^agc': 1,055 passed, 10 skipped, 1 failed of 1,066, the failureagc_driver_mesh_barycentric_emulationas onmainf759e165d9below. On lavapipe the case skips (no write watch) and-R '^agc'gives 949 passed, 84 skipped and the same 33 failed of 1,066 as at 3bc40d969e.MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), x86-64 Release under Rosetta 2, the validation layer inserted on both sides.
maindoes not build thedriver on macOS on its own, so the base is imellag's support branch
support/macos-boot-1030c05bd71a66b (main21a556f567plus the openmacOS PRs) and the change side that branch with ec47dad254 merged. Of the storage flush tests (#12070's pattern plus
storage_flush_wait_mip_chain), the base passes 25 of 25 and this head 26 of 26, includingagc_driver_storage_flush_orderingandagc_storage_flush_wait_mip_chain. The ordering test logged no skip line, so the shadowed-unit case appears to have run there; lavapipeskips it, so this is the first device off NVIDIA where it appears to have run. The only
VUID-on the change side isVUID-VkDeviceCreateInfo-pProperties-04451(2 lines,VK_KHR_portability_subsetnot enabled), fromagc_storage_flush_wait_mip_chain,which imellag traces to the recorder tests' existing device setup, not to this change.
809c7fa2df. B: main809c7fa2dfwith ec47dad254 merged (a local merge commit). Two binaries with the same shader-cacheversion; one shader-cache seed, made on A by a run from an empty shader cache through the menu and the Resume into gameplay, serves
both, with the NVIDIA driver cache frozen with it; every run starts warm from it.
APS5_PROFILE_*switch, trace window 180 s from 1,320 s (APS5_TRACE_SECONDS=1320:180,APS5_TRACE_EVENTS=2097152, andAPS5_TRACE_DIR, which only names the directory the trace and summary files are written to), the menu held for the whole run, main'sdefaults otherwise (the pipeline journal among them); the title's scope runs with swap off. Run order A1 B1 A2 B2 A3: A3 failed a
validity rule declared before the series (six shader-disk-cache misses in the first 10 s of its boot, where every other measured run
had none), and the series stopped there; a continuation declared before its runs then added A4 as A's extra, and B3. The table holds
the first three valid runs of each side, as declared; A3 is left out. The title's output goes to a log file (the sandbox launcher
redirects it), which the form advises against.
809c7fa2df809c7fa2df+ ec47dad254809c7fa2df809c7fa2df+ ec47dad254809c7fa2df809c7fa2df+ ec47dad254highest A 0.9782, highest B / lowest A 1.0386). Frame p50: A 952.7–989.8 ms, B 950.4–987.3 ms; B/A of the means 0.9909; the ranges
overlap (0.9602 and 1.0363 at the range ends). GPU busy per present A 145.2–152.3 ms, B 143.3–149.3 ms. On this main, the menu's
FPS and frame time do not differ between A and B beyond the run-to-run spread: the ranges overlap. The +2.45 % in the earlier A/B
below was measured on that earlier stack, not on main.
Driver.Packet.draw613–621 → 606–616;Driver.Draw.draw_enqueued532–539 →525–535;
Driver.Draw.shader_compile_and_link72–76 → 72–74;Shader.DrawStage.capture_resources28–29 → 28–29;Driver.Packet.dispatch281–305 → 281–294;Vulkan.Dispatch193–215 → 189–200;Driver.Packetas a whole 957–986 → 949–978.Driver.Draw.draw_enqueuedat 525–539 ms per present (both sides); the earlier stack's pairbelow ran at 2.740–2.840 FPS and 45–68 ms. Besides the base, that pair ran the title unpatched, with swap allowed for the title's
scope, and before main's pipeline journal. Its figures stay below as that stack's record.
agc_driver_storage_flush_orderingpasses on the RTX 3080 and on lavapipe, with the new case skipped on both (above). On lavapipe (the container of the 1f15e200f7 entry below, 2026-10-31),-R '^agc'at 3bc40d969e and at 1f15e200f7, built side by side, gives 949 passed, 84 skipped and the same 33 failed of 1,066 on both; lavapipe has no write watch, so unit shadows are off there and the new wait never applies. The RTX 3080^agcrun and the other runs below were not repeated on it.mainf759e165d9as a94e49393f (its added and removed lines are those off0378179a2; the range-diff shows one changed context row of
main's), plus 1f15e200f7 for the test's skip (oneandonlydean's review):agc_storage_flush_wait_mip_chainSkipped withANYPS5_TEST_HOST_IMPORT_ALIGNMENT=0and with=131072, Passed unset, Failed with=abcand with=4095;-R '^agc': 949 passed,84 skipped, 33 failed of 1,066, and the 33 are
mainf759e165d9's own failures on this device (same set, same skips);-R '^agc' -j 8: 1,055 passed,10 skipped, 1 failed of 1,066;
mainf759e165d9built the same way on it: 1,054 passed, 10 skipped, 1 failed of 1,065, the same tenskips and the same failure (
agc_driver_mesh_barycentric_emulation,the pixel shader did not emulate barycentricson both trees).main7e4f6e0440), 2026-10-25:agc_driver_storage_flush_ordering,agc_storage_flush_wait_mip_chain,agc_storage_writeback_blocks, everyagc_driver_linear_target_*andagc_driver_linear_readback_label*test: 14 of 15 passed, andagc_driver_linear_target_direct_write_completionskipped itself onthis device (it passes in the RTX 3080 run below);
agc_driver_storage_flush_orderingandagc_storage_flush_wait_mip_chainpass;full
-R '^agc' -j 8in a Release build: 1,005 of 1,012 passed, 7 skipped, none failed;APS5_FLUSH_WAIT_WHOLE_RANGE=1on the RTX 3080:agc_driver_storage_flush_orderingandagc_storage_flush_wait_mip_chainfail,and
agc_driver_linear_target_completion_stores(#9685's test that a drawn target stays pending across draws and labels without asubmission) passes, so the switch keeps #9685's own-store skip.
5d10ea9ea0; the menu runs on the68323bae7trees). From017123e1d6 to f0378179a2 the patch differs in one added line: the per-layer
PendingWriterSerialcall takes #9685's new overload withthe flushed target's own store notes, for each stored range.
5d10ea9ea0:agc_driver_storage_flush_orderingwith"storage flush ordering, writer outside the image's pending layers: the flush submitted and waited for a writer its stores cannot
overwrite";
agc_storage_flush_wait_mip_chainwith "flush wait over aDCC mip chain: a flush of the first unit did not complete the batch of a writer over another pending unit, which a write-back of a DCC
image with more than one mip may store", and passes the flush ordering test;
-j 16: 1,763/1,766. The threefailures are
net_dontwait_blocking_send,_sendtoand_sendmsg("blocking send: peer never exhausted the send buffers"), libSceNettests this change does not touch; main
5d10ea9ea0fails them the same way when they run alone on this machine.-R '^agc': base5d10ea9ea0fails 19 of 840 and this PR the same 19 of 841 (the one more test passes);they fail on lavapipe without this change.
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ctest -Von the RTX 3080(Vulkan-ValidationLayers 1.4.363):
5d10ea9ea04/4 (without the new test);VUID-.68323bae7+ #5799 #6868 #5372 #6918 #7643 #6679 + this change without the DCC mip clause (which does not apply in thismenu, below) and without 3bc40d969e's wait over live shadowed units or ec47dad254's rebuild of it (the measurement on main above has them). The title ran as shipped.
APS5_FLUSH_WAIT_WHOLE_RANGE=1; B runs this change. Same binary.APS5_PROFILE_DRAW=1, trace window 180 s from 1,320 s (APS5_TRACE_SECONDS=1320:180,APS5_TRACE_EVENTS=2097152).(19:47–19:57 against a window from about 20:02); A4 was added, and A2 matches the other A runs.
Driver.Packet.draw217–219 → 187–191 (means 218.3 → 188.7, −13.6%);Driver.Draw.draw_enqueued66–69 → 48–49;Driver.Draw.shader_compile_and_link145–146 → 135–137;Shader.DrawStage.capture_resources29–30 → 21–23.Driver.Packet.dispatch127–129 → 129–132,
Vulkan.Dispatch59–70 → 70–75). SoDriver.Packetas a whole goes 361–365 → 355–356 on B1 and B3, and theframe gain is small: +2.0% FPS (B1 +1.9%, B3 +2.1%) and −1.5% frame p50 for B1/B3 against the mean of A1–A4.
Vulkan errors, the frames render correctly. Its frame rate is not compared: the window's GPU work per frame differs from the reference
runs.
68323bae7+ #5799 #6868 #5372 #6918 #7643 #6679 (local tree 984b9f06de). B: the same + this change (local tree bdf58c66fb).Two binaries. Measured on 984b9f06de / bdf58c66fb; the rebase changes no code in the change itself except a conservative clause for
DCC images with more than one mip and its test, which does not apply in the measured window (below); 3bc40d969e then adds the wait over live shadowed units and ec47dad254 rebuilds it after every reap; the measurement on main above has both.
APS5_PROFILE_*switch, trace window 180 s from 1,320 s; runsalternating A1 B1 A2 B2 A3 B3. The title's output goes to a log file (the sandbox launcher redirects it), which the form advises against.
Driver.Packet.draw216–219 → 180–187;Driver.Draw.draw_enqueued67–68 → 45–49;Driver.Draw.shader_compile_and_link144–146 → 131–136;Shader.DrawStage.capture_resources29–31 → 20–22;Driver.Packet.dispatch123–125 → 131–133;Driver.Packetas a whole 357–361 → 348–354.tools/trace_digest.pyoutput of all six: this release.the same menu (40,777 in its 180 s trace window, 81.1 per present), none with a DCC image of more than one mip, so it changed no stored
set and added no wait there.
APS5_TRACE_EVENTS=2097152in these captures only sizes the per-thread trace buffer, so the window's events aren't dropped (trace_droppedis false in every summary line above): in the earlier stack's 180 s window queue 0's worker records about 1.25 million events and the draw
committer 266,000–271,000, against the default of 262,144.
Overlap
Overlap (2026-10-28 00:21 CET, trial merges with
git merge-treeof the 224 open PRs that touch the same files, out of 1,363 open, against this branch 1f15e200f7 and againstmainf759e165d9; 118 merge cleanly with this branch, 102 conflict with this branch only in files that already conflict withmain, none conflicts withmainand in further files with this branch, and four merge cleanly withmainbut not with this branch: #8707, #10743, #11485 and #12070):e7e78cff0e) conflicts with this branch at ec47dad254 only intests/execution/StorageFlushOrdering.cpp, where both add cases (git merge-tree, 2026-10-31;Recorder.hpp,Recorder.cppandTexture.cppauto-merge): it narrows which writers the flush waits for, this change which ranges; the order agreed on #8887 is this PR first, and #12070 listsDepends on: #8887.8be6c1abe8) merges cleanly withmain; with this branch it conflicts in the declarations inTexture.hpp, adjacent lines.StorageTexture::storesWhole()(DCC metadata with keys not uncompressed, or more than one mip while another live storage image overlaps the image) and uses it inwriteBack,pendingUnitInside(the flush pretest),evictStale,skippedResultsInsideand the clear hand-over. This change's "stores whole" rule inappendStoredLayersis the wider predicate (any DCC image with more than one mip), so either merge order keeps the flush's stored set covering what #8707's write-back stores. It now merges cleanly withmain; with this branch it conflicts in one region each ofTexture.hppandTexture.cpp(appendStoredLayersnext tostoresWhole()) and oftests/Recorder.cpp(the full run's call offlushWaitMipChainTestsnext to that ofdccMipWriteBackTests).mainand conflicts with this branch only intests/Recorder.cpp, where both add test functions afterwriteBackBlockTestsand their calls in the full run;Texture.hppandTexture.cppauto-merge.main.Checklist
mainf759e165d9(the base it is rebased onto;mainhas moved on since); no other open PR implements the same functions.mdfiles or images added to the repositoryLinux container, for the
^agcand targeted runs; AMD Radeon RX 9070 XT (driver 32.0.32015.7029, amdvlk64), Windows 11 Pro 10.0.22631, by @bunbeans2-arch at 1f15e200f7 merged ontomainf7f03daf52:agc_driver_storage_flush_ordering3 of 3 on that merge and on thatmain, validation layer inserted, noVUID-line (comment); Apple M4 Pro (MoltenVK 1.4.2, Vulkan SDK 1.4.363.0), macOS 27.2, x86-64 under Rosetta 2, by @imellag at ec47dad254 merged ontosupport/macos-boot-1030c05bd71a66b: 26 of 26 storage flush tests, details under Tested (comment)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-22T09:11:15Z.
Reviewing the updated017123e1d6 for a Windows007 cross-test. Source-only integration163fd9b52c merges cleanly over our current c4162b2156b8 recorder-memory control, preserving #9565's command-buffer release and your new mip-chain/flush-ordering cases:
https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-oct22-storage-waits
Conventions pass; UNBUILT/UNTESTED and not staged. The current game is unchanged c416 (main d6 + #9591/#6918 + now-merged #7961 + #9565). Correct offline menu:78presents/62.137794s=1.25527FPS, GPU196.17083ms/present, same32GiB/7800X3D/RTX5070Ti617.42. The prior same-settings b36 menu was1.22951FPS; one moving-menu pair/no clock lock, so no useful speed gain claimed from recorder release. A five-frame timing capture and loading/memory probe are next before another native build.
Your flush-wait change fits the remaining queue/resource stalls. I will include both new regressions, the existing storage-flush ordering controls and the full recorder set, with the actual Khronos layer and the whole-range switch as the negative control, before any title test. Also reviewing #9400's outside-mutex presync, kept separate so far. Raw title requests/code/traces remain local. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-22T09:37:17Z.
Windows cross-test of017123e1d6 on integration163fd9b52cc9 completed (basec4162b2156b8, the same current-main007 prerequisite/recorder stack as our active control). All commits retained; no #9652 join relaxation.
RTX5070Ti / NVIDIA617.42 / Windows11 10.0.26200 / 7800X3D, WinLibs GCC15.2r7 Release, game/native build SPIRV Tools OFF:
Clean final packaging, matched369modules SHA256 verified/staged, previous c416 cohort preserved. Not yet title-tested. The c416 control menu was1.25527FPS; its later loading probe hit the known RenderThread/quadtree fault class before guard termination, so no gameplay success. Prewarming two newly captured large loading pipelines locally before the163 title run; raw title code/requests stay local. No FPS claim for this PR from me yet. AI-assisted: Codex.
Imported from boykopovar/AnyPS5. Originally posted by imellag on 2026-10-30T20:52:04Z.
Review: COMMENTED
A question on the publish path, from reading head
1f15e200f7(no run).FlushPendingpublishes over the whole flush range after the stores:PublishShadow(address, bytes, scope, ...)atTexture.cpp:4361(the default scope isWhole), andPublishShadowinUnitShadow.cpp:544does not wait for GPU writers itself, apart from the completion case. Before this change,PendingWriterSerial(address, bytes, ownNotes)covered writers over the whole range, so a shadowed unit was published only after any in-flight writer over it had finished. With this change, when the scope publishes, the whole range is checked only for leases (PendingLeaseSerial,Texture.cpp:4320); writers are checked only over the stored layers (Texture.cpp:4324).So take a unit shadow that holds another image's retiled results inside the flush range but outside the layers the flushed images store, with an in-flight batch that writes over it. That unit is now published while the write may still be running. Before, it was published after the write had finished. Is that ordered somewhere else (the shadow's notes, or something that drops the unit when a newer GPU write is pending)? If not, should the writer check keep the whole range when
scope != PublishScope::None, as the lease check already does? The newStorageFlushOrderingcase with the far fill uses the defaultWholescope but has no shadowed unit over the fill, so it doesn't cover this.This came up because #12070 changes the same
ownNoteslines and is stacked on this PR.AI-assisted: yes