Skip to main content

MemoryDomain

Enum MemoryDomain 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub fn kind(&self) -> MemoryDomainKind

The payload-free discriminant of this domain.

Source

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.

Source

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.

Source

pub fn as_system_slice(&self) -> Option<&[u8]>

Source

pub fn share(&self) -> MemoryDomain

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.

Source

pub fn make_shareable(&mut self)

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.

Trait Implementations§

Source§

impl Debug for MemoryDomain

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> ElementBound for T
where T: Send,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.