render/device_scene.cpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | /// @file device_scene.cpp | ||
| 3 | /// @brief Building and running each frame's graph over the device scene. | ||
| 4 | #include "ernie/render/device_scene.h" | ||
| 5 | |||
| 6 | #include <glm/common.hpp> | ||
| 7 | #include <glm/geometric.hpp> | ||
| 8 | |||
| 9 | namespace ernie { | ||
| 10 | |||
| 11 | 15 | DeviceScene::DeviceScene(DeviceContext& context, Arenas& arenas, const Scene& scene, | |
| 12 | 15 | const ShaderCompiler& compiler) | |
| 13 | 15 | : context_(context), pool_(context), columns_(context, arenas, scene), | |
| 14 | 15 | transforms_(context, arenas, scene, compiler), geometry_(context, arenas, scene), | |
| 15 | 15 | instances_(context, arenas) { | |
| 16 | 15 | if (context.Capabilities().rayQuery) { | |
| 17 | 15 | tracer_ = std::make_unique<RayTracer>(context, arenas, compiler, geometry_); | |
| 18 | } | ||
| 19 | 15 | } | |
| 20 | |||
| 21 | 16 | bool DeviceScene::Follow(const glm::dvec3& viewpoint) { | |
| 22 | 16 | if (glm::length(viewpoint - transforms_.Origin()) <= kRebaseDistance) { | |
| 23 | return false; | ||
| 24 | } | ||
| 25 | 2 | ERNIE_ZONE("Rebase the render origin"); | |
| 26 | 4 | transforms_.SetOrigin(glm::round(viewpoint / kRebaseDistance) * kRebaseDistance); | |
| 27 | 2 | return true; | |
| 28 | 2 | } | |
| 29 | |||
| 30 | 27 | Ticket DeviceScene::Execute(const std::function<void(graph::Graph&)>& passes, | |
| 31 | std::span<const Ticket> waits, BinarySemaphores binary) { | ||
| 32 | 27 | ERNIE_ZONE("Run a frame"); | |
| 33 | 27 | graph::Graph graph(context_, pool_); | |
| 34 | 27 | columns_.AddSync(graph); | |
| 35 | 27 | transforms_.AddUpdate(graph); | |
| 36 | 27 | const GeometryPool::Changes changes = geometry_.Update(); | |
| 37 | 27 | instances_.Apply(changes); | |
| 38 | 27 | geometry_.AddUploads(graph); | |
| 39 | 27 | instances_.AddUploads(graph); | |
| 40 | 27 | if (tracer_) { | |
| 41 | 27 | tracer_->AddBuild(graph, changes, transforms_, instances_); | |
| 42 | } | ||
| 43 | 27 | if (passes) { | |
| 44 | 25 | passes(graph); | |
| 45 | } | ||
| 46 | 54 | return graph.Execute(context_.Main(), waits, binary); | |
| 47 | 27 | } | |
| 48 | |||
| 49 | } // namespace ernie | ||
| 50 |