pub struct ShaderLibrary { /* private fields */ }Expand description
A name-keyed, append-only set of compiled WGSL modules.
Build it at start-up, then share it (Arc<ShaderLibrary>) with the
pipeline cache and its warm-up worker. Insertion is idempotent per name:
re-inserting a name that is already present returns the existing id
without recompiling, so a caller that cannot easily prove it only
registers once still pays for one compile.
Implementations§
Source§impl ShaderLibrary
impl ShaderLibrary
Sourcepub fn insert_wgsl(
&mut self,
device: &Device,
name: impl Into<String>,
src: &str,
) -> ShaderId
pub fn insert_wgsl( &mut self, device: &Device, name: impl Into<String>, src: &str, ) -> ShaderId
Compiles src as WGSL and registers it under name, returning its id.
The module is labelled with name. If name is already registered the
existing id is returned and src is not compiled again — the library
is append-only, so a name never changes meaning once it is in.
Compilation errors are not raised here: wgpu reports a malformed module
through the device’s error scope / uncaptured-error handler, and the
resulting pipeline creation fails there. This mirrors frust-render’s
shader-effect path, which records the failure rather than panicking.
Sourcepub fn get(&self, id: ShaderId) -> Option<&ShaderModule>
pub fn get(&self, id: ShaderId) -> Option<&ShaderModule>
The module id addresses, or None if it was minted by a different
library.