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:
atlv 2025-05-18 02:30:38 -04:00 committed by GitHub
parent 2db103708a
commit 45ba5b9f03
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -203,28 +203,25 @@ impl ShaderCache {
shaders: &HashMap<AssetId<Shader>, Shader>,
import: &ShaderImport,
) -> Result<(), PipelineCacheError> {
if !composer.contains_module(&import.module_name()) {
if let Some(shader_handle) = import_path_shaders.get(import) {
if let Some(shader) = shaders.get(shader_handle) {
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
// Early out if we've already imported this module
if composer.contains_module(&import.module_name()) {
return Ok(());
}
// 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(())
}