MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ executes()

template<typename Func >
RuleBuilder & MayaFlux::Yantra::ComputationGrammar::RuleBuilder::executes ( Func &&  executor)
inline

Sets the executor function for this rule.

Template Parameters
FuncFunction type (usually a lambda)
Parameters
executorFunction that performs the computation
Returns
Reference to this builder for method chaining

The executor function receives the input data and execution context, and returns the result of the computation. This is where the actual work of the rule is performed.

If with_gpu_backend() was called, the executor wrapper attaches a ShaderExecutionContext to the operation before invoking the user lambda. The user lambda receives the already-GPU-backed operation transparently and serves as the CPU fallback if GPU setup fails.

Definition at line 416 of file ComputeGrammar.hpp.

417 {
418 if (m_rule.gpu_spec.has_value()) {
419 auto spec = *m_rule.gpu_spec;
420 m_rule.executor = [func = std::forward<Func>(executor), spec = std::move(spec)](
421 const std::any& input, const ExecutionContext& ctx) -> std::any {
422 const auto cfg = config_from_spec(spec);
423 const auto bindings = bindings_from_spec(spec);
424
425 if (cfg.shader_id != Portal::Graphics::INVALID_SHADER) {
426 auto gpu_exec = std::make_shared<ShaderExecutionContext<>>(cfg, bindings);
427 ExecutionContext patched = ctx;
428 patched.execution_metadata["_gpu_exec"] = gpu_exec;
429 return func(input, patched);
430 }
431 return func(input, ctx);
432 };
433 } else {
434 m_rule.executor = [func = std::forward<Func>(executor)](
435 const std::any& input, const ExecutionContext& ctx) -> std::any {
436 return func(input, ctx);
437 };
438 }
439 return *this;
440 }
Core::GlobalInputConfig input
Definition Config.cpp:38
constexpr ShaderID INVALID_SHADER
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.
std::optional< Portal::Graphics::ShaderSpec > gpu_spec
When set, executor receives a GPU-backed operation.
Executor executor
Function that performs the computation.

References MayaFlux::Yantra::bindings_from_spec(), MayaFlux::Yantra::config_from_spec(), MayaFlux::Yantra::ExecutionContext::execution_metadata, MayaFlux::Yantra::ComputationGrammar::Rule::executor, MayaFlux::Yantra::ComputationGrammar::Rule::gpu_spec, and input.

+ Here is the call graph for this function: