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
//
// 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.
//
// SurfaceVk.h:
// Defines the class interface for SurfaceVk, implementing SurfaceImpl.
//
#ifndef LIBANGLE_RENDERER_VULKAN_SURFACEVK_H_
#define LIBANGLE_RENDERER_VULKAN_SURFACEVK_H_
#include "common/CircularBuffer.h"
#include "common/SimpleMutex.h"
#include "common/vulkan/vk_headers.h"
#include "libANGLE/renderer/SurfaceImpl.h"
#include "libANGLE/renderer/vulkan/RenderTargetVk.h"
#include "libANGLE/renderer/vulkan/vk_helpers.h"
namespace rx
{
class SurfaceVk : public SurfaceImpl, public angle::ObserverInterface, public vk::Resource
{
public:
angle::Result getAttachmentRenderTarget(const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex,
GLsizei samples,
FramebufferAttachmentRenderTarget **rtOut) override;
protected:
SurfaceVk(const egl::SurfaceState &surfaceState);
~SurfaceVk() override;
void destroy(const egl::Display *display) override;
// We monitor the staging buffer for changes. This handles staged data from outside this class.
void onSubjectStateChange(angle::SubjectIndex index, angle::SubjectMessage message) override;
// width and height can change with client window resizing
EGLint getWidth() const override;
EGLint getHeight() const override;
EGLint mWidth;
EGLint mHeight;
RenderTargetVk mColorRenderTarget;
RenderTargetVk mDepthStencilRenderTarget;
};
class OffscreenSurfaceVk : public SurfaceVk
{
public:
OffscreenSurfaceVk(const egl::SurfaceState &surfaceState, vk::Renderer *renderer);
~OffscreenSurfaceVk() override;
egl::Error initialize(const egl::Display *display) override;
void destroy(const egl::Display *display) override;
egl::Error unMakeCurrent(const gl::Context *context) override;
const vk::ImageHelper *getColorImage() const { return &mColorAttachment.image; }
egl::Error swap(const gl::Context *context, SurfaceSwapFeedback *feedback) override;
egl::Error postSubBuffer(const gl::Context *context,
EGLint x,
EGLint y,
EGLint width,
EGLint height) override;
egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override;
egl::Error bindTexImage(const gl::Context *context,
gl::Texture *texture,
EGLint buffer) override;
egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override;
egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override;
egl::Error getMscRate(EGLint *numerator, EGLint *denominator) override;
void setSwapInterval(const egl::Display *display, EGLint interval) override;
EGLint isPostSubBufferSupported() const override;
EGLint getSwapBehavior() const override;
angle::Result initializeContents(const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex) override;
vk::ImageHelper *getColorAttachmentImage();
egl::Error lockSurface(const egl::Display *display,
EGLint usageHint,
bool preservePixels,
uint8_t **bufferPtrOut,
EGLint *bufferPitchOut) override;
egl::Error unlockSurface(const egl::Display *display, bool preservePixels) override;
EGLint origin() const override;
egl::Error attachToFramebuffer(const gl::Context *context,
gl::Framebuffer *framebuffer) override;
egl::Error detachFromFramebuffer(const gl::Context *context,
gl::Framebuffer *framebuffer) override;
protected:
struct AttachmentImage final : angle::NonCopyable
{
AttachmentImage(SurfaceVk *surfaceVk);
~AttachmentImage();
angle::Result initialize(DisplayVk *displayVk,
EGLint width,
EGLint height,
const vk::Format &vkFormat,
GLint samples,
bool isRobustResourceInitEnabled,
bool hasProtectedContent);
void destroy(const egl::Display *display);
vk::ImageHelper image;
vk::ImageViewHelper imageViews;
angle::ObserverBinding imageObserverBinding;
};
virtual angle::Result initializeImpl(DisplayVk *displayVk);
AttachmentImage mColorAttachment;
AttachmentImage mDepthStencilAttachment;
// EGL_KHR_lock_surface3
vk::BufferHelper mLockBufferHelper;
};
// Data structures used in WindowSurfaceVk
namespace impl
{
static constexpr size_t kSwapHistorySize = 2;
// Old swapchain and associated present fences/semaphores that need to be scheduled for
// recycling/destruction when appropriate.
struct SwapchainCleanupData : angle::NonCopyable
{
SwapchainCleanupData();
SwapchainCleanupData(SwapchainCleanupData &&other);
~SwapchainCleanupData();
// Fences must not be empty (VK_EXT_swapchain_maintenance1 is supported).
VkResult getFencesStatus(VkDevice device) const;
// Waits fences if any. Use before force destroying the swapchain.
void waitFences(VkDevice device, uint64_t timeout) const;
void destroy(VkDevice device,
vk::Recycler<vk::Fence> *fenceRecycler,
vk::Recycler<vk::Semaphore> *semaphoreRecycler);
// The swapchain to be destroyed.
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
// Any present fences/semaphores that were pending recycle at the time the swapchain was
// recreated will be scheduled for recycling at the same time as the swapchain's destruction.
// fences must be in the present operation order.
std::vector<vk::Fence> fences;
std::vector<vk::Semaphore> semaphores;
};
// Each present operation is associated with a wait semaphore. To know when that semaphore can be
// recycled, a swapSerial is used. When that swapSerial is finished, the semaphore used in the
// previous present operation involving imageIndex can be recycled. See doc/PresentSemaphores.md
// for details.
// When VK_EXT_swapchain_maintenance1 is supported, present fence is used instead of the swapSerial.
//
// Old swapchains are scheduled to be destroyed at the same time as the last wait semaphore used to
// present an image to the old swapchains can be recycled (only relevant when
// VK_EXT_swapchain_maintenance1 is not supported).
struct ImagePresentOperation : angle::NonCopyable
{
ImagePresentOperation();
ImagePresentOperation(ImagePresentOperation &&other);
ImagePresentOperation &operator=(ImagePresentOperation &&other);
~ImagePresentOperation();
void destroy(VkDevice device,
vk::Recycler<vk::Fence> *fenceRecycler,
vk::Recycler<vk::Semaphore> *semaphoreRecycler);
// fence is only used when VK_EXT_swapchain_maintenance1 is supported.
vk::Fence fence;
vk::Semaphore semaphore;
// Below members only relevant when VK_EXT_swapchain_maintenance1 is not supported.
// Used to associate a swapSerial with the previous present operation of the image.
uint32_t imageIndex;
QueueSerial queueSerial;
std::deque<SwapchainCleanupData> oldSwapchains;
};
// Swapchain images and their associated objects.
struct SwapchainImage : angle::NonCopyable
{
SwapchainImage();
SwapchainImage(SwapchainImage &&other);
~SwapchainImage();
std::unique_ptr<vk::ImageHelper> image;
vk::ImageViewHelper imageViews;
vk::Framebuffer framebuffer;
vk::Framebuffer fetchFramebuffer;
uint64_t frameNumber = 0;
};
enum class ImageAcquireState
{
Unacquired,
NeedToProcessResult,
Ready,
};
// Associated data for a call to vkAcquireNextImageKHR without necessarily holding the share group
// and global locks but ONLY from a thread where Surface is current.
struct UnlockedAcquireData : angle::NonCopyable
{
// Given that the CPU is throttled after a number of swaps, there is an upper bound to the
// number of semaphores that are used to acquire swapchain images, and that is
// kSwapHistorySize+1:
//
// Unrelated submission in Submission as part of
// the middle of frame buffer swap
// | |
// V V
// Frame i: ... ANI ... QS (fence Fa) ... QS (Fence Fb) QP Wait(..)
// Frame i+1: ... ANI ... QS (fence Fc) ... QS (Fence Fd) QP Wait(..) <--\
// Frame i+2: ... ANI ... QS (fence Fe) ... QS (Fence Ff) QP Wait(Fb) |
// ^ |
// | |
// CPU throttling |
// |
// Note: app should throttle itself here (equivalent of Wait(Fb))
//
// In frame i+2 (2 is kSwapHistorySize), ANGLE waits on fence Fb which means that the semaphore
// used for Frame i's ANI can be reused (because Fb-is-signalled implies Fa-is-signalled).
// Before this wait, there were three acquire semaphores in use corresponding to frames i, i+1
// and i+2. Frame i+3 can reuse the semaphore of frame i.
angle::CircularBuffer<vk::Semaphore, impl::kSwapHistorySize + 1> acquireImageSemaphores;
};
struct UnlockedAcquireResult : angle::NonCopyable
{
// The result of the call to vkAcquireNextImageKHR.
VkResult result = VK_SUCCESS;
// Semaphore to signal.
VkSemaphore acquireSemaphore = VK_NULL_HANDLE;
// Image index that was acquired
uint32_t imageIndex = std::numeric_limits<uint32_t>::max();
};
struct ImageAcquireOperation : angle::NonCopyable
{
// Initially image needs to be acquired.
ImageAcquireState state = ImageAcquireState::Unacquired;
// No synchronization is necessary when making the vkAcquireNextImageKHR call since it is ONLY
// possible on a thread where Surface is current.
UnlockedAcquireData unlockedAcquireData;
UnlockedAcquireResult unlockedAcquireResult;
};
enum class SurfaceSizeState
{
InvalidSwapchain,
Unresolved,
Resolved,
};
} // namespace impl
class WindowSurfaceVk : public SurfaceVk
{
public:
WindowSurfaceVk(const egl::SurfaceState &surfaceState, EGLNativeWindowType window);
~WindowSurfaceVk() override;
void destroy(const egl::Display *display) override;
egl::Error initialize(const egl::Display *display) override;
egl::Error unMakeCurrent(const gl::Context *context) override;
angle::Result getAttachmentRenderTarget(const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex,
GLsizei samples,
FramebufferAttachmentRenderTarget **rtOut) override;
egl::Error prepareSwap(const gl::Context *context) override;
egl::Error swap(const gl::Context *context, SurfaceSwapFeedback *feedback) override;
egl::Error swapWithDamage(const gl::Context *context,
const EGLint *rects,
EGLint n_rects,
SurfaceSwapFeedback *feedback) override;
egl::Error postSubBuffer(const gl::Context *context,
EGLint x,
EGLint y,
EGLint width,
EGLint height) override;
egl::Error querySurfacePointerANGLE(EGLint attribute, void **value) override;
egl::Error bindTexImage(const gl::Context *context,
gl::Texture *texture,
EGLint buffer) override;
egl::Error releaseTexImage(const gl::Context *context, EGLint buffer) override;
egl::Error getSyncValues(EGLuint64KHR *ust, EGLuint64KHR *msc, EGLuint64KHR *sbc) override;
egl::Error getMscRate(EGLint *numerator, EGLint *denominator) override;
void setSwapInterval(const egl::Display *display, EGLint interval) override;
// Sizes that Surface will have after render target is first accessed (e.g. after draw).
egl::Error getUserWidth(const egl::Display *display, EGLint *value) const final;
egl::Error getUserHeight(const egl::Display *display, EGLint *value) const final;
EGLint isPostSubBufferSupported() const override;
EGLint getSwapBehavior() const override;
angle::Result initializeContents(const gl::Context *context,
GLenum binding,
const gl::ImageIndex &imageIndex) override;
vk::Framebuffer &chooseFramebuffer();
angle::Result getCurrentFramebuffer(ContextVk *context,
vk::FramebufferFetchMode fetchMode,
const vk::RenderPass &compatibleRenderPass,
vk::Framebuffer *framebufferOut);
VkSurfaceTransformFlagBitsKHR getPreTransform() const
{
if (mEmulatedPreTransform != VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR)
{
return mEmulatedPreTransform;
}
return mPreTransform;
}
egl::Error setAutoRefreshEnabled(bool enabled) override;
egl::Error getBufferAge(const gl::Context *context, EGLint *age) override;
egl::Error setRenderBuffer(EGLint renderBuffer) override;
bool isSharedPresentMode() const { return IsSharedPresentMode(mSwapchainPresentMode); }
bool isSharedPresentModeDesired() const
{
return IsSharedPresentMode(getDesiredSwapchainPresentMode());
}
egl::Error lockSurface(const egl::Display *display,
EGLint usageHint,
bool preservePixels,
uint8_t **bufferPtrOut,
EGLint *bufferPitchOut) override;
egl::Error unlockSurface(const egl::Display *display, bool preservePixels) override;
EGLint origin() const override;
egl::Error attachToFramebuffer(const gl::Context *context,
gl::Framebuffer *framebuffer) override;
egl::Error detachFromFramebuffer(const gl::Context *context,
gl::Framebuffer *framebuffer) override;
angle::Result onSharedPresentContextFlush(ContextVk *contextVk);
bool hasStagedUpdates() const;
void setTimestampsEnabled(bool enabled) override;
EGLint getCompressionRate(const egl::Display *display) const override;
protected:
angle::Result swapImpl(ContextVk *contextVk,
const EGLint *rects,
EGLint n_rects,
const void *pNextChain,
SurfaceSwapFeedback *feedback);
EGLNativeWindowType mNativeWindowType;
VkSurfaceKHR mSurface;
VkBool32 mSupportsProtectedSwapchain;
private:
// Present modes that are compatible with the current mode. If mDesiredSwapchainPresentMode is
// in this list, mode switch can happen without the need to recreate the swapchain.
// There are currently only 6 possible present modes but vector is bigger for a workaround.
static constexpr uint32_t kCompatiblePresentModesSize = 10;
using CompatiblePresentModes =
angle::FixedVector<VkPresentModeKHR, kCompatiblePresentModesSize>;
static bool IsSharedPresentMode(vk::PresentMode presentMode)
{
return (presentMode == vk::PresentMode::SharedDemandRefreshKHR ||
presentMode == vk::PresentMode::SharedContinuousRefreshKHR);
}
virtual angle::Result createSurfaceVk(vk::ErrorContext *context) = 0;
virtual angle::Result getCurrentWindowSize(vk::ErrorContext *context,
gl::Extents *extentsOut) const = 0;
virtual angle::Result getWindowVisibility(vk::ErrorContext *context, bool *isVisibleOut) const;
impl::SurfaceSizeState getSizeState() const;
void setSizeState(impl::SurfaceSizeState sizeState);
angle::Result getUserExtentsImpl(vk::ErrorContext *context, VkExtent2D *extentOut) const;
vk::PresentMode getDesiredSwapchainPresentMode() const;
void setDesiredSwapchainPresentMode(vk::PresentMode presentMode);
void setDesiredSwapInterval(EGLint interval);
angle::Result initializeImpl(DisplayVk *displayVk, bool *anyMatchesOut);
// Invalidates the swapchain pointer, releases images, and defers acquire next swapchain image.
void invalidateSwapchain(vk::Renderer *renderer);
angle::Result recreateSwapchain(vk::ErrorContext *context);
angle::Result createSwapChain(vk::ErrorContext *context);
angle::Result collectOldSwapchain(vk::ErrorContext *context, VkSwapchainKHR swapchain);
angle::Result queryAndAdjustSurfaceCaps(
vk::ErrorContext *context,
vk::PresentMode presentMode,
VkSurfaceCapabilitiesKHR *surfaceCapsOut,
CompatiblePresentModes *compatiblePresentModesOut) const;
void adjustSurfaceExtent(VkExtent2D *extent) const;
// This method will invalidate the swapchain (if needed due to present returning OUT_OF_DATE, or
// swap interval changing). Updates the current swapchain present mode.
void checkForOutOfDateSwapchain(vk::Renderer *renderer, bool presentOutOfDate);
angle::Result prepareSwapchainForAcquireNextImage(vk::ErrorContext *context);
void createSwapchainImages(uint32_t imageCount);
void releaseSwapchainImages(vk::Renderer *renderer);
void destroySwapChainImages(DisplayVk *displayVk);
// Called when a swapchain image whose acquisition was deferred must be acquired or unlocked
// ANI result processed. This method will recreate the swapchain (if needed due to surface size
// changing etc, by calling prepareSwapchainForAcquireNextImage()) and call the
// acquireNextSwapchainImage(). On some platforms, vkAcquireNextImageKHR() returns OUT_OF_DATE
// instead of present, which is also recreates the swapchain. It is scheduled to be called
// later by deferAcquireNextImage().
angle::Result doDeferredAcquireNextImage(vk::ErrorContext *context);
// This method calls vkAcquireNextImageKHR() to acquire the next swapchain image or processes
// unlocked ANI result, then sets up the acquired image.
VkResult acquireNextSwapchainImage(vk::ErrorContext *context);
// This method is called when a swapchain image is presented. It schedules
// doDeferredAcquireNextImage() to be called later.
void deferAcquireNextImage();
bool skipAcquireNextSwapchainImageForSharedPresentMode() const;
angle::Result computePresentOutOfDate(vk::ErrorContext *context,
VkResult result,
bool *presentOutOfDate);
angle::Result prePresentSubmit(ContextVk *contextVk, const vk::Semaphore &presentSemaphore);
angle::Result recordPresentLayoutBarrierIfNecessary(ContextVk *contextVk);
angle::Result present(ContextVk *contextVk,
const EGLint *rects,
EGLint n_rects,
const void *pNextChain,
bool *presentOutOfDate);
angle::Result cleanUpPresentHistory(vk::ErrorContext *context);
angle::Result cleanUpOldSwapchains(vk::ErrorContext *context);
// Throttle the CPU such that application's logic and command buffer recording doesn't get more
// than two frame ahead of the frame being rendered (and three frames ahead of the one being
// presented). This is a failsafe, as the application should ensure command buffer recording is
// not ahead of the frame being rendered by *one* frame.
angle::Result throttleCPU(vk::ErrorContext *context, const QueueSerial ¤tSubmitSerial);
void mergeImageResourceUses();
// Finish all GPU operations on the surface
angle::Result finish(vk::ErrorContext *context);
void updateOverlay(ContextVk *contextVk) const;
bool overlayHasEnabledWidget(ContextVk *contextVk) const;
angle::Result drawOverlay(ContextVk *contextVk, impl::SwapchainImage *image) const;
bool isMultiSampled() const;
bool supportsPresentMode(vk::PresentMode presentMode) const;
bool updateColorSpace(DisplayVk *displayVk);
angle::FormatID getIntendedFormatID(vk::Renderer *renderer);
angle::FormatID getActualFormatID(vk::Renderer *renderer);
bool mIsSurfaceSizedBySwapchain;
// Atomic is to allow update state without necessarily locking the mSizeMutex.
std::atomic<impl::SurfaceSizeState> mSizeState;
// Protects mWidth and mHeight against getUserWidth()/getUserHeight() calls.
mutable angle::SimpleMutex mSizeMutex;
std::vector<vk::PresentMode> mPresentModes;
VkSwapchainKHR mSwapchain; // Current swapchain (same as last created or NULL)
VkSwapchainKHR mLastSwapchain; // Last created non retired swapchain (or NULL if retired)
// Cached information used to recreate swapchains.
vk::PresentMode mSwapchainPresentMode; // Current swapchain mode
std::atomic<vk::PresentMode> mDesiredSwapchainPresentMode; // Desired swapchain mode
uint32_t mMinImageCount;
VkSurfaceTransformFlagBitsKHR mPreTransform;
VkSurfaceTransformFlagBitsKHR mEmulatedPreTransform;
VkCompositeAlphaFlagBitsKHR mCompositeAlpha;
VkColorSpaceKHR mSurfaceColorSpace;
VkImageCompressionFlagBitsEXT mCompressionFlags;
VkImageCompressionFixedRateFlagsEXT mFixedRateFlags;
CompatiblePresentModes mCompatiblePresentModes;
// A circular buffer that stores the serial of the submission fence of the context on every
// swap. The CPU is throttled by waiting for the 2nd previous serial to finish. This should
// normally be a no-op, as the application should pace itself to avoid input lag, and is
// implemented in ANGLE as a fail safe. Removing this throttling requires untangling it from
// acquire semaphore recycling (see mAcquireImageSemaphores above)
angle::CircularBuffer<QueueSerial, impl::kSwapHistorySize> mSwapHistory;
// The previous swapchain which needs to be scheduled for destruction when appropriate. This
// will be done when the first image of the current swapchain is presented or when fences are
// signaled (when VK_EXT_swapchain_maintenance1 is supported). If there were older swapchains
// pending destruction when the swapchain is recreated, they will accumulate and be destroyed
// with the previous swapchain.
//
// Note that if the user resizes the window such that the swapchain is recreated every frame,
// this array can go grow indefinitely.
std::deque<impl::SwapchainCleanupData> mOldSwapchains;
std::vector<impl::SwapchainImage> mSwapchainImages;
std::vector<angle::ObserverBinding> mSwapchainImageBindings;
uint32_t mCurrentSwapchainImageIndex;
// There is no direct signal from Vulkan regarding when a Present semaphore can be be reused.
// During window resizing when swapchains are recreated every frame, the number of in-flight
// present semaphores can grow indefinitely. See doc/PresentSemaphores.md.
vk::Recycler<vk::Semaphore> mPresentSemaphoreRecycler;
// Fences are associated with present semaphores to know when they can be recycled.
vk::Recycler<vk::Fence> mPresentFenceRecycler;
// The presentation history, used to recycle semaphores and destroy old swapchains.
std::deque<impl::ImagePresentOperation> mPresentHistory;
// Depth/stencil image. Possibly multisampled.
vk::ImageHelper mDepthStencilImage;
vk::ImageViewHelper mDepthStencilImageViews;
angle::ObserverBinding mDepthStencilImageBinding;
// Multisample color image, view and framebuffer, if multisampling enabled.
vk::ImageHelper mColorImageMS;
vk::ImageViewHelper mColorImageMSViews;
angle::ObserverBinding mColorImageMSBinding;
vk::Framebuffer mFramebufferMS;
impl::ImageAcquireOperation mAcquireOperation;
// EGL_EXT_buffer_age: Track frame count.
uint64_t mFrameCount;
// EGL_KHR_lock_surface3
vk::BufferHelper mLockBufferHelper;
// EGL_KHR_partial_update
uint64_t mBufferAgeQueryFrameNumber;
// GL_EXT_shader_framebuffer_fetch
vk::FramebufferFetchMode mFramebufferFetchMode = vk::FramebufferFetchMode::None;
};
} // namespace rx
#endif // LIBANGLE_RENDERER_VULKAN_SURFACEVK_H_