diff options
author | Hans Goudey <h.goudey@me.com> | 2021-09-06 20:24:17 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-09-06 20:24:17 +0300 |
commit | 64d1fe34502ea7fb33a95b0d55bc2b52aba12184 (patch) | |
tree | 135eed320e84de59b58e580ece37a518a5a2606e | |
parent | e70f9b0d0eb9e7e55310741a08a1d2002963b829 (diff) |
Update field tests for the newer API
-rw-r--r-- | source/blender/functions/FN_field.hh | 12 | ||||
-rw-r--r-- | source/blender/functions/intern/field.cc | 20 | ||||
-rw-r--r-- | source/blender/functions/tests/FN_field_test.cc | 79 |
3 files changed, 56 insertions, 55 deletions
diff --git a/source/blender/functions/FN_field.hh b/source/blender/functions/FN_field.hh index 56bd9a43356..5b12e662f55 100644 --- a/source/blender/functions/FN_field.hh +++ b/source/blender/functions/FN_field.hh @@ -366,10 +366,9 @@ class FieldEvaluator : NonMovable, NonCopyable { */ template<typename T> int add_with_destination(Field<T> field, MutableSpan<T> dst) { - const int field_index = fields_to_evaluate_.append_and_get_index(std::move(field)); - dst_hints_.append(&scope_.construct<GVMutableArray_For_MutableSpan<T>>(__func__, dst)); - output_pointer_infos_.append({}); - return field_index; + GVMutableArray &generic_dst_hint = scope_.construct<GVMutableArray_For_MutableSpan<T>>( + __func__, dst); + return this->add_with_destination(std::move(field), generic_dst_hint); } int add(GField field, const GVArray **varray_ptr); @@ -434,11 +433,6 @@ Vector<const GVArray *> evaluate_fields(ResourceScope &scope, void evaluate_constant_field(const GField &field, void *r_value); -void evaluate_fields_to_spans(Span<GFieldRef> fields_to_evaluate, - IndexMask mask, - const FieldContext &context, - Span<GMutableSpan> out_spans); - template<typename T> T evaluate_constant_field(const Field<T> &field) { T value; diff --git a/source/blender/functions/intern/field.cc b/source/blender/functions/intern/field.cc index 042a12259c8..a27c5e4e3dc 100644 --- a/source/blender/functions/intern/field.cc +++ b/source/blender/functions/intern/field.cc @@ -462,19 +462,6 @@ void evaluate_constant_field(const GField &field, void *r_value) varrays[0]->get_to_uninitialized(0, r_value); } -void evaluate_fields_to_spans(Span<GFieldRef> fields_to_evaluate, - IndexMask mask, - const FieldContext &context, - Span<GMutableSpan> out_spans) -{ - ResourceScope scope; - Vector<GVMutableArray *> varrays; - for (GMutableSpan span : out_spans) { - varrays.append(&scope.construct<GVMutableArray_For_GMutableSpan>(__func__, span)); - } - evaluate_fields(scope, fields_to_evaluate, mask, context, varrays); -} - const GVArray *FieldContext::get_varray_for_input(const FieldInput &field_input, IndexMask mask, ResourceScope &scope) const @@ -522,10 +509,9 @@ int FieldEvaluator::add_with_destination(GField field, GVMutableArray &dst) int FieldEvaluator::add_with_destination(GField field, GMutableSpan dst) { - const int field_index = fields_to_evaluate_.append_and_get_index(std::move(field)); - dst_hints_.append(&scope_.construct<GVMutableArray_For_GMutableSpan>(__func__, dst)); - output_pointer_infos_.append({}); - return field_index; + GVMutableArray &varray_dst_hint = scope_.construct<GVMutableArray_For_GMutableSpan>(__func__, + dst); + return this->add_with_destination(std::move(field), varray_dst_hint); } int FieldEvaluator::add(GField field, const GVArray **varray_ptr) diff --git a/source/blender/functions/tests/FN_field_test.cc b/source/blender/functions/tests/FN_field_test.cc index 81529c988c6..212b79e75d3 100644 --- a/source/blender/functions/tests/FN_field_test.cc +++ b/source/blender/functions/tests/FN_field_test.cc @@ -16,11 +16,11 @@ TEST(field, ConstantFunction) 0}; Array<int> result(4); - GMutableSpan result_generic(result.as_mutable_span()); - FieldContext field_context; - evaluate_fields_to_spans( - {constant_field}, IndexMask(IndexRange(4)), field_context, {result_generic}); + 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); @@ -49,10 +49,11 @@ TEST(field, VArrayInput) GField index_field{std::make_shared<IndexFieldInput>()}; Array<int> result_1(4); - GMutableSpan result_generic_1(result_1.as_mutable_span()); - FieldContext field_context; - evaluate_fields_to_spans( - {index_field}, IndexMask(IndexRange(4)), field_context, {result_generic_1}); + + 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); @@ -60,8 +61,13 @@ TEST(field, VArrayInput) /* Evaluate a second time, just to test that the first didn't break anything. */ Array<int> result_2(10); - GMutableSpan result_generic_2(result_2.as_mutable_span()); - evaluate_fields_to_spans({index_field}, {2, 4, 6, 8}, field_context, {result_generic_2}); + + 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); @@ -76,12 +82,15 @@ TEST(field, VArrayInputMultipleOutputs) Array<int> result_1(10); Array<int> result_2(10); - GMutableSpan result_generic_1(result_1.as_mutable_span()); - GMutableSpan result_generic_2(result_2.as_mutable_span()); - FieldContext field_context; - evaluate_fields_to_spans( - {field_1, field_2}, {2, 4, 6, 8}, field_context, {result_generic_1, result_generic_2}); + 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); @@ -103,9 +112,14 @@ TEST(field, InputAndFunction) 0}; Array<int> result(10); - GMutableSpan result_generic(result.as_mutable_span()); - FieldContext field_context; - evaluate_fields_to_spans({output_field}, {2, 4, 6, 8}, field_context, {result_generic}); + + 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); @@ -128,9 +142,14 @@ TEST(field, TwoFunctions) std::make_shared<FieldOperation>(FieldOperation(std::move(add_10_fn), {add_field})), 0}; Array<int> result(10); - GMutableSpan result_generic(result.as_mutable_span()); - FieldContext field_context; - evaluate_fields_to_spans({result_field}, {2, 4, 6, 8}, field_context, {result_generic}); + + 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); @@ -180,13 +199,15 @@ TEST(field, FunctionTwoOutputs) Array<int> result_1(10); Array<int> result_2(10); - GMutableSpan result_generic_1(result_1.as_mutable_span()); - GMutableSpan result_generic_2(result_2.as_mutable_span()); - FieldContext field_context; - evaluate_fields_to_spans({result_field_1, result_field_2}, - {2, 4, 6, 8}, - field_context, - {result_generic_1, result_generic_2}); + + 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); @@ -204,7 +225,7 @@ TEST(field, TwoFunctionsTwoOutputs) std::shared_ptr<FieldOperation> fn = std::make_shared<FieldOperation>(FieldOperation( std::make_unique<TwoOutputFunction>("SI_SI_SO_SO"), {index_field, index_field})); - Vector<int64_t> mask_indices = {2, 4, 6, 8}; + Array<int64_t> mask_indices = {2, 4, 6, 8}; IndexMask mask = mask_indices.as_span(); Field<int> result_field_1{fn, 0}; |