pub struct ShaderRegistry {
pub cache_hits: u64,
pub compilations: u64,
/* private fields */
}Expand description
Central registry for shader sources and compiled variants.
Call ShaderRegistry::register to add a ShaderSource, then
ShaderRegistry::get_or_compile to obtain a compiled variant,
which is transparently cached in the internal VariantCache.
Fields§
§cache_hits: u64Number of cache hits since creation.
compilations: u64Number of compilations triggered since creation.
Implementations§
Source§impl ShaderRegistry
impl ShaderRegistry
Sourcepub fn new(cache_capacity: usize) -> Self
pub fn new(cache_capacity: usize) -> Self
Create a new empty registry with the given cache capacity.
Sourcepub fn register(&mut self, source: ShaderSource)
pub fn register(&mut self, source: ShaderSource)
Register a shader source. Overwrites any existing source with the same name and clears cached variants for that name.
Sourcepub fn get_or_compile(
&mut self,
name: &str,
defines: &HashMap<String, String>,
) -> Result<&CompiledVariant, RegistryError>
pub fn get_or_compile( &mut self, name: &str, defines: &HashMap<String, String>, ) -> Result<&CompiledVariant, RegistryError>
Get or compile a variant.
Returns Err when the source name is unknown or when a required
placeholder is not supplied in defines.
Sourcepub fn shader_names(&self) -> Vec<&str>
pub fn shader_names(&self) -> Vec<&str>
Return all registered shader names.
Sourcepub fn cached_count(&self) -> usize
pub fn cached_count(&self) -> usize
Return the number of entries currently in the variant cache.
Sourcepub fn invalidate(&mut self, name: &str)
pub fn invalidate(&mut self, name: &str)
Invalidate a single shader by name (clears its cached variants).
Sourcepub fn invalidate_all(&mut self)
pub fn invalidate_all(&mut self)
Invalidate all cached variants.
Source§impl ShaderRegistry
impl ShaderRegistry
Sourcepub fn compile_variant(
&mut self,
name: &str,
defines: &HashMap<String, String>,
opts: &ShaderCompileOptions,
) -> Result<CompiledVariant, RegistryError>
pub fn compile_variant( &mut self, name: &str, defines: &HashMap<String, String>, opts: &ShaderCompileOptions, ) -> Result<CompiledVariant, RegistryError>
Compile a specific shader variant with the given options.
Unlike get_or_compile this method
always forces a fresh compilation (not served from the cache) and
respects the max_source_bytes limit in opts.
Source§impl ShaderRegistry
impl ShaderRegistry
Sourcepub fn apply_hot_reload(&mut self, tracker: &HotReloadTracker) -> Vec<String>
pub fn apply_hot_reload(&mut self, tracker: &HotReloadTracker) -> Vec<String>
Check a HotReloadTracker and invalidate any stale shader variants.
Returns the list of shader names that were invalidated.
Sourcepub fn registered_count(&self) -> usize
pub fn registered_count(&self) -> usize
Return all shader names registered in this registry.
Sourcepub fn source_bytes(&self, name: &str) -> usize
pub fn source_bytes(&self, name: &str) -> usize
Return the size (in WGSL source bytes) of the named shader, or 0.
Auto Trait Implementations§
impl Freeze for ShaderRegistry
impl RefUnwindSafe for ShaderRegistry
impl Send for ShaderRegistry
impl Sync for ShaderRegistry
impl Unpin for ShaderRegistry
impl UnsafeUnpin for ShaderRegistry
impl UnwindSafe for ShaderRegistry
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
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>
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>
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