Skip to main content

WgpuTexture

Struct WgpuTexture 

Source
pub struct WgpuTexture { /* private fields */ }
Available on crate feature wgpu only.
Expand description

A native wgpu::Texture that already lives on the consumer’s own wgpu device — the zero-interop passthrough.

Every other crate::GpuResource variant wraps a foreign handle (a D3D11 texture, a Vulkan opaque-fd, a CUDA pointer, …) that the consumer must import onto its wgpu device before it can render. A WgpuTexture is the degenerate case: the producer minted the texture against the same device the consumer renders on, so there is nothing to import — the consumer uses the handle directly. The interop import path recognises this variant and returns the texture verbatim (no driver round-trip, no copy).

Gated on the crate’s wgpu feature for the same reason as CudaSurface: it stores a wgpu-native type, and backend-agnostic code must not pull wgpu in unconditionally.

§Lifetime

wgpu::Texture is itself an internally-refcounted handle — cloning it bumps wgpu’s own refcount and the last clone runs the destructor. The stored wgpu::Texture therefore keeps the GPU allocation alive on its own. The optional keep_alive pins the producer’s content lifetime instead — the same contract as every foreign handle’s keep-alive slot: a producer whose texture is a recyclable pool/ring slot parks the slot lease here so the pool cannot re-issue (and overwrite) the texture while any consumer-side clone of the resource is still sampling it. An interop import passthrough threads it onto the import result it returns, so the standard hold-until-superseded import-lease discipline covers native wgpu producers too. Cloning a WgpuTexture (and the GpuResource around it) is one wgpu refcount bump plus one Arc bump when a keep-alive is attached.

Implementations§

Source§

impl WgpuTexture

Source

pub fn new(texture: Texture) -> Self

Wrap a caller-owned wgpu::Texture that lives on the consumer’s wgpu device. Safe — no raw handle invariant to assert; the wgpu::Texture is a checked, refcounted handle. No producer keep-alive is attached: use Self::with_keep_alive when the texture is a recyclable pool slot (see the # Lifetime note).

Source

pub fn with_keep_alive(self, keep_alive: KeepAlive) -> Self

Attach the producer’s keep-alive anchor (e.g. the RAII lease of the pool/ring slot backing this texture). Held by every clone of the resource and by an interop passthrough’s import result; the producer’s pool may recycle the slot only once the last holder drops.

Source

pub fn texture(&self) -> &Texture

Borrow the wrapped texture.

Source

pub fn keep_alive(&self) -> Option<&KeepAlive>

The producer’s keep-alive anchor, when one was attached.

Source

pub fn into_texture(self) -> Texture

Consume the wrapper, returning the wrapped texture. Drops any attached producer keep-alive — for a pooled producer texture the caller must be done sampling the content (or hold the anchor via another clone) before calling this.

Trait Implementations§

Source§

impl Clone for WgpuTexture

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WgpuTexture

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
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> MaybeSend for T
where T: Send + ?Sized,

Source§

impl<T> MaybeSendSync for T
where T: Send + Sync + ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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, !>

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.
Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,