Skip to main content

Module vulkan

Module vulkan 

Source
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:

  1. Create the VkInstance with apiVersion >= 1.1 and >= the version the physical device reports (vkEnumerateInstanceVersion is always safe: wgpu assumes the device exposes every core version it reports, and a lower instance version hides those functions; open_device checks this and refuses), plus the extension VK_KHR_get_physical_device_properties2 (wgpu assumes it is on whenever it exists).
  2. requirements lists the device extensions wgpu needs and a VkPhysicalDeviceFeatures + pNext feature chain. Create the VkDevice with them (add your own extensions and features; chain your own structs in front of the pNext chain). A device created by wgpu itself already has them unless that wgpu needs fewer extensions than this one: open_device names the first one missing.
  3. open_device wraps the device as a wgpu::Device + wgpu::Queue for lactea::Engine.
  4. Every frame, wrap_image turns the host’s VkImage into a wgpu::Texture to 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§

VulkanHost
The host’s Vulkan objects. Dispatchable handles are pointers, extension names exactly as given to vkCreateInstance / vkCreateDevice.
VulkanRequirements
What vkCreateDevice needs for lactea; the pointers stay valid as long as this value.

Constants§

VK_FORMAT_B8G8R8A8_UNORM
VK_FORMAT_B8G8R8A8_UNORM.
VK_FORMAT_R8G8B8A8_UNORM
VK_FORMAT_R8G8B8A8_UNORM.

Functions§

format_from_vk
The image formats lactea renders into, by VkFormat; None for any other.
open_device⚠
Wrap the host’s VkDevice as the device and queue to build a lactea::Engine on. Uses wgpu’s default limits and no optional features.
requirements⚠
Which device extensions and features wgpu needs on host’s physical device. Reads only get_instance_proc_addr, instance, physical_device, api_version and the instance extensions.
wrap_image⚠
The host’s VkImage (a non-dispatchable handle, as u64) as a render attachment of device. format is one format_from_vk accepts and the image’s own; the image was created with VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT at width x height.