@@ -7,7 +7,7 @@ use librashader::reflect::cross::{GlslVersion, HlslShaderModel, MslVersion, Spir
77use librashader:: reflect:: naga:: { Naga , NagaLoweringOptions } ;
88use librashader:: reflect:: semantics:: ShaderSemantics ;
99use librashader:: reflect:: { CompileShader , FromCompilation , ReflectShader , SpirvCompilation } ;
10- use librashader:: runtime:: Size ;
10+ use librashader:: runtime:: { ColorSpace , Size } ;
1111use librashader:: { FastHashMap , ShortString } ;
1212use librashader_runtime:: parameters:: RuntimeParameters ;
1313use librashader_test:: render:: { CommonFrameOptions , RenderTest } ;
@@ -88,11 +88,32 @@ impl From<FrameOptionsArgs> for CommonFrameOptions {
8888 aspect_ratio : value. aspect_ratio . unwrap_or ( 0.0 ) ,
8989 frametime_delta : value. frametime_delta . unwrap_or ( 0 ) ,
9090 frames_per_second : value. frames_per_second . unwrap_or ( 1.0 ) ,
91+ color_space : value. color_space . into ( ) ,
92+ brightness_nits : value. brightness_nits . unwrap_or ( 200.0 ) ,
93+ expand_gamut : value. expand_gamut . unwrap_or ( 0 ) ,
94+ gyroscope : value. gyroscope . map ( vec3_from_args) . unwrap_or ( [ 0.0 ; 3 ] ) ,
95+ accelerometer : value. accelerometer . map ( vec3_from_args) . unwrap_or ( [ 0.0 ; 3 ] ) ,
96+ accelerometer_rest : value
97+ . accelerometer_rest
98+ . map ( vec3_from_args)
99+ . unwrap_or ( [ 0.0 ; 3 ] ) ,
91100 ..Default :: default ( )
92101 }
93102 }
94103}
95104
105+ /// Collapse a `num_args = 3` value list into a fixed `[f32; 3]`.
106+ ///
107+ /// clap guarantees exactly three values are present, so any missing
108+ /// component falls back to 0.
109+ fn vec3_from_args ( values : Vec < f32 > ) -> [ f32 ; 3 ] {
110+ [
111+ values. first ( ) . copied ( ) . unwrap_or ( 0.0 ) ,
112+ values. get ( 1 ) . copied ( ) . unwrap_or ( 0.0 ) ,
113+ values. get ( 2 ) . copied ( ) . unwrap_or ( 0.0 ) ,
114+ ]
115+ }
116+
96117impl From < ShaderFeatureArgs > for ShaderFeatures {
97118 fn from ( value : ShaderFeatureArgs ) -> Self {
98119 let mut features = ShaderFeatures :: NONE ;
@@ -134,6 +155,50 @@ struct FrameOptionsArgs {
134155 /// The time between the previous and current frame. The default is 0.
135156 #[ arg( long) ]
136157 pub frametime_delta : Option < u32 > ,
158+ /// The target color space for HDR shaders. The default is `sdr`.
159+ #[ arg( long, value_enum, default_value_t = ColorSpaceArg :: Sdr ) ]
160+ pub color_space : ColorSpaceArg ,
161+ /// The HDR SDR reference white in nits. The default is 200.
162+ #[ arg( long) ]
163+ pub brightness_nits : Option < f32 > ,
164+ /// The gamut expansion mode for HDR shaders. The default is 0.
165+ #[ arg( long) ]
166+ pub expand_gamut : Option < u32 > ,
167+ /// The three-axis gyroscope reading for shaders that use gyroscope data.
168+ /// The default is 0 0 0.
169+ #[ arg( long, num_args = 3 , value_names = [ "X" , "Y" , "Z" ] ) ]
170+ pub gyroscope : Option < Vec < f32 > > ,
171+ /// The three-axis accelerometer reading for shaders that use accelerometer data.
172+ /// The default is 0 0 0.
173+ #[ arg( long, num_args = 3 , value_names = [ "X" , "Y" , "Z" ] ) ]
174+ pub accelerometer : Option < Vec < f32 > > ,
175+ /// The accelerometer reading at for shaders that use accelerometer data.
176+ /// The default is 0 0 0.
177+ #[ arg( long, num_args = 3 , value_names = [ "X" , "Y" , "Z" ] ) ]
178+ pub accelerometer_rest : Option < Vec < f32 > > ,
179+ }
180+
181+ #[ derive( clap:: ValueEnum , Clone , Copy , Debug ) ]
182+ enum ColorSpaceArg {
183+ #[ clap( name = "sdr" ) ]
184+ Sdr ,
185+ #[ clap( name = "hdr10" ) ]
186+ Hdr10 ,
187+ #[ clap( name = "scrgb" ) ]
188+ ScRgb ,
189+ #[ clap( name = "pq-scrgb" ) ]
190+ PqScRgb ,
191+ }
192+
193+ impl From < ColorSpaceArg > for ColorSpace {
194+ fn from ( value : ColorSpaceArg ) -> Self {
195+ match value {
196+ ColorSpaceArg :: Sdr => ColorSpace :: Sdr ,
197+ ColorSpaceArg :: Hdr10 => ColorSpace :: Hdr10 ,
198+ ColorSpaceArg :: ScRgb => ColorSpace :: ScRgb ,
199+ ColorSpaceArg :: PqScRgb => ColorSpace :: PqScRgb ,
200+ }
201+ }
137202}
138203
139204#[ derive( Subcommand , Debug ) ]
@@ -421,6 +486,14 @@ pub fn main() -> Result<(), anyhow::Error> {
421486 features |= ShaderFeatures :: FRAMETIME_UNIFORMS ;
422487 }
423488
489+ if options. as_ref ( ) . is_some_and ( |args| {
490+ args. gyroscope . is_some ( )
491+ || args. accelerometer . is_some ( )
492+ || args. accelerometer_rest . is_some ( )
493+ } ) {
494+ features |= ShaderFeatures :: SENSOR_UNIFORMS ;
495+ }
496+
424497 let preset = get_shader_preset ( preset, wildcards, features) ?;
425498 let params = parse_params ( params) ?;
426499
@@ -477,6 +550,14 @@ pub fn main() -> Result<(), anyhow::Error> {
477550 features |= ShaderFeatures :: FRAMETIME_UNIFORMS ;
478551 }
479552
553+ if options. as_ref ( ) . is_some_and ( |args| {
554+ args. gyroscope . is_some ( )
555+ || args. accelerometer . is_some ( )
556+ || args. accelerometer_rest . is_some ( )
557+ } ) {
558+ features |= ShaderFeatures :: SENSOR_UNIFORMS ;
559+ }
560+
480561 let dimensions = parse_dimension ( dimensions, left. image_size ( ) ) ?;
481562 let params = parse_params ( params) ?;
482563
0 commit comments