Blender V4.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
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"
19
20#include "shaderc/shaderc.hpp"
21
22namespace blender::gpu {
23class VKShaderInterface;
24
25class VKShader : public Shader {
26 private:
27 VKContext *context_ = nullptr;
28
33 VkDescriptorSetLayout vk_descriptor_set_layout_ = VK_NULL_HANDLE;
34
40 VkPipeline vk_pipeline_base_ = VK_NULL_HANDLE;
41
42 bool is_compute_shader_ = false;
43 bool is_static_shader_ = false;
44 bool use_batch_compilation_ = false;
45
46 public:
52 bool compilation_failed = false;
53
54 VkPipelineLayout vk_pipeline_layout = VK_NULL_HANDLE;
56
57 VKShader(const char *name);
58 virtual ~VKShader();
59
60 void init(const shader::ShaderCreateInfo &info, bool is_batch_compilation) override;
61
66 bool finalize(const shader::ShaderCreateInfo *info = nullptr) override;
67 bool finalize_post();
68
76 bool is_ready() const;
77 void warm_cache(int limit) override;
78
80 eGPUShaderTFBType geom_type) override;
81 bool transform_feedback_enable(VertBuf *) override;
82 void transform_feedback_disable() override;
83
84 void bind() override;
85 void unbind() override;
86
87 void uniform_float(int location, int comp_len, int array_size, const float *data) override;
88 void uniform_int(int location, int comp_len, int array_size, const int *data) override;
89
90 std::string resources_declare(const shader::ShaderCreateInfo &info) const override;
91 std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const override;
92 std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const override;
93 std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const override;
94 std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override;
95 std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const override;
96
97 /* Unused: SSBO vertex fetch draw parameters. */
98 bool get_uses_ssbo_vertex_fetch() const override
99 {
100 return false;
101 }
103 {
104 return 0;
105 }
106
107 /* DEPRECATED: Kept only because of BGL API. */
108 int program_handle_get() const override;
109
113 VKStateManager &state_manager,
114 VKFrameBuffer &framebuffer);
115
116 const VKShaderInterface &interface_get() const;
117
124 {
125 return vk_descriptor_set_layout_ != VK_NULL_HANDLE;
126 }
127
128 VkDescriptorSetLayout vk_descriptor_set_layout_get() const
129 {
130 return vk_descriptor_set_layout_;
131 }
132
133 private:
134 void build_shader_module(MutableSpan<const char *> sources,
135 shaderc_shader_kind stage,
136 VKShaderModule &r_shader_module);
137 bool finalize_shader_module(VKShaderModule &shader_module, const char *stage_name);
138 bool finalize_descriptor_set_layouts(VKDevice &vk_device,
139 const VKShaderInterface &shader_interface);
140 bool finalize_pipeline_layout(VkDevice vk_device, const VKShaderInterface &shader_interface);
141
146 std::string workaround_geometry_shader_source_create(const shader::ShaderCreateInfo &info);
147 bool do_geometry_shader_injection(const shader::ShaderCreateInfo *info) const;
148};
149
150static inline VKShader &unwrap(Shader &shader)
151{
152 return static_cast<VKShader &>(shader);
153}
154
155static inline VKShader *unwrap(Shader *shader)
156{
157 return static_cast<VKShader *>(shader);
158}
159
160} // namespace blender::gpu
GPUPrimType
eGPUShaderTFBType
void init()
int get_ssbo_vertex_fetch_output_num_verts() const override
Definition vk_shader.hh:102
void unbind() override
Definition vk_shader.cc:735
VKShaderModule compute_module
Definition vk_shader.hh:50
std::string fragment_interface_declare(const shader::ShaderCreateInfo &info) const override
Definition vk_shader.cc:913
int program_handle_get() const override
void bind() override
Definition vk_shader.cc:729
VKShaderModule fragment_module
Definition vk_shader.hh:49
void transform_feedback_names_set(Span< const char * > name_list, eGPUShaderTFBType geom_type) override
Definition vk_shader.cc:711
void geometry_shader_from_glsl(MutableSpan< const char * > sources) override
Definition vk_shader.cc:546
void compute_shader_from_glsl(MutableSpan< const char * > sources) override
Definition vk_shader.cc:556
std::string geometry_interface_declare(const shader::ShaderCreateInfo &info) const override
void warm_cache(int limit) override
Definition vk_shader.cc:561
VKPushConstants push_constants
Definition vk_shader.hh:55
std::string resources_declare(const shader::ShaderCreateInfo &info) const override
Definition vk_shader.cc:747
bool is_ready() const
Definition vk_shader.cc:647
std::string compute_layout_declare(const shader::ShaderCreateInfo &info) const override
bool get_uses_ssbo_vertex_fetch() const override
Definition vk_shader.hh:98
bool has_descriptor_set() const
Definition vk_shader.hh:123
VkPipelineLayout vk_pipeline_layout
Definition vk_shader.hh:54
VkPipeline ensure_and_get_compute_pipeline()
void transform_feedback_disable() override
Definition vk_shader.cc:722
void uniform_int(int location, int comp_len, int array_size, const int *data) override
Definition vk_shader.cc:742
VKShader(const char *name)
Definition vk_shader.cc:493
VKShaderModule vertex_module
Definition vk_shader.hh:47
void vertex_shader_from_glsl(MutableSpan< const char * > sources) override
Definition vk_shader.cc:541
VKShaderModule geometry_module
Definition vk_shader.hh:48
VkPipeline ensure_and_get_graphics_pipeline(GPUPrimType primitive, VKVertexAttributeObject &vao, VKStateManager &state_manager, VKFrameBuffer &framebuffer)
std::string geometry_layout_declare(const shader::ShaderCreateInfo &info) const override
void uniform_float(int location, int comp_len, int array_size, const float *data) override
Definition vk_shader.cc:737
const VKShaderInterface & interface_get() const
bool transform_feedback_enable(VertBuf *) override
Definition vk_shader.cc:717
void fragment_shader_from_glsl(MutableSpan< const char * > sources) override
Definition vk_shader.cc:551
VkDescriptorSetLayout vk_descriptor_set_layout_get() const
Definition vk_shader.hh:128
bool finalize(const shader::ShaderCreateInfo *info=nullptr) override
Definition vk_shader.cc:566
std::string vertex_interface_declare(const shader::ShaderCreateInfo &info) const override
Definition vk_shader.cc:824
EvaluationStage stage
Definition deg_eval.cc:83
static Context * unwrap(GPUContext *ctx)
Describe inputs & outputs, stage interfaces, resources and sources of a shader. If all data is correc...