Blender V5.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
8
12
13#include "vk_backend.hh"
14
17 const VKPipelineDataGraphics &graphics,
18 VKBoundPipelines &r_bound_pipelines)
19{
20 if (assign_if_different(r_bound_pipelines.graphics.viewport_state, graphics.viewport)) {
21 command_buffer.set_viewport(graphics.viewport.viewports);
22 command_buffer.set_scissor(graphics.viewport.scissors);
23 }
24 if (assign_if_different(r_bound_pipelines.graphics.line_width, graphics.line_width)) {
25 if (graphics.line_width.has_value()) {
26 command_buffer.set_line_width(*graphics.line_width);
27 }
28 }
29 if (assign_if_different(r_bound_pipelines.graphics.stencil_state, graphics.stencil_state)) {
30 if (graphics.stencil_state.has_value()) {
31 const StencilState &stencil_state = *graphics.stencil_state;
32 command_buffer.set_stencil_compare_mask(stencil_state.compare_mask);
33 command_buffer.set_stencil_write_mask(stencil_state.write_mask);
34 command_buffer.set_stencil_reference(stencil_state.reference);
35 }
36 }
37 if (assign_if_different(r_bound_pipelines.graphics.front_face, graphics.front_face)) {
38 if (graphics.front_face.has_value()) {
39 command_buffer.set_front_face(*graphics.front_face);
40 }
41 }
42 if (assign_if_different(r_bound_pipelines.graphics.vertex_input_description,
44 {
45 if (graphics.vertex_input_description.has_value()) {
46 VKDevice &device = VKBackend::get().device;
47 const VKVertexInputDescription &description = device.vertex_input_descriptions.get(
48 *graphics.vertex_input_description);
49 command_buffer.set_vertex_input(description.bindings, description.attributes);
50 }
51 }
52}
53
55 const VKPipelineData &pipeline_data,
56 Span<uint8_t> storage_push_constants,
57 VKBoundPipeline &r_bound_pipeline,
58 VkPipelineBindPoint vk_pipeline_bind_point,
59 VkShaderStageFlags vk_shader_stage_flags)
60{
61 if (assign_if_different(r_bound_pipeline.vk_pipeline, pipeline_data.vk_pipeline)) {
62 command_buffer.bind_pipeline(vk_pipeline_bind_point, r_bound_pipeline.vk_pipeline);
63 }
64
65 const bool descriptor_set_changed = assign_if_different(r_bound_pipeline.vk_descriptor_set,
66 pipeline_data.vk_descriptor_set);
67 const bool layout_changed = assign_if_different(r_bound_pipeline.vk_pipeline_layout,
68 pipeline_data.vk_pipeline_layout);
69 if ((descriptor_set_changed || layout_changed) &&
70 r_bound_pipeline.vk_descriptor_set != VK_NULL_HANDLE)
71 {
72 command_buffer.bind_descriptor_sets(vk_pipeline_bind_point,
73 pipeline_data.vk_pipeline_layout,
74 0,
75 1,
76 &r_bound_pipeline.vk_descriptor_set,
77 0,
78 nullptr);
79 }
80
81 if (!pipeline_data.push_constants_range.is_empty()) {
82 Span<uint8_t> pipeline_push_constants = storage_push_constants.slice(
83 pipeline_data.push_constants_range);
84 command_buffer.push_constants(pipeline_data.vk_pipeline_layout,
85 vk_shader_stage_flags,
86 0,
87 pipeline_push_constants.size(),
88 pipeline_push_constants.data());
89 }
90}
91
93 VKRenderGraphLinks &links,
94 const VKIndexBufferBinding &index_buffer_binding)
95{
96 ResourceWithStamp resource = resources.get_buffer(index_buffer_binding.buffer);
97 links.buffers.append({resource, VK_ACCESS_INDEX_READ_BIT});
98}
99
101 const VKIndexBufferBinding &index_buffer_binding,
102 VKIndexBufferBinding &r_bound_index_buffer)
103{
104 if (assign_if_different(r_bound_index_buffer, index_buffer_binding)) {
105 command_buffer.bind_index_buffer(
106 r_bound_index_buffer.buffer, 0, r_bound_index_buffer.index_type);
107 }
108}
109
111 VKRenderGraphLinks &links,
112 const VKVertexBufferBindings &vertex_buffers)
113{
114 for (const ResourceHandle resource_handle :
115 Span<ResourceHandle>(vertex_buffers.resource_handles, vertex_buffers.buffer_count))
116 {
117 ResourceWithStamp resource = resources.get_buffer(resource_handle);
118 links.buffers.append({resource, VK_ACCESS_VERTEX_ATTRIBUTE_READ_BIT});
119 }
120}
121
123 const VKVertexBufferBindings &vertex_buffer_bindings,
124 VKVertexBufferBindings &r_bound_vertex_buffers)
125{
126 if (assign_if_different(r_bound_vertex_buffers, vertex_buffer_bindings) &&
127 r_bound_vertex_buffers.buffer_count)
128 {
129 command_buffer.bind_vertex_buffers(0,
130 r_bound_vertex_buffers.buffer_count,
131 r_bound_vertex_buffers.buffer,
132 r_bound_vertex_buffers.offset);
133 }
134}
135
136} // namespace blender::gpu::render_graph
constexpr bool is_empty() const
constexpr Span slice(int64_t start, int64_t size) const
Definition BLI_span.hh:141
constexpr const T * data() const
Definition BLI_span.hh:219
constexpr int64_t size() const
Definition BLI_span.hh:256
static VKBackend & get()
VKVertexInputDescriptionPool vertex_input_descriptions
Definition vk_device.hh:275
const VKVertexInputDescription & get(Key key)
Get the vertex input description of the given key.
virtual void set_scissor(const Vector< VkRect2D > scissors)=0
virtual void bind_pipeline(VkPipelineBindPoint pipeline_bind_point, VkPipeline pipeline)=0
virtual void set_vertex_input(Span< VkVertexInputBindingDescription2EXT > vertex_binding_descriptions, Span< VkVertexInputAttributeDescription2EXT > vertex_attribute_descriptions)=0
virtual void set_stencil_reference(const uint32_t reference)=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_stencil_compare_mask(const uint32_t compare_mask)=0
virtual void set_stencil_write_mask(const uint32_t write_mask)=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
virtual void set_front_face(const VkFrontFace front_face)=0
ResourceWithStamp get_buffer(ResourceHandle buffer_handle) const
void vk_index_buffer_binding_build_commands(VKCommandBufferInterface &command_buffer, const VKIndexBufferBinding &index_buffer_binding, VKIndexBufferBinding &r_bound_index_buffer)
void vk_pipeline_dynamic_graphics_build_commands(VKCommandBufferInterface &command_buffer, const VKPipelineDataGraphics &graphics, VKBoundPipelines &r_bound_pipelines)
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, Span< uint8_t > storage_push_constants, VKBoundPipeline &r_bound_pipeline, VkPipelineBindPoint vk_pipeline_bind_point, VkShaderStageFlags vk_shader_stage_flags)
void vk_vertex_buffer_bindings_build_links(VKResourceStateTracker &resources, VKRenderGraphLinks &links, const VKVertexBufferBindings &vertex_buffers)
void vk_index_buffer_binding_build_links(VKResourceStateTracker &resources, VKRenderGraphLinks &links, const VKIndexBufferBinding &index_buffer_binding)
uint64_t ResourceHandle
Definition vk_common.hh:68
bool assign_if_different(T &old_value, T &&new_value)
Description of vertex inputs used by graphic pipelines.
Vector< VkVertexInputAttributeDescription2EXT > attributes
Vector< VkVertexInputBindingDescription2EXT > bindings
struct blender::gpu::render_graph::VKBoundPipelines::@354275304307172366215375121273352137136061330352 graphics
std::optional< VKVertexInputDescriptionPool::Key > vertex_input_description
Vector< VkViewport, GPU_MAX_VIEWPORTS > viewports
Vector< VkRect2D, GPU_MAX_VIEWPORTS > scissors