Skip to content

host: make system blob memory work on macOS - #182

Open
utzcoz wants to merge 2 commits into
google:mainfrom
utzcoz:macos-host-memory
Open

host: make system blob memory work on macOS#182
utzcoz wants to merge 2 commits into
google:mainfrom
utzcoz:macos-host-memory

Conversation

@utzcoz

@utzcoz utzcoz commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Two host fixes for running the guest Vulkan driver through kumquat on macOS.
Both only take effect with SystemBlob enabled.

  • vulkan: add a guest only device local memory type when the host reports a
    single host visible unified type. Metal cannot bind a tiled image to an
    imported host pointer; this gives images ordinary device memory. Unit test
    added.

  • base: put the pid in the shared memory name and unlink it on creation, so a
    killed server does not leave objects that make the next ftruncate fail.

Tested with bazel test //host/vulkan:gfxstream_emulatedphysicalmemory_tests,
and vulkaninfo, vkcube and a dEQP-VK smoke run on kosmickrisp and MoltenVK.

@utzcoz

utzcoz commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@utzcoz

utzcoz commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

Friendly ping @gurchetansingh @jmacnak for reviewing.

Comment thread host/vulkan/vk_emulated_physical_device_memory.cpp Outdated
@gurchetansingh

Copy link
Copy Markdown
Collaborator

@jmacnak knows this code well, would be the right person to review

Comment thread host/vulkan/vk_emulated_physical_device_memory.cpp Outdated
@utzcoz
utzcoz force-pushed the macos-host-memory branch 2 times, most recently from 8a8f716 to 293c959 Compare September 10, 2026 15:53
With system blobs, host visible memory is shared memory imported as a host
pointer, and Metal cannot bind a tiled image to that. A device that reports one
unified memory type, as kosmickrisp does, then has nowhere to put an image, and
kk_image_plane_bind asserts on the first one.

Add a guest only type in that case: device local, allocating from the same host
type without host visible emulation. A tiled image is offered that type alone,
since the host visible one cannot hold it; a linear image may still use either.
MoltenVK reports a device local only type of its own, so nothing changes there.

The type goes first, not last: the spec requires a memory type whose flags are
a strict subset of another's to sit at a lower index, and device local alone is
a subset of every host visible type here.

Metal is what makes this the common case, so it is behind __APPLE__.
System blob memory is named shared-memory-vk-N with a per process counter and
opened without O_EXCL. A server that is killed leaves its objects behind, the
next one reuses the names, and on macOS an object that already has a size
cannot be resized: ftruncate fails with EINVAL and vkAllocateMemory fails.

Put the pid in the name, and on Apple unlink the object as soon as it exists;
the descriptor keeps it alive and is what the guest is handed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants