pub struct SamplerCache { /* private fields */ }Expand description
A thread-safe cache of GPU samplers.
This cache ensures that identical sampler configurations share the same GPU sampler object, reducing memory usage and creation overhead.
§Example
ⓘ
use astrelis_render::{SamplerCache, SamplerKey};
let cache = SamplerCache::new();
// Get or create a linear sampler
let sampler = cache.get_or_create(&device, SamplerKey::linear());
// The same sampler is returned for identical keys
let sampler2 = cache.get_or_create(&device, SamplerKey::linear());
// sampler and sampler2 point to the same GPU samplerImplementations§
Source§impl SamplerCache
impl SamplerCache
Sourcepub fn get_or_create(&self, device: &Device, key: SamplerKey) -> Arc<Sampler>
pub fn get_or_create(&self, device: &Device, key: SamplerKey) -> Arc<Sampler>
Get a sampler from the cache or create a new one.
If a sampler with the given key already exists in the cache, it is returned. Otherwise, a new sampler is created and cached.
§Panics
Panics if the internal RwLock is poisoned (another thread panicked while holding the lock).
Sourcepub fn get_or_create_from_descriptor(
&self,
device: &Device,
descriptor: &SamplerDescriptor<'_>,
) -> Arc<Sampler>
pub fn get_or_create_from_descriptor( &self, device: &Device, descriptor: &SamplerDescriptor<'_>, ) -> Arc<Sampler>
Get a sampler from the cache or create one using a descriptor.
This is a convenience method that converts the descriptor to a key.
Sourcepub fn linear_repeat(&self, device: &Device) -> Arc<Sampler>
pub fn linear_repeat(&self, device: &Device) -> Arc<Sampler>
Get a repeating linear sampler.
Sourcepub fn nearest_repeat(&self, device: &Device) -> Arc<Sampler>
pub fn nearest_repeat(&self, device: &Device) -> Arc<Sampler>
Get a repeating nearest sampler.
Sourcepub fn linear_mirror(&self, device: &Device) -> Arc<Sampler>
pub fn linear_mirror(&self, device: &Device) -> Arc<Sampler>
Get a mirrored linear sampler.
Sourcepub fn nearest_mirror(&self, device: &Device) -> Arc<Sampler>
pub fn nearest_mirror(&self, device: &Device) -> Arc<Sampler>
Get a mirrored nearest sampler.
Sourcepub fn from_sampling(
&self,
device: &Device,
sampling: ImageSampling,
) -> Arc<Sampler>
pub fn from_sampling( &self, device: &Device, sampling: ImageSampling, ) -> Arc<Sampler>
Get a sampler for the given sampling mode.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SamplerCache
impl RefUnwindSafe for SamplerCache
impl Send for SamplerCache
impl Sync for SamplerCache
impl Unpin for SamplerCache
impl UnsafeUnpin for SamplerCache
impl UnwindSafe for SamplerCache
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more