perf(agc): trap label reads of small images inside pending large ones on macOS #13678
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13678"
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 Gonic0 on 2026-10-30T23:35:49Z.
What
Builds on #13499. Its label trap skips an image that shares a page with another pending image, so the label stores it as before. In PPSA21564 (ASTRO BOT 01.007.000) on MoltenVK, every image the trap skipped during the intro was skipped for that reason, and each of them lies inside a large pending tiled render target: a 960x540 linear image and 120x67, 60x33 and 30x16 tiled images of 64 KiB inside 2432x1368, 1920x1080 and 3840x2160 targets. The memory is reused across passes. A label never stores those large targets (they are tiled and over
SmallStoreBytes), but the small images inside them were stored at every label. Each of those stores waited for the GPU (FlushPending→Recorder::Sync), on average 7.6 ms per frame on queue 0x40.Three changes, all macOS-only like the trap:
SmallStoreBytes. Images being stored (pending.flushing) still count, so a storing thread never faults on a new trap.FlushPendingstores an image that covers a trapped one, it stores the trapped one in the same flush. Without this, the large image's store lands first and the trapped image's store lands later, at the guest's first read, over it.StorageTexture::Flush()andWriteBack()store a dirty image withoutFlushPending, so they first store the trapped images it covers throughFlushPending.Flush()is called from the storage cache's evictions andFlushCachedTextures, under the cache's mutex;cachedStorageTexturealready callsFlushPendingunder that mutex next to its evictions,FlushPendingtakesGpuMutexrecursively and does not wait for the GPU inside a completion, and the memory-pressure eviction only evicts clean images, for which the new step does nothing.With these, the bytes in guest memory are the same as when the label stores the small image: the new test checks four sequences against the bytes
APS5_NO_LABEL_READ_TRAP=1leaves. Which of two overlapping images wins is still decided by the existing write-back rules (blocks stamped since an image's generation keep their bytes); this PR does not change that.The debt entry for label read traps describes the new rule and the two stores.
Performance
Apple M5 Pro, macOS 27.2, MoltenVK 1.4.2, 3840x2160. PPSA21564 01.007.000 from boot, warm shader cache, 60 s per run, the same tree with #13499 below this change (and the open macOS port PRs), alternated. Traces cover presents 700 to 880 (
APS5_TRACE_FRAMES=700:180), in the intro.Averaged over the five rounds: 45.1 → 50.0 FPS for the whole run, and 22.4 → 19.5 ms frame p50 in the traced window. Round 4 was slower with the change over the whole run, although its traced window was faster; across the five rounds the base alone ranged from 41.2 to 49.3 FPS.
Queue 0x40 drops from 6.8–8.5 ms of work per frame to 1.5–2.1 ms. In earlier runs with a temporary counter and the same page rule,
StoreReadbackBeforeLabelstored 230 to 3,400 images per 10 s before the change and none with it, and no trap was resolved: no guest read touched those images.Queue 0x0 is now the busy one (14–16 ms of work per frame). One run with the change (round 2) had a 438 ms frame at present 878: queues 0x40 and 0x48 waited on memory while queue 0x0 compiled shaders at first use and ran a long dispatch (
Driver.Dispatch.materialize). Every run compiles those five shaders at use, at different points; this one fell inside the traced window, and rounds 3 to 5 with the change had no frame over 27 ms.Paired summary lines (rounds 1 and 3)
Round 1, #13499:
Round 1, this change:
Round 3, #13499:
Round 3, this change:
Traces:
Tested
On the tree above (Apple M5 Pro, macOS 27.2, x86-64 under Rosetta 2):
agc_driver_recorder_testspass withVK_LAYER_KHRONOS_validation(one skips, as on #13499).agc_small_tiled_shadow_labelpasses 5 of 5.agc_*,guest_*andwrite_watch*CTest entries: 46 fail, the same 46 without this change.The new part of
agc_small_tiled_shadow_labelputs an 8x8 linear image inside a 256x256kR64KBXimage that is pending, and checks:Flush()) stores the trapped image inside it first;Before writing the expected bytes into the test, I ran the same sequences with
APS5_NO_LABEL_READ_TRAP=1and with this change, and printed the bytes: they were the same at each step. Without the second and third changes the trap left the large image's bytes in each step, and at step 5 a read of the trapped image returned the large image's older bytes.Negative controls, each of which fails the test:
FlushPendingnot storing the trapped images a store covers: "a store of a large image's block left a trapped image inside it trapped";I also tried ordering the images of one flush (trapped ones first, or by last write) and widening the GPU wait to the added images' ranges. Neither changed any byte in these sequences, on the GPU path or the CPU path (
FlushPendingwithidle), so neither is in this PR.Not tested on Linux or Windows, where nothing changes.
Checklist
NotImplemented_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)🤖 Generated with Claude Code