chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
26 / 27
96.3%
Branches:
43 / 84
51.2%
Functions:
4 / 4, 4 excl
100.0%

scene/tables/meshes.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <compare>
5 #include <cstdint>
6 #include <map>
7 #include <memory>
8 #include <optional>
9 #include <set>
10 #include <unordered_map>
11 #include <utility>
12 #include <vector>
13
14 #include "chrono_batch_render/algorithms/radix_sort.h"
15 #include "chrono_batch_render/algorithms/scan.h"
16 #include "chrono_batch_render/bvh/builder.h"
17 #include "chrono_batch_render/device/buffer.h"
18 #include "chrono_batch_render/device/program.h"
19 #include "chrono_batch_render/device/ref.h"
20 #include "chrono_batch_render/scene/records/meshes.h"
21 #include "chrono_batch_render/scene/tables/storage.h"
22 #include "chrono_batch_render/scene/tables/table.h"
23 #include "chrono_batch_render/stage/structure/structure.h"
24
25 namespace chrono::batch_render {
26
27
1/1
✓ Branch 1 taken 399 times.
399 struct GeometryStats {
28 uint32_t meshes = 0;
29 uint32_t shapes = 0;
30 uint32_t topologies = 0;
31 uint32_t built = 0;
32 uint32_t refit = 0;
33 uint32_t triangulated = 0;
34 };
35
36
2/6
<unknown function 27>:
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
<unknown function 36>:
✗ Branch 0 not taken.
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
✗ Branch 1 not taken.
39 struct MeshShape {
37 Ref<bvh::Blas> blas;
38 uint32_t points = 0;
39 uint32_t triangles = 0;
40 uint32_t users = 0;
41 };
42
43 class MeshTable : public RenderTable {
44 public:
45 399 MeshTable(Structure& structure, bvh::Builder& builder)
46
1/3
✓ Branch 1 taken 399 times.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
399 : m_structure(structure), m_builder(builder) {}
47
48 1013 std::string_view Name() const override {
49 1013 return "geometry";
50 }
51
52 std::span<const ColumnRef> Inputs() const override;
53 std::span<const TableId> TableOutputs() const override;
54 void Describe(RenderTables& tables) const override;
55 void Prepare() override;
56 void Run(const ChangeSet& changes, TableVersions& versions) override;
57
58 const GeometryStats& Stats() const {
59
1/1
✓ Branch 1 taken 1 time.
1 return m_stats;
60 }
61
62 std::optional<MeshShape> Find(uint32_t prim) const;
63
64 40 const MeshRecord& Record(uint32_t meshRow) const {
65
11/19
<unknown function 64>:
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 3 times.
chrono::batch_render::MeshTable::MeshTable(chrono::batch_render::Structure&, chrono::batch_render::bvh::Builder&):
✓ Branch 0 taken 1 time.
✓ Branch 0 taken 31 times.
✗ Branch 1 not taken.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 time.
49 return m_records.Row(meshRow);
66 }
67
68 void Hold(std::vector<Ref<const RefCounted>>& held) const override;
69
70 private:
71 struct TopologyKey {
72 1772 uint64_t indices = 0;
73 1732 uint32_t indexCount = 0;
74 1732 uint64_t counts = 0;
75 1732 uint32_t faceCount = 0;
76 1732 uint64_t holes = 0;
77 1732 uint32_t holeCount = 0;
78
79
16/36
✓ Branch 0 taken 40 times.
✓ Branch 1 taken 1732 times.
✓ Branch 2 taken 34 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 40 times.
✓ Branch 5 taken 1732 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1732 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 1732 times.
✗ Branch 12 not taken.
✓ Branch 13 taken 1732 times.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✓ Branch 17 taken 1732 times.
✗ Branch 18 not taken.
✓ Branch 19 taken 1732 times.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✓ Branch 23 taken 1732 times.
✗ Branch 24 not taken.
✓ Branch 25 taken 1732 times.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✓ Branch 29 taken 1732 times.
✗ Branch 30 not taken.
✓ Branch 31 taken 1732 times.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✓ Branch 35 taken 1732 times.
1772 auto operator<=>(const TopologyKey&) const = default;
80 };
81
82 struct ShapeKey {
83 522 uint64_t points = 0;
84 434 uint32_t pointCount = 0;
85 434 TopologyKey topology;
86
87
10/14
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 434 times.
✓ Branch 2 taken 69 times.
✓ Branch 3 taken 19 times.
✓ Branch 4 taken 88 times.
✓ Branch 5 taken 434 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 434 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 434 times.
✓ Branch 12 taken 4 times.
✓ Branch 13 taken 430 times.
522 auto operator<=>(const ShapeKey&) const = default;
88 };
89
90 98 struct Topology {
91 ArrayRef triangles;
92 ArrayRef corners;
93 ArrayRef faces;
94 ArrayRef starts;
95 ArrayRef adjacency;
96 uint32_t triangleCount = 0;
97 uint32_t covered = 0;
98 uint32_t users = 0;
99 bool ready = false;
100 };
101
102
1/4
chrono::batch_render::MeshTable::MeshTable(chrono::batch_render::Structure&, chrono::batch_render::bvh::Builder&):
✓ Branch 0 taken 111 times.
✗ Branch 1 not taken.
chrono::batch_render::MeshTable::ShapeKey::operator<=>(chrono::batch_render::MeshTable::ShapeKey const&) const:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
222 struct Shape {
103 Ref<bvh::Blas> blas;
104 ArrayRef normals;
105 ArrayRef bounds;
106 uint32_t pointCount = 0;
107 uint32_t users = 0;
108 uint32_t updated = 0;
109 bool build = false;
110 bool refit = false;
111 };
112
113 136 struct Mesh {
114 uint32_t prim = kNoPrim;
115 uint32_t generation = 0;
116 uint32_t pointsRow = kNoRow;
117 uint32_t meshRow = kNoRow;
118 std::optional<ShapeKey> key;
119 Shape* shape = nullptr;
120 };
121
122 void Place(uint32_t prim);
123 void Settle();
124 void Prune();
125 void Triangulate();
126 void Release(Mesh& mesh);
127 ShapeKey Key(const Mesh& mesh) const;
128 void Link(const Mesh& mesh);
129 void Update(std::vector<uint32_t>& updated);
130
131 Structure& m_structure;
132 bvh::Builder& m_builder;
133 device::Program& Kernels();
134
135 Ref<device::Program> m_program;
136 std::unique_ptr<algorithms::Scan> m_scan;
137 std::unique_ptr<algorithms::RadixSort> m_sort;
138 uint32_t m_scanCapacity = 0;
139 uint32_t m_sortCapacity = 0;
140 std::vector<std::pair<uint32_t, ShapeKey>> m_placing;
141 std::unordered_map<uint32_t, Mesh> m_meshes;
142 std::unordered_map<uint32_t, uint32_t> m_byPointsRow;
143 std::unordered_map<uint32_t, uint32_t> m_byMeshRow;
144 std::map<TopologyKey, Topology> m_topologies;
145 std::map<ShapeKey, Shape> m_shapes;
146 GeometryStats m_stats;
147 RecordTable<MeshRecord> m_records{"mesh records"};
148 std::vector<uint32_t> m_relinked;
149 bool m_stale = false;
150 };
151
152 }
153