Flutter Engine
 
Loading...
Searching...
No Matches
descriptor_pool_vk.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DESCRIPTOR_POOL_VK_H_
6#define FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DESCRIPTOR_POOL_VK_H_
7
8#include <cstdint>
9#include <unordered_map>
10
11#include "fml/status_or.h"
14
15namespace impeller {
16
17/// Used and un-used descriptor sets.
19 std::vector<vk::DescriptorSet> unused;
20 std::vector<vk::DescriptorSet> used;
21};
22
23using DescriptorCacheMap = std::unordered_map<PipelineKey, DescriptorCache>;
24
25//------------------------------------------------------------------------------
26/// @brief A per-frame descriptor pool. Descriptors
27/// from this pool don't need to be freed individually. Instead, the
28/// pool must be collected after all the descriptors allocated from
29/// it are done being used.
30///
31/// The pool or it's descriptors may not be accessed from multiple
32/// threads.
33///
34/// Encoders create pools as necessary as they have the same
35/// threading and lifecycle restrictions.
37 public:
38 explicit DescriptorPoolVK(std::weak_ptr<const ContextVK> context);
39
40 DescriptorPoolVK(std::weak_ptr<const ContextVK> context,
41 DescriptorCacheMap descriptor_sets,
42 std::vector<vk::UniqueDescriptorPool> pools);
43
45
47 const vk::DescriptorSetLayout& layout,
48 PipelineKey pipeline_key,
49 const ContextVK& context_vk);
50
51 private:
53
54 std::weak_ptr<const ContextVK> context_;
55 DescriptorCacheMap descriptor_sets_;
56 std::vector<vk::UniqueDescriptorPool> pools_;
57
58 void Destroy();
59
60 fml::Status CreateNewPool(const ContextVK& context_vk);
61
62 DescriptorPoolVK(const DescriptorPoolVK&) = delete;
63
64 DescriptorPoolVK& operator=(const DescriptorPoolVK&) = delete;
65};
66
67//------------------------------------------------------------------------------
68/// @brief Creates and manages the lifecycle of |vk::DescriptorPoolVK|
69/// objects.
71 : public std::enable_shared_from_this<DescriptorPoolRecyclerVK> {
72 public:
74
75 /// The maximum number of descriptor pools this recycler will hold onto.
76 static constexpr size_t kMaxRecycledPools = 32u;
77
78 /// @brief Creates a recycler for the given |ContextVK|.
79 ///
80 /// @param[in] context The context to create the recycler for.
81 explicit DescriptorPoolRecyclerVK(std::weak_ptr<ContextVK> context)
82 : context_(std::move(context)) {}
83
84 /// @brief Gets a descriptor pool.
85 ///
86 /// This may create a new descriptor pool if no existing pools had
87 /// the necessary capacity.
88 vk::UniqueDescriptorPool Get();
89
90 std::shared_ptr<DescriptorPoolVK> GetDescriptorPool();
91
92 void Reclaim(DescriptorCacheMap descriptor_sets,
93 std::vector<vk::UniqueDescriptorPool> pools);
94
95 private:
96 std::weak_ptr<ContextVK> context_;
97
98 Mutex recycled_mutex_;
99 std::vector<std::shared_ptr<DescriptorPoolVK>> recycled_
100 IPLR_GUARDED_BY(recycled_mutex_);
101
102 /// @brief Creates a new |vk::CommandPool|.
103 ///
104 /// @returns Returns a |std::nullopt| if a pool could not be created.
105 vk::UniqueDescriptorPool Create();
106
108
109 DescriptorPoolRecyclerVK& operator=(const DescriptorPoolRecyclerVK&) = delete;
110};
111
112} // namespace impeller
113
114#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DESCRIPTOR_POOL_VK_H_
Creates and manages the lifecycle of |vk::DescriptorPoolVK| objects.
std::shared_ptr< DescriptorPoolVK > GetDescriptorPool()
DescriptorPoolRecyclerVK(std::weak_ptr< ContextVK > context)
Creates a recycler for the given |ContextVK|.
void Reclaim(DescriptorCacheMap descriptor_sets, std::vector< vk::UniqueDescriptorPool > pools)
vk::UniqueDescriptorPool Get()
Gets a descriptor pool.
static constexpr size_t kMaxRecycledPools
The maximum number of descriptor pools this recycler will hold onto.
A per-frame descriptor pool. Descriptors from this pool don't need to be freed individually....
fml::StatusOr< vk::DescriptorSet > AllocateDescriptorSets(const vk::DescriptorSetLayout &layout, PipelineKey pipeline_key, const ContextVK &context_vk)
std::unordered_map< PipelineKey, DescriptorCache > DescriptorCacheMap
int64_t PipelineKey
Definition pipeline.h:21
Definition ref_ptr.h:261
Used and un-used descriptor sets.
std::vector< vk::DescriptorSet > unused
std::vector< vk::DescriptorSet > used
#define IPLR_GUARDED_BY(x)