@@ -210,7 +210,7 @@ impl<ShaderModule, RenderDevice> ShaderCache<ShaderModule, RenderDevice> {
210210 if let ShaderImport :: AssetPath ( path) = shader. import_path ( ) {
211211 let shader_resolver =
212212 ShaderResolver :: new ( & self . asset_paths , & self . shaders ) ;
213- let module_path = wesl :: ModulePath :: from_path ( path) ;
213+ let module_path = wesl_module_path_from_asset_path ( path) ;
214214 let mut compiler_options = wesl:: CompileOptions {
215215 imports : true ,
216216 condcomp : true ,
@@ -360,24 +360,8 @@ impl<ShaderModule, RenderDevice> ShaderCache<ShaderModule, RenderDevice> {
360360 if let Source :: Wesl ( _) = shader. source
361361 && let ShaderImport :: AssetPath ( path) = shader. import_path ( )
362362 {
363- use bevy_asset:: { io:: AssetSourceId , AssetPath } ;
364- use std:: path:: PathBuf ;
365-
366- let asset_path = AssetPath :: from ( path) ;
367- let module_path = if let AssetSourceId :: Name ( source) = asset_path. source ( ) {
368- let mut comp = vec ! [ "bevy_asset" . to_string( ) ] ;
369- let mut path = PathBuf :: new ( ) ;
370- path. push ( source. as_ref ( ) ) ;
371- path. push ( asset_path. path ( ) ) ;
372- comp. extend ( wesl:: ModulePath :: from_path ( path) . components ) ;
373- wesl:: ModulePath {
374- origin : wesl:: syntax:: PathOrigin :: Package ,
375- components : comp,
376- }
377- } else {
378- wesl:: ModulePath :: from_path ( asset_path. path ( ) )
379- } ;
380- self . asset_paths . insert ( module_path, id) ;
363+ self . asset_paths
364+ . insert ( wesl_module_path_from_asset_path ( path) , id) ;
381365 }
382366 self . shaders . insert ( id, shader) ;
383367 pipelines_to_queue
@@ -427,6 +411,27 @@ impl<'a> wesl::Resolver for ShaderResolver<'a> {
427411 }
428412}
429413
414+ #[ cfg( feature = "shader_format_wesl" ) ]
415+ fn wesl_module_path_from_asset_path ( path : & String ) -> wesl:: ModulePath {
416+ use bevy_asset:: { io:: AssetSourceId , AssetPath } ;
417+ use std:: path:: PathBuf ;
418+
419+ let asset_path = AssetPath :: from ( path) ;
420+ if let AssetSourceId :: Name ( source) = asset_path. source ( ) {
421+ let mut comp = vec ! [ "bevy_asset" . to_string( ) ] ;
422+ let mut path = PathBuf :: new ( ) ;
423+ path. push ( source. as_ref ( ) ) ;
424+ path. push ( asset_path. path ( ) ) ;
425+ comp. extend ( wesl:: ModulePath :: from_path ( path) . components ) ;
426+ wesl:: ModulePath {
427+ origin : wesl:: syntax:: PathOrigin :: Package ,
428+ components : comp,
429+ }
430+ } else {
431+ wesl:: ModulePath :: from_path ( asset_path. path ( ) )
432+ }
433+ }
434+
430435/// Type of error returned by a `PipelineCache` when the creation of a GPU pipeline object failed.
431436#[ cfg_attr(
432437 not( target_arch = "wasm32" ) ,
0 commit comments