Web: Selectively remove a few key features, using #ifndef GLSLANG_WEB

Save about 100K.

N.B.: This is done by eliminating a function call, at a high level,
not by #ifdef'ing a bunch of code.

Also, removed no longer needed *_EXTENSION #ifdef in the code not
needed by GLSLANG_WEB.
This commit is contained in:
John Kessenich 2019-07-28 02:12:10 -06:00
parent bfc21ff1a9
commit 23d27751e8
11 changed files with 21 additions and 45 deletions

View File

@ -79,6 +79,10 @@ if(ENABLE_HLSL)
add_definitions(-DENABLE_HLSL) add_definitions(-DENABLE_HLSL)
endif(ENABLE_HLSL) endif(ENABLE_HLSL)
if(ENABLE_GLSLANG_WEB)
add_definitions(-DGLSLANG_WEB)
endif(ENABLE_GLSLANG_WEB)
if(WIN32) if(WIN32)
set(CMAKE_DEBUG_POSTFIX "d") set(CMAKE_DEBUG_POSTFIX "d")
if(MSVC) if(MSVC)

View File

@ -1592,9 +1592,11 @@ void TGlslangToSpvTraverser::finishSpv()
for (auto it = iOSet.cbegin(); it != iOSet.cend(); ++it) for (auto it = iOSet.cbegin(); it != iOSet.cend(); ++it)
entryPoint->addIdOperand(*it); entryPoint->addIdOperand(*it);
#ifndef GLSLANG_WEB
// Add capabilities, extensions, remove unneeded decorations, etc., // Add capabilities, extensions, remove unneeded decorations, etc.,
// based on the resulting SPIR-V. // based on the resulting SPIR-V.
builder.postProcess(); builder.postProcess();
#endif
} }
// Write the SPV into 'out'. // Write the SPV into 'out'.

View File

@ -2089,6 +2089,7 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter
if (parameters.lod) if (parameters.lod)
query->addIdOperand(parameters.lod); query->addIdOperand(parameters.lod);
buildPoint->addInstruction(std::unique_ptr<Instruction>(query)); buildPoint->addInstruction(std::unique_ptr<Instruction>(query));
addCapability(CapabilityImageQuery);
return query->getResultId(); return query->getResultId();
} }

View File

@ -51,12 +51,8 @@ namespace spv {
#include "GLSL.std.450.h" #include "GLSL.std.450.h"
#include "GLSL.ext.KHR.h" #include "GLSL.ext.KHR.h"
#include "GLSL.ext.EXT.h" #include "GLSL.ext.EXT.h"
#ifdef AMD_EXTENSIONS
#include "GLSL.ext.AMD.h" #include "GLSL.ext.AMD.h"
#endif
#ifdef NV_EXTENSIONS
#include "GLSL.ext.NV.h" #include "GLSL.ext.NV.h"
#endif
} }
namespace spv { namespace spv {
@ -160,7 +156,6 @@ void Builder::postProcessType(const Instruction& inst, Id typeId)
} }
break; break;
case OpExtInst: case OpExtInst:
#if AMD_EXTENSIONS
switch (inst.getImmediateOperand(1)) { switch (inst.getImmediateOperand(1)) {
case GLSLstd450Frexp: case GLSLstd450Frexp:
case GLSLstd450FrexpStruct: case GLSLstd450FrexpStruct:
@ -176,7 +171,6 @@ void Builder::postProcessType(const Instruction& inst, Id typeId)
default: default:
break; break;
} }
#endif
break; break;
default: default:
if (basicTypeOp == OpTypeFloat && width == 16) if (basicTypeOp == OpTypeFloat && width == 16)
@ -222,12 +216,10 @@ void Builder::postProcess(Instruction& inst)
addCapability(CapabilityImageQuery); addCapability(CapabilityImageQuery);
break; break;
#ifdef NV_EXTENSIONS
case OpGroupNonUniformPartitionNV: case OpGroupNonUniformPartitionNV:
addExtension(E_SPV_NV_shader_subgroup_partitioned); addExtension(E_SPV_NV_shader_subgroup_partitioned);
addCapability(CapabilityGroupNonUniformPartitionedNV); addCapability(CapabilityGroupNonUniformPartitionedNV);
break; break;
#endif
case OpLoad: case OpLoad:
case OpStore: case OpStore:

