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>
impl<T, V> TexturePool<T, V>
Sourcepub fn new(caps: &TierCaps) -> Self
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.
Sourcepub fn with_max_unused_frames(caps: &TierCaps, max_unused_frames: u64) -> Self
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.
Sourcepub fn key_for(&self, desc: &TextureDesc) -> PoolKey
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.
Sourcepub fn acquire<A>(
&mut self,
allocator: &A,
desc: &TextureDesc,
frame: u64,
) -> PooledTexture<T, V>where
A: TextureAllocator<Texture = T, View = V>,
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.
Sourcepub fn release(&mut self, texture: PooledTexture<T, V>)
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.
Sourcepub fn age(&mut self, frame: u64)
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.
Sourcepub fn max_unused_frames(&self) -> u64
pub fn max_unused_frames(&self) -> u64
The keep-alive window in frames, as configured.