[Bf-blender-cvs] [ed1042ee060] master: Geometry Nodes: cleanup attribute usage
Jacques Lucke
noreply at git.blender.org
Wed Jan 13 12:31:18 CET 2021
Commit: ed1042ee060caf5132822b947cac768f90b5ba12
Author: Jacques Lucke
Date: Wed Jan 13 12:27:16 2021 +0100
Branches: master
https://developer.blender.org/rBed1042ee060caf5132822b947cac768f90b5ba12
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.
===================================================================
M source/blender/blenkernel/BKE_attribute_access.hh
M source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc
M source/blender/nodes/geometry/nodes/node_geo_point_separate.cc
===================================================================
diff --git a/source/blender/blenkernel/BKE_attribute_access.hh b/source/blender/blenkernel/BKE_attribute_access.hh
index 0c980178ffa..abcf8ed1c54 100644
--- a/source/blender/blenkernel/BKE_attribute_access.hh
+++ b/source/blender/blenkernel/BKE_attribute_access.hh
@@ -100,6 +100,11 @@ class ReadAttribute {
/* Get a span that contains all attribute values. */
fn::GSpan get_span() const;
+ template<typename T> Span<T> get_span() const
+ {
+ return this->get_span().typed<T>();
+ }
+
protected:
/* r_value is expected to be uninitialized. */
virtual void get_internal(const int64_t index, void *r_value) const = 0;
@@ -176,6 +181,16 @@ class WriteAttribute {
/* Write the changes to the span into the actual attribute, if they aren't already. */
void apply_span();
+ template<typename T> MutableSpan<T> get_span()
+ {
+ return this->get_span().typed<T>();
+ }
+
+ template<typename T> MutableSpan<T> get_span_for_write_only()
+ {
+ return this->get_span_for_write_only().typed<T>();
+ }
+
protected:
virtual void get_internal(const int64_t index, void *r_value) const = 0;
virtual void set_internal(const int64_t index, const void *value) = 0;
@@ -191,8 +206,8 @@ using WriteAttributePtr = std::unique_ptr<WriteAttribute>;
* The underlying ReadAttribute is owned optionally. */
template<typename T> class TypedReadAttribute {
private:
- std::unique_ptr<ReadAttribute> owned_attribute_;
- ReadAttribute *attribute_;
+ std::unique_ptr<const ReadAttribute> owned_attribute_;
+ const ReadAttribute *attribute_;
public:
TypedReadAttribute(ReadAttributePtr attribute) : TypedReadAttribute(*attribute)
@@ -201,7 +216,7 @@ template<typename T> class TypedReadAttribute {
BLI_assert(owned_attribute_);
}
- TypedReadAttribute(ReadAttribute &attribute) : attribute_(&attribute)
+ TypedReadAttribute(const ReadAttribute &attribute) : attribute_(&attribute)
{
BLI_assert(attribute_->cpp_type().is<T>());
}
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<std::string>("Attribute");
FloatReadAttribute attribute_in = component.attribute_get_for_read<float>(
input_name, result_domain, 0.0f);
Span<float> data_in = attribute_in.get_span();
- MutableSpan<Color4f> data_out = attribute_out.get_span_for_write_only();
+ MutableSpan<Color4f> data_out = attribute_result->get_span_for_write_only<Color4f>();
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<bool> span_result)
+static void do_equal_operation_float(const FloatReadAttribute &input_a,
+ const FloatReadAttribute &input_b,
+ const float threshold,
+ MutableSpan<bool> 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<bool> span_result)
+static void do_equal_operation_float3(const Float3ReadAttribute &input_a,
+ const Float3ReadAttribute &input_b,
+ const float threshold,
+ MutableSpan<bool> 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<bool> span_result)
+static void do_equal_operation_color4f(const Color4fReadAttribute &input_a,
+ const Color4fReadAttribute &input_b,
+ const float threshold,
+ MutableSpan<bool> 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<bool> span_result)
+static void do_equal_operation_bool(const BooleanReadAttribute &input_a,
+ const BooleanReadAttribute &input_b,
+ const float UNUSED(threshold),
+ MutableSpan<bool> 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<bool> span_result)
+static void do_not_equal_operation_float(const FloatReadAttribute &input_a,
+ const FloatReadAttribute &input_b,
+ const float threshold,
+ MutableSpan<bool> 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<bool> span_result)
+static void do_not_equal_operation_float3(const Float3ReadAttribute &input_a,
+ const Float3ReadAttribute &input_b,
+ const float threshold,
+ MutableSpan<bool> 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<bool> span_result)
+static void do_not_equal_operation_color4f(const Color4fReadAttribute &input_a,
+ const Color4fReadAttribute &input_b,
+ const float threshold,
+ MutableSpan<bool> 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<bool> span_result)
+static void do_not_equal_operation_bool(const BooleanReadAttribute &input_a,
+ const BooleanReadAttribute &input_b,
+ const float UNUSED(threshold),
+ MutableSpan<bool> 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<bool> 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<float>("Threshold");
if (operation == NODE_FLOAT_COMPARE_EQUAL) {
if (input_data_type == CD_PR
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list