Functions: support optional outputs in multi-function

Sometimes not all outputs of a multi-function are required by the
caller. In those cases it would be a waste of compute resources
to calculate the unused values anyway. Now, the caller of a
multi-function can specify when a specific output is not used.
The called function can check if an output is unused and may
ignore it. Multi-functions can still computed unused outputs as
before if they don't want to check if a specific output is unused.

The multi-function procedure system has been updated to support
ignored outputs in call instructions. An ignored output just has no
variable assigned to it.

The field system has been updated to generate a multi-function
procedure where unused outputs are ignored.
This commit is contained in:
2021-09-14 14:52:44 +02:00
parent 90a48fa064
commit fd60f6713a
9 changed files with 226 additions and 27 deletions

View File

@@ -328,5 +328,32 @@ TEST(multi_function, CustomMF_Convert)
EXPECT_EQ(outputs[2], 9);
}
TEST(multi_function, IgnoredOutputs)
{
OptionalOutputsFunction fn;
{
MFParamsBuilder params(fn, 10);
params.add_ignored_single_output("Out 1");
params.add_ignored_single_output("Out 2");
MFContextBuilder context;
fn.call(IndexRange(10), params, context);
}
{
Array<int> results_1(10);
Array<std::string> results_2(10, NoInitialization());
MFParamsBuilder params(fn, 10);
params.add_uninitialized_single_output(results_1.as_mutable_span(), "Out 1");
params.add_uninitialized_single_output(results_2.as_mutable_span(), "Out 2");
MFContextBuilder context;
fn.call(IndexRange(10), params, context);
EXPECT_EQ(results_1[0], 5);
EXPECT_EQ(results_1[3], 5);
EXPECT_EQ(results_1[9], 5);
EXPECT_EQ(results_2[0], "hello, this is a long string");
}
}
} // namespace
} // namespace blender::fn::tests