chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
9 / 9
100.0%
Branches:
10 / 24
41.7%
Functions:
2 / 2, 1 excl
100.0%

scene/tables/points.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <algorithm>
5 #include <cstdint>
6 #include <memory>
7 #include <span>
8 #include <string_view>
9 #include <unordered_map>
10 #include <vector>
11
12 #include "chrono_batch_render/algorithms/radix_sort.h"
13 #include "chrono_batch_render/bvh/builder.h"
14 #include "chrono_batch_render/device/buffer.h"
15 #include "chrono_batch_render/device/program.h"
16 #include "chrono_batch_render/device/ref.h"
17 #include "chrono_batch_render/scene/records/points.h"
18 #include "chrono_batch_render/scene/tables/procedural.h"
19 #include "chrono_batch_render/scene/tables/storage.h"
20 #include "chrono_batch_render/scene/tables/table.h"
21 #include "chrono_batch_render/stage/structure/structure.h"
22
23 namespace chrono::batch_render {
24
25 358 struct PointsStats {
26 uint32_t clouds = 0;
27 uint32_t built = 0;
28 uint32_t refit = 0;
29 uint32_t sorted = 0;
30 uint32_t points = 0;
31 uint32_t capacity = 0;
32 };
33
34 class PointsTable : public RenderTable {
35 public:
36 358 PointsTable(Structure& structure, bvh::Builder& builder, uint32_t maxRefits = 16,
37 uint32_t pointsPerBox = 1)
38 358 : m_structure(structure), m_builder(builder), m_maxRefits(maxRefits),
39
2/9
✗ Branch 0 not taken.
✓ Branch 1 taken 358 times.
✓ Branch 3 taken 358 times.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
358 m_pointsPerBox(std::max(pointsPerBox, 1u)) {}
40
41 951 std::string_view Name() const override {
42 951 return "points";
43 }
44
45 std::span<const ColumnRef> Inputs() const override;
46 std::span<const TableId> TableOutputs() const override;
47 void Describe(RenderTables& tables) const override;
48 void Prepare() override;
49 void Run(const ChangeSet& changes, TableVersions& versions) override;
50 void Hold(std::vector<Ref<const RefCounted>>& held) const override;
51
52 const PointsStats& Stats() const {
53 return m_stats;
54 }
55
56 37 const PointsRecord& Record(uint32_t pointsRow) const {
57
8/15
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✗ Branch 4 not taken.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
✓ Branch 11 taken 1 time.
✓ Branch 13 taken 1 time.
✗ Branch 14 not taken.
✓ Branch 15 taken 1 time.
✗ Branch 16 not taken.
✓ Branch 18 taken 20 times.
✗ Branch 19 not taken.
62 return m_records.Row(pointsRow);
58 }
59
60 private:
61 48 struct Cloud {
62 uint32_t prim = kNoPrim;
63 uint32_t generation = 0;
64 uint32_t pointBasedRow = kNoRow;
65 uint32_t row = kNoRow;
66 uint32_t count = 0;
67 uint32_t capacity = 0;
68 ProceduralBlas bvh;
69 Ref<device::Buffer> order;
70 Ref<device::Buffer> packed;
71 bool update = false;
72 };
73
74 void Place(uint32_t prim);
75 void Forget(uint32_t prim);
76 void Link(Cloud& cloud);
77 void Build(std::vector<uint32_t>& updated);
78 device::Program& Kernels();
79
80 Structure& m_structure;
81 bvh::Builder& m_builder;
82 uint32_t m_maxRefits;
83 uint32_t m_pointsPerBox;
84 std::unique_ptr<algorithms::RadixSort> m_sort;
85 uint32_t m_sortCapacity = 0;
86 Ref<device::Buffer> m_keys;
87 Ref<device::Buffer> m_values;
88 Ref<device::Program> m_program;
89 std::unordered_map<uint32_t, Cloud> m_clouds;
90 std::unordered_map<uint32_t, uint32_t> m_byPointBasedRow;
91 std::unordered_map<uint32_t, uint32_t> m_byRow;
92 RecordTable<PointsRecord> m_records{"points records"};
93 std::vector<uint32_t> m_relinked;
94 PointsStats m_stats;
95 };
96
97 }
98