Blender V5.3
vk_shader.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include "BLI_string_ref.hh"
12
13#include "gpu_shader_private.hh"
14
15#include "vk_backend.hh"
16#include "vk_context.hh"
17#include "vk_push_constants.hh"
18#include "vk_shader_module.hh"
20
21#include "shaderc/shaderc.hpp"
22
23namespace blender::gpu {
25
26class VKShader : public Shader {
27 private:
28 VKContext *context_ = nullptr;
29
34 VkDescriptorSetLayout vk_descriptor_set_layout_ = VK_NULL_HANDLE;
35
41 VkPipeline vk_pipeline_base_ = VK_NULL_HANDLE;
42
43 bool is_compute_shader_ = false;
44 bool is_static_shader_ = false;
45
53 bool has_precompiled_pipelines_ = false;
54 bool use_ray_query_ = false;
55
61 uint32_t max_input_attachment_index_ = 0;
62
63 public:
68
69 VkPipelineLayout vk_pipeline_layout = VK_NULL_HANDLE;
71
72 VKShader(const char *name);
73 virtual ~VKShader();
74
75 void init(const shader::ShaderCreateInfo &info, bool is_codegen_only) override;
76
78 const shader::ShaderCreateInfo &original_info) override
79 {
80 return original_info;
81 }
82
84 MutableSpan<StringRefNull> sources) override;
86 MutableSpan<StringRefNull> sources) override;
88 MutableSpan<StringRefNull> sources) override;
90 MutableSpan<StringRefNull> sources) override;
91 bool finalize(const shader::ShaderCreateInfo *info = nullptr) override;
92 bool finalize_post(Span<shader::PipelineState> pipeline_states);
93
94 void warm_cache(int limit) override;
95
96 void bind(const shader::SpecializationConstants *constants_state) override;
97 void unbind() override;
98
99 void uniform_float(int location, int comp_len, int array_size, const float *data) override;
100 void uniform_int(int location, int comp_len, int array_size, const int *data) override;
101
102 std::string resources_declare(const shader::ShaderCreateInfo &info) const override;
103 std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const override;
104 std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const override;
105 std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const override;
106 std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override;
107 std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const override;
108
110 const shader::SpecializationConstants &constants_state);
113 GPUPrimType primitive,
114 VKVertexInputDescriptionPool::Key vertex_input_description_key,
115 VKStateManager &state_manager,
116 const VKFrameBuffer &framebuffer,
117 shader::SpecializationConstants &constants_state);
118
119 const VKShaderInterface &interface_get() const;
120
127 {
128 return vk_descriptor_set_layout_ != VK_NULL_HANDLE;
129 }
130
131 VkDescriptorSetLayout vk_descriptor_set_layout_get() const
132 {
133 return vk_descriptor_set_layout_;
134 }
135
136 bool use_ray_query_get() const
137 {
138 return use_ray_query_;
139 }
140
141 private:
142 void build_shader_module(MutableSpan<StringRefNull> sources,
143 shaderc_shader_kind stage,
144 VKShaderModule &r_shader_module);
145 bool finalize_shader_module(VKShaderModule &shader_module, const char *stage_name);
146 bool finalize_descriptor_set_layouts(VKDevice &vk_device,
147 const VKShaderInterface &shader_interface);
148 bool finalize_pipeline_layout(VKDevice &device, const VKShaderInterface &shader_interface);
149
154 std::string workaround_geometry_shader_source_create(const shader::ShaderCreateInfo &info);
155 bool do_geometry_shader_injection(const shader::ShaderCreateInfo *info) const;
156};
157
158static inline VKShader &unwrap(Shader &shader)
159{
160 return static_cast<VKShader &>(shader);
161}
162
163static inline VKShader *unwrap(Shader *shader)
164{
165 return static_cast<VKShader *>(shader);
166}
167
168} // namespace blender::gpu
Shader(const char *name)
void fragment_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
Definition vk_shader.cc:582
void unbind() override
Definition vk_shader.cc:740
VKShaderModule compute_module
Definition vk_shader.hh:67
std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const override
Definition vk_shader.cc:973
bool use_ray_query_get() const
Definition vk_shader.hh:136
const shader::ShaderCreateInfo & patch_create_info(const shader::ShaderCreateInfo &original_info) override
Definition vk_shader.hh:77
VkPipeline ensure_and_get_compute_pipeline(const shader::SpecializationConstants &constants_state)
VKShaderModule fragment_module
Definition vk_shader.hh:66
std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const override
void warm_cache(int limit) override
Definition vk_shader.cc:594
VKPushConstants push_constants
Definition vk_shader.hh:70
std::string resources_declare(const shader::ShaderCreateInfo &info) const override
Definition vk_shader.cc:752
void geometry_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
Definition vk_shader.cc:576
std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const override
bool has_descriptor_set() const
Definition vk_shader.hh:126
VkPipelineLayout vk_pipeline_layout
Definition vk_shader.hh:69
bool ensure_graphics_pipelines(Span< shader::PipelineState > pipeline_states)
void vertex_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
Definition vk_shader.cc:570
void uniform_int(int location, int comp_len, int array_size, const int *data) override
Definition vk_shader.cc:747
void compute_shader_from_glsl(const shader::ShaderCreateInfo &info, MutableSpan< StringRefNull > sources) override
Definition vk_shader.cc:588
VKShader(const char *name)
Definition vk_shader.cc:505
VKShaderModule vertex_module
Definition vk_shader.hh:64
void bind(const shader::SpecializationConstants *constants_state) override
Definition vk_shader.cc:730
VKShaderModule geometry_module
Definition vk_shader.hh:65
std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override
bool finalize_post(Span< shader::PipelineState > pipeline_states)
Definition vk_shader.cc:628
void uniform_float(int location, int comp_len, int array_size, const float *data) override
Definition vk_shader.cc:742
VkPipeline ensure_and_get_graphics_pipeline(GPUPrimType primitive, VKVertexInputDescriptionPool::Key vertex_input_description_key, VKStateManager &state_manager, const VKFrameBuffer &framebuffer, shader::SpecializationConstants &constants_state)
VkDescriptorSetLayout vk_descriptor_set_layout_get() const
Definition vk_shader.hh:131
void init(const shader::ShaderCreateInfo &info, bool is_codegen_only) override
Definition vk_shader.cc:510
bool finalize(const shader::ShaderCreateInfo *info=nullptr) override
Definition vk_shader.cc:599
std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const override
Definition vk_shader.cc:864
#define interface_get(create_info, _res)
static Context * unwrap(GPUContext *ctx)
unsigned int uint32_t
Definition BKE_text.h:81
BMesh const char void * data
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...