Skip to main content

Module pipeline_cache

Module pipeline_cache 

Source
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§

PipelineCache
Single-owner cache of compiled wgpu::ComputePipelines.
PipelineCacheKey
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§

SharedPipelineCache
Thread-safe shared pipeline cache.