Commit 245d3602 by Jamie Madill

Pass GL context data into shader creation.

This allows us to remove the hack where we store the current GL client version in the Renderer. BUG=angle:789 Change-Id: I6526f11eaa922325a9a41df0df48b2152e022e26 Reviewed-on: https://chromium-review.googlesource.com/227713Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 80bacde5
...@@ -236,7 +236,7 @@ GLuint Context::createProgram() ...@@ -236,7 +236,7 @@ GLuint Context::createProgram()
GLuint Context::createShader(GLenum type) GLuint Context::createShader(GLenum type)
{ {
return mResourceManager->createShader(type); return mResourceManager->createShader(getData(), 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(GLenum type) GLuint ResourceManager::createShader(const gl::Data &data, 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, mRenderer->createShader(type), type, handle); mShaderMap[handle] = new Shader(this, mRenderer->createShader(data, type), type, handle);
} }
else UNREACHABLE(); else UNREACHABLE();
......
...@@ -32,6 +32,7 @@ class Texture; ...@@ -32,6 +32,7 @@ class Texture;
class Renderbuffer; class Renderbuffer;
class Sampler; class Sampler;
class FenceSync; class FenceSync;
struct Data;
class ResourceManager class ResourceManager
{ {
...@@ -43,7 +44,7 @@ class ResourceManager ...@@ -43,7 +44,7 @@ class ResourceManager
void release(); void release();
GLuint createBuffer(); GLuint createBuffer();
GLuint createShader(GLenum type); GLuint createShader(const gl::Data &data, GLenum type);
GLuint createProgram(); GLuint createProgram();
GLuint createTexture(); GLuint createTexture();
GLuint createRenderbuffer(); GLuint createRenderbuffer();
......
...@@ -124,9 +124,9 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length, ...@@ -124,9 +124,9 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length,
getSourceImpl(debugInfo, bufSize, length, buffer); getSourceImpl(debugInfo, bufSize, length, buffer);
} }
void Shader::compile() void Shader::compile(const gl::Data &data)
{ {
mCompiled = mShader->compile(mSource); mCompiled = mShader->compile(data, mSource);
} }
void Shader::addRef() void Shader::addRef()
......
...@@ -31,6 +31,7 @@ class ShaderImpl; ...@@ -31,6 +31,7 @@ class ShaderImpl;
namespace gl namespace gl
{ {
class ResourceManager; class ResourceManager;
struct Data;
struct PackedVarying : public sh::Varying struct PackedVarying : public sh::Varying
{ {
...@@ -75,7 +76,7 @@ class Shader ...@@ -75,7 +76,7 @@ class Shader
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;
void compile(); void compile(const gl::Data &data);
bool isCompiled() const { return mCompiled; } bool isCompiled() const { return mCompiled; }
void addRef(); void addRef();
......
...@@ -728,7 +728,7 @@ void GL_APIENTRY glCompileShader(GLuint shader) ...@@ -728,7 +728,7 @@ void GL_APIENTRY glCompileShader(GLuint shader)
} }
} }
shaderObject->compile(); shaderObject->compile(context->getData());
} }
} }
......
...@@ -104,7 +104,7 @@ class Renderer ...@@ -104,7 +104,7 @@ class Renderer
virtual bool getPostSubBufferSupport() const = 0; virtual bool getPostSubBufferSupport() const = 0;
// Shader creation // Shader creation
virtual ShaderImpl *createShader(GLenum type) = 0; virtual ShaderImpl *createShader(const gl::Data &data, GLenum type) = 0;
virtual ProgramImpl *createProgram() = 0; virtual ProgramImpl *createProgram() = 0;
// Shader operations // Shader operations
......
...@@ -23,7 +23,7 @@ class ShaderImpl ...@@ -23,7 +23,7 @@ class ShaderImpl
ShaderImpl() { } ShaderImpl() { }
virtual ~ShaderImpl() { } virtual ~ShaderImpl() { }
virtual bool compile(const std::string &source) = 0; virtual bool compile(const gl::Data &data, const std::string &source) = 0;
virtual const std::string &getInfoLog() const = 0; virtual const std::string &getInfoLog() const = 0;
virtual const std::string &getTranslatedSource() const = 0; virtual const std::string &getTranslatedSource() const = 0;
virtual std::string getDebugInfo() const = 0; virtual std::string getDebugInfo() const = 0;
......
...@@ -67,13 +67,13 @@ const std::vector<VarT> *GetShaderVariables(const std::vector<VarT> *variableLis ...@@ -67,13 +67,13 @@ const std::vector<VarT> *GetShaderVariables(const std::vector<VarT> *variableLis
return variableList; return variableList;
} }
ShaderD3D::ShaderD3D(GLenum type, RendererD3D *renderer) ShaderD3D::ShaderD3D(const gl::Data &data, GLenum type, RendererD3D *renderer)
: mType(type), : mType(type),
mRenderer(renderer), mRenderer(renderer),
mShaderVersion(100) mShaderVersion(100)
{ {
uncompile(); uncompile();
initializeCompiler(); initializeCompiler(data);
} }
ShaderD3D::~ShaderD3D() ShaderD3D::~ShaderD3D()
...@@ -98,7 +98,7 @@ std::string ShaderD3D::getDebugInfo() const ...@@ -98,7 +98,7 @@ std::string ShaderD3D::getDebugInfo() const
} }
// Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler) // Perform a one-time initialization of the shader compiler (or after being destructed by releaseCompiler)
void ShaderD3D::initializeCompiler() void ShaderD3D::initializeCompiler(const gl::Data &data)
{ {
if (!mFragmentCompiler) if (!mFragmentCompiler)
{ {
...@@ -106,15 +106,14 @@ void ShaderD3D::initializeCompiler() ...@@ -106,15 +106,14 @@ void ShaderD3D::initializeCompiler()
if (result) if (result)
{ {
ShShaderSpec specVersion = (mRenderer->getCurrentClientVersion() >= 3) ? SH_GLES3_SPEC : SH_GLES2_SPEC; ShShaderSpec specVersion = (data.clientVersion >= 3) ? SH_GLES3_SPEC : SH_GLES2_SPEC;
ShShaderOutput hlslVersion = (mRenderer->getMajorShaderModel() >= 4) ? SH_HLSL11_OUTPUT : SH_HLSL9_OUTPUT; ShShaderOutput hlslVersion = (mRenderer->getMajorShaderModel() >= 4) ? SH_HLSL11_OUTPUT : SH_HLSL9_OUTPUT;
ShBuiltInResources resources; ShBuiltInResources resources;
ShInitBuiltInResources(&resources); ShInitBuiltInResources(&resources);
// TODO(geofflang): use context's caps const gl::Caps &caps = *data.caps;
const gl::Caps &caps = mRenderer->getRendererCaps(); const gl::Extensions &extensions = *data.extensions;
const gl::Extensions &extensions = mRenderer->getRendererExtensions();
resources.MaxVertexAttribs = caps.maxVertexAttributes; resources.MaxVertexAttribs = caps.maxVertexAttributes;
resources.MaxVertexUniformVectors = caps.maxVertexUniformVectors; resources.MaxVertexUniformVectors = caps.maxVertexUniformVectors;
...@@ -215,10 +214,10 @@ void ShaderD3D::uncompile() ...@@ -215,10 +214,10 @@ void ShaderD3D::uncompile()
mDebugInfo.clear(); mDebugInfo.clear();
} }
void ShaderD3D::compileToHLSL(void *compiler, const std::string &source) void ShaderD3D::compileToHLSL(const gl::Data &data, void *compiler, const std::string &source)
{ {
// ensure the compiler is loaded // ensure the compiler is loaded
initializeCompiler(); initializeCompiler(data);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES); int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES);
std::string sourcePath; std::string sourcePath;
...@@ -255,7 +254,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source) ...@@ -255,7 +254,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
mShaderVersion = ShGetShaderVersion(compiler); mShaderVersion = ShGetShaderVersion(compiler);
if (mShaderVersion == 300 && mRenderer->getCurrentClientVersion() < 3) if (mShaderVersion == 300 && data.clientVersion < 3)
{ {
mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts"; mInfoLog = "GLSL ES 3.00 is not supported by OpenGL ES 2.0 contexts";
TRACE("\n%s", mInfoLog.c_str()); TRACE("\n%s", mInfoLog.c_str());
...@@ -409,13 +408,13 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader) ...@@ -409,13 +408,13 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader)
return ShGetShaderOutputType(compiler); return ShGetShaderOutputType(compiler);
} }
bool ShaderD3D::compile(const std::string &source) bool ShaderD3D::compile(const gl::Data &data, const std::string &source)
{ {
uncompile(); uncompile();
void *compiler = getCompiler(); void *compiler = getCompiler();
compileToHLSL(compiler, source); compileToHLSL(data, compiler, source);
if (mType == GL_VERTEX_SHADER) if (mType == GL_VERTEX_SHADER)
{ {
......
...@@ -25,7 +25,7 @@ class ShaderD3D : public ShaderImpl ...@@ -25,7 +25,7 @@ class ShaderD3D : public ShaderImpl
friend class DynamicHLSL; friend class DynamicHLSL;
public: public:
ShaderD3D(GLenum type, rx::RendererD3D *renderer); ShaderD3D(const gl::Data &data, GLenum type, rx::RendererD3D *renderer);
virtual ~ShaderD3D(); virtual ~ShaderD3D();
static ShaderD3D *makeShaderD3D(ShaderImpl *impl); static ShaderD3D *makeShaderD3D(ShaderImpl *impl);
...@@ -52,15 +52,15 @@ class ShaderD3D : public ShaderImpl ...@@ -52,15 +52,15 @@ class ShaderD3D : public ShaderImpl
static void releaseCompiler(); static void releaseCompiler();
static ShShaderOutput getCompilerOutputType(GLenum shader); static ShShaderOutput getCompilerOutputType(GLenum shader);
virtual bool compile(const std::string &source); virtual bool compile(const gl::Data &data, const std::string &source);
private: private:
DISALLOW_COPY_AND_ASSIGN(ShaderD3D); DISALLOW_COPY_AND_ASSIGN(ShaderD3D);
void compileToHLSL(void *compiler, const std::string &source); void compileToHLSL(const gl::Data &data, void *compiler, const std::string &source);
void parseVaryings(void *compiler); void parseVaryings(void *compiler);
void initializeCompiler(); void initializeCompiler(const gl::Data &data);
void parseAttributes(void *compiler); void parseAttributes(void *compiler);
void *getCompiler(); void *getCompiler();
......
...@@ -2329,9 +2329,9 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -2329,9 +2329,9 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
ShaderImpl *Renderer11::createShader(GLenum type) ShaderImpl *Renderer11::createShader(const gl::Data &data, GLenum type)
{ {
return new ShaderD3D(type, this); return new ShaderD3D(data, type, this);
} }
ProgramImpl *Renderer11::createProgram() ProgramImpl *Renderer11::createProgram()
......
...@@ -138,7 +138,7 @@ class Renderer11 : public RendererD3D ...@@ -138,7 +138,7 @@ class Renderer11 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT); virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT);
// Shader creation // Shader creation
virtual ShaderImpl *createShader(GLenum type); virtual ShaderImpl *createShader(const gl::Data &data, GLenum type);
virtual ProgramImpl *createProgram(); virtual ProgramImpl *createProgram();
// Shader operations // Shader operations
......
...@@ -2868,9 +2868,9 @@ gl::Error Renderer9::createRenderTarget(int width, int height, GLenum format, GL ...@@ -2868,9 +2868,9 @@ gl::Error Renderer9::createRenderTarget(int width, int height, GLenum format, GL
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
ShaderImpl *Renderer9::createShader(GLenum type) ShaderImpl *Renderer9::createShader(const gl::Data &data, GLenum type)
{ {
return new ShaderD3D(type, this); return new ShaderD3D(data, type, this);
} }
ProgramImpl *Renderer9::createProgram() ProgramImpl *Renderer9::createProgram()
......
...@@ -146,7 +146,7 @@ class Renderer9 : public RendererD3D ...@@ -146,7 +146,7 @@ class Renderer9 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT); virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT);
// Shader creation // Shader creation
virtual ShaderImpl *createShader(GLenum type); virtual ShaderImpl *createShader(const gl::Data &data, GLenum type);
virtual ProgramImpl *createProgram(); virtual ProgramImpl *createProgram();
// Shader operations // Shader operations
......
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