| Flutter Impeller |

Public Member Functions | List of all members
impeller::ExternalFenceVK Class Reference

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

`#include <external_fence_vk.h>`

## Public Member Functions
| ExternalFenceVK (const std::shared_ptr< Context > &context)
| Create a new un-signaled fence that can be exported as a sync file descriptor. More...
| ~ExternalFenceVK ()
| ExternalFenceVK (const ExternalFenceVK &)=delete
ExternalFenceVK & | operator= (const ExternalFenceVK &)=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 fence. The fence 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. More...
const vk::Fence & | GetHandle () const
const SharedHandleVK< vk::Fence > & | GetSharedHandle () const

## Detailed Description

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

The fences are exported as sync file descriptors.

Warning
  Only fences 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. See VUID-VkFenceGetFdInfoKHR-handleType-01454 for additional details on the implementation.

Definition at line 28 of file external_fence_vk.h.

## Constructor & Destructor Documentation

## ◆ ExternalFenceVK() [1/2]

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

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

Parameters

  [in] | context | The device context.

Definition at line 12 of file external_fence_vk.cc.

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

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

## ◆ ~ExternalFenceVK()

impeller::ExternalFenceVK::~ExternalFenceVK | ( |  | ) |
| default

## ◆ ExternalFenceVK() [2/2]

impeller::ExternalFenceVK::ExternalFenceVK | ( | const ExternalFenceVK & |  | ) |
| delete

## Member Function Documentation

## ◆ CreateFD()

fml::UniqueFD impeller::ExternalFenceVK::CreateFD | ( |  | ) | const

Create a new sync file descriptor for the underlying fence. The fence 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 fence 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 40 of file external_fence_vk.cc.

40 {
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 }
impeller::ExternalFenceVK::IsValid
bool IsValid() const
If a valid fence could be created.
Definition: external_fence_vk.cc:36

References IsValid(), and VALIDATION_LOG.

## ◆ GetHandle()

const vk::Fence & impeller::ExternalFenceVK::GetHandle | ( |  | ) | const

Definition at line 56 of file external_fence_vk.cc.

56 {
57 return fence_->Get();
58 }

## ◆ GetSharedHandle()

const SharedHandleVK< vk::Fence > & impeller::ExternalFenceVK::GetSharedHandle | ( |  | ) | const

Definition at line 60 of file external_fence_vk.cc.

60 {
61 return fence_;
62 }

## ◆ IsValid()

bool impeller::ExternalFenceVK::IsValid | ( |  | ) | const

If a valid fence could be created.

Returns
  True if valid, False otherwise.

Definition at line 36 of file external_fence_vk.cc.

36 {
37 return !!fence_;
38 }

Referenced by CreateFD().

## ◆ operator=()

ExternalFenceVK& impeller::ExternalFenceVK::operator= | ( | const ExternalFenceVK & |  | ) |
| delete

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

- impeller/renderer/backend/vulkan/swapchain/ahb/external_fence_vk.h
- impeller/renderer/backend/vulkan/swapchain/ahb/external_fence_vk.cc