MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Yantra::FftContext Class Reference

One FFT per window, as one dispatch of the FFT template. More...

#include <FftContext.hpp>

Inheritance diagram for MayaFlux::Yantra::FftContext:
Collaboration diagram for MayaFlux::Yantra::FftContext:

Classes

struct  Push

Public Member Functions

uint32_t descriptors () const noexcept
 Rows of weights of a projecting context, zero otherwise.
 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.
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.
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 > transform (std::span< const double > real, const SegmentGeometry &geometry, std::span< const double > window={})
 Transform windows of a real signal.
std::vector< double > transform_complex (std::span< const double > interleaved, const SegmentGeometry &geometry, std::span< const double > window={})
 Transform windows of a complex signal.
size_t values_per_window () const noexcept
 Doubles in the result of one window.
Public Member Functions inherited from MayaFlux::Yantra::WordPairExecutionContext
std::vector< double > decode_primary (const GpuChannelResult &result) const
 Decode a dispatch result, as returned by an asynchronous collect, to doubles.
std::vector< double > download_words (size_t binding, size_t count)
 Read a binding back as doubles after a recorded stage.
bool order_keyed () const noexcept
std::span< const double > primary_values () const noexcept
 The primary output of the last dispatch decoded to doubles.
std::span< const uint32_t > primary_words () const noexcept
 The primary output of the last dispatch as 32-bit words, empty if it produced none.
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.
 WordPairExecutionContext (GpuComputeConfig config, std::vector< GpuBufferBinding > bindings, bool order_key, std::string name="WordPairExecutionContext")
Public Member Functions inherited from MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType >
GpuChannelResult collect_result ()
 Collect the result of the last async dispatch.
