pub struct DiskShaderCache { /* private fields */ }Expand description
Disk-persistent GPU shader cache.
Each entry is stored as two files in cache_dir:
<key>.shd– the raw bytecode blob.<key>.meta– a single-line text file:<source_hash> <backend> <feature_flags> <unix_secs_since_epoch>.
The cache directory is created automatically on first use.
Implementations§
Source§impl DiskShaderCache
impl DiskShaderCache
Sourcepub fn open(cache_dir: impl AsRef<Path>) -> Result<Self, DiskCacheError>
pub fn open(cache_dir: impl AsRef<Path>) -> Result<Self, DiskCacheError>
Open (or create) a disk shader cache rooted at cache_dir.
The directory is created if it does not already exist.
§Errors
Returns a DiskCacheError if the directory cannot be created.
Sourcepub fn get(&mut self, version: &ShaderVersion) -> Option<Vec<u8>>
pub fn get(&mut self, version: &ShaderVersion) -> Option<Vec<u8>>
Look up a shader by its ShaderVersion.
Returns Some(bytecode) if both .shd and .meta files exist and
the metadata matches the requested version. Returns None on any
mismatch or I/O error.
Sourcepub fn put(&mut self, shader: &CompiledShader)
pub fn put(&mut self, shader: &CompiledShader)
Store a compiled shader on disk.
On any I/O error the error is recorded in statistics but is not propagated — the in-memory cache remains the source of truth.
Sourcepub fn invalidate_backend(&mut self, backend: &str)
pub fn invalidate_backend(&mut self, backend: &str)
Invalidate (delete) all entries for a specific backend.
Errors during directory listing or file deletion are silently ignored.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Remove all cached entries from disk.
Errors during directory listing or file deletion are silently ignored.
Sourcepub fn stats(&self) -> &DiskCacheStats
pub fn stats(&self) -> &DiskCacheStats
Returns a snapshot of the accumulated disk-cache statistics.
Auto Trait Implementations§
impl Freeze for DiskShaderCache
impl RefUnwindSafe for DiskShaderCache
impl Send for DiskShaderCache
impl Sync for DiskShaderCache
impl Unpin for DiskShaderCache
impl UnsafeUnpin for DiskShaderCache
impl UnwindSafe for DiskShaderCache
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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