Accept shader version 300 on ES3 contexts.

TRAC #22712 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2121 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 00b6a0e0
...@@ -37,7 +37,7 @@ extern "C" { ...@@ -37,7 +37,7 @@ extern "C" {
// Version number for shader translation API. // Version number for shader translation API.
// It is incremented everytime the API changes. // It is incremented everytime the API changes.
#define ANGLE_SH_VERSION 110 #define ANGLE_SH_VERSION 111
// //
// The names of the following enums have been derived by replacing GL prefix // The names of the following enums have been derived by replacing GL prefix
...@@ -119,7 +119,8 @@ typedef enum { ...@@ -119,7 +119,8 @@ typedef enum {
SH_NAME_MAX_LENGTH = 0x6001, SH_NAME_MAX_LENGTH = 0x6001,
SH_HASHED_NAME_MAX_LENGTH = 0x6002, SH_HASHED_NAME_MAX_LENGTH = 0x6002,
SH_HASHED_NAMES_COUNT = 0x6003, SH_HASHED_NAMES_COUNT = 0x6003,
SH_ACTIVE_UNIFORMS_ARRAY = 0x6004 SH_ACTIVE_UNIFORMS_ARRAY = 0x6004,
SH_SHADER_VERSION = 0x6005
} ShShaderInfo; } ShShaderInfo;
// Compile options. // Compile options.
...@@ -316,6 +317,7 @@ COMPILER_EXPORT int ShCompile( ...@@ -316,6 +317,7 @@ COMPILER_EXPORT int ShCompile(
// SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the // SH_HASHED_NAME_MAX_LENGTH: the max length of a hashed name including the
// null termination character. // null termination character.
// SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile. // SH_HASHED_NAMES_COUNT: the number of hashed names from the latest compile.
// SH_SHADER_VERSION: the version of the shader language
// //
// params: Requested parameter // params: Requested parameter
COMPILER_EXPORT void ShGetInfo(const ShHandle handle, COMPILER_EXPORT void ShGetInfo(const ShHandle handle,
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -118,6 +118,7 @@ TCompiler::~TCompiler() ...@@ -118,6 +118,7 @@ TCompiler::~TCompiler()
bool TCompiler::Init(const ShBuiltInResources& resources) bool TCompiler::Init(const ShBuiltInResources& resources)
{ {
shaderVersion = 100;
maxUniformVectors = (shaderType == SH_VERTEX_SHADER) ? maxUniformVectors = (shaderType == SH_VERTEX_SHADER) ?
resources.MaxVertexUniformVectors : resources.MaxVertexUniformVectors :
resources.MaxFragmentUniformVectors; resources.MaxFragmentUniformVectors;
...@@ -177,6 +178,9 @@ bool TCompiler::compile(const char* const shaderStrings[], ...@@ -177,6 +178,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);
......
// //
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "compiler/preprocessor/SourceLocation.h" #include "compiler/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,
......
// //
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -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;
......
// //
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -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;
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -66,6 +66,7 @@ struct TParseContext { ...@@ -66,6 +66,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,
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -67,6 +67,7 @@ public: ...@@ -67,6 +67,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; }
const TVariableInfoList& getAttribs() const { return attribs; } const TVariableInfoList& getAttribs() const { return attribs; }
const TVariableInfoList& getUniforms() const { return uniforms; } const TVariableInfoList& getUniforms() const { return uniforms; }
...@@ -135,6 +136,7 @@ private: ...@@ -135,6 +136,7 @@ private:
BuiltInFunctionEmulator builtInFunctionEmulator; BuiltInFunctionEmulator builtInFunctionEmulator;
// Results of compilation. // Results of compilation.
int shaderVersion;
TInfoSink infoSink; // Output sink. TInfoSink infoSink; // Output sink.
TVariableInfoList attribs; // Active attributes in the compiled shader. TVariableInfoList attribs; // Active attributes in the compiled shader.
TVariableInfoList uniforms; // Active uniforms in the compiled shader. TVariableInfoList uniforms; // Active uniforms in the compiled shader.
......
// //
// Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -250,6 +250,9 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params) ...@@ -250,6 +250,9 @@ void ShGetInfo(const ShHandle handle, ShShaderInfo pname, size_t* params)
case SH_HASHED_NAMES_COUNT: case SH_HASHED_NAMES_COUNT:
*params = compiler->getNameMap().size(); *params = compiler->getNameMap().size();
break; break;
case SH_SHADER_VERSION:
*params = compiler->getShaderVersion();
break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
} }
......
// //
// Copyright (c) 2011 The ANGLE Project Authors. All rights reserved. // Copyright (c) 2011-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
...@@ -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)
......
...@@ -376,7 +376,18 @@ void Shader::compileToHLSL(void *compiler) ...@@ -376,7 +376,18 @@ void Shader::compileToHLSL(void *compiler)
result = ShCompile(compiler, sourceStrings, 2, compileOptions | SH_SOURCE_PATH); result = ShCompile(compiler, sourceStrings, 2, compileOptions | SH_SOURCE_PATH);
} }
if (result) size_t shaderVersion = 100;
ShGetInfo(compiler, SH_SHADER_VERSION, &shaderVersion);
if (shaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3)
{
const char versionError[] = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts";
mInfoLog = new char[sizeof(versionError) + 1];
strcpy(mInfoLog, versionError);
TRACE("\n%s", mInfoLog);
}
else if (result)
{ {
size_t objCodeLen = 0; size_t objCodeLen = 0;
ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen); ShGetInfo(compiler, SH_OBJECT_CODE_LENGTH, &objCodeLen);
......
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