Commit 83f349ea by Jamie Madill

Remove CompilerImpl and merge code to gl::Compiler.

This class uses no Impl-specific code. We can also do a similar code relocation for the gl::Shader class, but in several steps because it is a bit more complex. BUG=angleproject:1159 Change-Id: I4d3ce3253df0a2bdee1d98e46cfd4b999d86be6e Reviewed-on: https://chromium-review.googlesource.com/299874Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 6cbf4385
...@@ -7,32 +7,128 @@ ...@@ -7,32 +7,128 @@
// Compiler.cpp: implements the gl::Compiler class. // Compiler.cpp: implements the gl::Compiler class.
#include "libANGLE/Compiler.h" #include "libANGLE/Compiler.h"
#include "libANGLE/renderer/CompilerImpl.h"
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Data.h"
#include "libANGLE/renderer/CompilerImpl.h"
#include "libANGLE/renderer/ImplFactory.h"
namespace gl namespace gl
{ {
Compiler::Compiler(rx::CompilerImpl *impl) namespace
: mCompiler(impl) {
// Global count of active shader compiler handles. Needed to know when to call ShInitialize and
// ShFinalize.
size_t activeCompilerHandles = 0;
} // anonymous namespace
Compiler::Compiler(rx::ImplFactory *implFactory, const gl::Data &data)
: mImplementation(implFactory->createCompiler()),
mSpec(data.clientVersion > 2 ? SH_GLES3_SPEC : SH_GLES2_SPEC),
mOutputType(mImplementation->getTranslatorOutputType()),
mResources(),
mFragmentCompiler(nullptr),
mVertexCompiler(nullptr)
{ {
ASSERT(mCompiler); 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;
// TODO: disabled until the extension is actually supported.
mResources.OES_EGL_image_external = 0;
// TODO: use shader precision caps to determine if high precision is supported?
mResources.FragmentPrecisionHigh = 1;
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;
} }
Compiler::~Compiler() Compiler::~Compiler()
{ {
SafeDelete(mCompiler); release();
SafeDelete(mImplementation);
} }
Error Compiler::release() Error Compiler::release()
{ {
return mCompiler->release(); if (mFragmentCompiler)
{
ShDestruct(mFragmentCompiler);
mFragmentCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (mVertexCompiler)
{
ShDestruct(mVertexCompiler);
mVertexCompiler = nullptr;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (activeCompilerHandles == 0)
{
ShFinalize();
}
mImplementation->release();
return gl::Error(GL_NO_ERROR);
} }
rx::CompilerImpl *Compiler::getImplementation() ShHandle Compiler::getCompilerHandle(GLenum type)
{ {
return mCompiler; ShHandle *compiler = nullptr;
} switch (type)
{
case GL_VERTEX_SHADER:
compiler = &mVertexCompiler;
break;
case GL_FRAGMENT_SHADER:
compiler = &mFragmentCompiler;
break;
default:
UNREACHABLE();
return nullptr;
}
if (!(*compiler))
{
if (activeCompilerHandles == 0)
{
ShInitialize();
}
*compiler = ShConstructCompiler(type, mSpec, mOutputType, &mResources);
activeCompilerHandles++;
}
return *compiler;
} }
} // namespace gl
...@@ -11,29 +11,39 @@ ...@@ -11,29 +11,39 @@
#define LIBANGLE_COMPILER_H_ #define LIBANGLE_COMPILER_H_
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#include "GLSLANG/ShaderLang.h"
namespace rx namespace rx
{ {
class CompilerImpl; class CompilerImpl;
class ImplFactory;
} }
namespace gl namespace gl
{ {
struct Data;
class Compiler final class Compiler final : angle::NonCopyable
{ {
public: public:
explicit Compiler(rx::CompilerImpl *impl); Compiler(rx::ImplFactory *implFactory, const Data &data);
~Compiler(); ~Compiler();
Error release(); Error release();
rx::CompilerImpl *getImplementation(); ShHandle getCompilerHandle(GLenum type);
ShShaderOutput getShaderOutputType() const { return mOutputType; }
private: private:
rx::CompilerImpl *mCompiler; rx::CompilerImpl *mImplementation;
ShShaderSpec mSpec;
ShShaderOutput mOutputType;
ShBuiltInResources mResources;
ShHandle mFragmentCompiler;
ShHandle mVertexCompiler;
}; };
} } // namespace gl
#endif // LIBANGLE_COMPILER_H_ #endif // LIBANGLE_COMPILER_H_
...@@ -145,7 +145,7 @@ Context::Context(const egl::Config *config, ...@@ -145,7 +145,7 @@ Context::Context(const egl::Config *config,
mResetStrategy = (notifyResets ? GL_LOSE_CONTEXT_ON_RESET_EXT : GL_NO_RESET_NOTIFICATION_EXT); mResetStrategy = (notifyResets ? GL_LOSE_CONTEXT_ON_RESET_EXT : GL_NO_RESET_NOTIFICATION_EXT);
mRobustAccess = robustAccess; mRobustAccess = robustAccess;
mCompiler = new Compiler(mRenderer->createCompiler(getData())); mCompiler = new Compiler(mRenderer, getData());
} }
Context::~Context() Context::~Context()
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
// for the gl::Compiler object. // for the gl::Compiler object.
#include "common/angleutils.h" #include "common/angleutils.h"
#include "GLSLANG/ShaderLang.h"
#include "libANGLE/Error.h" #include "libANGLE/Error.h"
#ifndef LIBANGLE_RENDERER_COMPILERIMPL_H_ #ifndef LIBANGLE_RENDERER_COMPILERIMPL_H_
...@@ -23,6 +24,9 @@ class CompilerImpl : angle::NonCopyable ...@@ -23,6 +24,9 @@ class CompilerImpl : angle::NonCopyable
virtual ~CompilerImpl() {} virtual ~CompilerImpl() {}
virtual gl::Error release() = 0; virtual gl::Error release() = 0;
// TODO(jmadill): Expose translator built-in resources init method.
virtual ShShaderOutput getTranslatorOutputType() const = 0;
}; };
} }
......
...@@ -36,7 +36,7 @@ class ImplFactory : angle::NonCopyable ...@@ -36,7 +36,7 @@ class ImplFactory : angle::NonCopyable
virtual ~ImplFactory() {} virtual ~ImplFactory() {}
// Shader creation // Shader creation
virtual CompilerImpl *createCompiler(const gl::Data &data) = 0; virtual CompilerImpl *createCompiler() = 0;
virtual ShaderImpl *createShader(GLenum type) = 0; virtual ShaderImpl *createShader(GLenum type) = 0;
virtual ProgramImpl *createProgram(const gl::Program::Data &data) = 0; virtual ProgramImpl *createProgram(const gl::Program::Data &data) = 0;
......
// //
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. // Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// CompilerGL:
// CompilerD3D.cpp: Implementation of the rx::CompilerD3D class. // Implementation of the D3D compiler methods.
//
#include "libANGLE/renderer/d3d/CompilerD3D.h" #include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/Caps.h"
#include "libANGLE/Data.h"
#include "common/debug.h"
namespace rx namespace rx
{ {
// Global count of active shader compiler handles. Needed to know when to call ShInitialize and ShFinalize. namespace
static size_t activeCompilerHandles = 0;
CompilerD3D::CompilerD3D(const gl::Data &data, ShShaderOutput outputType)
: mSpec(data.clientVersion > 2 ? SH_GLES3_SPEC : SH_GLES2_SPEC),
mOutputType(outputType),
mResources(),
mFragmentCompiler(NULL),
mVertexCompiler(NULL)
{ {
ASSERT(data.clientVersion == 2 || data.clientVersion == 3);
const gl::Caps &caps = *data.caps;
const gl::Extensions &extensions = *data.extensions;
ShInitBuiltInResources(&mResources); ShShaderOutput GetShaderOutputType(RendererClass rendererClass)
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 = 1;
// resources.OES_EGL_image_external = mRenderer->getShareHandleSupport() ? 1 : 0; // TODO: commented out until the extension is actually supported.
mResources.FragmentPrecisionHigh = 1; // Shader Model 2+ always supports FP24 (s16e7) which corresponds to highp
mResources.EXT_frag_depth = 1; // Shader Model 2+ always supports explicit depth output
// GLSL ES 3.0 constants
mResources.MaxVertexOutputVectors = caps.maxVertexOutputComponents / 4;
mResources.MaxFragmentInputVectors = caps.maxFragmentInputComponents / 4;
mResources.MinProgramTexelOffset = caps.minProgramTexelOffset;
mResources.MaxProgramTexelOffset = caps.maxProgramTexelOffset;
}
CompilerD3D::~CompilerD3D()
{
release();
}
gl::Error CompilerD3D::release()
{ {
if (mFragmentCompiler) if (rendererClass == RENDERER_D3D11)
{
ShDestruct(mFragmentCompiler);
mFragmentCompiler = NULL;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
}
if (mVertexCompiler)
{ {
ShDestruct(mVertexCompiler); return SH_HLSL11_OUTPUT;
mVertexCompiler = NULL;
ASSERT(activeCompilerHandles > 0);
activeCompilerHandles--;
} }
else
if (activeCompilerHandles == 0)
{ {
ShFinalize(); ASSERT(rendererClass == RENDERER_D3D9);
return SH_HLSL9_OUTPUT;
} }
return gl::Error(GL_NO_ERROR);
} }
ShHandle CompilerD3D::getCompilerHandle(GLenum type) } // anonymous namespace
{
ShHandle *compiler = NULL;
switch (type)
{
case GL_VERTEX_SHADER:
compiler = &mVertexCompiler;
break;
case GL_FRAGMENT_SHADER: CompilerD3D::CompilerD3D(RendererClass rendererClass)
compiler = &mFragmentCompiler; : mTranslatorOutputType(GetShaderOutputType(rendererClass))
break; {
default:
UNREACHABLE();
return NULL;
}
if (!(*compiler))
{
if (activeCompilerHandles == 0)
{
ShInitialize();
}
*compiler = ShConstructCompiler(type, mSpec, mOutputType, &mResources);
activeCompilerHandles++;
}
return *compiler;
} }
} } // namespace rx
...@@ -10,14 +10,7 @@ ...@@ -10,14 +10,7 @@
#define LIBANGLE_RENDERER_COMPILERD3D_H_ #define LIBANGLE_RENDERER_COMPILERD3D_H_
#include "libANGLE/renderer/CompilerImpl.h" #include "libANGLE/renderer/CompilerImpl.h"
#include "libANGLE/Caps.h" #include "libANGLE/renderer/d3d/RendererD3D.h"
#include "GLSLANG/ShaderLang.h"
namespace gl
{
struct Data;
}
namespace rx namespace rx
{ {
...@@ -25,20 +18,14 @@ namespace rx ...@@ -25,20 +18,14 @@ namespace rx
class CompilerD3D : public CompilerImpl class CompilerD3D : public CompilerImpl
{ {
public: public:
CompilerD3D(const gl::Data &data, ShShaderOutput outputType); CompilerD3D(RendererClass rendererClass);
virtual ~CompilerD3D(); ~CompilerD3D() override {}
gl::Error release() override;
ShHandle getCompilerHandle(GLenum type); gl::Error release() override { return gl::Error(GL_NO_ERROR); }
ShShaderOutput getTranslatorOutputType() const override { return mTranslatorOutputType; }
private: private:
ShShaderSpec mSpec; ShShaderOutput mTranslatorOutputType;
ShShaderOutput mOutputType;
ShBuiltInResources mResources;
ShHandle mFragmentCompiler;
ShHandle mVertexCompiler;
}; };
} }
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include "libANGLE/VertexArray.h" #include "libANGLE/VertexArray.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/BufferD3D.h" #include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/DisplayD3D.h" #include "libANGLE/renderer/d3d/DisplayD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h" #include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h" #include "libANGLE/renderer/d3d/ProgramD3D.h"
...@@ -33,7 +34,7 @@ namespace ...@@ -33,7 +34,7 @@ namespace
// degenerate case where we are stuck hogging memory. // degenerate case where we are stuck hogging memory.
const int ScratchMemoryBufferLifetime = 1000; const int ScratchMemoryBufferLifetime = 1000;
} } // anonymous namespace
const uintptr_t RendererD3D::DirtyPointer = std::numeric_limits<uintptr_t>::max(); const uintptr_t RendererD3D::DirtyPointer = std::numeric_limits<uintptr_t>::max();
...@@ -67,6 +68,11 @@ void RendererD3D::cleanup() ...@@ -67,6 +68,11 @@ void RendererD3D::cleanup()
} }
} }
CompilerImpl *RendererD3D::createCompiler()
{
return new CompilerD3D(getRendererClass());
}
gl::Error RendererD3D::drawArrays(const gl::Data &data, GLenum mode, GLint first, GLsizei count) gl::Error RendererD3D::drawArrays(const gl::Data &data, GLenum mode, GLint first, GLsizei count)
{ {
return genericDrawArrays(data, mode, first, count, 0); return genericDrawArrays(data, mode, first, count, 0);
......
...@@ -129,6 +129,8 @@ class RendererD3D : public Renderer, public BufferFactoryD3D ...@@ -129,6 +129,8 @@ class RendererD3D : public Renderer, public BufferFactoryD3D
bool isDeviceLost() const override; bool isDeviceLost() const override;
std::string getVendorString() const override; std::string getVendorString() const override;
CompilerImpl *createCompiler() override;
virtual int getMinorShaderModel() const = 0; virtual int getMinorShaderModel() const = 0;
virtual std::string getShaderModelSuffix() const = 0; virtual std::string getShaderModelSuffix() const = 0;
......
...@@ -6,14 +6,13 @@ ...@@ -6,14 +6,13 @@
// ShaderD3D.cpp: Defines the rx::ShaderD3D class which implements rx::ShaderImpl. // ShaderD3D.cpp: Defines the rx::ShaderD3D class which implements rx::ShaderImpl.
#include "libANGLE/Shader.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
#include "libANGLE/renderer/d3d/ShaderD3D.h" #include "libANGLE/renderer/d3d/ShaderD3D.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/features.h"
#include "common/utilities.h" #include "common/utilities.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/Shader.h"
#include "libANGLE/features.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
// Definitions local to the translation unit // Definitions local to the translation unit
namespace namespace
...@@ -321,8 +320,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source) ...@@ -321,8 +320,7 @@ bool ShaderD3D::compile(gl::Compiler *compiler, const std::string &source)
{ {
uncompile(); uncompile();
CompilerD3D *compilerD3D = GetImplAs<CompilerD3D>(compiler); ShHandle compilerHandle = compiler->getCompilerHandle(mShaderType);
ShHandle compilerHandle = compilerD3D->getCompilerHandle(mShaderType);
mCompilerOutputType = ShGetShaderOutputType(compilerHandle); mCompilerOutputType = ShGetShaderOutputType(compilerHandle);
......
...@@ -22,7 +22,6 @@ ...@@ -22,7 +22,6 @@
#include "libANGLE/Surface.h" #include "libANGLE/Surface.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/histogram_macros.h" #include "libANGLE/histogram_macros.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h" #include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h" #include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h" #include "libANGLE/renderer/d3d/ProgramD3D.h"
...@@ -3004,11 +3003,6 @@ FramebufferImpl *Renderer11::createFramebuffer(const gl::Framebuffer::Data &data ...@@ -3004,11 +3003,6 @@ FramebufferImpl *Renderer11::createFramebuffer(const gl::Framebuffer::Data &data
return new Framebuffer11(data, this); return new Framebuffer11(data, this);
} }
CompilerImpl *Renderer11::createCompiler(const gl::Data &data)
{
return new CompilerD3D(data, SH_HLSL11_OUTPUT);
}
ShaderImpl *Renderer11::createShader(GLenum type) ShaderImpl *Renderer11::createShader(GLenum type)
{ {
return new ShaderD3D(type, this); return new ShaderD3D(type, this);
......
...@@ -182,7 +182,6 @@ class Renderer11 : public RendererD3D ...@@ -182,7 +182,6 @@ class Renderer11 : public RendererD3D
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
virtual CompilerImpl *createCompiler(const gl::Data &data);
virtual ShaderImpl *createShader(GLenum type); virtual ShaderImpl *createShader(GLenum type);
virtual ProgramImpl *createProgram(const gl::Program::Data &data); virtual ProgramImpl *createProgram(const gl::Program::Data &data);
......
...@@ -21,7 +21,6 @@ ...@@ -21,7 +21,6 @@
#include "libANGLE/angletypes.h" #include "libANGLE/angletypes.h"
#include "libANGLE/features.h" #include "libANGLE/features.h"
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/CompilerD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h" #include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/IndexDataManager.h" #include "libANGLE/renderer/d3d/IndexDataManager.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h" #include "libANGLE/renderer/d3d/ProgramD3D.h"
...@@ -2714,11 +2713,6 @@ FramebufferImpl *Renderer9::createFramebuffer(const gl::Framebuffer::Data &data) ...@@ -2714,11 +2713,6 @@ FramebufferImpl *Renderer9::createFramebuffer(const gl::Framebuffer::Data &data)
return new Framebuffer9(data, this); return new Framebuffer9(data, this);
} }
CompilerImpl *Renderer9::createCompiler(const gl::Data &data)
{
return new CompilerD3D(data, SH_HLSL9_OUTPUT);
}
ShaderImpl *Renderer9::createShader(GLenum type) ShaderImpl *Renderer9::createShader(GLenum type)
{ {
return new ShaderD3D(type, this); return new ShaderD3D(type, this);
......
...@@ -169,7 +169,6 @@ class Renderer9 : public RendererD3D ...@@ -169,7 +169,6 @@ class Renderer9 : public RendererD3D
FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override; FramebufferImpl *createFramebuffer(const gl::Framebuffer::Data &data) override;
// Shader creation // Shader creation
virtual CompilerImpl *createCompiler(const gl::Data &data);
virtual ShaderImpl *createShader(GLenum type); virtual ShaderImpl *createShader(GLenum type);
virtual ProgramImpl *createProgram(const gl::Program::Data &data); virtual ProgramImpl *createProgram(const gl::Program::Data &data);
......
...@@ -3,23 +3,21 @@ ...@@ -3,23 +3,21 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// //
// CompilerGL:
// CompilerGL.cpp: Implements the class methods for CompilerGL. // Implementation of the GL compiler methods.
//
#include "libANGLE/renderer/gl/CompilerGL.h" #include "libANGLE/renderer/gl/CompilerGL.h"
#include "common/debug.h"
#include "libANGLE/Caps.h"
#include "libANGLE/Data.h"
#include "libANGLE/renderer/gl/FunctionsGL.h" #include "libANGLE/renderer/gl/FunctionsGL.h"
namespace rx namespace rx
{ {
// Global count of active shader compiler handles. Needed to know when to call ShInitialize and ShFinalize. namespace
static size_t activeCompilerHandles = 0; {
static ShShaderOutput GetShaderOutputType(const FunctionsGL *functions) ShShaderOutput GetShaderOutputType(const FunctionsGL *functions)
{ {
ASSERT(functions); ASSERT(functions);
...@@ -83,105 +81,11 @@ static ShShaderOutput GetShaderOutputType(const FunctionsGL *functions) ...@@ -83,105 +81,11 @@ static ShShaderOutput GetShaderOutputType(const FunctionsGL *functions)
} }
} }
CompilerGL::CompilerGL(const gl::Data &data, const FunctionsGL *functions) } // anonymous namespace
: CompilerImpl(),
mSpec(data.clientVersion > 2 ? SH_GLES3_SPEC : SH_GLES2_SPEC),
mOutputType(GetShaderOutputType(functions)),
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()
{
release();
}
gl::Error CompilerGL::release()
{
if (mFragmentCompiler)
{
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) CompilerGL::CompilerGL(const FunctionsGL *functions)
: mTranslatorOutputType(GetShaderOutputType(functions))
{ {
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, mOutputType, &mResources);
activeCompilerHandles++;
}
return *compiler;
} }
} } // namespace rx
...@@ -11,35 +11,21 @@ ...@@ -11,35 +11,21 @@
#include "libANGLE/renderer/CompilerImpl.h" #include "libANGLE/renderer/CompilerImpl.h"
#include "GLSLANG/ShaderLang.h"
namespace gl
{
struct Data;
}
namespace rx namespace rx
{ {
class FunctionsGL; class FunctionsGL;
class CompilerGL : public CompilerImpl class CompilerGL : public CompilerImpl
{ {
public: public:
CompilerGL(const gl::Data &data, const FunctionsGL *functions); CompilerGL(const FunctionsGL *functions);
~CompilerGL() override; ~CompilerGL() override {}
gl::Error release() override;
ShHandle getCompilerHandle(GLenum type); gl::Error release() override { return gl::Error(GL_NO_ERROR); }
ShShaderOutput getTranslatorOutputType() const { return mTranslatorOutputType; }
private: private:
ShShaderSpec mSpec; ShShaderOutput mTranslatorOutputType;
ShShaderOutput mOutputType;
ShBuiltInResources mResources;
ShHandle mFragmentCompiler;
ShHandle mVertexCompiler;
}; };
} }
......
...@@ -237,9 +237,9 @@ gl::Error RendererGL::drawRangeElements(const gl::Data &data, ...@@ -237,9 +237,9 @@ gl::Error RendererGL::drawRangeElements(const gl::Data &data,
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
CompilerImpl *RendererGL::createCompiler(const gl::Data &data) CompilerImpl *RendererGL::createCompiler()
{ {
return new CompilerGL(data, mFunctions); return new CompilerGL(mFunctions);
} }
ShaderImpl *RendererGL::createShader(GLenum type) ShaderImpl *RendererGL::createShader(GLenum type)
......
...@@ -58,7 +58,7 @@ class RendererGL : public Renderer ...@@ -58,7 +58,7 @@ class RendererGL : public Renderer
const gl::IndexRange &indexRange) override; const gl::IndexRange &indexRange) override;
// Shader creation // Shader creation
CompilerImpl *createCompiler(const gl::Data &data) override; CompilerImpl *createCompiler() override;
ShaderImpl *createShader(GLenum type) override; ShaderImpl *createShader(GLenum type) override;
ProgramImpl *createProgram(const gl::Program::Data &data) override; ProgramImpl *createProgram(const gl::Program::Data &data) override;
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Compiler.h" #include "libANGLE/Compiler.h"
#include "libANGLE/renderer/gl/CompilerGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h" #include "libANGLE/renderer/gl/FunctionsGL.h"
template <typename VarT> template <typename VarT>
...@@ -72,8 +71,7 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source) ...@@ -72,8 +71,7 @@ bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source)
} }
// Translate the ESSL into GLSL // Translate the ESSL into GLSL
CompilerGL *compilerGL = GetImplAs<CompilerGL>(compiler); ShHandle compilerHandle = compiler->getCompilerHandle(mType);
ShHandle compilerHandle = compilerGL->getCompilerHandle(mType);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | SH_INIT_GL_POSITION); int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | SH_INIT_GL_POSITION);
const char* sourceCString = source.c_str(); const char* sourceCString = source.c_str();
......
...@@ -21,7 +21,7 @@ class NullFactory : public ImplFactory ...@@ -21,7 +21,7 @@ class NullFactory : public ImplFactory
NullFactory() {} NullFactory() {}
// Shader creation // Shader creation
CompilerImpl *createCompiler(const gl::Data &data) override { return nullptr; } CompilerImpl *createCompiler() override { return nullptr; }
ShaderImpl *createShader(GLenum type) override { return nullptr; } ShaderImpl *createShader(GLenum type) override { return nullptr; }
ProgramImpl *createProgram(const gl::Program::Data &data) override { return nullptr; } ProgramImpl *createProgram(const gl::Program::Data &data) override { return nullptr; }
......
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