Blender V4.5
GPU_vertex_format.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2016 by Mike Erwin. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#pragma once
12
13#include "BLI_assert.h"
14#include "BLI_compiler_compat.h"
15#include "BLI_string_ref.hh"
16#include "BLI_sys_types.h"
17
18#include "GPU_format.hh"
19
20namespace blender::gpu {
21
22enum class VertAttrType : uint8_t {
24
25#define DECLARE(a, b, c, blender_enum, d, e, f, g, h) blender_enum = int(DataFormat::blender_enum),
26
27#define GPU_VERTEX_FORMAT_EXPAND(impl) \
28 SNORM_8_8_8_8_(impl) \
29\
30 SNORM_16_16_(impl) \
31 SNORM_16_16_16_16_(impl) \
32\
33 UNORM_8_8_8_8_(impl) \
34\
35 UNORM_16_16_(impl) \
36 UNORM_16_16_16_16_(impl) \
37\
38 SINT_8_8_8_8_(impl) \
39\
40 SINT_16_16_(impl) \
41 SINT_16_16_16_16_(impl) \
42\
43 SINT_32_(impl) \
44 SINT_32_32_(impl) \
45 SINT_32_32_32_(impl) \
46 SINT_32_32_32_32_(impl) \
47\
48 UINT_8_8_8_8_(impl) \
49\
50 UINT_16_16_(impl) \
51 UINT_16_16_16_16_(impl) \
52\
53 UINT_32_(impl) \
54 UINT_32_32_(impl) \
55 UINT_32_32_32_(impl) \
56 UINT_32_32_32_32_(impl) \
57\
58 SFLOAT_32_(impl) \
59 SFLOAT_32_32_(impl) \
60 SFLOAT_32_32_32_(impl) \
61 SFLOAT_32_32_32_32_(impl) \
62\
63 SNORM_10_10_10_2_(impl) \
64 UNORM_10_10_10_2_(impl) \
65\
66 /* Legacy format unsupported by Metal and Vulkan. To be phased out. */ \
67 SINT_TO_FLT_32_(impl) \
68 SINT_TO_FLT_32_32_(impl) \
69 SINT_TO_FLT_32_32_32_(impl) \
70 SINT_TO_FLT_32_32_32_32_(impl) \
71\
72 /* UFLOAT_11_11_10_(impl) Available on Metal (and maybe VK) but not on GL. */ \
73 /* UFLOAT_9_9_9_EXP_5_(impl) Available on Metal (and maybe VK) but not on GL. */
74
76#undef DECLARE
77
78#define DECLARE(a, b, c, blender_enum, d, e, f, g, h) \
79 blender_enum##_DEPRECATED = int(DataFormat::blender_enum),
80
81/* Deprecated formats. To be removed in 5.0. Needed for python shaders. */
82#define GPU_VERTEX_DEPRECATED_FORMAT_EXPAND(impl) \
83 SNORM_8_(impl) \
84 SNORM_8_8_(impl) \
85 SNORM_8_8_8_(impl) \
86 SNORM_16_(impl) \
87 SNORM_16_16_16_(impl) \
88 UNORM_8_(impl) \
89 UNORM_8_8_(impl) \
90 UNORM_8_8_8_(impl) \
91 UNORM_16_(impl) \
92 UNORM_16_16_16_(impl) \
93 SINT_8_(impl) \
94 SINT_8_8_(impl) \
95 SINT_8_8_8_(impl) \
96 SINT_16_(impl) \
97 SINT_16_16_16_(impl) \
98 UINT_8_(impl) \
99 UINT_8_8_(impl) \
100 UINT_8_8_8_(impl) \
101 UINT_16_(impl) \
102 UINT_16_16_16_(impl)
103
105
106#undef DECLARE
107};
108
110{
111 return DataFormat(int(format));
112}
113
114} // namespace blender::gpu
115
116struct GPUShader;
117
118constexpr static int GPU_VERT_ATTR_MAX_LEN = 16;
119constexpr static int GPU_VERT_ATTR_MAX_NAMES = 6;
120constexpr static int GPU_VERT_ATTR_NAMES_BUF_LEN = 256;
121constexpr static int GPU_VERT_FORMAT_MAX_NAMES = 63; /* More than enough, actual max is ~30. */
122/* Computed as GPU_VERT_ATTR_NAMES_BUF_LEN / 30 (actual max format name). */
123constexpr static int GPU_MAX_SAFE_ATTR_NAME = 12;
124
140
144 GPU_FETCH_INT_TO_FLOAT_UNIT, /* 127 (ubyte) -> 0.5 (and so on for other int types) */
145 /* Warning! adjust GPUVertAttr if changing. */
146};
147
149 /* To replace fetch_mode, comp_type, comp_len, size. */
151#ifndef NO_LEGACY_VERT_TYPE
152 /* GPUVertFetchMode */
154 /* GPUVertCompType */
156 /* 1 to 4 or 8 or 12 or 16 */
158 /* size in bytes, 1 to 64 */
160 /* WORKAROUND: Allow casting inside pyGPU attr_fill. To be removed with 5.0. */
162#endif
163 /* from beginning of vertex, in bytes */
164 uint8_t offset;
165 /* up to GPU_VERT_ATTR_MAX_NAMES */
166 uint8_t name_len;
168};
169
171 "We use uchar as index inside the name buffer "
172 "so GPU_VERT_ATTR_NAMES_BUF_LEN needs to be "
173 "smaller than GPUVertFormat->name_offset and "
174 "GPUVertAttr->names maximum value");
175
193
195void GPU_vertformat_copy(GPUVertFormat *dest, const GPUVertFormat &src);
196void GPU_vertformat_from_shader(GPUVertFormat *format, const GPUShader *shader);
197
201
207 const GPUVertCompType comp_type,
208 const uint comp_len,
209 const GPUVertFetchMode fetch_mode);
210
223
239
241
243 const GPUVertAttr *attr,
244 uint n_idx)
245{
246 return format->names + attr->names[n_idx];
247}
248
253void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr, const char *new_name);
254
259void GPU_vertformat_safe_attr_name(blender::StringRef attr_name, char *r_safe_name, uint max_len);
#define BLI_STATIC_ASSERT(a, msg)
Definition BLI_assert.h:83
#define BLI_INLINE
unsigned char uchar
unsigned int uint
#define DECLARE(a, b, c, blender_enum, d, e, f, g, h)
void GPU_vertformat_attr_rename(GPUVertFormat *format, int attr, const char *new_name)
static constexpr int GPU_VERT_ATTR_MAX_LEN
BLI_INLINE const char * GPU_vertformat_attr_name_get(const GPUVertFormat *format, const GPUVertAttr *attr, uint n_idx)
int GPU_vertformat_attr_id_get(const GPUVertFormat *, blender::StringRef name)
static constexpr int GPU_VERT_ATTR_MAX_NAMES
GPUVertFetchMode
@ GPU_FETCH_FLOAT
@ GPU_FETCH_INT_TO_FLOAT_UNIT
@ GPU_FETCH_INT
static constexpr int GPU_VERT_FORMAT_MAX_NAMES
void GPU_vertformat_alias_add(GPUVertFormat *, blender::StringRef alias)
#define GPU_VERTEX_DEPRECATED_FORMAT_EXPAND(impl)
void GPU_vertformat_safe_attr_name(blender::StringRef attr_name, char *r_safe_name, uint max_len)
static constexpr int GPU_VERT_ATTR_NAMES_BUF_LEN
void GPU_vertformat_multiload_enable(GPUVertFormat *format, int load_count)
void GPU_vertformat_clear(GPUVertFormat *)
void GPU_vertformat_copy(GPUVertFormat *dest, const GPUVertFormat &src)
uint GPU_vertformat_attr_add(GPUVertFormat *, blender::StringRef name, GPUVertCompType, uint comp_len, GPUVertFetchMode)
static constexpr int GPU_MAX_SAFE_ATTR_NAME
#define GPU_VERTEX_FORMAT_EXPAND(impl)
GPUVertFormat GPU_vertformat_from_attribute(blender::StringRef name, const GPUVertCompType comp_type, const uint comp_len, const GPUVertFetchMode fetch_mode)
void GPU_vertformat_deinterleave(GPUVertFormat *format)
void GPU_vertformat_from_shader(GPUVertFormat *format, const GPUShader *shader)
GPUVertCompType
@ GPU_COMP_U16
@ GPU_COMP_MAX
@ GPU_COMP_I10
@ GPU_COMP_F32
@ GPU_COMP_I32
@ GPU_COMP_I8
@ GPU_COMP_U32
@ GPU_COMP_I16
@ GPU_COMP_U8
format
constexpr DataFormat to_data_format(TextureFormat format)
uchar names[GPU_VERT_ATTR_MAX_NAMES]
blender::gpu::VertAttrType format
GPUVertAttr attrs[GPU_VERT_ATTR_MAX_LEN]
char names[GPU_VERT_ATTR_NAMES_BUF_LEN]