Flutter Impeller
impeller::ExternalSemaphoreVK Class Reference

A Vulkan semaphore that can be exported as a platform specific file descriptor. More...

#include <external_semaphore_vk.h>

Public Member Functions

 ExternalSemaphoreVK (const std::shared_ptr< Context > &context)
 Create a new un-signaled semaphore that can be exported as a sync file descriptor. More...
 
 ~ExternalSemaphoreVK ()
 
 ExternalSemaphoreVK (const ExternalSemaphoreVK &)=delete
 
ExternalSemaphoreVKoperator= (const ExternalSemaphoreVK &)=delete
 
bool IsValid () const
 If a valid fence could be created. More...
 
fml::UniqueFD CreateFD () const
 Create a new sync file descriptor for the underlying semaphore. More...
 
const vk::Semaphore & GetHandle () const
 
const SharedHandleVK< vk::Semaphore > & GetSharedHandle () const
 

Detailed Description

A Vulkan semaphore that can be exported as a platform specific file descriptor.

The semaphore are exported as sync file descriptors.

Warning
Only semaphore that have been signaled or have a single operation pending can be exported. Make sure to submit a fence signalling operation to a queue before attempted to obtain a file descriptor for the fence.

Definition at line 27 of file external_semaphore_vk.h.

Constructor & Destructor Documentation

◆ ExternalSemaphoreVK() [1/2]

impeller::ExternalSemaphoreVK::ExternalSemaphoreVK ( const std::shared_ptr< Context > &  context)
explicit

Create a new un-signaled semaphore that can be exported as a sync file descriptor.

Parameters
[in]contextThe device context.

Definition at line 13 of file external_semaphore_vk.cc.

14  {
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 }
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
auto MakeSharedVK(vk::UniqueHandle< T, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > handle)
#define VALIDATION_LOG
Definition: validation.h:91

References impeller::BackendCast< ContextVK, Context >::Cast(), impeller::MakeSharedVK(), and VALIDATION_LOG.

◆ ~ExternalSemaphoreVK()

impeller::ExternalSemaphoreVK::~ExternalSemaphoreVK ( )
default

◆ ExternalSemaphoreVK() [2/2]

impeller::ExternalSemaphoreVK::ExternalSemaphoreVK ( const ExternalSemaphoreVK )
delete

Member Function Documentation

◆ CreateFD()

fml::UniqueFD impeller::ExternalSemaphoreVK::CreateFD ( ) const

Create a new sync file descriptor for the underlying semaphore.

The semaphore must already be signaled or have a signal operation pending in a queue. There are no checks for this in the implementation and only Vulkan validation will catch such a misuse and undefined behavior.

Warning
Implementations are also allowed to return invalid file descriptors in case a semaphore has already been signaled. So it is not necessary an error to obtain an invalid descriptor from this call. For APIs that are meant to consume such descriptors, pass -1 as the file handle.

Since this call can return an invalid FD even in case of success, make sure to make the IsValid check before attempting to export a FD.

Returns
A (potentially invalid even in case of success) file descriptor.

Definition at line 44 of file external_semaphore_vk.cc.

44  {
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 }
bool IsValid() const
If a valid fence could be created.

References IsValid(), and VALIDATION_LOG.

◆ GetHandle()

const vk::Semaphore & impeller::ExternalSemaphoreVK::GetHandle ( ) const

Definition at line 61 of file external_semaphore_vk.cc.

61  {
62  return semaphore_->Get();
63 }

◆ GetSharedHandle()

const SharedHandleVK< vk::Semaphore > & impeller::ExternalSemaphoreVK::GetSharedHandle ( ) const

Definition at line 65 of file external_semaphore_vk.cc.

66  {
67  return semaphore_;
68 }

◆ IsValid()

bool impeller::ExternalSemaphoreVK::IsValid ( ) const

If a valid fence could be created.

Returns
True if valid, False otherwise.

Definition at line 40 of file external_semaphore_vk.cc.

40  {
41  return !!semaphore_;
42 }

Referenced by CreateFD().

◆ operator=()

ExternalSemaphoreVK& impeller::ExternalSemaphoreVK::operator= ( const ExternalSemaphoreVK )
delete

The documentation for this class was generated from the following files: