Flutter Engine
The Flutter Engine
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
 
ExternalFenceVKoperator= (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]contextThe 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: "
26 return;
27 }
28
29 context_vk.SetDebugName(fence.get(), "ExternalFenceSyncFD");
30
31 fence_ = MakeSharedVK(std::move(fence));
32}
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
static ContextVK & Cast(Context &base)
Definition: backend_cast.h:13
GAsyncResult * result
auto MakeSharedVK(vk::UniqueHandle< T, VULKAN_HPP_DEFAULT_DISPATCHER_TYPE > handle)
static SkString to_string(int n)
Definition: nanobench.cpp:119
#define VALIDATION_LOG
Definition: validation.h:73

◆ ~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: "
51 return {};
52 }
53 return fml::UniqueFD{fd};
54}
bool IsValid() const
If a valid fence could be created.

◆ 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}

◆ operator=()

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

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