pub struct PipelineCache { /* private fields */ }Expand description
Cached render and compute pipelines, keyed by descriptor hash.
The cache does NOT compute hashes itself — callers provide a u64 key
derived from their pipeline configuration. This keeps the cache generic
and avoids imposing a specific hashing strategy.
§Example
let key = hash_my_pipeline_config(&config);
let pipeline = cache.get_or_insert_render(key, || {
RenderPipelineBuilder::new(device, shader, "vs_main", "fs_main")
.color_target(format, None)
.build()
.unwrap()
});Implementations§
Source§impl PipelineCache
impl PipelineCache
Sourcepub fn get_or_insert_render(
&mut self,
key: u64,
create_fn: impl FnOnce() -> RenderPipeline,
) -> &RenderPipeline
pub fn get_or_insert_render( &mut self, key: u64, create_fn: impl FnOnce() -> RenderPipeline, ) -> &RenderPipeline
Get a cached render pipeline, or insert one by calling create_fn.
The key should be a hash of the pipeline descriptor (shader source,
vertex layout, blend state, etc.). If the key exists, returns the
cached pipeline without calling create_fn.
Sourcepub fn get_or_insert_compute(
&mut self,
key: u64,
create_fn: impl FnOnce() -> ComputePipeline,
) -> &ComputePipeline
pub fn get_or_insert_compute( &mut self, key: u64, create_fn: impl FnOnce() -> ComputePipeline, ) -> &ComputePipeline
Get a cached compute pipeline, or insert one by calling create_fn.
Sourcepub fn contains_render(&self, key: u64) -> bool
pub fn contains_render(&self, key: u64) -> bool
Check if a render pipeline is cached.
Sourcepub fn contains_compute(&self, key: u64) -> bool
pub fn contains_compute(&self, key: u64) -> bool
Check if a compute pipeline is cached.
Sourcepub fn get_render(&self, key: u64) -> Option<&RenderPipeline>
pub fn get_render(&self, key: u64) -> Option<&RenderPipeline>
Get a cached render pipeline by key.
Sourcepub fn get_compute(&self, key: u64) -> Option<&ComputePipeline>
pub fn get_compute(&self, key: u64) -> Option<&ComputePipeline>
Get a cached compute pipeline by key.
Sourcepub fn invalidate_render(&mut self, key: u64) -> bool
pub fn invalidate_render(&mut self, key: u64) -> bool
Remove a cached render pipeline (e.g., after shader hot-reload).
Sourcepub fn invalidate_compute(&mut self, key: u64) -> bool
pub fn invalidate_compute(&mut self, key: u64) -> bool
Remove a cached compute pipeline.