Updated glslang.

This commit is contained in:
Бранимир Караџић 2021-05-14 19:35:38 -07:00
parent e532aba391
commit 5d7814c334
10 changed files with 102 additions and 7 deletions

@ -3,6 +3,20 @@
All notable changes to this project will be documented in this file. All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/). This project adheres to [Semantic Versioning](https://semver.org/).
## 11.4.0 2021-04-22
### Other changes
* Fix to keep source compatible with CMake 3.10.2
## 11.3.0 2021-04-21
### Other changes
* Added --depfile
* Added --auto-sampled-textures
* Now supports InterpolateAt-based functions
* Supports cross-stage automatic IO mapping
* Supports GL_EXT_vulkan_glsl_relaxed (-R option)
## 11.2.0 2021-02-18 ## 11.2.0 2021-02-18
### Other changes ### Other changes

@ -4236,6 +4236,8 @@ spv::Id TGlslangToSpvTraverser::makeArraySizeId(const glslang::TArraySizes& arra
glslang::TIntermTyped* specNode = arraySizes.getDimNode(dim); glslang::TIntermTyped* specNode = arraySizes.getDimNode(dim);
if (specNode != nullptr) { if (specNode != nullptr) {
builder.clearAccessChain(); builder.clearAccessChain();
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
specNode->traverse(this); specNode->traverse(this);
return accessChainLoad(specNode->getAsTyped()->getType()); return accessChainLoad(specNode->getAsTyped()->getType());
} }

@ -40,6 +40,7 @@
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <algorithm> #include <algorithm>
#include <set>
#include "./../glslang/Public/ShaderLang.h" #include "./../glslang/Public/ShaderLang.h"
@ -84,12 +85,18 @@ public:
} }
} }
virtual std::set<std::string> getIncludedFiles()
{
return includedFiles;
}
virtual ~DirStackFileIncluder() override { } virtual ~DirStackFileIncluder() override { }
protected: protected:
typedef char tUserDataElement; typedef char tUserDataElement;
std::vector<std::string> directoryStack; std::vector<std::string> directoryStack;
int externalLocalDirectoryCount; int externalLocalDirectoryCount;
std::set<std::string> includedFiles;
// Search for a valid "local" path based on combining the stack of include // Search for a valid "local" path based on combining the stack of include
// directories and the nominal name of the header. // directories and the nominal name of the header.
@ -108,6 +115,7 @@ protected:
std::ifstream file(path, std::ios_base::binary | std::ios_base::ate); std::ifstream file(path, std::ios_base::binary | std::ios_base::ate);
if (file) { if (file) {
directoryStack.push_back(getDirectory(path)); directoryStack.push_back(getDirectory(path));
includedFiles.insert(path);
return newIncludeResult(path, file, (int)file.tellg()); return newIncludeResult(path, file, (int)file.tellg());
} }
} }

@ -58,6 +58,7 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <thread> #include <thread>
#include <set>
#include "../glslang/OSDependent/osinclude.h" #include "../glslang/OSDependent/osinclude.h"
@ -111,6 +112,7 @@ bool NaNClamp = false;
bool stripDebugInfo = false; bool stripDebugInfo = false;
bool beQuiet = false; bool beQuiet = false;
bool VulkanRulesRelaxed = false; bool VulkanRulesRelaxed = false;
bool autoSampledTextures = false;
// //
// Return codes from main/exit(). // Return codes from main/exit().
@ -165,6 +167,7 @@ int ReflectOptions = EShReflectionDefault;
int Options = 0; int Options = 0;
const char* ExecutableName = nullptr; const char* ExecutableName = nullptr;
const char* binaryFileName = nullptr; const char* binaryFileName = nullptr;
const char* depencyFileName = nullptr;
const char* entryPointName = nullptr; const char* entryPointName = nullptr;
const char* sourceEntryPointName = nullptr; const char* sourceEntryPointName = nullptr;
const char* shaderStageName = nullptr; const char* shaderStageName = nullptr;
@ -655,6 +658,8 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
HlslEnable16BitTypes = true; HlslEnable16BitTypes = true;
} else if (lowerword == "hlsl-dx9-compatible") { } else if (lowerword == "hlsl-dx9-compatible") {
HlslDX9compatible = true; HlslDX9compatible = true;
} else if (lowerword == "auto-sampled-textures") {
autoSampledTextures = true;
} else if (lowerword == "invert-y" || // synonyms } else if (lowerword == "invert-y" || // synonyms
lowerword == "iy") { lowerword == "iy") {
Options |= EOptionInvertY; Options |= EOptionInvertY;
@ -798,6 +803,11 @@ void ProcessArguments(std::vector<std::unique_ptr<glslang::TWorkItem>>& workItem
break; break;
} else if (lowerword == "quiet") { } else if (lowerword == "quiet") {
beQuiet = true; beQuiet = true;
} else if (lowerword == "depfile") {
if (argc <= 1)
Error("no <depfile-name> provided", lowerword.c_str());
depencyFileName = argv[1];
bumpArg();
} else if (lowerword == "version") { } else if (lowerword == "version") {
Options |= EOptionDumpVersions; Options |= EOptionDumpVersions;
} else if (lowerword == "help") { } else if (lowerword == "help") {
@ -1135,6 +1145,23 @@ struct ShaderCompUnit {
} }
}; };
// Writes a depfile similar to gcc -MMD foo.c
bool writeDepFile(std::string depfile, std::vector<std::string>& binaryFiles, const std::vector<std::string>& sources)
{
std::ofstream file(depfile);
if (file.fail())
return false;
for (auto it = binaryFiles.begin(); it != binaryFiles.end(); it++) {
file << *it << ":";
for (auto it = sources.begin(); it != sources.end(); it++) {
file << " " << *it;
}
file << std::endl;
}
return true;
}
// //
// For linking mode: Will independently parse each compilation unit, but then put them // For linking mode: Will independently parse each compilation unit, but then put them
// in the same program and link them together, making at most one linked module per // in the same program and link them together, making at most one linked module per
@ -1151,6 +1178,12 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
EShMessages messages = EShMsgDefault; EShMessages messages = EShMsgDefault;
SetMessageOptions(messages); SetMessageOptions(messages);
DirStackFileIncluder includer;
std::for_each(IncludeDirectoryList.rbegin(), IncludeDirectoryList.rend(), [&includer](const std::string& dir) {
includer.pushExternalLocalDirectory(dir); });
std::vector<std::string> sources;
// //
// Per-shader processing... // Per-shader processing...
// //
@ -1158,6 +1191,9 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
glslang::TProgram& program = *new glslang::TProgram; glslang::TProgram& program = *new glslang::TProgram;
for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) { for (auto it = compUnits.cbegin(); it != compUnits.cend(); ++it) {
const auto &compUnit = *it; const auto &compUnit = *it;
for (int i = 0; i < compUnit.count; i++) {
sources.push_back(compUnit.fileNameList[i]);
}
glslang::TShader* shader = new glslang::TShader(compUnit.stage); glslang::TShader* shader = new glslang::TShader(compUnit.stage);
shader->setStringsWithLengthsAndNames(compUnit.text, NULL, compUnit.fileNameList, compUnit.count); shader->setStringsWithLengthsAndNames(compUnit.text, NULL, compUnit.fileNameList, compUnit.count);
if (entryPointName) if (entryPointName)
@ -1189,6 +1225,9 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
shader->setNoStorageFormat((Options & EOptionNoStorageFormat) != 0); shader->setNoStorageFormat((Options & EOptionNoStorageFormat) != 0);
shader->setResourceSetBinding(baseResourceSetBinding[compUnit.stage]); shader->setResourceSetBinding(baseResourceSetBinding[compUnit.stage]);
if (autoSampledTextures)
shader->setTextureSamplerTransformMode(EShTexSampTransUpgradeTextureRemoveSampler);
if (Options & EOptionAutoMapBindings) if (Options & EOptionAutoMapBindings)
shader->setAutoMapBindings(true); shader->setAutoMapBindings(true);
@ -1252,9 +1291,6 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
const int defaultVersion = Options & EOptionDefaultDesktop ? 110 : 100; const int defaultVersion = Options & EOptionDefaultDesktop ? 110 : 100;
DirStackFileIncluder includer;
std::for_each(IncludeDirectoryList.rbegin(), IncludeDirectoryList.rend(), [&includer](const std::string& dir) {
includer.pushExternalLocalDirectory(dir); });
#ifndef GLSLANG_WEB #ifndef GLSLANG_WEB
if (Options & EOptionOutputPreprocessed) { if (Options & EOptionOutputPreprocessed) {
std::string str; std::string str;
@ -1314,6 +1350,8 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
} }
#endif #endif
std::vector<std::string> outputFiles;
// Dump SPIR-V // Dump SPIR-V
if (Options & EOptionSpv) { if (Options & EOptionSpv) {
if (CompileFailed || LinkFailed) if (CompileFailed || LinkFailed)
@ -1343,6 +1381,8 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
} else { } else {
glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage)); glslang::OutputSpvBin(spirv, GetBinaryName((EShLanguage)stage));
} }
outputFiles.push_back(GetBinaryName((EShLanguage)stage));
#ifndef GLSLANG_WEB #ifndef GLSLANG_WEB
if (!SpvToolsDisassembler && (Options & EOptionHumanReadableSpv)) if (!SpvToolsDisassembler && (Options & EOptionHumanReadableSpv))
spv::Disassemble(std::cout, spirv); spv::Disassemble(std::cout, spirv);
@ -1353,6 +1393,13 @@ void CompileAndLinkShaderUnits(std::vector<ShaderCompUnit> compUnits)
} }
} }
if (depencyFileName && !(CompileFailed || LinkFailed)) {
std::set<std::string> includedFiles = includer.getIncludedFiles();
sources.insert(sources.end(), includedFiles.begin(), includedFiles.end());
writeDepFile(depencyFileName, outputFiles, sources);
}
// Free everything up, program has to go before the shaders // Free everything up, program has to go before the shaders
// because it might have merged stuff from the shaders, and // because it might have merged stuff from the shaders, and
// the stuff from the shaders has to have its destructors called // the stuff from the shaders has to have its destructors called
@ -1772,7 +1819,10 @@ void usage()
" without explicit bindings\n" " without explicit bindings\n"
" --auto-map-locations | --aml automatically locate input/output lacking\n" " --auto-map-locations | --aml automatically locate input/output lacking\n"
" 'location' (fragile, not cross stage)\n" " 'location' (fragile, not cross stage)\n"
" --auto-sampled-textures Removes sampler variables and converts\n"
" existing textures to sampled textures\n"
" --client {vulkan<ver>|opengl<ver>} see -V and -G\n" " --client {vulkan<ver>|opengl<ver>} see -V and -G\n"
" --depfile <file> writes depfile for build systems\n"
" --dump-builtin-symbols prints builtin symbol table prior each compile\n" " --dump-builtin-symbols prints builtin symbol table prior each compile\n"
" -dumpfullversion | -dumpversion print bare major.minor.patchlevel\n" " -dumpfullversion | -dumpversion print bare major.minor.patchlevel\n"
" --flatten-uniform-arrays | --fua flatten uniform texture/sampler arrays to\n" " --flatten-uniform-arrays | --fua flatten uniform texture/sampler arrays to\n"

@ -35,7 +35,7 @@
#define GLSLANG_BUILD_INFO #define GLSLANG_BUILD_INFO
#define GLSLANG_VERSION_MAJOR 11 #define GLSLANG_VERSION_MAJOR 11
#define GLSLANG_VERSION_MINOR 2 #define GLSLANG_VERSION_MINOR 4
#define GLSLANG_VERSION_PATCH 0 #define GLSLANG_VERSION_PATCH 0
#define GLSLANG_VERSION_FLAVOR "" #define GLSLANG_VERSION_FLAVOR ""

@ -3244,7 +3244,7 @@ bool HlslGrammar::acceptConstructor(TIntermTyped*& node)
} }
// hook it up // hook it up
node = parseContext.handleFunctionCall(arguments->getLoc(), constructorFunction, arguments); node = parseContext.handleFunctionCall(token.loc, constructorFunction, arguments);
return node != nullptr; return node != nullptr;
} }

@ -115,6 +115,7 @@ struct TSampler { // misnomer now; includes images, textures without sampler,
#endif #endif
bool is1D() const { return dim == Esd1D; } bool is1D() const { return dim == Esd1D; }
bool is2D() const { return dim == Esd2D; }
bool isBuffer() const { return dim == EsdBuffer; } bool isBuffer() const { return dim == EsdBuffer; }
bool isRect() const { return dim == EsdRect; } bool isRect() const { return dim == EsdRect; }
bool isSubpass() const { return dim == EsdSubpass; } bool isSubpass() const { return dim == EsdSubpass; }

@ -1261,6 +1261,16 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
"bvec3 notEqual(u64vec3, u64vec3);" "bvec3 notEqual(u64vec3, u64vec3);"
"bvec4 notEqual(u64vec4, u64vec4);" "bvec4 notEqual(u64vec4, u64vec4);"
"int64_t bitCount(int64_t);"
"i64vec2 bitCount(i64vec2);"
"i64vec3 bitCount(i64vec3);"
"i64vec4 bitCount(i64vec4);"
"int64_t bitCount(uint64_t);"
"i64vec2 bitCount(u64vec2);"
"i64vec3 bitCount(u64vec3);"
"i64vec4 bitCount(u64vec4);"
"int64_t findLSB(int64_t);" "int64_t findLSB(int64_t);"
"i64vec2 findLSB(i64vec2);" "i64vec2 findLSB(i64vec2);"
"i64vec3 findLSB(i64vec3);" "i64vec3 findLSB(i64vec3);"

@ -2191,6 +2191,16 @@ void TParseContext::builtInOpCheck(const TSourceLoc& loc, const TFunction& fnCan
"[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]"); "[gl_MinProgramTexelOffset, gl_MaxProgramTexelOffset]");
} }
} }
if (callNode.getOp() == EOpTextureOffset) {
TSampler s = arg0->getType().getSampler();
if (s.is2D() && s.isArrayed() && s.isShadow()) {
if (isEsProfile())
error(loc, "TextureOffset does not support sampler2DArrayShadow : ", "sampler", "ES Profile");
else if (version <= 420)
error(loc, "TextureOffset does not support sampler2DArrayShadow : ", "sampler", "version <= 420");
}
}
} }
break; break;

@ -508,7 +508,7 @@ public:
// //
// setEnvInput: The input source language and stage. If generating code for a // setEnvInput: The input source language and stage. If generating code for a
// specific client, the input client semantics to use and the // specific client, the input client semantics to use and the
// version of the that client's input semantics to use, otherwise // version of that client's input semantics to use, otherwise
// use EShClientNone and version of 0, e.g. for validation mode. // use EShClientNone and version of 0, e.g. for validation mode.
// Note 'version' does not describe the target environment, // Note 'version' does not describe the target environment,
// just the version of the source dialect to compile under. // just the version of the source dialect to compile under.
@ -722,7 +722,7 @@ class TObjectReflection {
public: public:
GLSLANG_EXPORT TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex); GLSLANG_EXPORT TObjectReflection(const std::string& pName, const TType& pType, int pOffset, int pGLDefineType, int pSize, int pIndex);
GLSLANG_EXPORT const TType* getType() const { return type; } const TType* getType() const { return type; }
GLSLANG_EXPORT int getBinding() const; GLSLANG_EXPORT int getBinding() const;
GLSLANG_EXPORT void dump() const; GLSLANG_EXPORT void dump() const;
static TObjectReflection badReflection() { return TObjectReflection(); } static TObjectReflection badReflection() { return TObjectReflection(); }