Blender V5.0
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,
28 const std::optional<float> line_width,
29 VKBoundPipelines &r_bound_pipelines)
30{
31 if (assign_if_different(r_bound_pipelines.graphics.viewport_state, viewport)) {
32 command_buffer.set_viewport(viewport.viewports);
33 command_buffer.set_scissor(viewport.scissors);
34 }
35 if (assign_if_different(r_bound_pipelines.graphics.line_width, line_width)) {
36 if (line_width.has_value()) {
37 command_buffer.set_line_width(*line_width);
38 }
39 }
40}
41
43 const VKPipelineData &pipeline_data,
44 VKBoundPipeline &r_bound_pipeline,
45 VkPipelineBindPoint vk_pipeline_bind_point,
46 VkShaderStageFlags vk_shader_stage_flags)
47{
48 if (assign_if_different(r_bound_pipeline.vk_pipeline, pipeline_data.vk_pipeline)) {
49 command_buffer.bind_pipeline(vk_pipeline_bind_point, r_bound_pipeline.vk_pipeline);
50 }
51
52 if (assign_if_different(r_bound_pipeline.vk_descriptor_set, pipeline_data.vk_descriptor_set) &&
53 r_bound_pipeline.vk_descriptor_set != VK_NULL_HANDLE)
54 {
55 command_buffer.bind_descriptor_sets(vk_pipeline_bind_point,
56 pipeline_data.vk_pipeline_layout,
57 0,
58 1,
59 &r_bound_pipeline.vk_descriptor_set,
60 0,
61 nullptr);
62 }
63
65 pipeline_data.descriptor_buffer_device_address) &&
66 r_bound_pipeline.descriptor_buffer_device_address != 0)
67 {
68 r_bound_pipeline.descriptor_buffer_offset = pipeline_data.descriptor_buffer_offset;
69 VkDescriptorBufferBindingInfoEXT descriptor_buffer_binding_info = {
70 VK_STRUCTURE_TYPE_DESCRIPTOR_BUFFER_BINDING_INFO_EXT,
71 nullptr,
72 r_bound_pipeline.descriptor_buffer_device_address,
73 VK_BUFFER_USAGE_SAMPLER_DESCRIPTOR_BUFFER_BIT_EXT |
74 VK_BUFFER_USAGE_RESOURCE_DESCRIPTOR_BUFFER_BIT_EXT};
75 command_buffer.bind_descriptor_buffers(1, &descriptor_buffer_binding_info);
76
77 uint32_t buffer_index = 0;
78 command_buffer.set_descriptor_buffer_offsets(vk_pipeline_bind_point,
79 pipeline_data.vk_pipeline_layout,
80 0,
81 1,
82 &buffer_index,
83 &r_bound_pipeline.descriptor_buffer_offset);
84 }
85 else if (assign_if_different(r_bound_pipeline.descriptor_buffer_offset,
86 pipeline_data.descriptor_buffer_offset) &&
87 r_bound_pipeline.descriptor_buffer_device_address != 0)
88 {
89 uint32_t buffer_index = 0;
90 command_buffer.set_descriptor_buffer_offsets(vk_pipeline_bind_point,
91 pipeline_data.vk_pipeline_layout,
92 0,
93 1,
94 &buffer_index,
95 &r_bound_pipeline.descriptor_buffer_offset);
96 }
97
98 if (pipeline_data.push_constants_size) {
99 command_buffer.push_constants(pipeline_data.vk_pipeline_layout,
100 vk_shader_stage_flags,
101 0,
102 pipeline_data.push_constants_size,
103 pipeline_data.push_constants_data);
104 }
105}
106
108{
109 if (data.push_constants_data) {
110 MEM_freeN(const_cast<void *>(data.push_constants_data));
111 data.push_constants_data = nullptr;
112 }
113}
114
116 VKRenderGraphNodeLinks &node_links,
117 const VKIndexBufferBinding &index_buffer_binding)
118{
119 ResourceWithStamp resource = resources.get_buffer(index_buffer_binding.buffer);
120 node_links.inputs.append({resource, VK_ACCESS_INDEX_READ_BIT});
121}
122
124 const VKIndexBufferBinding &index_buffer_binding,
125 VKIndexBufferBinding &r_bound_index_buffer)
126{
127 if (assign_if_different(r_bound_index_buffer, index_buffer_binding)) {
128 command_buffer.bind_index_buffer(
129 r_bound_index_buffer.buffer, 0, r_bound_index_buffer.index_type);
130 }
131}
132
134 VKRenderGraphNodeLinks &node_links,
135 const VKVertexBufferBindings &vertex_buffers)
136{
137 node_links.inputs.reserve(node_links.inputs.size() + vertex_buffers.buffer_count);
138 for (const VkBuffer vk_buffer :
139 Span<VkBuffer>(vertex_buffers.buffer, vertex_buffers.buffer_count))
140 {
141 ResourceWithStamp resource = resources.get_buffer(vk_buffer);
142 node_links.inputs.append({resource, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT});
143 }
144}
145
147 const VKVertexBufferBindings &vertex_buffer_bindings,
148 VKVertexBufferBindings &r_bound_vertex_buffers)
149{
150 if (assign_if_different(r_bound_vertex_buffers, vertex_buffer_bindings) &&
151 r_bound_vertex_buffers.buffer_count)
152 {
153 command_buffer.bind_vertex_buffers(0,
154 r_bound_vertex_buffers.buffer_count,
155 r_bound_vertex_buffers.buffer,
156 r_bound_vertex_buffers.offset);
157 }
158}
159
160} // 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 set_line_width(const float line_width)=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_pipeline_dynamic_graphics_build_commands(VKCommandBufferInterface &command_buffer, const VKViewportData &viewport, const std::optional< float > line_width, VKBoundPipelines &r_bound_pipelines)
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_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)
struct blender::gpu::render_graph::VKBoundPipelines::@245157173206043141117177130032265241203257234004 graphics