45template <ComputeData InputType = std::vector<Kakshya::DataVariant>,
46 ComputeData OutputType = InputType>
64 std::vector<GpuBufferBinding> bindings = {},
65 std::string name =
"ShaderExecutionContext")
91 .element_type = type });
104 template <
typename T>
111 .element_type = type });
124 template <
typename T>
132 .element_type = type });
146 template <
typename T>
153 .element_type = type });
176 .element_type = type });
196 .element_type = type });
214 .element_type = type });
233 .element_type = type });
248 template <
typename T>
269 std::function<
void(uint32_t,
void*)> pc_updater)
298 template <
typename T>
300 const Datum<std::vector<Kakshya::DataVariant>>& result,
301 size_t binding_index)
303 const auto key =
"gpu_output_" + std::to_string(binding_index);
305 if (!result.metadata.contains(key)) {
307 std::source_location::current(),
308 "read_output: metadata key '{}' not found", key);
311 const auto& raw = safe_any_cast_or_throw<std::vector<uint8_t>>(result.metadata.at(key));
312 const size_t count = raw.size() /
sizeof(T);
313 std::vector<T> out(
count);
314 std::memcpy(out.data(), raw.data(),
count *
sizeof(T));
332 if (
b.binding == binding)
333 b.skip_auto_readback = skip;
414 return std::ranges::max(
437template <ComputeData InputType = std::vector<Kakshya::DataVariant>,
438 ComputeData OutputType = InputType>
439std::shared_ptr<ShaderExecutionContext<InputType, OutputType>>
442 std::vector<GpuBufferBinding> bindings,
443 std::string name =
"ShaderExecutionContext")
445 return std::make_shared<ShaderExecutionContext<InputType, OutputType>>(
Core::GlobalInputConfig input
void readback_aux(GpuChannelResult &result)
Read back all OUTPUT bindings that have explicit size overrides into the aux map of a GpuChannelResul...
Portal::Graphics::FenceID dispatch_core_async(const std::vector< std::vector< double > > &channels, const DataStructureInfo &structure_info)
Non-blocking variant of dispatch_core.
bool ensure_gpu_ready()
Ensure GPU resources are initialised.
size_t last_effective_element_count() const
Effective element count used by the last dispatch_core or dispatch_core_async call.
void set_output_size(size_t index, size_t byte_size)
Declare the byte capacity of an output binding independently of input data.
std::vector< float > readback_primary(size_t float_count)
Read back the primary output buffer into a float vector.
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 pr...
void set_push_constants(const void *data, size_t bytes)
Set push constant data from a raw byte pointer.
virtual output_type execute(const input_type &input, const ExecutionContext &ctx)
Dispatch to GPU and reconstruct a typed output Datum.
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.
Type-parameterised shell over GpuDispatchCore.
std::vector< GpuBufferBinding > m_bindings
uint32_t m_multipass_count
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.
std::vector< GpuBufferBinding > declare_buffer_bindings() const override
Returns the binding list declared via constructor or fluent API.
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 & 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...
ShaderExecutionContext & output(uint32_t binding, size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an OUTPUT binding at an explicit index.
uint32_t next_binding_index() const
Returns one past the highest binding index currently registered.
ShaderExecutionContext & input(const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an INPUT binding, inferring the next available binding index.
ShaderExecutionContext & set_multipass(uint32_t pass_count, std::function< void(uint32_t, void *)> pc_updater)
Configure multi-pass (CHAINED) dispatch.
ShaderExecutionContext & in_out(uint32_t binding, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Declare an INPUT_OUTPUT binding without pre-staging data.
ShaderExecutionContext(GpuComputeConfig config, std::vector< GpuBufferBinding > bindings={}, std::string name="ShaderExecutionContext")
Construct with shader config and optional pre-built binding list.
Portal::Graphics::FenceID dispatch_async(const input_type &input)
Dispatch asynchronously and return a fence for polling.
ShaderExecutionContext & in_out(GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Declare an INPUT_OUTPUT binding at an explicit index without pre-staging data.
typename GpuExecutionContext< InputType, OutputType >::output_type output_type
ShaderExecutionContext & input(uint32_t binding, const std::vector< T > &data, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an INPUT binding at an explicit index.
typename GpuExecutionContext< InputType, OutputType >::input_type input_type
GpuChannelResult collect_result()
Collect the result of the last async dispatch.
void set_skip_readback(uint32_t binding, bool skip)
Set or clear skip_auto_readback for a binding by index.
std::function< void(uint32_t, void *)> m_multipass_updater
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 & output(size_t byte_size, GpuBufferBinding::ElementType type=GpuBufferBinding::ElementType::FLOAT32)
Add an OUTPUT binding, inferring the next available binding index.
Concrete GpuExecutionContext for a single fixed shader with fixed bindings.
@ Runtime
General runtime operations (default fallback)
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
constexpr FenceID INVALID_FENCE
@ CHAINED
Part of a sequential chain.
std::shared_ptr< ShaderExecutionContext< InputType, OutputType > > make_shader_executor(GpuComputeConfig config, std::vector< GpuBufferBinding > bindings, std::string name="ShaderExecutionContext")
Convenience factory for ShaderExecutionContext.
ElementType
Element type the shader expects in this binding.
enum MayaFlux::Portal::Graphics::GpuBufferBinding::Direction INPUT
enum MayaFlux::Portal::Graphics::GpuBufferBinding::ElementType FLOAT32
Declares a single storage buffer or image binding a compute shader expects.
Plain-data description of the compute shader to dispatch.
Parameters for ExecutionMode::CHAINED.
Input/Output container for computation pipeline data flow with structure preservation.
ExecutionMode mode
Execution mode controlling scheduling behavior.
ExecutionParams parameters
Optional parameters specific to the execution mode.
Context information controlling how a compute operation executes.
std::vector< float > primary
Erased output of a GPU dispatch: reconstructed float data plus any raw auxiliary outputs keyed by bin...