11use futures:: executor:: block_on;
22use ouroboros:: self_referencing;
3- use std:: borrow:: Cow ;
43use std:: error:: Error ;
54use std:: time:: Instant ;
65use wgpu;
6+ use wgpu:: { include_spirv, include_spirv_raw} ;
77use winit:: application:: ApplicationHandler ;
88use winit:: dpi:: LogicalSize ;
99use winit:: event:: { ElementState , MouseButton , WindowEvent } ;
@@ -62,6 +62,8 @@ impl Default for ShaderToyApp {
6262 }
6363}
6464
65+ pub const USE_SPIRV_PASSTHROUGH : bool = true ;
66+
6567impl ShaderToyApp {
6668 async fn init ( & mut self , event_loop : & dyn ActiveEventLoop ) -> Result < ( ) , Box < dyn Error > > {
6769 let window_attributes = WindowAttributes :: default ( )
@@ -91,7 +93,10 @@ impl ShaderToyApp {
9193 } )
9294 . await
9395 . ok_or ( "No adapter found" ) ?;
94- let required_features = wgpu:: Features :: PUSH_CONSTANTS ;
96+ let mut required_features = wgpu:: Features :: PUSH_CONSTANTS ;
97+ if USE_SPIRV_PASSTHROUGH {
98+ required_features |= wgpu:: Features :: SPIRV_SHADER_PASSTHROUGH ;
99+ }
95100 let required_limits = wgpu:: Limits {
96101 max_push_constant_size : 256 ,
97102 ..Default :: default ( )
@@ -107,12 +112,14 @@ impl ShaderToyApp {
107112 None ,
108113 )
109114 . await ?;
110- let shader_bytes = include_bytes ! ( env!( "shadertoys_shaders.spv" ) ) ;
111- let shader_spirv: & [ u32 ] = bytemuck:: cast_slice ( shader_bytes) ;
112- let shader_module = device. create_shader_module ( wgpu:: ShaderModuleDescriptor {
113- label : Some ( "Shader Module" ) ,
114- source : wgpu:: ShaderSource :: SpirV ( Cow :: Borrowed ( shader_spirv) ) ,
115- } ) ;
115+ let shader_module = if USE_SPIRV_PASSTHROUGH {
116+ unsafe {
117+ device
118+ . create_shader_module_spirv ( & include_spirv_raw ! ( env!( "shadertoys_shaders.spv" ) ) )
119+ }
120+ } else {
121+ device. create_shader_module ( include_spirv ! ( env!( "shadertoys_shaders.spv" ) ) )
122+ } ;
116123 let swapchain_format = surface. get_capabilities ( & adapter) . formats [ 0 ] ;
117124 let pipeline_layout = device. create_pipeline_layout ( & wgpu:: PipelineLayoutDescriptor {
118125 label : None ,
0 commit comments