fix(agc): prefer imported prefixes before sparse heap mirrors #8762
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8762"
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 JJenkx on 2026-10-20T23:56:38Z.
What
A read-only buffer descriptor that extends past the committed prefix of a registered heap can bind a heap mirror before checking the host import that already covers that prefix. An address-based build then uses the import and releases the mirror. Alternating the two paths can recreate the same mirror repeatedly.
Try the existing import resolution and GPU-copy paths before the sparse heap mirror fallback. Keep the existing write-overlap, committed-range and descriptor-cut checks. A writable overhanging descriptor still falls back to a mirror; a view starting beyond an imported prefix is still rejected.
The regression fixture alternates descriptor and address-based builds over an imported 64 KiB prefix with an inaccessible tail, checks that no mirror is rebuilt or copied, rejects a view past the prefix, and verifies CPU/GPU stores through the writable fallback.
Overlap review:
tools/pr_overlap.pyreported no directly comparable overlap, but listed 22 stale/conflicting PRs for manual review. Their AGC diffs were inspected; none moves this sparse mirror fallback after import selection. #7647 changes mirror storage/allocation and keeps the original selection order; it is independent of this change. No dependency on the separate persistent heap-shadow experiment.Tested
Linux / Arch Linux, AMD Radeon RX 6650 XT, RADV Mesa 26.2.4-arch1.1. Based on main
5b59fbc5539b6c6db7a26972f6069f1c6cc179ac; candidate53b73b5dae17ab7005c93e766a3dc66fa2e10310.libs,agc_driver_graphics_tests, andagc_driver_bda_device_tests.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_DRIVER_FILES=/usr/share/vulkan/icd.d/radeon_icd.json ctest --test-dir build-full -R '^agc_driver_(graphics|bda_device)$' -V.100% tests passed out of 2; zeroVUID-messages; no missing validation layer.100% tests passed out of 2; zeroVUID-messages; no missing validation layer;Sparse imported heap tests passedexecuted.the sparse descriptor did not bind its imported prefix, then passed after it. The standalone candidate above also passes on current main.bcc36571bf(test only):sparseImportedHeapTestsbinds a read-only descriptor at a misaligned offset (base + 16,minStorageBufferOffsetAlignment256, active recorder) that extends past the committed 64 KiB prefix into aPROT_NONEpage. It must not bind the import, and its view and copied bytes stay within the committed prefix.agc_driver_graphicspasses onbcc36571bf; withregion.sparseremoved fromgpuCopyEligible(the reviewer's GPU-copy scenario) the case segfaults on the uncommitted tail. Sparse-run regions cannot take the GPU-copy or staging path because both require!region.sparse. This suite runs on the mock Vulkan device, so no validation layer is involved.python3 tools/check_conventions.py --base origin/main: passed.The new fixture is Linux-only. Independent Windows testing by @ycbuzi used candidate
53b73b5daemerged onto mainb77bd58806(merge6301d6bb2a), Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release withBUILD_TESTING=ON, and an NVIDIA GeForce RTX 4070 SUPER, driver 616.92 (ANYPS5_GPU=4070). They builtlibSceAgcDriverandagc_driver_graphics_tests; all 27 cases registered on Windows passed both repeats withctest --repeat until-fail:2. This covers existing Windows cases; the Linux-only sparse-prefix fixture and a title were not run. No Windows validation-layer or VUID result was reported. No title frame-rate, loading-time, or crash-fix claim is made; Echoes of the End is still under investigation.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 MarcZX10 on 2026-10-21T00:03:31Z.
Review: APPROVED
Reviewed the import-before-sparse-mirror reorder and the Linux regression fixture. The existing host-import and GPU-copy selection remains intact; the fallback now runs only after those paths, while the fixture checks read-only imported-prefix reuse, over-prefix rejection, writable fallback behavior, and cleanup. The reported focused validation runs and successful eligibility/convention checks are consistent with this narrow change.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T00:13:11Z.
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/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/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/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/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.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T07:19:16Z.
@JJenkx thanks, the reorder reads right for the aligned case your fixture covers. One path I'd like pinned before merge: now that the sparse mirror comes after the import paths, a sparse-run region whose import offset is not bindable in place (
bindableInPlacefalse, so not a multiple ofminStorageBufferOffsetAlignmentwhenadjustedRegionsis off) and that isgpuCopyEligibletakescopyOnGpu. The copy loop then sizes the copy asregion->end - region->begin. For a read-only region it firstmemcpys that whole range from guest memory (inputSnapshot), which would read the inaccessible tail, andCopyBufferwould read past the import, which only covers up toneededEnd. Before this change the sparse mirror took such a region first.Could you either add a case to
sparseImportedHeapTestswith a descriptor that starts at a misaligned offset inside the committed prefix and extends past it, or keep sparse-run regions off the GPU copy path, for exampleelse if (entry != nullptr && !runImport && recorder != nullptr && (staged || gpuCopyEligible(region)))? I haven't reproduced it; this is from reading the mergedUploadFinish.Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-21T07:46:30Z.
Windows run of
53b73b5daemerged ontomainb77bd58806(6301d6bb2a, clean), the host the description lists as not tested. Windows 11 Home 10.0.26200, MinGW-w64 GCC 15.2.0 (ucrt-posix-seh r7), Release,BUILD_TESTING=ON. GPU: NVIDIA GeForce RTX 4070 SUPER, driver 616.92, picked withANYPS5_GPU=4070(the machine also has a GTX 1650 SUPER).Built
libSceAgcDriverandagc_driver_graphics_testswith no errors or warnings;ctest --repeat until-fail:2on the 27 testsagc_driver_graphics_testsregisters on Windows: all pass on both repeats. The new fixture is under#ifndef _WIN32, so it did not run here; the existing cases pass with the reordered lookup. Not run: the new fixture (Linux-only), a title.Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-10-21T08:11:09Z.
@oneandonlydean thanks, pinned in
bcc36571bf(test only, no source change).The GPU-copy fallback cannot take a sparse-run region: a sparse run requires
region.sparse(sparseRun = region.sparseHeap && region.sparse), and bothgpuCopyEligibleandstagingEligiblereturn false forregion.sparse. A misaligned run import therefore falls through to the sparse heap mirror or the CPU copy of the committed pieces, as it did before the reorder.sparseImportedHeapTestsnow has that case:minStorageBufferOffsetAlignment256, an active recorder, and a read-only descriptor atbase + 16covering two 64 KiB pages of which only the first is committed (the second isPROT_NONE). The descriptor must not be bound to the import, its view must start with the guest's byte, and neither the view nor the copied bytes may exceed the committed 64 KiB. Here the view is the CPU copy of the committed piece (range 65536, offset 0, adjustment 0, 65536 bytes copied).agc_driver_graphicspasses, including the later writable fallback and its mirror rebuild count.region.sparseremoved fromgpuCopyEligible(your scenario): the new case segfaults reading the uncommitted tail.5b59fbc553with the new test fails earlier, at this PR's existing check (the sparse descriptor did not bind its imported prefix).Linux 7.2.9, GCC 16.2.1, Release. This suite runs on the mock Vulkan device, so the validation layer does not load (no VUIDs to compare).
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T08:16:48Z.
@JJenkx thanks, that settles it: with
region.sparseexcluded from bothgpuCopyEligibleandstagingEligible, a misaligned sparse run can't reach the GPU copy, and the new case pins it with a negative control that segfaults on the uncommitted tail. We'll checkbcc36571bfand run full CI.