Repository navigation
perf(agc): trap label reads of small images inside pending large ones on macOS - #13678
Merged
Merged
Conversation
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
Merged
12 tasks done
Contributor
✅ NVIDIA GPU test: passedPR head
Unstable on main (3, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (3, not counted against this PR)Passed on retry (1, failed in the parallel run, passed when re-run with a 360 s timeout; not counted against this PR)Validation IDs already present on main (5 IDs in 691 tests)Skipped (42)ReproduceAutomated build and test on a contributor's NVIDIA machine; it does not replace upstream CI. A new comment is posted for each new push. Full logs. |
12 tasks done
GuestWriteWatchTrapReads takes all access to the pages of a range until the resolver set with GuestWriteWatchSetReadTrapResolver has run for it. A fault on a trapped page waits while the resolver runs on the watch's own thread; host writes and GuestWriteWatchProtect run it first on the calling thread. Collections keep trapped pages inaccessible, and registering or unregistering memory drops its traps. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fault that reaches the handler after its page was given back is retried. The budget for that was shared by every thread faulting on the page, so the 17th delayed reader of one untrap was passed on as a crash. Each thread now has its own budget per page and untrap, which still bounds a fault the page's protection does not explain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A caller that traps the same range at every label then needs no record of its own of which ranges are trapped, which registering memory again could leave stale. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The per-thread retry entries are a 64-entry cache. More threads faulting in turn on a page whose protection does not explain the fault evict each other's entries before their next attempt, so each count restarted at 1 and the faults were retried forever. Retries between two untraps are now also counted in total, up to 64 times the per-thread budget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ing them Before a label, a pending linear or small storage image that shares no page with another pending or storing image now gets a write-watch read trap instead of its store. The first access to its pages stores it through the host-read hook; any other store releases the trap first. APS5_NO_LABEL_READ_TRAP=1 keeps the store at the label. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The trap was released when FlushPending took the image out of the pending registry, before it waited for GpuMutex, so a read in between saw the old bytes; cache eviction and explicit write-backs did not release it at all. Every store now releases it in writeBackLayers: after recording the GPU copy into the import, or before the first CPU access on the CPU path, which also releases the traps of other images on the same pages. A trapped image is stored whole, and direct memory mapped at a second address is not trapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The label read trap skipped every image sharing a page with another pending image. Large tiled images are never stored at a label, so an image inside one no longer counts as sharing. A store of an image over a trapped one now stores the trapped one in the same flush, and an eviction or explicit write-back stores the trapped images inside it first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gonic0
force-pushed
the
feat/agc-label-trap-aliased
branch
from
November 1, 2026 06:38
3da032e to
a3046f4
Compare
12 tasks done
Collaborator
|
Checked the diff (page rule, |
This was referenced Nov 1, 2026
This was referenced Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 perf(agc): trap CPU reads of label readbacks on macOS instead of storing them #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