Skip to content

Commit

Permalink
Merge pull request KhronosGroup#1717 from jeffbolznv/getBufferReferen…
Browse files Browse the repository at this point in the history
…ceAlignment

Move getBufferReferenceAlignment to be a method of TType
  • Loading branch information
johnkslang authored Mar 7, 2019
2 parents 839a948 + 7895e47 commit 40c16ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
23 changes: 7 additions & 16 deletions SPIRV/GlslangToSpv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,6 @@ class TGlslangToSpvTraverser : public glslang::TIntermTraverser {
builder.addExtension(ext);
}

unsigned int getBufferReferenceAlignment(const glslang::TType &type) const {
if (type.getBasicType() == glslang::EbtReference) {
return type.getReferentType()->getQualifier().hasBufferReferenceAlign() ?
(1u << type.getReferentType()->getQualifier().layoutBufferReferenceAlign) : 16u;
} else {
return 0;
}
}

glslang::SpvOptions& options;
spv::Function* shaderEntry;
spv::Function* currentFunction;
Expand Down Expand Up @@ -1735,7 +1726,7 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
}

// normal case for indexing array or structure or block
builder.accessChainPush(builder.makeIntConstant(spvIndex), TranslateCoherent(node->getLeft()->getType()), getBufferReferenceAlignment(node->getLeft()->getType()));
builder.accessChainPush(builder.makeIntConstant(spvIndex), TranslateCoherent(node->getLeft()->getType()), node->getLeft()->getType().getBufferReferenceAlignment());

// Add capabilities here for accessing PointSize and clip/cull distance.
// We have deferred generation of associated capabilities until now.
Expand Down Expand Up @@ -1774,7 +1765,7 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
TranslateCoherent(node->getLeft()->getType()),
glslangIntermediate->getBaseAlignmentScalar(node->getLeft()->getType(), dummySize));
} else
builder.accessChainPush(index, TranslateCoherent(node->getLeft()->getType()), getBufferReferenceAlignment(node->getLeft()->getType()));
builder.accessChainPush(index, TranslateCoherent(node->getLeft()->getType()), node->getLeft()->getType().getBufferReferenceAlignment());
}
return false;
case glslang::EOpVectorSwizzle:
Expand Down Expand Up @@ -2503,7 +2494,7 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt

// Point to the first element of the array.
builder.accessChainPush(elementId, TranslateCoherent(glslangOperands[arg]->getAsTyped()->getType()),
getBufferReferenceAlignment(glslangOperands[arg]->getAsTyped()->getType()));
glslangOperands[arg]->getAsTyped()->getType().getBufferReferenceAlignment());

spv::Builder::AccessChain::CoherentFlags coherentFlags = builder.getAccessChain().coherentFlags;
unsigned int alignment = builder.getAccessChain().alignment;
Expand Down Expand Up @@ -3518,7 +3509,7 @@ spv::Id TGlslangToSpvTraverser::accessChainLoad(const glslang::TType& type)
coherentFlags |= TranslateCoherent(type);

unsigned int alignment = builder.getAccessChain().alignment;
alignment |= getBufferReferenceAlignment(type);
alignment |= type.getBufferReferenceAlignment();

spv::Id loadedId = builder.accessChainLoad(TranslatePrecisionDecoration(type),
TranslateNonUniformDecoration(type.getQualifier()),
Expand Down Expand Up @@ -3585,7 +3576,7 @@ void TGlslangToSpvTraverser::accessChainStore(const glslang::TType& type, spv::I
coherentFlags |= TranslateCoherent(type);

unsigned int alignment = builder.getAccessChain().alignment;
alignment |= getBufferReferenceAlignment(type);
alignment |= type.getBufferReferenceAlignment();

builder.accessChainStore(rvalue,
spv::MemoryAccessMask(TranslateMemoryAccess(coherentFlags) & ~spv::MemoryAccessMakePointerVisibleKHRMask),
Expand Down Expand Up @@ -3635,7 +3626,7 @@ void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id
// set up the target storage
builder.clearAccessChain();
builder.setAccessChainLValue(lValue);
builder.accessChainPush(builder.makeIntConstant(index), TranslateCoherent(type), getBufferReferenceAlignment(type));
builder.accessChainPush(builder.makeIntConstant(index), TranslateCoherent(type), type.getBufferReferenceAlignment());

// store the member
multiTypeStore(glslangElementType, elementRValue);
Expand All @@ -3655,7 +3646,7 @@ void TGlslangToSpvTraverser::multiTypeStore(const glslang::TType& type, spv::Id
// set up the target storage
builder.clearAccessChain();
builder.setAccessChainLValue(lValue);
builder.accessChainPush(builder.makeIntConstant(m), TranslateCoherent(type), getBufferReferenceAlignment(type));
builder.accessChainPush(builder.makeIntConstant(m), TranslateCoherent(type), type.getBufferReferenceAlignment());

// store the member
multiTypeStore(glslangMemberType, memberRValue);
Expand Down
10 changes: 10 additions & 0 deletions glslang/Include/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -2188,6 +2188,16 @@ class TType {
return ! operator==(right);
}

unsigned int getBufferReferenceAlignment() const
{
if (getBasicType() == glslang::EbtReference) {
return getReferentType()->getQualifier().hasBufferReferenceAlign() ?
(1u << getReferentType()->getQualifier().layoutBufferReferenceAlign) : 16u;
} else {
return 0;
}
}

protected:
// Require consumer to pick between deep copy and shallow copy.
TType(const TType& type);
Expand Down

0 comments on commit 40c16ec

Please sign in to comment.