Flutter Engine
The Flutter Engine
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"
12#include "vulkan/vulkan_handles.hpp"
13
14namespace 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.
28 public:
29 explicit DescriptorPoolVK(std::weak_ptr<const ContextVK> context);
30
32
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.
52 : public std::enable_shared_from_this<DescriptorPoolRecyclerVK> {
53 public:
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
95
96 DescriptorPoolRecyclerVK& operator=(const DescriptorPoolRecyclerVK&) = delete;
97};
98
99} // namespace impeller
100
101#endif // FLUTTER_IMPELLER_RENDERER_BACKEND_VULKAN_DESCRIPTOR_POOL_VK_H_
AutoreleasePool pool
Creates and manages the lifecycle of |vk::DescriptorPoolVK| objects.
DescriptorPoolRecyclerVK(std::weak_ptr< ContextVK > context)
Creates a recycler for the given |ContextVK|.
vk::UniqueDescriptorPool Get()
Gets a descriptor pool.
void Reclaim(vk::UniqueDescriptorPool &&pool)
Returns the descriptor pool to be reset on a background thread.
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....
DescriptorPoolVK(std::weak_ptr< const ContextVK > context)
fml::StatusOr< vk::DescriptorSet > AllocateDescriptorSets(const vk::DescriptorSetLayout &layout, const ContextVK &context_vk)
Definition: ref_ptr.h:256