Blender V5.3
draw_shader.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "draw_shader.hh"
10
11#include "GPU_batch.hh"
12#include "GPU_capabilities.hh"
13
16
17#include "DRW_render.hh"
18
19namespace blender {
20
21#define SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS 4
22
24{
25 switch (shader_type) {
27 return "subdiv_lines";
28
30 return "subdiv_lines_loose";
31
33 return "subdiv_tris_single_material";
34
36 return "subdiv_tris_multiple_materials";
37
39 return "subdiv_edge_fac";
40
42 return "subdiv_sculpt_data";
43
45 return "subdiv_patch_evaluation_verts";
46
48 return "subdiv_patch_evaluation_fvar";
49
51 return "subdiv_patch_evaluation_fdots";
52
54 return "subdiv_patch_evaluation_fdots_normals";
55
57 return "subdiv_patch_evaluation_verts_orcos";
58
60 return "subdiv_edituv_stretch_angle";
61
63 return "subdiv_edituv_stretch_area";
64
66 return "subdiv_normals_accumulate";
67
69 return "subdiv_paint_overlay_flag";
70
72 return "subdiv_loop_normals";
73
75 break;
76
77 default:
78 break;
79 }
81 return "";
82}
83
84namespace draw::Shader {
85
87 static gpu::StaticShaderCache<ShaderCache> &get_static_cache()
88 {
89 static gpu::StaticShaderCache<ShaderCache> static_cache;
90 return static_cache;
91 }
92
93 public:
94 static ShaderCache &get()
95 {
96 return get_static_cache().get();
97 }
98 static void release()
99 {
100 get_static_cache().release();
101 }
102
103 gpu::StaticShader curves_topology = {"draw_curves_topology"};
104 gpu::StaticShader curves_evaluate_position = {"draw_curves_interpolate_position"};
105 gpu::StaticShader curves_evaluate_float4 = {"draw_curves_interpolate_float4_attribute"};
106 gpu::StaticShader curves_evaluate_float3 = {"draw_curves_interpolate_float3_attribute"};
107 gpu::StaticShader curves_evaluate_float2 = {"draw_curves_interpolate_float2_attribute"};
108 gpu::StaticShader curves_evaluate_float = {"draw_curves_interpolate_float_attribute"};
109 gpu::StaticShader curves_evaluate_length_intercept = {"draw_curves_evaluate_length_intercept"};
110
111 gpu::StaticShader gsplat_compute_ellipses = {"draw_gsplat_compute_ellipses"};
112 gpu::StaticShader gsplat_compute_radiance = {"draw_gsplat_compute_radiance"};
113 gpu::StaticShader gsplat_compute_ellipses_radiance = {"draw_gsplat_compute_ellipses_radiance"};
114
115 gpu::StaticShader debug_draw_display = {"draw_debug_draw_display"};
116 gpu::StaticShader draw_visibility_compute = {"draw_visibility_compute"};
117 gpu::StaticShader draw_view_finalize = {"draw_view_finalize"};
118 gpu::StaticShader draw_resource_finalize = {"draw_resource_finalize"};
119 gpu::StaticShader draw_command_generate = {"draw_command_generate"};
120
121 /* Indexed by the element size in 32-bit words, minus one. */
122 gpu::StaticShader mesh_gather[4] = {{"draw_mesh_gather_4"},
123 {"draw_mesh_gather_8"},
124 {"draw_mesh_gather_12"},
125 {"draw_mesh_gather_16"}};
126 gpu::StaticShader mesh_scatter_faces[4] = {{"draw_mesh_scatter_faces_4"},
127 {"draw_mesh_scatter_faces_8"},
128 {"draw_mesh_scatter_faces_12"},
129 {"draw_mesh_scatter_faces_16"}};
130
134 "subdiv_custom_data_interp_3d_f32_normalize"};
135
137 {
138 for (int i : IndexRange(SUBDIVISION_MAX_SHADERS)) {
140 continue;
141 }
143 }
144
147 std::string info_name = "subdiv_custom_data_interp";
148 const char *dimension_names[] = {"_1d", "_2d", "_3d", "_4d"};
149 info_name += dimension_names[dimension];
150
151 switch (comp_type) {
152 case GPU_COMP_U16:
153 info_name += "_u16";
154 break;
155 case GPU_COMP_I32:
156 info_name += "_i32";
157 break;
158 case GPU_COMP_F32:
159 info_name += "_f32";
160 break;
161 default:
163 }
164
165 subdiv_custom_data_sh[dimension][comp_type] = {info_name};
166 }
167 }
168 }
169};
170
171} // namespace draw::Shader
172
173using namespace blender::draw::Shader;
174
179
199
213
218
223
228
233
238
240{
241 BLI_assert(ELEM(element_size, 4, 8, 12, 16));
242 return ShaderCache::get().mesh_gather[element_size / 4 - 1].get();
243}
244
246{
247 BLI_assert(ELEM(element_size, 4, 8, 12, 16));
248 return ShaderCache::get().mesh_scatter_faces[element_size / 4 - 1].get();
249}
250
256
258{
259 BLI_assert(dimensions >= 1 && dimensions <= SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS);
260 if (comp_type == GPU_COMP_U16) {
261 BLI_assert(dimensions == 4);
262 }
264
265 return ShaderCache::get().subdiv_custom_data_sh[dimensions - 1][comp_type].get();
266}
267
272
278
279} // namespace blender
#define BLI_assert_unreachable()
#define ELEM(...)
constexpr IndexRange()=default
constexpr const char * c_str() const
gpu::StaticShader draw_resource_finalize
gpu::StaticShader draw_visibility_compute
gpu::StaticShader draw_command_generate
gpu::StaticShader curves_evaluate_length_intercept
gpu::StaticShader gsplat_compute_radiance
gpu::StaticShader subdiv_sh[SUBDIVISION_MAX_SHADERS]
gpu::StaticShader curves_evaluate_float
gpu::StaticShader curves_evaluate_float2
gpu::StaticShader subdiv_interp_corner_normals_sh
gpu::StaticShader curves_evaluate_float3
gpu::StaticShader gsplat_compute_ellipses_radiance
gpu::StaticShader curves_evaluate_position
gpu::StaticShader curves_evaluate_float4
gpu::StaticShader gsplat_compute_ellipses
gpu::StaticShader mesh_scatter_faces[4]
gpu::StaticShader subdiv_custom_data_sh[SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS][GPU_COMP_MAX]
#define SHADER_CUSTOM_DATA_INTERP_MAX_DIMENSIONS
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
unsigned int uint
Definition BKE_text.h:55
gpu::Shader * DRW_shader_debug_draw_display_get()
gpu::Shader * DRW_shader_gsplat_compute_get(draw::GSplatEvalShader type)
gpu::Shader * DRW_shader_mesh_scatter_faces_get(const int element_size)
gpu::Shader * DRW_shader_draw_command_generate_get()
gpu::Shader * DRW_shader_draw_resource_finalize_get()
gpu::Shader * DRW_shader_mesh_gather_get(const int element_size)
void DRW_shaders_free()
void GPU_shader_unbind()
gpu::Shader * DRW_shader_subdiv_interp_corner_normals_get()
gpu::Shader * DRW_shader_draw_visibility_compute_get()
gpu::Shader * DRW_shader_subdiv_custom_data_get(GPUVertCompType comp_type, int dimensions)
gpu::Shader * DRW_shader_draw_view_finalize_get()
gpu::Shader * DRW_shader_curves_topology_get()
static StringRefNull get_subdiv_shader_info_name(SubdivShaderType shader_type)
constexpr int SUBDIVISION_MAX_SHADERS
gpu::Shader * DRW_shader_subdiv_get(SubdivShaderType shader_type)
gpu::Shader * DRW_shader_curves_refine_get(draw::CurvesEvalShader type)