chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
19 / 21
90.5%
Branches:
22 / 35
62.9%
Functions:
1 / 2, 3 excl
50.0%

bvh/builder.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <memory>
6 #include <optional>
7 #include <span>
8 #include <variant>
9 #include <vector>
10
11 #include "chrono_batch_render/bvh/kernels/bvh.h"
12 #include "chrono_batch_render/device/accel.h"
13 #include "chrono_batch_render/device/adapter.h"
14 #include "chrono_batch_render/device/buffer.h"
15 #include "chrono_batch_render/device/commands.h"
16 #include "chrono_batch_render/device/ref.h"
17 #include "chrono_batch_render/export.h"
18
19 namespace chrono::batch_render::device {
20 class Device;
21 }
22
23 namespace chrono::batch_render::bvh {
24
25 using Geometry = std::variant<device::AccelTriangles, device::AccelBoxes>;
26
27 class CHRONO_BATCH_RENDER_API Blas : public RefCounted {
28 public:
29 1437 device::Traversal Format() const {
30
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 1437 times.
✗ Branch 3 not taken.
1437 return m_format;
31 }
32
33 virtual uint64_t Handle() const = 0;
34
35 protected:
36
1/1
✓ Branch 1 taken 619 times.
619 explicit Blas(device::Traversal format) : m_format(format) {}
37
38 ✗ ~Blas() override = default;
39
40 private:
41 device::Traversal m_format;
42 };
43
44 class CHRONO_BATCH_RENDER_API Tlas : public RefCounted {
45 public:
46 785 device::Traversal Format() const {
47
1/3
✗ Branch 0 not taken.
✓ Branch 1 taken 785 times.
✗ Branch 3 not taken.
785 return m_format;
48 }
49
50 4027 uint32_t Count() const {
51
12/15
<unknown function 29>:
✗ Branch 0 not taken.
✓ Branch 1 taken 159 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 623 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 607 times.
✓ Branch 7 taken 16 times.
<unknown function 50>:
✓ Branch 0 taken 1 time.
✓ Branch 1 taken 919 times.
✓ Branch 2 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 3 taken 1 time.
✓ Branch 3 taken 909 times.
✓ Branch 5 taken 5 times.
✓ Branch 6 taken 1 time.
4027 return uint32_t(m_capacities.size());
52 }
53
54 2621 std::span<const uint32_t> Capacities() const {
55
4/8
✗ Branch 1 not taken.
✓ Branch 2 taken 159 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 169 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✓ Branch 8 taken 742 times.
✓ Branch 11 taken 16 times.
2621 return m_capacities;
56 }
57
58 uint64_t Handle(uint32_t world = 0) const;
59
60 318 device::Buffer& Handles() const {
61
2/3
<unknown function 50>:
✓ Branch 1 taken 1 time.
<unknown function 60>:
✓ Branch 0 taken 317 times.
✗ Branch 1 not taken.
318 return *m_table;
62 }
63
64 protected:
65 Tlas(device::Traversal format, std::span<const uint32_t> capacities);
66
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
624 ~Tlas() override = default;
67
68 void SetHandles(device::Device& device, std::vector<uint64_t> handles);
69
70 private:
71 device::Traversal m_format;
72 std::vector<uint32_t> m_capacities;
73 std::vector<uint64_t> m_handles;
74 Ref<device::Buffer> m_table;
75 };
76
77 class CHRONO_BATCH_RENDER_API Builder {
78 public:
79 static std::unique_ptr<Builder> Create(device::Device& device,
80 device::Traversal format = device::Traversal::Auto);
81
82 virtual ~Builder() = default;
83 Builder(const Builder&) = delete;
84 Builder& operator=(const Builder&) = delete;
85
86 virtual device::Traversal Format() const = 0;
87
88 ✗ virtual void Prepare() {}
89
90 virtual Ref<Blas> CreateBlas(const Geometry& geometry) = 0;
91 virtual Ref<Tlas> CreateTlas(std::span<const uint32_t> capacities) = 0;
92
93 virtual void Build(device::CommandEncoder& encoder, std::span<const Ref<Blas>> blases) = 0;
94 virtual void Refit(device::CommandEncoder& encoder, std::span<const Ref<Blas>> blases) = 0;
95 virtual void Build(device::CommandEncoder& encoder, Tlas& tlas, device::BufferRange instances,
96 std::optional<device::BufferRange> counts = std::nullopt,
97 std::span<const uint32_t> worlds = {}) = 0;
98 virtual void Refit(device::CommandEncoder& encoder, Tlas& tlas, device::BufferRange instances,
99 std::optional<device::BufferRange> counts = std::nullopt,
100 std::span<const uint32_t> worlds = {}) = 0;
101 virtual void SubmitRefit(device::CommandEncoder&& encoder, Tlas& tlas,
102 device::BufferRange instances,
103 std::optional<device::BufferRange> counts = std::nullopt,
104 std::span<const uint32_t> worlds = {});
105
106 protected:
107 414 explicit Builder(device::Device& device) : m_device(device) {}
108
109 device::Device& m_device;
110 };
111
112 }
113