Repository navigation
fix(agc): keep resident DCC targets watched under aligned block imports - #8172
Conversation
Since host imports group adjacent ranges into aligned blocks (boykopovar#6457), an import can span both 64 KiB blocks that an earlier import left unwatched and the metadata of resident multisampled DCC targets. ImportWatched with staysWatched took the whole import out of the write watch when any part of it was not watched before. It now walks and compares each run of watched blocks of the import on its own, and unwatches only the blocks that were not watched or whose walk failed. A resident DCC target took the generation of its metadata from a walk of the metadata's pages alone. CPU stores to the rest of the metadata's 64 KiB block made before that walk were stamped later by the import's walk, so the block read as written, and the import window marked the metadata page as possibly stored over: the next draw refused the target. The generations now come from a walk of the whole blocks. agc_write_tracking and agc_driver_msaa_dcc_clear_* gain regression tests for both. Fixes boykopovar#8103 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
FYI, I have PR #8169 open for the same #8103 report, with a narrower |
|
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.
|
|
Native Linux with working write watching fills the WSL coverage gap for exact head The mixed-watch regression is discriminating on Linux:
DCC compatibility passes, with an important negative-control limit:
After exact restoration, the registered Ubuntu 24.04, kernel 7.0.0-38, Ryzen 9950X, GCC 13.3, Release; RTX 3090/NVIDIA 595.99.02; gfx1036 |
|
The Linux result matches our CI on this head: Your limit stands, and the PR should be read that way: the metadata-generation change in |
Since boykopovar#8172, a host import that stays in the write watch keeps each of its watched runs in the watch instead of taking the whole import out when part of it was unwatched. Grand Theft Auto V (PPSA04264) imports resident direct memory that way, and later maps the same memory at a second address, which turns it into shared views. From then on the write watch arms them, and the game's own stores fault and are resumed, the red zone hazard of boykopovar#361 (boykopovar#9136, eboot 0x162b9e4 and 0x28f413a). ImportWatched now marks the resident pages of each run it keeps in the watch with GuestArenaCompareResidentWhenShared. They stay write-watched while they are private, as boykopovar#8172 needs for resident DCC targets. Once they are shared, their collects fail and they are compared, as before boykopovar#8172, instead of being armed. Memory that is already shared when it is imported is not marked and stays tracked as before. agc_rewatched_direct_shared gains the imported case: resident direct memory imported with the watch kept, then mapped a second time, must collect as 0 through either mapping, stay writable and show a store through both, while unimported shared direct memory is still collected. windows_write_watch gains CheckResidentOnlyComparedWhenShared: a resident-only mark leaves a shared view armed and collected, and still keeps a resident page compared once a second mapping makes it shared.
Since boykopovar#8172, a host import that stays in the write watch keeps each of its watched runs in the watch instead of taking the whole import out when part of it was unwatched. Grand Theft Auto V (PPSA04264) imports resident direct memory that way, and later maps the same memory at a second address, which turns it into shared views. From then on the write watch arms them, and the game's own stores fault and are resumed, the red zone hazard of boykopovar#361 (boykopovar#9136, eboot 0x162b9e4 and 0x28f413a). ImportWatched now marks the resident pages of each run it keeps in the watch with GuestArenaCompareResidentWhenShared. They stay write-watched while they are private, as boykopovar#8172 needs for resident DCC targets. Once they are shared, their collects fail and they are compared, as before boykopovar#8172, instead of being armed. Memory that is already shared when it is imported is not marked and stays tracked as before. agc_rewatched_direct_shared gains the imported case: resident direct memory imported with the watch kept, then mapped a second time, must collect as 0 through either mapping, stay writable and show a store through both, while unimported shared direct memory is still collected. windows_write_watch gains CheckResidentOnlyComparedWhenShared: a resident-only mark leaves a shared view armed and collected, and still keeps a resident page compared once a second mapping makes it shared.
- ImageArrayWindowPastLayerLimit (upstream test): MinGW GCC refuses alignas(65536) on a static object; the texels now come from an aligned heap allocation. - BufferPool ImageMemoryOverBudget (boykopovar#7870): uses our mock's heap budget and usage fields. - WriteTracking CheckImportWindowOverUnwatchedPart: with boykopovar#8172's per-span unwatch the watched blocks stay watched; the unwatch hook must cover the part that leaves the watch. AI-assisted: yes
- ImageArrayWindowPastLayerLimit (upstream test): MinGW GCC refuses alignas(65536) on a static object; the texels now come from an aligned heap allocation. - BufferPool ImageMemoryOverBudget (boykopovar#7870): uses our mock's heap budget and usage fields. - WriteTracking CheckImportWindowOverUnwatchedPart: with boykopovar#8172's per-span unwatch the watched blocks stay watched; the unwatch hook must cover the part that leaves the watch. AI-assisted: yes
What
Fixes #8103. Since #6457,
agc_driver_msaa_dcc_clear_4has failed on Windows on both NVIDIA and AMD. Two separate problems cause it, and this PR fixes both.1.
ImportWatchedunwatched the whole import (Execution/src/GuestMemory.cpp)#6457 imports adjacent registered ranges as one aligned power-of-two block. In the test, that block is
0x200000000+0x400000, and it contains:ImportWatched(..., staysWatched = true)checked whether the whole run was covered. One unwatched block madebeforefalse, and it then calledunwatchLockedover the whole run, which took the resident target out of the watch.checkDccCurrentthen failed withmultisampled DCC target reuse requires watched guest memory.The fix splits the run into maximal runs of watched 64 KiB blocks. For each run it:
It unwatches only the parts that were not watched or whose walk failed.
!staysWatchedpath is unchanged.2. DCC metadata generations came from a walk of the metadata pages only (
Graphics/src/MultisampleTarget.cpp)With (1) alone, the test got further and failed with
writes to a resident multisampled DCC target or its metadata are not implemented (DCC range 0x2003b0000+0x1000). A diagnostic trace showed why:initialDccClearandabsorbDccFilltook the range's generation fromCollectWritesUncached(range). That walk covered only the 4 KiB, so the other 15 pages still had write-watch bits pending.UnchangedSinceand page-levelStoredOverfailed.The generations are now taken from a walk of the whole 64 KiB blocks around the range (
collectBlocks). If that walk returns 0, they fall back to a walk of the range alone. Every write collected this way was made before the generation, so this can only make the tracking more precise.StoredOver.Why there are two changes. Each one fixes a separate refusal, and the test passes only with both (see Tested). Plan (a) in the bisect comment, changing
importRun, was not used:sameRangealso goes throughimportRunwhen imports are refreshed, so its result can't depend on the watch state. This PR leavesimportRunand #6457's block selection unchanged.Credit. @simonbbby's control in the issue,
SetHostImportWindow(BlockBytes)inDccRefillTests, is what pointed at the multi-range block. Their Linux data (the test passes at 9127ea3, 5242599 and main, because the Linux fixture's mmap addresses never form the block) confirms that the failure depends on the memory layout.Regression tests. Both are layout-independent, so they do not rely on the Windows arena addresses:
agc_write_tracking, newCheckImportWindowOverUnwatchedBlock(GuestMemory level, no Vulkan, both platforms):staysWatched.agc_driver_msaa_dcc_clear_{2,4,8}, newDccImportWindowTests:writes to a resident multisampled DCC.Remaining case, not fixed here: if the CPU stores to another page of the metadata's 64 KiB block after the generation, and an import window later covers the metadata page, the draw is still refused. The window conservatively counts a resolved page as possibly touched by the CPU, and I left that tracker rule alone.
Overlap:
ImportWatchedto run the unwatch hook.CheckImportWindowOverUnwatchedPartasserts the opposite of this PR: that an import over a partly unwatched range unwatches its watched blocks too.GuestMemory.cpp, but notImportWatched's run handling.Tested
Windows 11 Home 26300, Ryzen 5 9600X, WinLibs GCC 15.2.0, Release, Ninja, on
main5253446. Environment:ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 APS5_NO_PIPELINE_JOURNAL=1.The Khronos validation layer is not installed on this machine, so the
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationrun was not done.Focused tests:
agc_write_trackingtook the watched blocks out of the write watchagc_driver_msaa_dcc_clear_4requires watched guest memoryrequires watched guest memorywrites to a resident multisampled DCCagc_driver_msaa_dcc_clear_2,_8writes to a resident multisampled DCC(the newDccImportWindowTests)agc_driver_msaa_dcc_clear_{2,4,8},agc_driver_msaa_dcc_stateandagc_write_trackingpassed 3 runs of 3 on each GPU.ctest -R "agc|shader|spirv|recomp|guest_memory|import|watch" -j6(837 tests):agc_driver_msaa_dcc_clear_4,agc_driver_pass_input_hazard,agc_pipeline_journal.agc_driver_pass_input_hazardandagc_pipeline_journal, both of which also fail on main when run alone.agc_driver_sgpr_pattern_fill_keys. That is a 10 s polling deadline that times out under load on main too: 2 of 8 parallel batches failed on main, and 0 of 8 with this PR on an idle machine. It passes serially.agc_driver_msaa_dcc_clear_4,agc_driver_draw_cache_reuse{,_verify,_inline},agc_driver_layered_volume_vertex_no_gpl,agc_driver_stencil_replay_no_gpl,agc_pipeline_journal.agc_driver_msaa_dcc_clear_4, plus two others:agc_driver_sgpr_pattern_fill_keys, the same load-dependent timeout as above.agc_trimmed_import, which fails 5 of 5 serially on main on this iGPU too (after an unmap of 1440 KiB ... served from the import that pinned the old ones). It passed on main only in that run's parallel batch.#6457's claims:
importRunand the block choice are not touched. The tests that carry #6457's import counts and costs pass on both GPUs:agc_storage_writeback_blocks,agc_driver_graphics(the BdaResources mocks),agc_driver_storage_write_back_overhangand thehost_importtests.Linux: WSL Ubuntu 24.04, gcc 13.3, built from this branch and from main. Same suite:
agc_driver_sgpr_pattern_fill_keys.[memory] write watch unavailable), soagc_write_trackingis skipped and the DCC tests fail atinitial multisampled DCC contents require watched guest memory, on main and here alike.python tools/check_conventions.py --base origin/mainpasses on Python 3.13 and 3.9.Checklist
main; no other open PR implements the same functions (fix(agc): run the unwatch hook when a watched import leaves the write watch #6308 and fix(agc): run the unwatch hook before an import whose range leaves the write watch whatever the import does #7505 change the same fallback differently; see Overlap)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file (none added).mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code