@@ -105,6 +105,10 @@ struct Args {
105
105
#[ argh( switch) ]
106
106
version : bool ,
107
107
108
+ /// override value, of the form "foo=N,bar=M", repeatable
109
+ #[ argh( option, long = "override" ) ]
110
+ overrides : Vec < Overrides > ,
111
+
108
112
/// the input and output files.
109
113
///
110
114
/// First positional argument is the input file. If not specified, the
@@ -202,12 +206,34 @@ impl FromStr for MslVersionArg {
202
206
}
203
207
}
204
208
209
+ #[ derive( Clone , Debug ) ]
210
+ struct Overrides {
211
+ pairs : Vec < ( String , f64 ) > ,
212
+ }
213
+
214
+ impl FromStr for Overrides {
215
+ type Err = String ;
216
+
217
+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
218
+ let mut pairs = vec ! [ ] ;
219
+ for pair in s. split ( ',' ) {
220
+ let Some ( ( name, value) ) = pair. split_once ( '=' ) else {
221
+ return Err ( format ! ( "value needs a `=`: {pair:?}" ) ) ;
222
+ } ;
223
+ let value = f64:: from_str ( value. trim ( ) ) . map_err ( |err| format ! ( "{err}: {value:?}" ) ) ?;
224
+ pairs. push ( ( name. trim ( ) . to_string ( ) , value) ) ;
225
+ }
226
+ Ok ( Overrides { pairs } )
227
+ }
228
+ }
229
+
205
230
#[ derive( Default ) ]
206
231
struct Parameters < ' a > {
207
232
validation_flags : naga:: valid:: ValidationFlags ,
208
233
bounds_check_policies : naga:: proc:: BoundsCheckPolicies ,
209
234
entry_point : Option < String > ,
210
235
keep_coordinate_space : bool ,
236
+ overrides : naga:: back:: PipelineConstants ,
211
237
spv_in : naga:: front:: spv:: Options ,
212
238
spv_out : naga:: back:: spv:: Options < ' a > ,
213
239
dot : naga:: back:: dot:: Options ,
@@ -301,7 +327,12 @@ fn run() -> Result<(), Box<dyn std::error::Error>> {
301
327
Some ( arg) => arg. 0 ,
302
328
None => params. bounds_check_policies . index ,
303
329
} ;
304
-
330
+ params. overrides = args
331
+ . overrides
332
+ . iter ( )
333
+ . flat_map ( |o| & o. pairs )
334
+ . cloned ( )
335
+ . collect ( ) ;
305
336
params. spv_in = naga:: front:: spv:: Options {
306
337
adjust_coordinate_space : !args. keep_coordinate_space ,
307
338
strict_capabilities : false ,
@@ -670,7 +701,9 @@ fn write_output(
670
701
"Generating hlsl output requires validation to \
671
702
succeed, and it failed in a previous step",
672
703
) ) ?,
673
- & hlsl:: PipelineOptions :: default ( ) ,
704
+ & hlsl:: PipelineOptions {
705
+ constants : params. overrides . clone ( ) ,
706
+ } ,
674
707
)
675
708
. unwrap_pretty ( ) ;
676
709
fs:: write ( output_path, buffer) ?;
0 commit comments