chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
17 / 17
100.0%
Branches:
12 / 19
63.2%
Functions:
4 / 4, 2 excl
100.0%

scene/tables/textures.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstdint>
5 #include <map>
6 #include <set>
7 #include <span>
8 #include <string_view>
9 #include <unordered_map>
10 #include <utility>
11 #include <vector>
12
13 #include "chrono_batch_render/scene/records/textures.h"
14 #include "chrono_batch_render/scene/tables/storage.h"
15 #include "chrono_batch_render/scene/tables/table.h"
16 #include "chrono_batch_render/stage/structure/structure.h"
17 #include "chrono_batch_render/texture/cache.h"
18
19 namespace chrono::batch_render {
20
21
1/1
✓ Branch 1 taken 360 times.
360 struct TextureStats {
22 uint32_t images = 0;
23 uint32_t bound = 0;
24 uint32_t loaded = 0;
25 uint32_t failed = 0;
26 uint32_t loading = 0;
27 };
28
29 struct TextureSlot {
30 SchemaId table = SchemaId::None;
31 uint32_t texture = 0;
32 bool color = false;
33 };
34
35 class TextureTable : public RenderTable {
36 public:
37 explicit TextureTable(Structure& structure, unsigned threads = 4);
38 ~TextureTable() override;
39 TextureTable(const TextureTable&) = delete;
40 TextureTable& operator=(const TextureTable&) = delete;
41
42 946 std::string_view Name() const override {
43 946 return "textures";
44 }
45
46 2391 std::span<const ColumnRef> Inputs() const override {
47 2391 return m_inputs;
48 }
49
50 861 std::span<const ColumnRef> RowInputs() const override {
51 861 return m_inputs;
52 }
53
54 360 std::span<const TableId> TableOutputs() const override {
55 360 static constexpr TableId kTables[] = {TableId::Textures};
56 360 return kTables;
57 }
58
59 void Describe(RenderTables& tables) const override;
60 void Hold(std::vector<Ref<const RefCounted>>& held) const override;
61
62 7 const TextureRecord& Record(uint32_t prim) const {
63
11/18
✓ Branch 0 taken 1 time.
✗ Branch 1 not taken.
✓ Branch 3 taken 1 time.
✓ Branch 5 taken 1 time.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 time.
✓ Branch 10 taken 1 time.
✗ Branch 11 not taken.
✓ Branch 13 taken 1 time.
✓ Branch 15 taken 1 time.
✗ Branch 16 not taken.
✓ Branch 18 taken 1 time.
✓ Branch 20 taken 1 time.
✗ Branch 21 not taken.
✓ Branch 23 taken 1 time.
✗ Branch 24 not taken.
✓ Branch 26 taken 1 time.
✗ Branch 27 not taken.
14 return m_records.Row(prim);
64 }
65
66 bool Pending() const override;
67 void Run(const ChangeSet& changes, TableVersions& versions) override;
68
69 void Finish() override;
70 uint64_t Handle(uint32_t prim, std::string_view input) const;
71
72 1 uint64_t Checker() const {
73 1 return m_cache.Binding(kCheckerTextureBinding);
74 }
75
76 const TextureStats& Stats() const {
77 return m_stats;
78 }
79
80 private:
81 using RowKey = std::pair<SchemaId, uint32_t>;
82
83 222 struct Bound {
84 TextureSlot slot;
85 TextureBinding binding;
86 };
87
88 248 struct Material {
89 std::vector<Bound> slots;
90 std::vector<RowKey> rows;
91 uint32_t bindings = kNoTextures;
92 bool checkered = false;
93 };
94
95 1002 struct Cells {
96 std::map<RowKey, std::vector<uint32_t>> columns;
97 };
98
99 const std::vector<uint32_t>& Read(Cells& cells, SchemaId table, uint32_t column);
100 std::set<uint32_t> Collect();
101 void Refresh(uint32_t prim);
102 void Release(uint32_t prim);
103 void Publish(uint32_t prim, const Material& material);
104 void Rebound(uint32_t world);
105 void Rebind(uint32_t prim, Cells& cells);
106 void UploadBindings();
107
108 Structure& m_structure;
109 TextureCache m_cache;
110 std::map<SchemaId, std::vector<TextureSlot>> m_slots;
111 std::vector<ColumnRef> m_inputs;
112 std::unordered_map<uint32_t, Material> m_materials;
113 std::map<RowKey, uint32_t> m_byRow;
114 uint64_t m_bindingAddress = 0;
115 TextureBinding m_checker;
116 uint32_t m_checkerUsers = 0;
117 TextureStats m_stats;
118 RecordTable<TextureRecord> m_records{"texture records"};
119 std::vector<uint32_t> m_rebound;
120 };
121
122 }
123