chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
17 / 19
89.5%
Branches:
21 / 37
56.8%
Functions:
-
-%

graph/graph.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <compare>
5 #include <cstdint>
6 #include <functional>
7 #include <span>
8 #include <string>
9 #include <string_view>
10 #include <vector>
11
12 namespace chrono::batch_render::graph {
13
14 inline constexpr uint32_t kNoNode = ~0u;
15
16 struct Edge {
17 uint32_t input = 0;
18 uint32_t source = kNoNode;
19 uint32_t output = 0;
20 };
21
22 1764 struct Node {
23 uint32_t kind = 0;
24 std::vector<Edge> inputs;
25 };
26
27 122 struct Ordering {
28 std::vector<uint32_t> order;
29 std::vector<uint32_t> cycle;
30 };
31
32 127 class Graph {
33 public:
34 uint32_t Add(uint32_t kind);
35 void Connect(uint32_t node, uint32_t input, uint32_t source, uint32_t output);
36
37 196 std::span<const Node> Nodes() const {
38
1/1
✓ Branch 1 taken 94 times.
196 return m_nodes;
39 }
40
41 764 const Node& operator[](uint32_t node) const {
42
1/1
✓ Branch 1 taken 763 times.
764 return m_nodes[node];
43 }
44
45 Ordering Order() const;
46
47 private:
48 std::vector<Node> m_nodes;
49 };
50
51
9/15
✓ Branch 1 taken 94 times.
✓ Branch 5 taken 1 time.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 time.
✓ Branch 12 taken 1 time.
✗ Branch 18 not taken.
✓ Branch 19 taken 1 time.
✗ Branch 21 not taken.
✓ Branch 22 taken 1 time.
✗ Branch 24 not taken.
✓ Branch 25 taken 1 time.
✗ Branch 27 not taken.
✓ Branch 28 taken 1 time.
✗ Branch 30 not taken.
✓ Branch 31 taken 1 time.
483 class ShapeKey {
52 public:
53 std::string_view Bytes() const {
54 return m_bytes;
55 }
56
57 uint64_t Hash() const;
58
59 19 bool operator==(const ShapeKey&) const = default;
60 auto operator<=>(const ShapeKey&) const = default;
61
62 private:
63 friend class ShapeWriter;
64
65
7/16
<unknown function 22>:
✗ Branch 0 not taken.
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
✓ Branch 1 taken 1 time.
✓ Branch 2 taken 1 time.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
<unknown function 51>:
✓ Branch 0 taken 1 time.
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✓ Branch 3 taken 2 times.
19 std::string m_bytes;
66 };
67
68
2/2
<unknown function 22>:
✓ Branch 1 taken 102 times.
<unknown function 51>:
✓ Branch 1 taken 15 times.
234 class ShapeWriter {
69 public:
70 void Add(uint32_t value);
71 void Add(std::string_view text);
72 void Add(std::span<const std::byte> bytes);
73
74 ShapeKey Finish() &&;
75
76 private:
77 ShapeKey m_key;
78 };
79
80 using NodeUniforms = std::function<void(uint32_t node, ShapeWriter& writer)>;
81
82 ShapeKey GraphShape(const Graph& graph, std::span<const uint32_t> order,
83 const NodeUniforms& uniforms = {});
84
85 }
86
87 template <> struct std::hash<::chrono::batch_render::graph::ShapeKey> {
88 80 size_t operator()(const ::chrono::batch_render::graph::ShapeKey& key) const {
89
1/2
<unknown function 22>:
✓ Branch 1 taken 54 times.
<unknown function 51>:
✗ Branch 1 not taken.
80 return size_t(key.Hash());
90 }
91 };
92