Blender V4.3
FN_lazy_function.hh File Reference
#include "BLI_cpp_type.hh"
#include "BLI_function_ref.hh"
#include "BLI_generic_pointer.hh"
#include "BLI_linear_allocator.hh"
#include "BLI_vector.hh"
#include <atomic>
#include <thread>

Go to the source code of this file.

Classes

class  blender::fn::lazy_function::LocalUserData
 
class  blender::fn::lazy_function::UserData
 
struct  blender::fn::lazy_function::Context
 
class  blender::fn::lazy_function::Params
 
struct  blender::fn::lazy_function::Input
 
struct  blender::fn::lazy_function::Output
 
class  blender::fn::lazy_function::LazyFunction
 

Namespaces

namespace  blender
 
namespace  blender::fn
 
namespace  blender::fn::lazy_function
 

Macros

#define FN_LAZY_FUNCTION_DEBUG_THREADS
 

Enumerations

enum class  blender::fn::lazy_function::ValueUsage : uint8_t { blender::fn::lazy_function::Used , blender::fn::lazy_function::Maybe , blender::fn::lazy_function::Unused }
 

Detailed Description

A LazyFunction encapsulates a computation which has inputs, outputs and potentially side effects. Most importantly, a LazyFunction supports laziness in its inputs and outputs:

  • Only outputs that are actually used have to be computed.
  • Inputs can be requested lazily based on which outputs are used or what side effects the function has.

A lazy-function that uses laziness may be executed more than once. The most common example is the geometry nodes switch node. Depending on a condition input, it decides which one of the other inputs is actually used. From the perspective of the switch node, its execution works as follows:

  1. The switch node is first executed. It sees that the output is used. Now it requests the condition input from the caller and exits.
  2. Once the caller is able to provide the condition input the switch node is executed again. This time it retrieves the condition and requests one of the other inputs. Then the node exits again, giving back control to the caller.
  3. When the caller computed the second requested input the switch node executes a last time. This time it retrieves the new input and forwards it to the output.

In some sense, a lazy-function can be thought of like a state machine. Every time it is executed, it advances its state until all required outputs are ready.

The lazy-function interface is designed to support composition of many such functions into a new lazy-functions, all while keeping the laziness working. For example, in geometry nodes a switch node in a node group should still be able to decide whether a node in the parent group will be executed or not. This is essential to avoid doing unnecessary work.

The lazy-function system consists of multiple core components:

  • The interface of a lazy-function itself including its calling convention.
  • A graph data structure that allows composing many lazy-functions by connecting their inputs and outputs.
  • An executor that allows multi-threaded execution or such a graph.

Definition in file FN_lazy_function.hh.

Macro Definition Documentation

◆ FN_LAZY_FUNCTION_DEBUG_THREADS

#define FN_LAZY_FUNCTION_DEBUG_THREADS

Definition at line 53 of file FN_lazy_function.hh.