Commit 91445bce by Jamie Madill

Make a shader Shader::Data state structure.

This design follows the similar designs for Program, Framebuffer, etc. Because of the current design, share a mutable pointer with the Impl so the patch becomes a bit smaller and easier to review. In a follow- up patch we can move the shared code into the GL layer. BUG=angleproject:1159 Change-Id: Ib243e74779f23be51cdca80f1b5c6e5f3e36059d Reviewed-on: https://chromium-review.googlesource.com/299876Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 046e53e3
...@@ -94,7 +94,7 @@ GLuint ResourceManager::createShader(const gl::Data &data, GLenum type) ...@@ -94,7 +94,7 @@ GLuint ResourceManager::createShader(const gl::Data &data, GLenum type)
if (type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER) if (type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER)
{ {
mShaderMap[handle] = new Shader(this, mFactory->createShader(type), type, handle); mShaderMap[handle] = new Shader(this, mFactory, type, handle);
} }
else UNREACHABLE(); else UNREACHABLE();
......
...@@ -9,22 +9,30 @@ ...@@ -9,22 +9,30 @@
// functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section 3.8 page 84. // functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section 3.8 page 84.
#include "libANGLE/Shader.h" #include "libANGLE/Shader.h"
#include <sstream>
#include "common/utilities.h"
#include "GLSLANG/ShaderLang.h"
#include "libANGLE/Constants.h"
#include "libANGLE/renderer/Renderer.h" #include "libANGLE/renderer/Renderer.h"
#include "libANGLE/renderer/ShaderImpl.h" #include "libANGLE/renderer/ShaderImpl.h"
#include "libANGLE/Constants.h"
#include "libANGLE/ResourceManager.h" #include "libANGLE/ResourceManager.h"
#include "common/utilities.h" namespace gl
{
#include "GLSLANG/ShaderLang.h"
#include <sstream> Shader::Data::Data(GLenum shaderType) : mShaderType(shaderType), mShaderVersion(100)
{
}
namespace gl Shader::Data::~Data()
{ {
}
Shader::Shader(ResourceManager *manager, rx::ShaderImpl *impl, GLenum type, GLuint handle) Shader::Shader(ResourceManager *manager, rx::ImplFactory *implFactory, GLenum type, GLuint handle)
: mShader(impl), : mData(type),
mImplementation(implFactory->createShader(&mData)),
mHandle(handle), mHandle(handle),
mType(type), mType(type),
mRefCount(0), mRefCount(0),
...@@ -32,12 +40,12 @@ Shader::Shader(ResourceManager *manager, rx::ShaderImpl *impl, GLenum type, GLui ...@@ -32,12 +40,12 @@ Shader::Shader(ResourceManager *manager, rx::ShaderImpl *impl, GLenum type, GLui
mCompiled(false), mCompiled(false),
mResourceManager(manager) mResourceManager(manager)
{ {
ASSERT(impl); ASSERT(mImplementation);
} }
Shader::~Shader() Shader::~Shader()
{ {
SafeDelete(mShader); SafeDelete(mImplementation);
} }
GLuint Shader::getHandle() const GLuint Shader::getHandle() const
...@@ -66,8 +74,12 @@ void Shader::setSource(GLsizei count, const char *const *string, const GLint *le ...@@ -66,8 +74,12 @@ void Shader::setSource(GLsizei count, const char *const *string, const GLint *le
int Shader::getInfoLogLength() const int Shader::getInfoLogLength() const
{ {
return mShader->getInfoLog().empty() ? 0 if (mData.mInfoLog.empty())
: (static_cast<int>(mShader->getInfoLog().length()) + 1); {
return 0;
}
return (static_cast<int>(mData.mInfoLog.length()) + 1);
} }
void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const
...@@ -76,8 +88,8 @@ void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const ...@@ -76,8 +88,8 @@ void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const
if (bufSize > 0) if (bufSize > 0)
{ {
index = std::min(bufSize - 1, static_cast<GLsizei>(mShader->getInfoLog().length())); index = std::min(bufSize - 1, static_cast<GLsizei>(mData.mInfoLog.length()));
memcpy(infoLog, mShader->getInfoLog().c_str(), index); memcpy(infoLog, mData.mInfoLog.c_str(), index);
infoLog[index] = '\0'; infoLog[index] = '\0';
} }
...@@ -95,9 +107,12 @@ int Shader::getSourceLength() const ...@@ -95,9 +107,12 @@ int Shader::getSourceLength() const
int Shader::getTranslatedSourceLength() const int Shader::getTranslatedSourceLength() const
{ {
return mShader->getTranslatedSource().empty() if (mData.mTranslatedSource.empty())
? 0 {
: (static_cast<int>(mShader->getTranslatedSource().length()) + 1); return 0;
}
return (static_cast<int>(mData.mTranslatedSource.length()) + 1);
} }
void Shader::getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *length, char *buffer) void Shader::getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *length, char *buffer)
...@@ -125,18 +140,27 @@ void Shader::getSource(GLsizei bufSize, GLsizei *length, char *buffer) const ...@@ -125,18 +140,27 @@ void Shader::getSource(GLsizei bufSize, GLsizei *length, char *buffer) const
void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const
{ {
getSourceImpl(mShader->getTranslatedSource(), bufSize, length, buffer); getSourceImpl(mData.mTranslatedSource, bufSize, length, buffer);
} }
void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const
{ {
std::string debugInfo(mShader->getDebugInfo()); std::string debugInfo(mImplementation->getDebugInfo());
getSourceImpl(debugInfo, bufSize, length, buffer); getSourceImpl(debugInfo, bufSize, length, buffer);
} }
void Shader::compile(Compiler *compiler) void Shader::compile(Compiler *compiler)
{ {
mCompiled = mShader->compile(compiler, mSource, 0); mData.mTranslatedSource.clear();
mData.mInfoLog.clear();
mData.mShaderVersion = 100;
mData.mVaryings.clear();
mData.mUniforms.clear();
mData.mInterfaceBlocks.clear();
mData.mActiveAttributes.clear();
mData.mActiveOutputVariables.clear();
mCompiled = mImplementation->compile(compiler, mSource, 0);
} }
void Shader::addRef() void Shader::addRef()
...@@ -171,65 +195,39 @@ void Shader::flagForDeletion() ...@@ -171,65 +195,39 @@ void Shader::flagForDeletion()
int Shader::getShaderVersion() const int Shader::getShaderVersion() const
{ {
return mShader->getShaderVersion(); return mData.mShaderVersion;
} }
const std::vector<sh::Varying> &Shader::getVaryings() const const std::vector<sh::Varying> &Shader::getVaryings() const
{ {
return mShader->getVaryings(); return mData.getVaryings();
} }
const std::vector<sh::Uniform> &Shader::getUniforms() const const std::vector<sh::Uniform> &Shader::getUniforms() const
{ {
return mShader->getUniforms(); return mData.getUniforms();
} }
const std::vector<sh::InterfaceBlock> &Shader::getInterfaceBlocks() const const std::vector<sh::InterfaceBlock> &Shader::getInterfaceBlocks() const
{ {
return mShader->getInterfaceBlocks(); return mData.getInterfaceBlocks();
} }
const std::vector<sh::Attribute> &Shader::getActiveAttributes() const const std::vector<sh::Attribute> &Shader::getActiveAttributes() const
{ {
return mShader->getActiveAttributes(); return mData.getActiveAttributes();
} }
const std::vector<sh::OutputVariable> &Shader::getActiveOutputVariables() const const std::vector<sh::OutputVariable> &Shader::getActiveOutputVariables() const
{ {
return mShader->getActiveOutputVariables(); return mData.getActiveOutputVariables();
}
std::vector<sh::Varying> &Shader::getVaryings()
{
return mShader->getVaryings();
}
std::vector<sh::Uniform> &Shader::getUniforms()
{
return mShader->getUniforms();
} }
std::vector<sh::InterfaceBlock> &Shader::getInterfaceBlocks()
{
return mShader->getInterfaceBlocks();
}
std::vector<sh::Attribute> &Shader::getActiveAttributes()
{
return mShader->getActiveAttributes();
}
std::vector<sh::OutputVariable> &Shader::getActiveOutputVariables()
{
return mShader->getActiveOutputVariables();
}
int Shader::getSemanticIndex(const std::string &attributeName) const int Shader::getSemanticIndex(const std::string &attributeName) const
{ {
if (!attributeName.empty()) if (!attributeName.empty())
{ {
const auto &activeAttributes = mShader->getActiveAttributes(); const auto &activeAttributes = mData.getActiveAttributes();
int semanticIndex = 0; int semanticIndex = 0;
for (size_t attributeIndex = 0; attributeIndex < activeAttributes.size(); attributeIndex++) for (size_t attributeIndex = 0; attributeIndex < activeAttributes.size(); attributeIndex++)
......
...@@ -24,7 +24,9 @@ ...@@ -24,7 +24,9 @@
namespace rx namespace rx
{ {
class ImplFactory;
class ShaderImpl; class ShaderImpl;
class ShaderSh;
} }
namespace gl namespace gl
...@@ -36,15 +38,59 @@ struct Data; ...@@ -36,15 +38,59 @@ struct Data;
class Shader : angle::NonCopyable class Shader : angle::NonCopyable
{ {
public: public:
Shader(ResourceManager *manager, rx::ShaderImpl *impl, GLenum type, GLuint handle); class Data final : angle::NonCopyable
{
public:
Data(GLenum shaderType);
~Data();
const std::string &getInfoLog() const { return mInfoLog; }
const std::string &getTranslatedSource() const { return mTranslatedSource; }
GLenum getShaderType() const { return mShaderType; }
int getShaderVersion() const { return mShaderVersion; }
const std::vector<sh::Varying> &getVaryings() const { return mVaryings; }
const std::vector<sh::Uniform> &getUniforms() const { return mUniforms; }
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const
{
return mInterfaceBlocks;
}
const std::vector<sh::Attribute> &getActiveAttributes() const { return mActiveAttributes; }
const std::vector<sh::OutputVariable> &getActiveOutputVariables() const
{
return mActiveOutputVariables;
}
// TODO(jmadill): Remove this.
std::string &getMutableInfoLog() { return mInfoLog; }
private:
friend class Shader;
// TODO(jmadill): Remove this.
friend class rx::ShaderSh;
GLenum mShaderType;
int mShaderVersion;
std::string mTranslatedSource;
std::string mInfoLog;
std::vector<sh::Varying> mVaryings;
std::vector<sh::Uniform> mUniforms;
std::vector<sh::InterfaceBlock> mInterfaceBlocks;
std::vector<sh::Attribute> mActiveAttributes;
std::vector<sh::OutputVariable> mActiveOutputVariables;
};
Shader(ResourceManager *manager, rx::ImplFactory *implFactory, GLenum type, GLuint handle);
virtual ~Shader(); virtual ~Shader();
GLenum getType() const { return mType; } GLenum getType() const { return mType; }
GLuint getHandle() const; GLuint getHandle() const;
rx::ShaderImpl *getImplementation() { return mShader; } const rx::ShaderImpl *getImplementation() const { return mImplementation; }
const rx::ShaderImpl *getImplementation() const { return mShader; }
void deleteSource(); void deleteSource();
void setSource(GLsizei count, const char *const *string, const GLint *length); void setSource(GLsizei count, const char *const *string, const GLint *length);
...@@ -53,6 +99,7 @@ class Shader : angle::NonCopyable ...@@ -53,6 +99,7 @@ class Shader : angle::NonCopyable
int getSourceLength() const; int getSourceLength() const;
void getSource(GLsizei bufSize, GLsizei *length, char *buffer) const; void getSource(GLsizei bufSize, GLsizei *length, char *buffer) const;
int getTranslatedSourceLength() const; int getTranslatedSourceLength() const;
const std::string &getTranslatedSource() const { return mData.getTranslatedSource(); }
void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const; void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const;
void getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const; void getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, char *buffer) const;
...@@ -73,18 +120,13 @@ class Shader : angle::NonCopyable ...@@ -73,18 +120,13 @@ class Shader : angle::NonCopyable
const std::vector<sh::Attribute> &getActiveAttributes() const; const std::vector<sh::Attribute> &getActiveAttributes() const;
const std::vector<sh::OutputVariable> &getActiveOutputVariables() const; const std::vector<sh::OutputVariable> &getActiveOutputVariables() const;
std::vector<sh::Varying> &getVaryings();
std::vector<sh::Uniform> &getUniforms();
std::vector<sh::InterfaceBlock> &getInterfaceBlocks();
std::vector<sh::Attribute> &getActiveAttributes();
std::vector<sh::OutputVariable> &getActiveOutputVariables();
int getSemanticIndex(const std::string &attributeName) const; int getSemanticIndex(const std::string &attributeName) const;
private: private:
static void getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *length, char *buffer); static void getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *length, char *buffer);
rx::ShaderImpl *mShader; Data mData;
rx::ShaderImpl *mImplementation;
const GLuint mHandle; const GLuint mHandle;
const GLenum mType; const GLenum mType;
std::string mSource; std::string mSource;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "libANGLE/Framebuffer.h" #include "libANGLE/Framebuffer.h"
#include "libANGLE/Program.h" #include "libANGLE/Program.h"
#include "libANGLE/Shader.h"
#include "libANGLE/VertexArray.h" #include "libANGLE/VertexArray.h"
namespace rx namespace rx
...@@ -37,7 +38,8 @@ class ImplFactory : angle::NonCopyable ...@@ -37,7 +38,8 @@ class ImplFactory : angle::NonCopyable
// Shader creation // Shader creation
virtual CompilerImpl *createCompiler() = 0; virtual CompilerImpl *createCompiler() = 0;
virtual ShaderImpl *createShader(GLenum type) = 0; // TODO(jmadill): Make const.
virtual ShaderImpl *createShader(gl::Shader::Data *data) = 0;
virtual ProgramImpl *createProgram(const gl::Program::Data &data) = 0; virtual ProgramImpl *createProgram(const gl::Program::Data &data) = 0;
// Framebuffer creation // Framebuffer creation
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
#ifndef LIBANGLE_RENDERER_SHADERIMPL_H_ #ifndef LIBANGLE_RENDERER_SHADERIMPL_H_
#define LIBANGLE_RENDERER_SHADERIMPL_H_ #define LIBANGLE_RENDERER_SHADERIMPL_H_
#include <vector>
#include "common/angleutils.h" #include "common/angleutils.h"
#include "libANGLE/Shader.h" #include "libANGLE/Shader.h"
...@@ -20,7 +18,7 @@ namespace rx ...@@ -20,7 +18,7 @@ namespace rx
class ShaderImpl : angle::NonCopyable class ShaderImpl : angle::NonCopyable
{ {
public: public:
ShaderImpl() : mShaderVersion(100) {} ShaderImpl(gl::Shader::Data *data) : mData(data) {}
virtual ~ShaderImpl() { } virtual ~ShaderImpl() { }
virtual bool compile(gl::Compiler *compiler, virtual bool compile(gl::Compiler *compiler,
...@@ -28,38 +26,9 @@ class ShaderImpl : angle::NonCopyable ...@@ -28,38 +26,9 @@ class ShaderImpl : angle::NonCopyable
int additionalOptions) = 0; int additionalOptions) = 0;
virtual std::string getDebugInfo() const = 0; virtual std::string getDebugInfo() const = 0;
virtual const std::string &getInfoLog() const { return mInfoLog; }
virtual const std::string &getTranslatedSource() const { return mTranslatedSource; }
int getShaderVersion() const { return mShaderVersion; }
const std::vector<sh::Varying> &getVaryings() const { return mVaryings; }
const std::vector<sh::Uniform> &getUniforms() const { return mUniforms; }
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return mInterfaceBlocks; }
const std::vector<sh::Attribute> &getActiveAttributes() const { return mActiveAttributes; }
const std::vector<sh::OutputVariable> &getActiveOutputVariables() const
{
return mActiveOutputVariables;
}
std::vector<sh::Varying> &getVaryings() { return mVaryings; }
std::vector<sh::Uniform> &getUniforms() { return mUniforms; }
std::vector<sh::InterfaceBlock> &getInterfaceBlocks() { return mInterfaceBlocks; }
std::vector<sh::Attribute> &getActiveAttributes() { return mActiveAttributes; }
std::vector<sh::OutputVariable> &getActiveOutputVariables() { return mActiveOutputVariables; }
protected: protected:
std::string mInfoLog; // TODO(jmadill): Use a const reference when possible.
std::string mTranslatedSource; gl::Shader::Data *mData;
// TODO(jmadill): make part of shared non-Impl state
int mShaderVersion;
std::vector<sh::Varying> mVaryings;
std::vector<sh::Uniform> mUniforms;
std::vector<sh::InterfaceBlock> mInterfaceBlocks;
std::vector<sh::Attribute> mActiveAttributes;
std::vector<sh::OutputVariable> mActiveOutputVariables;
}; };
} }
......
...@@ -65,8 +65,8 @@ bool CompareVarying(const sh::Varying &x, const sh::Varying &y) ...@@ -65,8 +65,8 @@ bool CompareVarying(const sh::Varying &x, const sh::Varying &y)
} // anonymous namespace } // anonymous namespace
ShaderSh::ShaderSh(GLenum type, const gl::Limitations &rendererLimitations) ShaderSh::ShaderSh(gl::Shader::Data *data, const gl::Limitations &rendererLimitations)
: mShaderType(type), mRendererLimitations(rendererLimitations) : ShaderImpl(data), mRendererLimitations(rendererLimitations)
{ {
} }
...@@ -76,15 +76,7 @@ ShaderSh::~ShaderSh() ...@@ -76,15 +76,7 @@ ShaderSh::~ShaderSh()
bool ShaderSh::compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) bool ShaderSh::compile(gl::Compiler *compiler, const std::string &source, int additionalOptions)
{ {
// Reset the previous state ShHandle compilerHandle = compiler->getCompilerHandle(mData->getShaderType());
mActiveAttributes.clear();
mVaryings.clear();
mUniforms.clear();
mInterfaceBlocks.clear();
mActiveOutputVariables.clear();
mTranslatedSource.clear();
ShHandle compilerHandle = compiler->getCompilerHandle(mShaderType);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | additionalOptions); int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | additionalOptions);
...@@ -101,12 +93,12 @@ bool ShaderSh::compile(gl::Compiler *compiler, const std::string &source, int ad ...@@ -101,12 +93,12 @@ bool ShaderSh::compile(gl::Compiler *compiler, const std::string &source, int ad
if (!result) if (!result)
{ {
mInfoLog = ShGetInfoLog(compilerHandle); mData->mInfoLog = ShGetInfoLog(compilerHandle);
TRACE("\n%s", mInfoLog.c_str()); TRACE("\n%s", mData->mInfoLog.c_str());
return false; return false;
} }
mTranslatedSource = ShGetObjectCode(compilerHandle); mData->mTranslatedSource = ShGetObjectCode(compilerHandle);
#ifndef NDEBUG #ifndef NDEBUG
// Prefix translated shader with commented out un-translated shader. // Prefix translated shader with commented out un-translated shader.
...@@ -126,31 +118,32 @@ bool ShaderSh::compile(gl::Compiler *compiler, const std::string &source, int ad ...@@ -126,31 +118,32 @@ bool ShaderSh::compile(gl::Compiler *compiler, const std::string &source, int ad
curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1); curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
} }
shaderStream << "\n\n"; shaderStream << "\n\n";
shaderStream << mTranslatedSource; shaderStream << mData->mTranslatedSource;
mTranslatedSource = shaderStream.str(); mData->mTranslatedSource = shaderStream.str();
#endif #endif
// Gather the shader information // Gather the shader information
mShaderVersion = ShGetShaderVersion(compilerHandle); mData->mShaderVersion = ShGetShaderVersion(compilerHandle);
mVaryings = GetShaderVariables(ShGetVaryings(compilerHandle)); mData->mVaryings = GetShaderVariables(ShGetVaryings(compilerHandle));
mUniforms = GetShaderVariables(ShGetUniforms(compilerHandle)); mData->mUniforms = GetShaderVariables(ShGetUniforms(compilerHandle));
mInterfaceBlocks = GetShaderVariables(ShGetInterfaceBlocks(compilerHandle)); mData->mInterfaceBlocks = GetShaderVariables(ShGetInterfaceBlocks(compilerHandle));
if (mShaderType == GL_VERTEX_SHADER) if (mData->mShaderType == GL_VERTEX_SHADER)
{ {
mActiveAttributes = GetActiveShaderVariables(ShGetAttributes(compilerHandle)); mData->mActiveAttributes = GetActiveShaderVariables(ShGetAttributes(compilerHandle));
} }
else else
{ {
ASSERT(mShaderType == GL_FRAGMENT_SHADER); ASSERT(mData->mShaderType == GL_FRAGMENT_SHADER);
// TODO(jmadill): Figure out why we only sort in the FS, and if we need to. // TODO(jmadill): Figure out why we only sort in the FS, and if we need to.
std::sort(mVaryings.begin(), mVaryings.end(), CompareVarying); std::sort(mData->mVaryings.begin(), mData->mVaryings.end(), CompareVarying);
mActiveOutputVariables = GetActiveShaderVariables(ShGetOutputVariables(compilerHandle)); mData->mActiveOutputVariables =
GetActiveShaderVariables(ShGetOutputVariables(compilerHandle));
} }
ASSERT(!mTranslatedSource.empty()); ASSERT(!mData->mTranslatedSource.empty());
return true; return true;
} }
......
...@@ -24,13 +24,12 @@ namespace rx ...@@ -24,13 +24,12 @@ namespace rx
class ShaderSh : public ShaderImpl class ShaderSh : public ShaderImpl
{ {
public: public:
ShaderSh(GLenum type, const gl::Limitations &rendererLimitations); ShaderSh(gl::Shader::Data *data, const gl::Limitations &rendererLimitations);
~ShaderSh(); ~ShaderSh();
bool compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) override; bool compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) override;
protected: protected:
GLenum mShaderType;
const gl::Limitations &mRendererLimitations; const gl::Limitations &mRendererLimitations;
}; };
......
...@@ -765,8 +765,10 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -765,8 +765,10 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
return false; return false;
} }
const ShaderD3D *vertexShader = GetImplAs<ShaderD3D>(programData.getAttachedVertexShader()); const gl::Shader *vertexShaderGL = programData.getAttachedVertexShader();
const ShaderD3D *fragmentShader = GetImplAs<ShaderD3D>(programData.getAttachedFragmentShader()); const ShaderD3D *vertexShader = GetImplAs<ShaderD3D>(vertexShaderGL);
const gl::Shader *fragmentShaderGL = programData.getAttachedFragmentShader();
const ShaderD3D *fragmentShader = GetImplAs<ShaderD3D>(fragmentShaderGL);
bool usesMRT = fragmentShader->mUsesMultipleRenderTargets; bool usesMRT = fragmentShader->mUsesMultipleRenderTargets;
bool usesFragCoord = fragmentShader->mUsesFragCoord; bool usesFragCoord = fragmentShader->mUsesFragCoord;
...@@ -792,7 +794,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -792,7 +794,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
// This saves us 1 output vector. // This saves us 1 output vector.
bool outputPositionFromVS = !(shaderModel >= 4 && mRenderer->getShaderModelSuffix() != ""); bool outputPositionFromVS = !(shaderModel >= 4 && mRenderer->getShaderModelSuffix() != "");
int shaderVersion = vertexShader->getShaderVersion(); int shaderVersion = vertexShaderGL->getShaderVersion();
if (static_cast<GLuint>(registersNeeded) > data.caps->maxVaryingVectors) if (static_cast<GLuint>(registersNeeded) > data.caps->maxVaryingVectors)
{ {
...@@ -953,7 +955,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data, ...@@ -953,7 +955,7 @@ bool DynamicHLSL::generateShaderLinkHLSL(const gl::Data &data,
} }
else else
{ {
const auto &shaderOutputVars = fragmentShader->getActiveOutputVariables(); const auto &shaderOutputVars = fragmentShaderGL->getActiveOutputVariables();
for (auto outputPair : programData.getOutputVariables()) for (auto outputPair : programData.getOutputVariables())
{ {
......
...@@ -1002,11 +1002,11 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog) ...@@ -1002,11 +1002,11 @@ LinkResult ProgramD3D::link(const gl::Data &data, gl::InfoLog &infoLog)
mSamplersVS.resize(data.caps->maxVertexTextureImageUnits); mSamplersVS.resize(data.caps->maxVertexTextureImageUnits);
mSamplersPS.resize(data.caps->maxTextureImageUnits); mSamplersPS.resize(data.caps->maxTextureImageUnits);
mVertexHLSL = vertexShaderD3D->getTranslatedSource(); mVertexHLSL = vertexShader->getTranslatedSource();
vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds); vertexShaderD3D->generateWorkarounds(&mVertexWorkarounds);
mShaderVersion = vertexShaderD3D->getShaderVersion(); mShaderVersion = vertexShader->getShaderVersion();
mPixelHLSL = fragmentShaderD3D->getTranslatedSource(); mPixelHLSL = fragmentShader->getTranslatedSource();
fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds); fragmentShaderD3D->generateWorkarounds(&mPixelWorkarounds);
if (mRenderer->getRendererLimitations().noFrontFacingSupport) if (mRenderer->getRendererLimitations().noFrontFacingSupport)
...@@ -1346,28 +1346,23 @@ void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v) ...@@ -1346,28 +1346,23 @@ void ProgramD3D::setUniform4uiv(GLint location, GLsizei count, const GLuint *v)
void ProgramD3D::defineUniformsAndAssignRegisters() void ProgramD3D::defineUniformsAndAssignRegisters()
{ {
const gl::Shader *vertexShader = mData.getAttachedVertexShader();
const ShaderD3D *vertexShaderD3D = GetImplAs<ShaderD3D>(vertexShader);
D3DUniformMap uniformMap; D3DUniformMap uniformMap;
const gl::Shader *vertexShader = mData.getAttachedVertexShader();
for (const sh::Uniform &vertexUniform : vertexShader->getUniforms()) for (const sh::Uniform &vertexUniform : vertexShader->getUniforms())
{ {
if (vertexUniform.staticUse) if (vertexUniform.staticUse)
{ {
defineUniformBase(vertexShaderD3D, vertexUniform, &uniformMap); defineUniformBase(vertexShader, vertexUniform, &uniformMap);
} }
} }
const gl::Shader *fragmentShader = mData.getAttachedFragmentShader(); const gl::Shader *fragmentShader = mData.getAttachedFragmentShader();
const ShaderD3D *fragmentShaderD3D = GetImplAs<ShaderD3D>(fragmentShader);
for (const sh::Uniform &fragmentUniform : fragmentShader->getUniforms()) for (const sh::Uniform &fragmentUniform : fragmentShader->getUniforms())
{ {
if (fragmentUniform.staticUse) if (fragmentUniform.staticUse)
{ {
defineUniformBase(fragmentShaderD3D, fragmentUniform, &uniformMap); defineUniformBase(fragmentShader, fragmentUniform, &uniformMap);
} }
} }
...@@ -1386,22 +1381,24 @@ void ProgramD3D::defineUniformsAndAssignRegisters() ...@@ -1386,22 +1381,24 @@ void ProgramD3D::defineUniformsAndAssignRegisters()
initializeUniformStorage(); initializeUniformStorage();
} }
void ProgramD3D::defineUniformBase(const ShaderD3D *shader, void ProgramD3D::defineUniformBase(const gl::Shader *shader,
const sh::Uniform &uniform, const sh::Uniform &uniform,
D3DUniformMap *uniformMap) D3DUniformMap *uniformMap)
{ {
if (uniform.isBuiltIn()) if (uniform.isBuiltIn())
{ {
defineUniform(shader, uniform, uniform.name, nullptr, uniformMap); defineUniform(shader->getType(), uniform, uniform.name, nullptr, uniformMap);
return; return;
} }
unsigned int startRegister = shader->getUniformRegister(uniform.name); const ShaderD3D *shaderD3D = GetImplAs<ShaderD3D>(shader);
ShShaderOutput outputType = shader->getCompilerOutputType();
unsigned int startRegister = shaderD3D->getUniformRegister(uniform.name);
ShShaderOutput outputType = shaderD3D->getCompilerOutputType();
sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType)); sh::HLSLBlockEncoder encoder(sh::HLSLBlockEncoder::GetStrategyFor(outputType));
encoder.skipRegisters(startRegister); encoder.skipRegisters(startRegister);
defineUniform(shader, uniform, uniform.name, &encoder, uniformMap); defineUniform(shader->getType(), uniform, uniform.name, &encoder, uniformMap);
} }
D3DUniform *ProgramD3D::getD3DUniformByName(const std::string &name) D3DUniform *ProgramD3D::getD3DUniformByName(const std::string &name)
...@@ -1417,7 +1414,7 @@ D3DUniform *ProgramD3D::getD3DUniformByName(const std::string &name) ...@@ -1417,7 +1414,7 @@ D3DUniform *ProgramD3D::getD3DUniformByName(const std::string &name)
return nullptr; return nullptr;
} }
void ProgramD3D::defineUniform(const ShaderD3D *shader, void ProgramD3D::defineUniform(GLenum shaderType,
const sh::ShaderVariable &uniform, const sh::ShaderVariable &uniform,
const std::string &fullName, const std::string &fullName,
sh::HLSLBlockEncoder *encoder, sh::HLSLBlockEncoder *encoder,
...@@ -1437,7 +1434,7 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader, ...@@ -1437,7 +1434,7 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader,
const sh::ShaderVariable &field = uniform.fields[fieldIndex]; const sh::ShaderVariable &field = uniform.fields[fieldIndex];
const std::string &fieldFullName = (fullName + elementString + "." + field.name); const std::string &fieldFullName = (fullName + elementString + "." + field.name);
defineUniform(shader, field, fieldFullName, encoder, uniformMap); defineUniform(shaderType, field, fieldFullName, encoder, uniformMap);
} }
if (encoder) if (encoder)
...@@ -1476,16 +1473,15 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader, ...@@ -1476,16 +1473,15 @@ void ProgramD3D::defineUniform(const ShaderD3D *shader,
static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo)); static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo));
unsigned int reg = unsigned int reg =
static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegister(blockInfo)); static_cast<unsigned int>(sh::HLSLBlockEncoder::getBlockRegister(blockInfo));
if (shader->getShaderType() == GL_FRAGMENT_SHADER) if (shaderType == GL_FRAGMENT_SHADER)
{ {
d3dUniform->psRegisterIndex = reg; d3dUniform->psRegisterIndex = reg;
} }
else if (shader->getShaderType() == GL_VERTEX_SHADER) else
{ {
ASSERT(shaderType == GL_VERTEX_SHADER);
d3dUniform->vsRegisterIndex = reg; d3dUniform->vsRegisterIndex = reg;
} }
else
UNREACHABLE();
// Arrays are treated as aggregate types // Arrays are treated as aggregate types
if (uniform.isArray()) if (uniform.isArray())
......
...@@ -200,10 +200,10 @@ class ProgramD3D : public ProgramImpl ...@@ -200,10 +200,10 @@ class ProgramD3D : public ProgramImpl
typedef std::map<std::string, sh::BlockMemberInfo> BlockInfoMap; typedef std::map<std::string, sh::BlockMemberInfo> BlockInfoMap;
void defineUniformsAndAssignRegisters(); void defineUniformsAndAssignRegisters();
void defineUniformBase(const ShaderD3D *shader, void defineUniformBase(const gl::Shader *shader,
const sh::Uniform &uniform, const sh::Uniform &uniform,
D3DUniformMap *uniformMap); D3DUniformMap *uniformMap);
void defineUniform(const ShaderD3D *shader, void defineUniform(GLenum shaderType,
const sh::ShaderVariable &uniform, const sh::ShaderVariable &uniform,
const std::string &fullName, const std::string &fullName,
sh::HLSLBlockEncoder *encoder, sh::HLSLBlockEncoder *encoder,
......
...@@ -39,7 +39,8 @@ const char *GetShaderTypeString(GLenum type) ...@@ -39,7 +39,8 @@ const char *GetShaderTypeString(GLenum type)
namespace rx namespace rx
{ {
ShaderD3D::ShaderD3D(GLenum type, const gl::Limitations &limitations) : ShaderSh(type, limitations) ShaderD3D::ShaderD3D(gl::Shader::Data *data, const gl::Limitations &limitations)
: ShaderSh(data, limitations)
{ {
uncompile(); uncompile();
} }
...@@ -50,17 +51,15 @@ ShaderD3D::~ShaderD3D() ...@@ -50,17 +51,15 @@ ShaderD3D::~ShaderD3D()
std::string ShaderD3D::getDebugInfo() const std::string ShaderD3D::getDebugInfo() const
{ {
return mDebugInfo + std::string("\n// ") + GetShaderTypeString(mShaderType) + " SHADER END\n"; return mDebugInfo + std::string("\n// ") + GetShaderTypeString(mData->getShaderType()) +
" SHADER END\n";
} }
// initialize/clean up previous state // initialize/clean up previous state
void ShaderD3D::uncompile() void ShaderD3D::uncompile()
{ {
// set by compileToHLSL // set by compileToHLSL
mCompilerOutputType = SH_ESSL_OUTPUT; mCompilerOutputType = SH_ESSL_OUTPUT;
mTranslatedSource.clear();
mInfoLog.clear();
mUsesMultipleRenderTargets = false; mUsesMultipleRenderTargets = false;
mUsesFragColor = false; mUsesFragColor = false;
...@@ -71,17 +70,11 @@ void ShaderD3D::uncompile() ...@@ -71,17 +70,11 @@ void ShaderD3D::uncompile()
mUsesPointCoord = false; mUsesPointCoord = false;
mUsesDepthRange = false; mUsesDepthRange = false;
mUsesFragDepth = false; mUsesFragDepth = false;
mShaderVersion = 100;
mUsesDiscardRewriting = false; mUsesDiscardRewriting = false;
mUsesNestedBreak = false; mUsesNestedBreak = false;
mUsesDeferredInit = false; mUsesDeferredInit = false;
mRequiresIEEEStrictCompiling = false; mRequiresIEEEStrictCompiling = false;
mVaryings.clear();
mUniforms.clear();
mInterfaceBlocks.clear();
mActiveAttributes.clear();
mActiveOutputVariables.clear();
mDebugInfo.clear(); mDebugInfo.clear();
} }
...@@ -120,11 +113,6 @@ unsigned int ShaderD3D::getInterfaceBlockRegister(const std::string &blockName) ...@@ -120,11 +113,6 @@ unsigned int ShaderD3D::getInterfaceBlockRegister(const std::string &blockName)
return mInterfaceBlockRegisterMap.find(blockName)->second; return mInterfaceBlockRegisterMap.find(blockName)->second;
} }
GLenum ShaderD3D::getShaderType() const
{
return mShaderType;
}
ShShaderOutput ShaderD3D::getCompilerOutputType() const ShShaderOutput ShaderD3D::getCompilerOutputType() const
{ {
return mCompilerOutputType; return mCompilerOutputType;
...@@ -134,7 +122,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a ...@@ -134,7 +122,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a
{ {
uncompile(); uncompile();
ShHandle compilerHandle = compiler->getCompilerHandle(mShaderType); ShHandle compilerHandle = compiler->getCompilerHandle(mData->getShaderType());
// TODO(jmadill): We shouldn't need to cache this. // TODO(jmadill): We shouldn't need to cache this.
mCompilerOutputType = ShGetShaderOutputType(compilerHandle); mCompilerOutputType = ShGetShaderOutputType(compilerHandle);
...@@ -162,23 +150,25 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a ...@@ -162,23 +150,25 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a
return false; return false;
} }
mUsesMultipleRenderTargets = mTranslatedSource.find("GL_USES_MRT") != std::string::npos; const std::string &translatedSource = mData->getTranslatedSource();
mUsesFragColor = mTranslatedSource.find("GL_USES_FRAG_COLOR") != std::string::npos;
mUsesFragData = mTranslatedSource.find("GL_USES_FRAG_DATA") != std::string::npos; mUsesMultipleRenderTargets = translatedSource.find("GL_USES_MRT") != std::string::npos;
mUsesFragCoord = mTranslatedSource.find("GL_USES_FRAG_COORD") != std::string::npos; mUsesFragColor = translatedSource.find("GL_USES_FRAG_COLOR") != std::string::npos;
mUsesFrontFacing = mTranslatedSource.find("GL_USES_FRONT_FACING") != std::string::npos; mUsesFragData = translatedSource.find("GL_USES_FRAG_DATA") != std::string::npos;
mUsesPointSize = mTranslatedSource.find("GL_USES_POINT_SIZE") != std::string::npos; mUsesFragCoord = translatedSource.find("GL_USES_FRAG_COORD") != std::string::npos;
mUsesPointCoord = mTranslatedSource.find("GL_USES_POINT_COORD") != std::string::npos; mUsesFrontFacing = translatedSource.find("GL_USES_FRONT_FACING") != std::string::npos;
mUsesDepthRange = mTranslatedSource.find("GL_USES_DEPTH_RANGE") != std::string::npos; mUsesPointSize = translatedSource.find("GL_USES_POINT_SIZE") != std::string::npos;
mUsesFragDepth = mTranslatedSource.find("GL_USES_FRAG_DEPTH") != std::string::npos; mUsesPointCoord = translatedSource.find("GL_USES_POINT_COORD") != std::string::npos;
mUsesDepthRange = translatedSource.find("GL_USES_DEPTH_RANGE") != std::string::npos;
mUsesFragDepth = translatedSource.find("GL_USES_FRAG_DEPTH") != std::string::npos;
mUsesDiscardRewriting = mUsesDiscardRewriting =
mTranslatedSource.find("ANGLE_USES_DISCARD_REWRITING") != std::string::npos; translatedSource.find("ANGLE_USES_DISCARD_REWRITING") != std::string::npos;
mUsesNestedBreak = mTranslatedSource.find("ANGLE_USES_NESTED_BREAK") != std::string::npos; mUsesNestedBreak = translatedSource.find("ANGLE_USES_NESTED_BREAK") != std::string::npos;
mUsesDeferredInit = mTranslatedSource.find("ANGLE_USES_DEFERRED_INIT") != std::string::npos; mUsesDeferredInit = translatedSource.find("ANGLE_USES_DEFERRED_INIT") != std::string::npos;
mRequiresIEEEStrictCompiling = mRequiresIEEEStrictCompiling =
mTranslatedSource.find("ANGLE_REQUIRES_IEEE_STRICT_COMPILING") != std::string::npos; translatedSource.find("ANGLE_REQUIRES_IEEE_STRICT_COMPILING") != std::string::npos;
for (const sh::Uniform &uniform : mUniforms) for (const sh::Uniform &uniform : mData->getUniforms())
{ {
if (uniform.staticUse && !uniform.isBuiltIn()) if (uniform.staticUse && !uniform.isBuiltIn())
{ {
...@@ -192,7 +182,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a ...@@ -192,7 +182,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a
} }
} }
for (const sh::InterfaceBlock &interfaceBlock : mInterfaceBlocks) for (const sh::InterfaceBlock &interfaceBlock : mData->getInterfaceBlocks())
{ {
if (interfaceBlock.staticUse) if (interfaceBlock.staticUse)
{ {
...@@ -207,12 +197,13 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a ...@@ -207,12 +197,13 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a
} }
#if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED #if ANGLE_SHADER_DEBUG_INFO == ANGLE_ENABLED
mDebugInfo += std::string("// ") + GetShaderTypeString(mShaderType) + " SHADER BEGIN\n"; mDebugInfo +=
std::string("// ") + GetShaderTypeString(mData->getShaderType()) + " SHADER BEGIN\n";
mDebugInfo += "\n// GLSL BEGIN\n\n" + source + "\n\n// GLSL END\n\n\n"; mDebugInfo += "\n// GLSL BEGIN\n\n" + source + "\n\n// GLSL END\n\n\n";
mDebugInfo += "// INITIAL HLSL BEGIN\n\n" + getTranslatedSource() + "\n// INITIAL HLSL END\n\n\n"; mDebugInfo += "// INITIAL HLSL BEGIN\n\n" + translatedSource + "\n// INITIAL HLSL END\n\n\n";
// Successive steps will append more info // Successive steps will append more info
#else #else
mDebugInfo += getTranslatedSource(); mDebugInfo += translatedSource;
#endif #endif
return true; return true;
} }
......
...@@ -24,7 +24,7 @@ class ShaderD3D : public ShaderSh ...@@ -24,7 +24,7 @@ class ShaderD3D : public ShaderSh
friend class DynamicHLSL; friend class DynamicHLSL;
public: public:
ShaderD3D(GLenum type, const gl::Limitations &limitations); ShaderD3D(gl::Shader::Data *data, const gl::Limitations &limitations);
virtual ~ShaderD3D(); virtual ~ShaderD3D();
// ShaderImpl implementation // ShaderImpl implementation
...@@ -38,13 +38,11 @@ class ShaderD3D : public ShaderSh ...@@ -38,13 +38,11 @@ class ShaderD3D : public ShaderSh
void appendDebugInfo(const std::string &info) { mDebugInfo += info; } void appendDebugInfo(const std::string &info) { mDebugInfo += info; }
void generateWorkarounds(D3DCompilerWorkarounds *workarounds) const; void generateWorkarounds(D3DCompilerWorkarounds *workarounds) const;
int getShaderVersion() const { return mShaderVersion; }
bool usesDepthRange() const { return mUsesDepthRange; } bool usesDepthRange() const { return mUsesDepthRange; }
bool usesPointSize() const { return mUsesPointSize; } bool usesPointSize() const { return mUsesPointSize; }
bool usesDeferredInit() const { return mUsesDeferredInit; } bool usesDeferredInit() const { return mUsesDeferredInit; }
bool usesFrontFacing() const { return mUsesFrontFacing; } bool usesFrontFacing() const { return mUsesFrontFacing; }
GLenum getShaderType() const;
ShShaderOutput getCompilerOutputType() const; ShShaderOutput getCompilerOutputType() const;
private: private:
......
...@@ -3003,9 +3003,9 @@ FramebufferImpl *Renderer11::createFramebuffer(const gl::Framebuffer::Data &data ...@@ -3003,9 +3003,9 @@ FramebufferImpl *Renderer11::createFramebuffer(const gl::Framebuffer::Data &data
return new Framebuffer11(data, this); return new Framebuffer11(data, this);
} }
ShaderImpl *Renderer11::createShader(GLenum type) ShaderImpl *Renderer11::createShader(gl::Shader::Data *data)
{ {
return new ShaderD3D(type, getRendererLimitations()); return new ShaderD3D(data, getRendererLimitations());
} }
ProgramImpl *Renderer11::createProgram(const gl::Program::Data &data) ProgramImpl *Renderer11::createProgram(const gl::Program::Data &data)
......
...@@ -182,8 +182,8 @@ class Renderer11 : public RendererD3D ...@@ -182,8 +182,8 @@ class Renderer11 : public RendererD3D
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
virtual ShaderImpl *createShader(GLenum type); ShaderImpl *createShader(gl::Shader::Data *data) override;
virtual ProgramImpl *createProgram(const gl::Program::Data &data); ProgramImpl *createProgram(const gl::Program::Data &data) override;
// Shader operations // Shader operations
virtual gl::Error loadExecutable(const void *function, size_t length, ShaderType type, virtual gl::Error loadExecutable(const void *function, size_t length, ShaderType type,
......
...@@ -2713,9 +2713,9 @@ FramebufferImpl *Renderer9::createFramebuffer(const gl::Framebuffer::Data &data) ...@@ -2713,9 +2713,9 @@ FramebufferImpl *Renderer9::createFramebuffer(const gl::Framebuffer::Data &data)
return new Framebuffer9(data, this); return new Framebuffer9(data, this);
} }
ShaderImpl *Renderer9::createShader(GLenum type) ShaderImpl *Renderer9::createShader(gl::Shader::Data *data)
{ {
return new ShaderD3D(type, getRendererLimitations()); return new ShaderD3D(data, getRendererLimitations());
} }
ProgramImpl *Renderer9::createProgram(const gl::Program::Data &data) ProgramImpl *Renderer9::createProgram(const gl::Program::Data &data)
......
...@@ -169,8 +169,8 @@ class Renderer9 : public RendererD3D ...@@ -169,8 +169,8 @@ class Renderer9 : public RendererD3D
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
virtual ShaderImpl *createShader(GLenum type); ShaderImpl *createShader(gl::Shader::Data *data) override;
virtual ProgramImpl *createProgram(const gl::Program::Data &data); ProgramImpl *createProgram(const gl::Program::Data &data) override;
// Shader operations // Shader operations
virtual gl::Error loadExecutable(const void *function, size_t length, ShaderType type, virtual gl::Error loadExecutable(const void *function, size_t length, ShaderType type,
......
...@@ -242,9 +242,9 @@ CompilerImpl *RendererGL::createCompiler() ...@@ -242,9 +242,9 @@ CompilerImpl *RendererGL::createCompiler()
return new CompilerGL(mFunctions); return new CompilerGL(mFunctions);
} }
ShaderImpl *RendererGL::createShader(GLenum type) ShaderImpl *RendererGL::createShader(gl::Shader::Data *data)
{ {
return new ShaderGL(type, getRendererLimitations(), mFunctions); return new ShaderGL(data, getRendererLimitations(), mFunctions);
} }
ProgramImpl *RendererGL::createProgram(const gl::Program::Data &data) ProgramImpl *RendererGL::createProgram(const gl::Program::Data &data)
......
...@@ -59,7 +59,7 @@ class RendererGL : public Renderer ...@@ -59,7 +59,7 @@ class RendererGL : public Renderer
// Shader creation // Shader creation
CompilerImpl *createCompiler() override; CompilerImpl *createCompiler() override;
ShaderImpl *createShader(GLenum type) override; ShaderImpl *createShader(gl::Shader::Data *data) override;
ProgramImpl *createProgram(const gl::Program::Data &data) override; ProgramImpl *createProgram(const gl::Program::Data &data) override;
// Framebuffer creation // Framebuffer creation
......
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
namespace rx namespace rx
{ {
ShaderGL::ShaderGL(GLenum type, ShaderGL::ShaderGL(gl::Shader::Data *data,
const gl::Limitations &rendererLimitations, const gl::Limitations &rendererLimitations,
const FunctionsGL *functions) const FunctionsGL *functions)
: ShaderSh(type, rendererLimitations), mFunctions(functions), mShaderID(0) : ShaderSh(data, rendererLimitations), mFunctions(functions), mShaderID(0)
{ {
ASSERT(mFunctions); ASSERT(mFunctions);
} }
...@@ -49,10 +49,10 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad ...@@ -49,10 +49,10 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad
} }
// Translate the ESSL into GLSL // Translate the ESSL into GLSL
const char *translatedSourceCString = mTranslatedSource.c_str(); const char *translatedSourceCString = mData->getTranslatedSource().c_str();
// Generate a shader object and set the source // Generate a shader object and set the source
mShaderID = mFunctions->createShader(mShaderType); mShaderID = mFunctions->createShader(mData->getShaderType());
mFunctions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr); mFunctions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr);
mFunctions->compileShader(mShaderID); mFunctions->compileShader(mShaderID);
...@@ -72,8 +72,9 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad ...@@ -72,8 +72,9 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad
mFunctions->deleteShader(mShaderID); mFunctions->deleteShader(mShaderID);
mShaderID = 0; mShaderID = 0;
mInfoLog = &buf[0]; // TODO(jmadill): possibly pass in info log?
TRACE("\n%s", mInfoLog.c_str()); mData->getMutableInfoLog() = &buf[0];
TRACE("\n%s", mData->getMutableInfoLog().c_str());
return false; return false;
} }
......
...@@ -19,7 +19,9 @@ class RendererGL; ...@@ -19,7 +19,9 @@ class RendererGL;
class ShaderGL : public ShaderSh class ShaderGL : public ShaderSh
{ {
public: public:
ShaderGL(GLenum type, const gl::Limitations &rendererLimitations, const FunctionsGL *functions); ShaderGL(gl::Shader::Data *data,
const gl::Limitations &rendererLimitations,
const FunctionsGL *functions);
~ShaderGL() override; ~ShaderGL() override;
bool compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) override; bool compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) override;
......
...@@ -22,7 +22,7 @@ class NullFactory : public ImplFactory ...@@ -22,7 +22,7 @@ class NullFactory : public ImplFactory
// Shader creation // Shader creation
CompilerImpl *createCompiler() override { return nullptr; } CompilerImpl *createCompiler() override { return nullptr; }
ShaderImpl *createShader(GLenum type) override { return nullptr; } ShaderImpl *createShader(gl::Shader::Data *data) override { return nullptr; }
ProgramImpl *createProgram(const gl::Program::Data &data) override { return nullptr; } ProgramImpl *createProgram(const gl::Program::Data &data) override { return nullptr; }
// Framebuffer creation // Framebuffer creation
......
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