Skip to main content

Module pipeline_cache

Module pipeline_cache 

Source
Expand description

Framing + validation for a persisted wgpu::PipelineCache blob.

A wgpu::PipelineCache lets a driver reuse the machine code it compiled for a device’s render pipelines across process launches, cutting warm-start shader/pipeline compilation to near zero. wgpu only implements it on Vulkan (any Vulkan adapter — Android, Linux, Windows-on-Vulkan); Metal/DX12 drivers manage their own caches, so this whole path is silently inert there (the feature is absent → no cache is ever created, and crate::pipeline::PipelineCache is simply built with None).

The shell owns file I/O and hands the framework an opaque Vec<u8> blob (no serde/file dependency lives here). Before that blob is ever fed to the unsafe wgpu::Device::create_pipeline_cache, it is wrapped in a small self-describing header — a magic tag plus the adapter fingerprint the data was produced on — checked here (unframe). A mismatch (wrong magic, different adapter/driver, truncated blob) is treated as “no cache” and the caller starts from an empty cache instead of handing the driver bytes from a foreign device. This is belt-and-braces on top of wgpu’s own create_pipeline_cache(fallback: true), which already falls back to an empty cache for mismatched data rather than misbehaving.

This is the only copy of the framing: frust-render used to carry an identical one (kept in lockstep by a drift-guard test) and now re-exports this module instead, so the on-disk layout has exactly one definition. A blob persisted by any earlier frust build still validates here unchanged — bump this module’s MAGIC if the layout ever does change, so an old blob is rejected rather than misparsed.

Functions§

adapter_cache_key
A compact identity string for the adapter a cache blob was produced on.
frame
Wraps a raw PipelineCache::get_data() payload in the validated header unframe checks, tagging it with the adapter it was produced on.
unframe
Validates a framed blob against adapter_key and returns the inner payload, or None if the blob is not a well-formed frame for this adapter.