fix(agc): take a host-coherent memory type for a host import (#6512) #6548
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6548"
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 fanyzp on 2026-10-15T19:58:13Z.
What
GuestBufferMemorybound a host-pointer import to the first memory type the intersection of its bits and the buffer's offered (std::countr_zero), without looking at what that type guarantees. The imported range is the guest's own memory, which the CPU reads through the same pointer, and Vulkan offers no invalidation for imported memory (vkInvalidateMappedMemoryRangesworks on memory mapped withvkMapMemory), so a candidate the device reports as not guaranteeing host coherency cannot back it: a store the GPU made through such an import can stay invisible to the CPU. Issue #6512 measures exactly that shape (inagc_driver_multisample_fill_host_only, the sentinel fill after the absorbed multisampled clear does not land, and a direct host read of the block agrees).The import now takes a
HOST_VISIBLE | HOST_COHERENTcandidate, preferring a cached one among those asContext::BufferMemoryTypedoes, and refuses the import when the device reports candidates without it (the range is copied instead, and the log names the step). A context whose memory properties are not known keeps the first candidate, as the tests' contexts do.Not established here: which types a discrete GPU's driver reports for a host pointer, which decides whether this is #6512's cause and whether the preference or the refusal is what fixes it there. On RADV (Radeon 680M, Mesa 26.2.3) the pointer's bits are a coherent type only, which is why #6512 does not reproduce on this machine (700 runs of the test, 200 of them with the process pinned to two CPUs, plus 200 on lavapipe: 0 failures) and why the refusal path is covered by the new test only. A device whose only candidates are non-coherent now copies guest ranges instead of importing them, which is slower and correct. A dma-buf import of a guest range keeps the first-candidate choice; the same argument may apply to it and it is not changed here.
Tested
agc_driver_graphics_tests(newhostImportMemoryTypeTests): a device whose lowest-index host-pointer candidate is not coherent and whose second one is imports through the coherent one; a device whose candidates are all non-coherent does not import the range (it is copied). The new test fails onmain(the import did not take the coherent memory type), so it covers the change.agc_driver_multisample_fill_host_only_testson this head: 50 runs on RADV, 50 more with the process pinned to two CPUs, 50 on lavapipe: 0 failures (the flake does not reproduce here, before or after the change).agc_graphics_profile_draw,agc_driver_host_import_at_map,agc_host_import_retirement,agc_host_import_retire: pass.agc_host_import_sparseskips here (it wants a udmabuf range above 1024 MiB).main, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer(validation layer 1.4.341, newer than the bundled headers' 1.4.335): the same pass and skip on both, the loader inserting the layer in each log and neither log holding aVUID-error, on RADV and on lavapipe. The only difference between the two logs is the new refusal line.ctestsuite was not run.Checklist
main; no other open PR implements the same functions (no open PR or issue mentions the import's memory type; #6512 is the report this follows from)docs/dev/debt/libSceAgcDriver.md)NotImplemented_nid_no_patch); no silent stubs added.mdfiles or images added to the repositoryImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-15T21:27:30Z.
Review: COMMENTED
NVIDIA Linux data for the part the description leaves open: which types a discrete driver reports for a host pointer.
Machine: NVIDIA GeForce RTX 3070, driver 595.99.02, Vulkan 1.4.329, Ubuntu 26.04 (kernel 7.0.0-38), i7-8700. GCC 15.2, Release,
BUILD_TESTING=ON. Head33a87a353merged ontomain44df21632, no conflicts.ANYPS5_GPU="NVIDIA GeForce RTX 3070", confirmed in the logs.GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02), Linux
Host-pointer candidates on this driver. These come from a small standalone Vulkan program, not AnyPS5 code: a 1 MiB anonymous private
mmap,vkGetMemoryHostPointerPropertiesEXTwithHOST_ALLOCATION_BIT_EXT, intersected with a storage + transfer buffer's requirements.HOST_VISIBLE | HOST_COHERENT(lowest index, whatmaintakes);HOST_VISIBLE | HOST_COHERENT | HOST_CACHED(what this PR prefers).Both candidates are coherent, so on this driver the PR changes the choice from uncached to cached. It never takes the refusal path. llvmpipe offers a single type with all four flags.
Tests
Graphics.cpp,GuestBufferMemory.cppfrommain):agc_driver_graphicsfails withthe import did not take the coherent memory type. With the fix it passes 3/3.agc_host_import_retire,agc_host_import_sparse,agc_driver_host_import_at_map: pass, with and without the fix.agc_driver_multisample_fill_host_only(#6512): 50/50 with the PR. On unchangedmainit did not fail here either: 0/230 idle, 0/30 under load.ctest -R "^agc|shader|recompiler|image" -E "agc_display_buffer_dcc|agc_driver_flip|agc_driver_lds_atomics64|display|flip" -j1 --timeout 60: 601/602 pass.agc_driver_stencil_ref_exportis skipped because the 3070 does not exposeVK_EXT_shader_stencil_export.agc_driver_store_over_untracked(#6347): 0/20 pass with the PR, 3/20 onmain.agc_pending_key_stores(#6500): 29/30 with the PR, 26/30 onmain. Both passed in the suite run above by chance.Written with AI assistance (Claude Code). I ran the tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-17T11:42:30Z.
Rebase handoff — rebased onto current
main(authorship unchanged). One conflict inGuestBufferMemory.cpp:main's newer dma-buf queue-family sharing (ImportFamilies/shareDmaBufImport) kept alongside yourcoherentImportTypehelper and the extendedbindImportsignature.Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release,
BUILD_TESTING=ON, AMD RX 9070 XT / RADV):tools/check_conventions.py --base origin/mainpassesmainregression (agc_driver_tessellationsegfault, #4727), not this PRTo pick it up:
Head is
43012d1d7.Imported from boykopovar/AnyPS5. Originally posted by fanyzp on 2026-10-17T15:44:31Z.
Picked the handoff up, thanks for resolving it.
New head is
89fb35adf: cherry-picked43012d1d7onto currentmain(84b0d2f24), which applied clean with no further conflict, soImportFamilies/shareDmaBufImportandcoherentImportTypesit together as in your resolution. Branch force-pushed, and the PR reportsMERGEABLEagain.Re-verified here (AMD Radeon 680M, RADV, Mesa 26.2.3, Linux 7.2.8; GCC 16.2.1, Release, Ninja,
BUILD_TESTING=ON):tools/check_conventions.py --base origin/main: passesagc_driver_graphics_tests(newhostImportMemoryTypeTests): passagc_host_import_retire_tests,agc_host_import_sparse_tests,agc_driver_host_import_at_map_tests: passagc_driver_multisample_fill_host_only_tests: 50/50GuestBufferMemory.cpptaken frommain,agc_driver_graphics_testsfails withthe import did not take the coherent memory type; with the fix it passes.On the new head
conventionspassed.BuildandProgress reportare stillaction_required, which a maintainer approves.The rebase resolution is blawesom's; the checks above were run here. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by Queuse on 2026-10-21T23:36:29Z.
Rebased branch and cached-choice coverage,
cd4272bc00, maina6dcea9279; authorship preserved.Baseline/candidate: graphics, import retirement and import-at-map pass on RTX 3050 Laptop/617.42 and Iris Xe/101.4502 (Windows 11, GCC 15.2.0-r7); Linux-only sparse import skips. Required Vulkan/validation/cache flags: zero missing layer/VUID errors.
Host-pointer probes offer Intel types 0/1/2 (0 device-local only; 2 coherent+cached), NVIDIA 3/4 (both coherent; 4 cached). Added representative cached-choice cases; removing that preference fails its assertion. #6512 is closed after #6522; this validates the separate memory-type protection, without claiming that flake or a title is fixed. AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T19:52:33Z.
Review: COMMENTED
Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement;
Unblocks: noneis allowed. The technical points below are unaffected.Points on 6548:
Comments in code.
GuestBufferMemory.cppadds a///doc block for the memory-type helper (four lines plus an inline reference toContext::BufferMemoryType). The repo rule is no comments except#endifand namespace ends. 13 added comment lines in this diff in total; please remove them.Refusal becomes a copy. When no candidate memory type guarantees host coherency the import is refused and "the range is copied instead". That copy path is the slow one this feature exists to avoid, and on a device without a coherent type it is taken on every use. Please say which GPUs fall into it and attach a
tools/trace_digest.pycomparison of main and the change on one of them, same scene.Title evidence. The fix references #6512 but no title ID and log line showing a title hits this memory-type choice on main. Please add one.