1
1
use futures:: executor:: block_on;
2
2
use ouroboros:: self_referencing;
3
- use std:: borrow:: Cow ;
4
3
use std:: error:: Error ;
5
4
use std:: time:: Instant ;
6
5
use wgpu;
6
+ use wgpu:: { include_spirv, include_spirv_raw} ;
7
7
use winit:: application:: ApplicationHandler ;
8
8
use winit:: dpi:: LogicalSize ;
9
9
use winit:: event:: { ElementState , MouseButton , WindowEvent } ;
@@ -62,6 +62,8 @@ impl Default for ShaderToyApp {
62
62
}
63
63
}
64
64
65
+ pub const USE_SPIRV_PASSTHROUGH : bool = true ;
66
+
65
67
impl ShaderToyApp {
66
68
async fn init ( & mut self , event_loop : & dyn ActiveEventLoop ) -> Result < ( ) , Box < dyn Error > > {
67
69
let window_attributes = WindowAttributes :: default ( )
@@ -91,7 +93,10 @@ impl ShaderToyApp {
91
93
} )
92
94
. await
93
95
. 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
+ }
95
100
let required_limits = wgpu:: Limits {
96
101
max_push_constant_size : 256 ,
97
102
..Default :: default ( )
@@ -107,12 +112,14 @@ impl ShaderToyApp {
107
112
None ,
108
113
)
109
114
. 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
+ } ;
116
123
let swapchain_format = surface. get_capabilities ( & adapter) . formats [ 0 ] ;
117
124
let pipeline_layout = device. create_pipeline_layout ( & wgpu:: PipelineLayoutDescriptor {
118
125
label : None ,
0 commit comments