chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
8 / 9
88.9%
Branches:
15 / 30
50.0%
Functions:
-
-%

stage/columns/array_pool.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstddef>
5 #include <cstdint>
6 #include <span>
7 #include <string>
8 #include <unordered_map>
9 #include <vector>
10
11 #include "chrono_batch_render/stage/columns/device_heap.h"
12 #include "chrono_batch_render/stage/schema/types.h"
13
14 namespace chrono::batch_render {
15
16 class ArrayPool {
17 public:
18 struct StagedCopy {
19 uint64_t dst;
20 uint64_t source;
21 uint32_t words;
22 };
23
24 ArrayPool(DeviceHeap& heap, std::string label, uint32_t itemBytes);
25
26 1976 uint32_t ItemBytes() const {
27
4/10
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 3 taken 732 times.
✓ Branch 4 taken 1215 times.
✗ Branch 5 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 8 not taken.
1976 return m_itemBytes;
28 }
29
30 5 uint32_t ArrayCount() const {
31
4/4
✓ Branch 1 taken 1 time.
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 1 time.
✓ Branch 4 taken 1 time.
5 return uint32_t(m_arrays.size());
32 }
33
34 ArrayRef Allocate(uint32_t count, uint32_t capacity = 0);
35 std::vector<ArrayRef> AllocateRun(std::span<const uint32_t> counts);
36 std::vector<ArrayRef> Borrow(Ref<device::Buffer> buffer, uint32_t arrays, uint32_t count);
37 bool Borrowed(const ArrayRef& array) const;
38 ArrayRef Share(const ArrayRef& array);
39 void Free(const ArrayRef& array);
40 uint32_t References(const ArrayRef& array) const;
41
42 device::BufferRange Range(const ArrayRef& array) const;
43 void Write(const ArrayRef& array, std::span<const std::byte> bytes);
44 void Stage(const ArrayRef& array, std::span<const std::byte> bytes);
45
46 144241 std::span<const std::byte> StagedBytes() const {
47
2/2
✓ Branch 0 taken 143865 times.
✓ Branch 1 taken 376 times.
144241 return m_stagedBytes;
48 }
49
50 std::vector<StagedCopy> TakeStaged(uint64_t base);
51 std::vector<std::byte> Read(const ArrayRef& array);
52 std::vector<std::vector<std::byte>> Read(std::span<const ArrayRef> arrays);
53
54 private:
55
5/14
<unknown function 30>:
✗ Branch 0 not taken.
✓ Branch 1 taken 1005 times.
<unknown function 46>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
<unknown function 55>:
✗ Branch 0 not taken.
✓ Branch 1 taken 3368 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1847 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 201 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 2852 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
12125 struct Run {
56 HeapBlock block;
57 uint32_t live = 0;
58 Ref<device::Buffer> borrowed;
59 };
60
61 struct Entry {
62 uint32_t run = 0;
63 uint32_t references = 0;
64 };
65
66 struct Staged {
67 ArrayRef array;
68 uint64_t offset = 0;
69 uint64_t bytes = 0;
70 };
71
72 void FlushStaged();
73 const Entry& Lookup(const ArrayRef& array) const;
74 uint32_t AddRun(HeapBlock block, uint32_t live);
75
76 DeviceHeap& m_heap;
77 std::string m_label;
78 uint32_t m_itemBytes;
79 std::vector<Run> m_runs;
80 std::vector<uint32_t> m_freeRuns;
81 std::unordered_map<uint64_t, Entry> m_arrays;
82 std::vector<Staged> m_staged;
83 std::vector<std::byte> m_stagedBytes;
84 std::unordered_map<uint64_t, size_t> m_stagedIndices;
85 };
86
87 }
88