| Flutter Impeller |

external_semaphore_vk.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 "impeller/renderer/backend/vulkan/swapchain/ahb/external_semaphore_vk.h"
6
7 #include "impeller/base/validation.h"
8 #include "impeller/renderer/backend/vulkan/context_vk.h"
9 #include "vulkan/vulkan_handles.hpp"
10
11 namespace impeller {
12
13 ExternalSemaphoreVK::ExternalSemaphoreVK(
14 const std::shared_ptr<Context>& context) {
15 if (!context) {
16 return;
17 }
18 vk::StructureChain<vk::SemaphoreCreateInfo, vk::ExportSemaphoreCreateInfoKHR>
19 info;
20
21 info.get<vk::ExportSemaphoreCreateInfoKHR>().handleTypes =
22 vk::ExternalSemaphoreHandleTypeFlagBits::eSyncFd;
23
24 const auto& context_vk = ContextVK::Cast(*context);
25 auto [result, semaphore] =
26 context_vk.GetDevice().createSemaphoreUnique(info.get());
27 if (result != vk::Result::eSuccess) {
28 VALIDATION_LOG << "Could not create external fence: "
29 << vk::to_string(result);
30 return;
31 }
32
33 context_vk.SetDebugName(semaphore.get(), "ExternalSemaphoreSyncFD");
34
35 semaphore_ = MakeSharedVK(std::move(semaphore));
36 }
37
38 ExternalSemaphoreVK::~ExternalSemaphoreVK() = default;
39
40 bool ExternalSemaphoreVK::IsValid() const {
41 return !!semaphore_;
42 }
43
44 fml::UniqueFD ExternalSemaphoreVK::CreateFD() const {
45 if (!IsValid()) {
46 return {};
47 }
48 vk::SemaphoreGetFdInfoKHR info;
49 info.semaphore = semaphore_->Get();
50 info.handleType = vk::ExternalSemaphoreHandleTypeFlagBits::eSyncFd;
51 auto [result, fd] =
52 semaphore_->GetUniqueWrapper().getOwner().getSemaphoreFdKHR(info);
53 if (result != vk::Result::eSuccess) {
54 VALIDATION_LOG << "Could not export external fence FD: "
55 << vk::to_string(result);
56 return {};
57 }
58 return fml::UniqueFD{fd};
59 }
60
61 const vk::Semaphore& ExternalSemaphoreVK::GetHandle() const {
62 return semaphore_->Get();
63 }
64
65 const SharedHandleVK<vk::Semaphore>& ExternalSemaphoreVK::GetSharedHandle()
66 const {
67 return semaphore_;
68 }
69
70 } // namespace impeller
impeller::BackendCast< ContextVK, Context >::Cast
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
impeller::ExternalSemaphoreVK::GetHandle
const vk::Semaphore & GetHandle() const
Definition: external_semaphore_vk.cc:61
impeller::ExternalSemaphoreVK::GetSharedHandle
const SharedHandleVK< vk::Semaphore > & GetSharedHandle() const
Definition: external_semaphore_vk.cc:65
impeller::ExternalSemaphoreVK::CreateFD
fml::UniqueFD CreateFD() const
Create a new sync file descriptor for the underlying semaphore.
Definition: external_semaphore_vk.cc:44
impeller::ExternalSemaphoreVK::IsValid
bool IsValid() const
If a valid fence could be created.
Definition: external_semaphore_vk.cc:40
impeller::ExternalSemaphoreVK::~ExternalSemaphoreVK
~ExternalSemaphoreVK()
impeller::ExternalSemaphoreVK::ExternalSemaphoreVK
ExternalSemaphoreVK(const std::shared_ptr< Context > &context)
Create a new un-signaled semaphore that can be exported as a sync file descriptor.
Definition: external_semaphore_vk.cc:13
external_semaphore_vk.h
impeller
Definition: allocation.cc:12
impeller::SharedHandleVK
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
Definition: shared_object_vk.h:53
impeller::MakeSharedVK
auto MakeSharedVK(vk::UniqueHandle< T, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > handle)
Definition: shared_object_vk.h:44
context_vk.h
validation.h
VALIDATION_LOG
#define VALIDATION_LOG
Definition: validation.h:91