@@ -203,28 +203,25 @@ impl ShaderCache {
203
203
shaders : & HashMap < AssetId < Shader > , Shader > ,
204
204
import : & ShaderImport ,
205
205
) -> Result < ( ) , PipelineCacheError > {
206
- if !composer. contains_module ( & import. module_name ( ) ) {
207
- if let Some ( shader_handle) = import_path_shaders. get ( import) {
208
- if let Some ( shader) = shaders. get ( shader_handle) {
209
- for import in & shader. imports {
210
- Self :: add_import_to_composer (
211
- composer,
212
- import_path_shaders,
213
- shaders,
214
- import,
215
- ) ?;
216
- }
206
+ // Early out if we've already imported this module
207
+ if composer. contains_module ( & import. module_name ( ) ) {
208
+ return Ok ( ( ) ) ;
209
+ }
217
210
218
- composer. add_composable_module ( shader. into ( ) ) ?;
219
- } else {
220
- Err ( PipelineCacheError :: ShaderImportNotYetAvailable ) ?;
221
- }
222
- } else {
223
- Err ( PipelineCacheError :: ShaderImportNotYetAvailable ) ?;
224
- }
225
- // if we fail to add a module the composer will tell us what is missing
211
+ // Check if the import is available (this handles the recursive import case)
212
+ let shader = import_path_shaders
213
+ . get ( import)
214
+ . and_then ( |handle| shaders. get ( handle) )
215
+ . ok_or ( PipelineCacheError :: ShaderImportNotYetAvailable ) ?;
216
+
217
+ // Recurse down to ensure all import dependencies are met
218
+ for import in & shader. imports {
219
+ Self :: add_import_to_composer ( composer, import_path_shaders, shaders, import) ?;
226
220
}
227
221
222
+ composer. add_composable_module ( shader. into ( ) ) ?;
223
+ // if we fail to add a module the composer will tell us what is missing
224
+
228
225
Ok ( ( ) )
229
226
}
230
227
0 commit comments