Skip to content
Snippets Groups Projects
Commit edadf456 authored by John Kessenich's avatar John Kessenich
Browse files

glslang: Add API override of version and profile for testing purposes. From...

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
parent 99a3c59f
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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()
......
......@@ -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():
//
......
......@@ -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"
//
......
......@@ -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();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment