Commit 619c833b by Bryan Bernhart Committed by Commit Bot

Add default compiler options to WebGL shaders.

Enforces default compiler options when compiling WebGL compatible shaders. BUG=angleproject:1616 Change-Id: I18490db68b29981fab4817bdd61727752cf50997 Reviewed-on: https://chromium-review.googlesource.com/409016 Commit-Queue: Bryan Bernhart <bryan.bernhart@intel.com> Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7bb45988
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "libANGLE/renderer/GLImplFactory.h" #include "libANGLE/renderer/GLImplFactory.h"
#include "libANGLE/renderer/ShaderImpl.h" #include "libANGLE/renderer/ShaderImpl.h"
#include "libANGLE/ResourceManager.h" #include "libANGLE/ResourceManager.h"
#include "libANGLE/Context.h"
namespace gl namespace gl
{ {
...@@ -227,7 +228,7 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, ...@@ -227,7 +228,7 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length,
getSourceImpl(debugInfo, bufSize, length, buffer); getSourceImpl(debugInfo, bufSize, length, buffer);
} }
void Shader::compile(Compiler *compiler) void Shader::compile(const Context *context)
{ {
mState.mTranslatedSource.clear(); mState.mTranslatedSource.clear();
mInfoLog.clear(); mInfoLog.clear();
...@@ -238,6 +239,7 @@ void Shader::compile(Compiler *compiler) ...@@ -238,6 +239,7 @@ void Shader::compile(Compiler *compiler)
mState.mActiveAttributes.clear(); mState.mActiveAttributes.clear();
mState.mActiveOutputVariables.clear(); mState.mActiveOutputVariables.clear();
Compiler *compiler = context->getCompiler();
ShHandle compilerHandle = compiler->getCompilerHandle(mState.mShaderType); ShHandle compilerHandle = compiler->getCompilerHandle(mState.mShaderType);
std::stringstream sourceStream; std::stringstream sourceStream;
...@@ -247,6 +249,14 @@ void Shader::compile(Compiler *compiler) ...@@ -247,6 +249,14 @@ void Shader::compile(Compiler *compiler)
mImplementation->prepareSourceAndReturnOptions(&sourceStream, &sourcePath); mImplementation->prepareSourceAndReturnOptions(&sourceStream, &sourcePath);
ShCompileOptions compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | additionalOptions); ShCompileOptions compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | additionalOptions);
// Add default options to WebGL shaders to prevent unexpected behavior during compilation.
if (context->getExtensions().webglCompatibility)
{
compileOptions |= SH_LIMIT_CALL_STACK_DEPTH;
compileOptions |= SH_LIMIT_EXPRESSION_COMPLEXITY;
compileOptions |= SH_ENFORCE_PACKING_RESTRICTIONS;
}
// Some targets (eg D3D11 Feature Level 9_3 and below) do not support non-constant loop indexes // Some targets (eg D3D11 Feature Level 9_3 and below) do not support non-constant loop indexes
// in fragment shaders. Shader compilation will fail. To provide a better error message we can // in fragment shaders. Shader compilation will fail. To provide a better error message we can
// instruct the compiler to pre-validate. // instruct the compiler to pre-validate.
......
...@@ -36,6 +36,7 @@ class Compiler; ...@@ -36,6 +36,7 @@ class Compiler;
class ContextState; class ContextState;
struct Limitations; struct Limitations;
class ResourceManager; class ResourceManager;
class Context;
class ShaderState final : angle::NonCopyable class ShaderState final : angle::NonCopyable
{ {
...@@ -110,7 +111,7 @@ class Shader final : angle::NonCopyable, public LabeledObject ...@@ -110,7 +111,7 @@ class Shader final : angle::NonCopyable, public LabeledObject
void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const; void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const;
void getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const; void getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const;
void compile(Compiler *compiler); void compile(const Context *context);
bool isCompiled() const { return mCompiled; } bool isCompiled() const { return mCompiled; }
void addRef(); void addRef();
......
...@@ -485,7 +485,7 @@ void GL_APIENTRY CompileShader(GLuint shader) ...@@ -485,7 +485,7 @@ void GL_APIENTRY CompileShader(GLuint shader)
{ {
return; return;
} }
shaderObject->compile(context->getCompiler()); shaderObject->compile(context);
} }
} }
......
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