Blender V5.3
vk_descriptor_set.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
8
9#pragma once
10
11#include "BLI_utility_mixins.hh"
12#include "BLI_vector.hh"
13
14#include "gpu_shader_private.hh"
15
18#include "vk_buffer.hh"
19#include "vk_common.hh"
21#include "vk_uniform_buffer.hh"
22
23namespace blender::gpu {
25class VKStateManager;
26class VKDevice;
27class VKPushConstants;
28class VKShader;
30class VKVertexBuffer;
31
41
42 public:
54 struct Location {
56 friend class VKShaderInterface;
57 friend struct VKResourceBinding;
58
59 private:
63 uint32_t binding;
64
65 Location(uint32_t binding) : binding(binding) {}
66
67 public:
68 Location() = default;
69
70 bool operator==(const Location &other) const
71 {
72 return binding == other.binding;
73 }
74
75 operator uint32_t() const
76 {
77 return binding;
78 }
79 };
80};
81
83 public:
85
87 VKContext &context,
89 VkDescriptorSetLayout vk_descriptor_set_layout,
90 render_graph::VKPipelineData &r_pipeline_data) = 0;
91 void bind_shader_resources(const VKDevice &device,
92 const VKStateManager &state_manager,
94 const VKBufferWithOffset &push_constants_buffer);
95 virtual void upload_descriptor_sets() = 0;
96
97 private:
98 void bind_image_resource(const VKStateManager &state_manager,
99 const VKResourceBinding &resource_binding);
100 void bind_texture_resource(const VKDevice &device,
101 const VKStateManager &state_manager,
102 const VKResourceBinding &resource_binding);
103 void bind_storage_buffer_resource(const VKStateManager &state_manager,
104 const VKResourceBinding &resource_binding);
105 void bind_uniform_buffer_resource(const VKStateManager &state_manager,
106 const VKResourceBinding &resource_binding);
107 void bind_acceleration_structure_resource(const VKStateManager &state_manager,
108 const VKResourceBinding &resource_binding);
109 void bind_input_attachment_resource(const VKDevice &device,
110 const VKStateManager &state_manager,
111 const VKResourceBinding &resource_binding);
112
113 void bind_push_constants(VKPushConstants &push_constants,
114 const VKBufferWithOffset &push_constants_buffer);
115
116 protected:
117 virtual void bind_texel_buffer(VKVertexBuffer &vertex_buffer,
118 VKDescriptorSet::Location location) = 0;
119 virtual void bind_buffer(VkDescriptorType vk_descriptor_type,
120 VkBuffer vk_buffer,
121 VkDeviceSize buffer_offset,
122 VkDeviceSize size_in_bytes,
123 VKDescriptorSet::Location location) = 0;
124 virtual void bind_image(VkDescriptorType vk_descriptor_type,
125 VkSampler vk_sampler,
126 VkImageView vk_image_view,
127 VkImageLayout vk_image_layout,
128 VKDescriptorSet::Location location) = 0;
129 virtual void bind_acceleration_structure(VkDescriptorType vk_descriptor_type,
130 VkAccelerationStructureKHR vk_acceleration_structure,
131 VKDescriptorSet::Location location) = 0;
132};
133
135 public:
136 VkDescriptorSet vk_descriptor_set = VK_NULL_HANDLE;
137
139 VKContext &context,
141 VkDescriptorSetLayout vk_descriptor_set_layout,
142 render_graph::VKPipelineData &r_pipeline_data) override;
143
144 void upload_descriptor_sets() override;
145
146 protected:
147 void bind_texel_buffer(VKVertexBuffer &vertex_buffer,
148 VKDescriptorSet::Location location) override;
149 void bind_buffer(VkDescriptorType vk_descriptor_type,
150 VkBuffer vk_buffer,
151 VkDeviceSize buffer_offset,
152 VkDeviceSize size_in_bytes,
153 VKDescriptorSet::Location location) override;
154 void bind_image(VkDescriptorType vk_descriptor_type,
155 VkSampler vk_sampler,
156 VkImageView vk_image_view,
157 VkImageLayout vk_image_layout,
158 VKDescriptorSet::Location location) override;
159 void bind_acceleration_structure(VkDescriptorType vk_descriptor_type,
160 VkAccelerationStructureKHR vk_acceleration_structure,
161 VKDescriptorSet::Location location) override;
162
163 private:
164 Vector<VkBufferView> vk_buffer_views_;
165 Vector<VkDescriptorBufferInfo> vk_descriptor_buffer_infos_;
166 Vector<VkDescriptorImageInfo> vk_descriptor_image_infos_;
167 Vector<VkWriteDescriptorSet> vk_write_descriptor_sets_;
169 vk_write_descriptor_sets_acceleration_structures_;
170 Vector<VkAccelerationStructureKHR> vk_acceleration_structures_;
171};
172
174 friend class VKDescriptorSet;
175
176 /* Last used layout to identify changes. */
177 VkDescriptorSetLayout vk_descriptor_set_layout_ = VK_NULL_HANDLE;
178
179 public:
181
183
188 void update_descriptor_set(VKContext &context,
189 render_graph::VKResourceAccessInfo &resource_access_info,
190 render_graph::VKPipelineData &r_pipeline_data);
191
196
197 private:
201 static void update_resource_access_info(VKContext &context,
202 render_graph::VKResourceAccessInfo &resource_access_info,
203 const VKBufferWithOffset &push_constants_buffer);
204 static void update_resource_access_info_binding(const VKStateManager &state_manager,
205 const VKResourceBinding &resource_binding,
207 static void update_resource_access_info_binding_uniform_buffer(
208 const VKStateManager &state_manager,
209 const VKResourceBinding &resource_binding,
211 static void update_resource_access_info_binding_image(
212 const VKStateManager &state_manager,
213 const VKResourceBinding &resource_binding,
215 static void update_resource_access_info_binding_sampler(
216 const VKStateManager &state_manager,
217 const VKResourceBinding &resource_binding,
219 static void update_resource_access_info_binding_storage_buffer(
220 const VKStateManager &state_manager,
221 const VKResourceBinding &resource_binding,
223 static void update_resource_access_info_binding_input_attachment(
224 const VKStateManager &state_manager,
225 const VKResourceBinding &resource_binding,
227 static void update_resource_access_info_binding_acceleration_structure(
228 const VKStateManager &state_manager,
229 const VKResourceBinding &resource_binding,
231};
232
233} // namespace blender::gpu
NonCopyable(const NonCopyable &other)=delete
void bind_buffer(VkDescriptorType vk_descriptor_type, VkBuffer vk_buffer, VkDeviceSize buffer_offset, VkDeviceSize size_in_bytes, VKDescriptorSet::Location location) override
void allocate_new_descriptor_set(VKDevice &device, VKContext &context, VKShader &shader, VkDescriptorSetLayout vk_descriptor_set_layout, render_graph::VKPipelineData &r_pipeline_data) override
void bind_image(VkDescriptorType vk_descriptor_type, VkSampler vk_sampler, VkImageView vk_image_view, VkImageLayout vk_image_layout, VKDescriptorSet::Location location) override
void bind_texel_buffer(VKVertexBuffer &vertex_buffer, VKDescriptorSet::Location location) override
void bind_acceleration_structure(VkDescriptorType vk_descriptor_type, VkAccelerationStructureKHR vk_acceleration_structure, VKDescriptorSet::Location location) override
class VKDescriptorSetPoolUpdator descriptor_sets
void update_descriptor_set(VKContext &context, render_graph::VKResourceAccessInfo &resource_access_info, render_graph::VKPipelineData &r_pipeline_data)
virtual void bind_texel_buffer(VKVertexBuffer &vertex_buffer, VKDescriptorSet::Location location)=0
virtual void allocate_new_descriptor_set(VKDevice &device, VKContext &context, VKShader &shader, VkDescriptorSetLayout vk_descriptor_set_layout, render_graph::VKPipelineData &r_pipeline_data)=0
virtual void bind_buffer(VkDescriptorType vk_descriptor_type, VkBuffer vk_buffer, VkDeviceSize buffer_offset, VkDeviceSize size_in_bytes, VKDescriptorSet::Location location)=0
virtual void bind_acceleration_structure(VkDescriptorType vk_descriptor_type, VkAccelerationStructureKHR vk_acceleration_structure, VKDescriptorSet::Location location)=0
virtual void bind_image(VkDescriptorType vk_descriptor_type, VkSampler vk_sampler, VkImageView vk_image_view, VkImageLayout vk_image_layout, VKDescriptorSet::Location location)=0
void bind_shader_resources(const VKDevice &device, const VKStateManager &state_manager, VKShader &shader, const VKBufferWithOffset &push_constants_buffer)
unsigned int uint32_t
Definition BKE_text.h:81
bool operator==(const Location &other) const