Skip to content

Commit de949a2

Browse files
SPV: Add NonUniform decorations for stores.
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>)
1 parent 517f39e commit de949a2

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

SPIRV/GlslangToSpv.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,8 @@ bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TI
22922292

22932293
// The result of operation is always stored, but conditionally the
22942294
// consumed result. The consumed result is always an r-value.
2295-
builder.accessChainStore(result);
2295+
builder.accessChainStore(result,
2296+
TranslateNonUniformDecoration(node->getOperand()->getType().getQualifier()));
22962297
builder.clearAccessChain();
22972298
if (node->getOp() == glslang::EOpPreIncrement ||
22982299
node->getOp() == glslang::EOpPreDecrement)
@@ -2368,6 +2369,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
23682369
spv::Id invertedType = spv::NoType; // to use to override the natural type of the node
23692370
std::vector<spv::Builder::AccessChain> complexLvalues; // for holding swizzling l-values too complex for
23702371
// SPIR-V, for an out parameter
2372+
std::vector<glslang::TQualifier> complexLValueQualifiers;
23712373
std::vector<spv::Id> temporaryLvalues; // temporaries to pass, as proxies for complexLValues
23722374

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

30903093
for (unsigned int i = 0; i < temporaryLvalues.size(); ++i) {
30913094
builder.setAccessChain(complexLvalues[i]);
3092-
builder.accessChainStore(builder.createLoad(temporaryLvalues[i], spv::NoPrecision));
3095+
builder.accessChainStore(builder.createLoad(temporaryLvalues[i], spv::NoPrecision), TranslateNonUniformDecoration(complexLValueQualifiers[i]));
30933096
}
30943097
}
30953098

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

4157-
builder.accessChainStore(rvalue,
4160+
builder.accessChainStore(rvalue, TranslateNonUniformDecoration(type.getQualifier()),
41584161
spv::MemoryAccessMask(TranslateMemoryAccess(coherentFlags) &
41594162
~spv::MemoryAccessMakePointerVisibleKHRMask),
41604163
TranslateMemoryScope(coherentFlags), alignment);
@@ -5239,7 +5242,7 @@ spv::Id TGlslangToSpvTraverser::createImageTextureFunctionCall(glslang::TIntermO
52395242

52405243
builder.accessChainPush(builder.makeIntConstant(i), flags, 0);
52415244
builder.accessChainStore(builder.createCompositeExtract(res, builder.getContainedTypeId(resType, i+1),
5242-
i+1));
5245+
i+1), TranslateNonUniformDecoration(imageType.getQualifier()));
52435246
}
52445247
return builder.createCompositeExtract(res, resultType(), 0);
52455248
}

SPIRV/SpvBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2666,12 +2666,14 @@ void Builder::accessChainPushSwizzle(std::vector<unsigned>& swizzle, Id preSwizz
26662666
}
26672667

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

26732673
transferAccessChainSwizzle(true);
26742674
Id base = collapseAccessChain();
2675+
addDecoration(base, nonUniform);
2676+
26752677
Id source = rvalue;
26762678

26772679
// dynamic component should be gone

SPIRV/SpvBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,8 @@ class Builder {
714714
}
715715

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

720721
// use accessChain and swizzle to load an r-value

Test/baseResults/spv.nonuniform.frag.out

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ spv.nonuniform.frag
6464
Decorate 17(nu_li) DecorationNonUniformEXT
6565
Decorate 17(nu_li) DecorationNonUniformEXT
6666
Decorate 19 DecorationNonUniformEXT
67+
Decorate 18(param) DecorationNonUniformEXT
68+
Decorate 17(nu_li) DecorationNonUniformEXT
6769
Decorate 24 DecorationNonUniformEXT
6870
Decorate 28 DecorationNonUniformEXT
6971
Decorate 29 DecorationNonUniformEXT
72+
Decorate 17(nu_li) DecorationNonUniformEXT
7073
Decorate 35(nu_inv4) Location 0
7174
Decorate 35(nu_inv4) DecorationNonUniformEXT
7275
Decorate 39 DecorationNonUniformEXT
@@ -126,6 +129,7 @@ spv.nonuniform.frag
126129
Decorate 150 DecorationNonUniformEXT
127130
Decorate 151 DecorationNonUniformEXT
128131
Decorate 152 DecorationNonUniformEXT
132+
Decorate 153 DecorationNonUniformEXT
129133
Decorate 160(storageTexelBuffer) DescriptorSet 0
130134
Decorate 160(storageTexelBuffer) Binding 9
131135
Decorate 92(nu_ii) DecorationNonUniformEXT

0 commit comments

Comments
 (0)