Hash :
83f349ea
Author :
Date :
2015-09-23T09:50:36
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/299874 Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
//
// Copyright (c) 2014 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Compiler.cpp: implements the gl::Compiler class.
#include "libANGLE/Compiler.h"
#include "common/debug.h"
#include "libANGLE/Data.h"
#include "libANGLE/renderer/CompilerImpl.h"
#include "libANGLE/renderer/ImplFactory.h"
namespace gl
{
namespace
{
// 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(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()
{
release();
SafeDelete(mImplementation);
}
Error Compiler::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);
}
ShHandle Compiler::getCompilerHandle(GLenum type)
{
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