Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
waveform_gpu_primitives.hpp
Go to the documentation of this file.
1#pragma once
2
9
12
13#include <cstddef>
14#include <cstdint>
15#include <span>
16#include <vector>
17
18namespace pulp::view {
19
21 float x = 0.0f;
22 float y_min = 0.0f;
23 float y_max = 0.0f;
24 float min_value = 0.0f;
25 float max_value = 0.0f;
26 std::uint32_t source_peak_index = 0;
27};
28
30 std::uint64_t source_generation = 0;
32 std::uint32_t overview_level_index = 0;
33 std::uint32_t samples_per_peak = 0;
34 std::uint32_t first_peak = 0;
35 std::uint32_t peak_count = 0;
36 std::int64_t visible_start = 0;
37 std::int64_t visible_length = 0;
38 std::int32_t bounds_x_milli_px = 0;
39 std::int32_t bounds_y_milli_px = 0;
40 std::int32_t bounds_width_milli_px = 0;
41 std::int32_t bounds_height_milli_px = 0;
42 std::uint32_t target_width_px = 0;
43 std::uint32_t target_height_px = 0;
44
45 [[nodiscard]] bool valid() const noexcept;
46};
47
48[[nodiscard]] bool operator==(const WaveformGpuUploadKey& a,
49 const WaveformGpuUploadKey& b) noexcept;
50[[nodiscard]] bool operator!=(const WaveformGpuUploadKey& a,
51 const WaveformGpuUploadKey& b) noexcept;
52
54 // Required cache identity supplied by the source/editor owner. Increment
55 // whenever thumbnail content changes; 0 produces an invalid GPU plan.
56 std::uint64_t source_generation = 0;
58 std::uint32_t max_columns = 0;
59 bool prefer_gpu = true;
60};
61
71
78
81 const WaveformViewport& viewport,
82 const WaveformGpuLayerConfig& config = {});
83
84[[nodiscard]] WaveformGpuLayerPlan
86 const WaveformViewport& viewport, int64_t playhead_sample,
87 const WaveformGpuLayerConfig& config = {},
88 const WaveformGpuUploadKey* previous_static_key = nullptr);
89
95 std::span<WaveformPeakVertex> dst) noexcept;
96
99 std::uint64_t resource_id = 0;
100 std::size_t bytes = 0;
101 std::uint64_t backend_generation = 0;
102 std::uint64_t last_used = 0;
103
104 [[nodiscard]] bool valid() const noexcept;
105};
106
108 std::size_t entries = 0;
109 std::size_t capacity = 0;
110 std::size_t bytes = 0;
111 std::size_t hits = 0;
112 std::size_t misses = 0;
113 std::size_t evictions = 0;
114};
115
123
131 public:
132 explicit WaveformGpuResourceCache(std::size_t capacity = 8);
133
134 bool prepare(std::size_t capacity,
135 std::vector<WaveformGpuResourceRecord>* evicted_records = nullptr);
136 [[nodiscard]] std::vector<WaveformGpuResourceRecord> clear_and_return_records();
137
139 std::uint64_t resource_id, std::size_t bytes,
140 std::uint64_t backend_generation = 1);
143 std::uint64_t backend_generation) noexcept;
144 bool erase(const WaveformGpuUploadKey& key, WaveformGpuResourceRecord& removed_record) noexcept;
145
146 [[nodiscard]] WaveformGpuResourceCacheStats stats() const noexcept;
147 [[nodiscard]] std::size_t capacity() const noexcept {
148 return capacity_;
149 }
150 [[nodiscard]] std::size_t size() const noexcept {
151 return records_.size();
152 }
153
154 private:
155 std::vector<WaveformGpuResourceRecord> records_;
156 std::size_t capacity_ = 0;
157 std::uint64_t clock_ = 0;
158 std::size_t hits_ = 0;
159 std::size_t misses_ = 0;
160 std::size_t evictions_ = 0;
161};
162
163} // namespace pulp::view
Definition waveform_overview.hpp:89
static constexpr uint32_t kAllChannels
Definition waveform_overview.hpp:133
std::vector< WaveformGpuResourceRecord > clear_and_return_records()
std::size_t capacity() const noexcept
Definition waveform_gpu_primitives.hpp:147
WaveformGpuResourceCacheStats stats() const noexcept
WaveformGpuResourceCache(std::size_t capacity=8)
const WaveformGpuResourceRecord * find(const WaveformGpuUploadKey &key, std::uint64_t backend_generation) noexcept
WaveformGpuResourcePutResult put(const WaveformGpuUploadKey &key, std::uint64_t resource_id, std::size_t bytes, std::uint64_t backend_generation=1)
bool prepare(std::size_t capacity, std::vector< WaveformGpuResourceRecord > *evicted_records=nullptr)
std::size_t size() const noexcept
Definition waveform_gpu_primitives.hpp:150
bool erase(const WaveformGpuUploadKey &key, WaveformGpuResourceRecord &removed_record) noexcept
const WaveformGpuResourceRecord * find(const WaveformGpuUploadKey &key) noexcept
Hover-cursor tracking for platform window hosts.
Definition fwd.hpp:27
WaveformGpuLayerPlan build_waveform_gpu_layer_plan(const pulp::audio::WaveformOverview &thumbnail, const WaveformViewport &viewport, int64_t playhead_sample, const WaveformGpuLayerConfig &config={}, const WaveformGpuUploadKey *previous_static_key=nullptr)
std::size_t fill_waveform_peak_vertices(const pulp::audio::WaveformOverview &thumbnail, const WaveformGpuStaticLayerPlan &plan, std::span< WaveformPeakVertex > dst) noexcept
Fill caller-owned vertices for CPU fallback or GPU upload staging.
WaveformGpuStaticLayerPlan build_waveform_gpu_static_layer_plan(const pulp::audio::WaveformOverview &thumbnail, const WaveformViewport &viewport, const WaveformGpuLayerConfig &config={})
@ a
Definition input_events.hpp:39
@ b
Definition input_events.hpp:39
STL namespace.
Definition waveform_gpu_primitives.hpp:53
std::uint32_t channel
Definition waveform_gpu_primitives.hpp:57
std::uint64_t source_generation
Definition waveform_gpu_primitives.hpp:56
bool prefer_gpu
Definition waveform_gpu_primitives.hpp:59
std::uint32_t max_columns
Definition waveform_gpu_primitives.hpp:58
Definition waveform_gpu_primitives.hpp:72
bool playhead_only_redraw
Definition waveform_gpu_primitives.hpp:76
WaveformGpuStaticLayerPlan static_layer
Definition waveform_gpu_primitives.hpp:73
WaveformPlayheadOverlay playhead
Definition waveform_gpu_primitives.hpp:74
bool static_layer_dirty
Definition waveform_gpu_primitives.hpp:75
Definition waveform_gpu_primitives.hpp:107
std::size_t entries
Definition waveform_gpu_primitives.hpp:108
std::size_t bytes
Definition waveform_gpu_primitives.hpp:110
std::size_t capacity
Definition waveform_gpu_primitives.hpp:109
std::size_t misses
Definition waveform_gpu_primitives.hpp:112
std::size_t evictions
Definition waveform_gpu_primitives.hpp:113
std::size_t hits
Definition waveform_gpu_primitives.hpp:111
Definition waveform_gpu_primitives.hpp:116
bool evicted
Definition waveform_gpu_primitives.hpp:119
WaveformGpuResourceRecord evicted_record
Definition waveform_gpu_primitives.hpp:121
WaveformGpuResourceRecord replaced_record
Definition waveform_gpu_primitives.hpp:120
bool replaced
Definition waveform_gpu_primitives.hpp:118
bool ok
Definition waveform_gpu_primitives.hpp:117
Definition waveform_gpu_primitives.hpp:97
std::uint64_t backend_generation
Definition waveform_gpu_primitives.hpp:101
std::size_t bytes
Definition waveform_gpu_primitives.hpp:100
std::uint64_t resource_id
Definition waveform_gpu_primitives.hpp:99
std::uint64_t last_used
Definition waveform_gpu_primitives.hpp:102
WaveformGpuUploadKey key
Definition waveform_gpu_primitives.hpp:98
Definition waveform_gpu_primitives.hpp:62
WaveformGpuUploadKey upload_key
Definition waveform_gpu_primitives.hpp:65
bool prefer_gpu
Definition waveform_gpu_primitives.hpp:68
bool valid
Definition waveform_gpu_primitives.hpp:63
std::size_t vertex_count
Definition waveform_gpu_primitives.hpp:66
WaveformViewport viewport
Definition waveform_gpu_primitives.hpp:64
std::size_t upload_bytes
Definition waveform_gpu_primitives.hpp:67
bool cpu_fallback_available
Definition waveform_gpu_primitives.hpp:69
Definition waveform_gpu_primitives.hpp:29
std::uint32_t target_height_px
Definition waveform_gpu_primitives.hpp:43
std::uint32_t first_peak
Definition waveform_gpu_primitives.hpp:34
std::uint32_t peak_count
Definition waveform_gpu_primitives.hpp:35
std::uint32_t channel
Definition waveform_gpu_primitives.hpp:31
std::int64_t visible_length
Definition waveform_gpu_primitives.hpp:37
std::int32_t bounds_y_milli_px
Definition waveform_gpu_primitives.hpp:39
std::int32_t bounds_height_milli_px
Definition waveform_gpu_primitives.hpp:41
std::int32_t bounds_width_milli_px
Definition waveform_gpu_primitives.hpp:40
std::int64_t visible_start
Definition waveform_gpu_primitives.hpp:36
std::uint64_t source_generation
Definition waveform_gpu_primitives.hpp:30
std::uint32_t target_width_px
Definition waveform_gpu_primitives.hpp:42
std::uint32_t samples_per_peak
Definition waveform_gpu_primitives.hpp:33
std::int32_t bounds_x_milli_px
Definition waveform_gpu_primitives.hpp:38
bool valid() const noexcept
std::uint32_t overview_level_index
Definition waveform_gpu_primitives.hpp:32
Definition waveform_gpu_primitives.hpp:20
float x
Definition waveform_gpu_primitives.hpp:21
float y_max
Definition waveform_gpu_primitives.hpp:23
float min_value
Definition waveform_gpu_primitives.hpp:24
float max_value
Definition waveform_gpu_primitives.hpp:25
std::uint32_t source_peak_index
Definition waveform_gpu_primitives.hpp:26
float y_min
Definition waveform_gpu_primitives.hpp:22
Definition waveform_editor_primitives.hpp:214
Immutable-for-paint viewport state and sample/pixel conversion rules.
Definition waveform_editor_primitives.hpp:26
Reusable waveform editor geometry, snapping, hit-testing, and transaction helpers.