Hash :
e7557744
Author :
Date :
2017-06-01T13:09:57
WebGL compatibility: remove UB for draw buffers in the GL backend. WebGL adds two rules: - Fragment outputs declared but not written to should default to black. - FBO attachments for outputs not declared in the shader should not be written to (it is UB in OpenGL ES). Fix the first one by using the SH_INIT_OUTPUT_VARIABLES compiler options, and the second one by messing with glDrawBuffers so that the enabled draw buffers are always a subset of the ones declared by the shader. BUG=angleproject:2048 Change-Id: I1d851c190959c1acfc3e41d837e6990aec1d4086 Reviewed-on: https://chromium-review.googlesource.com/521682 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> 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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
//
// Copyright 2016 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.
//
// ContextGL:
// OpenGL-specific functionality associated with a GL Context.
//
#include "libANGLE/renderer/gl/ContextGL.h"
#include "libANGLE/renderer/gl/BufferGL.h"
#include "libANGLE/renderer/gl/CompilerGL.h"
#include "libANGLE/renderer/gl/FenceNVGL.h"
#include "libANGLE/renderer/gl/FenceSyncGL.h"
#include "libANGLE/renderer/gl/FramebufferGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/PathGL.h"
#include "libANGLE/renderer/gl/ProgramGL.h"
#include "libANGLE/renderer/gl/QueryGL.h"
#include "libANGLE/renderer/gl/RenderbufferGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/SamplerGL.h"
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/renderer/gl/TextureGL.h"
#include "libANGLE/renderer/gl/TransformFeedbackGL.h"
#include "libANGLE/renderer/gl/VertexArrayGL.h"
namespace rx
{
ContextGL::ContextGL(const gl::ContextState &state, RendererGL *renderer)
: ContextImpl(state), mRenderer(renderer)
{
}
ContextGL::~ContextGL()
{
}
gl::Error ContextGL::initialize()
{
return gl::NoError();
}
CompilerImpl *ContextGL::createCompiler()
{
return new CompilerGL(getFunctions());
}
ShaderImpl *ContextGL::createShader(const gl::ShaderState &data)
{
return new ShaderGL(data, getFunctions(), getWorkaroundsGL(),
getExtensions().webglCompatibility);
}
ProgramImpl *ContextGL::createProgram(const gl::ProgramState &data)
{
return new ProgramGL(data, getFunctions(), getWorkaroundsGL(), getStateManager(),
getExtensions().pathRendering);
}
FramebufferImpl *ContextGL::createFramebuffer(const gl::FramebufferState &data)
{
return new FramebufferGL(data, getFunctions(), getStateManager(), getWorkaroundsGL(),
mRenderer->getBlitter(), false);
}
TextureImpl *ContextGL::createTexture(const gl::TextureState &state)
{
return new TextureGL(state, getFunctions(), getWorkaroundsGL(), getStateManager(),
mRenderer->getBlitter());
}
RenderbufferImpl *ContextGL::createRenderbuffer()
{
return new RenderbufferGL(getFunctions(), getWorkaroundsGL(), getStateManager(),
getNativeTextureCaps());
}
BufferImpl *ContextGL::createBuffer(const gl::BufferState &state)
{
return new BufferGL(state, getFunctions(), getStateManager());
}
VertexArrayImpl *ContextGL::createVertexArray(const gl::VertexArrayState &data)
{
return new VertexArrayGL(data, getFunctions(), getStateManager());
}
QueryImpl *ContextGL::createQuery(GLenum type)
{
switch (type)
{
case GL_COMMANDS_COMPLETED_CHROMIUM:
return new SyncQueryGL(type, getFunctions(), getStateManager());
default:
return new StandardQueryGL(type, getFunctions(), getStateManager());
}
}
FenceNVImpl *ContextGL::createFenceNV()
{
return new FenceNVGL(getFunctions());
}
FenceSyncImpl *ContextGL::createFenceSync()
{
return new FenceSyncGL(getFunctions());
}
TransformFeedbackImpl *ContextGL::createTransformFeedback(const gl::TransformFeedbackState &state)
{
return new TransformFeedbackGL(state, getFunctions(), getStateManager());
}
SamplerImpl *ContextGL::createSampler()
{
return new SamplerGL(getFunctions(), getStateManager());
}
std::vector<PathImpl *> ContextGL::createPaths(GLsizei range)
{
const FunctionsGL *funcs = getFunctions();
std::vector<PathImpl *> ret;
ret.reserve(range);
const GLuint first = funcs->genPathsNV(range);
if (first == 0)
return ret;
for (GLsizei i = 0; i < range; ++i)
{
const auto id = first + i;
ret.push_back(new PathGL(funcs, id));
}
return ret;
}
gl::Error ContextGL::flush()
{
return mRenderer->flush();
}
gl::Error ContextGL::finish()
{
return mRenderer->finish();
}
gl::Error ContextGL::drawArrays(const gl::Context *context, GLenum mode, GLint first, GLsizei count)
{
return mRenderer->drawArrays(mState, mode, first, count);
}
gl::Error ContextGL::drawArraysInstanced(const gl::Context *context,
GLenum mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
return mRenderer->drawArraysInstanced(mState, mode, first, count, instanceCount);
}
gl::Error ContextGL::drawElements(const gl::Context *context,
GLenum mode,
GLsizei count,
GLenum type,
const void *indices,
const gl::IndexRange &indexRange)
{
return mRenderer->drawElements(mState, mode, count, type, indices, indexRange);
}
gl::Error ContextGL::drawElementsInstanced(const gl::Context *context,
GLenum mode,
GLsizei count,
GLenum type,
const void *indices,
GLsizei instances,
const gl::IndexRange &indexRange)
{
return mRenderer->drawElementsInstanced(mState, mode, count, type, indices, instances,
indexRange);
}
gl::Error ContextGL::drawRangeElements(const gl::Context *context,
GLenum mode,
GLuint start,
GLuint end,
GLsizei count,
GLenum type,
const void *indices,
const gl::IndexRange &indexRange)
{
return mRenderer->drawRangeElements(mState, mode, start, end, count, type, indices, indexRange);
}
gl::Error ContextGL::drawArraysIndirect(const gl::Context *context,
GLenum mode,
const void *indirect)
{
return mRenderer->drawArraysIndirect(mState, mode, indirect);
}
gl::Error ContextGL::drawElementsIndirect(const gl::Context *context,
GLenum mode,
GLenum type,
const void *indirect)
{
return mRenderer->drawElementsIndirect(mState, mode, type, indirect);
}
void ContextGL::stencilFillPath(const gl::Path *path, GLenum fillMode, GLuint mask)
{
mRenderer->stencilFillPath(mState, path, fillMode, mask);
}
void ContextGL::stencilStrokePath(const gl::Path *path, GLint reference, GLuint mask)
{
mRenderer->stencilStrokePath(mState, path, reference, mask);
}
void ContextGL::coverFillPath(const gl::Path *path, GLenum coverMode)
{
mRenderer->coverFillPath(mState, path, coverMode);
}
void ContextGL::coverStrokePath(const gl::Path *path, GLenum coverMode)
{
mRenderer->coverStrokePath(mState, path, coverMode);
}
void ContextGL::stencilThenCoverFillPath(const gl::Path *path,
GLenum fillMode,
GLuint mask,
GLenum coverMode)
{
mRenderer->stencilThenCoverFillPath(mState, path, fillMode, mask, coverMode);
}
void ContextGL::stencilThenCoverStrokePath(const gl::Path *path,
GLint reference,
GLuint mask,
GLenum coverMode)
{
mRenderer->stencilThenCoverStrokePath(mState, path, reference, mask, coverMode);
}
void ContextGL::coverFillPathInstanced(const std::vector<gl::Path *> &paths,
GLenum coverMode,
GLenum transformType,
const GLfloat *transformValues)
{
mRenderer->coverFillPathInstanced(mState, paths, coverMode, transformType, transformValues);
}
void ContextGL::coverStrokePathInstanced(const std::vector<gl::Path *> &paths,
GLenum coverMode,
GLenum transformType,
const GLfloat *transformValues)
{
mRenderer->coverStrokePathInstanced(mState, paths, coverMode, transformType, transformValues);
}
void ContextGL::stencilFillPathInstanced(const std::vector<gl::Path *> &paths,
GLenum fillMode,
GLuint mask,
GLenum transformType,
const GLfloat *transformValues)
{
mRenderer->stencilFillPathInstanced(mState, paths, fillMode, mask, transformType,
transformValues);
}
void ContextGL::stencilStrokePathInstanced(const std::vector<gl::Path *> &paths,
GLint reference,
GLuint mask,
GLenum transformType,
const GLfloat *transformValues)
{
mRenderer->stencilStrokePathInstanced(mState, paths, reference, mask, transformType,
transformValues);
}
void ContextGL::stencilThenCoverFillPathInstanced(const std::vector<gl::Path *> &paths,
GLenum coverMode,
GLenum fillMode,
GLuint mask,
GLenum transformType,
const GLfloat *transformValues)
{
mRenderer->stencilThenCoverFillPathInstanced(mState, paths, coverMode, fillMode, mask,
transformType, transformValues);
}
void ContextGL::stencilThenCoverStrokePathInstanced(const std::vector<gl::Path *> &paths,
GLenum coverMode,
GLint reference,
GLuint mask,
GLenum transformType,
const GLfloat *transformValues)
{
mRenderer->stencilThenCoverStrokePathInstanced(mState, paths, coverMode, reference, mask,
transformType, transformValues);
}
GLenum ContextGL::getResetStatus()
{
return mRenderer->getResetStatus();
}
std::string ContextGL::getVendorString() const
{
return mRenderer->getVendorString();
}
std::string ContextGL::getRendererDescription() const
{
return mRenderer->getRendererDescription();
}
void ContextGL::insertEventMarker(GLsizei length, const char *marker)
{
mRenderer->insertEventMarker(length, marker);
}
void ContextGL::pushGroupMarker(GLsizei length, const char *marker)
{
mRenderer->pushGroupMarker(length, marker);
}
void ContextGL::popGroupMarker()
{
mRenderer->popGroupMarker();
}
void ContextGL::syncState(const gl::State::DirtyBits &dirtyBits)
{
mRenderer->getStateManager()->syncState(mState, dirtyBits);
}
GLint ContextGL::getGPUDisjoint()
{
return mRenderer->getGPUDisjoint();
}
GLint64 ContextGL::getTimestamp()
{
return mRenderer->getTimestamp();
}
void ContextGL::onMakeCurrent(const gl::ContextState &data)
{
// Queries need to be paused/resumed on context switches
mRenderer->getStateManager()->onMakeCurrent(data);
}
const gl::Caps &ContextGL::getNativeCaps() const
{
return mRenderer->getNativeCaps();
}
const gl::TextureCapsMap &ContextGL::getNativeTextureCaps() const
{
return mRenderer->getNativeTextureCaps();
}
const gl::Extensions &ContextGL::getNativeExtensions() const
{
return mRenderer->getNativeExtensions();
}
const gl::Limitations &ContextGL::getNativeLimitations() const
{
return mRenderer->getNativeLimitations();
}
const FunctionsGL *ContextGL::getFunctions() const
{
return mRenderer->getFunctions();
}
StateManagerGL *ContextGL::getStateManager()
{
return mRenderer->getStateManager();
}
const WorkaroundsGL &ContextGL::getWorkaroundsGL() const
{
return mRenderer->getWorkarounds();
}
gl::Error ContextGL::dispatchCompute(GLuint numGroupsX, GLuint numGroupsY, GLuint numGroupsZ)
{
return mRenderer->dispatchCompute(mState, numGroupsX, numGroupsY, numGroupsZ);
}
} // namespace rx