chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
26 / 26
100.0%
Branches:
35 / 43
81.4%
Functions:
1 / 1, 4 excl
100.0%

sensor_pipeline/node.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <deque>
6 #include <memory>
7 #include <string>
8 #include <string_view>
9 #include <unordered_map>
10 #include <vector>
11
12 namespace chrono::batch_render::sensor_pipeline {
13
14 enum class SignalType : uint8_t {
15 ElectronRate,
16 Electrons,
17 Digital,
18 LinearColor,
19 DisplayColor,
20 Radiance,
21 Returns,
22 PointCloud,
23 RadarCube,
24 CaptureStat,
25 };
26
27 struct SignalInfo {
28 std::string_view name;
29 std::string_view slangType;
30 std::string_view port;
31 };
32
33 inline constexpr SignalInfo kSignals[] = {
34 {"ElectronRate", "ElectronRate", "electronRate"},
35 {"Electrons", "Electrons", "electrons"},
36 {"Digital", "Digital", "digital"},
37 {"LinearColor", "LinearColor", "color"},
38 {"DisplayColor", "DisplayColor", "display"},
39 {"Radiance", "Radiance", "radiance"},
40 {"Returns", "Returns", "returns"},
41 {"PointCloud", "CloudSignal", "cloud"},
42 {"RadarCube", "RadarCube", "cube"},
43 {"CaptureStat", "CaptureStat", "stat"},
44 };
45
46 366 inline const SignalInfo& Signal(SignalType type) {
47
5/5
✓ Branch 1 taken 2 times.
✓ Branch 1 taken 45 times.
✓ Branch 4 taken 34 times.
✓ Branch 5 taken 8 times.
✓ Branch 11 taken 14 times.
366 return kSignals[uint32_t(type)];
48 }
49
50 inline constexpr uint32_t kReturnsChannels = 8;
51
52 enum class ElementType : uint8_t {
53 F32,
54 F16,
55 U16,
56 U8,
57 };
58
59 inline constexpr uint32_t kElementBytes[] = {4, 2, 2, 1};
60
61 inline constexpr uint32_t kStatWords = 16;
62 inline constexpr uint32_t kReduceGroups = 64;
63 inline constexpr uint32_t kStatStorageWords = (1 + kReduceGroups) * kStatWords;
64
65 544 struct SignalLayout {
66 55 uint32_t channels = 1;
67 55 uint32_t pattern = 0;
68 55 bool mosaic = false;
69 55 ElementType element = ElementType::F32;
70 55 bool perCapture = false;
71
72
5/10
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 55 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 55 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 55 times.
55 bool operator==(const SignalLayout&) const = default;
73 };
74
75 enum class NodeKind : uint8_t {
76 Source,
77 Point,
78 Stencil,
79 Reduce,
80 Global,
81 Compact,
82 };
83
84 inline constexpr std::string_view kNodeKindNames[] = {"source", "point", "stencil",
85 "reduce", "global", "compact"};
86
87 enum class LayoutRule : uint8_t {
88 FirstInput,
89 Detector,
90 FullChannels,
91 Color,
92 Stat,
93 Returns,
94 };
95
96 inline constexpr uint32_t kMostStencilRadius = 8;
97
98
4/5
<unknown function 46>:
✓ Branch 2 taken 114 times.
✓ Branch 3 taken 57 times.
<unknown function 98>:
✓ Branch 1 taken 2421 times.
✓ Branch 5 taken 230 times.
chrono::batch_render::sensor_pipeline::SignalLayout::operator==(chrono::batch_render::sensor_pipeline::SignalLayout const&) const:
✗ Branch 1 not taken.
7198 struct PortDef {
99 std::string name;
100 SignalType type = SignalType::ElectronRate;
101 bool optional = false;
102 };
103
104 inline constexpr uint32_t kNoContextArgument = ~0u;
105
106 enum class ParameterType : uint8_t { Float, Int, Bool };
107
108 2650 struct ParameterDef {
109 std::string name;
110 uint32_t words = 1;
111 std::vector<float> fallback;
112 ParameterType type = ParameterType::Float;
113 };
114
115 struct UniformDef {
116 std::string name;
117 std::vector<std::string> allowed;
118 std::string fallback;
119 };
120
121 struct NodeCode {
122 std::string module;
123 std::string type;
124 std::string file;
125 std::string source;
126 std::string version;
127 bool applies = false;
128 uint32_t context = kNoContextArgument;
129 };
130
131 struct NodeDef {
132 std::string id;
133 NodeKind kind = NodeKind::Point;
134 std::vector<PortDef> inputs;
135 std::vector<PortDef> outputs;
136 std::vector<ParameterDef> parameters;
137 std::vector<UniformDef> uniforms;
138 std::vector<float> state;
139 uint32_t radius = 0;
140 uint32_t passes = 1;
141 LayoutRule layout = LayoutRule::FirstInput;
142 NodeCode code;
143 };
144
145 59 class NodeRegistry {
146 public:
147 uint32_t Add(NodeDef def);
148
149 6172 const NodeDef& operator[](uint32_t index) const {
150
21/23
<unknown function 149>:
✓ Branch 1 taken 186 times.
✓ Branch 2 taken 173 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✓ Branch 4 taken 325 times.
✓ Branch 5 taken 15 times.
✓ Branch 6 taken 1 time.
✓ Branch 6 taken 4 times.
✓ Branch 7 taken 12 times.
✓ Branch 7 taken 84 times.
✓ Branch 8 taken 41 times.
✓ Branch 8 taken 251 times.
<unknown function 46>:
✓ Branch 1 taken 229 times.
✓ Branch 2 taken 99 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 6 times.
✓ Branch 6 taken 2 times.
✓ Branch 7 taken 6 times.
✓ Branch 10 taken 34 times.
<unknown function 98>:
✓ Branch 1 taken 32 times.
✓ Branch 2 taken 57 times.
chrono::batch_render::sensor_pipeline::SignalLayout::operator==(chrono::batch_render::sensor_pipeline::SignalLayout const&) const:
✓ Branch 2 taken 4 times.
6168 return m_defs[index];
151 }
152
153 uint32_t Find(std::string_view id) const;
154
155 uint32_t Size() const {
156 return uint32_t(m_defs.size());
157 }
158
159 private:
160 std::deque<NodeDef> m_defs;
161 std::unordered_map<std::string, uint32_t> m_ids;
162 };
163
164 inline constexpr uint32_t kNoDef = ~0u;
165
166 inline constexpr const char* kCameraNodes =
167 "chrono_batch_render.render.kernels.sensor_pipeline.nodes.camera";
168 inline constexpr const char* kIspNodes =
169 "chrono_batch_render.render.kernels.sensor_pipeline.nodes.isp";
170 inline constexpr const char* kLidarNodes =
171 "chrono_batch_render.render.kernels.sensor_pipeline.nodes.lidar";
172 inline constexpr const char* kRadarNodes =
173 "chrono_batch_render.render.kernels.sensor_pipeline.nodes.radar";
174 inline constexpr uint32_t kCfarRadius = 4;
175
176 void RegisterBuiltinNodes(NodeRegistry& registry);
177
178 const NodeRegistry& BuiltinNodes();
179
180 std::shared_ptr<const NodeRegistry> SensorPipelineNodes();
181
182 void RegisterSensorPipelineNode(NodeDef def);
183
184 }
185