refactor(render): cleanup add_import_to_composer (#19269)
# Objective - Reduce nesting ## Solution - Refactor ## Testing - `bevy run --example=3d_scene web --open`
This commit is contained in:
parent
2db103708a
commit
45ba5b9f03
@ -203,28 +203,25 @@ impl ShaderCache {
|
|||||||
shaders: &HashMap<AssetId<Shader>, Shader>,
|
shaders: &HashMap<AssetId<Shader>, Shader>,
|
||||||
import: &ShaderImport,
|
import: &ShaderImport,
|
||||||
) -> Result<(), PipelineCacheError> {
|
) -> Result<(), PipelineCacheError> {
|
||||||
if !composer.contains_module(&import.module_name()) {
|
// Early out if we've already imported this module
|
||||||
if let Some(shader_handle) = import_path_shaders.get(import) {
|
if composer.contains_module(&import.module_name()) {
|
||||||
if let Some(shader) = shaders.get(shader_handle) {
|
return Ok(());
|
||||||
for import in &shader.imports {
|
|
||||||
Self::add_import_to_composer(
|
|
||||||
composer,
|
|
||||||
import_path_shaders,
|
|
||||||
shaders,
|
|
||||||
import,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
composer.add_composable_module(shader.into())?;
|
|
||||||
} else {
|
|
||||||
Err(PipelineCacheError::ShaderImportNotYetAvailable)?;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(PipelineCacheError::ShaderImportNotYetAvailable)?;
|
|
||||||
}
|
|
||||||
// if we fail to add a module the composer will tell us what is missing
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if the import is available (this handles the recursive import case)
|
||||||
|
let shader = import_path_shaders
|
||||||
|
.get(import)
|
||||||
|
.and_then(|handle| shaders.get(handle))
|
||||||
|
.ok_or(PipelineCacheError::ShaderImportNotYetAvailable)?;
|
||||||
|
|
||||||
|
// Recurse down to ensure all import dependencies are met
|
||||||
|
for import in &shader.imports {
|
||||||
|
Self::add_import_to_composer(composer, import_path_shaders, shaders, import)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
composer.add_composable_module(shader.into())?;
|
||||||
|
// if we fail to add a module the composer will tell us what is missing
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user