94 std::span<const double> real,
const SegmentGeometry& geometry, std::span<const double> window = {})
96 std::vector<double> interleaved(real.size() * 2, 0.0);
97 for (
size_t i = 0; i < real.size(); ++i) {
98 interleaved[2 * i] = real[i];
110 std::span<const double> interleaved,
const SegmentGeometry& geometry, std::span<const double> window = {})
112 if (geometry.
count == 0) {
115 stage(interleaved, geometry, window);
116 execute(Datum<std::vector<Kakshya::DataVariant>> {}, ExecutionContext {});
119 return { result.begin(), result.end() };
137 if (geometry.
count == 0) {
140 std::vector<double> interleaved(real.size() * 2, 0.0);
141 for (
size_t i = 0; i < real.size(); ++i) {
142 interleaved[2 * i] = real[i];
144 stage(interleaved, geometry, window);
145 static_cast<void>(
dispatch_async(Datum<std::vector<Kakshya::DataVariant>> {}));
153 void stage(std::span<const double> interleaved,
const SegmentGeometry& geometry, std::span<const double> window = {})
157 std::vector<double> coefficients(
m_points, window.empty() ? 1.0 : 0.0);
158 std::copy_n(window.begin(), std::min<size_t>(window.size(),
m_points), coefficients.begin());
170 const auto scale_bits = std::bit_cast<uint64_t>(
m_scale);
172 .length = geometry.
length,
173 .stride = geometry.
stride,
174 .offset = geometry.
offset,
175 .scale_lo =
static_cast<uint32_t
>(scale_bits & 0xFFFFFFFFU),
176 .scale_hi =
static_cast<uint32_t
>(scale_bits >> 32U) });
204 .
workgroup(std::max<uint32_t>(std::min<uint32_t>(
points / 2, 256U), 1U))
229 const size_t bins =
static_cast<size_t>(
points) / 2 + 1;
230 return weights != 0 && weights % bins == 0 ?
static_cast<uint32_t
>(weights / bins) : 0U;
241 ,
m_weights(weights.begin(), weights.end())
243 const uint32_t half =
points / 2;
244 m_twiddle.reserve(
static_cast<size_t>(half) * 2);
245 for (uint32_t k = 0; k < half; ++k) {
246 const double angle = 2.0 * std::numbers::pi *
static_cast<double>(k) /
static_cast<double>(
points);
248 m_twiddle.push_back(inverse ? std::sin(angle) : -std::sin(angle));
Runs a shader on doubles carried as two 32-bit words, with no fp64 on the device.
Assemble & spectrum(SpectrumOutput s)
Set what an FFT writes for each window.
Assemble & descriptors(uint32_t n)
Set the rows of weights of a projecting FFT.
ShaderSpec build()
Finalise and return the ShaderSpec.
Assemble & pc(std::string name, Kakshya::GpuDataFormat format)
Declare a push constant field with explicit format.
Assemble & ssbo(std::string name, BindingDirection direction, Kakshya::GpuDataFormat format, Kakshya::DataModality modality=Kakshya::DataModality::SCALAR_F32)
Declare an SSBO binding.
Assemble & workgroup(uint32_t x, uint32_t y=1, uint32_t z=1)
Override workgroup size.
Assemble & points(uint32_t n)
Set the points per window of an FFT.
Assemble & tmpl(KernelTemplate t)
Set the kernel template.
Fluent assembler producing a ShaderSpec.
void stage(std::span< const double > interleaved, const SegmentGeometry &geometry, std::span< const double > window={})
Stage input, window and geometry for the next dispatch without running it.
std::vector< double > m_weights
static constexpr uint32_t result_binding
The binding that holds the result of a dispatch.
static Portal::Graphics::ShaderSpec fft_spec(uint32_t points, Portal::Graphics::SpectrumOutput output, uint32_t descriptors=0)
The spec of the template instance this context drives.
std::vector< double > m_twiddle
static uint32_t row_count(uint32_t points, size_t weights) noexcept
uint32_t descriptors() const noexcept
Rows of weights of a projecting context, zero otherwise.
std::array< uint32_t, 3 > calculate_dispatch_size(size_t, const DataStructureInfo &) const override
One workgroup per window.
std::vector< double > transform_complex(std::span< const double > interleaved, const SegmentGeometry &geometry, std::span< const double > window={})
Transform windows of a complex signal.
std::vector< double > transform(std::span< const double > real, const SegmentGeometry &geometry, std::span< const double > window={})
Transform windows of a real signal.
uint32_t points() const noexcept
void record_real(std::span< const double > real, const SegmentGeometry &geometry, std::span< const double > window={})
Record the transform of windows of a real signal without waiting for it.
FftContext(uint32_t points, Portal::Graphics::SpectrumOutput output=Portal::Graphics::SpectrumOutput::Complex, bool inverse=false)
FftContext(uint32_t points, std::span< const double > weights)
A projecting context.
FftContext(const Portal::Graphics::ShaderSpec &spec, uint32_t points, Portal::Graphics::SpectrumOutput output, bool inverse, std::span< const double > weights={})
size_t values_per_window() const noexcept
Doubles in the result of one window.
std::optional< SharedBufferInfo > shared_buffer_info(uint32_t set, size_t binding_index) const
What the shared buffer at (set, binding_index) declares, or nothing when absent.
void set_output_size(size_t index, size_t byte_size)
Declare the byte capacity of an output binding independently of input data.
ShaderExecutionContext & push(const T &data)
Set push constants from a trivially copyable struct or value.
output_type execute(const input_type &input, const ExecutionContext &ctx) override
Injects multipass configuration into the context before dispatch when set_multipass() has been called...
Portal::Graphics::FenceID dispatch_async(const input_type &input)
Dispatch asynchronously and return a fence for polling.
ShaderExecutionContext & output(size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an OUTPUT binding, inferring the next available binding index.
WordPairExecutionContext(GpuComputeConfig config, std::vector< GpuBufferBinding > bindings, bool order_key, std::string name="WordPairExecutionContext")
std::span< const double > primary_values() const noexcept
The primary output of the last dispatch decoded to doubles.
void stage_words(uint32_t binding, std::span< const double > values, size_t padded_count=0, bool complement=false)
Encode values and stage them as the data of a binding.
Shader context whose numeric input is staged as a uvec2 per double.
@ VEC2_U32
glm::uvec2: a 64-bit value as low word (x) and high word (y), not a sampled image format
@ FFT
Radix 2 FFT of word-pair doubles, one workgroup per window, points a power of two up to 2048.
SpectrumOutput
What an FFT template writes for each window.
@ Complex
points complex bins, interleaved re, im, scaled
@ Projection
descriptors values per window: row r of a weights binding, one weight per power bin,...
@ Power
points / 2 + 1 bins of re * re + im * im, after scaling
BindingDirection
Data flow direction for a shader binding slot.
GpuComputeConfig config_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuComputeConfig from a ShaderSpec.
std::vector< GpuBufferBinding > bindings_from_spec(const Portal::Graphics::ShaderSpec &spec)
Derive a GpuBufferBinding list from a ShaderSpec.
static constexpr DomainSpec Graphics
Domain constant for Graphics domain.
Complete declarative description of a generated compute shader.
Dimensions, modality, source type, and optional Composite field schema.
Where the windows of a GPU pass sit in the value array.