Hash :
a100d8f4
Author :
Date :
2018-12-29T16:39:55
ParallelCompile: add GL backend support For GL backend, at first each worker thread must have a naitve context for its own to work in. These worker contexts have to be shared from the main context, so that all shader and program objects are seen in any context. This extends backend displays to create and destroy the worker contexts. RendererGL manages and allocates them to the worker threads. ShaderImpl has a new compile method added to do the actual glCompile work in worker thread. The ProgramGL's link method is broken down by introducing the LinkEventGL class. Bug: chromium:849576 Change-Id: Idc2c51b4b6c978781ae77810e62c480acc67ebb5 Reviewed-on: https://chromium-review.googlesource.com/c/1373015 Commit-Queue: Jie A Chen <jie.a.chen@intel.com> Reviewed-by: Geoff Lang <geofflang@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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
//
// Copyright 2015 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.
//
// ShaderGL.cpp: Implements the class methods for ShaderGL.
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "common/debug.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/WorkaroundsGL.h"
#include <iostream>
namespace rx
{
ShaderGL::ShaderGL(const gl::ShaderState &data,
GLuint shaderID,
MultiviewImplementationTypeGL multiviewImplementationType,
const std::shared_ptr<RendererGL> &renderer)
: ShaderImpl(data),
mShaderID(shaderID),
mMultiviewImplementationType(multiviewImplementationType),
mRenderer(renderer),
mFallbackToMainThread(true),
mCompileStatus(GL_FALSE)
{}
ShaderGL::~ShaderGL()
{
ASSERT(mShaderID == 0);
}
void ShaderGL::destroy()
{
mRenderer->getFunctions()->deleteShader(mShaderID);
mShaderID = 0;
}
ShCompileOptions ShaderGL::prepareSourceAndReturnOptions(const gl::Context *context,
std::stringstream *sourceStream,
std::string * /*sourcePath*/)
{
*sourceStream << mData.getSource();
ShCompileOptions options = SH_INIT_GL_POSITION;
bool isWebGL = context->getExtensions().webglCompatibility;
if (isWebGL && (mData.getShaderType() != gl::ShaderType::Compute))
{
options |= SH_INIT_OUTPUT_VARIABLES;
}
const WorkaroundsGL &workarounds = GetWorkaroundsGL(context);
if (workarounds.doWhileGLSLCausesGPUHang)
{
options |= SH_REWRITE_DO_WHILE_LOOPS;
}
if (workarounds.emulateAbsIntFunction)
{
options |= SH_EMULATE_ABS_INT_FUNCTION;
}
if (workarounds.addAndTrueToLoopCondition)
{
options |= SH_ADD_AND_TRUE_TO_LOOP_CONDITION;
}
if (workarounds.emulateIsnanFloat)
{
options |= SH_EMULATE_ISNAN_FLOAT_FUNCTION;
}
if (workarounds.emulateAtan2Float)
{
options |= SH_EMULATE_ATAN2_FLOAT_FUNCTION;
}
if (workarounds.useUnusedBlocksWithStandardOrSharedLayout)
{
options |= SH_USE_UNUSED_STANDARD_SHARED_BLOCKS;
}
if (workarounds.dontRemoveInvariantForFragmentInput)
{
options |= SH_DONT_REMOVE_INVARIANT_FOR_FRAGMENT_INPUT;
}
if (workarounds.removeInvariantAndCentroidForESSL3)
{
options |= SH_REMOVE_INVARIANT_AND_CENTROID_FOR_ESSL3;
}
if (workarounds.rewriteFloatUnaryMinusOperator)
{
options |= SH_REWRITE_FLOAT_UNARY_MINUS_OPERATOR;
}
if (!workarounds.dontInitializeUninitializedLocals)
{
options |= SH_INITIALIZE_UNINITIALIZED_LOCALS;
}
if (workarounds.clampPointSize)
{
options |= SH_CLAMP_POINT_SIZE;
}
if (workarounds.rewriteVectorScalarArithmetic)
{
options |= SH_REWRITE_VECTOR_SCALAR_ARITHMETIC;
}
if (workarounds.dontUseLoopsToInitializeVariables)
{
options |= SH_DONT_USE_LOOPS_TO_INITIALIZE_VARIABLES;
}
if (workarounds.clampFragDepth)
{
options |= SH_CLAMP_FRAG_DEPTH;
}
if (workarounds.rewriteRepeatedAssignToSwizzled)
{
options |= SH_REWRITE_REPEATED_ASSIGN_TO_SWIZZLED;
}
if (mMultiviewImplementationType == MultiviewImplementationTypeGL::NV_VIEWPORT_ARRAY2)
{
options |= SH_INITIALIZE_BUILTINS_FOR_INSTANCED_MULTIVIEW;
options |= SH_SELECT_VIEW_IN_NV_GLSL_VERTEX_SHADER;
}
mFallbackToMainThread = true;
return options;
}
void ShaderGL::compileAndCheckShader(const char *source)
{
const FunctionsGL *functions = mRenderer->getFunctions();
functions->shaderSource(mShaderID, 1, &source, nullptr);
functions->compileShader(mShaderID);
// Check for compile errors from the native driver
mCompileStatus = GL_FALSE;
functions->getShaderiv(mShaderID, GL_COMPILE_STATUS, &mCompileStatus);
if (mCompileStatus == GL_FALSE)
{
// Compilation failed, put the error into the info log
GLint infoLogLength = 0;
functions->getShaderiv(mShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
// Info log length includes the null terminator, so 1 means that the info log is an empty
// string.
if (infoLogLength > 1)
{
std::vector<char> buf(infoLogLength);
functions->getShaderInfoLog(mShaderID, infoLogLength, nullptr, &buf[0]);
mInfoLog = &buf[0];
WARN() << std::endl << mInfoLog;
}
else
{
WARN() << std::endl << "Shader compilation failed with no info log.";
}
}
}
void ShaderGL::compileAsync(const std::string &source)
{
std::string infoLog;
ScopedWorkerContextGL worker(mRenderer.get(), &infoLog);
if (worker())
{
compileAndCheckShader(source.c_str());
mFallbackToMainThread = false;
}
else
{
#if !defined(NDEBUG)
WARN() << "bindWorkerContext failed." << std::endl << infoLog;
#endif
}
}
bool ShaderGL::postTranslateCompile(gl::ShCompilerInstance *compiler, std::string *infoLog)
{
if (mFallbackToMainThread)
{
const char *translatedSourceCString = mData.getTranslatedSource().c_str();
compileAndCheckShader(translatedSourceCString);
}
if (mCompileStatus == GL_FALSE)
{
*infoLog = mInfoLog;
return false;
}
return true;
}
std::string ShaderGL::getDebugInfo() const
{
return mData.getTranslatedSource();
}
GLuint ShaderGL::getShaderID() const
{
return mShaderID;
}
} // namespace rx