Blender V4.3
vk_resource_tracker.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "BLI_utility_mixins.hh"
12#include "BLI_vector.hh"
13
14#include "vk_common.hh"
15
16namespace blender::gpu {
17namespace render_graph {
18class VKRenderGraph;
19}
20class VKContext;
21
22#if (defined(__GNUC__) && __GNUC__ >= 14 && !defined(__clang__))
23# pragma GCC diagnostic push
24/* CPP20 compiler warnings in GCC14+.
25 * Must be resolved before upgrading to a newer C++, avoid noisy warnings for now. */
26# pragma GCC diagnostic ignored "-Wtemplate-id-cdtor"
27#endif
28
46
47 private:
48 int64_t id_ = -1;
49
50 public:
51 VKSubmissionID() = default;
52
53 private:
61 void reset()
62 {
63 id_ = 0;
64 }
65
73 void next()
74 {
75 id_++;
76 }
77
78 public:
80 {
81 id_ = other.id_;
82 return *this;
83 }
84
85 bool operator==(const VKSubmissionID &other)
86 {
87 return id_ == other.id_;
88 }
89
90 bool operator!=(const VKSubmissionID &other)
91 {
92 return id_ != other.id_;
93 }
94};
95
101 VKSubmissionID last_known_id_;
102
103 public:
108 bool is_changed(const VKContext &context);
109};
110
114template<typename Resource> class VKResourceTracker : NonCopyable {
115 VKSubmissionTracker submission_tracker_;
117
118 protected:
119 VKResourceTracker<Resource>() = default;
121 : submission_tracker_(other.submission_tracker_),
122 tracked_resources_(std::move(other.tracked_resources_))
123 {
124 }
125
127 {
128 submission_tracker_ = other.submission_tracker_;
129 tracked_resources_ = std::move(other.tracked_resources_);
130 return *this;
131 }
132
134 {
135 free_tracked_resources();
136 }
137
154 std::unique_ptr<Resource> &tracked_resource_for(VKContext &context, const bool is_dirty)
155 {
156 if (submission_tracker_.is_changed(context)) {
157 free_tracked_resources();
158 tracked_resources_.append(create_resource(context));
159 }
160 else if (is_dirty || tracked_resources_.is_empty()) {
161 tracked_resources_.append(create_resource(context));
162 }
163 return active_resource();
164 }
165
169 virtual std::unique_ptr<Resource> create_resource(VKContext &context) = 0;
170
175 {
176 return !tracked_resources_.is_empty();
177 }
178
182 std::unique_ptr<Resource> &active_resource()
183 {
184 BLI_assert(!tracked_resources_.is_empty());
185 return tracked_resources_.last();
186 }
187
188 private:
189 void free_tracked_resources()
190 {
191 tracked_resources_.clear();
192 }
193};
194
195#if (defined(__GNUC__) && __GNUC__ >= 14 && !defined(__clang__))
196# pragma GCC diagnostic pop
197#endif
198
199} // namespace blender::gpu
#define BLI_assert(a)
Definition BLI_assert.h:50
void reset()
clear internal cached data and reset random seed
void append(const T &value)
const T & last(const int64_t n=0) const
bool is_empty() const
std::unique_ptr< Resource > & tracked_resource_for(VKContext &context, const bool is_dirty)
std::unique_ptr< Resource > & active_resource()
VKResourceTracker< Resource > & operator=(VKResourceTracker< Resource > &&other)
virtual std::unique_ptr< Resource > create_resource(VKContext &context)=0
bool is_changed(const VKContext &context)
static ulong * next
__int64 int64_t
Definition stdint.h:89
const VKSubmissionID & operator=(const VKSubmissionID &other)
bool operator==(const VKSubmissionID &other)
bool operator!=(const VKSubmissionID &other)