scene/tables/transforms.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstdint> | ||
| 5 | #include <span> | ||
| 6 | #include <unordered_map> | ||
| 7 | #include <vector> | ||
| 8 | |||
| 9 | #include "chrono_batch_render/device/buffer.h" | ||
| 10 | #include "chrono_batch_render/device/commands.h" | ||
| 11 | #include "chrono_batch_render/device/program.h" | ||
| 12 | #include "chrono_batch_render/device/ref.h" | ||
| 13 | #include "chrono_batch_render/device/stream.h" | ||
| 14 | #include "chrono_batch_render/device/tensor.h" | ||
| 15 | #include "chrono_batch_render/scene/records/transforms.h" | ||
| 16 | #include "chrono_batch_render/scene/tables/kernels/transforms.h" | ||
| 17 | #include "chrono_batch_render/scene/tables/regions.h" | ||
| 18 | #include "chrono_batch_render/scene/tables/storage.h" | ||
| 19 | #include "chrono_batch_render/scene/tables/table.h" | ||
| 20 | #include "chrono_batch_render/stage/structure/structure.h" | ||
| 21 | #include "chrono_batch_render/stage/views/view.h" | ||
| 22 | #include "chrono_batch_render/stage/views/view_state.h" | ||
| 23 | |||
| 24 | namespace chrono::batch_render { | ||
| 25 | |||
| 26 | struct SimulationClock; | ||
| 27 | |||
| 28 | class TransformTable : public RenderTable { | ||
| 29 | public: | ||
| 30 | explicit TransformTable(Structure& structure, const SimulationClock* clock = nullptr); | ||
| 31 | |||
| 32 | 1001 | std::string_view Name() const override { | |
| 33 | 1001 | return "hierarchy"; | |
| 34 | } | ||
| 35 | |||
| 36 | std::span<const ColumnRef> Inputs() const override; | ||
| 37 | std::span<const TableId> TableOutputs() const override; | ||
| 38 | void Describe(RenderTables& tables) const override; | ||
| 39 | void Hold(std::vector<Ref<const RefCounted>>& held) const override; | ||
| 40 | void Prepare() override; | ||
| 41 | void Run(const ChangeSet& changes, TableVersions& versions) override; | ||
| 42 | |||
| 43 | 8449 | bool Pending() const override { | |
| 44 | 8449 | return m_follows.lagged || m_follows.riding; | |
| 45 | } | ||
| 46 | |||
| 47 | uint32_t Followers() const { | ||
| 48 | return uint32_t(m_follows.frames.size()); | ||
| 49 | } | ||
| 50 | |||
| 51 | uint32_t Segments() const { | ||
| 52 | return m_segments.Size(); | ||
| 53 | } | ||
| 54 | |||
| 55 | 19 | uint32_t Dispatched() const { | |
| 56 | 19 | return m_dispatched; | |
| 57 | } | ||
| 58 | |||
| 59 | 38 | uint32_t Rebuilds() const { | |
| 60 | 38 | return m_rebuilds; | |
| 61 | } | ||
| 62 | |||
| 63 | 53 | const Ref<device::Buffer>& Transforms() const { | |
| 64 | 291 | return m_transforms.Buffer(); | |
| 65 | } | ||
| 66 | |||
| 67 | 8 | const Ref<device::Buffer>& Imageables() const { | |
| 68 | 8 | return m_imageables.Buffer(); | |
| 69 | } | ||
| 70 | |||
| 71 | device::Tensor ReadWorldPoses(ViewState& view, device::DType type, Stream consumer, | ||
| 72 | QuaternionOrder order); | ||
| 73 | device::Tensor ReadWorldScales(ViewState& view, device::DType type, Stream consumer); | ||
| 74 | device::Tensor Localize(ViewState& view, const device::Tensor& values, | ||
| 75 | const device::Tensor* rotations, QuaternionOrder order, | ||
| 76 | const device::Tensor& sources); | ||
| 77 | |||
| 78 | private: | ||
| 79 | struct FollowPlan { | ||
| 80 | std::vector<uint32_t> frames; | ||
| 81 | std::vector<uint32_t> frameStarts; | ||
| 82 | std::vector<uint32_t> owned; | ||
| 83 | std::vector<uint32_t> owners; | ||
| 84 | std::vector<uint32_t> ownedStarts; | ||
| 85 | std::vector<uint32_t> worlds; | ||
| 86 | bool lagged = false; | ||
| 87 | bool pathed = false; | ||
| 88 | bool riding = false; | ||
| 89 | }; | ||
| 90 | |||
| 91 | void Rebuild(); | ||
| 92 | void PlanFollows(); | ||
| 93 | void RecordFollows(device::CommandEncoder& encoder, const ResolveParams& resolved); | ||
| 94 | void WriteMotions(bool restructured); | ||
| 95 | bool Apply(const ChangeSet& changes); | ||
| 96 | uint32_t ParentRow(uint32_t prim) const; | ||
| 97 | template <class Params> | ||
| 98 | device::Operation Dispatch(const char* entry, const Params& params, uint32_t threads); | ||
| 99 | |||
| 100 | Structure& m_structure; | ||
| 101 | const SimulationClock* m_clock = nullptr; | ||
| 102 | device::Program& Kernels(); | ||
| 103 | |||
| 104 | Ref<device::Program> m_program; | ||
| 105 | RecordTable<uint32_t> m_parents{"hierarchy parents"}; | ||
| 106 | RecordTable<uint32_t> m_xforms{"hierarchy transforms"}; | ||
| 107 | std::unordered_map<uint32_t, uint32_t> m_rows; | ||
| 108 | Regions m_segments; | ||
| 109 | Ref<device::Buffer> m_segmentRows; | ||
| 110 | Ref<device::Buffer> m_segmentStart; | ||
| 111 | Ref<device::Buffer> m_segmentCount; | ||
| 112 | DeviceTable<WorldTransform> m_transforms{"transforms"}; | ||
| 113 | DeviceTable<ResolvedImageable> m_imageables{"imageables"}; | ||
| 114 | DeviceTable<MotionRecord> m_motions{"motion records"}; | ||
| 115 | uint64_t m_motionSeen = 0; | ||
| 116 | FollowPlan m_follows; | ||
| 117 | Ref<device::Buffer> m_followRows; | ||
| 118 | Ref<device::Buffer> m_followOwners; | ||
| 119 | DeviceTable<FollowState> m_followStates{"follow states"}; | ||
| 120 | uint64_t m_followSeen = 0; | ||
| 121 | uint64_t m_clockSteps = 0; | ||
| 122 | uint64_t m_clockResets = 0; | ||
| 123 | double m_clockEnd = 0; | ||
| 124 | bool m_built = false; | ||
| 125 | uint64_t m_seen = 0; | ||
| 126 | uint32_t m_dispatched = 0; | ||
| 127 | uint32_t m_rebuilds = 0; | ||
| 128 | }; | ||
| 129 | |||
| 130 | } | ||
| 131 |