Hash :
15ce8227
Author :
Date :
2019-03-18T19:25:21
Fix error report when active color buffer has no fs output Also modify or remove some tests to sync up with the expected behavior stated in spec. Related to https://github.com/KhronosGroup/WebGL/pull/2780 If any draw buffer with an attachment does not have a defined fragment shader output, draws generate INVALID_OPERATION. Also remove Framebuffer masking for inactive outputs. This workaround is no longer necessary as the WebGL spec has changed. It also was never fully working and had bugs with certain orders of calls. Bug: angleproject:2872 Bug: chromium:927908 Bug: chromium:943538 Change-Id: I73715a6ab851ae3db7096f49ea0a9fdd6f576703 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1530018 Commit-Queue: Shrek Shao <shrekshao@google.com> Reviewed-by: Jonah Ryan-Davis <jonahr@google.com>
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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
//
// 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/Context.h"
#include "libANGLE/renderer/gl/BufferGL.h"
#include "libANGLE/renderer/gl/CompilerGL.h"
#include "libANGLE/renderer/gl/FenceNVGL.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/ProgramPipelineGL.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/SyncGL.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::State &state,
gl::ErrorSet *errorSet,
const std::shared_ptr<RendererGL> &renderer)
: ContextImpl(state, errorSet), mRenderer(renderer)
{}
ContextGL::~ContextGL() {}
angle::Result ContextGL::initialize()
{
return angle::Result::Continue;
}
CompilerImpl *ContextGL::createCompiler()
{
return new CompilerGL(getFunctions());
}
ShaderImpl *ContextGL::createShader(const gl::ShaderState &data)
{
const FunctionsGL *functions = getFunctions();
GLuint shader = functions->createShader(ToGLenum(data.getShaderType()));
return new ShaderGL(data, shader, mRenderer->getMultiviewImplementationType(), mRenderer);
}
ProgramImpl *ContextGL::createProgram(const gl::ProgramState &data)
{
return new ProgramGL(data, getFunctions(), getWorkaroundsGL(), getStateManager(),
getExtensions().pathRendering, mRenderer);
}
FramebufferImpl *ContextGL::createFramebuffer(const gl::FramebufferState &data)
{
const FunctionsGL *funcs = getFunctions();
GLuint fbo = 0;
funcs->genFramebuffers(1, &fbo);
return new FramebufferGL(data, fbo, false);
}
TextureImpl *ContextGL::createTexture(const gl::TextureState &state)
{
const FunctionsGL *functions = getFunctions();
StateManagerGL *stateManager = getStateManager();
GLuint texture = 0;
functions->genTextures(1, &texture);
stateManager->bindTexture(state.getType(), texture);
return new TextureGL(state, texture);
}
RenderbufferImpl *ContextGL::createRenderbuffer(const gl::RenderbufferState &state)
{
return new RenderbufferGL(state, getFunctions(), getWorkaroundsGL(), getStateManager(),
mRenderer->getBlitter(), 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(gl::QueryType type)
{
switch (type)
{
case gl::QueryType::CommandsCompleted:
return new SyncQueryGL(type, getFunctions());
default:
return new StandardQueryGL(type, getFunctions(), getStateManager());
}
}
FenceNVImpl *ContextGL::createFenceNV()
{
const FunctionsGL *functions = getFunctions();
if (FenceNVGL::Supported(functions))
{
return new FenceNVGL(functions);
}
else
{
ASSERT(FenceNVSyncGL::Supported(functions));
return new FenceNVSyncGL(functions);
}
}
SyncImpl *ContextGL::createSync()
{
return new SyncGL(getFunctions());
}
TransformFeedbackImpl *ContextGL::createTransformFeedback(const gl::TransformFeedbackState &state)
{
return new TransformFeedbackGL(state, getFunctions(), getStateManager());
}
SamplerImpl *ContextGL::createSampler(const gl::SamplerState &state)
{
return new SamplerGL(state, getFunctions(), getStateManager());
}
ProgramPipelineImpl *ContextGL::createProgramPipeline(const gl::ProgramPipelineState &data)
{
return new ProgramPipelineGL(data, getFunctions());
}
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;
}
MemoryObjectImpl *ContextGL::createMemoryObject()
{
UNREACHABLE();
return nullptr;
}
angle::Result ContextGL::flush(const gl::Context *context)
{
return mRenderer->flush();
}
angle::Result ContextGL::finish(const gl::Context *context)
{
return mRenderer->finish();
}
ANGLE_INLINE angle::Result ContextGL::setDrawArraysState(const gl::Context *context,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
if (context->getStateCache().hasAnyActiveClientAttrib())
{
const gl::State &glState = context->getState();
const gl::Program *program = glState.getProgram();
const gl::VertexArray *vao = glState.getVertexArray();
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao);
ANGLE_TRY(vaoGL->syncClientSideData(context, program->getActiveAttribLocationsMask(), first,
count, instanceCount));
}
return angle::Result::Continue;
}
ANGLE_INLINE angle::Result ContextGL::setDrawElementsState(const gl::Context *context,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instanceCount,
const void **outIndices)
{
const gl::State &glState = context->getState();
const gl::Program *program = glState.getProgram();
const gl::VertexArray *vao = glState.getVertexArray();
const gl::StateCache &stateCache = context->getStateCache();
if (stateCache.hasAnyActiveClientAttrib() || vao->getElementArrayBuffer() == nullptr)
{
const VertexArrayGL *vaoGL = GetImplAs<VertexArrayGL>(vao);
ANGLE_TRY(vaoGL->syncDrawElementsState(context, program->getActiveAttribLocationsMask(),
count, type, indices, instanceCount,
glState.isPrimitiveRestartEnabled(), outIndices));
}
else
{
*outIndices = indices;
}
return angle::Result::Continue;
}
angle::Result ContextGL::drawArrays(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count)
{
const gl::Program *program = context->getState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
ANGLE_TRY(setDrawArraysState(context, first, count, instanceCount));
if (!usesMultiview)
{
getFunctions()->drawArrays(ToGLenum(mode), first, count);
}
else
{
getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count, instanceCount);
}
return angle::Result::Continue;
}
angle::Result ContextGL::drawArraysInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLint first,
GLsizei count,
GLsizei instanceCount)
{
GLsizei adjustedInstanceCount = instanceCount;
const gl::Program *program = context->getState().getProgram();
if (program->usesMultiview())
{
adjustedInstanceCount *= program->getNumViews();
}
ANGLE_TRY(setDrawArraysState(context, first, count, adjustedInstanceCount));
getFunctions()->drawArraysInstanced(ToGLenum(mode), first, count, adjustedInstanceCount);
return angle::Result::Continue;
}
angle::Result ContextGL::drawElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices)
{
const gl::State &glState = context->getState();
const gl::Program *program = glState.getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
const void *drawIndexPtr = nullptr;
ANGLE_TRY(setDrawElementsState(context, count, type, indices, instanceCount, &drawIndexPtr));
if (!usesMultiview)
{
getFunctions()->drawElements(ToGLenum(mode), count, ToGLenum(type), drawIndexPtr);
}
else
{
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type), drawIndexPtr,
instanceCount);
}
return angle::Result::Continue;
}
angle::Result ContextGL::drawElementsInstanced(const gl::Context *context,
gl::PrimitiveMode mode,
GLsizei count,
gl::DrawElementsType type,
const void *indices,
GLsizei instances)
{
GLsizei adjustedInstanceCount = instances;
const gl::Program *program = context->getState().getProgram();
if (program->usesMultiview())
{
adjustedInstanceCount *= program->getNumViews();
}
const void *drawIndexPointer = nullptr;
ANGLE_TRY(setDrawElementsState(context, count, type, indices, adjustedInstanceCount,
&drawIndexPointer));
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type), drawIndexPointer,
adjustedInstanceCount);
return angle::Result::Continue;
}
angle::Result ContextGL::drawRangeElements(const gl::Context *context,
gl::PrimitiveMode mode,
GLuint start,
GLuint end,
GLsizei count,
gl::DrawElementsType type,
const void *indices)
{
const gl::Program *program = context->getState().getProgram();
const bool usesMultiview = program->usesMultiview();
const GLsizei instanceCount = usesMultiview ? program->getNumViews() : 0;
const void *drawIndexPointer = nullptr;
ANGLE_TRY(
setDrawElementsState(context, count, type, indices, instanceCount, &drawIndexPointer));
if (!usesMultiview)
{
getFunctions()->drawRangeElements(ToGLenum(mode), start, end, count, ToGLenum(type),
drawIndexPointer);
}
else
{
getFunctions()->drawElementsInstanced(ToGLenum(mode), count, ToGLenum(type),
drawIndexPointer, instanceCount);
}
return angle::Result::Continue;
}
angle::Result ContextGL::drawArraysIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
const void *indirect)
{
getFunctions()->drawArraysIndirect(ToGLenum(mode), indirect);
return angle::Result::Continue;
}
angle::Result ContextGL::drawElementsIndirect(const gl::Context *context,
gl::PrimitiveMode mode,
gl::DrawElementsType type,
const void *indirect)
{
getFunctions()->drawElementsIndirect(ToGLenum(mode), ToGLenum(type), indirect);
return angle::Result::Continue;
}
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);
}
gl::GraphicsResetStatus 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::pushDebugGroup(GLenum source, GLuint id, const std::string &message)
{
mRenderer->pushDebugGroup(source, id, message);
}
void ContextGL::popDebugGroup()
{
mRenderer->popDebugGroup();
}
angle::Result ContextGL::syncState(const gl::Context *context,
const gl::State::DirtyBits &dirtyBits,
const gl::State::DirtyBits &bitMask)
{
mRenderer->getStateManager()->syncState(context, dirtyBits, bitMask);
return angle::Result::Continue;
}
GLint ContextGL::getGPUDisjoint()
{
return mRenderer->getGPUDisjoint();
}
GLint64 ContextGL::getTimestamp()
{
return mRenderer->getTimestamp();
}
angle::Result ContextGL::onMakeCurrent(const gl::Context *context)
{
// Queries need to be paused/resumed on context switches
return mRenderer->getStateManager()->onMakeCurrent(context);
}
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();
}
void ContextGL::applyNativeWorkarounds(gl::Workarounds *workarounds) const
{
return mRenderer->applyNativeWorkarounds(workarounds);
}
StateManagerGL *ContextGL::getStateManager()
{
return mRenderer->getStateManager();
}
const WorkaroundsGL &ContextGL::getWorkaroundsGL() const
{
return mRenderer->getWorkarounds();
}
BlitGL *ContextGL::getBlitter() const
{
return mRenderer->getBlitter();
}
ClearMultiviewGL *ContextGL::getMultiviewClearer() const
{
return mRenderer->getMultiviewClearer();
}
angle::Result ContextGL::dispatchCompute(const gl::Context *context,
GLuint numGroupsX,
GLuint numGroupsY,
GLuint numGroupsZ)
{
return mRenderer->dispatchCompute(context, numGroupsX, numGroupsY, numGroupsZ);
}
angle::Result ContextGL::dispatchComputeIndirect(const gl::Context *context, GLintptr indirect)
{
return mRenderer->dispatchComputeIndirect(context, indirect);
}
angle::Result ContextGL::memoryBarrier(const gl::Context *context, GLbitfield barriers)
{
return mRenderer->memoryBarrier(barriers);
}
angle::Result ContextGL::memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers)
{
return mRenderer->memoryBarrierByRegion(barriers);
}
void ContextGL::setMaxShaderCompilerThreads(GLuint count)
{
mRenderer->setMaxShaderCompilerThreads(count);
}
} // namespace rx