Blender V5.0
GPU_shader_shared_utils.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2022 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
30
31#pragma once
32
33#ifdef GLSL_CPP_STUBS
34/* Silence macros when compiling for shaders. */
35# define BLI_STATIC_ASSERT(cond, msg)
36# define BLI_STATIC_ASSERT_ALIGN(type_, align_)
37# define BLI_STATIC_ASSERT_SIZE(type_, size_)
38# define ENUM_OPERATORS(a, b)
39# define UNUSED_VARS(a) (void)a
40/* Math function renaming. */
41# define cosf cos
42# define sinf sin
43# define tanf tan
44# define acosf acos
45# define asinf asin
46# define atanf atan
47# define floorf floor
48# define ceilf ceil
49# define sqrtf sqrt
50# define expf exp
51
52#elif defined(GPU_SHADER)
53/* Silence macros when compiling for shaders. */
54# define BLI_STATIC_ASSERT(cond, msg)
55# define BLI_STATIC_ASSERT_ALIGN(type_, align_)
56# define BLI_STATIC_ASSERT_SIZE(type_, size_)
57# define ATTR_FALLTHROUGH
58# define ENUM_OPERATORS(a, b)
59# define UNUSED_VARS(a)
60/* Math function renaming. */
61# define cosf cos
62# define sinf sin
63# define tanf tan
64# define acosf acos
65# define asinf asin
66# define atanf atan
67# define floorf floor
68# define ceilf ceil
69# define sqrtf sqrt
70# define expf exp
71
72#else /* C / C++ */
73# ifndef GPU_SHADER /* Avoid parsing this into shader code. */
74
75# include "BLI_assert.h"
76# include "BLI_sys_types.h"
77
78# include <math.h>
79
82
84// using bool2 = blender::int2; /* Size is not consistent across backend. */
85// using bool3 = blender::int3; /* Size is not consistent across backend. */
86// using bool4 = blender::int4; /* Size is not consistent across backend. */
87
88using blender::float2;
89using blender::float4;
90using blender::int2;
91using blender::int4;
92using blender::uint2;
93using blender::uint4;
96using blender::float3;
97using blender::int3;
98using blender::uint3;
103
105// using blender::float3x2; /* Does not follow alignment rules of GPU. */
107// using blender::float2x3; /* Does not follow alignment rules of GPU. */
108// using blender::float3x3; /* Does not follow alignment rules of GPU. */
109// using blender::float4x3; /* Does not follow alignment rules of GPU. */
113
114# endif
115
116/* For assert support. */
117# if defined(GPU_VERTEX_SHADER)
118# define GPU_THREAD uint3(gl_VertexID, gl_InstanceID, 0)
119# elif defined(GPU_FRAGMENT_SHADER)
120# define GPU_THREAD uint3(gl_FragCoord.x, gl_FragCoord.y, 0)
121# elif defined(GPU_COMPUTE_SHADER)
122# define GPU_THREAD gl_GlobalInvocationID
123# else
124# define GPU_THREAD error_not_in_a_shader_question_mark
125# endif
126#endif
int32_t bool32_t
VecBase< uint32_t, 2 > uint2
VecBase< int32_t, 4 > int4
VecBase< uint32_t, 4 > uint4
MatBase< float, 2, 2 > float2x2
VecBase< uint32_t, 3 > uint3
MatBase< float, 4, 4 > float4x4
MatBase< float, 2, 4 > float2x4
MatBase< float, 3, 4 > float3x4
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< int32_t, 3 > int3
MatBase< float, 4, 2 > float4x2
VecBase< float, 3 > float3