fix(agc): import shared guest memory through a read-write alias and never offer read-only pages #186
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/186"
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 MichonGoddijn231849 on 2026-09-30T15:14:06Z.
What
On NVIDIA (RTX 5080, driver 610.74),
vkAllocateMemoryrefuses a host-pointer import (VK_ERROR_OUT_OF_DEVICE_MEMORY) when any page in the range is read-only. After one refusal, later large imports in the same process fail too, even of memory that imported fine before.mainarms shared (direct memory) pages read-only for write tracking. So the first import of a direct-memory range is refused, and from then on every import fails ("out of memory ... retried later", thousands of times). Every BDA build then falls back to heap mirrors refreshed by copying: single dispatches took 11–16 s in "address bindings (bda)".This change:
GuestArenaMapAlias). Write tracking never arms that view; the GPU reads the same pages, so CPU writes stay visible. The view is unmapped when the import is destroyed.WindowsMappingskeeps a duplicated section handle per mapping, so the alias can be made after the caller closed its own handle.PAGE_READONLY/PAGE_EXECUTE_READ, not shared) is copied on purpose. It is the one kind the driver refuses, and it can't change without a protection change, which updates the registry, so the copy is exact.MapViewOfFile3(withGetLastError()).Tested
Windows 11, RTX 5080 (driver 610.74), MinGW GCC 15.2.
Standalone Vulkan test, each case in a fresh process, 64 MiB unless noted:
VirtualAllocRW, with or withoutMEM_WRITE_WATCHMEM_WRITE_WATCH-2-2: a range that imported before-2-2: fresh 16 MiB or 1 MiB.data), and untouched copy-on-write image pagesGTA V (PPSA04264), with #167, measured before the rebase onto the latest
main(the Windows import path is unchanged by it):cteston currentmainwith this change: the libc and guest tests pass. Not run on this machine:agc_driver,agc_shader_memory,agc_driver_flipandagc_driver_pm4exit with0xc0000139at startup, the same as on plainmainbefore the rebase;agc_driver_graphicsdoesn't build here (tests/Graphics.cpp:1246, from the recent merges, untouched here);empty_tls,tls_function_coverageandwindows_gui(relinker) fail.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by boykopovar on 2026-09-30T16:52:35Z.
Instead of quiet fallbacks, let's throw a clear exception in these places:
MapViewOfFile3fails to create the RW alias (currently returnsnullptrsilently). Include the Windows error fromGetLastError()in the exception.If after this the game starts to crash earlier than before the changes, this will only show the real problem.
Imported from boykopovar/AnyPS5. Originally posted by MichonGoddijn231849 on 2026-09-30T17:14:51Z.
Done in
f4be8f43, thanks. Both now throw with the reason:MapViewOfFile3throws withGetLastError().It surfaced two things in GTA V right away. Both are in the relinked executable's own image, read by compute shader
0x242d47200:MEM_IMAGE,PAGE_READWRITE/PAGE_WRITECOPY). I checked in a standalone test: NVIDIA imports those fine, so they are imported now instead of falling back.MEM_IMAGE,PAGE_READONLY). That is the one kind the driver refuses to import. It can't change without a protection change, which already updates the registry, so it is copied on purpose; every other non-importable range throws.With that, GTA V reaches the world again. If you'd rather not copy read-only memory, the alternative is for the loader to place the executable's read-only sections in private memory, so they import like the rest. Happy to do that instead.