Expand description
Compute-pipeline cache keyed by shader hash.
Compiling a WGSL shader module + creating a wgpu::ComputePipeline can take
several milliseconds on the first call. When many kernels share the same
shader source (or when the same kernel is constructed multiple times), this
overhead accumulates rapidly.
PipelineCache stores compiled pipelines in a HashMap keyed by a
PipelineCacheKey that encodes:
- an FNV-1a 64-bit hash of the WGSL source text,
- the shader entry-point name, and
- an opaque layout tag supplied by the caller (e.g.
"r-r-w"for a pipeline with two read-only and one read-write storage buffer).
§Thread safety
PipelineCache itself is not Sync; callers that need shared mutable
access across threads should use SharedPipelineCache — a type alias for
Arc<Mutex<PipelineCache>> — obtained from new_shared_pipeline_cache.
§Device-lost recovery
After a GPU device is lost and recreated, all previously compiled pipelines
are stale (they belong to the old wgpu::Device). Call PipelineCache::clear
(or SharedPipelineCache via its Mutex) before constructing new pipelines
against the fresh device.
Structs§
- Pipeline
Cache - Single-owner cache of compiled
wgpu::ComputePipelines. - Pipeline
Cache Key - Unique key identifying a compiled compute pipeline.
Functions§
- fnv1a_
64 - FNV-1a 64-bit hash of an arbitrary byte slice.
- new_
shared_ pipeline_ cache - Allocate a new
SharedPipelineCache.
Type Aliases§
- Shared
Pipeline Cache - Thread-safe shared pipeline cache.