Blender V4.5
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#ifdef GLSL_CPP_STUBS
32# pragma once
33
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/* Incompatible keywords. */
61# define static
62# define inline
63/* Math function renaming. */
64# define cosf cos
65# define sinf sin
66# define tanf tan
67# define acosf acos
68# define asinf asin
69# define atanf atan
70# define floorf floor
71# define ceilf ceil
72# define sqrtf sqrt
73# define expf exp
74
75#else /* C / C++ */
76# pragma once
77
78# include "BLI_assert.h"
79# include "BLI_sys_types.h"
80
83
85// using bool2 = blender::int2; /* Size is not consistent across backend. */
86// using bool3 = blender::int3; /* Size is not consistent across backend. */
87// using bool4 = blender::int4; /* Size is not consistent across backend. */
88
89using blender::float2;
90using blender::float4;
91using blender::int2;
92using blender::int4;
93using blender::uint2;
94using blender::uint4;
97using blender::float3;
98using blender::int3;
99using blender::uint3;
104
106// using blender::float3x2; /* Does not follow alignment rules of GPU. */
108// using blender::float2x3; /* Does not follow alignment rules of GPU. */
109// using blender::float3x3; /* Does not follow alignment rules of GPU. */
110// using blender::float4x3; /* Does not follow alignment rules of GPU. */
114
115#endif
116
117/* For assert support. */
118#if defined(GPU_VERTEX_SHADER)
119# define GPU_THREAD uint3(gl_VertexID, gl_InstanceID, 0)
120#elif defined(GPU_FRAGMENT_SHADER)
121# define GPU_THREAD uint3(gl_FragCoord.x, gl_FragCoord.y, 0)
122#elif defined(GPU_COMPUTE_SHADER)
123# define GPU_THREAD gl_GlobalInvocationID
124#else
125# define GPU_THREAD error_not_in_a_shader_question_mark
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