#[non_exhaustive]pub enum MemoryDomain {
System(SystemSlice),
SystemView(SystemView),
DmaBuf(OwnedDmaBuf),
VulkanTexture(OwnedVulkanTexture),
WebGPUBuffer(OwnedWebGPUBuffer),
Cuda(OwnedCudaBuffer),
D3D11Texture(OwnedD3D11Texture),
CvPixelBuffer(OwnedCvPixelBuffer),
WebGPUExternalTexture(OwnedWebGPUExternalTexture),
WgpuTexture(OwnedWgpuTexture),
WgpuBuffer(OwnedWgpuBuffer),
}Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
System(SystemSlice)
SystemView(SystemView)
Shared-CPU strided buffer: reference-counted bytes plus a TensorView
describing how to read them (M180). A layout-preserving transform (flip,
transpose, crop) hands the frame downstream by composing strides on the
same Arc allocation, so zero bytes are copied. The system-memory
analog of the per-plane stride metadata the GPU domains (eg
OwnedCudaBuffer) already carry. A consumer that needs contiguous
bytes calls SystemView::materialize; a stride-aware consumer reads
the view directly.
DmaBuf(OwnedDmaBuf)
VulkanTexture(OwnedVulkanTexture)
WebGPUBuffer(OwnedWebGPUBuffer)
Cuda(OwnedCudaBuffer)
NVIDIA CUDA device memory. Carries raw device pointers (the decoded
frame stays on the GPU), so a downstream GPU consumer can use it with
no device->host copy. The backing allocation is owned elsewhere (eg an
ffmpeg CUDA-hwframe AVFrame); see OwnedCudaBuffer.
D3D11Texture(OwnedD3D11Texture)
Direct3D 11 texture (Windows GPU memory). The decoded frame stays in a
ID3D11Texture2D so a DXGI / D3D11 consumer (a swapchain present sink)
uses it without a GPU->CPU copy. The texture is owned elsewhere (eg a
Media Foundation IMFDXGIBuffer from a DXVA decoder); see
OwnedD3D11Texture. The Windows analog of MemoryDomain::Cuda.
CvPixelBuffer(OwnedCvPixelBuffer)
A decoded picture left in a CoreVideo CVPixelBuffer (macOS / iOS). The
frame stays in the decoder’s (ideally IOSurface-backed) pixel buffer, so
a VideoToolbox encoder or a Metal consumer uses it without the CPU NV12
pack. The buffer is owned elsewhere (the producing element retains it
behind a CvPixelBufferKeepAlive); see OwnedCvPixelBuffer. The
macOS analog of MemoryDomain::D3D11Texture.
WebGPUExternalTexture(OwnedWebGPUExternalTexture)
A decoded picture left as a browser VideoFrame, to be imported into
WebGPU as a GPUExternalTexture and sampled on the GPU (browser/wasm),
so a WebCodecs-decoded frame never round-trips to CPU. The frame is
owned elsewhere (a web_sys::VideoFrame); see
OwnedWebGPUExternalTexture. The browser analog of
MemoryDomain::D3D11Texture.
WgpuTexture(OwnedWgpuTexture)
A picture rendered into a native wgpu GPU texture (desktop Vulkan / Metal
/ D3D12). The render-side analog of the decode-side CUDA / D3D11 domains:
a GPU element (eg the Vello analytics overlay) draws straight into a
wgpu::Texture and forwards the frame with no GPU->CPU copy, so a GPU
sink presents it directly. g2g-core never links wgpu, so the texture is
owned by a WgpuKeepAlive the producing element boxes; a consumer that
links wgpu recovers it via WgpuKeepAlive::as_any. See
OwnedWgpuTexture.
WgpuBuffer(OwnedWgpuBuffer)
A GPU-resident tensor (or other linear data) in a native wgpu storage
buffer (M215). The buffer analog of WgpuTexture: a
GPU element (eg WgpuPreprocess in GPU-output mode) leaves a compute
shader’s output in a wgpu::Buffer rather than reading it back to the
CPU, so a downstream GPU consumer reads it with no GPU->CPU copy. Owned by
a WgpuBufferKeepAlive (g2g-core never links wgpu); a consumer recovers
it via WgpuBufferKeepAlive::as_any. See OwnedWgpuBuffer.
Implementations§
Source§impl MemoryDomain
impl MemoryDomain
Sourcepub fn kind(&self) -> MemoryDomainKind
pub fn kind(&self) -> MemoryDomainKind
The payload-free discriminant of this domain.
Sourcepub fn require_system_slice(
&self,
category: &'static str,
) -> Result<&[u8], G2gError>
pub fn require_system_slice( &self, category: &'static str, ) -> Result<&[u8], G2gError>
The CPU-readable bytes when the payload lives in system memory, else
None (a device-domain handle that would need a download first).
The frame’s bytes for an element that reads host memory, or a loud
failure naming the domain that turned up instead. A bare
UnsupportedDomain says only that some element refused some frame, which
leaves the reader no way to tell a missing download from a wrong element;
category is the element’s own name, so the line says who refused what.
Needs alloc, which is what the logging it does needs.
Sourcepub fn require_system_bytes(
&self,
category: &'static str,
) -> Result<Cow<'_, [u8]>, G2gError>
pub fn require_system_bytes( &self, category: &'static str, ) -> Result<Cow<'_, [u8]>, G2gError>
As require_system_slice, but a shared
SystemView is accepted too: it is materialized into a dense buffer
(the one copy a strided chain pays), an owned System slice is borrowed.
pub fn as_system_slice(&self) -> Option<&[u8]>
Produce a second handle to this frame’s memory for a fan-out branch
(M213, M250). A zero-copy reference-count bump for every domain: the
GPU domains and the shared-CPU SystemView are handle-shared; owned-CPU
System bytes are too, provided make_shareable
has run first (the tee does this once before fanning out). Without that
pre-share, System falls back to a deep copy (nothing to refcount yet).
Read-only fan-out: branches must treat the shared memory as immutable. A
branch that needs to mutate copies first (as the per-frame metadata does
copy-on-write, and SystemSlice::as_mut_slice does for shared bytes), so
the shares never alias a mutation.
Prepare this frame’s memory to be fanned out zero-copy (M250): convert
owned-CPU System bytes into a refcounted shareable handle
once, so the subsequent per-branch share calls are
refcount bumps rather than deep copies. The other domains are already
handle-shared, so this is a no-op for them. Called once by the tee before
it broadcasts.