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 
6 
9 #include "vulkan/vulkan_handles.hpp"
10 
11 namespace impeller {
12 
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 
39 
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 
66  const {
67  return semaphore_;
68 }
69 
70 } // namespace impeller
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
const vk::Semaphore & GetHandle() const
const SharedHandleVK< vk::Semaphore > & GetSharedHandle() const
fml::UniqueFD CreateFD() const
Create a new sync file descriptor for the underlying semaphore.
bool IsValid() const
If a valid fence could be created.
ExternalSemaphoreVK(const std::shared_ptr< Context > &context)
Create a new un-signaled semaphore that can be exported as a sync file descriptor.
std::shared_ptr< SharedObjectVKT< T > > SharedHandleVK
auto MakeSharedVK(vk::UniqueHandle< T, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > handle)
#define VALIDATION_LOG
Definition: validation.h:91