Commit 58662082 by Geoff Lang Committed by Commit Bot

Pass a gl::Context to ShaderImpl methods.

Also add a destroy method. BUG=angleproject:2464 Change-Id: I7346b799af4e7d64ed5cc3d5eca8e108ce2cf699 Reviewed-on: https://chromium-review.googlesource.com/1054213Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Geoff Lang <geofflang@chromium.org>
parent 2cb7f974
...@@ -130,6 +130,7 @@ Shader::Shader(ShaderProgramManager *manager, ...@@ -130,6 +130,7 @@ Shader::Shader(ShaderProgramManager *manager,
void Shader::onDestroy(const gl::Context *context) void Shader::onDestroy(const gl::Context *context)
{ {
mImplementation->destroy(context);
mBoundCompiler.set(context, nullptr); mBoundCompiler.set(context, nullptr);
mImplementation.reset(nullptr); mImplementation.reset(nullptr);
delete this; delete this;
...@@ -226,7 +227,7 @@ int Shader::getTranslatedSourceWithDebugInfoLength(const Context *context) ...@@ -226,7 +227,7 @@ int Shader::getTranslatedSourceWithDebugInfoLength(const Context *context)
{ {
resolveCompile(context); resolveCompile(context);
const std::string &debugInfo = mImplementation->getDebugInfo(); const std::string &debugInfo = mImplementation->getDebugInfo(context);
if (debugInfo.empty()) if (debugInfo.empty())
{ {
return 0; return 0;
...@@ -282,7 +283,7 @@ void Shader::getTranslatedSourceWithDebugInfo(const Context *context, ...@@ -282,7 +283,7 @@ void Shader::getTranslatedSourceWithDebugInfo(const Context *context,
char *buffer) char *buffer)
{ {
resolveCompile(context); resolveCompile(context);
const std::string &debugInfo = mImplementation->getDebugInfo(); const std::string &debugInfo = mImplementation->getDebugInfo(context);
GetSourceImpl(debugInfo, bufSize, length, buffer); GetSourceImpl(debugInfo, bufSize, length, buffer);
} }
...@@ -312,8 +313,8 @@ void Shader::compile(const Context *context) ...@@ -312,8 +313,8 @@ void Shader::compile(const Context *context)
std::stringstream sourceStream; std::stringstream sourceStream;
mLastCompileOptions = mLastCompileOptions = mImplementation->prepareSourceAndReturnOptions(context, &sourceStream,
mImplementation->prepareSourceAndReturnOptions(&sourceStream, &mLastCompiledSourcePath); &mLastCompiledSourcePath);
mLastCompileOptions |= (SH_OBJECT_CODE | SH_VARIABLES); mLastCompileOptions |= (SH_OBJECT_CODE | SH_VARIABLES);
mLastCompiledSource = sourceStream.str(); mLastCompiledSource = sourceStream.str();
...@@ -447,7 +448,7 @@ void Shader::resolveCompile(const Context *context) ...@@ -447,7 +448,7 @@ void Shader::resolveCompile(const Context *context)
ASSERT(!mState.mTranslatedSource.empty()); ASSERT(!mState.mTranslatedSource.empty());
bool success = mImplementation->postTranslateCompile(mBoundCompiler.get(), &mInfoLog); bool success = mImplementation->postTranslateCompile(context, mBoundCompiler.get(), &mInfoLog);
mState.mCompileStatus = success ? CompileStatus::COMPILED : CompileStatus::NOT_COMPILED; mState.mCompileStatus = success ? CompileStatus::COMPILED : CompileStatus::NOT_COMPILED;
} }
......
...@@ -21,13 +21,18 @@ class ShaderImpl : angle::NonCopyable ...@@ -21,13 +21,18 @@ class ShaderImpl : angle::NonCopyable
ShaderImpl(const gl::ShaderState &data) : mData(data) {} ShaderImpl(const gl::ShaderState &data) : mData(data) {}
virtual ~ShaderImpl() { } virtual ~ShaderImpl() { }
virtual void destroy(const gl::Context *context) {}
// Returns additional sh::Compile options. // Returns additional sh::Compile options.
virtual ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream, virtual ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) = 0; std::string *sourcePath) = 0;
// Returns success for compiling on the driver. Returns success. // Returns success for compiling on the driver. Returns success.
virtual bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) = 0; virtual bool postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog) = 0;
virtual std::string getDebugInfo() const = 0; virtual std::string getDebugInfo(const gl::Context *context) const = 0;
const gl::ShaderState &getData() const { return mData; } const gl::ShaderState &getData() const { return mData; }
......
...@@ -62,7 +62,7 @@ ShaderD3D::~ShaderD3D() ...@@ -62,7 +62,7 @@ ShaderD3D::~ShaderD3D()
{ {
} }
std::string ShaderD3D::getDebugInfo() const std::string ShaderD3D::getDebugInfo(const gl::Context *context) const
{ {
if (mDebugInfo.empty()) if (mDebugInfo.empty())
{ {
...@@ -137,7 +137,8 @@ ShShaderOutput ShaderD3D::getCompilerOutputType() const ...@@ -137,7 +137,8 @@ ShShaderOutput ShaderD3D::getCompilerOutputType() const
return mCompilerOutputType; return mCompilerOutputType;
} }
ShCompileOptions ShaderD3D::prepareSourceAndReturnOptions(std::stringstream *shaderSourceStream, ShCompileOptions ShaderD3D::prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *shaderSourceStream,
std::string *sourcePath) std::string *sourcePath)
{ {
uncompile(); uncompile();
...@@ -173,7 +174,9 @@ const std::map<std::string, unsigned int> &GetUniformRegisterMap( ...@@ -173,7 +174,9 @@ const std::map<std::string, unsigned int> &GetUniformRegisterMap(
return *uniformRegisterMap; return *uniformRegisterMap;
} }
bool ShaderD3D::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) bool ShaderD3D::postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog)
{ {
// TODO(jmadill): We shouldn't need to cache this. // TODO(jmadill): We shouldn't need to cache this.
mCompilerOutputType = compiler->getShaderOutputType(); mCompilerOutputType = compiler->getShaderOutputType();
......
...@@ -39,10 +39,13 @@ class ShaderD3D : public ShaderImpl ...@@ -39,10 +39,13 @@ class ShaderD3D : public ShaderImpl
~ShaderD3D() override; ~ShaderD3D() override;
// ShaderImpl implementation // ShaderImpl implementation
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream, ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override; std::string *sourcePath) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override; bool postTranslateCompile(const gl::Context *context,
std::string getDebugInfo() const override; gl::Compiler *compiler,
std::string *infoLog) override;
std::string getDebugInfo(const gl::Context *context) const override;
// D3D-specific methods // D3D-specific methods
void uncompile(); void uncompile();
......
...@@ -36,6 +36,11 @@ ShaderGL::ShaderGL(const gl::ShaderState &data, ...@@ -36,6 +36,11 @@ ShaderGL::ShaderGL(const gl::ShaderState &data,
ShaderGL::~ShaderGL() ShaderGL::~ShaderGL()
{ {
ASSERT(mShaderID == 0);
}
void ShaderGL::destroy(const gl::Context *context)
{
if (mShaderID != 0) if (mShaderID != 0)
{ {
mFunctions->deleteShader(mShaderID); mFunctions->deleteShader(mShaderID);
...@@ -43,7 +48,8 @@ ShaderGL::~ShaderGL() ...@@ -43,7 +48,8 @@ ShaderGL::~ShaderGL()
} }
} }
ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(std::stringstream *sourceStream, ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string * /*sourcePath*/) std::string * /*sourcePath*/)
{ {
// Reset the previous state // Reset the previous state
...@@ -146,7 +152,9 @@ ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(std::stringstream *sour ...@@ -146,7 +152,9 @@ ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(std::stringstream *sour
return options; return options;
} }
bool ShaderGL::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) bool ShaderGL::postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog)
{ {
// Translate the ESSL into GLSL // Translate the ESSL into GLSL
const char *translatedSourceCString = mData.getTranslatedSource().c_str(); const char *translatedSourceCString = mData.getTranslatedSource().c_str();
...@@ -188,7 +196,7 @@ bool ShaderGL::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog ...@@ -188,7 +196,7 @@ bool ShaderGL::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog
return true; return true;
} }
std::string ShaderGL::getDebugInfo() const std::string ShaderGL::getDebugInfo(const gl::Context *context) const
{ {
return mData.getTranslatedSource(); return mData.getTranslatedSource();
} }
......
...@@ -27,11 +27,16 @@ class ShaderGL : public ShaderImpl ...@@ -27,11 +27,16 @@ class ShaderGL : public ShaderImpl
MultiviewImplementationTypeGL multiviewImplementationType); MultiviewImplementationTypeGL multiviewImplementationType);
~ShaderGL() override; ~ShaderGL() override;
void destroy(const gl::Context *context) override;
// ShaderImpl implementation // ShaderImpl implementation
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream, ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override; std::string *sourcePath) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override; bool postTranslateCompile(const gl::Context *context,
std::string getDebugInfo() const override; gl::Compiler *compiler,
std::string *infoLog) override;
std::string getDebugInfo(const gl::Context *context) const override;
GLuint getShaderID() const; GLuint getShaderID() const;
......
...@@ -22,19 +22,22 @@ ShaderNULL::~ShaderNULL() ...@@ -22,19 +22,22 @@ ShaderNULL::~ShaderNULL()
{ {
} }
ShCompileOptions ShaderNULL::prepareSourceAndReturnOptions(std::stringstream *sourceStream, ShCompileOptions ShaderNULL::prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) std::string *sourcePath)
{ {
*sourceStream << mData.getSource(); *sourceStream << mData.getSource();
return 0; return 0;
} }
bool ShaderNULL::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) bool ShaderNULL::postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog)
{ {
return true; return true;
} }
std::string ShaderNULL::getDebugInfo() const std::string ShaderNULL::getDebugInfo(const gl::Context *context) const
{ {
return ""; return "";
} }
......
...@@ -22,12 +22,15 @@ class ShaderNULL : public ShaderImpl ...@@ -22,12 +22,15 @@ class ShaderNULL : public ShaderImpl
~ShaderNULL() override; ~ShaderNULL() override;
// Returns additional sh::Compile options. // Returns additional sh::Compile options.
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream, ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override; std::string *sourcePath) override;
// Returns success for compiling on the driver. Returns success. // Returns success for compiling on the driver. Returns success.
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override; bool postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog) override;
std::string getDebugInfo() const override; std::string getDebugInfo(const gl::Context *context) const override;
}; };
} // namespace rx } // namespace rx
......
...@@ -22,20 +22,23 @@ ShaderVk::~ShaderVk() ...@@ -22,20 +22,23 @@ ShaderVk::~ShaderVk()
{ {
} }
ShCompileOptions ShaderVk::prepareSourceAndReturnOptions(std::stringstream *sourceStream, ShCompileOptions ShaderVk::prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) std::string *sourcePath)
{ {
*sourceStream << mData.getSource(); *sourceStream << mData.getSource();
return SH_INITIALIZE_UNINITIALIZED_LOCALS; return SH_INITIALIZE_UNINITIALIZED_LOCALS;
} }
bool ShaderVk::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) bool ShaderVk::postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog)
{ {
// No work to do here. // No work to do here.
return true; return true;
} }
std::string ShaderVk::getDebugInfo() const std::string ShaderVk::getDebugInfo(const gl::Context *context) const
{ {
return std::string(); return std::string();
} }
......
...@@ -22,12 +22,15 @@ class ShaderVk : public ShaderImpl ...@@ -22,12 +22,15 @@ class ShaderVk : public ShaderImpl
~ShaderVk() override; ~ShaderVk() override;
// Returns additional sh::Compile options. // Returns additional sh::Compile options.
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream, ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override; std::string *sourcePath) override;
// Returns success for compiling on the driver. Returns success. // Returns success for compiling on the driver. Returns success.
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override; bool postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog) override;
std::string getDebugInfo() const override; std::string getDebugInfo(const gl::Context *context) const override;
}; };
} // namespace rx } // namespace rx
......
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