@@ -58,7 +58,7 @@ public final class OpaqueExpressionGenerator {
58
58
private final ShadingLanguageVersion shadingLanguageVersion ;
59
59
60
60
public OpaqueExpressionGenerator (IRandom generator , GenerationParams generationParams ,
61
- ShadingLanguageVersion shadingLanguageVersion ) {
61
+ ShadingLanguageVersion shadingLanguageVersion ) {
62
62
this .generator = generator ;
63
63
this .generationParams = generationParams ;
64
64
// TODO: there are many more identities that we can easily play with here, e.g. bitwise and 1
@@ -142,37 +142,31 @@ private Expr makeOpaqueZeroOrOne(boolean isZero, BasicType type, boolean constCo
142
142
return makeRegularIntegerValuedLiteral (type , isZero ? "0" : "1" );
143
143
}
144
144
final int newDepth = depth + 1 ;
145
- Expr result = null ;
146
- while (result == null ) {
145
+ while (true ) {
147
146
final int numTypesOfOne = 2 ;
148
147
switch (generator .nextInt (numTypesOfOne )) {
149
148
case 0 :
150
149
// Make an opaque value recursively and apply an identity function to it
151
- result = applyIdentityFunction (makeOpaqueZeroOrOne (isZero , type , constContext ,
150
+ return applyIdentityFunction (makeOpaqueZeroOrOne (isZero , type , constContext ,
152
151
newDepth , fuzzer ),
153
152
type ,
154
153
constContext ,
155
154
newDepth ,
156
155
fuzzer );
157
- break ;
158
156
case 1 :
159
157
// injectionSwitch.x or injectionSwitch.y
160
- if (constContext ) {
161
- result = null ;
162
- } else {
163
- result = makeOpaqueZeroOrOneFromInjectionSwitch (isZero , type );
158
+ if (constContext || !generationParams .getInjectionSwitchIsAvailable ()) {
159
+ continue ;
164
160
}
165
- break ;
161
+ return makeOpaqueZeroOrOneFromInjectionSwitch ( isZero , type ) ;
166
162
default :
167
163
throw new RuntimeException ();
168
164
}
169
165
}
170
- //noinspection ConstantConditions
171
- assert result != null ;
172
- return result ;
173
166
}
174
167
175
168
private Expr makeOpaqueZeroOrOneFromInjectionSwitch (boolean isZero , BasicType type ) {
169
+ assert generationParams .getInjectionSwitchIsAvailable ();
176
170
if (type == BasicType .FLOAT ) {
177
171
if (isZero ) {
178
172
return zeroConstructor (injectionSwitch ("x" ), type );
@@ -210,29 +204,34 @@ private Expr makeOpaqueBooleanScalar(boolean value, boolean constContext, final
210
204
final int numTypesOfBool = generationParams .getShaderKind () == ShaderKind .FRAGMENT ? 4 : 2 ;
211
205
final Function <Expr , Expr > constructorFunction =
212
206
value ? this ::trueConstructor : this ::falseConstructor ;
213
- switch (generator .nextInt (numTypesOfBool )) {
214
- case 0 :
215
- // Make an opaque boolean value recursively and apply an identity function to it
216
- return recursivelyMakeOpaqueBooleanScalar (value , constContext , fuzzer , newDepth );
217
- case 1 : {
218
- return makeOpaqueBooleanScalarFromExpr (value ,
207
+ while (true ) {
208
+ switch (generator .nextInt (numTypesOfBool )) {
209
+ case 0 :
210
+ // Make an opaque boolean value recursively and apply an identity function to it
211
+ return recursivelyMakeOpaqueBooleanScalar (value , constContext , fuzzer , newDepth );
212
+ case 1 : {
213
+ if (!generationParams .getInjectionSwitchIsAvailable ()) {
214
+ continue ;
215
+ }
216
+ return makeOpaqueBooleanScalarFromExpr (value ,
219
217
new BinaryExpr (injectionSwitch ("x" ), injectionSwitch ("y" ),
220
- value ? BinOp .LT : BinOp .GT ));
221
- }
222
- case 2 : {
223
- // gl_FragCoord.x [op] 0
224
- assert generationParams .getShaderKind () == ShaderKind .FRAGMENT ;
225
- return makeOpaqueBooleanScalarFromExpr (value ,
218
+ value ? BinOp .LT : BinOp .GT ));
219
+ }
220
+ case 2 : {
221
+ // gl_FragCoord.x [op] 0
222
+ assert generationParams .getShaderKind () == ShaderKind .FRAGMENT ;
223
+ return makeOpaqueBooleanScalarFromExpr (value ,
226
224
compareWithGlFragCoord (value , constContext , fuzzer , newDepth , "x" ));
227
- }
228
- case 3 : {
229
- // gl_FragCoord.y [op] 0
230
- assert generationParams .getShaderKind () == ShaderKind .FRAGMENT ;
231
- return makeOpaqueBooleanScalarFromExpr (value ,
225
+ }
226
+ case 3 : {
227
+ // gl_FragCoord.y [op] 0
228
+ assert generationParams .getShaderKind () == ShaderKind .FRAGMENT ;
229
+ return makeOpaqueBooleanScalarFromExpr (value ,
232
230
compareWithGlFragCoord (value , constContext , fuzzer , newDepth , "y" ));
231
+ }
232
+ default :
233
+ throw new RuntimeException ();
233
234
}
234
- default :
235
- throw new RuntimeException ();
236
235
}
237
236
}
238
237
@@ -282,6 +281,7 @@ public Expr makeDeadCondition(Fuzzer fuzzer) {
282
281
}
283
282
284
283
private Expr injectionSwitch (String dimension ) {
284
+ assert generationParams .getInjectionSwitchIsAvailable ();
285
285
return new MemberLookupExpr (new VariableIdentifierExpr (Constants .INJECTION_SWITCH ), dimension );
286
286
}
287
287
0 commit comments