[Bf-blender-cvs] [e891fc8f112] virtual-array-attributes: progress
Jacques Lucke
noreply at git.blender.org
Mon Apr 12 18:27:57 CEST 2021
Commit: e891fc8f1123a4b878019e30ac96ac73787f4918
Author: Jacques Lucke
Date: Mon Apr 12 18:21:37 2021 +0200
Branches: virtual-array-attributes
https://developer.blender.org/rBe891fc8f1123a4b878019e30ac96ac73787f4918
progress
===================================================================
M source/blender/blenlib/BLI_virtual_array.hh
M source/blender/functions/FN_generic_virtual_array.hh
M source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
M source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
===================================================================
diff --git a/source/blender/blenlib/BLI_virtual_array.hh b/source/blender/blenlib/BLI_virtual_array.hh
index dab5aabc0e2..76f69851669 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -407,6 +407,11 @@ template<typename T> class VArray_Span final : public VArray_For_Span<T> {
{
return this->get_span();
}
+
+ IndexRange index_range() const
+ {
+ return IndexRange(this->size());
+ }
};
template<typename T> class VMutableArray_Span final : public VMutableArray_For_MutableSpan<T> {
@@ -467,6 +472,21 @@ template<typename T> class VMutableArray_Span final : public VMutableArray_For_M
{
return this->get_span();
}
+
+ T &operator[](const int64_t index)
+ {
+ return this->data_[index];
+ }
+
+ int64_t size() const
+ {
+ return this->size();
+ }
+
+ IndexRange index_range() const
+ {
+ return IndexRange(this->size());
+ }
};
/**
diff --git a/source/blender/functions/FN_generic_virtual_array.hh b/source/blender/functions/FN_generic_virtual_array.hh
index 25546957114..13d9bdc385d 100644
--- a/source/blender/functions/FN_generic_virtual_array.hh
+++ b/source/blender/functions/FN_generic_virtual_array.hh
@@ -30,6 +30,7 @@
namespace blender::fn {
template<typename T> class GVArray_Typed;
+template<typename T> class GVMutableArray_Typed;
/* A generically typed version of `VArray<T>`. */
class GVArray {
@@ -191,6 +192,11 @@ class GVMutableArray : public GVArray {
return (VMutableArray<T> *)this->try_get_internal_mutable_varray_impl();
}
+ template<typename T> GVMutableArray_Typed<T> typed()
+ {
+ return GVMutableArray_Typed<T>(*this);
+ }
+
void fill(const void *value);
protected:
diff --git a/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc b/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
index fdbdadf90b6..2c6b2ce0eef 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc
@@ -192,8 +192,8 @@ static float map_smootherstep(const float value,
return min_to + factor_mapped * (max_to - min_to);
}
-static void map_range_float(FloatReadAttribute attribute_input,
- FloatWriteAttribute attribute_result,
+static void map_range_float(const VArray<float> &attribute_input,
+ VMutableArray<float> &attribute_result,
const GeoNodeExecParams ¶ms)
{
const bNode &node = params.node();
@@ -204,8 +204,8 @@ static void map_range_float(FloatReadAttribute attribute_input,
const float min_to = params.get_input<float>("To Min");
const float max_to = params.get_input<float>("To Max");
- Span<float> span = attribute_input.get_span();
- MutableSpan<float> result_span = attribute_result.get_span();
+ VArray_Span<float> span{attribute_input};
+ VMutableArray_Span<float> result_span{attribute_result};
switch (interpolation_type) {
case NODE_MAP_RANGE_LINEAR: {
@@ -241,14 +241,14 @@ static void map_range_float(FloatReadAttribute attribute_input,
const float clamp_min = min_to < max_to ? min_to : max_to;
const float clamp_max = min_to < max_to ? max_to : min_to;
- for (int i : result_span.index_range()) {
+ for (int i : IndexRange(result_span.size())) {
result_span[i] = std::clamp(result_span[i], clamp_min, clamp_max);
}
}
}
-static void map_range_float3(Float3ReadAttribute attribute_input,
- Float3WriteAttribute attribute_result,
+static void map_range_float3(const VArray<float3> &attribute_input,
+ VMutableArray<float3> &attribute_result,
const GeoNodeExecParams ¶ms)
{
const bNode &node = params.node();
@@ -259,8 +259,8 @@ static void map_range_float3(Float3ReadAttribute attribute_input,
const float3 min_to = params.get_input<float3>("To Min_001");
const float3 max_to = params.get_input<float3>("To Max_001");
- Span<float3> span = attribute_input.get_span();
- MutableSpan<float3> result_span = attribute_result.get_span();
+ VArray_Span<float3> span{attribute_input};
+ VMutableArray_Span<float3> result_span{attribute_result};
switch (interpolation_type) {
case NODE_MAP_RANGE_LINEAR: {
@@ -323,13 +323,13 @@ static AttributeDomain get_result_domain(const GeometryComponent &component,
StringRef source_name,
StringRef result_name)
{
- ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_name);
+ ReadAttributeLookup result_attribute = component.attribute_try_get_for_read(result_name);
if (result_attribute) {
- return result_attribute->domain();
+ return result_attribute.domain;
}
- ReadAttributePtr source_attribute = component.attribute_try_get_for_read(source_name);
+ ReadAttributeLookup source_attribute = component.attribute_try_get_for_read(source_name);
if (source_attribute) {
- return source_attribute->domain();
+ return source_attribute.domain;
}
return ATTR_DOMAIN_POINT;
}
@@ -349,7 +349,7 @@ static void map_range_attribute(GeometryComponent &component, const GeoNodeExecP
const AttributeDomain domain = get_result_domain(component, input_name, result_name);
- ReadAttributePtr attribute_input = component.attribute_try_get_for_read(
+ std::unique_ptr<GVArray> attribute_input = component.attribute_try_get_for_read(
input_name, domain, data_type);
if (!attribute_input) {
@@ -358,7 +358,7 @@ static void map_range_attribute(GeometryComponent &component, const GeoNodeExecP
return;
}
- OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
+ MaybeUnsavedWriteAttribute attribute_result = component.attribute_try_get_for_output(
result_name, domain, data_type);
if (!attribute_result) {
params.error_message_add(NodeWarningType::Error,
@@ -369,18 +369,19 @@ static void map_range_attribute(GeometryComponent &component, const GeoNodeExecP
switch (data_type) {
case CD_PROP_FLOAT: {
- map_range_float(*attribute_input, *attribute_result, params);
+ map_range_float(attribute_input->typed<float>(), attribute_result->typed<float>(), params);
break;
}
case CD_PROP_FLOAT3: {
- map_range_float3(*attribute_input, *attribute_result, params);
+ map_range_float3(
+ attribute_input->typed<float3>(), attribute_result->typed<float3>(), params);
break;
}
default:
BLI_assert_unreachable();
}
- attribute_result.apply_span_and_save();
+ attribute_result.save_if_necessary();
}
static void geo_node_attribute_map_range_exec(GeoNodeExecParams params)
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 5ee31e78be2..9897c3fcf34 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc
@@ -149,9 +149,9 @@ static void geo_node_attribute_math_update(bNodeTree *UNUSED(ntree), bNode *node
operation_use_input_c(operation));
}
-static void do_math_operation(Span<float> span_a,
- Span<float> span_b,
- Span<float> span_c,
+static void do_math_operation(const VArray<float> &span_a,
+ const VArray<float> &span_b,
+ const VArray<float> &span_c,
MutableSpan<float> span_result,
const NodeMathOperation operation)
{
@@ -165,8 +165,8 @@ static void do_math_operation(Span<float> span_a,
UNUSED_VARS_NDEBUG(success);
}
-static void do_math_operation(Span<float> span_a,
- Span<float> span_b,
+static void do_math_operation(const VArray<float> &span_a,
+ const VArray<float> &span_b,
MutableSpan<float> span_result,
const NodeMathOperation operation)
{
@@ -180,7 +180,7 @@ static void do_math_operation(Span<float> span_a,
UNUSED_VARS_NDEBUG(success);
}
-static void do_math_operation(Span<float> span_input,
+static void do_math_operation(const VArray<float> &span_input,
MutableSpan<float> span_result,
const NodeMathOperation operation)
{
@@ -200,9 +200,9 @@ static AttributeDomain get_result_domain(const GeometryComponent &component,
StringRef result_name)
{
/* Use the domain of the result attribute if it already exists. */
- ReadAttributePtr result_attribute = component.attribute_try_get_for_read(result_name);
+ ReadAttributeLookup result_attribute = component.attribute_try_get_for_read(result_name);
if (result_attribute) {
- return result_attribute->domain();
+ return result_attribute.domain;
}
/* Otherwise use the highest priority domain from existing input attributes, or the default. */
@@ -228,52 +228,52 @@ static void attribute_math_calc(GeometryComponent &component, const GeoNodeExecP
const AttributeDomain result_domain = get_result_domain(
component, params, operation, result_name);
- OutputAttributePtr attribute_result = component.attribute_try_get_for_output(
+ MaybeUnsavedWriteAttribute attribute_result = component.attribute_try_get_for_output(
result_name, result_domain, result_type);
if (!attribute_result) {
return;
}
- ReadAttributePtr attribute_a = params.get_input_attribute(
+ std::unique_ptr<GVArray> attribute_a = params.get_input_attribute(
"A", component, result_domain, result_type, nullptr);
if (!attribute_a) {
return;
}
+ GVMutableArray_Typed<float> result_typed{*attribute_result};
+ VMutableArray_Span<float> result_span{*result_typed};
+
/* Note that passing the data with `get_span<float>()` works
* because the attributes were accessed with #CD_PROP_FLOAT. */
if (operation_use_input_b(operation)) {
- R
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list