stage/columns/column_table.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstddef> | ||
| 5 | #include <cstdint> | ||
| 6 | #include <functional> | ||
| 7 | #include <map> | ||
| 8 | #include <optional> | ||
| 9 | #include <span> | ||
| 10 | #include <string> | ||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | #include "chrono_batch_render/device/buffer.h" | ||
| 14 | #include "chrono_batch_render/device/ref.h" | ||
| 15 | #include "chrono_batch_render/stage/columns/device_heap.h" | ||
| 16 | |||
| 17 | namespace chrono::batch_render { | ||
| 18 | |||
| 19 | struct TableColumn { | ||
| 20 | uint32_t cellBytes = 4; | ||
| 21 | uint32_t fill = 0; | ||
| 22 | }; | ||
| 23 | |||
| 24 | class ColumnTable { | ||
| 25 | public: | ||
| 26 | ColumnTable(DeviceHeap& heap, std::string label, std::vector<TableColumn> columns); | ||
| 27 | |||
| 28 | ✗ | const std::string& Label() const { | |
| 29 | ✗ | return m_label; | |
| 30 | } | ||
| 31 | |||
| 32 | 112725 | uint32_t Rows() const { | |
| 33 | 110034 | return m_rows; | |
| 34 | } | ||
| 35 | |||
| 36 | 9663 | uint32_t Capacity() const { | |
| 37 | 9663 | return m_capacity; | |
| 38 | } | ||
| 39 | |||
| 40 | uint32_t ColumnCount() const { | ||
| 41 | return uint32_t(m_columns.size()); | ||
| 42 | } | ||
| 43 | |||
| 44 | uint32_t CellBytes(uint32_t column) const; | ||
| 45 | uint32_t AddColumn(TableColumn column); | ||
| 46 | |||
| 47 | 9012612 | uint64_t Layout() const { | |
| 48 | 9012611 | return m_layout; | |
| 49 | } | ||
| 50 | |||
| 51 | uint32_t Allocate(uint32_t count, bool pageAligned = false); | ||
| 52 | uint32_t Acquire(); | ||
| 53 | void Release(uint32_t row); | ||
| 54 | |||
| 55 | uint64_t Pages(uint32_t column) const; | ||
| 56 | std::vector<device::BufferRange> Ranges(uint32_t column, uint32_t first, uint32_t count) const; | ||
| 57 | std::optional<device::BufferRange> Contiguous(uint32_t column, uint32_t first, | ||
| 58 | uint32_t count) const; | ||
| 59 | |||
| 60 | void Redirect(uint32_t column, uint32_t first, uint32_t count, Ref<device::Buffer> buffer); | ||
| 61 | Ref<device::Buffer> Restore(uint32_t column, uint32_t first); | ||
| 62 | bool Redirected(uint32_t column, uint32_t first, uint32_t count) const; | ||
| 63 | |||
| 64 | using Scatter = std::function<void(uint32_t column, std::span<const uint32_t> rows, | ||
| 65 | std::span<const std::byte> cells)>; | ||
| 66 | |||
| 67 | void Stage(uint32_t column, uint32_t first, std::span<const std::byte> bytes); | ||
| 68 | bool Staged() const; | ||
| 69 | void Flush(const Scatter& scatter = {}); | ||
| 70 | std::vector<std::byte> Read(uint32_t column, uint32_t first, uint32_t count); | ||
| 71 | |||
| 72 | private: | ||
| 73 | 19071 | struct Span { | |
| 74 | uint32_t first = 0; | ||
| 75 | uint32_t rows = 0; | ||
| 76 | std::vector<HeapBlock> blocks; | ||
| 77 | }; | ||
| 78 | |||
| 79 | 6 | struct Redirection { | |
| 80 | uint32_t first = 0; | ||
| 81 | uint32_t rows = 0; | ||
| 82 | Ref<device::Buffer> buffer; | ||
| 83 | }; | ||
| 84 | |||
| 85 | 597956 | struct Staging { | |
| 86 | std::vector<uint32_t> rows; | ||
| 87 | std::vector<std::byte> bytes; | ||
| 88 | size_t coalesceAt = 4096; | ||
| 89 | }; | ||
| 90 | |||
| 91 | static void Coalesce(Staging& staged, uint32_t cell); | ||
| 92 | |||
| 93 | const Span& Find(uint32_t row) const; | ||
| 94 | const Redirection* FindRedirection(uint32_t column, uint32_t row) const; | ||
| 95 | void PointPages(uint32_t column, uint32_t first, uint32_t count, uint64_t address); | ||
| 96 | void CheckRows(uint32_t first, uint32_t count) const; | ||
| 97 | void Grow(uint32_t count); | ||
| 98 | void WritePages(uint32_t firstPage, uint32_t pageCount); | ||
| 99 | |||
| 100 | DeviceHeap& m_heap; | ||
| 101 | std::string m_label; | ||
| 102 | std::vector<TableColumn> m_columns; | ||
| 103 | std::vector<Span> m_spans; | ||
| 104 | std::vector<std::vector<uint64_t>> m_pages; | ||
| 105 | Ref<device::Buffer> m_pageTable; | ||
| 106 | uint32_t m_pageCapacity = 0; | ||
| 107 | std::vector<Staging> m_staged; | ||
| 108 | std::vector<std::vector<Redirection>> m_redirections; | ||
| 109 | std::map<uint32_t, uint32_t> m_aligned; | ||
| 110 | std::vector<uint32_t> m_free; | ||
| 111 | uint32_t m_rows = 0; | ||
| 112 | uint32_t m_capacity = 0; | ||
| 113 | uint64_t m_layout = 0; | ||
| 114 | }; | ||
| 115 | |||
| 116 | } | ||
| 117 |