Skip to content

Commit

Permalink
SPV: Add NonUniform decorations for stores.
Browse files Browse the repository at this point in the history
The direct pointer argument to stores has to use
the NonUniform decoration but we were not using
qualifiers at all to decorate the NonUniform pointer.

(Test fixes by Greg Fischer <greg@lunarg.com>)
  • Loading branch information
BNieuwenhuizen committed Sep 10, 2020
1 parent 517f39e commit de949a2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
11 changes: 7 additions & 4 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,8 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI

// The result of operation is always stored, but conditionally the
// consumed result. The consumed result is always an r-value.
builder.accessChainStore(result);
builder.accessChainStore(result,
TranslateNonUniformDecoration(node->getOperand()->getType().getQualifier()));
builder.clearAccessChain();
if (node->getOp() == glslang::EOpPreIncrement ||
node->getOp() == glslang::EOpPreDecrement)
Expand Down Expand Up @@ -2368,6 +2369,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
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<glslang::TQualifier> complexLValueQualifiers;
std::vector<spv::Id> temporaryLvalues; // temporaries to pass, as proxies for complexLValues

auto resultType = [&invertedType, &node, this](){ return invertedType != spv::NoType ?
Expand Down Expand Up @@ -2985,6 +2987,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
// receive the result, and must later swizzle that into the original
// l-value.
complexLvalues.push_back(builder.getAccessChain());
complexLValueQualifiers.push_back(glslangOperands[arg]->getAsTyped()->getType().getQualifier());
temporaryLvalues.push_back(builder.createVariable(
spv::NoPrecision, spv::StorageClassFunction,
builder.accessChainGetInferredType(), "swizzleTemp"));
Expand Down Expand Up @@ -3089,7 +3092,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt

for (unsigned int i = 0; i < temporaryLvalues.size(); ++i) {
builder.setAccessChain(complexLvalues[i]);
builder.accessChainStore(builder.createLoad(temporaryLvalues[i], spv::NoPrecision));
builder.accessChainStore(builder.createLoad(temporaryLvalues[i], spv::NoPrecision), TranslateNonUniformDecoration(complexLValueQualifiers[i]));
}
}

Expand Down Expand Up @@ -4154,7 +4157,7 @@ void TGlslangToSpvTraverser::accessChainStore(const glslang::TType& type, spv::I
unsigned int alignment = builder.getAccessChain().alignment;
alignment |= type.getBufferReferenceAlignment();

builder.accessChainStore(rvalue,
builder.accessChainStore(rvalue, TranslateNonUniformDecoration(type.getQualifier()),
spv::MemoryAccessMask(TranslateMemoryAccess(coherentFlags) &
~spv::MemoryAccessMakePointerVisibleKHRMask),
TranslateMemoryScope(coherentFlags), alignment);
Expand Down Expand Up @@ -5239,7 +5242,7 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO

builder.accessChainPush(builder.makeIntConstant(i), flags, 0);
builder.accessChainStore(builder.createCompositeExtract(res, builder.getContainedTypeId(resType, i+1),
i+1));
i+1), TranslateNonUniformDecoration(imageType.getQualifier()));
}
return builder.createCompositeExtract(res, resultType(), 0);
}
Expand Down
4 changes: 3 additions & 1 deletion SPIRV/SpvBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2666,12 +2666,14 @@ void Builder::accessChainPushSwizzle(std::vector<unsigned>& swizzle, Id preSwizz
}

// Comments in header
void Builder::accessChainStore(Id rvalue, spv::MemoryAccessMask memoryAccess, spv::Scope scope, unsigned int alignment)
void Builder::accessChainStore(Id rvalue, Decoration nonUniform, spv::MemoryAccessMask memoryAccess, spv::Scope scope, unsigned int alignment)
{
assert(accessChain.isRValue == false);

transferAccessChainSwizzle(true);
Id base = collapseAccessChain();
addDecoration(base, nonUniform);

Id source = rvalue;

// dynamic component should be gone
Expand Down
3 changes: 2 additions & 1 deletion SPIRV/SpvBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,8 @@ class Builder {
}

// use accessChain and swizzle to store value
void accessChainStore(Id rvalue, spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
void accessChainStore(Id rvalue, Decoration nonUniform,
spv::MemoryAccessMask memoryAccess = spv::MemoryAccessMaskNone,
spv::Scope scope = spv::ScopeMax, unsigned int alignment = 0);

// use accessChain and swizzle to load an r-value
Expand Down
4 changes: 4 additions & 0 deletions Test/baseResults/spv.nonuniform.frag.out
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ spv.nonuniform.frag
Decorate 17(nu_li) DecorationNonUniformEXT
Decorate 17(nu_li) DecorationNonUniformEXT
Decorate 19 DecorationNonUniformEXT
Decorate 18(param) DecorationNonUniformEXT
Decorate 17(nu_li) DecorationNonUniformEXT
Decorate 24 DecorationNonUniformEXT
Decorate 28 DecorationNonUniformEXT
Decorate 29 DecorationNonUniformEXT
Decorate 17(nu_li) DecorationNonUniformEXT
Decorate 35(nu_inv4) Location 0
Decorate 35(nu_inv4) DecorationNonUniformEXT
Decorate 39 DecorationNonUniformEXT
Expand Down Expand Up @@ -126,6 +129,7 @@ spv.nonuniform.frag
Decorate 150 DecorationNonUniformEXT
Decorate 151 DecorationNonUniformEXT
Decorate 152 DecorationNonUniformEXT
Decorate 153 DecorationNonUniformEXT
Decorate 160(storageTexelBuffer) DescriptorSet 0
Decorate 160(storageTexelBuffer) Binding 9
Decorate 92(nu_ii) DecorationNonUniformEXT
Expand Down

0 comments on commit de949a2

Please sign in to comment.