30using namespace blender::gpu;
38 std::fill_n(batch->verts,
ARRAY_SIZE(batch->verts),
nullptr);
39 batch->elem =
nullptr;
42 batch->shader =
nullptr;
43 batch->procedural_vertices = -1;
74 batch->verts[0] = vertex_buf;
76 batch->verts[
v] =
nullptr;
78 batch->elem = index_buf;
79 batch->prim_type = primitive_type;
81 batch->shader =
nullptr;
82 batch->procedural_vertices = -1;
89 for (
auto &
v : batch->verts) {
92 batch->elem =
nullptr;
93 batch->prim_type = primitive_type;
95 batch->shader =
nullptr;
96 batch->procedural_vertices = vertex_count;
106 batch_dst->prim_type = batch_src->prim_type;
108 batch_dst->verts[
v] = batch_src->verts[
v];
110 batch_dst->procedural_vertices = batch_src->procedural_vertices;
126 batch->procedural_vertices = -1;
149 batch->elem = index_buf;
160 if (batch->verts[
v] ==
nullptr) {
162 if (batch->verts[0] !=
nullptr) {
166 batch->verts[
v] = vertex_buf;
179 if (batch->verts[
v] == vertex_buf) {
211 char uniform_name[] =
"gpu_attr_0";
212 uint stride = format->stride;
215 for (
uint a_idx = 0; a_idx < format->attr_len; a_idx++) {
218 if (format->deinterleaved) {
219 offset += ((a_idx == 0) ? 0 : format->attrs[a_idx - 1].type.size()) * vbo->
vertex_len;
229 if (input ==
nullptr || input->
location == -1) {
233 bound_attr |= (1 << input->
location);
237 uniform_name[9] =
'0' + input->
location;
242 int descriptor[2] = {int(stride) / 4, int(offset) / 4};
246 char uniform_name_len[] =
"gpu_attr_0_len";
247 uniform_name_len[9] =
'0' + input->
location;
263 if (interface->ssbo_attr_mask_ == 0) {
267 uint16_t ssbo_attributes = interface->ssbo_attr_mask_;
294 BLI_assert_msg(ssbo_attributes == 0,
"Not all attribute storage buffer fulfilled");
308 int *r_instance_count)
310 if (batch->procedural_vertices >= 0) {
311 *r_vertex_count = batch->procedural_vertices;
315 else if (batch->elem) {
316 *r_vertex_count = batch->elem_()->index_len_get();
317 *r_vertex_first = batch->elem_()->index_start_get();
318 *r_base_index = batch->elem_()->index_base_get();
321 *r_vertex_count = batch->verts_(0)->vertex_len;
326 *r_instance_count = 1;
333 int output_primitive_cout)
338 int prim_first = vertex_first / vert_per_original_primitive;
339 int prim_len = vertex_count / vert_per_original_primitive;
342 "Primitive expansion only works for primitives with known amount of vertices");
346 prim_len = vertex_count - 1;
349 int out_vertex_first = prim_first * vert_per_expanded_primitive * output_primitive_cout;
350 int out_vertex_count = prim_len * vert_per_expanded_primitive * output_primitive_cout;
352 return IndexRange(out_vertex_first, out_vertex_count);
356 Batch *batch,
int vertex_first,
int vertex_count,
int instance_first,
int instance_count)
359 if (vertex_count == 0) {
367 batch->prim_type,
GPU_PRIM_TRIS, vertex_count, vertex_first, 2);
371 int vert_stride_count[3] = {(batch->prim_type ==
GPU_PRIM_LINES) ? 2 : 1, vertex_count, 0};
382 const bool is_unorm8 = attr.
type.
format == gpu::VertAttrType::UNORM_8_8_8_8;
384 "color attribute for polylines can only use GPU_FETCH_INT_TO_FLOAT_UNIT or "
396 if (batch->shader->is_polyline) {
408 if (batch->shader->is_polyline) {
420 BLI_assert(batch->shader->is_polyline ==
false);
427 Batch *batch,
int vertex_first,
int vertex_count,
int instance_first,
int instance_count)
433 if (vertex_count == 0) {
434 if (batch->procedural_vertices > 0) {
435 vertex_count = batch->procedural_vertices;
437 else if (batch->elem) {
438 vertex_count = batch->elem_()->index_len_get();
441 vertex_count = batch->verts_(0)->vertex_len;
444 if (instance_count == 0) {
448 if (vertex_count == 0 || instance_count == 0) {
457 batch->draw(vertex_first, vertex_count, instance_first, instance_count);
471 batch->draw_indirect(indirect_buf, offset);
486 batch->multi_draw_indirect(indirect_buf, count, offset, stride);
#define GPU_VERTBUF_DISCARD_SAFE(verts)
#define UNUSED_VARS_NDEBUG(...)
#define SET_FLAG_FROM_TEST(value, test, flag)
#define BLI_assert_msg(a, msg)
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr int64_t start() const
Batch * procedural_triangles_batch_get()
void assert_framebuffer_shader_compatibility(Shader *sh)
Batch * procedural_triangle_strips_batch_get()
Batch * procedural_lines_batch_get()
Batch * procedural_points_batch_get()
virtual Batch * batch_alloc()=0
static GPUBackend * get()
const ShaderInput * ssbo_get(const StringRefNull name) const
#define GPU_SSBO_INDEX_BUF_SLOT
int indices_per_primitive(GPUPrimType prim_type)
void debug_validate_binding_image_format()
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void GPU_batch_draw_indirect(gpu::Batch *batch, gpu::StorageBuf *indirect_buf, intptr_t offset)
void GPU_shader_uniform_2iv(gpu::Shader *sh, const char *name, const int data[2])
gpu::Batch * GPU_batch_create_procedural(GPUPrimType primitive_type, int32_t vertex_count)
gpu::Batch * GPU_batch_create_ex(GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
gpu::Batch * GPU_batch_calloc()
void GPU_batch_bind_as_resources(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants=nullptr)
void GPU_batch_program_set_builtin_with_config(gpu::Batch *batch, GPUBuiltinShader shader_id, GPUShaderConfig sh_cfg)
int GPU_vertformat_attr_id_get(const GPUVertFormat *, StringRef name)
gpu::Batch * GPU_batch_procedural_points_get()
BLI_INLINE const char * GPU_vertformat_attr_name_get(const GPUVertFormat *format, const GPUVertAttr *attr, uint n_idx)
static constexpr int GPU_BATCH_VBO_MAX_LEN
void GPU_batch_discard(gpu::Batch *batch)
void GPU_shader_uniform_3iv(gpu::Shader *sh, const char *name, const int data[3])
ATTR_WARN_UNUSED_RESULT const BMVert * v
void GPU_batch_set_shader(gpu::Batch *batch, gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
const GPUVertFormat * GPU_vertbuf_get_format(const gpu::VertBuf *verts)
void GPU_shader_uniform_int_ex(gpu::Shader *shader, int location, int length, int array_size, const int *value)
void GPU_shader_uniform_1b(gpu::Shader *sh, const char *name, bool value)
void GPU_vertbuf_bind_as_ssbo(gpu::VertBuf *verts, int binding)
void GPU_batch_draw_range(gpu::Batch *batch, int vertex_first, int vertex_count)
void GPU_indexbuf_bind_as_ssbo(gpu::IndexBuf *elem, int binding)
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)
void GPU_batch_copy(gpu::Batch *batch_dst, gpu::Batch *batch_src)
BMesh const char void * data
void GPU_batch_init_ex(gpu::Batch *batch, GPUPrimType primitive_type, gpu::VertBuf *vertex_buf, gpu::IndexBuf *index_buf, GPUBatchFlag owns_flag)
gpu::Batch * GPU_batch_procedural_triangle_strips_get()
void GPU_batch_draw_instance_range(gpu::Batch *batch, int instance_first, int instance_count)
void GPU_batch_zero(gpu::Batch *batch)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
void gpu_batch_presets_init()
void GPU_batch_program_set_imm_shader(gpu::Batch *batch)
void GPU_batch_draw(gpu::Batch *batch)
void GPU_batch_multi_draw_indirect(gpu::Batch *batch, gpu::StorageBuf *indirect_buf, int count, intptr_t offset, intptr_t stride)
static void polyline_draw_workaround(Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
void GPU_shader_bind(gpu::Shader *shader, const gpu::shader::SpecializationConstants *constants_state=nullptr)
void GPU_shader_uniform_1i(gpu::Shader *sh, const char *name, int value)
void GPU_batch_clear(gpu::Batch *batch)
void GPU_batch_program_set_builtin(gpu::Batch *batch, GPUBuiltinShader shader_id)
int GPU_shader_get_uniform(gpu::Shader *shader, const char *name)
gpu::Batch * GPU_batch_procedural_triangles_get()
gpu::Shader * immGetShader()
bool GPU_batch_vertbuf_has(const gpu::Batch *batch, const gpu::VertBuf *vertex_buf)
void GPU_indexbuf_discard(gpu::IndexBuf *elem)
void gpu_batch_presets_exit()
void GPU_batch_draw_advanced(gpu::Batch *batch, int vertex_first, int vertex_count, int instance_first, int instance_count)
gpu::Shader * GPU_shader_get_builtin_shader_with_config(GPUBuiltinShader shader, GPUShaderConfig sh_cfg)
void GPU_batch_elembuf_set(gpu::Batch *batch, gpu::IndexBuf *index_buf, bool own_ibo)
void GPU_batch_draw_parameter_get(gpu::Batch *batch, int *r_vertex_count, int *r_vertex_first, int *r_base_index, int *r_instance_count)
int GPU_batch_vertbuf_add(gpu::Batch *batch, gpu::VertBuf *vertex_buf, bool own_vbo)
gpu::Batch * GPU_batch_procedural_lines_get()
static uint16_t bind_attribute_as_ssbo(const ShaderInterface *interface, gpu::Shader *shader, VertBuf *vbo)
GPUVertFetchMode fetch_mode() const
struct blender::GPUVertAttr::Type type