Blender V4.3
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
12
15{
16 dst.push_constants_data = nullptr;
18 if (src.push_constants_size) {
20 void *data = MEM_mallocN(src.push_constants_size, __func__);
21 memcpy(data, src.push_constants_data, src.push_constants_size);
23 }
24}
25
27 const VKPipelineData &pipeline_data,
28 VKBoundPipeline &r_bound_pipeline,
29 VkPipelineBindPoint vk_pipeline_bind_point,
30 VkShaderStageFlags vk_shader_stage_flags)
31{
32 if (assign_if_different(r_bound_pipeline.vk_pipeline, pipeline_data.vk_pipeline)) {
33 command_buffer.bind_pipeline(vk_pipeline_bind_point, r_bound_pipeline.vk_pipeline);
34 }
35
36 if (assign_if_different(r_bound_pipeline.vk_descriptor_set, pipeline_data.vk_descriptor_set) &&
37 r_bound_pipeline.vk_descriptor_set != VK_NULL_HANDLE)
38 {
39 command_buffer.bind_descriptor_sets(vk_pipeline_bind_point,
40 pipeline_data.vk_pipeline_layout,
41 0,
42 1,
43 &r_bound_pipeline.vk_descriptor_set,
44 0,
45 nullptr);
46 }
47
48 if (pipeline_data.push_constants_size) {
49 command_buffer.push_constants(pipeline_data.vk_pipeline_layout,
50 vk_shader_stage_flags,
51 0,
52 pipeline_data.push_constants_size,
53 pipeline_data.push_constants_data);
54 }
55}
56
58{
59 MEM_SAFE_FREE(data.push_constants_data);
60}
61
63 VKRenderGraphNodeLinks &node_links,
64 const VKIndexBufferBinding &index_buffer_binding)
65{
66 ResourceWithStamp resource = resources.get_buffer(index_buffer_binding.buffer);
67 node_links.inputs.append({resource, VK_ACCESS_INDEX_READ_BIT});
68}
69
71 const VKIndexBufferBinding &index_buffer_binding,
72 VKIndexBufferBinding &r_bound_index_buffer)
73{
74 if (assign_if_different(r_bound_index_buffer, index_buffer_binding)) {
75 command_buffer.bind_index_buffer(
76 r_bound_index_buffer.buffer, 0, r_bound_index_buffer.index_type);
77 }
78}
79
81 VKRenderGraphNodeLinks &node_links,
82 const VKVertexBufferBindings &vertex_buffers)
83{
84 for (const VkBuffer vk_buffer :
85 Span<VkBuffer>(vertex_buffers.buffer, vertex_buffers.buffer_count))
86 {
87 ResourceWithStamp resource = resources.get_buffer(vk_buffer);
88 node_links.inputs.append({resource, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT});
89 }
90}
91
93 const VKVertexBufferBindings &vertex_buffer_bindings,
94 VKVertexBufferBindings &r_bound_vertex_buffers)
95{
96 if (assign_if_different(r_bound_vertex_buffers, vertex_buffer_bindings) &&
97 r_bound_vertex_buffers.buffer_count)
98 {
99 command_buffer.bind_vertex_buffers(0,
100 r_bound_vertex_buffers.buffer_count,
101 r_bound_vertex_buffers.buffer,
102 r_bound_vertex_buffers.offset);
103 }
104}
105
106} // namespace blender::gpu::render_graph
#define BLI_assert(a)
Definition BLI_assert.h:50
#define MEM_SAFE_FREE(v)
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 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
void *(* MEM_mallocN)(size_t len, const char *str)
Definition mallocn.cc:44
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_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)