Blender V4.3
GPU_common_types.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11#include "BLI_string_ref.hh"
12
34
55
70
75
77
78enum class Type {
79 /* Types supported natively across all GPU back-ends. */
80 FLOAT = 0,
81 VEC2,
82 VEC3,
83 VEC4,
84 MAT3,
85 MAT4,
86 UINT,
87 UVEC2,
88 UVEC3,
89 UVEC4,
90 INT,
91 IVEC2,
92 IVEC3,
93 IVEC4,
94 BOOL,
95 /* Additionally supported types to enable data optimization and native
96 * support in some GPU back-ends.
97 * NOTE: These types must be representable in all APIs. E.g. `VEC3_101010I2` is aliased as vec3
98 * in the GL back-end, as implicit type conversions from packed normal attribute data to vec3 is
99 * supported. UCHAR/CHAR types are natively supported in Metal and can be used to avoid
100 * additional data conversions for `GPU_COMP_U8` vertex attributes. */
102 UCHAR,
103 UCHAR2,
104 UCHAR3,
105 UCHAR4,
106 CHAR,
107 CHAR2,
108 CHAR3,
109 CHAR4,
110 USHORT,
111 USHORT2,
112 USHORT3,
113 USHORT4,
114 SHORT,
115 SHORT2,
116 SHORT3,
117 SHORT4
118};
119
121{
122 switch (type) {
123 case Type::FLOAT:
124 case Type::UINT:
125 case Type::INT:
126 case Type::BOOL:
127 return 1;
128 case Type::VEC2:
129 case Type::UVEC2:
130 case Type::IVEC2:
131 return 2;
132 case Type::VEC3:
133 case Type::UVEC3:
134 case Type::IVEC3:
135 return 3;
136 case Type::VEC4:
137 case Type::UVEC4:
138 case Type::IVEC4:
139 return 4;
140 case Type::MAT3:
141 return 9;
142 case Type::MAT4:
143 return 16;
144 /* Alias special types. */
145 case Type::UCHAR:
146 case Type::USHORT:
147 return 1;
148 case Type::UCHAR2:
149 case Type::USHORT2:
150 return 2;
151 case Type::UCHAR3:
152 case Type::USHORT3:
153 return 3;
154 case Type::UCHAR4:
155 case Type::USHORT4:
156 return 4;
157 case Type::CHAR:
158 case Type::SHORT:
159 return 1;
160 case Type::CHAR2:
161 case Type::SHORT2:
162 return 2;
163 case Type::CHAR3:
164 case Type::SHORT3:
165 return 3;
166 case Type::CHAR4:
167 case Type::SHORT4:
168 return 4;
170 return 3;
171 }
173 return -1;
174}
175
177 struct Value {
178 union {
181 float f;
182 };
183
184 inline bool operator==(const Value &other) const
185 {
186 return u == other.u;
187 }
188 };
189
193
195
196 SpecializationConstant(const char *name, uint32_t value) : type(Type::UINT), name(name)
197 {
198 this->value.u = value;
199 }
200
201 SpecializationConstant(const char *name, int value) : type(Type::INT), name(name)
202 {
203 this->value.i = value;
204 }
205
206 SpecializationConstant(const char *name, float value) : type(Type::FLOAT), name(name)
207 {
208 this->value.f = value;
209 }
210
211 SpecializationConstant(const char *name, bool value) : type(Type::BOOL), name(name)
212 {
213 this->value.u = value ? 1 : 0;
214 }
215
216 inline bool operator==(const SpecializationConstant &b) const
217 {
218 return this->type == b.type && this->name == b.name && this->value == b.value;
219 }
220};
221
222} // namespace blender::gpu::shader
#define BLI_assert_unreachable()
Definition BLI_assert.h:97
#define BLI_INLINE
@ GPU_LOADACTION_LOAD
@ GPU_LOADACTION_DONT_CARE
@ GPU_LOADACTION_CLEAR
eGPUStoreOp
@ GPU_STOREACTION_STORE
@ GPU_STOREACTION_DONT_CARE
eGPUFrontFace
@ GPU_COUNTERCLOCKWISE
@ GPU_CLOCKWISE
GPUAttachmentState
@ GPU_ATTACHMENT_WRITE
@ GPU_ATTACHMENT_READ
@ GPU_ATTACHMENT_IGNORE
local_group_size(16, 16) .push_constant(Type b
BLI_INLINE int to_component_count(const Type &type)
unsigned int uint32_t
Definition stdint.h:80
signed int int32_t
Definition stdint.h:77
SpecializationConstant(const char *name, int value)
SpecializationConstant(const char *name, float value)
bool operator==(const SpecializationConstant &b) const
SpecializationConstant(const char *name, uint32_t value)
SpecializationConstant(const char *name, bool value)