From 23d27751e82f1a430c50fcd72517d9c2ae10ca55 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sun, 28 Jul 2019 02:12:10 -0600 Subject: [PATCH] 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. --- CMakeLists.txt | 4 +++ SPIRV/GlslangToSpv.cpp | 2 ++ SPIRV/SpvBuilder.cpp | 1 + SPIRV/SpvPostProcess.cpp | 8 ------ SPIRV/disassemble.cpp | 31 +-------------------- StandAlone/ResourceLimits.cpp | 4 --- StandAlone/StandAlone.cpp | 6 ++++ Test/baseResults/size | 2 +- Test/runtests | 4 +-- glslang/MachineIndependent/Intermediate.cpp | 2 ++ glslang/MachineIndependent/ParseHelper.cpp | 2 ++ 11 files changed, 21 insertions(+), 45 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c84ae84..be551376 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,10 @@ if(ENABLE_HLSL) add_definitions(-DENABLE_HLSL) endif(ENABLE_HLSL) +if(ENABLE_GLSLANG_WEB) + add_definitions(-DGLSLANG_WEB) +endif(ENABLE_GLSLANG_WEB) + if(WIN32) set(CMAKE_DEBUG_POSTFIX "d") if(MSVC) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 8a17ce3b..dea911b2 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1592,9 +1592,11 @@ void TGlslangToSpvTraverser::finishSpv() for (auto it = iOSet.cbegin(); it != iOSet.cend(); ++it) entryPoint->addIdOperand(*it); +#ifndef GLSLANG_WEB // Add capabilities, extensions, remove unneeded decorations, etc., // based on the resulting SPIR-V. builder.postProcess(); +#endif } // Write the SPV into 'out'. diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp index 4ef7e5fe..51cf3c8b 100644 --- a/SPIRV/SpvBuilder.cpp +++ b/SPIRV/SpvBuilder.cpp @@ -2089,6 +2089,7 @@ Id Builder::createTextureQueryCall(Op opCode, const TextureParameters& parameter if (parameters.lod) query->addIdOperand(parameters.lod); buildPoint->addInstruction(std::unique_ptr(query)); + addCapability(CapabilityImageQuery); return query->getResultId(); } diff --git a/SPIRV/SpvPostProcess.cpp b/SPIRV/SpvPostProcess.cpp index 6e1f7cf6..18765a31 100644 --- a/SPIRV/SpvPostProcess.cpp +++ b/SPIRV/SpvPostProcess.cpp @@ -51,12 +51,8 @@ namespace spv { #include "GLSL.std.450.h" #include "GLSL.ext.KHR.h" #include "GLSL.ext.EXT.h" -#ifdef AMD_EXTENSIONS #include "GLSL.ext.AMD.h" -#endif -#ifdef NV_EXTENSIONS #include "GLSL.ext.NV.h" -#endif } namespace spv { @@ -160,7 +156,6 @@ void Builder::postProcessType(const Instruction& inst, Id typeId) } break; case OpExtInst: -#if AMD_EXTENSIONS switch (inst.getImmediateOperand(1)) { case GLSLstd450Frexp: case GLSLstd450FrexpStruct: @@ -176,7 +171,6 @@ void Builder::postProcessType(const Instruction& inst, Id typeId) default: break; } -#endif break; default: if (basicTypeOp == OpTypeFloat && width == 16) @@ -222,12 +216,10 @@ void Builder::postProcess(Instruction& inst) addCapability(CapabilityImageQuery); break; -#ifdef NV_EXTENSIONS case OpGroupNonUniformPartitionNV: addExtension(E_SPV_NV_shader_subgroup_partitioned); addCapability(CapabilityGroupNonUniformPartitionedNV); break; -#endif case OpLoad: case OpStore: diff --git a/SPIRV/disassemble.cpp b/SPIRV/disassemble.cpp index 80ebac4a..930e7994 100644 --- a/SPIRV/disassemble.cpp +++ b/SPIRV/disassemble.cpp @@ -52,26 +52,16 @@ namespace spv { extern "C" { // Include C-based headers that don't have a namespace #include "GLSL.std.450.h" -#ifdef AMD_EXTENSIONS #include "GLSL.ext.AMD.h" -#endif - -#ifdef NV_EXTENSIONS #include "GLSL.ext.NV.h" -#endif } } const char* GlslStd450DebugNames[spv::GLSLstd450Count]; namespace spv { -#ifdef AMD_EXTENSIONS static const char* GLSLextAMDGetDebugNames(const char*, unsigned); -#endif - -#ifdef NV_EXTENSIONS static const char* GLSLextNVGetDebugNames(const char*, unsigned); -#endif 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 enum ExtInstSet { GLSL450Inst, - -#ifdef AMD_EXTENSIONS GLSLextAMDInst, -#endif - -#ifdef NV_EXTENSIONS GLSLextNVInst, -#endif - OpenCLExtInst, }; @@ -499,37 +482,29 @@ void SpirvStream::disassembleInstruction(Id resultId, Id /*typeId*/, Op opCode, const char* name = idDescriptor[stream[word - 2]].c_str(); if (0 == memcmp("OpenCL", name, 6)) { extInstSet = OpenCLExtInst; -#ifdef AMD_EXTENSIONS } 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_explicit_vertex_parameter, name) == 0 || strcmp(spv::E_SPV_AMD_gcn_shader, name) == 0) { 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_viewport_array2, name) == 0 || strcmp(spv::E_SPV_NVX_multiview_per_view_attributes, name) == 0 || strcmp(spv::E_SPV_NV_fragment_shader_barycentric, name) == 0 || strcmp(spv::E_SPV_NV_mesh_shader, name) == 0) { extInstSet = GLSLextNVInst; -#endif } unsigned entrypoint = stream[word - 1]; if (extInstSet == GLSL450Inst) { if (entrypoint < GLSLstd450Count) { out << "(" << GlslStd450DebugNames[entrypoint] << ")"; } -#ifdef AMD_EXTENSIONS } else if (extInstSet == GLSLextAMDInst) { out << "(" << GLSLextAMDGetDebugNames(name, entrypoint) << ")"; -#endif -#ifdef NV_EXTENSIONS } else if (extInstSet == GLSLextNVInst) { out << "(" << GLSLextNVGetDebugNames(name, entrypoint) << ")"; -#endif } } break; @@ -653,7 +628,6 @@ static void GLSLstd450GetDebugNames(const char** names) names[GLSLstd450NClamp] = "NClamp"; } -#ifdef AMD_EXTENSIONS static const char* GLSLextAMDGetDebugNames(const char* name, unsigned entrypoint) { 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"; } -#endif -#ifdef NV_EXTENSIONS static const char* GLSLextNVGetDebugNames(const char* name, unsigned entrypoint) { 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"; } -#endif void Disassemble(std::ostream& out, const std::vector& stream) { diff --git a/StandAlone/ResourceLimits.cpp b/StandAlone/ResourceLimits.cpp index 66e79af9..028caa66 100644 --- a/StandAlone/ResourceLimits.cpp +++ b/StandAlone/ResourceLimits.cpp @@ -234,7 +234,6 @@ std::string GetDefaultTBuiltInResourceString() << "MaxCullDistances " << DefaultTBuiltInResource.maxCullDistances << "\n" << "MaxCombinedClipAndCullDistances " << DefaultTBuiltInResource.maxCombinedClipAndCullDistances << "\n" << "MaxSamples " << DefaultTBuiltInResource.maxSamples << "\n" -#ifdef NV_EXTENSIONS << "MaxMeshOutputVerticesNV " << DefaultTBuiltInResource.maxMeshOutputVerticesNV << "\n" << "MaxMeshOutputPrimitivesNV " << DefaultTBuiltInResource.maxMeshOutputPrimitivesNV << "\n" << "MaxMeshWorkGroupSizeX_NV " << DefaultTBuiltInResource.maxMeshWorkGroupSizeX_NV << "\n" @@ -244,7 +243,6 @@ std::string GetDefaultTBuiltInResourceString() << "MaxTaskWorkGroupSizeY_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeY_NV << "\n" << "MaxTaskWorkGroupSizeZ_NV " << DefaultTBuiltInResource.maxTaskWorkGroupSizeZ_NV << "\n" << "MaxMeshViewCountNV " << DefaultTBuiltInResource.maxMeshViewCountNV << "\n" -#endif << "nonInductiveForLoops " << DefaultTBuiltInResource.limits.nonInductiveForLoops << "\n" << "whileLoops " << DefaultTBuiltInResource.limits.whileLoops << "\n" << "doWhileLoops " << DefaultTBuiltInResource.limits.doWhileLoops << "\n" @@ -451,7 +449,6 @@ void DecodeResourceLimits(TBuiltInResource* resources, char* config) resources->maxCombinedClipAndCullDistances = value; else if (tokenStr == "MaxSamples") resources->maxSamples = value; -#ifdef NV_EXTENSIONS else if (tokenStr == "MaxMeshOutputVerticesNV") resources->maxMeshOutputVerticesNV = value; else if (tokenStr == "MaxMeshOutputPrimitivesNV") @@ -470,7 +467,6 @@ void DecodeResourceLimits(TBuiltInResource* resources, char* config) resources->maxTaskWorkGroupSizeZ_NV = value; else if (tokenStr == "MaxMeshViewCountNV") resources->maxMeshViewCountNV = value; -#endif else if (tokenStr == "nonInductiveForLoops") resources->limits.nonInductiveForLoops = (value != 0); else if (tokenStr == "whileLoops") diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index 6af00dca..68cb8e90 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -146,11 +146,13 @@ void ProcessConfigFile() { if (ConfigFile.size() == 0) Resources = glslang::DefaultTBuiltInResource; +#ifndef GLSLANG_WEB else { char* configString = ReadFileData(ConfigFile.c_str()); glslang::DecodeResourceLimits(&Resources, configString); FreeFileData(configString); } +#endif } int ReflectOptions = EShReflectionDefault; @@ -1118,8 +1120,10 @@ void CompileAndLinkShaderUnits(std::vector compUnits) } else { glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage)); } +#ifndef GLSLANG_WEB if (!SpvToolsDisassembler && (Options & EOptionHumanReadableSpv)) spv::Disassemble(std::cout, spirv); +#endif } } } @@ -1207,11 +1211,13 @@ int singleMain() workList.add(item.get()); }); +#ifndef GLSLANG_WEB if (Options & EOptionDumpConfig) { printf("%s", glslang::GetDefaultTBuiltInResourceString().c_str()); if (workList.empty()) return ESuccess; } +#endif if (Options & EOptionDumpBareVersion) { printf("%d.%d.%d\n", diff --git a/Test/baseResults/size b/Test/baseResults/size index f2e3e213..060c1428 100644 --- a/Test/baseResults/size +++ b/Test/baseResults/size @@ -1 +1 @@ -1202688 ../build/install/bin/glslangValidator.exe +1097728 ../build/install/bin/glslangValidator.exe diff --git a/Test/runtests b/Test/runtests index c50f1482..cf947a6b 100755 --- a/Test/runtests +++ b/Test/runtests @@ -55,8 +55,8 @@ diff -b $BASEDIR/hlsl.automap.frag.out $TARGETDIR/hlsl.automap.frag.out || HASER # multi-threaded test # 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 *.tes* *.comp -t > multiThread.out +$EXE -i -C *.vert *.geom *.frag *.tesc *.tese *.comp > singleThread.out +$EXE -i -C *.vert *.geom *.frag *.tesc *.tese *.comp -t > multiThread.out diff singleThread.out multiThread.out || HASERROR=1 if [ $HASERROR -eq 0 ] then diff --git a/glslang/MachineIndependent/Intermediate.cpp b/glslang/MachineIndependent/Intermediate.cpp index 19b24af8..8cb4f855 100644 --- a/glslang/MachineIndependent/Intermediate.cpp +++ b/glslang/MachineIndependent/Intermediate.cpp @@ -2729,6 +2729,7 @@ bool TIntermediate::postProcess(TIntermNode* root, EShLanguage /*language*/) if (aggRoot && aggRoot->getOp() == EOpNull) aggRoot->setOperator(EOpSequence); +#ifndef GLSLANG_WEB // Propagate 'noContraction' label in backward from 'precise' variables. glslang::PropagateNoContraction(*this); @@ -2739,6 +2740,7 @@ bool TIntermediate::postProcess(TIntermNode* root, EShLanguage /*language*/) performTextureUpgradeAndSamplerRemovalTransformation(root); break; } +#endif return true; } diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 6df25f0e..9c993672 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -4737,9 +4737,11 @@ void TParseContext::finish() if (parsingBuiltins) return; +#ifndef GLSLANG_WEB // Check on array indexes for ES 2.0 (version 100) limitations. for (size_t i = 0; i < needsIndexLimitationChecking.size(); ++i) constantIndexExpressionCheck(needsIndexLimitationChecking[i]); +#endif // 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