chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
12 / 12
100.0%
Branches:
12 / 23
52.2%
Functions:
3 / 3, 2 excl
100.0%

scene/tables/sensor_pipelines.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <map>
6 #include <memory>
7 #include <mutex>
8 #include <span>
9 #include <string>
10 #include <string_view>
11 #include <vector>
12
13 #include "chrono_batch_render/device/program.h"
14 #include "chrono_batch_render/scene/tables/connections.h"
15 #include "chrono_batch_render/scene/tables/pack.h"
16 #include "chrono_batch_render/scene/tables/storage.h"
17 #include "chrono_batch_render/scene/tables/table.h"
18 #include "chrono_batch_render/sensor_pipeline/definition.h"
19 #include "chrono_batch_render/sensor_pipeline/node.h"
20 #include "chrono_batch_render/stage/structure/structure.h"
21
22 namespace chrono::batch_render {
23
24 inline constexpr std::string_view kTapSource = "Tap";
25
26 struct SensorPipelineInstance {
27 uint32_t prim = kNoPrim;
28 std::string path;
29 uint32_t definition = 0;
30 sensor_pipeline::ResolvedSensorPipeline resolved;
31 std::vector<uint32_t> words;
32 uint32_t firstWord = 0;
33 std::string error;
34 };
35
36 class SensorPipelineTable : public RenderTable {
37 public:
38 explicit SensorPipelineTable(Structure& structure);
39
40 928 std::string_view Name() const override {
41 928 return "pipelines";
42 }
43
44 std::span<const ColumnRef> Inputs() const override;
45
46 8607 bool Pending() const override {
47
3/7
✓ Branch 2 taken 8607 times.
✓ Branch 4 taken 8607 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 8607 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
25821 return Registry() != sensor_pipeline::SensorPipelineNodes();
48 }
49
50 928 void Hold(std::vector<Ref<const RefCounted>>& held) const override {
51
4/8
✓ Branch 0 taken 928 times.
✓ Branch 1 taken 928 times.
✓ Branch 2 taken 927 times.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1856 HoldBuffers(held, {m_words.Buffer()});
52 1856 }
53
54 53 uint64_t WordsAddress() const {
55
1/2
✓ Branch 0 taken 53 times.
✗ Branch 1 not taken.
106 return m_words.Address();
56 }
57
58 std::vector<uint32_t> ReadWords(const SensorPipelineInstance& instance) const;
59
60 void Run(const ChangeSet& changes, TableVersions& versions) override;
61
62 std::shared_ptr<const SensorPipelineInstance> Find(uint32_t prim) const;
63 std::shared_ptr<const sensor_pipeline::SensorPipelineSet> Definitions() const;
64 std::shared_ptr<const sensor_pipeline::NodeRegistry> Registry() const;
65
66 542 uint64_t Version() const {
67
4/6
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 2 taken 501 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
542 return m_version;
68 }
69
70 private:
71 struct Gathered {
72 uint32_t parameter = 0;
73 ColumnRef column;
74 uint32_t row = 0;
75 };
76
77 void Pack(bool rewrite);
78
79 12 struct Tap {
80 std::string name;
81 uint32_t node = kNoPrim;
82 std::string output;
83 };
84
85 std::vector<Tap> GatherTaps() const;
86 sensor_pipeline::SensorPipelineDesc Gather(uint32_t pipeline, std::span<const Tap> taps) const;
87 sensor_pipeline::NodeDesc GatherNode(uint32_t prim) const;
88 std::vector<sensor_pipeline::ConnectionDesc> Connections(uint32_t prim) const;
89
90 Structure& m_structure;
91 sensor_pipeline::SensorPipelineLibrary m_library;
92 std::shared_ptr<const sensor_pipeline::NodeRegistry> m_registry;
93 mutable std::map<uint32_t, std::vector<Gathered>> m_gathered;
94 ConnectionCache m_connections{m_structure, {SchemaId::SensorNode, SchemaId::SensorPipeline}};
95 PackPlan m_pack{"pipeline"};
96 DeviceTable<uint32_t> m_words{"pipeline words"};
97 mutable std::vector<ColumnRef> m_inputs;
98 mutable uint32_t m_inputSchemas = 0;
99 mutable std::mutex m_mutex;
100 std::map<uint32_t, std::shared_ptr<const SensorPipelineInstance>> m_instances;
101 uint64_t m_seen = 0;
102 uint64_t m_version = 0;
103 };
104
105 }
106