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
8
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,
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. */
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
197 {
198 this->value.u = value;
199 }
200
202 {
203 this->value.i = value;
204 }
205
207 {
208 this->value.f = value;
209 }
210
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)