pub struct WgpuTexture { /* private fields */ }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
impl WgpuTexture
Sourcepub fn new(texture: Texture) -> Self
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).
Sourcepub fn with_keep_alive(self, keep_alive: KeepAlive) -> Self
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.
Sourcepub fn keep_alive(&self) -> Option<&KeepAlive>
pub fn keep_alive(&self) -> Option<&KeepAlive>
The producer’s keep-alive anchor, when one was attached.
Sourcepub fn into_texture(self) -> Texture
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.