chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
54 / 55
98.2%
Branches:
56 / 69
81.2%
Functions:
5 / 5
100.0%

scene/tables/surfaces.cpp
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #include "chrono_batch_render/scene/tables/surfaces.h"
3
4 #include <algorithm>
5 #include <set>
6
7 #include "chrono_batch_render/device/commands.h"
8 #include "chrono_batch_render/device/queue.h"
9 #include "chrono_batch_render/scene/kernels.h"
10 #include "chrono_batch_render/scene/records/render_tables.h"
11 #include "chrono_batch_render/scene/schema/columns.h"
12 #include "chrono_batch_render/scene/tables/kernels/surfaces.h"
13 #include "chrono_batch_render/stage/publish/change_set.h"
14 #include "chrono_batch_render/util/profiler.h"
15
16 namespace chrono::batch_render {
17
18 namespace {
19
20 constexpr ColumnRef kInputs[] = {kGprimPrimvars,
21 kGprimDisplayColor,
22 kGprimDisplayOpacity,
23 kPointBasedNormals,
24 kPointBasedNormalsInterpolation,
25 kMeshSubdivisionScheme,
26 kPointInstancerPrimvars,
27 kPointInstancerIds};
28
29 }
30
31 2573 std::span<const ColumnRef> SurfaceTable::Inputs() const {
32 2573 return kInputs;
33 }
34
35 649 void SurfaceTable::Describe(RenderTables& tables) const {
36
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
649 tables.surfaces.address = m_surfaces.Address();
37 649 }
38
39 649 void SurfaceTable::Run(const ChangeSet& changes, TableVersions&) {
40
4/5
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 644 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 5 times.
649 CHRONO_BATCH_RENDER_ZONE("Surfaces/Run");
41 649 m_written = 0;
42
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
649 ColumnStore& store = m_structure.GetColumnStore();
43
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
649 const std::span<const uint32_t> starts = m_instances.FirstInstances();
44
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
649 const std::span<const uint32_t> counts = m_instances.InstanceCounts();
45
2/4
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 649 times.
✗ Branch 3 not taken.
649 if (m_tables.instances.address == 0 || counts.empty()) {
46 return;
47 }
48
1/1
✓ Branch 1 taken 649 times.
649 device::Device& device = store.GetDevice();
49
1/1
✓ Branch 1 taken 649 times.
649 const bool grown = m_surfaces.Reserve(device, starts.back());
50
2/2
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 292 times.
649 std::set<uint32_t> dirty;
51 649 for (const uint32_t world :
52
8/8
✓ Branch 0 taken 357 times.
✓ Branch 1 taken 292 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 349 times.
✓ Branch 5 taken 300 times.
✓ Branch 8 taken 349 times.
✓ Branch 10 taken 658 times.
✓ Branch 11 taken 649 times.
1307 changes.resync || grown ? std::vector<uint32_t>{kGlobalWorld} : changes.worlds) {
53
1/1
✓ Branch 1 taken 658 times.
1316 dirty.merge(m_instances.Tlases(world));
54 649 }
55
1/1
✓ Branch 1 taken 649 times.
649 std::vector<uint32_t> tlases(dirty.begin(), dirty.end());
56 649 uint32_t widest = 0;
57
2/2
✓ Branch 0 taken 747 times.
✓ Branch 1 taken 649 times.
1396 for (const uint32_t tlas : tlases) {
58
2/2
✓ Branch 0 taken 649 times.
✓ Branch 1 taken 98 times.
747 widest = std::max(widest, starts[tlas + 1] - starts[tlas]);
59 747 m_written += counts[tlas];
60 }
61
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 649 times.
649 if (widest == 0) {
62 ✗ return;
63 }
64
1/1
✓ Branch 1 taken 649 times.
649 const Ref<device::Buffer> list = device.CreateBuffer({.label = "surface TLASes"}, tlases);
65 649 SurfaceParams params{};
66 1298 params.scene.address = store.DeviceData();
67 649 params.layout = m_tables.instances;
68 649 params.meshes = m_tables.meshes;
69
1/2
✓ Branch 0 taken 649 times.
✗ Branch 1 not taken.
649 params.surfaces.address = m_surfaces.Address();
70
1/1
✓ Branch 1 taken 649 times.
649 params.tlases.address = list->Address();
71
1/1
✓ Branch 1 taken 649 times.
649 params.normalsName = m_structure.GetTokens().Intern("normals").id;
72
1/3
✓ Branch 1 taken 649 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
649 params.displayOpacityName = m_structure.GetTokens().Intern("displayOpacity").id;
73
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 644 times.
649 device::Queue& queue = device.GetQueue();
74
4/5
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 644 times.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 5 times.
649 static const profiler::ZoneId zone = profiler::ZoneId::Named("Surfaces/Write");
75
1/1
✓ Branch 1 taken 649 times.
649 device::CommandEncoder encoder = queue.CreateEncoder();
76 649 {
77
1/1
✓ Branch 1 taken 649 times.
649 const device::ZoneScope scope(encoder, zone);
78
3/3
✓ Branch 1 taken 649 times.
✓ Branch 4 taken 649 times.
✓ Branch 7 taken 649 times.
649 encoder.Dispatch(
79
2/2
✓ Branch 1 taken 649 times.
✓ Branch 4 taken 649 times.
649 Kernels().Entry("WriteSurfaces"), params,
80
1/1
✓ Branch 1 taken 649 times.
649 {.x = device::GroupCount(widest, kSurfaceGroup), .y = uint32_t(tlases.size())});
81 649 }
82
2/2
✓ Branch 1 taken 649 times.
✓ Branch 4 taken 649 times.
649 queue.Submit(encoder.Finish());
83 2596 }
84
85 353 void SurfaceTable::Prepare() {
86 353 Kernels();
87 353 }
88
89 1002 device::Program& SurfaceTable::Kernels() {
90
2/2
✓ Branch 0 taken 371 times.
✓ Branch 1 taken 631 times.
1002 if (!m_program) {
91
2/2
✓ Branch 2 taken 371 times.
✓ Branch 5 taken 371 times.
1113 m_program = m_structure.GetColumnStore().GetDevice().CreateProgram(
92 {.modules = {"chrono_batch_render.scene.tables.kernels.surfaces"},
93 .library = &kSceneKernels,
94 .entries = {"WriteSurfaces"},
95
2/3
✓ Branch 1 taken 371 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 371 times.
742 .label = "surfaces"});
96 }
97 1002 return *m_program;
98 742 }
99
100 }
101