Blender  V3.3
Classes | Namespaces | Typedefs | Enumerations | Functions
BLI_devirtualize_parameters.hh File Reference
#include "BLI_parameter_pack_utils.hh"
#include "BLI_virtual_array.hh"

Go to the source code of this file.

Classes

class  blender::devirtualize_parameters::Devirtualizer< Fn, SourceTypes >
 

Namespaces

 blender
 
 blender::devirtualize_parameters
 

Typedefs

template<DeviMode... Mode>
using blender::devirtualize_parameters::DeviModeSequence = ValueSequence< DeviMode, Mode... >
 

Enumerations

enum class  blender::devirtualize_parameters::DeviMode {
  blender::devirtualize_parameters::None = 0 , blender::devirtualize_parameters::Keep = (1 << 0) , blender::devirtualize_parameters::Span = (1 << 1) , blender::devirtualize_parameters::Single = (1 << 2) ,
  blender::devirtualize_parameters::Range = (1 << 3)
}
 

Functions

 blender::devirtualize_parameters::ENUM_OPERATORS (DeviMode, DeviMode::Range)
 
template<typename T , typename Func >
void blender::devirtualize_varray (const VArray< T > &varray, const Func &func, bool enable=true)
 
template<typename T1 , typename T2 , typename Func >
void blender::devirtualize_varray2 (const VArray< T1 > &varray1, const VArray< T2 > &varray2, const Func &func, bool enable=true)
 

Detailed Description

In geometry nodes, many functions accept fields as inputs. For the implementation that means that the inputs are virtual arrays. Usually those are backed by actual arrays or single values but sometimes virtual arrays are used to compute values on demand or convert between data formats.

Using virtual arrays has the downside that individual elements are accessed through a virtual method call, which has some overhead compared to normal array access. Whether this overhead is negligible depends on the context. For very small functions (e.g. a single addition), the overhead can make the function many times slower. Furthermore, it prevents the compiler from doing some optimizations (e.g. loop unrolling and inserting SIMD instructions).

The solution is to "devirtualize" the virtual arrays in cases when the overhead cannot be ignored. That means that the function is instantiated multiple times at compile time for the different cases. For example, there can be an optimized function that adds a span and a single value, and another function that adds a span and another span. At run-time there is a dynamic dispatch that executes the best function given the specific virtual arrays.

The problem with this devirtualization is that it can result in exponentially increasing compile times and binary sizes, depending on the number of parameters that are devirtualized separately. So there is always a trade-off between run-time performance and compile-time/binary-size.

This file provides a utility to devirtualize array parameters to a function using a high level API. This makes it easy to experiment with different extremes of the mentioned trade-off and allows finding a good compromise for each function.

Definition in file BLI_devirtualize_parameters.hh.