Flutter Engine
The Flutter Engine
vulkan_backbuffer.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "vulkan_backbuffer.h"
6
7#include <limits>
8
9#include "flutter/vulkan/procs/vulkan_proc_table.h"
11#include "vulkan/vulkan.h"
12
13namespace vulkan {
14
18 : vk_(p_vk),
19 device_(device),
20 usage_command_buffer_(p_vk, device, pool),
21 render_command_buffer_(p_vk, device, pool),
22 valid_(false) {
23 if (!usage_command_buffer_.IsValid() || !render_command_buffer_.IsValid()) {
24 FML_DLOG(INFO) << "Command buffers were not valid.";
25 return;
26 }
27
28 if (!CreateSemaphores()) {
29 FML_DLOG(INFO) << "Could not create semaphores.";
30 return;
31 }
32
33 if (!CreateFences()) {
34 FML_DLOG(INFO) << "Could not create fences.";
35 return;
36 }
37
38 valid_ = true;
39}
40
43}
44
46 return valid_;
47}
48
49bool VulkanBackbuffer::CreateSemaphores() {
50 const VkSemaphoreCreateInfo create_info = {
52 .pNext = nullptr,
53 .flags = 0,
54 };
55
56 auto semaphore_collect = [this](VkSemaphore semaphore) {
57 vk_.DestroySemaphore(device_, semaphore, nullptr);
58 };
59
60 for (size_t i = 0; i < semaphores_.size(); i++) {
61 VkSemaphore semaphore = VK_NULL_HANDLE;
62
63 if (VK_CALL_LOG_ERROR(vk_.CreateSemaphore(device_, &create_info, nullptr,
64 &semaphore)) != VK_SUCCESS) {
65 return false;
66 }
67
68 semaphores_[i] = VulkanHandle<VkSemaphore>{semaphore, semaphore_collect};
69 }
70
71 return true;
72}
73
74bool VulkanBackbuffer::CreateFences() {
75 const VkFenceCreateInfo create_info = {
77 .pNext = nullptr,
79 };
80
81 auto fence_collect = [this](VkFence fence) {
82 vk_.DestroyFence(device_, fence, nullptr);
83 };
84
85 for (size_t i = 0; i < use_fences_.size(); i++) {
86 VkFence fence = VK_NULL_HANDLE;
87
88 if (VK_CALL_LOG_ERROR(vk_.CreateFence(device_, &create_info, nullptr,
89 &fence)) != VK_SUCCESS) {
90 return false;
91 }
92
93 use_fences_[i] = VulkanHandle<VkFence>{fence, fence_collect};
94 }
95
96 return true;
97}
98
100 VkFence fences[std::tuple_size_v<decltype(use_fences_)>];
101
102 for (size_t i = 0; i < use_fences_.size(); i++) {
103 fences[i] = use_fences_[i];
104 }
105
106 return VK_CALL_LOG_ERROR(vk_.WaitForFences(
107 device_, static_cast<uint32_t>(use_fences_.size()), fences, true,
109}
110
112 VkFence fences[std::tuple_size_v<decltype(use_fences_)>];
113
114 for (size_t i = 0; i < use_fences_.size(); i++) {
115 fences[i] = use_fences_[i];
116 }
117
118 return VK_CALL_LOG_ERROR(vk_.ResetFences(
119 device_, static_cast<uint32_t>(use_fences_.size()), fences)) ==
121}
122
124 return use_fences_[0];
125}
126
128 return use_fences_[1];
129}
130
132 return semaphores_[0];
133}
134
136 return semaphores_[1];
137}
138
140 return usage_command_buffer_;
141}
142
144 return render_command_buffer_;
145}
146
147} // namespace vulkan
AutoreleasePool pool
VulkanCommandBuffer & GetUsageCommandBuffer()
const VulkanHandle< VkSemaphore > & GetUsageSemaphore() const
VulkanBackbuffer(const VulkanProcTable &vk, const VulkanHandle< VkDevice > &device, const VulkanHandle< VkCommandPool > &pool)
const VulkanHandle< VkFence > & GetUsageFence() const
const VulkanHandle< VkSemaphore > & GetRenderSemaphore() const
VulkanCommandBuffer & GetRenderCommandBuffer()
const VulkanHandle< VkFence > & GetRenderFence() const
VkDevice device
Definition: main.cc:53
#define FML_ALLOW_UNUSED_LOCAL(x)
#define FML_DLOG(severity)
Definition: logging.h:102
static float max(float r, float g, float b)
Definition: hsl.cpp:49
VkStructureType sType
Definition: vulkan_core.h:3392
@ VK_SUCCESS
Definition: vulkan_core.h:141
#define VK_NULL_HANDLE
Definition: vulkan_core.h:46
@ VK_FENCE_CREATE_SIGNALED_BIT
Definition: vulkan_core.h:2488
@ VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO
Definition: vulkan_core.h:211
@ VK_STRUCTURE_TYPE_FENCE_CREATE_INFO
Definition: vulkan_core.h:210
#define VK_CALL_LOG_ERROR(expression)