Commit 422f2ce2 by Geoff Lang Committed by Commit Bot

GL: Refactor ShaderGL to not hold renderer objects.

BUG=angleproject:2464 Change-Id: I243c010e30d62e233411b1dab1d13a69b44e4b38 Reviewed-on: https://chromium-review.googlesource.com/1054214Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 2cfc4f50
...@@ -52,9 +52,10 @@ CompilerImpl *ContextGL::createCompiler() ...@@ -52,9 +52,10 @@ CompilerImpl *ContextGL::createCompiler()
ShaderImpl *ContextGL::createShader(const gl::ShaderState &data) ShaderImpl *ContextGL::createShader(const gl::ShaderState &data)
{ {
return new ShaderGL(data, getFunctions(), getWorkaroundsGL(), const FunctionsGL *functions = getFunctions();
getExtensions().webglCompatibility, GLuint shader = functions->createShader(ToGLenum(data.getShaderType()));
mRenderer->getMultiviewImplementationType());
return new ShaderGL(data, shader, mRenderer->getMultiviewImplementationType());
} }
ProgramImpl *ContextGL::createProgram(const gl::ProgramState &data) ProgramImpl *ContextGL::createProgram(const gl::ProgramState &data)
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Compiler.h" #include "libANGLE/Compiler.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/gl/FunctionsGL.h" #include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/RendererGL.h" #include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/WorkaroundsGL.h" #include "libANGLE/renderer/gl/WorkaroundsGL.h"
...@@ -20,18 +21,12 @@ namespace rx ...@@ -20,18 +21,12 @@ namespace rx
{ {
ShaderGL::ShaderGL(const gl::ShaderState &data, ShaderGL::ShaderGL(const gl::ShaderState &data,
const FunctionsGL *functions, GLuint shaderID,
const WorkaroundsGL &workarounds,
bool isWebGL,
MultiviewImplementationTypeGL multiviewImplementationType) MultiviewImplementationTypeGL multiviewImplementationType)
: ShaderImpl(data), : ShaderImpl(data),
mFunctions(functions), mShaderID(shaderID),
mWorkarounds(workarounds),
mShaderID(0),
mIsWebGL(isWebGL),
mMultiviewImplementationType(multiviewImplementationType) mMultiviewImplementationType(multiviewImplementationType)
{ {
ASSERT(mFunctions);
} }
ShaderGL::~ShaderGL() ShaderGL::~ShaderGL()
...@@ -41,104 +36,98 @@ ShaderGL::~ShaderGL() ...@@ -41,104 +36,98 @@ ShaderGL::~ShaderGL()
void ShaderGL::destroy(const gl::Context *context) void ShaderGL::destroy(const gl::Context *context)
{ {
if (mShaderID != 0) const FunctionsGL *functions = GetFunctionsGL(context);
{ functions->deleteShader(mShaderID);
mFunctions->deleteShader(mShaderID); mShaderID = 0;
mShaderID = 0;
}
} }
ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(const gl::Context *context, ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream, std::stringstream *sourceStream,
std::string * /*sourcePath*/) std::string * /*sourcePath*/)
{ {
// Reset the previous state
if (mShaderID != 0)
{
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
}
*sourceStream << mData.getSource(); *sourceStream << mData.getSource();
ShCompileOptions options = SH_INIT_GL_POSITION; ShCompileOptions options = SH_INIT_GL_POSITION;
if (mIsWebGL) bool isWebGL = context->getExtensions().webglCompatibility;
if (isWebGL)
{ {
options |= SH_INIT_OUTPUT_VARIABLES; options |= SH_INIT_OUTPUT_VARIABLES;
} }
if (mWorkarounds.doWhileGLSLCausesGPUHang) const WorkaroundsGL &workarounds = GetWorkaroundsGL(context);
if (workarounds.doWhileGLSLCausesGPUHang)
{ {
options |= SH_REWRITE_DO_WHILE_LOOPS; options |= SH_REWRITE_DO_WHILE_LOOPS;
} }
if (mWorkarounds.emulateAbsIntFunction) if (workarounds.emulateAbsIntFunction)
{ {
options |= SH_EMULATE_ABS_INT_FUNCTION; options |= SH_EMULATE_ABS_INT_FUNCTION;
} }
if (mWorkarounds.addAndTrueToLoopCondition) if (workarounds.addAndTrueToLoopCondition)
{ {
options |= SH_ADD_AND_TRUE_TO_LOOP_CONDITION; options |= SH_ADD_AND_TRUE_TO_LOOP_CONDITION;
} }
if (mWorkarounds.emulateIsnanFloat) if (workarounds.emulateIsnanFloat)
{ {
options |= SH_EMULATE_ISNAN_FLOAT_FUNCTION; options |= SH_EMULATE_ISNAN_FLOAT_FUNCTION;
} }
if (mWorkarounds.emulateAtan2Float) if (workarounds.emulateAtan2Float)
{ {
options |= SH_EMULATE_ATAN2_FLOAT_FUNCTION; options |= SH_EMULATE_ATAN2_FLOAT_FUNCTION;
} }
if (mWorkarounds.useUnusedBlocksWithStandardOrSharedLayout) if (workarounds.useUnusedBlocksWithStandardOrSharedLayout)
{ {
options |= SH_USE_UNUSED_STANDARD_SHARED_BLOCKS; options |= SH_USE_UNUSED_STANDARD_SHARED_BLOCKS;
} }
if (mWorkarounds.dontRemoveInvariantForFragmentInput) if (workarounds.dontRemoveInvariantForFragmentInput)
{ {
options |= SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT; options |= SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT;
} }
if (mWorkarounds.removeInvariantAndCentroidForESSL3) if (workarounds.removeInvariantAndCentroidForESSL3)
{ {
options |= SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3; options |= SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3;
} }
if (mWorkarounds.rewriteFloatUnaryMinusOperator) if (workarounds.rewriteFloatUnaryMinusOperator)
{ {
options |= SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR; options |= SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR;
} }
if (!mWorkarounds.dontInitializeUninitializedLocals) if (!workarounds.dontInitializeUninitializedLocals)
{ {
options |= SH_INITIALIZE_UNINITIALIZED_LOCALS; options |= SH_INITIALIZE_UNINITIALIZED_LOCALS;
} }
if (mWorkarounds.clampPointSize) if (workarounds.clampPointSize)
{ {
options |= SH_CLAMP_POINT_SIZE; options |= SH_CLAMP_POINT_SIZE;
} }
if (mWorkarounds.rewriteVectorScalarArithmetic) if (workarounds.rewriteVectorScalarArithmetic)
{ {
options |= SH_REWRITE_VECTOR_SCALAR_ARITHMETIC; options |= SH_REWRITE_VECTOR_SCALAR_ARITHMETIC;
} }
if (mWorkarounds.dontUseLoopsToInitializeVariables) if (workarounds.dontUseLoopsToInitializeVariables)
{ {
options |= SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES; options |= SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES;
} }
if (mWorkarounds.clampFragDepth) if (workarounds.clampFragDepth)
{ {
options |= SH_CLAMP_FRAG_DEPTH; options |= SH_CLAMP_FRAG_DEPTH;
} }
if (mWorkarounds.rewriteRepeatedAssignToSwizzled) if (workarounds.rewriteRepeatedAssignToSwizzled)
{ {
options |= SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED; options |= SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED;
} }
...@@ -159,29 +148,26 @@ bool ShaderGL::postTranslateCompile(const gl::Context *context, ...@@ -159,29 +148,26 @@ bool ShaderGL::postTranslateCompile(const gl::Context *context,
// Translate the ESSL into GLSL // Translate the ESSL into GLSL
const char *translatedSourceCString = mData.getTranslatedSource().c_str(); const char *translatedSourceCString = mData.getTranslatedSource().c_str();
// Generate a shader object and set the source // Set the source
mShaderID = mFunctions->createShader(ToGLenum(mData.getShaderType())); const FunctionsGL *functions = GetFunctionsGL(context);
mFunctions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr); functions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr);
mFunctions->compileShader(mShaderID); functions->compileShader(mShaderID);
// Check for compile errors from the native driver // Check for compile errors from the native driver
GLint compileStatus = GL_FALSE; GLint compileStatus = GL_FALSE;
mFunctions->getShaderiv(mShaderID, GL_COMPILE_STATUS, &compileStatus); functions->getShaderiv(mShaderID, GL_COMPILE_STATUS, &compileStatus);
if (compileStatus == GL_FALSE) if (compileStatus == GL_FALSE)
{ {
// Compilation failed, put the error into the info log // Compilation failed, put the error into the info log
GLint infoLogLength = 0; GLint infoLogLength = 0;
mFunctions->getShaderiv(mShaderID, GL_INFO_LOG_LENGTH, &infoLogLength); functions->getShaderiv(mShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
// Info log length includes the null terminator, so 1 means that the info log is an empty // Info log length includes the null terminator, so 1 means that the info log is an empty
// string. // string.
if (infoLogLength > 1) if (infoLogLength > 1)
{ {
std::vector<char> buf(infoLogLength); std::vector<char> buf(infoLogLength);
mFunctions->getShaderInfoLog(mShaderID, infoLogLength, nullptr, &buf[0]); functions->getShaderInfoLog(mShaderID, infoLogLength, nullptr, &buf[0]);
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
*infoLog = &buf[0]; *infoLog = &buf[0];
WARN() << std::endl << *infoLog; WARN() << std::endl << *infoLog;
......
...@@ -21,9 +21,7 @@ class ShaderGL : public ShaderImpl ...@@ -21,9 +21,7 @@ class ShaderGL : public ShaderImpl
{ {
public: public:
ShaderGL(const gl::ShaderState &data, ShaderGL(const gl::ShaderState &data,
const FunctionsGL *functions, GLuint shaderID,
const WorkaroundsGL &workarounds,
bool isWebGL,
MultiviewImplementationTypeGL multiviewImplementationType); MultiviewImplementationTypeGL multiviewImplementationType);
~ShaderGL() override; ~ShaderGL() override;
...@@ -41,11 +39,7 @@ class ShaderGL : public ShaderImpl ...@@ -41,11 +39,7 @@ class ShaderGL : public ShaderImpl
GLuint getShaderID() const; GLuint getShaderID() const;
private: private:
const FunctionsGL *mFunctions;
const WorkaroundsGL &mWorkarounds;
GLuint mShaderID; GLuint mShaderID;
bool mIsWebGL;
MultiviewImplementationTypeGL mMultiviewImplementationType; MultiviewImplementationTypeGL mMultiviewImplementationType;
}; };
......
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