perf(agc): create the host import of a linear color target in registered memory #9879

Merged
thuanquang merged 10 commits from upstream-pr/9879 into main 2026-10-26 19:18:22 +00:00
thuanquang commented 2026-10-22 20:27:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-22T20:27:37Z.


What

A linear color target gets a resident image only when its memory already has a host import (#6892). Every other draw into it is synchronous: copied in, drawn, waited for on the CPU and copied back. #6892 only looked the import up, because a first version that made it broke agc_driver_pixel_ancillary_word and agc_driver_pixel_fixed_point_position: the import over a short-lived block was compared, and the next block allocated at the same address stayed outside the write watch. Since #6759, a page committed again inside an excluded block is watched again.

On a lookup miss, the draw now makes the import itself, with a new ImportRequester::ColorTarget, when all of these hold:

  • the target could become resident anyway (resident linear targets, resident targets and the detiler are enabled);
  • its registered ranges are writable, and the whole import run, not only the target, is write-watched;
  • the import keeps it watched: a separate alias of shared memory, a direct import of private memory that settles on Windows (1 MiB or more, when the import probe keeps the watch and a settle queue exists), or an import the probe keeps watched on other systems, where a dma-buf import must stay watched too if the range has shared backing.

On Windows, resident direct-memory runs, where PPSA14363's targets live, are read-write, write-watched private pages since #9181, so they pass the writable check like any other private page.

A refused run is remembered until the registry, the committed pages (Windows) or the write watch change, or a shared alias is mapped over it, so a target that stays synchronous costs a map lookup per draw instead of a page scan. importRunAt checks this after its remembered failures and refusals and before it retires or evicts anything, through two helpers its own decision now uses: importWatching (settled, watched host-pointer and dma-buf imports) and importPages (the Windows page scan, moved out of importRunAt). A target whose import would be compared stays synchronous, because a compared import makes every refresh of the resident image compare the whole target. A target over an import that already exists is resident as before, with ExistingHostImportFor as the fast path, and APS5_NO_RESIDENT_LINEAR=1 still keeps every linear target synchronous. The debt file gets an entry for the targets that stay synchronous.

This is the case draft #1191 (@MichonGoddijn231849) was to bring back on top of #6892 once partial-block write-watch coverage existed. It builds on #9685: without #9685, a resident linear target is stored whole after every draw, which is slower than the synchronous path for PPSA14363's three 24 MiB targets. The branch therefore contains #9685's commits; this PR's change is commit 175d986c28. After it come @oneandonlydean's merge of main (f59787b272) and a merge of #9685's current head 5b5dcaeaff, then a merge of main 6c52b649e7 (fe1927d398), then a merge of #9685's head d36311d661 (b58a21d9f4).

Why

PPSA14363 (METAL GEAR SOLID - Master Collection Version, own dump) draws its PS1 game into three linear 3072x2048 RGBA8 color targets whose memory has no host import, so on main every draw into them is synchronous. Bring-up thread: #9615.

Tested

Windows 11 26200, Radeon RX 6700 XT (gfx1031), AMD driver 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release, BUILD_TESTING=ON.

Current head e1fa56c7bf: main ae7d59258e merged in after #9685 merged (6adad6733c, clean), plus one commit for #9181. #9181 stopped write-protecting resident runs on Windows, so the special case that counted armed read-only private pages as writable could no longer change a decision, and --armed/--armed-gate could only skip ("the collects did not arm the resident run read-only"). The commit removes the special case; resident runs pass as writable private pages. --armed becomes --direct and --armed-gate becomes --private-gate, without the arming step (see the test list). On the RX 6700 XT:

  • The build is clean, and agc_driver_linear_target_import_creation runs every case with no skip.
  • The focused set plus agc_driver_bda_* (57 ctest entries) passes 3 of 3. With the Khronos validation layer, 57 of 57 pass with 0 VUID- lines (the layer was inserted 78 times, no "was not found" line).
  • Red: with the gate's page walk removed (the registry's writable flag trusted), the test fails 3 of 3 at the --private-gate block: "read-write alias of shared guest memory 0x200100000+0x20000: the range does not start at a shared view".
  • PPSA14363 on this head, merged onto main 5b5d24cb22 (2026-10-26), with the exclusive GPU lock and the build lock. League of Legends was open on the PC, and no other game ran. The same route2 input on both sides, 480 s each:
    • This head: 600 presents per 10 s in every window from 40 s, frame p50 16.7 ms, p99 17.1 to 26.2 ms. The codec line "The Codec's receiver directly stimulates the small bones of your ear." comes at 111 s, and Dock gameplay with the radar by 131 s.
    • main alone: 56 to 68 presents per 10 s from 90 s, p50 234 to 326 ms. The codec line comes at 423 s, and the Dock is not reached in 480 s.
    • Details are in #9217. The table below is older, measured before #9181.

Earlier head 5575dc3108: a merge of #9685's head d6d8966bba (main b930da950d merged into #9685, only CMakeLists.txt conflicted there); this merge itself was clean, and the head merges cleanly with main 6cd36e6517. On the RX 6700 XT the build is clean. The focused set plus agc_driver_bda_* (55 ctest entries) passes 3 of 3. With the Khronos validation layer, 55 of 55 pass with 0 VUID- lines (the layer was inserted 74 times, no "was not found" line). ctest -R "^(agc|shader)_" passes 1010 of 1015: the 3 sample_order tests main fails on this GPU, plus agc_driver_sgpr_pattern_fill_keys and an agc_async_log_fatal timeout, both while four game instances ran next to the suite; run alone against this head's libraries, both pass 5 of 5.

Earlier head b58a21d9f4: a merge of #9685's head d36311d661, the per-64 KiB-block keep for drawn targets from @oneandonlydean's review on #9685 (details and red/green there). Only the debt file conflicted: #9685's narrowed entry and this PR's entry on the next line; both are kept. Tested on this head (RX 6700 XT, AMD driver 32.0.21045.16010): builds clean; the focused set with agc_driver_bda_* and #9685's agc_driver_linear_target_direct_write_completion (54 ctest entries) passes 3 of 3; with the Khronos validation layer 54 of 54, 0 VUID- lines, the layer inserted 72 times; ctest -R "^(agc|shader)_" 996 of 1002 with the 3 sample_order failures main has on this GPU and 3 timeouts under load from a parallel game run (shader_cache_runtime_sources, agc_driver_native_fmask, agc_driver_native_depth_clears), which pass when rerun alone.

Earlier head fe1927d398: a merge of main 6c52b649e7 on top of bb58e7ddbd. It resolves the logic conflict with #7465 in importRequesterTests that @oneandonlydean found: #7465's mapped range keeps pieces 6 and 7, and this PR's color-target block moved to its own pieces, 10 (writable) and 9 (read-only), with piece 8 left unregistered so that 10 is a run of its own, as 6 was before. Tested on the merge (RX 6700 XT, AMD driver 32.0.21045.16010): builds clean; the focused set with agc_driver_bda_* (54 ctest entries) passes 3 of 3; with the Khronos validation layer 54 of 54 pass, 0 VUID- lines, the layer inserted 72 times, no "was not found" line; ctest -R "^(agc|shader)_": 999 of 1002 pass, with the same 3 sample_order failures as main on this GPU. On fe1927d398 itself (only BdaResources.cpp differs from that merge): agc_driver_bda_* (7 entries) passes 3 of 3, and 7 of 7 with the validation layer, 0 VUID- lines.

Earlier head bb58e7ddbd: @oneandonlydean's merge of main 11d6efa06c, then a merge of #9685's head 5b5dcaeaff, which adds a fix to #8126's keep rule for drawn targets and a test (#9685's body). The runs below are on 04a6c9e4cc: this PR's commit on the same #9685 change, rebased onto 11d6efa06c. Its tree differs from this head only in the position of one add_test block in CMakeLists.txt and in one debt entry. Builds clean. The focused set with agc_driver_linear_target_import_creation (47 ctest entries) passes 3 of 3. With the Khronos validation layer: 47 of 47, 0 VUID- lines, the layer inserted 65 times, no "was not found" line. ctest -R "^(agc|shader)_": 998 of 1001 pass, with the same 3 failures as main on this GPU (agc_driver_sample_order, _grid_reference, _recipe_depth_locations).

New test agc_driver_linear_target_import_creation, eight cases. On systems other than Windows it forces ImportWatch::Watch for its run, so the watched cases also run on a device whose imports are compared (lavapipe in CI):

  • --created: a target in freshly registered, write-watched memory. The draw is recorded, the target is imported, and its memory stays watched.
  • --reused: a block freed and allocated again at the same address. It is watched, and the next draw starts from the CPU's bytes.
  • --direct (Windows): a 2 MiB resident direct-memory run (GuestArenaMapDirect), the layout PPSA14363's targets use. The draw is recorded, the target is imported, it stays watched, and the pixels are right after the device wait.
  • --private-gate (Windows, whatever the import probe says): a 512 KiB resident direct-memory run and a 128 KiB block whose second half is committed read-only while the registry still calls it writable. Under Unwatch, the run's import, which would be compared (it is below the settle floor), is refused. Under Watch, the read-only block is refused without being counted, and the run is imported.
  • --outside-watch: a 1 MiB block whose last 64 KiB was taken out of the write watch, with the target at its start. No import, a synchronous draw, the target stays watched, and the pixels are right after the device wait.
  • --rewatched (Windows): the same layout, refused once; then the unwatched block is committed again, which brings it back into the write watch without a registry change. The next draw is recorded and imported, so the remembered refusal was dropped.
  • --read-only-registry: a 1 MiB write-watched block that the guest registered read-only. No import and a synchronous draw.
  • --compared: a 64 KiB block whose import would be compared. No import, a synchronous draw, and the block stays watched.

