This refactors `SocketValueVariant` with the following goals in mind: * Support type erasure so that not all users of `SocketValueVariant` have to know about all the types sockets can have. * Move towards supporting "rainbow sockets" which are sockets whoose type is only known at run-time. * Reduce complexity when dealing with socket values in general. Previously, one had to use `SocketValueVariantCPPType` a lot to manage uninitialized memory. This is better abstracted away now. One related change that I had to do that I didn't see coming at first was that I had to refactor `set_default_remaining_outputs` because now the default value of a `SocketValueVariant` would not contain any value. Previously, it was initialized the zero-value of the template parameter. Similarly, I had to change how implicit conversions are created, because comparing the `CPPType` of linked sockets was not enough anymore to determine if a conversion is necessary. We could potentially use `SocketValueVariant` for the remaining socket types in the future as well. Not entirely sure if that helps yet. `SocketValueVariant` can easily be adapted to make that work though. That would also justify the name "SocketValueVariant" better. Pull Request: https://projects.blender.org/blender/blender/pulls/116231
79 lines
1.6 KiB
C++
79 lines
1.6 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/** \file
|
|
* \ingroup fn
|
|
*/
|
|
|
|
#include "BLI_array.hh"
|
|
|
|
#include "FN_lazy_function.hh"
|
|
|
|
namespace blender::fn::lazy_function {
|
|
|
|
std::string LazyFunction::name() const
|
|
{
|
|
return debug_name_;
|
|
}
|
|
|
|
std::string LazyFunction::input_name(int index) const
|
|
{
|
|
return inputs_[index].debug_name;
|
|
}
|
|
|
|
std::string LazyFunction::output_name(int index) const
|
|
{
|
|
return outputs_[index].debug_name;
|
|
}
|
|
|
|
void *LazyFunction::init_storage(LinearAllocator<> & /*allocator*/) const
|
|
{
|
|
return nullptr;
|
|
}
|
|
|
|
void LazyFunction::destruct_storage(void *storage) const
|
|
{
|
|
BLI_assert(storage == nullptr);
|
|
UNUSED_VARS_NDEBUG(storage);
|
|
}
|
|
|
|
void LazyFunction::possible_output_dependencies(const int /*output_index*/,
|
|
const FunctionRef<void(Span<int>)> fn) const
|
|
{
|
|
/* The output depends on all inputs by default. */
|
|
Vector<int, 16> indices(inputs_.size());
|
|
for (const int i : inputs_.index_range()) {
|
|
indices[i] = i;
|
|
}
|
|
fn(indices);
|
|
}
|
|
|
|
bool LazyFunction::always_used_inputs_available(const Params ¶ms) const
|
|
{
|
|
if (allow_missing_requested_inputs_) {
|
|
return true;
|
|
}
|
|
for (const int i : inputs_.index_range()) {
|
|
const Input &fn_input = inputs_[i];
|
|
if (fn_input.usage == ValueUsage::Used) {
|
|
if (params.try_get_input_data_ptr(i) == nullptr) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool Params::try_enable_multi_threading_impl()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
destruct_ptr<LocalUserData> UserData::get_local(LinearAllocator<> & /*allocator*/)
|
|
{
|
|
return {};
|
|
}
|
|
|
|
} // namespace blender::fn::lazy_function
|