SPV: Reduce spurious type generation by removing intermediate types in the middle of access chains.

This generally simplifies access chain generation, with far fewer  type conversions.
It is particularly important to future SPIR-V changes where there is less aggregate
type uniqueness due to carrying different layout information with the type.
This commit is contained in:
John Kessenich 2015-09-13 14:46:30 -06:00
parent c9a808319a
commit fa668dad99
8 changed files with 144 additions and 137 deletions

View File

@ -530,12 +530,12 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
// evaluate the right // evaluate the right
builder.clearAccessChain(); builder.clearAccessChain();
node->getRight()->traverse(this); node->getRight()->traverse(this);
spv::Id rValue = builder.accessChainLoad(TranslatePrecisionDecoration(node->getRight()->getType())); spv::Id rValue = builder.accessChainLoad(convertGlslangToSpvType(node->getRight()->getType()));
if (node->getOp() != glslang::EOpAssign) { if (node->getOp() != glslang::EOpAssign) {
// the left is also an r-value // the left is also an r-value
builder.setAccessChain(lValue); builder.setAccessChain(lValue);
spv::Id leftRValue = builder.accessChainLoad(TranslatePrecisionDecoration(node->getLeft()->getType())); spv::Id leftRValue = builder.accessChainLoad(convertGlslangToSpvType(node->getLeft()->getType()));
// do the operation // do the operation
rValue = createBinaryOperation(node->getOp(), TranslatePrecisionDecoration(node->getType()), rValue = createBinaryOperation(node->getOp(), TranslatePrecisionDecoration(node->getType()),
@ -587,10 +587,10 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
// so short circuit the access-chain stuff with a swizzle. // so short circuit the access-chain stuff with a swizzle.
std::vector<unsigned> swizzle; std::vector<unsigned> swizzle;
swizzle.push_back(node->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst()); swizzle.push_back(node->getRight()->getAsConstantUnion()->getConstArray()[0].getIConst());
builder.accessChainPushSwizzle(swizzle); builder.accessChainPushSwizzle(swizzle, convertGlslangToSpvType(node->getLeft()->getType()));
} else { } else {
// normal case for indexing array or structure or block // normal case for indexing array or structure or block
builder.accessChainPush(builder.makeIntConstant(index), convertGlslangToSpvType(node->getType())); builder.accessChainPush(builder.makeIntConstant(index));
} }
} }
return false; return false;
@ -611,15 +611,15 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
// compute the next index in the chain // compute the next index in the chain
builder.clearAccessChain(); builder.clearAccessChain();
node->getRight()->traverse(this); node->getRight()->traverse(this);
spv::Id index = builder.accessChainLoad(TranslatePrecisionDecoration(node->getRight()->getType())); spv::Id index = builder.accessChainLoad(convertGlslangToSpvType(node->getRight()->getType()));
// restore the saved access chain // restore the saved access chain
builder.setAccessChain(partial); builder.setAccessChain(partial);
if (! node->getLeft()->getType().isArray() && node->getLeft()->getType().isVector()) if (! node->getLeft()->getType().isArray() && node->getLeft()->getType().isVector())
builder.accessChainPushComponent(index); builder.accessChainPushComponent(index, convertGlslangToSpvType(node->getLeft()->getType()));
else else
builder.accessChainPush(index, convertGlslangToSpvType(node->getType())); builder.accessChainPush(index);
} }
return false; return false;
case glslang::EOpVectorSwizzle: case glslang::EOpVectorSwizzle:
@ -629,7 +629,7 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
std::vector<unsigned> swizzle; std::vector<unsigned> swizzle;
for (int i = 0; i < (int)swizzleSequence.size(); ++i) for (int i = 0; i < (int)swizzleSequence.size(); ++i)
swizzle.push_back(swizzleSequence[i]->getAsConstantUnion()->getConstArray()[0].getIConst()); swizzle.push_back(swizzleSequence[i]->getAsConstantUnion()->getConstArray()[0].getIConst());
builder.accessChainPushSwizzle(swizzle); builder.accessChainPushSwizzle(swizzle, convertGlslangToSpvType(node->getLeft()->getType()));
} }
return false; return false;
default: default:
@ -641,11 +641,11 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
// Get the operands // Get the operands
builder.clearAccessChain(); builder.clearAccessChain();
node->getLeft()->traverse(this); node->getLeft()->traverse(this);
spv::Id left = builder.accessChainLoad(TranslatePrecisionDecoration(node->getLeft()->getType())); spv::Id left = builder.accessChainLoad(convertGlslangToSpvType(node->getLeft()->getType()));
builder.clearAccessChain(); builder.clearAccessChain();
node->getRight()->traverse(this); node->getRight()->traverse(this);
spv::Id right = builder.accessChainLoad(TranslatePrecisionDecoration(node->getRight()->getType())); spv::Id right = builder.accessChainLoad(convertGlslangToSpvType(node->getRight()->getType()));
spv::Id result; spv::Id result;
spv::Decoration precision = TranslatePrecisionDecoration(node->getType()); spv::Decoration precision = TranslatePrecisionDecoration(node->getType());
@ -702,7 +702,7 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI
builder.clearAccessChain(); builder.clearAccessChain();
node->getOperand()->traverse(this); node->getOperand()->traverse(this);
spv::Id operand = builder.accessChainLoad(TranslatePrecisionDecoration(node->getOperand()->getType())); spv::Id operand = builder.accessChainLoad(convertGlslangToSpvType(node->getOperand()->getType()));
spv::Decoration precision = TranslatePrecisionDecoration(node->getType()); spv::Decoration precision = TranslatePrecisionDecoration(node->getType());
@ -1038,11 +1038,11 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
builder.clearAccessChain(); builder.clearAccessChain();
left->traverse(this); left->traverse(this);
spv::Id leftId = builder.accessChainLoad(TranslatePrecisionDecoration(left->getType())); spv::Id leftId = builder.accessChainLoad(convertGlslangToSpvType(left->getType()));
builder.clearAccessChain(); builder.clearAccessChain();
right->traverse(this); right->traverse(this);
spv::Id rightId = builder.accessChainLoad(TranslatePrecisionDecoration(right->getType())); spv::Id rightId = builder.accessChainLoad(convertGlslangToSpvType(right->getType()));
result = createBinaryOperation(binOp, precision, result = createBinaryOperation(binOp, precision,
convertGlslangToSpvType(node->getType()), leftId, rightId, convertGlslangToSpvType(node->getType()), leftId, rightId,
@ -1084,7 +1084,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
if (lvalue) if (lvalue)
operands.push_back(builder.accessChainGetLValue()); operands.push_back(builder.accessChainGetLValue());
else else
operands.push_back(builder.accessChainLoad(TranslatePrecisionDecoration(glslangOperands[arg]->getAsTyped()->getType()))); operands.push_back(builder.accessChainLoad(convertGlslangToSpvType(glslangOperands[arg]->getAsTyped()->getType())));
} }
if (atomic) { if (atomic) {
@ -1134,13 +1134,13 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang
node->getCondition()->traverse(this); node->getCondition()->traverse(this);
// make an "if" based on the value created by the condition // make an "if" based on the value created by the condition
spv::Builder::If ifBuilder(builder.accessChainLoad(spv::NoPrecision), builder); spv::Builder::If ifBuilder(builder.accessChainLoad(convertGlslangToSpvType(node->getCondition()->getType())), builder);
if (node->getTrueBlock()) { if (node->getTrueBlock()) {
// emit the "then" statement // emit the "then" statement
node->getTrueBlock()->traverse(this); node->getTrueBlock()->traverse(this);
if (result) if (result)
builder.createStore(builder.accessChainLoad(TranslatePrecisionDecoration(node->getTrueBlock()->getAsTyped()->getType())), result); builder.createStore(builder.accessChainLoad(convertGlslangToSpvType(node->getTrueBlock()->getAsTyped()->getType())), result);
} }
if (node->getFalseBlock()) { if (node->getFalseBlock()) {
@ -1148,7 +1148,7 @@ bool TGlslangToSpvTraverser::visitSelection(glslang::TVisit /* visit */, glslang
// emit the "else" statement // emit the "else" statement
node->getFalseBlock()->traverse(this); node->getFalseBlock()->traverse(this);
if (result) if (result)
builder.createStore(builder.accessChainLoad(TranslatePrecisionDecoration(node->getFalseBlock()->getAsTyped()->getType())), result); builder.createStore(builder.accessChainLoad(convertGlslangToSpvType(node->getFalseBlock()->getAsTyped()->getType())), result);
} }
ifBuilder.makeEndIf(); ifBuilder.makeEndIf();
@ -1169,7 +1169,7 @@ bool TGlslangToSpvTraverser::visitSwitch(glslang::TVisit /* visit */, glslang::T
{ {
// emit and get the condition before doing anything with switch // emit and get the condition before doing anything with switch
node->getCondition()->traverse(this); node->getCondition()->traverse(this);
spv::Id selector = builder.accessChainLoad(TranslatePrecisionDecoration(node->getCondition()->getAsTyped()->getType())); spv::Id selector = builder.accessChainLoad(convertGlslangToSpvType(node->getCondition()->getAsTyped()->getType()));
// browse the children to sort out code segments // browse the children to sort out code segments
int defaultSegment = -1; int defaultSegment = -1;
@ -1233,7 +1233,7 @@ bool TGlslangToSpvTraverser::visitLoop(glslang::TVisit /* visit */, glslang::TIn
if (node->getTest()) { if (node->getTest()) {
node->getTest()->traverse(this); node->getTest()->traverse(this);
// the AST only contained the test computation, not the branch, we have to add it // the AST only contained the test computation, not the branch, we have to add it
spv::Id condition = builder.accessChainLoad(TranslatePrecisionDecoration(node->getTest()->getType())); spv::Id condition = builder.accessChainLoad(convertGlslangToSpvType(node->getTest()->getType()));
builder.createLoopTestBranch(condition); builder.createLoopTestBranch(condition);
} else { } else {
builder.createBranchToBody(); builder.createBranchToBody();
@ -1279,7 +1279,7 @@ bool TGlslangToSpvTraverser::visitBranch(glslang::TVisit /* visit */, glslang::T
if (inMain) if (inMain)
builder.makeMainReturn(); builder.makeMainReturn();
else if (node->getExpression()) else if (node->getExpression())
builder.makeReturn(false, builder.accessChainLoad(TranslatePrecisionDecoration(node->getExpression()->getType()))); builder.makeReturn(false, builder.accessChainLoad(convertGlslangToSpvType(node->getExpression()->getType())));
else else
builder.makeReturn(); builder.makeReturn();
@ -1664,7 +1664,7 @@ void TGlslangToSpvTraverser::translateArguments(const glslang::TIntermSequence&
for (int i = 0; i < (int)glslangArguments.size(); ++i) { for (int i = 0; i < (int)glslangArguments.size(); ++i) {
builder.clearAccessChain(); builder.clearAccessChain();
glslangArguments[i]->traverse(this); glslangArguments[i]->traverse(this);
arguments.push_back(builder.accessChainLoad(TranslatePrecisionDecoration(glslangArguments[i]->getAsTyped()->getType()))); arguments.push_back(builder.accessChainLoad(convertGlslangToSpvType(glslangArguments[i]->getAsTyped()->getType())));
} }
} }
@ -1672,7 +1672,7 @@ void TGlslangToSpvTraverser::translateArguments(glslang::TIntermUnary& node, std
{ {
builder.clearAccessChain(); builder.clearAccessChain();
node.getOperand()->traverse(this); node.getOperand()->traverse(this);
arguments.push_back(builder.accessChainLoad(TranslatePrecisionDecoration(node.getAsTyped()->getType()))); arguments.push_back(builder.accessChainLoad(convertGlslangToSpvType(node.getOperand()->getType())));
} }
spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermOperator* node) spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermOperator* node)
@ -1806,17 +1806,19 @@ spv::Id TGlslangToSpvTraverser::handleUserFunctionCall(const glslang::TIntermAgg
// 1. Evaluate the arguments // 1. Evaluate the arguments
std::vector<spv::Builder::AccessChain> lValues; std::vector<spv::Builder::AccessChain> lValues;
std::vector<spv::Id> rValues; std::vector<spv::Id> rValues;
std::vector<spv::Id> argTypes;
for (int a = 0; a < (int)glslangArgs.size(); ++a) { for (int a = 0; a < (int)glslangArgs.size(); ++a) {
// build l-value // build l-value
builder.clearAccessChain(); builder.clearAccessChain();
glslangArgs[a]->traverse(this); glslangArgs[a]->traverse(this);
argTypes.push_back(convertGlslangToSpvType(glslangArgs[a]->getAsTyped()->getType()));
// keep outputs as l-values, evaluate input-only as r-values // keep outputs as l-values, evaluate input-only as r-values
if (qualifiers[a] != glslang::EvqConstReadOnly) { if (qualifiers[a] != glslang::EvqConstReadOnly) {
// save l-value // save l-value
lValues.push_back(builder.getAccessChain()); lValues.push_back(builder.getAccessChain());
} else { } else {
// process r-value // process r-value
rValues.push_back(builder.accessChainLoad(TranslatePrecisionDecoration(glslangArgs[a]->getAsTyped()->getType()))); rValues.push_back(builder.accessChainLoad(argTypes.back()));
} }
} }
@ -1836,7 +1838,7 @@ spv::Id TGlslangToSpvTraverser::handleUserFunctionCall(const glslang::TIntermAgg
if (qualifiers[a] == glslang::EvqIn || qualifiers[a] == glslang::EvqInOut) { if (qualifiers[a] == glslang::EvqIn || qualifiers[a] == glslang::EvqInOut) {
// need to copy the input into output space // need to copy the input into output space
builder.setAccessChain(lValues[lValueCount]); builder.setAccessChain(lValues[lValueCount]);
spv::Id copy = builder.accessChainLoad(spv::NoPrecision); // TODO: get precision spv::Id copy = builder.accessChainLoad(argTypes[a]);
builder.createStore(copy, arg); builder.createStore(copy, arg);
} }
++lValueCount; ++lValueCount;

View File

@ -1957,18 +1957,23 @@ void Builder::createBranchToLoopHeaderFromInside(const Loop& loop)
void Builder::clearAccessChain() void Builder::clearAccessChain()
{ {
accessChain.base = 0; accessChain.base = NoResult;
accessChain.indexChain.clear(); accessChain.indexChain.clear();
accessChain.instr = 0; accessChain.instr = NoResult;
accessChain.swizzle.clear(); accessChain.swizzle.clear();
accessChain.component = 0; accessChain.component = NoResult;
accessChain.resultType = NoType; accessChain.preSwizzleBaseType = NoType;
accessChain.isRValue = false; accessChain.isRValue = false;
} }
// Comments in header // Comments in header
void Builder::accessChainPushSwizzle(std::vector<unsigned>& swizzle) void Builder::accessChainPushSwizzle(std::vector<unsigned>& swizzle, Id preSwizzleBaseType)
{ {
// swizzles can be stacked in GLSL, but simplified to a single
// one here; the base type doesn't change
if (accessChain.preSwizzleBaseType == NoType)
accessChain.preSwizzleBaseType = preSwizzleBaseType;
// if needed, propagate the swizzle for the current access chain // if needed, propagate the swizzle for the current access chain
if (accessChain.swizzle.size()) { if (accessChain.swizzle.size()) {
std::vector<unsigned> oldSwizzle = accessChain.swizzle; std::vector<unsigned> oldSwizzle = accessChain.swizzle;
@ -1990,7 +1995,7 @@ void Builder::accessChainStore(Id rvalue)
Id base = collapseAccessChain(); Id base = collapseAccessChain();
if (accessChain.swizzle.size() && accessChain.component) if (accessChain.swizzle.size() && accessChain.component != NoResult)
MissingFunctionality("simultaneous l-value swizzle and dynamic component selection"); MissingFunctionality("simultaneous l-value swizzle and dynamic component selection");
// If swizzle exists, it is out-of-order or not full, we must load the target vector, // If swizzle exists, it is out-of-order or not full, we must load the target vector,
@ -2002,7 +2007,7 @@ void Builder::accessChainStore(Id rvalue)
} }
// dynamic component selection // dynamic component selection
if (accessChain.component) { if (accessChain.component != NoResult) {
Id tempBaseId = (source == NoResult) ? createLoad(base) : source; Id tempBaseId = (source == NoResult) ? createLoad(base) : source;
source = createVectorInsertDynamic(tempBaseId, getTypeId(tempBaseId), rvalue, accessChain.component); source = createVectorInsertDynamic(tempBaseId, getTypeId(tempBaseId), rvalue, accessChain.component);
} }
@ -2014,13 +2019,15 @@ void Builder::accessChainStore(Id rvalue)
} }
// Comments in header // Comments in header
Id Builder::accessChainLoad(Decoration /*precision*/) Id Builder::accessChainLoad(Id resultType)
{ {
Id id; Id id;
if (accessChain.isRValue) { if (accessChain.isRValue) {
if (accessChain.indexChain.size() > 0) { if (accessChain.indexChain.size() > 0) {
mergeAccessChainSwizzle(); // TODO: optimization: look at applying this optimization more widely mergeAccessChainSwizzle(); // TODO: optimization: look at applying this optimization more widely
Id swizzleBase = accessChain.preSwizzleBaseType != NoType ? accessChain.preSwizzleBaseType : resultType;
// if all the accesses are constants, we can use OpCompositeExtract // if all the accesses are constants, we can use OpCompositeExtract
std::vector<unsigned> indexes; std::vector<unsigned> indexes;
bool constant = true; bool constant = true;
@ -2034,7 +2041,7 @@ Id Builder::accessChainLoad(Decoration /*precision*/)
} }
if (constant) if (constant)
id = createCompositeExtract(accessChain.base, accessChain.resultType, indexes); id = createCompositeExtract(accessChain.base, swizzleBase, indexes);
else { else {
// make a new function variable for this r-value // make a new function variable for this r-value
Id lValue = createVariable(StorageClassFunction, getTypeId(accessChain.base), "indexable"); Id lValue = createVariable(StorageClassFunction, getTypeId(accessChain.base), "indexable");
@ -2057,24 +2064,22 @@ Id Builder::accessChainLoad(Decoration /*precision*/)
} }
// Done, unless there are swizzles to do // Done, unless there are swizzles to do
if (accessChain.swizzle.size() == 0 && accessChain.component == 0) if (accessChain.swizzle.size() == 0 && accessChain.component == NoResult)
return id; return id;
Id componentType = getScalarTypeId(accessChain.resultType);
// Do remaining swizzling // Do remaining swizzling
// First, static swizzling // First, static swizzling
if (accessChain.swizzle.size()) { if (accessChain.swizzle.size()) {
// static swizzle // static swizzle
Id resultType = componentType; Id swizzledType = getScalarTypeId(getTypeId(id));
if (accessChain.swizzle.size() > 1) if (accessChain.swizzle.size() > 1)
resultType = makeVectorType(componentType, (int)accessChain.swizzle.size()); swizzledType = makeVectorType(swizzledType, (int)accessChain.swizzle.size());
id = createRvalueSwizzle(resultType, id, accessChain.swizzle); id = createRvalueSwizzle(swizzledType, id, accessChain.swizzle);
} }
// dynamic single-component selection // dynamic single-component selection
if (accessChain.component) if (accessChain.component != NoResult)
id = createVectorExtractDynamic(id, componentType, accessChain.component); id = createVectorExtractDynamic(id, resultType, accessChain.component);
return id; return id;
} }
@ -2089,7 +2094,7 @@ Id Builder::accessChainGetLValue()
// extract and insert elements to perform writeMask and/or swizzle. This does not // extract and insert elements to perform writeMask and/or swizzle. This does not
// go with getting a direct l-value pointer. // go with getting a direct l-value pointer.
assert(accessChain.swizzle.size() == 0); assert(accessChain.swizzle.size() == 0);
assert(accessChain.component == spv::NoResult); assert(accessChain.component == NoResult);
return lvalue; return lvalue;
} }
@ -2170,7 +2175,7 @@ void Builder::simplifyAccessChainSwizzle()
{ {
// If the swizzle has fewer components than the vector, it is subsetting, and must stay // If the swizzle has fewer components than the vector, it is subsetting, and must stay
// to preserve that fact. // to preserve that fact.
if (getNumTypeComponents(accessChain.resultType) > (int)accessChain.swizzle.size()) if (getNumTypeComponents(accessChain.preSwizzleBaseType) > (int)accessChain.swizzle.size())
return; return;
// if components are out of order, it is a swizzle // if components are out of order, it is a swizzle
@ -2181,6 +2186,8 @@ void Builder::simplifyAccessChainSwizzle()
// otherwise, there is no need to track this swizzle // otherwise, there is no need to track this swizzle
accessChain.swizzle.clear(); accessChain.swizzle.clear();
if (accessChain.component == NoResult)
accessChain.preSwizzleBaseType = NoType;
} }
// clear out swizzle if it can become part of the indexes // clear out swizzle if it can become part of the indexes
@ -2188,12 +2195,12 @@ void Builder::mergeAccessChainSwizzle()
{ {
// is there even a chance of doing something? Need a single-component swizzle // is there even a chance of doing something? Need a single-component swizzle
if ((accessChain.swizzle.size() > 1) || if ((accessChain.swizzle.size() > 1) ||
(accessChain.swizzle.size() == 0 && accessChain.component == 0)) (accessChain.swizzle.size() == 0 && accessChain.component == NoResult))
return; return;
// TODO: optimization: remove this, but for now confine this to non-dynamic accesses // TODO: optimization: remove this, but for now confine this to non-dynamic accesses
// (the above test is correct when this is removed.) // (the above test is correct when this is removed.)
if (accessChain.component) if (accessChain.component != NoResult)
return; return;
// move the swizzle over to the indexes // move the swizzle over to the indexes
@ -2201,10 +2208,10 @@ void Builder::mergeAccessChainSwizzle()
accessChain.indexChain.push_back(makeUintConstant(accessChain.swizzle.front())); accessChain.indexChain.push_back(makeUintConstant(accessChain.swizzle.front()));
else else
accessChain.indexChain.push_back(accessChain.component); accessChain.indexChain.push_back(accessChain.component);
accessChain.resultType = getScalarTypeId(accessChain.resultType);
// now there is no need to track this swizzle // now there is no need to track this swizzle
accessChain.component = NoResult; accessChain.component = NoResult;
accessChain.preSwizzleBaseType = NoType;
accessChain.swizzle.clear(); accessChain.swizzle.clear();
} }

View File

@ -431,7 +431,7 @@ public:
Id instr; // the instruction that generates this access chain Id instr; // the instruction that generates this access chain
std::vector<unsigned> swizzle; std::vector<unsigned> swizzle;
Id component; // a dynamic component index, can coexist with a swizzle, done after the swizzle Id component; // a dynamic component index, can coexist with a swizzle, done after the swizzle
Id resultType; // dereferenced type, to be exclusive of swizzles Id preSwizzleBaseType; // dereferenced type, before swizzle or component is applied; NoType unless a swizzle or component is present
bool isRValue; bool isRValue;
}; };
@ -452,7 +452,6 @@ public:
{ {
assert(isPointer(lValue)); assert(isPointer(lValue));
accessChain.base = lValue; accessChain.base = lValue;
accessChain.resultType = getContainedTypeId(getTypeId(lValue));
} }
// set new base value as an r-value // set new base value as an r-value
@ -460,27 +459,30 @@ public:
{ {
accessChain.isRValue = true; accessChain.isRValue = true;
accessChain.base = rValue; accessChain.base = rValue;
accessChain.resultType = getTypeId(rValue);
} }
// push offset onto the end of the chain // push offset onto the end of the chain
void accessChainPush(Id offset, Id newType) void accessChainPush(Id offset)
{ {
accessChain.indexChain.push_back(offset); accessChain.indexChain.push_back(offset);
accessChain.resultType = newType;
} }
// push new swizzle onto the end of any existing swizzle, merging into a single swizzle // push new swizzle onto the end of any existing swizzle, merging into a single swizzle
void accessChainPushSwizzle(std::vector<unsigned>& swizzle); void accessChainPushSwizzle(std::vector<unsigned>& swizzle, Id preSwizzleBaseType);
// push a variable component selection onto the access chain; supporting only one, so unsided // push a variable component selection onto the access chain; supporting only one, so unsided
void accessChainPushComponent(Id component) { accessChain.component = component; } void accessChainPushComponent(Id component, Id preSwizzleBaseType)
{
accessChain.component = component;
if (accessChain.preSwizzleBaseType == NoType)
accessChain.preSwizzleBaseType = preSwizzleBaseType;
}
// use accessChain and swizzle to store value // use accessChain and swizzle to store value
void accessChainStore(Id rvalue); void accessChainStore(Id rvalue);
// use accessChain and swizzle to load an r-value // use accessChain and swizzle to load an r-value
Id accessChainLoad(Decoration precision); Id accessChainLoad(Id ResultType);
// get the direct pointer for an l-value // get the direct pointer for an l-value
Id accessChainGetLValue(); Id accessChainGetLValue();

View File

@ -7,7 +7,7 @@ Linked compute stage:
// Module Version 99 // Module Version 99
// Generated by (magic number): 51a00bb // Generated by (magic number): 51a00bb
// Id's are bound by 72 // Id's are bound by 68
Source ESSL 310 Source ESSL 310
Capability Shader Capability Shader
@ -26,21 +26,21 @@ Linked compute stage:
MemberName 25(outbna) 0 "k" MemberName 25(outbna) 0 "k"
MemberName 25(outbna) 1 "na" MemberName 25(outbna) 1 "na"
Name 27 "outbnamena" Name 27 "outbnamena"
Name 47 "i" Name 44 "i"
Name 53 "outs" Name 50 "outs"
MemberName 53(outs) 0 "s" MemberName 50(outs) 0 "s"
MemberName 53(outs) 1 "va" MemberName 50(outs) 1 "va"
Name 55 "outnames" Name 52 "outnames"
Name 59 "gl_LocalInvocationID" Name 55 "gl_LocalInvocationID"
Decorate 14(outb) GLSLShared Decorate 14(outb) GLSLShared
Decorate 14(outb) BufferBlock Decorate 14(outb) BufferBlock
Decorate 25(outbna) GLSLShared Decorate 25(outbna) GLSLShared
Decorate 25(outbna) BufferBlock Decorate 25(outbna) BufferBlock
Decorate 53(outs) GLSLShared Decorate 50(outs) GLSLShared
Decorate 53(outs) BufferBlock Decorate 50(outs) BufferBlock
Decorate 59(gl_LocalInvocationID) BuiltIn LocalInvocationId Decorate 55(gl_LocalInvocationID) BuiltIn LocalInvocationId
Decorate 71 BuiltIn WorkgroupSize Decorate 67 BuiltIn WorkgroupSize
Decorate 71 NoStaticUse Decorate 67 NoStaticUse
2: TypeVoid 2: TypeVoid
3: TypeFunction 2 3: TypeFunction 2
7: TypeInt 32 0 7: TypeInt 32 0
@ -64,30 +64,26 @@ Linked compute stage:
27(outbnamena): 26(ptr) Variable Uniform 27(outbnamena): 26(ptr) Variable Uniform
28: 17(int) Constant 1 28: 17(int) Constant 1
31: TypePointer Uniform 24(fvec4) 31: TypePointer Uniform 24(fvec4)
33: TypeRuntimeArray 12(fvec3) 33: 17(int) Constant 3
34: 17(int) Constant 3 34: 17(int) Constant 18
35: 17(int) Constant 18 35: TypePointer Uniform 12(fvec3)
36: TypePointer Uniform 12(fvec3) 39: 17(int) Constant 17
40: TypeRuntimeArray 12(fvec3) 40: 11(float) Constant 1077936128
41: 17(int) Constant 17 41: 12(fvec3) ConstantComposite 40 40 40
42: 11(float) Constant 1077936128 43: TypePointer WorkgroupLocal 17(int)
43: 12(fvec3) ConstantComposite 42 42 42 44(i): 43(ptr) Variable WorkgroupLocal
45: TypeRuntimeArray 12(fvec3) 49: TypeRuntimeArray 24(fvec4)
46: TypePointer WorkgroupLocal 17(int) 50(outs): TypeStruct 17(int) 49
47(i): 46(ptr) Variable WorkgroupLocal 51: TypePointer Uniform 50(outs)
52: TypeRuntimeArray 24(fvec4) 52(outnames): 51(ptr) Variable Uniform
53(outs): TypeStruct 17(int) 52 53: TypeVector 7(int) 3
54: TypePointer Uniform 53(outs) 54: TypePointer Input 53(ivec3)
55(outnames): 54(ptr) Variable Uniform 55(gl_LocalInvocationID): 54(ptr) Variable Input
56: TypeRuntimeArray 24(fvec4) 62: TypePointer Uniform 17(int)
57: TypeVector 7(int) 3 64: 7(int) Constant 16
58: TypePointer Input 57(ivec3) 65: 7(int) Constant 32
59(gl_LocalInvocationID): 58(ptr) Variable Input 66: 7(int) Constant 4
66: TypePointer Uniform 17(int) 67: 53(ivec3) ConstantComposite 64 65 66
68: 7(int) Constant 16
69: 7(int) Constant 32
70: 7(int) Constant 4
71: 57(ivec3) ConstantComposite 68 69 70
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
MemoryBarrier 8 9 MemoryBarrier 8 9
@ -99,26 +95,26 @@ Linked compute stage:
30: 24(fvec4) CompositeConstruct 29 29 29 29 30: 24(fvec4) CompositeConstruct 29 29 29 29
32: 31(ptr) AccessChain 27(outbnamena) 28 32: 31(ptr) AccessChain 27(outbnamena) 28
Store 32 30 Store 32 30
37: 36(ptr) AccessChain 16(outbname) 34 35 36: 35(ptr) AccessChain 16(outbname) 33 34
38: 12(fvec3) Load 37 37: 12(fvec3) Load 36
39: 11(float) CompositeExtract 38 0 38: 11(float) CompositeExtract 37 0
Store 20(s) 39 Store 20(s) 38
44: 36(ptr) AccessChain 16(outbname) 34 41 42: 35(ptr) AccessChain 16(outbname) 33 39
Store 44 43 Store 42 41
48: 17(int) Load 47(i) 45: 17(int) Load 44(i)
49: 11(float) Load 20(s) 46: 11(float) Load 20(s)
50: 12(fvec3) CompositeConstruct 49 49 49 47: 12(fvec3) CompositeConstruct 46 46 46
51: 36(ptr) AccessChain 16(outbname) 34 48 48: 35(ptr) AccessChain 16(outbname) 33 45
Store 51 50 Store 48 47
60: 57(ivec3) Load 59(gl_LocalInvocationID) 56: 53(ivec3) Load 55(gl_LocalInvocationID)
61: 7(int) CompositeExtract 60 0 57: 7(int) CompositeExtract 56 0
62: 11(float) Load 20(s) 58: 11(float) Load 20(s)
63: 24(fvec4) CompositeConstruct 62 62 62 62 59: 24(fvec4) CompositeConstruct 58 58 58 58
64: 31(ptr) AccessChain 55(outnames) 28 61 60: 31(ptr) AccessChain 52(outnames) 28 57
Store 64 63 Store 60 59
65: 17(int) ArrayLength 16(outbname) 61: 17(int) ArrayLength 16(outbname)
67: 66(ptr) AccessChain 55(outnames) 18 63: 62(ptr) AccessChain 52(outnames) 18
Store 67 65 Store 63 61
Branch 6 Branch 6
6: Label 6: Label
Return Return

View File

@ -51,7 +51,7 @@ Linked fragment stage:
292: 19(int) Constant 2 292: 19(int) Constant 2
299: 19(int) Constant 1 299: 19(int) Constant 1
301: TypePointer Function 7(float) 301: TypePointer Function 7(float)
332: TypeVector 7(float) 3 331: TypeVector 7(float) 3
347: 7(float) Constant 1073741824 347: 7(float) Constant 1073741824
354: 7(float) Constant 1065353216 354: 7(float) Constant 1065353216
359: 19(int) Constant 66 359: 19(int) Constant 66
@ -434,11 +434,11 @@ Linked fragment stage:
329: 7(float) Load 302(f) 329: 7(float) Load 302(f)
330: 7(float) FAdd 329 328 330: 7(float) FAdd 329 328
Store 302(f) 330 Store 302(f) 330
331: 8(fvec4) Load 10(v) 332: 8(fvec4) Load 10(v)
333: 332(fvec3) VectorShuffle 331 331 0 1 2 333: 331(fvec3) VectorShuffle 332 332 0 1 2
334: 8(fvec4) Load 10(v) 334: 8(fvec4) Load 10(v)
335: 332(fvec3) VectorShuffle 334 334 0 1 2 335: 331(fvec3) VectorShuffle 334 334 0 1 2
336: 332(fvec3) ExtInst 1(GLSL.std.450) 67(Cross) 333 335 336: 331(fvec3) ExtInst 1(GLSL.std.450) 67(Cross) 333 335
337: 7(float) CompositeExtract 336 0 337: 7(float) CompositeExtract 336 0
338: 7(float) Load 302(f) 338: 7(float) Load 302(f)
339: 7(float) FAdd 338 337 339: 7(float) FAdd 338 337

View File

@ -86,7 +86,7 @@ Linked fragment stage:
67: 14(int) Constant 0 67: 14(int) Constant 0
68: TypeInt 32 0 68: TypeInt 32 0
69: 68(int) Constant 0 69: 68(int) Constant 0
97: TypeVector 7(float) 2 96: TypeVector 7(float) 2
110: 68(int) Constant 2 110: 68(int) Constant 2
142: 7(float) Constant 0 142: 7(float) Constant 0
143: 8(fvec3) ConstantComposite 142 142 142 143: 8(fvec3) ConstantComposite 142 142 142
@ -227,8 +227,8 @@ Linked fragment stage:
34(comp): 15(ptr) FunctionParameter 34(comp): 15(ptr) FunctionParameter
36: Label 36: Label
95: 14(int) Load 34(comp) 95: 14(int) Load 34(comp)
96: 8(fvec3) CompositeExtract 33(i) 0 97: 8(fvec3) CompositeExtract 33(i) 0
98: 97(fvec2) VectorShuffle 96 96 1 0 98: 96(fvec2) VectorShuffle 97 97 1 0
99: 7(float) VectorExtractDynamic 98 95 99: 7(float) VectorExtractDynamic 98 95
100: 8(fvec3) Load 66(OutColor) 100: 8(fvec3) Load 66(OutColor)
101: 8(fvec3) CompositeConstruct 99 99 99 101: 8(fvec3) CompositeConstruct 99 99 99
@ -241,10 +241,10 @@ Linked fragment stage:
38(comp): 15(ptr) FunctionParameter 38(comp): 15(ptr) FunctionParameter
40: Label 40: Label
103: 8(fvec3) CompositeExtract 37(i) 0 103: 8(fvec3) CompositeExtract 37(i) 0
104: 97(fvec2) VectorShuffle 103 103 0 1 104: 96(fvec2) VectorShuffle 103 103 0 1
105: 8(fvec3) Load 66(OutColor) 105: 8(fvec3) Load 66(OutColor)
106: 97(fvec2) VectorShuffle 105 105 0 1 106: 96(fvec2) VectorShuffle 105 105 0 1
107: 97(fvec2) FAdd 106 104 107: 96(fvec2) FAdd 106 104
108: 8(fvec3) Load 66(OutColor) 108: 8(fvec3) Load 66(OutColor)
109: 8(fvec3) VectorShuffle 108 107 3 4 2 109: 8(fvec3) VectorShuffle 108 107 3 4 2
Store 66(OutColor) 109 Store 66(OutColor) 109
@ -279,10 +279,10 @@ Linked fragment stage:
50(comp): 15(ptr) FunctionParameter 50(comp): 15(ptr) FunctionParameter
52: Label 52: Label
121: 8(fvec3) CompositeExtract 49(i) 0 121: 8(fvec3) CompositeExtract 49(i) 0
122: 97(fvec2) VectorShuffle 121 121 0 1 122: 96(fvec2) VectorShuffle 121 121 0 1
123: 8(fvec3) Load 66(OutColor) 123: 8(fvec3) Load 66(OutColor)
124: 97(fvec2) VectorShuffle 123 123 2 1 124: 96(fvec2) VectorShuffle 123 123 2 1
125: 97(fvec2) FAdd 124 122 125: 96(fvec2) FAdd 124 122
126: 8(fvec3) Load 66(OutColor) 126: 8(fvec3) Load 66(OutColor)
127: 8(fvec3) VectorShuffle 126 125 0 4 3 127: 8(fvec3) VectorShuffle 126 125 0 4 3
Store 66(OutColor) 127 Store 66(OutColor) 127
@ -293,10 +293,10 @@ Linked fragment stage:
54(comp): 15(ptr) FunctionParameter 54(comp): 15(ptr) FunctionParameter
56: Label 56: Label
128: 8(fvec3) CompositeExtract 53(i) 0 128: 8(fvec3) CompositeExtract 53(i) 0
129: 97(fvec2) VectorShuffle 128 128 0 1 129: 96(fvec2) VectorShuffle 128 128 0 1
130: 8(fvec3) Load 66(OutColor) 130: 8(fvec3) Load 66(OutColor)
131: 97(fvec2) VectorShuffle 130 130 0 2 131: 96(fvec2) VectorShuffle 130 130 0 2
132: 97(fvec2) FAdd 131 129 132: 96(fvec2) FAdd 131 129
133: 8(fvec3) Load 66(OutColor) 133: 8(fvec3) Load 66(OutColor)
134: 8(fvec3) VectorShuffle 133 132 3 1 4 134: 8(fvec3) VectorShuffle 133 132 3 1 4
Store 66(OutColor) 134 Store 66(OutColor) 134

View File

@ -57,7 +57,7 @@ Linked compute stage:
25: TypeVector 24(int) 3 25: TypeVector 24(int) 3
26: TypePointer Input 25(ivec3) 26: TypePointer Input 25(ivec3)
27(gl_GlobalInvocationID): 26(ptr) Variable Input 27(gl_GlobalInvocationID): 26(ptr) Variable Input
29: TypeVector 24(int) 2 28: TypeVector 24(int) 2
32: TypePointer Function 8(float) 32: TypePointer Function 8(float)
34(gl_LocalInvocationID): 26(ptr) Variable Input 34(gl_LocalInvocationID): 26(ptr) Variable Input
38: 12(int) Constant 8 38: 12(int) Constant 8
@ -86,12 +86,12 @@ Linked compute stage:
Store 16 14 Store 16 14
20: 19(ptr) AccessChain 11(bufInst) 17 20: 19(ptr) AccessChain 11(bufInst) 17
Store 20 18 Store 20 18
28: 25(ivec3) Load 27(gl_GlobalInvocationID) 29: 25(ivec3) Load 27(gl_GlobalInvocationID)
30: 29(ivec2) VectorShuffle 28 28 0 1 30: 28(ivec2) VectorShuffle 29 29 0 1
31: 21(ivec2) Bitcast 30 31: 21(ivec2) Bitcast 30
Store 23(storePos) 31 Store 23(storePos) 31
35: 25(ivec3) Load 34(gl_LocalInvocationID) 35: 25(ivec3) Load 34(gl_LocalInvocationID)
36: 29(ivec2) VectorShuffle 35 35 0 1 36: 28(ivec2) VectorShuffle 35 35 0 1
37: 21(ivec2) Bitcast 36 37: 21(ivec2) Bitcast 36
39: 21(ivec2) CompositeConstruct 38 38 39: 21(ivec2) CompositeConstruct 38 38
40: 21(ivec2) ISub 37 39 40: 21(ivec2) ISub 37 39

View File

@ -58,7 +58,7 @@ Linked fragment stage:
50: TypePointer UniformConstant 49(ivec4) 50: TypePointer UniformConstant 49(ivec4)
51(v4): 50(ptr) Variable UniformConstant 51(v4): 50(ptr) Variable UniformConstant
71: 48(int) Constant 4 71: 48(int) Constant 4
86: TypeVector 7(float) 3 85: TypeVector 7(float) 3
97: TypePointer Input 7(float) 97: TypePointer Input 7(float)
98(f): 97(ptr) Variable Input 98(f): 97(ptr) Variable Input
116: 14(int) Constant 16 116: 14(int) Constant 16
@ -145,8 +145,8 @@ Linked fragment stage:
82: 8(fvec4) Load 36(gl_FragColor) 82: 8(fvec4) Load 36(gl_FragColor)
83: 8(fvec4) FAdd 82 81 83: 8(fvec4) FAdd 82 81
Store 36(gl_FragColor) 83 Store 36(gl_FragColor) 83
85: 8(fvec4) Load 12(BaseColor) 86: 8(fvec4) Load 12(BaseColor)
87: 86(fvec3) VectorShuffle 85 85 0 1 2 87: 85(fvec3) VectorShuffle 86 86 0 1 2
88: 8(fvec4) Load 84(r) 88: 8(fvec4) Load 84(r)
89: 8(fvec4) VectorShuffle 88 87 4 5 6 3 89: 8(fvec4) VectorShuffle 88 87 4 5 6 3
Store 84(r) 89 Store 84(r) 89
@ -169,10 +169,10 @@ Linked fragment stage:
Branch 91 Branch 91
92: Label 92: Label
104: 8(fvec4) Load 84(r) 104: 8(fvec4) Load 84(r)
105: 86(fvec3) VectorShuffle 104 104 0 1 2 105: 85(fvec3) VectorShuffle 104 104 0 1 2
106: 8(fvec4) Load 36(gl_FragColor) 106: 8(fvec4) Load 36(gl_FragColor)
107: 86(fvec3) VectorShuffle 106 106 0 1 2 107: 85(fvec3) VectorShuffle 106 106 0 1 2
108: 86(fvec3) FAdd 107 105 108: 85(fvec3) FAdd 107 105
109: 8(fvec4) Load 36(gl_FragColor) 109: 8(fvec4) Load 36(gl_FragColor)
110: 8(fvec4) VectorShuffle 109 108 4 5 6 3 110: 8(fvec4) VectorShuffle 109 108 4 5 6 3
Store 36(gl_FragColor) 110 Store 36(gl_FragColor) 110