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()
GLuint Context::createShader(GLenum type)
{
return mResourceManager->createShader(type);
return mResourceManager->createShader(getData(), type);
}
GLuint Context::createTexture()
......
......@@ -88,13 +88,13 @@ GLuint ResourceManager::createBuffer()
}
// Returns an unused shader/program name
GLuint ResourceManager::createShader(GLenum type)
GLuint ResourceManager::createShader(const gl::Data &data, GLenum type)
{
GLuint handle = mProgramShaderHandleAllocator.allocate();
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();
......
......@@ -32,6 +32,7 @@ class Texture;
class Renderbuffer;
class Sampler;
class FenceSync;
struct Data;
class ResourceManager
{
......@@ -43,7 +44,7 @@ class ResourceManager
void release();
GLuint createBuffer();
GLuint createShader(GLenum type);
GLuint createShader(const gl::Data &data, GLenum type);
GLuint createProgram();
GLuint createTexture();
GLuint createRenderbuffer();
......
......@@ -124,9 +124,9 @@ void Shader::getTranslatedSourceWithDebugInfo(GLsizei bufSize, GLsizei *length,
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()
......
......@@ -31,6 +31,7 @@ class ShaderImpl;
namespace gl
{
class ResourceManager;
struct Data;
struct PackedVarying : public sh::Varying
{
......@@ -75,7 +76,7 @@ class Shader
void getTranslatedSource(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; }
void addRef();
......
......@@ -728,7 +728,7 @@ void GL_APIENTRY glCompileShader(GLuint shader)
}
}
shaderObject->compile();
shaderObject->compile(context->getData());
}
}
......
......@@ -104,7 +104,7 @@ class Renderer
virtual bool getPostSubBufferSupport() const = 0;
// Shader creation
virtual ShaderImpl *createShader(GLenum type) = 0;
virtual ShaderImpl *createShader(const gl::Data &data, GLenum type) = 0;
virtual ProgramImpl *createProgram() = 0;
// Shader operations
......
......@@ -23,7 +23,7 @@ class ShaderImpl
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 &getTranslatedSource() const = 0;
virtual std::string getDebugInfo() const = 0;
......
......@@ -67,13 +67,13 @@ const std::vector<VarT> *GetShaderVariables(const std::vector<VarT> *variableLis
return variableList;
}
ShaderD3D::ShaderD3D(GLenum type, RendererD3D *renderer)
ShaderD3D::ShaderD3D(const gl::Data &data, GLenum type, RendererD3D *renderer)
: mType(type),
mRenderer(renderer),
mShaderVersion(100)
{
uncompile();
initializeCompiler();
initializeCompiler(data);
}
ShaderD3D::~ShaderD3D()
......@@ -98,7 +98,7 @@ std::string ShaderD3D::getDebugInfo() const
}
// 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)
{
......@@ -106,15 +106,14 @@ void ShaderD3D::initializeCompiler()
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;
ShBuiltInResources resources;
ShInitBuiltInResources(&resources);
// TODO(geofflang): use context's caps
const gl::Caps &caps = mRenderer->getRendererCaps();
const gl::Extensions &extensions = mRenderer->getRendererExtensions();
const gl::Caps &caps = *data.caps;
const gl::Extensions &extensions = *data.extensions;
resources.MaxVertexAttribs = caps.maxVertexAttributes;
resources.MaxVertexUniformVectors = caps.maxVertexUniformVectors;
......@@ -215,10 +214,10 @@ void ShaderD3D::uncompile()
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
initializeCompiler();
initializeCompiler(data);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES);
std::string sourcePath;
......@@ -255,7 +254,7 @@ void ShaderD3D::compileToHLSL(void *compiler, const std::string &source)
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";
TRACE("\n%s", mInfoLog.c_str());
......@@ -409,13 +408,13 @@ ShShaderOutput ShaderD3D::getCompilerOutputType(GLenum shader)
return ShGetShaderOutputType(compiler);
}
bool ShaderD3D::compile(const std::string &source)
bool ShaderD3D::compile(const gl::Data &data, const std::string &source)
{
uncompile();
void *compiler = getCompiler();
compileToHLSL(compiler, source);
compileToHLSL(data, compiler, source);
if (mType == GL_VERTEX_SHADER)
{
......
......@@ -25,7 +25,7 @@ class ShaderD3D : public ShaderImpl
friend class DynamicHLSL;
public:
ShaderD3D(GLenum type, rx::RendererD3D *renderer);
ShaderD3D(const gl::Data &data, GLenum type, rx::RendererD3D *renderer);
virtual ~ShaderD3D();
static ShaderD3D *makeShaderD3D(ShaderImpl *impl);
......@@ -52,15 +52,15 @@ class ShaderD3D : public ShaderImpl
static void releaseCompiler();
static ShShaderOutput getCompilerOutputType(GLenum shader);
virtual bool compile(const std::string &source);
virtual bool compile(const gl::Data &data, const std::string &source);
private:
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 initializeCompiler();
void initializeCompiler(const gl::Data &data);
void parseAttributes(void *compiler);
void *getCompiler();
......
......@@ -2329,9 +2329,9 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
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()
......
......@@ -138,7 +138,7 @@ class Renderer11 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT);
// Shader creation
virtual ShaderImpl *createShader(GLenum type);
virtual ShaderImpl *createShader(const gl::Data &data, GLenum type);
virtual ProgramImpl *createProgram();
// Shader operations
......
......@@ -2868,9 +2868,9 @@ gl::Error Renderer9::createRenderTarget(int width, int height, GLenum format, GL
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()
......
......@@ -146,7 +146,7 @@ class Renderer9 : public RendererD3D
virtual gl::Error createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTarget **outRT);
// Shader creation
virtual ShaderImpl *createShader(GLenum type);
virtual ShaderImpl *createShader(const gl::Data &data, GLenum type);
virtual ProgramImpl *createProgram();
// 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