Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
gpu_spectral_mask.hpp
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <cstdint>
4#include <memory>
5#include <optional>
6#include <span>
7#include <string>
8
9namespace pulp::gpu_audio {
10// First shared spectral seam: immutable real gains, Hann WOLA, fixed planar
11// hops. Every method is serialized non-RT; callers own callback bridging and
12// continuously advanced CPU fallback. The session performs ordinary CPU copies
13// into/out of shared slots, but no WebGPU payload upload/readback copy.
14class GpuSpectralMaskSession {
15 public:
16 struct Config {
17 std::uint32_t fft_size = 0, hop = 0, channels = 0, sample_rate = 0;
18 std::uint32_t slots = 3;
19 std::span<const float> gains; // DC through Nyquist, fft_size/2+1 values
20 };
22 struct CreateResult {
23 std::unique_ptr<GpuSpectralMaskSession> session;
25 explicit operator bool() const noexcept {
26 return session && error == Error::None;
27 }
28 };
29 struct Result {
30 std::uint64_t epoch = 0, sequence = 0;
31 // Physical success only: the callback owner must reject late output.
32 bool delivered = false, late = false;
33 };
34 struct Diagnostics {
37 std::string dawn_revision;
38 std::string adapter_name;
39 std::uint32_t vendor_id = 0, device_id = 0;
40 // Header/native/proc revision agreement plus host-pointer import.
41 // This does not imply a separately configured manifest pin was checked.
47 std::uint64_t cpu_input_bytes = 0, cpu_output_bytes = 0;
52 std::string provider_revision;
56 };
57 // Non-RT snapshot. Transfer counters exclude resource initialization.
59 static CreateResult create(const Config&) noexcept;
60 // Opt-in prepared program reading one effective gain snapshot per hop.
63 bool prepared() const noexcept;
64 std::uint32_t latency_samples() const noexcept; // intrinsic FFT+hop only
65 // Process-unique stream identity, never reused by a recreated session.
66 std::uint64_t epoch() const noexcept;
67 // A refusal does not advance history. Retry the same sequence/input or
68 // drain and recreate; silently dropping hops invalidates causal history.
69 bool submit_hop(std::span<const float> planar, std::uint64_t sequence,
70 std::uint64_t deadline_ns = 0) noexcept;
71 // Non-RT, create_with_per_hop_gains preparation only. Copies one complete caller-owned
72 // effective table into the leased imported input slot. No interpolation or
73 // latest-value adoption occurs here. The table applies to this hop's analysis
74 // frame (none during initial FFT fill); overlap-add combines prior frames.
75 // A refusal consumes neither sequence nor table. Retry identical input/table.
76 bool submit_hop_with_gains(std::span<const float> planar, std::uint64_t sequence,
77 std::span<const float> gains,
78 std::uint64_t deadline_ns = 0) noexcept;
79 std::size_t service(std::uint64_t now_ns) noexcept;
80 // A failed result poisons this epoch: prepared() becomes false, future
81 // submissions are refused, and remaining completions are retired without
82 // delivery. Continue service/receive or release, then recreate the session
83 // with a new epoch; a physical success cannot repair missing DSP history.
84 std::optional<Result> receive(std::span<float> planar) noexcept;
85 // Retain the session and retry if its physical drain cannot yet finish.
86 bool release() noexcept;
87
88 private:
89 static CreateResult create_impl(const Config&, bool per_hop_gains) noexcept;
90 bool submit_impl(std::span<const float>, std::uint64_t, std::span<const float>,
91 std::uint64_t) noexcept;
92 struct Impl;
93 explicit GpuSpectralMaskSession(std::unique_ptr<Impl>) noexcept;
94 std::unique_ptr<Impl> impl_;
95};
96} // namespace pulp::gpu_audio
std::optional< Result > receive(std::span< float > planar) noexcept
bool submit_hop_with_gains(std::span< const float > planar, std::uint64_t sequence, std::span< const float > gains, std::uint64_t deadline_ns=0) noexcept
static CreateResult create(const Config &) noexcept
Error
Definition gpu_spectral_mask.hpp:21
@ ProviderUnavailable
Definition gpu_spectral_mask.hpp:21
@ InvalidConfig
Definition gpu_spectral_mask.hpp:21
@ None
Definition gpu_spectral_mask.hpp:21
@ PreparationFailed
Definition gpu_spectral_mask.hpp:21
std::size_t service(std::uint64_t now_ns) noexcept
std::uint32_t latency_samples() const noexcept
std::uint64_t epoch() const noexcept
static CreateResult create_with_per_hop_gains(const Config &) noexcept
bool submit_hop(std::span< const float > planar, std::uint64_t sequence, std::uint64_t deadline_ns=0) noexcept
Definition flow_pans.hpp:19
Definition host_transport_projector.hpp:8
STL namespace.
Definition gpu_spectral_mask.hpp:16
std::uint32_t slots
Definition gpu_spectral_mask.hpp:18
std::span< const float > gains
Definition gpu_spectral_mask.hpp:19
std::uint32_t fft_size
Definition gpu_spectral_mask.hpp:17
std::uint32_t sample_rate
Definition gpu_spectral_mask.hpp:17
std::uint32_t hop
Definition gpu_spectral_mask.hpp:17
std::uint32_t channels
Definition gpu_spectral_mask.hpp:17
std::unique_ptr< GpuSpectralMaskSession > session
Definition gpu_spectral_mask.hpp:23
Error error
Definition gpu_spectral_mask.hpp:24
Definition gpu_spectral_mask.hpp:34
std::uint32_t vendor_id
Definition gpu_spectral_mask.hpp:39
std::string dawn_revision
Deprecated: read provider_revision.
Definition gpu_spectral_mask.hpp:37
std::uint64_t cpu_output_bytes
Definition gpu_spectral_mask.hpp:47
std::uint64_t cpu_input_bytes
Definition gpu_spectral_mask.hpp:47
bool physical_release_confirmed
Definition gpu_spectral_mask.hpp:46
std::uint64_t imported_allocations
Definition gpu_spectral_mask.hpp:49
bool authenticated_shared_metal
Deprecated: read authenticated_shared_provider.
Definition gpu_spectral_mask.hpp:44
std::uint64_t runtime_copy_buffer_calls
Definition gpu_spectral_mask.hpp:48
std::uint64_t runtime_write_buffer_calls
Definition gpu_spectral_mask.hpp:48
std::uint64_t retired_failure
Definition gpu_spectral_mask.hpp:50
bool configured_revision_verified
Definition gpu_spectral_mask.hpp:45
std::string adapter_name
Definition gpu_spectral_mask.hpp:38
std::string provider_revision
Revision the shared provider reports for itself.
Definition gpu_spectral_mask.hpp:52
std::uint64_t retired_success
Definition gpu_spectral_mask.hpp:49
bool authenticated_shared_provider
The shared provider authenticated its revision and its host-pointer import.
Definition gpu_spectral_mask.hpp:55
std::uint32_t device_id
Definition gpu_spectral_mask.hpp:39
std::uint64_t runtime_map_async_calls
Definition gpu_spectral_mask.hpp:49
Definition gpu_spectral_mask.hpp:29
std::uint64_t epoch
Definition gpu_spectral_mask.hpp:30
bool delivered
Definition gpu_spectral_mask.hpp:32
std::uint64_t sequence
Definition gpu_spectral_mask.hpp:30
bool late
Definition gpu_spectral_mask.hpp:32