The import requester tests in BdaResources.cpp count the new requester and check that it makes no compared import, no import of a range the guest cannot write, and no import of heap memory outside the write watch.

  • Red, one part of the change removed at a time, each built and run on its own, on 085f3cf29a (this change before the review fixes) except the whole-run check, which was removed from the review-fix tree:
    • The draw no longer creates the import (Draw.cpp of #9685's head, the rest of the change kept): --created, --reused and --armed (now --direct, measured before #9181 with its arming step) fail ("...the draw into a linear target in registered, write-watched memory without a host import waited for the GPU instead of being recorded"); --armed-gate and --compared pass.
    • The gate removed: --compared fails, and so does agc_driver_graphics ("a color target's import was made where imports of its memory are compared").
    • The whole-run watch check removed: --outside-watch fails ("run outside the write watch: a linear target whose import run has a block outside the write watch was drawn into a resident image").
    • The registry's writable flag trusted for every private page, without asking for the guest protection: --armed-gate (now --private-gate) fails, because the import of the block committed read-only throws ("read-write alias of shared guest memory ...: the range does not start at a shared view").
    • The registry's writable check removed from the gate (on 4bd83988c7): --read-only-registry fails ("range registered read-only: a linear target in memory the guest registered read-only was drawn into a resident image").
  • Current head 175d986c28, restacked without conflicts on #9685's rebased head cee2512ef8 (main ff191e29d1; still merges cleanly with 513ca7e558): the focused set plus main's agc_driver_linear_readback_label and agc_recorder_* entries, 26 ctest entries, pass 3 of 3. With the Khronos validation layer on the same set, this head passes 26 of 26 (layer inserted 33 times) and main 513ca7e558 16 of 16 (19 times), with 0 VUID- lines and no "was not found" line on either. This PR's commit is unchanged by the restack; the results below are from the commits they name.
  • Green: on 4bd83988c7 (rebased onto main 9d6adeb550), 18 ctest entries, 3 rounds each, all pass: the new test; #9685's linear-target tests (completion_points with its sync_flip and unpipelined entries, completion_stores, cpu_writes, dispatch_access, draw_bindings, rectangle_bound, resident); address_passes with address_passes_draw_transitions and address_passes_targets_split; store_over_untracked; graphics; pixel_ancillary_word; pixel_fixed_point_position; and host_import_windows.
  • Validation layer (VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1, ANYPS5_REQUIRE_VULKAN=1, ctest -V, VK_LOADER_DEBUG=layer), same entries: on #9685's head e5edf0cd4a (this PR's base), 17 of 17 pass (all but the new test), with the layer inserted 25 times. On this head, 18 of 18 pass, with the layer inserted 26 times. Neither log has a VUID- line or a "was not found" line.
  • Existing tests: none needed APS5_NO_RESIDENT_LINEAR. The existing linear-target tests use private blocks of 16 to 128 KiB, which the gate keeps synchronous on Windows. uint8x4_color_target_no_resident keeps APS5_NO_RESIDENT_TARGETS=1, which now also prevents the import creation. With the gate disabled, so that the small-block tests ran resident even over compared imports, pixel_ancillary_word, pixel_fixed_point_position, pixel32_ar_export, pixel_uint16_export, pixel_sample_coverage, srgb8 and uint8x4 all passed, which also shows that #6892's original failure no longer reproduces since #6759.
  • Full ctest -R "^agc_" on this head 4bd83988c7 (base main 9d6adeb550): 911 of 914 pass; the 3 failures are the three sample_order entries that main fails on this GPU and toolchain. Before the rebase, f60f66658e on main d6eafa54d0 passed 895 of 900, with the same failures plus two that main has since fixed.

PPSA14363 (measured before #9181): MGS1's PS1 part, on the heads of that time. main ff191e29d1 libraries (prepared from #9685's build, so #9115's trophy fix is on main), only libSceAgcDriver.prx swapped: #9685's head cee2512ef8 (this PR's base) against this head 175d986c28, both built clean from their commits. Same scripted route, 300 s, APS5_TRACE_SUMMARY_EVERY=10, the first 100 frame dumps (every 30th present), a trace window at 200 s, in the order this PR, base, this PR, all three in one hold of the GPU and build locks with no game running on the PC. Per 10 s window from 80 s, when the PS1 part starts, without the window that ends with the trace write:

MGS1's PS1 part cee2512ef8 (#9685) this PR, two runs
presents per 10 s 8 to 337 600
frame p99 211.3 to 3385.2 ms 17.0 to 17.4 ms
frame max 214.1 to 3385.2 ms 17.3 to 19.6 ms

On the base, every draw into the three targets is synchronous: the trace window spends 129.4 ms per frame in ColorTarget.Write and 84.3 ms in Graphics.Wait.

Summary lines of the trace window (200 to 220 s), the base first:

{"commit":"cee2512ef812","dirty":false,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":4104,"ms":20582.143},"presents":58,"frame_ms":{"p50":616.164,"p90":735.007,"p99":786.226,"max":786.226},"gpu_busy_ms_per_present":4.95,"worker_busy_pct":{"queue worker 0x0":96.906},"top_phases_ms_per_frame":{"Driver.Packet":343.874,"Graphics.Draw":343.452,"Driver.Packet.draw":288.471,"Driver.Draw":288.446,"Driver.Draw.draw_enqueued":287.151,"ColorTarget.Write":129.356,"Graphics.Wait":84.328,"Graphics.Wait.fence_wait":83.858},"trace_dropped":false,"trace":"aps5-trace-cee2512ef812-25568.json.gz"}
{"commit":"175d986c2890","dirty":false,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":11899,"ms":20003.081},"presents":1199,"frame_ms":{"p50":16.683,"p90":16.897,"p99":17.063,"max":17.768},"gpu_busy_ms_per_present":1.811,"worker_busy_pct":{"queue worker 0x0":6.171},"top_phases_ms_per_frame":{"VideoOut.Flip":13.265,"VideoOut.Flip.vblank_wait":12.494,"Driver.Packet":1.026,"Driver.Packet.draw":0.676,"Driver.Draw":0.666,"Graphics.Draw":0.647,"VideoOut.Flip.present":0.622,"Driver.Present":0.619},"trace_dropped":false,"trace":"aps5-trace-175d986c2890-24864.json.gz"}

tools/performance_compare.py on them: mean frame 354.865 to 16.683 ms, p99 786.226 to 17.063 ms, GPU busy per present 4.950 to 1.811 ms. The traces are not attached, because these runs come from a commercial title (asked on #9373 whether summary lines are enough).

tools/check_conventions.py passes.

Overlap: #9402 (@janzezno) changes refreshImports right after the line where this PR clears its remembered refusals; agreed on #9879 that neither depends on the other and the one that merges second rebases. #10025 (mehmetbayoglu) changes the pageReadOnly condition of the page walk in importRunAt, which this PR moves into importPages: a textual conflict, so the one that merges second carries that line over.

Left for follow-ups (from the reviews): a refused run that joins a neighbouring range is not retried with the target's own range, and an import made by another requester can still replace the target's import with one over a partly unwatched run.

Not tested: Linux and macOS. The gate's shared-backing and dma-buf branch has never run, and this head's non-Windows code (that branch, and the test's ImportWatch::Watch override) has not been compiled outside CI; the version before the review fixes was syntax-checked with g++ 13. GPUs other than the RX 6700 XT.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: #9685
  • Fixes: none
  • Unblocks: PPSA14363 #9615
  • GPUs tested: AMD Radeon RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.16010, Windows 11 26200
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4973669313 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9879). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-22T20:27:37Z. --- ### What A linear color target gets a resident image only when its memory already has a host import (#6892). Every other draw into it is synchronous: copied in, drawn, waited for on the CPU and copied back. #6892 only looked the import up, because a first version that made it broke `agc_driver_pixel_ancillary_word` and `agc_driver_pixel_fixed_point_position`: the import over a short-lived block was compared, and the next block allocated at the same address stayed outside the write watch. Since #6759, a page committed again inside an excluded block is watched again. On a lookup miss, the draw now makes the import itself, with a new `ImportRequester::ColorTarget`, when all of these hold: - the target could become resident anyway (resident linear targets, resident targets and the detiler are enabled); - its registered ranges are writable, and the whole import run, not only the target, is write-watched; - the import keeps it watched: a separate alias of shared memory, a direct import of private memory that settles on Windows (1 MiB or more, when the import probe keeps the watch and a settle queue exists), or an import the probe keeps watched on other systems, where a dma-buf import must stay watched too if the range has shared backing. On Windows, resident direct-memory runs, where PPSA14363's targets live, are read-write, write-watched private pages since #9181, so they pass the writable check like any other private page. A refused run is remembered until the registry, the committed pages (Windows) or the write watch change, or a shared alias is mapped over it, so a target that stays synchronous costs a map lookup per draw instead of a page scan. `importRunAt` checks this after its remembered failures and refusals and before it retires or evicts anything, through two helpers its own decision now uses: `importWatching` (settled, watched host-pointer and dma-buf imports) and `importPages` (the Windows page scan, moved out of `importRunAt`). A target whose import would be compared stays synchronous, because a compared import makes every refresh of the resident image compare the whole target. A target over an import that already exists is resident as before, with `ExistingHostImportFor` as the fast path, and `APS5_NO_RESIDENT_LINEAR=1` still keeps every linear target synchronous. The debt file gets an entry for the targets that stay synchronous. This is the case draft #1191 (@MichonGoddijn231849) was to bring back on top of #6892 once partial-block write-watch coverage existed. It builds on #9685: without #9685, a resident linear target is stored whole after every draw, which is slower than the synchronous path for PPSA14363's three 24 MiB targets. The branch therefore contains #9685's commits; this PR's change is commit `175d986c28`. After it come @oneandonlydean's merge of `main` (`f59787b272`) and a merge of #9685's current head `5b5dcaeaff`, then a merge of `main` `6c52b649e7` (`fe1927d398`), then a merge of #9685's head `d36311d661` (`b58a21d9f4`). ### Why PPSA14363 (METAL GEAR SOLID - Master Collection Version, own dump) draws its PS1 game into three linear 3072x2048 RGBA8 color targets whose memory has no host import, so on `main` every draw into them is synchronous. Bring-up thread: #9615. ### Tested Windows 11 26200, Radeon RX 6700 XT (gfx1031), AMD driver 32.0.21045.16010, WinLibs GCC 15.2.0 r7, Release, `BUILD_TESTING=ON`. **Current head `e1fa56c7bf`**: `main` `ae7d59258e` merged in after #9685 merged (`6adad6733c`, clean), plus one commit for #9181. #9181 stopped write-protecting resident runs on Windows, so the special case that counted armed read-only private pages as writable could no longer change a decision, and `--armed`/`--armed-gate` could only skip ("the collects did not arm the resident run read-only"). The commit removes the special case; resident runs pass as writable private pages. `--armed` becomes `--direct` and `--armed-gate` becomes `--private-gate`, without the arming step (see the test list). On the RX 6700 XT: - The build is clean, and `agc_driver_linear_target_import_creation` runs every case with no skip. - The focused set plus `agc_driver_bda_*` (57 `ctest` entries) passes 3 of 3. With the Khronos validation layer, 57 of 57 pass with 0 `VUID-` lines (the layer was inserted 78 times, no "was not found" line). - Red: with the gate's page walk removed (the registry's writable flag trusted), the test fails 3 of 3 at the `--private-gate` block: "read-write alias of shared guest memory 0x200100000+0x20000: the range does not start at a shared view". - PPSA14363 on this head, merged onto `main` `5b5d24cb22` (2026-10-26), with the exclusive GPU lock and the build lock. League of Legends was open on the PC, and no other game ran. The same route2 input on both sides, 480 s each: - This head: 600 presents per 10 s in every window from 40 s, frame p50 16.7 ms, p99 17.1 to 26.2 ms. The codec line "The Codec's receiver directly stimulates the small bones of your ear." comes at 111 s, and Dock gameplay with the radar by 131 s. - `main` alone: 56 to 68 presents per 10 s from 90 s, p50 234 to 326 ms. The codec line comes at 423 s, and the Dock is not reached in 480 s. - Details are in #9217. The table below is older, measured before #9181. **Earlier head `5575dc3108`**: a merge of #9685's head `d6d8966bba` (`main` `b930da950d` merged into #9685, only `CMakeLists.txt` conflicted there); this merge itself was clean, and the head merges cleanly with `main` `6cd36e6517`. On the RX 6700 XT the build is clean. The focused set plus `agc_driver_bda_*` (55 `ctest` entries) passes 3 of 3. With the Khronos validation layer, 55 of 55 pass with 0 `VUID-` lines (the layer was inserted 74 times, no "was not found" line). `ctest -R "^(agc|shader)_"` passes 1010 of 1015: the 3 `sample_order` tests `main` fails on this GPU, plus `agc_driver_sgpr_pattern_fill_keys` and an `agc_async_log_fatal` timeout, both while four game instances ran next to the suite; run alone against this head's libraries, both pass 5 of 5. **Earlier head `b58a21d9f4`**: a merge of #9685's head `d36311d661`, the per-64 KiB-block keep for drawn targets from @oneandonlydean's review on #9685 (details and red/green there). Only the debt file conflicted: #9685's narrowed entry and this PR's entry on the next line; both are kept. Tested on this head (RX 6700 XT, AMD driver 32.0.21045.16010): builds clean; the focused set with `agc_driver_bda_*` and #9685's `agc_driver_linear_target_direct_write_completion` (54 `ctest` entries) passes 3 of 3; with the Khronos validation layer 54 of 54, 0 `VUID-` lines, the layer inserted 72 times; `ctest -R "^(agc|shader)_"` 996 of 1002 with the 3 `sample_order` failures `main` has on this GPU and 3 timeouts under load from a parallel game run (`shader_cache_runtime_sources`, `agc_driver_native_fmask`, `agc_driver_native_depth_clears`), which pass when rerun alone. **Earlier head `fe1927d398`**: a merge of `main` `6c52b649e7` on top of `bb58e7ddbd`. It resolves the logic conflict with #7465 in `importRequesterTests` that @oneandonlydean found: #7465's mapped range keeps pieces 6 and 7, and this PR's color-target block moved to its own pieces, 10 (writable) and 9 (read-only), with piece 8 left unregistered so that 10 is a run of its own, as 6 was before. Tested on the merge (RX 6700 XT, AMD driver 32.0.21045.16010): builds clean; the focused set with `agc_driver_bda_*` (54 `ctest` entries) passes 3 of 3; with the Khronos validation layer 54 of 54 pass, 0 `VUID-` lines, the layer inserted 72 times, no "was not found" line; `ctest -R "^(agc|shader)_"`: 999 of 1002 pass, with the same 3 `sample_order` failures as `main` on this GPU. On `fe1927d398` itself (only `BdaResources.cpp` differs from that merge): `agc_driver_bda_*` (7 entries) passes 3 of 3, and 7 of 7 with the validation layer, 0 `VUID-` lines. **Earlier head `bb58e7ddbd`**: @oneandonlydean's merge of `main` `11d6efa06c`, then a merge of #9685's head `5b5dcaeaff`, which adds a fix to #8126's keep rule for drawn targets and a test (#9685's body). The runs below are on `04a6c9e4cc`: this PR's commit on the same #9685 change, rebased onto `11d6efa06c`. Its tree differs from this head only in the position of one `add_test` block in `CMakeLists.txt` and in one debt entry. Builds clean. The focused set with `agc_driver_linear_target_import_creation` (47 `ctest` entries) passes 3 of 3. With the Khronos validation layer: 47 of 47, 0 `VUID-` lines, the layer inserted 65 times, no "was not found" line. `ctest -R "^(agc|shader)_"`: 998 of 1001 pass, with the same 3 failures as `main` on this GPU (`agc_driver_sample_order`, `_grid_reference`, `_recipe_depth_locations`). **New test** `agc_driver_linear_target_import_creation`, eight cases. On systems other than Windows it forces `ImportWatch::Watch` for its run, so the watched cases also run on a device whose imports are compared (lavapipe in CI): - `--created`: a target in freshly registered, write-watched memory. The draw is recorded, the target is imported, and its memory stays watched. - `--reused`: a block freed and allocated again at the same address. It is watched, and the next draw starts from the CPU's bytes. - `--direct` (Windows): a 2 MiB resident direct-memory run (`GuestArenaMapDirect`), the layout PPSA14363's targets use. The draw is recorded, the target is imported, it stays watched, and the pixels are right after the device wait. - `--private-gate` (Windows, whatever the import probe says): a 512 KiB resident direct-memory run and a 128 KiB block whose second half is committed read-only while the registry still calls it writable. Under `Unwatch`, the run's import, which would be compared (it is below the settle floor), is refused. Under `Watch`, the read-only block is refused without being counted, and the run is imported. - `--outside-watch`: a 1 MiB block whose last 64 KiB was taken out of the write watch, with the target at its start. No import, a synchronous draw, the target stays watched, and the pixels are right after the device wait. - `--rewatched` (Windows): the same layout, refused once; then the unwatched block is committed again, which brings it back into the write watch without a registry change. The next draw is recorded and imported, so the remembered refusal was dropped. - `--read-only-registry`: a 1 MiB write-watched block that the guest registered read-only. No import and a synchronous draw. - `--compared`: a 64 KiB block whose import would be compared. No import, a synchronous draw, and the block stays watched. The import requester tests in `BdaResources.cpp` count the new requester and check that it makes no compared import, no import of a range the guest cannot write, and no import of heap memory outside the write watch. - **Red, one part of the change removed at a time**, each built and run on its own, on `085f3cf29a` (this change before the review fixes) except the whole-run check, which was removed from the review-fix tree: - The draw no longer creates the import (`Draw.cpp` of #9685's head, the rest of the change kept): `--created`, `--reused` and `--armed` (now `--direct`, measured before #9181 with its arming step) fail ("...the draw into a linear target in registered, write-watched memory without a host import waited for the GPU instead of being recorded"); `--armed-gate` and `--compared` pass. - The gate removed: `--compared` fails, and so does `agc_driver_graphics` ("a color target's import was made where imports of its memory are compared"). - The whole-run watch check removed: `--outside-watch` fails ("run outside the write watch: a linear target whose import run has a block outside the write watch was drawn into a resident image"). - The registry's writable flag trusted for every private page, without asking for the guest protection: `--armed-gate` (now `--private-gate`) fails, because the import of the block committed read-only throws ("read-write alias of shared guest memory ...: the range does not start at a shared view"). - The registry's writable check removed from the gate (on `4bd83988c7`): `--read-only-registry` fails ("range registered read-only: a linear target in memory the guest registered read-only was drawn into a resident image"). - **Current head `175d986c28`**, restacked without conflicts on #9685's rebased head `cee2512ef8` (`main` `ff191e29d1`; still merges cleanly with `513ca7e558`): the focused set plus `main`'s `agc_driver_linear_readback_label` and `agc_recorder_*` entries, 26 `ctest` entries, pass 3 of 3. With the Khronos validation layer on the same set, this head passes 26 of 26 (layer inserted 33 times) and `main` `513ca7e558` 16 of 16 (19 times), with 0 `VUID-` lines and no "was not found" line on either. This PR's commit is unchanged by the restack; the results below are from the commits they name. - **Green**: on `4bd83988c7` (rebased onto `main` `9d6adeb550`), 18 `ctest` entries, 3 rounds each, all pass: the new test; #9685's linear-target tests (`completion_points` with its `sync_flip` and `unpipelined` entries, `completion_stores`, `cpu_writes`, `dispatch_access`, `draw_bindings`, `rectangle_bound`, `resident`); `address_passes` with `address_passes_draw_transitions` and `address_passes_targets_split`; `store_over_untracked`; `graphics`; `pixel_ancillary_word`; `pixel_fixed_point_position`; and `host_import_windows`. - **Validation layer** (`VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1`, `ANYPS5_REQUIRE_VULKAN=1`, `ctest -V`, `VK_LOADER_DEBUG=layer`), same entries: on #9685's head `e5edf0cd4a` (this PR's base), 17 of 17 pass (all but the new test), with the layer inserted 25 times. On this head, 18 of 18 pass, with the layer inserted 26 times. Neither log has a `VUID-` line or a "was not found" line. - **Existing tests**: none needed `APS5_NO_RESIDENT_LINEAR`. The existing linear-target tests use private blocks of 16 to 128 KiB, which the gate keeps synchronous on Windows. `uint8x4_color_target_no_resident` keeps `APS5_NO_RESIDENT_TARGETS=1`, which now also prevents the import creation. With the gate disabled, so that the small-block tests ran resident even over compared imports, `pixel_ancillary_word`, `pixel_fixed_point_position`, `pixel32_ar_export`, `pixel_uint16_export`, `pixel_sample_coverage`, `srgb8` and `uint8x4` all passed, which also shows that #6892's original failure no longer reproduces since #6759. - **Full `ctest -R "^agc_"`** on this head `4bd83988c7` (base `main` `9d6adeb550`): 911 of 914 pass; the 3 failures are the three `sample_order` entries that `main` fails on this GPU and toolchain. Before the rebase, `f60f66658e` on `main` `d6eafa54d0` passed 895 of 900, with the same failures plus two that `main` has since fixed. **PPSA14363** (measured before #9181): MGS1's PS1 part, on the heads of that time. `main` `ff191e29d1` libraries (prepared from #9685's build, so #9115's trophy fix is on `main`), only `libSceAgcDriver.prx` swapped: #9685's head `cee2512ef8` (this PR's base) against this head `175d986c28`, both built clean from their commits. Same scripted route, 300 s, `APS5_TRACE_SUMMARY_EVERY=10`, the first 100 frame dumps (every 30th present), a trace window at 200 s, in the order this PR, base, this PR, all three in one hold of the GPU and build locks with no game running on the PC. Per 10 s window from 80 s, when the PS1 part starts, without the window that ends with the trace write: | MGS1's PS1 part | `cee2512ef8` (#9685) | this PR, two runs | |---|---|---| | presents per 10 s | 8 to 337 | 600 | | frame p99 | 211.3 to 3385.2 ms | 17.0 to 17.4 ms | | frame max | 214.1 to 3385.2 ms | 17.3 to 19.6 ms | On the base, every draw into the three targets is synchronous: the trace window spends 129.4 ms per frame in `ColorTarget.Write` and 84.3 ms in `Graphics.Wait`. Summary lines of the trace window (200 to 220 s), the base first: ```json {"commit":"cee2512ef812","dirty":false,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":4104,"ms":20582.143},"presents":58,"frame_ms":{"p50":616.164,"p90":735.007,"p99":786.226,"max":786.226},"gpu_busy_ms_per_present":4.95,"worker_busy_pct":{"queue worker 0x0":96.906},"top_phases_ms_per_frame":{"Driver.Packet":343.874,"Graphics.Draw":343.452,"Driver.Packet.draw":288.471,"Driver.Draw":288.446,"Driver.Draw.draw_enqueued":287.151,"ColorTarget.Write":129.356,"Graphics.Wait":84.328,"Graphics.Wait.fence_wait":83.858},"trace_dropped":false,"trace":"aps5-trace-cee2512ef812-25568.json.gz"} ``` ```json {"commit":"175d986c2890","dirty":false,"env":{"APS5_DUMP_FRAMES":"100","APS5_DUMP_FRAMES_EVERY":"30","APS5_PAD_INPUT_FILE":"<path>","APS5_TRACE_SECONDS":"200:20","APS5_TRACE_SUMMARY_EVERY":"10"},"gpu":"AMD Radeon RX 6700 XT","driver":"AMD proprietary driver 26.10.1 (AMD proprietary shader compiler)","os":"Windows 10.0.26200","cpu":"AMD Ryzen 5 5600X 6-Core Processor","cpu_threads":12,"memory_mib":32690,"title_id":"PPSA14363","title":"METAL GEAR SOLID - Master Collection Version","content_version":"03.000.000","resolution":"1920x1080","window":{"spec":"seconds 200:20","first_present":11899,"ms":20003.081},"presents":1199,"frame_ms":{"p50":16.683,"p90":16.897,"p99":17.063,"max":17.768},"gpu_busy_ms_per_present":1.811,"worker_busy_pct":{"queue worker 0x0":6.171},"top_phases_ms_per_frame":{"VideoOut.Flip":13.265,"VideoOut.Flip.vblank_wait":12.494,"Driver.Packet":1.026,"Driver.Packet.draw":0.676,"Driver.Draw":0.666,"Graphics.Draw":0.647,"VideoOut.Flip.present":0.622,"Driver.Present":0.619},"trace_dropped":false,"trace":"aps5-trace-175d986c2890-24864.json.gz"} ``` `tools/performance_compare.py` on them: mean frame 354.865 to 16.683 ms, p99 786.226 to 17.063 ms, GPU busy per present 4.950 to 1.811 ms. The traces are not attached, because these runs come from a commercial title (asked on #9373 whether summary lines are enough). `tools/check_conventions.py` passes. Overlap: #9402 (@janzezno) changes `refreshImports` right after the line where this PR clears its remembered refusals; agreed on #9879 that neither depends on the other and the one that merges second rebases. #10025 (mehmetbayoglu) changes the `pageReadOnly` condition of the page walk in `importRunAt`, which this PR moves into `importPages`: a textual conflict, so the one that merges second carries that line over. Left for follow-ups (from the reviews): a refused run that joins a neighbouring range is not retried with the target's own range, and an import made by another requester can still replace the target's import with one over a partly unwatched run. Not tested: Linux and macOS. The gate's shared-backing and dma-buf branch has never run, and this head's non-Windows code (that branch, and the test's `ImportWatch::Watch` override) has not been compiled outside CI; the version before the review fixes was syntax-checked with g++ 13. GPUs other than the RX 6700 XT. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: #9685 - [x] Fixes: none - [x] Unblocks: PPSA14363 #9615 - [x] GPUs tested: AMD Radeon RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.16010, Windows 11 26200 - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!9879
No description provided.