private Optional<Type> maybeComputeBooleanVectorType(Type lhsType) { if (lhsType instanceof BasicType) { final int numElements = ((BasicType) lhsType).getNumElements(); if (1 < numElements && numElements <= 4) { return Optional.of(BasicType.makeVectorType(BasicType.BOOL, numElements)); } } return Optional.empty(); }
public SwizzleExprTemplate(BasicType argType, BasicType resultType, boolean isLValue) { assert BasicType.allVectorTypes().contains(argType); assert BasicType.allVectorTypes().contains(resultType) || BasicType.allScalarTypes() .contains(resultType); if (isLValue) { assert resultType.getNumElements() <= argType.getNumElements(); } this.argType = argType; this.resultType = resultType; this.isLValue = isLValue; }
public List<Integer> getIndices(String name) { int startIndex = 0; for (ScopeEntry entry : entries) { BasicType type = (BasicType) entry.getType().getWithoutQualifiers(); if (entry.getVariableDeclInfo().getName().equals(name)) { List<Integer> result = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { result.add(startIndex + i); } return result; } startIndex += type.getNumElements(); } throw new RuntimeException("Should be unreachable."); }
private int getWidth(ScopeEntry entry) { return ((BasicType) entry.getType().getWithoutQualifiers()).getNumElements(); }
@Override public Expr generateExpr(IRandom generator, Expr... args) { assert args.length == getNumArguments(); String[] mapping = chooseVectorComponentNamingScheme(generator); String swizzleIndices = ""; int nextComponent = 0; while (nextComponent < resultType.getNumElements()) { String candidate = mapping[generator.nextInt(argType.getNumElements())]; if (isLValue() && swizzleIndices.contains(candidate)) { continue; } swizzleIndices += candidate; nextComponent++; } return new MemberLookupExpr(args[0], swizzleIndices); }
public boolean canAccept(ScopeEntry entry) { BasicType basicType = (BasicType) entry.getType().getWithoutQualifiers(); if (!(basicType.getElementType().equals(elementType))) { return false; } if (entries.stream() .anyMatch(x -> x.getVariablesDeclaration() == entry.getVariablesDeclaration())) { return false; } return currentWidth() + basicType.getNumElements() <= MAX_WIDTH; }
public Expr makeOpaqueBoolean(boolean value, BasicType type, boolean constContext, final int depth, Fuzzer fuzzer) { assert type.isBoolean(); if (type == BasicType.BOOL) { return makeOpaqueBooleanScalar(value, constContext, depth, fuzzer); } List<Expr> args = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { args.add(makeOpaqueBoolean(value, BasicType.BOOL, constContext, depth, fuzzer)); } return new TypeConstructorExpr(type.toString(), args); }
private static Integer getSize(Type type) { assert isArrayVectorOrMatrix(type); if (type instanceof ArrayType) { return ((ArrayType) type).getArrayInfo().getSize(); } if (BasicType.allVectorTypes().contains(type)) { return ((BasicType) type).getNumElements(); } return ((BasicType) type).getNumColumns(); }
private static Initializer makeInitializer(BasicType baseType, ArrayInfo arrayInfo, List<Number> args) { if (arrayInfo != null) { assert arrayInfo.getSize() * baseType.getNumElements() == args.size(); List<Expr> argExprs = new ArrayList<>(); for (int index = 0; index < arrayInfo.getSize(); index++) { argExprs.add(getBasicTypeLiteralExpr(baseType, args.subList(index * baseType.getNumElements(), (index + 1) * baseType.getNumElements()))); } return new ScalarInitializer(new ArrayConstructorExpr( new ArrayType(baseType.getWithoutQualifiers(), arrayInfo.clone()), argExprs)); } return new ScalarInitializer(getBasicTypeLiteralExpr(baseType, args)); }
@Override public Expr generateExpr(IRandom generator, Expr... args) { assert args.length == getNumArguments(); int index; if (BasicType.allVectorTypes().contains(argType)) { index = generator.nextInt(argType.getNumElements()); } else { assert BasicType.allMatrixTypes().contains(argType); index = generator.nextInt(BasicType.numColumns(argType)); } return new ArrayIndexExpr(args[0], new IntConstantExpr(String.valueOf(index))); }
private static String get(BasicType type, boolean isArray) { String result = "glUniform"; if (type.isMatrix()) { throw new RuntimeException("Not dealing with matrices yet."); } result += type.getNumElements(); if (type.getElementType() == BasicType.FLOAT) { result += "f"; } else if (type.getElementType() == BasicType.INT) { result += "i"; } else if (type.getElementType() == BasicType.UINT) { result += "ui"; } else { assert type.getElementType() == BasicType.BOOL; result += "i"; } if (isArray) { result += "v"; } return result; }
private Expr makeOpaqueZeroOrOneFromInjectionSwitch(boolean isZero, BasicType type) { assert generationParams.getInjectionSwitchIsAvailable(); if (type == BasicType.FLOAT) { if (isZero) { return zeroConstructor(injectionSwitch("x"), type); } return oneConstructor(injectionSwitch("y"), type); } List<Expr> args = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { // We use float for each argument, on the assumption that all the scalar and vector // constructors can take float arguments args.add(makeOpaqueZeroOrOneFromInjectionSwitch(isZero, BasicType.FLOAT)); } return new TypeConstructorExpr(type.toString(), args); }
final int dim = (int) Math.sqrt(((BasicType) exprType).getNumElements()); if (tce.getNumArgs() != dim * dim) { return false;
private Expr makeRegularIntegerValuedLiteral(BasicType type, String integerPart) { assert type.getElementType() != BasicType.BOOL; if (type == BasicType.FLOAT) { return new FloatConstantExpr(integerPart + ".0"); } if (type == BasicType.INT) { return new IntConstantExpr(integerPart); } if (type == BasicType.UINT) { return new UIntConstantExpr(integerPart + "u"); } List<Expr> args = new ArrayList<>(); for (int i = 0; i < type.getNumElements(); i++) { assert type.getElementType() != type; args.add(makeRegularIntegerValuedLiteral(type.getElementType(), integerPart)); } return new TypeConstructorExpr(type.toString(), args); }
for (int i = 0; i < basicType.getNumElements() * arrayLength; i++) { if (basicType.getElementType() == BasicType.FLOAT) { values.add(floatSupplier.get());
= generator.nextInt(type.getNumElements()); for (int i = 0; i < type.getNumElements(); i++) { final boolean decision = generator.nextBoolean(); aElements.add(makeOpaqueBoolean(decision, BasicType.BOOL, constContext, depth, fuzzer)); new TypeConstructorExpr(type.toString(), yElements), new TypeConstructorExpr( BasicType.makeVectorType(BasicType.BOOL, type.getNumElements()) .toString(), aElements)));
return; if (basicType.getNumElements() != tce.getNumArgs()) {