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>. Ifwgpufell back to GLES there is no Vulkan device to import into, andImportError::NotVulkansays so — the caller takes the CPU path instead of silently rendering nothing. - Row pitch must agree. A
LINEARVkImage’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::StrideMismatchreports it and the caller falls back.
Every failure is a typed error, never a silently blank frame.
Structs§
- Dmabuf
Ref - A dmabuf described well enough to import, borrowing its descriptors.
- Imported
Planes - A dmabuf imported as sampleable textures.
- Imported
Render Target - One compositor-owned scanout dma-buf imported as a writable render target.
- Plane
Ref - One plane of a buffer being imported, borrowed for the call.
- Vulkan
DrmDevice Identity - DRM character-device identities reported by the Vulkan physical device.
Enums§
- Import
Error - 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”.
- Plane
Layout - How the imported planes are laid out, and therefore how to sample them.
Functions§
- import
- Import
imageas sampleablewgputextures, aliasing its GPU memory. - import_
render_ target - Import the one linear plane of a compositor-owned scanout buffer
(
XRGB8888,XBGR2101010orABGR16161616F) as a render attachment ondevice. - 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. ReturnsNonewhen the backend is not Vulkan or the driver does not exposeVK_EXT_physical_device_drm.