@@ -65,7 +65,7 @@ pub struct ShaderCache<ShaderModule, RenderDevice> {
6565 & ValidateShader ,
6666 ) -> Result < ShaderModule , PipelineCacheError > ,
6767 #[ cfg( feature = "shader_format_wesl" ) ]
68- asset_paths : HashMap < wesl:: syntax :: ModulePath , AssetId < Shader > > ,
68+ asset_paths : HashMap < wesl:: ModulePath , AssetId < Shader > > ,
6969 shaders : HashMap < AssetId < Shader > , Shader > ,
7070 import_path_shaders : HashMap < ShaderImport , AssetId < Shader > > ,
7171 waiting_on_import : HashMap < ShaderImport , Vec < AssetId < Shader > > > ,
@@ -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 :: syntax :: 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 ,
@@ -361,7 +361,7 @@ impl<ShaderModule, RenderDevice> ShaderCache<ShaderModule, RenderDevice> {
361361 && let ShaderImport :: AssetPath ( path) = shader. import_path ( )
362362 {
363363 self . asset_paths
364- . insert ( wesl :: syntax :: ModulePath :: from_path ( path) , id) ;
364+ . insert ( wesl_module_path_from_asset_path ( path) , id) ;
365365 }
366366 self . shaders . insert ( id, shader) ;
367367 pipelines_to_queue
@@ -379,14 +379,14 @@ impl<ShaderModule, RenderDevice> ShaderCache<ShaderModule, RenderDevice> {
379379
380380#[ cfg( feature = "shader_format_wesl" ) ]
381381pub struct ShaderResolver < ' a > {
382- asset_paths : & ' a HashMap < wesl:: syntax :: ModulePath , AssetId < Shader > > ,
382+ asset_paths : & ' a HashMap < wesl:: ModulePath , AssetId < Shader > > ,
383383 shaders : & ' a HashMap < AssetId < Shader > , Shader > ,
384384}
385385
386386#[ cfg( feature = "shader_format_wesl" ) ]
387387impl < ' a > ShaderResolver < ' a > {
388388 pub fn new (
389- asset_paths : & ' a HashMap < wesl:: syntax :: ModulePath , AssetId < Shader > > ,
389+ asset_paths : & ' a HashMap < wesl:: ModulePath , AssetId < Shader > > ,
390390 shaders : & ' a HashMap < AssetId < Shader > , Shader > ,
391391 ) -> Self {
392392 Self {
@@ -400,7 +400,7 @@ impl<'a> ShaderResolver<'a> {
400400impl < ' a > wesl:: Resolver for ShaderResolver < ' a > {
401401 fn resolve_source (
402402 & self ,
403- module_path : & wesl:: syntax :: ModulePath ,
403+ module_path : & wesl:: ModulePath ,
404404 ) -> Result < alloc:: borrow:: Cow < ' _ , str > , wesl:: ResolveError > {
405405 let asset_id = self . asset_paths . get ( module_path) . ok_or_else ( || {
406406 wesl:: ResolveError :: ModuleNotFound ( module_path. clone ( ) , "Invalid asset id" . to_string ( ) )
@@ -411,6 +411,27 @@ impl<'a> wesl::Resolver for ShaderResolver<'a> {
411411 }
412412}
413413
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+
414435/// Type of error returned by a `PipelineCache` when the creation of a GPU pipeline object failed.
415436#[ cfg_attr(
416437 not( target_arch = "wasm32" ) ,
0 commit comments