Skip to main content

ShaderLibrary

Struct ShaderLibrary 

Source
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

Source

pub fn new() -> Self

An empty library.

Source

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.

Source

pub fn get(&self, id: ShaderId) -> Option<&ShaderModule>

The module id addresses, or None if it was minted by a different library.

Source

pub fn id_of(&self, name: &str) -> Option<ShaderId>

The id registered under name, if any.

Source

pub fn name_of(&self, id: ShaderId) -> Option<&str>

The name id was registered under — used for pipeline labels.

Source

pub fn len(&self) -> usize

How many distinct modules are registered.

Source

pub fn is_empty(&self) -> bool

Whether no module is registered yet.

Trait Implementations§

Source§

impl Debug for ShaderLibrary

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ShaderLibrary

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,