pub struct WgslModuleCache { /* private fields */ }Expand description
Memoizes runtime-compiled WGSL modules for one device.
Runtime-assembled shaders (fused filter chains, specialized spatial
passes, user fragment surfaces) are compiled from a fully substituted
source string, so that string is the specialization key: two callers
that produce byte-identical WGSL must share one wgpu::ShaderModule.
One cache belongs to one device. Sharing a cache across devices would hand out modules the other device cannot use, so hosts own a cache next to the device they created it for.
The map is behind a Mutex because this is pure memoization with no
cross-thread protocol to model as a channel: lookups happen during
pipeline setup, and a hit costs one hash of the source.
Implementations§
Source§impl WgslModuleCache
impl WgslModuleCache
Sourcepub fn new() -> WgslModuleCache
pub fn new() -> WgslModuleCache
Creates an empty cache for one device.
Sourcepub fn module(
&self,
device: &Device,
label: Option<&str>,
source: &str,
) -> ShaderModule
pub fn module( &self, device: &Device, label: Option<&str>, source: &str, ) -> ShaderModule
Returns the module compiled from source, compiling it on first use.
§Panics
Panics when a previous caller panicked while holding the cache lock.