Commit c415283b by Geoff Lang

Implement CompilerGL.

BUG=angle:882 Change-Id: I6fd426b19677b51f4df74d495acc9a6fde9822e8 Reviewed-on: https://chromium-review.googlesource.com/251540Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 29190088
...@@ -9,21 +9,113 @@ ...@@ -9,21 +9,113 @@
#include "libANGLE/renderer/gl/CompilerGL.h" #include "libANGLE/renderer/gl/CompilerGL.h"
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Caps.h"
#include "libANGLE/Data.h"
namespace rx namespace rx
{ {
CompilerGL::CompilerGL() // Global count of active shader compiler handles. Needed to know when to call ShInitialize and ShFinalize.
: CompilerImpl() static size_t activeCompilerHandles = 0;
{}
CompilerGL::CompilerGL(const gl::Data &data)
: CompilerImpl(),
mSpec(data.clientVersion > 2 ? SH_GLES3_SPEC : SH_GLES2_SPEC),
mResources(),
mFragmentCompiler(nullptr),
mVertexCompiler(nullptr)
{
ASSERT(data.clientVersion == 2 || data.clientVersion == 3);
const gl::Caps &caps = *data.caps;
const gl::Extensions &extensions = *data.extensions;
ShInitBuiltInResources(&mResources);
mResources.MaxVertexAttribs = caps.maxVertexAttributes;
mResources.MaxVertexUniformVectors = caps.maxVertexUniformVectors;
mResources.MaxVaryingVectors = caps.maxVaryingVectors;
mResources.MaxVertexTextureImageUnits = caps.maxVertexTextureImageUnits;
mResources.MaxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits;
mResources.MaxTextureImageUnits = caps.maxTextureImageUnits;
mResources.MaxFragmentUniformVectors = caps.maxFragmentUniformVectors;
mResources.MaxDrawBuffers = caps.maxDrawBuffers;
mResources.OES_standard_derivatives = extensions.standardDerivatives;
mResources.EXT_draw_buffers = extensions.drawBuffers;
mResources.EXT_shader_texture_lod = extensions.shaderTextureLOD;
mResources.OES_EGL_image_external = 0; // TODO: disabled until the extension is actually supported.
mResources.FragmentPrecisionHigh = 1; // TODO: use shader precision caps to determine if high precision is supported?
mResources.EXT_frag_depth = extensions.fragDepth;
// GLSL ES 3.0 constants
mResources.MaxVertexOutputVectors = caps.maxVertexOutputComponents / 4;
mResources.MaxFragmentInputVectors = caps.maxFragmentInputComponents / 4;
mResources.MinProgramTexelOffset = caps.minProgramTexelOffset;
mResources.MaxProgramTexelOffset = caps.maxProgramTexelOffset;
}
CompilerGL::~CompilerGL() CompilerGL::~CompilerGL()
{} {
release();
}
gl::Error CompilerGL::release() gl::Error CompilerGL::release()
{ {
UNIMPLEMENTED(); if (mFragmentCompiler)
return gl::Error(GL_INVALID_OPERATION); {
ShDestruct(mFragmentCompiler);
mFragmentCompiler = NULL;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (mVertexCompiler)
{
ShDestruct(mVertexCompiler);
mVertexCompiler = NULL;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (activeCompilerHandles == 0)
{
ShFinalize();
}
return gl::Error(GL_NO_ERROR);
}
ShHandle CompilerGL::getCompilerHandle(GLenum type)
{
ShHandle *compiler = NULL;
switch (type)
{
case GL_VERTEX_SHADER:
compiler = &mVertexCompiler;
break;
case GL_FRAGMENT_SHADER:
compiler = &mFragmentCompiler;
break;
default:
UNREACHABLE();
return NULL;
}
if ((*compiler) == nullptr)
{
if (activeCompilerHandles == 0)
{
ShInitialize();
}
*compiler = ShConstructCompiler(type, mSpec, SH_GLSL_OUTPUT, &mResources);
activeCompilerHandles++;
}
return *compiler;
} }
} }
...@@ -11,19 +11,35 @@ ...@@ -11,19 +11,35 @@
#include "libANGLE/renderer/CompilerImpl.h" #include "libANGLE/renderer/CompilerImpl.h"
#include "GLSLANG/ShaderLang.h"
namespace gl
{
struct Data;
}
namespace rx namespace rx
{ {
class CompilerGL : public CompilerImpl class CompilerGL : public CompilerImpl
{ {
public: public:
CompilerGL(); CompilerGL(const gl::Data &data);
~CompilerGL() override; ~CompilerGL() override;
gl::Error release() override; gl::Error release() override;
ShHandle getCompilerHandle(GLenum type);
private: private:
DISALLOW_COPY_AND_ASSIGN(CompilerGL); DISALLOW_COPY_AND_ASSIGN(CompilerGL);
ShShaderSpec mSpec;
ShShaderOutput mOutputType;
ShBuiltInResources mResources;
ShHandle mFragmentCompiler;
ShHandle mVertexCompiler;
}; };
} }
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "libANGLE/renderer/gl/RendererGL.h" #include "libANGLE/renderer/gl/RendererGL.h"
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Data.h"
#include "libANGLE/renderer/gl/BufferGL.h" #include "libANGLE/renderer/gl/BufferGL.h"
#include "libANGLE/renderer/gl/CompilerGL.h" #include "libANGLE/renderer/gl/CompilerGL.h"
#include "libANGLE/renderer/gl/DefaultAttachmentGL.h" #include "libANGLE/renderer/gl/DefaultAttachmentGL.h"
...@@ -66,7 +67,7 @@ gl::Error RendererGL::drawElements(const gl::Data &data, GLenum mode, GLsizei co ...@@ -66,7 +67,7 @@ gl::Error RendererGL::drawElements(const gl::Data &data, GLenum mode, GLsizei co
CompilerImpl *RendererGL::createCompiler(const gl::Data &data) CompilerImpl *RendererGL::createCompiler(const gl::Data &data)
{ {
return new CompilerGL(); return new CompilerGL(data);
} }
ShaderImpl *RendererGL::createShader(GLenum type) ShaderImpl *RendererGL::createShader(GLenum type)
......
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