chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
11 / 11
100.0%
Branches:
11 / 35
31.4%
Functions:
3 / 3, 1 excl
100.0%

scene/tables/curves.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <algorithm>
5 #include <cstdint>
6 #include <deque>
7 #include <memory>
8 #include <optional>
9 #include <span>
10 #include <string>
11 #include <string_view>
12 #include <unordered_map>
13 #include <utility>
14 #include <vector>
15
16 #include "chrono_batch_render/algorithms/scan.h"
17 #include "chrono_batch_render/bvh/builder.h"
18 #include "chrono_batch_render/device/buffer.h"
19 #include "chrono_batch_render/device/operation.h"
20 #include "chrono_batch_render/device/program.h"
21 #include "chrono_batch_render/device/ref.h"
22 #include "chrono_batch_render/scene/records/curves.h"
23 #include "chrono_batch_render/scene/tables/procedural.h"
24 #include "chrono_batch_render/scene/tables/storage.h"
25 #include "chrono_batch_render/scene/tables/table.h"
26 #include "chrono_batch_render/stage/structure/structure.h"
27
28 namespace chrono::batch_render {
29
30 357 struct CurvesStats {
31 uint32_t prims = 0;
32 uint32_t built = 0;
33 uint32_t refit = 0;
34 uint32_t points = 0;
35 uint32_t curves = 0;
36 uint32_t segments = 0;
37 uint32_t capacity = 0;
38 uint32_t readBacks = 0;
39 };
40
41 inline constexpr const char* kShapeOptionsFile =
42 "chrono_batch_render/render/kernels/shapes/options.slang";
43
44 class CurvesTable : public RenderTable {
45 public:
46 357 CurvesTable(Structure& structure, bvh::Builder& builder, uint32_t maxRefits = 16,
47 float tolerance = kDefaultCurveTolerance, uint32_t maxSteps = kDefaultMaxCurveSteps,
48 bool exact = false)
49 357 : m_structure(structure), m_builder(builder), m_maxRefits(maxRefits),
50
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
357 m_tolerance(tolerance), m_maxSteps(std::clamp(maxSteps, 1u, kMostCurveSteps)),
51
3/22
✗ Branch 0 not taken.
✓ Branch 1 taken 357 times.
✓ Branch 3 taken 357 times.
✓ Branch 8 taken 357 times.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
714 m_exact(exact) {}
52
53 ~CurvesTable() override;
54
55 938 std::string_view Name() const override {
56 938 return "curves";
57 }
58
59 std::span<const ColumnRef> Inputs() const override;
60 std::span<const TableId> TableOutputs() const override;
61 void Describe(RenderTables& tables) const override;
62 void Prepare() override;
63 void Run(const ChangeSet& changes, TableVersions& versions) override;
64 void Hold(std::vector<Ref<const RefCounted>>& held) const override;
65
66 8599 bool Pending() const override {
67
3/4
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 8585 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 14 times.
8599 return !m_pending.empty() && m_pending.front().download.Ready();
68 }
69
70 bool Exact() const {
71 return m_exact;
72 }
73
74 std::string ShapeOptions() const;
75
76 const CurvesStats& Stats() const {
77 return m_stats;
78 }
79
80 3 const CurvesRecord& Record(uint32_t curvesRow) const {
81
4/7
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 time.
✗ Branch 9 not taken.
6 return m_records.Row(curvesRow);
82 }
83
84 std::vector<uint32_t> SpanSteps(uint32_t curvesRow) const;
85
86 private:
87 struct Prim {
88 uint32_t prim = kNoPrim;
89 uint32_t generation = 0;
90 uint32_t pointBasedRow = kNoRow;
91 uint32_t curvesRow = kNoRow;
92 uint32_t row = kNoRow;
93 uint32_t basisRow = kNoRow;
94 uint32_t kindRow = kNoRow;
95 uint32_t kind = kCurveKindBasis;
96 uint32_t count = 0;
97 uint32_t curveCount = 0;
98 uint32_t pointCapacity = 0;
99 uint32_t curveCapacity = 0;
100 uint32_t wanted = 0;
101 ProceduralBlas bvh;
102 Ref<device::Buffer> segments;
103 Ref<device::Buffer> spanFirst;
104 Ref<device::Buffer> spanSteps;
105 Ref<device::Buffer> starts;
106 Ref<device::Buffer> varyingStarts;
107 Ref<device::Buffer> knotStarts;
108 bool drawn = false;
109 bool update = false;
110 };
111
112 void Place(uint32_t prim);
113 void Forget(uint32_t prim);
114 void Link(Prim& curves);
115 void Resize(Prim& curves, uint32_t segments);
116 void WriteRecord(Prim& curves);
117 void EnsureScratch(uint32_t items);
118 void Collect();
119 void Build(std::vector<uint32_t>& updated);
120 device::Program& Kernels();
121
122 Structure& m_structure;
123 bvh::Builder& m_builder;
124 uint32_t m_maxRefits;
125 float m_tolerance;
126 uint32_t m_maxSteps;
127 bool m_exact;
128 uint64_t m_seen = 0;
129 std::unique_ptr<algorithms::Scan> m_scan;
130 uint32_t m_scanCapacity = 0;
131 Ref<device::Buffer> m_counts;
132 Ref<device::Buffer> m_scanned;
133 Ref<device::Buffer> m_varying;
134 Ref<device::Buffer> m_scannedVarying;
135 Ref<device::Buffer> m_steps;
136 Ref<device::Buffer> m_stepFirst;
137 Ref<device::Buffer> m_orders;
138 Ref<device::Buffer> m_scannedOrders;
139 Ref<device::Program> m_program;
140 std::unordered_map<uint32_t, Prim> m_prims;
141 std::unordered_map<uint32_t, uint32_t> m_byPointBasedRow;
142 std::unordered_map<uint32_t, uint32_t> m_byCurvesRow;
143 std::unordered_map<uint32_t, uint32_t> m_byHermiteRow;
144 std::unordered_map<uint32_t, uint32_t> m_byNurbsRow;
145 RecordTable<CurvesRecord> m_records{"curves records"};
146 std::vector<uint32_t> m_relinked;
147
148 struct PendingTotals {
149 device::Download download;
150 Ref<device::Buffer> totals;
151 std::vector<std::pair<uint32_t, uint32_t>> prims;
152 std::vector<bool> restepped;
153 };
154
155 std::deque<PendingTotals> m_pending;
156 CurvesStats m_stats;
157 };
158
159 }
160