stage/views/view_state.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstdint> | ||
| 5 | #include <map> | ||
| 6 | #include <span> | ||
| 7 | #include <string> | ||
| 8 | #include <tuple> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | #include "chrono_batch_render/device/buffer.h" | ||
| 12 | #include "chrono_batch_render/device/ref.h" | ||
| 13 | #include "chrono_batch_render/stage/schema/primvars.h" | ||
| 14 | #include "chrono_batch_render/stage/schema/schema.h" | ||
| 15 | #include "chrono_batch_render/stage/structure/structure.h" | ||
| 16 | |||
| 17 | namespace chrono::batch_render { | ||
| 18 | |||
| 19 | struct ViewBlock { | ||
| 20 | uint32_t first = 0; | ||
| 21 | uint32_t firstRow = 0; | ||
| 22 | uint32_t count = 0; | ||
| 23 | }; | ||
| 24 | |||
| 25 | 59147 | struct ViewRows { | |
| 26 | uint64_t epoch = ~uint64_t(0); | ||
| 27 | std::vector<uint32_t> rows; | ||
| 28 | std::vector<ViewBlock> blocks; | ||
| 29 | std::vector<uint32_t> worlds; | ||
| 30 | uint32_t live = 0; | ||
| 31 | Ref<device::Buffer> device; | ||
| 32 | |||
| 33 | 48259 | bool Dense() const { | |
| 34 | 48259 | return blocks.size() == 1 && live == rows.size(); | |
| 35 | } | ||
| 36 | }; | ||
| 37 | |||
| 38 | struct RowSource { | ||
| 39 | uint64_t rows = 0; | ||
| 40 | uint32_t firstRow = 0; | ||
| 41 | }; | ||
| 42 | |||
| 43 | 11 | struct PrimvarLayout { | |
| 44 | std::vector<ArrayRef> tables; | ||
| 45 | PrimvarEntry entry{}; | ||
| 46 | }; | ||
| 47 | |||
| 48 | class ViewState { | ||
| 49 | public: | ||
| 50 | ViewState(Structure& structure, SchemaId schema, std::vector<uint32_t> prims, | ||
| 51 | uint32_t instance = kNoInstance); | ||
| 52 | |||
| 53 | static constexpr uint32_t kNoInstance = 0xFFFFFFFF; | ||
| 54 | |||
| 55 | 2 | uint32_t Instance() const { | |
| 56 | 2 | return m_instance; | |
| 57 | } | ||
| 58 | |||
| 59 | 85784 | Structure& GetStructure() const { | |
| 60 | 85782 | return m_structure; | |
| 61 | } | ||
| 62 | |||
| 63 | 930048 | ColumnStore& GetColumnStore() const { | |
| 64 | 511057 | return m_structure.GetColumnStore(); | |
| 65 | } | ||
| 66 | |||
| 67 | 440047 | SchemaId Schema() const { | |
| 68 | 336680 | return m_schema; | |
| 69 | } | ||
| 70 | |||
| 71 | 131517 | uint32_t Size() const { | |
| 72 | 131517 | return uint32_t(m_prims.size()); | |
| 73 | } | ||
| 74 | |||
| 75 | 83853 | std::span<const uint32_t> Prims() const { | |
| 76 | 83853 | return m_prims; | |
| 77 | } | ||
| 78 | |||
| 79 | bool Live(uint32_t index) const; | ||
| 80 | const ViewRows& Rows(SchemaId table); | ||
| 81 | const Ref<device::Buffer>& DeviceRows(SchemaId table); | ||
| 82 | RowSource Source(SchemaId table); | ||
| 83 | |||
| 84 | const Ref<device::Buffer>& XformParents(); | ||
| 85 | |||
| 86 | 13 | PrimvarLayout& Layout(ColumnRef column, std::string_view name) { | |
| 87 | 26 | return m_primvarLayouts[{column.schema, column.index, std::string(name)}]; | |
| 88 | } | ||
| 89 | |||
| 90 | private: | ||
| 91 | Structure& m_structure; | ||
| 92 | SchemaId m_schema; | ||
| 93 | uint32_t m_instance; | ||
| 94 | std::vector<uint32_t> m_prims; | ||
| 95 | std::vector<uint32_t> m_generations; | ||
| 96 | std::map<SchemaId, ViewRows> m_rows; | ||
| 97 | Ref<device::Buffer> m_xformParents; | ||
| 98 | uint64_t m_xformParentsEpoch = ~uint64_t(0); | ||
| 99 | std::map<std::tuple<SchemaId, uint32_t, std::string>, PrimvarLayout> m_primvarLayouts; | ||
| 100 | }; | ||
| 101 | |||
| 102 | } | ||
| 103 |