fix(agc): keep aligned imports inside watched spans #8169
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8169"
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 MarcZX10 on 2026-10-20T01:11:15Z.
What
The aligned host-import path can group adjacent registered ranges into a larger block even when another part of that block is no longer write watched. Importing that block then removes write watching from the whole span, including a watched DCC color source that the 4x refill test still needs.
When write watching is active, this change accepts a grouped import only when the complete candidate block is still watched. Otherwise it falls back to the requested range. It preserves the existing grouped-import behavior when write watching is unavailable and for single-range imports.
The regression test constructs the mixed-watch condition on Windows, checks that the target starts watched, imports it beside unwatched gaps, and asserts that the target remains watched. The test and fix are separate commits.
Tested
python3 tools/check_conventions.py --base upstream/main: passed.git diff upstream/main...HEAD --check: passed.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 repositoryImported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T01:19:54Z.
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.
core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/BdaResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppImported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T02:24:54Z.
I ran #8169 and #8172 on the same Windows base so both fixes for #8103 can be compared. @MarcZX10 mentioned they could not build #8169 or run the Windows repro, so here are those results. Disclosure: #8172 is my PR, so I've kept this to measurements.
Setup
main7e12b3da8.629ee88e8, merged onto that base.58f0e89ca, applied onto the same base.BUILD_TESTING=ON.ANYPS5_GPU=AMD).ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 APS5_NO_PIPELINE_JOURNAL=1. No validation layer is installed.1. The #8103 repro
Each test ran 3 times on each GPU.
agc_driver_msaa_dcc_clear_4requires watched guest memory)agc_driver_msaa_dcc_clear_2,_8,agc_driver_msaa_dcc_state,agc_write_trackingagc_driver_graphicsSo both PRs fix
agc_driver_msaa_dcc_clear_4on this machine.With #8169,
agc_driver_graphicsstops at its first failure:2.
agc|guest_memory|import|watchsubset831 tests,
-j6, NVIDIA.agc_driver_msaa_dcc_clear_4,agc_driver_pass_input_hazard,agc_pipeline_journalagc_driver_graphics,agc_storage_writeback_blocks,agc_host_import_retirement,agc_host_import_retire,agc_driver_pass_input_hazard,agc_pipeline_journalagc_driver_pass_input_hazard,agc_pipeline_journalagc_driver_pass_input_hazardandagc_pipeline_journalfail on main too.agc_pipeline_journalfails becauseAPS5_NO_PIPELINE_JOURNAL=1is set.The four tests that fail only with #8169 also failed 2 of 2 when run alone on NVIDIA, and once each on the iGPU:
agc_storage_writeback_blocks:a 4 MiB image over 64 KiB pieces of which every other one is not GPU mapped: 0 imports made (0 by write-back segments), CPU write-back, 1048576 of 1048576 texels storedagc_host_import_retirement:unlocked mapping retired an import instead of requesting the GPU lockagc_host_import_retire:FAIL: the grown run was not imported as one import replacing the firstagc_driver_graphics: see aboveagc_driver_graphicsstops at the first failure, so I made a local diagnostic build (not part of either PR). It runs each of the 58 sub-tests ofRunBdaResourceTestsin its own process.importCrossingTests,importSpanTests,failedImportRemapTests,spaceImportRunTests,importWindowTests,spaceReadAcrossImportsTestsimportBlockMapTests(both variants),importBlockBuildTests,importBlockHoleTests,importBlockUnalignedTests,importBlockFlagTests,importBlockRemapTests,importBlockFailureTests,importBlockBudgetTestsevictingRefusalWindowTests,evictingRefusalBlockRangesTests,evictingRefusalStepDownTests64 adjacent 64 KiB pieces mapped one by one were not imported as one 4 MiB block: 64 importsOf these fixtures, I checked two.
importCrossingTestsallocates with::operator new, andHostImportRetireHold.cppusesVirtualAlloc. Neither is in the guest arena. On WindowsGuestMemory::WriteWatched()is true, so the newGuestMemory::Watched(...)condition inimportRunreturns the single range for these blocks. The only code change in #8169 is that condition, and every one of these sub-tests passes on main.I did not measure whether guest-arena ranges in a real title, for example read-only ones, are all watched. So I can't say how often titles would hit this.
3. #8169's regression test (
importBlockMixedWatchTests)Under ctest on this machine, the test prints
write watching unavailable: mixed import block not testedand returns, on main and on #8169 alike. A local print showed the values of its guard:GuestArenaAvailable= 1GuestArenaWriteWatched= 1GuestMemory::WriteWatched()= 1context.hostImportAlignment= 0The context that
RunBdaResourceTestsreceives ismockContext(), whose alignment is 0. ThePieceWindowthe test builds sets its ownimporting.hostImportAlignmentto 64 KiB.I removed only the
context.hostImportAlignment == 0condition, locally:an aligned import through unwatched neighboring spans dropped the target from the write watch.So the test detects the bug once the guard reads the alignment from
window.importing(or the condition is dropped). As committed, it does not run here.4. #8172's tests on the #8169 build
I applied only #8172's two test files on top of #8169.
agc_write_tracking,CheckImportWindowOverUnwatchedBlocktook the watched blocks out of the write watchagc_driver_msaa_dcc_clear_{2,4,8},DccImportWindowTestswrites to a resident multisampled DCC target or its metadata are not implemented (DCC range 0x200100000+0x1000, 4 samples)(likewise for 2 and 8)Both tests call
GuestMemory::ImportWatcheddirectly, which #8169 does not change. They testImportWatchedand the DCC metadata generations, notimportRun. Failing them does not mean #8169 fails to fix the issue's test.With #8169, the stock
dcc_clear_4never builds the 4 MiB block (see section 5), so it does not reach the metadata refusal thatDccImportWindowTestschecks.5. Import churn (
APS5_TRACE_HOST_IMPORT=1)What the counts mean
host import of ... oklines.host import of ... retired: the range was mapped again.refreshImportsprints that line whensameRange(entry)is false while the range is still leased.agc_storage_writeback_blocksagc_host_import_retirementagc_host_import_retireagc_driver_msaa_dcc_clear_4agc_driver_host_import_lifetimeagc_driver_host_import_at_map_unmap,_second_mapping,_mutation_race,_sparse,_teardown,_windows,storage_write_back_overhangIn
dcc_clear_4:So none of these tests showed a retire/re-import loop with #8169. For #8169, the "retired" count is 0 everywhere.
The concern raised in the #8103 bisect comment comes from this code path, which no test above covers. It is from reading the code; I did not measure it:
sameRange(const HostImport&)re-runsimportRun(lease, entry.base, ...)at every allocation-generation refresh. With #8169, that result depends onGuestMemory::Watchedover the candidate block.staysWatched == falsewhenwatchedHostPointeris false:unwatchImportsis set and the import is not settled (read-only, or belowsettleFloorBytes).ImportWatchedthen unwatches the whole run.refreshImportscallsGuestMemory::Unwatchon it again at each refresh (if (it->second.unwatched)).importRunwould return the single range.sameRunwould fail and the import would be retired. A later import would take the single range, because the block stays unwatched.rewatchSettledImportsonly covers settled imports.Summary of measured facts
agc_driver_msaa_dcc_clear_4pass on the RTX 5070 Ti and the Radeon iGPU here, 3 of 3 runs each.agc_driver_graphics(17 BDA sub-tests),agc_storage_writeback_blocks,agc_host_import_retirementandagc_host_import_retire. Their messages are about adjacent ranges no longer being grouped. #8172 adds no failures to the subset.hostImportAlignmentis 0. With that condition removed, it fails on main and passes with #8169.ImportWatchedand the DCC generations, which #8169 does not change.AI-assisted: yes (Claude Code); results above were run on this machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T07:21:54Z.
Thanks for jumping on #8103 so quickly. We're closing this in favour of #8172, which fixes the same regression at its cause: ImportWatched keeps the watched blocks under a partly unwatched import. It also fixes a second DCC metadata-generation failure. A Windows hardware run on a 5070 Ti and a Radeon shows both parts are needed for
msaa_dcc_clear_4.For reference, this head also fails CI (run 39352989674, Windows).
agc_host_import_retirefails 3 checks, andagc_driver_graphicsfails at BdaResources.cpp:192 because adjacent ranges are no longer imported as one span. The new!Watchedguard inimportRunstops grouping unwatched runs that the existing fixtures depend on, and the same check fails on Linux too.Pull request closed