GCC Code Coverage Report


./
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
61 of 63, 0 excluded
96.8%
Functions:
10 of 10, 0 excluded
100.0%
Branches:
57 of 128, 0 excluded
44.5%

libs/core/src/eu/core/vertex_layout.cc
Line Branch Exec Source
1 #include "eu/core/vertex_layout.h"
2
3 #include <algorithm>
4
5 #include "eu/assert/assert.h"
6
7 namespace eu::core
8 {
9
10
11 14 std::vector<VertexType> find_duplicates(const ShaderVertexAttributes& attributes)
12 {
13 14 std::vector<VertexType> ret;
14
15 14 std::set<VertexType> seen;
16
2/2
✓ Branch 19 → 5 taken 35 times.
✓ Branch 19 → 20 taken 14 times.
63 for (const auto& att : attributes)
17 {
18
3/4
✓ Branch 7 → 8 taken 35 times.
✗ Branch 7 → 23 not taken.
✓ Branch 8 → 9 taken 1 time.
✓ Branch 8 → 10 taken 34 times.
35 if (seen.insert(att.type).second == false)
19 {
20
1/2
✓ Branch 9 → 10 taken 1 time.
✗ Branch 9 → 23 not taken.
1 ret.emplace_back(att.type);
21 }
22 }
23
24 14 return ret;
25 14 }
26
27 /** A list of things we need to extract from the Geom when compiling */
28 struct VertexTypeList
29 {
30 9 explicit VertexTypeList(const std::vector<VertexType>& a_base_layout)
31 9 : base_layout(a_base_layout)
32 {
33 9 }
34
35 12 void add(const ShaderVertexAttributes& elements)
36 {
37
2/2
✓ Branch 16 → 4 taken 27 times.
✓ Branch 16 → 17 taken 12 times.
51 for (const auto& e: elements)
38 {
39
1/2
✓ Branch 6 → 7 taken 27 times.
✗ Branch 6 → 18 not taken.
27 indices.insert(e.type);
40 }
41 12 }
42
43 std::vector<VertexType> base_layout;
44 std::set<VertexType> indices;
45 };
46
47 16 CompiledShaderVertexAttributes compile_shader_layout(
48 const CompiledVertexTypeList& l,
49 const ShaderVertexAttributes& elements,
50 std::optional<InstanceProp> instance_prop,
51 std::optional<int> start_index
52 )
53 {
54 16 std::vector<CompiledVertexElement> list;
55
56
2/2
✓ Branch 38 → 4 taken 31 times.
✓ Branch 38 → 39 taken 12 times.
59 for (const auto& e: elements)
57 {
58
1/2
✓ Branch 6 → 7 taken 31 times.
✗ Branch 6 → 83 not taken.
31 const auto found = l.indices.find(e.type);
59
7/10
✓ Branch 9 → 10 taken 27 times.
✓ Branch 9 → 11 taken 4 times.
✓ Branch 12 → 13 taken 4 times.
✓ Branch 12 → 19 taken 27 times.
✓ Branch 13 → 14 taken 4 times.
✗ Branch 13 → 83 not taken.
✓ Branch 14 → 15 taken 4 times.
✗ Branch 14 → 19 not taken.
✗ Branch 16 → 17 not taken.
✓ Branch 16 → 74 taken 4 times.
35 ASSERT(found != l.indices.end() && "layout wasn't added to the compilation list");
60
1/2
✓ Branch 21 → 22 taken 27 times.
✗ Branch 21 → 29 not taken.
27 if (found != l.indices.end())
61 {
62 54 list.push_back({e.type, e.name, found->second});
63 }
64 }
65
66
1/2
✗ Branch 40 → 41 not taken.
✓ Branch 40 → 63 taken 12 times.
12 if (instance_prop.has_value())
67 {
68 // if the value was provided, it can't be less than what we have already used
69 ASSERT(start_index.has_value() == false || start_index.value() >= l.next_index);
70 list.push_back({instance_prop->type, instance_prop->name, start_index.value_or(l.next_index)});
71 }
72
73 24 return {list, l.debug_types};
74
6/24
✓ Branch 22 → 23 taken 27 times.
✗ Branch 22 → 82 not taken.
✓ Branch 24 → 25 taken 27 times.
✗ Branch 24 → 77 not taken.
✗ Branch 26 → 27 not taken.
✓ Branch 26 → 28 taken 27 times.
✗ Branch 56 → 57 not taken.
✗ Branch 56 → 93 not taken.
✗ Branch 58 → 59 not taken.
✗ Branch 58 → 88 not taken.
✗ Branch 60 → 61 not taken.
✗ Branch 60 → 62 not taken.
✓ Branch 63 → 64 taken 12 times.
✗ Branch 63 → 100 not taken.
✓ Branch 64 → 65 taken 12 times.
✗ Branch 64 → 94 not taken.
✓ Branch 66 → 67 taken 12 times.
✗ Branch 66 → 68 not taken.
✗ Branch 79 → 80 not taken.
✗ Branch 79 → 81 not taken.
✗ Branch 90 → 91 not taken.
✗ Branch 90 → 92 not taken.
✗ Branch 94 → 95 not taken.
✗ Branch 94 → 96 not taken.
82 }
75
76 [[nodiscard]]
77 9 CompiledGeomVertexAttributes get_geom_layout(const CompiledVertexTypeList& l)
78 {
79 9 std::vector<CompiledVertexElementNoName> list;
80
1/2
✓ Branch 3 → 4 taken 9 times.
✗ Branch 3 → 35 not taken.
9 list.reserve(l.indices.size());
81
82
2/2
✓ Branch 12 → 6 taken 22 times.
✓ Branch 12 → 13 taken 9 times.
31 for (const auto& [first, second]: l.indices)
83 {
84
1/2
✓ Branch 9 → 10 taken 22 times.
✗ Branch 9 → 27 not taken.
22 list.push_back({first, second});
85 }
86
87
1/2
✓ Branch 15 → 16 taken 9 times.
✗ Branch 15 → 35 not taken.
9 std::sort(
88 list.begin(),
89 list.end(),
90 27 [](const CompiledVertexElementNoName& lhs, const CompiledVertexElementNoName& rhs)
91 27 { return lhs.index < rhs.index; }
92 );
93
94 // todo(Gustav): the index property is confusing and error-prone, just remove it
95
96 18 return {list, l.debug_types};
97
3/8
✓ Branch 16 → 17 taken 9 times.
✗ Branch 16 → 35 not taken.
✓ Branch 17 → 18 taken 9 times.
✗ Branch 17 → 29 not taken.
✓ Branch 19 → 20 taken 9 times.
✗ Branch 19 → 21 not taken.
✗ Branch 29 → 30 not taken.
✗ Branch 29 → 31 not taken.
18 }
98
99 22 int calculate_shader_attribute_size(const VertexType&)
100 {
101 22 return 1;
102 }
103
104 9 CompiledVertexTypeList compile_vertex_type_list(const VertexTypeList& list)
105 {
106 9 std::map<VertexType, int> indices;
107
108 9 int next_index = 0;
109
110
2/2
✓ Branch 19 → 5 taken 2 times.
✓ Branch 19 → 20 taken 9 times.
20 for (const auto type: list.base_layout)
111 {
112
1/2
✓ Branch 8 → 9 taken 2 times.
✗ Branch 8 → 53 not taken.
2 indices.insert({type, next_index});
113 2 next_index += calculate_shader_attribute_size(type);
114 }
115
116
2/2
✓ Branch 34 → 22 taken 22 times.
✓ Branch 34 → 35 taken 9 times.
31 for (const auto type: list.indices)
117 {
118 // already in base layout, don't add again
119
3/4
✓ Branch 24 → 25 taken 22 times.
✗ Branch 24 → 55 not taken.
✓ Branch 26 → 27 taken 2 times.
✓ Branch 26 → 28 taken 20 times.
22 if (indices.find(type) != indices.end())
120 {
121 2 continue;
122 }
123
124
1/2
✓ Branch 29 → 30 taken 20 times.
✗ Branch 29 → 57 not taken.
20 indices.insert({type, next_index});
125 20 next_index += calculate_shader_attribute_size(type);
126 }
127
128 27 return {indices, {list.indices.begin(), list.indices.end()}, next_index};
129
4/10
✓ Branch 35 → 36 taken 9 times.
✗ Branch 35 → 68 not taken.
✓ Branch 40 → 41 taken 9 times.
✗ Branch 40 → 59 not taken.
✗ Branch 42 → 43 not taken.
✓ Branch 42 → 44 taken 9 times.
✓ Branch 45 → 46 taken 9 times.
✗ Branch 45 → 47 not taken.
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 64 not taken.
36 }
130
131 9 CompiledVertexTypeList compile_attribute_layouts(
132 const std::vector<VertexType>& base_layout, const std::vector<ShaderVertexAttributes>& descriptions
133 )
134 {
135
1/2
✓ Branch 2 → 3 taken 9 times.
✗ Branch 2 → 45 not taken.
9 auto list = VertexTypeList{base_layout};
136
137
2/2
✓ Branch 30 → 5 taken 12 times.
✓ Branch 30 → 31 taken 9 times.
30 for (const auto& d: descriptions)
138 {
139
1/2
✓ Branch 7 → 8 taken 12 times.
✗ Branch 7 → 41 not taken.
12 const auto duplicates = find_duplicates(d);
140
2/10
✓ Branch 9 → 10 taken 12 times.
✗ Branch 9 → 11 not taken.
✗ Branch 12 → 13 not taken.
✓ Branch 12 → 19 taken 12 times.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 39 not taken.
✗ Branch 14 → 15 not taken.
✗ Branch 14 → 19 not taken.
✗ Branch 16 → 17 not taken.
✗ Branch 16 → 36 not taken.
12 ASSERT(duplicates.empty() && "ShaderVertexAttributes has duplicate types");
141
1/2
✓ Branch 19 → 20 taken 12 times.
✗ Branch 19 → 39 not taken.
12 list.add(d);
142 12 }
143
144
1/2
✓ Branch 31 → 32 taken 9 times.
✗ Branch 31 → 43 not taken.
18 return compile_vertex_type_list(list);
145 9 }
146
147 8 CompiledVertexTypeList compile_attribute_layouts(const std::vector<ShaderVertexAttributes>& descriptions)
148 {
149
1/2
✓ Branch 3 → 4 taken 8 times.
✗ Branch 3 → 8 not taken.
8 return compile_attribute_layouts({}, descriptions);
150 }
151
152 } // namespace eu::core
153