diff options
Diffstat (limited to '3rdparty/bgfx/3rdparty/glslang/glslang/Include/Types.h')
-rw-r--r-- | 3rdparty/bgfx/3rdparty/glslang/glslang/Include/Types.h | 372 |
1 files changed, 234 insertions, 138 deletions
diff --git a/3rdparty/bgfx/3rdparty/glslang/glslang/Include/Types.h b/3rdparty/bgfx/3rdparty/glslang/glslang/Include/Types.h index 6fce15ec3fa..2207d0b3f95 100644 --- a/3rdparty/bgfx/3rdparty/glslang/glslang/Include/Types.h +++ b/3rdparty/bgfx/3rdparty/glslang/glslang/Include/Types.h @@ -188,6 +188,8 @@ struct TSampler { // misnomer now; includes images, textures without sampler, case EbtFloat: break; case EbtInt: s.append("i"); break; case EbtUint: s.append("u"); break; + case EbtInt64: s.append("i64"); break; + case EbtUint64: s.append("u64"); break; default: break; // some compilers want this } if (image) { @@ -401,8 +403,24 @@ public: // drop qualifiers that don't belong in a temporary variable void makeTemporary() { - storage = EvqTemporary; - builtIn = EbvNone; + semanticName = nullptr; + storage = EvqTemporary; + builtIn = EbvNone; + clearInterstage(); + clearMemory(); + specConstant = false; + clearLayout(); + } + + void clearInterstage() + { + clearInterpolation(); + patch = false; + sample = false; + } + + void clearInterpolation() + { centroid = false; smooth = false; flat = false; @@ -410,15 +428,15 @@ public: #ifdef AMD_EXTENSIONS explicitInterp = false; #endif - patch = false; - sample = false; + } + + void clearMemory() + { coherent = false; volatil = false; restrict = false; readonly = false; writeonly = false; - specConstant = false; - clearLayout(); } // Drop just the storage qualification, which perhaps should @@ -434,6 +452,7 @@ public: specConstant = false; } + const char* semanticName; TStorageQualifier storage : 6; TBuiltInVariable builtIn : 8; TPrecisionQualifier precision : 3; @@ -575,42 +594,47 @@ public: } // Implementing an embedded layout-qualifier class here, since C++ can't have a real class bitfield - void clearLayout() + void clearLayout() // all layout { - layoutMatrix = ElmNone; - layoutPacking = ElpNone; - layoutOffset = layoutNotSet; - layoutAlign = layoutNotSet; + clearUniformLayout(); + layoutPushConstant = false; +#ifdef NV_EXTENSIONS + layoutPassthrough = false; + layoutViewportRelative = false; + // -2048 as the default value indicating layoutSecondaryViewportRelative is not set + layoutSecondaryViewportRelativeOffset = -2048; +#endif + + clearInterstageLayout(); + + layoutSpecConstantId = layoutSpecConstantIdEnd; + + layoutFormat = ElfNone; + } + void clearInterstageLayout() + { layoutLocation = layoutLocationEnd; layoutComponent = layoutComponentEnd; - layoutSet = layoutSetEnd; - layoutBinding = layoutBindingEnd; layoutIndex = layoutIndexEnd; - + clearStreamLayout(); + clearXfbLayout(); + } + void clearStreamLayout() + { layoutStream = layoutStreamEnd; - + } + void clearXfbLayout() + { layoutXfbBuffer = layoutXfbBufferEnd; layoutXfbStride = layoutXfbStrideEnd; layoutXfbOffset = layoutXfbOffsetEnd; - layoutAttachment = layoutAttachmentEnd; - layoutSpecConstantId = layoutSpecConstantIdEnd; - - layoutFormat = ElfNone; - - layoutPushConstant = false; -#ifdef NV_EXTENSIONS - layoutPassthrough = false; - layoutViewportRelative = false; - // -2048 as the default vaule indicating layoutSecondaryViewportRelative is not set - layoutSecondaryViewportRelativeOffset = -2048; -#endif } + bool hasLayout() const { return hasUniformLayout() || hasAnyLocation() || - hasBinding() || hasStream() || hasXfb() || hasFormat() || @@ -670,8 +694,21 @@ public: hasPacking() || hasOffset() || hasBinding() || + hasSet() || hasAlign(); } + void clearUniformLayout() // only uniform specific + { + layoutMatrix = ElmNone; + layoutPacking = ElpNone; + layoutOffset = layoutNotSet; + layoutAlign = layoutNotSet; + + layoutSet = layoutSetEnd; + layoutBinding = layoutBindingEnd; + layoutAttachment = layoutAttachmentEnd; + } + bool hasMatrix() const { return layoutMatrix != ElmNone; @@ -1202,30 +1239,11 @@ public: typeName = copyOf.typeName; } + // Make complete copy of the whole type graph rooted at 'copyOf'. void deepCopy(const TType& copyOf) { - shallowCopy(copyOf); - - if (copyOf.arraySizes) { - arraySizes = new TArraySizes; - *arraySizes = *copyOf.arraySizes; - } - - if (copyOf.structure) { - structure = new TTypeList; - for (unsigned int i = 0; i < copyOf.structure->size(); ++i) { - TTypeLoc typeLoc; - typeLoc.loc = (*copyOf.structure)[i].loc; - typeLoc.type = new TType(); - typeLoc.type->deepCopy(*(*copyOf.structure)[i].type); - structure->push_back(typeLoc); - } - } - - if (copyOf.fieldName) - fieldName = NewPoolTString(copyOf.fieldName->c_str()); - if (copyOf.typeName) - typeName = NewPoolTString(copyOf.typeName->c_str()); + TMap<TTypeList*,TTypeList*> copied; // to enable copying a type graph as a graph, not a tree + deepCopy(copyOf, copied); } // Recursively make temporary @@ -1346,6 +1364,8 @@ public: case EbvViewportMaskNV: case EbvSecondaryPositionNV: case EbvSecondaryViewportMaskNV: + case EbvPositionPerViewNV: + case EbvViewportMaskPerViewNV: #endif return true; default: @@ -1564,10 +1584,11 @@ public: TString getCompleteString() const { - const int maxSize = GlslangMaxTypeLength; - char buf[maxSize]; - char* p = &buf[0]; - char* end = &buf[maxSize]; + TString typeString; + + const auto appendStr = [&](const char* s) { typeString.append(s); }; + const auto appendUint = [&](unsigned int u) { typeString.append(std::to_string(u).c_str()); }; + const auto appendInt = [&](int i) { typeString.append(std::to_string(i).c_str()); }; if (qualifier.hasLayout()) { // To reduce noise, skip this if the only layout is an xfb_buffer @@ -1575,137 +1596,175 @@ public: TQualifier noXfbBuffer = qualifier; noXfbBuffer.layoutXfbBuffer = TQualifier::layoutXfbBufferEnd; if (noXfbBuffer.hasLayout()) { - p += snprintf(p, end - p, "layout("); + appendStr("layout("); if (qualifier.hasAnyLocation()) { - p += snprintf(p, end - p, "location=%d ", qualifier.layoutLocation); - if (qualifier.hasComponent()) - p += snprintf(p, end - p, "component=%d ", qualifier.layoutComponent); - if (qualifier.hasIndex()) - p += snprintf(p, end - p, "index=%d ", qualifier.layoutIndex); + appendStr(" location="); + appendUint(qualifier.layoutLocation); + if (qualifier.hasComponent()) { + appendStr(" component="); + appendUint(qualifier.layoutComponent); + } + if (qualifier.hasIndex()) { + appendStr(" index="); + appendUint(qualifier.layoutIndex); + } + } + if (qualifier.hasSet()) { + appendStr(" set="); + appendUint(qualifier.layoutSet); + } + if (qualifier.hasBinding()) { + appendStr(" binding="); + appendUint(qualifier.layoutBinding); + } + if (qualifier.hasStream()) { + appendStr(" stream="); + appendUint(qualifier.layoutStream); + } + if (qualifier.hasMatrix()) { + appendStr(" "); + appendStr(TQualifier::getLayoutMatrixString(qualifier.layoutMatrix)); + } + if (qualifier.hasPacking()) { + appendStr(" "); + appendStr(TQualifier::getLayoutPackingString(qualifier.layoutPacking)); + } + if (qualifier.hasOffset()) { + appendStr(" offset="); + appendInt(qualifier.layoutOffset); + } + if (qualifier.hasAlign()) { + appendStr(" align="); + appendInt(qualifier.layoutAlign); + } + if (qualifier.hasFormat()) { + appendStr(" "); + appendStr(TQualifier::getLayoutFormatString(qualifier.layoutFormat)); + } + if (qualifier.hasXfbBuffer() && qualifier.hasXfbOffset()) { + appendStr(" xfb_buffer="); + appendUint(qualifier.layoutXfbBuffer); + } + if (qualifier.hasXfbOffset()) { + appendStr(" xfb_offset="); + appendUint(qualifier.layoutXfbOffset); + } + if (qualifier.hasXfbStride()) { + appendStr(" xfb_stride="); + appendUint(qualifier.layoutXfbStride); + } + if (qualifier.hasAttachment()) { + appendStr(" input_attachment_index="); + appendUint(qualifier.layoutAttachment); + } + if (qualifier.hasSpecConstantId()) { + appendStr(" constant_id="); + appendUint(qualifier.layoutSpecConstantId); } - if (qualifier.hasSet()) - p += snprintf(p, end - p, "set=%d ", qualifier.layoutSet); - if (qualifier.hasBinding()) - p += snprintf(p, end - p, "binding=%d ", qualifier.layoutBinding); - if (qualifier.hasStream()) - p += snprintf(p, end - p, "stream=%d ", qualifier.layoutStream); - if (qualifier.hasMatrix()) - p += snprintf(p, end - p, "%s ", TQualifier::getLayoutMatrixString(qualifier.layoutMatrix)); - if (qualifier.hasPacking()) - p += snprintf(p, end - p, "%s ", TQualifier::getLayoutPackingString(qualifier.layoutPacking)); - if (qualifier.hasOffset()) - p += snprintf(p, end - p, "offset=%d ", qualifier.layoutOffset); - if (qualifier.hasAlign()) - p += snprintf(p, end - p, "align=%d ", qualifier.layoutAlign); - if (qualifier.hasFormat()) - p += snprintf(p, end - p, "%s ", TQualifier::getLayoutFormatString(qualifier.layoutFormat)); - if (qualifier.hasXfbBuffer() && qualifier.hasXfbOffset()) - p += snprintf(p, end - p, "xfb_buffer=%d ", qualifier.layoutXfbBuffer); - if (qualifier.hasXfbOffset()) - p += snprintf(p, end - p, "xfb_offset=%d ", qualifier.layoutXfbOffset); - if (qualifier.hasXfbStride()) - p += snprintf(p, end - p, "xfb_stride=%d ", qualifier.layoutXfbStride); - if (qualifier.hasAttachment()) - p += snprintf(p, end - p, "input_attachment_index=%d ", qualifier.layoutAttachment); - if (qualifier.hasSpecConstantId()) - p += snprintf(p, end - p, "constant_id=%d ", qualifier.layoutSpecConstantId); if (qualifier.layoutPushConstant) - p += snprintf(p, end - p, "push_constant "); + appendStr(" push_constant"); #ifdef NV_EXTENSIONS if (qualifier.layoutPassthrough) - p += snprintf(p, end - p, "passthrough "); + appendStr(" passthrough"); if (qualifier.layoutViewportRelative) - p += snprintf(p, end - p, "layoutViewportRelative "); - if (qualifier.layoutSecondaryViewportRelativeOffset != -2048) - p += snprintf(p, end - p, "layoutSecondaryViewportRelativeOffset=%d ", qualifier.layoutSecondaryViewportRelativeOffset); + appendStr(" layoutViewportRelative"); + if (qualifier.layoutSecondaryViewportRelativeOffset != -2048) { + appendStr(" layoutSecondaryViewportRelativeOffset="); + appendInt(qualifier.layoutSecondaryViewportRelativeOffset); + } #endif - p += snprintf(p, end - p, ") "); + appendStr(")"); } } if (qualifier.invariant) - p += snprintf(p, end - p, "invariant "); + appendStr(" invariant"); if (qualifier.noContraction) - p += snprintf(p, end - p, "noContraction "); + appendStr(" noContraction"); if (qualifier.centroid) - p += snprintf(p, end - p, "centroid "); + appendStr(" centroid"); if (qualifier.smooth) - p += snprintf(p, end - p, "smooth "); + appendStr(" smooth"); if (qualifier.flat) - p += snprintf(p, end - p, "flat "); + appendStr(" flat"); if (qualifier.nopersp) - p += snprintf(p, end - p, "noperspective "); + appendStr(" noperspective"); #ifdef AMD_EXTENSIONS if (qualifier.explicitInterp) - p += snprintf(p, end - p, "__explicitInterpAMD "); + appendStr(" __explicitInterpAMD"); #endif if (qualifier.patch) - p += snprintf(p, end - p, "patch "); + appendStr(" patch"); if (qualifier.sample) - p += snprintf(p, end - p, "sample "); + appendStr(" sample"); if (qualifier.coherent) - p += snprintf(p, end - p, "coherent "); + appendStr(" coherent"); if (qualifier.volatil) - p += snprintf(p, end - p, "volatile "); + appendStr(" volatile"); if (qualifier.restrict) - p += snprintf(p, end - p, "restrict "); + appendStr(" restrict"); if (qualifier.readonly) - p += snprintf(p, end - p, "readonly "); + appendStr(" readonly"); if (qualifier.writeonly) - p += snprintf(p, end - p, "writeonly "); + appendStr(" writeonly"); if (qualifier.specConstant) - p += snprintf(p, end - p, "specialization-constant "); - p += snprintf(p, end - p, "%s ", getStorageQualifierString()); + appendStr(" specialization-constant"); + appendStr(" "); + appendStr(getStorageQualifierString()); if (isArray()) { for(int i = 0; i < (int)arraySizes->getNumDims(); ++i) { int size = arraySizes->getDimSize(i); if (size == 0) - p += snprintf(p, end - p, "implicitly-sized array of "); - else - p += snprintf(p, end - p, "%d-element array of ", arraySizes->getDimSize(i)); + appendStr(" implicitly-sized array of"); + else { + appendStr(" "); + appendInt(arraySizes->getDimSize(i)); + appendStr("-element array of"); + } } } - if (qualifier.precision != EpqNone) - p += snprintf(p, end - p, "%s ", getPrecisionQualifierString()); - if (isMatrix()) - p += snprintf(p, end - p, "%dX%d matrix of ", matrixCols, matrixRows); - else if (isVector()) - p += snprintf(p, end - p, "%d-component vector of ", vectorSize); + if (qualifier.precision != EpqNone) { + appendStr(" "); + appendStr(getPrecisionQualifierString()); + } + if (isMatrix()) { + appendStr(" "); + appendInt(matrixCols); + appendStr("X"); + appendInt(matrixRows); + appendStr(" matrix of"); + } else if (isVector()) { + appendStr(" "); + appendInt(vectorSize); + appendStr("-component vector of"); + } - *p = 0; - TString s(buf); - s.append(getBasicTypeString()); + appendStr(" "); + typeString.append(getBasicTypeString()); if (qualifier.builtIn != EbvNone) { - s.append(" "); - s.append(getBuiltInVariableString()); + appendStr(" "); + appendStr(getBuiltInVariableString()); } // Add struct/block members if (structure) { - s.append("{"); + appendStr("{"); for (size_t i = 0; i < structure->size(); ++i) { - if (s.size() > 3 * GlslangMaxTypeLength) { - // If we are getting too long, cut it short, - // just need to draw the line somewhere, as there is no limit to - // how large a struct/block type can get. - s.append("..."); - break; - } if (! (*structure)[i].type->hiddenMember()) { - s.append((*structure)[i].type->getCompleteString()); - s.append(" "); - s.append((*structure)[i].type->getFieldName()); + typeString.append((*structure)[i].type->getCompleteString()); + typeString.append(" "); + typeString.append((*structure)[i].type->getFieldName()); if (i < structure->size() - 1) - s.append(", "); + appendStr(", "); } } - s.append("}"); + appendStr("}"); } - return s; + return typeString; } TString getBasicTypeString() const @@ -1720,6 +1779,7 @@ public: const char* getBuiltInVariableString() const { return GetBuiltInVariableString(qualifier.builtIn); } const char* getPrecisionQualifierString() const { return GetPrecisionQualifierString(qualifier.precision); } const TTypeList* getStruct() const { return structure; } + void setStruct(TTypeList* s) { structure = s; } TTypeList* getWritableStruct() const { return structure; } // This should only be used when known to not be sharing with other threads int computeNumComponents() const @@ -1742,7 +1802,7 @@ public: } // append this type's mangled name to the passed in 'name' - void appendMangledName(TString& name) + void appendMangledName(TString& name) const { buildMangledName(name); name += ';' ; @@ -1830,7 +1890,43 @@ protected: TType(const TType& type); TType& operator=(const TType& type); - void buildMangledName(TString&); + // Recursively copy a type graph, while preserving the graph-like + // quality. That is, don't make more than one copy of a structure that + // gets reused multiple times in the type graph. + void deepCopy(const TType& copyOf, TMap<TTypeList*,TTypeList*>& copiedMap) + { + shallowCopy(copyOf); + + if (copyOf.arraySizes) { + arraySizes = new TArraySizes; + *arraySizes = *copyOf.arraySizes; + } + + if (copyOf.structure) { + auto prevCopy = copiedMap.find(copyOf.structure); + if (prevCopy != copiedMap.end()) + structure = prevCopy->second; + else { + structure = new TTypeList; + copiedMap[copyOf.structure] = structure; + for (unsigned int i = 0; i < copyOf.structure->size(); ++i) { + TTypeLoc typeLoc; + typeLoc.loc = (*copyOf.structure)[i].loc; + typeLoc.type = new TType(); + typeLoc.type->deepCopy(*(*copyOf.structure)[i].type, copiedMap); + structure->push_back(typeLoc); + } + } + } + + if (copyOf.fieldName) + fieldName = NewPoolTString(copyOf.fieldName->c_str()); + if (copyOf.typeName) + typeName = NewPoolTString(copyOf.typeName->c_str()); + } + + + void buildMangledName(TString&) const; TBasicType basicType : 8; int vectorSize : 4; // 1 means either scalar or 1-component vector; see vector1 to disambiguate. |