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 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 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); }
public static List<BasicType> allNumericTypesExceptNonSquareMatrices() { final List<BasicType> result = allNumericTypes(); result.removeAll(allNonSquareMatrixTypes()); return result; }
public static List<BasicType> allNonMatrixNumericTypes() { final List<BasicType> result = allNumericTypes(); result.removeAll(allMatrixTypes()); return result; }
public static List<BasicType> allNonSquareMatrixTypes() { List<BasicType> result = allMatrixTypes(); result.removeAll(allSquareMatrixTypes()); return result; }
Fuzzer fuzzer) { assert BasicType.allGenTypes().contains(type); final List<Expr> xElements = new ArrayList<>(); final List<Expr> yElements = new ArrayList<>(); = 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)); final Expr something = fuzzedConstructor(fuzzer.fuzzExpr(type.getElementType(), false, true, depth)); Expr index = type.isVector() ? new ArrayIndexExpr( new ParenExpr(expr).clone(), new IntConstantExpr(new Integer(i).toString())) index = applyIdentityFunction(index, type.getElementType(), constContext, depth, fuzzer); expr, new FunctionCallExpr("mix", new TypeConstructorExpr(type.toString(), xElements), new TypeConstructorExpr(type.toString(), yElements), new TypeConstructorExpr( BasicType.makeVectorType(BasicType.BOOL, type.getNumElements()) .toString(), aElements)));
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); }
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; }
@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))); }
if (BasicType.allVectorTypes().contains(structureType.getWithoutQualifiers())) { BasicType vecType = (BasicType) structureType.getWithoutQualifiers(); .makeVectorType(vecType.getElementType(), memberLookupExpr.getMember().length())); final BasicType v = BasicType.makeVectorType(vecType.getElementType(), memberLookupExpr.getMember().length()); types.put(memberLookupExpr, v);
@Override public void visitArrayIndexExpr(ArrayIndexExpr arrayIndexExpr) { super.visitArrayIndexExpr(arrayIndexExpr); Type arrayType = lookupType(arrayIndexExpr.getArray()); if (arrayType == null) { return; } arrayType = arrayType.getWithoutQualifiers(); Type elementType; if (BasicType.allVectorTypes().contains(arrayType)) { elementType = ((BasicType) arrayType).getElementType(); } else if (BasicType.allMatrixTypes().contains(arrayType)) { elementType = ((BasicType) arrayType).getColumnType(); } else { assert arrayType instanceof ArrayType; elementType = ((ArrayType) arrayType).getBaseType(); } types.put(arrayIndexExpr, elementType); }
@Override public Expr getCanonicalConstant() { if (this == FLOAT) { return new FloatConstantExpr("1.0"); } if (this == INT) { return new IntConstantExpr("1"); } if (this == UINT) { return new UIntConstantExpr("1u"); } if (this == BOOL) { return BoolConstantExpr.TRUE; } return new TypeConstructorExpr(toString().toString(), getElementType().getCanonicalConstant()); }
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(); }
public static Expr getBasicTypeLiteralExpr(BasicType baseType, List<Number> args) { List<Expr> argExprs; if (baseType.getElementType() == BasicType.FLOAT) { argExprs = args.stream().map(item -> new FloatConstantExpr(item.toString())) .collect(Collectors.toList()); } else if (baseType.getElementType() == BasicType.UINT) { argExprs = args.stream().map(item -> new UIntConstantExpr(item.toString() + "u")) .collect(Collectors.toList()); } else { argExprs = args.stream().map(item -> new IntConstantExpr(item.toString())) .collect(Collectors.toList()); } if (argExprs.size() == 1) { return argExprs.get(0); } return new TypeConstructorExpr(baseType.toString(), argExprs); }
/** * Yields the basic type that the component we are pulling out should have. * @return The basic type of the component. */ public BasicType getComponentType() { return BasicType.makeVectorType( ((BasicType) vectorVariablesDeclaration.getBaseType().getWithoutQualifiers()) .getElementType(), componentData.getWidth()); }
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; }
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); }
@Override public void visitBasicType(BasicType basicType) { out.append(basicType.toString()); }
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."); }