perf(agc): copy only nonzero pages before a watched import #5698
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/5698"
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 milescoviello on 2026-10-14T07:16:43Z.
What
Ghost of Tsushima (PPSA02225) maps about 4.9 GB of direct memory with
sceKernelBatchMap2at start-up, and the driver imports it (GuestAllocationsEnd→VulkanDevice::ImportGuestMemory→ImportMappedRanges→ImportWatched). The import leaves the range watched, so since #3874ImportWatchedfirst copies the whole range, to compare each page the import resolves with its bytes when the window closes. heaptrack shows this copy as the largest allocation the title makes: 4.92 GB of its 5.30 GB peak heap.Pages that are all zero are no longer copied.
ImportWatchedgives each page of the range a slot: the index of its copy, or none for a page that was all zero.WindowCopy::Holdscompares a page without a copy with a zero page. Every page is compared with the same bytes as before, so the window stamps the same pages as onmain. The copy reads each page once to check it for zero and copies only the others; before, it copied every page.agc_write_trackinggainsCheckImportWindowZeroPages. It runs an import window over a block with bytes, two zero blocks and two blocks with other bytes after them. Inside the window it stores the same bytes into the first block, zero into the first zero block, and new bytes into the second zero block and the last block. It then checks which blocks read as written. The case also passes withmain's full copy. It fails, each time with its own message, for three broken versions: one that takes a page without a copy as unchanged, one that takes it as changed, and one that looks up a copied page by its offset in the range instead of its slot.Tested
Ubuntu 24.04, GCC 13.3 (CI's compiler), Release with CI's configure flags, on
maind8888df9b:All 508 tests in
libSceAgcDriverpass on an RTX 4070 Ti (NVIDIA 580.142).agc_driver_stencil_ref_exportis skipped, as onmain, because the device lacksVK_EXT_shader_stencil_export.agc_write_trackingpasses 3/3.Ghost of Tsushima (PPSA02225), relinked with
--to-inteland run on Linux for 150 s under heaptrack. The two runs differ only inlibSceAgcDriver.prxand start from the same shader cache:mainImportWatchedat the peakThe title logs the same messages in both runs: the same 28 shaders fail to prepare, as on
main.A MinGW-w64 GCC 13
-fsyntax-onlycompile of both changed files has no errors.tools/check_conventions.py --base upstream/mainpasses, andtools/pr_overlap.py --branchfinds no overlap.Not checked on Windows or on a console.
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T13:41:26Z.
Checked the diff against main: slots per 4 KiB page, zero pages compared against a zero page, same bytes compared as before.
agc_write_trackingpasses; the new case passes without the change (as the description says) and fails whenHoldstreats a zero page as unchanged. Merging once the Windows build is green.