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 | 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 | 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 | 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 | 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 |