Commit 006cbc5b by Jamie Madill

Remove rx::ShaderSh and move the shared code to the GL.

The GL layer can interact with the translator directly, to query all the active shader variables and call ShCompile. BUG=angleproject:1159 Change-Id: I334a9bef28f93cf85dd8cac0fb8542ac567cc3ec Reviewed-on: https://chromium-review.googlesource.com/299877Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tryjob-Request: Jamie Madill <jmadill@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 91445bce
...@@ -289,7 +289,7 @@ GLuint Context::createProgram() ...@@ -289,7 +289,7 @@ GLuint Context::createProgram()
GLuint Context::createShader(GLenum type) GLuint Context::createShader(GLenum type)
{ {
return mResourceManager->createShader(getData(), type); return mResourceManager->createShader(mRenderer->getRendererLimitations(), type);
} }
GLuint Context::createTexture() GLuint Context::createTexture()
......
...@@ -88,13 +88,13 @@ GLuint ResourceManager::createBuffer() ...@@ -88,13 +88,13 @@ GLuint ResourceManager::createBuffer()
} }
// Returns an unused shader/program name // Returns an unused shader/program name
GLuint ResourceManager::createShader(const gl::Data &data, GLenum type) GLuint ResourceManager::createShader(const gl::Limitations &rendererLimitations, GLenum type)
{ {
GLuint handle = mProgramShaderHandleAllocator.allocate(); GLuint handle = mProgramShaderHandleAllocator.allocate();
if (type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER) if (type == GL_VERTEX_SHADER || type == GL_FRAGMENT_SHADER)
{ {
mShaderMap[handle] = new Shader(this, mFactory, type, handle); mShaderMap[handle] = new Shader(this, mFactory, rendererLimitations, type, handle);
} }
else UNREACHABLE(); else UNREACHABLE();
......
...@@ -25,13 +25,14 @@ class ImplFactory; ...@@ -25,13 +25,14 @@ class ImplFactory;
namespace gl namespace gl
{ {
class Buffer; class Buffer;
class Shader; struct Data;
class FenceSync;
struct Limitations;
class Program; class Program;
class Texture;
class Renderbuffer; class Renderbuffer;
class Sampler; class Sampler;
class FenceSync; class Shader;
struct Data; class Texture;
class ResourceManager : angle::NonCopyable class ResourceManager : angle::NonCopyable
{ {
...@@ -43,7 +44,7 @@ class ResourceManager : angle::NonCopyable ...@@ -43,7 +44,7 @@ class ResourceManager : angle::NonCopyable
void release(); void release();
GLuint createBuffer(); GLuint createBuffer();
GLuint createShader(const gl::Data &data, GLenum type); GLuint createShader(const gl::Limitations &rendererLimitations, GLenum type);
GLuint createProgram(); GLuint createProgram();
GLuint createTexture(); GLuint createTexture();
GLuint createRenderbuffer(); GLuint createRenderbuffer();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "common/utilities.h" #include "common/utilities.h"
#include "GLSLANG/ShaderLang.h" #include "GLSLANG/ShaderLang.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/Constants.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"
...@@ -22,6 +23,55 @@ ...@@ -22,6 +23,55 @@
namespace gl namespace gl
{ {
namespace
{
template <typename VarT>
std::vector<VarT> GetActiveShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
std::vector<VarT> result;
for (size_t varIndex = 0; varIndex < variableList->size(); varIndex++)
{
const VarT &var = variableList->at(varIndex);
if (var.staticUse)
{
result.push_back(var);
}
}
return result;
}
template <typename VarT>
const std::vector<VarT> &GetShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
return *variableList;
}
// true if varying x has a higher priority in packing than y
bool CompareVarying(const sh::Varying &x, const sh::Varying &y)
{
if (x.type == y.type)
{
return x.arraySize > y.arraySize;
}
// Special case for handling structs: we sort these to the end of the list
if (x.type == GL_STRUCT_ANGLEX)
{
return false;
}
if (y.type == GL_STRUCT_ANGLEX)
{
return true;
}
return gl::VariableSortOrder(x.type) < gl::VariableSortOrder(y.type);
}
} // anonymous namespace
Shader::Data::Data(GLenum shaderType) : mShaderType(shaderType), mShaderVersion(100) Shader::Data::Data(GLenum shaderType) : mShaderType(shaderType), mShaderVersion(100)
{ {
} }
...@@ -30,9 +80,14 @@ Shader::Data::~Data() ...@@ -30,9 +80,14 @@ Shader::Data::~Data()
{ {
} }
Shader::Shader(ResourceManager *manager, rx::ImplFactory *implFactory, GLenum type, GLuint handle) Shader::Shader(ResourceManager *manager,
rx::ImplFactory *implFactory,
const gl::Limitations &rendererLimitations,
GLenum type,
GLuint handle)
: mData(type), : mData(type),
mImplementation(implFactory->createShader(&mData)), mImplementation(implFactory->createShader(mData)),
mRendererLimitations(rendererLimitations),
mHandle(handle), mHandle(handle),
mType(type), mType(type),
mRefCount(0), mRefCount(0),
...@@ -69,17 +124,17 @@ void Shader::setSource(GLsizei count, const char *const *string, const GLint *le ...@@ -69,17 +124,17 @@ void Shader::setSource(GLsizei count, const char *const *string, const GLint *le
} }
} }
mSource = stream.str(); mData.mSource = stream.str();
} }
int Shader::getInfoLogLength() const int Shader::getInfoLogLength() const
{ {
if (mData.mInfoLog.empty()) if (mInfoLog.empty())
{ {
return 0; return 0;
} }
return (static_cast<int>(mData.mInfoLog.length()) + 1); return (static_cast<int>(mInfoLog.length()) + 1);
} }
void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const
...@@ -88,8 +143,8 @@ void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const ...@@ -88,8 +143,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>(mData.mInfoLog.length())); index = std::min(bufSize - 1, static_cast<GLsizei>(mInfoLog.length()));
memcpy(infoLog, mData.mInfoLog.c_str(), index); memcpy(infoLog, mInfoLog.c_str(), index);
infoLog[index] = '\0'; infoLog[index] = '\0';
} }
...@@ -102,7 +157,7 @@ void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const ...@@ -102,7 +157,7 @@ void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const
int Shader::getSourceLength() const int Shader::getSourceLength() const
{ {
return mSource.empty() ? 0 : (static_cast<int>(mSource.length()) + 1); return mData.mSource.empty() ? 0 : (static_cast<int>(mData.mSource.length()) + 1);
} }
int Shader::getTranslatedSourceLength() const int Shader::getTranslatedSourceLength() const
...@@ -135,7 +190,7 @@ void Shader::getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei * ...@@ -135,7 +190,7 @@ void Shader::getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *
void Shader::getSource(GLsizei bufSize, GLsizei *length, char *buffer) const void Shader::getSource(GLsizei bufSize, GLsizei *length, char *buffer) const
{ {
getSourceImpl(mSource, bufSize, length, buffer); getSourceImpl(mData.mSource, bufSize, length, buffer);
} }
void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const void Shader::getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const
...@@ -152,7 +207,7 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, ...@@ -152,7 +207,7 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length,
void Shader::compile(Compiler *compiler) void Shader::compile(Compiler *compiler)
{ {
mData.mTranslatedSource.clear(); mData.mTranslatedSource.clear();
mData.mInfoLog.clear(); mInfoLog.clear();
mData.mShaderVersion = 100; mData.mShaderVersion = 100;
mData.mVaryings.clear(); mData.mVaryings.clear();
mData.mUniforms.clear(); mData.mUniforms.clear();
...@@ -160,7 +215,81 @@ void Shader::compile(Compiler *compiler) ...@@ -160,7 +215,81 @@ void Shader::compile(Compiler *compiler)
mData.mActiveAttributes.clear(); mData.mActiveAttributes.clear();
mData.mActiveOutputVariables.clear(); mData.mActiveOutputVariables.clear();
mCompiled = mImplementation->compile(compiler, mSource, 0); ShHandle compilerHandle = compiler->getCompilerHandle(mData.mShaderType);
std::stringstream sourceStream;
int additionalOptions = mImplementation->prepareSourceAndReturnOptions(&sourceStream);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | additionalOptions);
// Some targets (eg D3D11 Feature Level 9_3 and below) do not support non-constant loop indexes
// in fragment shaders. Shader compilation will fail. To provide a better error message we can
// instruct the compiler to pre-validate.
if (mRendererLimitations.shadersRequireIndexedLoopValidation)
{
compileOptions |= SH_VALIDATE_LOOP_INDEXING;
}
std::string sourceString = sourceStream.str();
const char *sourceCString = sourceString.c_str();
bool result = ShCompile(compilerHandle, &sourceCString, 1, compileOptions);
if (!result)
{
mInfoLog = ShGetInfoLog(compilerHandle);
TRACE("\n%s", mInfoLog.c_str());
mCompiled = false;
return;
}
mData.mTranslatedSource = ShGetObjectCode(compilerHandle);
#ifndef NDEBUG
// Prefix translated shader with commented out un-translated shader.
// Useful in diagnostics tools which capture the shader source.
std::ostringstream shaderStream;
shaderStream << "// GLSL\n";
shaderStream << "//\n";
size_t curPos = 0;
while (curPos != std::string::npos)
{
size_t nextLine = mData.mSource.find("\n", curPos);
size_t len = (nextLine == std::string::npos) ? std::string::npos : (nextLine - curPos + 1);
shaderStream << "// " << mData.mSource.substr(curPos, len);
curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
}
shaderStream << "\n\n";
shaderStream << mData.mTranslatedSource;
mData.mTranslatedSource = shaderStream.str();
#endif
// Gather the shader information
mData.mShaderVersion = ShGetShaderVersion(compilerHandle);
mData.mVaryings = GetShaderVariables(ShGetVaryings(compilerHandle));
mData.mUniforms = GetShaderVariables(ShGetUniforms(compilerHandle));
mData.mInterfaceBlocks = GetShaderVariables(ShGetInterfaceBlocks(compilerHandle));
if (mData.mShaderType == GL_VERTEX_SHADER)
{
mData.mActiveAttributes = GetActiveShaderVariables(ShGetAttributes(compilerHandle));
}
else
{
ASSERT(mData.mShaderType == GL_FRAGMENT_SHADER);
// TODO(jmadill): Figure out why we only sort in the FS, and if we need to.
std::sort(mData.mVaryings.begin(), mData.mVaryings.end(), CompareVarying);
mData.mActiveOutputVariables =
GetActiveShaderVariables(ShGetOutputVariables(compilerHandle));
}
ASSERT(!mData.mTranslatedSource.empty());
mCompiled = mImplementation->postTranslateCompile(compiler, &mInfoLog);
} }
void Shader::addRef() void Shader::addRef()
......
...@@ -32,6 +32,7 @@ class ShaderSh; ...@@ -32,6 +32,7 @@ class ShaderSh;
namespace gl namespace gl
{ {
class Compiler; class Compiler;
struct Limitations;
class ResourceManager; class ResourceManager;
struct Data; struct Data;
...@@ -44,7 +45,7 @@ class Shader : angle::NonCopyable ...@@ -44,7 +45,7 @@ class Shader : angle::NonCopyable
Data(GLenum shaderType); Data(GLenum shaderType);
~Data(); ~Data();
const std::string &getInfoLog() const { return mInfoLog; } const std::string &getSource() const { return mSource; }
const std::string &getTranslatedSource() const { return mTranslatedSource; } const std::string &getTranslatedSource() const { return mTranslatedSource; }
GLenum getShaderType() const { return mShaderType; } GLenum getShaderType() const { return mShaderType; }
...@@ -62,19 +63,13 @@ class Shader : angle::NonCopyable ...@@ -62,19 +63,13 @@ class Shader : angle::NonCopyable
return mActiveOutputVariables; return mActiveOutputVariables;
} }
// TODO(jmadill): Remove this.
std::string &getMutableInfoLog() { return mInfoLog; }
private: private:
friend class Shader; friend class Shader;
// TODO(jmadill): Remove this.
friend class rx::ShaderSh;
GLenum mShaderType; GLenum mShaderType;
int mShaderVersion; int mShaderVersion;
std::string mTranslatedSource; std::string mTranslatedSource;
std::string mInfoLog; std::string mSource;
std::vector<sh::Varying> mVaryings; std::vector<sh::Varying> mVaryings;
std::vector<sh::Uniform> mUniforms; std::vector<sh::Uniform> mUniforms;
...@@ -83,7 +78,11 @@ class Shader : angle::NonCopyable ...@@ -83,7 +78,11 @@ class Shader : angle::NonCopyable
std::vector<sh::OutputVariable> mActiveOutputVariables; std::vector<sh::OutputVariable> mActiveOutputVariables;
}; };
Shader(ResourceManager *manager, rx::ImplFactory *implFactory, GLenum type, GLuint handle); Shader(ResourceManager *manager,
rx::ImplFactory *implFactory,
const gl::Limitations &rendererLimitations,
GLenum type,
GLuint handle);
virtual ~Shader(); virtual ~Shader();
...@@ -127,12 +126,13 @@ class Shader : angle::NonCopyable ...@@ -127,12 +126,13 @@ class Shader : angle::NonCopyable
Data mData; Data mData;
rx::ShaderImpl *mImplementation; rx::ShaderImpl *mImplementation;
const gl::Limitations &mRendererLimitations;
const GLuint mHandle; const GLuint mHandle;
const GLenum mType; const GLenum mType;
std::string mSource;
unsigned int mRefCount; // Number of program objects this shader is attached to unsigned int mRefCount; // Number of program objects this shader is attached to
bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use
bool mCompiled; // Indicates if this shader has been successfully compiled bool mCompiled; // Indicates if this shader has been successfully compiled
std::string mInfoLog;
ResourceManager *mResourceManager; ResourceManager *mResourceManager;
}; };
......
...@@ -38,8 +38,7 @@ class ImplFactory : angle::NonCopyable ...@@ -38,8 +38,7 @@ class ImplFactory : angle::NonCopyable
// Shader creation // Shader creation
virtual CompilerImpl *createCompiler() = 0; virtual CompilerImpl *createCompiler() = 0;
// TODO(jmadill): Make const. virtual ShaderImpl *createShader(const gl::Shader::Data &data) = 0;
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
......
...@@ -18,17 +18,18 @@ namespace rx ...@@ -18,17 +18,18 @@ namespace rx
class ShaderImpl : angle::NonCopyable class ShaderImpl : angle::NonCopyable
{ {
public: public:
ShaderImpl(gl::Shader::Data *data) : mData(data) {} ShaderImpl(const gl::Shader::Data &data) : mData(data) {}
virtual ~ShaderImpl() { } virtual ~ShaderImpl() { }
virtual bool compile(gl::Compiler *compiler, // Returns additional ShCompile options.
const std::string &source, virtual int prepareSourceAndReturnOptions(std::stringstream *sourceStream) = 0;
int additionalOptions) = 0; // Returns success for compiling on the driver. Returns success.
virtual bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) = 0;
virtual std::string getDebugInfo() const = 0; virtual std::string getDebugInfo() const = 0;
protected: protected:
// TODO(jmadill): Use a const reference when possible. const gl::Shader::Data &mData;
gl::Shader::Data *mData;
}; };
} }
......
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderSh:
// Common class representing a shader compile with ANGLE's translator.
//
#include "libANGLE/renderer/ShaderSh.h"
#include "common/utilities.h"
#include "libANGLE/Caps.h"
#include "libANGLE/Compiler.h"
namespace rx
{
namespace
{
template <typename VarT>
std::vector<VarT> GetActiveShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
std::vector<VarT> result;
for (size_t varIndex = 0; varIndex < variableList->size(); varIndex++)
{
const VarT &var = variableList->at(varIndex);
if (var.staticUse)
{
result.push_back(var);
}
}
return result;
}
template <typename VarT>
const std::vector<VarT> &GetShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
return *variableList;
}
// true if varying x has a higher priority in packing than y
bool CompareVarying(const sh::Varying &x, const sh::Varying &y)
{
if (x.type == y.type)
{
return x.arraySize > y.arraySize;
}
// Special case for handling structs: we sort these to the end of the list
if (x.type == GL_STRUCT_ANGLEX)
{
return false;
}
if (y.type == GL_STRUCT_ANGLEX)
{
return true;
}
return gl::VariableSortOrder(x.type) < gl::VariableSortOrder(y.type);
}
} // anonymous namespace
ShaderSh::ShaderSh(gl::Shader::Data *data, const gl::Limitations &rendererLimitations)
: ShaderImpl(data), mRendererLimitations(rendererLimitations)
{
}
ShaderSh::~ShaderSh()
{
}
bool ShaderSh::compile(gl::Compiler *compiler, const std::string &source, int additionalOptions)
{
ShHandle compilerHandle = compiler->getCompilerHandle(mData->getShaderType());
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | additionalOptions);
// Some targets (eg D3D11 Feature Level 9_3 and below) do not support non-constant loop indexes
// in fragment shaders. Shader compilation will fail. To provide a better error message we can
// instruct the compiler to pre-validate.
if (mRendererLimitations.shadersRequireIndexedLoopValidation)
{
compileOptions |= SH_VALIDATE_LOOP_INDEXING;
}
const char *sourceCString = source.c_str();
bool result = ShCompile(compilerHandle, &sourceCString, 1, compileOptions);
if (!result)
{
mData->mInfoLog = ShGetInfoLog(compilerHandle);
TRACE("\n%s", mData->mInfoLog.c_str());
return false;
}
mData->mTranslatedSource = ShGetObjectCode(compilerHandle);
#ifndef NDEBUG
// Prefix translated shader with commented out un-translated shader.
// Useful in diagnostics tools which capture the shader source.
std::ostringstream shaderStream;
shaderStream << "// GLSL\n";
shaderStream << "//\n";
size_t curPos = 0;
while (curPos != std::string::npos)
{
size_t nextLine = source.find("\n", curPos);
size_t len = (nextLine == std::string::npos) ? std::string::npos : (nextLine - curPos + 1);
shaderStream << "// " << source.substr(curPos, len);
curPos = (nextLine == std::string::npos) ? std::string::npos : (nextLine + 1);
}
shaderStream << "\n\n";
shaderStream << mData->mTranslatedSource;
mData->mTranslatedSource = shaderStream.str();
#endif
// Gather the shader information
mData->mShaderVersion = ShGetShaderVersion(compilerHandle);
mData->mVaryings = GetShaderVariables(ShGetVaryings(compilerHandle));
mData->mUniforms = GetShaderVariables(ShGetUniforms(compilerHandle));
mData->mInterfaceBlocks = GetShaderVariables(ShGetInterfaceBlocks(compilerHandle));
if (mData->mShaderType == GL_VERTEX_SHADER)
{
mData->mActiveAttributes = GetActiveShaderVariables(ShGetAttributes(compilerHandle));
}
else
{
ASSERT(mData->mShaderType == GL_FRAGMENT_SHADER);
// TODO(jmadill): Figure out why we only sort in the FS, and if we need to.
std::sort(mData->mVaryings.begin(), mData->mVaryings.end(), CompareVarying);
mData->mActiveOutputVariables =
GetActiveShaderVariables(ShGetOutputVariables(compilerHandle));
}
ASSERT(!mData->mTranslatedSource.empty());
return true;
}
} // namespace rx
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderSh:
// Common class representing a shader compile with ANGLE's translator.
// TODO(jmadill): Move this to the GL layer.
//
#ifndef LIBANGLE_RENDERER_SHADERSH_H_
#define LIBANGLE_RENDERER_SHADERSH_H_
#include "libANGLE/renderer/ShaderImpl.h"
namespace gl
{
struct Limitations;
}
namespace rx
{
class ShaderSh : public ShaderImpl
{
public:
ShaderSh(gl::Shader::Data *data, const gl::Limitations &rendererLimitations);
~ShaderSh();
bool compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) override;
protected:
const gl::Limitations &mRendererLimitations;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_SHADERSH_H_
...@@ -39,8 +39,7 @@ const char *GetShaderTypeString(GLenum type) ...@@ -39,8 +39,7 @@ const char *GetShaderTypeString(GLenum type)
namespace rx namespace rx
{ {
ShaderD3D::ShaderD3D(gl::Shader::Data *data, const gl::Limitations &limitations) ShaderD3D::ShaderD3D(const gl::Shader::Data &data) : ShaderImpl(data)
: ShaderSh(data, limitations)
{ {
uncompile(); uncompile();
} }
...@@ -51,7 +50,7 @@ ShaderD3D::~ShaderD3D() ...@@ -51,7 +50,7 @@ ShaderD3D::~ShaderD3D()
std::string ShaderD3D::getDebugInfo() const std::string ShaderD3D::getDebugInfo() const
{ {
return mDebugInfo + std::string("\n// ") + GetShaderTypeString(mData->getShaderType()) + return mDebugInfo + std::string("\n// ") + GetShaderTypeString(mData.getShaderType()) +
" SHADER END\n"; " SHADER END\n";
} }
...@@ -118,39 +117,33 @@ ShShaderOutput ShaderD3D::getCompilerOutputType() const ...@@ -118,39 +117,33 @@ ShShaderOutput ShaderD3D::getCompilerOutputType() const
return mCompilerOutputType; return mCompilerOutputType;
} }
bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int additionalOptionsIn) int ShaderD3D::prepareSourceAndReturnOptions(std::stringstream *shaderSourceStream)
{ {
uncompile(); uncompile();
ShHandle compilerHandle = compiler->getCompilerHandle(mData->getShaderType()); int additionalOptions = 0;
// TODO(jmadill): We shouldn't need to cache this.
mCompilerOutputType = ShGetShaderOutputType(compilerHandle);
int additionalOptions = additionalOptionsIn;
#if !defined(ANGLE_ENABLE_WINDOWS_STORE) #if !defined(ANGLE_ENABLE_WINDOWS_STORE)
const std::string &source = mData.getSource();
std::stringstream sourceStream;
if (gl::DebugAnnotationsActive()) if (gl::DebugAnnotationsActive())
{ {
std::string sourcePath = getTempPath(); std::string sourcePath = getTempPath();
writeFile(sourcePath.c_str(), source.c_str(), source.length()); writeFile(sourcePath.c_str(), source.c_str(), source.length());
additionalOptions |= SH_LINE_DIRECTIVES | SH_SOURCE_PATH; additionalOptions |= SH_LINE_DIRECTIVES | SH_SOURCE_PATH;
sourceStream << sourcePath; *shaderSourceStream << sourcePath;
} }
#endif #endif
*shaderSourceStream << source;
return additionalOptions;
}
sourceStream << source; bool ShaderD3D::postTranslateCompile(gl::Compiler *compiler, std::string *infoLog)
bool result = ShaderSh::compile(compiler, sourceStream.str(), additionalOptions); {
// TODO(jmadill): We shouldn't need to cache this.
if (!result) mCompilerOutputType = compiler->getShaderOutputType();
{
return false;
}
const std::string &translatedSource = mData->getTranslatedSource(); const std::string &translatedSource = mData.getTranslatedSource();
mUsesMultipleRenderTargets = translatedSource.find("GL_USES_MRT") != std::string::npos; mUsesMultipleRenderTargets = translatedSource.find("GL_USES_MRT") != std::string::npos;
mUsesFragColor = translatedSource.find("GL_USES_FRAG_COLOR") != std::string::npos; mUsesFragColor = translatedSource.find("GL_USES_FRAG_COLOR") != std::string::npos;
...@@ -168,7 +161,9 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a ...@@ -168,7 +161,9 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a
mRequiresIEEEStrictCompiling = mRequiresIEEEStrictCompiling =
translatedSource.find("ANGLE_REQUIRES_IEEE_STRICT_COMPILING") != std::string::npos; translatedSource.find("ANGLE_REQUIRES_IEEE_STRICT_COMPILING") != std::string::npos;
for (const sh::Uniform &uniform : mData->getUniforms()) ShHandle compilerHandle = compiler->getCompilerHandle(mData.getShaderType());
for (const sh::Uniform &uniform : mData.getUniforms())
{ {
if (uniform.staticUse && !uniform.isBuiltIn()) if (uniform.staticUse && !uniform.isBuiltIn())
{ {
...@@ -182,7 +177,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a ...@@ -182,7 +177,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source, int a
} }
} }
for (const sh::InterfaceBlock &interfaceBlock : mData->getInterfaceBlocks()) for (const sh::InterfaceBlock &interfaceBlock : mData.getInterfaceBlocks())
{ {
if (interfaceBlock.staticUse) if (interfaceBlock.staticUse)
{ {
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#ifndef LIBANGLE_RENDERER_D3D_SHADERD3D_H_ #ifndef LIBANGLE_RENDERER_D3D_SHADERD3D_H_
#define LIBANGLE_RENDERER_D3D_SHADERD3D_H_ #define LIBANGLE_RENDERER_D3D_SHADERD3D_H_
#include "libANGLE/renderer/ShaderSh.h" #include "libANGLE/renderer/ShaderImpl.h"
#include <map> #include <map>
...@@ -19,16 +19,17 @@ class DynamicHLSL; ...@@ -19,16 +19,17 @@ class DynamicHLSL;
class RendererD3D; class RendererD3D;
struct D3DCompilerWorkarounds; struct D3DCompilerWorkarounds;
class ShaderD3D : public ShaderSh class ShaderD3D : public ShaderImpl
{ {
friend class DynamicHLSL; friend class DynamicHLSL;
public: public:
ShaderD3D(gl::Shader::Data *data, const gl::Limitations &limitations); ShaderD3D(const gl::Shader::Data &data);
virtual ~ShaderD3D(); virtual ~ShaderD3D();
// ShaderImpl implementation // ShaderImpl implementation
bool compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) override; int prepareSourceAndReturnOptions(std::stringstream *sourceStream) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override;
std::string getDebugInfo() const override; std::string getDebugInfo() const override;
// D3D-specific methods // D3D-specific methods
...@@ -64,7 +65,6 @@ class ShaderD3D : public ShaderSh ...@@ -64,7 +65,6 @@ class ShaderD3D : public ShaderSh
std::string mDebugInfo; std::string mDebugInfo;
std::map<std::string, unsigned int> mUniformRegisterMap; std::map<std::string, unsigned int> mUniformRegisterMap;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap; std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
RendererD3D *mRenderer;
}; };
} }
......
...@@ -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(gl::Shader::Data *data) ShaderImpl *Renderer11::createShader(const gl::Shader::Data &data)
{ {
return new ShaderD3D(data, getRendererLimitations()); return new ShaderD3D(data);
} }
ProgramImpl *Renderer11::createProgram(const gl::Program::Data &data) ProgramImpl *Renderer11::createProgram(const gl::Program::Data &data)
......
...@@ -182,7 +182,7 @@ class Renderer11 : public RendererD3D ...@@ -182,7 +182,7 @@ class Renderer11 : public RendererD3D
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
ShaderImpl *createShader(gl::Shader::Data *data) override; ShaderImpl *createShader(const gl::Shader::Data &data) override;
ProgramImpl *createProgram(const gl::Program::Data &data) override; ProgramImpl *createProgram(const gl::Program::Data &data) override;
// Shader operations // Shader operations
......
...@@ -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(gl::Shader::Data *data) ShaderImpl *Renderer9::createShader(const gl::Shader::Data &data)
{ {
return new ShaderD3D(data, getRendererLimitations()); return new ShaderD3D(data);
} }
ProgramImpl *Renderer9::createProgram(const gl::Program::Data &data) ProgramImpl *Renderer9::createProgram(const gl::Program::Data &data)
......
...@@ -169,7 +169,7 @@ class Renderer9 : public RendererD3D ...@@ -169,7 +169,7 @@ class Renderer9 : public RendererD3D
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
ShaderImpl *createShader(gl::Shader::Data *data) override; ShaderImpl *createShader(const gl::Shader::Data &data) override;
ProgramImpl *createProgram(const gl::Program::Data &data) override; ProgramImpl *createProgram(const gl::Program::Data &data) override;
// Shader operations // Shader operations
......
...@@ -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(gl::Shader::Data *data) ShaderImpl *RendererGL::createShader(const gl::Shader::Data &data)
{ {
return new ShaderGL(data, getRendererLimitations(), mFunctions); return new ShaderGL(data, 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(gl::Shader::Data *data) override; ShaderImpl *createShader(const 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,8 @@ ...@@ -16,10 +16,8 @@
namespace rx namespace rx
{ {
ShaderGL::ShaderGL(gl::Shader::Data *data, ShaderGL::ShaderGL(const gl::Shader::Data &data, const FunctionsGL *functions)
const gl::Limitations &rendererLimitations, : ShaderImpl(data), mFunctions(functions), mShaderID(0)
const FunctionsGL *functions)
: ShaderSh(data, rendererLimitations), mFunctions(functions), mShaderID(0)
{ {
ASSERT(mFunctions); ASSERT(mFunctions);
} }
...@@ -33,7 +31,7 @@ ShaderGL::~ShaderGL() ...@@ -33,7 +31,7 @@ ShaderGL::~ShaderGL()
} }
} }
bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int additionalOptionsIn) int ShaderGL::prepareSourceAndReturnOptions(std::stringstream *sourceStream)
{ {
// Reset the previous state // Reset the previous state
if (mShaderID != 0) if (mShaderID != 0)
...@@ -42,17 +40,18 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad ...@@ -42,17 +40,18 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad
mShaderID = 0; mShaderID = 0;
} }
int additionalOptions = (additionalOptionsIn | SH_INIT_GL_POSITION); *sourceStream << mData.getSource();
if (!ShaderSh::compile(compiler, source, additionalOptions))
{
return false;
}
return SH_INIT_GL_POSITION;
}
bool ShaderGL::postTranslateCompile(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();
// Generate a shader object and set the source // Generate a shader object and set the source
mShaderID = mFunctions->createShader(mData->getShaderType()); mShaderID = mFunctions->createShader(mData.getShaderType());
mFunctions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr); mFunctions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr);
mFunctions->compileShader(mShaderID); mFunctions->compileShader(mShaderID);
...@@ -72,9 +71,8 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad ...@@ -72,9 +71,8 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source, int ad
mFunctions->deleteShader(mShaderID); mFunctions->deleteShader(mShaderID);
mShaderID = 0; mShaderID = 0;
// TODO(jmadill): possibly pass in info log? *infoLog = &buf[0];
mData->getMutableInfoLog() = &buf[0]; TRACE("\n%s", infoLog->c_str());
TRACE("\n%s", mData->getMutableInfoLog().c_str());
return false; return false;
} }
......
...@@ -9,22 +9,21 @@ ...@@ -9,22 +9,21 @@
#ifndef LIBANGLE_RENDERER_GL_SHADERGL_H_ #ifndef LIBANGLE_RENDERER_GL_SHADERGL_H_
#define LIBANGLE_RENDERER_GL_SHADERGL_H_ #define LIBANGLE_RENDERER_GL_SHADERGL_H_
#include "libANGLE/renderer/ShaderSh.h" #include "libANGLE/renderer/ShaderImpl.h"
namespace rx namespace rx
{ {
class FunctionsGL; class FunctionsGL;
class RendererGL;
class ShaderGL : public ShaderSh class ShaderGL : public ShaderImpl
{ {
public: public:
ShaderGL(gl::Shader::Data *data, ShaderGL(const gl::Shader::Data &data, const FunctionsGL *functions);
const gl::Limitations &rendererLimitations,
const FunctionsGL *functions);
~ShaderGL() override; ~ShaderGL() override;
bool compile(gl::Compiler *compiler, const std::string &source, int additionalOptions) override; // ShaderImpl implementation
int prepareSourceAndReturnOptions(std::stringstream *sourceStream) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override;
std::string getDebugInfo() const override; std::string getDebugInfo() const override;
GLuint getShaderID() const; GLuint getShaderID() const;
......
...@@ -147,8 +147,6 @@ ...@@ -147,8 +147,6 @@
'libANGLE/renderer/Renderer.cpp', 'libANGLE/renderer/Renderer.cpp',
'libANGLE/renderer/Renderer.h', 'libANGLE/renderer/Renderer.h',
'libANGLE/renderer/ShaderImpl.h', 'libANGLE/renderer/ShaderImpl.h',
'libANGLE/renderer/ShaderSh.cpp',
'libANGLE/renderer/ShaderSh.h',
'libANGLE/renderer/SurfaceImpl.cpp', 'libANGLE/renderer/SurfaceImpl.cpp',
'libANGLE/renderer/SurfaceImpl.h', 'libANGLE/renderer/SurfaceImpl.h',
'libANGLE/renderer/TextureImpl.h', 'libANGLE/renderer/TextureImpl.h',
......
...@@ -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(gl::Shader::Data *data) override { return nullptr; } ShaderImpl *createShader(const 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