View File

@ -52,26 +52,16 @@ namespace spv {
extern "C" { extern "C" {
// Include C-based headers that don't have a namespace // Include C-based headers that don't have a namespace
#include "GLSL.std.450.h" #include "GLSL.std.450.h"
#ifdef AMD_EXTENSIONS
#include "GLSL.ext.AMD.h" #include "GLSL.ext.AMD.h"
#endif
#ifdef NV_EXTENSIONS
#include "GLSL.ext.NV.h" #include "GLSL.ext.NV.h"
#endif
} }
} }
const char* GlslStd450DebugNames[spv::GLSLstd450Count]; const char* GlslStd450DebugNames[spv::GLSLstd450Count];
namespace spv { namespace spv {
#ifdef AMD_EXTENSIONS
static const char* GLSLextAMDGetDebugNames(const char*, unsigned); static const char* GLSLextAMDGetDebugNames(const char*, unsigned);
#endif
#ifdef NV_EXTENSIONS
static const char* GLSLextNVGetDebugNames(const char*, unsigned); static const char* GLSLextNVGetDebugNames(const char*, unsigned);
#endif
static void Kill(std::ostream& out, const char* message) static void Kill(std::ostream& out, const char* message)
{ {
@ -82,15 +72,8 @@ static void Kill(std::ostream& out, const char* message)
// used to identify the extended instruction library imported when printing // used to identify the extended instruction library imported when printing
enum ExtInstSet { enum ExtInstSet {
GLSL450Inst, GLSL450Inst,
#ifdef AMD_EXTENSIONS
GLSLextAMDInst, GLSLextAMDInst,
#endif
#ifdef NV_EXTENSIONS
GLSLextNVInst, GLSLextNVInst,
#endif
OpenCLExtInst, OpenCLExtInst,
}; };
@ -499,14 +482,11 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode,
const char* name = idDescriptor[stream[word - 2]].c_str(); const char* name = idDescriptor[stream[word - 2]].c_str();
if (0 == memcmp("OpenCL", name, 6)) { if (0 == memcmp("OpenCL", name, 6)) {
extInstSet = OpenCLExtInst; extInstSet = OpenCLExtInst;
#ifdef AMD_EXTENSIONS
} else if (strcmp(spv::E_SPV_AMD_shader_ballot, name) == 0 || } else if (strcmp(spv::E_SPV_AMD_shader_ballot, name) == 0 ||
strcmp(spv::E_SPV_AMD_shader_trinary_minmax, name) == 0 || strcmp(spv::E_SPV_AMD_shader_trinary_minmax, name) == 0 ||
strcmp(spv::E_SPV_AMD_shader_explicit_vertex_parameter, name) == 0 || strcmp(spv::E_SPV_AMD_shader_explicit_vertex_parameter, name) == 0 ||
strcmp(spv::E_SPV_AMD_gcn_shader, name) == 0) { strcmp(spv::E_SPV_AMD_gcn_shader, name) == 0) {
extInstSet = GLSLextAMDInst; extInstSet = GLSLextAMDInst;
#endif
#ifdef NV_EXTENSIONS
} else if (strcmp(spv::E_SPV_NV_sample_mask_override_coverage, name) == 0 || } else if (strcmp(spv::E_SPV_NV_sample_mask_override_coverage, name) == 0 ||
strcmp(spv::E_SPV_NV_geometry_shader_passthrough, name) == 0 || strcmp(spv::E_SPV_NV_geometry_shader_passthrough, name) == 0 ||
strcmp(spv::E_SPV_NV_viewport_array2, name) == 0 || strcmp(spv::E_SPV_NV_viewport_array2, name) == 0 ||
@ -514,22 +494,17 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode,
strcmp(spv::E_SPV_NV_fragment_shader_barycentric, name) == 0 || strcmp(spv::E_SPV_NV_fragment_shader_barycentric, name) == 0 ||
strcmp(spv::E_SPV_NV_mesh_shader, name) == 0) { strcmp(spv::E_SPV_NV_mesh_shader, name) == 0) {
extInstSet = GLSLextNVInst; extInstSet = GLSLextNVInst;
#endif
} }
unsigned entrypoint = stream[word - 1]; unsigned entrypoint = stream[word - 1];
if (extInstSet == GLSL450Inst) { if (extInstSet == GLSL450Inst) {
if (entrypoint < GLSLstd450Count) { if (entrypoint < GLSLstd450Count) {
out << "(" << GlslStd450DebugNames[entrypoint] << ")"; out << "(" << GlslStd450DebugNames[entrypoint] << ")";
} }
#ifdef AMD_EXTENSIONS
} else if (extInstSet == GLSLextAMDInst) { } else if (extInstSet == GLSLextAMDInst) {
out << "(" << GLSLextAMDGetDebugNames(name, entrypoint) << ")"; out << "(" << GLSLextAMDGetDebugNames(name, entrypoint) << ")";
#endif
#ifdef NV_EXTENSIONS
} }
else if (extInstSet == GLSLextNVInst) { else if (extInstSet == GLSLextNVInst) {
out << "(" << GLSLextNVGetDebugNames(name, entrypoint) << ")"; out << "(" << GLSLextNVGetDebugNames(name, entrypoint) << ")";
#endif
} }
} }
break; break;
@ -653,7 +628,6 @@ static void GLSLstd450GetDebugNames(const char** names)
names[GLSLstd450NClamp] = "NClamp"; names[GLSLstd450NClamp] = "NClamp";
} }
#ifdef AMD_EXTENSIONS
static const char* GLSLextAMDGetDebugNames(const char* name, unsigned entrypoint) static const char* GLSLextAMDGetDebugNames(const char* name, unsigned entrypoint)
{ {
if (strcmp(name, spv::E_SPV_AMD_shader_ballot) == 0) { if (strcmp(name, spv::E_SPV_AMD_shader_ballot) == 0) {
@ -695,9 +669,7 @@ static const char* GLSLextAMDGetDebugNames(const char* name, unsigned entrypoint
return "Bad"; return "Bad";
} }
#endif
#ifdef NV_EXTENSIONS
static const char* GLSLextNVGetDebugNames(const char* name, unsigned entrypoint) static const char* GLSLextNVGetDebugNames(const char* name, unsigned entrypoint)
{ {
if (strcmp(name, spv::E_SPV_NV_sample_mask_override_coverage) == 0 || if (strcmp(name, spv::E_SPV_NV_sample_mask_override_coverage) == 0 ||
@ -751,7 +723,6 @@ static const char* GLSLextNVGetDebugNames(const char* name, unsigned entrypoint)
} }
return "Bad"; return "Bad";
} }
#endif
void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream) void Disassemble(std::ostream& out, const std::vector<unsigned int>& stream)
{ {

View File

@ -234,7 +234,6 @@ std::string GetDefaultTBuiltInResourceString()
<< "MaxCullDistances " << DefaultTBuiltInResource.maxCullDistances << "\n" << "MaxCullDistances " << DefaultTBuiltInResource.maxCullDistances << "\n"
<< "MaxCombinedClipAndCullDistances " << DefaultTBuiltInResource.maxCombinedClipAndCullDistances << "\n" << "MaxCombinedClipAndCullDistances " << DefaultTBuiltInResource.maxCombinedClipAndCullDistances << "\n"
<< "MaxSamples " << DefaultTBuiltInResource.maxSamples << "\n" << "MaxSamples " << DefaultTBuiltInResource.maxSamples << "\n"
#ifdef NV_EXTENSIONS
<< "MaxMeshOutputVerticesNV " << DefaultTBuiltInResource.maxMeshOutputVerticesNV << "\n" << "MaxMeshOutputVerticesNV " << DefaultTBuiltInResource.maxMeshOutputVerticesNV << "\n"
<< "MaxMeshOutputPrimitivesNV " << DefaultTBuiltInResource.maxMeshOutputPrimitivesNV << "\n" << "MaxMeshOutputPrimitivesNV " << DefaultTBuiltInResource.maxMeshOutputPrimitivesNV << "\n"
<< "MaxMeshWorkGroupSizeX_NV " << DefaultTBuiltInResource.maxMeshWorkGroupSizeX_NV << "\n" << "MaxMeshWorkGroupSizeX_NV " << DefaultTBuiltInResource.maxMeshWorkGroupSizeX_NV << "\n"
@ -244,7 +243,6 @@ std::string GetDefaultTBuiltInResourceString()
<< "MaxTaskWorkGroupSizeY_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeY_NV << "\n" << "MaxTaskWorkGroupSizeY_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeY_NV << "\n"
<< "MaxTaskWorkGroupSizeZ_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeZ_NV << "\n" << "MaxTaskWorkGroupSizeZ_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeZ_NV << "\n"
<< "MaxMeshViewCountNV " << DefaultTBuiltInResource.maxMeshViewCountNV << "\n" << "MaxMeshViewCountNV " << DefaultTBuiltInResource.maxMeshViewCountNV << "\n"
#endif
<< "nonInductiveForLoops " << DefaultTBuiltInResource.limits.nonInductiveForLoops << "\n" << "nonInductiveForLoops " << DefaultTBuiltInResource.limits.nonInductiveForLoops << "\n"
<< "whileLoops " << DefaultTBuiltInResource.limits.whileLoops << "\n" << "whileLoops " << DefaultTBuiltInResource.limits.whileLoops << "\n"
<< "doWhileLoops " << DefaultTBuiltInResource.limits.doWhileLoops << "\n" << "doWhileLoops " << DefaultTBuiltInResource.limits.doWhileLoops << "\n"
@ -451,7 +449,6 @@ void DecodeResourceLimits(TBuiltInResource* resources, char* config)
resources->maxCombinedClipAndCullDistances = value; resources->maxCombinedClipAndCullDistances = value;
else if (tokenStr == "MaxSamples") else if (tokenStr == "MaxSamples")
resources->maxSamples = value; resources->maxSamples = value;
#ifdef NV_EXTENSIONS
else if (tokenStr == "MaxMeshOutputVerticesNV") else if (tokenStr == "MaxMeshOutputVerticesNV")
resources->maxMeshOutputVerticesNV = value; resources->maxMeshOutputVerticesNV = value;
else if (tokenStr == "MaxMeshOutputPrimitivesNV") else if (tokenStr == "MaxMeshOutputPrimitivesNV")
@ -470,7 +467,6 @@ void DecodeResourceLimits(TBuiltInResource* resources, char* config)
resources->maxTaskWorkGroupSizeZ_NV = value; resources->maxTaskWorkGroupSizeZ_NV = value;
else if (tokenStr == "MaxMeshViewCountNV") else if (tokenStr == "MaxMeshViewCountNV")
resources->maxMeshViewCountNV = value; resources->maxMeshViewCountNV = value;
#endif
else if (tokenStr == "nonInductiveForLoops") else if (tokenStr == "nonInductiveForLoops")
resources->limits.nonInductiveForLoops = (value != 0); resources->limits.nonInductiveForLoops = (value != 0);
else if (tokenStr == "whileLoops") else if (tokenStr == "whileLoops")

View File

@ -146,11 +146,13 @@ void ProcessConfigFile()
{ {
if (ConfigFile.size() == 0) if (ConfigFile.size() == 0)
Resources = glslang::DefaultTBuiltInResource; Resources = glslang::DefaultTBuiltInResource;
#ifndef GLSLANG_WEB
else { else {
char* configString = ReadFileData(ConfigFile.c_str()); char* configString = ReadFileData(ConfigFile.c_str());
glslang::DecodeResourceLimits(&Resources, configString); glslang::DecodeResourceLimits(&Resources, configString);
FreeFileData(configString); FreeFileData(configString);
} }
#endif
} }
int ReflectOptions = EShReflectionDefault; int ReflectOptions = EShReflectionDefault;
@ -1118,8 +1120,10 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
} else { } else {
glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage)); glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
} }
#ifndef GLSLANG_WEB
if (!SpvToolsDisassembler && (Options & EOptionHumanReadableSpv)) if (!SpvToolsDisassembler && (Options & EOptionHumanReadableSpv))
spv::Disassemble(std::cout, spirv); spv::Disassemble(std::cout, spirv);
#endif
} }
} }
} }
@ -1207,11 +1211,13 @@ int singleMain()
workList.add(item.get()); workList.add(item.get());
}); });
#ifndef GLSLANG_WEB
if (Options & EOptionDumpConfig) { if (Options & EOptionDumpConfig) {
printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str()); printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str());
if (workList.empty()) if (workList.empty())
return ESuccess; return ESuccess;
} }
#endif
if (Options & EOptionDumpBareVersion) { if (Options & EOptionDumpBareVersion) {
printf("%d.%d.%d\n", printf("%d.%d.%d\n",

View File

@ -1 +1 @@
1202688 ../build/install/bin/glslangValidator.exe 1097728 ../build/install/bin/glslangValidator.exe

View File

@ -55,8 +55,8 @@ diff -b $BASEDIR/hlsl.automap.frag.out $TARGETDIR/hlsl.automap.frag.out || HASER
# multi-threaded test # multi-threaded test
# #
echo Comparing single thread to multithread for all tests in current directory... echo Comparing single thread to multithread for all tests in current directory...
$EXE -i -C *.vert *.geom *.frag *.tes* *.comp > singleThread.out $EXE -i -C *.vert *.geom *.frag *.tesc *.tese *.comp > singleThread.out
$EXE -i -C *.vert *.geom *.frag *.tes* *.comp -t > multiThread.out $EXE -i -C *.vert *.geom *.frag *.tesc *.tese *.comp -t > multiThread.out
diff singleThread.out multiThread.out || HASERROR=1 diff singleThread.out multiThread.out || HASERROR=1
if [ $HASERROR -eq 0 ] if [ $HASERROR -eq 0 ]
then then

View File

@ -2729,6 +2729,7 @@ bool TIntermediate::postProcess(TIntermNode* root, EShLanguage /*language*/)
if (aggRoot && aggRoot->getOp() == EOpNull) if (aggRoot && aggRoot->getOp() == EOpNull)
aggRoot->setOperator(EOpSequence); aggRoot->setOperator(EOpSequence);
#ifndef GLSLANG_WEB
// Propagate 'noContraction' label in backward from 'precise' variables. // Propagate 'noContraction' label in backward from 'precise' variables.
glslang::PropagateNoContraction(*this); glslang::PropagateNoContraction(*this);
@ -2739,6 +2740,7 @@ bool TIntermediate::postProcess(TIntermNode* root, EShLanguage /*language*/)
performTextureUpgradeAndSamplerRemovalTransformation(root); performTextureUpgradeAndSamplerRemovalTransformation(root);
break; break;
} }
#endif
return true; return true;
} }

View File

@ -4737,9 +4737,11 @@ void TParseContext::finish()
if (parsingBuiltins) if (parsingBuiltins)
return; return;
#ifndef GLSLANG_WEB
// Check on array indexes for ES 2.0 (version 100) limitations. // Check on array indexes for ES 2.0 (version 100) limitations.
for (size_t i = 0; i < needsIndexLimitationChecking.size(); ++i) for (size_t i = 0; i < needsIndexLimitationChecking.size(); ++i)
constantIndexExpressionCheck(needsIndexLimitationChecking[i]); constantIndexExpressionCheck(needsIndexLimitationChecking[i]);
#endif
// Check for stages that are enabled by extension. // Check for stages that are enabled by extension.
// Can't do this at the beginning, it is chicken and egg to add a stage by // Can't do this at the beginning, it is chicken and egg to add a stage by