scene/tables/views.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #include "chrono_batch_render/scene/tables/views.h" | ||
| 3 | |||
| 4 | #include <algorithm> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "chrono_batch_render/device/commands.h" | ||
| 9 | #include "chrono_batch_render/device/queue.h" | ||
| 10 | #include "chrono_batch_render/scene/kernels.h" | ||
| 11 | #include "chrono_batch_render/scene/records/render_tables.h" | ||
| 12 | #include "chrono_batch_render/scene/tables/kernels/views.h" | ||
| 13 | #include "chrono_batch_render/stage/publish/change_set.h" | ||
| 14 | #include "chrono_batch_render/util/profiler.h" | ||
| 15 | |||
| 16 | namespace chrono::batch_render { | ||
| 17 | |||
| 18 | 527 | void ViewTable::Describe(RenderTables& tables) const { | |
| 19 | 527 | tables.views.address = m_views ? m_views->Address() : 0; | |
| 20 | 527 | tables.viewStarts.address = m_starts ? m_starts->Address() : 0; | |
| 21 | 527 | } | |
| 22 | |||
| 23 | 353 | void ViewTable::Prepare() { | |
| 24 | 353 | Kernels(); | |
| 25 | 353 | } | |
| 26 | |||
| 27 | 527 | void ViewTable::Run(const ChangeSet&, TableVersions&) { | |
| 28 | 527 | CHRONO_BATCH_RENDER_ZONE("Views/Run"); | |
| 29 | 527 | const Prims& prims = m_structure.GetPrims(); | |
| 30 | 527 | ColumnStore& store = m_structure.GetColumnStore(); | |
| 31 | 527 | device::Device& device = store.GetDevice(); | |
| 32 | 667 | std::vector<uint32_t> starts(std::max(store.Schema(SchemaId::RenderProduct).Capacity(), 1u), 0); | |
| 33 | 527 | std::vector<ViewEntry> entries; | |
| 34 | 960 | for (const auto& product : m_products.Products()) { | |
| 35 | 433 | starts[prims.Row(product->prim, SchemaId::RenderProduct)] = uint32_t(entries.size()); | |
| 36 | 904 | for (const uint32_t sensor : product->sensors) { | |
| 37 | 471 | ViewEntry entry{.product = prims.Row(product->prim, SchemaId::RenderProduct), | |
| 38 | .camera = kNoRow, | ||
| 39 | 471 | .distortion = kNoRow}; | |
| 40 | 471 | if (IsA(prims.Record(sensor).schema, SchemaId::Camera)) { | |
| 41 | 428 | entry.camera = prims.Row(sensor, SchemaId::Camera); | |
| 42 | 428 | if (prims.HasApi(sensor, SchemaId::LensDistortionAPI)) { | |
| 43 | 428 | entry.distortion = prims.Row(sensor, SchemaId::LensDistortionAPI); | |
| 44 | } | ||
| 45 | } | ||
| 46 | 471 | entries.push_back(entry); | |
| 47 | } | ||
| 48 | 527 | } | |
| 49 | 527 | m_count = uint32_t(entries.size()); | |
| 50 | 780 | m_starts = device.CreateBuffer({.label = "view starts"}, std::span<const uint32_t>(starts)); | |
| 51 | 1054 | m_views = device.CreateBuffer( | |
| 52 | 527 | {.bytes = std::max<uint64_t>(entries.size(), 1) * sizeof(ViewRecord), .label = "views"}); | |
| 53 | 527 | if (entries.empty()) { | |
| 54 | 141 | return; | |
| 55 | } | ||
| 56 | 386 | const Ref<device::Buffer> list = | |
| 57 | 386 | device.CreateBuffer({.label = "view entries"}, std::span<const ViewEntry>(entries)); | |
| 58 | 386 | ViewParams params{}; | |
| 59 | 386 | params.cameras = m_tables.cameras; | |
| 60 | 386 | params.distortions = m_tables.distortions; | |
| 61 | 386 | params.products = m_tables.products; | |
| 62 | 386 | params.entries.address = list->Address(); | |
| 63 | 386 | params.views.address = m_views->Address(); | |
| 64 | 386 | params.count = m_count; | |
| 65 | 386 | device::Queue& queue = device.GetQueue(); | |
| 66 | 386 | device::CommandEncoder encoder = queue.CreateEncoder(); | |
| 67 | 386 | encoder.Dispatch(Kernels().Entry("WriteViews"), params, | |
| 68 | 386 | {.x = device::GroupCount(m_count, kViewGroup)}); | |
| 69 | 386 | queue.Submit(encoder.Finish()); | |
| 70 | 2880 | } | |
| 71 | |||
| 72 | 739 | device::Program& ViewTable::Kernels() { | |
| 73 | 739 | if (!m_program) { | |
| 74 | 1059 | m_program = m_structure.GetColumnStore().GetDevice().CreateProgram( | |
| 75 | {.modules = {"chrono_batch_render.scene.tables.kernels.views"}, | ||
| 76 | .library = &kSceneKernels, | ||
| 77 | .entries = {"WriteViews"}, | ||
| 78 | 706 | .label = "views"}); | |
| 79 | } | ||
| 80 | 739 | return *m_program; | |
| 81 | 706 | } | |
| 82 | |||
| 83 | } | ||
| 84 |