MayaFlux 0.4.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType > Class Template Reference

Concrete GpuExecutionContext for a single fixed shader with fixed bindings. More...

#include <ShaderExecutionContext.hpp>

+ Inheritance diagram for MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType >:
+ Collaboration diagram for MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType >:

Public Types

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 >
 

Public Member Functions

template<typename T >
ShaderExecutionContextin_out (const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT_OUTPUT binding, inferring the next available binding index.
 
ShaderExecutionContextin_out (GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Declare an INPUT_OUTPUT binding at an explicit index without pre-staging data.
 
template<typename T >
ShaderExecutionContextin_out (uint32_t binding, const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT_OUTPUT binding at an explicit index.
 
ShaderExecutionContextin_out (uint32_t binding, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Declare an INPUT_OUTPUT binding without pre-staging data.
 
template<typename T >
ShaderExecutionContextinput (const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT binding, inferring the next available binding index.
 
template<typename T >
ShaderExecutionContextinput (uint32_t binding, const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an INPUT binding at an explicit index.
 
ShaderExecutionContextoutput (size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an OUTPUT binding, inferring the next available binding index.
 
ShaderExecutionContextoutput (uint32_t binding, size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
 Add an OUTPUT binding at an explicit index.
 
template<typename T >
ShaderExecutionContextpush (const T &data)
 Set push constants from a trivially copyable struct or value.
 
ShaderExecutionContextset_multipass (uint32_t pass_count, std::function< void(uint32_t, void *)> pc_updater)
 Configure multi-pass (CHAINED) dispatch.
 
 ShaderExecutionContext (GpuShaderConfig config, std::vector< GpuBufferBinding > bindings={}, std::string name="ShaderExecutionContext")
 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 (GpuExecutionContext &&)=delete
 
 GpuExecutionContext (GpuShaderConfig config)
 
GpuExecutionContextoperator= (const GpuExecutionContext &)=delete
 
GpuExecutionContextoperator= (GpuExecutionContext &&)=delete
 
 ~GpuExecutionContext () override=default
 
- Public Member Functions inherited from MayaFlux::Yantra::GpuDispatchCore
bool ensure_gpu_ready ()
 Ensure GPU resources are initialised.
 
std::shared_ptr< Core::VKImageget_output_image (size_t binding_index) const
 Return the image registered at an IMAGE_STORAGE output binding.
 
 GpuDispatchCore (const GpuDispatchCore &)=delete
 
 GpuDispatchCore (GpuDispatchCore &&)=delete
 
 GpuDispatchCore (GpuShaderConfig config)
 
bool is_gpu_ready () const
 Query GPU readiness without attempting initialisation.
 
GpuDispatchCoreoperator= (const GpuDispatchCore &)=delete
 
GpuDispatchCoreoperator= (GpuDispatchCore &&)=delete
 
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.
 
virtual ~GpuDispatchCore ()=default
 

Static Public Member Functions

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.
 

Protected Member Functions

std::vector< GpuBufferBindingdeclare_buffer_bindings () const override
 Returns the binding list declared via constructor or fluent API.
 
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.
 
- Protected Member Functions inherited from MayaFlux::Yantra::GpuExecutionContext< InputType, OutputType >
virtual output_type collect_gpu_outputs (const GpuChannelResult &raw, const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
 Reconstruct Datum<OutputType> from a GpuChannelResult.
 
virtual std::pair< std::vector< std::vector< double > >, DataStructureInfoextract_inputs (const input_type &input)
 Extract double channels and structure metadata from the input Datum.
 
- Protected Member Functions inherited from MayaFlux::Yantra::GpuDispatchCore
virtual std::array< uint32_t, 3 > calculate_dispatch_size (size_t total_elements, const DataStructureInfo &structure_info) const
 Calculate workgroup dispatch counts from structure dimensions.
 
GpuChannelResult dispatch_core (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
 Full single-pass dispatch.
 
GpuChannelResult dispatch_core_chained (const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info, const ExecutionContext &ctx)
 Multi-pass (chained) dispatch.
 
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.
 
const GpuShaderConfiggpu_config () const
 
size_t largest_binding_data_element_count () const
 
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_image_sampled (size_t binding_index, std::shared_ptr< Core::VKImage > image, vk::Sampler sampler)
 Register a VKImage + sampler for an IMAGE_SAMPLED binding.
 
void stage_image_storage (size_t binding_index, std::shared_ptr< Core::VKImage > image)
 Register a VKImage for an IMAGE_STORAGE binding.
 
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

uint32_t next_binding_index () const
 Returns one past the highest binding index currently registered.
 

Private Attributes

std::vector< GpuBufferBindingm_bindings
 
uint32_t m_multipass_count { 0 }
 
std::function< void(uint32_t, void *)> m_multipass_updater
 
std::string m_name
 

Additional Inherited Members

- Protected Attributes inherited from MayaFlux::Yantra::GpuDispatchCore
std::vector< std::vector< uint8_t > > m_binding_data
 
std::vector< GpuBufferBindingm_bindings
 
std::vector< ImageBindingm_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

template<ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = InputType>
class MayaFlux::Yantra::ShaderExecutionContext< InputType, OutputType >

Concrete GpuExecutionContext for a single fixed shader with fixed bindings.

The standard path for attaching GPU dispatch to any ComputeOperation via ComputeOperation::set_gpu_backend(). Bindings are declared at construction or built incrementally through the fluent API. The owning ComputeOperation provides category identity, parameter system, and CPU fallback.

Construction followed by fluent configuration:

auto executor = std::make_shared<ShaderExecutionContext<>>(
GpuShaderConfig { "graph_build.comp", { 256, 1, 1 }, sizeof(GraphBuildPC) });
executor->input(positions)
.input(attributes)
.output(k_max_edges * 2 * sizeof(float))
.push(pc);
my_operation->set_gpu_backend(executor);
ShaderExecutionContext & push(const T &data)
Set push constants from a trivially copyable struct or value.
ShaderExecutionContext & output(size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an OUTPUT binding, inferring the next available binding index.
Plain-data description of the compute shader to dispatch.

Or with explicit binding indices when order cannot be inferred:

executor->input(0, positions)
.inout(1, data)
.output(2, output_bytes);

Output readback after pipeline execution:

Eigen::Index count
Concrete GpuExecutionContext for a single fixed shader with fixed bindings.
Template Parameters
InputTypeComputeData type accepted.
OutputTypeComputeData type produced.

Definition at line 47 of file ShaderExecutionContext.hpp.


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