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
This commit is contained in:
parent
99a3c59fae
commit
edadf45605
5 changed files with 48 additions and 18 deletions
|
|
@ -155,7 +155,7 @@ void TInputScanner::consumeWhitespaceComment(bool& foundNonSpaceTab)
|
||||||
// or no #version was found; otherwise, returns false. There is no error case, it always
|
// 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.
|
// 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.
|
// appeared before the #version.
|
||||||
//
|
//
|
||||||
// N.B. does not attempt to leave input in any particular known state. The assumption
|
// N.B. does not attempt to leave input in any particular known state. The assumption
|
||||||
|
|
|
||||||
|
|
@ -453,6 +453,10 @@ bool CompileDeferred(
|
||||||
const EShOptimizationLevel optLevel,
|
const EShOptimizationLevel optLevel,
|
||||||
const TBuiltInResource* resources,
|
const TBuiltInResource* resources,
|
||||||
int defaultVersion, // use 100 for ES environment, 110 for desktop
|
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
|
bool forwardCompatible, // give errors for use of deprecated features
|
||||||
EShMessages messages, // warnings/errors/AST; things to print out
|
EShMessages messages, // warnings/errors/AST; things to print out
|
||||||
TIntermediate& intermediate // returned tree, etc.
|
TIntermediate& intermediate // returned tree, etc.
|
||||||
|
|
@ -497,6 +501,23 @@ bool CompileDeferred(
|
||||||
bool versionNotFirstToken;
|
bool versionNotFirstToken;
|
||||||
bool versionNotFirst = userInput.scanVersion(version, profile, versionNotFirstToken);
|
bool versionNotFirst = userInput.scanVersion(version, profile, versionNotFirstToken);
|
||||||
bool versionNotFound = version == 0;
|
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 goodVersion = DeduceVersionProfile(compiler->infoSink, compiler->getLanguage(), versionNotFirst, defaultVersion, version, profile);
|
||||||
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst));
|
bool versionWillBeError = (versionNotFound || (profile == EEsProfile && version >= 300 && versionNotFirst));
|
||||||
bool warnVersionNotFirst = false;
|
bool warnVersionNotFirst = false;
|
||||||
|
|
@ -727,7 +748,7 @@ int ShCompile(
|
||||||
compiler->infoSink.debug.erase();
|
compiler->infoSink.debug.erase();
|
||||||
|
|
||||||
TIntermediate intermediate(compiler->getLanguage());
|
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
|
// Call the machine dependent compiler
|
||||||
|
|
@ -1006,7 +1027,7 @@ TShader::~TShader()
|
||||||
//
|
//
|
||||||
// Returns true for success.
|
// 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())
|
if (! InitThread())
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -1016,7 +1037,12 @@ bool TShader::parse(const TBuiltInResource* builtInResources, int defaultVersion
|
||||||
if (! preamble)
|
if (! preamble)
|
||||||
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()
|
const char* TShader::getInfoLog()
|
||||||
|
|
|
||||||
|
|
@ -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():
|
// When to use requireProfile():
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,20 @@ typedef enum {
|
||||||
|
|
||||||
namespace glslang {
|
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"
|
// The behaviors from the GLSL "#extension extension_name : behavior"
|
||||||
//
|
//
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
#define _COMPILER_INTERFACE_INCLUDED_
|
#define _COMPILER_INTERFACE_INCLUDED_
|
||||||
|
|
||||||
#include "../Include/ResourceLimits.h"
|
#include "../Include/ResourceLimits.h"
|
||||||
|
#include "../MachineIndependent/Versions.h"
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#define C_DECL __cdecl
|
#define C_DECL __cdecl
|
||||||
|
|
@ -279,6 +280,9 @@ public:
|
||||||
virtual ~TShader();
|
virtual ~TShader();
|
||||||
void setStrings(const char* const* s, int n) { strings = s; numStrings = n; }
|
void setStrings(const char* const* s, int n) { strings = s; numStrings = n; }
|
||||||
void setPreamble(const char* s) { preamble = s; }
|
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);
|
bool parse(const TBuiltInResource*, int defaultVersion, bool forwardCompatible, EShMessages);
|
||||||
|
|
||||||
const char* getInfoLog();
|
const char* getInfoLog();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue