chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
124 / 124
100.0%
Branches:
67 / 100
67.0%
Functions:
24 / 24, 2 excl
100.0%

graph/library.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <algorithm>
5 #include <cstdint>
6 #include <memory>
7 #include <mutex>
8 #include <span>
9 #include <type_traits>
10 #include <unordered_map>
11 #include <utility>
12 #include <vector>
13
14 #include "chrono_batch_render/graph/graph.h"
15
16 namespace chrono::batch_render::graph {
17
18 319 template <class Definition> class DefinitionSet {
19 public:
20
4/10
<unknown function 18>:
✗ Branch 0 not taken.
✓ Branch 1 taken 22 times.
✓ Branch 2 taken 5 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
<unknown function 20>:
✓ Branch 0 taken 91 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 34 times.
✗ Branch 3 not taken.
336 struct Entry {
21 uint32_t id = 0;
22 std::shared_ptr<const Definition> definition;
23 };
24
25 319 DefinitionSet(std::vector<Entry> entries, uint64_t version)
26 319 : m_entries(std::move(entries)), m_version(version) {}
27
28 312 std::span<const Entry> Entries() const {
29
1/1
✓ Branch 1 taken 1 time.
312 return m_entries;
30 }
31
32 79 std::shared_ptr<const Definition> Find(uint32_t id) const {
33 79 const auto found = std::ranges::lower_bound(m_entries, id, {}, &Entry::id);
34
11/18
chrono::batch_render::graph::DefinitionSet<chrono::batch_render::material::MaterialDefinition>::Find(unsigned int) const:
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
chrono::batch_render::graph::DefinitionSet<chrono::batch_render::sensor_pipeline::SensorPipelineDefinition>::Find(unsigned int) const:
✓ Branch 0 taken 69 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 69 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 69 times.
✗ Branch 5 not taken.
chrono::batch_render::graph::DefinitionSet<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Find(unsigned int) const:
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 3 times.
✗ Branch 5 not taken.
79 return found != m_entries.end() && found->id == id ? found->definition : nullptr;
35 }
36
37 1 uint64_t Version() const {
38
1/1
✓ Branch 1 taken 1 time.
1 return m_version;
39 }
40
41 private:
42 std::vector<Entry> m_entries;
43 uint64_t m_version = 0;
44 };
45
46 template <class Definition> class DefinitionLibrary {
47 public:
48 using Set = DefinitionSet<Definition>;
49
50 707 explicit DefinitionLibrary(uint32_t firstId = 0) : m_next(firstId) {}
51
52 62 template <class Make> uint32_t Intern(const ShapeKey& key, Make&& make) {
53 62 const std::lock_guard lock(m_mutex);
54
3/3
unsigned int chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::material::MaterialDefinition>::Intern<chrono::batch_render::MaterialTable::ResolveNode(unsigned int, unsigned int, std::shared_ptr<chrono::batch_render::material::MaterialNodeDefinition const>)::{lambda(unsigned int)#1}>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::MaterialTable::ResolveNode(unsigned int, unsigned int, std::shared_ptr<chrono::batch_render::material::MaterialNodeDefinition const>)::{lambda(unsigned int)#1}&&):
✓ Branch 1 taken 15 times.
unsigned int chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::sensor_pipeline::SensorPipelineDefinition>::Intern<chrono::batch_render::SensorPipelineTable::Run(chrono::batch_render::ChangeSet const&, chrono::batch_render::TableVersions&)::{lambda(unsigned int)#1}>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::SensorPipelineTable::Run(chrono::batch_render::ChangeSet const&, chrono::batch_render::TableVersions&)::{lambda(unsigned int)#1}&&):
✓ Branch 1 taken 44 times.
unsigned int chrono::batch_render::graph::DefinitionLibrary<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Intern<chrono::batch_render::graph::(anonymous namespace)::DefinitionLibraryTest_InternsEachShapeOnceWithGrowingIds_Test::TestBody()::{lambda(unsigned int)#1} const&>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::graph::(anonymous namespace)::DefinitionLibraryTest_InternsEachShapeOnceWithGrowingIds_Test::TestBody()::{lambda(unsigned int)#1} const&):
✓ Branch 1 taken 3 times.
62 const auto found = m_ids.find(key);
55
6/6
unsigned int chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::material::MaterialDefinition>::Intern<chrono::batch_render::MaterialTable::ResolveNode(unsigned int, unsigned int, std::shared_ptr<chrono::batch_render::material::MaterialNodeDefinition const>)::{lambda(unsigned int)#1}>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::MaterialTable::ResolveNode(unsigned int, unsigned int, std::shared_ptr<chrono::batch_render::material::MaterialNodeDefinition const>)::{lambda(unsigned int)#1}&&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 14 times.
unsigned int chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::sensor_pipeline::SensorPipelineDefinition>::Intern<chrono::batch_render::SensorPipelineTable::Run(chrono::batch_render::ChangeSet const&, chrono::batch_render::TableVersions&)::{lambda(unsigned int)#1}>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::SensorPipelineTable::Run(chrono::batch_render::ChangeSet const&, chrono::batch_render::TableVersions&)::{lambda(unsigned int)#1}&&):
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 38 times.
unsigned int chrono::batch_render::graph::DefinitionLibrary<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Intern<chrono::batch_render::graph::(anonymous namespace)::DefinitionLibraryTest_InternsEachShapeOnceWithGrowingIds_Test::TestBody()::{lambda(unsigned int)#1} const&>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::graph::(anonymous namespace)::DefinitionLibraryTest_InternsEachShapeOnceWithGrowingIds_Test::TestBody()::{lambda(unsigned int)#1} const&):
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 2 times.
62 if (found != m_ids.end()) {
56 8 return found->second;
57 }
58 54 const uint32_t id = m_next++;
59
3/6
unsigned int chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::material::MaterialDefinition>::Intern<chrono::batch_render::MaterialTable::ResolveNode(unsigned int, unsigned int, std::shared_ptr<chrono::batch_render::material::MaterialNodeDefinition const>)::{lambda(unsigned int)#1}>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::MaterialTable::ResolveNode(unsigned int, unsigned int, std::shared_ptr<chrono::batch_render::material::MaterialNodeDefinition const>)::{lambda(unsigned int)#1}&&):
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
unsigned int chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::sensor_pipeline::SensorPipelineDefinition>::Intern<chrono::batch_render::SensorPipelineTable::Run(chrono::batch_render::ChangeSet const&, chrono::batch_render::TableVersions&)::{lambda(unsigned int)#1}>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::SensorPipelineTable::Run(chrono::batch_render::ChangeSet const&, chrono::batch_render::TableVersions&)::{lambda(unsigned int)#1}&&):
✗ Branch 0 not taken.
✓ Branch 1 taken 38 times.
unsigned int chrono::batch_render::graph::DefinitionLibrary<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Intern<chrono::batch_render::graph::(anonymous namespace)::DefinitionLibraryTest_InternsEachShapeOnceWithGrowingIds_Test::TestBody()::{lambda(unsigned int)#1} const&>(chrono::batch_render::graph::ShapeKey const&, chrono::batch_render::graph::(anonymous namespace)::DefinitionLibraryTest_InternsEachShapeOnceWithGrowingIds_Test::TestBody()::{lambda(unsigned int)#1} const&):
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
54 m_entries.push_back({id, std::make_shared<const Definition>(make(id))});
60 108 m_ids.emplace(key, id);
61 54 m_snapshot.reset();
62 54 return id;
63 224 }
64
65 382 std::shared_ptr<const Set> Snapshot() const {
66 382 const std::lock_guard lock(m_mutex);
67
6/6
chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::material::MaterialDefinition>::Snapshot() const:
✓ Branch 0 taken 279 times.
✓ Branch 1 taken 32 times.
chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::sensor_pipeline::SensorPipelineDefinition>::Snapshot() const:
✓ Branch 0 taken 38 times.
✓ Branch 1 taken 30 times.
chrono::batch_render::graph::DefinitionLibrary<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Snapshot() const:
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
382 if (!m_snapshot) {
68
6/9
chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::material::MaterialDefinition>::Snapshot() const:
✓ Branch 1 taken 279 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 279 times.
chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::sensor_pipeline::SensorPipelineDefinition>::Snapshot() const:
✓ Branch 1 taken 38 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 38 times.
chrono::batch_render::graph::DefinitionLibrary<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Snapshot() const:
✓ Branch 1 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 2 times.
319 m_snapshot = std::make_shared<const Set>(m_entries, ++m_version);
69 }
70
3/6
chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::material::MaterialDefinition>::Snapshot() const:
✓ Branch 0 taken 311 times.
✗ Branch 1 not taken.
chrono::batch_render::graph::DefinitionLibrary<chrono::batch_render::sensor_pipeline::SensorPipelineDefinition>::Snapshot() const:
✓ Branch 0 taken 68 times.
✗ Branch 1 not taken.
chrono::batch_render::graph::DefinitionLibrary<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::Snapshot() const:
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
764 return m_snapshot;
71 382 }
72
73 private:
74 mutable std::mutex m_mutex;
75 std::unordered_map<ShapeKey, uint32_t> m_ids;
76 std::vector<typename Set::Entry> m_entries;
77 mutable std::shared_ptr<const Set> m_snapshot;
78 mutable uint64_t m_version = 0;
79 uint32_t m_next = 0;
80 };
81
82
1/4
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 template <class T> class Published {
83 public:
84 13 explicit Published(T initial = T()) : m_value(std::make_shared<const T>(std::move(initial))) {}
85
86 19334 std::shared_ptr<const T> Get() const {
87 19334 const std::lock_guard lock(m_mutex);
88
3/6
chrono::batch_render::graph::Published<chrono::batch_render::material::(anonymous namespace)::Nodes>::Get() const:
✓ Branch 0 taken 9833 times.
✗ Branch 1 not taken.
chrono::batch_render::graph::Published<chrono::batch_render::sensor_pipeline::NodeRegistry>::Get() const:
✓ Branch 0 taken 9498 times.
✗ Branch 1 not taken.
chrono::batch_render::graph::Published<std::vector<int, std::allocator<int> > >::Get() const:
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
38668 return m_value;
89 19334 }
90
91 34 template <class Edit> auto Update(Edit&& edit) {
92 34 const std::lock_guard lock(m_mutex);
93
10/10
auto chrono::batch_render::graph::Published<chrono::batch_render::material::(anonymous namespace)::Nodes>::Update<chrono::batch_render::material::RegisterClosurePrimitive(chrono::batch_render::material::ClosurePrimitive)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}>(chrono::batch_render::material::RegisterClosurePrimitive(chrono::batch_render::material::ClosurePrimitive)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}&&):
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
auto chrono::batch_render::graph::Published<chrono::batch_render::material::(anonymous namespace)::Nodes>::Update<chrono::batch_render::material::RegisterMaterialNode(chrono::batch_render::material::MaterialNodeDefinition)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}>(chrono::batch_render::material::RegisterMaterialNode(chrono::batch_render::material::MaterialNodeDefinition)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}&&):
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
auto chrono::batch_render::graph::Published<chrono::batch_render::sensor_pipeline::NodeRegistry>::Update<chrono::batch_render::sensor_pipeline::RegisterSensorPipelineNode(chrono::batch_render::sensor_pipeline::NodeDef)::{lambda(chrono::batch_render::sensor_pipeline::NodeRegistry&)#1}>(chrono::batch_render::sensor_pipeline::RegisterSensorPipelineNode(chrono::batch_render::sensor_pipeline::NodeDef)::{lambda(chrono::batch_render::sensor_pipeline::NodeRegistry&)#1}&&):
✓ Branch 1 taken 10 times.
✓ Branch 4 taken 10 times.
auto chrono::batch_render::graph::Published<std::vector<int, std::allocator<int> > >::Update<chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#1}>(chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#1}&&):
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
auto chrono::batch_render::graph::Published<std::vector<int, std::allocator<int> > >::Update<chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#2}>(chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#2}&&):
✓ Branch 1 taken 1 time.
auto chrono::batch_render::graph::Published<std::vector<int, std::allocator<int> > >::Update<chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#3}>(chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#3}&&):
✓ Branch 1 taken 1 time.
34 auto copy = std::make_shared<T>(*m_value);
94 if constexpr (std::is_void_v<decltype(edit(*copy))>) {
95
4/4
auto chrono::batch_render::graph::Published<chrono::batch_render::material::(anonymous namespace)::Nodes>::Update<chrono::batch_render::material::RegisterClosurePrimitive(chrono::batch_render::material::ClosurePrimitive)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}>(chrono::batch_render::material::RegisterClosurePrimitive(chrono::batch_render::material::ClosurePrimitive)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}&&):
✓ Branch 1 taken 1 time.
auto chrono::batch_render::graph::Published<chrono::batch_render::material::(anonymous namespace)::Nodes>::Update<chrono::batch_render::material::RegisterMaterialNode(chrono::batch_render::material::MaterialNodeDefinition)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}>(chrono::batch_render::material::RegisterMaterialNode(chrono::batch_render::material::MaterialNodeDefinition)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}&&):
✓ Branch 1 taken 20 times.
auto chrono::batch_render::graph::Published<chrono::batch_render::sensor_pipeline::NodeRegistry>::Update<chrono::batch_render::sensor_pipeline::RegisterSensorPipelineNode(chrono::batch_render::sensor_pipeline::NodeDef)::{lambda(chrono::batch_render::sensor_pipeline::NodeRegistry&)#1}>(chrono::batch_render::sensor_pipeline::RegisterSensorPipelineNode(chrono::batch_render::sensor_pipeline::NodeDef)::{lambda(chrono::batch_render::sensor_pipeline::NodeRegistry&)#1}&&):
✓ Branch 1 taken 10 times.
auto chrono::batch_render::graph::Published<std::vector<int, std::allocator<int> > >::Update<chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#1}>(chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#1}&&):
✓ Branch 1 taken 1 time.
33 edit(*copy);
96
4/8
auto chrono::batch_render::graph::Published<chrono::batch_render::material::(anonymous namespace)::Nodes>::Update<chrono::batch_render::material::RegisterClosurePrimitive(chrono::batch_render::material::ClosurePrimitive)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}>(chrono::batch_render::material::RegisterClosurePrimitive(chrono::batch_render::material::ClosurePrimitive)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}&&):
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
auto chrono::batch_render::graph::Published<chrono::batch_render::material::(anonymous namespace)::Nodes>::Update<chrono::batch_render::material::RegisterMaterialNode(chrono::batch_render::material::MaterialNodeDefinition)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}>(chrono::batch_render::material::RegisterMaterialNode(chrono::batch_render::material::MaterialNodeDefinition)::{lambda(chrono::batch_render::material::(anonymous namespace)::Nodes&)#1}&&):
✗ Branch 1 not taken.
✓ Branch 2 taken 20 times.
auto chrono::batch_render::graph::Published<chrono::batch_render::sensor_pipeline::NodeRegistry>::Update<chrono::batch_render::sensor_pipeline::RegisterSensorPipelineNode(chrono::batch_render::sensor_pipeline::NodeDef)::{lambda(chrono::batch_render::sensor_pipeline::NodeRegistry&)#1}>(chrono::batch_render::sensor_pipeline::RegisterSensorPipelineNode(chrono::batch_render::sensor_pipeline::NodeDef)::{lambda(chrono::batch_render::sensor_pipeline::NodeRegistry&)#1}&&):
✗ Branch 1 not taken.
✓ Branch 2 taken 10 times.
auto chrono::batch_render::graph::Published<std::vector<int, std::allocator<int> > >::Update<chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#1}>(chrono::batch_render::graph::(anonymous namespace)::PublishedTest_UpdatesPublishNewSnapshotsAndFailedEditsKeepTheOldOne_Test::TestBody()::{lambda(std::vector<int, std::allocator<int> >&)#1}&&):
✗ Branch 1 not taken.
✓ Branch 2 taken 1 time.
32 m_value = std::move(copy);
97 } else {
98 1 auto result = edit(*copy);
99 1 m_value = std::move(copy);
100
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 time.
1 return result;
101 }
102 34 }
103
104 private:
105 mutable std::mutex m_mutex;
106 std::shared_ptr<const T> m_value;
107 };
108
109 }
110