Commit: 5f003515a189cfed3f47347ae3184adcc8c1f6cf Author: Hans Goudey Date: Mon Aug 30 15:25:04 2021 -0500 Branches: temp-geometry-nodes-fields--fields https://developer.blender.org/rB5f003515a189cfed3f47347ae3184adcc8c1f6cf
Add a new (failing) test and some comments =================================================================== M source/blender/functions/tests/FN_field_test.cc =================================================================== diff --git a/source/blender/functions/tests/FN_field_test.cc b/source/blender/functions/tests/FN_field_test.cc index 5db878d32b3..58be8e7d335 100644 --- a/source/blender/functions/tests/FN_field_test.cc +++ b/source/blender/functions/tests/FN_field_test.cc @@ -10,6 +10,7 @@ namespace blender::fn::tests { TEST(field, ConstantFunction) { + /* TODO: Figure out how to not use another "FieldFunction(" inside of std::make_shared. */ Field constant_field{CPPType::get<int>(), std::make_shared<FieldFunction>( FieldFunction(std::make_unique<CustomMF_Constant<int>>(10), {})), @@ -26,7 +27,8 @@ TEST(field, ConstantFunction) } class IndexFieldInput final : public FieldInput { - StringRef name_ = "Index"; /* TODO: I don't think this is a valid way to override the name. */ + /* TODO: I don't think this is a valid way to override the name, but I wish it was. */ + StringRef name_ = "Index"; GVArrayPtr retrieve_data(IndexMask mask) const final { auto index_func = [](int i) { return i; }; @@ -127,4 +129,61 @@ TEST(field, TwoFunctions) EXPECT_EQ(result[8], 26); } +class TwoOutputFunction : public MultiFunction { + private: + MFSignature signature_; + + public: + TwoOutputFunction(StringRef name) + { + MFSignatureBuilder signature{name}; + 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); + const VArray<int> &in2 = params.readonly_single_input<int>(1); + MutableSpan<int> add = params.uninitialized_single_output<int>(2); + MutableSpan<int> add_10 = params.uninitialized_single_output<int>(2); + 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. */ + Field index_field_1{CPPType::get<int>(), std::make_shared<IndexFieldInput>()}; + Field index_field_2{CPPType::get<int>(), std::make_shared<IndexFieldInput>()}; + + std::shared_ptr<FieldFunction> fn = std::make_shared<FieldFunction>(FieldFunction( + std::make_unique<TwoOutputFunction>("SI_SI_SO_SO"), {index_field_1, index_field_2})); + + Field result_field_1{CPPType::get<int>(), fn, 0}; + Field result_field_2{CPPType::get<int>(), fn, 1}; + + 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()); + evaluate_fields( + {result_field_1, result_field_2}, {2, 4, 6, 8}, {result_generic_1, result_generic_2}); + 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); +} + } // namespace blender::fn::tests _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs