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 its picture in GPU memory (a hardware decoder, WebKit rendering a page) can hand it over as a dmabuf: a file descriptor naming the allocation plus the layout to read it. Importing that as a wgpu::Texture aliases the memory, so nothing is copied.

Import needs VK_KHR_external_memory_fd + VK_EXT_external_memory_dma_buf, which wgpu-hal enables. A tiled or compressed layout, or a linear one whose row pitch the driver would not have chosen, needs VK_EXT_image_drm_format_modifier: crates.io wgpu-hal 29 does not enable it, the repository’s patched copy (vendor/wgpu-hal, see vendor/PATCHES.md) does on Vulkan 1.2 and up.

  • With the extension (explicit_layout_available) the image is created with the producer’s own modifier, plane offset and row pitch, after the driver confirmed it can sample that exact combination.
  • Without it Vulkan can only be told VK_IMAGE_TILING_LINEAR, so a buffer with any other 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: the import goes through Device::as_hal::<vulkan::Api>, so a wgpu that fell back to GLES reports ImportError::NotVulkan and the caller takes the CPU path; and without the modifier extension a LINEAR image’s row pitch is the driver’s, so a disagreeing producer stride would shear the picture and reports ImportError::StrideMismatch.

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

Structs§

Colorimetry
The colour convention a frame’s samples follow.
DmabufImage
A client’s single-plane dma-buf, imported once, that yields a texture to draw each commit from (Self::texture).
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.
WriteFence
A client buffer’s pending writes, as a semaphore the presenting queue’s next submission waits for (wait_for_writes). Keep it until a submission made after it completed; dropping it destroys the semaphore.

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§

explicit_layout_available
Whether device was opened with VK_EXT_image_drm_format_modifier, so an import can state the producer’s exact layout instead of assuming the driver’s linear one.
image_stats
(images alive, images made, nanoseconds spent making them) for the per-commit images of DmabufImage::texture. An image is alive from its creation until wgpu destroys its texture, which it does only after every submission that used it retired, so alive is the GPU’s backlog.
import
Import image as sampleable wgpu textures, aliasing its GPU memory.
import_copy_target
Import the one linear plane of an ABGR8888/XBGR8888 dma-buf as a texture a frame is copied into (COPY_DST).
import_image
Import image, a single plane, so that each commit can draw from it (DmabufImage::texture).
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.
sampleable_modifiers
The DRM modifiers device can sample for a single-plane dma-buf of fourcc: each one the driver lists for the format and confirms (VulkanImporter::check_modifier, the check every import repeats at its real size) can be imported and sampled. Empty when the device is not Vulkan, lacks VK_EXT_image_drm_format_modifier, or has no such format.
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.
wait_for_writes
Make the next submission on queue wait on the GPU for the writes still pending on the single-plane dma-buf plane (the producer’s implicit fence), so a sample of the buffer in it or any later submission reads what the producer wrote. No thread waits: the fence is exported as a sync file and imported as a semaphore the submission waits for.
write_fence_waits
How many times a submission was made to wait on the GPU for a client buffer’s pending writes since the process started: commits whose buffer the producer’s GPU had not finished when it was imported.