Function wgpu::util::pipeline_cache_key

source ·
pub fn pipeline_cache_key(adapter_info: &AdapterInfo) -> Option<String>
Expand description

A recommended key for storing PipelineCaches for the adapter associated with the given AdapterInfo This key will define a class of adapters for which the same cache might be valid.

If this returns None, the adapter doesn’t support PipelineCache. This may be because the API doesn’t support application managed caches (such as browser WebGPU), or that wgpu hasn’t implemented it for that API yet.

This key could be used as a filename, as seen in the example below.

Examples

let cache_dir: PathBuf = PathBuf::new();
let filename = wgpu::util::pipeline_cache_key(&adapter_info);
if let Some(filename) = filename {
    let cache_file = cache_dir.join(&filename);
    let cache_data = std::fs::read(&cache_file);
    let pipeline_cache: wgpu::PipelineCache = todo!("Use data (if present) to create a pipeline cache");

    let data = pipeline_cache.get_data();
    if let Some(data) = data {
        let temp_file = cache_file.with_extension("temp");
        std::fs::write(&temp_file, &data)?;
        std::fs::rename(&temp_file, &cache_file)?;
    }
}