Blender V5.3
vk_resource_pool.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_mutex.hh"
12#include "BLI_span.hh"
13
14#include "vk_common.hh"
15
18#include "vk_immediate.hh"
19
20namespace blender::gpu {
21class VKDevice;
22class VKDiscardPool;
23
24template<typename Item> class TimelineResources : Vector<std::pair<TimelineValue, Item>> {
25 friend class VKDiscardPool;
26
27 public:
28 void append_timeline(TimelineValue timeline, Item item)
29 {
30 this->append(std::pair(timeline, item));
31 }
32
34 {
35 for (std::pair<TimelineValue, Item> &pair : *this) {
36 pair.first = timeline;
37 }
38 }
39
40 int64_t size() const
41 {
42 return static_cast<const Vector<std::pair<TimelineValue, Item>> &>(*this).size();
43 }
44 bool is_empty() const
45 {
46 return static_cast<const Vector<std::pair<TimelineValue, Item>> &>(*this).is_empty();
47 }
48
52 template<typename Deleter> void remove_old(TimelineValue current_timeline, Deleter deleter)
53 {
54 int64_t first_index_to_keep = 0;
55 for (std::pair<TimelineValue, Item> &item : *this) {
56 if (item.first > current_timeline) {
57 break;
58 }
59 deleter(item.second);
60 first_index_to_keep++;
61 }
62
63 if (first_index_to_keep > 0) {
64 this->remove(0, first_index_to_keep);
65 }
66 }
67};
68
80 friend class VKDevice;
81 friend class VKBackend;
82
83 private:
84 TimelineResources<ResourceHandle> swapchain_images_;
93 TimelineResources<VkAccelerationStructureKHR> acceleration_structures_;
95
96 Mutex mutex_;
97
98 TimelineValue timeline_ = UINT64_MAX;
99
100 public:
101 void deinit(VKDevice &device);
102
103 void discard_swapchain_image(ResourceHandle image_handle);
108 void discard_image_view(VkImageView vk_image_view);
116 TimelineValue timeline);
117 void discard_allocation(VmaAllocation vma_allocation);
118 void discard_shader_module(VkShaderModule vk_shader_module);
119 void discard_pipeline(VkPipeline vk_pipeline);
120 void discard_pipeline_layout(VkPipelineLayout vk_pipeline_layout);
121 void discard_descriptor_pool_for_reuse(VkDescriptorPool vk_descriptor_pool,
122 VKDescriptorPools *descriptor_pools);
123 void discard_acceleration_structure(VkAccelerationStructureKHR vk_acceleration_structure);
124
143 void move_data(VKDiscardPool &src_pool, TimelineValue timeline);
144 inline Mutex &mutex_get()
145 {
146 return mutex_;
147 }
148 void destroy_discarded_resources(VKDevice &device, TimelineValue current_timeline);
149
157
158 friend std::ostream &operator<<(std::ostream &os, const VKDiscardPool &discard_pool);
159};
160
161} // namespace blender::gpu
#define UINT64_MAX
void update_timeline(TimelineValue timeline)
void remove_old(TimelineValue current_timeline, Deleter deleter)
void append_timeline(TimelineValue timeline, Item item)
void discard_swapchain_image(ResourceHandle image_handle)
void discard_image_view(VkImageView vk_image_view)
void move_data(VKDiscardPool &src_pool, TimelineValue timeline)
void discard_descriptor_pool_for_reuse(VkDescriptorPool vk_descriptor_pool, VKDescriptorPools *descriptor_pools)
static VKDiscardPool & discard_pool_get()
void discard_shader_module(VkShaderModule vk_shader_module)
void discard_resources(Span< render_graph::VKResourceStateTracker::DiscardableResource > discardable, TimelineValue timeline)
void deinit(VKDevice &device)
void discard_allocation(VmaAllocation vma_allocation)
void discard_pipeline(VkPipeline vk_pipeline)
void discard_pipeline_layout(VkPipelineLayout vk_pipeline_layout)
void destroy_discarded_resources(VKDevice &device, TimelineValue current_timeline)
void discard_acceleration_structure(VkAccelerationStructureKHR vk_acceleration_structure)
uint64_t TimelineValue
Definition vk_common.hh:39
PruningStream & operator<<(PruningStream &dst, const TokenStream &src)
uint64_t ResourceHandle
Definition vk_common.hh:68
__int64 int64_t
Definition BKE_text.h:90
std::mutex Mutex
Definition BLI_mutex.hh:51
int size() const
Definition vector.hh:130