fix(agc): restore write-watch coverage for remapped pages #6759
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6759"
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 Zenodeon on 2026-10-16T09:57:51Z.
What
Restore CPU-write tracking when fresh private backing replaces complete pages inside an imported 64 KiB block. For example, a new 16 KiB allocation inside a previously excluded block currently remains classified as unwatched, even though its private backing supports write tracking.
Represent exclusions as a mask of 4 KiB pages. Restore only fully remapped pages with a newer mapping generation, preserving excluded neighbors and ignoring stale mapping notifications. Require whole-block coverage before using block-level write hints, and clear stale hints when private backing is mapped.
This is a standalone resource-lifecycle correctness fix. It contains only the coverage implementation, its GuestMemory integration, a portable coverage regression and a Windows mapping-callback regression. It does not include residency, shader experiments, input configuration, diagnostics or changes from #6718. No rendering or FPS improvement is claimed for this PR.
Coverage metadata grows by one byte per 64 KiB arena block: approximately 15.6 MiB for the existing 1000 GiB reserved arena. Exclusion-generation entries remain sparse.
Related work was rechecked. #6701 changes write-tracking stamp allocation and shares the hint-handling area, but does not implement page-level exclusion restoration; integrating both may require a rebase. #6455 stamps watched portions of CPU stores; #6308/#4448/#6678 change import/unwatch handling. None is a prerequisite for this repair.
Tested
Rebase validation — 2026-10-20. Rebased onto upstream
main661f8b717. Current head:823c6a55e148aeaa1e2444eb37a0d324ce0b78c5; original authorship is retained. The sparse write tracker useshintOf/stampHint; the remap callback now clears an existing leaf's hint without allocating a missing leaf, preservingdriverPieces.droppedinvalidation and whole-block coverage checks.Windows 11 build 26200, Intel Core i7-13700, NVIDIA GeForce RTX 4070 / driver 610.88, GCC 15.2 / Release / SPIR-V Tools. Fresh focused targets rebuilt for main and the PR. Main: 10/10 pass, zero skips, 11.98 s. PR: 11/11 pass, zero skips, 11.19 s, including the real Windows
agc_partial_watch_restorationcallback regression. Both useANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationand the same GPU. Loader logs confirm the Khronos 1.4.304 layer actually loads; neither log reports a missing requested layer. No new VUID errors compared with main. Both include the sameVUID-VkDeviceCreateInfo-pNext-pNextfor an extension structure unknown to that older validation layer; zero total VUIDs is not claimed.Old DLL copies beside the test executables were moved aside before these final runs so the tests load the rebuilt unpatched libraries. Conventions against canonical
upstream/mainand diff checks pass. The requiredorigin/maincheck was attempted but its stale fork baseline hits Windows command-line length limits; the canonical target baseline succeeds. No new gameplay/performance claim, raw-trace upload, or Linux/vendor validation is implied by this rebase.Previous rebase validation — 2026-10-19 (historical). Rebased onto upstream
main6b8228b2bfecb895010e379362c6d0bb288c2d47. Current head:79c6c4fd27438ee1f9ae444b5433f4e86599a04e. Original authorship is retained.The private-remap callback now combines stale-hint clearing with upstream’s newer
driverPieces.droppedinvalidation. It does not restore the older erase operation over the new write-history bookkeeping. The portable coverage and real Windows reset/commit callback regressions remain intact. This PR remains standalone, with no #6718, residency or shader changes.Earlier validation and investigation (historical revisions):
Previous review-update head:
30e0ab992c80d35957dcb9532d484671caf4f0d5, rebased onto upstreamc0a7468f6f666a46b1c3e2fb14bb651fed05afc5. Standalone: no #6718 memo repair, selected-import, residency or shader changes are included.The previously missing Windows callback coverage is now exercised directly. New test
agc_partial_watch_restorationallocates separate 16 KiB private backing granules, excludes their containing 64 KiB block, remaps one 16 KiB range through the real GuestArena reset/commit path, and checks:With only the production GuestMemory implementation and coverage header replaced by current unpatched upstream, that same test fails with
a partial private remap did not restore its write watch. The repaired source passes.Fresh standalone Windows validation: 21/21 pass, zero skips, 16.36 s total; longest individual test 7.16 s. GCC 15.2.0, Release, SPIR-V Tools enabled, Windows 11 10.0.26200, RTX 4070 / driver 591.86. This includes the callback regression, portable coverage, imports/unmap/retirement, CPU snapshots/write-back, aliasing, clears, graphics and both pixel regressions. Every test has a 30-second timeout. Conventions and diff checks pass.
Linux helper-only validation: Ubuntu 26.04.1 under WSL 2, kernel 6.18.54.1, GCC 15.2. The current helper test fails with the pre-repair header at
a partial replacement did not restore its complete pages; it passes with the repaired header, both normally and with AddressSanitizer + UBSan. This supplements the independent helper oracle reported in the review; Linux does not exercise the Windows-only callback, and no Linux GPU/title validation is claimed.No new rendering, FPS, game stability or cross-title claim. The working game runtime and local controls are unchanged; evidence remains local. The following integration results are historical and retain their original limitations.
-O3 -DNDEBUG,BUILD_TESTING=ON,ANYPS5_ENABLE_SPIRV_TOOLS=ON.332b0b1b7. The synthetic regression fails against that revision before the repair witha fresh partial-block private mapping stayed excluded, and passes after it.agc_driver_pixel_ancillary_wordandagc_driver_pixel_fixed_point_positionwith residency enabled before this repair; both pass afterward. Source-only integration passes 18/18 focused tests with residency off and on. Residency remains separately attributed and is excluded from this PR.v_interp_mov p10/p20flat-interpolation semantic-test failure. That patch is excluded here; this PR's clean-source graphics test passes. No guard was weakened.Keeping this PR in draft for maintainer feedback and remaining cross-title/stability coverage. Integration gameplay checks above used the earlier tested repair revision on
5d9dcc42d; the current-main rebase was rebuilt and tested separately. No fresh manual controls/audio confirmation is claimed.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)Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-16T10:23:40Z.
Independent native Linux check of the portable coverage helper, exact head
6aac39219570c674c66d64f9eefbcd7f3b112fef. Ubuntu 24.04, kernel 7.0.0-38, GCC 13.3, Ryzen 9 9950X; CPU only.Compiled the unchanged
WriteWatchCoverage.cpptest directly against the PR header: passes. With only the production header fromHEAD^, it fails witha partial replacement did not restore its complete pages.A separate oracle uses a boolean per 4 KiB page, a generation per 64 KiB exclusion block, and linear interval-intersection/containment checks, rather than the implementation's bit masks. Across five seeds it agrees with the actual PR header for 240,000 Exclude/Restore operations and 8,730,000 Covers queries. Arenas include empty, 17-byte, page/block boundary sizes and a three-block-plus-17-byte tail. It checks mutation return values as well as coverage, with aligned/unaligned and clipped ranges, re-exclusion, equal/older/newer generations, every page, two-byte boundary crossings, random spans and whole-arena queries.
Discriminating controls, using seed 1:
<changed to<=): oracle fails.This supports both sides of the repair: complete remapped pages regain coverage while incomplete pages, excluded neighbors and newer exclusions remain protected. Repository worktree is clean; the probes and mutated headers are separate scratch files.
Limits: helper-level validation only.
watchPrivateMappingin the editedGuestMemory.cppis under_WIN32, so this does not exercise its hint clearing or mapping callback on Linux. No Windows runtime, import/GPU integration, SuperTuxKart/title replay, rendering or performance claim.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T10:24:26Z.
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/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/Execution/src/GuestMemory.cppcore/libs/prx/libSceAgcDriver/tests/Recorder.cppcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtcore/libs/prx/libSceAgcDriver/CMakeLists.txtImported from boykopovar/AnyPS5. Originally posted by Zenodeon on 2026-10-17T21:55:52Z.
Thanks for the independent helper validation and for identifying the remaining Windows integration gap. Updated head
30e0ab992is rebased ontoc0a7468f6and addsagc_partial_watch_restoration, which exercises the real GuestArena reset/commit callback on Windows.The test excludes a 64 KiB block, remaps a 16 KiB private allocation inside it, and checks restored coverage, excluded neighbors, stale-hint clearing and visibility of genuine CPU writes. It also verifies that re-excluding a partly watched block cannot invent a complete write-history hint.
With current unpatched upstream production code, the same test fails at
a partial private remap did not restore its write watch. With the repair, 21/21 focused Windows tests pass, zero skips, 16.36 s total, including the callback, import retirement, write-back, aliasing, clears and both pixel regressions. GCC 15.2 / Release / SPIR-V Tools; Windows 11 10.0.26200, RTX 4070, driver 591.86. Every test finishes within 30 s; conventions and diff checks pass.I also reran the portable helper on Ubuntu 26.04.1/WSL 2 with GCC 15.2: the pre-repair header fails, while the repaired header passes normally and under AddressSanitizer + UBSan. Those Linux runs remain helper-only; the Windows callback is tested separately above.
The PR remains standalone and in draft. No #6718, residency or shader changes, new gameplay-performance claim, or evidence-bundle upload. Existing cross-title/stability limitations remain documented. AI-assisted implementation and validation.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-20T08:36:30Z.
Review: CHANGES_REQUESTED
This now conflicts with
mainin a way that needs your adaptation, not a mechanical rebase:GuestMemory.cppWriteTracker::hinted: main reads hints throughhintOf(block)(sparseLeaf::hintBlocks, #7788 area). KeephintOf(block) == 0 || !coverage.Covers(...)semantics but with your whole-blockCovers(blockBegin(block), min(WriteBlockBytes, base + size - blockBegin(block))).startHintscallsstampHint(block)on main; keep your whole-blockCoverscheck there.watchPrivateMapping:tracker.hintBlocks[block] = 0no longer exists. Clear the hint through the leaf (without allocating one if it is absent), next to the existingdriverPieces.droppedupdate.The mask/
Coverslogic and both tests looked right on the previous head; once rebased the Windows job of the merge queue will be the gate for this_WIN32code, so please make sureagc_partial_watch_restorationstill passes.Imported from boykopovar/AnyPS5. Originally posted by Zenodeon on 2026-10-20T09:16:24Z.
@adriadam10 Addressed in the rebased head
823c6a55e148aeaa1e2444eb37a0d324ce0b78c5, based on main661f8b717.hintedreads throughhintOf(block)and uses whole-block coverage;startHintsretainsstampHint(block)with the whole-block coverage check.watchPrivateMappingclears the hint only when its sparse leaf already exists, without allocating a missing leaf, beside the preserveddriverPieces.droppedupdate.Fresh Windows validation on the same RTX 4070 (driver 610.88), Windows 11 build 26200, GCC 15.2 Release: main passes 10/10 focused tests; this head passes 11/11, zero skips, including
agc_partial_watch_restorationthrough the actual reset/commit callback. Required Vulkan validation and disabled shader caching were enabled on both builds, and loader logs confirm the validation layer loaded. No new VUID errors relative to main; both logs contain the same device-create VUID for a structure unknown to the installed older validation layer. Conventions against canonical upstream/main and diff checks pass.The PR description contains the updated rebase and validation details. Ready for re-review.
AI-assisted: yes (OpenAI Codex).