perf(agc): elide a repeated fill of a range that still holds its pattern #10668
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/10668"
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 meh7an on 2026-10-24T16:12:16Z.
What
Titles often fill the same range with the same pattern again and again, with nothing writing the range in between. On
mainevery such fill is recorded as avkCmdFillBuffer(or a pattern copy) into the host import. Sonic Origins Plus zero-fills four ranges every frame on its main menu, about 68 MiB per frame. Over one run on the Sonic 2 page that is 7,905 GPU fills (about 134 GB), and the fills cost the boot intro its frame rate as well.This PR makes
VulkanDevice::FillBufferremember the last fill of each range: its address and size, the 16-byte pattern, the write-tracker generation itsMarkWrittenreturned, the import'sHostImportSerial, andGuestMemory::UnwatchSerial. A fill that repeats the remembered one records nothing when all of these hold:UnchangedSincestill holds over the range for that generation.CollectWritesUncachedruns first, so a CPU store not collected yet counts. Every import writer stamps its blocks: labels, key stores, copies, in-place V# writes, and GPU-direct and shadow write-backs.Graphics::LeaseWorkPending, new). BDA stores are stamped only when their batch completes (BdaResources::markWrittenPages), so a BDA dispatch recorded after the remembered fill could still write the range.The check runs after
FillBuffer's sync on copied writers and completion labels, whose stores stamp when they run, and after queued key stores are flushed. Queued label stores stamp when they are queued.A skipped fill still calls
GuestMemory::MarkWrittenover its range, as a recorded one does. So everything over the range that revalidates by write stamps behaves as after the store, and only the transfer is gone:OverwrittenInMemory;storeBufferFill's steps around the call are unchanged: flushing pending images, discards, and the metadata notes.APS5_NO_FILL_ELISION=1records every fill, as before.[fill-sync]line ofAPS5_PROFILE_DRAWcounts the elided fills and their bytes.agc_driver_repeated_fill_elision(new) runs on write-watched memory:MarkWrittenof a write-back).ClearHostImports.APS5_NO_FILL_ELISION=1the test fails at the first repeat.main. On Linux it runsmain's decided import mode and, when that is "watch", a second pass with imports forced unwatched.No open PR or
maincommit elides repeated fills.tools/pr_overlap.pyfinds no overlapping change. It could not compare 70 PRs, because they conflict withmain. Of those, three touchFillBuffer, and they only call it: #2434 and #9898 from tests, #7201 with an added condition.Tested
Rebased onto
mainca0e9557aa(2026-10-27). Same machine: Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, i9-9900K. Sonic Origins Plus (PPSA05324) on the Sonic 3 & Knuckles page of the main menu,main's defaults.mainca0e9557aaagainstmainwith this PR (2b395fe86a), both clean builds of the same tree. One warm-up boot, oneAPS5_PROFILE_GPU=1boot per build, then two interleaved traced rounds (main, PR,main, PR;APS5_TRACE_SECONDS=200:15, six title FPS readings each).main[gputime]fill class per present[gputime]GPU time per present, all ranges, the same six blocks on the pagectest(2655 tests) onmainplus this PR: all pass.ctest --test-dir build -R "fill|host_import|dcc_key|label|guest_memory_lifetime|depth_fast_clear" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 54/54 onmain, 55/55 on this PR. The extra one isagc_driver_repeated_fill_elision; it reports that the write watch proves the range unchanged, so the repeats are elided. Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line.The digests below come from the first round of each build. All four traces are attached, one zip per round with the
mainand PR traces.fill-elision-s3k-ca0e-round1.zip
fill-elision-s3k-ca0e-round2.zip
Sonic 3 & Knuckles page, round 1, main
seconds 200:15 from present 3502: 197 presents, frame p50 64.4 / p90 105.7 / p99 128.5 / max 136.3 ms, GPU busy 71.2 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
ca0e9557aa, dropped: yesSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 70.7, VideoOut.Flip 43.0, Driver.Present 42.7, VideoOut.Flip.present 42.7, Graphics.Draw 41.9, Driver.Present.render_fence_wait 41.6, Vulkan.Retire 41.6, Vulkan.Retire.wait 41.6, Graphics.Draw.draw_and_resource_release 36.5, Driver.Packet 20.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Sonic 3 & Knuckles page, round 1, this PR
seconds 200:15 from present 4604: 241 presents, frame p50 61.8 / p90 64.7 / p99 69.0 / max 72.8 ms, GPU busy 55.6 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
2b395fe86a, dropped: yesSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 55.6, Graphics.Draw 24.6, VideoOut.Flip 23.9, Driver.Present 23.8, VideoOut.Flip.present 23.7, Driver.Present.render_fence_wait 22.9, Vulkan.Retire 22.9, Vulkan.Retire.wait 22.9, Graphics.Draw.draw_and_resource_release 19.8, Driver.Packet 12.5
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Before the rebase. The measurements below were taken on
mainc9b2660d56.Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, i9-9900K, on
mainc9b2660d56. Sonic Origins Plus (PPSA05324),main's defaults (noAPS5_*opt-ins).Boot intro, 5-20 s after launch, one boot per build (
APS5_TRACE_SECONDS=5:15):mainThe intro reaches the 60 Hz cap:
VideoOut.Flip.vblank_waitbecomes the presenter's largest phase.Sonic 2 page of the main menu. Two interleaved traced rounds per build after one warm-up boot each (
APS5_TRACE_SECONDS=200:15):Driver.Packet(ms/frame)mainAPS5_PROFILE_DRAW, is about 30 µs per fill. The[fill-sync]decide, record and notes phases total 229 ms over 7,905 fills, about 0.1 ms per frame.APS5_PROFILE_DRAW=1run of this PR on the same page elided 7,626 of 7,905 fills (about 130 GB not stored).Tests
ctest(2119 tests) onmainplus this PR: everything passes exceptagc_driver_sample_order,agc_driver_sample_order_grid_referenceandagc_driver_sample_order_recipe_depth_locations, which fail the same way on plainmainon this machine.ctest --test-dir build -R "fill|host_import|dcc_key|label|guest_memory_lifetime|depth_fast_clear" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 54/54 onmain, 55/55 on this PR (the extra one isagc_driver_repeated_fill_elision). Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line.The digests below come from the intro boots and from the first Sonic 2 round of each build. All six traces are attached: two Sonic 2 rounds per build, and one intro boot per build.
fill-elision-intro.zip
fill-elision-s2-round1.zip
fill-elision-s2-round2.zip
Boot intro, main
seconds 5:15 from present 199: 650 presents, frame p50 22.0 / p90 34.4 / p99 44.7 / max 46.6 ms, GPU busy 22.8 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
c9b2660d56, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 22.8, VideoOut.Flip 21.0, Driver.Present 20.7, VideoOut.Flip.present 20.6, Driver.Packet 19.3, Driver.Present.render_fence_wait 18.7, Vulkan.Retire 18.7, Vulkan.Retire.wait 18.7, Driver.Packet.pipeline_drain 9.4, Graphics.Draw 8.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Boot intro, this PR
seconds 5:15 from present 256: 899 presents, frame p50 16.7 / p90 16.9 / p99 17.6 / max 37.5 ms, GPU busy 11.2 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit b70c1d2a8f06, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): VideoOut.Flip 16.2, Driver.Packet 14.4, batch 11.2, VideoOut.Flip.vblank_wait 10.7, Driver.Packet.rendering_wait 8.7, Driver.Present 5.5, VideoOut.Flip.present 5.4, Driver.Packet.pipeline_drain 3.6, Graphics.Draw 2.9, Graphics.Draw.draw_and_resource_release 2.8
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Sonic 2 page, round 1, main
seconds 200:15 from present 3576: 184 presents, frame p50 79.9 / p90 85.4 / p99 111.1 / max 112.5 ms, GPU busy 67.8 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
c9b2660d56, dropped: yesSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 67.8, Graphics.Draw 29.4, VideoOut.Flip 27.3, Driver.Present 27.2, VideoOut.Flip.present 27.1, Driver.Present.render_fence_wait 26.7, Vulkan.Retire 26.7, Vulkan.Retire.wait 26.7, Graphics.Draw.draw_and_resource_release 24.4, Driver.Packet 16.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Sonic 2 page, round 1, this PR
seconds 200:15 from present 4136: 182 presents, frame p50 80.0 / p90 91.9 / p99 102.2 / max 110.8 ms, GPU busy 58.1 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit b70c1d2a8f06, dropped: yes
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): batch 58.1, Graphics.Draw 30.4, Graphics.Draw.draw_and_resource_release 25.0, VideoOut.Flip 23.1, Driver.Present 23.0, VideoOut.Flip.present 22.9, Driver.Present.render_fence_wait 22.5, Vulkan.Retire 22.5, Vulkan.Retire.wait 22.5, Driver.Packet 16.2
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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 MarcZX10 on 2026-10-24T16:17:26Z.
Review: APPROVED
Reviewed the complete diff at b70c1d2a8f06c3448e5e26b5f4c9ee5106918632. The elision predicate is scoped to an exact address/size/pattern and requires the same host import and unchanged watch epoch; it collects uncached writes before comparing generations. I traced the write-order cases: queued DCC key stores are flushed before the cache check, copied writers and completion labels are synchronized earlier in FillBuffer, tracked GPU/label writes stamp their ranges, and deferred BDA lease work blocks elision. The normal fill path still records its pending-write note and generation, and the hit advances the generation while relying on the prior fill's still-pending write note where needed. Context loss clears the cache. The regression covers CPU/GPU overwrite, metadata stamp, pattern/size changes and import replacement.\n\nDirect local checks: and All conventions checks passed. pass. I attempted a focused local CMake configuration, but this checkout cannot configure the full test tree because the SDL2 submodule has no CMakeLists and SDL lacks XRandR support; so I could not independently run the new Vulkan test here. The PR reports paired validation-layer test runs (54/54 main, 55/55 change, no missing-layer diagnostic or VUID) and the paired performance traces, with the product-suite failures matching on main and the change. Hosted eligibility, conventions, intake, labels and report pass; platform/product build jobs are skipped by repository policy.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-24T20:21:45Z.
Review: APPROVED
Follow-up review of head c141ccb4253cbea11782bc721ad7458c266fc4a1. The test now derives whether repeat fills should be elided from the tracker after the first synchronized fill and checks recorded repeats when the write watch cannot prove unchanged contents. On Linux it additionally runs the forced-unwatched import mode when the normal decision is watched, so the RADV-reported case is represented without assuming an optimization that main does not provide there. The failure reported on b70c1d2a8 was in that prior test assumption; the author has asked the reporter to rerun the corrected head, which is still pending. Focused hosted tests are skipped under repository policy, so this approval is based on code/test review plus the existing Windows/NVIDIA and Windows/RDNA1 reports, not a claimed RADV rerun. Eligibility, conventions, labels and report passed.