Id Builder::makeVoidType()
{
Instruction* type;
- if (groupedTypes[OpTypeVoid].size() == 0) {
+ if (groupedTypes[OpTypeVoid].size() == 0)
+ {
type = new Instruction(getUniqueId(), NoType, OpTypeVoid);
groupedTypes[OpTypeVoid].push_back(type);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
Id Builder::makeBoolType()
{
Instruction* type;
- if (groupedTypes[OpTypeBool].size() == 0) {
+ if (groupedTypes[OpTypeBool].size() == 0)
+ {
type = new Instruction(getUniqueId(), NoType, OpTypeBool);
groupedTypes[OpTypeBool].push_back(type);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
Id Builder::makeSamplerType()
{
Instruction* type;
- if (groupedTypes[OpTypeSampler].size() == 0) {
+ if (groupedTypes[OpTypeSampler].size() == 0)
+ {
type = new Instruction(getUniqueId(), NoType, OpTypeSampler);
groupedTypes[OpTypeSampler].push_back(type);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypePointer].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypePointer].size(); ++t)
+ {
type = groupedTypes[OpTypePointer][t];
if (type->getImmediateOperand(0) == (unsigned)storageClass &&
type->getIdOperand(1) == pointee)
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeInt].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeInt].size(); ++t)
+ {
type = groupedTypes[OpTypeInt][t];
if (type->getImmediateOperand(0) == (unsigned)width &&
type->getImmediateOperand(1) == (hasSign ? 1u : 0u))
module.mapInstruction(type);
// deal with capabilities
- switch (width) {
+ switch (width)
+ {
case 16:
addCapability(CapabilityInt16);
break;
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeFloat].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeFloat].size(); ++t)
+ {
type = groupedTypes[OpTypeFloat][t];
if (type->getImmediateOperand(0) == (unsigned)width)
return type->getResultId();
module.mapInstruction(type);
// deal with capabilities
- switch (width) {
+ switch (width)
+ {
case 16:
addCapability(CapabilityFloat16);
break;
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeStruct].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeStruct].size(); ++t)
+ {
type = groupedTypes[OpTypeStruct][t];
if (type->getNumOperands() != 2)
continue;
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeVector].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeVector].size(); ++t)
+ {
type = groupedTypes[OpTypeVector][t];
if (type->getIdOperand(0) == component && type->getImmediateOperand(1) == (unsigned)size)
return type->getResultId();
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeMatrix].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeMatrix].size(); ++t)
+ {
type = groupedTypes[OpTypeMatrix][t];
if (type->getIdOperand(0) == column && type->getImmediateOperand(1) == (unsigned)cols)
return type->getResultId();
Id Builder::makeArrayType(Id element, Id sizeId, int stride)
{
Instruction* type;
- if (stride == 0) {
+ if (stride == 0)
+ {
// try to find existing type
- for (int t = 0; t < (int)groupedTypes[OpTypeArray].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeArray].size(); ++t)
+ {
type = groupedTypes[OpTypeArray][t];
if (type->getIdOperand(0) == element && type->getIdOperand(1) == sizeId)
return type->getResultId();
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeFunction].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeFunction].size(); ++t)
+ {
type = groupedTypes[OpTypeFunction][t];
if (type->getIdOperand(0) != returnType ||
(int)paramTypes.size() != type->getNumOperands() - 1)
continue;
bool mismatch = false;
- for (int p = 0; p < (int)paramTypes.size(); ++p) {
- if (paramTypes[p] != type->getIdOperand(p + 1)) {
+ for (int p = 0; p < (int)paramTypes.size(); ++p)
+ {
+ if (paramTypes[p] != type->getIdOperand(p + 1))
+ {
mismatch = true;
break;
}
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeImage].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeImage].size(); ++t)
+ {
type = groupedTypes[OpTypeImage][t];
if (type->getIdOperand(0) == sampledType &&
type->getImmediateOperand(1) == (unsigned int)dim &&
module.mapInstruction(type);
// deal with capabilities
- switch (dim) {
+ switch (dim)
+ {
case DimBuffer:
if (sampled)
addCapability(CapabilitySampledBuffer);
addCapability(CapabilityImage1D);
break;
case DimCube:
- if (arrayed) {
+ if (arrayed)
+ {
if (sampled)
addCapability(CapabilitySampledCubeArray);
else
break;
}
- if (ms) {
+ if (ms)
+ {
if (arrayed)
addCapability(CapabilityImageMSArray);
if (!sampled)
{
// try to find it
Instruction* type;
- for (int t = 0; t < (int)groupedTypes[OpTypeSampledImage].size(); ++t) {
+ for (int t = 0; t < (int)groupedTypes[OpTypeSampledImage].size(); ++t)
+ {
type = groupedTypes[OpTypeSampledImage][t];
if (type->getIdOperand(0) == imageType)
return type->getResultId();
Instruction* instr = module.getInstruction(typeId);
Op typeClass = instr->getOpCode();
- switch (typeClass) {
+ switch (typeClass)
+ {
case OpTypeVoid:
case OpTypeBool:
case OpTypeInt:
{
Instruction* instr = module.getInstruction(typeId);
- switch (instr->getOpCode()) {
+ switch (instr->getOpCode())
+ {
case OpTypeBool:
case OpTypeInt:
case OpTypeFloat:
case OpTypeVector:
case OpTypeMatrix:
return instr->getImmediateOperand(1);
- case OpTypeArray: {
+ case OpTypeArray:
+ {
Id lengthId = instr->getImmediateOperand(1);
return module.getInstruction(lengthId)->getImmediateOperand(0);
}
Instruction* instr = module.getInstruction(typeId);
Op typeClass = instr->getOpCode();
- switch (typeClass) {
+ switch (typeClass)
+ {
case OpTypeVoid:
case OpTypeBool:
case OpTypeInt:
Instruction* instr = module.getInstruction(typeId);
Op typeClass = instr->getOpCode();
- switch (typeClass) {
+ switch (typeClass)
+ {
case OpTypeVector:
case OpTypeMatrix:
case OpTypeArray:
Id Builder::findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned value) const
{
Instruction* constant;
- for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i) {
+ for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i)
+ {
constant = groupedConstants[typeClass][i];
if (constant->getOpCode() == opcode && constant->getTypeId() == typeId &&
constant->getImmediateOperand(0) == value)
Id Builder::findScalarConstant(Op typeClass, Op opcode, Id typeId, unsigned v1, unsigned v2) const
{
Instruction* constant;
- for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i) {
+ for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i)
+ {
constant = groupedConstants[typeClass][i];
if (constant->getOpCode() == opcode && constant->getTypeId() == typeId &&
constant->getImmediateOperand(0) == v1 && constant->getImmediateOperand(1) == v2)
// the value consumed will be a constant, so includes specialization.
bool Builder::isConstantOpCode(Op opcode) const
{
- switch (opcode) {
+ switch (opcode)
+ {
case OpUndef:
case OpConstantTrue:
case OpConstantFalse:
// See if we already made it. Applies only to regular constants, because specialization constants
// must remain distinct for the purpose of applying a SpecId decoration.
- if (!specConstant) {
+ if (!specConstant)
+ {
Id existing = 0;
- for (int i = 0; i < (int)groupedConstants[OpTypeBool].size(); ++i) {
+ for (int i = 0; i < (int)groupedConstants[OpTypeBool].size(); ++i)
+ {
constant = groupedConstants[OpTypeBool][i];
if (constant->getTypeId() == typeId && constant->getOpCode() == opcode)
existing = constant->getResultId();
// See if we already made it. Applies only to regular constants, because specialization constants
// must remain distinct for the purpose of applying a SpecId decoration.
- if (!specConstant) {
+ if (!specConstant)
+ {
Id existing = findScalarConstant(OpTypeInt, opcode, typeId, value);
if (existing)
return existing;
// See if we already made it. Applies only to regular constants, because specialization constants
// must remain distinct for the purpose of applying a SpecId decoration.
- if (!specConstant) {
+ if (!specConstant)
+ {
Id existing = findScalarConstant(OpTypeFloat, opcode, typeId, value);
if (existing)
return existing;
// See if we already made it. Applies only to regular constants, because specialization constants
// must remain distinct for the purpose of applying a SpecId decoration.
- if (!specConstant) {
+ if (!specConstant)
+ {
Id existing = findScalarConstant(OpTypeFloat, opcode, typeId, op1, op2);
if (existing)
return existing;
{
Instruction* constant = 0;
bool found = false;
- for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i) {
+ for (int i = 0; i < (int)groupedConstants[typeClass].size(); ++i)
+ {
constant = groupedConstants[typeClass][i];
// same shape?
// same contents?
bool mismatch = false;
- for (int op = 0; op < constant->getNumOperands(); ++op) {
- if (constant->getIdOperand(op) != comps[op]) {
+ for (int op = 0; op < constant->getNumOperands(); ++op)
+ {
+ if (constant->getIdOperand(op) != comps[op])
+ {
mismatch = true;
break;
}
}
- if (!mismatch) {
+ if (!mismatch)
+ {
found = true;
break;
}
assert(typeId);
Op typeClass = getTypeClass(typeId);
- switch (typeClass) {
+ switch (typeClass)
+ {
case OpTypeVector:
case OpTypeArray:
case OpTypeStruct:
return makeFloatConstant(0.0);
}
- if (!specConstant) {
+ if (!specConstant)
+ {
Id existing = findCompositeConstant(typeClass, members);
if (existing)
return existing;
setPrecision(firstParamId + p, precisions[p]);
// CFG
- if (entry) {
+ if (entry)
+ {
*entry = new Block(getUniqueId(), *function);
function->addBlock(*entry);
setBuildPoint(*entry);
// Comments in header
void Builder::makeReturn(bool implicit, Id retVal)
{
- if (retVal) {
+ if (retVal)
+ {
Instruction* inst = new Instruction(NoResult, NoType, OpReturnValue);
inst->addIdOperand(retVal);
buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
assert(block);
// If our function did not contain a return, add a return void now.
- if (!block->isTerminated()) {
+ if (!block->isTerminated())
+ {
if (function.getReturnType() == makeVoidType())
makeReturn(true);
- else {
+ else
+ {
makeReturn(true, createUndefined(function.getReturnType()));
}
}
Instruction* inst = new Instruction(getUniqueId(), pointerType, OpVariable);
inst->addImmediateOperand(storageClass);
- switch (storageClass) {
+ switch (storageClass)
+ {
case StorageClassFunction:
// Validation rules require the declaration in the entry block
buildPoint->getParent().addLocalVariable(std::unique_ptr<Instruction>(inst));
spv::Id typeId = getTypeId(base);
assert(isPointerType(typeId) && offsets.size() > 0);
typeId = getContainedTypeId(typeId);
- for (int i = 0; i < (int)offsets.size(); ++i) {
- if (isStructType(typeId)) {
+ for (int i = 0; i < (int)offsets.size(); ++i)
+ {
+ if (isStructType(typeId))
+ {
assert(isConstantScalar(offsets[i]));
typeId = getContainedTypeId(typeId, getConstantScalar(offsets[i]));
} else
numArgs; // track which operand, if it exists, is the mask of optional arguments
++numArgs; // speculatively make room for the mask operand
ImageOperandsMask mask = ImageOperandsMaskNone; // the mask operand
- if (parameters.bias) {
+ if (parameters.bias)
+ {
mask = (ImageOperandsMask)(mask | ImageOperandsBiasMask);
texArgs[numArgs++] = parameters.bias;
}
- if (parameters.lod) {
+ if (parameters.lod)
+ {
mask = (ImageOperandsMask)(mask | ImageOperandsLodMask);
texArgs[numArgs++] = parameters.lod;
explicitLod = true;
- } else if (parameters.gradX) {
+ } else if (parameters.gradX)
+ {
mask = (ImageOperandsMask)(mask | ImageOperandsGradMask);
texArgs[numArgs++] = parameters.gradX;
texArgs[numArgs++] = parameters.gradY;
explicitLod = true;
- } else if (noImplicitLod && !fetch && !gather) {
+ } else if (noImplicitLod && !fetch && !gather)
+ {
// have to explicitly use lod of 0 if not allowed to have them be implicit, and
// we would otherwise be about to issue an implicit instruction
mask = (ImageOperandsMask)(mask | ImageOperandsLodMask);
texArgs[numArgs++] = makeFloatConstant(0.0);
explicitLod = true;
}
- if (parameters.offset) {
+ if (parameters.offset)
+ {
if (isConstant(parameters.offset))
mask = (ImageOperandsMask)(mask | ImageOperandsConstOffsetMask);
else
mask = (ImageOperandsMask)(mask | ImageOperandsOffsetMask);
texArgs[numArgs++] = parameters.offset;
}
- if (parameters.offsets) {
+ if (parameters.offsets)
+ {
mask = (ImageOperandsMask)(mask | ImageOperandsConstOffsetsMask);
texArgs[numArgs++] = parameters.offsets;
}
- if (parameters.sample) {
+ if (parameters.sample)
+ {
mask = (ImageOperandsMask)(mask | ImageOperandsSampleMask);
texArgs[numArgs++] = parameters.sample;
}
- if (parameters.lodClamp) {
+ if (parameters.lodClamp)
+ {
// capability if this bit is used
addCapability(CapabilityMinLod);
// Set up the instruction
//
Op opCode = OpNop; // All paths below need to set this
- if (fetch) {
+ if (fetch)
+ {
if (sparse)
opCode = OpImageSparseFetch;
else
opCode = OpImageFetch;
- } else if (gather) {
+ } else if (gather)
+ {
if (parameters.Dref)
if (sparse)
opCode = OpImageSparseDrefGather;
opCode = OpImageSparseGather;
else
opCode = OpImageGather;
- } else if (explicitLod) {
- if (parameters.Dref) {
+ } else if (explicitLod)
+ {
+ if (parameters.Dref)
+ {
if (proj)
if (sparse)
opCode = OpImageSparseSampleProjDrefExplicitLod;
opCode = OpImageSparseSampleDrefExplicitLod;
else
opCode = OpImageSampleDrefExplicitLod;
- } else {
+ } else
+ {
if (proj)
if (sparse)
opCode = OpImageSparseSampleProjExplicitLod;
else
opCode = OpImageSampleExplicitLod;
}
- } else {
- if (parameters.Dref) {
+ } else
+ {
+ if (parameters.Dref)
+ {
if (proj)
if (sparse)
opCode = OpImageSparseSampleProjDrefImplicitLod;
opCode = OpImageSparseSampleDrefImplicitLod;
else
opCode = OpImageSampleDrefImplicitLod;
- } else {
+ } else
+ {
if (proj)
if (sparse)
opCode = OpImageSparseSampleProjImplicitLod;
// This happens when a legacy shadow*() call is made, which
// gets a vec4 back instead of a float.
Id smearedType = resultType;
- if (!isScalarType(resultType)) {
- switch (opCode) {
+ if (!isScalarType(resultType))
+ {
+ switch (opCode)
+ {
case OpImageSampleDrefImplicitLod:
case OpImageSampleDrefExplicitLod:
case OpImageSampleProjDrefImplicitLod:
Id typeId0 = 0;
Id typeId1 = 0;
- if (sparse) {
+ if (sparse)
+ {
typeId0 = resultType;
typeId1 = getDerefTypeId(parameters.texelOut);
resultType = makeStructResultType(typeId0, typeId1);
Id resultId = textureInst->getResultId();
- if (sparse) {
+ if (sparse)
+ {
// set capability
addCapability(CapabilitySparseResidency);
createStore(createCompositeExtract(resultId, typeId1, 1), parameters.texelOut);
resultId = createCompositeExtract(resultId, typeId0, 0);
setPrecision(resultId, precision);
- } else {
+ } else
+ {
// When a smear is needed, do it, as per what was computed
// above when resultType was changed to a scalar type.
if (resultType != smearedType)
// Figure out the result type
Id resultType = 0;
- switch (opCode) {
+ switch (opCode)
+ {
case OpImageQuerySize:
- case OpImageQuerySizeLod: {
+ case OpImageQuerySizeLod:
+ {
int numComponents = 0;
- switch (getTypeDimensionality(getImageType(parameters.sampler))) {
+ switch (getTypeDimensionality(getImageType(parameters.sampler)))
+ {
case Dim1D:
case DimBuffer:
numComponents = 1;
// Scalars and Vectors
- if (isScalarType(valueType) || isVectorType(valueType)) {
+ if (isScalarType(valueType) || isVectorType(valueType))
+ {
assert(valueType == getTypeId(value2));
// These just need a single comparison, just have
// to figure out what it is.
Op op;
- switch (getMostBasicTypeClass(valueType)) {
+ switch (getMostBasicTypeClass(valueType))
+ {
case OpTypeFloat:
op = equal ? OpFOrdEqual : OpFOrdNotEqual;
break;
break;
}
- if (isScalarType(valueType)) {
+ if (isScalarType(valueType))
+ {
// scalar
resultId = createBinOp(op, boolType, value1, value2);
- } else {
+ } else
+ {
// vector
resultId = createBinOp(op, makeVectorType(boolType, numConstituents), value1, value2);
setPrecision(resultId, precision);
assert(isAggregateType(valueType) || isMatrixType(valueType));
// Compare each pair of constituents
- for (int constituent = 0; constituent < numConstituents; ++constituent) {
+ for (int constituent = 0; constituent < numConstituents; ++constituent)
+ {
std::vector<unsigned> indexes(1, constituent);
Id constituentType1 = getContainedTypeId(getTypeId(value1), constituent);
Id constituentType2 = getContainedTypeId(getTypeId(value2), constituent);
Id scalarTypeId = getScalarTypeId(resultTypeId);
std::vector<Id> constituents; // accumulate the arguments for OpCompositeConstruct
- for (unsigned int i = 0; i < sources.size(); ++i) {
+ for (unsigned int i = 0; i < sources.size(); ++i)
+ {
assert(!isAggregate(sources[i]));
unsigned int sourceSize = getNumComponents(sources[i]);
unsigned int sourcesToUse = sourceSize;
if (sourcesToUse + targetComponent > numTargetComponents)
sourcesToUse = numTargetComponents - targetComponent;
- for (unsigned int s = 0; s < sourcesToUse; ++s) {
+ for (unsigned int s = 0; s < sourcesToUse; ++s)
+ {
Id arg = sources[i];
- if (sourceSize > 1) {
+ if (sourceSize > 1)
+ {
std::vector<unsigned> swiz;
swiz.push_back(s);
arg = createRvalueSwizzle(precision, scalarTypeId, arg, swiz);
Id ids[maxMatrixSize][maxMatrixSize];
Id one = makeFloatConstant(1.0);
Id zero = makeFloatConstant(0.0);
- for (int col = 0; col < 4; ++col) {
- for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col)
+ {
+ for (int row = 0; row < 4; ++row)
+ {
if (col == row)
ids[col][row] = one;
else
}
// modify components as dictated by the arguments
- if (sources.size() == 1 && isScalar(sources[0])) {
+ if (sources.size() == 1 && isScalar(sources[0]))
+ {
// a single scalar; resets the diagonals
for (int col = 0; col < 4; ++col)
ids[col][col] = sources[0];
- } else if (isMatrix(sources[0])) {
+ } else if (isMatrix(sources[0]))
+ {
// constructing from another matrix; copy over the parts that exist in both the argument and
// constructee
Id matrix = sources[0];
int minCols = std::min(numCols, getNumColumns(matrix));
int minRows = std::min(numRows, getNumRows(matrix));
- for (int col = 0; col < minCols; ++col) {
+ for (int col = 0; col < minCols; ++col)
+ {
std::vector<unsigned> indexes;
indexes.push_back(col);
- for (int row = 0; row < minRows; ++row) {
+ for (int row = 0; row < minRows; ++row)
+ {
indexes.push_back(row);
ids[col][row] = createCompositeExtract(matrix, componentTypeId, indexes);
indexes.pop_back();
setPrecision(ids[col][row], precision);
}
}
- } else {
+ } else
+ {
// fill in the matrix in column-major order with whatever argument components are available
int row = 0;
int col = 0;
- for (int arg = 0; arg < (int)sources.size(); ++arg) {
+ for (int arg = 0; arg < (int)sources.size(); ++arg)
+ {
Id argComp = sources[arg];
- for (int comp = 0; comp < getNumComponents(sources[arg]); ++comp) {
- if (getNumComponents(sources[arg]) > 1) {
+ for (int comp = 0; comp < getNumComponents(sources[arg]); ++comp)
+ {
+ if (getNumComponents(sources[arg]) > 1)
+ {
argComp = createCompositeExtract(sources[arg], componentTypeId, comp);
setPrecision(argComp, precision);
}
ids[col][row++] = argComp;
- if (row == numRows) {
+ if (row == numRows)
+ {
row = 0;
col++;
}
// make the column vectors
Id columnTypeId = getContainedTypeId(resultTypeId);
std::vector<Id> matrixColumns;
- for (int col = 0; col < numCols; ++col) {
+ for (int col = 0; col < numCols; ++col)
+ {
std::vector<Id> vectorComponents;
for (int row = 0; row < numRows; ++row)
vectorComponents.push_back(ids[col][row]);
auto defaultOrMerge = (defaultSegment >= 0) ? segmentBlocks[defaultSegment] : mergeBlock;
switchInst->addIdOperand(defaultOrMerge->getId());
defaultOrMerge->addPredecessor(buildPoint);
- for (int i = 0; i < (int)caseValues.size(); ++i) {
+ for (int i = 0; i < (int)caseValues.size(); ++i)
+ {
switchInst->addImmediateOperand(caseValues[i]);
switchInst->addIdOperand(segmentBlocks[valueIndexToSegment[i]]->getId());
segmentBlocks[valueIndexToSegment[i]]->addPredecessor(buildPoint);
void Builder::nextSwitchSegment(std::vector<Block*>& segmentBlock, int nextSegment)
{
int lastSegment = nextSegment - 1;
- if (lastSegment >= 0) {
+ if (lastSegment >= 0)
+ {
// Close out previous segment by jumping, if necessary, to next segment
if (!buildPoint->isTerminated())
createBranch(segmentBlock[nextSegment]);
accessChain.preSwizzleBaseType = preSwizzleBaseType;
// if needed, propagate the swizzle for the current access chain
- if (accessChain.swizzle.size()) {
+ if (accessChain.swizzle.size())
+ {
std::vector<unsigned> oldSwizzle = accessChain.swizzle;
accessChain.swizzle.resize(0);
- for (unsigned int i = 0; i < swizzle.size(); ++i) {
+ for (unsigned int i = 0; i < swizzle.size(); ++i)
+ {
accessChain.swizzle.push_back(oldSwizzle[swizzle[i]]);
}
} else
// If swizzle still exists, it is out-of-order or not full, we must load the target vector,
// extract and insert elements to perform writeMask and/or swizzle.
Id source = NoResult;
- if (accessChain.swizzle.size()) {
+ if (accessChain.swizzle.size())
+ {
Id tempBaseId = createLoad(base);
source =
createLvalueSwizzle(getTypeId(tempBaseId), tempBaseId, rvalue, accessChain.swizzle);
}
// dynamic component selection
- if (accessChain.component != NoResult) {
+ if (accessChain.component != NoResult)
+ {
Id tempBaseId = (source == NoResult) ? createLoad(base) : source;
source = createVectorInsertDynamic(tempBaseId, getTypeId(tempBaseId), rvalue,
accessChain.component);
{
Id id;
- if (accessChain.isRValue) {
+ if (accessChain.isRValue)
+ {
// transfer access chain, but keep it static, so we can stay in registers
transferAccessChainSwizzle(false);
- if (accessChain.indexChain.size() > 0) {
+ if (accessChain.indexChain.size() > 0)
+ {
Id swizzleBase = accessChain.preSwizzleBaseType != NoType
? accessChain.preSwizzleBaseType
: resultType;
// if all the accesses are constants, we can use OpCompositeExtract
std::vector<unsigned> indexes;
bool constant = true;
- for (int i = 0; i < (int)accessChain.indexChain.size(); ++i) {
+ for (int i = 0; i < (int)accessChain.indexChain.size(); ++i)
+ {
if (isConstantScalar(accessChain.indexChain[i]))
indexes.push_back(getConstantScalar(accessChain.indexChain[i]));
- else {
+ else
+ {
constant = false;
break;
}
if (constant)
id = createCompositeExtract(accessChain.base, swizzleBase, indexes);
- else {
+ else
+ {
// make a new function variable for this r-value
Id lValue =
createVariable(StorageClassFunction, getTypeId(accessChain.base), "indexable");
setPrecision(id, precision);
} else
id = accessChain.base; // no precision, it was set when this was defined
- } else {
+ } else
+ {
transferAccessChainSwizzle(true);
// load through the access chain
id = createLoad(collapseAccessChain());
// Do remaining swizzling
// First, static swizzling
- if (accessChain.swizzle.size()) {
+ if (accessChain.swizzle.size())
+ {
// static swizzle
Id swizzledType = getScalarTypeId(getTypeId(id));
if (accessChain.swizzle.size() > 1)
type = getContainedTypeId(type);
// dereference each index
- for (auto it = accessChain.indexChain.cbegin(); it != accessChain.indexChain.cend(); ++it) {
+ for (auto it = accessChain.indexChain.cbegin(); it != accessChain.indexChain.cend(); ++it)
+ {
if (isStructType(type))
type = getContainedTypeId(type, getConstantScalar(*it));
else
out.push_back(0);
// Capabilities
- for (auto it = capabilities.cbegin(); it != capabilities.cend(); ++it) {
+ for (auto it = capabilities.cbegin(); it != capabilities.cend(); ++it)
+ {
Instruction capInst(0, 0, OpCapability);
capInst.addImmediateOperand(*it);
capInst.dump(out);
dumpInstructions(out, executionModes);
// Debug instructions
- if (source != SourceLanguageUnknown) {
+ if (source != SourceLanguageUnknown)
+ {
Instruction sourceInst(0, 0, OpSource);
sourceInst.addImmediateOperand(source);
sourceInst.addImmediateOperand(sourceVersion);
sourceInst.dump(out);
}
- for (int e = 0; e < (int)extensions.size(); ++e) {
+ for (int e = 0; e < (int)extensions.size(); ++e)
+ {
Instruction extInst(0, 0, OpSourceExtension);
extInst.addStringOperand(extensions[e]);
extInst.dump(out);
{
assert(accessChain.isRValue == false);
- if (accessChain.indexChain.size() > 0) {
- if (accessChain.instr == 0) {
+ if (accessChain.indexChain.size() > 0)
+ {
+ if (accessChain.instr == 0)
+ {
StorageClass storageClass =
(StorageClass)module.getStorageClass(getTypeId(accessChain.base));
accessChain.instr =
return;
// if components are out of order, it is a swizzle
- for (unsigned int i = 0; i < accessChain.swizzle.size(); ++i) {
+ for (unsigned int i = 0; i < accessChain.swizzle.size(); ++i)
+ {
if (i != accessChain.swizzle[i])
return;
}
if (isBoolType(getContainedTypeId(accessChain.preSwizzleBaseType)))
return;
- if (accessChain.swizzle.size() == 1) {
+ if (accessChain.swizzle.size() == 1)
+ {
// handle static component
accessChain.indexChain.push_back(makeUintConstant(accessChain.swizzle.front()));
accessChain.swizzle.clear();
// component, so don't bother even looking at accessChain.component
accessChain.preSwizzleBaseType = NoType;
accessChain.component = NoResult;
- } else if (dynamic && accessChain.component != NoResult) {
+ } else if (dynamic && accessChain.component != NoResult)
+ {
// handle dynamic component
accessChain.indexChain.push_back(accessChain.component);
accessChain.preSwizzleBaseType = NoType;
void Builder::dumpInstructions(std::vector<unsigned int>& out,
const std::vector<std::unique_ptr<Instruction> >& instructions) const
{
- for (int i = 0; i < (int)instructions.size(); ++i) {
+ for (int i = 0; i < (int)instructions.size(); ++i)
+ {
instructions[i]->dump(out);
}
}
{
static std::unordered_set<const char*> issued;
- if (issued.find(tbd) == issued.end()) {
+ if (issued.find(tbd) == issued.end())
+ {
printf("TBD functionality: %s\n", tbd);
issued.insert(tbd);
}