pub struct BindGroupCache { /* private fields */ }Expand description
Cached bind groups, keyed by descriptor hash.
The cache does NOT compute hashes — callers provide a u64 key.
This keeps the cache generic and avoids imposing a hashing strategy.
§Examples
ⓘ
use mabda::bind_group_cache::BindGroupCache;
let mut cache = BindGroupCache::new();
let key = hash_bind_group_descriptor(&layout, &buffers);
let bg = cache.get_or_insert(key, || {
device.create_bind_group(&descriptor)
});Implementations§
Source§impl BindGroupCache
impl BindGroupCache
Sourcepub fn get_or_insert(
&mut self,
key: u64,
create_fn: impl FnOnce() -> BindGroup,
) -> &BindGroup
pub fn get_or_insert( &mut self, key: u64, create_fn: impl FnOnce() -> BindGroup, ) -> &BindGroup
Get a cached bind group, or create one by calling create_fn.
If the key exists, returns the cached bind group without calling
create_fn. The key should encode everything that affects the
bind group: layout, buffer handles, offsets, texture views, samplers.
Sourcepub fn invalidate(&mut self, key: u64) -> bool
pub fn invalidate(&mut self, key: u64) -> bool
Remove a cached bind group (e.g., after buffer reallocation).
Returns true if the bind group was found and removed.
Sourcepub fn invalidate_where(&mut self, predicate: impl Fn(u64) -> bool)
pub fn invalidate_where(&mut self, predicate: impl Fn(u64) -> bool)
Remove all bind groups whose keys match a predicate.
Useful for bulk invalidation when a shared resource (e.g., a buffer generation counter) changes.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for BindGroupCache
impl !RefUnwindSafe for BindGroupCache
impl Send for BindGroupCache
impl Sync for BindGroupCache
impl Unpin for BindGroupCache
impl UnsafeUnpin for BindGroupCache
impl !UnwindSafe for BindGroupCache
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