Expand description
Draw decoded frames on the GPU, handing back a texture you present.
The egress half of the zero-copy story, and the fourth role module alongside
capture, encode and
decode. decode keeps a hardware-decoded
frame on the GPU; this draws it there too, converting YUV to RGB in a shader
instead of downloading pixels to convert them on the CPU.
Renderer::render returns a plain wgpu::Texture, which is the whole
integration seam: presenting it to a window, feeding it to egui or bevy, or
copying it back is yours to do, so this module carries no windowing or UI
dependency.
use moq_video::render::{Config, Renderer};
let mut renderer = Renderer::new(device, queue, Config::new())?;
let texture = renderer.render(&frame)?;§Zero-copy
A hardware-decoded frame is imported by aliasing the decoder’s surface as a
texture rather than copying it: CVMetalTextureCache on macOS and iOS for the
PixelBuffer variant of Surface, and Vulkan external
memory on Linux for DMA-BUFs, packed or planar. A planar one is imported a
memory plane at a time, since Vulkan will not take an NV12 or YU12 buffer as
a single image, and the shader was already sampling planes.
Linux callers open the device with request_device, which enables
wgpu::Features::VULKAN_EXTERNAL_MEMORY_DMA_BUF for that import. A CPU
frame is uploaded as planes. Any other GPU surface, and any import that
fails, is an error rather than a download, so a frame’s path is settled
where it is produced: decode or capture with output of the device to
receive only frames that draw here.
§Export
export runs the other way, handing a texture you drew to an encoder as a
Frame: on the GPU when the encoder reads this platform’s
GPU surface, read back to the CPU when it does not. readback is that
read back on its own, for a consumer that wants the picture’s RGBA pixels
with no encoder behind it.
Enabled by the non-default render feature, which is what pulls in wgpu.
Modules§
- export
- Hand textures drawn with
wgputo an encoder, asFrames. - readback
- Read textures drawn with
wgpuback to the CPU, as packed RGBA.
Structs§
Functions§
- output
- The
Outputto decode and capture with for aRendererondevice. - request_
device - Open
adapter’s device asdescriptorasks, plus what this module’s zero-copy paths need where the adapter has it.