Blender V4.3
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
9namespace blender::gpu {
10
11template<typename Layout>
12static 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
24TEST(std140, fl)
25{
26 uint32_t offset = 0;
27
28 def_attr<Std140>(shader::Type::FLOAT, 0, 0, 4, &offset);
29
31 EXPECT_EQ(offset, 16);
32}
33
34TEST(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
42 EXPECT_EQ(offset, 16);
43}
44
45TEST(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
54 EXPECT_EQ(offset, 16);
55}
56
57TEST(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
67 EXPECT_EQ(offset, 16);
68}
69
70TEST(std140, fl2)
71{
72 uint32_t offset = 0;
73
74 def_attr<Std140>(shader::Type::FLOAT, 2, 0, 32, &offset);
75
77 EXPECT_EQ(offset, 32);
78}
79
80TEST(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
88 EXPECT_EQ(offset, 48);
89}
90
91TEST(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
99 EXPECT_EQ(offset, 16);
100}
101
102TEST(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
112 EXPECT_EQ(offset, 272);
113}
114
115TEST(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
123 EXPECT_EQ(offset, 16);
124}
125
126TEST(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
134 EXPECT_EQ(offset, 112);
135}
136
137} // namespace blender::gpu
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
static void reserve(const shader::Type type, int32_t array_size, uint32_t *r_offset)
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)
static void align_end_of_struct(uint32_t *r_offset)
static void align(const shader::Type &type, const int32_t array_size, uint32_t *r_offset)
unsigned int uint32_t
Definition stdint.h:80