fix(agc): import shared direct memory as dma-buf without VK_EXT_external_memory_host #16474

Merged
Rad0van merged 3 commits from upstream-pr/16474 into main 2026-11-15 19:28:37 +00:00
Rad0van commented 2026-11-06 19:45:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Rad0van on 2026-11-06T19:45:20Z.


What

The guest memory import machinery (import alignment, import window and size limit, and the dma-buf import of shared direct memory) was enabled only when the device exposes VK_EXT_external_memory_host. Linux drivers that have VK_KHR_external_memory_fd and VK_EXT_external_memory_dma_buf but no host pointer import (Honeykrisp, the Asahi Linux Vulkan driver for Apple GPUs) therefore never imported anything: every guest range was copied, and GPU stores through FLAT/GLOBAL addresses into direct memory failed with BDA access failed ... read-only in the BDA table.

The machinery is now enabled when either import is available:

  • hostPointerImport (new, in the device state and Graphics::Context) records whether VK_EXT_external_memory_host is usable; dmaBufImport is decided independently of it.
  • Without host pointer import the import alignment is the host page size, VK_EXT_external_memory_host is not requested, and importable GDS is not requested.
  • createHostPointerImport fails up front when host pointer import is unavailable, so createImport falls through to the existing udmabuf backing import (createBackingImport).
  • Graphics::Context::hostPointerImport defaults to true, so contexts built by tests keep their behaviour; APS5_NO_HOST_IMPORT still disables both imports.

Related, no dependency: #2434 changes the order of the two imports when both exist; it does not touch this gate.

Tested

Ubuntu 26.04 (Asahi Linux, kernel 7.2.0-1001-asahi-arm), Apple M2 Max. The host is aarch64, so the libraries were cross-compiled with Ubuntu's g++-15-x86-64-linux-gnu (GCC 15.2) and the x86-64 test executables run under FEX 2610 inside muvm 0.7 (4 KiB pages), with Vulkan forwarded to the native Honeykrisp driver (Mesa 26.0.8) through FEX thunks. Build-time tools (glslang, nid_patcher, relinker, the SQLite generators) were native aarch64 builds of the same sources.

