From ed1042ee060caf5132822b947cac768f90b5ba12 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 13 Jan 2021 12:27:16 +0100 Subject: Geometry Nodes: cleanup attribute usage Now that typed attribute wrappers don't need to own the attribute anymore, many `std::move` calls can be removed. --- .../nodes/node_geo_attribute_color_ramp.cc | 6 +- .../geometry/nodes/node_geo_attribute_compare.cc | 108 ++++++++------------- .../geometry/nodes/node_geo_attribute_fill.cc | 20 ++-- .../geometry/nodes/node_geo_attribute_math.cc | 3 +- .../nodes/geometry/nodes/node_geo_attribute_mix.cc | 48 +++------ .../geometry/nodes/node_geo_attribute_randomize.cc | 23 ++--- .../nodes/node_geo_attribute_vector_math.cc | 20 ++-- .../geometry/nodes/node_geo_point_separate.cc | 15 ++- 8 files changed, 92 insertions(+), 151 deletions(-) (limited to 'source/blender/nodes') diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc index 7d49253c6a3..5d126328988 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc @@ -51,21 +51,19 @@ static void execute_on_component(const GeoNodeExecParams ¶ms, GeometryCompon return; } - Color4fWriteAttribute attribute_out = std::move(attribute_result); - const std::string input_name = params.get_input("Attribute"); FloatReadAttribute attribute_in = component.attribute_get_for_read( input_name, result_domain, 0.0f); Span data_in = attribute_in.get_span(); - MutableSpan data_out = attribute_out.get_span_for_write_only(); + MutableSpan data_out = attribute_result->get_span_for_write_only(); ColorBand *color_ramp = &node_storage->color_ramp; for (const int i : data_in.index_range()) { BKE_colorband_evaluate(color_ramp, data_in[i], data_out[i]); } - attribute_out.apply_span(); + attribute_result->apply_span(); } static void geo_node_attribute_color_ramp_exec(GeoNodeExecParams params) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc index 5d6e2412a3d..8ea88e7153d 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc @@ -103,10 +103,10 @@ static void do_math_operation(const FloatReadAttribute &input_a, BLI_assert(false); } -static void do_equal_operation(const FloatReadAttribute &input_a, - const FloatReadAttribute &input_b, - const float threshold, - MutableSpan span_result) +static void do_equal_operation_float(const FloatReadAttribute &input_a, + const FloatReadAttribute &input_b, + const float threshold, + MutableSpan span_result) { const int size = input_a.size(); for (const int i : IndexRange(size)) { @@ -116,10 +116,10 @@ static void do_equal_operation(const FloatReadAttribute &input_a, } } -static void do_equal_operation(const Float3ReadAttribute &input_a, - const Float3ReadAttribute &input_b, - const float threshold, - MutableSpan span_result) +static void do_equal_operation_float3(const Float3ReadAttribute &input_a, + const Float3ReadAttribute &input_b, + const float threshold, + MutableSpan span_result) { const float threshold_squared = pow2f(threshold); const int size = input_a.size(); @@ -130,10 +130,10 @@ static void do_equal_operation(const Float3ReadAttribute &input_a, } } -static void do_equal_operation(const Color4fReadAttribute &input_a, - const Color4fReadAttribute &input_b, - const float threshold, - MutableSpan span_result) +static void do_equal_operation_color4f(const Color4fReadAttribute &input_a, + const Color4fReadAttribute &input_b, + const float threshold, + MutableSpan span_result) { const float threshold_squared = pow2f(threshold); const int size = input_a.size(); @@ -144,10 +144,10 @@ static void do_equal_operation(const Color4fReadAttribute &input_a, } } -static void do_equal_operation(const BooleanReadAttribute &input_a, - const BooleanReadAttribute &input_b, - const float UNUSED(threshold), - MutableSpan span_result) +static void do_equal_operation_bool(const BooleanReadAttribute &input_a, + const BooleanReadAttribute &input_b, + const float UNUSED(threshold), + MutableSpan span_result) { const int size = input_a.size(); for (const int i : IndexRange(size)) { @@ -157,10 +157,10 @@ static void do_equal_operation(const BooleanReadAttribute &input_a, } } -static void do_not_equal_operation(const FloatReadAttribute &input_a, - const FloatReadAttribute &input_b, - const float threshold, - MutableSpan span_result) +static void do_not_equal_operation_float(const FloatReadAttribute &input_a, + const FloatReadAttribute &input_b, + const float threshold, + MutableSpan span_result) { const int size = input_a.size(); for (const int i : IndexRange(size)) { @@ -170,10 +170,10 @@ static void do_not_equal_operation(const FloatReadAttribute &input_a, } } -static void do_not_equal_operation(const Float3ReadAttribute &input_a, - const Float3ReadAttribute &input_b, - const float threshold, - MutableSpan span_result) +static void do_not_equal_operation_float3(const Float3ReadAttribute &input_a, + const Float3ReadAttribute &input_b, + const float threshold, + MutableSpan span_result) { const float threshold_squared = pow2f(threshold); const int size = input_a.size(); @@ -184,10 +184,10 @@ static void do_not_equal_operation(const Float3ReadAttribute &input_a, } } -static void do_not_equal_operation(const Color4fReadAttribute &input_a, - const Color4fReadAttribute &input_b, - const float threshold, - MutableSpan span_result) +static void do_not_equal_operation_color4f(const Color4fReadAttribute &input_a, + const Color4fReadAttribute &input_b, + const float threshold, + MutableSpan span_result) { const float threshold_squared = pow2f(threshold); const int size = input_a.size(); @@ -198,10 +198,10 @@ static void do_not_equal_operation(const Color4fReadAttribute &input_a, } } -static void do_not_equal_operation(const BooleanReadAttribute &input_a, - const BooleanReadAttribute &input_b, - const float UNUSED(threshold), - MutableSpan span_result) +static void do_not_equal_operation_bool(const BooleanReadAttribute &input_a, + const BooleanReadAttribute &input_b, + const float UNUSED(threshold), + MutableSpan span_result) { const int size = input_a.size(); for (const int i : IndexRange(size)) { @@ -260,7 +260,7 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx return; } - BooleanWriteAttribute attribute_result_bool = std::move(attribute_result); + BooleanWriteAttribute attribute_result_bool = *attribute_result; MutableSpan result_span = attribute_result_bool.get_span_for_write_only(); /* Use specific types for correct equality operations, but for other operations we use implicit @@ -269,59 +269,35 @@ static void attribute_compare_calc(GeometryComponent &component, const GeoNodeEx const float threshold = params.get_input("Threshold"); if (operation == NODE_FLOAT_COMPARE_EQUAL) { if (input_data_type == CD_PROP_FLOAT) { - FloatReadAttribute attribute_a_float = std::move(attribute_a); - FloatReadAttribute attribute_b_float = std::move(attribute_b); - do_equal_operation( - std::move(attribute_a_float), std::move(attribute_b_float), threshold, result_span); + do_equal_operation_float(*attribute_a, *attribute_b, threshold, result_span); } else if (input_data_type == CD_PROP_FLOAT3) { - Float3ReadAttribute attribute_a_float3 = std::move(attribute_a); - Float3ReadAttribute attribute_b_float3 = std::move(attribute_b); - do_equal_operation( - std::move(attribute_a_float3), std::move(attribute_b_float3), threshold, result_span); + do_equal_operation_float3(*attribute_a, *attribute_b, threshold, result_span); } else if (input_data_type == CD_PROP_COLOR) { - Color4fReadAttribute attribute_a_color = std::move(attribute_a); - Color4fReadAttribute attribute_b_color = std::move(attribute_b); - do_equal_operation( - std::move(attribute_a_color), std::move(attribute_b_color), threshold, result_span); + do_equal_operation_color4f(*attribute_a, *attribute_b, threshold, result_span); } else if (input_data_type == CD_PROP_BOOL) { - BooleanReadAttribute attribute_a_bool = std::move(attribute_a); - BooleanReadAttribute attribute_b_bool = std::move(attribute_b); - do_equal_operation( - std::move(attribute_a_bool), std::move(attribute_b_bool), threshold, result_span); + do_equal_operation_bool(*attribute_a, *attribute_b, threshold, result_span); } } else if (operation == NODE_FLOAT_COMPARE_NOT_EQUAL) { if (input_data_type == CD_PROP_FLOAT) { - FloatReadAttribute attribute_a_float = std::move(attribute_a); - FloatReadAttribute attribute_b_float = std::move(attribute_b); - do_not_equal_operation( - std::move(attribute_a_float), std::move(attribute_b_float), threshold, result_span); + do_not_equal_operation_float(*attribute_a, *attribute_b, threshold, result_span); } else if (input_data_type == CD_PROP_FLOAT3) { - Float3ReadAttribute attribute_a_float3 = std::move(attribute_a); - Float3ReadAttribute attribute_b_float3 = std::move(attribute_b); - do_not_equal_operation( - std::move(attribute_a_float3), std::move(attribute_b_float3), threshold, result_span); + do_not_equal_operation_float3(*attribute_a, *attribute_b, threshold, result_span); } else if (input_data_type == CD_PROP_COLOR) { - Color4fReadAttribute attribute_a_color = std::move(attribute_a); - Color4fReadAttribute attribute_b_color = std::move(attribute_b); - do_not_equal_operation( - std::move(attribute_a_color), std::move(attribute_b_color), threshold, result_span); + do_not_equal_operation_color4f(*attribute_a, *attribute_b, threshold, result_span); } else if (input_data_type == CD_PROP_BOOL) { - BooleanReadAttribute attribute_a_bool = std::move(attribute_a); - BooleanReadAttribute attribute_b_bool = std::move(attribute_b); - do_not_equal_operation( - std::move(attribute_a_bool), std::move(attribute_b_bool), threshold, result_span); + do_not_equal_operation_bool(*attribute_a, *attribute_b, threshold, result_span); } } } else { - do_math_operation(std::move(attribute_a), std::move(attribute_b), operation, result_span); + do_math_operation(*attribute_a, *attribute_b, operation, result_span); } attribute_result_bool.apply_span(); diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc index 27349fc38f2..96685196917 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc @@ -76,35 +76,31 @@ static void fill_attribute(GeometryComponent &component, const GeoNodeExecParams switch (data_type) { case CD_PROP_FLOAT: { - FloatWriteAttribute float_attribute = std::move(attribute); const float value = params.get_input("Value_001"); - MutableSpan attribute_span = float_attribute.get_span_for_write_only(); + MutableSpan attribute_span = attribute->get_span_for_write_only(); attribute_span.fill(value); - float_attribute.apply_span(); + attribute->apply_span(); break; } case CD_PROP_FLOAT3: { - Float3WriteAttribute float3_attribute = std::move(attribute); const float3 value = params.get_input("Value"); - MutableSpan attribute_span = float3_attribute.get_span_for_write_only(); + MutableSpan attribute_span = attribute->get_span_for_write_only(); attribute_span.fill(value); - float3_attribute.apply_span(); + attribute->apply_span(); break; } case CD_PROP_COLOR: { - Color4fWriteAttribute color4f_attribute = std::move(attribute); const Color4f value = params.get_input("Value_002"); - MutableSpan attribute_span = color4f_attribute.get_span_for_write_only(); + MutableSpan attribute_span = attribute->get_span_for_write_only(); attribute_span.fill(value); - color4f_attribute.apply_span(); + attribute->apply_span(); break; } case CD_PROP_BOOL: { - BooleanWriteAttribute boolean_attribute = std::move(attribute); const bool value = params.get_input("Value_003"); - MutableSpan attribute_span = boolean_attribute.get_span_for_write_only(); + MutableSpan attribute_span = attribute->get_span_for_write_only(); attribute_span.fill(value); - boolean_attribute.apply_span(); + attribute->apply_span(); break; } default: diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc index 8e7d7bc324b..6e3b34f702a 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc @@ -122,8 +122,7 @@ static void attribute_math_calc(GeometryComponent &component, const GeoNodeExecP return; } - do_math_operation( - std::move(attribute_a), std::move(attribute_b), std::move(attribute_result), operation); + do_math_operation(*attribute_a, *attribute_b, *attribute_result, operation); } static void geo_node_attribute_math_exec(GeoNodeExecParams params) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc index 9a780e1212b..4d8645b3b25 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc @@ -47,7 +47,7 @@ static void do_mix_operation_float(const int blend_mode, const FloatReadAttribute &factors, const FloatReadAttribute &inputs_a, const FloatReadAttribute &inputs_b, - FloatWriteAttribute &results) + FloatWriteAttribute results) { const int size = results.size(); for (const int i : IndexRange(size)) { @@ -64,7 +64,7 @@ static void do_mix_operation_float3(const int blend_mode, const FloatReadAttribute &factors, const Float3ReadAttribute &inputs_a, const Float3ReadAttribute &inputs_b, - Float3WriteAttribute &results) + Float3WriteAttribute results) { const int size = results.size(); for (const int i : IndexRange(size)) { @@ -80,7 +80,7 @@ static void do_mix_operation_color4f(const int blend_mode, const FloatReadAttribute &factors, const Color4fReadAttribute &inputs_a, const Color4fReadAttribute &inputs_b, - Color4fWriteAttribute &results) + Color4fWriteAttribute results) { const int size = results.size(); for (const int i : IndexRange(size)) { @@ -95,39 +95,21 @@ static void do_mix_operation_color4f(const int blend_mode, static void do_mix_operation(const CustomDataType result_type, int blend_mode, const FloatReadAttribute &attribute_factor, - ReadAttributePtr attribute_a, - ReadAttributePtr attribute_b, - WriteAttributePtr attribute_result) + const ReadAttribute &attribute_a, + const ReadAttribute &attribute_b, + WriteAttribute &attribute_result) { if (result_type == CD_PROP_FLOAT) { - FloatReadAttribute attribute_a_float = std::move(attribute_a); - FloatReadAttribute attribute_b_float = std::move(attribute_b); - FloatWriteAttribute attribute_result_float = std::move(attribute_result); - do_mix_operation_float(blend_mode, - attribute_factor, - attribute_a_float, - attribute_b_float, - attribute_result_float); + do_mix_operation_float( + blend_mode, attribute_factor, attribute_a, attribute_b, attribute_result); } else if (result_type == CD_PROP_FLOAT3) { - Float3ReadAttribute attribute_a_float3 = std::move(attribute_a); - Float3ReadAttribute attribute_b_float3 = std::move(attribute_b); - Float3WriteAttribute attribute_result_float3 = std::move(attribute_result); - do_mix_operation_float3(blend_mode, - attribute_factor, - attribute_a_float3, - attribute_b_float3, - attribute_result_float3); + do_mix_operation_float3( + blend_mode, attribute_factor, attribute_a, attribute_b, attribute_result); } else if (result_type == CD_PROP_COLOR) { - Color4fReadAttribute attribute_a_color4f = std::move(attribute_a); - Color4fReadAttribute attribute_b_color4f = std::move(attribute_b); - Color4fWriteAttribute attribute_result_color4f = std::move(attribute_result); - do_mix_operation_color4f(blend_mode, - attribute_factor, - attribute_a_color4f, - attribute_b_color4f, - attribute_result_color4f); + do_mix_operation_color4f( + blend_mode, attribute_factor, attribute_a, attribute_b, attribute_result); } } @@ -170,9 +152,9 @@ static void attribute_mix_calc(GeometryComponent &component, const GeoNodeExecPa do_mix_operation(result_type, node_storage->blend_type, attribute_factor, - std::move(attribute_a), - std::move(attribute_b), - std::move(attribute_result)); + *attribute_a, + *attribute_b, + *attribute_result); } static void geo_node_attribute_mix_exec(GeoNodeExecParams params) diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc index b8b53a17ecc..60e1441e363 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc @@ -74,9 +74,9 @@ static float noise_from_index(const int seed, const int hash) return BLI_hash_int_01(combined_hash); } -static void randomize_attribute(BooleanWriteAttribute &attribute, - Span hashes, - const int seed) +static void randomize_attribute_bool(BooleanWriteAttribute attribute, + Span hashes, + const int seed) { MutableSpan attribute_span = attribute.get_span(); for (const int i : IndexRange(attribute.size())) { @@ -86,8 +86,8 @@ static void randomize_attribute(BooleanWriteAttribute &attribute, attribute.apply_span(); } -static void randomize_attribute( - FloatWriteAttribute &attribute, float min, float max, Span hashes, const int seed) +static void randomize_attribute_float( + FloatWriteAttribute attribute, float min, float max, Span hashes, const int seed) { MutableSpan attribute_span = attribute.get_span(); for (const int i : IndexRange(attribute.size())) { @@ -97,8 +97,8 @@ static void randomize_attribute( attribute.apply_span(); } -static void randomize_attribute( - Float3WriteAttribute &attribute, float3 min, float3 max, Span hashes, const int seed) +static void randomize_attribute_float3( + Float3WriteAttribute attribute, float3 min, float3 max, Span hashes, const int seed) { MutableSpan attribute_span = attribute.get_span(); for (const int i : IndexRange(attribute.size())) { @@ -161,22 +161,19 @@ static void randomize_attribute(GeometryComponent &component, switch (data_type) { case CD_PROP_FLOAT: { - FloatWriteAttribute float_attribute = std::move(attribute); const float min_value = params.get_input("Min_001"); const float max_value = params.get_input("Max_001"); - randomize_attribute(float_attribute, min_value, max_value, hashes, seed); + randomize_attribute_float(*attribute, min_value, max_value, hashes, seed); break; } case CD_PROP_FLOAT3: { - Float3WriteAttribute float3_attribute = std::move(attribute); const float3 min_value = params.get_input("Min"); const float3 max_value = params.get_input("Max"); - randomize_attribute(float3_attribute, min_value, max_value, hashes, seed); + randomize_attribute_float3(*attribute, min_value, max_value, hashes, seed); break; } case CD_PROP_BOOL: { - BooleanWriteAttribute boolean_attribute = std::move(attribute); - randomize_attribute(boolean_attribute, hashes, seed); + randomize_attribute_bool(*attribute, hashes, seed); break; } default: diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc index d70857757c7..de377e8bc87 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc @@ -363,20 +363,17 @@ static void attribute_vector_math_calc(GeometryComponent &component, case NODE_VECTOR_MATH_MODULO: case NODE_VECTOR_MATH_MINIMUM: case NODE_VECTOR_MATH_MAXIMUM: - do_math_operation_fl3_fl3_to_fl3( - std::move(attribute_a), std::move(attribute_b), std::move(attribute_result), operation); + do_math_operation_fl3_fl3_to_fl3(*attribute_a, *attribute_b, *attribute_result, operation); break; case NODE_VECTOR_MATH_DOT_PRODUCT: case NODE_VECTOR_MATH_DISTANCE: - do_math_operation_fl3_fl3_to_fl( - std::move(attribute_a), std::move(attribute_b), std::move(attribute_result), operation); + do_math_operation_fl3_fl3_to_fl(*attribute_a, *attribute_b, *attribute_result, operation); break; case NODE_VECTOR_MATH_LENGTH: - do_math_operation_fl3_to_fl(std::move(attribute_a), std::move(attribute_result), operation); + do_math_operation_fl3_to_fl(*attribute_a, *attribute_result, operation); break; case NODE_VECTOR_MATH_SCALE: - do_math_operation_fl3_fl_to_fl3( - std::move(attribute_a), std::move(attribute_b), std::move(attribute_result), operation); + do_math_operation_fl3_fl_to_fl3(*attribute_a, *attribute_b, *attribute_result, operation); break; case NODE_VECTOR_MATH_NORMALIZE: case NODE_VECTOR_MATH_FLOOR: @@ -386,14 +383,11 @@ static void attribute_vector_math_calc(GeometryComponent &component, case NODE_VECTOR_MATH_SINE: case NODE_VECTOR_MATH_COSINE: case NODE_VECTOR_MATH_TANGENT: - do_math_operation_fl3_to_fl3(std::move(attribute_a), std::move(attribute_result), operation); + do_math_operation_fl3_to_fl3(*attribute_a, *attribute_result, operation); break; case NODE_VECTOR_MATH_WRAP: - do_math_operation_fl3_fl3_fl3_to_fl3(std::move(attribute_a), - std::move(attribute_b), - std::move(attribute_c), - std::move(attribute_result), - operation); + do_math_operation_fl3_fl3_fl3_to_fl3( + *attribute_a, *attribute_b, *attribute_c, *attribute_result, operation); break; } } diff --git a/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc b/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc index 3229d87e1b2..066b2952111 100644 --- a/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc +++ b/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc @@ -38,22 +38,22 @@ static bNodeSocketTemplate geo_node_point_instance_out[] = { namespace blender::nodes { -static void fill_new_attribute_from_input(ReadAttributePtr input_attribute, - WriteAttributePtr out_attribute_a, - WriteAttributePtr out_attribute_b, +static void fill_new_attribute_from_input(const ReadAttribute &input_attribute, + WriteAttribute &out_attribute_a, + WriteAttribute &out_attribute_b, Span a_or_b) { - fn::GSpan in_span = input_attribute->get_span(); + fn::GSpan in_span = input_attribute.get_span(); int i_a = 0; int i_b = 0; for (int i_in = 0; i_in < in_span.size(); i_in++) { const bool move_to_b = a_or_b[i_in]; if (move_to_b) { - out_attribute_b->set(i_b, in_span[i_in]); + out_attribute_b.set(i_b, in_span[i_in]); i_b++; } else { - out_attribute_a->set(i_a, in_span[i_in]); + out_attribute_a.set(i_a, in_span[i_in]); i_a++; } } @@ -108,8 +108,7 @@ static void move_split_attributes(const GeometryComponent &in_component, continue; } - fill_new_attribute_from_input( - std::move(attribute), std::move(out_attribute_a), std::move(out_attribute_b), a_or_b); + fill_new_attribute_from_input(*attribute, *out_attribute_a, *out_attribute_b, a_or_b); } } -- cgit v1.2.3