Web: Generalize _EXTENSIONS* in SPIR-V back-end.

About 50 fewer #ifdefs.
About 14K smaller.
Note, the base size is ill-defined due to optimizer settings (size vs. performance),
compression, and target architecture.  Some recent %'s are accidentally reported as
3X the real savings.  Early %'s were accurate.  What matters though is that each
step got worthwhile gains, and what the final size ends up being.
This commit is contained in:
John Kessenich 2019-08-06 07:00:58 -06:00
parent b6d3ee5aca
commit a28f7a75d1
11 changed files with 1188 additions and 1312 deletions

File diff suppressed because it is too large Load Diff

View File

@ -586,7 +586,7 @@ Id Builder::makeSampledImageType(Id imageType)
return type->getResultId(); return type->getResultId();
} }
#ifdef NV_EXTENSIONS #ifndef GLSLANG_WEB
Id Builder::makeAccelerationStructureNVType() Id Builder::makeAccelerationStructureNVType()
{ {
Instruction *type; Instruction *type;
@ -602,6 +602,7 @@ Id Builder::makeAccelerationStructureNVType()
return type->getResultId(); return type->getResultId();
} }
#endif #endif
Id Builder::getDerefTypeId(Id resultId) const Id Builder::getDerefTypeId(Id resultId) const
{ {
Id typeId = getTypeId(resultId); Id typeId = getTypeId(resultId);
@ -1904,7 +1905,7 @@ Id Builder::createTextureCall(Decoration precision, Id resultType, bool sparse,
opCode = OpImageSparseFetch; opCode = OpImageSparseFetch;
else else
opCode = OpImageFetch; opCode = OpImageFetch;
#ifdef NV_EXTENSIONS #ifndef GLSLANG_WEB
} else if (parameters.granularity && parameters.coarse) { } else if (parameters.granularity && parameters.coarse) {
opCode = OpImageSampleFootprintNV; opCode = OpImageSampleFootprintNV;
#endif #endif
@ -2067,11 +2068,7 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter
break; break;
} }
case OpImageQueryLod: case OpImageQueryLod:
#ifdef AMD_EXTENSIONS
resultType = makeVectorType(getScalarTypeId(getTypeId(parameters.coords)), 2); resultType = makeVectorType(getScalarTypeId(getTypeId(parameters.coords)), 2);
#else
resultType = makeVectorType(makeFloatType(32), 2);
#endif
break; break;
case OpImageQueryLevels: case OpImageQueryLevels:
case OpImageQuerySamples: case OpImageQuerySamples:

View File

@ -442,9 +442,11 @@ public:
{ {
precision = EpqNone; precision = EpqNone;
invariant = false; invariant = false;
noContraction = false;
makeTemporary(); makeTemporary();
declaredBuiltIn = EbvNone; declaredBuiltIn = EbvNone;
#ifndef GLSLANG_WEB
noContraction = false;
#endif
} }
// drop qualifiers that don't belong in a temporary variable // drop qualifiers that don't belong in a temporary variable
@ -517,11 +519,11 @@ public:
static_assert(EbvLast < 256, "need to increase size of TBuiltInVariable bitfields!"); static_assert(EbvLast < 256, "need to increase size of TBuiltInVariable bitfields!");
TPrecisionQualifier precision : 3; TPrecisionQualifier precision : 3;
bool invariant : 1; // require canonical treatment for cross-shader invariance bool invariant : 1; // require canonical treatment for cross-shader invariance
bool noContraction: 1; // prevent contraction and reassociation, e.g., for 'precise' keyword, and expressions it affects
bool centroid : 1; bool centroid : 1;
bool smooth : 1; bool smooth : 1;
bool flat : 1; bool flat : 1;
#ifndef GLSLANG_WEB #ifndef GLSLANG_WEB
bool noContraction: 1; // prevent contraction and reassociation, e.g., for 'precise' keyword, and expressions it affects
bool nopersp : 1; bool nopersp : 1;
bool explicitInterp : 1; bool explicitInterp : 1;
bool pervertexNV : 1; bool pervertexNV : 1;
@ -552,40 +554,36 @@ public:
{ {
return subgroupcoherent || workgroupcoherent || queuefamilycoherent || devicecoherent || coherent || volatil || restrict || readonly || writeonly; return subgroupcoherent || workgroupcoherent || queuefamilycoherent || devicecoherent || coherent || volatil || restrict || readonly || writeonly;
} }
bool bufferReferenceNeedsVulkanMemoryModel() const
{
#ifdef GLSLANG_WEB
return false;
#else
// include qualifiers that map to load/store availability/visibility/nonprivate memory access operands
return subgroupcoherent || workgroupcoherent || queuefamilycoherent || devicecoherent || coherent || nonprivate;
#endif
}
#ifdef GLSLANG_WEB
bool bufferReferenceNeedsVulkanMemoryModel() const { return false; }
bool isInterpolation() const bool isInterpolation() const
{ {
#ifndef GLSLANG_WEB
return flat || smooth || nopersp || explicitInterp;
#else
return flat || smooth; return flat || smooth;
#endif
} }
bool isExplicitInterpolation() const { return false; }
#ifndef GLSLANG_WEB bool isAuxiliary() const { return centroid; }
bool isNoContraction() const { return false; }
#else
bool bufferReferenceNeedsVulkanMemoryModel() const
{
// include qualifiers that map to load/store availability/visibility/nonprivate memory access operands
return subgroupcoherent || workgroupcoherent || queuefamilycoherent || devicecoherent || coherent || nonprivate;
}
bool isInterpolation() const
{
return flat || smooth || nopersp || explicitInterp;
}
bool isExplicitInterpolation() const bool isExplicitInterpolation() const
{ {
return explicitInterp; return explicitInterp;
} }
#endif
bool isAuxiliary() const bool isAuxiliary() const
{ {
#ifndef GLSLANG_WEB
return centroid || patch || sample || pervertexNV; return centroid || patch || sample || pervertexNV;
#else
return centroid;
#endif
} }
bool isNoContraction() const { return noContraction; }
#endif
bool isPipeInput() const bool isPipeInput() const
{ {

View File

@ -1299,10 +1299,17 @@ public:
bool isConstructor() const; bool isConstructor() const;
bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; } bool isTexture() const { return op > EOpTextureGuardBegin && op < EOpTextureGuardEnd; }
bool isSampling() const { return op > EOpSamplingGuardBegin && op < EOpSamplingGuardEnd; } bool isSampling() const { return op > EOpSamplingGuardBegin && op < EOpSamplingGuardEnd; }
#ifdef GLSLANG_WEB
bool isImage() const { return false; }
bool isSparseTexture() const { return false; }
bool isImageFootprint() const { return false; }
bool isSparseImage() const { return false; }
#else
bool isImage() const { return op > EOpImageGuardBegin && op < EOpImageGuardEnd; } bool isImage() const { return op > EOpImageGuardBegin && op < EOpImageGuardEnd; }
bool isSparseTexture() const { return op > EOpSparseTextureGuardBegin && op < EOpSparseTextureGuardEnd; } bool isSparseTexture() const { return op > EOpSparseTextureGuardBegin && op < EOpSparseTextureGuardEnd; }
bool isImageFootprint() const { return op > EOpImageFootprintGuardBegin && op < EOpImageFootprintGuardEnd; } bool isImageFootprint() const { return op > EOpImageFootprintGuardBegin && op < EOpImageFootprintGuardEnd; }
bool isSparseImage() const { return op == EOpSparseImageLoad; } bool isSparseImage() const { return op == EOpSparseImageLoad; }
#endif
void setOperationPrecision(TPrecisionQualifier p) { operationPrecision = p; } void setOperationPrecision(TPrecisionQualifier p) { operationPrecision = p; }
TPrecisionQualifier getOperationPrecision() const { return operationPrecision != EpqNone ? TPrecisionQualifier getOperationPrecision() const { return operationPrecision != EpqNone ?

View File

@ -877,6 +877,7 @@ TIntermTyped* TParseContext::handleDotDereference(const TSourceLoc& loc, TInterm
} else } else
error(loc, "does not apply to this type:", field.c_str(), base->getType().getCompleteString().c_str()); error(loc, "does not apply to this type:", field.c_str(), base->getType().getCompleteString().c_str());
#ifndef GLSLANG_WEB
// Propagate noContraction up the dereference chain // Propagate noContraction up the dereference chain
if (base->getQualifier().noContraction) if (base->getQualifier().noContraction)
result->getWritableType().getQualifier().noContraction = true; result->getWritableType().getQualifier().noContraction = true;
@ -884,6 +885,7 @@ TIntermTyped* TParseContext::handleDotDereference(const TSourceLoc& loc, TInterm
// Propagate nonuniform // Propagate nonuniform
if (base->getQualifier().isNonUniform()) if (base->getQualifier().isNonUniform())
result->getWritableType().getQualifier().nonUniform = true; result->getWritableType().getQualifier().nonUniform = true;
#endif
return result; return result;
} }
@ -3431,7 +3433,7 @@ void TParseContext::mergeQualifiers(const TSourceLoc& loc, TQualifier& dst, cons
(profile == EEsProfile && version < 310)) (profile == EEsProfile && version < 310))
&& ! extensionTurnedOn(E_GL_ARB_shading_language_420pack)) { && ! extensionTurnedOn(E_GL_ARB_shading_language_420pack)) {
// non-function parameters // non-function parameters
if (src.noContraction && (dst.invariant || dst.isInterpolation() || dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone)) if (src.isNoContraction() && (dst.invariant || dst.isInterpolation() || dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone))
error(loc, "precise qualifier must appear first", "", ""); error(loc, "precise qualifier must appear first", "", "");
if (src.invariant && (dst.isInterpolation() || dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone)) if (src.invariant && (dst.isInterpolation() || dst.isAuxiliary() || dst.storage != EvqTemporary || dst.precision != EpqNone))
error(loc, "invariant qualifier must appear before interpolation, storage, and precision qualifiers ", "", ""); error(loc, "invariant qualifier must appear before interpolation, storage, and precision qualifiers ", "", "");
@ -3443,7 +3445,7 @@ void TParseContext::mergeQualifiers(const TSourceLoc& loc, TQualifier& dst, cons
error(loc, "precision qualifier must appear as last qualifier", "", ""); error(loc, "precision qualifier must appear as last qualifier", "", "");
// function parameters // function parameters
if (src.noContraction && (dst.storage == EvqConst || dst.storage == EvqIn || dst.storage == EvqOut)) if (src.isNoContraction() && (dst.storage == EvqConst || dst.storage == EvqIn || dst.storage == EvqOut))
error(loc, "precise qualifier must appear first", "", ""); error(loc, "precise qualifier must appear first", "", "");
if (src.storage == EvqConst && (dst.storage == EvqIn || dst.storage == EvqOut)) if (src.storage == EvqConst && (dst.storage == EvqIn || dst.storage == EvqOut))
error(loc, "in/out must appear before const", "", ""); error(loc, "in/out must appear before const", "", "");
@ -3482,11 +3484,11 @@ void TParseContext::mergeQualifiers(const TSourceLoc& loc, TQualifier& dst, cons
bool repeated = false; bool repeated = false;
#define MERGE_SINGLETON(field) repeated |= dst.field && src.field; dst.field |= src.field; #define MERGE_SINGLETON(field) repeated |= dst.field && src.field; dst.field |= src.field;
MERGE_SINGLETON(invariant); MERGE_SINGLETON(invariant);
MERGE_SINGLETON(noContraction);
MERGE_SINGLETON(centroid); MERGE_SINGLETON(centroid);
MERGE_SINGLETON(smooth); MERGE_SINGLETON(smooth);
MERGE_SINGLETON(flat); MERGE_SINGLETON(flat);
#ifndef GLSLANG_WEB #ifndef GLSLANG_WEB
MERGE_SINGLETON(noContraction);
MERGE_SINGLETON(nopersp); MERGE_SINGLETON(nopersp);
MERGE_SINGLETON(explicitInterp); MERGE_SINGLETON(explicitInterp);
MERGE_SINGLETON(perPrimitiveNV); MERGE_SINGLETON(perPrimitiveNV);
@ -4449,12 +4451,14 @@ void TParseContext::paramCheckFix(const TSourceLoc& loc, const TQualifier& quali
error(loc, "cannot use layout qualifiers on a function parameter", "", ""); error(loc, "cannot use layout qualifiers on a function parameter", "", "");
if (qualifier.invariant) if (qualifier.invariant)
error(loc, "cannot use invariant qualifier on a function parameter", "", ""); error(loc, "cannot use invariant qualifier on a function parameter", "", "");
if (qualifier.noContraction) { #ifndef GLSLANG_WEB
if (qualifier.isNoContraction()) {
if (qualifier.isParamOutput()) if (qualifier.isParamOutput())
type.getQualifier().noContraction = true; type.getQualifier().noContraction = true;
else else
warn(loc, "qualifier has no effect on non-output parameters", "precise", ""); warn(loc, "qualifier has no effect on non-output parameters", "precise", "");
} }
#endif
if (qualifier.isNonUniform()) if (qualifier.isNonUniform())
type.getQualifier().nonUniform = qualifier.nonUniform; type.getQualifier().nonUniform = qualifier.nonUniform;
@ -7281,11 +7285,13 @@ void TParseContext::declareBlock(const TSourceLoc& loc, TTypeList& typeList, con
for (unsigned int member = 0; member < typeList.size(); ++member) for (unsigned int member = 0; member < typeList.size(); ++member)
layoutTypeCheck(typeList[member].loc, *typeList[member].type); layoutTypeCheck(typeList[member].loc, *typeList[member].type);
#ifndef GLSLANG_WEB
if (memberWithPerViewQualifier) { if (memberWithPerViewQualifier) {
for (unsigned int member = 0; member < typeList.size(); ++member) { for (unsigned int member = 0; member < typeList.size(); ++member) {
checkAndResizeMeshViewDim(typeList[member].loc, *typeList[member].type, /*isBlockMember*/ true); checkAndResizeMeshViewDim(typeList[member].loc, *typeList[member].type, /*isBlockMember*/ true);
} }
} }
#endif
// reverse merge, so that currentBlockQualifier now has all layout information // reverse merge, so that currentBlockQualifier now has all layout information
// (can't use defaultQualification directly, it's missing other non-layout-default-class qualifiers) // (can't use defaultQualification directly, it's missing other non-layout-default-class qualifiers)
@ -7699,11 +7705,15 @@ void TParseContext::addQualifierToExisting(const TSourceLoc& loc, TQualifier qua
error(loc, "cannot change qualification after use", "invariant", ""); error(loc, "cannot change qualification after use", "invariant", "");
symbol->getWritableType().getQualifier().invariant = true; symbol->getWritableType().getQualifier().invariant = true;
invariantCheck(loc, symbol->getType().getQualifier()); invariantCheck(loc, symbol->getType().getQualifier());
} else if (qualifier.noContraction) { }
#ifndef GLSLANG_WEB
else if (qualifier.isNoContraction()) {
if (intermediate.inIoAccessed(identifier)) if (intermediate.inIoAccessed(identifier))
error(loc, "cannot change qualification after use", "precise", ""); error(loc, "cannot change qualification after use", "precise", "");
symbol->getWritableType().getQualifier().noContraction = true; symbol->getWritableType().getQualifier().noContraction = true;
} else if (qualifier.specConstant) { }
#endif
else if (qualifier.specConstant) {
symbol->getWritableType().getQualifier().makeSpecConstant(); symbol->getWritableType().getQualifier().makeSpecConstant();
if (qualifier.hasSpecConstantId()) if (qualifier.hasSpecConstantId())
symbol->getWritableType().getQualifier().layoutSpecConstantId = qualifier.layoutSpecConstantId; symbol->getWritableType().getQualifier().layoutSpecConstantId = qualifier.layoutSpecConstantId;

View File

@ -115,7 +115,6 @@
#define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C #define GL_SAMPLER_CUBE_MAP_ARRAY_ARB 0x900C
#define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D #define GL_SAMPLER_CUBE_MAP_ARRAY_SHADOW_ARB 0x900D
#ifdef AMD_EXTENSIONS
#define GL_FLOAT16_SAMPLER_1D_AMD 0x91CE #define GL_FLOAT16_SAMPLER_1D_AMD 0x91CE
#define GL_FLOAT16_SAMPLER_2D_AMD 0x91CF #define GL_FLOAT16_SAMPLER_2D_AMD 0x91CF
#define GL_FLOAT16_SAMPLER_3D_AMD 0x91D0 #define GL_FLOAT16_SAMPLER_3D_AMD 0x91D0
@ -147,7 +146,6 @@
#define GL_FLOAT16_IMAGE_BUFFER_AMD 0x91E8 #define GL_FLOAT16_IMAGE_BUFFER_AMD 0x91E8
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_AMD 0x91E9 #define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_AMD 0x91E9
#define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_ARRAY_AMD 0x91EA #define GL_FLOAT16_IMAGE_2D_MULTISAMPLE_ARRAY_AMD 0x91EA
#endif
#define GL_INT_SAMPLER_1D 0x8DC9 #define GL_INT_SAMPLER_1D 0x8DC9
#define GL_INT_SAMPLER_2D 0x8DCA #define GL_INT_SAMPLER_2D 0x8DCA

View File

@ -1239,10 +1239,12 @@ layout_qualifier_id
precise_qualifier precise_qualifier
: PRECISE { : PRECISE {
#ifndef GLSLANG_WEB
parseContext.profileRequires($$.loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader5, "precise"); parseContext.profileRequires($$.loc, ECoreProfile | ECompatibilityProfile, 400, E_GL_ARB_gpu_shader5, "precise");
parseContext.profileRequires($1.loc, EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5, "precise"); parseContext.profileRequires($1.loc, EEsProfile, 320, Num_AEP_gpu_shader5, AEP_gpu_shader5, "precise");
$$.init($1.loc); $$.init($1.loc);
$$.qualifier.noContraction = true; $$.qualifier.noContraction = true;
#endif
} }
; ;

File diff suppressed because it is too large Load Diff

View File

@ -525,7 +525,7 @@ void TIntermediate::mergeErrorCheck(TInfoSink& infoSink, const TIntermSymbol& sy
} }
// Precise... // Precise...
if (! crossStage && symbol.getQualifier().noContraction != unitSymbol.getQualifier().noContraction) { if (! crossStage && symbol.getQualifier().isNoContraction() != unitSymbol.getQualifier().isNoContraction()) {
error(infoSink, "Presence of precise qualifier must match:"); error(infoSink, "Presence of precise qualifier must match:");
writeTypeComparison = true; writeTypeComparison = true;
} }

View File

@ -37,6 +37,8 @@
// propagate the 'noContraction' qualifier. // propagate the 'noContraction' qualifier.
// //
#ifndef GLSLANG_WEB
#include "propagateNoContraction.h" #include "propagateNoContraction.h"
#include <cstdlib> #include <cstdlib>
@ -79,7 +81,7 @@ typedef std::unordered_set<glslang::TIntermBranch*> ReturnBranchNodeSet;
// the node has 'noContraction' qualifier, otherwise false. // the node has 'noContraction' qualifier, otherwise false.
bool isPreciseObjectNode(glslang::TIntermTyped* node) bool isPreciseObjectNode(glslang::TIntermTyped* node)
{ {
return node->getType().getQualifier().noContraction; return node->getType().getQualifier().isNoContraction();
} }
// Returns true if the opcode is a dereferencing one. // Returns true if the opcode is a dereferencing one.
@ -864,3 +866,5 @@ void PropagateNoContraction(const glslang::TIntermediate& intermediate)
} }
} }
}; };
#endif // GLSLANG_WEB

