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
gpu / vulkan / vulkan_swap_chain.cc [blame]
// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "gpu/vulkan/vulkan_swap_chain.h"
#include "base/compiler_specific.h"
#include "base/debug/crash_logging.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool.h"
#include "base/threading/scoped_blocking_call.h"
#include "gpu/vulkan/vulkan_device_queue.h"
#include "gpu/vulkan/vulkan_fence_helper.h"
#include "gpu/vulkan/vulkan_function_pointers.h"
namespace gpu {
namespace {
VkSemaphore CreateSemaphore(VkDevice vk_device) {
// Generic semaphore creation structure.
constexpr VkSemaphoreCreateInfo semaphore_create_info = {
VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO};
VkSemaphore vk_semaphore = VK_NULL_HANDLE;
auto result = vkCreateSemaphore(vk_device, &semaphore_create_info,
/*pAllocator=*/nullptr, &vk_semaphore);
LOG_IF(FATAL, VK_SUCCESS != result)
<< "vkCreateSemaphore() failed: " << result;
return vk_semaphore;
}
} // namespace
VulkanSwapChain::VulkanSwapChain(uint64_t acquire_next_image_timeout_ns)
: acquire_next_image_timeout_ns_(acquire_next_image_timeout_ns) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK_GT(acquire_next_image_timeout_ns, 0u);
}
VulkanSwapChain::~VulkanSwapChain() {
#if DCHECK_IS_ON()
base::AutoLock auto_lock(lock_);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(images_.empty());
DCHECK_EQ(static_cast<VkSwapchainKHR>(VK_NULL_HANDLE), swap_chain_);
#endif
}
bool VulkanSwapChain::Initialize(
VulkanDeviceQueue* device_queue,
VkSurfaceKHR surface,
const VkSurfaceFormatKHR& surface_format,
const gfx::Size& image_size,
uint32_t min_image_count,
VkImageUsageFlags image_usage_flags,
VkSurfaceTransformFlagBitsKHR pre_transform,
VkCompositeAlphaFlagBitsKHR composite_alpha,
std::unique_ptr<VulkanSwapChain> old_swap_chain) {
base::AutoLock auto_lock(lock_);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(device_queue);
device_queue_ = device_queue;
is_incremental_present_supported_ =
gfx::HasExtension(device_queue_->enabled_extensions(),
VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
device_queue_->GetFenceHelper()->ProcessCleanupTasks();
return InitializeSwapChain(surface, surface_format, image_size,
min_image_count, image_usage_flags, pre_transform,
composite_alpha, std::move(old_swap_chain)) &&
InitializeSwapImages(surface_format) && AcquireNextImage();
}
void VulkanSwapChain::Destroy() {
base::AutoLock auto_lock(lock_);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
WaitUntilPostSubBufferAsyncFinished();
if (!pending_semaphores_queue_.empty()) [[unlikely]] {
auto* fence_helper = device_queue_->GetFenceHelper();
fence_helper->EnqueueCleanupTaskForSubmittedWork(base::BindOnce(
[](base::circular_deque<PendingSemaphores> pending_semaphores_queue,
VulkanDeviceQueue* device_queue, bool device_lost) {
VkDevice device = device_queue->GetVulkanDevice();
for (auto& pending_semaphores : pending_semaphores_queue) {
vkDestroySemaphore(device, pending_semaphores.acquire_semaphore,
/*pAllocator=*/nullptr);
vkDestroySemaphore(device, pending_semaphores.present_semaphore,
/*pAllocator=*/nullptr);
}
},
std::move(pending_semaphores_queue_)));
pending_semaphores_queue_.clear();
}
DCHECK(!is_writing_);
DestroySwapImages();
DestroySwapChain();
}
gfx::SwapResult VulkanSwapChain::PostSubBuffer(const gfx::Rect& rect) {
base::AutoLock auto_lock(lock_);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
WaitUntilPostSubBufferAsyncFinished();
DCHECK(!has_pending_post_sub_buffer_);
if (!PresentBuffer(rect)) [[unlikely]] {
return gfx::SwapResult::SWAP_FAILED;
}
if (!AcquireNextImage()) [[unlikely]] {
return gfx::SwapResult::SWAP_FAILED;
}
return gfx::SwapResult::SWAP_ACK;
}
void VulkanSwapChain::PostSubBufferAsync(
const gfx::Rect& rect,
PostSubBufferCompletionCallback callback) {
base::AutoLock auto_lock(lock_);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
WaitUntilPostSubBufferAsyncFinished();
DCHECK(!has_pending_post_sub_buffer_);
if (!PresentBuffer(rect)) [[unlikely]] {
base::SingleThreadTaskRunner::GetCurrentDefault()->PostTask(
FROM_HERE,
base::BindOnce(std::move(callback), gfx::SwapResult::SWAP_FAILED));
return;
}
DCHECK_EQ(state_, VK_SUCCESS);
has_pending_post_sub_buffer_ = true;
post_sub_buffer_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(
[](VulkanSwapChain* self,
scoped_refptr<base::SingleThreadTaskRunner> task_runner,
PostSubBufferCompletionCallback callback) {
base::AutoLock auto_lock(self->lock_);
DCHECK(self->has_pending_post_sub_buffer_);
auto swap_result = self->AcquireNextImage()
? gfx::SwapResult::SWAP_ACK
: gfx::SwapResult::SWAP_FAILED;
task_runner->PostTask(
FROM_HERE, base::BindOnce(std::move(callback), swap_result));
self->has_pending_post_sub_buffer_ = false;
self->condition_variable_.Signal();
},
base::Unretained(this),
base::SingleThreadTaskRunner::GetCurrentDefault(),
std::move(callback)));
}
bool VulkanSwapChain::InitializeSwapChain(
VkSurfaceKHR surface,
const VkSurfaceFormatKHR& surface_format,
const gfx::Size& image_size,
uint32_t min_image_count,
VkImageUsageFlags image_usage_flags,
VkSurfaceTransformFlagBitsKHR pre_transform,
VkCompositeAlphaFlagBitsKHR composite_alpha,
std::unique_ptr<VulkanSwapChain> old_swap_chain) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
VkDevice device = device_queue_->GetVulkanDevice();
VkResult result = VK_SUCCESS;
VkSwapchainCreateInfoKHR swap_chain_create_info = {
.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR,
.flags = 0,
.surface = surface,
.minImageCount = min_image_count,
.imageFormat = surface_format.format,
.imageColorSpace = surface_format.colorSpace,
.imageExtent = {static_cast<uint32_t>(image_size.width()),
static_cast<uint32_t>(image_size.height())},
.imageArrayLayers = 1,
.imageUsage = image_usage_flags,
.imageSharingMode = VK_SHARING_MODE_EXCLUSIVE,
.preTransform = pre_transform,
.compositeAlpha = composite_alpha,
.presentMode = VK_PRESENT_MODE_FIFO_KHR,
.clipped = VK_TRUE,
.oldSwapchain = VK_NULL_HANDLE,
};
if (old_swap_chain) [[likely]] {
base::AutoLock auto_lock(old_swap_chain->lock_);
old_swap_chain->WaitUntilPostSubBufferAsyncFinished();
swap_chain_create_info.oldSwapchain = old_swap_chain->swap_chain_;
// Reuse |post_sub_buffer_task_runner_| and |pending_semaphores_queue_|
// from the |old_swap_chain|.
post_sub_buffer_task_runner_ = old_swap_chain->post_sub_buffer_task_runner_;
pending_semaphores_queue_ =
std::move(old_swap_chain->pending_semaphores_queue_);
old_swap_chain->pending_semaphores_queue_.clear();
}
VkSwapchainKHR new_swap_chain = VK_NULL_HANDLE;
result = vkCreateSwapchainKHR(device, &swap_chain_create_info,
/*pAllocator=*/nullptr, &new_swap_chain);
if (old_swap_chain) [[likely]] {
auto* fence_helper = device_queue_->GetFenceHelper();
fence_helper->EnqueueVulkanObjectCleanupForSubmittedWork(
std::move(old_swap_chain));
}
if (VK_SUCCESS != result) [[unlikely]] {
LOG(DFATAL) << "vkCreateSwapchainKHR() failed: " << result;
return false;
}
swap_chain_ = new_swap_chain;
size_ = gfx::Size(swap_chain_create_info.imageExtent.width,
swap_chain_create_info.imageExtent.height);
if (!post_sub_buffer_task_runner_) [[unlikely]] {
post_sub_buffer_task_runner_ = base::ThreadPool::CreateSequencedTaskRunner(
{base::TaskPriority::USER_BLOCKING,
base::TaskShutdownBehavior::BLOCK_SHUTDOWN, base::MayBlock()});
}
image_usage_ = image_usage_flags;
return true;
}
void VulkanSwapChain::DestroySwapChain() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
VkDevice device = device_queue_->GetVulkanDevice();
// vkDestroySwapchainKHR() will hang on X11, after resuming from hibernate.
// It is because a Xserver issue. To workaround it, we will not call
// vkDestroySwapchainKHR(), if the problem is detected. When the problem is
// detected, we will consider it as context lost, so the GPU process will
// tear down all resources, and a new GPU process will be created. So it is OK
// to leak this swapchain.
// TODO(penghuang): remove this workaround when Xserver issue is fixed
// upstream. https://crbug.com/1130495
if (!destroy_swapchain_will_hang_)
vkDestroySwapchainKHR(device, swap_chain_, /*pAllocator=*/nullptr);
swap_chain_ = VK_NULL_HANDLE;
}
bool VulkanSwapChain::InitializeSwapImages(
const VkSurfaceFormatKHR& surface_format) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
VkDevice device = device_queue_->GetVulkanDevice();
VkResult result = VK_SUCCESS;
uint32_t image_count = 0;
result = vkGetSwapchainImagesKHR(device, swap_chain_, &image_count, nullptr);
if (VK_SUCCESS != result) [[unlikely]] {
LOG(FATAL) << "vkGetSwapchainImagesKHR(nullptr) failed: " << result;
}
std::vector<VkImage> images(image_count);
result =
vkGetSwapchainImagesKHR(device, swap_chain_, &image_count, images.data());
if (VK_SUCCESS != result) [[unlikely]] {
LOG(FATAL) << "vkGetSwapchainImagesKHR(images) failed: " << result;
}
images_.resize(image_count);
for (uint32_t i = 0; i < image_count; ++i) {
auto& image_data = images_[i];
image_data.image = images[i];
}
return true;
}
void VulkanSwapChain::DestroySwapImages() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
VkDevice device = device_queue_->GetVulkanDevice();
for (auto& image : images_) {
vkDestroySemaphore(device, image.acquire_semaphore,
/*pAllocator=*/nullptr);
vkDestroySemaphore(device, image.present_semaphore,
/*pAllocator=*/nullptr);
}
images_.clear();
}
bool VulkanSwapChain::BeginWriteCurrentImage(VkImage* image,
uint32_t* image_index,
VkImageLayout* image_layout,
VkImageUsageFlags* image_usage,
VkSemaphore* begin_semaphore,
VkSemaphore* end_semaphore) {
base::AutoLock auto_lock(lock_);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(image);
DCHECK(image_index);
DCHECK(image_layout);
DCHECK(image_usage);
DCHECK(begin_semaphore);
DCHECK(end_semaphore);
DCHECK(!is_writing_);
if (state_ != VK_SUCCESS) [[unlikely]] {
return false;
}
if (!acquired_image_) [[unlikely]] {
return false;
}
auto& current_image_data = images_[*acquired_image_];
if (!new_acquired_) [[unlikely]] {
// In this case, {Begin,End}WriteCurrentImage has been called, but
// PostSubBuffer() is not call, so |acquire_semaphore| has been wait on for
// the previous write request, release it with FenceHelper.
device_queue_->GetFenceHelper()->EnqueueSemaphoreCleanupForSubmittedWork(
current_image_data.acquire_semaphore);
// Use |end_semaphore| from previous write as |begin_semaphore| for the new
// write request, and create a new semaphore for |end_semaphore|.
current_image_data.acquire_semaphore = current_image_data.present_semaphore;
current_image_data.present_semaphore =
CreateSemaphore(device_queue_->GetVulkanDevice());
if (current_image_data.present_semaphore == VK_NULL_HANDLE) [[unlikely]] {
return false;
}
}
*image = current_image_data.image;
*image_index = *acquired_image_;
*image_layout = current_image_data.image_layout;
*image_usage = image_usage_;
*begin_semaphore = current_image_data.acquire_semaphore;
*end_semaphore = current_image_data.present_semaphore;
is_writing_ = true;
return true;
}
void VulkanSwapChain::EndWriteCurrentImage() {
base::AutoLock auto_lock(lock_);
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK(is_writing_);
DCHECK(acquired_image_);
auto& current_image_data = images_[*acquired_image_];
current_image_data.image_layout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
is_writing_ = false;
new_acquired_ = false;
}
bool VulkanSwapChain::PresentBuffer(const gfx::Rect& rect) {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
DCHECK_EQ(state_, VK_SUCCESS);
DCHECK(acquired_image_);
auto& current_image_data = images_[*acquired_image_];
DCHECK(current_image_data.present_semaphore != VK_NULL_HANDLE);
VkRectLayerKHR rect_layer = {
.offset = {rect.x(), rect.y()},
.extent = {static_cast<uint32_t>(rect.width()),
static_cast<uint32_t>(rect.height())},
.layer = 0,
};
VkPresentRegionKHR present_region = {
.rectangleCount = 1,
.pRectangles = &rect_layer,
};
VkPresentRegionsKHR present_regions = {
.sType = VK_STRUCTURE_TYPE_PRESENT_REGIONS_KHR,
.swapchainCount = 1,
.pRegions = &present_region,
};
VkPresentInfoKHR present_info = {
.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
.pNext = is_incremental_present_supported_ ? &present_regions : nullptr,
.waitSemaphoreCount = 1,
.pWaitSemaphores = ¤t_image_data.present_semaphore,
.swapchainCount = 1,
.pSwapchains = &swap_chain_,
.pImageIndices = &acquired_image_.value(),
};
VkQueue queue = device_queue_->GetVulkanQueue();
auto result = vkQueuePresentKHR(queue, &present_info);
if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) [[unlikely]] {
LOG(DFATAL) << "vkQueuePresentKHR() failed: " << result;
state_ = result;
return false;
}
VLOG_IF(2, result == VK_SUBOPTIMAL_KHR) << "Swapchain is suboptimal.";
acquired_image_.reset();
return true;
}
bool VulkanSwapChain::AcquireNextImage() {
DCHECK_EQ(state_, VK_SUCCESS);
DCHECK(!acquired_image_);
// VulkanDeviceQueue is not threadsafe for now, but |device_queue_| will not
// be released, and device_queue_->device will never be changed after
// initialization, so it is safe for now.
// TODO(penghuang): make VulkanDeviceQueue threadsafe.
VkDevice device = device_queue_->GetVulkanDevice();
VkSemaphore acquire_semaphore = VK_NULL_HANDLE;
VkSemaphore present_semaphore = VK_NULL_HANDLE;
if (!GetOrCreateSemaphores(&acquire_semaphore, &present_semaphore))
return false;
uint32_t next_image;
auto result = ({
base::ScopedBlockingCall scoped_blocking_call(
FROM_HERE, base::BlockingType::MAY_BLOCK);
vkAcquireNextImageKHR(device, swap_chain_, acquire_next_image_timeout_ns_,
acquire_semaphore, /*fence=*/VK_NULL_HANDLE,
&next_image);
});
if (result == VK_TIMEOUT) [[unlikely]] {
LOG(ERROR) << "vkAcquireNextImageKHR() hangs.";
vkDestroySemaphore(device, acquire_semaphore, /*pAllocator=*/nullptr);
vkDestroySemaphore(device, present_semaphore, /*pAllocator=*/nullptr);
state_ = VK_ERROR_SURFACE_LOST_KHR;
destroy_swapchain_will_hang_ = true;
return false;
}
if (result != VK_SUCCESS && result != VK_SUBOPTIMAL_KHR) [[unlikely]] {
LOG(DFATAL) << "vkAcquireNextImageKHR() failed: " << result;
vkDestroySemaphore(device, acquire_semaphore, /*pAllocator=*/nullptr);
vkDestroySemaphore(device, present_semaphore, /*pAllocator=*/nullptr);
state_ = result;
return false;
}
acquired_image_.emplace(next_image);
new_acquired_ = true;
// For the previous use of the image, |current_image_data.acquire_semaphore|
// has been wait on for the compositing work last time,
// and |current_image_data.present_semaphore| has been wait on by present
// engine for presenting the image last time, so those two semaphores should
// be free for reusing when |num_images() * 2| frames are passed, because it
// is impossible there are more than |num_images() * 2| frames are in flight.
auto& current_image_data = images_[next_image];
ReturnSemaphores(current_image_data.acquire_semaphore,
current_image_data.present_semaphore);
current_image_data.acquire_semaphore = acquire_semaphore;
current_image_data.present_semaphore = present_semaphore;
return true;
}
void VulkanSwapChain::WaitUntilPostSubBufferAsyncFinished() {
DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
while (has_pending_post_sub_buffer_) {
base::ScopedBlockingCall scoped_blocking_call(
FROM_HERE, base::BlockingType::WILL_BLOCK);
condition_variable_.Wait();
}
DCHECK(acquired_image_ || state_ != VK_SUCCESS);
}
bool VulkanSwapChain::GetOrCreateSemaphores(VkSemaphore* acquire_semaphore,
VkSemaphore* present_semaphore) {
// When pending semaphores are more than |num_images() * 2|, we will
// assume the semaphores at the front of the queue has been signaled
// and can be reused (because it is impossible there are more than
// |num_images() * 2| frames are in flight). Otherwise, new semaphores
// will be created.
if (pending_semaphores_queue_.size() >= num_images() * 2) [[likely]] {
const auto& semaphores = pending_semaphores_queue_.front();
DCHECK(semaphores.acquire_semaphore != VK_NULL_HANDLE);
DCHECK(semaphores.present_semaphore != VK_NULL_HANDLE);
pending_semaphores_queue_.pop_front();
*acquire_semaphore = semaphores.acquire_semaphore;
*present_semaphore = semaphores.present_semaphore;
return true;
}
VkDevice device = device_queue_->GetVulkanDevice();
*acquire_semaphore = CreateSemaphore(device);
if (*acquire_semaphore == VK_NULL_HANDLE)
return false;
*present_semaphore = CreateSemaphore(device);
if (*present_semaphore == VK_NULL_HANDLE) {
// Failed to get or create semaphores, release resources.
vkDestroySemaphore(device, *acquire_semaphore, /*pAllocator=*/nullptr);
return false;
}
return true;
}
void VulkanSwapChain::ReturnSemaphores(VkSemaphore acquire_semaphore,
VkSemaphore present_semaphore) {
DCHECK_EQ(acquire_semaphore != VK_NULL_HANDLE,
present_semaphore != VK_NULL_HANDLE);
if (acquire_semaphore == VK_NULL_HANDLE)
return;
pending_semaphores_queue_.push_back({acquire_semaphore, present_semaphore});
}
VulkanSwapChain::ScopedWrite::ScopedWrite(VulkanSwapChain* swap_chain)
: swap_chain_(swap_chain) {
success_ = swap_chain_->BeginWriteCurrentImage(
&image_, &image_index_, &image_layout_, &image_usage_, &begin_semaphore_,
&end_semaphore_);
if (success_) [[likely]] {
DCHECK(begin_semaphore_ != VK_NULL_HANDLE);
DCHECK(end_semaphore_ != VK_NULL_HANDLE);
} else {
DCHECK(begin_semaphore_ == VK_NULL_HANDLE);
DCHECK(end_semaphore_ == VK_NULL_HANDLE);
}
}
VulkanSwapChain::ScopedWrite::ScopedWrite(ScopedWrite&& other) {
*this = std::move(other);
}
VulkanSwapChain::ScopedWrite::~ScopedWrite() {
Reset();
}
const VulkanSwapChain::ScopedWrite& VulkanSwapChain::ScopedWrite::operator=(
ScopedWrite&& other) {
Reset();
std::swap(swap_chain_, other.swap_chain_);
std::swap(success_, other.success_);
std::swap(image_, other.image_);
std::swap(image_index_, other.image_index_);
std::swap(image_layout_, other.image_layout_);
std::swap(image_usage_, other.image_usage_);
std::swap(begin_semaphore_, other.begin_semaphore_);
std::swap(end_semaphore_, other.end_semaphore_);
return *this;
}
void VulkanSwapChain::ScopedWrite::Reset() {
if (success_) [[likely]] {
DCHECK(begin_semaphore_ != VK_NULL_HANDLE);
DCHECK(end_semaphore_ != VK_NULL_HANDLE);
swap_chain_->EndWriteCurrentImage();
} else {
DCHECK(begin_semaphore_ == VK_NULL_HANDLE);
DCHECK(end_semaphore_ == VK_NULL_HANDLE);
}
swap_chain_ = nullptr;
success_ = false;
image_ = VK_NULL_HANDLE;
image_index_ = 0;
image_layout_ = VK_IMAGE_LAYOUT_UNDEFINED;
image_usage_ = 0;
begin_semaphore_ = VK_NULL_HANDLE;
end_semaphore_ = VK_NULL_HANDLE;
}
} // namespace gpu