2023-05-31 16:19:06 +02:00
|
|
|
/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2016-09-13 08:41:43 +02:00
|
|
|
|
2019-02-17 22:08:12 +01:00
|
|
|
/** \file
|
|
|
|
* \ingroup gpu
|
2018-07-17 21:11:23 +02:00
|
|
|
*
|
2023-02-09 21:37:23 +01:00
|
|
|
* GPU geometry batch.
|
|
|
|
*
|
|
|
|
* Contains Vertex Buffers, Index Buffers, and Shader reference, altogether representing a drawable
|
|
|
|
* entity. It is meant to be used for drawing large (> 1000 vertices) reusable (drawn multiple
|
|
|
|
* times) model with complex data layout. In other words, it is meant for all cases where the
|
|
|
|
* immediate drawing module (imm) is inadequate.
|
|
|
|
*
|
|
|
|
* Vertex & Index Buffers can be owned by a batch. In such case they will be freed when the batch
|
|
|
|
* gets cleared or discarded.
|
2016-09-13 08:41:43 +02:00
|
|
|
*/
|
|
|
|
|
2018-07-18 00:12:21 +02:00
|
|
|
#pragma once
|
2016-09-13 08:41:43 +02:00
|
|
|
|
2020-08-10 03:17:35 +02:00
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_index_buffer.hh"
|
|
|
|
#include "GPU_shader.hh"
|
|
|
|
#include "GPU_storage_buffer.hh"
|
2024-02-11 22:10:00 +01:00
|
|
|
#include "GPU_uniform_buffer.hh"
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_vertex_buffer.hh"
|
|
|
|
|
|
|
|
struct GPUShader;
|
2017-03-17 04:32:35 +01:00
|
|
|
|
2021-10-26 23:16:33 +02:00
|
|
|
#define GPU_BATCH_VBO_MAX_LEN 16
|
2019-12-02 01:40:58 +01:00
|
|
|
#define GPU_BATCH_INST_VBO_MAX_LEN 2
|
2018-07-18 00:12:21 +02:00
|
|
|
#define GPU_BATCH_VAO_STATIC_LEN 3
|
|
|
|
#define GPU_BATCH_VAO_DYN_ALLOC_COUNT 16
|
2018-01-15 14:06:39 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
enum eGPUBatchFlag {
|
2020-08-10 03:17:35 +02:00
|
|
|
/** Invalid default state. */
|
|
|
|
GPU_BATCH_INVALID = 0,
|
|
|
|
|
2024-03-24 16:38:30 +01:00
|
|
|
/** blender::gpu::VertBuf ownership. (One bit per vbo) */
|
2020-08-10 03:17:35 +02:00
|
|
|
GPU_BATCH_OWNS_VBO = (1 << 0),
|
|
|
|
GPU_BATCH_OWNS_VBO_MAX = (GPU_BATCH_OWNS_VBO << (GPU_BATCH_VBO_MAX_LEN - 1)),
|
|
|
|
GPU_BATCH_OWNS_VBO_ANY = ((GPU_BATCH_OWNS_VBO << GPU_BATCH_VBO_MAX_LEN) - 1),
|
2024-03-24 16:38:30 +01:00
|
|
|
/** Instance blender::gpu::VertBuf ownership. (One bit per vbo) */
|
2020-08-10 03:17:35 +02:00
|
|
|
GPU_BATCH_OWNS_INST_VBO = (GPU_BATCH_OWNS_VBO_MAX << 1),
|
|
|
|
GPU_BATCH_OWNS_INST_VBO_MAX = (GPU_BATCH_OWNS_INST_VBO << (GPU_BATCH_INST_VBO_MAX_LEN - 1)),
|
|
|
|
GPU_BATCH_OWNS_INST_VBO_ANY = ((GPU_BATCH_OWNS_INST_VBO << GPU_BATCH_INST_VBO_MAX_LEN) - 1) &
|
|
|
|
~GPU_BATCH_OWNS_VBO_ANY,
|
2024-03-24 16:38:30 +01:00
|
|
|
/** blender::gpu::IndexBuf ownership. */
|
2020-08-10 03:17:35 +02:00
|
|
|
GPU_BATCH_OWNS_INDEX = (GPU_BATCH_OWNS_INST_VBO_MAX << 1),
|
|
|
|
|
|
|
|
/** Has been initialized. At least one VBO is set. */
|
2021-10-26 23:16:33 +02:00
|
|
|
GPU_BATCH_INIT = (1 << 26),
|
2020-08-10 03:17:35 +02:00
|
|
|
/** Batch is initialized but its VBOs are still being populated. (optional) */
|
2021-10-26 23:16:33 +02:00
|
|
|
GPU_BATCH_BUILDING = (1 << 26),
|
2020-08-10 03:17:35 +02:00
|
|
|
/** Cached data need to be rebuild. (VAO, PSO, ...) */
|
2021-10-26 23:16:33 +02:00
|
|
|
GPU_BATCH_DIRTY = (1 << 27),
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2020-08-10 03:17:35 +02:00
|
|
|
|
|
|
|
#define GPU_BATCH_OWNS_NONE GPU_BATCH_INVALID
|
|
|
|
|
|
|
|
BLI_STATIC_ASSERT(GPU_BATCH_OWNS_INDEX < GPU_BATCH_INIT,
|
|
|
|
"eGPUBatchFlag: Error: status flags are shadowed by the ownership bits!")
|
|
|
|
|
2020-10-01 20:21:01 +02:00
|
|
|
ENUM_OPERATORS(eGPUBatchFlag, GPU_BATCH_DIRTY)
|
2020-08-10 03:17:35 +02:00
|
|
|
|
2024-03-26 03:06:25 +01:00
|
|
|
namespace blender::gpu {
|
|
|
|
|
2020-08-10 03:17:35 +02:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Base class which is then specialized for each implementation (GL, VK, ...).
|
|
|
|
* TODO(fclem): Make the content of this struct hidden and expose getters/setters.
|
|
|
|
*
|
|
|
|
* Do not allocate manually as the real struct is bigger (i.e: GLBatch). This is only
|
2023-02-09 21:37:23 +01:00
|
|
|
* the common and "public" part of the struct. Use `GPU_batch_calloc()` and `GPU_batch_create()`
|
|
|
|
* instead.
|
2021-01-04 02:00:18 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
class Batch {
|
|
|
|
public:
|
2024-03-23 01:24:18 +01:00
|
|
|
/** verts[0] is required, others can be nullptr */
|
2024-03-24 16:38:30 +01:00
|
|
|
blender::gpu::VertBuf *verts[GPU_BATCH_VBO_MAX_LEN];
|
2019-01-28 21:46:25 +01:00
|
|
|
/** Instance attributes. */
|
2024-03-24 16:38:30 +01:00
|
|
|
blender::gpu::VertBuf *inst[GPU_BATCH_INST_VBO_MAX_LEN];
|
2024-03-23 01:24:18 +01:00
|
|
|
/** nullptr if element list not needed */
|
2024-03-24 16:38:30 +01:00
|
|
|
blender::gpu::IndexBuf *elem;
|
2022-09-02 18:30:48 +02:00
|
|
|
/** Resource ID attribute workaround. */
|
|
|
|
GPUStorageBuf *resource_id_buf;
|
2021-02-05 06:23:34 +01:00
|
|
|
/** Bookkeeping. */
|
2020-08-10 03:17:35 +02:00
|
|
|
eGPUBatchFlag flag;
|
|
|
|
/** Type of geometry to draw. */
|
2020-08-08 23:37:43 +02:00
|
|
|
GPUPrimType prim_type;
|
2020-08-11 01:31:40 +02:00
|
|
|
/** Current assigned shader. DEPRECATED. Here only for uniform binding. */
|
2024-03-23 01:24:18 +01:00
|
|
|
GPUShader *shader;
|
2024-03-26 03:06:25 +01:00
|
|
|
|
|
|
|
virtual ~Batch() = default;
|
|
|
|
|
|
|
|
virtual void draw(int v_first, int v_count, int i_first, int i_count) = 0;
|
|
|
|
virtual void draw_indirect(GPUStorageBuf *indirect_buf, intptr_t offset) = 0;
|
|
|
|
virtual void multi_draw_indirect(GPUStorageBuf *indirect_buf,
|
|
|
|
int count,
|
|
|
|
intptr_t offset,
|
|
|
|
intptr_t stride) = 0;
|
|
|
|
|
|
|
|
/* Convenience casts. */
|
|
|
|
IndexBuf *elem_() const
|
|
|
|
{
|
|
|
|
return elem;
|
|
|
|
}
|
|
|
|
VertBuf *verts_(const int index) const
|
|
|
|
{
|
|
|
|
return verts[index];
|
|
|
|
}
|
|
|
|
VertBuf *inst_(const int index) const
|
|
|
|
{
|
|
|
|
return inst[index];
|
|
|
|
}
|
2024-03-23 01:24:18 +01:00
|
|
|
};
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2024-03-26 03:06:25 +01:00
|
|
|
} // namespace blender::gpu
|
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Creation
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Allocate a #blender::gpu::Batch with a cleared state.
|
|
|
|
* The returned #blender::gpu::Batch needs to be passed to `GPU_batch_init` before being usable.
|
2023-02-09 21:37:23 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
blender::gpu::Batch *GPU_batch_calloc();
|
2023-02-09 21:37:23 +01:00
|
|
|
|
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Creates a #blender::gpu::Batch with explicit buffer ownership.
|
2023-02-09 21:37:23 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
blender::gpu::Batch *GPU_batch_create_ex(GPUPrimType primitive_type,
|
|
|
|
blender::gpu::VertBuf *vertex_buf,
|
|
|
|
blender::gpu::IndexBuf *index_buf,
|
|
|
|
eGPUBatchFlag owns_flag);
|
2023-02-09 21:37:23 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Creates a #blender::gpu::Batch without buffer ownership.
|
2023-02-09 21:37:23 +01:00
|
|
|
*/
|
|
|
|
#define GPU_batch_create(primitive_type, vertex_buf, index_buf) \
|
|
|
|
GPU_batch_create_ex(primitive_type, vertex_buf, index_buf, (eGPUBatchFlag)0)
|
|
|
|
|
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Initialize a cleared #blender::gpu::Batch with explicit buffer ownership.
|
|
|
|
* A #blender::gpu::Batch is in cleared state if it was just allocated using `GPU_batch_calloc()`
|
|
|
|
* or cleared using `GPU_batch_clear()`.
|
2023-02-09 21:37:23 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_init_ex(blender::gpu::Batch *batch,
|
2023-02-09 21:37:23 +01:00
|
|
|
GPUPrimType primitive_type,
|
2024-03-24 16:38:30 +01:00
|
|
|
blender::gpu::VertBuf *vertex_buf,
|
|
|
|
blender::gpu::IndexBuf *index_buf,
|
2020-09-04 20:59:13 +02:00
|
|
|
eGPUBatchFlag owns_flag);
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Initialize a cleared #blender::gpu::Batch without buffer ownership.
|
|
|
|
* A #blender::gpu::Batch is in cleared state if it was just allocated using `GPU_batch_calloc()`
|
|
|
|
* or cleared using `GPU_batch_clear()`.
|
2023-02-09 21:37:23 +01:00
|
|
|
*/
|
|
|
|
#define GPU_batch_init(batch, primitive_type, vertex_buf, index_buf) \
|
|
|
|
GPU_batch_init_ex(batch, primitive_type, vertex_buf, index_buf, (eGPUBatchFlag)0)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DEPRECATED: It is easy to loose ownership with this. To be removed.
|
2021-12-09 10:01:47 +01:00
|
|
|
* This will share the VBOs with the new batch.
|
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_copy(blender::gpu::Batch *batch_dst, blender::gpu::Batch *batch_src);
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Deletion
|
|
|
|
* \{ */
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Clear a #blender::gpu::Batch without freeing its own memory.
|
|
|
|
* The #blender::gpu::Batch can then be reused using `GPU_batch_init()`.
|
2023-02-09 21:37:23 +01:00
|
|
|
* Discards all owned vertex and index buffers.
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_clear(blender::gpu::Batch *batch);
|
|
|
|
|
|
|
|
void GPU_batch_zero(blender::gpu::Batch *batch);
|
2023-02-09 21:37:23 +01:00
|
|
|
|
|
|
|
#define GPU_BATCH_CLEAR_SAFE(batch) \
|
|
|
|
do { \
|
2024-03-23 01:24:18 +01:00
|
|
|
if (batch != nullptr) { \
|
2023-02-09 21:37:23 +01:00
|
|
|
GPU_batch_clear(batch); \
|
2024-03-26 03:06:25 +01:00
|
|
|
GPU_batch_zero(batch); \
|
2023-02-09 21:37:23 +01:00
|
|
|
} \
|
|
|
|
} while (0)
|
2019-08-14 15:29:46 +02:00
|
|
|
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Free a #blender::gpu::Batch object.
|
2023-02-09 21:37:23 +01:00
|
|
|
* Discards all owned vertex and index buffers.
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_discard(blender::gpu::Batch *batch);
|
2023-02-09 21:37:23 +01:00
|
|
|
|
|
|
|
#define GPU_BATCH_DISCARD_SAFE(batch) \
|
|
|
|
do { \
|
2024-03-23 01:24:18 +01:00
|
|
|
if (batch != nullptr) { \
|
2023-02-09 21:37:23 +01:00
|
|
|
GPU_batch_discard(batch); \
|
2024-03-23 01:24:18 +01:00
|
|
|
batch = nullptr; \
|
2023-02-09 21:37:23 +01:00
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Buffers Management
|
|
|
|
* \{ */
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Add the given \a vertex_buf as vertex buffer to a #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
* \return the index of verts in the batch.
|
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
int GPU_batch_vertbuf_add(blender::gpu::Batch *batch,
|
|
|
|
blender::gpu::VertBuf *vertex_buf,
|
|
|
|
bool own_vbo);
|
2023-02-09 21:37:23 +01:00
|
|
|
|
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Add the given \a vertex_buf as instanced vertex buffer to a #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
* \return the index of verts in the batch.
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
int GPU_batch_instbuf_add(blender::gpu::Batch *batch,
|
|
|
|
blender::gpu::VertBuf *vertex_buf,
|
|
|
|
bool own_vbo);
|
2023-02-09 21:37:23 +01:00
|
|
|
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Set the first instanced vertex buffer of a #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
* \note Override ONLY the first instance VBO (and free them if owned).
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_instbuf_set(blender::gpu::Batch *batch,
|
|
|
|
blender::gpu::VertBuf *vertex_buf,
|
|
|
|
bool own_vbo);
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Set the index buffer of a #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
* \note Override any previously assigned index buffer (and free it if owned).
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_elembuf_set(blender::gpu::Batch *batch,
|
|
|
|
blender::gpu::IndexBuf *index_buf,
|
|
|
|
bool own_ibo);
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the #GPUbatch has \a vertex_buf in its vertex buffer list.
|
|
|
|
* \note The search is only conducted on the non-instance rate vertex buffer list.
|
|
|
|
*/
|
2024-03-28 10:57:47 +01:00
|
|
|
bool GPU_batch_vertbuf_has(const blender::gpu::Batch *batch, blender::gpu::VertBuf *vertex_buf);
|
2016-09-15 18:41:28 +02:00
|
|
|
|
2022-09-02 18:30:48 +02:00
|
|
|
/**
|
2023-02-09 21:37:23 +01:00
|
|
|
* Set resource id buffer to bind as instance attribute to workaround the lack of gl_BaseInstance
|
|
|
|
* on some hardware / platform.
|
|
|
|
* \note Only to be used by draw manager.
|
2022-09-02 18:30:48 +02:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_resource_id_buf_set(blender::gpu::Batch *batch, GPUStorageBuf *resource_id_buf);
|
2022-09-02 18:30:48 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Shader Binding & Uniforms
|
2021-12-09 10:01:47 +01:00
|
|
|
*
|
2023-02-09 21:37:23 +01:00
|
|
|
* TODO(fclem): This whole section should be removed. See the other `TODO`s in this section.
|
2024-03-26 03:06:25 +01:00
|
|
|
* This is because we want to remove #blender::gpu::Batch.shader to avoid usage mistakes.
|
2023-02-09 21:37:23 +01:00
|
|
|
* Interacting directly with the #GPUShader provide a clearer interface and less error-prone.
|
|
|
|
* \{ */
|
|
|
|
|
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Sets the shader to be drawn with this #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
* \note This need to be called first for the `GPU_batch_uniform_*` functions to work.
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2023-02-09 21:37:23 +01:00
|
|
|
/* TODO(fclem): These should be removed and replaced by `GPU_shader_bind()`. */
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_set_shader(blender::gpu::Batch *batch, GPUShader *shader);
|
|
|
|
void GPU_batch_program_set_builtin(blender::gpu::Batch *batch, eGPUBuiltinShader shader_id);
|
|
|
|
void GPU_batch_program_set_builtin_with_config(blender::gpu::Batch *batch,
|
2019-02-10 01:02:06 +01:00
|
|
|
eGPUBuiltinShader shader_id,
|
|
|
|
eGPUShaderConfig sh_cfg);
|
2023-02-09 21:37:23 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Bind program bound to IMM (immediate mode) to the #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
*
|
2024-03-26 03:06:25 +01:00
|
|
|
* XXX: Use this with much care. Drawing with the #blender::gpu::Batch API is not compatible with
|
|
|
|
* IMM. DO NOT DRAW WITH THE BATCH BEFORE CALLING #immUnbindProgram.
|
2023-02-09 21:37:23 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_program_set_imm_shader(blender::gpu::Batch *batch);
|
2018-07-18 15:09:31 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Set uniform variables for the shader currently bound to the #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
*/
|
2021-02-06 04:07:03 +01:00
|
|
|
/* TODO(fclem): These need to be replaced by GPU_shader_uniform_* with explicit shader. */
|
2020-08-13 15:35:16 +02:00
|
|
|
#define GPU_batch_uniform_1i(batch, name, x) GPU_shader_uniform_1i((batch)->shader, name, x);
|
|
|
|
#define GPU_batch_uniform_1b(batch, name, x) GPU_shader_uniform_1b((batch)->shader, name, x);
|
|
|
|
#define GPU_batch_uniform_1f(batch, name, x) GPU_shader_uniform_1f((batch)->shader, name, x);
|
|
|
|
#define GPU_batch_uniform_2f(batch, name, x, y) GPU_shader_uniform_2f((batch)->shader, name, x, y);
|
|
|
|
#define GPU_batch_uniform_3f(batch, name, x, y, z) \
|
|
|
|
GPU_shader_uniform_3f((batch)->shader, name, x, y, z);
|
|
|
|
#define GPU_batch_uniform_4f(batch, name, x, y, z, w) \
|
|
|
|
GPU_shader_uniform_4f((batch)->shader, name, x, y, z, w);
|
|
|
|
#define GPU_batch_uniform_2fv(batch, name, val) GPU_shader_uniform_2fv((batch)->shader, name, val);
|
|
|
|
#define GPU_batch_uniform_3fv(batch, name, val) GPU_shader_uniform_3fv((batch)->shader, name, val);
|
|
|
|
#define GPU_batch_uniform_4fv(batch, name, val) GPU_shader_uniform_4fv((batch)->shader, name, val);
|
|
|
|
#define GPU_batch_uniform_2fv_array(batch, name, len, val) \
|
|
|
|
GPU_shader_uniform_2fv_array((batch)->shader, name, len, val);
|
|
|
|
#define GPU_batch_uniform_4fv_array(batch, name, len, val) \
|
|
|
|
GPU_shader_uniform_4fv_array((batch)->shader, name, len, val);
|
|
|
|
#define GPU_batch_uniform_mat4(batch, name, val) \
|
|
|
|
GPU_shader_uniform_mat4((batch)->shader, name, val);
|
2022-01-11 09:57:22 +01:00
|
|
|
#define GPU_batch_uniformbuf_bind(batch, name, ubo) \
|
2023-02-12 22:52:27 +01:00
|
|
|
GPU_uniformbuf_bind(ubo, GPU_shader_get_ubo_binding((batch)->shader, name));
|
2020-09-02 00:27:41 +02:00
|
|
|
#define GPU_batch_texture_bind(batch, name, tex) \
|
2023-02-12 22:52:27 +01:00
|
|
|
GPU_texture_bind(tex, GPU_shader_get_sampler_binding((batch)->shader, name));
|
2018-07-18 15:09:31 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Shader Binding & Uniforms
|
|
|
|
* \{ */
|
|
|
|
|
2022-08-30 21:54:33 +02:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Draw the #blender::gpu::Batch with vertex count and instance count from its vertex buffers
|
|
|
|
* lengths. Ensures the associated shader is bound. TODO(fclem) remove this behavior.
|
2022-08-30 21:54:33 +02:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_draw(blender::gpu::Batch *batch);
|
2023-02-09 21:37:23 +01:00
|
|
|
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Draw the #blender::gpu::Batch with vertex count and instance count from its vertex buffers
|
|
|
|
* lengths. Ensures the associated shader is bound. TODO(fclem) remove this behavior.
|
2023-02-09 21:37:23 +01:00
|
|
|
*
|
|
|
|
* A \a vertex_count of 0 will use the default number of vertex.
|
|
|
|
* The \a vertex_first sets the start of the instance-rate attributes.
|
|
|
|
*
|
|
|
|
* \note No out-of-bound access check is made on the vertex buffers since they are tricky to
|
|
|
|
* detect. Double check that the range of vertex has data or that the data isn't read by the
|
|
|
|
* shader.
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_draw_range(blender::gpu::Batch *batch, int vertex_first, int vertex_count);
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2021-12-09 10:01:47 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Draw multiple instances of the #blender::gpu::Batch with custom instance range.
|
2023-02-09 21:37:23 +01:00
|
|
|
* Ensures the associated shader is bound. TODO(fclem) remove this behavior.
|
|
|
|
*
|
|
|
|
* An \a instance_count of 0 will use the default number of instances.
|
|
|
|
* The \a instance_first sets the start of the instance-rate attributes.
|
|
|
|
*
|
2024-03-26 03:06:25 +01:00
|
|
|
* \note this can be used even if the #blender::gpu::Batch contains no instance-rate attributes.
|
2023-02-09 21:37:23 +01:00
|
|
|
* \note No out-of-bound access check is made on the vertex buffers since they are tricky to
|
|
|
|
* detect. Double check that the range of vertex has data or that the data isn't read by the
|
|
|
|
* shader.
|
2021-12-09 10:01:47 +01:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_draw_instance_range(blender::gpu::Batch *batch,
|
|
|
|
int instance_first,
|
|
|
|
int instance_count);
|
2022-07-30 13:28:05 +02:00
|
|
|
|
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Draw the #blender::gpu::Batch custom parameters.
|
2023-02-09 21:37:23 +01:00
|
|
|
* IMPORTANT: This does not bind/unbind shader and does not call GPU_matrix_bind().
|
|
|
|
*
|
|
|
|
* A \a vertex_count of 0 will use the default number of vertex.
|
|
|
|
* An \a instance_count of 0 will use the default number of instances.
|
|
|
|
*
|
|
|
|
* \note No out-of-bound access check is made on the vertex buffers since they are tricky to
|
|
|
|
* detect. Double check that the range of vertex has data or that the data isn't read by the
|
|
|
|
* shader.
|
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_draw_advanced(blender::gpu::Batch *batch,
|
|
|
|
int vertex_first,
|
|
|
|
int vertex_count,
|
|
|
|
int instance_first,
|
|
|
|
int instance_count);
|
2023-02-09 21:37:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Issue a single draw call using arguments sourced from a #GPUStorageBuf.
|
2024-03-26 03:06:25 +01:00
|
|
|
* The argument are expected to be valid for the type of geometry contained by this
|
|
|
|
* #blender::gpu::Batch (index or non-indexed).
|
2023-02-09 21:37:23 +01:00
|
|
|
*
|
2024-02-01 17:26:08 +01:00
|
|
|
* The indirect buffer needs to be synced after filling its contents and before calling this
|
|
|
|
* function using `GPU_storagebuf_sync_as_indirect_buffer`.
|
2023-02-09 21:37:23 +01:00
|
|
|
*
|
|
|
|
* For more info see the GL documentation:
|
|
|
|
* https://registry.khronos.org/OpenGL-Refpages/gl4/html/glDrawArraysIndirect.xhtml
|
2022-07-30 13:28:05 +02:00
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_draw_indirect(blender::gpu::Batch *batch,
|
|
|
|
GPUStorageBuf *indirect_buf,
|
|
|
|
intptr_t offset);
|
2023-02-09 21:37:23 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Issue \a count draw calls using arguments sourced from a #GPUStorageBuf.
|
|
|
|
* The \a stride (in bytes) control the spacing between each command description.
|
2024-03-26 03:06:25 +01:00
|
|
|
* The argument are expected to be valid for the type of geometry contained by this
|
|
|
|
* #blender::gpu::Batch (index or non-indexed).
|
2023-02-09 21:37:23 +01:00
|
|
|
*
|
2024-02-01 17:26:08 +01:00
|
|
|
* The indirect buffer needs to be synced after filling its contents and before calling this
|
|
|
|
* function using `GPU_storagebuf_sync_as_indirect_buffer`.
|
2023-02-09 21:37:23 +01:00
|
|
|
*
|
|
|
|
* For more info see the GL documentation:
|
|
|
|
* https://registry.khronos.org/OpenGL-Refpages/gl4/html/glMultiDrawArraysIndirect.xhtml
|
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_multi_draw_indirect(blender::gpu::Batch *batch,
|
|
|
|
GPUStorageBuf *indirect_buf,
|
|
|
|
int count,
|
|
|
|
intptr_t offset,
|
|
|
|
intptr_t stride);
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/**
|
2024-03-26 03:06:25 +01:00
|
|
|
* Return indirect draw call parameters for this #blender::gpu::Batch.
|
2023-02-09 21:37:23 +01:00
|
|
|
* NOTE: \a r_base_index is set to -1 if not using an index buffer.
|
|
|
|
*/
|
2024-03-26 03:06:25 +01:00
|
|
|
void GPU_batch_draw_parameter_get(blender::gpu::Batch *batch,
|
2023-02-09 21:37:23 +01:00
|
|
|
int *r_vertex_count,
|
|
|
|
int *r_vertex_first,
|
|
|
|
int *r_base_index,
|
|
|
|
int *r_indices_count);
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/** \} */
|
2018-07-17 21:11:23 +02:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
/** \name Module init/exit
|
|
|
|
* \{ */
|
2017-02-08 00:38:07 +01:00
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
void gpu_batch_init();
|
|
|
|
void gpu_batch_exit();
|
2018-01-15 06:21:23 +01:00
|
|
|
|
2023-02-09 21:37:23 +01:00
|
|
|
/** \} */
|