chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
48 / 53
90.6%
Branches:
45 / 54
83.3%
Functions:
10 / 11
90.9%

stage/publish/change_set.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/stage/publish/change_set.h"
3
4 #include <algorithm>
5
6 #include "chrono_batch_render/device/queue.h"
7 #include "chrono_batch_render/stage/columns/kernels/changes.h"
8
9 namespace chrono::batch_render {
10
11 1768 device::BufferRange ChangedRows::Count() const {
12 1768 return m_buffer->Slice(0, sizeof(uint32_t));
13 }
14
15 ✗ device::BufferRange ChangedRows::Rows() const {
16
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ return m_buffer->Slice(kChangedRowsOffset * sizeof(uint32_t),
17
0/2
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ std::max<uint64_t>(m_capacity, 1) * sizeof(uint32_t));
18 }
19
20 1768 std::vector<uint32_t> ChangedRows::ToHost() const {
21
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1768 times.
1768 if (!m_buffer) {
22 ✗ return {};
23 }
24 1768 device::Queue& queue = m_buffer->GetDevice().GetQueue();
25 1768 uint32_t count = 0;
26 1768 queue.Read(Count(), &count);
27 1768 std::vector<uint32_t> rows(count);
28
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 1735 times.
1768 if (count > 0) {
29
2/2
✓ Branch 1 taken 33 times.
✓ Branch 4 taken 33 times.
33 queue.Read(m_buffer->Slice(kChangedRowsOffset * sizeof(uint32_t), count * sizeof(uint32_t)),
30
1/1
✓ Branch 1 taken 33 times.
33 rows.data());
31 }
32 1768 std::ranges::sort(rows);
33 1768 return rows;
34 1768 }
35
36 1774 const ChangedRows* ChangeSet::Rows(ColumnRef column) const {
37 1774 const auto found = std::ranges::find_if(
38
2/2
✓ Branch 0 taken 6160 times.
✓ Branch 1 taken 1773 times.
9707 columns, [&](const ChangedRows& rows) { return rows.Column().column == column.column; });
39
2/2
✓ Branch 0 taken 1773 times.
✓ Branch 1 taken 1 time.
1774 return found == columns.end() ? nullptr : &*found;
40 }
41
42 8149 std::span<const uint32_t> ChangeSet::ArrayRows(ColumnRef column) const {
43
3/4
✓ Branch 0 taken 8149 times.
✓ Branch 1 taken 17263 times.
✓ Branch 2 taken 25412 times.
✗ Branch 3 not taken.
25412 for (const auto& [at, rows] : arrays) {
44
2/2
✓ Branch 0 taken 8149 times.
✓ Branch 1 taken 17263 times.
25412 if (at.column == column.column) {
45 8149 return rows;
46 }
47 }
48 ✗ return {};
49 }
50
51 2583 bool ChangeSet::Wrote(TableId table) const {
52 2583 return std::ranges::find(wrote, table) != wrote.end();
53 }
54
55 3 bool ChangeSet::World(uint32_t world) const {
56
4/4
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 1 time.
3 return Global() || std::ranges::binary_search(worlds, world);
57 }
58
59 1349 bool ChangeSet::Global() const {
60
4/4
✓ Branch 0 taken 1339 times.
✓ Branch 1 taken 10 times.
✓ Branch 2 taken 62 times.
✓ Branch 3 taken 1277 times.
1349 return !worlds.empty() && worlds.back() == kGlobalWorld;
61 }
62
63 4948 void TableVersions::Record(TableId table, std::span<const uint32_t> worlds) {
64 4948 ++m_sequence;
65
2/2
✓ Branch 0 taken 2818 times.
✓ Branch 1 taken 2130 times.
4948 if (uint32_t(table) >= m_versions.size()) {
66 2818 m_versions.resize(uint32_t(table) + 1);
67 }
68 4948 m_versions[uint32_t(table)] = m_sequence;
69
1/1
✓ Branch 2 taken 4948 times.
4948 Entry& entry = m_entries.emplace_back(Entry{m_sequence, table, {worlds.begin(), worlds.end()}});
70 4948 std::ranges::sort(entry.worlds);
71 4948 entry.worlds.erase(std::ranges::unique(entry.worlds).begin(), entry.worlds.end());
72 4948 }
73
74 8763 void TableVersions::Collect(TableId table, uint64_t since, std::vector<uint32_t>& worlds) const {
75
2/2
✓ Branch 0 taken 98350 times.
✓ Branch 1 taken 8763 times.
107113 for (const Entry& entry : m_entries) {
76
4/4
✓ Branch 0 taken 17226 times.
✓ Branch 1 taken 81124 times.
✓ Branch 2 taken 8383 times.
✓ Branch 3 taken 8843 times.
98350 if (entry.table != table || entry.sequence <= since) {
77 89507 continue;
78 }
79 8843 worlds.insert(worlds.end(), entry.worlds.begin(), entry.worlds.end());
80 }
81 8763 std::ranges::sort(worlds);
82 8763 worlds.erase(std::ranges::unique(worlds).begin(), worlds.end());
83 8763 }
84
85 1167 void TableVersions::Trim(uint64_t seen) {
86
13/16
✓ Branch 0 taken 532 times.
✓ Branch 1 taken 1522 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1522 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1522 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 1522 times.
✓ Branch 8 taken 18 times.
✓ Branch 9 taken 100 times.
✓ Branch 10 taken 51 times.
✓ Branch 11 taken 232 times.
✓ Branch 12 taken 42 times.
✓ Branch 13 taken 297 times.
✓ Branch 14 taken 2430 times.
✓ Branch 15 taken 2342 times.
8733 std::erase_if(m_entries, [&](const Entry& entry) { return entry.sequence <= seen; });
87 1167 }
88
89 }
90