2022-02-11 09:07:11 +11:00
|
|
|
/* SPDX-License-Identifier: Apache-2.0 */
|
2021-09-09 12:54:20 +02:00
|
|
|
|
|
|
|
|
#include "testing/testing.h"
|
|
|
|
|
|
2022-03-18 10:57:45 +01:00
|
|
|
#include "BLI_cpp_type.hh"
|
2021-09-09 12:54:20 +02:00
|
|
|
#include "FN_field.hh"
|
|
|
|
|
#include "FN_multi_function_builder.hh"
|
2021-09-14 14:52:44 +02:00
|
|
|
#include "FN_multi_function_test_common.hh"
|
2021-09-09 12:54:20 +02:00
|
|
|
|
|
|
|
|
namespace blender::fn::tests {
|
|
|
|
|
|
|
|
|
|
TEST(field, ConstantFunction)
|
|
|
|
|
{
|
|
|
|
|
/* TODO: Figure out how to not use another "FieldOperation(" inside of std::make_shared. */
|
|
|
|
|
GField constant_field{std::make_shared<FieldOperation>(
|
|
|
|
|
FieldOperation(std::make_unique<CustomMF_Constant<int>>(10), {})),
|
|
|
|
|
0};
|
|
|
|
|
|
|
|
|
|
Array<int> result(4);
|
|
|
|
|
|
|
|
|
|
FieldContext context;
|
|
|
|
|
FieldEvaluator evaluator{context, 4};
|
|
|
|
|
evaluator.add_with_destination(constant_field, result.as_mutable_span());
|
|
|
|
|
evaluator.evaluate();
|
|
|
|
|
EXPECT_EQ(result[0], 10);
|
|
|
|
|
EXPECT_EQ(result[1], 10);
|
|
|
|
|
EXPECT_EQ(result[2], 10);
|
|
|
|
|
EXPECT_EQ(result[3], 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class IndexFieldInput final : public FieldInput {
|
|
|
|
|
public:
|
|
|
|
|
IndexFieldInput() : FieldInput(CPPType::get<int>(), "Index")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
GVArray get_varray_for_context(const FieldContext &UNUSED(context),
|
|
|
|
|
IndexMask mask,
|
|
|
|
|
ResourceScope &UNUSED(scope)) const final
|
2021-09-09 12:54:20 +02:00
|
|
|
{
|
|
|
|
|
auto index_func = [](int i) { return i; };
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
return VArray<int>::ForFunc(mask.min_array_size(), index_func);
|
2021-09-09 12:54:20 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST(field, VArrayInput)
|
|
|
|
|
{
|
|
|
|
|
GField index_field{std::make_shared<IndexFieldInput>()};
|
|
|
|
|
|
|
|
|
|
Array<int> result_1(4);
|
|
|
|
|
|
|
|
|
|
FieldContext context;
|
|
|
|
|
FieldEvaluator evaluator{context, 4};
|
|
|
|
|
evaluator.add_with_destination(index_field, result_1.as_mutable_span());
|
|
|
|
|
evaluator.evaluate();
|
|
|
|
|
EXPECT_EQ(result_1[0], 0);
|
|
|
|
|
EXPECT_EQ(result_1[1], 1);
|
|
|
|
|
EXPECT_EQ(result_1[2], 2);
|
|
|
|
|
EXPECT_EQ(result_1[3], 3);
|
|
|
|
|
|
|
|
|
|
/* Evaluate a second time, just to test that the first didn't break anything. */
|
|
|
|
|
Array<int> result_2(10);
|
|
|
|
|
|
|
|
|
|
const Array<int64_t> indices = {2, 4, 6, 8};
|
|
|
|
|
const IndexMask mask{indices};
|
|
|
|
|
|
|
|
|
|
FieldEvaluator evaluator_2{context, &mask};
|
|
|
|
|
evaluator_2.add_with_destination(index_field, result_2.as_mutable_span());
|
|
|
|
|
evaluator_2.evaluate();
|
|
|
|
|
EXPECT_EQ(result_2[2], 2);
|
|
|
|
|
EXPECT_EQ(result_2[4], 4);
|
|
|
|
|
EXPECT_EQ(result_2[6], 6);
|
|
|
|
|
EXPECT_EQ(result_2[8], 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(field, VArrayInputMultipleOutputs)
|
|
|
|
|
{
|
|
|
|
|
std::shared_ptr<FieldInput> index_input = std::make_shared<IndexFieldInput>();
|
|
|
|
|
GField field_1{index_input};
|
|
|
|
|
GField field_2{index_input};
|
|
|
|
|
|
|
|
|
|
Array<int> result_1(10);
|
|
|
|
|
Array<int> result_2(10);
|
|
|
|
|
|
|
|
|
|
const Array<int64_t> indices = {2, 4, 6, 8};
|
|
|
|
|
const IndexMask mask{indices};
|
|
|
|
|
|
|
|
|
|
FieldContext context;
|
|
|
|
|
FieldEvaluator evaluator{context, &mask};
|
|
|
|
|
evaluator.add_with_destination(field_1, result_1.as_mutable_span());
|
|
|
|
|
evaluator.add_with_destination(field_2, result_2.as_mutable_span());
|
|
|
|
|
evaluator.evaluate();
|
|
|
|
|
EXPECT_EQ(result_1[2], 2);
|
|
|
|
|
EXPECT_EQ(result_1[4], 4);
|
|
|
|
|
EXPECT_EQ(result_1[6], 6);
|
|
|
|
|
EXPECT_EQ(result_1[8], 8);
|
|
|
|
|
EXPECT_EQ(result_2[2], 2);
|
|
|
|
|
EXPECT_EQ(result_2[4], 4);
|
|
|
|
|
EXPECT_EQ(result_2[6], 6);
|
|
|
|
|
EXPECT_EQ(result_2[8], 8);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(field, InputAndFunction)
|
|
|
|
|
{
|
|
|
|
|
GField index_field{std::make_shared<IndexFieldInput>()};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<MultiFunction> add_fn = std::make_unique<CustomMF_SI_SI_SO<int, int, int>>(
|
|
|
|
|
"add", [](int a, int b) { return a + b; });
|
|
|
|
|
GField output_field{std::make_shared<FieldOperation>(
|
|
|
|
|
FieldOperation(std::move(add_fn), {index_field, index_field})),
|
|
|
|
|
0};
|
|
|
|
|
|
|
|
|
|
Array<int> result(10);
|
|
|
|
|
|
|
|
|
|
const Array<int64_t> indices = {2, 4, 6, 8};
|
|
|
|
|
const IndexMask mask{indices};
|
|
|
|
|
|
|
|
|
|
FieldContext context;
|
|
|
|
|
FieldEvaluator evaluator{context, &mask};
|
|
|
|
|
evaluator.add_with_destination(output_field, result.as_mutable_span());
|
|
|
|
|
evaluator.evaluate();
|
|
|
|
|
EXPECT_EQ(result[2], 4);
|
|
|
|
|
EXPECT_EQ(result[4], 8);
|
|
|
|
|
EXPECT_EQ(result[6], 12);
|
|
|
|
|
EXPECT_EQ(result[8], 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(field, TwoFunctions)
|
|
|
|
|
{
|
|
|
|
|
GField index_field{std::make_shared<IndexFieldInput>()};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<MultiFunction> add_fn = std::make_unique<CustomMF_SI_SI_SO<int, int, int>>(
|
|
|
|
|
"add", [](int a, int b) { return a + b; });
|
|
|
|
|
GField add_field{std::make_shared<FieldOperation>(
|
|
|
|
|
FieldOperation(std::move(add_fn), {index_field, index_field})),
|
|
|
|
|
0};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<MultiFunction> add_10_fn = std::make_unique<CustomMF_SI_SO<int, int>>(
|
|
|
|
|
"add_10", [](int a) { return a + 10; });
|
|
|
|
|
GField result_field{
|
|
|
|
|
std::make_shared<FieldOperation>(FieldOperation(std::move(add_10_fn), {add_field})), 0};
|
|
|
|
|
|
|
|
|
|
Array<int> result(10);
|
|
|
|
|
|
|
|
|
|
const Array<int64_t> indices = {2, 4, 6, 8};
|
|
|
|
|
const IndexMask mask{indices};
|
|
|
|
|
|
|
|
|
|
FieldContext context;
|
|
|
|
|
FieldEvaluator evaluator{context, &mask};
|
|
|
|
|
evaluator.add_with_destination(result_field, result.as_mutable_span());
|
|
|
|
|
evaluator.evaluate();
|
|
|
|
|
EXPECT_EQ(result[2], 14);
|
|
|
|
|
EXPECT_EQ(result[4], 18);
|
|
|
|
|
EXPECT_EQ(result[6], 22);
|
|
|
|
|
EXPECT_EQ(result[8], 26);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class TwoOutputFunction : public MultiFunction {
|
|
|
|
|
private:
|
|
|
|
|
MFSignature signature_;
|
|
|
|
|
|
|
|
|
|
public:
|
2021-11-21 13:06:05 +01:00
|
|
|
TwoOutputFunction()
|
2021-09-09 12:54:20 +02:00
|
|
|
{
|
2021-11-21 13:06:05 +01:00
|
|
|
MFSignatureBuilder signature{"Two Outputs"};
|
2021-09-09 12:54:20 +02:00
|
|
|
signature.single_input<int>("In1");
|
|
|
|
|
signature.single_input<int>("In2");
|
|
|
|
|
signature.single_output<int>("Add");
|
|
|
|
|
signature.single_output<int>("Add10");
|
|
|
|
|
signature_ = signature.build();
|
|
|
|
|
this->set_signature(&signature_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void call(IndexMask mask, MFParams params, MFContext UNUSED(context)) const override
|
|
|
|
|
{
|
|
|
|
|
const VArray<int> &in1 = params.readonly_single_input<int>(0, "In1");
|
|
|
|
|
const VArray<int> &in2 = params.readonly_single_input<int>(1, "In2");
|
|
|
|
|
MutableSpan<int> add = params.uninitialized_single_output<int>(2, "Add");
|
|
|
|
|
MutableSpan<int> add_10 = params.uninitialized_single_output<int>(3, "Add10");
|
|
|
|
|
mask.foreach_index([&](const int64_t i) {
|
|
|
|
|
add[i] = in1[i] + in2[i];
|
|
|
|
|
add_10[i] = add[i] + 10;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
TEST(field, FunctionTwoOutputs)
|
|
|
|
|
{
|
|
|
|
|
/* Also use two separate input fields, why not. */
|
|
|
|
|
GField index_field_1{std::make_shared<IndexFieldInput>()};
|
|
|
|
|
GField index_field_2{std::make_shared<IndexFieldInput>()};
|
|
|
|
|
|
2021-11-21 13:06:05 +01:00
|
|
|
std::shared_ptr<FieldOperation> fn = std::make_shared<FieldOperation>(
|
|
|
|
|
FieldOperation(std::make_unique<TwoOutputFunction>(), {index_field_1, index_field_2}));
|
2021-09-09 12:54:20 +02:00
|
|
|
|
|
|
|
|
GField result_field_1{fn, 0};
|
|
|
|
|
GField result_field_2{fn, 1};
|
|
|
|
|
|
|
|
|
|
Array<int> result_1(10);
|
|
|
|
|
Array<int> result_2(10);
|
|
|
|
|
|
|
|
|
|
const Array<int64_t> indices = {2, 4, 6, 8};
|
|
|
|
|
const IndexMask mask{indices};
|
|
|
|
|
|
|
|
|
|
FieldContext context;
|
|
|
|
|
FieldEvaluator evaluator{context, &mask};
|
|
|
|
|
evaluator.add_with_destination(result_field_1, result_1.as_mutable_span());
|
|
|
|
|
evaluator.add_with_destination(result_field_2, result_2.as_mutable_span());
|
|
|
|
|
evaluator.evaluate();
|
|
|
|
|
EXPECT_EQ(result_1[2], 4);
|
|
|
|
|
EXPECT_EQ(result_1[4], 8);
|
|
|
|
|
EXPECT_EQ(result_1[6], 12);
|
|
|
|
|
EXPECT_EQ(result_1[8], 16);
|
|
|
|
|
EXPECT_EQ(result_2[2], 14);
|
|
|
|
|
EXPECT_EQ(result_2[4], 18);
|
|
|
|
|
EXPECT_EQ(result_2[6], 22);
|
|
|
|
|
EXPECT_EQ(result_2[8], 26);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(field, TwoFunctionsTwoOutputs)
|
|
|
|
|
{
|
|
|
|
|
GField index_field{std::make_shared<IndexFieldInput>()};
|
|
|
|
|
|
2021-11-21 13:06:05 +01:00
|
|
|
std::shared_ptr<FieldOperation> fn = std::make_shared<FieldOperation>(
|
|
|
|
|
FieldOperation(std::make_unique<TwoOutputFunction>(), {index_field, index_field}));
|
2021-09-09 12:54:20 +02:00
|
|
|
|
|
|
|
|
Array<int64_t> mask_indices = {2, 4, 6, 8};
|
|
|
|
|
IndexMask mask = mask_indices.as_span();
|
|
|
|
|
|
|
|
|
|
Field<int> result_field_1{fn, 0};
|
|
|
|
|
Field<int> intermediate_field{fn, 1};
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<MultiFunction> add_10_fn = std::make_unique<CustomMF_SI_SO<int, int>>(
|
|
|
|
|
"add_10", [](int a) { return a + 10; });
|
|
|
|
|
Field<int> result_field_2{
|
|
|
|
|
std::make_shared<FieldOperation>(FieldOperation(std::move(add_10_fn), {intermediate_field})),
|
|
|
|
|
0};
|
|
|
|
|
|
|
|
|
|
FieldContext field_context;
|
|
|
|
|
FieldEvaluator field_evaluator{field_context, &mask};
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
VArray<int> result_1;
|
|
|
|
|
VArray<int> result_2;
|
2021-09-09 12:54:20 +02:00
|
|
|
field_evaluator.add(result_field_1, &result_1);
|
|
|
|
|
field_evaluator.add(result_field_2, &result_2);
|
|
|
|
|
field_evaluator.evaluate();
|
|
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
EXPECT_EQ(result_1.get(2), 4);
|
|
|
|
|
EXPECT_EQ(result_1.get(4), 8);
|
|
|
|
|
EXPECT_EQ(result_1.get(6), 12);
|
|
|
|
|
EXPECT_EQ(result_1.get(8), 16);
|
|
|
|
|
EXPECT_EQ(result_2.get(2), 24);
|
|
|
|
|
EXPECT_EQ(result_2.get(4), 28);
|
|
|
|
|
EXPECT_EQ(result_2.get(6), 32);
|
|
|
|
|
EXPECT_EQ(result_2.get(8), 36);
|
2021-09-09 12:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST(field, SameFieldTwice)
|
|
|
|
|
{
|
|
|
|
|
GField constant_field{
|
|
|
|
|
std::make_shared<FieldOperation>(std::make_unique<CustomMF_Constant<int>>(10)), 0};
|
|
|
|
|
|
|
|
|
|
FieldContext field_context;
|
|
|
|
|
IndexMask mask{IndexRange(2)};
|
|
|
|
|
ResourceScope scope;
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
Vector<GVArray> results = evaluate_fields(
|
2021-09-09 12:54:20 +02:00
|
|
|
scope, {constant_field, constant_field}, mask, field_context);
|
|
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
VArray<int> varray1 = results[0].typed<int>();
|
|
|
|
|
VArray<int> varray2 = results[1].typed<int>();
|
2021-09-09 12:54:20 +02:00
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
EXPECT_EQ(varray1.get(0), 10);
|
|
|
|
|
EXPECT_EQ(varray1.get(1), 10);
|
|
|
|
|
EXPECT_EQ(varray2.get(0), 10);
|
|
|
|
|
EXPECT_EQ(varray2.get(1), 10);
|
2021-09-09 12:54:20 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-14 14:52:44 +02:00
|
|
|
TEST(field, IgnoredOutput)
|
|
|
|
|
{
|
|
|
|
|
static OptionalOutputsFunction fn;
|
|
|
|
|
Field<int> field{std::make_shared<FieldOperation>(fn), 0};
|
|
|
|
|
|
|
|
|
|
FieldContext field_context;
|
|
|
|
|
FieldEvaluator field_evaluator{field_context, 10};
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
VArray<int> results;
|
2021-09-14 14:52:44 +02:00
|
|
|
field_evaluator.add(field, &results);
|
|
|
|
|
field_evaluator.evaluate();
|
|
|
|
|
|
Geometry Nodes: refactor virtual array system
Goals of this refactor:
* Simplify creating virtual arrays.
* Simplify passing virtual arrays around.
* Simplify converting between typed and generic virtual arrays.
* Reduce memory allocations.
As a quick reminder, a virtual arrays is a data structure that behaves like an
array (i.e. it can be accessed using an index). However, it may not actually
be stored as array internally. The two most important implementations
of virtual arrays are those that correspond to an actual plain array and those
that have the same value for every index. However, many more
implementations exist for various reasons (interfacing with legacy attributes,
unified iterator over all points in multiple splines, ...).
With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and
`GVMutableArray`) can be used like "normal values". They typically live
on the stack. Before, they were usually inside a `std::unique_ptr`. This makes
passing them around much easier. Creation of new virtual arrays is also
much simpler now due to some constructors. Memory allocations are
reduced by making use of small object optimization inside the core types.
Previously, `VArray` was a class with virtual methods that had to be overridden
to change the behavior of a the virtual array. Now,`VArray` has a fixed size
and has no virtual methods. Instead it contains a `VArrayImpl` that is
similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly,
unless a new virtual array implementation is added.
To support the small object optimization for many `VArrayImpl` classes,
a new `blender::Any` type is added. It is similar to `std::any` with two
additional features. It has an adjustable inline buffer size and alignment.
The inline buffer size of `std::any` can't be relied on and is usually too
small for our use case here. Furthermore, `blender::Any` can store
additional user-defined type information without increasing the
stack size.
Differential Revision: https://developer.blender.org/D12986
2021-11-16 10:15:51 +01:00
|
|
|
EXPECT_EQ(results.get(0), 5);
|
|
|
|
|
EXPECT_EQ(results.get(3), 5);
|
2021-09-14 14:52:44 +02:00
|
|
|
}
|
|
|
|
|
|
2021-09-09 12:54:20 +02:00
|
|
|
} // namespace blender::fn::tests
|