chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
19 / 23
82.6%
Branches:
39 / 59
66.1%
Functions:
-
-%

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
0/1
✗ Branch 1 not taken.
✗ return m_label;
30 }
31
32 112725 uint32_t Rows() const {
33
18/20
<unknown function 28>:
✓ Branch 0 taken 138 times.
✓ Branch 1 taken 2582 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 81670 times.
<unknown function 32>:
✓ Branch 0 taken 4227 times.
✓ Branch 0 taken 3740 times.
✓ Branch 1 taken 801 times.
✓ Branch 1 taken 4042 times.
✓ Branch 2 taken 320 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
✓ Branch 4 taken 7 times.
✓ Branch 4 taken 626 times.
✓ Branch 5 taken 9 times.
✓ Branch 7 taken 2976 times.
✓ Branch 8 taken 9 times.
✓ Branch 10 taken 498 times.
✓ Branch 11 taken 9 times.
✓ Branch 13 taken 498 times.
✓ Branch 14 taken 311 times.
110034 return m_rows;
34 }
35
36 9663 uint32_t Capacity() const {
37
11/13
<unknown function 32>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 1 taken 1502 times.
✓ Branch 2 taken 37 times.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 325 times.
✓ Branch 4 taken 498 times.
✓ Branch 6 taken 331 times.
✓ Branch 7 taken 498 times.
✓ Branch 10 taken 498 times.
✓ Branch 13 taken 498 times.
<unknown function 36>:
✓ Branch 0 taken 140 times.
✓ Branch 1 taken 1480 times.
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
7/7
<unknown function 28>:
✓ Branch 1 taken 80969 times.
<unknown function 32>:
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
✓ Branch 7 taken 1 time.
✓ Branch 10 taken 1 time.
✓ Branch 13 taken 1 time.
✓ Branch 17 taken 1 time.
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
3/18
<unknown function 28>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
<unknown function 32>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
<unknown function 73>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
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