From 05dbbd83f00d270c00cb1a0904c504c31e1812af Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 15 Apr 2021 11:21:35 +0200 Subject: Geometry Nodes: refactor implicit conversions This refactor simplifies having standalone function pointer that does a single conversion. It also speeds up implicit type conversion of attributes. --- source/blender/nodes/NOD_type_conversions.hh | 43 ++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 9 deletions(-) (limited to 'source/blender/nodes/NOD_type_conversions.hh') diff --git a/source/blender/nodes/NOD_type_conversions.hh b/source/blender/nodes/NOD_type_conversions.hh index e23fddab58b..34225208fe6 100644 --- a/source/blender/nodes/NOD_type_conversions.hh +++ b/source/blender/nodes/NOD_type_conversions.hh @@ -21,20 +21,45 @@ namespace blender::nodes { using fn::CPPType; +using fn::GVArray; + +struct ConversionFunctions { + const fn::MultiFunction *multi_function; + void (*convert_single_to_initialized)(const void *src, void *dst); + void (*convert_single_to_uninitialized)(const void *src, void *dst); +}; class DataTypeConversions { private: - Map, const fn::MultiFunction *> conversions_; + Map, ConversionFunctions> conversions_; public: - void add(fn::MFDataType from_type, fn::MFDataType to_type, const fn::MultiFunction &fn) + void add(fn::MFDataType from_type, + fn::MFDataType to_type, + const fn::MultiFunction &fn, + void (*convert_single_to_initialized)(const void *src, void *dst), + void (*convert_single_to_uninitialized)(const void *src, void *dst)) + { + conversions_.add_new({from_type, to_type}, + {&fn, convert_single_to_initialized, convert_single_to_uninitialized}); + } + + const ConversionFunctions *get_conversion_functions(fn::MFDataType from, fn::MFDataType to) const + { + return conversions_.lookup_ptr({from, to}); + } + + const ConversionFunctions *get_conversion_functions(const CPPType &from, const CPPType &to) const { - conversions_.add_new({from_type, to_type}, &fn); + return this->get_conversion_functions(fn::MFDataType::ForSingle(from), + fn::MFDataType::ForSingle(to)); } - const fn::MultiFunction *get_conversion(fn::MFDataType from, fn::MFDataType to) const + const fn::MultiFunction *get_conversion_multi_function(fn::MFDataType from, + fn::MFDataType to) const { - return conversions_.lookup_default({from, to}, nullptr); + const ConversionFunctions *functions = this->get_conversion_functions(from, to); + return functions ? functions->multi_function : nullptr; } bool is_convertible(const CPPType &from_type, const CPPType &to_type) const @@ -43,10 +68,10 @@ class DataTypeConversions { {fn::MFDataType::ForSingle(from_type), fn::MFDataType::ForSingle(to_type)}); } - void convert(const CPPType &from_type, - const CPPType &to_type, - const void *from_value, - void *to_value) const; + void convert_to_uninitialized(const CPPType &from_type, + const CPPType &to_type, + const void *from_value, + void *to_value) const; }; const DataTypeConversions &get_implicit_type_conversions(); -- cgit v1.2.3