Focused tests, same machine and GPU, main (9f2b939) and this change on top of it (the branch was then rebased onto 7b7edf6; none of the 27 new commits touch these files), ctest -R '^agc_.*(import|shared_write|guest_memory_lifetime|bda_device)' -E windows -V with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (layer 1.4.341):

  • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS; neither log contains a VUID- validation error.
  • main: 11 passed, 27 skipped, 2 failed. This change: 11 passed, 24 skipped, 5 failed.
  • Same failures on both: agc_host_import_sparse (its mock device table has no vkCmdFillBuffer), agc_driver_guest_memory_lifetime_converted (the converted executable it starts picks up the emulator's glibc 2.42; environment).
  • agc_driver_msaa_dcc_compared_import_{2,4,8} were skipped on main (the device imports no host memory) and now run; they stop at Require(GuestMemory::WriteWatched()) because neither FEX nor Box64 implements userfaultfd, so the guest arena is not write-watched in this environment. That check precedes and does not depend on this change.

Homebrew: DOOM (PPSA99666, AGC compute presentation) relinked with main's relinker, 30 s, no Vulkan layer, VK_EXT_external_memory_host: extension optional missing in the host report:

  • main: 57 BDA access failed write-backs into the display buffer (0x200c00000+0x2000000); the frame is not updated.
  • This change: 0 BDA failures; [write-watch] ... dma-buf imports are CPU-coherent (0 of 4 pages stale after a GPU store over CPU writes).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes #16466
  • Unblocks: none
  • GPUs tested: Apple M2 Max (G14C B1), Honeykrisp Mesa 26.0.8-1ubuntu0.3 (aarch64, through FEX 2610 Vulkan thunks), Ubuntu 26.04 Asahi Linux, kernel 7.2.0-1001-asahi-arm
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5193639912 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16474). Originally posted by [Rad0van](https://github.com/Rad0van) on 2026-11-06T19:45:20Z. --- ### What The guest memory import machinery (import alignment, import window and size limit, and the dma-buf import of shared direct memory) was enabled only when the device exposes `VK_EXT_external_memory_host`. Linux drivers that have `VK_KHR_external_memory_fd` and `VK_EXT_external_memory_dma_buf` but no host pointer import (Honeykrisp, the Asahi Linux Vulkan driver for Apple GPUs) therefore never imported anything: every guest range was copied, and GPU stores through FLAT/GLOBAL addresses into direct memory failed with `BDA access failed ... read-only in the BDA table`. The machinery is now enabled when either import is available: - `hostPointerImport` (new, in the device state and `Graphics::Context`) records whether `VK_EXT_external_memory_host` is usable; `dmaBufImport` is decided independently of it. - Without host pointer import the import alignment is the host page size, `VK_EXT_external_memory_host` is not requested, and importable GDS is not requested. - `createHostPointerImport` fails up front when host pointer import is unavailable, so `createImport` falls through to the existing udmabuf backing import (`createBackingImport`). - `Graphics::Context::hostPointerImport` defaults to `true`, so contexts built by tests keep their behaviour; `APS5_NO_HOST_IMPORT` still disables both imports. Related, no dependency: #2434 changes the order of the two imports when both exist; it does not touch this gate. ### Tested Ubuntu 26.04 (Asahi Linux, kernel 7.2.0-1001-asahi-arm), Apple M2 Max. The host is aarch64, so the libraries were cross-compiled with Ubuntu's `g++-15-x86-64-linux-gnu` (GCC 15.2) and the x86-64 test executables run under FEX 2610 inside muvm 0.7 (4 KiB pages), with Vulkan forwarded to the native Honeykrisp driver (Mesa 26.0.8) through FEX thunks. Build-time tools (glslang, nid_patcher, relinker, the SQLite generators) were native aarch64 builds of the same sources. Focused tests, same machine and GPU, `main` (9f2b939) and this change on top of it (the branch was then rebased onto 7b7edf6; none of the 27 new commits touch these files), `ctest -R '^agc_.*(import|shared_write|guest_memory_lifetime|bda_device)' -E windows -V` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (layer 1.4.341): - Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`; neither log contains a `VUID-` validation error. - `main`: 11 passed, 27 skipped, 2 failed. This change: 11 passed, 24 skipped, 5 failed. - Same failures on both: `agc_host_import_sparse` (its mock device table has no `vkCmdFillBuffer`), `agc_driver_guest_memory_lifetime_converted` (the converted executable it starts picks up the emulator's glibc 2.42; environment). - `agc_driver_msaa_dcc_compared_import_{2,4,8}` were skipped on `main` (`the device imports no host memory`) and now run; they stop at `Require(GuestMemory::WriteWatched())` because neither FEX nor Box64 implements `userfaultfd`, so the guest arena is not write-watched in this environment. That check precedes and does not depend on this change. Homebrew: DOOM (PPSA99666, AGC compute presentation) relinked with `main`'s relinker, 30 s, no Vulkan layer, `VK_EXT_external_memory_host: extension optional missing` in the host report: - `main`: 57 `BDA access failed` write-backs into the display buffer (0x200c00000+0x2000000); the frame is not updated. - This change: 0 BDA failures; `[write-watch] ... dma-buf imports are CPU-coherent (0 of 4 pages stale after a GPU store over CPU writes)`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes #16466 - [x] Unblocks: none - [x] GPUs tested: Apple M2 Max (G14C B1), Honeykrisp Mesa 26.0.8-1ubuntu0.3 (aarch64, through FEX 2610 Vulkan thunks), Ubuntu 26.04 Asahi Linux, kernel 7.2.0-1001-asahi-arm - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mashingaan commented 2026-11-08 10:47:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mashingaan on 2026-11-08T10:47:11Z.

Review: APPROVED


The hostPointerImport/dmaBufImport split is clean, the dma-buf path no longer requires VK_EXT_external_memory_host, and the probe is skipped when host pointer import is unavailable. The Windows and Linux runs plus the DOOM dma-buf check cover the restructure. No findings.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5817580884 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16474#pullrequestreview-5817580884). Originally posted by [mashingaan](https://github.com/mashingaan) on 2026-11-08T10:47:11Z. **Review:** APPROVED --- The hostPointerImport/dmaBufImport split is clean, the dma-buf path no longer requires VK_EXT_external_memory_host, and the probe is skipped when host pointer import is unavailable. The Windows and Linux runs plus the DOOM dma-buf check cover the restructure. No findings.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!16474
No description provided.