chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
62 / 63
98.4%
Branches:
76 / 90
84.4%
Functions:
6 / 6
100.0%

scene/tables/sensors.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/scene/tables/sensors.h"
3
4 #include <algorithm>
5
6 #include "chrono_batch_render/device/commands.h"
7 #include "chrono_batch_render/device/queue.h"
8 #include "chrono_batch_render/scene/kernels.h"
9 #include "chrono_batch_render/scene/records/render_tables.h"
10 #include "chrono_batch_render/scene/schema/columns.h"
11 #include "chrono_batch_render/scene/tables/kernels/sensors.h"
12 #include "chrono_batch_render/stage/publish/change_set.h"
13 #include "chrono_batch_render/util/profiler.h"
14
15 namespace chrono::batch_render {
16
17 namespace {
18
19 5 std::vector<ColumnRef> SensorInputs() {
20 5 std::vector<ColumnRef> inputs;
21 25 for (const SchemaId schema : {SchemaId::Camera, SchemaId::LensDistortionAPI,
22
2/2
✓ Branch 0 taken 25 times.
✓ Branch 1 taken 5 times.
30 SchemaId::DetectorAPI, SchemaId::Lidar, SchemaId::Radar}) {
23
1/1
✓ Branch 1 taken 25 times.
25 const Span<const ColumnInfo> columns = Columns(schema);
24
2/2
✓ Branch 0 taken 300 times.
✓ Branch 1 taken 25 times.
325 for (uint32_t index = 0; index < columns.size(); ++index) {
25
1/1
✓ Branch 1 taken 300 times.
300 inputs.push_back({schema, &columns[index], index});
26 }
27 }
28 5 return inputs;
29 ✗ }
30
31 }
32
33 2352 std::span<const ColumnRef> SensorTable::Inputs() const {
34
4/5
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2347 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 5 times.
2352 static const std::vector<ColumnRef> inputs = SensorInputs();
35 2352 return inputs;
36 }
37
38 498 void SensorTable::Describe(RenderTables& tables) const {
39
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 tables.cameras.address = m_cameras.Address();
40
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 tables.distortions.address = m_distortions.Address();
41
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 tables.detectors.address = m_detectors.Address();
42
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 tables.lidars.address = m_lidars.Address();
43
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 tables.radars.address = m_radars.Address();
44 498 }
45
46 498 void SensorTable::Run(const ChangeSet&, TableVersions& versions) {
47
4/5
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 493 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 5 times.
498 CHRONO_BATCH_RENDER_ZONE("Sensors/Run");
48
3/3
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
✓ Branch 8 taken 498 times.
498 versions.Record(TableId::Cameras, std::vector<uint32_t>{kGlobalWorld});
49
1/1
✓ Branch 1 taken 498 times.
498 ColumnStore& store = m_structure.GetColumnStore();
50
1/1
✓ Branch 1 taken 498 times.
498 device::Device& device = store.GetDevice();
51 498 SensorParams params{};
52
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 params.cameraRows = store.Schema(SchemaId::Camera).Rows();
53
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 params.distortionRows = store.Schema(SchemaId::LensDistortionAPI).Rows();
54
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 params.detectorRows = store.Schema(SchemaId::DetectorAPI).Rows();
55
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 params.lidarRows = store.Schema(SchemaId::Lidar).Rows();
56
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 params.radarRows = store.Schema(SchemaId::Radar).Rows();
57
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 m_cameras.Reserve(device, store.Schema(SchemaId::Camera).Capacity());
58
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 m_distortions.Reserve(device, store.Schema(SchemaId::LensDistortionAPI).Capacity());
59
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 m_detectors.Reserve(device, store.Schema(SchemaId::DetectorAPI).Capacity());
60
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 m_lidars.Reserve(device, store.Schema(SchemaId::Lidar).Capacity());
61
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 m_radars.Reserve(device, store.Schema(SchemaId::Radar).Capacity());
62
1/1
✓ Branch 1 taken 498 times.
498 params.scene.address = store.DeviceData();
63
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 params.cameras.address = m_cameras.Address();
64
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 params.distortions.address = m_distortions.Address();
65
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 params.detectors.address = m_detectors.Address();
66
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 params.lidars.address = m_lidars.Address();
67
1/2
✓ Branch 0 taken 498 times.
✗ Branch 1 not taken.
498 params.radars.address = m_radars.Address();
68
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 493 times.
498 device::Queue& queue = device.GetQueue();
69
4/5
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 493 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 5 times.
498 static const profiler::ZoneId zone = profiler::ZoneId::Named("Sensors/Write");
70
1/1
✓ Branch 1 taken 498 times.
498 device::CommandEncoder encoder = queue.CreateEncoder();
71 498 {
72
1/1
✓ Branch 1 taken 498 times.
498 const device::ZoneScope scope(encoder, zone);
73
2/2
✓ Branch 0 taken 1036 times.
✓ Branch 1 taken 1454 times.
3526 for (const auto& [entry, rows] : {std::pair{"WriteCameras", params.cameraRows},
74 std::pair{"WriteDistortions", params.distortionRows},
75 std::pair{"WriteDetectors", params.detectorRows},
76 std::pair{"WriteLidars", params.lidarRows},
77
2/2
✓ Branch 0 taken 2490 times.
✓ Branch 1 taken 498 times.
2988 std::pair{"WriteRadars", params.radarRows}}) {
78
2/2
✓ Branch 0 taken 1036 times.
✓ Branch 1 taken 1454 times.
2490 if (rows > 0) {
79
3/3
✓ Branch 1 taken 1036 times.
✓ Branch 4 taken 1036 times.
✓ Branch 7 taken 1036 times.
2072 encoder.Dispatch(Kernels().Entry(entry), params,
80
1/1
✓ Branch 1 taken 1036 times.
1036 {.x = device::GroupCount(rows, kSensorGroup)});
81 }
82 }
83 498 }
84
2/2
✓ Branch 1 taken 498 times.
✓ Branch 4 taken 498 times.
498 queue.Submit(encoder.Finish());
85 498 }
86
87 353 void SensorTable::Prepare() {
88 353 Kernels();
89 353 }
90
91 1389 device::Program& SensorTable::Kernels() {
92
2/2
✓ Branch 0 taken 353 times.
✓ Branch 1 taken 1036 times.
1389 if (!m_program) {
93
2/2
✓ Branch 2 taken 353 times.
✓ Branch 5 taken 353 times.
1059 m_program = m_structure.GetColumnStore().GetDevice().CreateProgram(
94 {.modules = {"chrono_batch_render.scene.tables.kernels.sensors"},
95 .library = &kSceneKernels,
96 .entries = {"WriteCameras", "WriteDistortions", "WriteDetectors", "WriteLidars",
97 "WriteRadars"},
98
2/3
✓ Branch 1 taken 353 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 353 times.
706 .label = "sensors"});
99 }
100 1389 return *m_program;
101 706 }
102
103 }
104