Repository navigation
perf(agc): trap CPU reads of label readbacks on macOS instead of storing them - #13499
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
The PR reports a performance improvement against its opt-out mode, but the repository requires captures from main and the change before that claim can be checked.
What I ran
Reviewed head a485eb515e3021a565d66222bfe3eceb883e933d against base a026562629da7bcc7af781639a11ab0647a524dd. The dependency stack preview reports a clean merge preview for this head against the current base. Environment: Linux x86-64, Debian 12, Python 3.11.2, GCC 12.2.0.
git diff --check a026562629da7bcc7af781639a11ab0647a524dd...a485eb515e3021a565d66222bfe3eceb883e933d
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13499
python3 tools/pr_stack_check.py 13499 --repo boykopovar/AnyPS5 --output-dir /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13499-a485eb515e30/stack
gh pr checks 13499 --repo boykopovar/AnyPS5Results
| Check | Result |
|---|---|
| Diff whitespace check | Passed |
| Repository conventions and PR template | Passed |
| Dependency and merge preview | Passed; #13220 → #13442 → #13499, with a clean preview against current base |
| Hosted checks | Pending when checked |
| Performance evidence required by repository rules | Missing: the description has no paired main/change summary lines, attached traces, or trace_digest.py output |
Raw output
All conventions checks passed.
PR stack check — fresh
Target: https://github.com/boykopovar/AnyPS5/pull/13499
Target branch tip: `a026562629da7bcc7af781639a11ab0647a524dd`
All heads unchanged: **True**
Dependency order: #13220 → #13442 → #13499
## Individual merge previews
- PR #13220: **clean** against current base; head `e9f09f54fabb6408d3e2711b8df10c10112ab00e`; changed paths: none reported
- PR #13442: **clean** against current base; head `bd49ace09e78998c8da23033ff0e3fa9b1d9237e`; changed paths: none reported
- PR #13499: **clean** against current base; head `a485eb515e3021a565d66222bfe3eceb883e933d`; changed paths: none reported
## Dependency relationships
- PR #13220 → #13442: current dependency head not included; overlapping path: `core/libs/tests/write_watch/CMakeLists.txt`
- PR #13442 → #13499: dependency head included
conventions pending 0
eligibility pending 0
intake pending 0
labels pending 0
library-portability pending 0
report pending 0
The precheck's ABI-audit and test-quality helper steps were not executable in its isolated PR snapshot because those local helper scripts are absent there; these are not reported as repository failures.
Findings
Blocking
- Required performance comparison is incomplete. The description reports 44.0/44.3 FPS with traps and 38.1/37.1 FPS with
APS5_NO_LABEL_READ_TRAP=1, both on the PR stack. It does not provide captures frommainand the change, nor the required trace artifacts and digest. The repository rule requires those paired captures for a speed claim. After dependency #13442 is in the baseline tree, add summary lines from the same title, scene, and machine, attach both traces, and include thetools/trace_digest.pyoutput. Repository performance-report rule · Performance report form
Non-blocking
- No additional blocking source defect was established by this no-build pass.
Not verified
- I did not build or run C++/CTest. The 82 CTest results, negative controls, and Apple M5 Pro/MoltenVK measurements in the PR description are author-reported and were not independently reproduced.
- Hosted checks were pending at the time checked. The reported measurements do not cover a title that reads these images from the CPU.
To get this to a good state
After #13442 is in the baseline tree, add the matched main and change captures and the required artifacts. I’ll re-check the updated head and its evidence.
|
@Gonic0 thanks, the label trap reads well on macOS only: Linux and Windows are untouched, the opt-out variable is documented, and the gaps you list in the debt entry are the right ones. A few questions where we could not tell from the diff, and two tests we would like to see.
For tests: the two-image shared-page case from point 3, and one that traps the same image at two labels in a row, which also pins the no-op trap from #13442. |
|
Thanks. The description now has paired captures from the same machine and scene. There are four captures with
The second round's summary lines, both traces and their AI-assisted: yes |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
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.
|
✅ NVIDIA GPU test: passedPR head
Unstable on main (2, 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 689 tests)Skipped (41)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. |
|
Thanks, all four held up.
Two labels in a row on the same image were already in the test: two Five negative controls fail the test on the new head. The 82 recorder entries with the validation layer report the same AI-assisted: yes |
✅ NVIDIA GPU test: passedPR head
Unstable on main (1, these also failed in recent main runs on this machine; not counted against this PR)Failing on main too (4, not counted against this PR)Validation IDs already present on main (5 IDs in 706 tests)Skipped (50)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. |
|
Windows data on how much a Windows version of this could gain. It's an upper bound, not a test of this PR. Windows 11 Enterprise 10.0.22621, Ryzen 9 5950X, RX 6700 XT, Afterimage (PPSA14053) intro at 3840x2160. On this scene the label store is the committer's largest stall. A committer sampler profile puts 25% of the committer's samples in To bound the gain, I skipped the store entirely with
AI-assisted: yes (Claude Code). |
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>
5e529c2 to
0fdd66d
Compare
|
Checked the diff, the release paths and the shared-page and direct-memory alias rules. Dean's four points are covered by |
The conflict with boykopovar#13499 in docs/dev/debt/libSceAgcDriver.md keeps both sides: this branch's Pending storage-image results entry, then boykopovar#13499's Label read traps entry.
What
Builds on #13442. Until it merges, this branch carries its commits; only
2cf5b41ec8and0fdd66d900are new here.StorageTexture::StoreReadbackBeforeLabelwrites back every pending linear or small storage image before each label, whether or not the CPU reads it. On macOS this PR traps CPU reads of such an image with #13442's write-watch read traps instead of storing it, so the store happens only when something reads or writes its memory.GuestWriteWatchTrapReadsover its exact range instead of its store. The alias check is a new libkernel export,DirectMemoryAliased_nid_postfix, which tells whether any of a range's physical memory is mapped by another direct mapping. If the trap cannot be set (unwatched memory, a host write in progress), the image is stored as before. feat(libc): trap guest reads of write-watched pages on macOS #13442 makes a trap of an already trapped range a no-op, so the same range can be trapped at every label without the driver tracking it.GuestMemory::FlushGpuWritesover the trap's range on the write watch's resolver thread. That is the host-read hook every other reader of guest memory uses: it stores the pending results and waits until they are in memory. While a queued draw still holds reads of the range (DrawPipeline::HeldReads, which makes the store wait), it retries.writeBackLayers, soFlushPending, cache eviction (Flush),WriteBackand refreshes all do. A store that copies into the import on the GPU releases it once the copy is recorded, so a read that faults before then waits for the store. A store through the CPU releases it before its first access to guest memory, together with the traps of other images on the same pages; those images stay pending and are trapped again at the next label. A trapped image is stored whole.APS5_NO_LABEL_READ_TRAP=1keeps the store at the label. Linux and Windows are unchanged.Gaps, in the new entry of
docs/dev/debt/libSceAgcDriver.md:GpuMutexand touches a trapped image waits for the resolver forever;EFAULT;The page rule keeps the storing thread from faulting on a page another image's trap covers. If it did, the resolver would wait for that store while the store waits for the resolver.
Tested
Apple M5 Pro, macOS 27.2, MoltenVK from Vulkan SDK 1.4.363, x86-64 Release under Rosetta 2.
mainalone does not build on macOS, so the tests and the game ran in a tree with the open macOS port PRs, where these files are identical.agc_small_tiled_shadow_label(agc_driver_recorder_tests --small-tiled-shadow-label-only) gets a trap check on macOS. After the image is written again on the GPU:FlushPendingstores it and gives the page back;FlushPendingwhile the test holdsGpuMutex, which takes the image out of the pending registry and waits. The page is still without access; a read started then sees the stored results once the test releases the mutex.Two 8x8 linear images on one page (both architectures' page size):
FlushPendingwith the reasonidle, which takes the CPU path) completes, stores the second and gives the page back. The next label traps the first again, and a read sees its results.The test thread releases
GpuMutexaround the read, since the resolver needs it. The test passes with and withoutAPS5_NO_LABEL_READ_TRAP=1.Negative controls, each of which fails it:
writeBackLayers: "storing a trapped image did not release its trap";FlushPendingtakes the image out of the registry, as before: "a trapped image taken for a store gave back its pages before the store";FlushPendingwithout waiting: "a read of a trapped image did not see its pending results".The 82 CTest entries of
agc_driver_recorder_testspass, except one skip andagc_recorder_failed_check, which fails the same way withAPS5_NO_LABEL_READ_TRAP=1. The write-watch tests pass on x86-64 and arm64 (#13442). The whole-image store of a trapped image and the alias check are not covered by a test: these images have one layer, the recorder test's memory is not direct memory, andguest_memory_testsdoes not build on macOS (sceKernelMunmap).PPSA21564 (ASTRO BOT 01.007.000), the logos before the intro.
maindoes not build on macOS without the open port PRs, so the base is that tree with #13220 and #13442 (5b2b0eb50830), and the change is the same tree with this commit'sTexture.cpp(1f0553384a68). Captures withAPS5_TRACE_FRAMES=150:240and no other trace or profile switch, alternated base, change, base, change:5b2b0eb508301f0553384a685b2b0eb508301f0553384a68Summary lines of the second round. Base:
{"commit":"5b2b0eb50830","dirty":null,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_DUMP_FRAMES":"200","APS5_DUMP_FRAMES_EVERY":"60","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"150:240"},"gpu":"Apple M5 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":18,"memory_mib":49152,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"frames 150:240","first_present":150,"ms":6300.896},"presents":240,"frame_ms":{"p50":26.029,"p90":28.079,"p99":30.286,"max":55.441},"gpu_busy_ms_per_present":19.524,"worker_busy_pct":{"queue worker 0x0":98.610,"queue worker 0x40":99.662,"queue worker 0x48":97.088,"queue worker 0x3a":0.060},"top_phases_ms_per_frame":{"Driver.Packet":76.611,"Driver.Packet.memory_wait":46.970,"Driver.Packet.dispatch":15.657,"Driver.Dispatch":14.064,"VideoOut.Flip":6.645,"Vulkan.DispatchRecipe":5.770,"Vulkan.DispatchRecipe.command_record":5.765,"Driver.Present":5.472},"trace_dropped":false,"trace":"aps5-trace-5b2b0eb50830-47155.json.gz"}This PR:
{"commit":"1f0553384a68","dirty":null,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_DUMP_FRAMES":"200","APS5_DUMP_FRAMES_EVERY":"60","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"150:240"},"gpu":"Apple M5 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":18,"memory_mib":49152,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"frames 150:240","first_present":150,"ms":5043.434},"presents":240,"frame_ms":{"p50":20.649,"p90":22.565,"p99":25.074,"max":42.485},"gpu_busy_ms_per_present":11.920,"worker_busy_pct":{"queue worker 0x0":98.392,"queue worker 0x40":99.649,"queue worker 0x48":86.217,"queue worker 0x3a":0.058},"top_phases_ms_per_frame":{"Driver.Packet":59.510,"Driver.Packet.memory_wait":36.905,"Driver.Packet.dispatch":12.250,"Driver.Dispatch":11.379,"Vulkan.DispatchRecipe":6.837,"Vulkan.DispatchRecipe.command_record":6.833,"VideoOut.Flip":6.486,"Driver.Present":5.521},"trace_dropped":false,"trace":"aps5-trace-1f0553384a68-47301.json.gz"}Traces: base, this PR.
trace_digest.py, base (second round)frames 150:240 from present 150: 240 presents, frame p50 26.0 / p90 28.1 / p99 30.3 / max 55.4 ms, GPU busy 19.5 ms per present
Apple M5 Pro, MoltenVK 1.4.2, Darwin 27.2.0, 3840x2160, commit 5b2b0eb50830, dropped: no
{"commit":"5b2b0eb50830","dirty":null,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_DUMP_FRAMES":"200","APS5_DUMP_FRAMES_EVERY":"60","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"150:240"},"gpu":"Apple M5 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":18,"memory_mib":49152,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"frames 150:240","first_present":150,"ms":6300.896},"presents":240,"frame_ms":{"p50":26.029,"p90":28.079,"p99":30.286,"max":55.441},"gpu_busy_ms_per_present":19.524,"worker_busy_pct":{"queue worker 0x0":98.61,"queue worker 0x40":99.662,"queue worker 0x48":97.088,"queue worker 0x3a":0.06},"top_phases_ms_per_frame":{"Driver.Packet":76.611,"Driver.Packet.memory_wait":46.97,"Driver.Packet.dispatch":15.657,"Driver.Dispatch":14.064,"VideoOut.Flip":6.645,"Vulkan.DispatchRecipe":5.77,"Vulkan.DispatchRecipe.command_record":5.765,"Driver.Present":5.472},"trace_dropped":false,"trace":"aps5-trace-5b2b0eb50830-47155.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 73.1, Driver.Packet.memory_wait 46.9, batch 19.5, Driver.Packet.dispatch 15.3, Driver.Dispatch 13.6, VideoOut.Flip 6.6, Driver.WorkerWait 6.3, Vulkan.DispatchRecipe 5.7, Vulkan.DispatchRecipe.command_record 5.7, Driver.Present 5.5
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, this PR (second round)frames 150:240 from present 150: 240 presents, frame p50 20.6 / p90 22.6 / p99 25.1 / max 42.5 ms, GPU busy 11.9 ms per present
Apple M5 Pro, MoltenVK 1.4.2, Darwin 27.2.0, 3840x2160, commit 1f0553384a68, dropped: no
{"commit":"1f0553384a68","dirty":null,"env":{"APS5_ASYNC_PIPELINES":"1","APS5_DUMP_FRAMES":"200","APS5_DUMP_FRAMES_EVERY":"60","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_DIR":"<path>","APS5_TRACE_FRAMES":"150:240"},"gpu":"Apple M5 Pro","driver":"MoltenVK 1.4.2","os":"Darwin 27.2.0","cpu":"VirtualApple @ 2.50GHz","cpu_threads":18,"memory_mib":49152,"title_id":"PPSA21564","title":"ASTRO BOT","content_version":"01.007.000","resolution":"3840x2160","window":{"spec":"frames 150:240","first_present":150,"ms":5043.434},"presents":240,"frame_ms":{"p50":20.649,"p90":22.565,"p99":25.074,"max":42.485},"gpu_busy_ms_per_present":11.92,"worker_busy_pct":{"queue worker 0x0":98.392,"queue worker 0x40":99.649,"queue worker 0x48":86.217,"queue worker 0x3a":0.058},"top_phases_ms_per_frame":{"Driver.Packet":59.51,"Driver.Packet.memory_wait":36.905,"Driver.Packet.dispatch":12.25,"Driver.Dispatch":11.379,"Vulkan.DispatchRecipe":6.837,"Vulkan.DispatchRecipe.command_record":6.833,"VideoOut.Flip":6.486,"Driver.Present":5.521},"trace_dropped":false,"trace":"aps5-trace-1f0553384a68-47301.json.gz"}Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 56.2, Driver.Packet.memory_wait 36.9, batch 11.9, Driver.Packet.dispatch 11.9, Driver.Dispatch 10.9, Vulkan.DispatchRecipe 6.7, Vulkan.DispatchRecipe.command_record 6.7, VideoOut.Flip 6.5, Driver.WorkerWait 6.3, Driver.Present 5.5
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
Over whole 120 s runs, counting the frames dumped every 60 presents, the same comparison gives 44.0 and 44.3 FPS against 38.1 and 37.1 with
APS5_NO_LABEL_READ_TRAP=1. With0fdd66d900it gives 44.2 and 44.7 against 38.2, 37.8 and 37.8; one more run with the traps, the first after the rebuild, gave 22.3. The image is the same. In an earlier instrumented run of this design, no trap was resolved by a read in that scene: the emulator itself stored every trapped image, about 65 times a second, before any guest read.Validation: the 82 CTest entries of
agc_driver_recorder_testswithVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1(ctest -V) on the base and on this PR report the same 152VUID-VkDeviceCreateInfo-pProperties-04451lines (the test device does not enableVK_KHR_portability_subseton MoltenVK, #10920) and no otherVUID-. Neither log reports the layer as not found.Not tested on a title that reads these images from the CPU.
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)🤖 Generated with Claude Code