diff options
author | Jacques Lucke <jacques@blender.org> | 2021-04-15 12:21:35 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-04-15 12:21:48 +0300 |
commit | 05dbbd83f00d270c00cb1a0904c504c31e1812af (patch) | |
tree | 47ca07fd617f692518a254bbf01d2e76d45cc697 /source/blender/blenkernel/intern/attribute_access.cc | |
parent | 2c3a9caffee61d52cc50a70ff9b2ec3984ee0fc5 (diff) |
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.
Diffstat (limited to 'source/blender/blenkernel/intern/attribute_access.cc')
-rw-r--r-- | source/blender/blenkernel/intern/attribute_access.cc | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/attribute_access.cc b/source/blender/blenkernel/intern/attribute_access.cc index 8542c9d35a4..ac582fc30e7 100644 --- a/source/blender/blenkernel/intern/attribute_access.cc +++ b/source/blender/blenkernel/intern/attribute_access.cc @@ -210,23 +210,25 @@ class ConvertedReadAttribute final : public ReadAttribute { const CPPType &from_type_; const CPPType &to_type_; ReadAttributePtr base_attribute_; - const nodes::DataTypeConversions &conversions_; + void (*convert_)(const void *src, void *dst); public: ConvertedReadAttribute(ReadAttributePtr base_attribute, const CPPType &to_type) : ReadAttribute(base_attribute->domain(), to_type, base_attribute->size()), from_type_(base_attribute->cpp_type()), to_type_(to_type), - base_attribute_(std::move(base_attribute)), - conversions_(nodes::get_implicit_type_conversions()) + base_attribute_(std::move(base_attribute)) { + const nodes::DataTypeConversions &conversions = nodes::get_implicit_type_conversions(); + convert_ = conversions.get_conversion_functions(base_attribute_->cpp_type(), to_type) + ->convert_single_to_uninitialized; } void get_internal(const int64_t index, void *r_value) const override { BUFFER_FOR_CPP_TYPE_VALUE(from_type_, buffer); base_attribute_->get(index, buffer); - conversions_.convert(from_type_, to_type_, buffer, r_value); + convert_(buffer, r_value); } }; @@ -989,7 +991,7 @@ blender::bke::ReadAttributePtr GeometryComponent::attribute_get_constant_for_rea BLI_assert(conversions.is_convertible(*in_cpp_type, *out_cpp_type)); void *out_value = alloca(out_cpp_type->size()); - conversions.convert(*in_cpp_type, *out_cpp_type, value, out_value); + conversions.convert_to_uninitialized(*in_cpp_type, *out_cpp_type, value, out_value); const int domain_size = this->attribute_domain_size(domain); blender::bke::ReadAttributePtr attribute = std::make_unique<blender::bke::ConstantReadAttribute>( |