Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
web_gpu_convolver.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <functional>
6#include <memory>
7#include <vector>
8
10
11namespace pulp::gpu_audio {
12
49public:
54 static constexpr uint32_t kDefaultDepth = 3;
55
60 using Sink = std::function<void(uint32_t seq, const float* out_planar, bool ok)>;
61
62 explicit WebGpuConvolver(uint32_t depth = kDefaultDepth);
64
67
71 bool prepare(render::GpuCompute* gpu, int sample_rate, int block, int channels,
72 const float* ir, int ir_len);
73
79 bool submit(uint32_t seq, const float* in_planar, int frames,
80 std::chrono::microseconds deadline);
81
85 uint32_t collect(const Sink& sink);
86
87 bool prepared() const { return prepared_; }
90 bool device_lost() const { return gpu_ != nullptr && gpu_->device_lost(); }
91 uint32_t fft_size() const { return fft_size_; }
92 uint32_t depth() const { return depth_; }
93 uint32_t in_flight() const;
94
95 // Per-pipeline counters. GpuCompute::async_stats() counts the same events
96 // device-wide; these are this convolver's view of them, plus the one status
97 // the device cannot see — a readback that landed non-finite (counted failed).
98 uint64_t submits() const;
99 uint64_t resolves() const;
100 uint64_t expired() const;
101 uint64_t failed() const;
102
103private:
104 enum class SlotState : uint8_t { Free, InFlight, Ready, Bad };
105
106 struct Slot {
107 SlotState state = SlotState::Free;
108 uint32_t seq = 0;
109 std::vector<float> in_pad;
110 std::vector<float> time;
111 };
112
118 struct State {
119 std::vector<Slot> slots;
120 std::vector<uint32_t> pending;
121 uint32_t head = 0;
122 uint32_t count = 0;
123
124 uint64_t submits = 0;
125 uint64_t resolves = 0;
126 uint64_t expired = 0;
127 uint64_t failed = 0;
128 };
129
130 std::shared_ptr<State> state_;
131 render::GpuCompute* gpu_ = nullptr;
132
133 uint32_t depth_ = kDefaultDepth;
134 uint32_t channels_ = 0;
135 uint32_t block_ = 0;
136 uint32_t sample_rate_ = 0;
137 uint32_t fft_size_ = 0;
138 bool prepared_ = false;
139
140 std::vector<float> ir_spec_;
141 std::vector<std::vector<float>> carry_;
142 std::vector<float> out_;
143};
144
145} // namespace pulp::gpu_audio
WebGpuConvolver & operator=(const WebGpuConvolver &)=delete
WebGpuConvolver(uint32_t depth=kDefaultDepth)
bool prepared() const
Definition web_gpu_convolver.hpp:87
WebGpuConvolver(const WebGpuConvolver &)=delete
uint64_t resolves() const
maps that landed with a usable payload
uint32_t depth() const
Definition web_gpu_convolver.hpp:92
uint32_t collect(const Sink &sink)
Harvest.
uint32_t fft_size() const
Definition web_gpu_convolver.hpp:91
bool prepare(render::GpuCompute *gpu, int sample_rate, int block, int channels, const float *ir, int ir_len)
Allocate scratch, transform the IR on the CPU, and upload the resident IR spectrum.
uint64_t expired() const
deadline passed before the map resolved
uint64_t failed() const
map error, device loss, or non-finite payload
bool submit(uint32_t seq, const float *in_planar, int frames, std::chrono::microseconds deadline)
Issue one block.
bool device_lost() const
Device loss is normal browser behavior, not an init failure: the owner is expected to re-acquire a de...
Definition web_gpu_convolver.hpp:90
std::function< void(uint32_t seq, const float *out_planar, bool ok)> Sink
Called once per finished block, in submission order.
Definition web_gpu_convolver.hpp:60
static constexpr uint32_t kDefaultDepth
Blocks that may be in flight at once.
Definition web_gpu_convolver.hpp:54
GPU compute pipeline for non-rendering workloads (e.g.
Definition gpu_compute.hpp:48
Definition flow_pans.hpp:19
SequencerStateChannel is the audio-safe transport for a plugin's structured NON-parameter state: the ...
Definition audio_device_manager.hpp:48