1
1
use std:: {
2
2
error:: Error ,
3
3
path:: { Path , PathBuf } ,
4
+ str:: FromStr ,
4
5
} ;
5
6
6
7
use clap:: { error:: ErrorKind , Parser } ;
@@ -14,7 +15,7 @@ use futures::{
14
15
use notify:: { Event , RecommendedWatcher , RecursiveMode , Watcher } ;
15
16
16
17
use spirv_builder:: {
17
- CompileResult , MetadataPrintout , SpirvBuilder , SpirvBuilderError , SpirvMetadata ,
18
+ Capability , CompileResult , MetadataPrintout , SpirvBuilder , SpirvBuilderError , SpirvMetadata ,
18
19
} ;
19
20
20
21
use tracing:: { error, info} ;
@@ -87,6 +88,13 @@ fn spirv_metadata(s: &str) -> Result<SpirvMetadata, clap::Error> {
87
88
}
88
89
}
89
90
91
+ fn spirv_capability ( s : & str ) -> Result < Capability , clap:: Error > {
92
+ match Capability :: from_str ( s) {
93
+ Ok ( capability) => Ok ( capability) ,
94
+ Err ( _) => Err ( clap:: Error :: new ( ErrorKind :: InvalidValue ) ) ,
95
+ }
96
+ }
97
+
90
98
/// Clap application struct.
91
99
#[ derive( Debug , Clone , Parser ) ]
92
100
#[ command( author, version, about, long_about = None ) ]
@@ -102,6 +110,9 @@ struct ShaderBuilder {
102
110
/// Compile shaders in release mode.
103
111
#[ arg( long, default_value = "true" ) ]
104
112
release : bool ,
113
+ /// Enables the provided SPIR-V capability.
114
+ #[ arg( long, value_parser=spirv_capability) ]
115
+ capability : Vec < Capability > ,
105
116
/// Compile one .spv file per entry point.
106
117
#[ arg( long, default_value = "false" ) ]
107
118
multimodule : bool ,
@@ -146,7 +157,7 @@ struct ShaderBuilder {
146
157
impl ShaderBuilder {
147
158
/// Builds a shader with the provided set of options.
148
159
pub fn build_shader ( & self ) -> Result < CompileResult , SpirvBuilderError > {
149
- SpirvBuilder :: new ( & self . path_to_crate , & self . target )
160
+ let mut builder = SpirvBuilder :: new ( & self . path_to_crate , & self . target )
150
161
. deny_warnings ( self . deny_warnings )
151
162
. release ( self . release )
152
163
. multimodule ( self . multimodule )
@@ -158,8 +169,13 @@ impl ShaderBuilder {
158
169
. scalar_block_layout ( self . scalar_block_layout )
159
170
. skip_block_layout ( self . skip_block_layout )
160
171
. preserve_bindings ( self . preserve_bindings )
161
- . print_metadata ( MetadataPrintout :: None )
162
- . build ( )
172
+ . print_metadata ( MetadataPrintout :: None ) ;
173
+
174
+ for capability in & self . capability {
175
+ builder = builder. capability ( * capability) ;
176
+ }
177
+
178
+ builder. build ( )
163
179
}
164
180
}
165
181
0 commit comments