stage/structure/prims.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 <unordered_map> | ||
| 8 | #include <vector> | ||
| 9 | |||
| 10 | #include "chrono_batch_render/stage/columns/column_store.h" | ||
| 11 | #include "chrono_batch_render/stage/schema/ids.h" | ||
| 12 | #include "chrono_batch_render/stage/schema/schema.h" | ||
| 13 | |||
| 14 | namespace chrono::batch_render { | ||
| 15 | |||
| 16 | 24826 | struct PrimRecord { | |
| 17 | SchemaId schema = SchemaId::None; | ||
| 18 | uint32_t parent = kNoPrim; | ||
| 19 | uint32_t world = kGlobalWorld; | ||
| 20 | uint32_t flags = 0; | ||
| 21 | uint32_t slots = kNoRow; | ||
| 22 | uint32_t generation = 0; | ||
| 23 | uint64_t apis = 0; | ||
| 24 | }; | ||
| 25 | |||
| 26 | struct ApiInstance { | ||
| 27 | uint32_t instance = 0; | ||
| 28 | uint32_t row = kNoRow; | ||
| 29 | }; | ||
| 30 | |||
| 31 | struct BlockShape { | ||
| 32 | std::vector<SchemaId> schemas; | ||
| 33 | std::vector<uint32_t> parents; | ||
| 34 | std::vector<uint64_t> apis; | ||
| 35 | }; | ||
| 36 | |||
| 37 | struct BlockTable { | ||
| 38 | SchemaId table = SchemaId::None; | ||
| 39 | uint32_t first = 0; | ||
| 40 | uint32_t perCopy = 0; | ||
| 41 | uint32_t count = kNoRow; | ||
| 42 | }; | ||
| 43 | |||
| 44 | 5645 | struct PrimBlock { | |
| 45 | uint32_t firstPrim = kNoPrim; | ||
| 46 | uint32_t count = 0; | ||
| 47 | uint32_t copies = 0; | ||
| 48 | uint32_t firstWorld = kGlobalWorld; | ||
| 49 | uint32_t worldsPerCopy = 0; | ||
| 50 | uint32_t firstSlot = kNoRow; | ||
| 51 | uint32_t slotsPerCopy = 0; | ||
| 52 | std::vector<BlockTable> tables; | ||
| 53 | |||
| 54 | 52203 | uint32_t Prim(uint32_t copy, uint32_t index) const { | |
| 55 | 52199 | return firstPrim + copy * count + index; | |
| 56 | } | ||
| 57 | |||
| 58 | 388 | uint32_t PrimCount() const { | |
| 59 | 388 | return count * copies; | |
| 60 | } | ||
| 61 | }; | ||
| 62 | |||
| 63 | class Prims { | ||
| 64 | public: | ||
| 65 | 501 | explicit Prims(ColumnStore& store) : m_store(store) {} | |
| 66 | |||
| 67 | 134708 | uint32_t Size() const { | |
| 68 | 134708 | return uint32_t(m_records.size()); | |
| 69 | } | ||
| 70 | |||
| 71 | 115 | uint32_t LiveCount() const { | |
| 72 | 115 | return m_live; | |
| 73 | } | ||
| 74 | |||
| 75 | 13860 | uint32_t WorldCount() const { | |
| 76 | 13860 | return m_worldCount; | |
| 77 | } | ||
| 78 | |||
| 79 | bool Alive(uint32_t prim) const; | ||
| 80 | uint32_t Generation(uint32_t prim) const; | ||
| 81 | const PrimRecord& Record(uint32_t prim) const; | ||
| 82 | uint32_t Row(uint32_t prim, SchemaId table) const; | ||
| 83 | uint32_t FindRow(uint32_t prim, SchemaId table) const; | ||
| 84 | std::vector<uint32_t> Rows(std::span<const uint32_t> prims, SchemaId table) const; | ||
| 85 | bool HasApi(uint32_t prim, SchemaId api) const; | ||
| 86 | std::span<const ApiInstance> Instances(uint32_t prim, SchemaId api) const; | ||
| 87 | uint32_t InstanceRow(uint32_t prim, SchemaId api, uint32_t instance) const; | ||
| 88 | |||
| 89 | PrimBlock Add(const BlockShape& shape, std::span<const uint32_t> parents, | ||
| 90 | uint32_t reuseWorld = kGlobalWorld, bool pageAligned = false); | ||
| 91 | void CheckRemovable(uint32_t prim) const; | ||
| 92 | void Remove(uint32_t prim); | ||
| 93 | BlockTable Apply(std::span<const uint32_t> prims, SchemaId api); | ||
| 94 | void Unapply(std::span<const uint32_t> prims, SchemaId api); | ||
| 95 | BlockTable ApplyInstance(std::span<const uint32_t> prims, SchemaId api, uint32_t instance); | ||
| 96 | void UnapplyInstance(std::span<const uint32_t> prims, SchemaId api, uint32_t instance); | ||
| 97 | void StageLinks(std::span<const uint32_t> prims, SchemaId api); | ||
| 98 | std::vector<BlockTable> Retype(uint32_t prim, SchemaId schema, uint64_t apis); | ||
| 99 | void Reparent(uint32_t prim, uint32_t parent); | ||
| 100 | void Renew(uint32_t prim); | ||
| 101 | void MarkSession(uint32_t prim); | ||
| 102 | bool Session(uint32_t prim) const; | ||
| 103 | |||
| 104 | private: | ||
| 105 | void Check(const BlockShape& shape, std::span<const uint32_t> parents) const; | ||
| 106 | PrimBlock AllocateOne(SchemaId schema, uint64_t apis); | ||
| 107 | PrimBlock AllocateBlock(const BlockShape& shape, uint32_t copies, bool pageAligned); | ||
| 108 | void Write(uint32_t prim, const PrimRecord& record, std::span<const uint32_t> rows); | ||
| 109 | void StageRecord(uint32_t prim); | ||
| 110 | uint32_t AcquireSlots(uint32_t count); | ||
| 111 | void Regroup(uint32_t prim, uint64_t apis, SchemaId api, uint32_t row); | ||
| 112 | void ReleaseRow(SchemaId table, uint32_t row); | ||
| 113 | void SetHead(uint32_t prim, SchemaId api, uint32_t row); | ||
| 114 | |||
| 115 | ColumnStore& m_store; | ||
| 116 | std::vector<PrimRecord> m_records; | ||
| 117 | std::vector<uint32_t> m_slotRows; | ||
| 118 | std::vector<uint32_t> m_freePrims; | ||
| 119 | std::map<uint32_t, std::vector<uint32_t>> m_freeSlots; | ||
| 120 | std::unordered_map<uint64_t, std::vector<ApiInstance>> m_instances; | ||
| 121 | uint32_t m_live = 0; | ||
| 122 | uint32_t m_worldCount = 0; | ||
| 123 | }; | ||
| 124 | |||
| 125 | } | ||
| 126 |