Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multiple swizzled out operands #2175

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2353,10 +2353,10 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();

spv::Id result = spv::NoResult;
spv::Id invertedType = spv::NoType; // to use to override the natural type of the node
spv::Builder::AccessChain complexLvalue; // for holding swizzling l-values too complex for SPIR-V,
// for at out parameter
spv::Id temporaryLvalue = spv::NoResult; // temporary to pass, as proxy for complexLValue
spv::Id invertedType = spv::NoType; // to use to override the natural type of the node
std::vector<spv::Builder::AccessChain> complexLvalues; // for holding swizzling l-values too complex for
// SPIR-V, for an out parameter
std::vector<spv::Id> temporaryLvalues; // temporaries to pass, as proxies for complexLValues

auto resultType = [&invertedType, &node, this](){ return invertedType != spv::NoType ?
invertedType :
Expand Down Expand Up @@ -2972,10 +2972,10 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
// reduce to a simple access chain. So, we need a temporary vector to
// receive the result, and must later swizzle that into the original
// l-value.
complexLvalue = builder.getAccessChain();
temporaryLvalue = builder.createVariable(spv::StorageClassFunction,
builder.accessChainGetInferredType(), "swizzleTemp");
operands.push_back(temporaryLvalue);
complexLvalues.push_back(builder.getAccessChain());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, in contrast to the note below, here, lvalues are either inverted or needing this swizzle temporary, and invertedType (especially if generalized) is set each time through the loop. Below, it is just remembering the one answer from here, regardless of how many arguments of each type exist.

temporaryLvalues.push_back(builder.createVariable(spv::StorageClassFunction,
builder.accessChainGetInferredType(), "swizzleTemp"));
operands.push_back(temporaryLvalues.back());
} else {
operands.push_back(builder.accessChainGetLValue());
}
Expand Down Expand Up @@ -3070,11 +3070,13 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
result = createMiscOperation(node->getOp(), precision, resultType(), operands, node->getBasicType());
break;
}

if (invertedType != spv::NoResult)
result = createInvertedSwizzle(precision, *glslangOperands[0]->getAsBinaryNode(), result);
else if (temporaryLvalue != spv::NoResult) {
builder.setAccessChain(complexLvalue);
builder.accessChainStore(builder.createLoad(temporaryLvalue));

for (unsigned int i = 0; i < temporaryLvalues.size(); ++i) {
builder.setAccessChain(complexLvalues[i]);
builder.accessChainStore(builder.createLoad(temporaryLvalues[i]));
}
}

Expand Down
Loading