Blender V5.0
GPU_batch.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
18
19#pragma once
20
21#include "BLI_index_range.hh"
22#include "BLI_utildefines.h"
23
24#include "GPU_index_buffer.hh"
25#include "GPU_shader.hh"
26#include "GPU_storage_buffer.hh"
27#include "GPU_vertex_buffer.hh"
28
29namespace blender::gpu {
30class Shader;
31} // namespace blender::gpu
32
33constexpr static int GPU_BATCH_VBO_MAX_LEN = 16;
34constexpr static int GPU_BATCH_VAO_STATIC_LEN = 3;
35constexpr static int GPU_BATCH_VAO_DYN_ALLOC_COUNT = 16;
36
55
56#define GPU_BATCH_OWNS_NONE GPU_BATCH_INVALID
57
59 "GPUBatchFlag: Error: status flags are shadowed by the ownership bits!")
60
62
63namespace blender::gpu {
64
73class Batch {
74 public:
80 int32_t procedural_vertices;
84 GPUPrimType prim_type;
86 gpu::Shader *shader;
87
88 virtual ~Batch() = default;
89
90 virtual void draw(int v_first, int v_count, int i_first, int i_count) = 0;
91 virtual void draw_indirect(blender::gpu::StorageBuf *indirect_buf, intptr_t offset) = 0;
92 virtual void multi_draw_indirect(blender::gpu::StorageBuf *indirect_buf,
93 int count,
94 intptr_t offset,
95 intptr_t stride) = 0;
96
97 uint32_t vertex_count_get() const
98 {
99 if (elem) {
100 return elem_()->index_len_get();
101 }
102 return verts_(0)->vertex_len;
103 }
104
105 /* Convenience casts. */
106 IndexBuf *elem_() const
107 {
108 return elem;
109 }
110 VertBuf *verts_(const int index) const
111 {
112 return verts[index];
113 }
114};
115
116} // namespace blender::gpu
117
118/* -------------------------------------------------------------------- */
121
126blender::gpu::Batch *GPU_batch_calloc();
127
131blender::gpu::Batch *GPU_batch_create_ex(GPUPrimType primitive_type,
132 blender::gpu::VertBuf *vertex_buf,
133 blender::gpu::IndexBuf *index_buf,
134 GPUBatchFlag owns_flag);
135
136blender::gpu::Batch *GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count);
137
141#define GPU_batch_create(primitive_type, vertex_buf, index_buf) \
142 GPU_batch_create_ex(primitive_type, vertex_buf, index_buf, (GPUBatchFlag)0)
143
149void GPU_batch_init_ex(blender::gpu::Batch *batch,
150 GPUPrimType primitive_type,
151 blender::gpu::VertBuf *vertex_buf,
152 blender::gpu::IndexBuf *index_buf,
153 GPUBatchFlag owns_flag);
159#define GPU_batch_init(batch, primitive_type, vertex_buf, index_buf) \
160 GPU_batch_init_ex(batch, primitive_type, vertex_buf, index_buf, (GPUBatchFlag)0)
161
166void GPU_batch_copy(blender::gpu::Batch *batch_dst, blender::gpu::Batch *batch_src);
167
169
170/* -------------------------------------------------------------------- */
173
179void GPU_batch_clear(blender::gpu::Batch *batch);
180
181void GPU_batch_zero(blender::gpu::Batch *batch);
182
183#define GPU_BATCH_CLEAR_SAFE(batch) \
184 do { \
185 if (batch != nullptr) { \
186 GPU_batch_clear(batch); \
187 GPU_batch_zero(batch); \
188 } \
189 } while (0)
190
195void GPU_batch_discard(blender::gpu::Batch *batch);
196
197#define GPU_BATCH_DISCARD_SAFE(batch) \
198 do { \
199 if (batch != nullptr) { \
200 GPU_batch_discard(batch); \
201 batch = nullptr; \
202 } \
203 } while (0)
204
206
207/* -------------------------------------------------------------------- */
210
215int GPU_batch_vertbuf_add(blender::gpu::Batch *batch,
216 blender::gpu::VertBuf *vertex_buf,
217 bool own_vbo);
218
223void GPU_batch_elembuf_set(blender::gpu::Batch *batch,
224 blender::gpu::IndexBuf *index_buf,
225 bool own_ibo);
226
231bool GPU_batch_vertbuf_has(const blender::gpu::Batch *batch,
232 const blender::gpu::VertBuf *vertex_buf);
233
235
236/* -------------------------------------------------------------------- */
243
248/* TODO(fclem): These should be removed and replaced by `GPU_shader_bind()`. */
250 blender::gpu::Batch *batch,
251 blender::gpu::Shader *shader,
252 const blender::gpu::shader::SpecializationConstants *constants_state = nullptr);
253void GPU_batch_program_set_builtin(blender::gpu::Batch *batch, GPUBuiltinShader shader_id);
255 GPUBuiltinShader shader_id,
256 GPUShaderConfig sh_cfg);
263void GPU_batch_program_set_imm_shader(blender::gpu::Batch *batch);
264
268/* TODO(fclem): These need to be replaced by GPU_shader_uniform_* with explicit shader. */
269#define GPU_batch_uniform_1i(batch, name, x) GPU_shader_uniform_1i((batch)->shader, name, x);
270#define GPU_batch_uniform_1b(batch, name, x) GPU_shader_uniform_1b((batch)->shader, name, x);
271#define GPU_batch_uniform_1f(batch, name, x) GPU_shader_uniform_1f((batch)->shader, name, x);
272#define GPU_batch_uniform_2f(batch, name, x, y) GPU_shader_uniform_2f((batch)->shader, name, x, y);
273#define GPU_batch_uniform_3f(batch, name, x, y, z) \
274 GPU_shader_uniform_3f((batch)->shader, name, x, y, z);
275#define GPU_batch_uniform_4f(batch, name, x, y, z, w) \
276 GPU_shader_uniform_4f((batch)->shader, name, x, y, z, w);
277#define GPU_batch_uniform_2fv(batch, name, val) GPU_shader_uniform_2fv((batch)->shader, name, val);
278#define GPU_batch_uniform_3fv(batch, name, val) GPU_shader_uniform_3fv((batch)->shader, name, val);
279#define GPU_batch_uniform_4fv(batch, name, val) GPU_shader_uniform_4fv((batch)->shader, name, val);
280#define GPU_batch_uniform_2fv_array(batch, name, len, val) \
281 GPU_shader_uniform_2fv_array((batch)->shader, name, len, val);
282#define GPU_batch_uniform_4fv_array(batch, name, len, val) \
283 GPU_shader_uniform_4fv_array((batch)->shader, name, len, val);
284#define GPU_batch_uniform_mat4(batch, name, val) \
285 GPU_shader_uniform_mat4((batch)->shader, name, val);
286#define GPU_batch_uniformbuf_bind(batch, name, ubo) \
287 GPU_uniformbuf_bind(ubo, GPU_shader_get_ubo_binding((batch)->shader, name));
288#define GPU_batch_texture_bind(batch, name, tex) \
289 GPU_texture_bind(tex, GPU_shader_get_sampler_binding((batch)->shader, name));
290
295 blender::gpu::Batch *batch,
296 blender::gpu::Shader *shader,
297 const blender::gpu::shader::SpecializationConstants *constants = nullptr);
298
300
301/* -------------------------------------------------------------------- */
304
309void GPU_batch_draw(blender::gpu::Batch *batch);
310
322void GPU_batch_draw_range(blender::gpu::Batch *batch, int vertex_first, int vertex_count);
323
336void GPU_batch_draw_instance_range(blender::gpu::Batch *batch,
337 int instance_first,
338 int instance_count);
339
351void GPU_batch_draw_advanced(blender::gpu::Batch *batch,
352 int vertex_first,
353 int vertex_count,
354 int instance_first,
355 int instance_count);
356
368void GPU_batch_draw_indirect(blender::gpu::Batch *batch,
369 blender::gpu::StorageBuf *indirect_buf,
370 intptr_t offset);
371
384void GPU_batch_multi_draw_indirect(blender::gpu::Batch *batch,
385 blender::gpu::StorageBuf *indirect_buf,
386 int count,
387 intptr_t offset,
388 intptr_t stride);
389
394void GPU_batch_draw_parameter_get(blender::gpu::Batch *batch,
395 int *r_vertex_count,
396 int *r_vertex_first,
397 int *r_base_index,
398 int *r_instance_count);
399
404 GPUPrimType output_prim_type,
405 int vertex_count,
406 int vertex_first,
407 int output_primitive_cout);
408
410
411/* -------------------------------------------------------------------- */
418
423blender::gpu::Batch *GPU_batch_procedural_points_get();
424
429blender::gpu::Batch *GPU_batch_procedural_lines_get();
430
435blender::gpu::Batch *GPU_batch_procedural_triangles_get();
436
441blender::gpu::Batch *GPU_batch_procedural_triangle_strips_get();
442
444
445/* -------------------------------------------------------------------- */
448
449void gpu_batch_init();
450void gpu_batch_exit();
451
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
#define ENUM_OPERATORS(_type, _max)
void GPU_batch_elembuf_set(blender::gpu::Batch *batch, blender::gpu::IndexBuf *index_buf, bool own_ibo)
static constexpr int GPU_BATCH_VBO_MAX_LEN
Definition GPU_batch.hh:33
void GPU_batch_multi_draw_indirect(blender::gpu::Batch *batch, blender::gpu::StorageBuf *indirect_buf, int count, intptr_t offset, intptr_t stride)
blender::gpu::Batch * GPU_batch_procedural_triangle_strips_get()
Definition gpu_batch.cc:525
void GPU_batch_discard(blender::gpu::Batch *batch)
void GPU_batch_zero(blender::gpu::Batch *batch)
void GPU_batch_program_set_builtin_with_config(blender::gpu::Batch *batch, GPUBuiltinShader shader_id, GPUShaderConfig sh_cfg)
blender::gpu::Batch * GPU_batch_procedural_lines_get()
Definition gpu_batch.cc:515
void GPU_batch_draw_advanced(blender::gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
blender::IndexRange GPU_batch_draw_expanded_parameter_get(GPUPrimType input_prim_type, GPUPrimType output_prim_type, int vertex_count, int vertex_first, int output_primitive_cout)
Definition gpu_batch.cc:323
void GPU_batch_draw_instance_range(blender::gpu::Batch *batch, int instance_first, int instance_count)
static constexpr int GPU_BATCH_VAO_STATIC_LEN
Definition GPU_batch.hh:34
static constexpr int GPU_BATCH_VAO_DYN_ALLOC_COUNT
Definition GPU_batch.hh:35
blender::gpu::Batch * GPU_batch_procedural_points_get()
Definition gpu_batch.cc:510
void GPU_batch_init_ex(blender::gpu::Batch *batch, GPUPrimType primitive_type, blender::gpu::VertBuf *vertex_buf, blender::gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
void GPU_batch_program_set_imm_shader(blender::gpu::Batch *batch)
void GPU_batch_program_set_builtin(blender::gpu::Batch *batch, GPUBuiltinShader shader_id)
void GPU_batch_clear(blender::gpu::Batch *batch)
int GPU_batch_vertbuf_add(blender::gpu::Batch *batch, blender::gpu::VertBuf *vertex_buf, bool own_vbo)
blender::gpu::Batch * GPU_batch_procedural_triangles_get()
Definition gpu_batch.cc:520
void gpu_batch_init()
Definition gpu_batch.cc:536
blender::gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, blender::gpu::VertBuf *vertex_buf, blender::gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
Definition gpu_batch.cc:51
void GPU_batch_draw_indirect(blender::gpu::Batch *batch, blender::gpu::StorageBuf *indirect_buf, intptr_t offset)
GPUBatchFlag
Definition GPU_batch.hh:37
@ GPU_BATCH_INVALID
Definition GPU_batch.hh:39
@ GPU_BATCH_DIRTY
Definition GPU_batch.hh:53
@ GPU_BATCH_INIT
Definition GPU_batch.hh:49
@ GPU_BATCH_OWNS_INDEX
Definition GPU_batch.hh:46
@ GPU_BATCH_OWNS_VBO
Definition GPU_batch.hh:42
@ GPU_BATCH_OWNS_VBO_ANY
Definition GPU_batch.hh:44
@ GPU_BATCH_OWNS_VBO_MAX
Definition GPU_batch.hh:43
@ GPU_BATCH_BUILDING
Definition GPU_batch.hh:51
void GPU_batch_draw(blender::gpu::Batch *batch)
void GPU_batch_copy(blender::gpu::Batch *batch_dst, blender::gpu::Batch *batch_src)
blender::gpu::Batch * GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count)
Definition gpu_batch.cc:83
void GPU_batch_draw_range(blender::gpu::Batch *batch, int vertex_first, int vertex_count)
bool GPU_batch_vertbuf_has(const blender::gpu::Batch *batch, const blender::gpu::VertBuf *vertex_buf)
void GPU_batch_bind_as_resources(blender::gpu::Batch *batch, blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants=nullptr)
void GPU_batch_draw_parameter_get(blender::gpu::Batch *batch, int *r_vertex_count, int *r_vertex_first, int *r_base_index, int *r_instance_count)
void GPU_batch_set_shader(blender::gpu::Batch *batch, blender::gpu::Shader *shader, const blender::gpu::shader::SpecializationConstants *constants_state=nullptr)
void gpu_batch_exit()
Definition gpu_batch.cc:541
GPUPrimType
GPUBuiltinShader
static float verts[][3]
Batch * GPU_batch_calloc()
Definition gpu_batch.cc:44
struct @021025263243242147216143265077100330027142264337::@225245033123204053237120173316075113304004012000 batch
int count
uint8_t flag
Definition wm_window.cc:145