diff options
author | Jacques Lucke <jacques@blender.org> | 2021-03-21 21:31:24 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-03-21 21:33:13 +0300 |
commit | 4fe8d0419c2f080a248f52b3924ce2a4e897e5cb (patch) | |
tree | 81aba45e26cca99578087835184ce5664362b791 /source/blender/nodes | |
parent | 68c31c41e52caa1ac5b527f835b16f8e298dfd86 (diff) |
Functions: refactor virtual array data structures
When a function is executed for many elements (e.g. per point) it is often the case
that some parameters are different for every element and other parameters are
the same (there are some more less common cases). To simplify writing such
functions one can use a "virtual array". This is a data structure that has a value
for every index, but might not be stored as an actual array internally. Instead, it
might be just a single value or is computed on the fly. There are various tradeoffs
involved when using this data structure which are mentioned in `BLI_virtual_array.hh`.
It is called "virtual", because it uses inheritance and virtual methods.
Furthermore, there is a new virtual vector array data structure, which is an array
of vectors. Both these types have corresponding generic variants, which can be used
when the data type is not known at compile time. This is typically the case when
building a somewhat generic execution system. The function system used these virtual
data structures before, but now they are more versatile.
I've done this refactor in preparation for the attribute processor and other features of
geometry nodes. I moved the typed virtual arrays to blenlib, so that they can be used
independent of the function system.
One open question for me is whether all the generic data structures (and `CPPType`)
should be moved to blenlib as well. They are well isolated and don't really contain
any business logic. That can be done later if necessary.
Diffstat (limited to 'source/blender/nodes')
6 files changed, 14 insertions, 14 deletions
diff --git a/source/blender/nodes/function/nodes/node_fn_object_transforms.cc b/source/blender/nodes/function/nodes/node_fn_object_transforms.cc index 26b25406590..55f592d7879 100644 --- a/source/blender/nodes/function/nodes/node_fn_object_transforms.cc +++ b/source/blender/nodes/function/nodes/node_fn_object_transforms.cc @@ -42,7 +42,7 @@ class ObjectTransformsFunction : public blender::fn::MultiFunction { blender::fn::MFParams params, blender::fn::MFContext context) const override { - blender::fn::VSpan handles = + const blender::VArray<blender::bke::PersistentObjectHandle> &handles = params.readonly_single_input<blender::bke::PersistentObjectHandle>(0, "Object"); blender::MutableSpan locations = params.uninitialized_single_output<blender::float3>( 1, "Location"); diff --git a/source/blender/nodes/function/nodes/node_fn_random_float.cc b/source/blender/nodes/function/nodes/node_fn_random_float.cc index d0ecb5592da..84ded73c601 100644 --- a/source/blender/nodes/function/nodes/node_fn_random_float.cc +++ b/source/blender/nodes/function/nodes/node_fn_random_float.cc @@ -48,9 +48,9 @@ class RandomFloatFunction : public blender::fn::MultiFunction { blender::fn::MFParams params, blender::fn::MFContext UNUSED(context)) const override { - blender::fn::VSpan<float> min_values = params.readonly_single_input<float>(0, "Min"); - blender::fn::VSpan<float> max_values = params.readonly_single_input<float>(1, "Max"); - blender::fn::VSpan<int> seeds = params.readonly_single_input<int>(2, "Seed"); + const blender::VArray<float> &min_values = params.readonly_single_input<float>(0, "Min"); + const blender::VArray<float> &max_values = params.readonly_single_input<float>(1, "Max"); + const blender::VArray<int> &seeds = params.readonly_single_input<int>(2, "Seed"); blender::MutableSpan<float> values = params.uninitialized_single_output<float>(3, "Value"); for (int64_t i : mask) { diff --git a/source/blender/nodes/shader/nodes/node_shader_map_range.cc b/source/blender/nodes/shader/nodes/node_shader_map_range.cc index c01e390c513..3aa533599cf 100644 --- a/source/blender/nodes/shader/nodes/node_shader_map_range.cc +++ b/source/blender/nodes/shader/nodes/node_shader_map_range.cc @@ -108,11 +108,11 @@ class MapRangeFunction : public blender::fn::MultiFunction { blender::fn::MFParams params, blender::fn::MFContext UNUSED(context)) const override { - blender::fn::VSpan<float> values = params.readonly_single_input<float>(0, "Value"); - blender::fn::VSpan<float> from_min = params.readonly_single_input<float>(1, "From Min"); - blender::fn::VSpan<float> from_max = params.readonly_single_input<float>(2, "From Max"); - blender::fn::VSpan<float> to_min = params.readonly_single_input<float>(3, "To Min"); - blender::fn::VSpan<float> to_max = params.readonly_single_input<float>(4, "To Max"); + const blender::VArray<float> &values = params.readonly_single_input<float>(0, "Value"); + const blender::VArray<float> &from_min = params.readonly_single_input<float>(1, "From Min"); + const blender::VArray<float> &from_max = params.readonly_single_input<float>(2, "From Max"); + const blender::VArray<float> &to_min = params.readonly_single_input<float>(3, "To Min"); + const blender::VArray<float> &to_max = params.readonly_single_input<float>(4, "To Max"); blender::MutableSpan<float> results = params.uninitialized_single_output<float>(5, "Result"); for (int64_t i : mask) { diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc index 59b89c46fc7..a9057428981 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.cc @@ -74,8 +74,8 @@ class SeparateRGBFunction : public blender::fn::MultiFunction { blender::fn::MFParams params, blender::fn::MFContext UNUSED(context)) const override { - blender::fn::VSpan<blender::Color4f> colors = params.readonly_single_input<blender::Color4f>( - 0, "Color"); + const blender::VArray<blender::Color4f> &colors = + params.readonly_single_input<blender::Color4f>(0, "Color"); blender::MutableSpan<float> rs = params.uninitialized_single_output<float>(1, "R"); blender::MutableSpan<float> gs = params.uninitialized_single_output<float>(2, "G"); blender::MutableSpan<float> bs = params.uninitialized_single_output<float>(3, "B"); diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc index 8b23327460f..c0dc66b3342 100644 --- a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc +++ b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.cc @@ -59,8 +59,8 @@ class MF_SeparateXYZ : public blender::fn::MultiFunction { blender::fn::MFParams params, blender::fn::MFContext UNUSED(context)) const override { - blender::fn::VSpan<blender::float3> vectors = params.readonly_single_input<blender::float3>( - 0, "XYZ"); + const blender::VArray<blender::float3> &vectors = + params.readonly_single_input<blender::float3>(0, "XYZ"); blender::MutableSpan<float> xs = params.uninitialized_single_output<float>(1, "X"); blender::MutableSpan<float> ys = params.uninitialized_single_output<float>(2, "Y"); blender::MutableSpan<float> zs = params.uninitialized_single_output<float>(3, "Z"); diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc b/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc index a86a8bb8935..0d50582e23a 100644 --- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc +++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.cc @@ -142,7 +142,7 @@ class ColorBandFunction : public blender::fn::MultiFunction { blender::fn::MFParams params, blender::fn::MFContext UNUSED(context)) const override { - blender::fn::VSpan<float> values = params.readonly_single_input<float>(0, "Value"); + const blender::VArray<float> &values = params.readonly_single_input<float>(0, "Value"); blender::MutableSpan<blender::Color4f> colors = params.uninitialized_single_output<blender::Color4f>(1, "Color"); blender::MutableSpan<float> alphas = params.uninitialized_single_output<float>(2, "Alpha"); |