bvh/common.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <concepts> | ||
| 5 | #include <cstddef> | ||
| 6 | #include <cstdint> | ||
| 7 | #include <cstring> | ||
| 8 | #include <memory> | ||
| 9 | #include <span> | ||
| 10 | #include <string> | ||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | #include "chrono_batch_render/bvh/builder.h" | ||
| 14 | #include "chrono_batch_render/device/accel.h" | ||
| 15 | #include "chrono_batch_render/device/buffer.h" | ||
| 16 | #include "chrono_batch_render/device/kernels/shared.h" | ||
| 17 | #include "chrono_batch_render/util/error.h" | ||
| 18 | |||
| 19 | namespace chrono::batch_render::bvh { | ||
| 20 | |||
| 21 | std::unique_ptr<Builder> CreateSoftwareBuilder(device::Device& device); | ||
| 22 | std::unique_ptr<Builder> CreateHardwareBuilder(device::Device& device); | ||
| 23 | |||
| 24 | uint32_t Kind(const Geometry& geometry); | ||
| 25 | uint32_t PrimitiveCount(const Geometry& geometry); | ||
| 26 | device::AccelInput ToAccelInput(const Geometry& geometry); | ||
| 27 | std::vector<Ref<device::Buffer>> GeometryBuffers(const Geometry& geometry); | ||
| 28 | uint64_t StorageBytes(uint32_t count, uint32_t kind); | ||
| 29 | |||
| 30 | uint64_t Total(std::span<const uint32_t> capacities); | ||
| 31 | std::vector<uint32_t> Offsets(std::span<const uint32_t> capacities); | ||
| 32 | |||
| 33 | device::Buffer& Reserve(device::Device& device, Ref<device::Buffer>& buffer, | ||
| 34 | const device::BufferDesc& desc); | ||
| 35 | |||
| 36 | void RequireInstances(const char* what, const Tlas& tlas, device::BufferRange instances); | ||
| 37 | std::vector<uint32_t> SelectWorlds(const char* what, const Tlas& tlas, | ||
| 38 | std::span<const uint32_t> worlds); | ||
| 39 | void RequireRefittable(const char* what, const device::AccelInput& input); | ||
| 40 | |||
| 41 | const char* FormatName(device::Traversal format); | ||
| 42 | |||
| 43 | template <class Concrete, class Structure> | ||
| 44 | 2222 | const Concrete& RequireFormat(const char* what, const Structure& structure) { | |
| 45 | 2222 | if (structure.Format() != Concrete::kFormat) { | |
| 46 | ✗ | throw Error("{} of a {} {} by a builder of {} ones", what, FormatName(structure.Format()), | |
| 47 | std::derived_from<Concrete, Blas> ? "BLAS" : "TLAS", | ||
| 48 | ✗ | FormatName(Concrete::kFormat)); | |
| 49 | } | ||
| 50 | 2222 | return static_cast<const Concrete&>(structure); | |
| 51 | } | ||
| 52 | |||
| 53 | 222 | class Tables { | |
| 54 | public: | ||
| 55 | 872 | template <class T> uint64_t Add(const std::vector<T>& values) { | |
| 56 | 872 | const uint64_t at = RoundUp(m_bytes.size(), alignof(T)); | |
| 57 | 872 | m_bytes.resize(at + values.size() * sizeof(T)); | |
| 58 | 872 | std::memcpy(m_bytes.data() + at, values.data(), values.size() * sizeof(T)); | |
| 59 | 872 | return at; | |
| 60 | } | ||
| 61 | |||
| 62 | Ref<device::Buffer> Upload(device::Device& device, std::string label) const; | ||
| 63 | |||
| 64 | private: | ||
| 65 | std::vector<std::byte> m_bytes; | ||
| 66 | }; | ||
| 67 | |||
| 68 | } | ||
| 69 |