Loading...
Searching...
No Matches
BufferView.hpp
1#pragma once
2#include <Process/Monitoring/Monitor.hpp>
3#include <Process/Monitoring/MonitorLink.hpp>
4
5#include <Effect/EffectLayer.hpp>
6
7#include <QGraphicsSceneHoverEvent>
8#include <QImage>
9#include <QPolygonF>
10
11#include <Ui/Monitor/BufferDecode.hpp>
12#include <Ui/Monitor/BufferGather.hpp>
13#include <Ui/Monitor/LayerHelpers.hpp>
14#include <halp/buffer.hpp>
15#include <halp/controls.hpp>
16#include <halp/meta.hpp>
17
18#include <array>
19#include <atomic>
20#include <memory>
21#include <optional>
22#include <vector>
23
24class QRhiResourceUpdateBatch;
25namespace score::gfx
26{
27class RenderList;
28struct Port;
29}
30
43namespace Ui::BufferView
44{
48
49enum class Mode
50{
51 Curves,
52 Table,
53 Image,
54 Histogram
55};
56inline constexpr std::string_view mode_names[]{"Curves", "Table", "Image", "Histogram"};
57inline constexpr std::string_view type_names[]{
58 "Float (32 bit)", "Half (16 bit)", "Int (32 bit)",
59 "UInt (32 bit)", "UInt8 (normalised)", "UInt8 (raw)"};
60
62struct Frame
63{
65 std::vector<float> values;
67 int64_t count{};
69 int64_t available{};
71 int64_t first{};
73 int64_t step{1};
75 int64_t buffer_bytes{};
77 int64_t read_bytes{};
78 Layout layout{};
80 Fallback fallback{};
82 bool capped{};
85 bool exact{};
87};
88
90{
93 std::atomic<int> interval{16};
94};
95
96struct Layer;
97
98struct Node
99{
100 halp_meta(name, "Buffer view")
101 halp_meta(c_name, "BufferView")
102 halp_meta(category, "Monitoring/Visuals")
103 halp_meta(author, "ossia score")
104 halp_meta(manual_url, "")
105 halp_meta(
106 description,
107 "Show the contents of a GPU buffer as curves, a table, an image or "
108 "histograms, read with the element type, components, stride and offset given")
109 halp_meta(uuid, "4c1f7a2e-93b8-4d56-a0e1-6b2d8f3c9e14")
110 halp_flag(fully_custom_item);
112
113 struct
114 {
115 struct : halp::gpu_buffer_input<"Buffer">
116 {
117 halp_flag(single_cable);
118 } buffer;
119 struct : halp::combobox_t<"Mode", Mode>
120 {
121 struct range
122 {
123 std::string_view values[4]{mode_names[0], mode_names[1], mode_names[2], mode_names[3]};
124 Mode init{Mode::Curves};
125 };
126 } mode;
127 struct : halp::combobox_t<"Type", ElementType>
128 {
129 halp_meta(description, "What each component of an element is")
130 struct range
131 {
132 std::string_view values[6]{type_names[0], type_names[1], type_names[2],
133 type_names[3], type_names[4], type_names[5]};
134 ElementType init{ElementType::Float};
135 };
136 } type;
137 struct : halp::spinbox_i32<"Components", halp::range{1, 4, 1}>
138 {
139 halp_meta(description, "Components of an element: 4 for a vec4")
140 } components;
141 struct : halp::spinbox_i32<"Stride", halp::range{0, 65536, 0}>
142 {
143 halp_meta(description, "Bytes from one element to the next; 0 when they follow each other")
144 } stride;
145 struct : halp::spinbox_i32<"Offset", halp::range{0, 2147483647, 0}>
146 {
147 halp_meta(description, "Bytes before element 0")
148 } offset;
149 struct : halp::spinbox_i32<"Width", halp::range{0, 16384, 0}>
150 {
151 halp_meta(description, "Elements per row in Image mode; 0 makes the image square")
152 } width;
153 struct : halp::toggle_t<bool, "Autoscale", halp::toggle_setup{.init = true}>
154 {
155 halp_meta(description, "Fit the scales to the values; off, values are shown from 0 to 1")
156 } autoscale;
157 struct : halp::spinbox_i32<"Max elements", halp::range{1, 1048576, 65536}>
158 {
159 halp_meta(
160 description,
161 "Elements read back at most, from the first shown; a readback holds 16 MiB at most")
162 } max_elements;
163 // An int control: past 2^31 elements, Offset moves element 0 further
164 struct : halp::spinbox_i32<"First element", halp::range{0, 2147483647, 0}>
165 {
166 halp_meta(description, "Index of the first element shown")
167 } first;
168 struct : halp::toggle_t<bool, "Overview", halp::toggle_setup{.init = false}>
169 {
170 halp_meta(
171 description,
172 "When more elements follow the first than Max elements, show elements spread "
173 "evenly over all of them, and the extent of every one")
174 } overview;
175 } inputs;
176
177 struct
178 {
179 } outputs;
180
181 std::shared_ptr<BufferMonitor> monitor = std::make_shared<BufferMonitor>();
182
183 Node();
184 ~Node();
185
186 void inputAboutToFinish(
187 score::gfx::RenderList& r, const score::gfx::Port& p, QRhiResourceUpdateBatch*& res);
188 void release(score::gfx::RenderList& r);
189 void operator()() { }
190
192 Layout layout() const noexcept;
193
194private:
195 struct Readback;
196 void decodeReadback();
197 void publishEmpty(int64_t buffer_bytes, int64_t available, int64_t first, const Layout& l);
198
199 std::shared_ptr<Readback> m_readback;
200};
201
203{
204 Layer(
205 const Process::ProcessModel& process, const Process::Context& doc,
206 QGraphicsItem* parent);
207
208 void paint_impl(QPainter* p) const override;
210 void mousePressEvent(QGraphicsSceneMouseEvent* ev) override;
211 void hoverMoveEvent(QGraphicsSceneHoverEvent* ev) override;
212 void hoverLeaveEvent(QGraphicsSceneHoverEvent* ev) override;
213
214private:
215 Mode mode() const;
216 bool autoscale() const;
217 int components() const noexcept;
218 std::pair<float, float> rangeOf(int c) const;
219
220 void refresh(BufferMonitor& mon);
222 void measure();
223 void reset();
224
225 QRectF plotRect() const;
226 void paintCurves(QPainter* p) const;
227 void paintTable(QPainter* p) const;
228 void paintImage(QPainter* p) const;
229 void paintHistogram(QPainter* p) const;
232 void paintInfo(
233 QPainter* p, const QRectF& plot, const QStringList& extra, bool bottom = false) const;
235 QRectF imageRect(QSize& size) const;
236 void buildImage() const;
237 QString formatValue(float v) const;
239 int64_t indexOf(int64_t i) const noexcept;
240
241 const Process::ControlInlet* m_mode{};
242 const Process::ControlInlet* m_width{};
243 const Process::ControlInlet* m_autoscale{};
244 Process::MonitorLink* m_link{};
245 Ui::Monitor::DoubleClick m_doubleClick;
246
247 Frame m_frame;
248 bool m_has{};
250 std::array<float, 4> m_lo{}, m_hi{};
252 std::array<float, 4> m_frameLo{}, m_frameHi{};
253 int64_t m_nonFinite{};
254 std::optional<QPointF> m_hover;
255
257 mutable QPolygonF m_polyline;
258 mutable QImage m_image;
259 mutable bool m_imageDirty{true};
260 mutable std::array<std::array<int, 64>, 4> m_bins{};
261};
262}
Definition Port.hpp:247
Definition EffectLayer.hpp:17
Definition Monitor.hpp:59
The Process class.
Definition score-lib-process/Process/Process.hpp:82
Definition LayerHelpers.hpp:103
List of nodes to be rendered to an output.
Definition RenderList.hpp:36
Definition BufferView.cpp:21
Fallback
Why a buffer is read back as one range instead of through the gather pass.
Definition BufferGather.hpp:27
ElementType
Definition BufferDecode.hpp:18
Graphics rendering pipeline for ossia score.
Definition Filter/PreviewWidget.hpp:11
Definition ProcessContext.hpp:12
Definition Monitor.hpp:27
Definition BufferView.hpp:90
std::atomic< int > interval
Milliseconds between two readbacks: the refresh interval of the views.
Definition BufferView.hpp:93
The elements of one readback, decoded.
Definition BufferView.hpp:63
int64_t count
Elements in values
Definition BufferView.hpp:67
int64_t read_bytes
Bytes the readback held.
Definition BufferView.hpp:77
int64_t available
Elements the buffer holds under the layout, read back or not.
Definition BufferView.hpp:69
int64_t step
Elements of the buffer from one in values to the next.
Definition BufferView.hpp:73
std::vector< float > values
The components of each element, one after the other.
Definition BufferView.hpp:65
int64_t first
Index of the element values starts with.
Definition BufferView.hpp:71
bool capped
Whether the 16 MiB a readback holds kept count below what was asked.
Definition BufferView.hpp:82
bool exact
Definition BufferView.hpp:85
Fallback fallback
Why the elements were read as one contiguous range.
Definition BufferView.hpp:80
int64_t buffer_bytes
Size of the buffer; 0 without one.
Definition BufferView.hpp:75
Definition BufferView.hpp:203
void mousePressEvent(QGraphicsSceneMouseEvent *ev) override
A double click fits the scales to the elements shown now.
Definition BufferView.cpp:469
Definition BufferView.cpp:76
Definition BufferView.hpp:99
Layout layout() const noexcept
The layout the controls describe.
Definition BufferView.cpp:115
What the header of a staging buffer says of the elements measured.
Definition BufferGather.hpp:210
Definition BufferDecode.hpp:29
Definition MIDISync.hpp:149
Port of a score::gfx::Node.
Definition score-plugin-gfx/Gfx/Graph/Utils.hpp:215