| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * This program is free software; you can redistribute it and/or | 
					
						
							|  |  |  |  * modify it under the terms of the GNU General Public License | 
					
						
							|  |  |  |  * as published by the Free Software Foundation; either version 2 | 
					
						
							| 
									
										
										
										
											2018-04-22 08:44:23 +02:00
										 |  |  |  * of the License, or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is distributed in the hope that it will be useful, | 
					
						
							|  |  |  |  * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
					
						
							|  |  |  |  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
					
						
							|  |  |  |  * GNU General Public License for more details. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * You should have received a copy of the GNU General Public License | 
					
						
							|  |  |  |  * along with this program; if not, write to the Free Software Foundation, | 
					
						
							|  |  |  |  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  |  * The Original Code is Copyright (C) 2016 by Mike Erwin. | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  |  * GPU geometry batch | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  |  * Contains VAOs + VBOs + Shader representing a drawable entity. | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-07 09:50:34 +02:00
										 |  |  | #pragma once
 | 
					
						
							| 
									
										
										
										
											2016-09-13 02:41:43 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-05 20:15:56 +02:00
										 |  |  | #include "GPU_index_buffer.h"
 | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | #include "GPU_shader.h"
 | 
					
						
							| 
									
										
										
										
											2020-03-19 09:33:03 +01:00
										 |  |  | #include "GPU_vertex_buffer.h"
 | 
					
						
							| 
									
										
										
										
											2017-03-16 23:32:35 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-26 18:16:33 -03: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-16 00:06:39 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | typedef enum eGPUBatchFlag { | 
					
						
							|  |  |  |   /** Invalid default state. */ | 
					
						
							|  |  |  |   GPU_BATCH_INVALID = 0, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** GPUVertBuf ownership. (One bit per vbo) */ | 
					
						
							|  |  |  |   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), | 
					
						
							|  |  |  |   /** Instance GPUVertBuf ownership. (One bit per vbo) */ | 
					
						
							|  |  |  |   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, | 
					
						
							|  |  |  |   /** GPUIndexBuf ownership. */ | 
					
						
							|  |  |  |   GPU_BATCH_OWNS_INDEX = (GPU_BATCH_OWNS_INST_VBO_MAX << 1), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   /** Has been initialized. At least one VBO is set. */ | 
					
						
							| 
									
										
										
										
											2021-10-26 18:16:33 -03:00
										 |  |  |   GPU_BATCH_INIT = (1 << 26), | 
					
						
							| 
									
										
										
										
											2020-10-19 08:12:33 -07:00
										 |  |  |   /** Batch is initialized but its VBOs are still being populated. (optional) */ | 
					
						
							| 
									
										
										
										
											2021-10-26 18:16:33 -03: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 18:16:33 -03:00
										 |  |  |   GPU_BATCH_DIRTY = (1 << 27), | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | } eGPUBatchFlag; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #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 23:51:01 +05:30
										 |  |  | ENUM_OPERATORS(eGPUBatchFlag, GPU_BATCH_DIRTY) | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * IMPORTANT: Do not allocate manually as the real struct is bigger (i.e: GLBatch). This is only | 
					
						
							|  |  |  |  * the common and "public" part of the struct. Use the provided allocator. | 
					
						
							| 
									
										
										
										
											2020-09-19 14:32:41 +10:00
										 |  |  |  * TODO(fclem): Make the content of this struct hidden and expose getters/setters. | 
					
						
							| 
									
										
										
										
											2021-01-04 12:00:18 +11:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | typedef struct GPUBatch { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /** verts[0] is required, others can be NULL */ | 
					
						
							|  |  |  |   GPUVertBuf *verts[GPU_BATCH_VBO_MAX_LEN]; | 
					
						
							|  |  |  |   /** Instance attributes. */ | 
					
						
							| 
									
										
										
										
											2019-12-02 01:40:58 +01:00
										 |  |  |   GPUVertBuf *inst[GPU_BATCH_INST_VBO_MAX_LEN]; | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   /** NULL if element list not needed */ | 
					
						
							|  |  |  |   GPUIndexBuf *elem; | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11: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. */ | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  |   struct GPUShader *shader; | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | } GPUBatch; | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-10 11:41:22 +02:00
										 |  |  | GPUBatch *GPU_batch_calloc(void); | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | GPUBatch *GPU_batch_create_ex(GPUPrimType prim, | 
					
						
							|  |  |  |                               GPUVertBuf *vert, | 
					
						
							|  |  |  |                               GPUIndexBuf *elem, | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  |                               eGPUBatchFlag owns_flag); | 
					
						
							| 
									
										
										
										
											2020-08-10 03:17:35 +02:00
										 |  |  | void GPU_batch_init_ex(GPUBatch *batch, | 
					
						
							|  |  |  |                        GPUPrimType prim, | 
					
						
							|  |  |  |                        GPUVertBuf *vert, | 
					
						
							|  |  |  |                        GPUIndexBuf *elem, | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  |                        eGPUBatchFlag owns_flag); | 
					
						
							| 
									
										
										
										
											2018-12-18 13:08:08 +01:00
										 |  |  | void GPU_batch_copy(GPUBatch *batch_dst, GPUBatch *batch_src); | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define GPU_batch_create(prim, verts, elem) GPU_batch_create_ex(prim, verts, elem, 0)
 | 
					
						
							|  |  |  | #define GPU_batch_init(batch, prim, verts, elem) GPU_batch_init_ex(batch, prim, verts, elem, 0)
 | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-14 23:29:46 +10:00
										 |  |  | /* Same as discard but does not free. (does not call free callback). */ | 
					
						
							|  |  |  | void GPU_batch_clear(GPUBatch *); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_batch_discard(GPUBatch *); /* verts & elem are not discarded */ | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | void GPU_batch_instbuf_set(GPUBatch *, GPUVertBuf *, bool own_vbo); /* Instancing */ | 
					
						
							| 
									
										
										
										
											2019-07-14 16:49:44 +02:00
										 |  |  | void GPU_batch_elembuf_set(GPUBatch *batch, GPUIndexBuf *elem, bool own_ibo); | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-12-02 01:40:58 +01:00
										 |  |  | int GPU_batch_instbuf_add_ex(GPUBatch *, GPUVertBuf *, bool own_vbo); | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | int GPU_batch_vertbuf_add_ex(GPUBatch *, GPUVertBuf *, bool own_vbo); | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define GPU_batch_vertbuf_add(batch, verts) GPU_batch_vertbuf_add_ex(batch, verts, false)
 | 
					
						
							| 
									
										
										
										
											2016-09-15 18:41:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-30 01:07:29 +02:00
										 |  |  | void GPU_batch_set_shader(GPUBatch *batch, GPUShader *shader); | 
					
						
							| 
									
										
										
										
											2020-02-11 15:18:55 +01:00
										 |  |  | void GPU_batch_program_set_imm_shader(GPUBatch *batch); | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | void GPU_batch_program_set_builtin(GPUBatch *batch, eGPUBuiltinShader shader_id); | 
					
						
							|  |  |  | void GPU_batch_program_set_builtin_with_config(GPUBatch *batch, | 
					
						
							|  |  |  |                                                eGPUBuiltinShader shader_id, | 
					
						
							|  |  |  |                                                eGPUShaderConfig sh_cfg); | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 03:01:13 +02:00
										 |  |  | /* Will only work after setting the batch program. */ | 
					
						
							| 
									
										
										
										
											2021-02-05 19:07:03 -08: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); | 
					
						
							| 
									
										
										
										
											2020-09-02 00:27:41 +02:00
										 |  |  | #define GPU_batch_texture_bind(batch, name, tex) \
 | 
					
						
							|  |  |  |   GPU_texture_bind(tex, GPU_shader_get_texture_binding((batch)->shader, name)); | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-09 03:01:13 +02:00
										 |  |  | void GPU_batch_draw(GPUBatch *batch); | 
					
						
							|  |  |  | void GPU_batch_draw_range(GPUBatch *batch, int v_first, int v_count); | 
					
						
							|  |  |  | void GPU_batch_draw_instanced(GPUBatch *batch, int i_count); | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* This does not bind/unbind shader and does not call GPU_matrix_bind() */ | 
					
						
							| 
									
										
										
										
											2019-05-22 11:31:49 +02:00
										 |  |  | void GPU_batch_draw_advanced(GPUBatch *, int v_first, int v_count, int i_first, int i_count); | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #if 0 /* future plans */
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 00:12:21 +02:00
										 |  |  | /* Can multiple batches share a GPUVertBuf? Use ref count? */ | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* We often need a batch with its own data, to be created and discarded together. */ | 
					
						
							|  |  |  | /* WithOwn variants reduce number of system allocations. */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct BatchWithOwnVertexBuffer { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPUBatch batch; | 
					
						
							|  |  |  |   GPUVertBuf verts; /* link batch.verts to this */ | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | } BatchWithOwnVertexBuffer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct BatchWithOwnElementList { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPUBatch batch; | 
					
						
							|  |  |  |   GPUIndexBuf elem; /* link batch.elem to this */ | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | } BatchWithOwnElementList; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef struct BatchWithOwnVertexBufferAndElementList { | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  |   GPUBatch batch; | 
					
						
							|  |  |  |   GPUIndexBuf elem; /* link batch.elem to this */ | 
					
						
							|  |  |  |   GPUVertBuf verts; /* link batch.verts to this */ | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | } BatchWithOwnVertexBufferAndElementList; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | GPUBatch *create_BatchWithOwnVertexBuffer(GPUPrimType, GPUVertFormat *, uint v_len, GPUIndexBuf *); | 
					
						
							|  |  |  | GPUBatch *create_BatchWithOwnElementList(GPUPrimType, GPUVertBuf *, uint prim_len); | 
					
						
							| 
									
										
										
										
											2019-04-17 08:24:14 +02:00
										 |  |  | GPUBatch *create_BatchWithOwnVertexBufferAndElementList(GPUPrimType, | 
					
						
							|  |  |  |                                                         GPUVertFormat *, | 
					
						
							|  |  |  |                                                         uint v_len, | 
					
						
							|  |  |  |                                                         uint prim_len); | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | /* verts: shared, own */ | 
					
						
							|  |  |  | /* elem: none, shared, own */ | 
					
						
							| 
									
										
										
										
											2018-07-18 23:09:31 +10:00
										 |  |  | GPUBatch *create_BatchInGeneral(GPUPrimType, VertexBufferStuff, ElementListStuff); | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #endif /* future plans */
 | 
					
						
							| 
									
										
										
										
											2017-02-08 00:38:07 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-15 16:21:23 +11:00
										 |  |  | void gpu_batch_init(void); | 
					
						
							|  |  |  | void gpu_batch_exit(void); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-17 21:11:23 +02:00
										 |  |  | /* Macros */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-17 06:17:24 +02:00
										 |  |  | #define GPU_BATCH_DISCARD_SAFE(batch) \
 | 
					
						
							|  |  |  |   do { \ | 
					
						
							|  |  |  |     if (batch != NULL) { \ | 
					
						
							|  |  |  |       GPU_batch_discard(batch); \ | 
					
						
							|  |  |  |       batch = NULL; \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_BATCH_CLEAR_SAFE(batch) \
 | 
					
						
							|  |  |  |   do { \ | 
					
						
							|  |  |  |     if (batch != NULL) { \ | 
					
						
							|  |  |  |       GPU_batch_clear(batch); \ | 
					
						
							|  |  |  |       memset(batch, 0, sizeof(*(batch))); \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GPU_BATCH_DISCARD_ARRAY_SAFE(_batch_array, _len) \
 | 
					
						
							|  |  |  |   do { \ | 
					
						
							|  |  |  |     if (_batch_array != NULL) { \ | 
					
						
							|  |  |  |       BLI_assert(_len > 0); \ | 
					
						
							|  |  |  |       for (int _i = 0; _i < _len; _i++) { \ | 
					
						
							|  |  |  |         GPU_BATCH_DISCARD_SAFE(_batch_array[_i]); \ | 
					
						
							|  |  |  |       } \ | 
					
						
							|  |  |  |       MEM_freeN(_batch_array); \ | 
					
						
							|  |  |  |     } \ | 
					
						
							|  |  |  |   } while (0) | 
					
						
							| 
									
										
										
										
											2018-08-30 17:47:36 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 15:28:47 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |