stage/publish/change_set.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstdint> | ||
| 5 | #include <span> | ||
| 6 | #include <vector> | ||
| 7 | |||
| 8 | #include "chrono_batch_render/device/buffer.h" | ||
| 9 | #include "chrono_batch_render/device/operation.h" | ||
| 10 | #include "chrono_batch_render/device/ref.h" | ||
| 11 | #include "chrono_batch_render/stage/schema/schema.h" | ||
| 12 | #include "chrono_batch_render/stage/structure/structure.h" | ||
| 13 | |||
| 14 | namespace chrono::batch_render { | ||
| 15 | |||
| 16 | enum class TableId : uint32_t; | ||
| 17 | |||
| 18 | 447 | class TableVersions { | |
| 19 | public: | ||
| 20 | void Record(TableId table, std::span<const uint32_t> worlds); | ||
| 21 | |||
| 22 | 11632 | uint64_t Sequence() const { | |
| 23 | 11632 | return m_sequence; | |
| 24 | } | ||
| 25 | |||
| 26 | 33010 | uint64_t Version(TableId table) const { | |
| 27 | 33011 | return uint32_t(table) < m_versions.size() ? m_versions[uint32_t(table)] : 0; | |
| 28 | } | ||
| 29 | |||
| 30 | void Collect(TableId table, uint64_t since, std::vector<uint32_t>& worlds) const; | ||
| 31 | void Trim(uint64_t seen); | ||
| 32 | |||
| 33 | private: | ||
| 34 | 21898 | struct Entry { | |
| 35 | uint64_t sequence = 0; | ||
| 36 | TableId table{}; | ||
| 37 | std::vector<uint32_t> worlds; | ||
| 38 | }; | ||
| 39 | |||
| 40 | std::vector<Entry> m_entries; | ||
| 41 | std::vector<uint64_t> m_versions; | ||
| 42 | uint64_t m_sequence = 0; | ||
| 43 | }; | ||
| 44 | |||
| 45 | 11661 | class ChangedRows { | |
| 46 | public: | ||
| 47 | ChangedRows() = default; | ||
| 48 | |||
| 49 | 4071 | ChangedRows(ColumnRef column, Ref<device::Buffer> buffer, uint32_t capacity) | |
| 50 | 4071 | : m_column(column), m_buffer(std::move(buffer)), m_capacity(capacity) {} | |
| 51 | |||
| 52 | 7933 | ColumnRef Column() const { | |
| 53 | 7933 | return m_column; | |
| 54 | } | ||
| 55 | |||
| 56 | uint32_t Capacity() const { | ||
| 57 | return m_capacity; | ||
| 58 | } | ||
| 59 | |||
| 60 | bool Empty() const { | ||
| 61 | return !m_buffer; | ||
| 62 | } | ||
| 63 | |||
| 64 | device::BufferRange Count() const; | ||
| 65 | device::BufferRange Rows() const; | ||
| 66 | std::vector<uint32_t> ToHost() const; | ||
| 67 | |||
| 68 | private: | ||
| 69 | ColumnRef m_column; | ||
| 70 | Ref<device::Buffer> m_buffer; | ||
| 71 | uint32_t m_capacity = 0; | ||
| 72 | }; | ||
| 73 | |||
| 74 | struct ChangeSet { | ||
| 75 | Ordinal since = 0; | ||
| 76 | Ordinal until = 0; | ||
| 77 | Ordinal sinceStamp = 0; | ||
| 78 | Ordinal untilStamp = 0; | ||
| 79 | bool resync = false; | ||
| 80 | bool structure = false; | ||
| 81 | std::vector<StructureEntry> added; | ||
| 82 | std::vector<StructureEntry> removed; | ||
| 83 | std::vector<StructureEntry> apis; | ||
| 84 | std::vector<uint32_t> worlds; | ||
| 85 | std::vector<ChangedRows> columns; | ||
| 86 | std::vector<std::pair<ColumnRef, std::vector<uint32_t>>> arrays; | ||
| 87 | std::vector<TableId> wrote; | ||
| 88 | |||
| 89 | const ChangedRows* Rows(ColumnRef column) const; | ||
| 90 | std::span<const uint32_t> ArrayRows(ColumnRef column) const; | ||
| 91 | bool World(uint32_t world) const; | ||
| 92 | bool Global() const; | ||
| 93 | bool Wrote(TableId table) const; | ||
| 94 | }; | ||
| 95 | |||
| 96 | } | ||
| 97 |