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 @@
#include "libANGLE/renderer/GLImplFactory.h"
#include "libANGLE/renderer/ShaderImpl.h"
#include "libANGLE/ResourceManager.h"
#include "libANGLE/Context.h"
namespace gl
{
......@@ -227,7 +228,7 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length,
getSourceImpl(debugInfo, bufSize, length, buffer);
}
void Shader::compile(Compiler *compiler)
void Shader::compile(const Context *context)
{
mState.mTranslatedSource.clear();
mInfoLog.clear();
......@@ -238,6 +239,7 @@ void Shader::compile(Compiler *compiler)
mState.mActiveAttributes.clear();
mState.mActiveOutputVariables.clear();
Compiler *compiler = context->getCompiler();
ShHandle compilerHandle = compiler->getCompilerHandle(mState.mShaderType);
std::stringstream sourceStream;
......@@ -247,6 +249,14 @@ void Shader::compile(Compiler *compiler)
mImplementation->prepareSourceAndReturnOptions(&sourceStream, &sourcePath);
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
// in fragment shaders. Shader compilation will fail. To provide a better error message we can
// instruct the compiler to pre-validate.
......
......@@ -36,6 +36,7 @@ class Compiler;
class ContextState;
struct Limitations;
class ResourceManager;
class Context;
class ShaderState final : angle::NonCopyable
{
......@@ -110,7 +111,7 @@ class Shader final : angle::NonCopyable, public LabeledObject
void getTranslatedSource(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; }
void addRef();
......
......@@ -485,7 +485,7 @@ void GL_APIENTRY CompileShader(GLuint shader)
{
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