Portal::Graphics::FenceID dispatch_async (const input_type &input)
 Dispatch asynchronously and return a fence for polling.
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.
template<typename T>
ShaderExecutionContext & in_out (const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT_OUTPUT binding, inferring the next available binding index.
ShaderExecutionContext & in_out (GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Declare an INPUT_OUTPUT binding at an explicit index without pre-staging data.
template<typename T>
ShaderExecutionContext & in_out (uint32_t binding, const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT_OUTPUT binding at an explicit index.
ShaderExecutionContext & in_out (uint32_t binding, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Declare an INPUT_OUTPUT binding without pre-staging data.
template<typename T>
ShaderExecutionContext & input (const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT binding, inferring the next available binding index.
template<typename T>
ShaderExecutionContext & input (uint32_t binding, const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT binding at an explicit index.
ShaderExecutionContext & output (size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an OUTPUT binding, inferring the next available binding index.
ShaderExecutionContext & output (uint32_t binding, size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an OUTPUT binding at an explicit index.
template<typename T>
ShaderExecutionContext & push (const T &data)
 Set push constants from a trivially copyable struct or value.
ShaderExecutionContext & set_multipass (uint32_t pass_count, std::function< void(uint32_t, void *)> pc_updater)
 Configure multi-pass (CHAINED) dispatch.
void set_skip_readback (uint32_t binding, bool skip)
 Set or clear skip_auto_readback for a binding by index.
 ShaderExecutionContext (GpuComputeConfig config, std::vector< GpuBufferBinding > bindings={}, std::string name="ShaderExecutionContext", bool compute_isolated=true)
 Construct with shader config and optional pre-built binding list.
Public Member Functions inherited from MayaFlux::Yantra::GpuExecutionContext< InputType, OutputType >
 GpuExecutionContext (const GpuExecutionContext &)=delete
 GpuExecutionContext (GpuComputeConfig config, bool compute_isolated=true)
 GpuExecutionContext (GpuExecutionContext &&)=delete
GpuExecutionContext & operator= (const GpuExecutionContext &)=delete
GpuExecutionContext & operator= (GpuExecutionContext &&)=delete
 ~GpuExecutionContext () override=default
Public Member Functions inherited from MayaFlux::Yantra::GpuDispatchCore
const std::string & dispatch_key () const
 The key used for this context's GpuResourceManager unit.
void download_binding (size_t index, void *dest, size_t byte_size)
 Read back a specific binding into a caller-provided destination.
void download_shared (uint32_t set, size_t binding_index, void *dest, size_t byte_size)
bool ensure_gpu_ready ()
 Ensure GPU resources are initialised.
void ensure_shared_buffer (uint32_t set, size_t binding_index, size_t element_count, GpuBufferBinding::ElementType element_type, Portal::Graphics::BufferUsageHint usage_hint=Portal::Graphics::BufferUsageHint::COMPUTE_STORAGE)
 Ensure a shared storage buffer of at least element_count elements exists at (set, binding_index).
void fill_shared (uint32_t set, size_t binding_index, uint32_t value)
 Fill the whole shared buffer at (set, binding_index) with one 32-bit value, in order with the recorded dispatches.
std::shared_ptr< Core::VKImage > get_output_image (size_t binding_index) const
 Return the image registered at an IMAGE_STORAGE output binding.
 GpuDispatchCore (const GpuDispatchCore &)=delete
 GpuDispatchCore (GpuComputeConfig config, bool compute_isolated=true)
 GpuDispatchCore (GpuDispatchCore &&)=delete
void import_shared (uint32_t set, size_t binding_index, const GpuDispatchCore &source, uint32_t source_set, size_t source_binding_index, GpuBufferBinding::ElementType element_type)
 Resolve a binding of this context to a shared buffer owned by another context.
bool is_gpu_ready () const
 Query GPU readiness without attempting initialisation.
GpuDispatchCore & operator= (const GpuDispatchCore &)=delete
GpuDispatchCore & operator= (GpuDispatchCore &&)=delete
void record_stages (const std::vector< DependencyStage > &stages)
 Stage and record each stage in order, one dispatch per stage.
template<typename T>
void set_binding_data (size_t index, const std::vector< T > &data)
template<typename T>
void set_binding_data (size_t index, std::span< const T > data)
 Pre-stage typed data for a specific binding slot, bypassing the default channel-flattening path in prepare_gpu_inputs.
void set_output_size (size_t index, size_t byte_size)
 Declare the byte capacity of an output binding independently of input data.
template<typename T>
void set_push_constants (const T &data)
 Typed convenience wrapper for set_push_constants(const void*, size_t).
void set_push_constants (const void *data, size_t bytes)
 Set push constant data from a raw byte pointer.
void set_recording (std::shared_ptr< GpuDispatchRecorder > recording)
 Append this context's work to a recording shared with other contexts.
uint64_t shared_buffer_address (uint32_t set, size_t binding_index) const
 Device address of the shared buffer at (set, binding_index), or zero when absent.
Portal::Graphics::GpuBufferHandle shared_buffer_handle (uint32_t set, size_t binding_index) const
 Non-owning view of the shared buffer at (set, binding_index).
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 stage_image_at (size_t binding_index, std::shared_ptr< Core::VKImage > image, GpuBufferBinding::ElementType kind, vk::Sampler sampler=nullptr)
 Register a VKImage at an explicit binding index.
void swap_shader (GpuComputeConfig config)
 Switch which shader subsequent dispatch_core calls target.
void upload_shared_raw (uint32_t set, size_t binding_index, const uint8_t *data, size_t byte_size)
virtual ~GpuDispatchCore ()=default

Static Public Member Functions

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.
Static Public Member Functions inherited from MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType >
template<typename T>
static std::vector< T > read_output (const Datum< std::vector< Kakshya::DataVariant > > &result, size_t binding_index)
 Read a typed output buffer from a pipeline result Datum.

Static Public Attributes

static constexpr uint32_t result_binding = 3
 The binding that holds the result of a dispatch.

Protected Member Functions

std::array< uint32_t, 3 > calculate_dispatch_size (size_t, const DataStructureInfo &) const override
 One workgroup per window.
Protected Member Functions inherited from MayaFlux::Yantra::WordPairExecutionContext
output_type collect_gpu_outputs (const GpuChannelResult &raw, const std::vector< std::vector< double > > &, const DataStructureInfo &) override
 Keeps the primary output as words; the context returns no Datum.
Protected Member Functions inherited from MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType >
std::vector< GpuBufferBinding > declare_buffer_bindings () const override
 Returns the binding list declared via constructor or fluent API.
Protected Member Functions inherited from MayaFlux::Yantra::GpuExecutionContext< InputType, OutputType >
virtual std::pair< std::vector< std::vector< double > >, DataStructureInfo > extract_inputs (const input_type &input)
 Extract channel data and structure metadata from the input Datum.
Protected Member Functions inherited from MayaFlux::Yantra::GpuDispatchCore
GpuChannelResult dispatch_core (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
 Full single-pass dispatch.
Portal::Graphics::FenceID dispatch_core_async (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
 Non-blocking variant of dispatch_core.
GpuChannelResult dispatch_core_chained (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info, const ExecutionContext &ctx)
 Multi-pass (chained) dispatch.
GpuChannelResult dispatch_core_chained_indirect (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info, const ExecutionContext &ctx)
 Multi-pass dispatch where a GPU-resident indirect buffer gates each pass's workgroup count instead of a fixed pass_count.
size_t find_first_output_index () const
void flatten_channels_to_staging (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
 Flatten planar double channels into m_staging_floats.
void flatten_native_variants_to_staging (const std::vector< Kakshya::DataVariant > &variants, const DataStructureInfo &structure_info)
 Flatten native-typed DataVariant channels into m_native_staging_bytes without any conversion.
const GpuComputeConfig & gpu_config () const
size_t largest_binding_data_element_count () const
size_t last_effective_element_count () const
 Effective element count used by the last dispatch_core or dispatch_core_async call.
virtual void on_before_gpu_dispatch (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
 Called immediately before dispatch.
virtual void prepare_gpu_inputs (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
 Marshal channel data into GPU input buffers.
void readback_aux (GpuChannelResult &result)
 Read back all OUTPUT bindings that have explicit size overrides into the aux map of a GpuChannelResult.
std::vector< float > readback_primary (size_t float_count)
 Read back the primary output buffer into a float vector.
void stage_native_bytes (Kakshya::GpuDataFormat format, const void *data, size_t byte_size)
 Stage raw input bytes of one element type for the next dispatch.
void stage_passthrough (size_t binding_index, const void *data, size_t byte_size)
 Stage raw bytes for a PASSTHROUGH binding before dispatch.

Private Member Functions

 FftContext (const Portal::Graphics::ShaderSpec &spec, uint32_t points, Portal::Graphics::SpectrumOutput output, bool inverse, std::span< const double > weights={})

Static Private Member Functions

static uint32_t row_count (uint32_t points, size_t weights) noexcept

Private Attributes

uint32_t m_descriptors
uint32_t m_points
bool m_power
bool m_projection
double m_scale
std::vector< double > m_twiddle
std::vector< double > m_weights
uint32_t m_windows { 1 }

Additional Inherited Members

Public Types inherited from MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType >
using input_type = typename GpuExecutionContext<InputType, OutputType>::input_type
using output_type = typename GpuExecutionContext<InputType, OutputType>::output_type
Public Types inherited from MayaFlux::Yantra::GpuExecutionContext< InputType, OutputType >
using input_type = Datum<InputType>
using output_type = Datum<OutputType>
Protected Attributes inherited from MayaFlux::Yantra::GpuDispatchCore
std::vector< std::vector< uint8_t > > m_binding_data
std::vector< GpuBufferBinding > m_bindings
std::vector< ImageBinding > m_image_bindings
std::vector< size_t > m_output_size_overrides
std::vector< std::vector< uint8_t > > m_passthrough_bytes
std::vector< uint8_t > m_push_constants
GpuResourceManager m_resources
std::vector< float > m_staging_floats

Detailed Description

One FFT per window, as one dispatch of the FFT template.

Windows are read from the input at a length, stride and offset given in complex elements, multiplied by a window function and zero padded to the point count. The butterflies run in the template's emulated IEEE double arithmetic on word pairs, with twiddle factors computed here in double, so a result agrees with a host transform to rounding. An inverse context uses the conjugate twiddles and scales its output by one over the point count.

Complex output is points bins per window as interleaved re, im. Power output is points / 2 + 1 bins per window of re * re + im * im, which is the non-redundant half for a real signal. A projection context takes rows of weights, one per power bin, and returns one value per row and window: the weights summed against the power spectrum, so band energies, spectral moments and filterbank outputs leave the device as a few doubles per window.

The point count is a power of two from 2 to 2048. The input must hold at least one complex element.

Definition at line 38 of file FftContext.hpp.


The documentation for this class was generated from the following file: