Blender V4.5
vk_pipeline_data.cc
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
12
25
27 const VKViewportData &viewport_data,
28 VKViewportData &r_viewport_state)
29{
30 if (assign_if_different(r_viewport_state, viewport_data)) {
31 command_buffer.set_viewport(viewport_data.viewports);
32 command_buffer.set_scissor(viewport_data.scissors);
33 }
34}
35
37 const VKPipelineData &pipeline_data,
38 VKBoundPipeline &r_bound_pipeline,
39 VkPipelineBindPoint vk_pipeline_bind_point,
40 VkShaderStageFlags vk_shader_stage_flags)
41{
42 if (assign_if_different(r_bound_pipeline.vk_pipeline, pipeline_data.vk_pipeline)) {
43 command_buffer.bind_pipeline(vk_pipeline_bind_point, r_bound_pipeline.vk_pipeline);
44 }
45
46 if (assign_if_different(r_bound_pipeline.vk_descriptor_set, pipeline_data.vk_descriptor_set) &&
47 r_bound_pipeline.vk_descriptor_set != VK_NULL_HANDLE)
48 {
49 command_buffer.bind_descriptor_sets(vk_pipeline_bind_point,
50 pipeline_data.vk_pipeline_layout,
51 0,
52 1,
53 &r_bound_pipeline.vk_descriptor_set,
54 0,
55 nullptr);
56 }
57
59 pipeline_data.descriptor_buffer_device_address) &&
60 r_bound_pipeline.descriptor_buffer_device_address != 0)
61 {
62 r_bound_pipeline.descriptor_buffer_offset = pipeline_data.descriptor_buffer_offset;
63 VkDescriptorBufferBindingInfoEXT descriptor_buffer_binding_info = {
64 VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT,
65 nullptr,
66 r_bound_pipeline.descriptor_buffer_device_address,
67 VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT |
68 VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT};
69 command_buffer.bind_descriptor_buffers(1, &descriptor_buffer_binding_info);
70
71 uint32_t buffer_index = 0;
72 command_buffer.set_descriptor_buffer_offsets(vk_pipeline_bind_point,
73 pipeline_data.vk_pipeline_layout,
74 0,
75 1,
76 &buffer_index,
77 &r_bound_pipeline.descriptor_buffer_offset);
78 }
79 else if (assign_if_different(r_bound_pipeline.descriptor_buffer_offset,
80 pipeline_data.descriptor_buffer_offset) &&
81 r_bound_pipeline.descriptor_buffer_device_address != 0)
82 {
83 uint32_t buffer_index = 0;
84 command_buffer.set_descriptor_buffer_offsets(vk_pipeline_bind_point,
85 pipeline_data.vk_pipeline_layout,
86 0,
87 1,
88 &buffer_index,
89 &r_bound_pipeline.descriptor_buffer_offset);
90 }
91
92 if (pipeline_data.push_constants_size) {
93 command_buffer.push_constants(pipeline_data.vk_pipeline_layout,
94 vk_shader_stage_flags,
95 0,
96 pipeline_data.push_constants_size,
97 pipeline_data.push_constants_data);
98 }
99}
100
102{
103 if (data.push_constants_data) {
104 MEM_freeN(const_cast<void *>(data.push_constants_data));
105 data.push_constants_data = nullptr;
106 }
107}
108
110 VKRenderGraphNodeLinks &node_links,
111 const VKIndexBufferBinding &index_buffer_binding)
112{
113 ResourceWithStamp resource = resources.get_buffer(index_buffer_binding.buffer);
114 node_links.inputs.append({resource, VK_ACCESS_INDEX_READ_BIT});
115}
116
118 const VKIndexBufferBinding &index_buffer_binding,
119 VKIndexBufferBinding &r_bound_index_buffer)
120{
121 if (assign_if_different(r_bound_index_buffer, index_buffer_binding)) {
122 command_buffer.bind_index_buffer(
123 r_bound_index_buffer.buffer, 0, r_bound_index_buffer.index_type);
124 }
125}
126
128 VKRenderGraphNodeLinks &node_links,
129 const VKVertexBufferBindings &vertex_buffers)
130{
131 node_links.inputs.reserve(node_links.inputs.size() + vertex_buffers.buffer_count);
132 for (const VkBuffer vk_buffer :
133 Span<VkBuffer>(vertex_buffers.buffer, vertex_buffers.buffer_count))
134 {
135 ResourceWithStamp resource = resources.get_buffer(vk_buffer);
136 node_links.inputs.append({resource, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT});
137 }
138}
139
141 const VKVertexBufferBindings &vertex_buffer_bindings,
142 VKVertexBufferBindings &r_bound_vertex_buffers)
143{
144 if (assign_if_different(r_bound_vertex_buffers, vertex_buffer_bindings) &&
145 r_bound_vertex_buffers.buffer_count)
146 {
147 command_buffer.bind_vertex_buffers(0,
148 r_bound_vertex_buffers.buffer_count,
149 r_bound_vertex_buffers.buffer,
150 r_bound_vertex_buffers.offset);
151 }
152}
153
154} // namespace blender::gpu::render_graph
#define BLI_assert(a)
Definition BLI_assert.h:46
BMesh const char void * data
virtual void set_scissor(const Vector< VkRect2D > scissors)=0
virtual void bind_pipeline(VkPipelineBindPoint pipeline_bind_point, VkPipeline pipeline)=0
virtual void bind_vertex_buffers(uint32_t first_binding, uint32_t binding_count, const VkBuffer *p_buffers, const VkDeviceSize *p_offsets)=0
virtual void bind_descriptor_sets(VkPipelineBindPoint pipeline_bind_point, VkPipelineLayout layout, uint32_t first_set, uint32_t descriptor_set_count, const VkDescriptorSet *p_descriptor_sets, uint32_t dynamic_offset_count, const uint32_t *p_dynamic_offsets)=0
virtual void set_descriptor_buffer_offsets(VkPipelineBindPoint pipeline_bind_point, VkPipelineLayout layout, uint32_t first_set, uint32_t set_count, const uint32_t *p_buffer_indices, const VkDeviceSize *p_offsets)=0
virtual void bind_descriptor_buffers(uint32_t buffer_count, const VkDescriptorBufferBindingInfoEXT *p_binding_infos)=0
virtual void set_viewport(const Vector< VkViewport > viewports)=0
virtual void bind_index_buffer(VkBuffer buffer, VkDeviceSize offset, VkIndexType index_type)=0
virtual void push_constants(VkPipelineLayout layout, VkShaderStageFlags stage_flags, uint32_t offset, uint32_t size, const void *p_values)=0
ResourceWithStamp get_buffer(VkBuffer vk_buffer) const
#define resource
void * MEM_mallocN(size_t len, const char *str)
Definition mallocn.cc:128
void MEM_freeN(void *vmemh)
Definition mallocn.cc:113
void vk_pipeline_data_copy(VKPipelineData &dst, const VKPipelineData &src)
void vk_index_buffer_binding_build_commands(VKCommandBufferInterface &command_buffer, const VKIndexBufferBinding &index_buffer_binding, VKIndexBufferBinding &r_bound_index_buffer)
void vk_index_buffer_binding_build_links(VKResourceStateTracker &resources, VKRenderGraphNodeLinks &node_links, const VKIndexBufferBinding &index_buffer_binding)
void vk_vertex_buffer_bindings_build_links(VKResourceStateTracker &resources, VKRenderGraphNodeLinks &node_links, const VKVertexBufferBindings &vertex_buffers)
void vk_pipeline_data_free(VKPipelineData &data)
void vk_pipeline_viewport_set_commands(VKCommandBufferInterface &command_buffer, const VKViewportData &viewport_data, VKViewportData &r_viewport_state)
void vk_vertex_buffer_bindings_build_commands(VKCommandBufferInterface &command_buffer, const VKVertexBufferBindings &vertex_buffer_bindings, VKVertexBufferBindings &r_bound_vertex_buffers)
void vk_pipeline_data_build_commands(VKCommandBufferInterface &command_buffer, const VKPipelineData &pipeline_data, VKBoundPipeline &r_bound_pipeline, VkPipelineBindPoint vk_pipeline_bind_point, VkShaderStageFlags vk_shader_stage_flags)
bool assign_if_different(T &old_value, T new_value)