Skip to main content

TexturePool

Struct TexturePool 

Source
pub struct TexturePool<T = Texture, V = TextureView> { /* private fields */ }
Expand description

Recycles the intermediate textures a frame renders into, keyed by quantized configuration and aged by frame clock.

Generic over the texture (T) and view (V) types for the same reason Texture is: the pool’s own behavior is exercised on a host with plain stand-in values. The engine always uses the default TexturePool<wgpu::Texture, wgpu::TextureView>.

Implementations§

Source§

impl<T, V> TexturePool<T, V>

Source

pub fn new(caps: &TierCaps) -> Self

An empty pool configured from an adapter’s capabilities: quantized extents are capped at TierCaps::max_texture_dimension_2d and wgpu::TextureUsages::TRANSIENT_ATTACHMENT is applied only where TierCaps::transient_saves_memory says it buys something.

Source

pub fn with_max_unused_frames(caps: &TierCaps, max_unused_frames: u64) -> Self

Self::new with an explicit keep-alive window, for a host that knows its own memory budget is tighter (or its resize storms longer) than the DEFAULT_MAX_UNUSED_FRAMES default.

Source

pub fn key_for(&self, desc: &TextureDesc) -> PoolKey

The PoolKey desc resolves to: quantized extent, effective usage, format and sample count.

Public because a caller sizing a cache or asserting that two requests share a texture should ask the pool rather than re-deriving the quantization rule.

Source

pub fn acquire<A>( &mut self, allocator: &A, desc: &TextureDesc, frame: u64, ) -> PooledTexture<T, V>
where A: TextureAllocator<Texture = T, View = V>,

Hands out a texture for desc, reusing a parked entry of the same configuration when there is one and allocating otherwise.

frame is the caller’s monotonically increasing frame counter; it is stamped on the entry and is what Self::age measures disuse against. The returned texture is at least desc’s extent and usually larger — see PooledTexture::requested_size.

Source

pub fn release(&mut self, texture: PooledTexture<T, V>)

Parks texture for reuse under the key it was acquired with.

Its PooledTexture::last_used_frame stamp is left as the acquiring frame, so the keep-alive window is measured from when the entry was last needed, not from when the holder happened to give it back.

Source

pub fn age(&mut self, frame: u64)

Advances the pool to frame and drops every parked entry unused for more than the keep-alive window.

Call once per frame, including frames that acquired nothing — those are the frames entries age on. Entries still checked out are untouched: the pool does not hold them.

Source

pub fn stats(&self) -> PoolStats

The pool’s counters right now.

Source

pub fn max_unused_frames(&self) -> u64

The keep-alive window in frames, as configured.

Trait Implementations§

Source§

impl<T: Debug, V: Debug> Debug for TexturePool<T, V>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, V> Freeze for TexturePool<T, V>

§

impl<T, V> RefUnwindSafe for TexturePool<T, V>

§

impl<T, V> Send for TexturePool<T, V>

§

impl<T, V> Sync for TexturePool<T, V>

§

impl<T, V> Unpin for TexturePool<T, V>

§

impl<T, V> UnsafeUnpin for TexturePool<T, V>

§

impl<T, V> UnwindSafe for TexturePool<T, V>

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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,