/// Update specialized shaders and remove any related specialized
/// pipelines and assets.
Update specialized shaders and remove any related specialized
pipelines and assets.
Update specialized shaders and remove any related specialized pipelines and assets .
pub fn update_shader(
        &mut self,
        shader: &Handle<Shader>,
        pipelines: &mut Assets<PipelineDescriptor>,
        shaders: &mut Assets<Shader>,
        render_resource_context: &dyn RenderResourceContext,
    ) -> Result<(), ShaderError> {
        if let Some(specialized_shaders) = self.specialized_shaders.get_mut(shader) {
            for specialized_shader in specialized_shaders {
                // Recompile specialized shader. If it fails, we bail immediately.
                let shader_def_vec = specialized_shader
                    .specialization
                    .shader_defs
                    .iter()
                    .cloned()
                    .collect::<Vec<String>>();
                let new_handle =
                    shaders.add(render_resource_context.get_specialized_shader(
                        shaders.get(shader).unwrap(),
                        Some(&shader_def_vec),
                    )?);
                // Replace handle and remove old from assets.
                let old_handle = std::mem::replace(&mut specialized_shader.shader, new_handle);
                shaders.remove(&old_handle);
                // Find source pipelines that use the old specialized
                // shader, and remove from tracking.
                if let Some(source_pipelines) =
                    self.specialized_shader_pipelines.remove(&old_handle)
                {
                    // Remove all specialized pipelines from tracking
                    // and asset storage. They will be rebuilt on next
                    // draw.
                    for source_pipeline in source_pipelines {
                        if let Some(specialized_pipelines) =
                            self.specialized_pipelines.remove(&source_pipeline)
                        {
                            for p in specialized_pipelines {
                                pipelines.remove(p.pipeline);
                            }
                        }
                    }
                }
            }
        }
        Ok(())
    }
pub fn update_shader ( & mut self , shader : & Handle < Shader > , pipelines : & mut Assets < PipelineDescriptor > , shaders : & mut Assets < Shader > , render_resource_context : & dyn RenderResourceContext , ) -> Result < ( ) , ShaderError > { if let Some ( specialized_shaders ) = self . specialized_shaders . get_mut ( shader ) { for specialized_shader in specialized_shaders { // Recompile specialized shader. If it fails, we bail immediately. let shader_def_vec = specialized_shader . specialization . shader_defs . iter ( ) . cloned ( ) . collect :: < Vec < String > > ( ) ; let new_handle = shaders . add ( render_resource_context . get_specialized_shader ( shaders . get ( shader ) . unwrap ( ) , Some ( & shader_def_vec ) , ) ? ) ; // Replace handle and remove old from assets. let old_handle = std :: mem :: replace ( & mut specialized_shader . shader , new_handle ) ; shaders . remove ( & old_handle ) ; // Find source pipelines that use the old specialized // shader, and remove from tracking. if let Some ( source_pipelines ) = self . specialized_shader_pipelines . remove ( & old_handle ) { // Remove all specialized pipelines from tracking // and asset storage. They will be rebuilt on next // draw. for source_pipeline in source_pipelines { if let Some ( specialized_pipelines ) = self . specialized_pipelines . remove ( & source_pipeline ) { for p in specialized_pipelines { pipelines . remove ( p . pipeline ) ; } } } } } } Ok ( ( ) ) }
Update specialized shaders and remove any related specialized
pipelines and assets.
Update specialized shaders and remove any related specialized pipelines and assets .
&mut self
shader
&Handle<Shader>
pipelines
&mut Assets<PipelineDescriptor>
shaders
&mut Assets<Shader>
render_resource_context
&dyn RenderResourceContext