Commit b28964b6 by Nicolas Capens

Parse the shader version number.

Bug 19331817 Change-Id: I53f24cec92052eb7367219c299222b02301f3a19 Reviewed-on: https://swiftshader-review.googlesource.com/2288Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent b97ad2e8
...@@ -73,6 +73,7 @@ TCompiler::~TCompiler() ...@@ -73,6 +73,7 @@ TCompiler::~TCompiler()
bool TCompiler::Init(const ShBuiltInResources& resources) bool TCompiler::Init(const ShBuiltInResources& resources)
{ {
shaderVersion = 100;
maxCallStackDepth = resources.MaxCallStackDepth; maxCallStackDepth = resources.MaxCallStackDepth;
TScopedPoolAllocator scopedAlloc(&allocator, false); TScopedPoolAllocator scopedAlloc(&allocator, false);
...@@ -123,6 +124,9 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -123,6 +124,9 @@ bool TCompiler::compile(const char* const shaderStrings[],
bool success = bool success =
(PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) && (PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) &&
(parseContext.treeRoot != NULL); (parseContext.treeRoot != NULL);
shaderVersion = parseContext.shaderVersion();
if (success) { if (success) {
TIntermNode* root = parseContext.treeRoot; TIntermNode* root = parseContext.treeRoot;
success = intermediate.postProcess(root); success = intermediate.postProcess(root);
...@@ -257,4 +261,4 @@ void FreeCompilerGlobals() ...@@ -257,4 +261,4 @@ void FreeCompilerGlobals()
{ {
FreeParseContextIndex(); FreeParseContextIndex();
FreePoolIndex(); FreePoolIndex();
} }
\ No newline at end of file
...@@ -92,6 +92,7 @@ public: ...@@ -92,6 +92,7 @@ public:
int compileOptions); int compileOptions);
// Get results of the last compilation. // Get results of the last compilation.
int getShaderVersion() const { return shaderVersion; }
TInfoSink& getInfoSink() { return infoSink; } TInfoSink& getInfoSink() { return infoSink; }
protected: protected:
...@@ -124,6 +125,7 @@ private: ...@@ -124,6 +125,7 @@ private:
TExtensionBehavior extensionBehavior; TExtensionBehavior extensionBehavior;
// Results of compilation. // Results of compilation.
int shaderVersion;
TInfoSink infoSink; // Output sink. TInfoSink infoSink; // Output sink.
// Memory allocator. Allocates and tracks memory required by the compiler. // Memory allocator. Allocates and tracks memory required by the compiler.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "preprocessor/SourceLocation.h" #include "preprocessor/SourceLocation.h"
TDiagnostics::TDiagnostics(TInfoSink& infoSink) : TDiagnostics::TDiagnostics(TInfoSink& infoSink) :
mShaderVersion(100),
mInfoSink(infoSink), mInfoSink(infoSink),
mNumErrors(0), mNumErrors(0),
mNumWarnings(0) mNumWarnings(0)
...@@ -21,6 +22,11 @@ TDiagnostics::~TDiagnostics() ...@@ -21,6 +22,11 @@ TDiagnostics::~TDiagnostics()
{ {
} }
void TDiagnostics::setShaderVersion(int version)
{
mShaderVersion = version;
}
void TDiagnostics::writeInfo(Severity severity, void TDiagnostics::writeInfo(Severity severity,
const pp::SourceLocation& loc, const pp::SourceLocation& loc,
const std::string& reason, const std::string& reason,
......
...@@ -17,11 +17,14 @@ class TDiagnostics : public pp::Diagnostics ...@@ -17,11 +17,14 @@ class TDiagnostics : public pp::Diagnostics
TDiagnostics(TInfoSink& infoSink); TDiagnostics(TInfoSink& infoSink);
virtual ~TDiagnostics(); virtual ~TDiagnostics();
int shaderVersion() const { return mShaderVersion; }
TInfoSink& infoSink() { return mInfoSink; } TInfoSink& infoSink() { return mInfoSink; }
int numErrors() const { return mNumErrors; } int numErrors() const { return mNumErrors; }
int numWarnings() const { return mNumWarnings; } int numWarnings() const { return mNumWarnings; }
void setShaderVersion(int version);
void writeInfo(Severity severity, void writeInfo(Severity severity,
const pp::SourceLocation& loc, const pp::SourceLocation& loc,
const std::string& reason, const std::string& reason,
...@@ -36,6 +39,8 @@ class TDiagnostics : public pp::Diagnostics ...@@ -36,6 +39,8 @@ class TDiagnostics : public pp::Diagnostics
const std::string& text); const std::string& text);
private: private:
int mShaderVersion;
TInfoSink& mInfoSink; TInfoSink& mInfoSink;
int mNumErrors; int mNumErrors;
int mNumWarnings; int mNumWarnings;
......
...@@ -148,9 +148,12 @@ void TDirectiveHandler::handleExtension(const pp::SourceLocation& loc, ...@@ -148,9 +148,12 @@ void TDirectiveHandler::handleExtension(const pp::SourceLocation& loc,
void TDirectiveHandler::handleVersion(const pp::SourceLocation& loc, void TDirectiveHandler::handleVersion(const pp::SourceLocation& loc,
int version) int version)
{ {
static const int kVersion = 100; if (version == 100 ||
version == 300)
if (version != kVersion) {
mDiagnostics.setShaderVersion(version);
}
else
{ {
std::stringstream stream; std::stringstream stream;
stream << version; stream << version;
......
...@@ -65,6 +65,7 @@ struct TParseContext { ...@@ -65,6 +65,7 @@ struct TParseContext {
pp::Preprocessor preprocessor; pp::Preprocessor preprocessor;
void* scanner; void* scanner;
int shaderVersion() const { return diagnostics.shaderVersion(); }
int numErrors() const { return diagnostics.numErrors(); } int numErrors() const { return diagnostics.numErrors(); }
TInfoSink& infoSink() { return diagnostics.infoSink(); } TInfoSink& infoSink() { return diagnostics.infoSink(); }
void error(TSourceLoc loc, const char *reason, const char* token, void error(TSourceLoc loc, const char *reason, const char* token,
......
...@@ -708,7 +708,9 @@ void DirectiveParser::parseVersion(Token* token) ...@@ -708,7 +708,9 @@ void DirectiveParser::parseVersion(Token* token)
enum State enum State
{ {
VERSION_NUMBER VERSION_NUMBER,
VERSION_PROFILE,
VERSION_ENDLINE
}; };
bool valid = true; bool valid = true;
...@@ -716,12 +718,12 @@ void DirectiveParser::parseVersion(Token* token) ...@@ -716,12 +718,12 @@ void DirectiveParser::parseVersion(Token* token)
int state = VERSION_NUMBER; int state = VERSION_NUMBER;
mTokenizer->lex(token); mTokenizer->lex(token);
while ((token->type != '\n') && (token->type != Token::LAST)) while (valid && (token->type != '\n') && (token->type != Token::LAST))
{ {
switch (state++) switch (state)
{ {
case VERSION_NUMBER: case VERSION_NUMBER:
if (valid && (token->type != Token::CONST_INT)) if (token->type != Token::CONST_INT)
{ {
mDiagnostics->report(Diagnostics::INVALID_VERSION_NUMBER, mDiagnostics->report(Diagnostics::INVALID_VERSION_NUMBER,
token->location, token->text); token->location, token->text);
...@@ -733,26 +735,41 @@ void DirectiveParser::parseVersion(Token* token) ...@@ -733,26 +735,41 @@ void DirectiveParser::parseVersion(Token* token)
token->location, token->text); token->location, token->text);
valid = false; valid = false;
} }
break;
default:
if (valid) if (valid)
{ {
mDiagnostics->report(Diagnostics::UNEXPECTED_TOKEN, state = (version < 300) ? VERSION_ENDLINE : VERSION_PROFILE;
}
break;
case VERSION_PROFILE:
if (token->type != Token::IDENTIFIER || token->text != "es")
{
mDiagnostics->report(Diagnostics::INVALID_VERSION_DIRECTIVE,
token->location, token->text); token->location, token->text);
valid = false; valid = false;
} }
state = VERSION_ENDLINE;
break;
default:
mDiagnostics->report(Diagnostics::UNEXPECTED_TOKEN,
token->location, token->text);
valid = false;
break; break;
} }
mTokenizer->lex(token); mTokenizer->lex(token);
} }
if (valid && (state != VERSION_NUMBER + 1))
if (valid && (state != VERSION_ENDLINE))
{ {
mDiagnostics->report(Diagnostics::INVALID_VERSION_DIRECTIVE, mDiagnostics->report(Diagnostics::INVALID_VERSION_DIRECTIVE,
token->location, token->text); token->location, token->text);
valid = false; valid = false;
} }
if (valid) if (valid)
{
mDirectiveHandler->handleVersion(token->location, version); mDirectiveHandler->handleVersion(token->location, version);
}
} }
void DirectiveParser::parseLine(Token* token) void DirectiveParser::parseLine(Token* token)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment