From edadf45605f5ff49577586cb360c1b1ab32b5a1c Mon Sep 17 00:00:00 2001 From: John Kessenich <cepheus@frii.com> Date: Tue, 16 Jun 2015 19:01:56 +0000 Subject: [PATCH] glslang: Add API override of version and profile for testing purposes. From Lei Zhang <antiagainst@google.com>. Add defaultProfile and forceDefaultVersionAndProfile into shader compilation interface. forceDefaultVersionAndProfile allows us to force parsing the input shaders using defaultVersion and defaultProfile, regardless of the #version directive in input shaders. These two parameters enables us to programmatically invoke glslang but specify version and profile from somewhere else like command line. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31504 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- glslang/MachineIndependent/Scan.cpp | 2 +- glslang/MachineIndependent/ShaderLang.cpp | 32 ++++++++++++++++++++--- glslang/MachineIndependent/Versions.cpp | 14 ---------- glslang/MachineIndependent/Versions.h | 14 ++++++++++ glslang/Public/ShaderLang.h | 4 +++ 5 files changed, 48 insertions(+), 18 deletions(-) diff --git a/glslang/MachineIndependent/Scan.cpp b/glslang/MachineIndependent/Scan.cpp index f7f4d60ce..83f16ce44 100644 --- a/glslang/MachineIndependent/Scan.cpp +++ b/glslang/MachineIndependent/Scan.cpp @@ -155,7 +155,7 @@ void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab) // or no #version was found; otherwise, returns false. There is no error case, it always // succeeds, but will leave version == 0 if no #version was found. // -// Sets versionNotFirstToken based on whether tokens (beyond white space and comments) +// Sets notFirstToken based on whether tokens (beyond white space and comments) // appeared before the #version. // // N.B. does not attempt to leave input in any particular known state. The assumption diff --git a/glslang/MachineIndependent/ShaderLang.cpp b/glslang/MachineIndependent/ShaderLang.cpp index aaadace3b..075ee8d04 100644 --- a/glslang/MachineIndependent/ShaderLang.cpp +++ b/glslang/MachineIndependent/ShaderLang.cpp @@ -453,6 +453,10 @@ bool CompileDeferred( const EShOptimizationLevel optLevel, const TBuiltInResource* resources, int defaultVersion, // use 100 for ES environment, 110 for desktop + EProfile defaultProfile, + // set version/profile to defaultVersion/defaultProfile regardless of the #version + // directive in the source code + bool forceDefaultVersionAndProfile, bool forwardCompatible, // give errors for use of deprecated features EShMessages messages, // warnings/errors/AST; things to print out TIntermediate& intermediate // returned tree, etc. @@ -497,6 +501,23 @@ bool CompileDeferred( bool versionNotFirstToken; bool versionNotFirst = userInput.scanVersion(version, profile, versionNotFirstToken); bool versionNotFound = version == 0; + if (forceDefaultVersionAndProfile) { + if (!(messages & EShMsgSuppressWarnings) && !versionNotFound && + (version != defaultVersion || profile != defaultProfile)) { + compiler->infoSink.info << "Warning, (version, profile) forced to be (" + << defaultVersion << ", " << ProfileName(defaultProfile) + << "), while in source code it is (" + << version << ", " << ProfileName(profile) << ")\n"; + } + + if (versionNotFound) { + versionNotFirstToken = false; + versionNotFirst = false; + versionNotFound = false; + } + version = defaultVersion; + profile = defaultProfile; + } bool goodVersion = DeduceVersionProfile(compiler->infoSink, compiler->getLanguage(), versionNotFirst, defaultVersion, version, profile); bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst)); bool warnVersionNotFirst = false; @@ -727,7 +748,7 @@ int ShCompile( compiler->infoSink.debug.erase(); TIntermediate intermediate(compiler->getLanguage()); - bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, "", optLevel, resources, defaultVersion, forwardCompatible, messages, intermediate); + bool success = CompileDeferred(compiler, shaderStrings, numStrings, inputLengths, "", optLevel, resources, defaultVersion, ENoProfile, false, forwardCompatible, messages, intermediate); // // Call the machine dependent compiler @@ -1006,7 +1027,7 @@ TShader::~TShader() // // Returns true for success. // -bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages) +bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile, bool forwardCompatible, EShMessages messages) { if (! InitThread()) return false; @@ -1016,7 +1037,12 @@ bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion if (! preamble) preamble = ""; - return CompileDeferred(compiler, strings, numStrings, nullptr, preamble, EShOptNone, builtInResources, defaultVersion, forwardCompatible, messages, *intermediate); + return CompileDeferred(compiler, strings, numStrings, nullptr, preamble, EShOptNone, builtInResources, defaultVersion, defaultProfile, forceDefaultVersionAndProfile, forwardCompatible, messages, *intermediate); +} + +bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion, bool forwardCompatible, EShMessages messages) +{ + return parse(builtInResources, defaultVersion, ENoProfile, false, forwardCompatible, messages); } const char* TShader::getInfoLog() diff --git a/glslang/MachineIndependent/Versions.cpp b/glslang/MachineIndependent/Versions.cpp index 2ffd5c441..e7531cb85 100644 --- a/glslang/MachineIndependent/Versions.cpp +++ b/glslang/MachineIndependent/Versions.cpp @@ -265,20 +265,6 @@ const char* TParseContext::getPreamble() } } -// -// Map from profile enum to externally readable text name. -// -const char* ProfileName(EProfile profile) -{ - switch (profile) { - case ENoProfile: return "none"; - case ECoreProfile: return "core"; - case ECompatibilityProfile: return "compatibility"; - case EEsProfile: return "es"; - default: return "unknown profile"; - } -} - // // When to use requireProfile(): // diff --git a/glslang/MachineIndependent/Versions.h b/glslang/MachineIndependent/Versions.h index 20e00799b..ee673d381 100644 --- a/glslang/MachineIndependent/Versions.h +++ b/glslang/MachineIndependent/Versions.h @@ -57,6 +57,20 @@ typedef enum { namespace glslang { +// +// Map from profile enum to externally readable text name. +// +inline const char* ProfileName(EProfile profile) +{ + switch (profile) { + case ENoProfile: return "none"; + case ECoreProfile: return "core"; + case ECompatibilityProfile: return "compatibility"; + case EEsProfile: return "es"; + default: return "unknown profile"; + } +} + // // The behaviors from the GLSL "#extension extension_name : behavior" // diff --git a/glslang/Public/ShaderLang.h b/glslang/Public/ShaderLang.h index c1829f7eb..e2e7eb21b 100644 --- a/glslang/Public/ShaderLang.h +++ b/glslang/Public/ShaderLang.h @@ -35,6 +35,7 @@ #define _COMPILER_INTERFACE_INCLUDED_ #include "../Include/ResourceLimits.h" +#include "../MachineIndependent/Versions.h" #ifdef _WIN32 #define C_DECL __cdecl @@ -279,6 +280,9 @@ public: virtual ~TShader(); void setStrings(const char* const* s, int n) { strings = s; numStrings = n; } void setPreamble(const char* s) { preamble = s; } + bool parse(const TBuiltInResource*, int defaultVersion, EProfile defaultProfile, bool forceDefaultVersionAndProfile, bool forwardCompatible, EShMessages); + // Equivalent to parse() without a default profile and without forcing defaults. + // Provided for backwards compatibility. bool parse(const TBuiltInResource*, int defaultVersion, bool forwardCompatible, EShMessages); const char* getInfoLog(); -- GitLab