fix(agc): prepare a draw or dispatch again when the memory it captured changed before it was recorded #7446
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7446"
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 EagleBearerYS on 2026-10-18T06:49:49Z.
What
Onimusha: Way of the Sword (PPSA27836) gets a draw that binds zeros where the game has written buffer descriptors. In frankea's run on #5769 (
main5de7a46e0bplus a diagnostic branch, Windows 11, RTX 4090, cold and warm caches), it shows once per run, before any input:main's. The second comes from the diagnostic branch, which isn't in this PR. Every record it lists is a capture of eight zero dwords where the live memory now holds a V#: records 0x30 apart, read by one draw on queue 0.Why the zeros stay:
AddSnapshotonly warns for a live region, so a table the title writes in that window stays bound as captured.The change: at the last point the queue worker handles a draw or dispatch, it compares the regions it captured with guest memory. If they differ, it prepares the packet again from current memory, once.
AddSnapshotreads them, with no flush and no sync.[labels]line counts the packets prepared again "for captured memory that changed before recording".Related:
libSceAgcDriverdebt entry says. This PR updates that entry.What it doesn't cover:
AddSnapshotstill only warns there;APS5_DRAW_PIPELINE, off by default): it isn't prepared again, and commits as onmain.Cost, on a synthetic draw harness modeled on Resident Evil Village (PPSA01556)'s draw stream (not in the tree; Linux, lavapipe, 100 frames of 1,000 draws). Each draw compares 9.5 regions, 978 bytes.
memcmpof the same bytes, for scaleTested
check_skipspasses.mainf1af6c5915. The only status changes are the four new tests. The 5 failures on both are that machine's IPv6 tests.agc_driver_draw_recapture_on_change(pipelined, and_inlinewithAPS5_PIPELINED_DRAWS=0): a draw through a descriptor table whose V# changes from zero to valid after the capture must bind the valid V# and be prepared again once. An unchanged table is not prepared again. Red: "the draw bound the zero V# captured before the table changed".agc_driver_dispatch_recapture_on_change(and_itemswithAPS5_PIPELINE_DISPATCH=1): the same for a dispatch whose table's V# moves to another buffer.Driver::SetCaptureCheckHook, with no second thread.APS5_GPU_CHECKPOINTS=1(comment). The tree ismainb51c65dplus #7506, a libc export the title needs to load, with and without this PR, one run each, from the menus to the first story-mode load:captures of 0x20 bytes in
0x2112c00000+0x10000that differ from registered memory: 2 without this PR and 0 with it; withAPS5_NO_HOST_IMPORT=1, 4 without and 1 with;with host imports off, the run with this PR also logged four warnings the run without it didn't, 0x38 bytes at +0x158 of four 2 MiB regions. They didn't come back in the reruns below;
both stop where
mainstops: #6374's device loss with host imports, and aregister 0x203refusal without them.Reruns with host imports off and
APS5_PROFILE_DRAW=1, two runs of each build, alternated, on the same tree and route (comment):All four stop at the same
register 0x203 = 0x00000045refusal. The single runs above with host imports off had totals of 38 without this PR and 17 with it. The prepared-again count is the last one the[labels]line printed (about every 10 s).mainc3591adf9with and without this PR (3fd9a62aed), two runs each, one of each withAPS5_PROFILE_DRAW=1:guest snapshot differs from registered memorywarning (snapshot 0x2112c002e0+0x20);[labels]line counts one packet redone for captured memory that changed before recording, from its first report on, in the same window;WAIT_REG_MEM_64timeouts and "still pinned" lines vary from run to run on plainmaintoo, so frankea reads nothing into them.3fd9a62aedonmain6efb7261bwith 13 other open PRs, built once as one tree (comment):agc_driver_dispatch_recapture_on_changeandagc_driver_draw_recapture_on_changepass 3 of 3 runs;agc_*tests, 713 of 716 pass. LeandroLP23 reports that the 3 that fail (agc_driver_host_import_lifetime,agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl) fail the same way on unchangedmainthere.cc60990a43, a merge ofmain0db47b263d. The only conflict was inDraw.cpp:main's #6946 moved the second half ofdraw()intofinishDraw, which runs inline by default, or on a draw finisher thread withAPS5_DRAW_PIPELINEset. This PR's checks moved intofinishDrawwith it, and prepare the draw again through its queue and packet, asmain's own label recapture does. A draw finished on the finisher thread has no queue to prepare from, so it isn't checked (see What it doesn't cover). On GitHub's runners (run), the four tests pass 10 runs in a row on Linux, none skipped. On Windows they build and skip, as the runner has no Vulkan device. The libc and libkernel suites pass on both, run withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.^agcsweep on Linux (run): 856 of 920 pass, 62 skip and 2 fail:agc_driver_sgpr_pattern_fill_keys,main's #8715 test, under the sweep's parallel load ("the dispatch completed 17 times without a pending write over the keys"), as onmain;agc_driver_queued_index_read_order,main's #6914 test ("the queued draw's commit stored the image's results over its index buffer"). Run alone with up to 20 repeats, it fails on its first run with "the image write left no pending result to order against": on this merge (run), on #9129's merge of the samemain(run), whose diff doesn't touch the draw path, and onmain0db47b263ditself (run).main'sagc_driver_pipelined_metadata_passandagc_driver_pipelined_metadata_pass_draw_pipeline(from #6946) fail atvkCreateInstance(-9) on GitHub's device-less runner, before this PR's code; upstream's Windows job builds them as skipped stubs.cc60990a43, on an NVIDIA GeForce RTX 3070 Laptop GPU (driver 617.42), Windows 11 10.0.26300, WinLibs GCC 15.2.0, Release, the case wachi35676 reported and GitHub's Windows runner can't run. Each run makes 3 host imports.0623263512) reverted on the same head:agc_driver_draw_recapture_on_changefails on its 4th run and_inlineon its 9th, with wachi35676's message ("brightest color byte 0 (the zero V# captured before the change was bound), 1 packet(s) prepared again"); the two dispatch tests pass 10 of 10. That matches LeandroLP23's bisect on AMD.APS5_PROFILE_DRAW=1.1d6d1ff5a5, a merge ofmain19cb822f84, after adriadam10's approval atcc60990a43. The only conflict was indocs/dev/debt/libSceAgcDriver.md.main(#8281) rewrote the shader float mode entry, and this PR changes the WAIT_REG_MEM entry under it; the merge keepsmain's float mode entry and this PR's WAIT_REG_MEM entry.main's changes toDriver::dispatchandDriver::finishDraware away from this PR's checks. This PR's added and removed lines are unchanged.agc_driver_draw_recapture_on_changeandagc_driver_dispatch_recapture_on_changepass: 2 run, 2 pass, 0 skip, 0 fail. On Windows both skip, since the runner has no Vulkan device: 2 run, 0 pass, 2 skip, 0 fail.APS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.0x10de:0x2c05) and an AMD Radeon RDNA2 iGPU (0x1002:0x13c0), Windows 11, by @wachi35676 (comment):1d6d1ff5a5merged ontomainb90d009d9fwith the fourdrawcalls takingtail.packetOffset(see the next bullet), WinLibs GCC 15.2.0, Release,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, host imports on.agc_driver_draw_recapture_on_change,_inline,agc_driver_dispatch_recapture_on_changeand_itemspass 3 of 3 on both GPUs, none skipped. The draw case reportsbrightest color byte 255 (the valid V# was bound), 1 packet(s) prepared again, so the failure they reported at3fd9a62aeis gone.a4a99c3afc, a merge ofmain47f9cee2cd(run). The textual merge is clean, butmain'sea65a95401(#5431) givesDriver::drawapacketOffsetparameter, and this PR's four redraw calls inDraw.cppdidn't compile against it, as wachi35676 found. The merge passestail.packetOffsetthere, asmain's own redraw after captured labels does. This PR's other changed lines are the same as before. The four recapture tests pass 10 runs in a row on Linux: 4 run, 4 pass, 0 skip, 0 fail. Windows builds them and skips all 4, since that runner has no Vulkan device. Suites: libc and libkernel pass on Linux (144 and 209), and libc passes on Windows (171). Windows' libkernel suite runs 227 tests and failsguest_timed_join_import_libkernel_sysandguest_timed_join_import_libkernel_web, which this PR doesn't touch;main88f99678bffails the same two in this verify's Windows job (run), andmain's own Windows CI passes them. The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.a4a99c3afconmain898a7fef4, rechecked by @wachi35676 (comment): the pushed head merges cleanly and builds without changes. On the RTX 5070 Ti and the AMD RDNA2 iGPU, with host imports on,agc_driver_draw_recapture_on_change,_inline,agc_driver_dispatch_recapture_on_changeand_itemspass 3 of 3. The changed-table draw reportsbrightest color byte 255 (the valid V# was bound), 1 packet(s) prepared again.0b272314cc, a merge ofmain0836dfdf4f(run). #12862 movedlibSceAgcDriver's test registrations intotests/cmake/; the conflict inCMakeLists.txtis resolved withtools/agc_test_split.py resolve, which moves this PR's registrations into a newtests/cmake/agc_driver_draw_recapture_on_change_tests.cmake(+10 lines). Nothing else conflicted. Apart from the move, this PR's diff is unchanged. With-DBUILD_TESTING=ON,ctest -Ngives 3079 tests:main's 3075 plus its 4 tests, each listed once.agc_driver_dispatch_recapture_on_change,agc_driver_dispatch_recapture_on_change_items,agc_driver_draw_recapture_on_change,agc_driver_draw_recapture_on_change_inlinepass 10 runs in a row. Linux: 4 run, 4 pass, 0 skip, 0 fail. Windows: 4 run, 0 pass, 4 skip (no Vulkan device), 0 fail. Suites: libc and libkernel pass on Linux (199 and 308) and on Windows (226 and 330). The suites ran withAPS5_SKIP_TIMING_TESTS=1, which relaxesprecise_wait's median bounds on GitHub's hosted runners.Checklist
mainf1af6c5915, withmain0db47b263dmerged in atcc60990a43andmain19cb822f84at1d6d1ff5a5(merges cleanly with currentmain); no other open PR implements the same functions. Overlaps (git merge-treewith each PR merged intomain1c523bdb48), each in adjacent lines where both sides stay:Draw.cpp: #1896 (indirect draws pipelined behind the packet worker, draft) widens the pipelined branch to indirect draws where this PR adds its check; keep #1896's condition with the check in the branch. #6612 (tessellation followed by an NGG geometry stage) and #6679 (merged hull programs) look up the indirect user-data words withUserDataWordsnext to this PR'srecordedOne; keep their lookups and addrecordedOne.Dispatch.cpp: #5497 (DCC keys read behind a pattern fill kernel's fast clear) adds its pattern match where this PR addscaptureChecked; keep both.Driver.hpp: #7275 (opt-in render-state overrides) declaresHotReloadShadersnext toSetCaptureCheckHook; keep both.GuestBufferMemory.cpp: #6636 (ours, reused address-based draw builds) moves the live-snapshot condition intoliveSnapshotCompared, where this PR addssnapshot.compared; the merge readslive && (snapshot.compared || !liveSnapshotCompared(snapshot.address, snapshot.bytes.size())).libSceAgcDriverdebt file: #6760 (f64 min and max input denormal mode) edits the shader float mode entry, the line before the WAIT_REG_MEM entry this PR edits; keep both.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)Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-18T11:06:47Z.
Tested on the title and on NVIDIA, the two items under "Not tested".
Tree: main
b51c65d+ #7506 (the title needs that libc export to load) + this PR (3fd9a62). Windows 11 26200, RTX 5070 Ti (NVIDIA 617.42), WinLibs GCC 15.2.0 r7, Release,APS5_GPU_CHECKPOINTS=1. Dump 01.000.001. Same path every run: menus, New Game, difficulty, layout, then the first story-mode load. One run per row; "without" is the same tree minus this PR.0x2112c00000+0x10000read invalid at 0x4840000read invalid at 0x4840000APS5_NO_HOST_IMPORT=1, withoutregister 0x203 = 0x00000045refusalAPS5_NO_HOST_IMPORT=1, withThe running total is main's "N mismatches so far"; the log prints only some of the warnings.
0x2112c00000+0x10000are the ones in your description. They go from 2 to 0 and from 4 to 1. The one left with the PR:+0x158of four 2 MiB regions (0x2111000000,0x210d800000,0x210e800000,0x2110c00000). The first isdiffers first at +0x0and is the run's first mismatch. With one run each, I can't tell whether they come from the PR or just didn't show in the baseline run.[labels]line, so I couldn't read the "prepared again" count. If it needs a switch, say which and I'll rerun.Not run: repeated runs, AMD, Intel.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T11:13:42Z.
@cadenasynyster thank you, that covers both open items. The
[labels]line needsAPS5_PROFILE_DRAW=1(any value), and it prints about every 10 s. If you have time for a rerun, the host-imports-off pair two or three times each with that switch would show whether the four 0x38-byte warnings at +0x158 follow this PR, and how many packets it prepared again in those runs.The four lines may only be sampling: the warning prints at most one mismatch every 10 s, with a running count. With the 0x2112c00000 captures gone, other mismatches get the printed lines instead, and your totals (38 without this PR, 17 with it) point that way. So the last "(N mismatches so far)" of each rerun, with and without this PR, is the number to compare.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:33:32Z.
AMD on Windows: the tests this PR names pass on an RDNA 3.5 GPU.
Radeon 860M (RDNA 3.5, driver 32.0.13058.8001), Windows 11 26300, WinLibs GCC 15.2.0 r7, Release.
main6efb7261bwith this PR (3fd9a62ae) merged, together with #7296, #7377, #7445, #6708, #6748, #6785, #6706, #6613, #7449, #7391, #7489, #7484, #7514. They were built once, so the result is for the combination; each merge was clean.agc_driver_dispatch_recapture_on_change,agc_driver_draw_recapture_on_change: pass, 3 runs of 3.agc_*test on the combined build: 713 of 716 pass. The 3 that fail,agc_driver_host_import_lifetime,agc_driver_quad_pixel_maskandagc_driver_layered_volume_vertex_no_gpl, fail the same way on unchangedmainhere, so none comes from these PRs.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T16:39:28Z.
@LeandroLP23 thanks for running them on the Radeon 860M. Your run is now in the Tested section, with your note that the three
agc_*failures fail the same way on unchangedmainthere.Imported from boykopovar/AnyPS5. Originally posted by cadenasynyster on 2026-10-18T17:04:41Z.
Reruns as you asked: host imports off (
APS5_NO_HOST_IMPORT=1),APS5_PROFILE_DRAW=1, two runs of each build, alternated (without, with, without, with). Same tree as before: mainb51c65d+ #7506, with or without this PR (3fd9a62). Windows 11 26200, RTX 5070 Ti (NVIDIA 617.42), WinLibs GCC 15.2.0 r7, Release. Same route every run, until the title stops on its own.register 0x203 = 0x00000045refusal[labels]line wraps, so the number is on the line before the words "captured memory that changed before recording" ("…, 2 for captured memory that changed before recording"). It was 2 in both runs, as of the last report; the log prints it about every 10 s.0x203refusal in all four.Not run: host imports on with the switch, more than two runs of each, AMD, Intel.
AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-18T17:12:35Z.
@cadenasynyster thanks for the reruns. With host imports off, the last mismatch total is 61 and 52 without this PR and 5 and 11 with it, the four 0x38-byte warnings didn't come back, and all four runs stop at the same
register 0x203refusal. Both pairs are now in the Tested section, next to your first runs.Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-19T00:13:18Z.
Tested at
3fd9a62aeon Windows 11 (GCC 15.2.0, Release), merged ontomain9f25d0bf5, on an RTX 5070 Ti (617.42) and an AMD Radeon iGPU, RDNA2 (1002:13c0, 32.0.21042.62,ANYPS5_GPU=AMD).agc_driver_draw_recapture_on_changeandagc_driver_draw_recapture_on_change_inlinefail on both GPUs, 3 of 3 runs each:With
APS5_NO_HOST_IMPORT=1, both pass 3 of 3 on both GPUs. So on Windows with host imports, the packet is prepared again but the draw still binds the stale V#. The Windows CI runner skipped these tests (no Vulkan device), so this path hadn't been run before.agc_driver_dispatch_recapture_on_changeand_itemspass on both GPUs, and the rest of the 719-testagc_|shader|recompilerset shows no change againstmain.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T15:19:38Z.
Review: CHANGES_REQUESTED
Thanks for the thorough testing. Two things block this:
3fd9a62ae(Windows, RTX 5070 Ti and Radeon RDNA2) thatagc_driver_draw_recapture_on_changeandagc_driver_draw_recapture_on_change_inlinefail 3 of 3 with host imports: the packet is prepared again ("1 packet(s) prepared again") but the draw still binds the zero V#. WithAPS5_NO_HOST_IMPORT=1both pass. Host imports are the default path on Windows, so the recapture does not do its job there, and the Windows CI runner skips these tests, so nothing covers it. Please find why the second pass still reads stale bytes for a host-imported region (the import window or a cached mirror serving the old content) and fix it, or show that the test setup is what differs.main:Draw.cpp(the surrounding code changed, so the check placement needs another look) anddocs/dev/debt/libSceAgcDriver.md. Please rebase and rerun the four tests.Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-19T15:41:12Z.
@adriadam10 @wachi35676 the host-import failure depends on the
mainthe head is merged into, and #7476 (7a2e4a4e7) is what makes it pass. Radeon 860M (RDNA 3.5), driver 32.0.13058.8001, Windows 11, WinLibs GCC 15.2.0, Release,ANYPS5_NO_SHADER_CACHE=1, head3fd9a62aemerged into each base, only this PR:mainbasedraw_recapture_on_changeand_inline, host imports on (default)APS5_NO_HOST_IMPORT=19f25d0bf5(wachi's base)brightest color byte 0 (the zero V# captured before the change was bound), 1 packet(s) prepared again7a2e4a4e7^1, just before #74767a2e4a4e7, #7476 merged6efb7261b(my earlier base)So I can reproduce wachi's failure on AMD's driver too, and my earlier pass came from a base that already had #7476. Only 7 merges separate the two bases, and #7476 is the only one that touches the write watch. Host imports were active in my runs: the log shows
[write-watch] host imports of write-watched memory keep the write watch: yes.I couldn't check the current head against today's
main, since it conflicts. Rebased onto amainwith #7476, it should no longer fail with host imports. If #7446 needs #7476's re-watch for this case, it could list it under "Depends on".AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-21T03:40:03Z.
@adriadam10 The branch now merges
main(94d5a26066), which resolves the conflicts inDraw.cppand the debt entry, and brings in #7476.3fd9a62aecame from the base the head was merged into. Both draw tests fail on amainjust before #7476 and pass once #7476 is in (Radeon 860M, AMD's Windows driver). Now that the branch carries #7476, the case it fixes is covered.73983f1c29queues the last drawable record of a CPU-path indirect draw on the draw pipeline when no earlier record was drawn inline. That path skipped the check this PR runs before the first record is recorded, so the merge adds it there: the captured memory is compared before enqueuing, as the direct pipelined path does.@wachi35676, @LeandroLP23: could one of you rerun
agc_driver_draw_recapture_on_change,agc_driver_draw_recapture_on_change_inlineand the two dispatch tests on Windows with host imports on, at94d5a26066? That's the case the Windows runner can't cover.