@@ -3,7 +3,8 @@ use librashader_common::ImageFormat;
3
3
use nom:: bytes:: complete:: { is_not, tag, take_while} ;
4
4
5
5
use librashader_common:: map:: ShortString ;
6
- use nom:: character:: complete:: multispace1;
6
+ use nom:: character:: complete:: { multispace0, multispace1} ;
7
+ use nom:: combinator:: opt;
7
8
use nom:: number:: complete:: float;
8
9
use nom:: sequence:: delimited;
9
10
use nom:: IResult ;
@@ -36,8 +37,16 @@ fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessErro
36
37
let ( input, minimum) = float ( input) ?;
37
38
let ( input, _) = multispace1 ( input) ?;
38
39
let ( input, maximum) = float ( input) ?;
39
- let ( input, _) = multispace1 ( input) ?;
40
- let ( input, step) = float ( input) ?;
40
+
41
+ // Step is actually optional and defaults to 0.02
42
+ // This behaviour can be seen in shaders like
43
+ // crt/crt-slangtest-cubic.slangp
44
+ // which doesn't have a step argument
45
+ // #pragma parameter OUT_GAMMA "Monitor Output Gamma" 2.2 1.8 2.4
46
+
47
+ // https://github.com/libretro/slang-shaders/blob/0e2939787076e4a8a83be89175557fde23abe837/crt/shaders/crt-slangtest/parameters.inc#L1
48
+ let ( input, _) = multispace0 ( input) ?;
49
+ let ( input, step) = opt ( float) ( input) ?;
41
50
Ok ( (
42
51
input,
43
52
ShaderParameter {
@@ -46,7 +55,7 @@ fn parse_parameter_string(input: &str) -> Result<ShaderParameter, PreprocessErro
46
55
initial,
47
56
minimum,
48
57
maximum,
49
- step,
58
+ step : step . unwrap_or ( 0.02 ) ,
50
59
} ,
51
60
) )
52
61
}
@@ -145,4 +154,22 @@ mod test {
145
154
step: 25.0
146
155
} , parse_parameter_string( r#"#pragma parameter HSM_CORE_RES_SAMPLING_MULT_SCANLINE_DIR " Scanline Dir Multiplier" 100 25 1600 25"# ) . unwrap( ) )
147
156
}
157
+
158
+ #[ test]
159
+ fn parses_parameter_pragma_with_no_step ( ) {
160
+ assert_eq ! (
161
+ ShaderParameter {
162
+ id: "OUT_GAMMA" . into( ) ,
163
+ description: "Monitor Output Gamma" . to_string( ) ,
164
+ initial: 2.2 ,
165
+ minimum: 1.8 ,
166
+ maximum: 2.4 ,
167
+ step: 0.02
168
+ } ,
169
+ parse_parameter_string(
170
+ r#"#pragma parameter OUT_GAMMA "Monitor Output Gamma" 2.2 1.8 2.4"#
171
+ )
172
+ . unwrap( )
173
+ )
174
+ }
148
175
}
0 commit comments