GCC Code Coverage Report


ernie/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
15 / 15
100.0%
Branches:
12 / 24
50.0%
Functions:
-
-%

render/device_scene.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 /// @file device_scene.h
3 /// @brief The device scene: the managers that keep a scene's device state, and the graph each
4 /// frame runs to bring it up to date and then run the passes that read it, in one submission.
5 ///
6 /// DeviceScene device(context, arenas, scene, compiler);
7 /// device.Transforms().Bind(bucket, "xformOp:translate",
8 /// device.Columns().Bind(bucket, "xformOp:translate"));
9 /// const Ticket done = device.Execute([&](graph::Graph& graph) {
10 /// const graph::Buffer worlds = graph.Import(device.Transforms().Worlds(), "worlds");
11 /// graph.Add("Shade", ...);
12 /// });
13 #pragma once
14
15 #include "ernie/device/shader_compiler.h"
16 #include "ernie/graph/graph.h"
17 #include "ernie/render/geometry.h"
18 #include "ernie/render/instances.h"
19 #include "ernie/render/rt/ray_tracer.h"
20 #include "ernie/render/scene_columns.h"
21 #include "ernie/render/transform_graph.h"
22
23 #include <functional>
24 #include <memory>
25 #include <span>
26
27 namespace ernie {
28
29 /// @brief A scene on a device and the graph each frame runs: the columns bound on the device
30 /// follow the scene, world transforms compose from them, the geometry and its acceleration
31 /// structures follow, and then the frame's own passes run, finding what to trace as a
32 /// `TraceScene` on the graph's blackboard. Devices without ray queries get no ray tracer yet.
33 class DeviceScene {
34 public:
35 /// @param arenas Where the device columns live; `MemoryUse::Shared` to share them with CUDA.
36 DeviceScene(DeviceContext& context, Arenas& arenas, const Scene& scene,
37 const ShaderCompiler& compiler);
38 DeviceScene(const DeviceScene&) = delete;
39 DeviceScene& operator=(const DeviceScene&) = delete;
40
41 1 SceneColumns& Columns() {
42
1/2
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
1 return columns_;
43 }
44 5 TransformGraph& Transforms() {
45
6/12
<unknown function 41>:
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 time.
✗ Branch 14 not taken.
<unknown function 45>:
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
7 return transforms_;
46 }
47 GeometryPool& Geometry() {
48 return geometry_;
49 }
50 7 InstanceTable& Instances() {
51
3/6
<unknown function 45>:
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
<unknown function 50>:
✓ Branch 1 taken 1 time.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 time.
✗ Branch 5 not taken.
8 return instances_;
52 }
53 /// @return The ray tracer, or null on devices without ray queries.
54 5 RayTracer* Tracer() {
55
2/4
<unknown function 50>:
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
<unknown function 54>:
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
5 return tracer_.get();
56 }
57 /// @brief Keeps the render origin near a viewpoint: once it is more than `kRebaseDistance`
58 /// away, the origin moves to the viewpoint snapped to a `kRebaseDistance` grid, so a viewpoint
59 /// hovering at the threshold does not rebase back and forth.
60 /// @return Whether the origin moved.
61 bool Follow(const glm::dvec3& viewpoint);
62 /// Metres: far enough that rebases are rare, near enough that floats there resolve 0.1 mm.
63 static constexpr double kRebaseDistance = 1024.0;
64
65 /// @return Where the frames' transients come from.
66 graph::TransientPool& Pool() {
67 return pool_;
68 }
69
70 /// @brief Runs a frame on the main queue after `waits`: the columns' sync, the transforms,
71 /// then the passes `passes` adds.
72 /// @param binary Semaphores the frame waits on and signals, as a swapchain image's.
73 /// @return The frame's ticket.
74 /// @throws graph::GraphError when the passes cannot run.
75 Ticket Execute(const std::function<void(graph::Graph&)>& passes,
76 std::span<const Ticket> waits = {}, BinarySemaphores binary = {});
77
78 private:
79 DeviceContext& context_;
80 graph::TransientPool pool_;
81 SceneColumns columns_;
82 TransformGraph transforms_;
83 GeometryPool geometry_;
84 InstanceTable instances_;
85 std::unique_ptr<RayTracer> tracer_;
86 };
87
88 } // namespace ernie
89