Blender V4.3
vk_state_manager.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 "gpu_state_private.hh"
12
13#include "BLI_array.hh"
14
16
17namespace blender::gpu {
18class VKTexture;
19class VKUniformBuffer;
20class VKVertexBuffer;
21class VKStorageBuffer;
22class VKIndexBuffer;
23class VKContext;
24class VKDescriptorSetTracker;
25
33static constexpr int BIND_SPACE_IMAGE_OFFSET = 512;
34
37 public:
39
40 void bind(VKUniformBuffer *resource, int binding)
41 {
42 if (bound_resources.size() <= binding) {
43 bound_resources.resize(binding + 1);
44 }
45 bound_resources[binding] = resource;
46 }
47
48 VKUniformBuffer *get(int binding) const
49 {
50 return bound_resources[binding];
51 }
52
53 void unbind(void *resource)
54 {
55 for (int index : IndexRange(bound_resources.size())) {
56 if (bound_resources[index] == resource) {
57 bound_resources[index] = nullptr;
58 }
59 }
60 }
61
63 {
64 bound_resources.clear();
65 }
66};
67
71template<int Offset> class BindSpaceImages {
72 public:
74
75 void bind(VKTexture *resource, int binding)
76 {
77 if (binding >= Offset) {
78 binding -= Offset;
79 }
80 if (bound_resources.size() <= binding) {
81 bound_resources.resize(binding + 1);
82 }
83 bound_resources[binding] = resource;
84 }
85
86 VKTexture *get(int binding) const
87 {
88 if (binding >= Offset) {
89 binding -= Offset;
90 }
91 return bound_resources[binding];
92 }
93
94 void unbind(void *resource)
95 {
96 for (int index : IndexRange(bound_resources.size())) {
97 if (bound_resources[index] == resource) {
98 bound_resources[index] = nullptr;
99 }
100 }
101 }
102
104 {
105 bound_resources.clear();
106 }
107};
108
111 public:
112 enum class Type {
113 Unused,
118 };
119 struct Elem {
121 void *resource;
122 };
124
125 void bind(Type resource_type, void *resource, int binding)
126 {
127 if (bound_resources.size() <= binding) {
128 bound_resources.resize(binding + 1);
129 }
130 bound_resources[binding].resource_type = resource_type;
131 bound_resources[binding].resource = resource;
132 }
133
134 const Elem &get(int binding) const
135 {
136 return bound_resources[binding];
137 }
138
139 void unbind(void *resource)
140 {
141 for (int index : IndexRange(bound_resources.size())) {
142 if (bound_resources[index].resource == resource) {
143 bound_resources[index].resource = nullptr;
144 bound_resources[index].resource_type = Type::Unused;
145 }
146 }
147 }
148
150 {
151 bound_resources.clear();
152 }
153};
154
157 public:
158 enum class Type {
159 Unused,
160 Texture,
162 };
169
170 void bind(Type resource_type, void *resource, GPUSamplerState sampler, int binding)
171 {
172 if (bound_resources.size() <= binding) {
173 bound_resources.resize(binding + 1);
174 }
175 bound_resources[binding].resource_type = resource_type;
176 bound_resources[binding].resource = resource;
177 bound_resources[binding].sampler = sampler;
178 }
179
180 const Elem &get(int binding) const
181 {
182 return bound_resources[binding];
183 }
184
185 void unbind(void *resource)
186 {
187 for (int index : IndexRange(bound_resources.size())) {
188 if (bound_resources[index].resource == resource) {
189 bound_resources[index].resource = nullptr;
190 bound_resources[index].resource_type = Type::Unused;
192 }
193 }
194 }
195
197 {
198 bound_resources.clear();
199 }
200};
201
204
205 uint texture_unpack_row_length_ = 0;
206
207 BindSpaceTextures textures_;
209 BindSpaceUniformBuffers uniform_buffers_;
210 BindSpaceStorageBuffers storage_buffers_;
211
212 public:
213 bool is_dirty = false;
214
215 void apply_state() override;
216 void force_state() override;
217
218 void issue_barrier(eGPUBarrier barrier_bits) override;
219
220 void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override;
221 void texture_unbind(Texture *tex) override;
222 void texture_unbind_all() override;
223
224 void image_bind(Texture *tex, int unit) override;
225 void image_unbind(Texture *tex) override;
226 void image_unbind_all() override;
227
228 void uniform_buffer_bind(VKUniformBuffer *uniform_buffer, int slot);
229 void uniform_buffer_unbind(VKUniformBuffer *uniform_buffer);
231
232 void texel_buffer_bind(VKVertexBuffer &vertex_buffer, int slot);
233 void texel_buffer_unbind(VKVertexBuffer &vertex_buffer);
234
236 void *resource,
237 int binding);
238 void storage_buffer_unbind(void *resource);
240
241 void unbind_from_all_namespaces(void *resource);
242
244
251};
252} // namespace blender::gpu
unsigned int uint
eGPUBarrier
Definition GPU_state.hh:29
VKTexture * get(int binding) const
Vector< VKTexture * > bound_resources
void bind(VKTexture *resource, int binding)
void bind(Type resource_type, void *resource, int binding)
const Elem & get(int binding) const
void bind(Type resource_type, void *resource, GPUSamplerState sampler, int binding)
const Elem & get(int binding) const
Vector< VKUniformBuffer * > bound_resources
void bind(VKUniformBuffer *resource, int binding)
VKUniformBuffer * get(int binding) const
void texel_buffer_bind(VKVertexBuffer &vertex_buffer, int slot)
void issue_barrier(eGPUBarrier barrier_bits) override
void image_bind(Texture *tex, int unit) override
void unbind_from_all_namespaces(void *resource)
void uniform_buffer_unbind(VKUniformBuffer *uniform_buffer)
void storage_buffer_unbind(void *resource)
void uniform_buffer_bind(VKUniformBuffer *uniform_buffer, int slot)
void texture_unbind(Texture *tex) override
void texel_buffer_unbind(VKVertexBuffer &vertex_buffer)
void texture_bind(Texture *tex, GPUSamplerState sampler, int unit) override
void image_unbind(Texture *tex) override
void storage_buffer_bind(BindSpaceStorageBuffers::Type resource_type, void *resource, int binding)
void texture_unpack_row_length_set(uint len) override
local_group_size(16, 16) .push_constant(Type local_group_size(16, 16) .push_constant(Type input_tx sampler(1, ImageType::FLOAT_2D, "matte_tx") .image(0
int len
static constexpr int BIND_SPACE_IMAGE_OFFSET
static constexpr GPUSamplerState default_sampler()