MCPcopy Create free account
hub / github.com/KhronosGroup/glslang / createCompositeCompare

Method createCompositeCompare

SPIRV/SpvBuilder.cpp:4057–4123  ·  view source on GitHub ↗

External comments in header. Operates recursively to visit the composite's hierarchy.

Source from the content-addressed store, hash-verified

4055// External comments in header.
4056// Operates recursively to visit the composite's hierarchy.
4057Id Builder::createCompositeCompare(Decoration precision, Id value1, Id value2, bool equal)
4058{
4059 Id boolType = makeBoolType();
4060 Id valueType = getTypeId(value1);
4061
4062 Id resultId = NoResult;
4063
4064 int numConstituents = getNumTypeConstituents(valueType);
4065
4066 // Scalars and Vectors
4067
4068 if (isScalarType(valueType) || isVectorType(valueType)) {
4069 assert(valueType == getTypeId(value2));
4070 // These just need a single comparison, just have
4071 // to figure out what it is.
4072 Op op;
4073 switch (getMostBasicTypeClass(valueType)) {
4074 case Op::OpTypeFloat:
4075 op = equal ? Op::OpFOrdEqual : Op::OpFUnordNotEqual;
4076 break;
4077 case Op::OpTypeInt:
4078 default:
4079 op = equal ? Op::OpIEqual : Op::OpINotEqual;
4080 break;
4081 case Op::OpTypeBool:
4082 op = equal ? Op::OpLogicalEqual : Op::OpLogicalNotEqual;
4083 precision = NoPrecision;
4084 break;
4085 }
4086
4087 if (isScalarType(valueType)) {
4088 // scalar
4089 resultId = createBinOp(op, boolType, value1, value2);
4090 } else {
4091 // vector
4092 resultId = createBinOp(op, makeVectorType(boolType, numConstituents), value1, value2);
4093 setPrecision(resultId, precision);
4094 // reduce vector compares...
4095 resultId = createUnaryOp(equal ? Op::OpAll : Op::OpAny, boolType, resultId);
4096 }
4097
4098 return setPrecision(resultId, precision);
4099 }
4100
4101 // Only structs, arrays, and matrices should be left.
4102 // They share in common the reduction operation across their constituents.
4103 assert(isAggregateType(valueType) || isMatrixType(valueType));
4104
4105 // Compare each pair of constituents
4106 for (int constituent = 0; constituent < numConstituents; ++constituent) {
4107 std::vector<unsigned> indexes(1, constituent);
4108 Id constituentType1 = getContainedTypeId(getTypeId(value1), constituent);
4109 Id constituentType2 = getContainedTypeId(getTypeId(value2), constituent);
4110 Id constituent1 = createCompositeExtract(value1, constituentType1, indexes);
4111 Id constituent2 = createCompositeExtract(value2, constituentType2, indexes);
4112
4113 Id subResultId = createCompositeCompare(precision, constituent1, constituent2, equal);
4114

Callers 1

createBinaryOperationMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected