Blender
V4.3
source
blender
gpu
vulkan
tests
vk_memory_layout_test.cc
Go to the documentation of this file.
1
/* SPDX-FileCopyrightText: 2023 Blender Authors
2
*
3
* SPDX-License-Identifier: Apache-2.0 */
4
5
#include "testing/testing.h"
6
7
#include "
vk_memory_layout.hh
"
8
9
namespace
blender::gpu
{
10
11
template
<
typename
Layout>
12
static
void
def_attr
(
const
shader::Type
type,
13
const
int
array_size,
14
const
uint32_t
expected_alignment,
15
const
uint32_t
expected_reserve,
16
uint32_t
*r_offset)
17
{
18
align<Layout>
(type, array_size, r_offset);
19
EXPECT_EQ
(*r_offset, expected_alignment);
20
reserve<Layout>
(type, array_size, r_offset);
21
EXPECT_EQ
(*r_offset, expected_reserve);
22
}
23
24
TEST
(std140, fl)
25
{
26
uint32_t
offset = 0;
27
28
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 0, 4, &offset);
29
30
align_end_of_struct<Std140>
(&offset);
31
EXPECT_EQ
(offset, 16);
32
}
33
34
TEST
(std140, _2fl)
35
{
36
uint32_t
offset = 0;
37
38
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 0, 4, &offset);
39
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 4, 8, &offset);
40
41
align_end_of_struct<Std140>
(&offset);
42
EXPECT_EQ
(offset, 16);
43
}
44
45
TEST
(std140, _3fl)
46
{
47
uint32_t
offset = 0;
48
49
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 0, 4, &offset);
50
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 4, 8, &offset);
51
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 8, 12, &offset);
52
53
align_end_of_struct<Std140>
(&offset);
54
EXPECT_EQ
(offset, 16);
55
}
56
57
TEST
(std140, _4fl)
58
{
59
uint32_t
offset = 0;
60
61
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 0, 4, &offset);
62
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 4, 8, &offset);
63
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 8, 12, &offset);
64
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 12, 16, &offset);
65
66
align_end_of_struct<Std140>
(&offset);
67
EXPECT_EQ
(offset, 16);
68
}
69
70
TEST
(std140, fl2)
71
{
72
uint32_t
offset = 0;
73
74
def_attr<Std140>
(
shader::Type::FLOAT
, 2, 0, 32, &offset);
75
76
align_end_of_struct<Std140>
(&offset);
77
EXPECT_EQ
(offset, 32);
78
}
79
80
TEST
(std140, fl_fl2)
81
{
82
uint32_t
offset = 0;
83
84
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 0, 4, &offset);
85
def_attr<Std140>
(
shader::Type::FLOAT
, 2, 16, 48, &offset);
86
87
align_end_of_struct<Std140>
(&offset);
88
EXPECT_EQ
(offset, 48);
89
}
90
91
TEST
(std140, fl_vec2)
92
{
93
uint32_t
offset = 0;
94
95
def_attr<Std140>
(
shader::Type::FLOAT
, 0, 0, 4, &offset);
96
def_attr<Std140>
(
shader::Type::VEC2
, 0, 8, 16, &offset);
97
98
align_end_of_struct<Std140>
(&offset);
99
EXPECT_EQ
(offset, 16);
100
}
101
102
TEST
(std140, gpu_shader_2D_widget_base)
103
{
104
uint32_t
offset = 0;
105
106
def_attr<Std140>
(
shader::Type::VEC4
, 12, 0, 192, &offset);
107
def_attr<Std140>
(
shader::Type::MAT4
, 0, 192, 256, &offset);
108
def_attr<Std140>
(
shader::Type::VEC3
, 0, 256, 268, &offset);
109
def_attr<Std140>
(
shader::Type::BOOL
, 0, 268, 272, &offset);
110
111
align_end_of_struct<Std140>
(&offset);
112
EXPECT_EQ
(offset, 272);
113
}
114
115
TEST
(std430, overlay_grid)
116
{
117
uint32_t
offset = 0;
118
119
def_attr<Std430>
(
shader::Type::VEC3
, 0, 0, 12, &offset);
120
def_attr<Std430>
(
shader::Type::INT
, 0, 12, 16, &offset);
121
122
align_end_of_struct<Std430>
(&offset);
123
EXPECT_EQ
(offset, 16);
124
}
125
126
TEST
(std430, simple_lighting)
127
{
128
uint32_t
offset = 0;
129
130
def_attr<Std430>
(
shader::Type::MAT4
, 0, 0, 64, &offset);
131
def_attr<Std430>
(
shader::Type::MAT3
, 0, 64, 112, &offset);
132
133
align_end_of_struct<Std430>
(&offset);
134
EXPECT_EQ
(offset, 112);
135
}
136
137
}
// namespace blender::gpu
EXPECT_EQ
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
blender::gpu::shader::Type
Type
Definition
GPU_common_types.hh:78
blender::gpu::shader::Type::MAT3
@ MAT3
blender::gpu::shader::Type::MAT4
@ MAT4
blender::gpu::shader::Type::INT
@ INT
blender::gpu::shader::Type::VEC2
@ VEC2
blender::gpu::shader::Type::VEC3
@ VEC3
blender::gpu::shader::Type::BOOL
@ BOOL
blender::gpu::shader::Type::FLOAT
@ FLOAT
blender::gpu::shader::Type::VEC4
@ VEC4
blender::gpu
Definition
blf_internal_types.hh:23
blender::gpu::reserve
static void reserve(const shader::Type type, int32_t array_size, uint32_t *r_offset)
Definition
vk_memory_layout.hh:102
blender::gpu::TEST
TEST(std140, fl)
Definition
vk_memory_layout_test.cc:24
blender::gpu::def_attr
static void def_attr(const shader::Type type, const int array_size, const uint32_t expected_alignment, const uint32_t expected_reserve, uint32_t *r_offset)
Definition
vk_memory_layout_test.cc:12
blender::gpu::align_end_of_struct
static void align_end_of_struct(uint32_t *r_offset)
Definition
vk_memory_layout.hh:115
blender::gpu::align
static void align(const shader::Type &type, const int32_t array_size, uint32_t *r_offset)
Definition
vk_memory_layout.hh:77
uint32_t
unsigned int uint32_t
Definition
stdint.h:80
vk_memory_layout.hh
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0