Expand description
Vulkan interop: run lactea on the host’s own VkDevice and render into host VkImages.
wgpu cannot adopt a foreign image on a device of its own, so the engine has to be on the host’s
device. The host keeps creating the VkInstance and VkDevice; lactea only wraps the handles
through wgpu::hal::vulkan and never destroys them. Only raw Vulkan handles cross this API, so the
host may use any Vulkan binding, or a wgpu of another major version (its as_hal::<Vulkan>()
gives the handles).
The contract, in order:
- Create the
VkInstancewithapiVersion>= 1.1 and >= the version the physical device reports (vkEnumerateInstanceVersionis always safe: wgpu assumes the device exposes every core version it reports, and a lower instance version hides those functions;open_devicechecks this and refuses), plus the extensionVK_KHR_get_physical_device_properties2(wgpu assumes it is on whenever it exists). requirementslists the device extensions wgpu needs and aVkPhysicalDeviceFeatures+pNextfeature chain. Create theVkDevicewith them (add your own extensions and features; chain your own structs in front of thepNextchain). A device created by wgpu itself already has them unless that wgpu needs fewer extensions than this one:open_devicenames the first one missing.open_devicewraps the device as awgpu::Device+wgpu::Queueforlactea::Engine.- Every frame,
wrap_imageturns the host’sVkImageinto awgpu::Textureto render into.
Layout and synchronisation: lactea submits to the host’s queue (queue_family_index /
queue_index, externally synchronised like any queue: do not submit to it from another thread at
the same time). The image may be in any layout and its contents are discarded; after the
submission it is in VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL with the colour writes finished
once the work has executed. On the same queue a pipeline barrier (COLOR_ATTACHMENT_OUTPUT ->
whatever comes next) is enough. Drop the engine and the wrapped device before the VkDevice, and
keep each image alive until the work rendering into it has executed.
Present where wgpu has a Vulkan backend: Windows and non-Apple Unix.
Structs§
- Vulkan
Host - The host’s Vulkan objects. Dispatchable handles are pointers, extension names exactly as given
to
vkCreateInstance/vkCreateDevice. - Vulkan
Requirements - What
vkCreateDeviceneeds for lactea; the pointers stay valid as long as this value.
Constants§
- VK_
FORMAT_ B8G8 R8A8_ UNORM VK_FORMAT_B8G8R8A8_UNORM.- VK_
FORMAT_ R8G8 B8A8_ UNORM VK_FORMAT_R8G8B8A8_UNORM.
Functions§
- format_
from_ vk - The image formats lactea renders into, by
VkFormat;Nonefor any other. - open_
device ⚠ - Wrap the host’s
VkDeviceas the device and queue to build alactea::Engineon. Uses wgpu’s default limits and no optional features. - requirements⚠
- Which device extensions and features wgpu needs on
host’s physical device. Reads onlyget_instance_proc_addr,instance,physical_device,api_versionand the instance extensions. - wrap_
image ⚠ - The host’s
VkImage(a non-dispatchable handle, asu64) as a render attachment ofdevice.formatis oneformat_from_vkaccepts and the image’s own; the image was created withVK_IMAGE_USAGE_COLOR_ATTACHMENT_BITatwidthxheight.