Changeset View
Changeset View
Standalone View
Standalone View
source/blender/nodes/NOD_geometry_exec.hh
| Show First 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | |||||
| using fn::GMutablePointer; | using fn::GMutablePointer; | ||||
| using fn::GMutableSpan; | using fn::GMutableSpan; | ||||
| using fn::GPointer; | using fn::GPointer; | ||||
| using fn::GSpan; | using fn::GSpan; | ||||
| using fn::GVArray; | using fn::GVArray; | ||||
| using fn::GVArray_GSpan; | using fn::GVArray_GSpan; | ||||
| using fn::GVMutableArray; | using fn::GVMutableArray; | ||||
| using fn::GVMutableArray_GSpan; | using fn::GVMutableArray_GSpan; | ||||
| using fn::ValueOrField; | |||||
| using geometry_nodes_eval_log::NodeWarningType; | using geometry_nodes_eval_log::NodeWarningType; | ||||
| /** | /** | ||||
| * This class exists to separate the memory management details of the geometry nodes evaluator | * This class exists to separate the memory management details of the geometry nodes evaluator | ||||
| * from the node execution functions and related utilities. | * from the node execution functions and related utilities. | ||||
| */ | */ | ||||
| class GeoNodeExecParamsProvider { | class GeoNodeExecParamsProvider { | ||||
| public: | public: | ||||
| ▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | private: | ||||
| GeoNodeExecParamsProvider *provider_; | GeoNodeExecParamsProvider *provider_; | ||||
| public: | public: | ||||
| GeoNodeExecParams(GeoNodeExecParamsProvider &provider) : provider_(&provider) | GeoNodeExecParams(GeoNodeExecParamsProvider &provider) : provider_(&provider) | ||||
| { | { | ||||
| } | } | ||||
| template<typename T> | template<typename T> | ||||
| static inline constexpr bool is_stored_as_field_v = std::is_same_v<T, float> || | static inline constexpr bool is_field_base_type_v = std::is_same_v<T, float> || | ||||
| std::is_same_v<T, int> || | std::is_same_v<T, int> || | ||||
| std::is_same_v<T, bool> || | std::is_same_v<T, bool> || | ||||
| std::is_same_v<T, ColorGeometry4f> || | std::is_same_v<T, ColorGeometry4f> || | ||||
| std::is_same_v<T, float3> || | std::is_same_v<T, float3> || | ||||
| std::is_same_v<T, std::string>; | std::is_same_v<T, std::string>; | ||||
| /** | /** | ||||
| * Get the input value for the input socket with the given identifier. | * Get the input value for the input socket with the given identifier. | ||||
| Show All 11 Lines | #endif | ||||
| /** | /** | ||||
| * Get the input value for the input socket with the given identifier. | * Get the input value for the input socket with the given identifier. | ||||
| * | * | ||||
| * This method can only be called once for each identifier. | * This method can only be called once for each identifier. | ||||
| */ | */ | ||||
| template<typename T> T extract_input(StringRef identifier) | template<typename T> T extract_input(StringRef identifier) | ||||
| { | { | ||||
| if constexpr (is_stored_as_field_v<T>) { | if constexpr (is_field_base_type_v<T>) { | ||||
| Field<T> field = this->extract_input<Field<T>>(identifier); | ValueOrField<T> value_or_field = this->extract_input<ValueOrField<T>>(identifier); | ||||
| return fn::evaluate_constant_field(field); | return value_or_field.as_value(); | ||||
| } | |||||
| else if constexpr (fn::is_field_v<T>) { | |||||
| using BaseType = typename T::base_type; | |||||
| ValueOrField<BaseType> value_or_field = this->extract_input<ValueOrField<BaseType>>( | |||||
| identifier); | |||||
| return value_or_field.as_field(); | |||||
| } | } | ||||
| else { | else { | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| this->check_input_access(identifier, &CPPType::get<T>()); | this->check_input_access(identifier, &CPPType::get<T>()); | ||||
| #endif | #endif | ||||
| GMutablePointer gvalue = this->extract_input(identifier); | GMutablePointer gvalue = this->extract_input(identifier); | ||||
| T value = gvalue.relocate_out<T>(); | T value = gvalue.relocate_out<T>(); | ||||
| if constexpr (std::is_same_v<T, GeometrySet>) { | if constexpr (std::is_same_v<T, GeometrySet>) { | ||||
| Show All 10 Lines | #endif | ||||
| * | * | ||||
| * This method can only be called once for each identifier. | * This method can only be called once for each identifier. | ||||
| */ | */ | ||||
| template<typename T> Vector<T> extract_multi_input(StringRef identifier) | template<typename T> Vector<T> extract_multi_input(StringRef identifier) | ||||
| { | { | ||||
| Vector<GMutablePointer> gvalues = provider_->extract_multi_input(identifier); | Vector<GMutablePointer> gvalues = provider_->extract_multi_input(identifier); | ||||
| Vector<T> values; | Vector<T> values; | ||||
| for (GMutablePointer gvalue : gvalues) { | for (GMutablePointer gvalue : gvalues) { | ||||
| if constexpr (is_stored_as_field_v<T>) { | if constexpr (is_field_base_type_v<T>) { | ||||
| const Field<T> field = gvalue.relocate_out<Field<T>>(); | const ValueOrField<T> value_or_field = gvalue.relocate_out<ValueOrField<T>>(); | ||||
| values.append(fn::evaluate_constant_field(field)); | values.append(value_or_field.as_value()); | ||||
| } | } | ||||
| else { | else { | ||||
| values.append(gvalue.relocate_out<T>()); | values.append(gvalue.relocate_out<T>()); | ||||
| } | } | ||||
| } | } | ||||
| return values; | return values; | ||||
| } | } | ||||
| /** | /** | ||||
| * Get the input value for the input socket with the given identifier. | * Get the input value for the input socket with the given identifier. | ||||
| */ | */ | ||||
| template<typename T> const T get_input(StringRef identifier) const | template<typename T> T get_input(StringRef identifier) const | ||||
| { | { | ||||
| if constexpr (is_stored_as_field_v<T>) { | if constexpr (is_field_base_type_v<T>) { | ||||
| const Field<T> &field = this->get_input<Field<T>>(identifier); | ValueOrField<T> value_or_field = this->get_input<ValueOrField<T>>(identifier); | ||||
| return fn::evaluate_constant_field(field); | return value_or_field.as_value(); | ||||
| } | |||||
| else if constexpr (fn::is_field_v<T>) { | |||||
| using BaseType = typename T::base_type; | |||||
| ValueOrField<BaseType> value_or_field = this->get_input<ValueOrField<BaseType>>(identifier); | |||||
| return value_or_field.as_field(); | |||||
| } | } | ||||
| else { | else { | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| this->check_input_access(identifier, &CPPType::get<T>()); | this->check_input_access(identifier, &CPPType::get<T>()); | ||||
| #endif | #endif | ||||
| GPointer gvalue = provider_->get_input(identifier); | GPointer gvalue = provider_->get_input(identifier); | ||||
| BLI_assert(gvalue.is_type<T>()); | BLI_assert(gvalue.is_type<T>()); | ||||
| const T &value = *(const T *)gvalue.get(); | const T &value = *(const T *)gvalue.get(); | ||||
| if constexpr (std::is_same_v<T, GeometrySet>) { | if constexpr (std::is_same_v<T, GeometrySet>) { | ||||
| this->check_input_geometry_set(identifier, value); | this->check_input_geometry_set(identifier, value); | ||||
| } | } | ||||
| return value; | return value; | ||||
| } | } | ||||
| } | } | ||||
| /** | /** | ||||
| * Store the output value for the given socket identifier. | * Store the output value for the given socket identifier. | ||||
| */ | */ | ||||
| template<typename T> void set_output(StringRef identifier, T &&value) | template<typename T> void set_output(StringRef identifier, T &&value) | ||||
| { | { | ||||
| using StoredT = std::decay_t<T>; | using StoredT = std::decay_t<T>; | ||||
| if constexpr (is_stored_as_field_v<StoredT>) { | if constexpr (is_field_base_type_v<StoredT>) { | ||||
| this->set_output<Field<StoredT>>(identifier, | this->set_output(identifier, ValueOrField<StoredT>(std::forward<T>(value))); | ||||
| fn::make_constant_field<StoredT>(std::forward<T>(value))); | } | ||||
| else if constexpr (fn::is_field_v<StoredT>) { | |||||
| using BaseType = typename StoredT::base_type; | |||||
| this->set_output(identifier, ValueOrField<BaseType>(std::forward<T>(value))); | |||||
| } | } | ||||
| else { | else { | ||||
| const CPPType &type = CPPType::get<StoredT>(); | const CPPType &type = CPPType::get<StoredT>(); | ||||
| #ifdef DEBUG | #ifdef DEBUG | ||||
| this->check_output_access(identifier, type); | this->check_output_access(identifier, type); | ||||
| #endif | #endif | ||||
| GMutablePointer gvalue = provider_->alloc_output_value(type); | GMutablePointer gvalue = provider_->alloc_output_value(type); | ||||
| new (gvalue.get()) StoredT(std::forward<T>(value)); | new (gvalue.get()) StoredT(std::forward<T>(value)); | ||||
| ▲ Show 20 Lines • Show All 115 Lines • Show Last 20 Lines | |||||