scene/tables/procedural.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #include "chrono_batch_render/scene/tables/procedural.h" | ||
| 3 | |||
| 4 | #include <string> | ||
| 5 | |||
| 6 | #include "chrono_batch_render/bvh/kernels/bvh.h" | ||
| 7 | #include "chrono_batch_render/device/device.h" | ||
| 8 | |||
| 9 | namespace chrono::batch_render { | ||
| 10 | |||
| 11 | 129 | void ProceduralBlas::Allocate(device::Device& device, bvh::Builder& builder, uint32_t count, | |
| 12 | std::string_view label) { | ||
| 13 | 129 | capacity = count; | |
| 14 | 129 | blas = nullptr; | |
| 15 | 129 | boxes = nullptr; | |
| 16 | 129 | fresh = true; | |
| 17 | 129 | if (count == 0) { | |
| 18 | return; | ||
| 19 | } | ||
| 20 | 242 | boxes = device.CreateBuffer({.bytes = uint64_t(count) * sizeof(BvhBox), | |
| 21 | .usage = device::BufferUsage::AccelBuildInput, | ||
| 22 | 121 | .label = std::string(label)}); | |
| 23 | 121 | blas = builder.CreateBlas( | |
| 24 | 121 | device::AccelBoxes{.boxes = boxes->Slice(0), .count = count, .refittable = true}); | |
| 25 | 242 | } | |
| 26 | |||
| 27 | 215 | void ProceduralBlas::Bound(ColumnStore& store) { | |
| 28 | 215 | if (bounds.count == 0) { | |
| 29 | 86 | bounds = store.Arrays(ColumnType::Float3Array).Allocate(2); | |
| 30 | } | ||
| 31 | 215 | } | |
| 32 | |||
| 33 | ✗ | void ProceduralBlas::Release(ColumnStore& store) { | |
| 34 | ✗ | if (bounds.count > 0) { | |
| 35 | ✗ | store.Arrays(ColumnType::Float3Array).Free(bounds); | |
| 36 | ✗ | bounds = {}; | |
| 37 | } | ||
| 38 | ✗ | } | |
| 39 | |||
| 40 | 205 | bool ProceduralBlas::Rebuilds(uint32_t maxRefits) { | |
| 41 | 205 | if (fresh || refits >= maxRefits) { | |
| 42 | 160 | fresh = false; | |
| 43 | 160 | refits = 0; | |
| 44 | 160 | return true; | |
| 45 | } | ||
| 46 | 45 | ++refits; | |
| 47 | 45 | return false; | |
| 48 | } | ||
| 49 | |||
| 50 | 283 | void ProceduralBlas::Hold(std::vector<Ref<const RefCounted>>& held) const { | |
| 51 | 283 | if (blas) { | |
| 52 | 275 | held.emplace_back(blas); | |
| 53 | 275 | held.emplace_back(boxes); | |
| 54 | } | ||
| 55 | 283 | } | |
| 56 | |||
| 57 | } | ||
| 58 |