| Flutter Impeller |

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
10 #include "fml/status_or.h"
11 #include "impeller/renderer/backend/vulkan/context_vk.h"
12 #include "vulkan/vulkan_handles.hpp"
13
14 namespace impeller {
15
16 //------------------------------------------------------------------------------
17 /// @brief A per-frame descriptor pool. Descriptors
18 /// from this pool don't need to be freed individually. Instead, the
19 /// pool must be collected after all the descriptors allocated from
20 /// it are done being used.
21 ///
22 /// The pool or it's descriptors may not be accessed from multiple
23 /// threads.
24 ///
25 /// Encoders create pools as necessary as they have the same
26 /// threading and lifecycle restrictions.
27 class DescriptorPoolVK {
28 public:
29 explicit DescriptorPoolVK(std::weak_ptr<const ContextVK> context);
30
31 ~DescriptorPoolVK();
32
33 fml::StatusOr<vk::DescriptorSet> AllocateDescriptorSets(
34 const vk::DescriptorSetLayout& layout,
35 const ContextVK& context_vk);
36
37 private:
38 std::weak_ptr<const ContextVK> context_;
39 std::vector<vk::UniqueDescriptorPool> pools_;
40
41 fml::Status CreateNewPool(const ContextVK& context_vk);
42
43 DescriptorPoolVK(const DescriptorPoolVK&) = delete;
44
45 DescriptorPoolVK& operator=(const DescriptorPoolVK&) = delete;
46 };
47
48 //------------------------------------------------------------------------------
49 /// @brief Creates and manages the lifecycle of |vk::DescriptorPoolVK|
50 /// objects.
51 class DescriptorPoolRecyclerVK final
52 : public std::enable_shared_from_this<DescriptorPoolRecyclerVK> {
53 public:
54 ~DescriptorPoolRecyclerVK() = default;
55
56 /// The maximum number of descriptor pools this recycler will hold onto.
57 static constexpr size_t kMaxRecycledPools = 32u;
58
59 /// @brief Creates a recycler for the given |ContextVK|.
60 ///
61 /// @param[in] context The context to create the recycler for.
62 explicit DescriptorPoolRecyclerVK(std::weak_ptr<ContextVK> context)
63 : context_(std::move(context)) {}
64
65 /// @brief Gets a descriptor pool.
66 ///
67 /// This may create a new descriptor pool if no existing pools had
68 /// the necessary capacity.
69 vk::UniqueDescriptorPool Get();
70
71 /// @brief Returns the descriptor pool to be reset on a background
72 /// thread.
73 ///
74 /// @param[in] pool The pool to recycler.
75 void Reclaim(vk::UniqueDescriptorPool&& pool);
76
77 private:
78 std::weak_ptr<ContextVK> context_;
79
80 Mutex recycled_mutex_;
81 std::vector<vk::UniqueDescriptorPool> recycled_ IPLR_GUARDED_BY(
82 recycled_mutex_);
83
84 /// @brief Creates a new |vk::CommandPool|.
85 ///
86 /// @returns Returns a |std::nullopt| if a pool could not be created.
87 vk::UniqueDescriptorPool Create();
88
89 /// @brief Reuses a recycled |vk::CommandPool|, if available.
90 ///
91 /// @returns Returns a |std::nullopt| if a pool was not available.
92 std::optional<vk::UniqueDescriptorPool> Reuse();
93
94 DescriptorPoolRecyclerVK(const DescriptorPoolRecyclerVK&) = delete;
95
96 DescriptorPoolRecyclerVK& operator=(const DescriptorPoolRecyclerVK&) = delete;
97 };
98
99 } // namespace impeller
100
101 #endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DESCRIPTOR_POOL_VK_H_
impeller::DescriptorPoolRecyclerVK::Reclaim
void Reclaim(vk::UniqueDescriptorPool &&pool)
Returns the descriptor pool to be reset on a background thread.
Definition: descriptor_pool_vk.cc:133
impeller::DescriptorPoolVK::DescriptorPoolVK
DescriptorPoolVK(std::weak_ptr< const ContextVK > context)
Definition: descriptor_pool_vk.cc:67
impeller::DescriptorPoolVK::~DescriptorPoolVK
~DescriptorPoolVK()
Definition: descriptor_pool_vk.cc:70
impeller::DescriptorPoolRecyclerVK::~DescriptorPoolRecyclerVK
~DescriptorPoolRecyclerVK()=default
impeller::DescriptorPoolRecyclerVK
Creates and manages the lifecycle of |vk::DescriptorPoolVK| objects.
Definition: descriptor_pool_vk.h:51
impeller::DescriptorPoolRecyclerVK::kMaxRecycledPools
static constexpr size_t kMaxRecycledPools
The maximum number of descriptor pools this recycler will hold onto.
Definition: descriptor_pool_vk.h:57
impeller::DescriptorPoolRecyclerVK::DescriptorPoolRecyclerVK
DescriptorPoolRecyclerVK(std::weak_ptr< ContextVK > context)
Creates a recycler for the given |ContextVK|.
Definition: descriptor_pool_vk.h:62
impeller::DescriptorPoolVK
A per-frame descriptor pool. Descriptors from this pool don't need to be freed individually....
Definition: descriptor_pool_vk.h:27
impeller::DescriptorPoolRecyclerVK::Get
vk::UniqueDescriptorPool Get()
Gets a descriptor pool.
Definition: descriptor_pool_vk.cc:151
impeller::ContextVK
Definition: context_vk.h:42
std
Definition: comparable.h:95
impeller::DescriptorPoolVK::AllocateDescriptorSets
fml::StatusOr< vk::DescriptorSet > AllocateDescriptorSets(const vk::DescriptorSetLayout &layout, const ContextVK &context_vk)
Definition: descriptor_pool_vk.cc:94
context_vk.h
impeller
Definition: aiks_blur_unittests.cc:20