Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
impeller::ResourceManagerVK Class Referencefinal

A resource manager controls how resources are allocated and reclaimed. More...

#include <resource_manager_vk.h>

Inheritance diagram for impeller::ResourceManagerVK:

Public Member Functions

void Reclaim (std::unique_ptr< ResourceVK > resource)
 Mark a resource as being reclaimable.
 
 ~ResourceManagerVK ()
 Destroys the resource manager.
 

Static Public Member Functions

static std::shared_ptr< ResourceManagerVKCreate ()
 Creates a shared resource manager (a dedicated thread).
 

Detailed Description

A resource manager controls how resources are allocated and reclaimed.

Reclaimed resources are collected in a batch on a separate thread. In the future, the resource manager may allow resource pooling/reuse, delaying reclamation past frame workloads, etc...

Definition at line 39 of file resource_manager_vk.h.

Constructor & Destructor Documentation

◆ ~ResourceManagerVK()

impeller::ResourceManagerVK::~ResourceManagerVK ( )

Destroys the resource manager.

The resource manager will stop collecting resources and will be destroyed when all references to it are dropped.

Definition at line 25 of file resource_manager_vk.cc.

25 {
26 FML_DCHECK(waiter_.get_id() != std::this_thread::get_id())
27 << "The ResourceManager being destructed on its own spawned thread is a "
28 << "sign that ContextVK was not properly destroyed. A usual fix for this "
29 << "is to ensure that ContextVK is shutdown (i.e. context->Shutdown()) "
30 "before the ResourceManager is destroyed (i.e. at the end of a test).";
31 Terminate();
32 waiter_.join();
33}
#define FML_DCHECK(condition)
Definition logging.h:103

Member Function Documentation

◆ Create()

std::shared_ptr< ResourceManagerVK > impeller::ResourceManagerVK::Create ( )
static

Creates a shared resource manager (a dedicated thread).

Upon creation, a thread is spawned which will collect resources as they are reclaimed (passed to Reclaim). The thread will exit when the resource manager is destroyed.

Note
Only one |ResourceManagerVK| should be created per Vulkan context, but that contract is not enforced by this method.
Returns
A resource manager if one could be created.

Definition at line 14 of file resource_manager_vk.cc.

14 {
15 // It will be tempting to refactor this to create the waiter thread in the
16 // static method instead of the constructor. However, that causes the
17 // destructor never to be called, and the thread never terminates!
18 //
19 // See https://github.com/flutter/flutter/issues/134482.
20 return std::shared_ptr<ResourceManagerVK>(new ResourceManagerVK());
21}

◆ Reclaim()

void impeller::ResourceManagerVK::Reclaim ( std::unique_ptr< ResourceVK resource)

Mark a resource as being reclaimable.

The resource will be reset at some point in the future.

Parameters
[in]resourceThe resource to reclaim.
Note
Despite being a public API, this method cannot be invoked directly. Instead, use UniqueResourceVKT to create a unique handle to a resource, which will call this method.

Definition at line 75 of file resource_manager_vk.cc.

75 {
76 if (!resource) {
77 return;
78 }
79 {
80 std::scoped_lock lock(reclaimables_mutex_);
81 reclaimables_.emplace_back(std::move(resource));
82 }
83 reclaimables_cv_.notify_one();
84}

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