GL_ARB_enhanced_layouts, part 2: Full implementation of location/component, plus the parsing for xfb* and align/offset (but not yet full semantics for align/offset).
git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@24692 e7fa87d3-cd2b-0410-9028-fcbf551c1848
This commit is contained in:
@@ -353,29 +353,55 @@ public:
|
||||
{
|
||||
layoutMatrix = ElmNone;
|
||||
layoutPacking = ElpNone;
|
||||
layoutOffset = -1;
|
||||
layoutAlign = -1;
|
||||
|
||||
layoutLocation = layoutLocationEnd;
|
||||
layoutComponent = layoutComponentEnd;
|
||||
layoutBinding = layoutBindingEnd;
|
||||
layoutStream = layoutStreamEnd;
|
||||
|
||||
layoutXfbBuffer = layoutXfbBufferEnd;
|
||||
layoutXfbStride = layoutXfbStrideEnd;
|
||||
layoutXfbOffset = layoutXfbOffsetEnd;
|
||||
}
|
||||
bool hasLayout() const
|
||||
{
|
||||
return layoutMatrix != ElmNone ||
|
||||
layoutPacking != ElpNone ||
|
||||
return hasUniformLayout() ||
|
||||
hasLocation() ||
|
||||
hasBinding() ||
|
||||
hasStream();
|
||||
hasStream() ||
|
||||
hasXfb();
|
||||
}
|
||||
TLayoutMatrix layoutMatrix : 3;
|
||||
TLayoutPacking layoutPacking : 4;
|
||||
int layoutOffset;
|
||||
int layoutAlign;
|
||||
unsigned int layoutLocation : 7;
|
||||
static const unsigned int layoutLocationEnd = 0x3F;
|
||||
unsigned int layoutComponent : 3;
|
||||
static const unsigned int layoutComponentEnd = 4;
|
||||
unsigned int layoutBinding : 8;
|
||||
static const unsigned int layoutBindingEnd = 0xFF;
|
||||
unsigned int layoutStream : 8;
|
||||
static const unsigned int layoutStreamEnd = 0xFF;
|
||||
unsigned int layoutXfbBuffer : 4;
|
||||
static const unsigned int layoutXfbBufferEnd = 0xF;
|
||||
unsigned int layoutXfbStride : 8;
|
||||
static const unsigned int layoutXfbStrideEnd = 0xFF;
|
||||
unsigned int layoutXfbOffset : 8;
|
||||
static const unsigned int layoutXfbOffsetEnd = 0xFF;
|
||||
bool hasUniformLayout() const
|
||||
{
|
||||
return layoutMatrix != ElmNone ||
|
||||
layoutPacking != ElpNone ||
|
||||
layoutOffset != -1 ||
|
||||
layoutAlign != -1;
|
||||
}
|
||||
TLayoutMatrix layoutMatrix : 3;
|
||||
TLayoutPacking layoutPacking : 4;
|
||||
unsigned int layoutLocation : 7; // ins/outs should have small numbers, buffer offsets could be large
|
||||
static const unsigned int layoutLocationEnd = 0x3F;
|
||||
unsigned int layoutBinding : 8;
|
||||
static const unsigned int layoutBindingEnd = 0xFF;
|
||||
unsigned int layoutStream : 8;
|
||||
static const unsigned int layoutStreamEnd = 0xFF;
|
||||
bool hasLocation() const
|
||||
{
|
||||
return layoutLocation != layoutLocationEnd;
|
||||
return layoutLocation != layoutLocationEnd ||
|
||||
layoutComponent != layoutComponentEnd;
|
||||
}
|
||||
bool hasBinding() const
|
||||
{
|
||||
@@ -385,6 +411,12 @@ public:
|
||||
{
|
||||
return layoutStream != layoutStreamEnd;
|
||||
}
|
||||
bool hasXfb() const
|
||||
{
|
||||
return layoutXfbBuffer != layoutXfbBufferEnd ||
|
||||
layoutXfbStride != layoutXfbStrideEnd ||
|
||||
layoutXfbOffset != layoutXfbOffsetEnd;
|
||||
}
|
||||
static const char* getLayoutPackingString(TLayoutPacking packing)
|
||||
{
|
||||
switch (packing) {
|
||||
@@ -824,8 +856,11 @@ public:
|
||||
|
||||
if (qualifier.hasLayout()) {
|
||||
p += snprintf(p, end - p, "layout(");
|
||||
if (qualifier.hasLocation())
|
||||
if (qualifier.hasLocation()) {
|
||||
p += snprintf(p, end - p, "location=%d ", qualifier.layoutLocation);
|
||||
if (qualifier.layoutComponent != qualifier.layoutComponentEnd)
|
||||
p += snprintf(p, end - p, "component=%d ", qualifier.layoutComponent);
|
||||
}
|
||||
if (qualifier.hasBinding())
|
||||
p += snprintf(p, end - p, "binding=%d ", qualifier.layoutBinding);
|
||||
if (qualifier.hasStream())
|
||||
@@ -834,6 +869,17 @@ public:
|
||||
p += snprintf(p, end - p, "%s ", TQualifier::getLayoutMatrixString(qualifier.layoutMatrix));
|
||||
if (qualifier.layoutPacking != ElpNone)
|
||||
p += snprintf(p, end - p, "%s ", TQualifier::getLayoutPackingString(qualifier.layoutPacking));
|
||||
if (qualifier.layoutOffset != -1)
|
||||
p += snprintf(p, end - p, "offset=%d ", qualifier.layoutOffset);
|
||||
if (qualifier.layoutAlign != -1)
|
||||
p += snprintf(p, end - p, "align=%d ", qualifier.layoutAlign);
|
||||
|
||||
if (qualifier.layoutXfbBuffer != qualifier.layoutXfbBufferEnd)
|
||||
p += snprintf(p, end - p, "xfb_buffer=%d ", qualifier.layoutXfbBuffer);
|
||||
if (qualifier.layoutXfbOffset != qualifier.layoutXfbOffsetEnd)
|
||||
p += snprintf(p, end - p, "xfb_offset=%d ", qualifier.layoutXfbOffset);
|
||||
if (qualifier.layoutXfbStride != qualifier.layoutXfbStrideEnd)
|
||||
p += snprintf(p, end - p, "xfb_stride=%d ", qualifier.layoutXfbStride);
|
||||
p += snprintf(p, end - p, ") ");
|
||||
}
|
||||
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
// source have to figure out how to create revision.h just to get a build
|
||||
// going. However, if it is not updated, it can be a version behind.
|
||||
|
||||
#define GLSLANG_REVISION "24674"
|
||||
#define GLSLANG_DATE "2014/01/07 10:44:41"
|
||||
#define GLSLANG_REVISION "24675"
|
||||
#define GLSLANG_DATE "2014/01/07 11:14:48"
|
||||
|
||||
@@ -101,6 +101,8 @@ TParseContext::TParseContext(TSymbolTable& symt, TIntermediate& interm, bool pb,
|
||||
globalBufferDefaults.layoutMatrix = ElmColumnMajor;
|
||||
globalBufferDefaults.layoutPacking = ElpShared;
|
||||
|
||||
// TODO: 4.4 enhanced layouts: defaults for xfb?
|
||||
|
||||
globalInputDefaults.clear();
|
||||
|
||||
globalOutputDefaults.clear();
|
||||
@@ -2429,7 +2431,7 @@ void TParseContext::redeclareBuiltinBlock(TSourceLoc loc, TTypeList& newTypeList
|
||||
symbolTable.insert(*block);
|
||||
|
||||
// Check for general layout qualifier errors
|
||||
layoutTypeCheck(loc, *block);
|
||||
layoutObjectCheck(loc, *block);
|
||||
|
||||
// Tracking for implicit sizing of array
|
||||
if (isIoResizeArray(block->getType())) {
|
||||
@@ -2829,7 +2831,20 @@ void TParseContext::setLayoutQualifier(TSourceLoc loc, TPublicType& publicType,
|
||||
}
|
||||
|
||||
std::transform(id.begin(), id.end(), id.begin(), ::tolower);
|
||||
if (id == "location") {
|
||||
|
||||
if (id == "offset") {
|
||||
const char* feature = "uniform buffer-member offset";
|
||||
requireProfile(loc, ECoreProfile | ECompatibilityProfile, feature);
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, GL_ARB_enhanced_layouts, feature);
|
||||
publicType.qualifier.layoutOffset = value;
|
||||
return;
|
||||
} else if (id == "align") {
|
||||
const char* feature = "uniform buffer-member align";
|
||||
requireProfile(loc, ECoreProfile | ECompatibilityProfile, feature);
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, GL_ARB_enhanced_layouts, feature);
|
||||
publicType.qualifier.layoutAlign = value;
|
||||
return;
|
||||
} else if (id == "location") {
|
||||
requireProfile(loc, EEsProfile | ECoreProfile | ECompatibilityProfile, "location");
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 330, 0, "location");
|
||||
if ((unsigned int)value >= TQualifier::layoutLocationEnd)
|
||||
@@ -2837,8 +2852,7 @@ void TParseContext::setLayoutQualifier(TSourceLoc loc, TPublicType& publicType,
|
||||
else
|
||||
publicType.qualifier.layoutLocation = value;
|
||||
return;
|
||||
}
|
||||
if (id == "binding") {
|
||||
} else if (id == "binding") {
|
||||
requireProfile(loc, ECoreProfile | ECompatibilityProfile, "binding");
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 420, GL_ARB_shading_language_420pack, "binding");
|
||||
if ((unsigned int)value >= TQualifier::layoutBindingEnd)
|
||||
@@ -2846,7 +2860,37 @@ void TParseContext::setLayoutQualifier(TSourceLoc loc, TPublicType& publicType,
|
||||
else
|
||||
publicType.qualifier.layoutBinding = value;
|
||||
return;
|
||||
} else if (id == "component") {
|
||||
requireProfile(loc, ECoreProfile | ECompatibilityProfile, "component");
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, GL_ARB_enhanced_layouts, "component");
|
||||
if ((unsigned)value >= TQualifier::layoutComponentEnd)
|
||||
error(loc, "component is too large", id.c_str(), "");
|
||||
else
|
||||
publicType.qualifier.layoutComponent = value;
|
||||
return;
|
||||
} else if (id.compare(0, 4, "xfb_") == 0) {
|
||||
const char* feature = "transform feedback qualifier";
|
||||
requireStage(loc, (EShLanguageMask)(EShLangVertexMask | EShLangGeometryMask | EShLangTessControlMask | EShLangTessEvaluationMask), feature);
|
||||
requireProfile(loc, ECoreProfile | ECompatibilityProfile, feature);
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, GL_ARB_enhanced_layouts, feature);
|
||||
if (id == "xfb_buffer") {
|
||||
if (value >= TQualifier::layoutXfbBufferEnd) // TODO: 4.4 enhanced layouts: also check against gl_MaxTransformFeedbackBuffers
|
||||
error(loc, "buffer is too large", id.c_str(), "");
|
||||
else
|
||||
publicType.qualifier.layoutXfbBuffer = value;
|
||||
} else if (id == "xfb_offset") {
|
||||
if (value >= TQualifier::layoutXfbOffsetEnd) // TODO: 4.4 enhanced layouts: also check against gl_MaxTransformFeedbackInterleavedComponents
|
||||
error(loc, "offset is too large", id.c_str(), "");
|
||||
else
|
||||
publicType.qualifier.layoutXfbOffset = value;
|
||||
} else if (id == "xfb_stride") {
|
||||
if (value >= TQualifier::layoutXfbStrideEnd) // TODO: 4.4 enhanced layouts: also check against gl_MaxTransformFeedbackInterleavedComponents
|
||||
error(loc, "stride is too large", id.c_str(), "");
|
||||
else
|
||||
publicType.qualifier.layoutXfbStride = value;
|
||||
}
|
||||
}
|
||||
|
||||
switch (language) {
|
||||
case EShLangVertex:
|
||||
break;
|
||||
@@ -2900,51 +2944,122 @@ void TParseContext::mergeObjectLayoutQualifiers(TSourceLoc loc, TQualifier& dst,
|
||||
if (src.layoutPacking != ElpNone)
|
||||
dst.layoutPacking = src.layoutPacking;
|
||||
|
||||
if (! inheritOnly) {
|
||||
if (src.hasLocation())
|
||||
dst.layoutLocation = src.layoutLocation;
|
||||
if (src.hasBinding())
|
||||
dst.layoutBinding = src.layoutBinding;
|
||||
}
|
||||
|
||||
if (src.hasStream())
|
||||
dst.layoutStream = src.layoutStream;
|
||||
|
||||
if (src.layoutXfbBuffer != TQualifier::layoutXfbBufferEnd)
|
||||
dst.layoutXfbBuffer = src.layoutXfbBuffer;
|
||||
|
||||
if (! inheritOnly) {
|
||||
if (src.layoutLocation != TQualifier::layoutLocationEnd)
|
||||
dst.layoutLocation = src.layoutLocation;
|
||||
if (src.layoutComponent != TQualifier::layoutComponentEnd)
|
||||
dst.layoutComponent = src.layoutComponent;
|
||||
|
||||
if (src.layoutOffset != -1)
|
||||
dst.layoutOffset = src.layoutOffset;
|
||||
if (src.layoutAlign != -1)
|
||||
dst.layoutAlign = src.layoutAlign;
|
||||
|
||||
if (src.layoutBinding != TQualifier::layoutBindingEnd)
|
||||
dst.layoutBinding = src.layoutBinding;
|
||||
|
||||
if (src.layoutXfbStride != TQualifier::layoutXfbStrideEnd)
|
||||
dst.layoutXfbStride = src.layoutXfbStride;
|
||||
if (src.layoutXfbOffset != TQualifier::layoutXfbOffsetEnd)
|
||||
dst.layoutXfbOffset = src.layoutXfbOffset;
|
||||
}
|
||||
}
|
||||
|
||||
// Do error layout error checking given a full variable/block declaration.
|
||||
void TParseContext::layoutTypeCheck(TSourceLoc loc, const TSymbol& symbol)
|
||||
void TParseContext::layoutObjectCheck(TSourceLoc loc, const TSymbol& symbol)
|
||||
{
|
||||
const TType& type = symbol.getType();
|
||||
const TQualifier& qualifier = type.getQualifier();
|
||||
|
||||
// first, qualifier only error checking
|
||||
// first, cross check WRT to just the type
|
||||
layoutTypeCheck(loc, type);
|
||||
|
||||
// now, any remaining error checking based on the object itself
|
||||
|
||||
if (qualifier.hasLocation()) {
|
||||
switch (qualifier.storage) {
|
||||
case EvqUniform:
|
||||
case EvqBuffer:
|
||||
if (symbol.getAsVariable() == 0)
|
||||
error(loc, "can only be used on variable declaration", "location", "");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Check packing and matrix
|
||||
// TODO: 4.4 enhanced layouts: generalize to include offset/align
|
||||
if (qualifier.layoutMatrix || qualifier.layoutPacking) {
|
||||
switch (qualifier.storage) {
|
||||
case EvqBuffer:
|
||||
case EvqUniform:
|
||||
if (type.getBasicType() != EbtBlock) {
|
||||
if (qualifier.layoutMatrix != ElmNone)
|
||||
error(loc, "cannot specify matrix layout on a variable declaration", "layout", "");
|
||||
if (qualifier.layoutPacking != ElpNone)
|
||||
error(loc, "cannot specify packing on a variable declaration", "layout", "");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (type.getBasicType() != EbtBlock && symbol.getAsVariable()) {
|
||||
if (qualifier.layoutMatrix != ElmNone ||
|
||||
qualifier.layoutPacking != ElpNone)
|
||||
error(loc, "qualifiers for matrix layout and block packing only apply to uniform or buffer blocks", "layout", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do error layout error checking with respect to a type.
|
||||
void TParseContext::layoutTypeCheck(TSourceLoc loc, const TType& type)
|
||||
{
|
||||
const TQualifier& qualifier = type.getQualifier();
|
||||
|
||||
// first, intra layout qualifier-only error checking
|
||||
layoutQualifierCheck(loc, qualifier);
|
||||
|
||||
// now, error checking combining type and qualifier
|
||||
|
||||
if (qualifier.hasLocation()) {
|
||||
if (qualifier.layoutComponent != TQualifier::layoutComponentEnd) {
|
||||
// "It is a compile-time error if this sequence of components gets larger than 3."
|
||||
if (qualifier.layoutComponent + type.getVectorSize() > 4)
|
||||
error(loc, "type overflows the available 4 components", "component", "");
|
||||
|
||||
// "It is a compile-time error to apply the component qualifier to a matrix, a structure, a block, or an array containing any of these."
|
||||
if (type.isMatrix() || type.getBasicType() == EbtBlock || type.getBasicType() == EbtStruct)
|
||||
error(loc, "cannot apply to a matrix, structure, or block", "component", "");
|
||||
}
|
||||
|
||||
switch (qualifier.storage) {
|
||||
case EvqVaryingIn:
|
||||
case EvqVaryingOut:
|
||||
if (type.getBasicType() == EbtBlock)
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, 0 /* TODO ARB_enhanced_layouts*/, "location qualifier on in/out block");
|
||||
profileRequires(loc, ECoreProfile | ECompatibilityProfile, 440, GL_ARB_enhanced_layouts, "location qualifier on in/out block");
|
||||
break;
|
||||
case EvqUniform:
|
||||
case EvqBuffer:
|
||||
{
|
||||
const char* feature = "location qualifier on uniform or buffer";
|
||||
if (symbol.getAsVariable() == 0)
|
||||
error(loc, "can only be used on variable declaration", feature, "");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
error(loc, "location qualifiers only appy to uniform, buffer, in, or out storage qualifiers", symbol.getName().c_str(), "");
|
||||
error(loc, "can only appy to uniform, buffer, in, or out storage qualifiers", "location", "");
|
||||
break;
|
||||
}
|
||||
|
||||
int repeated = intermediate.addUsedLocation(qualifier, type);
|
||||
if (repeated >= 0)
|
||||
error(loc, "repeated use of location", "location", "%d", repeated);
|
||||
bool typeCollision;
|
||||
int repeated = intermediate.addUsedLocation(qualifier, type, typeCollision);
|
||||
if (repeated >= 0 && ! typeCollision)
|
||||
error(loc, "overlapping use of location", "location", "%d", repeated);
|
||||
// "fragment-shader outputs ... if two variables are placed within the same
|
||||
// location, they must have the same underlying type (floating-point or integer)"
|
||||
if (typeCollision && language == EShLangFragment && qualifier.isPipeOutput())
|
||||
error(loc, "fragment outputs sharing the same location must be the same basic type", "location", "%d", repeated);
|
||||
}
|
||||
|
||||
if (qualifier.hasBinding()) {
|
||||
@@ -2967,34 +3082,22 @@ void TParseContext::layoutTypeCheck(TSourceLoc loc, const TSymbol& symbol)
|
||||
error(loc, "sampler binding not less than gl_MaxCombinedTextureImageUnits", "binding", type.isArray() ? "(using array)" : "");
|
||||
}
|
||||
}
|
||||
|
||||
// Check packing and matrix
|
||||
if (qualifier.layoutMatrix || qualifier.layoutPacking) {
|
||||
switch (qualifier.storage) {
|
||||
case EvqBuffer:
|
||||
case EvqUniform:
|
||||
if (symbol.getType().getBasicType() != EbtBlock) {
|
||||
if (qualifier.layoutMatrix != ElmNone)
|
||||
error(loc, "cannot specify matrix layout on a variable declaration", symbol.getName().c_str(), "");
|
||||
if (qualifier.layoutPacking != ElpNone)
|
||||
error(loc, "cannot specify packing on a variable declaration", symbol.getName().c_str(), "");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (symbol.getType().getBasicType() != EbtBlock && symbol.getAsVariable()) {
|
||||
if (qualifier.layoutMatrix != ElmNone ||
|
||||
qualifier.layoutPacking != ElpNone)
|
||||
error(loc, "layout qualifiers for matrix layout and packing only apply to uniform or buffer blocks", symbol.getName().c_str(), "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do layout error checking that can be done within a qualifier proper, not needing to know
|
||||
// if there are blocks, atomic counters, variables, etc.
|
||||
void TParseContext::layoutQualifierCheck(TSourceLoc loc, const TQualifier& qualifier)
|
||||
{
|
||||
// "It is a compile-time error to use *component* without also specifying the location qualifier (order does not matter)."
|
||||
if (qualifier.layoutComponent != TQualifier::layoutComponentEnd && qualifier.layoutLocation == TQualifier::layoutLocationEnd)
|
||||
error(loc, "must specify 'location' to use 'component'", "component", "");
|
||||
|
||||
if (qualifier.hasLocation()) {
|
||||
|
||||
// "As with input layout qualifiers, all shaders except compute shaders
|
||||
// allow *location* layout qualifiers on output variable declarations,
|
||||
// output block declarations, and output block member declarations."
|
||||
|
||||
switch (qualifier.storage) {
|
||||
case EvqVaryingIn:
|
||||
{
|
||||
@@ -3257,7 +3360,7 @@ TIntermNode* TParseContext::declareVariable(TSourceLoc loc, TString& identifier,
|
||||
}
|
||||
|
||||
// look for errors/adjustments in layout qualifier use
|
||||
layoutTypeCheck(loc, *symbol);
|
||||
layoutObjectCheck(loc, *symbol);
|
||||
|
||||
// see if it's a linker-level object to track
|
||||
if (newDeclaration && symbolTable.atGlobalLevel())
|
||||
@@ -3710,7 +3813,10 @@ void TParseContext::declareBlock(TSourceLoc loc, TTypeList& typeList, const TStr
|
||||
}
|
||||
|
||||
// fix and check for member layout qualifiers
|
||||
// TODO: 4.4 enhanced layouts: generalize to include offset/align
|
||||
mergeObjectLayoutQualifiers(loc, defaultQualification, currentBlockQualifier, true);
|
||||
bool memberWithLocation = false;
|
||||
bool memberWithoutLocation = false;
|
||||
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
||||
TQualifier& memberQualifier = typeList[member].type->getQualifier();
|
||||
TSourceLoc memberLoc = typeList[member].loc;
|
||||
@@ -3720,10 +3826,28 @@ void TParseContext::declareBlock(TSourceLoc loc, TTypeList& typeList, const TStr
|
||||
}
|
||||
if (memberQualifier.layoutPacking != ElpNone)
|
||||
error(memberLoc, "member of block cannot have a packing layout qualifier", typeList[member].type->getFieldName().c_str(), "");
|
||||
if (memberQualifier.hasLocation()) {
|
||||
const char* feature = "location on block member";
|
||||
switch (currentBlockQualifier.storage) {
|
||||
case EvqVaryingIn:
|
||||
case EvqVaryingOut:
|
||||
requireProfile(memberLoc, ECoreProfile | ECompatibilityProfile, feature);
|
||||
profileRequires(memberLoc, ECoreProfile | ECompatibilityProfile, 440, GL_ARB_enhanced_layouts, feature);
|
||||
memberWithLocation = true;
|
||||
break;
|
||||
default:
|
||||
error(memberLoc, "can only use in an in/out block", feature, "");
|
||||
break;
|
||||
}
|
||||
} else
|
||||
memberWithoutLocation = true;
|
||||
TQualifier newMemberQualification = defaultQualification;
|
||||
mergeQualifiers(memberLoc, newMemberQualification, memberQualifier, false);
|
||||
memberQualifier = newMemberQualification;
|
||||
}
|
||||
fixBlockLocations(loc, currentBlockQualifier, typeList, memberWithLocation, memberWithoutLocation);
|
||||
for (unsigned int member = 0; member < typeList.size(); ++member)
|
||||
layoutTypeCheck(typeList[member].loc, *typeList[member].type);
|
||||
|
||||
// reverse merge, so that currentBlockQualifier now has all layout information
|
||||
// (can't use defaultQualification directly, it's missing other non-layout-default-class qualifiers)
|
||||
@@ -3783,7 +3907,7 @@ void TParseContext::declareBlock(TSourceLoc loc, TTypeList& typeList, const TStr
|
||||
}
|
||||
|
||||
// Check for general layout qualifier errors
|
||||
layoutTypeCheck(loc, variable);
|
||||
layoutObjectCheck(loc, variable);
|
||||
|
||||
if (isIoResizeArray(blockType)) {
|
||||
ioArraySymbolResizeList.push_back(&variable);
|
||||
@@ -3795,6 +3919,46 @@ void TParseContext::declareBlock(TSourceLoc loc, TTypeList& typeList, const TStr
|
||||
intermediate.addSymbolLinkageNode(linkage, variable);
|
||||
}
|
||||
|
||||
//
|
||||
// "For a block, this process applies to the entire block, or until the first member
|
||||
// is reached that has a location layout qualifier. When a block member is declared with a location
|
||||
// qualifier, its location comes from that qualifier: The member's location qualifier overrides the block-level
|
||||
// declaration. Subsequent members are again assigned consecutive locations, based on the newest location,
|
||||
// until the next member declared with a location qualifier. The values used for locations do not have to be
|
||||
// declared in increasing order."
|
||||
void TParseContext::fixBlockLocations(TSourceLoc loc, TQualifier& qualifier, TTypeList& typeList, bool memberWithLocation, bool memberWithoutLocation)
|
||||
{
|
||||
// "If a block has no block-level location layout qualifier, it is required that either all or none of its members
|
||||
// have a location layout qualifier, or a compile-time error results."
|
||||
if (! qualifier.hasLocation() && memberWithLocation && memberWithoutLocation)
|
||||
error(loc, "either the block needs a location, or all members need a location, or no members have a location", "location", "");
|
||||
else {
|
||||
if (memberWithLocation) {
|
||||
// remove any block-level location and make it per *every* member
|
||||
int nextLocation; // by the rule above, initial value is not relevant
|
||||
if (qualifier.hasLocation()) {
|
||||
nextLocation = qualifier.layoutLocation;
|
||||
qualifier.layoutLocation = TQualifier::layoutLocationEnd;
|
||||
if (qualifier.layoutComponent != TQualifier::layoutComponentEnd) {
|
||||
// "It is a compile-time error to apply the *component* qualifier to a ... block"
|
||||
error(loc, "cannot apply to a block", "component", "");
|
||||
}
|
||||
}
|
||||
for (unsigned int member = 0; member < typeList.size(); ++member) {
|
||||
TQualifier& memberQualifier = typeList[member].type->getQualifier();
|
||||
TSourceLoc memberLoc = typeList[member].loc;
|
||||
if (! memberQualifier.hasLocation()) {
|
||||
if (nextLocation >= TQualifier::layoutLocationEnd)
|
||||
error(memberLoc, "location is too large", "location", "");
|
||||
memberQualifier.layoutLocation = nextLocation;
|
||||
memberQualifier.layoutComponent = 0;
|
||||
}
|
||||
nextLocation = memberQualifier.layoutLocation + intermediate.computeTypeLocationSize(*typeList[member].type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For an identifier that is already declared, add more qualification to it.
|
||||
void TParseContext::addQualifierToExisting(TSourceLoc loc, TQualifier qualifier, const TString& identifier)
|
||||
{
|
||||
@@ -3941,6 +4105,7 @@ void TParseContext::updateStandaloneQualifierDefaults(TSourceLoc loc, const TPub
|
||||
|
||||
layoutQualifierCheck(loc, qualifier);
|
||||
|
||||
// TODO: 4.4 enhanced layouts: generalize to include all new ones
|
||||
switch (qualifier.storage) {
|
||||
case EvqUniform:
|
||||
if (qualifier.layoutMatrix != ElmNone)
|
||||
|
||||
@@ -150,7 +150,8 @@ public:
|
||||
void setLayoutQualifier(TSourceLoc, TPublicType&, TString&);
|
||||
void setLayoutQualifier(TSourceLoc, TPublicType&, TString&, const TIntermTyped*);
|
||||
void mergeObjectLayoutQualifiers(TSourceLoc, TQualifier& dest, const TQualifier& src, bool inheritOnly);
|
||||
void layoutTypeCheck(TSourceLoc, const TSymbol&);
|
||||
void layoutObjectCheck(TSourceLoc, const TSymbol&);
|
||||
void layoutTypeCheck(TSourceLoc, const TType&);
|
||||
void layoutQualifierCheck(TSourceLoc, const TQualifier&);
|
||||
void checkNoShaderLayouts(TSourceLoc, const TShaderQualifiers&);
|
||||
|
||||
@@ -163,6 +164,7 @@ public:
|
||||
TIntermTyped* constructStruct(TIntermNode*, const TType&, int, TSourceLoc);
|
||||
TIntermTyped* constructBuiltIn(const TType&, TOperator, TIntermNode*, TSourceLoc, bool subset);
|
||||
void declareBlock(TSourceLoc, TTypeList& typeList, const TString* instanceName = 0, TArraySizes* arraySizes = 0);
|
||||
void fixBlockLocations(TSourceLoc, TQualifier&, TTypeList&, bool memberWithLocation, bool memberWithoutLocation);
|
||||
void addQualifierToExisting(TSourceLoc, TQualifier, const TString& identifier);
|
||||
void addQualifierToExisting(TSourceLoc, TQualifier, TIdentifierList&);
|
||||
void invariantCheck(TSourceLoc, const TType&, const TString& identifier);
|
||||
|
||||
@@ -252,7 +252,8 @@ void TIntermediate::mergeErrorCheck(TInfoSink& infoSink, const TIntermSymbol& sy
|
||||
writeTypeComparison = true;
|
||||
}
|
||||
|
||||
// Layouts...
|
||||
// Layouts...
|
||||
// TODO: 4.4 enhanced layouts: generalize to include offset/align
|
||||
if (symbol.getQualifier().layoutMatrix != unitSymbol.getQualifier().layoutMatrix ||
|
||||
symbol.getQualifier().layoutPacking != unitSymbol.getQualifier().layoutPacking ||
|
||||
symbol.getQualifier().layoutLocation != unitSymbol.getQualifier().layoutLocation ||
|
||||
@@ -481,8 +482,14 @@ bool TIntermediate::userOutputUsed() const
|
||||
// as the accumulation is done.
|
||||
//
|
||||
// Returns < 0 if no collision, >= 0 if collision and the value returned is a colliding value.
|
||||
int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& type)
|
||||
//
|
||||
// typeCollision is set to true if there is no direct collision, but the types in the same location
|
||||
// are different.
|
||||
//
|
||||
int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& type, bool& typeCollision)
|
||||
{
|
||||
typeCollision = false;
|
||||
|
||||
int set;
|
||||
if (qualifier.isPipeInput())
|
||||
set = 0;
|
||||
@@ -510,20 +517,34 @@ int TIntermediate::addUsedLocation(const TQualifier& qualifier, const TType& typ
|
||||
size = computeTypeLocationSize(type);
|
||||
}
|
||||
|
||||
TRange range = { qualifier.layoutLocation, qualifier.layoutLocation + size - 1 };
|
||||
TRange locationRange = { qualifier.layoutLocation, qualifier.layoutLocation + size - 1 };
|
||||
TRange componentRange = { 0, 3 };
|
||||
if (qualifier.layoutComponent != TQualifier::layoutComponentEnd) {
|
||||
componentRange.start = qualifier.layoutComponent;
|
||||
componentRange.last = componentRange.start + type.getVectorSize() - 1;
|
||||
}
|
||||
|
||||
// check for collisions, except for vertex inputs on desktop
|
||||
if (! (profile != EEsProfile && language == EShLangVertex && qualifier.isPipeInput())) {
|
||||
for (size_t r = 0; r < usedLocations[set].size(); ++r) {
|
||||
if (range.last >= usedLocations[set][r].start &&
|
||||
range.start <= usedLocations[set][r].last) {
|
||||
for (size_t r = 0; r < usedIo[set].size(); ++r) {
|
||||
if (locationRange.last >= usedIo[set][r].location.start &&
|
||||
locationRange.start <= usedIo[set][r].location.last &&
|
||||
componentRange.last >= usedIo[set][r].component.start &&
|
||||
componentRange.start <= usedIo[set][r].component.last) {
|
||||
// there is a collision; pick one
|
||||
return std::max(range.start, usedLocations[set][r].start);
|
||||
return std::max(locationRange.start, usedIo[set][r].location.start);
|
||||
} else if (locationRange.last >= usedIo[set][r].location.start &&
|
||||
locationRange.start <= usedIo[set][r].location.last &&
|
||||
type.getBasicType() != usedIo[set][r].basicType) {
|
||||
typeCollision = true;
|
||||
return std::max(locationRange.start, usedIo[set][r].location.start);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usedLocations[set].push_back(range);
|
||||
TIoRange range = { locationRange, componentRange, type.getBasicType() };
|
||||
|
||||
usedIo[set].push_back(range);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@@ -546,7 +567,6 @@ int TIntermediate::computeTypeLocationSize(const TType& type)
|
||||
// "The locations consumed by block and structure members are determined by applying the rules above
|
||||
// recursively..."
|
||||
if (type.isStruct()) {
|
||||
// TODO: 440 functionality: input/output block locations when members also have locations
|
||||
int size = 0;
|
||||
for (size_t member = 0; member < type.getStruct()->size(); ++member) {
|
||||
TType memberType(type, member);
|
||||
|
||||
@@ -172,7 +172,8 @@ public:
|
||||
void addIoAccessed(const TString& name) { ioAccessed.insert(name); }
|
||||
bool inIoAccessed(const TString& name) const { return ioAccessed.find(name) != ioAccessed.end(); }
|
||||
|
||||
int addUsedLocation(const TQualifier&, const TType&);
|
||||
int addUsedLocation(const TQualifier&, const TType&, bool& typeCollision);
|
||||
int computeTypeLocationSize(const TType&);
|
||||
|
||||
protected:
|
||||
void error(TInfoSink& infoSink, const char*);
|
||||
@@ -183,7 +184,6 @@ protected:
|
||||
void inOutLocationCheck(TInfoSink&);
|
||||
TIntermSequence& findLinkerObjects() const;
|
||||
bool userOutputUsed() const;
|
||||
int computeTypeLocationSize(const TType&);
|
||||
|
||||
protected:
|
||||
const EShLanguage language;
|
||||
@@ -217,11 +217,19 @@ protected:
|
||||
|
||||
std::set<TString> ioAccessed; // set of names of statically read/written I/O that might need extra checking
|
||||
|
||||
// A location range is a 2-D rectangle; the set of (location, component) pairs all lying
|
||||
// both within the location range and the component range.
|
||||
// The following are entirely encapsulated by addUsedLocation().
|
||||
struct TRange {
|
||||
int start;
|
||||
int last;
|
||||
};
|
||||
std::vector<TRange> usedLocations[3]; // sets of used locations, one for each of in, out, and uniform
|
||||
struct TIoRange {
|
||||
TRange location;
|
||||
TRange component;
|
||||
TBasicType basicType;
|
||||
};
|
||||
std::vector<TIoRange> usedIo[3]; // sets of used locations, one for each of in, out, and uniform
|
||||
|
||||
private:
|
||||
void operator=(TIntermediate&); // prevent assignments
|
||||
|
||||
Reference in New Issue
Block a user