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