Revision control
Copy as Markdown
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Laszlo Agocs <laszlo.agocs@qt.io>
Date: Wed, 16 Sep 2026 11:00:00 +0200
Subject: [PATCH] Patch glslang 16.6.0 and restore SPVRemapper
Namespacing for INTEGRITY.
Include condition changes for INTEGRITY.
C++ filesystem usage for QNX.
Restore a SPVRemapper ported to spirv.hpp11.
---
src/3rdparty/glslang/LICENSE.txt | 3 +
src/3rdparty/glslang/README.md | 4 +-
src/3rdparty/glslang/SPIRV/GlslangToSpv.cpp | 4 +
src/3rdparty/glslang/SPIRV/GlslangToSpv.h | 4 +-
src/3rdparty/glslang/SPIRV/SPVRemapper.cpp | 1559 +++++++++++++++++
src/3rdparty/glslang/SPIRV/SPVRemapper.h | 300 ++++
src/3rdparty/glslang/SPIRV/SpvTools.cpp | 2 +
src/3rdparty/glslang/SPIRV/SpvTools.h | 2 +
.../glslang/GenericCodeGen/CodeGen.cpp | 2 +
.../glslang/glslang/GenericCodeGen/Link.cpp | 3 +
.../glslang/glslang/Include/BaseTypes.h | 2 +
src/3rdparty/glslang/glslang/Include/Common.h | 8 +-
.../glslang/glslang/Include/ConstantUnion.h | 2 +
.../glslang/glslang/Include/InfoSink.h | 28 +-
.../glslang/Include/InitializeGlobals.h | 2 +
.../glslang/glslang/Include/PoolAlloc.h | 2 +
.../glslang/glslang/Include/ShHandle.h | 4 +
.../glslang/glslang/Include/SpirvIntrinsics.h | 2 +
src/3rdparty/glslang/glslang/Include/Types.h | 6 +
src/3rdparty/glslang/glslang/Include/arrays.h | 2 +
.../glslang/glslang/Include/intermediate.h | 2 +
.../glslang/MachineIndependent/Constant.cpp | 3 +
.../glslang/MachineIndependent/InfoSink.cpp | 2 +
.../glslang/MachineIndependent/Initialize.cpp | 2 +
.../glslang/MachineIndependent/Initialize.h | 2 +
.../MachineIndependent/IntermTraverse.cpp | 2 +
.../MachineIndependent/Intermediate.cpp | 2 +
.../MachineIndependent/LiveTraverser.h | 2 +
.../MachineIndependent/ParseContextBase.cpp | 4 +-
.../MachineIndependent/ParseHelper.cpp | 3 +
.../glslang/MachineIndependent/ParseHelper.h | 2 +
.../glslang/MachineIndependent/PoolAlloc.cpp | 2 +
.../glslang/MachineIndependent/RemoveTree.cpp | 2 +
.../glslang/MachineIndependent/RemoveTree.h | 2 +
.../glslang/MachineIndependent/Scan.cpp | 4 +-
.../glslang/glslang/MachineIndependent/Scan.h | 2 +
.../glslang/MachineIndependent/ScanContext.h | 2 +
.../glslang/MachineIndependent/ShaderLang.cpp | 38 +-
.../MachineIndependent/SpirvIntrinsics.cpp | 2 +
.../MachineIndependent/SymbolTable.cpp | 2 +
.../glslang/MachineIndependent/SymbolTable.h | 5 +-
.../glslang/MachineIndependent/Versions.cpp | 2 +
.../glslang/MachineIndependent/Versions.h | 2 +
.../glslang/MachineIndependent/attribute.cpp | 2 +
.../glslang/MachineIndependent/attribute.h | 2 +
.../MachineIndependent/glslang_tab.cpp | 8 +-
.../MachineIndependent/glslang_tab.cpp.h | 8 +-
.../glslang/MachineIndependent/intermOut.cpp | 2 +
.../glslang/MachineIndependent/iomapper.cpp | 2 +
.../glslang/MachineIndependent/iomapper.h | 2 +
.../glslang/MachineIndependent/limits.cpp | 2 +
.../MachineIndependent/linkValidate.cpp | 2 +
.../MachineIndependent/localintermediate.h | 2 +
.../glslang/MachineIndependent/parseConst.cpp | 2 +
.../MachineIndependent/parseVersions.h | 2 +
.../MachineIndependent/preprocessor/Pp.cpp | 2 +
.../preprocessor/PpAtom.cpp | 3 +
.../preprocessor/PpContext.cpp | 2 +
.../preprocessor/PpContext.h | 2 +
.../preprocessor/PpScanner.cpp | 2 +
.../preprocessor/PpTokens.cpp | 2 +
.../preprocessor/PpTokens.h | 2 +
.../propagateNoContraction.cpp | 2 +
.../propagateNoContraction.h | 4 +-
.../glslang/MachineIndependent/reflection.cpp | 2 +
.../glslang/MachineIndependent/reflection.h | 2 +
.../glslang/OSDependent/Unix/ossource.cpp | 4 +-
.../glslang/OSDependent/Windows/ossource.cpp | 2 +
.../glslang/glslang/OSDependent/osinclude.h | 2 +
.../glslang/glslang/Public/ResourceLimits.h | 4 +
.../glslang/glslang/Public/ShaderLang.h | 42 +-
.../glslang/ResourceLimits/ResourceLimits.cpp | 4 +
72 files changed, 2085 insertions(+), 66 deletions(-)
create mode 100644 src/3rdparty/glslang/SPIRV/SPVRemapper.cpp
create mode 100644 src/3rdparty/glslang/SPIRV/SPVRemapper.h
diff --git a/src/3rdparty/glslang/LICENSE.txt b/src/3rdparty/glslang/LICENSE.txt
index 1ea89c0..054e68a 100644
--- a/src/3rdparty/glslang/LICENSE.txt
+++ b/src/3rdparty/glslang/LICENSE.txt
@@ -13,6 +13,9 @@ Other parts, outside of glslang proper, include:
- update_glslang_sources.py, which is not part of the project proper and does
not need to be used.
+- the SPIR-V "remapper", which is optional, but has the same license as
+ glslang proper
+
- Google tests and SPIR-V tools, and anything in the external subdirectory
are external and optional; see them for their respective licenses.
diff --git a/src/3rdparty/glslang/README.md b/src/3rdparty/glslang/README.md
index 8582354..d771f91 100644
--- a/src/3rdparty/glslang/README.md
+++ b/src/3rdparty/glslang/README.md
@@ -8,9 +8,7 @@
2. The --shift-texture-binding\[s\] option no longer affects combined samplers. The new --shift-combined-sampler-binding\[s\] option should be used to control combined sampler bindings independently from separate textures. The old behavior can be achieved by setting both options to the same value.
-3. The spirv-remap utility from glslang has been ported to the SPIRV-Tools repository as a new optimization pass called canonicalize-ids, available in spirv-opt. See spirv-opt --help for usage details.
-
-4. Building glslang as a DLL or shared library is now possible and supported.
+3. Building glslang as a DLL or shared library is now possible and supported.
# Glslang Components and Status
diff --git a/src/3rdparty/glslang/SPIRV/GlslangToSpv.cpp b/src/3rdparty/glslang/SPIRV/GlslangToSpv.cpp
index 23e7e4e..9a3bbc3 100644
--- a/src/3rdparty/glslang/SPIRV/GlslangToSpv.cpp
+++ b/src/3rdparty/glslang/SPIRV/GlslangToSpv.cpp
@@ -74,6 +74,8 @@ namespace spv {
#include <string>
#include <vector>
+using namespace QtShaderTools;
+
namespace {
namespace {
@@ -12824,6 +12826,7 @@ void TGlslangToSpvTraverser::enableCoopMatConversions()
} // end anonymous namespace
+namespace QtShaderTools {
namespace glslang {
void GetSpirvVersion(std::string& version)
@@ -12960,3 +12963,4 @@ void GlslangToSpv(const TIntermediate& intermediate, std::vector<unsigned int>&
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/SPIRV/GlslangToSpv.h b/src/3rdparty/glslang/SPIRV/GlslangToSpv.h
index 7ca0987..edad157 100644
--- a/src/3rdparty/glslang/SPIRV/GlslangToSpv.h
+++ b/src/3rdparty/glslang/SPIRV/GlslangToSpv.h
@@ -41,6 +41,7 @@
#include "Logger.h"
#include "glslang/Include/visibility.h"
+namespace QtShaderTools {
namespace glslang {
class TIntermediate;
@@ -71,4 +72,5 @@ GLSLANG_EXPORT void GlslangToSpv(const glslang::TIntermediate& intermediate, std
GLSLANG_EXPORT bool OutputSpvBin(const std::vector<unsigned int>& spirv, const char* baseName);
GLSLANG_EXPORT bool OutputSpvHex(const std::vector<unsigned int>& spirv, const char* baseName, const char* varName);
-}
+} // namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/SPIRV/SPVRemapper.cpp b/src/3rdparty/glslang/SPIRV/SPVRemapper.cpp
new file mode 100644
index 0000000..3f10201
--- /dev/null
+++ b/src/3rdparty/glslang/SPIRV/SPVRemapper.cpp
@@ -0,0 +1,1559 @@
+//
+// Copyright (C) 2015 LunarG, Inc.
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+//
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+
+#include "SPVRemapper.h"
+#include "doc.h"
+
+#include <algorithm>
+#include <cassert>
+
+namespace spv {
+
+ // By default, just abort on error. Can be overridden via RegisterErrorHandler
+ spirvbin_t::errorfn_t spirvbin_t::errorHandler = [](const std::string&) { exit(5); };
+ // By default, eat log messages. Can be overridden via RegisterLogHandler
+ spirvbin_t::logfn_t spirvbin_t::logHandler = [](const std::string&) { };
+
+ // This can be overridden to provide other message behavior if needed
+ void spirvbin_t::msg(int minVerbosity, int indent, const std::string& txt) const
+ {
+ if (verbose >= minVerbosity)
+ logHandler(std::string(indent, ' ') + txt);
+ }
+
+ // hash opcode, with special handling for OpExtInst
+ std::uint32_t spirvbin_t::asOpCodeHash(unsigned word)
+ {
+ const spv::Op opCode = asOpCode(word);
+
+ std::uint32_t offset = 0;
+
+ switch (opCode) {
+ case spv::Op::OpExtInst:
+ offset += asId(word + 4); break;
+ default:
+ break;
+ }
+
+ return std::uint32_t(opCode) * 19 + offset; // 19 = small prime
+ }
+
+ spirvbin_t::range_t spirvbin_t::literalRange(spv::Op opCode) const
+ {
+ static const int maxCount = 1<<30;
+
+ switch (opCode) {
+ case spv::Op::OpTypeFloat: // fall through...
+ case spv::Op::OpTypePointer: return range_t(2, 3);
+ case spv::Op::OpTypeInt: return range_t(2, 4);
+ // TODO: case spv::OpTypeImage:
+ // TODO: case spv::OpTypeSampledImage:
+ case spv::Op::OpTypeSampler: return range_t(3, 8);
+ case spv::Op::OpTypeVector: // fall through
+ case spv::Op::OpTypeMatrix: // ...
+ case spv::Op::OpTypePipe: return range_t(3, 4);
+ case spv::Op::OpConstant: return range_t(3, maxCount);
+ default: return range_t(0, 0);
+ }
+ }
+
+ spirvbin_t::range_t spirvbin_t::typeRange(spv::Op opCode) const
+ {
+ static const int maxCount = 1<<30;
+
+ if (isConstOp(opCode))
+ return range_t(1, 2);
+
+ switch (opCode) {
+ case spv::Op::OpTypeVector: // fall through
+ case spv::Op::OpTypeMatrix: // ...
+ case spv::Op::OpTypeSampler: // ...
+ case spv::Op::OpTypeArray: // ...
+ case spv::Op::OpTypeRuntimeArray: // ...
+ case spv::Op::OpTypePipe: return range_t(2, 3);
+ case spv::Op::OpTypeStruct: // fall through
+ case spv::Op::OpTypeFunction: return range_t(2, maxCount);
+ case spv::Op::OpTypePointer: return range_t(3, 4);
+ default: return range_t(0, 0);
+ }
+ }
+
+ spirvbin_t::range_t spirvbin_t::constRange(spv::Op opCode) const
+ {
+ static const int maxCount = 1<<30;
+
+ switch (opCode) {
+ case spv::Op::OpTypeArray: // fall through...
+ case spv::Op::OpTypeRuntimeArray: return range_t(3, 4);
+ case spv::Op::OpConstantComposite: return range_t(3, maxCount);
+ default: return range_t(0, 0);
+ }
+ }
+
+ // Return the size of a type in 32-bit words. This currently only
+ // handles ints and floats, and is only invoked by queries which must be
+ // integer types. If ever needed, it can be generalized.
+ unsigned spirvbin_t::typeSizeInWords(spv::Id id) const
+ {
+ const unsigned typeStart = idPos(id);
+ const spv::Op opCode = asOpCode(typeStart);
+
+ if (errorLatch)
+ return 0;
+
+ switch (opCode) {
+ case spv::Op::OpTypeInt: // fall through...
+ case spv::Op::OpTypeFloat: return (spv[typeStart+2]+31)/32;
+ default:
+ return 0;
+ }
+ }
+
+ // Looks up the type of a given const or variable ID, and
+ // returns its size in 32-bit words.
+ unsigned spirvbin_t::idTypeSizeInWords(spv::Id id) const
+ {
+ const auto tid_it = idTypeSizeMap.find(id);
+ if (tid_it == idTypeSizeMap.end()) {
+ error("type size for ID not found");
+ return 0;
+ }
+
+ return tid_it->second;
+ }
+
+ // Is this an opcode we should remove when using --strip?
+ bool spirvbin_t::isStripOp(spv::Op opCode, unsigned start) const
+ {
+ switch (opCode) {
+ case spv::Op::OpSource:
+ case spv::Op::OpSourceExtension:
+ case spv::Op::OpName:
+ case spv::Op::OpMemberName:
+ case spv::Op::OpLine :
+ {
+ const std::string name = literalString(start + 2);
+
+ std::vector<std::string>::const_iterator it;
+ for (it = stripWhiteList.begin(); it < stripWhiteList.end(); it++)
+ {
+ if (name.find(*it) != std::string::npos) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+ default :
+ return false;
+ }
+ }
+
+ // Return true if this opcode is flow control
+ bool spirvbin_t::isFlowCtrl(spv::Op opCode) const
+ {
+ switch (opCode) {
+ case spv::Op::OpBranchConditional:
+ case spv::Op::OpBranch:
+ case spv::Op::OpSwitch:
+ case spv::Op::OpLoopMerge:
+ case spv::Op::OpSelectionMerge:
+ case spv::Op::OpLabel:
+ case spv::Op::OpFunction:
+ case spv::Op::OpFunctionEnd: return true;
+ default: return false;
+ }
+ }
+
+ // Return true if this opcode defines a type
+ bool spirvbin_t::isTypeOp(spv::Op opCode) const
+ {
+ switch (opCode) {
+ case spv::Op::OpTypeVoid:
+ case spv::Op::OpTypeBool:
+ case spv::Op::OpTypeInt:
+ case spv::Op::OpTypeFloat:
+ case spv::Op::OpTypeVector:
+ case spv::Op::OpTypeMatrix:
+ case spv::Op::OpTypeImage:
+ case spv::Op::OpTypeSampler:
+ case spv::Op::OpTypeArray:
+ case spv::Op::OpTypeRuntimeArray:
+ case spv::Op::OpTypeStruct:
+ case spv::Op::OpTypeOpaque:
+ case spv::Op::OpTypePointer:
+ case spv::Op::OpTypeFunction:
+ case spv::Op::OpTypeEvent:
+ case spv::Op::OpTypeDeviceEvent:
+ case spv::Op::OpTypeReserveId:
+ case spv::Op::OpTypeQueue:
+ case spv::Op::OpTypeSampledImage:
+ case spv::Op::OpTypePipe: return true;
+ default: return false;
+ }
+ }
+
+ // Return true if this opcode defines a constant
+ bool spirvbin_t::isConstOp(spv::Op opCode) const
+ {
+ switch (opCode) {
+ case spv::Op::OpConstantSampler:
+ error("unimplemented constant type");
+ return true;
+
+ case spv::Op::OpConstantNull:
+ case spv::Op::OpConstantTrue:
+ case spv::Op::OpConstantFalse:
+ case spv::Op::OpConstantComposite:
+ case spv::Op::OpConstant:
+ return true;
+
+ default:
+ return false;
+ }
+ }
+
+ const auto inst_fn_nop = [](spv::Op, unsigned) { return false; };
+ const auto op_fn_nop = [](spv::Id&) { };
+
+ // g++ doesn't like these defined in the class proper in an anonymous namespace.
+ // Dunno why. Also MSVC doesn't like the constexpr keyword. Also dunno why.
+ // Defining them externally seems to please both compilers, so, here they are.
+ const spv::Id spirvbin_t::unmapped = spv::Id(-10000);
+ const spv::Id spirvbin_t::unused = spv::Id(-10001);
+ const int spirvbin_t::header_size = 5;
+
+ spv::Id spirvbin_t::nextUnusedId(spv::Id id)
+ {
+ while (isNewIdMapped(id)) // search for an unused ID
+ ++id;
+
+ return id;
+ }
+
+ spv::Id spirvbin_t::localId(spv::Id id, spv::Id newId)
+ {
+ //assert(id != spv::NoResult && newId != spv::NoResult);
+
+ if (id > bound()) {
+ error(std::string("ID out of range: ") + std::to_string(id));
+ return spirvbin_t::unused;
+ }
+
+ if (id >= idMapL.size())
+ idMapL.resize(id+1, unused);
+
+ if (newId != unmapped && newId != unused) {
+ if (isOldIdUnused(id)) {
+ error(std::string("ID unused in module: ") + std::to_string(id));
+ return spirvbin_t::unused;
+ }
+
+ if (!isOldIdUnmapped(id)) {
+ error(std::string("ID already mapped: ") + std::to_string(id) + " -> "
+ + std::to_string(localId(id)));
+
+ return spirvbin_t::unused;
+ }
+
+ if (isNewIdMapped(newId)) {
+ error(std::string("ID already used in module: ") + std::to_string(newId));
+ return spirvbin_t::unused;
+ }
+
+ msg(4, 4, std::string("map: ") + std::to_string(id) + " -> " + std::to_string(newId));
+ setMapped(newId);
+ largestNewId = std::max(largestNewId, newId);
+ }
+
+ return idMapL[id] = newId;
+ }
+
+ // Parse a literal string from the SPIR binary and return it as an std::string
+ // Due to C++11 RValue references, this doesn't copy the result string.
+ std::string spirvbin_t::literalString(unsigned word) const
+ {
+ std::string literal;
+ const spirword_t * pos = spv.data() + word;
+
+ literal.reserve(16);
+
+ do {
+ spirword_t word = *pos;
+ for (int i = 0; i < 4; i++) {
+ char c = word & 0xff;
+ if (c == '\0')
+ return literal;
+ literal += c;
+ word >>= 8;
+ }
+ pos++;
+ } while (true);
+ }
+
+ void spirvbin_t::applyMap()
+ {
+ msg(3, 2, std::string("Applying map: "));
+
+ // Map local IDs through the ID map
+ process(inst_fn_nop, // ignore instructions
+ [this](spv::Id& id) {
+ id = localId(id);
+
+ if (errorLatch)
+ return;
+
+ assert(id != unused && id != unmapped);
+ }
+ );
+ }
+
+ // Find free IDs for anything we haven't mapped
+ void spirvbin_t::mapRemainder()
+ {
+ msg(3, 2, std::string("Remapping remainder: "));
+
+ spv::Id unusedId = 1; // can't use 0: that's NoResult
+ spirword_t maxBound = 0;
+
+ for (spv::Id id = 0; id < idMapL.size(); ++id) {
+ if (isOldIdUnused(id))
+ continue;
+
+ // Find a new mapping for any used but unmapped IDs
+ if (isOldIdUnmapped(id)) {
+ localId(id, unusedId = nextUnusedId(unusedId));
+ if (errorLatch)
+ return;
+ }
+
+ if (isOldIdUnmapped(id)) {
+ error(std::string("old ID not mapped: ") + std::to_string(id));
+ return;
+ }
+
+ // Track max bound
+ maxBound = std::max(maxBound, localId(id) + 1);
+
+ if (errorLatch)
+ return;
+ }
+
+ bound(maxBound); // reset header ID bound to as big as it now needs to be
+ }
+
+ // Mark debug instructions for stripping
+ void spirvbin_t::stripDebug()
+ {
+ // Strip instructions in the stripOp set: debug info.
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ // remember opcodes we want to strip later
+ if (isStripOp(opCode, start))
+ stripInst(start);
+ return true;
+ },
+ op_fn_nop);
+ }
+
+ // Mark instructions that refer to now-removed IDs for stripping
+ void spirvbin_t::stripDeadRefs()
+ {
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ // strip opcodes pointing to removed data
+ switch (opCode) {
+ case spv::Op::OpName:
+ case spv::Op::OpMemberName:
+ case spv::Op::OpDecorate:
+ case spv::Op::OpMemberDecorate:
+ if (idPosR.find(asId(start+1)) == idPosR.end())
+ stripInst(start);
+ break;
+ default:
+ break; // leave it alone
+ }
+
+ return true;
+ },
+ op_fn_nop);
+
+ strip();
+ }
+
+ // Update local maps of ID, type, etc positions
+ void spirvbin_t::buildLocalMaps()
+ {
+ msg(2, 2, std::string("build local maps: "));
+
+ mapped.clear();
+ idMapL.clear();
+// preserve nameMap, so we don't clear that.
+ fnPos.clear();
+ fnCalls.clear();
+ typeConstPos.clear();
+ idPosR.clear();
+ entryPoint = spv::NoResult;
+ largestNewId = 0;
+
+ idMapL.resize(bound(), unused);
+
+ int fnStart = 0;
+ spv::Id fnRes = spv::NoResult;
+
+ // build local Id and name maps
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ unsigned word = start+1;
+ spv::Id typeId = spv::NoResult;
+
+ if (spv::InstructionDesc[std::uint32_t(opCode)].hasType())
+ typeId = asId(word++);
+
+ // If there's a result ID, remember the size of its type
+ if (spv::InstructionDesc[std::uint32_t(opCode)].hasResult()) {
+ const spv::Id resultId = asId(word++);
+ idPosR[resultId] = start;
+
+ if (typeId != spv::NoResult) {
+ const unsigned idTypeSize = typeSizeInWords(typeId);
+
+ if (errorLatch)
+ return false;
+
+ if (idTypeSize != 0)
+ idTypeSizeMap[resultId] = idTypeSize;
+ }
+ }
+
+ if (opCode == spv::Op::OpName) {
+ const spv::Id target = asId(start+1);
+ const std::string name = literalString(start+2);
+ nameMap[name] = target;
+
+ } else if (opCode == spv::Op::OpFunctionCall) {
+ ++fnCalls[asId(start + 3)];
+ } else if (opCode == spv::Op::OpEntryPoint) {
+ entryPoint = asId(start + 2);
+ } else if (opCode == spv::Op::OpFunction) {
+ if (fnStart != 0) {
+ error("nested function found");
+ return false;
+ }
+
+ fnStart = start;
+ fnRes = asId(start + 2);
+ } else if (opCode == spv::Op::OpFunctionEnd) {
+ assert(fnRes != spv::NoResult);
+ if (fnStart == 0) {
+ error("function end without function start");
+ return false;
+ }
+
+ fnPos[fnRes] = range_t(fnStart, start + asWordCount(start));
+ fnStart = 0;
+ } else if (isConstOp(opCode)) {
+ if (errorLatch)
+ return false;
+
+ assert(asId(start + 2) != spv::NoResult);
+ typeConstPos.insert(start);
+ } else if (isTypeOp(opCode)) {
+ assert(asId(start + 1) != spv::NoResult);
+ typeConstPos.insert(start);
+ }
+
+ return false;
+ },
+
+ [this](spv::Id& id) { localId(id, unmapped); }
+ );
+ }
+
+ // Validate the SPIR header
+ void spirvbin_t::validate() const
+ {
+ msg(2, 2, std::string("validating: "));
+
+ if (spv.size() < header_size) {
+ error("file too short: ");
+ return;
+ }
+
+ if (magic() != spv::MagicNumber) {
+ error("bad magic number");
+ return;
+ }
+
+ // field 1 = version
+ // field 2 = generator magic
+ // field 3 = result <id> bound
+
+ if (schemaNum() != 0) {
+ error("bad schema, must be 0");
+ return;
+ }
+ }
+
+ int spirvbin_t::processInstruction(unsigned word, instfn_t instFn, idfn_t idFn)
+ {
+ const auto instructionStart = word;
+ const unsigned wordCount = asWordCount(instructionStart);
+ const int nextInst = word++ + wordCount;
+ spv::Op opCode = asOpCode(instructionStart);
+
+ if (nextInst > int(spv.size())) {
+ error("spir instruction terminated too early");
+ return -1;
+ }
+
+ // Base for computing number of operands; will be updated as more is learned
+ unsigned numOperands = wordCount - 1;
+
+ if (instFn(opCode, instructionStart))
+ return nextInst;
+
+ // Read type and result ID from instruction desc table
+ if (spv::InstructionDesc[std::uint32_t(opCode)].hasType()) {
+ idFn(asId(word++));
+ --numOperands;
+ }
+
+ if (spv::InstructionDesc[std::uint32_t(opCode)].hasResult()) {
+ idFn(asId(word++));
+ --numOperands;
+ }
+
+ // Extended instructions: currently, assume everything is an ID.
+ // TODO: add whatever data we need for exceptions to that
+ if (opCode == spv::Op::OpExtInst) {
+
+ idFn(asId(word)); // Instruction set is an ID that also needs to be mapped
+
+ word += 2; // instruction set, and instruction from set
+ numOperands -= 2;
+
+ for (unsigned op=0; op < numOperands; ++op)
+ idFn(asId(word++)); // ID
+
+ return nextInst;
+ }
+
+ // Circular buffer so we can look back at previous unmapped values during the mapping pass.
+ static const unsigned idBufferSize = 4;
+ spv::Id idBuffer[idBufferSize];
+ unsigned idBufferPos = 0;
+
+ // Store IDs from instruction in our map
+ for (int op = 0; numOperands > 0; ++op, --numOperands) {
+ // SpecConstantOp is special: it includes the operands of another opcode which is
+ // given as a literal in the 3rd word. We will switch over to pretending that the
+ // opcode being processed is the literal opcode value of the SpecConstantOp. See the
+ // SPIRV spec for details. This way we will handle IDs and literals as appropriate for
+ // the embedded op.
+ if (opCode == spv::Op::OpSpecConstantOp) {
+ if (op == 0) {
+ opCode = asOpCode(word++); // this is the opcode embedded in the SpecConstantOp.
+ --numOperands;
+ }
+ }
+
+ switch (spv::InstructionDesc[std::uint32_t(opCode)].operands.getClass(op)) {
+ case spv::OperandId:
+ case spv::OperandScope:
+ case spv::OperandMemorySemantics:
+ idBuffer[idBufferPos] = asId(word);
+ idBufferPos = (idBufferPos + 1) % idBufferSize;
+ idFn(asId(word++));
+ break;
+
+ case spv::OperandVariableIds:
+ for (unsigned i = 0; i < numOperands; ++i)
+ idFn(asId(word++));
+ return nextInst;
+
+ case spv::OperandVariableLiterals:
+ // for clarity
+ // if (opCode == spv::OpDecorate && asDecoration(word - 1) == spv::DecorationBuiltIn) {
+ // ++word;
+ // --numOperands;
+ // }
+ // word += numOperands;
+ return nextInst;
+
+ case spv::OperandVariableLiteralId: {
+ if (opCode == spv::Op::OpSwitch) {
+ // word-2 is the position of the selector ID. OpSwitch Literals match its type.
+ // In case the IDs are currently being remapped, we get the word[-2] ID from
+ // the circular idBuffer.
+ const unsigned literalSizePos = (idBufferPos+idBufferSize-2) % idBufferSize;
+ const unsigned literalSize = idTypeSizeInWords(idBuffer[literalSizePos]);
+ const unsigned numLiteralIdPairs = (nextInst-word) / (1+literalSize);
+
+ if (errorLatch)
+ return -1;
+
+ for (unsigned arg=0; arg<numLiteralIdPairs; ++arg) {
+ word += literalSize; // literal
+ idFn(asId(word++)); // label
+ }
+ } else {
+ assert(0); // currentely, only OpSwitch uses OperandVariableLiteralId
+ }
+
+ return nextInst;
+ }
+
+ case spv::OperandLiteralString: {
+ const int stringWordCount = literalStringWords(literalString(word));
+ word += stringWordCount;
+ numOperands -= (stringWordCount-1); // -1 because for() header post-decrements
+ break;
+ }
+
+ case spv::OperandVariableLiteralStrings:
+ return nextInst;
+
+ // Execution mode might have extra literal operands. Skip them.
+ case spv::OperandExecutionMode:
+ return nextInst;
+
+ case spv::OperandMemoryAccess:
+ {
+ uint32_t mask = spv[word];
+ if (mask & uint32_t(spv::MemoryAccessMask::Aligned)) {
+ ++word;
+ --numOperands;
+ }
+ if (mask & uint32_t(spv::MemoryAccessMask::MakePointerAvailable |
+ spv::MemoryAccessMask::MakePointerVisible)) {
+ idFn(asId(word+1));
+ ++word;
+ --numOperands;
+ }
+ ++word;
+ }
+ break;
+
+ case spv::OperandTensorAddressingOperands:
+ {
+ uint32_t mask = spv[word];
+ if (mask & uint32_t(spv::TensorAddressingOperandsMask::TensorView)) {
+ idFn(asId(word+1));
+ ++word;
+ --numOperands;
+ }
+ if (mask & uint32_t(spv::TensorAddressingOperandsMask::DecodeFunc)) {
+ idFn(asId(word+1));
+ ++word;
+ --numOperands;
+ }
+ ++word;
+ }
+ break;
+
+ // Single word operands we simply ignore, as they hold no IDs
+ case spv::OperandLiteralNumber:
+ case spv::OperandSource:
+ case spv::OperandExecutionModel:
+ case spv::OperandAddressing:
+ case spv::OperandMemory:
+ case spv::OperandStorage:
+ case spv::OperandDimensionality:
+ case spv::OperandSamplerAddressingMode:
+ case spv::OperandSamplerFilterMode:
+ case spv::OperandSamplerImageFormat:
+ case spv::OperandImageChannelOrder:
+ case spv::OperandImageChannelDataType:
+ case spv::OperandImageOperands:
+ case spv::OperandFPFastMath:
+ case spv::OperandFPRoundingMode:
+ case spv::OperandLinkageType:
+ case spv::OperandAccessQualifier:
+ case spv::OperandFuncParamAttr:
+ case spv::OperandDecoration:
+ case spv::OperandBuiltIn:
+ case spv::OperandSelect:
+ case spv::OperandLoop:
+ case spv::OperandFunction:
+ case spv::OperandGroupOperation:
+ case spv::OperandKernelEnqueueFlags:
+ case spv::OperandKernelProfilingInfo:
+ case spv::OperandCapability:
+ case spv::OperandCooperativeMatrixOperands:
+ ++word;
+ break;
+
+ default:
+ assert(0 && "Unhandled Operand Class");
+ break;
+ }
+ }
+
+ return nextInst;
+ }
+
+ // Make a pass over all the instructions and process them given appropriate functions
+ spirvbin_t& spirvbin_t::process(instfn_t instFn, idfn_t idFn, unsigned begin, unsigned end)
+ {
+ // For efficiency, reserve name map space. It can grow if needed.
+ nameMap.reserve(32);
+
+ // If begin or end == 0, use defaults
+ begin = (begin == 0 ? header_size : begin);
+ end = (end == 0 ? unsigned(spv.size()) : end);
+
+ // basic parsing and InstructionDesc table borrowed from SpvDisassemble.cpp...
+ unsigned nextInst = unsigned(spv.size());
+
+ for (unsigned word = begin; word < end; word = nextInst) {
+ nextInst = processInstruction(word, instFn, idFn);
+
+ if (errorLatch)
+ return *this;
+ }
+
+ return *this;
+ }
+
+ // Apply global name mapping to a single module
+ void spirvbin_t::mapNames()
+ {
+ static const std::uint32_t softTypeIdLimit = 3011; // small prime. TODO: get from options
+ static const std::uint32_t firstMappedID = 3019; // offset into ID space
+
+ for (const auto& name : nameMap) {
+ std::uint32_t hashval = 1911;
+ for (const char c : name.first)
+ hashval = hashval * 1009 + c;
+
+ if (isOldIdUnmapped(name.second)) {
+ localId(name.second, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
+ if (errorLatch)
+ return;
+ }
+ }
+ }
+
+ // Map fn contents to IDs of similar functions in other modules
+ void spirvbin_t::mapFnBodies()
+ {
+ static const std::uint32_t softTypeIdLimit = 19071; // small prime. TODO: get from options
+ static const std::uint32_t firstMappedID = 6203; // offset into ID space
+
+ // Initial approach: go through some high priority opcodes first and assign them
+ // hash values.
+
+ spv::Id fnId = spv::NoResult;
+ std::vector<unsigned> instPos;
+ instPos.reserve(unsigned(spv.size()) / 16); // initial estimate; can grow if needed.
+
+ // Build local table of instruction start positions
+ process(
+ [&](spv::Op, unsigned start) { instPos.push_back(start); return true; },
+ op_fn_nop);
+
+ if (errorLatch)
+ return;
+
+ // Window size for context-sensitive canonicalization values
+ // Empirical best size from a single data set. TODO: Would be a good tunable.
+ // We essentially perform a little convolution around each instruction,
+ // to capture the flavor of nearby code, to hopefully match to similar
+ // code in other modules.
+ static const unsigned windowSize = 2;
+
+ for (unsigned entry = 0; entry < unsigned(instPos.size()); ++entry) {
+ const unsigned start = instPos[entry];
+ const spv::Op opCode = asOpCode(start);
+
+ if (opCode == spv::Op::OpFunction)
+ fnId = asId(start + 2);
+
+ if (opCode == spv::Op::OpFunctionEnd)
+ fnId = spv::NoResult;
+
+ if (fnId != spv::NoResult) { // if inside a function
+ if (spv::InstructionDesc[std::uint32_t(opCode)].hasResult()) {
+ const unsigned word = start + (spv::InstructionDesc[std::uint32_t(opCode)].hasType() ? 2 : 1);
+ const spv::Id resId = asId(word);
+ std::uint32_t hashval = fnId * 17; // small prime
+
+ for (unsigned i = entry-1; i >= entry-windowSize; --i) {
+ if (asOpCode(instPos[i]) == spv::Op::OpFunction)
+ break;
+ hashval = hashval * 30103 + asOpCodeHash(instPos[i]); // 30103 = semiarbitrary prime
+ }
+
+ for (unsigned i = entry; i <= entry + windowSize; ++i) {
+ if (asOpCode(instPos[i]) == spv::Op::OpFunctionEnd)
+ break;
+ hashval = hashval * 30103 + asOpCodeHash(instPos[i]); // 30103 = semiarbitrary prime
+ }
+
+ if (isOldIdUnmapped(resId)) {
+ localId(resId, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
+ if (errorLatch)
+ return;
+ }
+
+ }
+ }
+ }
+
+ spv::Op thisOpCode(spv::Op::OpNop);
+ std::unordered_map<int, int> opCounter;
+ int idCounter(0);
+ fnId = spv::NoResult;
+
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ switch (opCode) {
+ case spv::Op::OpFunction:
+ // Reset counters at each function
+ idCounter = 0;
+ opCounter.clear();
+ fnId = asId(start + 2);
+ break;
+
+ case spv::Op::OpImageSampleImplicitLod:
+ case spv::Op::OpImageSampleExplicitLod:
+ case spv::Op::OpImageSampleDrefImplicitLod:
+ case spv::Op::OpImageSampleDrefExplicitLod:
+ case spv::Op::OpImageSampleProjImplicitLod:
+ case spv::Op::OpImageSampleProjExplicitLod:
+ case spv::Op::OpImageSampleProjDrefImplicitLod:
+ case spv::Op::OpImageSampleProjDrefExplicitLod:
+ case spv::Op::OpDot:
+ case spv::Op::OpCompositeExtract:
+ case spv::Op::OpCompositeInsert:
+ case spv::Op::OpVectorShuffle:
+ case spv::Op::OpLabel:
+ case spv::Op::OpVariable:
+
+ case spv::Op::OpAccessChain:
+ case spv::Op::OpLoad:
+ case spv::Op::OpStore:
+ case spv::Op::OpCompositeConstruct:
+ case spv::Op::OpFunctionCall:
+ ++opCounter[std::uint32_t(opCode)];
+ idCounter = 0;
+ thisOpCode = opCode;
+ break;
+ default:
+ thisOpCode = spv::Op::OpNop;
+ }
+
+ return false;
+ },
+
+ [&](spv::Id& id) {
+ if (thisOpCode != spv::Op::OpNop) {
+ ++idCounter;
+ const std::uint32_t hashval =
+ // Explicitly cast operands to unsigned int to avoid integer
+ // promotion to signed int followed by integer overflow,
+ // which would result in undefined behavior.
+ static_cast<unsigned int>(opCounter[std::uint32_t(thisOpCode)])
+ * std::uint32_t(thisOpCode)
+ * 50047
+ + idCounter
+ + static_cast<unsigned int>(fnId) * 117;
+
+ if (isOldIdUnmapped(id))
+ localId(id, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
+ }
+ });
+ }
+
+ // EXPERIMENTAL: forward IO and uniform load/stores into operands
+ // This produces invalid Schema-0 SPIRV
+ void spirvbin_t::forwardLoadStores()
+ {
+ idset_t fnLocalVars; // set of function local vars
+ idmap_t idMap; // Map of load result IDs to what they load
+
+ // EXPERIMENTAL: Forward input and access chain loads into consumptions
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ // Add inputs and uniforms to the map
+ if ((opCode == spv::Op::OpVariable && asWordCount(start) == 4) &&
+ (spv[start+3] == std::uint32_t(spv::StorageClass::Uniform) ||
+ spv[start+3] == std::uint32_t(spv::StorageClass::UniformConstant) ||
+ spv[start+3] == std::uint32_t(spv::StorageClass::Input)))
+ fnLocalVars.insert(asId(start+2));
+
+ if (opCode == spv::Op::OpAccessChain && fnLocalVars.count(asId(start+3)) > 0)
+ fnLocalVars.insert(asId(start+2));
+
+ if (opCode == spv::Op::OpLoad && fnLocalVars.count(asId(start+3)) > 0) {
+ idMap[asId(start+2)] = asId(start+3);
+ stripInst(start);
+ }
+
+ return false;
+ },
+
+ [&](spv::Id& id) { if (idMap.find(id) != idMap.end()) id = idMap[id]; }
+ );
+
+ if (errorLatch)
+ return;
+
+ // EXPERIMENTAL: Implicit output stores
+ fnLocalVars.clear();
+ idMap.clear();
+
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ // Add inputs and uniforms to the map
+ if ((opCode == spv::Op::OpVariable && asWordCount(start) == 4) &&
+ (spv[start+3] == std::uint32_t(spv::StorageClass::Output)))
+ fnLocalVars.insert(asId(start+2));
+
+ if (opCode == spv::Op::OpStore && fnLocalVars.count(asId(start+1)) > 0) {
+ idMap[asId(start+2)] = asId(start+1);
+ stripInst(start);
+ }
+
+ return false;
+ },
+ op_fn_nop);
+
+ if (errorLatch)
+ return;
+
+ process(
+ inst_fn_nop,
+ [&](spv::Id& id) { if (idMap.find(id) != idMap.end()) id = idMap[id]; }
+ );
+
+ if (errorLatch)
+ return;
+
+ strip(); // strip out data we decided to eliminate
+ }
+
+ // optimize loads and stores
+ void spirvbin_t::optLoadStore()
+ {
+ idset_t fnLocalVars; // candidates for removal (only locals)
+ idmap_t idMap; // Map of load result IDs to what they load
+ blockmap_t blockMap; // Map of IDs to blocks they first appear in
+ int blockNum = 0; // block count, to avoid crossing flow control
+
+ // Find all the function local pointers stored at most once, and not via access chains
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ const int wordCount = asWordCount(start);
+
+ // Count blocks, so we can avoid crossing flow control
+ if (isFlowCtrl(opCode))
+ ++blockNum;
+
+ // Add local variables to the map
+ if ((opCode == spv::Op::OpVariable && spv[start+3] == std::uint32_t(spv::StorageClass::Function) && asWordCount(start) == 4)) {
+ fnLocalVars.insert(asId(start+2));
+ return true;
+ }
+
+ // Ignore process vars referenced via access chain
+ if ((opCode == spv::Op::OpAccessChain || opCode == spv::Op::OpInBoundsAccessChain) && fnLocalVars.count(asId(start+3)) > 0) {
+ fnLocalVars.erase(asId(start+3));
+ idMap.erase(asId(start+3));
+ return true;
+ }
+
+ if (opCode == spv::Op::OpLoad && fnLocalVars.count(asId(start+3)) > 0) {
+ const spv::Id varId = asId(start+3);
+
+ // Avoid loads before stores
+ if (idMap.find(varId) == idMap.end()) {
+ fnLocalVars.erase(varId);
+ idMap.erase(varId);
+ }
+
+ // don't do for volatile references
+ if (wordCount > 4 && (spv[start+4] & std::uint32_t(spv::MemoryAccessMask::Volatile))) {
+ fnLocalVars.erase(varId);
+ idMap.erase(varId);
+ }
+
+ // Handle flow control
+ if (blockMap.find(varId) == blockMap.end()) {
+ blockMap[varId] = blockNum; // track block we found it in.
+ } else if (blockMap[varId] != blockNum) {
+ fnLocalVars.erase(varId); // Ignore if crosses flow control
+ idMap.erase(varId);
+ }
+
+ return true;
+ }
+
+ if (opCode == spv::Op::OpStore && fnLocalVars.count(asId(start+1)) > 0) {
+ const spv::Id varId = asId(start+1);
+
+ if (idMap.find(varId) == idMap.end()) {
+ idMap[varId] = asId(start+2);
+ } else {
+ // Remove if it has more than one store to the same pointer
+ fnLocalVars.erase(varId);
+ idMap.erase(varId);
+ }
+
+ // don't do for volatile references
+ if (wordCount > 3 && (spv[start+3] & std::uint32_t(spv::MemoryAccessMask::Volatile))) {
+ fnLocalVars.erase(asId(start+3));
+ idMap.erase(asId(start+3));
+ }
+
+ // Handle flow control
+ if (blockMap.find(varId) == blockMap.end()) {
+ blockMap[varId] = blockNum; // track block we found it in.
+ } else if (blockMap[varId] != blockNum) {
+ fnLocalVars.erase(varId); // Ignore if crosses flow control
+ idMap.erase(varId);
+ }
+
+ return true;
+ }
+
+ return false;
+ },
+
+ // If local var id used anywhere else, don't eliminate
+ [&](spv::Id& id) {
+ if (fnLocalVars.count(id) > 0) {
+ fnLocalVars.erase(id);
+ idMap.erase(id);
+ }
+ }
+ );
+
+ if (errorLatch)
+ return;
+
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ if (opCode == spv::Op::OpLoad && fnLocalVars.count(asId(start+3)) > 0)
+ idMap[asId(start+2)] = idMap[asId(start+3)];
+ return false;
+ },
+ op_fn_nop);
+
+ if (errorLatch)
+ return;
+
+ // Chase replacements to their origins, in case there is a chain such as:
+ // 2 = store 1
+ // 3 = load 2
+ // 4 = store 3
+ // 5 = load 4
+ // We want to replace uses of 5 with 1.
+ for (const auto& idPair : idMap) {
+ spv::Id id = idPair.first;
+ while (idMap.find(id) != idMap.end()) // Chase to end of chain
+ id = idMap[id];
+
+ idMap[idPair.first] = id; // replace with final result
+ }
+
+ // Remove the load/store/variables for the ones we've discovered
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ if ((opCode == spv::Op::OpLoad && fnLocalVars.count(asId(start+3)) > 0) ||
+ (opCode == spv::Op::OpStore && fnLocalVars.count(asId(start+1)) > 0) ||
+ (opCode == spv::Op::OpVariable && fnLocalVars.count(asId(start+2)) > 0)) {
+
+ stripInst(start);
+ return true;
+ }
+
+ return false;
+ },
+
+ [&](spv::Id& id) {
+ if (idMap.find(id) != idMap.end()) id = idMap[id];
+ }
+ );
+
+ if (errorLatch)
+ return;
+
+ strip(); // strip out data we decided to eliminate
+ }
+
+ // remove bodies of uncalled functions
+ void spirvbin_t::dceFuncs()
+ {
+ msg(3, 2, std::string("Removing Dead Functions: "));
+
+ // TODO: There are more efficient ways to do this.
+ bool changed = true;
+
+ while (changed) {
+ changed = false;
+
+ for (auto fn = fnPos.begin(); fn != fnPos.end(); ) {
+ if (fn->first == entryPoint) { // don't DCE away the entry point!
+ ++fn;
+ continue;
+ }
+
+ const auto call_it = fnCalls.find(fn->first);
+
+ if (call_it == fnCalls.end() || call_it->second == 0) {
+ changed = true;
+ stripRange.push_back(fn->second);
+
+ // decrease counts of called functions
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ if (opCode == spv::Op::OpFunctionCall) {
+ const auto call_it = fnCalls.find(asId(start + 3));
+ if (call_it != fnCalls.end()) {
+ if (--call_it->second <= 0)
+ fnCalls.erase(call_it);
+ }
+ }
+
+ return true;
+ },
+ op_fn_nop,
+ fn->second.first,
+ fn->second.second);
+
+ if (errorLatch)
+ return;
+
+ fn = fnPos.erase(fn);
+ } else ++fn;
+ }
+ }
+ }
+
+ // remove unused function variables + decorations
+ void spirvbin_t::dceVars()
+ {
+ msg(3, 2, std::string("DCE Vars: "));
+
+ std::unordered_map<spv::Id, int> varUseCount;
+
+ // Count function variable use
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ if (opCode == spv::Op::OpVariable) {
+ ++varUseCount[asId(start+2)];
+ return true;
+ } else if (opCode == spv::Op::OpEntryPoint) {
+ const int wordCount = asWordCount(start);
+ for (int i = 4; i < wordCount; i++) {
+ ++varUseCount[asId(start+i)];
+ }
+ return true;
+ } else
+ return false;
+ },
+
+ [&](spv::Id& id) { if (varUseCount[id]) ++varUseCount[id]; }
+ );
+
+ if (errorLatch)
+ return;
+
+ // Remove single-use function variables + associated decorations and names
+ process(
+ [&](spv::Op opCode, unsigned start) {
+ spv::Id id = spv::NoResult;
+ if (opCode == spv::Op::OpVariable)
+ id = asId(start+2);
+ if (opCode == spv::Op::OpDecorate || opCode == spv::Op::OpName)
+ id = asId(start+1);
+
+ if (id != spv::NoResult && varUseCount[id] == 1)
+ stripInst(start);
+
+ return true;
+ },
+ op_fn_nop);
+ }
+
+ // remove unused types
+ void spirvbin_t::dceTypes()
+ {
+ std::vector<bool> isType(bound(), false);
+
+ // for speed, make O(1) way to get to type query (map is log(n))
+ for (const auto typeStart : typeConstPos)
+ isType[asTypeConstId(typeStart)] = true;
+
+ std::unordered_map<spv::Id, int> typeUseCount;
+
+ // This is not the most efficient algorithm, but this is an offline tool, and
+ // it's easy to write this way. Can be improved opportunistically if needed.
+ bool changed = true;
+ while (changed) {
+ changed = false;
+ strip();
+ typeUseCount.clear();
+
+ // Count total type usage
+ process(inst_fn_nop,
+ [&](spv::Id& id) { if (isType[id]) ++typeUseCount[id]; }
+ );
+
+ if (errorLatch)
+ return;
+
+ // Remove single reference types
+ for (const auto typeStart : typeConstPos) {
+ const spv::Id typeId = asTypeConstId(typeStart);
+ if (typeUseCount[typeId] == 1) {
+ changed = true;
+ --typeUseCount[typeId];
+ stripInst(typeStart);
+ }
+ }
+
+ if (errorLatch)
+ return;
+ }
+ }
+
+#ifdef NOTDEF
+ bool spirvbin_t::matchType(const spirvbin_t::globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const
+ {
+ // Find the local type id "lt" and global type id "gt"
+ const auto lt_it = typeConstPosR.find(lt);
+ if (lt_it == typeConstPosR.end())
+ return false;
+
+ const auto typeStart = lt_it->second;
+
+ // Search for entry in global table
+ const auto gtype = globalTypes.find(gt);
+ if (gtype == globalTypes.end())
+ return false;
+
+ const auto& gdata = gtype->second;
+
+ // local wordcount and opcode
+ const int wordCount = asWordCount(typeStart);
+ const spv::Op opCode = asOpCode(typeStart);
+
+ // no type match if opcodes don't match, or operand count doesn't match
+ if (opCode != opOpCode(gdata[0]) || wordCount != opWordCount(gdata[0]))
+ return false;
+
+ const unsigned numOperands = wordCount - 2; // all types have a result
+
+ const auto cmpIdRange = [&](range_t range) {
+ for (int x=range.first; x<std::min(range.second, wordCount); ++x)
+ if (!matchType(globalTypes, asId(typeStart+x), gdata[x]))
+ return false;
+ return true;
+ };
+
+ const auto cmpConst = [&]() { return cmpIdRange(constRange(opCode)); };
+ const auto cmpSubType = [&]() { return cmpIdRange(typeRange(opCode)); };
+
+ // Compare literals in range [start,end)
+ const auto cmpLiteral = [&]() {
+ const auto range = literalRange(opCode);
+ return std::equal(spir.begin() + typeStart + range.first,
+ spir.begin() + typeStart + std::min(range.second, wordCount),
+ gdata.begin() + range.first);
+ };
+
+ assert(isTypeOp(opCode) || isConstOp(opCode));
+
+ switch (opCode) {
+ case spv::OpTypeOpaque: // TODO: disable until we compare the literal strings.
+ case spv::OpTypeQueue: return false;
+ case spv::OpTypeEvent: // fall through...
+ case spv::OpTypeDeviceEvent: // ...
+ case spv::OpTypeReserveId: return false;
+ // for samplers, we don't handle the optional parameters yet
+ case spv::OpTypeSampler: return cmpLiteral() && cmpConst() && cmpSubType() && wordCount == 8;
+ default: return cmpLiteral() && cmpConst() && cmpSubType();
+ }
+ }
+
+ // Look for an equivalent type in the globalTypes map
+ spv::Id spirvbin_t::findType(const spirvbin_t::globaltypes_t& globalTypes, spv::Id lt) const
+ {
+ // Try a recursive type match on each in turn, and return a match if we find one
+ for (const auto& gt : globalTypes)
+ if (matchType(globalTypes, lt, gt.first))
+ return gt.first;
+
+ return spv::NoType;
+ }
+#endif // NOTDEF
+
+ // Return start position in SPV of given Id. error if not found.
+ unsigned spirvbin_t::idPos(spv::Id id) const
+ {
+ const auto tid_it = idPosR.find(id);
+ if (tid_it == idPosR.end()) {
+ error("ID not found");
+ return 0;
+ }
+
+ return tid_it->second;
+ }
+
+ // Hash types to canonical values. This can return ID collisions (it's a bit
+ // inevitable): it's up to the caller to handle that gracefully.
+ std::uint32_t spirvbin_t::hashType(unsigned typeStart) const
+ {
+ const unsigned wordCount = asWordCount(typeStart);
+ const spv::Op opCode = asOpCode(typeStart);
+
+ switch (opCode) {
+ case spv::Op::OpTypeVoid: return 0;
+ case spv::Op::OpTypeBool: return 1;
+ case spv::Op::OpTypeInt: return 3 + (spv[typeStart+3]);
+ case spv::Op::OpTypeFloat: return 5;
+ case spv::Op::OpTypeVector:
+ return 6 + hashType(idPos(spv[typeStart+2])) * (spv[typeStart+3] - 1);
+ case spv::Op::OpTypeMatrix:
+ return 30 + hashType(idPos(spv[typeStart+2])) * (spv[typeStart+3] - 1);
+ case spv::Op::OpTypeImage:
+ return 120 + hashType(idPos(spv[typeStart+2])) +
+ spv[typeStart+3] + // dimensionality
+ spv[typeStart+4] * 8 * 16 + // depth
+ spv[typeStart+5] * 4 * 16 + // arrayed
+ spv[typeStart+6] * 2 * 16 + // multisampled
+ spv[typeStart+7] * 1 * 16; // format
+ case spv::Op::OpTypeSampler:
+ return 500;
+ case spv::Op::OpTypeSampledImage:
+ return 502;
+ case spv::Op::OpTypeArray:
+ return 501 + hashType(idPos(spv[typeStart+2])) * spv[typeStart+3];
+ case spv::Op::OpTypeRuntimeArray:
+ return 5000 + hashType(idPos(spv[typeStart+2]));
+ case spv::Op::OpTypeStruct:
+ {
+ std::uint32_t hash = 10000;
+ for (unsigned w=2; w < wordCount; ++w)
+ hash += w * hashType(idPos(spv[typeStart+w]));
+ return hash;
+ }
+
+ case spv::Op::OpTypeOpaque: return 6000 + spv[typeStart+2];
+ case spv::Op::OpTypePointer: return 100000 + hashType(idPos(spv[typeStart+3]));
+ case spv::Op::OpTypeFunction:
+ {
+ std::uint32_t hash = 200000;
+ for (unsigned w=2; w < wordCount; ++w)
+ hash += w * hashType(idPos(spv[typeStart+w]));
+ return hash;
+ }
+
+ case spv::Op::OpTypeEvent: return 300000;
+ case spv::Op::OpTypeDeviceEvent: return 300001;
+ case spv::Op::OpTypeReserveId: return 300002;
+ case spv::Op::OpTypeQueue: return 300003;
+ case spv::Op::OpTypePipe: return 300004;
+ case spv::Op::OpConstantTrue: return 300007;
+ case spv::Op::OpConstantFalse: return 300008;
+ case spv::Op::OpConstantComposite:
+ {
+ std::uint32_t hash = 300011 + hashType(idPos(spv[typeStart+1]));
+ for (unsigned w=3; w < wordCount; ++w)
+ hash += w * hashType(idPos(spv[typeStart+w]));
+ return hash;
+ }
+ case spv::Op::OpConstant:
+ {
+ std::uint32_t hash = 400011 + hashType(idPos(spv[typeStart+1]));
+ for (unsigned w=3; w < wordCount; ++w)
+ hash += w * spv[typeStart+w];
+ return hash;
+ }
+ case spv::Op::OpConstantNull:
+ {
+ std::uint32_t hash = 500009 + hashType(idPos(spv[typeStart+1]));
+ return hash;
+ }
+ case spv::Op::OpConstantSampler:
+ {
+ std::uint32_t hash = 600011 + hashType(idPos(spv[typeStart+1]));
+ for (unsigned w=3; w < wordCount; ++w)
+ hash += w * spv[typeStart+w];
+ return hash;
+ }
+
+ default:
+ error("unknown type opcode");
+ return 0;
+ }
+ }
+
+ void spirvbin_t::mapTypeConst()
+ {
+ globaltypes_t globalTypeMap;
+
+ msg(3, 2, std::string("Remapping Consts & Types: "));
+
+ static const std::uint32_t softTypeIdLimit = 3011; // small prime. TODO: get from options
+ static const std::uint32_t firstMappedID = 8; // offset into ID space
+
+ for (auto& typeStart : typeConstPos) {
+ const spv::Id resId = asTypeConstId(typeStart);
+ const std::uint32_t hashval = hashType(typeStart);
+
+ if (errorLatch)
+ return;
+
+ if (isOldIdUnmapped(resId)) {
+ localId(resId, nextUnusedId(hashval % softTypeIdLimit + firstMappedID));
+ if (errorLatch)
+ return;
+ }
+ }
+ }
+
+ // Strip a single binary by removing ranges given in stripRange
+ void spirvbin_t::strip()
+ {
+ if (stripRange.empty()) // nothing to do
+ return;
+
+ // Sort strip ranges in order of traversal
+ std::sort(stripRange.begin(), stripRange.end());
+
+ // Allocate a new binary big enough to hold old binary
+ // We'll step this iterator through the strip ranges as we go through the binary
+ auto strip_it = stripRange.begin();
+
+ int strippedPos = 0;
+ for (unsigned word = 0; word < unsigned(spv.size()); ++word) {
+ while (strip_it != stripRange.end() && word >= strip_it->second)
+ ++strip_it;
+
+ if (strip_it == stripRange.end() || word < strip_it->first || word >= strip_it->second)
+ spv[strippedPos++] = spv[word];
+ }
+
+ spv.resize(strippedPos);
+ stripRange.clear();
+
+ buildLocalMaps();
+ }
+
+ // Strip a single binary by removing ranges given in stripRange
+ void spirvbin_t::remap(std::uint32_t opts)
+ {
+ options = opts;
+
+ // Set up opcode tables from SpvDoc
+ spv::Parameterize();
+
+ validate(); // validate header
+ buildLocalMaps(); // build ID maps
+
+ msg(3, 4, std::string("ID bound: ") + std::to_string(bound()));
+
+ if (options & STRIP) stripDebug();
+ if (errorLatch) return;
+
+ strip(); // strip out data we decided to eliminate
+ if (errorLatch) return;
+
+ if (options & OPT_LOADSTORE) optLoadStore();
+ if (errorLatch) return;
+
+ if (options & OPT_FWD_LS) forwardLoadStores();
+ if (errorLatch) return;
+
+ if (options & DCE_FUNCS) dceFuncs();
+ if (errorLatch) return;
+
+ if (options & DCE_VARS) dceVars();
+ if (errorLatch) return;
+
+ if (options & DCE_TYPES) dceTypes();
+ if (errorLatch) return;
+
+ strip(); // strip out data we decided to eliminate
+ if (errorLatch) return;
+
+ stripDeadRefs(); // remove references to things we DCEed
+ if (errorLatch) return;
+
+ // after the last strip, we must clean any debug info referring to now-deleted data
+
+ if (options & MAP_TYPES) mapTypeConst();
+ if (errorLatch) return;
+
+ if (options & MAP_NAMES) mapNames();
+ if (errorLatch) return;
+
+ if (options & MAP_FUNCS) mapFnBodies();
+ if (errorLatch) return;
+
+ if (options & MAP_ALL) {
+ mapRemainder(); // map any unmapped IDs
+ if (errorLatch) return;
+
+ applyMap(); // Now remap each shader to the new IDs we've come up with
+ if (errorLatch) return;
+ }
+ }
+
+ // remap from a memory image
+ void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, const std::vector<std::string>& whiteListStrings,
+ std::uint32_t opts)
+ {
+ stripWhiteList = whiteListStrings;
+ spv.swap(in_spv);
+ remap(opts);
+ spv.swap(in_spv);
+ }
+
+ // remap from a memory image - legacy interface without white list
+ void spirvbin_t::remap(std::vector<std::uint32_t>& in_spv, std::uint32_t opts)
+ {
+ stripWhiteList.clear();
+ spv.swap(in_spv);
+ remap(opts);
+ spv.swap(in_spv);
+ }
+
+} // namespace SPV
+
diff --git a/src/3rdparty/glslang/SPIRV/SPVRemapper.h b/src/3rdparty/glslang/SPIRV/SPVRemapper.h
new file mode 100644
index 0000000..d4c2295
--- /dev/null
+++ b/src/3rdparty/glslang/SPIRV/SPVRemapper.h
@@ -0,0 +1,300 @@
+//
+// Copyright (C) 2015 LunarG, Inc.
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+//
+// Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+//
+// Neither the name of 3Dlabs Inc. Ltd. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+// COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+// POSSIBILITY OF SUCH DAMAGE.
+//
+
+#ifndef SPIRVREMAPPER_H
+#define SPIRVREMAPPER_H
+
+#include <string>
+#include <vector>
+#include <cstdlib>
+#include <exception>
+
+#ifdef GLSLANG_IS_SHARED_LIBRARY
+ #ifdef _WIN32
+ #ifdef GLSLANG_EXPORTING
+ #define GLSLANG_EXPORT __declspec(dllexport)
+ #else
+ #define GLSLANG_EXPORT __declspec(dllimport)
+ #endif
+ #elif __GNUC__ >= 4
+ #define GLSLANG_EXPORT __attribute__((visibility("default")))
+ #endif
+#endif // GLSLANG_IS_SHARED_LIBRARY
+#ifndef GLSLANG_EXPORT
+#define GLSLANG_EXPORT
+#endif
+
+namespace spv {
+
+class spirvbin_base_t
+{
+public:
+ enum Options {
+ NONE = 0,
+ STRIP = (1<<0),
+ MAP_TYPES = (1<<1),
+ MAP_NAMES = (1<<2),
+ MAP_FUNCS = (1<<3),
+ DCE_FUNCS = (1<<4),
+ DCE_VARS = (1<<5),
+ DCE_TYPES = (1<<6),
+ OPT_LOADSTORE = (1<<7),
+ OPT_FWD_LS = (1<<8), // EXPERIMENTAL: PRODUCES INVALID SCHEMA-0 SPIRV
+ MAP_ALL = (MAP_TYPES | MAP_NAMES | MAP_FUNCS),
+ DCE_ALL = (DCE_FUNCS | DCE_VARS | DCE_TYPES),
+ OPT_ALL = (OPT_LOADSTORE),
+
+ ALL_BUT_STRIP = (MAP_ALL | DCE_ALL | OPT_ALL),
+ DO_EVERYTHING = (STRIP | ALL_BUT_STRIP)
+ };
+};
+
+} // namespace SPV
+
+#include <functional>
+#include <cstdint>
+#include <unordered_map>
+#include <unordered_set>
+#include <map>
+#include <set>
+#include <cassert>
+
+#include "spirv.hpp11"
+
+namespace spv {
+
+static inline constexpr Id NoResult = 0;
+
+// class to hold SPIR-V binary data for remapping, DCE, and debug stripping
+class GLSLANG_EXPORT spirvbin_t : public spirvbin_base_t
+{
+public:
+ spirvbin_t(int verbose = 0) : entryPoint(spv::NoResult), largestNewId(0), verbose(verbose), errorLatch(false)
+ { }
+
+ virtual ~spirvbin_t() { }
+
+ // remap on an existing binary in memory
+ void remap(std::vector<std::uint32_t>& spv, const std::vector<std::string>& whiteListStrings,
+ std::uint32_t opts = DO_EVERYTHING);
+
+ // remap on an existing binary in memory - legacy interface without white list
+ void remap(std::vector<std::uint32_t>& spv, std::uint32_t opts = DO_EVERYTHING);
+
+ // Type for error/log handler functions
+ typedef std::function<void(const std::string&)> errorfn_t;
+ typedef std::function<void(const std::string&)> logfn_t;
+
+ // Register error/log handling functions (can be lambda fn / functor / etc)
+ static void registerErrorHandler(errorfn_t handler) { errorHandler = handler; }
+ static void registerLogHandler(logfn_t handler) { logHandler = handler; }
+
+protected:
+ // This can be overridden to provide other message behavior if needed
+ virtual void msg(int minVerbosity, int indent, const std::string& txt) const;
+
+private:
+ // Local to global, or global to local ID map
+ typedef std::unordered_map<spv::Id, spv::Id> idmap_t;
+ typedef std::unordered_set<spv::Id> idset_t;
+ typedef std::unordered_map<spv::Id, int> blockmap_t;
+
+ void remap(std::uint32_t opts = DO_EVERYTHING);
+
+ // Map of names to IDs
+ typedef std::unordered_map<std::string, spv::Id> namemap_t;
+
+ typedef std::uint32_t spirword_t;
+
+ typedef std::pair<unsigned, unsigned> range_t;
+ typedef std::function<void(spv::Id&)> idfn_t;
+ typedef std::function<bool(spv::Op, unsigned start)> instfn_t;
+
+ // Special Values for ID map:
+ static const spv::Id unmapped; // unchanged from default value
+ static const spv::Id unused; // unused ID
+ static const int header_size; // SPIR header = 5 words
+
+ class id_iterator_t;
+
+ // For mapping type entries between different shaders
+ typedef std::vector<spirword_t> typeentry_t;
+ typedef std::map<spv::Id, typeentry_t> globaltypes_t;
+
+ // A set that preserves position order, and a reverse map
+ typedef std::set<int> posmap_t;
+ typedef std::unordered_map<spv::Id, int> posmap_rev_t;
+
+ // Maps and ID to the size of its base type, if known.
+ typedef std::unordered_map<spv::Id, unsigned> typesize_map_t;
+
+ // handle error
+ void error(const std::string& txt) const { errorLatch = true; errorHandler(txt); }
+
+ bool isConstOp(spv::Op opCode) const;
+ bool isTypeOp(spv::Op opCode) const;
+ bool isStripOp(spv::Op opCode) const;
+ bool isFlowCtrl(spv::Op opCode) const;
+ range_t literalRange(spv::Op opCode) const;
+ range_t typeRange(spv::Op opCode) const;
+ range_t constRange(spv::Op opCode) const;
+ unsigned typeSizeInWords(spv::Id id) const;
+ unsigned idTypeSizeInWords(spv::Id id) const;
+
+ bool isStripOp(spv::Op opCode, unsigned start) const;
+
+ spv::Id& asId(unsigned word) { return spv[word]; }
+ const spv::Id& asId(unsigned word) const { return spv[word]; }
+ spv::Op asOpCode(unsigned word) const { return opOpCode(spv[word]); }
+ std::uint32_t asOpCodeHash(unsigned word);
+ spv::Decoration asDecoration(unsigned word) const { return spv::Decoration(spv[word]); }
+ unsigned asWordCount(unsigned word) const { return opWordCount(spv[word]); }
+ spv::Id asTypeConstId(unsigned word) const { return asId(word + (isTypeOp(asOpCode(word)) ? 1 : 2)); }
+ unsigned idPos(spv::Id id) const;
+
+ static unsigned opWordCount(spirword_t data) { return data >> spv::WordCountShift; }
+ static spv::Op opOpCode(spirword_t data) { return spv::Op(data & spv::OpCodeMask); }
+
+ // Header access & set methods
+ spirword_t magic() const { return spv[0]; } // return magic number
+ spirword_t bound() const { return spv[3]; } // return Id bound from header
+ spirword_t bound(spirword_t b) { return spv[3] = b; }
+ spirword_t genmagic() const { return spv[2]; } // generator magic
+ spirword_t genmagic(spirword_t m) { return spv[2] = m; }
+ spirword_t schemaNum() const { return spv[4]; } // schema number from header
+
+ // Mapping fns: get
+ spv::Id localId(spv::Id id) const { return idMapL[id]; }
+
+ // Mapping fns: set
+ inline spv::Id localId(spv::Id id, spv::Id newId);
+ void countIds(spv::Id id);
+
+ // Return next unused new local ID.
+ // NOTE: boost::dynamic_bitset would be more efficient due to find_next(),
+ // which std::vector<bool> doens't have.
+ inline spv::Id nextUnusedId(spv::Id id);
+
+ void buildLocalMaps();
+ std::string literalString(unsigned word) const; // Return literal as a std::string
+ int literalStringWords(const std::string& str) const { return (int(str.size())+4)/4; }
+
+ bool isNewIdMapped(spv::Id newId) const { return isMapped(newId); }
+ bool isOldIdUnmapped(spv::Id oldId) const { return localId(oldId) == unmapped; }
+ bool isOldIdUnused(spv::Id oldId) const { return localId(oldId) == unused; }
+ bool isOldIdMapped(spv::Id oldId) const { return !isOldIdUnused(oldId) && !isOldIdUnmapped(oldId); }
+ bool isFunction(spv::Id oldId) const { return fnPos.find(oldId) != fnPos.end(); }
+
+ // bool matchType(const globaltypes_t& globalTypes, spv::Id lt, spv::Id gt) const;
+ // spv::Id findType(const globaltypes_t& globalTypes, spv::Id lt) const;
+ std::uint32_t hashType(unsigned typeStart) const;
+
+ spirvbin_t& process(instfn_t, idfn_t, unsigned begin = 0, unsigned end = 0);
+ int processInstruction(unsigned word, instfn_t, idfn_t);
+
+ void validate() const;
+ void mapTypeConst();
+ void mapFnBodies();
+ void optLoadStore();
+ void dceFuncs();
+ void dceVars();
+ void dceTypes();
+ void mapNames();
+ void foldIds(); // fold IDs to smallest space
+ void forwardLoadStores(); // load store forwarding (EXPERIMENTAL)
+ void offsetIds(); // create relative offset IDs
+
+ void applyMap(); // remap per local name map
+ void mapRemainder(); // map any IDs we haven't touched yet
+ void stripDebug(); // strip all debug info
+ void stripDeadRefs(); // strips debug info for now-dead references after DCE
+ void strip(); // remove debug symbols
+
+ std::vector<spirword_t> spv; // SPIR words
+
+ std::vector<std::string> stripWhiteList;
+
+ namemap_t nameMap; // ID names from OpName
+
+ // Since we want to also do binary ops, we can't use std::vector<bool>. we could use
+ // boost::dynamic_bitset, but we're trying to avoid a boost dependency.
+ typedef std::uint64_t bits_t;
+ std::vector<bits_t> mapped; // which new IDs have been mapped
+ static const int mBits = sizeof(bits_t) * 4;
+
+ bool isMapped(spv::Id id) const { return id < maxMappedId() && ((mapped[id/mBits] & (1LL<<(id%mBits))) != 0); }
+ void setMapped(spv::Id id) { resizeMapped(id); mapped[id/mBits] |= (1LL<<(id%mBits)); }
+ void resizeMapped(spv::Id id) { if (id >= maxMappedId()) mapped.resize(id/mBits+1, 0); }
+ size_t maxMappedId() const { return mapped.size() * mBits; }
+
+ // Add a strip range for a given instruction starting at 'start'
+ // Note: avoiding brace initializers to please older versions os MSVC.
+ void stripInst(unsigned start) { stripRange.push_back(range_t(start, start + asWordCount(start))); }
+
+ // Function start and end. use unordered_map because we'll have
+ // many fewer functions than IDs.
+ std::unordered_map<spv::Id, range_t> fnPos;
+
+ // Which functions are called, anywhere in the module, with a call count
+ std::unordered_map<spv::Id, int> fnCalls;
+
+ posmap_t typeConstPos; // word positions that define types & consts (ordered)
+ posmap_rev_t idPosR; // reverse map from IDs to positions
+ typesize_map_t idTypeSizeMap; // maps each ID to its type size, if known.
+
+ std::vector<spv::Id> idMapL; // ID {M}ap from {L}ocal to {G}lobal IDs
+
+ spv::Id entryPoint; // module entry point
+ spv::Id largestNewId; // biggest new ID we have mapped anything to
+
+ // Sections of the binary to strip, given as [begin,end)
+ std::vector<range_t> stripRange;
+
+ // processing options:
+ std::uint32_t options;
+ int verbose; // verbosity level
+
+ // Error latch: this is set if the error handler is ever executed. It would be better to
+ // use a try/catch block and throw, but that's not desired for certain environments, so
+ // this is the alternative.
+ mutable bool errorLatch;
+
+ static errorfn_t errorHandler;
+ static logfn_t logHandler;
+};
+
+} // namespace SPV
+
+#endif // SPIRVREMAPPER_H
diff --git a/src/3rdparty/glslang/SPIRV/SpvTools.cpp b/src/3rdparty/glslang/SPIRV/SpvTools.cpp
index 6c64fdd..3dc456f 100644
--- a/src/3rdparty/glslang/SPIRV/SpvTools.cpp
+++ b/src/3rdparty/glslang/SPIRV/SpvTools.cpp
@@ -46,6 +46,7 @@
#include "spirv-tools/optimizer.hpp"
#include "glslang/MachineIndependent/localintermediate.h"
+namespace QtShaderTools {
namespace glslang {
// Translate glslang's view of target versioning to what SPIRV-Tools uses.
@@ -292,5 +293,6 @@ void SpirvToolsStripDebugInfo(const glslang::TIntermediate& intermediate,
}
} // end namespace glslang
+} // namespace QtShaderTools
#endif
diff --git a/src/3rdparty/glslang/SPIRV/SpvTools.h b/src/3rdparty/glslang/SPIRV/SpvTools.h
index 6d72beb..6f6942f 100644
--- a/src/3rdparty/glslang/SPIRV/SpvTools.h
+++ b/src/3rdparty/glslang/SPIRV/SpvTools.h
@@ -53,6 +53,7 @@
#include "GlslangToSpv.h"
#include "Logger.h"
+namespace QtShaderTools {
namespace glslang {
#if ENABLE_OPT
@@ -105,5 +106,6 @@ GLSLANG_EXPORT void SpirvToolsStripDebugInfo(const glslang::TIntermediate& inter
#endif
} // end namespace glslang
+} // namespace QtShaderTools
#endif // GLSLANG_SPV_TOOLS_H
diff --git a/src/3rdparty/glslang/glslang/GenericCodeGen/CodeGen.cpp b/src/3rdparty/glslang/glslang/GenericCodeGen/CodeGen.cpp
index 1ef2449..7c6297e 100644
--- a/src/3rdparty/glslang/glslang/GenericCodeGen/CodeGen.cpp
+++ b/src/3rdparty/glslang/glslang/GenericCodeGen/CodeGen.cpp
@@ -36,6 +36,7 @@
#include "../Include/ShHandle.h"
#include "../MachineIndependent/Versions.h"
+namespace QtShaderTools {
//
// Here is where real machine specific high-level data would be defined.
//
@@ -70,3 +71,4 @@ bool TGenericCompiler::compile(TIntermNode* /*root*/, int /*version*/, EProfile
return haveValidObjectCode;
}
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/GenericCodeGen/Link.cpp b/src/3rdparty/glslang/glslang/GenericCodeGen/Link.cpp
index 5df39b8..9b96f05 100644
--- a/src/3rdparty/glslang/glslang/GenericCodeGen/Link.cpp
+++ b/src/3rdparty/glslang/glslang/GenericCodeGen/Link.cpp
@@ -39,6 +39,7 @@
#include "../Include/Common.h"
#include "../Include/ShHandle.h"
+namespace QtShaderTools {
//
// Actual link object, derived from the shader handle base classes.
//
@@ -85,3 +86,5 @@ void DeleteBindingList(TShHandleBase* bindingList)
{
delete bindingList;
}
+
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/Include/BaseTypes.h b/src/3rdparty/glslang/glslang/Include/BaseTypes.h
index 4ff7372..e344860 100644
--- a/src/3rdparty/glslang/glslang/Include/BaseTypes.h
+++ b/src/3rdparty/glslang/glslang/Include/BaseTypes.h
@@ -39,6 +39,7 @@
#ifndef _BASICTYPES_INCLUDED_
#define _BASICTYPES_INCLUDED_
+namespace QtShaderTools {
namespace glslang {
//
@@ -733,5 +734,6 @@ __inline int getTypeRank(TBasicType type)
}
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _BASICTYPES_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/Common.h b/src/3rdparty/glslang/glslang/Include/Common.h
index 04c11dc..cc2934f 100644
--- a/src/3rdparty/glslang/glslang/Include/Common.h
+++ b/src/3rdparty/glslang/glslang/Include/Common.h
@@ -114,6 +114,7 @@ std::string to_string(const T& val) {
void operator delete[](void*) { } \
void operator delete[](void *, void *) { }
+namespace QtShaderTools {
namespace glslang {
//
@@ -123,12 +124,13 @@ namespace glslang {
typedef std::basic_string <char, std::char_traits<char>, TStringAllocator> TString;
} // end namespace glslang
+} // namespace QtShaderTools
// Repackage the std::hash for use by unordered map/set with a TString key.
namespace std {
- template<> struct hash<glslang::TString> {
- std::size_t operator()(const glslang::TString& s) const
+ template<> struct hash<QtShaderTools::glslang::TString> {
+ std::size_t operator()(const QtShaderTools::glslang::TString& s) const
{
const unsigned _FNV_offset_basis = 2166136261U;
const unsigned _FNV_prime = 16777619U;
@@ -146,6 +148,7 @@ namespace std {
};
}
+namespace QtShaderTools {
namespace glslang {
inline TString* NewPoolTString(const char* s)
@@ -303,5 +306,6 @@ template <class T> int IntLog2(T n)
}
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _COMMON_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/ConstantUnion.h b/src/3rdparty/glslang/glslang/Include/ConstantUnion.h
index bf6b8a8..bfaa478 100644
--- a/src/3rdparty/glslang/glslang/Include/ConstantUnion.h
+++ b/src/3rdparty/glslang/glslang/Include/ConstantUnion.h
@@ -41,6 +41,7 @@
#include "../Include/Common.h"
#include "../Include/BaseTypes.h"
+namespace QtShaderTools {
namespace glslang {
class TConstUnion {
@@ -945,5 +946,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _CONSTANT_UNION_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/InfoSink.h b/src/3rdparty/glslang/glslang/Include/InfoSink.h
index 8c9b42b..8891b28 100644
--- a/src/3rdparty/glslang/glslang/Include/InfoSink.h
+++ b/src/3rdparty/glslang/glslang/Include/InfoSink.h
@@ -36,11 +36,13 @@
#define _INFOSINK_INCLUDED_
#include "../Include/Common.h"
-#if __has_include(<filesystem>)
-#include <filesystem>
-#endif
+
+// QNX says no
+//#include <filesystem>
+
#include <cmath>
+namespace QtShaderTools {
namespace glslang {
//
@@ -106,23 +108,12 @@ public:
snprintf(locText, maxSize, ":%d", loc.line);
}
- if(loc.getFilename() == nullptr && shaderFileName != nullptr && absolute) {
- #if defined(__cpp_lib_filesystem)
- append(std::filesystem::absolute(shaderFileName).string());
- #else
+ // QNX says no: std::filesystem is unusable there, so always take the
+ // non-filesystem path below.
+ if (loc.getFilename() == nullptr && shaderFileName != nullptr && absolute) {
append(shaderFileName);
- #endif
} else {
- std::string location = loc.getStringNameOrNum(false);
- if (absolute) {
- #if defined(__cpp_lib_filesystem)
- append(std::filesystem::absolute(location).string());
- #else
- append(location);
- #endif
- } else {
- append(location);
- }
+ append(loc.getStringNameOrNum(false));
}
append(locText);
@@ -174,5 +165,6 @@ public:
glslang::TInfoSinkBase info;
glslang::TInfoSinkBase debug;
};
+} // namespace QtShaderTools
#endif // _INFOSINK_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/InitializeGlobals.h b/src/3rdparty/glslang/glslang/Include/InitializeGlobals.h
index b7fdd7a..d196bad 100644
--- a/src/3rdparty/glslang/glslang/Include/InitializeGlobals.h
+++ b/src/3rdparty/glslang/glslang/Include/InitializeGlobals.h
@@ -35,10 +35,12 @@
#ifndef __INITIALIZE_GLOBALS_INCLUDED_
#define __INITIALIZE_GLOBALS_INCLUDED_
+namespace QtShaderTools {
namespace glslang {
inline bool InitializePoolIndex() { return true; } // DEPRECATED: No need to call
} // end namespace glslang
+} // namespace QtShaderTools
#endif // __INITIALIZE_GLOBALS_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/PoolAlloc.h b/src/3rdparty/glslang/glslang/Include/PoolAlloc.h
index 21236ed..0284f45 100644
--- a/src/3rdparty/glslang/glslang/Include/PoolAlloc.h
+++ b/src/3rdparty/glslang/glslang/Include/PoolAlloc.h
@@ -67,6 +67,7 @@
#include <cstring>
#include <vector>
+namespace QtShaderTools {
namespace glslang {
// If we are using guard blocks, we must track each individual
@@ -327,5 +328,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _POOLALLOC_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/ShHandle.h b/src/3rdparty/glslang/glslang/Include/ShHandle.h
index dee47c0..edc9b18 100644
--- a/src/3rdparty/glslang/glslang/Include/ShHandle.h
+++ b/src/3rdparty/glslang/glslang/Include/ShHandle.h
@@ -47,6 +47,8 @@
#include "../MachineIndependent/Versions.h"
#include "InfoSink.h"
+namespace QtShaderTools {
+
class TCompiler;
class TLinker;
class TUniformMap;
@@ -173,4 +175,6 @@ void DeleteCompiler(TCompiler*);
void DeleteUniformMap(TUniformMap*);
+} //namespace QtShaderTools
+
#endif // _SHHANDLE_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/SpirvIntrinsics.h b/src/3rdparty/glslang/glslang/Include/SpirvIntrinsics.h
index 0082a4d..1b01536 100644
--- a/src/3rdparty/glslang/glslang/Include/SpirvIntrinsics.h
+++ b/src/3rdparty/glslang/glslang/Include/SpirvIntrinsics.h
@@ -41,6 +41,7 @@
#include "Common.h"
#include <variant>
+namespace QtShaderTools {
namespace glslang {
class TIntermTyped;
@@ -138,3 +139,4 @@ struct TSpirvType {
};
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/Include/Types.h b/src/3rdparty/glslang/glslang/Include/Types.h
index 2d8eec7..ee9ffee 100644
--- a/src/3rdparty/glslang/glslang/Include/Types.h
+++ b/src/3rdparty/glslang/glslang/Include/Types.h
@@ -49,6 +49,11 @@
#include <algorithm>
#include <climits>
+#ifdef restrict
+#undef restrict
+#endif
+
+namespace QtShaderTools {
namespace glslang {
class TIntermAggregate;
@@ -3286,5 +3291,6 @@ protected:
};
} // end namespace glslang
+} // end namespace QtShaderTools
#endif // _TYPES_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/arrays.h b/src/3rdparty/glslang/glslang/Include/arrays.h
index d476226..a622586 100644
--- a/src/3rdparty/glslang/glslang/Include/arrays.h
+++ b/src/3rdparty/glslang/glslang/Include/arrays.h
@@ -43,6 +43,7 @@
#include <algorithm>
+namespace QtShaderTools {
namespace glslang {
// This is used to mean there is no size yet (unsized), it is waiting to get a size from somewhere else.
@@ -380,5 +381,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _ARRAYS_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Include/intermediate.h b/src/3rdparty/glslang/glslang/Include/intermediate.h
index 029ece5..ca1dce6 100644
--- a/src/3rdparty/glslang/glslang/Include/intermediate.h
+++ b/src/3rdparty/glslang/glslang/Include/intermediate.h
@@ -52,6 +52,7 @@
#include "Types.h"
#include "ConstantUnion.h"
+namespace QtShaderTools {
namespace glslang {
class TIntermediate;
@@ -1997,5 +1998,6 @@ inline bool SameSpecializationConstants(TIntermTyped* node1, TIntermTyped* node2
}
} // end namespace glslang
+} // namespace QtShaderTools
#endif // __INTERMEDIATE_H
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Constant.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/Constant.cpp
index f402233..ca6fd84 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Constant.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Constant.cpp
@@ -45,6 +45,7 @@
namespace {
+using namespace QtShaderTools;
using namespace glslang;
constexpr double pi = 3.1415926535897932384626433832795;
@@ -64,6 +65,7 @@ To bitCast(From from)
} // end anonymous namespace
+namespace QtShaderTools {
namespace glslang {
//
@@ -1389,3 +1391,4 @@ TIntermTyped* TIntermediate::foldSwizzle(TIntermTyped* node, TSwizzleSelectors<T
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/InfoSink.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/InfoSink.cpp
index d00c422..7c14783 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/InfoSink.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/InfoSink.cpp
@@ -36,6 +36,7 @@
#include <cstring>
+namespace QtShaderTools {
namespace glslang {
void TInfoSinkBase::append(const char* s)
@@ -111,3 +112,4 @@ void TInfoSinkBase::append(const TString& t)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.cpp
index 5b2825b..9bf98cf 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.cpp
@@ -56,6 +56,7 @@
#include "Initialize.h"
#include "span.h"
+namespace QtShaderTools {
namespace glslang {
// TODO: ARB_Compatability: do full extension support
@@ -12576,3 +12577,4 @@ bool IsSupportedLongVectorBuiltin(const TFunction* fnCandidate, TType* resultTyp
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.h b/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.h
index 62e9dca..5bcca00 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Initialize.h
@@ -43,6 +43,7 @@
#include "SymbolTable.h"
#include "Versions.h"
+namespace QtShaderTools {
namespace glslang {
//
@@ -115,5 +116,6 @@ constexpr bool PureOperatorBuiltins = true;
bool IsSupportedLongVectorBuiltin(const TFunction* fnCandidate, TType* resultType, TIntermNode* arguments);
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _INITIALIZE_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/IntermTraverse.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/IntermTraverse.cpp
index 447e8cb..f1b8704 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/IntermTraverse.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/IntermTraverse.cpp
@@ -37,6 +37,7 @@
#include "../Include/intermediate.h"
+namespace QtShaderTools {
namespace glslang {
//
@@ -338,3 +339,4 @@ void TIntermVariableDecl::traverse(TIntermTraverser *it)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Intermediate.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/Intermediate.cpp
index 4004a6e..651f0aa 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Intermediate.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Intermediate.cpp
@@ -50,6 +50,7 @@
#include <utility>
#include <tuple>
+namespace QtShaderTools {
namespace glslang {
////////////////////////////////////////////////////////////////////////////
@@ -4149,3 +4150,4 @@ const char* TIntermediate::getResourceName(TResourceType res)
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/LiveTraverser.h b/src/3rdparty/glslang/glslang/MachineIndependent/LiveTraverser.h
index 76ccfec..d1b4e7f 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/LiveTraverser.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/LiveTraverser.h
@@ -44,6 +44,7 @@
#include <list>
#include <unordered_set>
+namespace QtShaderTools {
namespace glslang {
//
@@ -207,3 +208,4 @@ private:
};
} // namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/ParseContextBase.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/ParseContextBase.cpp
index e43cf51..7ba19ec 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/ParseContextBase.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/ParseContextBase.cpp
@@ -40,8 +40,9 @@
#include "ParseHelper.h"
-extern int yyparse(glslang::TParseContext*);
+extern int yyparse(QtShaderTools::glslang::TParseContext*);
+namespace QtShaderTools {
namespace glslang {
//
@@ -781,3 +782,4 @@ void TParseContextBase::finish()
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp
index ec6d553..eada34b 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.cpp
@@ -49,6 +49,8 @@
#include "Versions.h"
#include "preprocessor/PpContext.h"
+namespace QtShaderTools {
+
extern int yyparse(glslang::TParseContext*);
namespace glslang {
@@ -12529,3 +12531,4 @@ TLayoutFormat TParseContext::mapLegacyLayoutFormat(TLayoutFormat legacyLayoutFor
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.h b/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.h
index f508694..e077429 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/ParseHelper.h
@@ -55,6 +55,7 @@
#include "Scan.h"
#include "attribute.h"
+namespace QtShaderTools {
namespace glslang {
struct TPragma {
@@ -627,5 +628,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _PARSER_HELPER_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/PoolAlloc.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/PoolAlloc.cpp
index 40d4c8d..44198e6 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/PoolAlloc.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/PoolAlloc.cpp
@@ -42,6 +42,7 @@
#define THREAD_LOCAL thread_local
#endif
+namespace QtShaderTools {
namespace glslang {
namespace {
@@ -304,3 +305,4 @@ void TAllocation::checkAllocList() const
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.cpp
index 29baf1f..ceae0e3 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.cpp
@@ -37,6 +37,7 @@
#include "../Include/intermediate.h"
#include "RemoveTree.h"
+namespace QtShaderTools {
namespace glslang {
//
@@ -122,3 +123,4 @@ void RemoveAllTreeNodes(TIntermNode* root)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.h b/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.h
index 1ed0156..33b53d5 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/RemoveTree.h
@@ -34,8 +34,10 @@
#pragma once
+namespace QtShaderTools {
namespace glslang {
void RemoveAllTreeNodes(TIntermNode*);
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Scan.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/Scan.cpp
index ebe35d2..3ad4565 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Scan.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Scan.cpp
@@ -58,8 +58,9 @@
#include "preprocessor/PpContext.h"
#include "preprocessor/PpTokens.h"
+namespace QtShaderTools {
// Required to avoid missing prototype warnings for some compilers
-int yylex(YYSTYPE*, glslang::TParseContext&);
+int yylex(YYSTYPE*, QtShaderTools::glslang::TParseContext&);
namespace glslang {
@@ -2273,3 +2274,4 @@ int TScanContext::secondGenerationImage()
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Scan.h b/src/3rdparty/glslang/glslang/MachineIndependent/Scan.h
index 24b75cf..44be905 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Scan.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Scan.h
@@ -38,6 +38,7 @@
#include "Versions.h"
+namespace QtShaderTools {
namespace glslang {
// Use a global end-of-input character, so no translation is needed across
@@ -272,5 +273,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _GLSLANG_SCAN_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/ScanContext.h b/src/3rdparty/glslang/glslang/MachineIndependent/ScanContext.h
index ce2145e..277b46b 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/ScanContext.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/ScanContext.h
@@ -42,6 +42,7 @@
#include "ParseHelper.h"
+namespace QtShaderTools {
namespace glslang {
class TPpContext;
@@ -96,3 +97,4 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp
index 791044f..4ec8ac3 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/ShaderLang.cpp
@@ -87,6 +87,7 @@ std::mutex init_lock;
#endif
+using namespace QtShaderTools;
using namespace glslang;
// Create a language specific version of parseables.
@@ -1357,7 +1358,7 @@ bool CompileDeferred(
//
// ShInitialize() should be called exactly once per process, not per thread.
//
-int ShInitialize()
+int ShInitialize_Qt()
{
#ifndef DISABLE_THREAD_SUPPORT
const std::lock_guard<std::mutex> lock(init_lock);
@@ -1375,28 +1376,28 @@ int ShInitialize()
// objects.
//
-ShHandle ShConstructCompiler(const EShLanguage language, int /*debugOptions unused*/)
+ShHandle ShConstructCompiler_Qt(const EShLanguage language, int debugOptions)
{
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructCompiler(language, 0));
return reinterpret_cast<void*>(base);
}
-ShHandle ShConstructLinker(const EShExecutable executable, int /*debugOptions unused*/)
+ShHandle ShConstructLinker_Qt(const EShExecutable executable, int debugOptions)
{
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructLinker(executable, 0));
return reinterpret_cast<void*>(base);
}
-ShHandle ShConstructUniformMap()
+ShHandle ShConstructUniformMap_Qt()
{
TShHandleBase* base = static_cast<TShHandleBase*>(ConstructUniformMap());
return reinterpret_cast<void*>(base);
}
-void ShDestruct(ShHandle handle)
+void ShDestruct_Qt(ShHandle handle)
{
if (handle == nullptr)
return;
@@ -1414,7 +1415,7 @@ void ShDestruct(ShHandle handle)
//
// Cleanup symbol tables
//
-int ShFinalize()
+int ShFinalize_Qt()
{
#ifndef DISABLE_THREAD_SUPPORT
const std::lock_guard<std::mutex> lock(init_lock);
@@ -1466,7 +1467,7 @@ int ShFinalize()
// Return: The return value is really boolean, indicating
// success (1) or failure (0).
//
-int ShCompile(
+int ShCompile_Qt(
const ShHandle handle,
const char* const shaderStrings[],
const int numStrings,
@@ -1524,7 +1525,7 @@ int ShCompile(
// Return: The return value of is really boolean, indicating
// success or failure.
//
-int ShLinkExt(
+int ShLinkExt_Qt(
const ShHandle linkHandle,
const ShHandle compHandles[],
const int numHandles)
@@ -1575,7 +1576,7 @@ int ShLinkExt(
// ShSetEncrpytionMethod is a place-holder for specifying
// how source code is encrypted.
//
-void ShSetEncryptionMethod(ShHandle handle)
+void ShSetEncryptionMethod_Qt(ShHandle handle)
{
if (handle == nullptr)
return;
@@ -1584,7 +1585,7 @@ void ShSetEncryptionMethod(ShHandle handle)
//
// Return any compiler/linker/uniformmap log of messages for the application.
//
-const char* ShGetInfoLog(const ShHandle handle)
+const char* ShGetInfoLog_Qt(const ShHandle handle)
{
if (handle == nullptr)
return nullptr;
@@ -1607,7 +1608,7 @@ const char* ShGetInfoLog(const ShHandle handle)
// Return the resulting binary code from the link process. Structure
// is machine dependent.
//
-const void* ShGetExecutable(const ShHandle handle)
+const void* ShGetExecutable_Qt(const ShHandle handle)
{
if (handle == nullptr)
return nullptr;
@@ -1629,7 +1630,7 @@ const void* ShGetExecutable(const ShHandle handle)
// Return: The return value of is really boolean, indicating
// success or failure.
//
-int ShSetVirtualAttributeBindings(const ShHandle handle, const ShBindingTable* table)
+int ShSetVirtualAttributeBindings_Qt(const ShHandle handle, const ShBindingTable* table)
{
if (handle == nullptr)
return 0;
@@ -1648,7 +1649,7 @@ int ShSetVirtualAttributeBindings(const ShHandle handle, const ShBindingTable* t
//
// Let the linker know where the predefined attributes have to live.
//
-int ShSetFixedAttributeBindings(const ShHandle handle, const ShBindingTable* table)
+int ShSetFixedAttributeBindings_Qt(const ShHandle handle, const ShBindingTable* table)
{
if (handle == nullptr)
return 0;
@@ -1666,7 +1667,7 @@ int ShSetFixedAttributeBindings(const ShHandle handle, const ShBindingTable* tab
//
// Some attribute locations are off-limits to the linker...
//
-int ShExcludeAttributes(const ShHandle handle, int *attributes, int count)
+int ShExcludeAttributes_Qt(const ShHandle handle, int *attributes, int count)
{
if (handle == nullptr)
return 0;
@@ -1687,7 +1688,7 @@ int ShExcludeAttributes(const ShHandle handle, int *attributes, int count)
// Return: The return value of is really boolean, indicating
// success or failure.
//
-int ShGetUniformLocation(const ShHandle handle, const char* name)
+int ShGetUniformLocation_Qt(const ShHandle handle, const char* name)
{
if (handle == nullptr)
return -1;
@@ -1711,6 +1712,7 @@ int ShGetUniformLocation(const ShHandle handle, const char* name)
// See more detailed comment in ShaderLang.h
//
+namespace QtShaderTools {
namespace glslang {
Version GetVersion()
@@ -1745,12 +1747,12 @@ int GetKhronosToolId()
bool InitializeProcess()
{
- return ShInitialize() != 0;
+ return ShInitialize_Qt() != 0;
}
void FinalizeProcess()
{
- ShFinalize();
+ ShFinalize_Qt();
}
class TDeferredCompiler : public TCompiler {
@@ -1883,7 +1885,6 @@ void TShader::setUniformLocationBase(int base)
{
intermediate->setUniformLocationBase(base);
}
-void TShader::setBindingsPerResourceType() { intermediate->setBindingsPerResourceType(); }
void TShader::setNoStorageFormat(bool useUnknownFormat) { intermediate->setNoStorageFormat(useUnknownFormat); }
void TShader::setResourceSetBinding(const std::vector<std::string>& base) { intermediate->setResourceSetBinding(base); }
void TShader::setTextureSamplerTransformMode(EShTextureSamplerTransformMode mode) { intermediate->setTextureSamplerTransformMode(mode); }
@@ -2283,3 +2284,4 @@ bool TProgram::mapIO(TIoMapResolver* pResolver, TIoMapper* pIoMapper)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/SpirvIntrinsics.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/SpirvIntrinsics.cpp
index 9cb043a..f2f263f 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/SpirvIntrinsics.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/SpirvIntrinsics.cpp
@@ -41,6 +41,7 @@
#include "../Include/Types.h"
#include "ParseHelper.h"
+namespace QtShaderTools {
namespace glslang {
bool TSpirvTypeParameter::operator==(const TSpirvTypeParameter& rhs) const
@@ -358,3 +359,4 @@ TSpirvInstruction* TParseContext::mergeSpirvInstruction(const TSourceLoc& loc, T
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.cpp
index 333d76d..c8a9899 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.cpp
@@ -44,6 +44,7 @@
#include "SymbolTable.h"
+namespace QtShaderTools {
namespace glslang {
//
@@ -529,3 +530,4 @@ void TSymbolTable::copyTable(const TSymbolTable& copyOf)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h b/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h
index b9aecb5..52548a3 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/SymbolTable.h
@@ -68,10 +68,10 @@
#include "../Include/Common.h"
#include "../Include/intermediate.h"
#include "../Include/InfoSink.h"
-
+#include <cstdint>
#include <functional>
-#include <unordered_map>
+namespace QtShaderTools {
namespace glslang {
//
@@ -1001,5 +1001,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _SYMBOL_TABLE_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Versions.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/Versions.cpp
index e80a1ca..08c41b2 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Versions.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Versions.cpp
@@ -152,6 +152,7 @@
#include <iterator>
+namespace QtShaderTools {
namespace glslang {
//
@@ -1681,3 +1682,4 @@ void TParseVersions::requireSpv(const TSourceLoc& loc, const char *op, unsigned
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/Versions.h b/src/3rdparty/glslang/glslang/MachineIndependent/Versions.h
index ed028b3..5627623 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/Versions.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/Versions.h
@@ -63,6 +63,7 @@ typedef enum : unsigned {
LAST_ELEMENT_MARKER(EProfileCount),
} EProfile;
+namespace QtShaderTools {
namespace glslang {
//
@@ -432,5 +433,6 @@ const char* const AEP_mesh_shader[] = { E_GL_NV_mesh_shader, E_GL_EXT_mesh_shade
const int Num_AEP_mesh_shader = sizeof(AEP_mesh_shader)/sizeof(AEP_mesh_shader[0]);
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _VERSIONS_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/attribute.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/attribute.cpp
index e30fd1b..275a0b6 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/attribute.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/attribute.cpp
@@ -38,6 +38,7 @@
#include "../Include/intermediate.h"
#include "ParseHelper.h"
+namespace QtShaderTools {
namespace glslang {
// extract integers out of attribute arguments stored in attribute aggregate
@@ -399,3 +400,4 @@ void TParseContext::handleFunctionAttributes(const TSourceLoc& loc, TFunction& f
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/attribute.h b/src/3rdparty/glslang/glslang/MachineIndependent/attribute.h
index b049fa8..7f6491e 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/attribute.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/attribute.h
@@ -40,6 +40,7 @@
#include "../Include/Common.h"
#include "../Include/ConstantUnion.h"
+namespace QtShaderTools {
namespace glslang {
enum TAttributeType {
@@ -151,5 +152,6 @@ namespace glslang {
typedef TList<TAttributeArgs> TAttributes;
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _ATTRIBUTE_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp
index ebde28d..7b68ad8 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp
@@ -90,6 +90,7 @@ Jutta Degener, 1995
#include "../Public/ShaderLang.h"
#include "attribute.h"
+using namespace QtShaderTools;
using namespace glslang;
@@ -783,7 +784,9 @@ typedef enum yysymbol_kind_t yysymbol_kind_t;
#define parseContext (*pParseContext)
#define yyerror(context, msg) context->parserError(msg)
+namespace QtShaderTools {
extern int yylex(YYSTYPE*, TParseContext&);
+} // QtShaderTools
#line 790 "MachineIndependent/glslang_tab.cpp"
@@ -5632,6 +5635,8 @@ yydestruct (const char *yymsg,
| yyparse. |
`----------*/
+namespace QtShaderTools {
+
int
yyparse (glslang::TParseContext* pParseContext)
{
@@ -13988,5 +13993,6 @@ yyreturnlab:
return yyresult;
}
-#line 4807 "MachineIndependent/glslang.y"
+} // QtShaderTools
+#line 4807 "MachineIndependent/glslang.y"
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp.h b/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp.h
index 43e2b1f..f824fc4 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/glslang_tab.cpp.h
@@ -44,6 +44,9 @@
#if YYDEBUG
extern int yydebug;
#endif
+#ifdef __VXWORKS__
+#define BOOL ANOTHER_BOOL // VxWorks has typedef BOOL
+#endif
/* Token kinds. */
#ifndef YYTOKENTYPE
@@ -570,6 +573,7 @@ extern int yydebug;
typedef enum yytokentype yytoken_kind_t;
#endif
+namespace QtShaderTools {
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
@@ -624,7 +628,7 @@ typedef union YYSTYPE YYSTYPE;
-int yyparse (glslang::TParseContext* pParseContext);
-
+int yyparse (QtShaderTools::glslang::TParseContext* pParseContext);
+} // namespace QtShaderTools
#endif /* !YY_YY_MACHINEINDEPENDENT_GLSLANG_TAB_CPP_H_INCLUDED */
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/intermOut.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/intermOut.cpp
index 9237de2..863bf09 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/intermOut.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/intermOut.cpp
@@ -47,6 +47,7 @@
#include <cstdint>
+namespace QtShaderTools {
namespace glslang {
//
@@ -1595,3 +1596,4 @@ void TIntermediate::output(TInfoSink& infoSink, bool tree)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp
index f38ef56..3974d57 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.cpp
@@ -59,6 +59,7 @@
// c. implicit dead bindings are left un-bound.
//
+namespace QtShaderTools {
namespace glslang {
static int getLayoutSetLimit(bool relaxSetBindingLimits)
@@ -1856,3 +1857,4 @@ bool TGlslIoMapper::doMap(TIoMapResolver* resolver, TInfoSink& infoSink) {
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.h b/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.h
index 72ec58c..b59bc58 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/iomapper.h
@@ -44,6 +44,7 @@
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
//
+namespace QtShaderTools {
class TInfoSink;
namespace glslang {
@@ -241,5 +242,6 @@ private:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _IOMAPPER_INCLUDED
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/limits.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/limits.cpp
index 4404bec..aba6bdf 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/limits.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/limits.cpp
@@ -53,6 +53,7 @@
#include "ParseHelper.h"
+namespace QtShaderTools {
namespace glslang {
//
@@ -196,3 +197,4 @@ void TParseContext::constantIndexExpressionCheck(TIntermNode* index)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp
index 0b3d4e2..b19d60e 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/linkValidate.cpp
@@ -52,6 +52,7 @@
#include "SymbolTable.h"
#include "LiveTraverser.h"
+namespace QtShaderTools {
namespace glslang {
//
@@ -2794,3 +2795,4 @@ bool TIntermediate::isIoResizeArray(const TType& type, EShLanguage language) {
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h b/src/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h
index c5af0bd..61f8aa6 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/localintermediate.h
@@ -51,6 +51,7 @@
#include <unordered_map>
#include <vector>
+namespace QtShaderTools {
class TInfoSink;
namespace glslang {
@@ -1412,5 +1413,6 @@ private:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _LOCAL_INTERMEDIATE_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/parseConst.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/parseConst.cpp
index 8350972..81dfbef 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/parseConst.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/parseConst.cpp
@@ -39,6 +39,7 @@
#include "ParseHelper.h"
+namespace QtShaderTools {
namespace glslang {
class TConstTraverser : public TIntermTraverser {
@@ -211,3 +212,4 @@ bool TIntermediate::parseConstTree(TIntermNode* root, TConstUnionArray unionArra
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/parseVersions.h b/src/3rdparty/glslang/glslang/MachineIndependent/parseVersions.h
index cbc2836..15c7480 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/parseVersions.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/parseVersions.h
@@ -45,6 +45,7 @@
#include <map>
+namespace QtShaderTools {
namespace glslang {
//
@@ -197,5 +198,6 @@ private:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _PARSE_VERSIONS_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp
index f5a9793..71f71e0 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp
@@ -89,6 +89,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "PpContext.h"
#include "PpTokens.h"
+namespace QtShaderTools {
namespace glslang {
// Handle #define
@@ -1421,3 +1422,4 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp
index 06c2333..2192913 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp
@@ -89,6 +89,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
namespace {
+using namespace QtShaderTools;
using namespace glslang;
const struct {
@@ -151,6 +152,7 @@ const struct {
} // end anonymous namespace
+namespace QtShaderTools {
namespace glslang {
//
@@ -179,3 +181,4 @@ TStringAtomMap::TStringAtomMap()
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp
index 12ab9c2..f059117 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp
@@ -82,6 +82,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "PpContext.h"
+namespace QtShaderTools {
namespace glslang {
TPpContext::TPpContext(TParseContextBase& pc, const std::string& rootFileName, TShader::Includer& inclr) :
@@ -119,3 +120,4 @@ void TPpContext::setInput(TInputScanner& input, bool versionWillBeError)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.h b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.h
index f164f0e..31b5453 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpContext.h
@@ -86,6 +86,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "../ParseHelper.h"
#include "PpTokens.h"
+namespace QtShaderTools {
namespace glslang {
class TPpToken {
@@ -739,5 +740,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // PPCONTEXT_H
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp
index a7243de..9141f1f 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp
@@ -91,6 +91,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "PpTokens.h"
#include "../Scan.h"
+namespace QtShaderTools {
namespace glslang {
///////////////////////////////////////////////////////////////////////////////////////////////
@@ -1498,3 +1499,4 @@ void TPpContext::missingEndifCheck()
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp
index 472df78..a7cbae2 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp
@@ -94,6 +94,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "PpContext.h"
#include "PpTokens.h"
+namespace QtShaderTools {
namespace glslang {
// Add a token (including backing string) to the end of a macro
@@ -183,3 +184,4 @@ void TPpContext::UngetToken(int token, TPpToken* ppToken)
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h
index 486f69a..a96ed44 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h
@@ -78,6 +78,7 @@ NVIDIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef PARSER_H
#define PARSER_H
+namespace QtShaderTools {
namespace glslang {
// Multi-character tokens
@@ -180,5 +181,6 @@ enum EFixedAtoms {
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif /* not PARSER_H */
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.cpp
index 763c239..6dc5b02 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.cpp
@@ -46,6 +46,7 @@
#include <unordered_set>
#include "localintermediate.h"
+namespace QtShaderTools {
namespace {
// Use a string to hold the access chain information, as in most cases the
@@ -871,3 +872,4 @@ void PropagateNoContraction(const glslang::TIntermediate& intermediate)
}
}
}
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.h b/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.h
index d849be8..3721850 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/propagateNoContraction.h
@@ -41,6 +41,7 @@
#include "../Include/intermediate.h"
+namespace QtShaderTools {
namespace glslang {
// Propagates the 'precise' qualifier for objects (objects marked with
@@ -53,4 +54,5 @@ namespace glslang {
// nodes, it means the operation should not be contracted.
void PropagateNoContraction(const glslang::TIntermediate& intermediate);
-} // end namespace glslang
+}
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/reflection.cpp b/src/3rdparty/glslang/glslang/MachineIndependent/reflection.cpp
index 3fcb72f..dff028a 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/reflection.cpp
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/reflection.cpp
@@ -63,6 +63,7 @@
// there wasn't exactly one entry point.
//
+namespace QtShaderTools {
namespace glslang {
//
@@ -1294,3 +1295,4 @@ void TReflection::dump()
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/MachineIndependent/reflection.h b/src/3rdparty/glslang/glslang/MachineIndependent/reflection.h
index 185f801..cdf7eaa 100644
--- a/src/3rdparty/glslang/glslang/MachineIndependent/reflection.h
+++ b/src/3rdparty/glslang/glslang/MachineIndependent/reflection.h
@@ -46,6 +46,7 @@
// A reflection database and its interface, consistent with the OpenGL API reflection queries.
//
+namespace QtShaderTools {
namespace glslang {
class TIntermediate;
@@ -222,5 +223,6 @@ protected:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _REFLECTION_INCLUDED
diff --git a/src/3rdparty/glslang/glslang/OSDependent/Unix/ossource.cpp b/src/3rdparty/glslang/glslang/OSDependent/Unix/ossource.cpp
index fbb51f7..a18b5cb 100644
--- a/src/3rdparty/glslang/glslang/OSDependent/Unix/ossource.cpp
+++ b/src/3rdparty/glslang/glslang/OSDependent/Unix/ossource.cpp
@@ -39,10 +39,11 @@
#include <cstdio>
-#if !defined(__Fuchsia__)
+#if !defined(__Fuchsia__) && !defined(__ghs__)
#include <sys/resource.h>
#endif
+namespace QtShaderTools {
namespace glslang {
// #define DUMP_COUNTERS
@@ -60,3 +61,4 @@ void OS_DumpMemoryCounters()
}
} // end namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/OSDependent/Windows/ossource.cpp b/src/3rdparty/glslang/glslang/OSDependent/Windows/ossource.cpp
index d7f89f7..b4fe844 100644
--- a/src/3rdparty/glslang/glslang/OSDependent/Windows/ossource.cpp
+++ b/src/3rdparty/glslang/glslang/OSDependent/Windows/ossource.cpp
@@ -49,6 +49,7 @@
#error Trying to build a windows specific file in a non windows build.
#endif
+namespace QtShaderTools {
namespace glslang {
//#define DUMP_COUNTERS
@@ -65,3 +66,4 @@ void OS_DumpMemoryCounters()
}
} // namespace glslang
+} // namespace QtShaderTools
diff --git a/src/3rdparty/glslang/glslang/OSDependent/osinclude.h b/src/3rdparty/glslang/glslang/OSDependent/osinclude.h
index da1c4f6..2d5d8c9 100644
--- a/src/3rdparty/glslang/glslang/OSDependent/osinclude.h
+++ b/src/3rdparty/glslang/glslang/OSDependent/osinclude.h
@@ -36,10 +36,12 @@
#define __OSINCLUDE_H
#include "../Include/visibility.h"
+namespace QtShaderTools {
namespace glslang {
GLSLANG_EXPORT void OS_DumpMemoryCounters();
} // end namespace glslang
+} // namespace QtShaderTools
#endif // __OSINCLUDE_H
diff --git a/src/3rdparty/glslang/glslang/Public/ResourceLimits.h b/src/3rdparty/glslang/glslang/Public/ResourceLimits.h
index 8245e12..3dba0cb 100644
--- a/src/3rdparty/glslang/glslang/Public/ResourceLimits.h
+++ b/src/3rdparty/glslang/glslang/Public/ResourceLimits.h
@@ -40,6 +40,8 @@
#include "../Include/ResourceLimits.h"
#include "../Include/visibility.h"
+namespace QtShaderTools {
+
// Return pointer to user-writable Resource to pass through API in
// future-proof way.
GLSLANG_EXPORT extern TBuiltInResource* GetResources();
@@ -55,4 +57,6 @@ GLSLANG_EXPORT std::string GetDefaultTBuiltInResourceString();
// Decodes the resource limits from |config| to |resources|.
GLSLANG_EXPORT void DecodeResourceLimits(TBuiltInResource* resources, char* config);
+}
+
#endif // _STAND_ALONE_RESOURCE_LIMITS_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/Public/ShaderLang.h b/src/3rdparty/glslang/glslang/Public/ShaderLang.h
index dc68285..7393fdf 100644
--- a/src/3rdparty/glslang/glslang/Public/ShaderLang.h
+++ b/src/3rdparty/glslang/glslang/Public/ShaderLang.h
@@ -64,12 +64,12 @@
//
// (Call once per process, not once per thread.)
//
-GLSLANG_EXPORT int ShInitialize();
+GLSLANG_EXPORT int ShInitialize_Qt();
//
// Call this at process shutdown to clean up memory.
//
-GLSLANG_EXPORT int ShFinalize();
+GLSLANG_EXPORT int ShFinalize_Qt();
//
// Types of languages the compiler can consume.
@@ -126,6 +126,11 @@ typedef enum : unsigned {
LAST_ELEMENT_MARKER(EShLanguageMaskCount),
} EShLanguageMask;
+#ifdef __cplusplus
+ }
+#endif
+
+namespace QtShaderTools {
namespace glslang {
class TType;
@@ -220,6 +225,11 @@ struct TEnvironment {
GLSLANG_EXPORT const char* StageName(EShLanguage);
} // end namespace glslang
+} // namespace QtShaderTools
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
//
// Types of output the linker will create.
@@ -324,10 +334,10 @@ typedef void* ShHandle;
// Driver calls these to create and destroy compiler/linker
// objects.
//
-GLSLANG_EXPORT ShHandle ShConstructCompiler(const EShLanguage, int /*debugOptions unused*/); // one per shader
-GLSLANG_EXPORT ShHandle ShConstructLinker(const EShExecutable, int /*debugOptions unused*/); // one per shader pair
-GLSLANG_EXPORT ShHandle ShConstructUniformMap(); // one per uniform namespace (currently entire program object)
-GLSLANG_EXPORT void ShDestruct(ShHandle);
+GLSLANG_EXPORT ShHandle ShConstructCompiler_Qt(const EShLanguage, int /*debugOptions unused*/); // one per shader
+GLSLANG_EXPORT ShHandle ShConstructLinker_Qt(const EShExecutable, int /*debugOptions unused*/); // one per shader pair
+GLSLANG_EXPORT ShHandle ShConstructUniformMap_Qt(); // one per uniform namespace (currently entire program object)
+GLSLANG_EXPORT void ShDestruct_Qt(ShHandle);
//
// The return value of ShCompile is boolean, non-zero indicating
@@ -336,7 +346,7 @@ GLSLANG_EXPORT void ShDestruct(ShHandle);
// The info-log should be written by ShCompile into
// ShHandle, so it can answer future queries.
//
-GLSLANG_EXPORT int ShCompile(const ShHandle, const char* const shaderStrings[], const int numStrings,
+GLSLANG_EXPORT int ShCompile_Qt(const ShHandle, const char* const shaderStrings[], const int numStrings,
const int* lengths, const EShOptimizationLevel, const TBuiltInResource* resources,
int, // debugOptions unused
int defaultVersion = 110, // use 100 for ES environment, overridden by #version in shader
@@ -345,7 +355,7 @@ GLSLANG_EXPORT int ShCompile(const ShHandle, const char* const shaderStrings[],
const char* fileName = nullptr
);
-GLSLANG_EXPORT int ShLinkExt(
+GLSLANG_EXPORT int ShLinkExt_Qt(
const ShHandle, // linker object
const ShHandle h[], // compiler objects to link together
const int numHandles);
@@ -354,26 +364,26 @@ GLSLANG_EXPORT int ShLinkExt(
// ShSetEncrpytionMethod is a place-holder for specifying
// how source code is encrypted.
//
-GLSLANG_EXPORT void ShSetEncryptionMethod(ShHandle);
+GLSLANG_EXPORT void ShSetEncryptionMethod_Qt(ShHandle);
//
// All the following return 0 if the information is not
// available in the object passed down, or the object is bad.
//
-GLSLANG_EXPORT const char* ShGetInfoLog(const ShHandle);
-GLSLANG_EXPORT const void* ShGetExecutable(const ShHandle);
-GLSLANG_EXPORT int ShSetVirtualAttributeBindings(const ShHandle, const ShBindingTable*); // to detect user aliasing
-GLSLANG_EXPORT int ShSetFixedAttributeBindings(const ShHandle, const ShBindingTable*); // to force any physical mappings
+GLSLANG_EXPORT const char* ShGetInfoLog_Qt(const ShHandle);
+GLSLANG_EXPORT const void* ShGetExecutable_Qt(const ShHandle);
+GLSLANG_EXPORT int ShSetVirtualAttributeBindings_Qt(const ShHandle, const ShBindingTable*); // to detect user aliasing
+GLSLANG_EXPORT int ShSetFixedAttributeBindings_Qt(const ShHandle, const ShBindingTable*); // to force any physical mappings
//
// Tell the linker to never assign a vertex attribute to this list of physical attributes
//
-GLSLANG_EXPORT int ShExcludeAttributes(const ShHandle, int *attributes, int count);
+GLSLANG_EXPORT int ShExcludeAttributes_Qt(const ShHandle, int *attributes, int count);
//
// Returns the location ID of the named uniform.
// Returns -1 if error.
//
-GLSLANG_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* name);
+GLSLANG_EXPORT int ShGetUniformLocation_Qt(const ShHandle uniformMap, const char* name);
#ifdef __cplusplus
} // end extern "C"
@@ -399,6 +409,7 @@ GLSLANG_EXPORT int ShGetUniformLocation(const ShHandle uniformMap, const char* n
#include <string>
#include <utility>
+namespace QtShaderTools {
class TCompiler;
class TInfoSink;
@@ -1057,5 +1068,6 @@ private:
};
} // end namespace glslang
+} // namespace QtShaderTools
#endif // _COMPILER_INTERFACE_INCLUDED_
diff --git a/src/3rdparty/glslang/glslang/ResourceLimits/ResourceLimits.cpp b/src/3rdparty/glslang/glslang/ResourceLimits/ResourceLimits.cpp
index 79a1b3a..a8b7bf6 100644
--- a/src/3rdparty/glslang/glslang/ResourceLimits/ResourceLimits.cpp
+++ b/src/3rdparty/glslang/glslang/ResourceLimits/ResourceLimits.cpp
@@ -39,6 +39,7 @@
#include "glslang/Public/ResourceLimits.h"
+namespace QtShaderTools {
static TBuiltInResource Resources;
static const TBuiltInResource DefaultTBuiltInResource = {
@@ -540,3 +541,6 @@ const TBuiltInResource* GetDefaultResources()
{
return &DefaultTBuiltInResource;
}
+
+} // namespace QtShaderTools
+
--
2.36.1.windows.1