| Flutter Impeller |

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