pub struct PipelineCache { /* private fields */ }Expand description
The engine’s render-pipeline cache.
Owns nothing but policy plus the compiled pipelines: the wgpu::Device is
passed per call, and the shader modules come from the shared
ShaderLibrary handed to PipelineCache::new.
See the module docs for the variant key, the warm-up queue and the eager-steal rule.
Implementations§
Source§impl PipelineCache
impl PipelineCache
Sourcepub fn new(
shaders: Arc<ShaderLibrary>,
driver_cache: Option<PipelineCache>,
) -> Self
pub fn new( shaders: Arc<ShaderLibrary>, driver_cache: Option<PipelineCache>, ) -> Self
A cache over shaders, optionally seeding every pipeline it builds
from a persisted driver_cache.
driver_cache is None on every backend but Vulkan; see
crate::pipeline_cache for how a persisted blob is validated before
it becomes one.
Sourcepub fn shaders(&self) -> &ShaderLibrary
pub fn shaders(&self) -> &ShaderLibrary
The library this cache resolves ShaderIds against.
Sourcepub fn get_or_create(
&mut self,
device: &Device,
desc: &RenderPipelineDesc,
) -> &RenderPipeline
pub fn get_or_create( &mut self, device: &Device, desc: &RenderPipelineDesc, ) -> &RenderPipeline
The pipeline for desc, compiling it if this is the first request.
A variant queued for the warm-up worker but not yet started is stolen and built inline; one the worker is already building is waited for. Either way the variant is compiled exactly once.
§Panics
If desc.shader was not minted by this cache’s ShaderLibrary. An
id is opaque and library-scoped, so that is a wiring bug, not a runtime
condition.
Sourcepub fn warm_up(&mut self, device: &Device, descs: &[RenderPipelineDesc])
pub fn warm_up(&mut self, device: &Device, descs: &[RenderPipelineDesc])
Queues descs and builds them on a worker thread.
Call it once the surface (and therefore the device) exists, with every variant the app is known to draw. Returns immediately, and the render thread never blocks on the worker — a variant it asks for early is stolen out of the queue instead.
Safe to call repeatedly: a surface reinstall enqueues its variants against the live worker rather than starting a second one, and a call whose variants are all built already starts nothing at all.
If the thread cannot be spawned the queue is drained inline instead, so warm-up degrades to a synchronous build rather than silently not happening.
Sourcepub fn shutdown(&mut self)
pub fn shutdown(&mut self)
Stops warm-up and joins the worker, so no thread holding a clone of the device outlives this cache.
Drop calls this; call it explicitly to order the wait before other
teardown of your own. It is idempotent, and terminal — afterwards
Self::warm_up records its variants without starting a worker, and
they are compiled on first request.
Sourcepub fn compiled_variants(&self) -> u64
pub fn compiled_variants(&self) -> u64
How many pipelines this cache has actually compiled.
Sourcepub fn queued_variants(&self) -> usize
pub fn queued_variants(&self) -> usize
How many warm-up variants are still waiting to be built.