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.
- Dmabuf
Image - A client’s single-plane dma-buf, imported once, that yields a texture to
draw each commit from (
Self::texture). - 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.
- Write
Fence - 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§
- 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§
- explicit_
layout_ available - Whether
devicewas opened withVK_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 ofDmabufImage::texture. An image is alive from its creation until wgpu destroys its texture, which it does only after every submission that used it retired, soaliveis the GPU’s backlog.- import
- Import
imageas sampleablewgputextures, aliasing its GPU memory. - import_
copy_ target - Import the one linear plane of an
ABGR8888/XBGR8888dma-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,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.
- sampleable_
modifiers - The DRM modifiers
devicecan sample for a single-plane dma-buf offourcc: 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, lacksVK_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. ReturnsNonewhen the backend is not Vulkan or the driver does not exposeVK_EXT_physical_device_drm. - wait_
for_ writes - Make the next submission on
queuewait on the GPU for the writes still pending on the single-plane dma-bufplane(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.