Blender V5.0
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
13#include "vk_common.hh"
14
16#include "vk_immediate.hh"
17
18namespace blender::gpu {
19class VKDevice;
20class VKDiscardPool;
21
22template<typename Item> class TimelineResources : Vector<std::pair<TimelineValue, Item>> {
23 friend class VKDiscardPool;
24
25 public:
26 void append_timeline(TimelineValue timeline, Item item)
27 {
28 this->append(std::pair(timeline, item));
29 }
30
32 {
33 for (std::pair<TimelineValue, Item> &pair : *this) {
34 pair.first = timeline;
35 }
36 }
37
38 int64_t size() const
39 {
40 return static_cast<const Vector<std::pair<TimelineValue, Item>> &>(*this).size();
41 }
42 bool is_empty() const
43 {
44 return static_cast<const Vector<std::pair<TimelineValue, Item>> &>(*this).is_empty();
45 }
46
50 template<typename Deleter> void remove_old(TimelineValue current_timeline, Deleter deleter)
51 {
52 int64_t first_index_to_keep = 0;
53 for (std::pair<TimelineValue, Item> &item : *this) {
54 if (item.first > current_timeline) {
55 break;
56 }
57 deleter(item.second);
58 first_index_to_keep++;
59 }
60
61 if (first_index_to_keep > 0) {
62 this->remove(0, first_index_to_keep);
63 }
64 }
65};
66
78 friend class VKDevice;
79 friend class VKBackend;
80
81 private:
90
91 Mutex mutex_;
92
93 TimelineValue timeline_ = UINT64_MAX;
94
95 public:
96 void deinit(VKDevice &device);
97
98 void discard_image(VkImage vk_image, VmaAllocation vma_allocation);
99 void discard_image_view(VkImageView vk_image_view);
100 void discard_buffer(VkBuffer vk_buffer, VmaAllocation vma_allocation);
101 void discard_buffer_view(VkBufferView vk_buffer_view);
102 void discard_shader_module(VkShaderModule vk_shader_module);
103 void discard_pipeline(VkPipeline vk_pipeline);
104 void discard_pipeline_layout(VkPipelineLayout vk_pipeline_layout);
105 void discard_descriptor_pool_for_reuse(VkDescriptorPool vk_descriptor_pool,
106 VKDescriptorPools *descriptor_pools);
107
126 void move_data(VKDiscardPool &src_pool, TimelineValue timeline);
127 inline Mutex &mutex_get()
128 {
129 return mutex_;
130 }
131 void destroy_discarded_resources(VKDevice &device, TimelineValue current_timeline);
132
140};
141
142} // namespace blender::gpu
long long int int64_t
void append(const std::pair< TimelineValue, Item > &value)
void update_timeline(TimelineValue timeline)
void remove_old(TimelineValue current_timeline, Deleter deleter)
void append_timeline(TimelineValue timeline, Item item)
void discard_image_view(VkImageView vk_image_view)
void discard_buffer_view(VkBufferView vk_buffer_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_image(VkImage vk_image, VmaAllocation vma_allocation)
void discard_buffer(VkBuffer vk_buffer, VmaAllocation vma_allocation)
void deinit(VKDevice &device)
void discard_pipeline(VkPipeline vk_pipeline)
void discard_pipeline_layout(VkPipelineLayout vk_pipeline_layout)
void destroy_discarded_resources(VKDevice &device, TimelineValue current_timeline)
#define UINT64_MAX
uint64_t TimelineValue
Definition vk_common.hh:36
std::mutex Mutex
Definition BLI_mutex.hh:47