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 | 30 | SchemaId::DetectorAPI, SchemaId::Lidar, SchemaId::Radar}) { | |
| 23 | 25 | const Span<const ColumnInfo> columns = Columns(schema); | |
| 24 | 325 | for (uint32_t index = 0; index < columns.size(); ++index) { | |
| 25 | 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 | 2352 | static const std::vector<ColumnRef> inputs = SensorInputs(); | |
| 35 | 2352 | return inputs; | |
| 36 | } | ||
| 37 | |||
| 38 | 498 | void SensorTable::Describe(RenderTables& tables) const { | |
| 39 | 498 | tables.cameras.address = m_cameras.Address(); | |
| 40 | 498 | tables.distortions.address = m_distortions.Address(); | |
| 41 | 498 | tables.detectors.address = m_detectors.Address(); | |
| 42 | 498 | tables.lidars.address = m_lidars.Address(); | |
| 43 | 498 | tables.radars.address = m_radars.Address(); | |
| 44 | 498 | } | |
| 45 | |||
| 46 | 498 | void SensorTable::Run(const ChangeSet&, TableVersions& versions) { | |
| 47 | 498 | CHRONO_BATCH_RENDER_ZONE("Sensors/Run"); | |
| 48 | 498 | versions.Record(TableId::Cameras, std::vector<uint32_t>{kGlobalWorld}); | |
| 49 | 498 | ColumnStore& store = m_structure.GetColumnStore(); | |
| 50 | 498 | device::Device& device = store.GetDevice(); | |
| 51 | 498 | SensorParams params{}; | |
| 52 | 498 | params.cameraRows = store.Schema(SchemaId::Camera).Rows(); | |
| 53 | 498 | params.distortionRows = store.Schema(SchemaId::LensDistortionAPI).Rows(); | |
| 54 | 498 | params.detectorRows = store.Schema(SchemaId::DetectorAPI).Rows(); | |
| 55 | 498 | params.lidarRows = store.Schema(SchemaId::Lidar).Rows(); | |
| 56 | 498 | params.radarRows = store.Schema(SchemaId::Radar).Rows(); | |
| 57 | 498 | m_cameras.Reserve(device, store.Schema(SchemaId::Camera).Capacity()); | |
| 58 | 498 | m_distortions.Reserve(device, store.Schema(SchemaId::LensDistortionAPI).Capacity()); | |
| 59 | 498 | m_detectors.Reserve(device, store.Schema(SchemaId::DetectorAPI).Capacity()); | |
| 60 | 498 | m_lidars.Reserve(device, store.Schema(SchemaId::Lidar).Capacity()); | |
| 61 | 498 | m_radars.Reserve(device, store.Schema(SchemaId::Radar).Capacity()); | |
| 62 | 498 | params.scene.address = store.DeviceData(); | |
| 63 | 498 | params.cameras.address = m_cameras.Address(); | |
| 64 | 498 | params.distortions.address = m_distortions.Address(); | |
| 65 | 498 | params.detectors.address = m_detectors.Address(); | |
| 66 | 498 | params.lidars.address = m_lidars.Address(); | |
| 67 | 498 | params.radars.address = m_radars.Address(); | |
| 68 | 498 | device::Queue& queue = device.GetQueue(); | |
| 69 | 498 | static const profiler::ZoneId zone = profiler::ZoneId::Named("Sensors/Write"); | |
| 70 | 498 | device::CommandEncoder encoder = queue.CreateEncoder(); | |
| 71 | 498 | { | |
| 72 | 498 | const device::ZoneScope scope(encoder, zone); | |
| 73 | 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 | 2988 | std::pair{"WriteRadars", params.radarRows}}) { | |
| 78 | 2490 | if (rows > 0) { | |
| 79 | 2072 | encoder.Dispatch(Kernels().Entry(entry), params, | |
| 80 | 1036 | {.x = device::GroupCount(rows, kSensorGroup)}); | |
| 81 | } | ||
| 82 | } | ||
| 83 | 498 | } | |
| 84 | 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 | 1389 | if (!m_program) { | |
| 93 | 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 | 706 | .label = "sensors"}); | |
| 99 | } | ||
| 100 | 1389 | return *m_program; | |
| 101 | 706 | } | |
| 102 | |||
| 103 | } | ||
| 104 |