render/rt/ray_tracer.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | /// @file ray_tracer.cpp | ||
| 3 | /// @brief Keeping the acceleration structures up to date each frame. | ||
| 4 | #include "ernie/render/rt/ray_tracer.h" | ||
| 5 | |||
| 6 | #include "ernie/shaders/device/buffer_ref.h" | ||
| 7 | #include "ernie/shaders/rt/ray_tracer.h" | ||
| 8 | #include "ernie/shaders/scene/geometry.h" | ||
| 9 | #include "ernie/shaders/scene/shapes.h" | ||
| 10 | #include "ernie/util/profiler.h" | ||
| 11 | |||
| 12 | #include <array> | ||
| 13 | |||
| 14 | namespace ernie { | ||
| 15 | |||
| 16 | 15 | RayTracer::RayTracer(DeviceContext& context, Arenas& arenas, const ShaderCompiler& compiler, | |
| 17 | 15 | const GeometryPool& geometry) | |
| 18 | 15 | : geometry_(geometry), bottoms_(context, arenas, geometry), tops_(context, compiler) {} | |
| 19 | |||
| 20 | 34 | std::span<const ShaderModule> RayTracer::Modules() { | |
| 21 | 34 | static const std::array modules{shaders::kBufferRef, shaders::kGeometry, shaders::kShapes, | |
| 22 | 34 | shaders::kRayTracer}; | |
| 23 | 34 | return modules; | |
| 24 | } | ||
| 25 | |||
| 26 | 27 | void RayTracer::AddBuild(graph::Graph& graph, const GeometryPool::Changes& changes, | |
| 27 | const TransformGraph& transforms, const InstanceTable& instances) { | ||
| 28 | 27 | ERNIE_ZONE("Update the ray tracer"); | |
| 29 | 27 | const graph::Graph::ScopeGuard scope = graph.Scope("Ray tracer"); | |
| 30 | 27 | bottoms_.Apply(changes); | |
| 31 | 27 | bottoms_.AddBuilds(graph); | |
| 32 | 27 | const graph::Acceleration top = tops_.AddBuild(graph, transforms, instances, bottoms_); | |
| 33 | 27 | const DeviceColumn& records = geometry_.Records(); | |
| 34 | 27 | const DeviceColumn& colours = instances.Colours(); | |
| 35 | 27 | graph.Board().Put( | |
| 36 | 27 | TraceScene{.parameters = {.scene = tops_.Structure()->Address(), | |
| 37 | 27 | .records = ToBufferRef<shaders::GeometryRecord>(records)}, | |
| 38 | .top = top, | ||
| 39 | 27 | .records = graph.Import(records), | |
| 40 | 27 | .instances = instances.Count(), | |
| 41 | 27 | .colours = graph.Import(colours), | |
| 42 | 27 | .colourBuffer = ToBufferRef<float>(colours), | |
| 43 | 27 | .origin = transforms.Origin()}); | |
| 44 | 27 | } | |
| 45 | |||
| 46 | } // namespace ernie | ||
| 47 |