bvh/lbvh.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstdint> | ||
| 5 | #include <optional> | ||
| 6 | #include <span> | ||
| 7 | |||
| 8 | #include "chrono_batch_render/algorithms/radix_sort.h" | ||
| 9 | #include "chrono_batch_render/bvh/builder.h" | ||
| 10 | #include "chrono_batch_render/bvh/kernels/lbvh.h" | ||
| 11 | #include "chrono_batch_render/device/buffer.h" | ||
| 12 | #include "chrono_batch_render/device/commands.h" | ||
| 13 | #include "chrono_batch_render/device/program.h" | ||
| 14 | #include "chrono_batch_render/device/ref.h" | ||
| 15 | |||
| 16 | namespace chrono::batch_render::device { | ||
| 17 | class Device; | ||
| 18 | } | ||
| 19 | |||
| 20 | namespace chrono::batch_render::bvh { | ||
| 21 | |||
| 22 | LbvhGeometry LbvhEntry(device::Program& program, const char* what, const Geometry& geometry); | ||
| 23 | |||
| 24 | class LbvhBuilder { | ||
| 25 | public: | ||
| 26 | static constexpr uint32_t kMaxPrimitives = 65535 * 256; | ||
| 27 | |||
| 28 | LbvhBuilder(device::Device& device, uint32_t capacity, uint32_t segments = 1); | ||
| 29 | |||
| 30 | 1573 | uint32_t Capacity() const { | |
| 31 | 1573 | return m_capacity; | |
| 32 | } | ||
| 33 | |||
| 34 | 1159 | uint32_t Segments() const { | |
| 35 | 1159 | return m_segments; | |
| 36 | } | ||
| 37 | |||
| 38 | void Build(device::CommandEncoder& encoder, std::span<const Geometry> geometries, | ||
| 39 | std::span<const device::BufferRange> outputs) const; | ||
| 40 | |||
| 41 | void Build(device::CommandEncoder& encoder, device::BufferRange instances, | ||
| 42 | std::span<const uint32_t> capacities, std::optional<device::BufferRange> counts, | ||
| 43 | std::span<const device::BufferRange> outputs) const; | ||
| 44 | |||
| 45 | private: | ||
| 46 | void Record(device::CommandEncoder& encoder, LbvhParams params, | ||
| 47 | std::span<const uint32_t> capacities, std::span<const device::BufferRange> outputs, | ||
| 48 | std::span<const LbvhGeometry> geometries) const; | ||
| 49 | |||
| 50 | device::BufferRange Words(uint64_t at, uint64_t words) const; | ||
| 51 | |||
| 52 | uint32_t m_capacity; | ||
| 53 | uint32_t m_segments; | ||
| 54 | Ref<device::Program> m_program; | ||
| 55 | device::Kernel* m_prepare; | ||
| 56 | device::Kernel* m_morton; | ||
| 57 | device::Kernel* m_hierarchy; | ||
| 58 | device::Kernel* m_fitBoxes; | ||
| 59 | device::Kernel* m_seed; | ||
| 60 | device::Kernel* m_advance; | ||
| 61 | device::Kernel* m_collapse; | ||
| 62 | device::Kernel* m_finish; | ||
| 63 | algorithms::RadixSort m_sort; | ||
| 64 | Ref<device::Buffer> m_scratch; | ||
| 65 | Ref<device::Buffer> m_layout; | ||
| 66 | Ref<device::Buffer> m_state; | ||
| 67 | LbvhParams m_params{}; | ||
| 68 | }; | ||
| 69 | |||
| 70 | } | ||
| 71 |