View File

@ -703,7 +703,6 @@ public:
case EsdBuffer: case EsdBuffer:
return GL_SAMPLER_BUFFER; return GL_SAMPLER_BUFFER;
} }
#ifdef AMD_EXTENSIONS
case EbtFloat16: case EbtFloat16:
switch ((int)sampler.dim) { switch ((int)sampler.dim) {
case Esd1D: case Esd1D:
@ -732,7 +731,6 @@ public:
case EsdBuffer: case EsdBuffer:
return GL_FLOAT16_SAMPLER_BUFFER_AMD; return GL_FLOAT16_SAMPLER_BUFFER_AMD;
} }
#endif
case EbtInt: case EbtInt:
switch ((int)sampler.dim) { switch ((int)sampler.dim) {
case Esd1D: case Esd1D:
@ -795,7 +793,6 @@ public:
case EsdBuffer: case EsdBuffer:
return GL_IMAGE_BUFFER; return GL_IMAGE_BUFFER;
} }
#ifdef AMD_EXTENSIONS
case EbtFloat16: case EbtFloat16:
switch ((int)sampler.dim) { switch ((int)sampler.dim) {
case Esd1D: case Esd1D:
@ -814,7 +811,6 @@ public:
case EsdBuffer: case EsdBuffer:
return GL_FLOAT16_IMAGE_BUFFER_AMD; return GL_FLOAT16_IMAGE_BUFFER_AMD;
} }
#endif
case EbtInt: case EbtInt:
switch ((int)sampler.dim) { switch ((int)sampler.dim) {
case Esd1D: case Esd1D:
@ -880,9 +876,7 @@ public:
switch (type.getBasicType()) { switch (type.getBasicType()) {
case EbtFloat: return GL_FLOAT_VEC2 + offset; case EbtFloat: return GL_FLOAT_VEC2 + offset;
case EbtDouble: return GL_DOUBLE_VEC2 + offset; case EbtDouble: return GL_DOUBLE_VEC2 + offset;
#ifdef AMD_EXTENSIONS
case EbtFloat16: return GL_FLOAT16_VEC2_NV + offset; case EbtFloat16: return GL_FLOAT16_VEC2_NV + offset;
#endif
case EbtInt: return GL_INT_VEC2 + offset; case EbtInt: return GL_INT_VEC2 + offset;
case EbtUint: return GL_UNSIGNED_INT_VEC2 + offset; case EbtUint: return GL_UNSIGNED_INT_VEC2 + offset;
case EbtInt64: return GL_INT64_ARB + offset; case EbtInt64: return GL_INT64_ARB + offset;
@ -942,7 +936,6 @@ public:
default: return 0; default: return 0;
} }
} }
#ifdef AMD_EXTENSIONS
case EbtFloat16: case EbtFloat16:
switch (type.getMatrixCols()) { switch (type.getMatrixCols()) {
case 2: case 2:
@ -967,7 +960,6 @@ public:
default: return 0; default: return 0;
} }
} }
#endif
default: default:
return 0; return 0;
} }
@ -976,9 +968,7 @@ public:
switch (type.getBasicType()) { switch (type.getBasicType()) {
case EbtFloat: return GL_FLOAT; case EbtFloat: return GL_FLOAT;
case EbtDouble: return GL_DOUBLE; case EbtDouble: return GL_DOUBLE;
#ifdef AMD_EXTENSIONS
case EbtFloat16: return GL_FLOAT16_NV; case EbtFloat16: return GL_FLOAT16_NV;
#endif
case EbtInt: return GL_INT; case EbtInt: return GL_INT;
case EbtUint: return GL_UNSIGNED_INT; case EbtUint: return GL_UNSIGNED_INT;
case EbtInt64: return GL_INT64_ARB; case EbtInt64: return GL_INT64_ARB;