pub struct ShaderCache<ShaderModule, RenderDevice> { /* private fields */ }Expand description
A cache for shaders and shader imports, with asset state-tracking for waiting to load shaders until all imports are resolved.
Note that the RenderDevice generic parameter is a means by which
to avoid a cyclic dependency with bevy_render, while also permitting
alternative rendering implementations. The actual processing of the
shader source into a usable compiled module is left to the renderer.
Implementations§
Source§impl<ShaderModule, RenderDevice> ShaderCache<ShaderModule, RenderDevice>
impl<ShaderModule, RenderDevice> ShaderCache<ShaderModule, RenderDevice>
Sourcepub fn new(
device: RenderDevice,
features: Features,
downlevel: DownlevelFlags,
load_module: fn(&RenderDevice, ShaderCacheSource<'_>, &ValidateShader) -> Result<ShaderModule, ShaderCacheError>,
) -> Self
pub fn new( device: RenderDevice, features: Features, downlevel: DownlevelFlags, load_module: fn(&RenderDevice, ShaderCacheSource<'_>, &ValidateShader) -> Result<ShaderModule, ShaderCacheError>, ) -> Self
Creates a new ShaderCache with the given features and shader
module loading function. load_module is responsible for actually
compiling shader source into a module usable by the render device.
Sourcepub fn get(
&mut self,
pipeline: CachedPipelineId,
id: AssetId<Shader>,
shader_defs: &[ShaderDefVal],
) -> Result<Arc<ShaderModule>, ShaderCacheError>
pub fn get( &mut self, pipeline: CachedPipelineId, id: AssetId<Shader>, shader_defs: &[ShaderDefVal], ) -> Result<Arc<ShaderModule>, ShaderCacheError>
Attempts to retrieve or create a compiled shader module for the given shader id and shader definitions.
The provided pipeline is tracked so it may later be reported “dirty”
when a shader is removed or replaced.
Note that the cache is keyed by id and shader_defs, meaning providing
the same shader_defs in a different order, or with redundancies, will
not result in cache hits, and thus require re-composing the module and
calling load_module again.
Sourcepub fn set_shader(
&mut self,
id: AssetId<Shader>,
shader: Shader,
) -> Vec<CachedPipelineId> ⓘ
pub fn set_shader( &mut self, id: AssetId<Shader>, shader: Shader, ) -> Vec<CachedPipelineId> ⓘ
Inserts and possibly replaces a shader at the given asset id.
Returns a vec of which cached pipelines depended on it (directly or indirectly via a shader import) and thus must be recompiled.
Auto Trait Implementations§
impl<ShaderModule, RenderDevice> Freeze for ShaderCache<ShaderModule, RenderDevice>where
RenderDevice: Freeze,
impl<ShaderModule, RenderDevice> !RefUnwindSafe for ShaderCache<ShaderModule, RenderDevice>
impl<ShaderModule, RenderDevice> Send for ShaderCache<ShaderModule, RenderDevice>
impl<ShaderModule, RenderDevice> Sync for ShaderCache<ShaderModule, RenderDevice>
impl<ShaderModule, RenderDevice> !Unpin for ShaderCache<ShaderModule, RenderDevice>
impl<ShaderModule, RenderDevice> UnsafeUnpin for ShaderCache<ShaderModule, RenderDevice>where
RenderDevice: UnsafeUnpin,
impl<ShaderModule, RenderDevice> !UnwindSafe for ShaderCache<ShaderModule, RenderDevice>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.