42 batch->elem =
nullptr;
43 batch->resource_id_buf =
nullptr;
46 batch->shader =
nullptr;
77 batch->verts[0] = vertex_buf;
81 for (
auto &
v :
batch->inst) {
84 batch->elem = index_buf;
85 batch->prim_type = primitive_type;
87 batch->shader =
nullptr;
96 batch_dst->prim_type = batch_src->prim_type;
98 batch_dst->verts[
v] = batch_src->verts[
v];
144 batch->inst[0] = vertex_buf;
157 batch->elem = index_buf;
168 if (
batch->inst[
v] ==
nullptr) {
170 if (
batch->inst[0]) {
175 batch->inst[
v] = vertex_buf;
191 if (
batch->verts[
v] ==
nullptr) {
193 if (
batch->verts[0] !=
nullptr) {
197 batch->verts[
v] = vertex_buf;
210 if (
batch->verts[
v] == vertex_buf) {
221 batch->resource_id_buf = resource_id_buf;
233 batch->shader = shader;
247 char uniform_name[] =
"gpu_attr_0";
251 for (
uint a_idx = 0; a_idx <
format->attr_len; a_idx++) {
253 for (
uint n_idx = 0; n_idx < a->name_len; n_idx++) {
256 if (input ==
nullptr || input->location == -1) {
260 bound_attr |= (1 << input->location);
264 uniform_name[9] =
'0' + input->location;
266 if (
format->deinterleaved) {
267 offset += ((a_idx == 0) ? 0 :
format->attrs[a_idx - 1].size) * vbo->
vertex_len;
287 if (interface->ssbo_attr_mask_ == 0) {
314 ssbo_attributes &= ~bind_attribute_as_ssbo(interface, shader, vbo);
318 BLI_assert_msg(ssbo_attributes == 0,
"Not all attribute storage buffer fulfilled");
332 int *r_instance_count)
334 Batch *
batch =
static_cast<Batch *
>(gpu_batch);
337 *r_vertex_count =
batch->elem_()->index_len_get();
338 *r_vertex_first =
batch->elem_()->index_start_get();
339 *r_base_index =
batch->elem_()->index_base_get();
342 *r_vertex_count =
batch->verts_(0)->vertex_len;
347 int i_count = (
batch->inst[0]) ?
batch->inst_(0)->vertex_len : 1;
349 if (
batch->inst[1] !=
nullptr) {
350 i_count =
min_ii(i_count,
batch->inst_(1)->vertex_len);
352 *r_instance_count = i_count;
364 "Primitive expansion only works for primitives with known amount of vertices");
366 int prim_first = vertex_first / vert_per_original_primitive;
367 int prim_len = vertex_count / vert_per_original_primitive;
369 int out_vertex_first = prim_first * vert_per_expanded_primitive;
370 int out_vertex_count = prim_len * vert_per_expanded_primitive;
396 Batch *gpu_batch,
int vertex_first,
int vertex_count,
int instance_first,
int instance_count)
399 Batch *
batch =
static_cast<Batch *
>(gpu_batch);
401 if (vertex_count == 0) {
403 vertex_count =
batch->elem_()->index_len_get();
406 vertex_count =
batch->verts_(0)->vertex_len;
409 if (instance_count == 0) {
410 instance_count = (
batch->inst[0]) ?
batch->inst_(0)->vertex_len : 1;
412 if (
batch->inst[1] !=
nullptr) {
413 instance_count =
min_ii(instance_count,
batch->inst_(1)->vertex_len);
417 if (vertex_count == 0 || instance_count == 0) {
422 batch->draw(vertex_first, vertex_count, instance_first, instance_count);
429 Batch *
batch =
static_cast<Batch *
>(gpu_batch);
431 batch->draw_indirect(indirect_buf, offset);
439 Batch *
batch =
static_cast<Batch *
>(gpu_batch);
441 batch->multi_draw_indirect(indirect_buf,
count, offset, stride);
#define BLI_assert_msg(a, msg)
MINLINE int min_ii(int a, int b)
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define GPU_BATCH_INST_VBO_MAX_LEN
#define GPU_BATCH_VBO_MAX_LEN
@ GPU_BATCH_OWNS_INST_VBO
@ GPU_BATCH_OWNS_INST_VBO_ANY
void gpu_batch_presets_init()
void gpu_batch_presets_exit()
void GPU_indexbuf_discard(blender::gpu::IndexBuf *elem)
void GPU_indexbuf_bind_as_ssbo(blender::gpu::IndexBuf *elem, int binding)
void GPU_shader_uniform_1i(GPUShader *sh, const char *name, int value)
void GPU_shader_uniform_2iv(GPUShader *sh, const char *name, const int data[2])
void GPU_shader_bind(GPUShader *shader)
void GPU_shader_uniform_1b(GPUShader *sh, const char *name, bool value)
GPUShader * GPU_shader_get_builtin_shader_with_config(eGPUBuiltinShader shader, eGPUShaderConfig sh_cfg)
#define GPU_VERTBUF_DISCARD_SAFE(verts)
void GPU_vertbuf_bind_as_ssbo(blender::gpu::VertBuf *verts, int binding)
void GPU_vertbuf_discard(blender::gpu::VertBuf *)
Read Guarded memory(de)allocation.
struct GPUShader GPUShader
ATTR_WARN_UNUSED_RESULT const BMVert * v
static GPUBackend * get()
virtual Batch * batch_alloc()=0
const ShaderInput * ssbo_get(const char *name) const
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
void GPU_batch_resource_id_buf_set(Batch *batch, GPUStorageBuf *resource_id_buf)
void GPU_batch_draw_indirect(Batch *gpu_batch, GPUStorageBuf *indirect_buf, intptr_t offset)
void GPU_batch_discard(Batch *batch)
int GPU_batch_instbuf_add(Batch *batch, VertBuf *vertex_buf, bool own_vbo)
Batch * GPU_batch_create_ex(GPUPrimType primitive_type, VertBuf *vertex_buf, IndexBuf *index_buf, eGPUBatchFlag owns_flag)
bool GPU_batch_vertbuf_has(const Batch *batch, const VertBuf *vertex_buf)
void GPU_batch_program_set_imm_shader(Batch *batch)
void GPU_batch_draw(Batch *batch)
void GPU_batch_draw_instance_range(Batch *batch, int instance_first, int instance_count)
static uint16_t bind_attribute_as_ssbo(const ShaderInterface *interface, GPUShader *shader, VertBuf *vbo)
void GPU_batch_draw_parameter_get(Batch *gpu_batch, int *r_vertex_count, int *r_vertex_first, int *r_base_index, int *r_instance_count)
Batch * GPU_batch_calloc()
blender::IndexRange GPU_batch_draw_expanded_parameter_get(const blender::gpu::Batch *batch, GPUPrimType expanded_prim_type, int vertex_count, int vertex_first)
void GPU_batch_draw_range(Batch *batch, int vertex_first, int vertex_count)
int GPU_batch_vertbuf_add(Batch *batch, VertBuf *vertex_buf, bool own_vbo)
void GPU_batch_program_set_builtin(Batch *batch, eGPUBuiltinShader shader_id)
void GPU_batch_init_ex(Batch *batch, GPUPrimType primitive_type, VertBuf *vertex_buf, IndexBuf *index_buf, eGPUBatchFlag owns_flag)
void GPU_batch_set_shader(Batch *batch, GPUShader *shader)
void GPU_batch_bind_as_resources(Batch *batch, GPUShader *shader)
void GPU_batch_instbuf_set(Batch *batch, VertBuf *vertex_buf, bool own_vbo)
void GPU_batch_zero(Batch *batch)
void GPU_batch_draw_advanced(Batch *gpu_batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
void GPU_batch_copy(Batch *batch_dst, Batch *batch_src)
void GPU_batch_program_set_builtin_with_config(Batch *batch, eGPUBuiltinShader shader_id, eGPUShaderConfig sh_cfg)
void GPU_batch_clear(Batch *batch)
void GPU_batch_elembuf_set(Batch *batch, blender::gpu::IndexBuf *index_buf, bool own_ibo)
void GPU_batch_multi_draw_indirect(Batch *gpu_batch, GPUStorageBuf *indirect_buf, int count, intptr_t offset, intptr_t stride)
#define GPU_SSBO_INDEX_BUF_SLOT
int indices_per_primitive(GPUPrimType prim_type)