| 
									
										
										
										
											2022-02-11 09:07:11 +11:00
										 |  |  | /* SPDX-License-Identifier: GPL-2.0-or-later */ | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-18 08:08:12 +11:00
										 |  |  | /** \file
 | 
					
						
							|  |  |  |  * \ingroup gpu | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 20:56:39 +02:00
										 |  |  | #include "BLI_utildefines.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-01 15:33:54 +01:00
										 |  |  | /** Opaque type hiding blender::gpu::Fence. */ | 
					
						
							|  |  |  | typedef struct GPUFence GPUFence; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  | typedef enum eGPUWriteMask { | 
					
						
							| 
									
										
										
										
											2020-08-17 18:11:09 +02:00
										 |  |  |   GPU_WRITE_NONE = 0, | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |   GPU_WRITE_RED = (1 << 0), | 
					
						
							|  |  |  |   GPU_WRITE_GREEN = (1 << 1), | 
					
						
							|  |  |  |   GPU_WRITE_BLUE = (1 << 2), | 
					
						
							|  |  |  |   GPU_WRITE_ALPHA = (1 << 3), | 
					
						
							|  |  |  |   GPU_WRITE_DEPTH = (1 << 4), | 
					
						
							| 
									
										
										
										
											2020-08-28 14:33:51 +02:00
										 |  |  |   GPU_WRITE_STENCIL = (1 << 5), | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |   GPU_WRITE_COLOR = (GPU_WRITE_RED | GPU_WRITE_GREEN | GPU_WRITE_BLUE | GPU_WRITE_ALPHA), | 
					
						
							|  |  |  | } eGPUWriteMask; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-01 23:51:01 +05:30
										 |  |  | ENUM_OPERATORS(eGPUWriteMask, GPU_WRITE_COLOR) | 
					
						
							| 
									
										
										
										
											2020-08-16 20:56:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-12 06:10:11 +02:00
										 |  |  | typedef enum eGPUBarrier { | 
					
						
							|  |  |  |   GPU_BARRIER_NONE = 0, | 
					
						
							| 
									
										
										
										
											2022-02-04 19:46:40 +01:00
										 |  |  |   GPU_BARRIER_COMMAND = (1 << 0), | 
					
						
							|  |  |  |   GPU_BARRIER_FRAMEBUFFER = (1 << 1), | 
					
						
							|  |  |  |   GPU_BARRIER_SHADER_IMAGE_ACCESS = (1 << 2), | 
					
						
							|  |  |  |   GPU_BARRIER_SHADER_STORAGE = (1 << 3), | 
					
						
							|  |  |  |   GPU_BARRIER_TEXTURE_FETCH = (1 << 4), | 
					
						
							|  |  |  |   GPU_BARRIER_TEXTURE_UPDATE = (1 << 5), | 
					
						
							|  |  |  |   GPU_BARRIER_VERTEX_ATTRIB_ARRAY = (1 << 6), | 
					
						
							|  |  |  |   GPU_BARRIER_ELEMENT_ARRAY = (1 << 7), | 
					
						
							| 
									
										
										
										
											2022-11-15 14:25:04 +01:00
										 |  |  |   GPU_BARRIER_UNIFORM = (1 << 8), | 
					
						
							| 
									
										
										
										
											2020-09-12 06:10:11 +02:00
										 |  |  | } eGPUBarrier; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-15 14:25:04 +01:00
										 |  |  | ENUM_OPERATORS(eGPUBarrier, GPU_BARRIER_UNIFORM) | 
					
						
							| 
									
										
										
										
											2020-09-12 06:10:11 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-05-13 09:24:28 +10:00
										 |  |  | /* NOTE: For Metal and Vulkan only.
 | 
					
						
							|  |  |  |  * TODO(Metal): Update barrier calls to use stage flags. */ | 
					
						
							| 
									
										
										
										
											2022-05-12 20:49:09 +02:00
										 |  |  | typedef enum eGPUStageBarrierBits { | 
					
						
							|  |  |  |   GPU_BARRIER_STAGE_VERTEX = (1 << 0), | 
					
						
							|  |  |  |   GPU_BARRIER_STAGE_FRAGMENT = (1 << 1), | 
					
						
							|  |  |  |   GPU_BARRIER_STAGE_COMPUTE = (1 << 2), | 
					
						
							|  |  |  |   GPU_BARRIER_STAGE_ANY_GRAPHICS = (GPU_BARRIER_STAGE_VERTEX | GPU_BARRIER_STAGE_FRAGMENT), | 
					
						
							|  |  |  |   GPU_BARRIER_STAGE_ANY = (GPU_BARRIER_STAGE_VERTEX | GPU_BARRIER_STAGE_FRAGMENT | | 
					
						
							|  |  |  |                            GPU_BARRIER_STAGE_COMPUTE), | 
					
						
							|  |  |  | } eGPUStageBarrierBits; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ENUM_OPERATORS(eGPUStageBarrierBits, GPU_BARRIER_STAGE_COMPUTE) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * Defines the fixed pipeline blending equation. | 
					
						
							|  |  |  |  * SRC is the output color from the shader. | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |  * DST is the color from the frame-buffer. | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  |  * The blending equation is: | 
					
						
							|  |  |  |  * `(SRC * A) + (DST * B)`. | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |  * The blend mode will modify the A and B parameters. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | typedef enum eGPUBlend { | 
					
						
							|  |  |  |   GPU_BLEND_NONE = 0, | 
					
						
							| 
									
										
										
										
											2022-01-06 13:54:52 +11:00
										 |  |  |   /** Pre-multiply variants will _NOT_ multiply rgb output by alpha. */ | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |   GPU_BLEND_ALPHA, | 
					
						
							|  |  |  |   GPU_BLEND_ALPHA_PREMULT, | 
					
						
							|  |  |  |   GPU_BLEND_ADDITIVE, | 
					
						
							|  |  |  |   GPU_BLEND_ADDITIVE_PREMULT, | 
					
						
							|  |  |  |   GPU_BLEND_MULTIPLY, | 
					
						
							|  |  |  |   GPU_BLEND_SUBTRACT, | 
					
						
							|  |  |  |   /** Replace logic op: SRC * (1 - DST)
 | 
					
						
							|  |  |  |    * NOTE: Does not modify alpha. */ | 
					
						
							|  |  |  |   GPU_BLEND_INVERT, | 
					
						
							| 
									
										
										
										
											2020-08-19 11:42:12 +10:00
										 |  |  |   /** Order independent transparency.
 | 
					
						
							| 
									
										
										
										
											2021-02-05 16:23:34 +11:00
										 |  |  |    * NOTE: Cannot be used as is. Needs special setup (frame-buffer, shader ...). */ | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |   GPU_BLEND_OIT, | 
					
						
							|  |  |  |   /** Special blend to add color under and multiply dst color by src alpha. */ | 
					
						
							|  |  |  |   GPU_BLEND_BACKGROUND, | 
					
						
							|  |  |  |   /** Custom blend parameters using dual source blending : SRC0 + SRC1 * DST
 | 
					
						
							|  |  |  |    * NOTE: Can only be used with _ONE_ Draw Buffer and shader needs to be specialized. */ | 
					
						
							|  |  |  |   GPU_BLEND_CUSTOM, | 
					
						
							| 
									
										
										
										
											2020-11-03 14:39:50 +01:00
										 |  |  |   GPU_BLEND_ALPHA_UNDER_PREMUL, | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  | } eGPUBlend; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef enum eGPUDepthTest { | 
					
						
							|  |  |  |   GPU_DEPTH_NONE = 0, | 
					
						
							| 
									
										
										
										
											2020-08-20 16:38:34 +02:00
										 |  |  |   GPU_DEPTH_ALWAYS, /* Used to draw to the depth buffer without really testing. */ | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |   GPU_DEPTH_LESS, | 
					
						
							| 
									
										
										
										
											2020-08-20 16:38:34 +02:00
										 |  |  |   GPU_DEPTH_LESS_EQUAL, /* Default. */ | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |   GPU_DEPTH_EQUAL, | 
					
						
							|  |  |  |   GPU_DEPTH_GREATER, | 
					
						
							|  |  |  |   GPU_DEPTH_GREATER_EQUAL, | 
					
						
							|  |  |  | } eGPUDepthTest; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef enum eGPUStencilTest { | 
					
						
							|  |  |  |   GPU_STENCIL_NONE = 0, | 
					
						
							|  |  |  |   GPU_STENCIL_ALWAYS, | 
					
						
							|  |  |  |   GPU_STENCIL_EQUAL, | 
					
						
							|  |  |  |   GPU_STENCIL_NEQUAL, | 
					
						
							|  |  |  | } eGPUStencilTest; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef enum eGPUStencilOp { | 
					
						
							|  |  |  |   GPU_STENCIL_OP_NONE = 0, | 
					
						
							|  |  |  |   GPU_STENCIL_OP_REPLACE, | 
					
						
							|  |  |  |   /** Special values for stencil shadows. */ | 
					
						
							|  |  |  |   GPU_STENCIL_OP_COUNT_DEPTH_PASS, | 
					
						
							|  |  |  |   GPU_STENCIL_OP_COUNT_DEPTH_FAIL, | 
					
						
							|  |  |  | } eGPUStencilOp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef enum eGPUFaceCullTest { | 
					
						
							| 
									
										
										
										
											2020-07-17 20:04:37 +02:00
										 |  |  |   GPU_CULL_NONE = 0, /* Culling disabled. */ | 
					
						
							|  |  |  |   GPU_CULL_FRONT, | 
					
						
							|  |  |  |   GPU_CULL_BACK, | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  | } eGPUFaceCullTest; | 
					
						
							| 
									
										
										
										
											2020-07-17 20:04:37 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-17 20:26:12 +02:00
										 |  |  | typedef enum eGPUProvokingVertex { | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  |   GPU_VERTEX_LAST = 0,  /* Default. */ | 
					
						
							|  |  |  |   GPU_VERTEX_FIRST = 1, /* Follow Blender loop order. */ | 
					
						
							| 
									
										
										
										
											2020-07-17 20:26:12 +02:00
										 |  |  | } eGPUProvokingVertex; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 23:20:59 +02:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 15:38:34 +02:00
										 |  |  | void GPU_blend(eGPUBlend blend); | 
					
						
							| 
									
										
										
										
											2020-08-16 14:01:07 +02:00
										 |  |  | void GPU_face_culling(eGPUFaceCullTest culling); | 
					
						
							| 
									
										
										
										
											2020-08-20 16:38:34 +02:00
										 |  |  | void GPU_depth_test(eGPUDepthTest test); | 
					
						
							| 
									
										
										
										
											2020-08-23 11:06:52 +02:00
										 |  |  | void GPU_stencil_test(eGPUStencilTest test); | 
					
						
							| 
									
										
										
										
											2020-07-17 20:26:12 +02:00
										 |  |  | void GPU_provoking_vertex(eGPUProvokingVertex vert); | 
					
						
							| 
									
										
										
										
											2020-08-20 16:38:34 +02:00
										 |  |  | void GPU_front_facing(bool invert); | 
					
						
							| 
									
										
										
										
											2018-10-30 15:31:32 -03:00
										 |  |  | void GPU_depth_range(float near, float far); | 
					
						
							| 
									
										
										
										
											2020-07-17 19:21:33 +02:00
										 |  |  | void GPU_scissor_test(bool enable); | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | void GPU_line_smooth(bool enable); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * \note By convention, this is set as needed and not reset back to 1.0. | 
					
						
							|  |  |  |  * This means code that draws lines must always set the line width beforehand, | 
					
						
							|  |  |  |  * but is not expected to restore it's previous value. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | void GPU_line_width(float width); | 
					
						
							| 
									
										
										
										
											2020-08-16 23:20:59 +02:00
										 |  |  | void GPU_logic_op_xor_set(bool enable); | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | void GPU_point_size(float size); | 
					
						
							|  |  |  | void GPU_polygon_smooth(bool enable); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Programmable point size: | 
					
						
							|  |  |  |  * - Shaders set their own point size when enabled | 
					
						
							|  |  |  |  * - Use GPU_point_size when disabled. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * TODO: remove and use program point size everywhere. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2019-05-28 17:14:22 +02:00
										 |  |  | void GPU_program_point_size(bool enable); | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | void GPU_scissor(int x, int y, int width, int height); | 
					
						
							| 
									
										
										
										
											2020-08-16 01:49:52 +02:00
										 |  |  | void GPU_scissor_get(int coords[4]); | 
					
						
							| 
									
										
										
										
											2020-07-17 19:03:30 +02:00
										 |  |  | void GPU_viewport(int x, int y, int width, int height); | 
					
						
							| 
									
										
										
										
											2018-07-02 18:27:05 +02:00
										 |  |  | void GPU_viewport_size_get_f(float coords[4]); | 
					
						
							|  |  |  | void GPU_viewport_size_get_i(int coords[4]); | 
					
						
							| 
									
										
										
										
											2020-08-16 23:20:59 +02:00
										 |  |  | void GPU_write_mask(eGPUWriteMask mask); | 
					
						
							| 
									
										
										
										
											2020-07-16 04:16:10 +02:00
										 |  |  | void GPU_color_mask(bool r, bool g, bool b, bool a); | 
					
						
							|  |  |  | void GPU_depth_mask(bool depth); | 
					
						
							|  |  |  | bool GPU_depth_mask_get(void); | 
					
						
							| 
									
										
										
										
											2020-08-17 18:11:09 +02:00
										 |  |  | void GPU_shadow_offset(bool enable); | 
					
						
							| 
									
										
										
										
											2020-09-04 20:59:13 +02:00
										 |  |  | void GPU_clip_distances(int distances_enabled); | 
					
						
							| 
									
										
										
										
											2020-07-29 18:13:19 +02:00
										 |  |  | bool GPU_mipmap_enabled(void); | 
					
						
							| 
									
										
										
										
											2020-08-17 18:11:09 +02:00
										 |  |  | void GPU_state_set(eGPUWriteMask write_mask, | 
					
						
							|  |  |  |                    eGPUBlend blend, | 
					
						
							|  |  |  |                    eGPUFaceCullTest culling_test, | 
					
						
							|  |  |  |                    eGPUDepthTest depth_test, | 
					
						
							|  |  |  |                    eGPUStencilTest stencil_test, | 
					
						
							|  |  |  |                    eGPUStencilOp stencil_op, | 
					
						
							|  |  |  |                    eGPUProvokingVertex provoking_vert); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void GPU_stencil_reference_set(uint reference); | 
					
						
							|  |  |  | void GPU_stencil_write_mask_set(uint write_mask); | 
					
						
							|  |  |  | void GPU_stencil_compare_mask_set(uint compare_mask); | 
					
						
							| 
									
										
										
										
											2018-06-26 15:17:31 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-04-27 12:34:57 +02:00
										 |  |  | eGPUFaceCullTest GPU_face_culling_get(void); | 
					
						
							| 
									
										
										
										
											2020-08-16 23:20:59 +02:00
										 |  |  | eGPUBlend GPU_blend_get(void); | 
					
						
							| 
									
										
										
										
											2020-08-20 16:38:34 +02:00
										 |  |  | eGPUDepthTest GPU_depth_test_get(void); | 
					
						
							| 
									
										
										
										
											2020-08-16 23:20:59 +02:00
										 |  |  | eGPUWriteMask GPU_write_mask_get(void); | 
					
						
							| 
									
										
										
										
											2020-08-23 11:06:52 +02:00
										 |  |  | uint GPU_stencil_mask_get(void); | 
					
						
							|  |  |  | eGPUStencilTest GPU_stencil_test_get(void); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * \note Already pre-multiplied by `U.pixelsize`. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-09-18 19:59:51 +02:00
										 |  |  | float GPU_line_width_get(void); | 
					
						
							| 
									
										
										
										
											2020-08-16 23:20:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-31 12:28:59 +01:00
										 |  |  | void GPU_flush(void); | 
					
						
							|  |  |  | void GPU_finish(void); | 
					
						
							| 
									
										
										
										
											2020-09-12 17:29:37 +02:00
										 |  |  | void GPU_apply_state(void); | 
					
						
							| 
									
										
										
										
											2020-10-09 15:12:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void GPU_bgl_start(void); | 
					
						
							| 
									
										
										
										
											2021-12-09 20:01:47 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * Just turn off the `bgl` safeguard system. Can be called even without #GPU_bgl_start. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-10-09 15:12:28 +02:00
										 |  |  | void GPU_bgl_end(void); | 
					
						
							|  |  |  | bool GPU_bgl_get(void); | 
					
						
							| 
									
										
										
										
											2018-10-31 12:28:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-12 06:10:11 +02:00
										 |  |  | void GPU_memory_barrier(eGPUBarrier barrier); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-01 15:33:54 +01:00
										 |  |  | GPUFence *GPU_fence_create(void); | 
					
						
							|  |  |  | void GPU_fence_free(GPUFence *fence); | 
					
						
							|  |  |  | void GPU_fence_signal(GPUFence *fence); | 
					
						
							|  |  |  | void GPU_fence_wait(GPUFence *fence); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-02 15:28:47 +01:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 |