Blender V5.3
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# include "gpu_shader_compat.hh"
35
36/* Silence macros when compiling for shaders. */
37# define BLI_STATIC_ASSERT(cond, msg)
38# define BLI_STATIC_ASSERT_ALIGN(type_, align_)
39# define BLI_STATIC_ASSERT_SIZE(type_, size_)
40# define ENUM_OPERATORS(a)
41# define UNUSED_VARS(a) (void)a
42/* Math function renaming. */
43# define cosf cos
44# define sinf sin
45# define tanf tan
46# define acosf acos
47# define asinf asin
48# define atanf atan
49# define floorf floor
50# define ceilf ceil
51# define sqrtf sqrt
52# define expf exp
53
54#elif defined(GPU_SHADER)
55# include "gpu_shader_compat.hh"
56
57/* Silence macros when compiling for shaders. */
58# define BLI_STATIC_ASSERT(cond, msg)
59# define BLI_STATIC_ASSERT_ALIGN(type_, align_)
60# define BLI_STATIC_ASSERT_SIZE(type_, size_)
61# define ENUM_OPERATORS(a)
62# define UNUSED_VARS(a)
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# ifndef GPU_SHADER /* Avoid parsing this into shader code. */
77
78# include "BLI_assert.hh"
79# include "BLI_enum_flags.hh"
80# include "BLI_sys_types.hh"
81
82# include <math.h>
83
86
88// using bool2 = blender::int2; /* Size is not consistent across backend. */
89// using bool3 = blender::int3; /* Size is not consistent across backend. */
90// using bool4 = blender::int4; /* Size is not consistent across backend. */
91
92using blender::float2;
93using blender::float4;
94using blender::int2;
95using blender::int4;
96using blender::uint2;
97using blender::uint4;
102using blender::float3;
103using blender::int3;
104using blender::uint3;
109
111// using blender::float3x2; /* Does not follow alignment rules of GPU. */
113// using blender::float2x3; /* Does not follow alignment rules of GPU. */
114// using blender::float3x3; /* Does not follow alignment rules of GPU. */
115// using blender::float4x3; /* Does not follow alignment rules of GPU. */
119
126template<typename T> struct union_t {
128
129 const T &operator()() const
130 {
131 return *reinterpret_cast<const T *>(this);
132 }
133
135 {
136 return *reinterpret_cast<T *>(this);
137 }
138};
139
140/* Mute the following attributes. Avoid warning about unknown attribute.
141 * These are parsed by our shader translation tool. */
142
143/* To be used on struct. Means the layout is to be used with uniform or storage buffers. */
144# define host_shared
145
146# endif
147#endif
int32_t bool32_t
#define 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
const T & operator()() const