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