Flutter Impeller
impeller::DescriptorPoolRecyclerVK Class Referencefinal

Creates and manages the lifecycle of |vk::DescriptorPoolVK| objects. More...

#include <descriptor_pool_vk.h>

Inheritance diagram for impeller::DescriptorPoolRecyclerVK:

Public Member Functions

 ~DescriptorPoolRecyclerVK ()=default
 
 DescriptorPoolRecyclerVK (std::weak_ptr< ContextVK > context)
 Creates a recycler for the given |ContextVK|. More...
 
vk::UniqueDescriptorPool Get ()
 Gets a descriptor pool. More...
 
std::shared_ptr< DescriptorPoolVKGetDescriptorPool ()
 
void Reclaim (DescriptorCacheMap descriptor_sets, std::vector< vk::UniqueDescriptorPool > pools)
 

Static Public Attributes

static constexpr size_t kMaxRecycledPools = 32u
 The maximum number of descriptor pools this recycler will hold onto. More...
 

Detailed Description

Creates and manages the lifecycle of |vk::DescriptorPoolVK| objects.

Definition at line 70 of file descriptor_pool_vk.h.

Constructor & Destructor Documentation

◆ ~DescriptorPoolRecyclerVK()

impeller::DescriptorPoolRecyclerVK::~DescriptorPoolRecyclerVK ( )
default

◆ DescriptorPoolRecyclerVK()

impeller::DescriptorPoolRecyclerVK::DescriptorPoolRecyclerVK ( std::weak_ptr< ContextVK context)
inlineexplicit

Creates a recycler for the given |ContextVK|.

Parameters
[in]contextThe context to create the recycler for.

Definition at line 81 of file descriptor_pool_vk.h.

82  : context_(std::move(context)) {}

Member Function Documentation

◆ Get()

vk::UniqueDescriptorPool impeller::DescriptorPoolRecyclerVK::Get ( )

Gets a descriptor pool.

        This may create a new descriptor pool if no existing pools had
        the necessary capacity. 

Definition at line 138 of file descriptor_pool_vk.cc.

138  {
139  // Recycle a pool with a matching minumum capcity if it is available.
140  return Create();
141 }

◆ GetDescriptorPool()

std::shared_ptr< DescriptorPoolVK > impeller::DescriptorPoolRecyclerVK::GetDescriptorPool ( )

Definition at line 174 of file descriptor_pool_vk.cc.

174  {
175  {
176  Lock recycled_lock(recycled_mutex_);
177  if (!recycled_.empty()) {
178  auto result = recycled_.back();
179  recycled_.pop_back();
180  return result;
181  }
182  }
183  return std::make_shared<DescriptorPoolVK>(context_);
184 }

◆ Reclaim()

void impeller::DescriptorPoolRecyclerVK::Reclaim ( DescriptorCacheMap  descriptor_sets,
std::vector< vk::UniqueDescriptorPool >  pools 
)

Definition at line 111 of file descriptor_pool_vk.cc.

113  {
114  // Reset the pool on a background thread.
115  auto strong_context = context_.lock();
116  if (!strong_context) {
117  return;
118  }
119 
120  for (auto& [_, cache] : descriptor_sets) {
121  cache.unused.insert(cache.unused.end(), cache.used.begin(),
122  cache.used.end());
123  cache.used.clear();
124  }
125 
126  // Move the pool to the recycled list. If more than 32 pool are
127  // cached then delete the newest entry.
128  Lock recycled_lock(recycled_mutex_);
129  while (recycled_.size() >= kMaxRecycledPools) {
130  auto& back_entry = recycled_.back();
131  back_entry->Destroy();
132  recycled_.pop_back();
133  }
134  recycled_.push_back(std::make_shared<DescriptorPoolVK>(
135  context_, std::move(descriptor_sets), std::move(pools)));
136 }
static constexpr size_t kMaxRecycledPools
The maximum number of descriptor pools this recycler will hold onto.

References kMaxRecycledPools.

Member Data Documentation

◆ kMaxRecycledPools

constexpr size_t impeller::DescriptorPoolRecyclerVK::kMaxRecycledPools = 32u
staticconstexpr

The maximum number of descriptor pools this recycler will hold onto.

Definition at line 76 of file descriptor_pool_vk.h.

Referenced by Reclaim().


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