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,
void Shader::onDestroy(const gl::Context *context)
{
mImplementation->destroy(context);
mBoundCompiler.set(context, nullptr);
mImplementation.reset(nullptr);
delete this;
......@@ -226,7 +227,7 @@ int Shader::getTranslatedSourceWithDebugInfoLength(const Context *context)
{
resolveCompile(context);
const std::string &debugInfo = mImplementation->getDebugInfo();
const std::string &debugInfo = mImplementation->getDebugInfo(context);
if (debugInfo.empty())
{
return 0;
......@@ -282,7 +283,7 @@ void Shader::getTranslatedSourceWithDebugInfo(const Context *context,
char *buffer)
{
resolveCompile(context);
const std::string &debugInfo = mImplementation->getDebugInfo();
const std::string &debugInfo = mImplementation->getDebugInfo(context);
GetSourceImpl(debugInfo, bufSize, length, buffer);
}
......@@ -312,8 +313,8 @@ void Shader::compile(const Context *context)
std::stringstream sourceStream;
mLastCompileOptions =
mImplementation->prepareSourceAndReturnOptions(&sourceStream, &mLastCompiledSourcePath);
mLastCompileOptions = mImplementation->prepareSourceAndReturnOptions(context, &sourceStream,
&mLastCompiledSourcePath);
mLastCompileOptions |= (SH_OBJECT_CODE | SH_VARIABLES);
mLastCompiledSource = sourceStream.str();
......@@ -447,7 +448,7 @@ void Shader::resolveCompile(const Context *context)
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;
}
......
......@@ -21,13 +21,18 @@ class ShaderImpl : angle::NonCopyable
ShaderImpl(const gl::ShaderState &data) : mData(data) {}
virtual ~ShaderImpl() { }
virtual void destroy(const gl::Context *context) {}
// 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;
// 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; }
......
......@@ -62,7 +62,7 @@ ShaderD3D::~ShaderD3D()
{
}
std::string ShaderD3D::getDebugInfo() const
std::string ShaderD3D::getDebugInfo(const gl::Context *context) const
{
if (mDebugInfo.empty())
{
......@@ -137,7 +137,8 @@ ShShaderOutput ShaderD3D::getCompilerOutputType() const
return mCompilerOutputType;
}
ShCompileOptions ShaderD3D::prepareSourceAndReturnOptions(std::stringstream *shaderSourceStream,
ShCompileOptions ShaderD3D::prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *shaderSourceStream,
std::string *sourcePath)
{
uncompile();
......@@ -173,7 +174,9 @@ const std::map<std::string, unsigned int> &GetUniformRegisterMap(
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.
mCompilerOutputType = compiler->getShaderOutputType();
......
......@@ -39,10 +39,13 @@ class ShaderD3D : public ShaderImpl
~ShaderD3D() override;
// ShaderImpl implementation
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream,
ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override;
std::string getDebugInfo() const override;
bool postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog) override;
std::string getDebugInfo(const gl::Context *context) const override;
// D3D-specific methods
void uncompile();
......
......@@ -36,6 +36,11 @@ ShaderGL::ShaderGL(const gl::ShaderState &data,
ShaderGL::~ShaderGL()
{
ASSERT(mShaderID == 0);
}
void ShaderGL::destroy(const gl::Context *context)
{
if (mShaderID != 0)
{
mFunctions->deleteShader(mShaderID);
......@@ -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*/)
{
// Reset the previous state
......@@ -146,7 +152,9 @@ ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(std::stringstream *sour
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
const char *translatedSourceCString = mData.getTranslatedSource().c_str();
......@@ -188,7 +196,7 @@ bool ShaderGL::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog
return true;
}
std::string ShaderGL::getDebugInfo() const
std::string ShaderGL::getDebugInfo(const gl::Context *context) const
{
return mData.getTranslatedSource();
}
......
......@@ -27,11 +27,16 @@ class ShaderGL : public ShaderImpl
MultiviewImplementationTypeGL multiviewImplementationType);
~ShaderGL() override;
void destroy(const gl::Context *context) override;
// ShaderImpl implementation
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream,
ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override;
std::string getDebugInfo() const override;
bool postTranslateCompile(const gl::Context *context,
gl::Compiler *compiler,
std::string *infoLog) override;
std::string getDebugInfo(const gl::Context *context) const override;
GLuint getShaderID() const;
......
......@@ -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)
{
*sourceStream << mData.getSource();
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;
}
std::string ShaderNULL::getDebugInfo() const
std::string ShaderNULL::getDebugInfo(const gl::Context *context) const
{
return "";
}
......
......@@ -22,12 +22,15 @@ class ShaderNULL : public ShaderImpl
~ShaderNULL() override;
// Returns additional sh::Compile options.
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream,
ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override;
// 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
......
......@@ -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)
{
*sourceStream << mData.getSource();
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.
return true;
}
std::string ShaderVk::getDebugInfo() const
std::string ShaderVk::getDebugInfo(const gl::Context *context) const
{
return std::string();
}
......
......@@ -22,12 +22,15 @@ class ShaderVk : public ShaderImpl
~ShaderVk() override;
// Returns additional sh::Compile options.
ShCompileOptions prepareSourceAndReturnOptions(std::stringstream *sourceStream,
ShCompileOptions prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string *sourcePath) override;
// 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
......
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