Web: Remove/rationalize a set of *_EXTENSIONS, using GLSLANG_WEB.
Focus was on the front end (not SPIR-V), minus the grammar. Reduces #ifdef count by around 320 and makes the web build 270K smaller, which is about 90% the target size. The grammar and scanner will be another step, as will the SPIR-V backend. This makes heavy use of methods #ifdef'd to return false as a global way of turning off code, relying on C++ DCE to do the rest.
This commit is contained in:
parent
e66dace97e
commit
7015bd658e
32 changed files with 2661 additions and 2712 deletions
|
|
@ -78,11 +78,15 @@ void TIntermediate::warn(TInfoSink& infoSink, const char* message)
|
|||
//
|
||||
void TIntermediate::merge(TInfoSink& infoSink, TIntermediate& unit)
|
||||
{
|
||||
#ifndef GLSLANG_WEB
|
||||
mergeCallGraphs(infoSink, unit);
|
||||
mergeModes(infoSink, unit);
|
||||
mergeTrees(infoSink, unit);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
|
||||
void TIntermediate::mergeCallGraphs(TInfoSink& infoSink, TIntermediate& unit)
|
||||
{
|
||||
if (unit.getNumEntryPoints() > 0) {
|
||||
|
|
@ -142,18 +146,13 @@ void TIntermediate::mergeModes(TInfoSink& infoSink, TIntermediate& unit)
|
|||
if (vertices == TQualifier::layoutNotSet)
|
||||
vertices = unit.vertices;
|
||||
else if (vertices != unit.vertices) {
|
||||
if (language == EShLangGeometry
|
||||
#ifdef NV_EXTENSIONS
|
||||
|| language == EShLangMeshNV
|
||||
#endif
|
||||
)
|
||||
if (language == EShLangGeometry || language == EShLangMeshNV)
|
||||
error(infoSink, "Contradictory layout max_vertices values");
|
||||
else if (language == EShLangTessControl)
|
||||
error(infoSink, "Contradictory layout vertices values");
|
||||
else
|
||||
assert(0);
|
||||
}
|
||||
#ifdef NV_EXTENSIONS
|
||||
if (primitives == TQualifier::layoutNotSet)
|
||||
primitives = unit.primitives;
|
||||
else if (primitives != unit.primitives) {
|
||||
|
|
@ -162,7 +161,6 @@ void TIntermediate::mergeModes(TInfoSink& infoSink, TIntermediate& unit)
|
|||
else
|
||||
assert(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (inputPrimitive == ElgNone)
|
||||
inputPrimitive = unit.inputPrimitive;
|
||||
|
|
@ -224,21 +222,16 @@ void TIntermediate::mergeModes(TInfoSink& infoSink, TIntermediate& unit)
|
|||
xfbBuffers[b].implicitStride = std::max(xfbBuffers[b].implicitStride, unit.xfbBuffers[b].implicitStride);
|
||||
if (unit.xfbBuffers[b].contains64BitType)
|
||||
xfbBuffers[b].contains64BitType = true;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
if (unit.xfbBuffers[b].contains32BitType)
|
||||
xfbBuffers[b].contains32BitType = true;
|
||||
if (unit.xfbBuffers[b].contains16BitType)
|
||||
xfbBuffers[b].contains16BitType = true;
|
||||
#endif
|
||||
// TODO: 4.4 link: enhanced layouts: compare ranges
|
||||
}
|
||||
|
||||
MERGE_TRUE(multiStream);
|
||||
|
||||
#ifdef NV_EXTENSIONS
|
||||
MERGE_TRUE(layoutOverrideCoverage);
|
||||
MERGE_TRUE(geoPassthroughEXT);
|
||||
#endif
|
||||
|
||||
for (unsigned int i = 0; i < unit.shiftBinding.size(); ++i) {
|
||||
if (unit.shiftBinding[i] > 0)
|
||||
|
|
@ -287,13 +280,8 @@ void TIntermediate::mergeTrees(TInfoSink& infoSink, TIntermediate& unit)
|
|||
}
|
||||
|
||||
// Getting this far means we have two existing trees to merge...
|
||||
#ifdef NV_EXTENSIONS
|
||||
numShaderRecordNVBlocks += unit.numShaderRecordNVBlocks;
|
||||
#endif
|
||||
|
||||
#ifdef NV_EXTENSIONS
|
||||
numTaskNVBlocks += unit.numTaskNVBlocks;
|
||||
#endif
|
||||
|
||||
// Get the top-level globals of each unit
|
||||
TIntermSequence& globals = treeRoot->getAsAggregate()->getSequence();
|
||||
|
|
@ -493,6 +481,7 @@ void TIntermediate::mergeImplicitArraySizes(TType& type, const TType& unitType)
|
|||
for (int i = 0; i < (int)type.getStruct()->size(); ++i)
|
||||
mergeImplicitArraySizes(*(*type.getStruct())[i].type, *(*unitType.getStruct())[i].type);
|
||||
}
|
||||
#endif // not GLSLANG_WEB
|
||||
|
||||
//
|
||||
// Compare two global objects from two compilation units and see if they match
|
||||
|
|
@ -547,7 +536,7 @@ void TIntermediate::mergeErrorCheck(TInfoSink& infoSink, const TIntermSymbol& sy
|
|||
symbol.getQualifier().flat != unitSymbol.getQualifier().flat ||
|
||||
symbol.getQualifier().sample != unitSymbol.getQualifier().sample ||
|
||||
symbol.getQualifier().patch != unitSymbol.getQualifier().patch ||
|
||||
symbol.getQualifier().nopersp != unitSymbol.getQualifier().nopersp) {
|
||||
symbol.getQualifier().isNonPerspective() != unitSymbol.getQualifier().isNonPerspective()) {
|
||||
error(infoSink, "Interpolation and auxiliary storage qualifiers must match:");
|
||||
writeTypeComparison = true;
|
||||
}
|
||||
|
|
@ -615,7 +604,7 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
warn(infoSink, "Entry point not found");
|
||||
}
|
||||
|
||||
if (numPushConstants > 1)
|
||||
if (getNumPushConstants() > 1)
|
||||
error(infoSink, "Only one push_constant block is allowed per stage");
|
||||
|
||||
// recursion and missing body checking
|
||||
|
|
@ -629,6 +618,7 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
if (invocations == TQualifier::layoutNotSet)
|
||||
invocations = 1;
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
if (inIoAccessed("gl_ClipDistance") && inIoAccessed("gl_ClipVertex"))
|
||||
error(infoSink, "Can only use one of gl_ClipDistance or gl_ClipVertex (gl_ClipDistance is preferred)");
|
||||
if (inIoAccessed("gl_CullDistance") && inIoAccessed("gl_ClipVertex"))
|
||||
|
|
@ -642,12 +632,10 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
for (size_t b = 0; b < xfbBuffers.size(); ++b) {
|
||||
if (xfbBuffers[b].contains64BitType)
|
||||
RoundToPow2(xfbBuffers[b].implicitStride, 8);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
else if (xfbBuffers[b].contains32BitType)
|
||||
RoundToPow2(xfbBuffers[b].implicitStride, 4);
|
||||
else if (xfbBuffers[b].contains16BitType)
|
||||
RoundToPow2(xfbBuffers[b].implicitStride, 2);
|
||||
#endif
|
||||
|
||||
// "It is a compile-time or link-time error to have
|
||||
// any xfb_offset that overflows xfb_stride, whether stated on declarations before or after the xfb_stride, or
|
||||
|
|
@ -668,16 +656,11 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
error(infoSink, "xfb_stride must be multiple of 8 for buffer holding a double or 64-bit integer:");
|
||||
infoSink.info.prefix(EPrefixError);
|
||||
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (xfbBuffers[b].contains32BitType && ! IsMultipleOfPow2(xfbBuffers[b].stride, 4)) {
|
||||
#else
|
||||
} else if (! IsMultipleOfPow2(xfbBuffers[b].stride, 4)) {
|
||||
#endif
|
||||
error(infoSink, "xfb_stride must be multiple of 4:");
|
||||
infoSink.info.prefix(EPrefixError);
|
||||
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
|
||||
}
|
||||
#ifdef AMD_EXTENSIONS
|
||||
// "If the buffer is capturing any
|
||||
// outputs with half-precision or 16-bit integer components, the stride must be a multiple of 2"
|
||||
else if (xfbBuffers[b].contains16BitType && ! IsMultipleOfPow2(xfbBuffers[b].stride, 2)) {
|
||||
|
|
@ -686,7 +669,6 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
infoSink.info << " xfb_buffer " << (unsigned int)b << ", xfb_stride " << xfbBuffers[b].stride << "\n";
|
||||
}
|
||||
|
||||
#endif
|
||||
// "The resulting stride (implicit or explicit), when divided by 4, must be less than or equal to the
|
||||
// implementation-dependent constant gl_MaxTransformFeedbackInterleavedComponents."
|
||||
if (xfbBuffers[b].stride > (unsigned int)(4 * resources.maxTransformFeedbackInterleavedComponents)) {
|
||||
|
|
@ -730,8 +712,6 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
break;
|
||||
case EShLangCompute:
|
||||
break;
|
||||
|
||||
#ifdef NV_EXTENSIONS
|
||||
case EShLangRayGenNV:
|
||||
case EShLangIntersectNV:
|
||||
case EShLangAnyHitNV:
|
||||
|
|
@ -764,8 +744,6 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
if (numTaskNVBlocks > 1)
|
||||
error(infoSink, "Only one taskNV interface block is allowed per shader");
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
error(infoSink, "Unknown Stage.");
|
||||
break;
|
||||
|
|
@ -787,6 +765,7 @@ void TIntermediate::finalCheck(TInfoSink& infoSink, bool keepUncalled)
|
|||
} finalLinkTraverser;
|
||||
|
||||
treeRoot->traverse(&finalLinkTraverser);
|
||||
#endif
|
||||
}
|
||||
|
||||
//
|
||||
|
|
@ -1187,14 +1166,10 @@ int TIntermediate::computeTypeLocationSize(const TType& type, EShLanguage stage)
|
|||
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
|
||||
// TODO: are there valid cases of having an unsized array with a location? If so, running this code too early.
|
||||
TType elementType(type, 0);
|
||||
if (type.isSizedArray()
|
||||
#ifdef NV_EXTENSIONS
|
||||
&& !type.getQualifier().isPerView()
|
||||
#endif
|
||||
)
|
||||
if (type.isSizedArray() && !type.getQualifier().isPerView())
|
||||
return type.getOuterArraySize() * computeTypeLocationSize(elementType, stage);
|
||||
else {
|
||||
#ifdef NV_EXTENSIONS
|
||||
#ifndef GLSLANG_WEB
|
||||
// unset perViewNV attributes for arrayed per-view outputs: "perviewNV vec4 v[MAX_VIEWS][3];"
|
||||
elementType.getQualifier().perViewNV = false;
|
||||
#endif
|
||||
|
|
@ -1273,6 +1248,7 @@ int TIntermediate::computeTypeUniformLocationSize(const TType& type)
|
|||
return 1;
|
||||
}
|
||||
|
||||
#ifndef GLSLANG_WEB
|
||||
// Accumulate xfb buffer ranges and check for collisions as the accumulation is done.
|
||||
//
|
||||
// Returns < 0 if no collision, >= 0 if collision and the value returned is a colliding value.
|
||||
|
|
@ -1285,11 +1261,7 @@ int TIntermediate::addXfbBufferOffset(const TType& type)
|
|||
TXfbBuffer& buffer = xfbBuffers[qualifier.layoutXfbBuffer];
|
||||
|
||||
// compute the range
|
||||
#ifdef AMD_EXTENSIONS
|
||||
unsigned int size = computeTypeXfbSize(type, buffer.contains64BitType, buffer.contains32BitType, buffer.contains16BitType);
|
||||
#else
|
||||
unsigned int size = computeTypeXfbSize(type, buffer.contains64BitType);
|
||||
#endif
|
||||
buffer.implicitStride = std::max(buffer.implicitStride, qualifier.layoutXfbOffset + size);
|
||||
TRange range(qualifier.layoutXfbOffset, qualifier.layoutXfbOffset + size - 1);
|
||||
|
||||
|
|
@ -1309,15 +1281,10 @@ int TIntermediate::addXfbBufferOffset(const TType& type)
|
|||
// Recursively figure out how many bytes of xfb buffer are used by the given type.
|
||||
// Return the size of type, in bytes.
|
||||
// Sets contains64BitType to true if the type contains a 64-bit data type.
|
||||
#ifdef AMD_EXTENSIONS
|
||||
// Sets contains32BitType to true if the type contains a 32-bit data type.
|
||||
// Sets contains16BitType to true if the type contains a 16-bit data type.
|
||||
// N.B. Caller must set contains64BitType, contains32BitType, and contains16BitType to false before calling.
|
||||
unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains64BitType, bool& contains32BitType, bool& contains16BitType) const
|
||||
#else
|
||||
// N.B. Caller must set contains64BitType to false before calling.
|
||||
unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains64BitType) const
|
||||
#endif
|
||||
{
|
||||
// "...if applied to an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8,
|
||||
// and the space taken in the buffer will be a multiple of 8.
|
||||
|
|
@ -1330,44 +1297,32 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
|
|||
// TODO: perf: this can be flattened by using getCumulativeArraySize(), and a deref that discards all arrayness
|
||||
assert(type.isSizedArray());
|
||||
TType elementType(type, 0);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
return type.getOuterArraySize() * computeTypeXfbSize(elementType, contains64BitType, contains16BitType, contains16BitType);
|
||||
#else
|
||||
return type.getOuterArraySize() * computeTypeXfbSize(elementType, contains64BitType);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (type.isStruct()) {
|
||||
unsigned int size = 0;
|
||||
bool structContains64BitType = false;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
bool structContains32BitType = false;
|
||||
bool structContains16BitType = false;
|
||||
#endif
|
||||
for (int member = 0; member < (int)type.getStruct()->size(); ++member) {
|
||||
TType memberType(type, member);
|
||||
// "... if applied to
|
||||
// an aggregate containing a double or 64-bit integer, the offset must also be a multiple of 8,
|
||||
// and the space taken in the buffer will be a multiple of 8."
|
||||
bool memberContains64BitType = false;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
bool memberContains32BitType = false;
|
||||
bool memberContains16BitType = false;
|
||||
int memberSize = computeTypeXfbSize(memberType, memberContains64BitType, memberContains32BitType, memberContains16BitType);
|
||||
#else
|
||||
int memberSize = computeTypeXfbSize(memberType, memberContains64BitType);
|
||||
#endif
|
||||
if (memberContains64BitType) {
|
||||
structContains64BitType = true;
|
||||
RoundToPow2(size, 8);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (memberContains32BitType) {
|
||||
structContains32BitType = true;
|
||||
RoundToPow2(size, 4);
|
||||
} else if (memberContains16BitType) {
|
||||
structContains16BitType = true;
|
||||
RoundToPow2(size, 2);
|
||||
#endif
|
||||
}
|
||||
size += memberSize;
|
||||
}
|
||||
|
|
@ -1375,14 +1330,12 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
|
|||
if (structContains64BitType) {
|
||||
contains64BitType = true;
|
||||
RoundToPow2(size, 8);
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (structContains32BitType) {
|
||||
contains32BitType = true;
|
||||
RoundToPow2(size, 4);
|
||||
} else if (structContains16BitType) {
|
||||
contains16BitType = true;
|
||||
RoundToPow2(size, 2);
|
||||
#endif
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
|
@ -1402,7 +1355,6 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
|
|||
if (type.getBasicType() == EbtDouble || type.getBasicType() == EbtInt64 || type.getBasicType() == EbtUint64) {
|
||||
contains64BitType = true;
|
||||
return 8 * numComponents;
|
||||
#ifdef AMD_EXTENSIONS
|
||||
} else if (type.getBasicType() == EbtFloat16 || type.getBasicType() == EbtInt16 || type.getBasicType() == EbtUint16) {
|
||||
contains16BitType = true;
|
||||
return 2 * numComponents;
|
||||
|
|
@ -1412,11 +1364,8 @@ unsigned int TIntermediate::computeTypeXfbSize(const TType& type, bool& contains
|
|||
contains32BitType = true;
|
||||
return 4 * numComponents;
|
||||
}
|
||||
#else
|
||||
} else
|
||||
return 4 * numComponents;
|
||||
#endif
|
||||
}
|
||||
#endif // not GLSLANG_WEB
|
||||
|
||||
const int baseAlignmentVec4Std140 = 16;
|
||||
|
||||
|
|
@ -1741,7 +1690,7 @@ int TIntermediate::getBlockSize(const TType& blockType)
|
|||
|
||||
int TIntermediate::computeBufferReferenceTypeSize(const TType& type)
|
||||
{
|
||||
assert(type.getBasicType() == EbtReference);
|
||||
assert(type.isReference());
|
||||
int size = getBlockSize(*type.getReferentType());
|
||||
|
||||
int align = type.getBufferReferenceAlignment();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue