Skip to main content

Module dmabuf_import

Module dmabuf_import 

Expand description

Zero-copy DMA-BUF → wgpu texture import via Vulkan external memory. Shared by the WebView’s page buffers and the video decoder’s hardware frames. DMA-BUF → wgpu texture import via Vulkan external memory.

A producer that already has a picture in GPU memory — a hardware video decoder, or WebKit rendering a page — can hand it over as a dmabuf: a file descriptor naming the allocation, plus enough layout information to read it. Importing that as a wgpu::Texture aliases the same memory, so nothing is copied.

§What is reachable, and what is not

Import needs VK_KHR_external_memory_fd + VK_EXT_external_memory_dma_buf, which wgpu-hal enables. Interpreting a tiled or compressed layout additionally needs VK_EXT_image_drm_format_modifier — and wgpu-hal does not enable it (verified against wgpu-hal 29: adapter.rs pushes external_memory_fd and external_memory_dma_buf, and nothing else in that family). Without it Vulkan can only be told VK_IMAGE_TILING_LINEAR, so a buffer with any other DRM format modifier cannot be described and must not be imported: doing so would sample the tiling pattern as pixels.

Two further limits are enforced rather than hoped for:

  • Vulkan only. The import goes through Device::as_hal::<vulkan::Api>. If wgpu fell back to GLES there is no Vulkan device to import into, and ImportError::NotVulkan says so — the caller takes the CPU path instead of silently rendering nothing.
  • Row pitch must agree. A LINEAR VkImage’s row pitch is chosen by the driver, and there is no way to override it without the modifier extension. If it disagrees with the producer’s stride, the picture would shear; ImportError::StrideMismatch reports it and the caller falls back.

Every failure is a typed error, never a silently blank frame.

Structs§

DmabufRef
A dmabuf described well enough to import, borrowing its descriptors.
ImportedPlanes
A dmabuf imported as sampleable textures.
ImportedRenderTarget
One compositor-owned scanout dma-buf imported as a writable render target.
PlaneRef
One plane of a buffer being imported, borrowed for the call.
VulkanDrmDeviceIdentity
DRM character-device identities reported by the Vulkan physical device.

Enums§

ImportError
Why an import could not happen. Each variant names a real, distinct condition the caller can act on — all of them mean “use the CPU path”.
PlaneLayout
How the imported planes are laid out, and therefore how to sample them.

Functions§

import
Import image as sampleable wgpu textures, aliasing its GPU memory.
import_render_target
Import the one linear plane of a compositor-owned scanout buffer (XRGB8888, XBGR2101010 or ABGR16161616F) as a render attachment on device.
render_target_format
The scanout formats the compositor renders into, with the Vulkan and wgpu formats that describe the same bytes and the bytes per pixel.
vulkan_drm_device_identity
Query the DRM nodes owned by the exact Vulkan physical device behind device. Returns None when the backend is not Vulkan or the driver does not expose VK_EXT_physical_device_drm.