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:
52 of 116, 0 excluded
44.8%

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 11 → 5 taken 35 times.
✓ Branch 11 → 12 taken 14 times.
49 for (const auto& att : attributes)
17 {
18
3/4
✓ Branch 6 → 7 taken 35 times.
✗ Branch 6 → 15 not taken.
✓ Branch 7 → 8 taken 1 time.
✓ Branch 7 → 9 taken 34 times.
35 if (seen.insert(att.type).second == false)
19 {
20
1/2
✓ Branch 8 → 9 taken 1 time.
✗ Branch 8 → 15 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 8 → 4 taken 27 times.
✓ Branch 8 → 9 taken 12 times.
39 for (const auto& e: elements)
38 {
39
1/2
✓ Branch 5 → 6 taken 27 times.
✗ Branch 5 → 10 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 28 → 4 taken 31 times.
✓ Branch 28 → 29 taken 12 times.
43 for (const auto& e: elements)
57 {
58
1/2
✓ Branch 5 → 6 taken 31 times.
✗ Branch 5 → 66 not taken.
31 const auto found = l.indices.find(e.type);
59
7/10
✓ Branch 8 → 9 taken 27 times.
✓ Branch 8 → 10 taken 4 times.
✓ Branch 11 → 12 taken 4 times.
✓ Branch 11 → 18 taken 27 times.
✓ Branch 12 → 13 taken 4 times.
✗ Branch 12 → 66 not taken.
✓ Branch 13 → 14 taken 4 times.
✗ Branch 13 → 18 not taken.
✗ Branch 15 → 16 not taken.
✓ Branch 15 → 57 taken 4 times.
35 ASSERT(found != l.indices.end() && "layout wasn't added to the compilation list");
60
1/2
✓ Branch 20 → 21 taken 27 times.
✗ Branch 20 → 26 not taken.
27 if (found != l.indices.end())
61 {
62 27 list.push_back({e.type, e.name, found->second});
63 }
64 }
65
66
1/2
✗ Branch 30 → 31 not taken.
✓ Branch 30 → 51 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 12 return {list, l.debug_types};
74
4/18
✓ Branch 21 → 22 taken 27 times.
✗ Branch 21 → 65 not taken.
✓ Branch 23 → 24 taken 27 times.
✗ Branch 23 → 60 not taken.
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 76 not taken.
✗ Branch 48 → 49 not taken.
✗ Branch 48 → 71 not taken.
✓ Branch 51 → 52 taken 12 times.
✗ Branch 51 → 80 not taken.
✓ Branch 52 → 53 taken 12 times.
✗ Branch 52 → 77 not taken.
✗ Branch 62 → 63 not taken.
✗ Branch 62 → 64 not taken.
✗ Branch 73 → 74 not taken.
✗ Branch 73 → 75 not taken.
✗ Branch 77 → 78 not taken.
✗ Branch 77 → 79 not taken.
43 }
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 → 27 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 → 22 not taken.
22 list.push_back({first, second});
85 }
86
87
1/2
✓ Branch 15 → 16 taken 9 times.
✗ Branch 15 → 27 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 9 return {list, l.debug_types};
97
2/6
✓ Branch 16 → 17 taken 9 times.
✗ Branch 16 → 27 not taken.
✓ Branch 17 → 18 taken 9 times.
✗ Branch 17 → 24 not taken.
✗ Branch 24 → 25 not taken.
✗ Branch 24 → 26 not taken.
9 }
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 11 → 5 taken 2 times.
✓ Branch 11 → 12 taken 9 times.
11 for (const auto type: list.base_layout)
111 {
112
1/2
✓ Branch 7 → 8 taken 2 times.
✗ Branch 7 → 37 not taken.
2 indices.insert({type, next_index});
113 2 next_index += calculate_shader_attribute_size(type);
114 }
115
116
2/2
✓ Branch 26 → 14 taken 22 times.
✓ Branch 26 → 27 taken 9 times.
31 for (const auto type: list.indices)
117 {
118 // already in base layout, don't add again
119
3/4
✓ Branch 16 → 17 taken 22 times.
✗ Branch 16 → 39 not taken.
✓ Branch 18 → 19 taken 2 times.
✓ Branch 18 → 20 taken 20 times.
22 if (indices.find(type) != indices.end())
120 {
121 2 continue;
122 }
123
124
1/2
✓ Branch 21 → 22 taken 20 times.
✗ Branch 21 → 41 not taken.
20 indices.insert({type, next_index});
125 20 next_index += calculate_shader_attribute_size(type);
126 }
127
128 18 return {indices, {list.indices.begin(), list.indices.end()}, next_index};
129
2/6
✓ Branch 27 → 28 taken 9 times.
✗ Branch 27 → 49 not taken.
✓ Branch 32 → 33 taken 9 times.
✗ Branch 32 → 43 not taken.
✗ Branch 46 → 47 not taken.
✗ Branch 46 → 48 not taken.
18 }
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 → 37 not taken.
9 auto list = VertexTypeList{base_layout};
136
137
2/2
✓ Branch 22 → 5 taken 12 times.
✓ Branch 22 → 23 taken 9 times.
21 for (const auto& d: descriptions)
138 {
139
1/2
✓ Branch 6 → 7 taken 12 times.
✗ Branch 6 → 33 not taken.
12 const auto duplicates = find_duplicates(d);
140
2/10
✓ Branch 8 → 9 taken 12 times.
✗ Branch 8 → 10 not taken.
✗ Branch 11 → 12 not taken.
✓ Branch 11 → 18 taken 12 times.
✗ Branch 12 → 13 not taken.
✗ Branch 12 → 31 not taken.
✗ Branch 13 → 14 not taken.
✗ Branch 13 → 18 not taken.
✗ Branch 15 → 16 not taken.
✗ Branch 15 → 28 not taken.
12 ASSERT(duplicates.empty() && "ShaderVertexAttributes has duplicate types");
141
1/2
✓ Branch 18 → 19 taken 12 times.
✗ Branch 18 → 31 not taken.
12 list.add(d);
142 12 }
143
144
1/2
✓ Branch 23 → 24 taken 9 times.
✗ Branch 23 → 35 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