Hash :
ecc378cc
Author :
Date :
2025-03-03T16:43:33
Reland "Dont use Subject/Observer for SwapchainImageChanged" This is reland of the following CL https://chromium-review.googlesource.com/c/angle/angle/+/6319893 Because we do deferred ANI (VkAcquireNextImage) call until image is needed, we need a way to force Context to go through FramebufferVk::syncState call (FramebufferVk::syncState calls WindowSurfaceVk::getAttachmentRenderTarget, which end up calling ANI. Right now we uses subject/observer mechanism, by sending angle::SubjectMessage::SwapchainImageChanged to all observers of WindowSurfaceVk. In this case it is egl::Surface. Then eglSurface redirects this message to its observers, which are all gl::Framebuffer's attachments: color, depth, stencil. Even though only color attachment needs to be notified, but because we don't have a separate list of observers, depth/stencil attachment also receive the notification and they early out. Then gl::Framebuffer sets DIRTY_BIT_COLOR_BUFFER_CONTENTS_0 dirty bit and send the angle::SubjectMessage::DirtyBitsFlagged to Context, which dirty DrawFBO and ReadFBO and dirty cached state. Note that this is specific for swap image changed case, there is no surface property change (surface property change will still trigger the subject/observer message with SubjectMessage::SubjectChanged message, but this occurs rarely). This gets worse for apps that uses multiple contexts, for the example pokemon_masters_ex has three contexts, each context has its own default frame buffer that attach to the same surface, and we never remove non-current context from the observer list. This end up with egl::Surface has 12 observers and for every frame, it loop over the list of 12 observers and send message (virtual function call) to each of them. Color attachment also ends up sending two messages to Context, one for Read FBO and another for Draw FBO. There are total 21 virtual function calls. Even for single context usage, you have 6 virtual function calls, for every frame. EGL spec says "an EGLSurface must be current on only one thread at a time", any other context must call EGLMakeCurrent in order to use this surface, which will add all necessary dirty bits at that time. So we really only need to notify current context. In this CL, SwapchainImageChanged no longer uses subject/observer mechanism, so this message is removed. This CL still uses subject/observer mechanism to send DirtyBitsFlagged from Framebuffer back to context. We could call setDrawFramebufferDirty and setReadFramebufferDirty directly, but that will require to remove the "const" decoration out of gl::Context which generates too much code diff, so onStateChange(angle::SubjectMessage::DirtyBitsFlagged) is still used. Bug: angleproject:400711938 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6319893 Commit-Queue: Charlie Lao <cclao@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org> Reviewed-by: Yuxin Hu <yuxinhu@google.com> Change-Id: I017b0e8934b5194a520828fa5c4af1d6e3ef9aac Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/6404621
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 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627
//
// Copyright 2002 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.
//
// Framebuffer.h: Defines the gl::Framebuffer class. Implements GL framebuffer
// objects and related functionality. [OpenGL ES 2.0.24] section 4.4 page 105.
#ifndef LIBANGLE_FRAMEBUFFER_H_
#define LIBANGLE_FRAMEBUFFER_H_
#include <vector>
#include "common/FixedVector.h"
#include "common/Optional.h"
#include "common/angleutils.h"
#include "libANGLE/Constants.h"
#include "libANGLE/Debug.h"
#include "libANGLE/Error.h"
#include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/Observer.h"
#include "libANGLE/RefCountObject.h"
#include "libANGLE/State.h"
#include "libANGLE/angletypes.h"
namespace rx
{
class GLImplFactory;
class FramebufferImpl;
class RenderbufferImpl;
class SurfaceImpl;
} // namespace rx
namespace egl
{
class Display;
class Surface;
} // namespace egl
namespace gl
{
struct Caps;
class Context;
struct Extensions;
class Framebuffer;
class ImageIndex;
class PixelLocalStorage;
class Renderbuffer;
class TextureCapsMap;
struct FramebufferStatus
{
bool isComplete() const { return status == GL_FRAMEBUFFER_COMPLETE; }
static FramebufferStatus Complete();
static FramebufferStatus Incomplete(GLenum status, const char *reason);
GLenum status = GL_FRAMEBUFFER_COMPLETE;
const char *reason = nullptr;
};
class FramebufferState final : angle::NonCopyable
{
public:
explicit FramebufferState(rx::UniqueSerial serial);
FramebufferState(const Caps &caps, FramebufferID id, rx::UniqueSerial serial);
~FramebufferState();
const std::string &getLabel() const;
uint32_t getReadIndex() const;
const FramebufferAttachment *getAttachment(const Context *context, GLenum attachment) const;
const FramebufferAttachment *getReadAttachment() const;
const FramebufferAttachment *getFirstNonNullAttachment() const;
const FramebufferAttachment *getFirstColorAttachment() const;
const FramebufferAttachment *getDepthOrStencilAttachment() const;
const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
const FramebufferAttachment *getDepthAttachment() const;
const FramebufferAttachment *getStencilAttachment() const;
const FramebufferAttachment *getDepthStencilAttachment() const;
const FramebufferAttachment *getReadPixelsAttachment(GLenum readFormat) const;
const DrawBuffersVector<GLenum> &getDrawBufferStates() const { return mDrawBufferStates; }
DrawBufferMask getEnabledDrawBuffers() const { return mEnabledDrawBuffers; }
GLenum getReadBufferState() const { return mReadBufferState; }
const DrawBuffersVector<FramebufferAttachment> &getColorAttachments() const
{
return mColorAttachments;
}
const DrawBufferMask getColorAttachmentsMask() const { return mColorAttachmentsMask; }
const Extents getAttachmentExtentsIntersection() const;
bool attachmentsHaveSameDimensions() const;
bool hasSeparateDepthAndStencilAttachments() const;
bool colorAttachmentsAreUniqueImages() const;
Box getDimensions() const;
Extents getExtents() const;
const FramebufferAttachment *getDrawBuffer(size_t drawBufferIdx) const;
size_t getDrawBufferCount() const;
GLint getDefaultWidth() const { return mDefaultWidth; }
GLint getDefaultHeight() const { return mDefaultHeight; }
GLint getDefaultSamples() const { return mDefaultSamples; }
bool getDefaultFixedSampleLocations() const { return mDefaultFixedSampleLocations; }
GLint getDefaultLayers() const { return mDefaultLayers; }
bool getFlipY() const { return mFlipY; }
bool hasDepth() const;
bool hasStencil() const;
GLuint getStencilBitCount() const;
bool hasExternalTextureAttachment() const;
bool hasYUVAttachment() const;
bool isMultiview() const;
GLsizei getNumViews() const;
GLint getBaseViewIndex() const;
SrgbWriteControlMode getWriteControlMode() const { return mSrgbWriteControlMode; }
FramebufferID id() const { return mId; }
bool isDefault() const;
const Offset &getSurfaceTextureOffset() const { return mSurfaceTextureOffset; }
rx::UniqueSerial getFramebufferSerial() const { return mFramebufferSerial; }
bool isBoundAsDrawFramebuffer(const Context *context) const;
bool isFoveationEnabled() const { return mFoveationState.isFoveated(); }
const FoveationState &getFoveationState() const { return mFoveationState; }
private:
const FramebufferAttachment *getWebGLDepthStencilAttachment() const;
const FramebufferAttachment *getWebGLDepthAttachment() const;
const FramebufferAttachment *getWebGLStencilAttachment() const;
friend class Framebuffer;
// The Framebuffer ID is unique to a Context.
// The Framebuffer UniqueSerial is unique to a Share Group.
FramebufferID mId;
rx::UniqueSerial mFramebufferSerial;
std::string mLabel;
DrawBuffersVector<FramebufferAttachment> mColorAttachments;
FramebufferAttachment mDepthAttachment;
FramebufferAttachment mStencilAttachment;
// Tracks all the color buffers attached to this FramebufferDesc
DrawBufferMask mColorAttachmentsMask;
DrawBuffersVector<GLenum> mDrawBufferStates;
GLenum mReadBufferState;
DrawBufferMask mEnabledDrawBuffers;
ComponentTypeMask mDrawBufferTypeMask;
GLint mDefaultWidth;
GLint mDefaultHeight;
GLint mDefaultSamples;
bool mDefaultFixedSampleLocations;
GLint mDefaultLayers;
bool mFlipY;
// It's necessary to store all this extra state so we can restore attachments
// when DEPTH_STENCIL/DEPTH/STENCIL is unbound in WebGL 1.
FramebufferAttachment mWebGLDepthStencilAttachment;
FramebufferAttachment mWebGLDepthAttachment;
FramebufferAttachment mWebGLStencilAttachment;
bool mWebGLDepthStencilConsistent;
// Tracks if we need to initialize the resources for each attachment.
angle::BitSet<IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS + 2> mResourceNeedsInit;
bool mDefaultFramebufferReadAttachmentInitialized;
FramebufferAttachment mDefaultFramebufferReadAttachment;
// EXT_sRGB_write_control
SrgbWriteControlMode mSrgbWriteControlMode;
Offset mSurfaceTextureOffset;
// GL_QCOM_framebuffer_foveated
FoveationState mFoveationState;
};
class Framebuffer final : public angle::ObserverInterface,
public LabeledObject,
public angle::Subject
{
public:
// Constructor to build default framebuffers.
Framebuffer(const Context *context, rx::GLImplFactory *factory);
// Constructor to build application-defined framebuffers
Framebuffer(const Context *context, rx::GLImplFactory *factory, FramebufferID id);
~Framebuffer() override;
void onDestroy(const Context *context);
egl::Error setSurfaces(const Context *context,
egl::Surface *surface,
egl::Surface *readSurface);
void setReadSurface(const Context *context, egl::Surface *readSurface);
egl::Error unsetSurfaces(const Context *context);
angle::Result setLabel(const Context *context, const std::string &label) override;
const std::string &getLabel() const override;
rx::FramebufferImpl *getImplementation() const { return mImpl; }
FramebufferID id() const { return mState.mId; }
void setAttachment(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource);
void setAttachmentMultisample(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei samples);
void setAttachmentMultiview(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLint baseViewIndex);
void resetAttachment(const Context *context, GLenum binding);
bool detachTexture(Context *context, TextureID texture);
bool detachRenderbuffer(Context *context, RenderbufferID renderbuffer);
const FramebufferAttachment *getColorAttachment(size_t colorAttachment) const;
const FramebufferAttachment *getDepthAttachment() const;
const FramebufferAttachment *getStencilAttachment() const;
const FramebufferAttachment *getDepthStencilAttachment() const;
const FramebufferAttachment *getDepthOrStencilAttachment() const;
const FramebufferAttachment *getStencilOrDepthStencilAttachment() const;
const FramebufferAttachment *getReadColorAttachment() const;
GLenum getReadColorAttachmentType() const;
const FramebufferAttachment *getFirstColorAttachment() const;
const FramebufferAttachment *getFirstNonNullAttachment() const;
const DrawBuffersVector<FramebufferAttachment> &getColorAttachments() const
{
return mState.mColorAttachments;
}
const FramebufferState &getState() const { return mState; }
const FramebufferAttachment *getAttachment(const Context *context, GLenum attachment) const;
bool isMultiview() const;
bool readDisallowedByMultiview() const;
ANGLE_INLINE GLsizei getNumViews() const { return mState.getNumViews(); }
GLint getBaseViewIndex() const;
Extents getExtents() const;
size_t getDrawbufferStateCount() const;
GLenum getDrawBufferState(size_t drawBuffer) const;
const DrawBuffersVector<GLenum> &getDrawBufferStates() const;
void setDrawBuffers(size_t count, const GLenum *buffers);
const FramebufferAttachment *getDrawBuffer(size_t drawBuffer) const;
ComponentType getDrawbufferWriteType(size_t drawBuffer) const;
ComponentTypeMask getDrawBufferTypeMask() const;
DrawBufferMask getDrawBufferMask() const { return mState.mEnabledDrawBuffers; }
bool hasEnabledDrawBuffer() const;
GLenum getReadBufferState() const;
void setReadBuffer(GLenum buffer);
size_t getNumColorAttachments() const { return mState.mColorAttachments.size(); }
bool hasDepth() const { return mState.hasDepth(); }
bool hasStencil() const { return mState.hasStencil(); }
GLuint getStencilBitCount() const { return mState.getStencilBitCount(); }
bool hasExternalTextureAttachment() const { return mState.hasExternalTextureAttachment(); }
bool hasYUVAttachment() const { return mState.hasYUVAttachment(); }
// This method calls checkStatus.
int getSamples(const Context *context) const;
int getReadBufferResourceSamples(const Context *context) const;
angle::Result getSamplePosition(const Context *context, size_t index, GLfloat *xy) const;
GLint getDefaultWidth() const;
GLint getDefaultHeight() const;
GLint getDefaultSamples() const;
bool getDefaultFixedSampleLocations() const;
GLint getDefaultLayers() const;
bool getFlipY() const;
void setDefaultWidth(const Context *context, GLint defaultWidth);
void setDefaultHeight(const Context *context, GLint defaultHeight);
void setDefaultSamples(const Context *context, GLint defaultSamples);
void setDefaultFixedSampleLocations(const Context *context, bool defaultFixedSampleLocations);
void setDefaultLayers(GLint defaultLayers);
void setFlipY(bool flipY);
bool isFoveationEnabled() const
{
return (mState.mFoveationState.getFoveatedFeatureBits() & GL_FOVEATION_ENABLE_BIT_QCOM);
}
void setFoveatedFeatureBits(const GLuint features);
GLuint getFoveatedFeatureBits() const;
bool isFoveationConfigured() const;
void configureFoveation();
void setFocalPoint(uint32_t layer,
uint32_t focalPointIndex,
float focalX,
float focalY,
float gainX,
float gainY,
float foveaArea);
const FocalPoint &getFocalPoint(uint32_t layer, uint32_t focalPoint) const;
GLuint getSupportedFoveationFeatures() const;
bool hasAnyAttachmentChanged() const { return mAttachmentChangedAfterEnablingFoveation; }
void invalidateCompletenessCache();
ANGLE_INLINE bool cachedStatusValid() { return mCachedStatus.valid(); }
ANGLE_INLINE const FramebufferStatus &checkStatus(const Context *context) const
{
// The default framebuffer is always complete except when it is surfaceless in which
// case it is always unsupported.
ASSERT(!isDefault() || mCachedStatus.valid());
if (isDefault() || (!hasAnyDirtyBit() && mCachedStatus.valid()))
{
return mCachedStatus.value();
}
return checkStatusImpl(context);
}
// Helper for checkStatus == GL_FRAMEBUFFER_COMPLETE.
ANGLE_INLINE bool isComplete(const Context *context) const
{
return checkStatus(context).isComplete();
}
bool hasValidDepthStencil() const;
// Returns the offset into the texture backing the default framebuffer's surface if any. Returns
// zero offset otherwise. The renderer will apply the offset to scissor and viewport rects used
// for draws, clears, and blits.
const Offset &getSurfaceTextureOffset() const;
angle::Result discard(const Context *context, size_t count, const GLenum *attachments);
angle::Result invalidate(const Context *context, size_t count, const GLenum *attachments);
angle::Result invalidateSub(const Context *context,
size_t count,
const GLenum *attachments,
const Rectangle &area);
angle::Result clear(const Context *context, GLbitfield mask);
angle::Result clearBufferfv(const Context *context,
GLenum buffer,
GLint drawbuffer,
const GLfloat *values);
angle::Result clearBufferuiv(const Context *context,
GLenum buffer,
GLint drawbuffer,
const GLuint *values);
angle::Result clearBufferiv(const Context *context,
GLenum buffer,
GLint drawbuffer,
const GLint *values);
angle::Result clearBufferfi(const Context *context,
GLenum buffer,
GLint drawbuffer,
GLfloat depth,
GLint stencil);
GLenum getImplementationColorReadFormat(const Context *context);
GLenum getImplementationColorReadType(const Context *context);
angle::Result readPixels(const Context *context,
const Rectangle &area,
GLenum format,
GLenum type,
const PixelPackState &pack,
Buffer *packBuffer,
void *pixels);
angle::Result blit(const Context *context,
const Rectangle &sourceArea,
const Rectangle &destArea,
GLbitfield mask,
GLenum filter);
bool isDefault() const { return mState.isDefault(); }
enum DirtyBitType : size_t
{
DIRTY_BIT_COLOR_ATTACHMENT_0,
DIRTY_BIT_COLOR_ATTACHMENT_MAX =
DIRTY_BIT_COLOR_ATTACHMENT_0 + IMPLEMENTATION_MAX_DRAW_BUFFERS,
DIRTY_BIT_DEPTH_ATTACHMENT = DIRTY_BIT_COLOR_ATTACHMENT_MAX,
DIRTY_BIT_STENCIL_ATTACHMENT,
DIRTY_BIT_COLOR_BUFFER_CONTENTS_0,
DIRTY_BIT_COLOR_BUFFER_CONTENTS_MAX =
DIRTY_BIT_COLOR_BUFFER_CONTENTS_0 + IMPLEMENTATION_MAX_DRAW_BUFFERS,
DIRTY_BIT_DEPTH_BUFFER_CONTENTS = DIRTY_BIT_COLOR_BUFFER_CONTENTS_MAX,
DIRTY_BIT_STENCIL_BUFFER_CONTENTS,
DIRTY_BIT_DRAW_BUFFERS,
DIRTY_BIT_READ_BUFFER,
DIRTY_BIT_DEFAULT_WIDTH,
DIRTY_BIT_DEFAULT_HEIGHT,
DIRTY_BIT_DEFAULT_SAMPLES,
DIRTY_BIT_DEFAULT_FIXED_SAMPLE_LOCATIONS,
DIRTY_BIT_DEFAULT_LAYERS,
DIRTY_BIT_FRAMEBUFFER_SRGB_WRITE_CONTROL_MODE,
DIRTY_BIT_FLIP_Y,
DIRTY_BIT_FOVEATION,
DIRTY_BIT_UNKNOWN,
DIRTY_BIT_MAX = DIRTY_BIT_UNKNOWN
};
using DirtyBits = angle::BitSet<DIRTY_BIT_MAX>;
bool hasAnyDirtyBit() const { return mDirtyBits.any(); }
DrawBufferMask getActiveFloat32ColorAttachmentDrawBufferMask() const
{
return mFloat32ColorAttachmentBits & getDrawBufferMask();
}
DrawBufferMask getActiveSharedExponentColorAttachmentDrawBufferMask() const
{
return mSharedExponentColorAttachmentBits & getDrawBufferMask();
}
bool hasResourceThatNeedsInit() const { return mState.mResourceNeedsInit.any(); }
angle::Result syncState(const Context *context,
GLenum framebufferBinding,
Command command) const;
void setWriteControlMode(SrgbWriteControlMode srgbWriteControlMode);
// Observer implementation
void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
bool formsRenderingFeedbackLoopWith(const Context *context) const;
bool formsCopyingFeedbackLoopWith(TextureID copyTextureID,
GLint copyTextureLevel,
GLint copyTextureLayer) const;
angle::Result ensureClearAttachmentsInitialized(const Context *context, GLbitfield mask);
angle::Result ensureClearBufferAttachmentsInitialized(const Context *context,
GLenum buffer,
GLint drawbuffer);
angle::Result ensureDrawAttachmentsInitialized(const Context *context);
// Conservatively initializes both read color and depth. Blit can access the depth buffer.
angle::Result ensureReadAttachmentsInitialized(const Context *context);
Box getDimensions() const;
// ANGLE_shader_pixel_local_storage.
// Lazily creates a PixelLocalStorage object for this Framebuffer.
PixelLocalStorage &getPixelLocalStorage(const Context *);
// Returns nullptr if the pixel local storage object has not been created yet.
PixelLocalStorage *peekPixelLocalStorage() const { return mPixelLocalStorage.get(); }
// Detaches the the pixel local storage object so the Context can call deleteContextObjects().
std::unique_ptr<PixelLocalStorage> detachPixelLocalStorage();
void onSwapChainImageChanged()
{
mDirtyBits.set(DIRTY_BIT_COLOR_BUFFER_CONTENTS_0);
onStateChange(angle::SubjectMessage::DirtyBitsFlagged);
}
static const FramebufferID kDefaultDrawFramebufferHandle;
private:
bool detachResourceById(Context *context, GLenum resourceType, GLuint resourceId);
bool detachMatchingAttachment(Context *context,
FramebufferAttachment *attachment,
GLenum matchType,
GLuint matchId);
FramebufferStatus checkStatusWithGLFrontEnd(const Context *context) const;
const FramebufferStatus &checkStatusImpl(const Context *context) const;
void setAttachment(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLuint baseViewIndex,
bool isMultiview,
GLsizei samplesIn);
void commitWebGL1DepthStencilIfConsistent(const Context *context,
GLsizei numViews,
GLuint baseViewIndex,
bool isMultiview,
GLsizei samples);
void setAttachmentImpl(const Context *context,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLuint baseViewIndex,
bool isMultiview,
GLsizei samples);
void updateAttachment(const Context *context,
FramebufferAttachment *attachment,
size_t dirtyBit,
angle::ObserverBinding *onDirtyBinding,
GLenum type,
GLenum binding,
const ImageIndex &textureIndex,
FramebufferAttachmentObject *resource,
GLsizei numViews,
GLuint baseViewIndex,
bool isMultiview,
GLsizei samples);
void markAttachmentsInitialized(const DrawBufferMask &color, bool depth, bool stencil);
// Checks that we have a partially masked clear:
// * some color channels are masked out
// * some stencil values are masked out
// * scissor test partially overlaps the framebuffer
bool partialClearNeedsInit(const Context *context, bool color, bool depth, bool stencil);
bool partialBufferClearNeedsInit(const Context *context, GLenum bufferType);
FramebufferAttachment *getAttachmentFromSubjectIndex(angle::SubjectIndex index);
ANGLE_INLINE void updateFloat32AndSharedExponentColorAttachmentBits(
size_t index,
const InternalFormat *format)
{
mFloat32ColorAttachmentBits.set(index, format->type == GL_FLOAT);
mSharedExponentColorAttachmentBits.set(index, format->type == GL_UNSIGNED_INT_5_9_9_9_REV);
}
angle::Result syncAllDrawAttachmentState(const Context *context, Command command) const;
angle::Result syncAttachmentState(const Context *context,
Command command,
const FramebufferAttachment *attachment) const;
FramebufferState mState;
rx::FramebufferImpl *mImpl;
mutable Optional<FramebufferStatus> mCachedStatus;
DrawBuffersVector<angle::ObserverBinding> mDirtyColorAttachmentBindings;
angle::ObserverBinding mDirtyDepthAttachmentBinding;
angle::ObserverBinding mDirtyStencilAttachmentBinding;
mutable DirtyBits mDirtyBits;
DrawBufferMask mFloat32ColorAttachmentBits;
DrawBufferMask mSharedExponentColorAttachmentBits;
// The dirty bits guard is checked when we get a dependent state change message. We verify that
// we don't set a dirty bit that isn't already set, when inside the dirty bits syncState.
mutable Optional<DirtyBits> mDirtyBitsGuard;
// ANGLE_shader_pixel_local_storage
std::unique_ptr<PixelLocalStorage> mPixelLocalStorage;
// QCOM_framebuffer_foveated
bool mAttachmentChangedAfterEnablingFoveation;
};
inline bool FramebufferState::isDefault() const
{
return mId == Framebuffer::kDefaultDrawFramebufferHandle;
}
using UniqueFramebufferPointer = angle::UniqueObjectPointer<Framebuffer, Context>;
ANGLE_INLINE const FramebufferAttachment *FramebufferState::getFirstNonNullAttachment() const
{
auto *colorAttachment = getFirstColorAttachment();
if (colorAttachment)
{
return colorAttachment;
}
return getDepthOrStencilAttachment();
}
ANGLE_INLINE const FramebufferAttachment *FramebufferState::getFirstColorAttachment() const
{
for (const FramebufferAttachment &colorAttachment : mColorAttachments)
{
if (colorAttachment.isAttached())
{
return &colorAttachment;
}
}
return nullptr;
}
ANGLE_INLINE const FramebufferAttachment *FramebufferState::getDepthOrStencilAttachment() const
{
if (mDepthAttachment.isAttached())
{
return &mDepthAttachment;
}
if (mStencilAttachment.isAttached())
{
return &mStencilAttachment;
}
return nullptr;
}
ANGLE_INLINE GLsizei FramebufferState::getNumViews() const
{
const FramebufferAttachment *attachment = getFirstNonNullAttachment();
if (attachment == nullptr)
{
return FramebufferAttachment::kDefaultNumViews;
}
return attachment->getNumViews();
}
} // namespace gl
#endif // LIBANGLE_FRAMEBUFFER_H_