Sets the executor function for this rule.
- Template Parameters
-
| Func | Function type (usually a lambda) |
- Parameters
-
| executor | Function 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 {
420 m_rule.
executor = [func = std::forward<Func>(executor), spec = std::move(spec)](
421 const std::any&
input,
const ExecutionContext& ctx) -> std::any {
424
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 {
435 const std::any&
input,
const ExecutionContext& ctx) -> std::any {
436 return func(
input, ctx);
437 };
438 }
439 return *this;
440 }
Core::GlobalInputConfig input
Rule m_rule
Rule being constructed.
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.