chrono_batch_render/
Coverage:
low: ≥ 0%
medium: ≥ 75.0%
high: ≥ 90.0%
Lines:
5 / 12
41.7%
Branches:
3 / 28
10.7%
Functions:
0 / 2, 2 excl
0.0%

device/queue.h
Line Branch Exec Source
1 // SPDX-License-Identifier: BSD-3-Clause
2 #pragma once
3
4 #include <cstddef>
5 #include <cstdint>
6 #include <functional>
7 #include <memory>
8 #include <mutex>
9 #include <span>
10 #include <vector>
11
12 #include "chrono_batch_render/device/buffer.h"
13 #include "chrono_batch_render/device/commands.h"
14 #include "chrono_batch_render/device/operation.h"
15 #include "chrono_batch_render/device/ref.h"
16 #include "chrono_batch_render/device/stream.h"
17 #include "chrono_batch_render/device/texture.h"
18 #include "chrono_batch_render/export.h"
19
20 namespace chrono::batch_render::device {
21
22 class Device;
23 class Queue;
24
25 class CHRONO_BATCH_RENDER_API Queue {
26 public:
27 virtual ~Queue();
28 Queue(const Queue&) = delete;
29 Queue& operator=(const Queue&) = delete;
30
31 833426 Device& GetDevice() const {
32
0/22
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✗ Branch 7 not taken.
✗ Branch 10 not taken.
✗ Branch 13 not taken.
✗ Branch 16 not taken.
✗ Branch 21 not taken.
✗ Branch 24 not taken.
✗ Branch 33 not taken.
✗ Branch 37 not taken.
✗ Branch 41 not taken.
✗ Branch 45 not taken.
✗ Branch 49 not taken.
✗ Branch 52 not taken.
✗ Branch 55 not taken.
✗ Branch 58 not taken.
✗ Branch 61 not taken.
✗ Branch 64 not taken.
✗ Branch 74 not taken.
✗ Branch 77 not taken.
833426 return m_device;
33 }
34
35 CommandEncoder CreateEncoder();
36
37 Operation Submit(CommandBuffer&& commands);
38
39 Operation Submit(const CommandBuffer& commands);
40
41 Operation Mark();
42
43 void BeginBatch();
44
45 Operation EndBatch();
46
47 void Follow(Stream stream);
48
49 void Follow(const Operation& operation);
50
51 void Exclusive(const std::function<void()>& use);
52
53 void Write(BufferRange dst, const void* data);
54 BufferRange Upload(const void* data, uint64_t bytes);
55
56 void Write(Texture& dst, uint32_t level, const void* data);
57
58 Download ReadAsync(BufferRange src);
59
60 void Read(BufferRange src, void* data);
61
62 void Retire(std::shared_ptr<void> retired, const Operation& until);
63
64 uint64_t Submitted() const;
65
66 uint64_t Completed() const;
67
68 void WaitIdle();
69
70 protected:
71 explicit Queue(Device& device, bool runsKernels = true);
72
73 static std::shared_ptr<void>& Recording(const CommandBuffer& commands) {
74
2/4
<unknown function 31>:
✗ Branch 0 not taken.
✗ Branch 1 not taken.
<unknown function 74>:
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 return commands.m_recorded.native;
75 }
76
77
1/2
<unknown function 31>:
✗ Branch 1 not taken.
<unknown function 74>:
✓ Branch 1 taken 11 times.
11 class Timestamps {
78 public:
79 11 virtual ~Timestamps() = default;
80 virtual bool Read(std::span<uint64_t> ns) const = 0;
81 };
82
83 virtual void Execute(const CommandBuffer& queued, const CommandBuffer& commands,
84 const Timestamps* timestamps, uint64_t value) = 0;
85
86 virtual std::shared_ptr<Timestamps> CreateTimestamps(uint32_t count) = 0;
87
88 virtual uint64_t Finished() const = 0;
89
90 virtual void WaitFor(uint64_t value) const = 0;
91
92 ✗ virtual bool SharesStreams() {
93 ✗ return false;
94 }
95
96 ✗ virtual void* NativeStream() {
97 ✗ return nullptr;
98 }
99
100 virtual void ExecuteNative(const CommandBuffer& queued, uint64_t value, const void* native,
101 const Timestamps* timestamps);
102
103 virtual void FollowQueue(Queue& other, uint64_t value);
104 virtual bool FollowDevice(Queue& other, uint64_t value);
105
106 Operation RunNative(const void* native, const char* zone = nullptr);
107
108 std::unique_lock<std::mutex> LockSubmissions();
109
110 virtual void FollowStream(void* stream);
111 virtual void StreamWait(void* stream, uint64_t value);
112
113 private:
114 friend class CommandBuffer;
115 friend class Device;
116 friend struct Operation;
117 struct State;
118
119 void OpenRecording();
120 void CloseRecording();
121
122 Operation SubmitCommands(const CommandBuffer& commands);
123 uint64_t Run(const CommandBuffer& commands, const void* native = nullptr);
124 uint64_t Launch(const CommandBuffer& queued, const CommandBuffer& commands, uint64_t value,
125 const void* native);
126 uint64_t RunEach(const CommandBuffer& commands);
127 CommandBuffer Isolate(const CommandBuffer& commands, const Command& command);
128 std::shared_ptr<Timestamps> TimestampsFor(const CommandBuffer& commands);
129 void CollectZones(uint64_t finished) const;
130
131 void Wait(uint64_t value);
132 void Throttle(uint64_t value);
133 void Reach(uint64_t value);
134 void Collect(uint64_t finished) const;
135 void Retire(Resource& resource);
136 void Retire(std::shared_ptr<void> retired, uint64_t value);
137 void Close() noexcept;
138
139 Device& m_device;
140 bool m_runsKernels;
141 std::unique_ptr<State> m_state;
142 };
143
144 }
145