[Bf-blender-cvs] [8adebaeb7c3] master: Modifiers: measure execution time and provide Python access

2023-02-06 Thread Jacques Lucke
Commit: 8adebaeb7c3c663ec775fda239fdfe5ddb654b06
Author: Jacques Lucke
Date:   Mon Feb 6 15:39:59 2023 +0100
Branches: master
https://developer.blender.org/rB8adebaeb7c3c663ec775fda239fdfe5ddb654b06

Modifiers: measure execution time and provide Python access

The goal is to give technical artists the ability to optimize modifier usage
and/or geometry node groups for performance. In the long term, it
would be useful if Blender could provide its own UI to display profiling
information to users. However, right now, there are too many open
design questions making it infeasible to tackle this in the short term.

This commit uses a simpler approach: Instead of adding new ui for
profiling data, it exposes the execution-time of modifiers in the Python
API. This allows technical artists to access the information and to build
their own UI to display the relevant information. In the long term this
will hopefully also help us to integrate a native ui for this in Blender
by observing how users use this information.

Note: The execution time of a modifier highly depends on what other
things the CPU is doing at the same time. For example, in many more
complex files, many objects and therefore modifiers are evaluated at
the same time by multiple threads which makes the measurement
much less reliable. For best results, make sure that only one object
is evaluated at a time (e.g. by changing it in isolation) and that no
other process on the system keeps the CPU busy.

As shown below, the execution time has to be accessed on the
evaluated object, not the original object.

```lang=python
import bpy
depsgraph = bpy.context.view_layer.depsgraph
ob = bpy.context.active_object
ob_eval = ob.evaluated_get(depsgraph)
modifier_eval = ob_eval.modifiers[0]
print(modifier_eval.execution_time, "s")
```

Differential Revision: https://developer.blender.org/D17185

===

M   source/blender/blenkernel/BKE_modifier.h
M   source/blender/blenkernel/intern/DerivedMesh.cc
M   source/blender/blenkernel/intern/curves.cc
M   source/blender/blenkernel/intern/displist.cc
M   source/blender/blenkernel/intern/modifier.cc
M   source/blender/blenkernel/intern/pointcloud.cc
M   source/blender/blenkernel/intern/volume.cc
M   source/blender/makesdna/DNA_modifier_types.h
M   source/blender/makesrna/intern/rna_modifier.c

===

diff --git a/source/blender/blenkernel/BKE_modifier.h 
b/source/blender/blenkernel/BKE_modifier.h
index ce2f9e878f8..4641cc47b14 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -612,3 +612,25 @@ void BKE_modifier_blend_read_lib(struct BlendLibReader 
*reader, struct Object *o
 #ifdef __cplusplus
 }
 #endif
+
+#ifdef __cplusplus
+
+namespace blender::bke {
+
+/**
+ * A convenience class that can be used to set `ModifierData::execution_time` 
based on the lifetime
+ * of this class.
+ */
+class ScopedModifierTimer {
+ private:
+  ModifierData _;
+  double start_time_;
+
+ public:
+  ScopedModifierTimer(ModifierData );
+  ~ScopedModifierTimer();
+};
+
+}  // namespace blender::bke
+
+#endif
diff --git a/source/blender/blenkernel/intern/DerivedMesh.cc 
b/source/blender/blenkernel/intern/DerivedMesh.cc
index 565009fe08f..c3d535a3e9d 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.cc
+++ b/source/blender/blenkernel/intern/DerivedMesh.cc
@@ -760,6 +760,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
   }
 
   if (mti->type == eModifierTypeType_OnlyDeform && !sculpt_dyntopo) {
+blender::bke::ScopedModifierTimer modifier_timer{*md};
 if (!deformed_verts) {
   deformed_verts = BKE_mesh_vert_coords_alloc(mesh_input, 
_deformed_verts);
 }
@@ -846,6 +847,8 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
   continue;
 }
 
+blender::bke::ScopedModifierTimer modifier_timer{*md};
+
 /* Add orco mesh as layer if needed by this modifier. */
 if (mesh_final && mesh_orco && mti->requiredDataMask) {
   CustomData_MeshMasks mask = {0};
@@ -1323,6 +1326,8 @@ static void editbmesh_calc_modifiers(struct Depsgraph 
*depsgraph,
   continue;
 }
 
+blender::bke::ScopedModifierTimer modifier_timer{*md};
+
 /* Add an orco mesh as layer if needed by this modifier. */
 if (mesh_final && mesh_orco && mti->requiredDataMask) {
   CustomData_MeshMasks mask = {0};
diff --git a/source/blender/blenkernel/intern/curves.cc 
b/source/blender/blenkernel/intern/curves.cc
index 1519c0addd2..3003d014b4f 100644
--- a/source/blender/blenkernel/intern/curves.cc
+++ b/source/blender/blenkernel/intern/curves.cc
@@ -314,6 +314,8 @@ static void curves_evaluate_modifiers(struct Depsgraph 
*depsgraph,
   continue;
 }
 
+blender::bke::ScopedModifierTimer modifier_timer{*md};

[Bf-blender-cvs] [3d6ceb737d8] master: Geometry Nodes: parallelize part of Duplicate Elements node

2023-02-05 Thread Jacques Lucke
Commit: 3d6ceb737d81361fb27edb017ede826692efa75c
Author: Jacques Lucke
Date:   Sun Feb 5 20:59:39 2023 +0100
Branches: master
https://developer.blender.org/rB3d6ceb737d81361fb27edb017ede826692efa75c

Geometry Nodes: parallelize part of Duplicate Elements node

This implements two optimizations:
* If the duplication count is constant, the offsets array can be
  filled directly in parallel.
* Otherwise, extracting the counts from the virtual array is parallelized.
  But there is still a serial loop over all elements in the end to compute
  the offsets.

===

M   source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc 
b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
index 586b14ff29f..da4d3c7e641 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
@@ -81,8 +81,22 @@ static OffsetIndices accumulate_counts_to_offsets(const 
IndexMask selection
Array 
_offset_data)
 {
   r_offset_data.reinitialize(selection.size() + 1);
-  counts.materialize_compressed(selection, r_offset_data);
-  offset_indices::accumulate_counts_to_offsets(r_offset_data);
+  if (counts.is_single()) {
+const int count = counts.get_internal_single();
+threading::parallel_for(selection.index_range(), 1024, [&](const 
IndexRange range) {
+  for (const int64_t i : range) {
+r_offset_data[i] = count * i;
+  }
+});
+r_offset_data.last() = count * selection.size();
+  }
+  else {
+threading::parallel_for(selection.index_range(), 1024, [&](const 
IndexRange range) {
+  counts.materialize_compressed(selection.slice(range),
+
r_offset_data.as_mutable_span().slice(range));
+});
+offset_indices::accumulate_counts_to_offsets(r_offset_data);
+  }
   return OffsetIndices(r_offset_data);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ca99a59605e] master: Fix T104261: crash when trying to draw viewer overlay for empty curve

2023-02-02 Thread Jacques Lucke
Commit: ca99a59605e52e6b4ec759523b1403b2b7e33ee7
Author: Jacques Lucke
Date:   Thu Feb 2 17:20:57 2023 +0100
Branches: master
https://developer.blender.org/rBca99a59605e52e6b4ec759523b1403b2b7e33ee7

Fix T104261: crash when trying to draw viewer overlay for empty curve

`BKE_displist_make_curveTypes` only sets `curve_eval` if the final geometry
of the object actually contains curve data, otherwise it's null.

===

M   source/blender/draw/engines/overlay/overlay_viewer_attribute.cc

===

diff --git a/source/blender/draw/engines/overlay/overlay_viewer_attribute.cc 
b/source/blender/draw/engines/overlay/overlay_viewer_attribute.cc
index 69ff877c1e5..fe20fb135c5 100644
--- a/source/blender/draw/engines/overlay/overlay_viewer_attribute.cc
+++ b/source/blender/draw/engines/overlay/overlay_viewer_attribute.cc
@@ -131,11 +131,13 @@ static void populate_cache_for_geometry(Object ,
 }
 case OB_CURVES_LEGACY: {
   Curve *curve = static_cast(object.data);
-  const bke::CurvesGeometry  = curve->curve_eval->geometry.wrap();
-  if (curves.attributes().contains(".viewer")) {
-GPUBatch *batch = 
DRW_cache_curve_edge_wire_viewer_attribute_get();
-DRW_shgroup_uniform_float_copy(pd.viewer_attribute_curve_grp, 
"opacity", opacity);
-DRW_shgroup_call_obmat(pd.viewer_attribute_curve_grp, batch, 
object.object_to_world);
+  if (curve->curve_eval) {
+const bke::CurvesGeometry  = curve->curve_eval->geometry.wrap();
+if (curves.attributes().contains(".viewer")) {
+  GPUBatch *batch = 
DRW_cache_curve_edge_wire_viewer_attribute_get();
+  DRW_shgroup_uniform_float_copy(pd.viewer_attribute_curve_grp, 
"opacity", opacity);
+  DRW_shgroup_call_obmat(pd.viewer_attribute_curve_grp, batch, 
object.object_to_world);
+}
   }
   break;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [72089387079] master: Fix T104278: incorrect handling of unavailable linked node groups

2023-02-02 Thread Jacques Lucke
Commit: 72089387079f09b536814d1e10ab54c3d114f603
Author: Jacques Lucke
Date:   Thu Feb 2 16:34:33 2023 +0100
Branches: master
https://developer.blender.org/rB72089387079f09b536814d1e10ab54c3d114f603

Fix T104278: incorrect handling of unavailable linked node groups

The declaration of group nodes using unavailable linked groups contains
a `skip_updating_sockets` tag, which indicates that the node shouldn't
change. This information was not used properly further down the line.

===

M   source/blender/blenkernel/intern/node.cc

===

diff --git a/source/blender/blenkernel/intern/node.cc 
b/source/blender/blenkernel/intern/node.cc
index 48dad8d4034..74351022fd3 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -3591,11 +3591,24 @@ static void update_socket_declarations(ListBase 
*sockets,
   }
 }
 
+static void reset_socket_declarations(ListBase *sockets)
+{
+  LISTBASE_FOREACH (bNodeSocket *, socket, sockets) {
+socket->runtime->declaration = nullptr;
+  }
+}
+
 void nodeSocketDeclarationsUpdate(bNode *node)
 {
   BLI_assert(node->runtime->declaration != nullptr);
-  update_socket_declarations(>inputs, 
node->runtime->declaration->inputs);
-  update_socket_declarations(>outputs, 
node->runtime->declaration->outputs);
+  if (node->runtime->declaration->skip_updating_sockets) {
+reset_socket_declarations(>inputs);
+reset_socket_declarations(>outputs);
+  }
+  else {
+update_socket_declarations(>inputs, 
node->runtime->declaration->inputs);
+update_socket_declarations(>outputs, 
node->runtime->declaration->outputs);
+  }
 }
 
 bool nodeDeclarationEnsureOnOutdatedNode(bNodeTree *ntree, bNode *node)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [2a19810f970] master: Fix T104296: crash caused by incorrectly initialized group nodes

2023-02-02 Thread Jacques Lucke
Commit: 2a19810f970bc88f2b2d5eb86595bf4dcd2bc5b6
Author: Jacques Lucke
Date:   Thu Feb 2 16:30:32 2023 +0100
Branches: master
https://developer.blender.org/rB2a19810f970bc88f2b2d5eb86595bf4dcd2bc5b6

Fix T104296: crash caused by incorrectly initialized group nodes

Versioning code in `do_versions_after_linking_260` inserted new group input
and output nodes. And (reasonably?) expected sockets to exist on those nodes.
However, `nodeAddStaticNode` did not initialize sockets on nodes with that use
`declare_dynamic` yet. This patch changes it so that `declare_dynamic` is used
in more places, which caused issues during file loading when node groups are
updated in somewhat arbitrary order (not in an order that is based on which
groups use which).

Differential Revision: https://developer.blender.org/D17183

===

M   source/blender/blenkernel/intern/node.cc
M   source/blender/nodes/intern/node_socket.cc

===

diff --git a/source/blender/blenkernel/intern/node.cc 
b/source/blender/blenkernel/intern/node.cc
index 26b1f2f5096..48dad8d4034 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -922,7 +922,11 @@ void ntreeBlendReadLib(BlendLibReader *reader, bNodeTree 
*ntree)
* to match the static layout. */
   if (!BLO_read_lib_is_undo(reader)) {
 LISTBASE_FOREACH (bNode *, node, >nodes) {
-  node_verify_sockets(ntree, node, false);
+  /* Don't update node groups here because they may depend on other node 
groups which are not
+   * fully versioned yet and don't have `typeinfo` pointers set. */
+  if (node->type != NODE_GROUP) {
+node_verify_sockets(ntree, node, false);
+  }
 }
   }
 }
@@ -1075,7 +1079,7 @@ IDTypeInfo IDType_ID_NT = {
 
 static void node_add_sockets_from_type(bNodeTree *ntree, bNode *node, 
bNodeType *ntype)
 {
-  if (ntype->declare != nullptr) {
+  if (ntype->declare || ntype->declare_dynamic) {
 node_verify_sockets(ntree, node, true);
 return;
   }
@@ -3594,24 +3598,23 @@ void nodeSocketDeclarationsUpdate(bNode *node)
   update_socket_declarations(>outputs, 
node->runtime->declaration->outputs);
 }
 
-bool nodeDeclarationEnsureOnOutdatedNode(bNodeTree * /*ntree*/, bNode *node)
+bool nodeDeclarationEnsureOnOutdatedNode(bNodeTree *ntree, bNode *node)
 {
   if (node->runtime->declaration != nullptr) {
 return false;
   }
-  if (node->typeinfo->declare == nullptr) {
-return false;
-  }
   if (node->typeinfo->declare_dynamic) {
 node->runtime->declaration = new blender::nodes::NodeDeclaration();
-blender::nodes::build_node_declaration(*node->typeinfo, 
*node->runtime->declaration);
+blender::nodes::build_node_declaration_dynamic(*ntree, *node, 
*node->runtime->declaration);
+return true;
   }
-  else {
+  if (node->typeinfo->declare) {
 /* Declaration should have been created in #nodeRegisterType. */
 BLI_assert(node->typeinfo->fixed_declaration != nullptr);
 node->runtime->declaration = node->typeinfo->fixed_declaration;
+return true;
   }
-  return true;
+  return false;
 }
 
 bool nodeDeclarationEnsure(bNodeTree *ntree, bNode *node)
diff --git a/source/blender/nodes/intern/node_socket.cc 
b/source/blender/nodes/intern/node_socket.cc
index 814ad1c80e1..7d6499a496f 100644
--- a/source/blender/nodes/intern/node_socket.cc
+++ b/source/blender/nodes/intern/node_socket.cc
@@ -283,7 +283,7 @@ void node_verify_sockets(bNodeTree *ntree, bNode *node, 
bool do_id_user)
   if (ntype == nullptr) {
 return;
   }
-  if (ntype->declare != nullptr) {
+  if (ntype->declare || ntype->declare_dynamic) {
 nodeDeclarationEnsureOnOutdatedNode(ntree, node);
 refresh_node(*ntree, *node, *node->runtime->declaration, do_id_user);
 return;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [bbc18673f39] master: Cleanup: make format

2023-02-02 Thread Jacques Lucke
Commit: bbc18673f39490666f6cd1e23bcf11b1adb15133
Author: Jacques Lucke
Date:   Thu Feb 2 13:12:45 2023 +0100
Branches: master
https://developer.blender.org/rBbbc18673f39490666f6cd1e23bcf11b1adb15133

Cleanup: make format

===

M   source/blender/blenkernel/intern/writeffmpeg.c
M   source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl
M   source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl
M   source/blender/gpu/tests/shaders/gpu_compute_dummy_test.glsl
M   source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl
M   source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl
M   tests/python/bl_usd_import_test.py

===

diff --git a/source/blender/blenkernel/intern/writeffmpeg.c 
b/source/blender/blenkernel/intern/writeffmpeg.c
index 3b402730ee9..afb9f530d8e 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -480,7 +480,7 @@ static const AVCodec *get_av1_encoder(
* where using a different encoder is desireable, such as in T103849. */
   codec = avcodec_find_encoder_by_name("librav1e");
   if (!codec) {
-  /* Fallback to libaom-av1 if librav1e is not found. */
+/* Fallback to libaom-av1 if librav1e is not found. */
 codec = avcodec_find_encoder_by_name("libaom-av1");
   }
   break;
diff --git a/source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl 
b/source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl
index f3b85669b9c..9881f752eb9 100644
--- a/source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl
+++ b/source/blender/gpu/tests/shaders/gpu_compute_1d_test.glsl
@@ -1,4 +1,5 @@
-void main() {
+void main()
+{
   int index = int(gl_GlobalInvocationID.x);
   vec4 pos = vec4(gl_GlobalInvocationID.x);
   imageStore(img_output, index, pos);
diff --git a/source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl 
b/source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl
index 698a256e88e..cbc598e4ceb 100644
--- a/source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl
+++ b/source/blender/gpu/tests/shaders/gpu_compute_2d_test.glsl
@@ -1,4 +1,5 @@
-void main() {
+void main()
+{
   vec4 pixel = vec4(1.0, 0.5, 0.2, 1.0);
   imageStore(img_output, ivec2(gl_GlobalInvocationID.xy), pixel);
 }
diff --git a/source/blender/gpu/tests/shaders/gpu_compute_dummy_test.glsl 
b/source/blender/gpu/tests/shaders/gpu_compute_dummy_test.glsl
index 0b2c54c4153..919810306a4 100644
--- a/source/blender/gpu/tests/shaders/gpu_compute_dummy_test.glsl
+++ b/source/blender/gpu/tests/shaders/gpu_compute_dummy_test.glsl
@@ -1,2 +1,3 @@
-void main () {
+void main()
+{
 }
diff --git a/source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl 
b/source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl
index ad1ed1b42db..94c281720b9 100644
--- a/source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl
+++ b/source/blender/gpu/tests/shaders/gpu_compute_ibo_test.glsl
@@ -1,4 +1,5 @@
-void main() {
+void main()
+{
   uint store_index = int(gl_GlobalInvocationID.x);
   out_indices[store_index] = store_index;
 }
diff --git a/source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl 
b/source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl
index 72f7f9326bb..e8d2eb9201b 100644
--- a/source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl
+++ b/source/blender/gpu/tests/shaders/gpu_compute_vbo_test.glsl
@@ -1,4 +1,5 @@
-void main() {
+void main()
+{
   uint index = gl_GlobalInvocationID.x;
   vec4 pos = vec4(gl_GlobalInvocationID.x);
   out_positions[index] = pos;
diff --git a/tests/python/bl_usd_import_test.py 
b/tests/python/bl_usd_import_test.py
index 438a5c48d73..e05b32cf0e8 100644
--- a/tests/python/bl_usd_import_test.py
+++ b/tests/python/bl_usd_import_test.py
@@ -189,6 +189,7 @@ class USDImportTest(AbstractUSDTest):
 self.assertAlmostEqual(1.234, test_cam.shift_x, 3)
 self.assertAlmostEqual(5.678, test_cam.shift_y, 3)
 
+
 def main():
 global args
 import argparse

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [19fe5caf872] master: Geometry Nodes: add support for eye dropper for object input in modifier

2023-02-01 Thread Jacques Lucke
Commit: 19fe5caf872476db265596eaac1dc35ad1c6422d
Author: Jacques Lucke
Date:   Wed Feb 1 12:53:57 2023 +0100
Branches: master
https://developer.blender.org/rB19fe5caf872476db265596eaac1dc35ad1c6422d

Geometry Nodes: add support for eye dropper for object input in modifier

Differential Revision: https://developer.blender.org/D17108

===

M   source/blender/makesdna/DNA_ID.h
M   source/blender/makesrna/intern/rna_access.c
M   source/blender/modifiers/intern/MOD_nodes.cc

===

diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 1e43321836f..a0f5448a003 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -104,6 +104,12 @@ typedef struct IDPropertyUIDataString {
 /** For #IDP_UI_DATA_TYPE_ID. */
 typedef struct IDPropertyUIDataID {
   IDPropertyUIData base;
+  /**
+   * #ID_Type. This type type is not enforced. It is just a hint to the ui for 
what kind of ID is
+   * expected. If this is zero, any id type is expected.
+   */
+  short id_type;
+  char _pad[6];
 } IDPropertyUIDataID;
 
 typedef struct IDPropertyData {
diff --git a/source/blender/makesrna/intern/rna_access.c 
b/source/blender/makesrna/intern/rna_access.c
index e7187b2822b..d6d7ae359d6 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -1415,6 +1415,16 @@ int RNA_property_string_maxlength(PropertyRNA *prop)
 
 StructRNA *RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
 {
+  if (prop->magic != RNA_MAGIC) {
+const IDProperty *idprop = (IDProperty *)prop;
+if (idprop->type == IDP_ID) {
+  const IDPropertyUIDataID *ui_data = (const IDPropertyUIDataID 
*)idprop->ui_data;
+  if (ui_data) {
+return ID_code_to_RNA_type(ui_data->id_type);
+  }
+}
+  }
+
   prop = rna_ensure_property(prop);
 
   if (prop->type == PROP_POINTER) {
diff --git a/source/blender/modifiers/intern/MOD_nodes.cc 
b/source/blender/modifiers/intern/MOD_nodes.cc
index da623881548..6ecd2c74462 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -513,7 +513,10 @@ id_property_create_from_socket(const bNodeSocket )
 case SOCK_OBJECT: {
   const bNodeSocketValueObject *value = static_cast(
   socket.default_value);
-  return bke::idprop::create(socket.identifier, reinterpret_cast(value->value));
+  auto property = bke::idprop::create(socket.identifier, 
reinterpret_cast(value->value));
+  IDPropertyUIDataID *ui_data = (IDPropertyUIDataID 
*)IDP_ui_data_ensure(property.get());
+  ui_data->id_type = ID_OB;
+  return property;
 }
 case SOCK_COLLECTION: {
   const bNodeSocketValueCollection *value = static_cast(

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [345dded146e] master: Revert "Geometry Nodes: hide group inputs with "Hide Value" enabled in modifier"

2023-01-31 Thread Jacques Lucke
Commit: 345dded146e5f573f546d9b56d1d82e9e0bf2a54
Author: Jacques Lucke
Date:   Tue Jan 31 19:28:22 2023 +0100
Branches: master
https://developer.blender.org/rB345dded146e5f573f546d9b56d1d82e9e0bf2a54

Revert "Geometry Nodes: hide group inputs with "Hide Value" enabled in modifier"

This reverts commit 11a9578a1972db0a2d3f4e593d9b22598340825b.

Reverting this because there was a miscommunication between Simon and me. 
Shortly
before I committed the change, Simon noticed that there are cases when "Hide 
Value"
is checked to hide the value in a group node, but we still want to show the 
value
in the modifier.

===

M   source/blender/modifiers/intern/MOD_nodes.cc

===

diff --git a/source/blender/modifiers/intern/MOD_nodes.cc 
b/source/blender/modifiers/intern/MOD_nodes.cc
index 140eec20582..da623881548 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -1733,9 +1733,6 @@ static void panel_draw(const bContext *C, Panel *panel)
 
 int socket_index;
 LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, >node_group->inputs, 
socket_index) {
-  if (socket->flag & SOCK_HIDE_VALUE) {
-continue;
-  }
   draw_property_for_socket(*C, layout, nmd, _ptr, ptr, *socket, 
socket_index);
 }
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [11a9578a197] master: Geometry Nodes: hide group inputs with "Hide Value" enabled in modifier

2023-01-31 Thread Jacques Lucke
Commit: 11a9578a1972db0a2d3f4e593d9b22598340825b
Author: Jacques Lucke
Date:   Tue Jan 31 18:54:55 2023 +0100
Branches: master
https://developer.blender.org/rB11a9578a1972db0a2d3f4e593d9b22598340825b

Geometry Nodes: hide group inputs with "Hide Value" enabled in modifier

When the "Hide Value" option of a group input is enabled, only its name
is displayed in group nodes. Modifiers should have the same behavior.
However, for modifiers, only showing the name does not make sense
when the user can't edit the value. Therefore the value is not shown at all.

===

M   source/blender/modifiers/intern/MOD_nodes.cc

===

diff --git a/source/blender/modifiers/intern/MOD_nodes.cc 
b/source/blender/modifiers/intern/MOD_nodes.cc
index da623881548..140eec20582 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -1733,6 +1733,9 @@ static void panel_draw(const bContext *C, Panel *panel)
 
 int socket_index;
 LISTBASE_FOREACH_INDEX (bNodeSocket *, socket, >node_group->inputs, 
socket_index) {
+  if (socket->flag & SOCK_HIDE_VALUE) {
+continue;
+  }
   draw_property_for_socket(*C, layout, nmd, _ptr, ptr, *socket, 
socket_index);
 }
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [29951651489] master: Cleanup: simplify wrapping CurvesGeometry in C++

2023-01-31 Thread Jacques Lucke
Commit: 29951651489079da8d72782eb4f8b693d57896a8
Author: Jacques Lucke
Date:   Tue Jan 31 18:45:34 2023 +0100
Branches: master
https://developer.blender.org/rB29951651489079da8d72782eb4f8b693d57896a8

Cleanup: simplify wrapping CurvesGeometry in C++

===

M   source/blender/blenkernel/BKE_curves.hh
M   source/blender/blenkernel/intern/attribute.cc
M   source/blender/blenkernel/intern/crazyspace.cc
M   source/blender/blenkernel/intern/curve_legacy_convert.cc
M   source/blender/blenkernel/intern/curves.cc
M   source/blender/blenkernel/intern/geometry_component_edit_data.cc
M   source/blender/blenkernel/intern/geometry_fields.cc
M   source/blender/blenkernel/intern/geometry_set.cc
M   source/blender/blenkernel/intern/mesh_convert.cc
M   source/blender/draw/engines/overlay/overlay_sculpt_curves.cc
M   source/blender/draw/engines/overlay/overlay_viewer_attribute.cc
M   source/blender/draw/intern/draw_cache_impl_curve.cc
M   source/blender/draw/intern/draw_cache_impl_curves.cc
M   source/blender/draw/intern/draw_curves.cc
M   source/blender/editors/curves/intern/curves_data.cc
M   source/blender/editors/curves/intern/curves_ops.cc
M   source/blender/editors/curves/intern/curves_selection.cc
M   source/blender/editors/curves/intern/curves_undo.cc
M   source/blender/editors/object/object_add.cc
M   source/blender/editors/object/object_modifier.cc
M   source/blender/editors/object/object_transform.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_add.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_brush.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_comb.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_delete.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_density.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_pinch.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_selection.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc
M   source/blender/editors/transform/transform_convert_curves.cc
M   source/blender/geometry/intern/realize_instances.cc
M   source/blender/makesdna/DNA_curves_types.h
M   source/blender/nodes/geometry/nodes/node_geo_convex_hull.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_fill.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_length.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_primitive_arc.cc
M   
source/blender/nodes/geometry/nodes/node_geo_curve_primitive_bezier_segment.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_primitive_circle.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_primitive_line.cc
M   
source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadratic_bezier.cc
M   
source/blender/nodes/geometry/nodes/node_geo_curve_primitive_quadrilateral.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_primitive_spiral.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_resample.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_reverse.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_set_handle_type.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
M   source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
M   source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M   source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
M   source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
M   source/blender/nodes/geometry/nodes/node_geo_set_curve_handles.cc
M   source/blender/nodes/geometry/nodes/node_geo_set_curve_normal.cc
M   source/blender/nodes/geometry/nodes/node_geo_set_curve_radius.cc
M   source/blender/nodes/geometry/nodes/node_geo_set_curve_tilt.cc
M   source/blender/nodes/geometry/nodes/node_geo_set_position.cc
M   source/blender/nodes/geometry/nodes

[Bf-blender-cvs] [e497da5fda3] master: Fix: off by one error in previous commit

2023-01-28 Thread Jacques Lucke
Commit: e497da5fda3547d794f0fecbbc126d34446661fb
Author: Jacques Lucke
Date:   Sun Jan 29 00:13:37 2023 +0100
Branches: master
https://developer.blender.org/rBe497da5fda3547d794f0fecbbc126d34446661fb

Fix: off by one error in previous commit

Fixes rB90253ad2e753acde161b38d82bd650d54d3f6581.

===

M   source/blender/nodes/intern/geometry_nodes_lazy_function.cc

===

diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index 8075694edca..1a7f1520b12 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -1088,7 +1088,7 @@ class LazyFunctionForAnonymousAttributeSetJoin : public 
lf::LazyFunction {
 constexpr int cache_amount = 16;
 static std::array 
cached_functions =
 get_cache(std::make_index_sequence{});
-if (amount <= cached_functions.size()) {
+if (amount < cached_functions.size()) {
   return cached_functions[amount];
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [90253ad2e75] master: Geometry Nodes: avoid creating a lazy function many times

2023-01-28 Thread Jacques Lucke
Commit: 90253ad2e753acde161b38d82bd650d54d3f6581
Author: Jacques Lucke
Date:   Sat Jan 28 15:28:55 2023 +0100
Branches: master
https://developer.blender.org/rB90253ad2e753acde161b38d82bd650d54d3f6581

Geometry Nodes: avoid creating a lazy function many times

It's better to use some statically allocated functions instead
of dynamically allocating them all the time.

===

M   source/blender/nodes/intern/geometry_nodes_lazy_function.cc

===

diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index 4c8a67f81b3..8075694edca 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -1078,6 +1078,33 @@ class LazyFunctionForAnonymousAttributeSetJoin : public 
lf::LazyFunction {
   {
 return 2 * i + 1;
   }
+
+  /**
+   * Cache for functions small amounts to avoid to avoid building them many 
times.
+   */
+  static const LazyFunctionForAnonymousAttributeSetJoin _cached(
+  const int amount, Vector> _functions)
+  {
+constexpr int cache_amount = 16;
+static std::array 
cached_functions =
+get_cache(std::make_index_sequence{});
+if (amount <= cached_functions.size()) {
+  return cached_functions[amount];
+}
+
+auto fn = 
std::make_unique(amount);
+const auto _ref = *fn;
+r_functions.append(std::move(fn));
+return fn_ref;
+  }
+
+ private:
+  template
+  static std::array 
get_cache(
+  std::index_sequence /*indices*/)
+  {
+return {LazyFunctionForAnonymousAttributeSetJoin(I)...};
+  }
 };
 
 enum class AttributeReferenceKeyType {
@@ -2529,18 +2556,17 @@ struct GeometryNodesLazyFunctionGraphBuilder {
 key.extend(used_sockets);
 std::sort(key.begin(), key.end());
 return cache.lookup_or_add_cb(key, [&]() {
-  auto lazy_function = 
std::make_unique(
-  attribute_set_sockets.size());
-  lf::Node _node = lf_graph_->add_function(*lazy_function);
+  const auto _function = 
LazyFunctionForAnonymousAttributeSetJoin::get_cached(
+  attribute_set_sockets.size(), lf_graph_info_->functions);
+  lf::Node _node = lf_graph_->add_function(lazy_function);
   for (const int i : attribute_set_sockets.index_range()) {
-lf::InputSocket _use_input = 
lf_node.input(lazy_function->get_use_input(i));
+lf::InputSocket _use_input = 
lf_node.input(lazy_function.get_use_input(i));
 socket_usage_inputs_.add(_use_input);
 lf::InputSocket _attributes_input = lf_node.input(
-lazy_function->get_attribute_set_input(i));
+lazy_function.get_attribute_set_input(i));
 lf_graph_->add_link(*used_sockets[i], lf_use_input);
 lf_graph_->add_link(*attribute_set_sockets[i], lf_attributes_input);
   }
-  lf_graph_info_->functions.append(std::move(lazy_function));
   return _node.output(0);
 });
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [904357d67a2] master: Fix: assert when converting between incompatible field types

2023-01-28 Thread Jacques Lucke
Commit: 904357d67a29ccc7fb512f22619288d2db182b9e
Author: Jacques Lucke
Date:   Sat Jan 28 14:52:15 2023 +0100
Branches: master
https://developer.blender.org/rB904357d67a29ccc7fb512f22619288d2db182b9e

Fix: assert when converting between incompatible field types

This results in a compile time error now which hopefully prevents
this specific kind of mistake in the future.

===

M   source/blender/functions/FN_field.hh
M   
source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc

===

diff --git a/source/blender/functions/FN_field.hh 
b/source/blender/functions/FN_field.hh
index 993558b3a18..7d1fa855206 100644
--- a/source/blender/functions/FN_field.hh
+++ b/source/blender/functions/FN_field.hh
@@ -193,6 +193,16 @@ template class Field : public GField, 
detail::TypedFieldBase {
 BLI_assert(this->cpp_type().template is());
   }
 
+  /**
+   * Generally, the constructor above would be sufficient, but this additional 
constructor ensures
+   * that trying to create e.g. a `Field` from a `Field` does not 
compile (instead of
+   * only failing at run-time).
+   */
+  template Field(Field field) : GField(std::move(field))
+  {
+static_assert(std::is_same_v);
+  }
+
   Field(std::shared_ptr node, const int node_output_index = 0)
   : Field(GField(std::move(node), node_output_index))
   {
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
 
b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
index 820fa4856a4..086a68401ed 100644
--- 
a/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
+++ 
b/source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
@@ -237,7 +237,7 @@ static void node_geo_exec(GeoNodeExecParams params)
   }
   if (params.output_is_required("Point Index")) {
 Field sort_index = params.extract_input>("Sort Index");
-Field sort_weight = params.extract_input>("Weights");
+Field sort_weight = params.extract_input>("Weights");
 if (use_start_point_special_case(curve_index, sort_index, sort_weight)) {
   params.set_output("Point Index", 
Field(std::make_shared()));
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b2534fb8661] master: Fix: anonymous attribute output requested even though it's not used

2023-01-28 Thread Jacques Lucke
Commit: b2534fb8661e4168207f2ebee70925b2d6f27421
Author: Jacques Lucke
Date:   Sat Jan 28 14:55:39 2023 +0100
Branches: master
https://developer.blender.org/rBb2534fb8661e4168207f2ebee70925b2d6f27421

Fix: anonymous attribute output requested even though it's not used

The code removed here was intended to be an optimization that
avoids creating an additional node to join multiple attribute sets.
However, that optimization did not work, because it did not take
into account whether the single attribute set is required or not.

===

M   source/blender/nodes/intern/geometry_nodes_lazy_function.cc

===

diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index 64551249e29..4c8a67f81b3 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -2523,9 +2523,6 @@ struct GeometryNodesLazyFunctionGraphBuilder {
 if (attribute_set_sockets.is_empty()) {
   return nullptr;
 }
-if (attribute_set_sockets.size() == 1) {
-  return attribute_set_sockets[0];
-}
 
 Vector key;
 key.extend(attribute_set_sockets);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [79f70e48eb9] master: Fix: crash in mesh topology nodes

2023-01-27 Thread Jacques Lucke
Commit: 79f70e48eb96609cff2f9bb45d762e230b6fe820
Author: Jacques Lucke
Date:   Fri Jan 27 12:40:08 2023 +0100
Branches: master
https://developer.blender.org/rB79f70e48eb96609cff2f9bb45d762e230b6fe820

Fix: crash in mesh topology nodes

This was broken in rBd6c9cd445cb41480b40.

===

M   
source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc
M   
source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc

===

diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc
 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc
index 8d7ebb4e105..81608271d5b 100644
--- 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc
+++ 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_corners_of_vertex.cc
@@ -123,7 +123,7 @@ class CornersOfVertInput final : public bke::MeshFieldInput 
{
   corner_of_vertex[selection_i] = 
corner_indices[sort_indices[index_in_sort_wrapped]];
 }
 else {
-  corner_of_vertex[selection_i] = 
corner_indices[index_in_sort_wrapped];
+  corner_of_vertex[selection_i] = corners[index_in_sort_wrapped];
 }
   }
 });
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc
index 7c27a4b783d..8fd1ffa5148 100644
--- 
a/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc
+++ 
b/source/blender/nodes/geometry/nodes/node_geo_mesh_topology_edges_of_vertex.cc
@@ -124,7 +124,7 @@ class EdgesOfVertInput final : public bke::MeshFieldInput {
   edge_of_vertex[selection_i] = 
edge_indices[sort_indices[index_in_sort_wrapped]];
 }
 else {
-  edge_of_vertex[selection_i] = edge_indices[index_in_sort_wrapped];
+  edge_of_vertex[selection_i] = edges[index_in_sort_wrapped];
 }
   }
 });

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4a768a7857b] master: Cleanup: remove unused variable

2023-01-26 Thread Jacques Lucke
Commit: 4a768a7857b57cb3ac0274564a510c2cf9fe00a7
Author: Jacques Lucke
Date:   Thu Jan 26 13:31:23 2023 +0100
Branches: master
https://developer.blender.org/rB4a768a7857b57cb3ac0274564a510c2cf9fe00a7

Cleanup: remove unused variable

===

M   source/blender/blenkernel/intern/node.cc

===

diff --git a/source/blender/blenkernel/intern/node.cc 
b/source/blender/blenkernel/intern/node.cc
index cb650c038e4..26b1f2f5096 100644
--- a/source/blender/blenkernel/intern/node.cc
+++ b/source/blender/blenkernel/intern/node.cc
@@ -3803,8 +3803,6 @@ void 
BKE_node_instance_hash_remove_untagged(bNodeInstanceHash *hash,
 
 void ntreeUpdateAllNew(Main *main)
 {
-  Vector new_ntrees;
-
   /* Update all new node trees on file read or append, to add/remove sockets
* in groups nodes if the group changed, and handle any update flags that
* might have been set in file reading or versioning. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8f70825923d] temp-bundled-assets: Cleanup

2023-01-24 Thread Jacques Lucke
Commit: 8f70825923dc128039d3f64427124f2b552b3656
Author: Jacques Lucke
Date:   Tue Jan 24 19:29:42 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rB8f70825923dc128039d3f64427124f2b552b3656

Cleanup

===

M   source/blender/asset_system/AS_asset_bundled.h
M   source/blender/asset_system/intern/asset_bundled.cc
M   source/blender/editors/space_file/file_draw.c

===

diff --git a/source/blender/asset_system/AS_asset_bundled.h 
b/source/blender/asset_system/AS_asset_bundled.h
index e4b03842742..fc8a6b34ac8 100644
--- a/source/blender/asset_system/AS_asset_bundled.h
+++ b/source/blender/asset_system/AS_asset_bundled.h
@@ -10,7 +10,7 @@
 extern "C" {
 #endif
 
-bool ED_asset_bundle_contains_path(const char *path);
+bool ED_asset_bundled_contains_path(const char *path);
 
 #ifdef __cplusplus
 }
diff --git a/source/blender/asset_system/intern/asset_bundled.cc 
b/source/blender/asset_system/intern/asset_bundled.cc
index 85db409777b..943d8a6428a 100644
--- a/source/blender/asset_system/intern/asset_bundled.cc
+++ b/source/blender/asset_system/intern/asset_bundled.cc
@@ -4,7 +4,7 @@
  * \ingroup asset_system
  */
 
-#include "BLI_string.h"
+#include "BLI_path_util.h"
 
 #include "BKE_appdir.h"
 
@@ -23,9 +23,9 @@ StringRefNull bundled_assets_directory_path()
 
 }  // namespace blender::asset_system
 
-bool ED_asset_bundle_contains_path(const char *path)
+bool ED_asset_bundled_contains_path(const char *path)
 {
   const blender::StringRefNull bundled_path =
   blender::asset_system::bundled_assets_directory_path();
-  return BLI_str_startswith(path, bundled_path.c_str());
+  return BLI_path_contains(bundled_path.c_str(), path);
 }
diff --git a/source/blender/editors/space_file/file_draw.c 
b/source/blender/editors/space_file/file_draw.c
index 62779692fcf..216a83b050c 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -130,7 +130,7 @@ static void draw_tile_background(const rcti *draw_rect, int 
colorid, int shade)
 
 static eFileAssetImportType get_asset_import_type(const SpaceFile *sfile, 
const char *blend_path)
 {
-  if (ED_asset_bundle_contains_path(blend_path)) {
+  if (ED_asset_bundled_contains_path(blend_path)) {
 return FILE_ASSET_IMPORT_APPEND_REUSE;
   }
   const FileAssetSelectParams *asset_params = 
ED_fileselect_get_asset_params(sfile);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [cd9ab37373f] temp-bundled-assets: progress

2023-01-24 Thread Jacques Lucke
Commit: cd9ab37373f827b03ed340681a9c20baf1499a38
Author: Jacques Lucke
Date:   Wed Jan 18 16:14:46 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rBcd9ab37373f827b03ed340681a9c20baf1499a38

progress

===

A   source/blender/asset_system/AS_asset_bundled.hh
M   source/blender/asset_system/CMakeLists.txt
A   source/blender/asset_system/intern/asset_bundled.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/editors/space_file/filesel.cc

===

diff --git a/source/blender/asset_system/AS_asset_bundled.hh 
b/source/blender/asset_system/AS_asset_bundled.hh
new file mode 100644
index 000..8031e39a144
--- /dev/null
+++ b/source/blender/asset_system/AS_asset_bundled.hh
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup asset_system
+ */
+
+#pragma once
+
+#include "BLI_string_ref.hh"
+
+namespace blender::asset_system {
+
+StringRefNull bundled_assets_directory_path();
+
+}
diff --git a/source/blender/asset_system/CMakeLists.txt 
b/source/blender/asset_system/CMakeLists.txt
index f8e1df40d80..aff4897d38d 100644
--- a/source/blender/asset_system/CMakeLists.txt
+++ b/source/blender/asset_system/CMakeLists.txt
@@ -14,6 +14,7 @@ set(INC_SYS
 )
 
 set(SRC
+  intern/asset_bundled.cc
   intern/asset_catalog.cc
   intern/asset_catalog_path.cc
   intern/asset_catalog_tree.cc
@@ -24,6 +25,7 @@ set(SRC
   intern/asset_storage.cc
   intern/utils.cc
 
+  AS_asset_bundled.hh
   AS_asset_catalog.hh
   AS_asset_catalog_path.hh
   AS_asset_catalog_tree.hh
diff --git a/source/blender/asset_system/intern/asset_bundled.cc 
b/source/blender/asset_system/intern/asset_bundled.cc
new file mode 100644
index 000..76481ac33da
--- /dev/null
+++ b/source/blender/asset_system/intern/asset_bundled.cc
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup asset_system
+ */
+
+#include "AS_asset_bundled.hh"
+
+namespace blender::asset_system {
+
+StringRefNull bundled_assets_directory_path()
+{
+  return 
"/home/jacques/blender/build_release/bin/3.5/datafiles/assets/base_meshes";
+}
+
+}  // namespace blender::asset_system
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index af6011af832..5618ca83c6f 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -14,6 +14,7 @@
 
 #include "CLG_log.h"
 
+#include "AS_asset_bundled.hh"
 #include "AS_asset_catalog_tree.hh"
 #include "AS_asset_library.hh"
 #include "asset_library_service.hh"
@@ -61,8 +62,7 @@ AssetLibrary *AssetLibraryService::get_asset_library(
 
   switch (type) {
 case ASSET_LIBRARY_BUNDLED: {
-  const std::string root_path =
-  
"/home/jacques/blender/build_release/bin/3.5/datafiles/assets/base_meshes";
+  const StringRefNull root_path = bundled_assets_directory_path();
   return get_asset_library_on_disk(root_path);
 }
 case ASSET_LIBRARY_LOCAL: {
diff --git a/source/blender/editors/space_file/filesel.cc 
b/source/blender/editors/space_file/filesel.cc
index cbd4e1d7836..7b077349f3e 100644
--- a/source/blender/editors/space_file/filesel.cc
+++ b/source/blender/editors/space_file/filesel.cc
@@ -58,6 +58,8 @@
 #include "UI_interface_icons.h"
 #include "UI_view2d.h"
 
+#include "AS_asset_bundled.hh"
+
 #include "file_intern.h"
 #include "filelist.h"
 
@@ -427,7 +429,7 @@ static void 
fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
   switch (eAssetLibraryType(library->type)) {
 case ASSET_LIBRARY_BUNDLED:
   BLI_strncpy(base_params->dir,
-  
"/home/jacques/blender/build_release/bin/3.5/datafiles/assets/base_meshes",
+  
blender::asset_system::bundled_assets_directory_path().c_str(),
   sizeof(base_params->dir));
   base_params->type = FILE_ASSET_LIBRARY;
   break;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1b11d52a814] temp-bundled-assets: use another identifier for bundled asset lib

2023-01-24 Thread Jacques Lucke
Commit: 1b11d52a8145fc621fa9243bcc66373ca391bd68
Author: Jacques Lucke
Date:   Tue Jan 24 18:56:27 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rB1b11d52a8145fc621fa9243bcc66373ca391bd68

use another identifier for bundled asset lib

===

M   source/blender/makesdna/DNA_asset_types.h

===

diff --git a/source/blender/makesdna/DNA_asset_types.h 
b/source/blender/makesdna/DNA_asset_types.h
index 504d05d45dd..fa77a0b90a6 100644
--- a/source/blender/makesdna/DNA_asset_types.h
+++ b/source/blender/makesdna/DNA_asset_types.h
@@ -85,11 +85,11 @@ typedef struct AssetMetaData {
 } AssetMetaData;
 
 typedef enum eAssetLibraryType {
-  /* For the future. Display assets bundled with Blender by default. */
-  ASSET_LIBRARY_BUNDLED = 0,
   /** Display assets from the current session (current "Main"). */
   ASSET_LIBRARY_LOCAL = 1,
   ASSET_LIBRARY_ALL = 2,
+  /* Display assets bundled with Blender by default. */
+  ASSET_LIBRARY_BUNDLED = 3,
 
   /** Display assets from custom asset libraries, as defined in the preferences
* (#bUserAssetLibrary). The name will be taken from 
#FileSelectParams.asset_library_ref.idname

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d2fc31f178a] temp-bundled-assets: use append-and-reuse for bundled assets

2023-01-24 Thread Jacques Lucke
Commit: d2fc31f178a1b18e3f4ddaf23f5a8c59efd504ed
Author: Jacques Lucke
Date:   Tue Jan 24 19:23:46 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rBd2fc31f178a1b18e3f4ddaf23f5a8c59efd504ed

use append-and-reuse for bundled assets

===

A   source/blender/asset_system/AS_asset_bundled.h
M   source/blender/asset_system/AS_asset_bundled.hh
M   source/blender/asset_system/intern/asset_bundled.cc
M   source/blender/editors/space_file/file_draw.c

===

diff --git a/source/blender/asset_system/AS_asset_bundled.h 
b/source/blender/asset_system/AS_asset_bundled.h
new file mode 100644
index 000..e4b03842742
--- /dev/null
+++ b/source/blender/asset_system/AS_asset_bundled.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+
+/** \file
+ * \ingroup asset_system
+ */
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+bool ED_asset_bundle_contains_path(const char *path);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/source/blender/asset_system/AS_asset_bundled.hh 
b/source/blender/asset_system/AS_asset_bundled.hh
index 8031e39a144..5f2d4a14780 100644
--- a/source/blender/asset_system/AS_asset_bundled.hh
+++ b/source/blender/asset_system/AS_asset_bundled.hh
@@ -8,6 +8,8 @@
 
 #include "BLI_string_ref.hh"
 
+#include "AS_asset_bundled.h"
+
 namespace blender::asset_system {
 
 StringRefNull bundled_assets_directory_path();
diff --git a/source/blender/asset_system/intern/asset_bundled.cc 
b/source/blender/asset_system/intern/asset_bundled.cc
index 7e1d4dda009..85db409777b 100644
--- a/source/blender/asset_system/intern/asset_bundled.cc
+++ b/source/blender/asset_system/intern/asset_bundled.cc
@@ -4,6 +4,8 @@
  * \ingroup asset_system
  */
 
+#include "BLI_string.h"
+
 #include "BKE_appdir.h"
 
 #include "AS_asset_bundled.hh"
@@ -20,3 +22,10 @@ StringRefNull bundled_assets_directory_path()
 }
 
 }  // namespace blender::asset_system
+
+bool ED_asset_bundle_contains_path(const char *path)
+{
+  const blender::StringRefNull bundled_path =
+  blender::asset_system::bundled_assets_directory_path();
+  return BLI_str_startswith(path, bundled_path.c_str());
+}
diff --git a/source/blender/editors/space_file/file_draw.c 
b/source/blender/editors/space_file/file_draw.c
index e85a6cbc0d4..62779692fcf 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -55,6 +55,8 @@
 #include "GPU_immediate_util.h"
 #include "GPU_state.h"
 
+#include "AS_asset_bundled.h"
+
 #include "filelist.h"
 
 #include "file_intern.h" /* own include */
@@ -126,6 +128,16 @@ static void draw_tile_background(const rcti *draw_rect, 
int colorid, int shade)
   UI_draw_roundbox_aa(_rect_fl, true, 5.0f, color);
 }
 
+static eFileAssetImportType get_asset_import_type(const SpaceFile *sfile, 
const char *blend_path)
+{
+  if (ED_asset_bundle_contains_path(blend_path)) {
+return FILE_ASSET_IMPORT_APPEND_REUSE;
+  }
+  const FileAssetSelectParams *asset_params = 
ED_fileselect_get_asset_params(sfile);
+  BLI_assert(asset_params != NULL);
+  return asset_params->import_type;
+}
+
 static void file_draw_icon(const SpaceFile *sfile,
uiBlock *block,
const FileDirEntry *file,
@@ -165,13 +177,10 @@ static void file_draw_icon(const SpaceFile *sfile,
   ImBuf *preview_image = filelist_file_getimage(file);
   char blend_path[FILE_MAX_LIBEXTRA];
   if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
-const FileAssetSelectParams *asset_params = 
ED_fileselect_get_asset_params(sfile);
-BLI_assert(asset_params != NULL);
-
 UI_but_drag_set_asset(but,
   &(AssetHandle){.file_data = file},
   BLI_strdup(blend_path),
-  asset_params->import_type,
+  get_asset_import_type(sfile, blend_path),
   icon,
   preview_image,
   UI_DPI_FAC);
@@ -558,13 +567,10 @@ static void file_draw_preview(const SpaceFile *sfile,
   char blend_path[FILE_MAX_LIBEXTRA];
 
   if (BLO_library_path_explode(path, blend_path, NULL, NULL)) {
-const FileAssetSelectParams *asset_params = 
ED_fileselect_get_asset_params(sfile);
-BLI_assert(asset_params != NULL);
-
 UI_but_drag_set_asset(but,
   &(AssetHandle){.file_data = file},
   BLI_strdup(blend_path),
-  asset_params->import_type,
+  get_asset_import_type(sfile, blend_path),
   icon,
   

[Bf-blender-cvs] [3f962b8e283] temp-bundled-assets: remove null check

2023-01-24 Thread Jacques Lucke
Commit: 3f962b8e28365976778af1354b773b8da983042b
Author: Jacques Lucke
Date:   Tue Jan 24 19:02:03 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rB3f962b8e28365976778af1354b773b8da983042b

remove null check

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index c594dd42584..57a4c5c052a 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -829,9 +829,6 @@ static bool asset_tag_matches_filter(const char 
*filter_search, const AssetMetaD
 static bool is_filtered_asset(FileListInternEntry *file, FileListFilter 
*filter)
 {
   const AssetMetaData *asset_data = 
filelist_file_internal_get_asset_data(file);
-  if (asset_data == nullptr) {
-return false;
-  }
 
   /* Not used yet for the asset view template. */
   if (filter->asset_catalog_filter && 
!file_is_asset_visible_in_catalog_filter_settings(

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f506e891f26] temp-bundled-assets: Merge branch 'master' into asset-bundle

2023-01-24 Thread Jacques Lucke
Commit: f506e891f26bebc87b54b6f9a983c8f376a95bc4
Author: Jacques Lucke
Date:   Tue Jan 24 18:50:46 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rBf506e891f26bebc87b54b6f9a983c8f376a95bc4

Merge branch 'master' into asset-bundle

===



===



___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [807e85976ae] temp-bundled-assets: initial assets

2023-01-24 Thread Jacques Lucke
Commit: 807e85976ae0b962740bfff927ba40a13b91df68
Author: Jacques Lucke
Date:   Wed Jan 18 16:01:34 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rB807e85976ae0b962740bfff927ba40a13b91df68

initial assets

===

M   source/blender/asset_system/intern/asset_library.cc
M   source/blender/asset_system/intern/asset_library_service.cc
M   source/blender/editors/asset/intern/asset_library_reference_enum.cc
M   source/blender/editors/asset/intern/asset_list.cc
M   source/blender/editors/space_file/filesel.cc
M   source/blender/makesdna/DNA_asset_types.h

===

diff --git a/source/blender/asset_system/intern/asset_library.cc 
b/source/blender/asset_system/intern/asset_library.cc
index 2379e738e37..d7fb16f99ac 100644
--- a/source/blender/asset_system/intern/asset_library.cc
+++ b/source/blender/asset_system/intern/asset_library.cc
@@ -259,6 +259,12 @@ StringRefNull AssetLibrary::root_path() const
 Vector all_valid_asset_library_refs()
 {
   Vector result;
+  {
+AssetLibraryReference library_ref{};
+library_ref.custom_library_index = -1;
+library_ref.type = ASSET_LIBRARY_BUNDLED;
+result.append(library_ref);
+  }
   int i;
   LISTBASE_FOREACH_INDEX (const bUserAssetLibrary *, asset_library, 
_libraries, i) {
 if (!BLI_is_dir(asset_library->path)) {
diff --git a/source/blender/asset_system/intern/asset_library_service.cc 
b/source/blender/asset_system/intern/asset_library_service.cc
index af48a173bc0..af6011af832 100644
--- a/source/blender/asset_system/intern/asset_library_service.cc
+++ b/source/blender/asset_system/intern/asset_library_service.cc
@@ -60,6 +60,11 @@ AssetLibrary *AssetLibraryService::get_asset_library(
   const eAssetLibraryType type = eAssetLibraryType(library_reference.type);
 
   switch (type) {
+case ASSET_LIBRARY_BUNDLED: {
+  const std::string root_path =
+  
"/home/jacques/blender/build_release/bin/3.5/datafiles/assets/base_meshes";
+  return get_asset_library_on_disk(root_path);
+}
 case ASSET_LIBRARY_LOCAL: {
   /* For the "Current File" library  we get the asset library root path 
based on main. */
   std::string root_path = bmain ? 
AS_asset_library_find_suitable_root_path_from_main(bmain) :
diff --git 
a/source/blender/editors/asset/intern/asset_library_reference_enum.cc 
b/source/blender/editors/asset/intern/asset_library_reference_enum.cc
index d20f3205a77..14051a3adb3 100644
--- a/source/blender/editors/asset/intern/asset_library_reference_enum.cc
+++ b/source/blender/editors/asset/intern/asset_library_reference_enum.cc
@@ -47,7 +47,7 @@ AssetLibraryReference 
ED_asset_library_reference_from_enum_value(int value)
   if (value < ASSET_LIBRARY_CUSTOM) {
 library.type = value;
 library.custom_library_index = -1;
-BLI_assert(ELEM(value, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL));
+BLI_assert(ELEM(value, ASSET_LIBRARY_ALL, ASSET_LIBRARY_LOCAL, 
ASSET_LIBRARY_BUNDLED));
 return library;
   }
 
@@ -100,6 +100,18 @@ const EnumPropertyItem 
*ED_asset_library_reference_to_rna_enum_itemf(const bool
 RNA_enum_item_add_separator(, );
   }
 
+  {
+AssetLibraryReference library_reference;
+library_reference.type = ASSET_LIBRARY_BUNDLED;
+library_reference.custom_library_index = -1;
+const int enum_value = 
ED_asset_library_reference_to_enum_value(_reference);
+EnumPropertyItem tmp = {
+enum_value, "BUNDLED", ICON_NONE, "Bundled", "Show assets that came 
bundled with Blender"};
+RNA_enum_item_add(, , );
+  }
+
+  RNA_enum_item_add_separator(, );
+
   int i;
   LISTBASE_FOREACH_INDEX (bUserAssetLibrary *, user_library, 
_libraries, i) {
 /* Note that the path itself isn't checked for validity here. If an 
invalid library path is
diff --git a/source/blender/editors/asset/intern/asset_list.cc 
b/source/blender/editors/asset/intern/asset_list.cc
index 64934316413..1749391356c 100644
--- a/source/blender/editors/asset/intern/asset_list.cc
+++ b/source/blender/editors/asset/intern/asset_list.cc
@@ -372,6 +372,7 @@ std::optional 
AssetListStorage::asset_library_reference_to_file
   switch (eAssetLibraryType(library_reference.type)) {
 case ASSET_LIBRARY_ALL:
   return FILE_ASSET_LIBRARY_ALL;
+case ASSET_LIBRARY_BUNDLED:
 case ASSET_LIBRARY_CUSTOM:
   return FILE_ASSET_LIBRARY;
 case ASSET_LIBRARY_LOCAL:
diff --git a/source/blender/editors/space_file/filesel.cc 
b/source/blender/editors/space_file/filesel.cc
index 12d05054e9b..cbd4e1d7836 100644
--- a/source/blender/editors/space_file/filesel.cc
+++ b/source/blender/editors/space_file/filesel.cc
@@ -424,7 +424,13 @@ static void 
fileselect_refresh_asset_params(FileAssetSelectParams *asset_params)
 }
   }
 
-  switch (library->type) {
+  switch (eAssetLibraryType(library->type)) {
+

[Bf-blender-cvs] [3d90d1acd46] temp-bundled-assets: Assets: Bundle essentials with Blender. (WIP)

2023-01-24 Thread Jacques Lucke
Commit: 3d90d1acd46938103082bcd5329dfe008107a419
Author: Jacques Lucke
Date:   Wed Jan 18 16:48:13 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rB3d90d1acd46938103082bcd5329dfe008107a419

Assets: Bundle essentials with Blender. (WIP)

Differential Revision: https://developer.blender.org/D17031

===

M   source/blender/editors/space_file/filelist.cc

===

diff --git a/source/blender/editors/space_file/filelist.cc 
b/source/blender/editors/space_file/filelist.cc
index 22986672650..6c80a680a49 100644
--- a/source/blender/editors/space_file/filelist.cc
+++ b/source/blender/editors/space_file/filelist.cc
@@ -829,6 +829,9 @@ static bool asset_tag_matches_filter(const char 
*filter_search, const AssetMetaD
 static bool is_filtered_asset(FileListInternEntry *file, FileListFilter 
*filter)
 {
   const AssetMetaData *asset_data = 
filelist_file_internal_get_asset_data(file);
+  if (asset_data == nullptr) {
+return false;
+  }
 
   /* Not used yet for the asset view template. */
   if (filter->asset_catalog_filter && 
!file_is_asset_visible_in_catalog_filter_settings(

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [fe6ae405c59] temp-bundled-assets: remove hardcoded path

2023-01-24 Thread Jacques Lucke
Commit: fe6ae405c5917da828c814d907ce4c304ef5bf49
Author: Jacques Lucke
Date:   Wed Jan 18 16:22:07 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rBfe6ae405c5917da828c814d907ce4c304ef5bf49

remove hardcoded path

===

M   source/blender/asset_system/intern/asset_bundled.cc

===

diff --git a/source/blender/asset_system/intern/asset_bundled.cc 
b/source/blender/asset_system/intern/asset_bundled.cc
index 76481ac33da..7e1d4dda009 100644
--- a/source/blender/asset_system/intern/asset_bundled.cc
+++ b/source/blender/asset_system/intern/asset_bundled.cc
@@ -4,13 +4,19 @@
  * \ingroup asset_system
  */
 
+#include "BKE_appdir.h"
+
 #include "AS_asset_bundled.hh"
 
 namespace blender::asset_system {
 
 StringRefNull bundled_assets_directory_path()
 {
-  return 
"/home/jacques/blender/build_release/bin/3.5/datafiles/assets/base_meshes";
+  static std::string path = []() {
+const char *datafiles_path = BKE_appdir_folder_id(BLENDER_DATAFILES, 
"assets");
+return datafiles_path;
+  }();
+  return path;
 }
 
 }  // namespace blender::asset_system

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3bc5595d5a5] temp-bundled-assets: cleanup

2023-01-24 Thread Jacques Lucke
Commit: 3bc5595d5a5d827c800e98beed4a3511dda5fc96
Author: Jacques Lucke
Date:   Wed Jan 18 16:05:00 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rB3bc5595d5a5d827c800e98beed4a3511dda5fc96

cleanup

===

M   source/blender/editors/asset/intern/asset_library_reference_enum.cc

===

diff --git 
a/source/blender/editors/asset/intern/asset_library_reference_enum.cc 
b/source/blender/editors/asset/intern/asset_library_reference_enum.cc
index 14051a3adb3..79c42c2c20e 100644
--- a/source/blender/editors/asset/intern/asset_library_reference_enum.cc
+++ b/source/blender/editors/asset/intern/asset_library_reference_enum.cc
@@ -95,18 +95,16 @@ const EnumPropertyItem 
*ED_asset_library_reference_to_rna_enum_itemf(const bool
 RNA_enum_items_add(, , generated_items);
   }
 
-  /* Add separator if needed. */
-  if (!BLI_listbase_is_empty(_libraries)) {
-RNA_enum_item_add_separator(, );
-  }
-
   {
 AssetLibraryReference library_reference;
 library_reference.type = ASSET_LIBRARY_BUNDLED;
 library_reference.custom_library_index = -1;
 const int enum_value = 
ED_asset_library_reference_to_enum_value(_reference);
-EnumPropertyItem tmp = {
-enum_value, "BUNDLED", ICON_NONE, "Bundled", "Show assets that came 
bundled with Blender"};
+EnumPropertyItem tmp = {enum_value,
+"ESSENTIALS",
+ICON_NONE,
+"Essentials",
+"Show assets that came bundled with Blender"};
 RNA_enum_item_add(, , );
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [873003975b6] temp-bundled-assets: initial bundling

2023-01-24 Thread Jacques Lucke
Commit: 873003975b6a1895134231d0746c34b79a4f130f
Author: Jacques Lucke
Date:   Wed Jan 18 14:28:51 2023 +0100
Branches: temp-bundled-assets
https://developer.blender.org/rB873003975b6a1895134231d0746c34b79a4f130f

initial bundling

===

M   build_files/utils/make_update.py
M   source/creator/CMakeLists.txt

===

diff --git a/build_files/utils/make_update.py b/build_files/utils/make_update.py
index fbadeecd597..bf01a7a7f76 100755
--- a/build_files/utils/make_update.py
+++ b/build_files/utils/make_update.py
@@ -104,6 +104,19 @@ def svn_update(args: argparse.Namespace, release_version: 
Optional[str]) -> None
 svn_url_tests = svn_url + lib_tests
 call(svn_non_interactive + ["checkout", svn_url_tests, 
lib_tests_dirpath])
 
+lib_assets = "assets"
+lib_assets_dirpath = os.path.join(lib_dirpath, lib_assets)
+
+if os.path.exists(lib_assets_dirpath):
+print_stage("Checking out Assets")
+
+if make_utils.command_missing(args.svn_command):
+sys.stderr.write("svn not found, can't checkout assets\n")
+sys.exit(1)
+
+svn_url_assets = svn_url + lib_assets
+call(svn_non_interactive + ["checkout", svn_url_assets, 
lib_assets_dirpath])
+
 # Update precompiled libraries and tests
 
 if not os.path.isdir(lib_dirpath):
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index 1cf908b4821..d02b8cfe4ec 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -1471,6 +1471,20 @@ install(
 )
 
 
+# -
+# Bundle assets
+
+set(ASSET_BUNDLE_DIR ${CMAKE_SOURCE_DIR}/../lib/assets)
+
+if(EXISTS "${ASSET_BUNDLE_DIR}")
+  install(
+DIRECTORY ${ASSET_BUNDLE_DIR}
+DESTINATION ${TARGETDIR_VER}/datafiles
+PATTERN ".svn" EXCLUDE
+  )
+endif()
+
+
 # -
 # Setup link libraries

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ae80a6696fe] master: Geometry Nodes: don't show warning in modifier with multiple geometry inputs

2023-01-24 Thread Jacques Lucke
Commit: ae80a6696febe96b329cbad94502b643aba790b0
Author: Jacques Lucke
Date:   Tue Jan 24 17:45:47 2023 +0100
Branches: master
https://developer.blender.org/rBae80a6696febe96b329cbad94502b643aba790b0

Geometry Nodes: don't show warning in modifier with multiple geometry inputs

Simon mentioned that this gets in the way more than it helps. No geometry
sockets currently show up in the modifier panel. People may build node groups
that have multiple geometry inputs that can be used when the group is used
as node instead of as modifier.

In the future we could also allow e.g. choosing an object to pass into a 
geometry
socket. That has the problem that we'd also have to duplicate other 
functionality
of the Object Info node (original vs. relative space).

===

M   source/blender/modifiers/intern/MOD_nodes.cc

===

diff --git a/source/blender/modifiers/intern/MOD_nodes.cc 
b/source/blender/modifiers/intern/MOD_nodes.cc
index a23156dd3c8..da623881548 100644
--- a/source/blender/modifiers/intern/MOD_nodes.cc
+++ b/source/blender/modifiers/intern/MOD_nodes.cc
@@ -1280,9 +1280,6 @@ static void check_property_socket_sync(const Object *ob, 
ModifierData *md)
   BKE_modifier_set_error(ob, md, "Node group's geometry input must be the 
first");
 }
   }
-  else if (geometry_socket_count > 1) {
-BKE_modifier_set_error(ob, md, "Node group can only have one geometry 
input");
-  }
 }
 
 static void modifyGeometry(ModifierData *md,

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6899474615d] master: Fix: crash when adding curves in curves sculpt mode with interpolation

2023-01-24 Thread Jacques Lucke
Commit: 6899474615dfb35b455fc05d91dadd066f60ae97
Author: Jacques Lucke
Date:   Tue Jan 24 17:30:24 2023 +0100
Branches: master
https://developer.blender.org/rB6899474615dfb35b455fc05d91dadd066f60ae97

Fix: crash when adding curves in curves sculpt mode with interpolation

There were two issues:
* The `new_point_counts_per_curve` was one too large, resulting in
  `interpolate_from_neighbors` reading invalid memory.
* Writing the counts into the existing offsets array didn't quite work
  because there can be a collision at the offset right between the
  last old curve and the first new point. There was a race condition
  where this value could be read and written at the same time.

===

M   source/blender/geometry/intern/add_curves_on_mesh.cc

===

diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc 
b/source/blender/geometry/intern/add_curves_on_mesh.cc
index 2ef51867e07..5f174558e29 100644
--- a/source/blender/geometry/intern/add_curves_on_mesh.cc
+++ b/source/blender/geometry/intern/add_curves_on_mesh.cc
@@ -286,19 +286,25 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry 
,
 
   /* Compute new curve offsets. */
   MutableSpan curve_offsets = curves.offsets_for_write();
-  MutableSpan new_point_counts_per_curve = 
curve_offsets.drop_front(old_curves_num);
-  if (inputs.interpolate_point_count) {
+  Array new_point_counts_per_curve(added_curves_num);
+  if (inputs.interpolate_point_count && old_curves_num > 0) {
+const OffsetIndices 
old_points_by_curve{curve_offsets.take_front(old_curves_num + 1)};
 interpolate_from_neighbors(
 neighbors_per_curve,
 inputs.fallback_point_count,
-[&](const int curve_i) { return curve_offsets[curve_i + 1] - 
curve_offsets[curve_i]; },
+[&](const int curve_i) { return old_points_by_curve.size(curve_i); },
 new_point_counts_per_curve);
   }
   else {
 new_point_counts_per_curve.fill(inputs.fallback_point_count);
   }
-  
offset_indices::accumulate_counts_to_offsets(curve_offsets.drop_front(old_curves_num),
-   old_points_num);
+  curve_offsets[old_curves_num] = old_points_num;
+  int offset = old_points_num;
+  for (const int i : new_point_counts_per_curve.index_range()) {
+const int point_count_in_curve = new_point_counts_per_curve[i];
+curve_offsets[old_curves_num + i + 1] = offset + point_count_in_curve;
+offset += point_count_in_curve;
+  }
 
   const int new_points_num = curves.offsets().last();
   curves.resize(new_points_num, new_curves_num);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [813425877b6] master: Geometry Nodes: propagate material from guides in Interpolate Curves node

2023-01-24 Thread Jacques Lucke
Commit: 813425877b632e3e1ddeaaa9ef6f3a0367e46fb1
Author: Jacques Lucke
Date:   Tue Jan 24 16:24:00 2023 +0100
Branches: master
https://developer.blender.org/rB813425877b632e3e1ddeaaa9ef6f3a0367e46fb1

Geometry Nodes: propagate material from guides in Interpolate Curves node

This was missing from the original implementation.

===

M   source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc 
b/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
index c4f275334a8..dc3b24e4fae 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
@@ -747,6 +747,11 @@ static GeometrySet generate_interpolated_curves(
   all_neighbor_indices,
   all_neighbor_weights);
 
+  if (guide_curves_id.mat != nullptr) {
+child_curves_id->mat = static_cast(MEM_dupallocN(guide_curves_id.mat));
+child_curves_id->totcol = guide_curves_id.totcol;
+  }
+
   return GeometrySet::create_with_curves(child_curves_id);
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [33edef15ed4] master: Fix T104095: missing crazy space data while sculpting curves

2023-01-24 Thread Jacques Lucke
Commit: 33edef15ed405281debe6bc81ae822daff25bbf4
Author: Jacques Lucke
Date:   Tue Jan 24 14:06:43 2023 +0100
Branches: master
https://developer.blender.org/rB33edef15ed405281debe6bc81ae822daff25bbf4

Fix T104095: missing crazy space data while sculpting curves

`remember_deformed_curve_positions_if_necessary` has to be called before
topology changing operations on curves. Otherwise the crazy-space data
is invalid.

===

M   source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
M   source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc 
b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
index d49f2583bde..18a662289aa 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc
@@ -192,6 +192,10 @@ static void node_geo_exec(GeoNodeExecParams params)
   const AnonymousAttributePropagationInfo _info = 
params.get_output_propagation_info(
   "Geometry");
 
+  for (GeometrySet  : geometry_sets) {
+
GeometryComponentEditData::remember_deformed_curve_positions_if_necessary(geometry);
+  }
+
   GeometrySet geometry_set_result;
   join_component_type(geometry_sets, geometry_set_result, 
propagation_info);
   join_component_type(geometry_sets, geometry_set_result, 
propagation_info);
diff --git a/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc 
b/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc
index 385b47a2f1e..18311e9ca58 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_realize_instances.cc
@@ -34,6 +34,7 @@ static void node_geo_exec(GeoNodeExecParams params)
   }
 
   GeometrySet geometry_set = params.extract_input("Geometry");
+  
GeometryComponentEditData::remember_deformed_curve_positions_if_necessary(geometry_set);
   geometry::RealizeInstancesOptions options;
   options.keep_original_ids = legacy_behavior;
   options.realize_instance_attributes = !legacy_behavior;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c16bd343168] master: Fix: memory allocation before guarded allocator is initialized

2023-01-24 Thread Jacques Lucke
Commit: c16bd343168d72d9fea2c440d91565d7701b1cea
Author: Jacques Lucke
Date:   Tue Jan 24 13:07:54 2023 +0100
Branches: master
https://developer.blender.org/rBc16bd343168d72d9fea2c440d91565d7701b1cea

Fix: memory allocation before guarded allocator is initialized

Use the construct-on-first-use idiom to fix this.

===

M   source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc

===

diff --git 
a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc 
b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
index 6b0b2e75c27..75be8279037 100644
--- a/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
+++ b/source/blender/draw/engines/workbench/workbench_effect_antialiasing.cc
@@ -74,7 +74,11 @@ class TaaSamples {
   }
 };
 
-static TaaSamples TAA_SAMPLES = TaaSamples();
+static const TaaSamples _taa_samples()
+{
+  static const TaaSamples taa_samples;
+  return taa_samples;
+}
 
 static float filter_blackman_harris(float x, const float width)
 {
@@ -195,23 +199,25 @@ void AntiAliasingPass::setup_view(View , int2 
resolution)
 return;
   }
 
+  const TaaSamples _samples = get_taa_samples();
+
   float2 sample_offset;
   switch (samples_len_) {
 default:
 case 5:
-  sample_offset = TAA_SAMPLES.x5[sample_];
+  sample_offset = taa_samples.x5[sample_];
   break;
 case 8:
-  sample_offset = TAA_SAMPLES.x8[sample_];
+  sample_offset = taa_samples.x8[sample_];
   break;
 case 11:
-  sample_offset = TAA_SAMPLES.x11[sample_];
+  sample_offset = taa_samples.x11[sample_];
   break;
 case 16:
-  sample_offset = TAA_SAMPLES.x16[sample_];
+  sample_offset = taa_samples.x16[sample_];
   break;
 case 32:
-  sample_offset = TAA_SAMPLES.x32[sample_];
+  sample_offset = taa_samples.x32[sample_];
   break;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [6043ed9e62e] master: Build: checkout assets directory automatically

2023-01-23 Thread Jacques Lucke
Commit: 6043ed9e62ec9c72f04930c711e65142675b4187
Author: Jacques Lucke
Date:   Mon Jan 23 13:52:21 2023 +0100
Branches: master
https://developer.blender.org/rB6043ed9e62ec9c72f04930c711e65142675b4187

Build: checkout assets directory automatically

This changes `make update` to download the assets repository automatically
if it does not exist already. If it does exist, it is updated. Precompiled 
libraries
have the same behavior. This is required for T103620.

`pipeline_config.yaml` is updated as well for the builtbot.

Differential Revision: https://developer.blender.org/D17090

===

M   build_files/config/pipeline_config.yaml
M   build_files/utils/make_update.py

===

diff --git a/build_files/config/pipeline_config.yaml 
b/build_files/config/pipeline_config.yaml
index 392bd842586..88ca5108e8b 100644
--- a/build_files/config/pipeline_config.yaml
+++ b/build_files/config/pipeline_config.yaml
@@ -43,6 +43,10 @@ update-code:
 branch: trunk
 commit_id: HEAD
 path: lib/benchmarks
+assets:
+branch: trunk
+commit_id: HEAD
+path: lib/assets
 
 #
 # Buildbot only configs
diff --git a/build_files/utils/make_update.py b/build_files/utils/make_update.py
index fbadeecd597..2288a9972b8 100755
--- a/build_files/utils/make_update.py
+++ b/build_files/utils/make_update.py
@@ -104,17 +104,30 @@ def svn_update(args: argparse.Namespace, release_version: 
Optional[str]) -> None
 svn_url_tests = svn_url + lib_tests
 call(svn_non_interactive + ["checkout", svn_url_tests, 
lib_tests_dirpath])
 
-# Update precompiled libraries and tests
+lib_assets = "assets"
+lib_assets_dirpath = os.path.join(lib_dirpath, lib_assets)
+
+if not os.path.exists(lib_assets_dirpath):
+print_stage("Checking out Assets")
+
+if make_utils.command_missing(args.svn_command):
+sys.stderr.write("svn not found, can't checkout assets\n")
+sys.exit(1)
+
+svn_url_assets = svn_url + lib_assets
+call(svn_non_interactive + ["checkout", svn_url_assets, 
lib_assets_dirpath])
+
+# Update precompiled libraries, assets and tests
 
 if not os.path.isdir(lib_dirpath):
 print("Library path: %r, not found, skipping" % lib_dirpath)
 else:
 paths_local_and_remote = []
 if os.path.exists(os.path.join(lib_dirpath, ".svn")):
-print_stage("Updating Precompiled Libraries and Tests (one 
repository)")
+print_stage("Updating Precompiled Libraries, Assets and Tests (one 
repository)")
 paths_local_and_remote.append((lib_dirpath, svn_url))
 else:
-print_stage("Updating Precompiled Libraries and Tests (multiple 
repositories)")
+print_stage("Updating Precompiled Libraries, Assets and Tests 
(multiple repositories)")
 # Separate paths checked out.
 for dirname in os.listdir(lib_dirpath):
 if dirname.startswith("."):

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c68d4bf8393] master: Cleanup: fix msvc compilation issue

2023-01-22 Thread Jacques Lucke
Commit: c68d4bf8393895cb57c7e0cd4e9d65cf0b482cf9
Author: Jacques Lucke
Date:   Mon Jan 23 02:16:35 2023 +0100
Branches: master
https://developer.blender.org/rBc68d4bf8393895cb57c7e0cd4e9d65cf0b482cf9

Cleanup: fix msvc compilation issue

===

M   source/blender/blenkernel/intern/blendfile.cc

===

diff --git a/source/blender/blenkernel/intern/blendfile.cc 
b/source/blender/blenkernel/intern/blendfile.cc
index 2ac2ae43684..68f37df9ca9 100644
--- a/source/blender/blenkernel/intern/blendfile.cc
+++ b/source/blender/blenkernel/intern/blendfile.cc
@@ -640,7 +640,7 @@ UserDef *BKE_blendfile_userdef_read_from_memory(const void 
*filebuf,
 
 UserDef *BKE_blendfile_userdef_from_defaults(void)
 {
-  UserDef *userdef = MEM_cnew(__func__);
+  UserDef *userdef = static_cast(MEM_callocN(sizeof(UserDef), 
__func__));
   *userdef = blender::dna::shallow_copy(U_default);
 
   /* Add-ons. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [93a840360a0] master: Cleanup: quiet clang warnings

2023-01-22 Thread Jacques Lucke
Commit: 93a840360a025df7830f48e4d7c398c3e45ff41c
Author: Jacques Lucke
Date:   Mon Jan 23 00:55:15 2023 +0100
Branches: master
https://developer.blender.org/rB93a840360a025df7830f48e4d7c398c3e45ff41c

Cleanup: quiet clang warnings

===

M   source/blender/blenkernel/intern/blendfile.cc
M   source/blender/makesdna/DNA_userdef_types.h
M   source/blender/windowmanager/intern/wm_files.cc

===

diff --git a/source/blender/blenkernel/intern/blendfile.cc 
b/source/blender/blenkernel/intern/blendfile.cc
index 9ccd3e7541a..2ac2ae43684 100644
--- a/source/blender/blenkernel/intern/blendfile.cc
+++ b/source/blender/blenkernel/intern/blendfile.cc
@@ -641,7 +641,7 @@ UserDef *BKE_blendfile_userdef_read_from_memory(const void 
*filebuf,
 UserDef *BKE_blendfile_userdef_from_defaults(void)
 {
   UserDef *userdef = MEM_cnew(__func__);
-  memcpy(userdef, _default, sizeof(*userdef));
+  *userdef = blender::dna::shallow_copy(U_default);
 
   /* Add-ons. */
   {
diff --git a/source/blender/makesdna/DNA_userdef_types.h 
b/source/blender/makesdna/DNA_userdef_types.h
index 4c9568d9228..0e96e1db30c 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -659,6 +659,8 @@ typedef struct UserDef_Experimental {
   (((userdef)->flag & USER_DEVELOPER_UI) && ((userdef)->experimental).member)
 
 typedef struct UserDef {
+  DNA_DEFINE_CXX_METHODS(UserDef)
+
   /** UserDef has separate do-version handling, and can be read from other 
files. */
   int versionfile, subversionfile;
 
diff --git a/source/blender/windowmanager/intern/wm_files.cc 
b/source/blender/windowmanager/intern/wm_files.cc
index 75c9ea42e3a..8a0e206b5e7 100644
--- a/source/blender/windowmanager/intern/wm_files.cc
+++ b/source/blender/windowmanager/intern/wm_files.cc
@@ -2304,7 +2304,7 @@ static int wm_userpref_read_exec(bContext *C, wmOperator 
*op)
   const bool use_factory_settings_app_template_only =
   (use_factory_settings && RNA_boolean_get(op->ptr, 
"use_factory_startup_app_template_only"));
 
-  UserDef U_backup = U;
+  UserDef U_backup = blender::dna::shallow_copy(U);
 
   wmHomeFileRead_Params read_homefile_params{};
   read_homefile_params.use_data = use_data;
@@ -2407,7 +2407,7 @@ static int wm_homefile_read_exec(bContext *C, wmOperator 
*op)
   bool use_userdef = false;
   char filepath_buf[FILE_MAX];
   const char *filepath = nullptr;
-  UserDef U_backup = U;
+  UserDef U_backup = blender::dna::shallow_copy(U);
 
   if (!use_factory_settings) {
 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath");

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [4bef5f3df70] master: Cleanup: move some undo related files to C++

2023-01-22 Thread Jacques Lucke
Commit: 4bef5f3df700b43012667c58a74a25a2e252a670
Author: Jacques Lucke
Date:   Mon Jan 23 00:32:39 2023 +0100
Branches: master
https://developer.blender.org/rB4bef5f3df700b43012667c58a74a25a2e252a670

Cleanup: move some undo related files to C++

For continued testing in D14139. Also see T103343.

===

M   source/blender/blenkernel/BKE_undo_system.h
M   source/blender/blenkernel/CMakeLists.txt
R085source/blender/blenkernel/intern/blender_undo.c 
source/blender/blenkernel/intern/blender_undo.cc
R088source/blender/blenkernel/intern/blendfile.c
source/blender/blenkernel/intern/blendfile.cc
R086source/blender/blenkernel/intern/undo_system.c  
source/blender/blenkernel/intern/undo_system.cc
M   source/blender/blenloader/BLO_readfile.h
M   source/blender/blenloader/tests/blendfile_loading_base_test.cc
M   source/blender/editors/armature/CMakeLists.txt
R090source/blender/editors/armature/editarmature_undo.c 
source/blender/editors/armature/editarmature_undo.cc
M   source/blender/editors/curve/CMakeLists.txt
M   source/blender/editors/curve/curve_intern.h
R089source/blender/editors/curve/editcurve_undo.c   
source/blender/editors/curve/editcurve_undo.cc
M   source/blender/editors/gpencil/CMakeLists.txt
R085source/blender/editors/gpencil/gpencil_undo.c   
source/blender/editors/gpencil/gpencil_undo.cc
M   source/blender/editors/include/ED_armature.h
M   source/blender/editors/include/ED_curve.h
M   source/blender/editors/include/ED_sculpt.h
M   source/blender/editors/include/ED_text.h
M   source/blender/editors/sculpt_paint/CMakeLists.txt
R091source/blender/editors/sculpt_paint/sculpt_undo.c   
source/blender/editors/sculpt_paint/sculpt_undo.cc
M   source/blender/editors/space_text/CMakeLists.txt
M   source/blender/editors/space_text/text_intern.h
R086source/blender/editors/space_text/text_undo.c   
source/blender/editors/space_text/text_undo.cc
M   source/blender/editors/undo/CMakeLists.txt
R089source/blender/editors/undo/ed_undo.c   
source/blender/editors/undo/ed_undo.cc
R090source/blender/editors/undo/memfile_undo.c  
source/blender/editors/undo/memfile_undo.cc
R091source/blender/editors/undo/undo_intern.h   
source/blender/editors/undo/undo_intern.hh
R098source/blender/editors/undo/undo_system_types.c 
source/blender/editors/undo/undo_system_types.cc
M   source/blender/editors/uvedit/uvedit_clipboard.cc
M   source/blender/windowmanager/CMakeLists.txt
M   source/blender/windowmanager/WM_api.h
M   source/blender/windowmanager/WM_types.h
R087source/blender/windowmanager/intern/wm_files.c  
source/blender/windowmanager/intern/wm_files.cc
R091source/blender/windowmanager/intern/wm_init_exit.c  
source/blender/windowmanager/intern/wm_init_exit.cc
M   source/blender/windowmanager/intern/wm_platform_support.h
M   source/blender/windowmanager/intern/wm_window.c
M   source/blender/windowmanager/wm.h
M   source/blender/windowmanager/wm_files.h

===

diff --git a/source/blender/blenkernel/BKE_undo_system.h 
b/source/blender/blenkernel/BKE_undo_system.h
index 5d1a27f8ba0..365a3a86b7c 100644
--- a/source/blender/blenkernel/BKE_undo_system.h
+++ b/source/blender/blenkernel/BKE_undo_system.h
@@ -93,6 +93,7 @@ typedef enum eUndoPushReturn {
   UNDO_PUSH_RET_SUCCESS = (1 << 0),
   UNDO_PUSH_RET_OVERRIDE_CHANGED = (1 << 1),
 } eUndoPushReturn;
+ENUM_OPERATORS(eUndoPushReturn, UNDO_PUSH_RET_OVERRIDE_CHANGED)
 
 typedef void (*UndoTypeForEachIDRefFn)(void *user_data, struct UndoRefID 
*id_ref);
 
@@ -137,7 +138,7 @@ typedef struct UndoType {
 
   /**
* The size of the undo struct 'inherited' from #UndoStep for that specific 
type. Used for
-   * generic allocation in BKE's `undo_system.c`. */
+   * generic allocation in BKE's `undo_system.cc`. */
   size_t step_size;
 } UndoType;
 
diff --git a/source/blender/blenkernel/CMakeLists.txt 
b/source/blender/blenkernel/CMakeLists.txt
index 8d6fe6c3cf7..1f4ab73911a 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -78,9 +78,9 @@ set(SRC
   intern/autoexec.c
   intern/blender.c
   intern/blender_copybuffer.c
-  intern/blender_undo.c
+  intern/blender_undo.cc
   intern/blender_user_menu.c
-  intern/blendfile.c
+  intern/blendfile.cc
   intern/blendfile_link_append.c
   intern/boids.c
   intern/bpath.c
@@ -296,7 +296,7 @@ set(SRC
   intern/tracking_stabilize.c
   intern/tracking_util.c
   intern/type_conversions.cc
-  intern/undo_system.c
+  intern/undo_system.cc
   intern/unit.c
   intern/vfont.c
   intern/vfontdata_freetype.c
diff --git a/source/blender/blenkernel/intern/blender_undo.c 
b/source/blender/blenkernel/intern/blender_undo.cc
similarity index 85%
rename from source/blender/blenkernel/intern/blender_undo.c
rena

[Bf-blender-cvs] [c2a28f9f6cf] master: Cleanup: quiet compiler warnings

2023-01-21 Thread Jacques Lucke
Commit: c2a28f9f6cfad66b945700e5d62bd25765083241
Author: Jacques Lucke
Date:   Sun Jan 22 02:03:44 2023 +0100
Branches: master
https://developer.blender.org/rBc2a28f9f6cfad66b945700e5d62bd25765083241

Cleanup: quiet compiler warnings

===

M   source/blender/blenkernel/intern/image_partial_update.cc
M   source/blender/blenkernel/intern/multires.cc
M   source/blender/blenkernel/intern/multires_reshape.cc
M   source/blender/editors/object/object_bake.cc
M   source/blender/makesdna/DNA_modifier_types.h
M   source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc

===

diff --git a/source/blender/blenkernel/intern/image_partial_update.cc 
b/source/blender/blenkernel/intern/image_partial_update.cc
index ecf55d6b694..4de807c0706 100644
--- a/source/blender/blenkernel/intern/image_partial_update.cc
+++ b/source/blender/blenkernel/intern/image_partial_update.cc
@@ -276,7 +276,7 @@ struct TileChangeset {
 const int chunk_len = chunk_x_len * chunk_y_len;
 
 for (int chunk_index = 0; chunk_index < chunk_len; chunk_index++) {
-  chunk_dirty_flags_[chunk_index] = chunk_dirty_flags_[chunk_index] |
+  chunk_dirty_flags_[chunk_index] = chunk_dirty_flags_[chunk_index] ||
 other.chunk_dirty_flags_[chunk_index];
 }
 has_dirty_chunks_ |= other.has_dirty_chunks_;
diff --git a/source/blender/blenkernel/intern/multires.cc 
b/source/blender/blenkernel/intern/multires.cc
index 9b04435b91c..2c5c7ba72ee 100644
--- a/source/blender/blenkernel/intern/multires.cc
+++ b/source/blender/blenkernel/intern/multires.cc
@@ -751,7 +751,7 @@ static DerivedMesh *multires_dm_create_local(Scene *scene,
  bool alloc_paint_mask,
  MultiresFlags flags)
 {
-  MultiresModifierData mmd = {{nullptr}};
+  MultiresModifierData mmd{};
 
   mmd.lvl = lvl;
   mmd.sculptlvl = lvl;
diff --git a/source/blender/blenkernel/intern/multires_reshape.cc 
b/source/blender/blenkernel/intern/multires_reshape.cc
index 522e7632b94..536dade7463 100644
--- a/source/blender/blenkernel/intern/multires_reshape.cc
+++ b/source/blender/blenkernel/intern/multires_reshape.cc
@@ -84,7 +84,7 @@ bool multiresModifier_reshapeFromDeformModifier(Depsgraph 
*depsgraph,
 MultiresModifierData *mmd,
 ModifierData *deform_md)
 {
-  MultiresModifierData highest_mmd = *mmd;
+  MultiresModifierData highest_mmd = blender::dna::shallow_copy(*mmd);
   highest_mmd.sculptlvl = highest_mmd.totlvl;
   highest_mmd.lvl = highest_mmd.totlvl;
   highest_mmd.renderlvl = highest_mmd.totlvl;
diff --git a/source/blender/editors/object/object_bake.cc 
b/source/blender/editors/object/object_bake.cc
index 30805ff8ad2..da16c1eae60 100644
--- a/source/blender/editors/object/object_bake.cc
+++ b/source/blender/editors/object/object_bake.cc
@@ -221,7 +221,7 @@ static DerivedMesh *multiresbake_create_loresdm(Scene 
*scene, Object *ob, int *l
   DerivedMesh *dm;
   MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
   Mesh *me = (Mesh *)ob->data;
-  MultiresModifierData tmp_mmd = *mmd;
+  MultiresModifierData tmp_mmd = blender::dna::shallow_copy(*mmd);
 
   *lvl = mmd->lvl;
 
@@ -246,7 +246,7 @@ static DerivedMesh *multiresbake_create_hiresdm(Scene 
*scene, Object *ob, int *l
 {
   Mesh *me = (Mesh *)ob->data;
   MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
-  MultiresModifierData tmp_mmd = *mmd;
+  MultiresModifierData tmp_mmd = blender::dna::shallow_copy(*mmd);
   DerivedMesh *cddm = CDDM_from_mesh(me);
   DerivedMesh *dm;
 
diff --git a/source/blender/makesdna/DNA_modifier_types.h 
b/source/blender/makesdna/DNA_modifier_types.h
index aa7df999cf5..fe35fea77ed 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1094,6 +1094,8 @@ typedef struct ExplodeModifierData {
 } ExplodeModifierData;
 
 typedef struct MultiresModifierData {
+  DNA_DEFINE_CXX_METHODS(MultiresModifierData)
+
   ModifierData modifier;
 
   char lvl, sculptlvl, renderlvl, totlvl;
diff --git a/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc 
b/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
index 2142fa666cb..c4f275334a8 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
@@ -238,7 +238,6 @@ static void compute_point_counts_per_child(const 
bke::CurvesGeometry _curv
 {
   const OffsetIndices guide_points_by_curve = guide_curves.points_by_curve();
   threading::parallel_for(r_points_per_child.index_range(), 512, [&](const 
IndexRange range) {
-int points_sum = 0;
 for (const int child

[Bf-blender-cvs] [96dfa68e5f6] master: Cleanup: extract function that slices parameters for multi-function call

2023-01-21 Thread Jacques Lucke
Commit: 96dfa68e5f6597f180794fc5bba68cb39c064540
Author: Jacques Lucke
Date:   Sun Jan 22 00:13:47 2023 +0100
Branches: master
https://developer.blender.org/rB96dfa68e5f6597f180794fc5bba68cb39c064540

Cleanup: extract function that slices parameters for multi-function call

===

M   source/blender/functions/intern/multi_function.cc

===

diff --git a/source/blender/functions/intern/multi_function.cc 
b/source/blender/functions/intern/multi_function.cc
index 2f83ab08879..7cf79cc4b81 100644
--- a/source/blender/functions/intern/multi_function.cc
+++ b/source/blender/functions/intern/multi_function.cc
@@ -62,6 +62,54 @@ static int64_t compute_alignment(const int64_t grain_size)
   return 32;
 }
 
+static void add_sliced_parameters(const Signature ,
+  Params _params,
+  const IndexRange slice_range,
+  ParamsBuilder _sliced_params)
+{
+  for (const int param_index : signature.params.index_range()) {
+const ParamType _type = signature.params[param_index].type;
+switch (param_type.category()) {
+  case ParamCategory::SingleInput: {
+const GVArray  = full_params.readonly_single_input(param_index);
+r_sliced_params.add_readonly_single_input(varray.slice(slice_range));
+break;
+  }
+  case ParamCategory::SingleMutable: {
+const GMutableSpan span = full_params.single_mutable(param_index);
+const GMutableSpan sliced_span = span.slice(slice_range);
+r_sliced_params.add_single_mutable(sliced_span);
+break;
+  }
+  case ParamCategory::SingleOutput: {
+if (bool(signature.params[param_index].flag & 
ParamFlag::SupportsUnusedOutput)) {
+  const GMutableSpan span = 
full_params.uninitialized_single_output_if_required(
+  param_index);
+  if (span.is_empty()) {
+r_sliced_params.add_ignored_single_output();
+  }
+  else {
+const GMutableSpan sliced_span = span.slice(slice_range);
+r_sliced_params.add_uninitialized_single_output(sliced_span);
+  }
+}
+else {
+  const GMutableSpan span = 
full_params.uninitialized_single_output(param_index);
+  const GMutableSpan sliced_span = span.slice(slice_range);
+  r_sliced_params.add_uninitialized_single_output(sliced_span);
+}
+break;
+  }
+  case ParamCategory::VectorInput:
+  case ParamCategory::VectorMutable:
+  case ParamCategory::VectorOutput: {
+BLI_assert_unreachable();
+break;
+  }
+}
+  }
+}
+
 void MultiFunction::call_auto(IndexMask mask, Params params, Context context) 
const
 {
   if (mask.is_empty()) {
@@ -102,53 +150,9 @@ void MultiFunction::call_auto(IndexMask mask, Params 
params, Context context) co
 Vector offset_mask_indices;
 const IndexMask offset_mask = mask.slice_and_offset(sub_range, 
offset_mask_indices);
 
-ParamsBuilder offset_params{*this, offset_mask.min_array_size()};
-
-/* Slice all parameters so that for the actual function call. */
-for (const int param_index : this->param_indices()) {
-  const ParamType param_type = this->param_type(param_index);
-  switch (param_type.category()) {
-case ParamCategory::SingleInput: {
-  const GVArray  = 
params.readonly_single_input(param_index);
-  
offset_params.add_readonly_single_input(varray.slice(input_slice_range));
-  break;
-}
-case ParamCategory::SingleMutable: {
-  const GMutableSpan span = params.single_mutable(param_index);
-  const GMutableSpan sliced_span = span.slice(input_slice_range);
-  offset_params.add_single_mutable(sliced_span);
-  break;
-}
-case ParamCategory::SingleOutput: {
-  if (bool(signature_ref_->params[param_index].flag &
-   ParamFlag::SupportsUnusedOutput)) {
-const GMutableSpan span = 
params.uninitialized_single_output_if_required(
-param_index);
-if (span.is_empty()) {
-  offset_params.add_ignored_single_output();
-}
-else {
-  const GMutableSpan sliced_span = 
span.slice(input_slice_range);
-  offset_params.add_uninitialized_single_output(sliced_span);
-}
-  }
-  else {
-const GMutableSpan span = 
params.uninitialized_single_output(param_index);
-const GMutableSpan sliced_span = span.slice(input_slice_range);
-offset_params.add_uninitialized_single_output(sliced_span);
-  }
-  break;
-}

[Bf-blender-cvs] [3f1886d0b78] master: Functions: align chunk sizes in multi-function evaluation

2023-01-21 Thread Jacques Lucke
Commit: 3f1886d0b788d043917ec86702b4b480f8d5dd2e
Author: Jacques Lucke
Date:   Sun Jan 22 00:03:25 2023 +0100
Branches: master
https://developer.blender.org/rB3f1886d0b788d043917ec86702b4b480f8d5dd2e

Functions: align chunk sizes in multi-function evaluation

This can improve performance in some circumstances when there are
vectorized and/or unrolled loops. I especially noticed that this helps
a lot while working on D16970 (got a 10-20% speedup there by avoiding
running into the non-vectorized fallback loop too often).

===

M   source/blender/blenlib/BLI_task.hh
M   source/blender/functions/intern/multi_function.cc

===

diff --git a/source/blender/blenlib/BLI_task.hh 
b/source/blender/blenlib/BLI_task.hh
index c726691ad46..60585e35099 100644
--- a/source/blender/blenlib/BLI_task.hh
+++ b/source/blender/blenlib/BLI_task.hh
@@ -71,6 +71,36 @@ void parallel_for(IndexRange range, int64_t grain_size, 
const Function 
   function(range);
 }
 
+/**
+ * Same as #parallel_for but tries to make the sub-range sizes multiples of 
the given alignment.
+ * This can improve performance when the range is processed using vectorized 
and/or unrolled loops,
+ * because the fallback loop that processes remaining values is used less 
often. A disadvantage of
+ * using this instead of #parallel_for is that the size differences between 
sub-ranges can be
+ * larger, which means that work is distributed less evenly.
+ */
+template
+void parallel_for_aligned(const IndexRange range,
+  const int64_t grain_size,
+  const int64_t alignment,
+  const Function )
+{
+  const int64_t global_begin = range.start();
+  const int64_t global_end = range.one_after_last();
+  const int64_t alignment_mask = ~(alignment - 1);
+  parallel_for(range, grain_size, [&](const IndexRange unaligned_range) {
+/* Move the sub-range boundaries down to the next aligned index. The 
"global" begin and end
+ * remain fixed though. */
+const int64_t unaligned_begin = unaligned_range.start();
+const int64_t unaligned_end = unaligned_range.one_after_last();
+const int64_t aligned_begin = std::max(global_begin, unaligned_begin & 
alignment_mask);
+const int64_t aligned_end = unaligned_end == global_end ?
+unaligned_end :
+std::max(global_begin, unaligned_end & 
alignment_mask);
+const IndexRange aligned_range{aligned_begin, aligned_end - aligned_begin};
+function(aligned_range);
+  });
+}
+
 template
 Value parallel_reduce(IndexRange range,
   int64_t grain_size,
diff --git a/source/blender/functions/intern/multi_function.cc 
b/source/blender/functions/intern/multi_function.cc
index fedf9a00d13..2f83ab08879 100644
--- a/source/blender/functions/intern/multi_function.cc
+++ b/source/blender/functions/intern/multi_function.cc
@@ -52,6 +52,16 @@ static int64_t compute_grain_size(const ExecutionHints 
, const IndexMask m
   return grain_size;
 }
 
+static int64_t compute_alignment(const int64_t grain_size)
+{
+  if (grain_size <= 512) {
+/* Don't use a number that's too large, or otherwise the work will be 
split quite unevenly. */
+return 8;
+  }
+  /* It's not common that more elements are processed in a loop at once. */
+  return 32;
+}
+
 void MultiFunction::call_auto(IndexMask mask, Params params, Context context) 
const
 {
   if (mask.is_empty()) {
@@ -71,71 +81,75 @@ void MultiFunction::call_auto(IndexMask mask, Params 
params, Context context) co
 return;
   }
 
-  threading::parallel_for(mask.index_range(), grain_size, [&](const IndexRange 
sub_range) {
-const IndexMask sliced_mask = mask.slice(sub_range);
-if (!hints.allocates_array) {
-  /* There is no benefit to changing indices in this case. */
-  this->call(sliced_mask, params, context);
-  return;
-}
-if (sliced_mask[0] < grain_size) {
-  /* The indices are low, no need to offset them. */
-  this->call(sliced_mask, params, context);
-  return;
-}
-const int64_t input_slice_start = sliced_mask[0];
-const int64_t input_slice_size = sliced_mask.last() - input_slice_start + 
1;
-const IndexRange input_slice_range{input_slice_start, input_slice_size};
-
-Vector offset_mask_indices;
-const IndexMask offset_mask = mask.slice_and_offset(sub_range, 
offset_mask_indices);
-
-ParamsBuilder offset_params{*this, offset_mask.min_array_size()};
-
-/* Slice all parameters so that for the actual function call. */
-for (const int param_index : this->param_indices()) {
-  const ParamType param_type = this->param_type(param_index);
-  switch (param_type.category()) {
-case ParamCategory::SingleInput: {
-  const GVArray

[Bf-blender-cvs] [8d98d5c4027] master: Cleanup: fix compiling in debug mode

2023-01-21 Thread Jacques Lucke
Commit: 8d98d5c4027e3dca85e87fb20e2485b5c88838cc
Author: Jacques Lucke
Date:   Sat Jan 21 23:56:11 2023 +0100
Branches: master
https://developer.blender.org/rB8d98d5c4027e3dca85e87fb20e2485b5c88838cc

Cleanup: fix compiling in debug mode

===

M   source/blender/editors/uvedit/uvedit_unwrap_ops.cc

===

diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc 
b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc
index 7a99fec413c..d95655cef45 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.cc
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.cc
@@ -2301,7 +2301,6 @@ static int smart_project_exec(bContext *C, wmOperator *op)
 
 if (project_normal_array.size() == 0) {
   MEM_freeN(thick_faces);
-  BLI_assert(project_normal_array == nullptr);
   continue;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [244c87dd680] master: Geometry Nodes: avoid geometry copy if nothing is selected in Set Position node

2023-01-20 Thread Jacques Lucke
Commit: 244c87dd680c4f5b5acfcd088aaae0e04298c4f5
Author: Jacques Lucke
Date:   Fri Jan 20 21:27:13 2023 +0100
Branches: master
https://developer.blender.org/rB244c87dd680c4f5b5acfcd088aaae0e04298c4f5

Geometry Nodes: avoid geometry copy if nothing is selected in Set Position node

This improves performance in cases where the Set Position node is "turned off"
by passing `false` into the selection input.

It's possible that the node still takes some time in this case currently, 
because
it is destructing the input fields which may reference geometries that need
to be destructed as well. We could potentially change this node (and others)
so that the field inputs are only requested when the selection is not a
constant `false`.

===

M   source/blender/nodes/geometry/nodes/node_geo_set_position.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc 
b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
index 2ad126567d1..4f6a256620a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
@@ -116,19 +116,22 @@ static void 
set_computed_position_and_offset(GeometryComponent ,
   }
 }
 
-static void set_position_in_component(GeometryComponent ,
+static void set_position_in_component(GeometrySet ,
+  GeometryComponentType component_type,
   const Field _field,
   const Field _field,
   const Field _field)
 {
-  eAttrDomain domain = component.type() == GEO_COMPONENT_TYPE_INSTANCES ? 
ATTR_DOMAIN_INSTANCE :
-  
ATTR_DOMAIN_POINT;
-  bke::GeometryFieldContext field_context{component, domain};
+  const GeometryComponent  = 
*geometry.get_component_for_read(component_type);
+  const eAttrDomain domain = component.type() == GEO_COMPONENT_TYPE_INSTANCES ?
+ ATTR_DOMAIN_INSTANCE :
+ ATTR_DOMAIN_POINT;
   const int domain_size = component.attribute_domain_size(domain);
   if (domain_size == 0) {
 return;
   }
 
+  bke::GeometryFieldContext field_context{component, domain};
   fn::FieldEvaluator evaluator{field_context, domain_size};
   evaluator.set_selection(selection_field);
   evaluator.add(position_field);
@@ -136,10 +139,14 @@ static void set_position_in_component(GeometryComponent 
,
   evaluator.evaluate();
 
   const IndexMask selection = evaluator.get_evaluated_selection_as_mask();
+  if (selection.is_empty()) {
+return;
+  }
 
+  GeometryComponent _component = 
geometry.get_component_for_write(component_type);
   const VArray positions_input = evaluator.get_evaluated(0);
   const VArray offsets_input = evaluator.get_evaluated(1);
-  set_computed_position_and_offset(component, positions_input, offsets_input, 
selection);
+  set_computed_position_and_offset(mutable_component, positions_input, 
offsets_input, selection);
 }
 
 static void node_geo_exec(GeoNodeExecParams params)
@@ -154,8 +161,7 @@ static void node_geo_exec(GeoNodeExecParams params)
GEO_COMPONENT_TYPE_CURVE,
GEO_COMPONENT_TYPE_INSTANCES}) {
 if (geometry.has(type)) {
-  set_position_in_component(
-  geometry.get_component_for_write(type), selection_field, 
position_field, offset_field);
+  set_position_in_component(geometry, type, selection_field, 
position_field, offset_field);
 }
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c8a10c43b13] master: Geometry Nodes: show number of curve points in socket inspection tooltip

2023-01-20 Thread Jacques Lucke
Commit: c8a10c43b13e109ec1bd78eedeea318be2c22980
Author: Jacques Lucke
Date:   Fri Jan 20 14:44:37 2023 +0100
Branches: master
https://developer.blender.org/rBc8a10c43b13e109ec1bd78eedeea318be2c22980

Geometry Nodes: show number of curve points in socket inspection tooltip

This was not done originally, because one had to iterate over all curves
to get the number of points which had some overhead. Now the number
of points is stored all the time anyway.

===

M   source/blender/editors/space_node/node_draw.cc
M   source/blender/nodes/NOD_geometry_nodes_log.hh
M   source/blender/nodes/intern/geometry_nodes_log.cc

===

diff --git a/source/blender/editors/space_node/node_draw.cc 
b/source/blender/editors/space_node/node_draw.cc
index bc4b6d416c1..53a86e23ce1 100644
--- a/source/blender/editors/space_node/node_draw.cc
+++ b/source/blender/editors/space_node/node_draw.cc
@@ -945,7 +945,8 @@ static void 
create_inspection_string_for_geometry_info(const geo_log::GeometryIn
 char line[256];
 BLI_snprintf(line,
  sizeof(line),
- TIP_("\u2022 Curve: %s splines"),
+ TIP_("\u2022 Curve: %s points, %s splines"),
+ to_string(curve_info.points_num).c_str(),
  to_string(curve_info.splines_num).c_str());
 ss << line;
 break;
diff --git a/source/blender/nodes/NOD_geometry_nodes_log.hh 
b/source/blender/nodes/NOD_geometry_nodes_log.hh
index 3d453de4b78..9f28bad1630 100644
--- a/source/blender/nodes/NOD_geometry_nodes_log.hh
+++ b/source/blender/nodes/NOD_geometry_nodes_log.hh
@@ -126,6 +126,7 @@ class GeometryInfoLog : public ValueLog {
 int verts_num, edges_num, faces_num;
   };
   struct CurveInfo {
+int points_num;
 int splines_num;
   };
   struct PointCloudInfo {
diff --git a/source/blender/nodes/intern/geometry_nodes_log.cc 
b/source/blender/nodes/intern/geometry_nodes_log.cc
index 66ccab2f77f..919159a31de 100644
--- a/source/blender/nodes/intern/geometry_nodes_log.cc
+++ b/source/blender/nodes/intern/geometry_nodes_log.cc
@@ -89,6 +89,7 @@ GeometryInfoLog::GeometryInfoLog(const GeometrySet 
_set)
   case GEO_COMPONENT_TYPE_CURVE: {
 const CurveComponent _component = *(const CurveComponent 
*)component;
 CurveInfo  = this->curve_info.emplace();
+info.points_num = 
curve_component.attribute_domain_size(ATTR_DOMAIN_POINT);
 info.splines_num = 
curve_component.attribute_domain_size(ATTR_DOMAIN_CURVE);
 break;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c006ba83e0b] master: Fix: execution graph for geometry nodes contained cycles leading to crash

2023-01-20 Thread Jacques Lucke
Commit: c006ba83e0b296983b53d924cfbd0c69aad12de6
Author: Jacques Lucke
Date:   Fri Jan 20 14:38:09 2023 +0100
Branches: master
https://developer.blender.org/rBc006ba83e0b296983b53d924cfbd0c69aad12de6

Fix: execution graph for geometry nodes contained cycles leading to crash

The `fix_link_cycles` function added in rB2ffd08e95249df2a068dd did not
handle the case correctly when there are multiple cycles going through
the same socket.

===

M   source/blender/nodes/intern/geometry_nodes_lazy_function.cc

===

diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index 54f8c3c912d..64551249e29 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -2571,28 +2571,31 @@ struct GeometryNodesLazyFunctionGraphBuilder {
 
 Array socket_states(sockets_num);
 
-Stack lf_sockets_to_check;
+Vector lf_sockets_to_check;
 for (lf::Node *lf_node : lf_graph_->nodes()) {
   if (lf_node->is_function()) {
 for (lf::OutputSocket *lf_socket : lf_node->outputs()) {
   if (lf_socket->targets().is_empty()) {
-lf_sockets_to_check.push(lf_socket);
+lf_sockets_to_check.append(lf_socket);
   }
 }
   }
   if (lf_node->outputs().is_empty()) {
 for (lf::InputSocket *lf_socket : lf_node->inputs()) {
-  lf_sockets_to_check.push(lf_socket);
+  lf_sockets_to_check.append(lf_socket);
 }
   }
 }
 Vector lf_socket_stack;
 while (!lf_sockets_to_check.is_empty()) {
-  lf::Socket *lf_inout_socket = lf_sockets_to_check.peek();
+  lf::Socket *lf_inout_socket = lf_sockets_to_check.last();
   lf::Node _node = lf_inout_socket->node();
   SocketState  = socket_states[lf_inout_socket->index_in_graph()];
-  lf_socket_stack.append(lf_inout_socket);
-  state.in_stack = true;
+
+  if (!state.in_stack) {
+lf_socket_stack.append(lf_inout_socket);
+state.in_stack = true;
+  }
 
   Vector lf_origin_sockets;
   if (lf_inout_socket->is_input()) {
@@ -2616,10 +2619,24 @@ struct GeometryNodesLazyFunctionGraphBuilder {
   }
 
   bool pushed_socket = false;
+  bool detected_cycle = false;
   for (lf::Socket *lf_origin_socket : lf_origin_sockets) {
 if (socket_states[lf_origin_socket->index_in_graph()].in_stack) {
+  /* A cycle has been detected. The cycle is broken by removing a link 
and replacing it
+   * with a constant "true" input. This can only affect inputs which 
determine whether a
+   * specific value is used. Therefore, setting it to a constant true 
can result in more
+   * computation later, but does not change correctness.
+   *
+   * After the cycle is broken, the cycle-detection is "rolled back" 
to the socket where
+   * the first socket of the cycle was found. This is necessary in 
case another cycle goes
+   * through this socket. */
+
+  detected_cycle = true;
+  const int index_in_socket_stack = 
lf_socket_stack.first_index_of(lf_origin_socket);
+  const int index_in_sockets_to_check = 
lf_sockets_to_check.first_index_of(
+  lf_origin_socket);
   const Span cycle = 
lf_socket_stack.as_span().drop_front(
-  lf_socket_stack.first_index_of(lf_origin_socket));
+  index_in_socket_stack);
 
   bool broke_cycle = false;
   for (lf::Socket *lf_cycle_socket : cycle) {
@@ -2631,23 +2648,35 @@ struct GeometryNodesLazyFunctionGraphBuilder {
   lf_cycle_input_socket.set_default_value(_true);
   broke_cycle = true;
 }
+/* This is actually removed from the stack when it is resized 
below. */
+SocketState _cycle_socket_state = 
socket_states[lf_cycle_socket->index_in_graph()];
+lf_cycle_socket_state.in_stack = false;
   }
   if (!broke_cycle) {
 BLI_assert_unreachable();
   }
+  /* Roll back algorithm by removing the sockets that corresponded to 
the cycle from the
+   * stacks. */
+  lf_socket_stack.resize(index_in_socket_stack);
+  /* The +1 is there so that the socket itself is not removed. */
+  lf_sockets_to_check.resize(index_in_sockets_to_check + 1);
+  break;
 }
 else if (!socket_states[lf_origin_socket->index_in_graph()].done) {
-  lf_sockets_to_check.push(lf_origin_socket);
+  lf_sockets_to_check.append(lf_origin_socket);
   pushed_socket = true;
 }
   }
+  if (detected_cycle) {
+continue;
+  }
   if (pushed_socket) 

[Bf-blender-cvs] [d79abb5d4f5] master: Fix: missing clamping in single mode in Sample Index node

2023-01-20 Thread Jacques Lucke
Commit: d79abb5d4f559fad4d2e057c7d163334ac9c30d8
Author: Jacques Lucke
Date:   Fri Jan 20 14:33:06 2023 +0100
Branches: master
https://developer.blender.org/rBd79abb5d4f559fad4d2e057c7d163334ac9c30d8

Fix: missing clamping in single mode in Sample Index node

===

M   source/blender/nodes/geometry/nodes/node_geo_sample_index.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc 
b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
index 2ac19b02f9c..b6267d2439a 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
@@ -298,6 +298,7 @@ static void node_geo_exec(GeoNodeExecParams params)
   const NodeGeometrySampleIndex  = node_storage(params.node());
   const eCustomDataType data_type = eCustomDataType(storage.data_type);
   const eAttrDomain domain = eAttrDomain(storage.domain);
+  const bool use_clamp = bool(storage.clamp);
 
   GField value_field = get_input_attribute_field(params, data_type);
   ValueOrField index_value_or_field = 
params.extract_input>("Index");
@@ -307,24 +308,33 @@ static void node_geo_exec(GeoNodeExecParams params)
   if (index_value_or_field.is_field()) {
 /* If the index is a field, the output has to be a field that still 
depends on the input. */
 auto fn = std::make_shared(
-std::move(geometry), std::move(value_field), domain, 
bool(storage.clamp));
+std::move(geometry), std::move(value_field), domain, use_clamp);
 auto op = FieldOperation::Create(std::move(fn), 
{index_value_or_field.as_field()});
 output_field = GField(std::move(op));
   }
   else if (const GeometryComponent *component = 
find_source_component(geometry, domain)) {
 /* Optimization for the case when the index is a single value. Here only 
that one index has to
  * be evaluated. */
-const int index = index_value_or_field.as_value();
-const IndexMask mask = IndexRange(index, 1);
-bke::GeometryFieldContext geometry_context(*component, domain);
-FieldEvaluator evaluator(geometry_context, );
-evaluator.add(value_field);
-evaluator.evaluate();
-const GVArray  = evaluator.get_evaluated(0);
-BUFFER_FOR_CPP_TYPE_VALUE(cpp_type, buffer);
-data.get_to_uninitialized(index, buffer);
-output_field = fn::make_constant_field(cpp_type, buffer);
-cpp_type.destruct(buffer);
+const int domain_size = component->attribute_domain_size(domain);
+int index = index_value_or_field.as_value();
+if (use_clamp) {
+  index = std::clamp(index, 0, domain_size - 1);
+}
+if (index >= 0 && index < domain_size) {
+  const IndexMask mask = IndexRange(index, 1);
+  bke::GeometryFieldContext geometry_context(*component, domain);
+  FieldEvaluator evaluator(geometry_context, );
+  evaluator.add(value_field);
+  evaluator.evaluate();
+  const GVArray  = evaluator.get_evaluated(0);
+  BUFFER_FOR_CPP_TYPE_VALUE(cpp_type, buffer);
+  data.get_to_uninitialized(index, buffer);
+  output_field = fn::make_constant_field(cpp_type, buffer);
+  cpp_type.destruct(buffer);
+}
+else {
+  output_field = fn::make_constant_field(cpp_type, 
cpp_type.default_value());
+}
   }
   else {
 /* Output default value if there is no geometry. */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b6278c5a967] master: Fix: crash when subdividing curves

2023-01-20 Thread Jacques Lucke
Commit: b6278c5a9670a550051b9e51f81541392ab16e4a
Author: Jacques Lucke
Date:   Fri Jan 20 14:15:22 2023 +0100
Branches: master
https://developer.blender.org/rBb6278c5a9670a550051b9e51f81541392ab16e4a

Fix: crash when subdividing curves

This was an error in rB38a45e46bc910c68ae3.

===

M   source/blender/geometry/intern/subdivide_curves.cc

===

diff --git a/source/blender/geometry/intern/subdivide_curves.cc 
b/source/blender/geometry/intern/subdivide_curves.cc
index 99a20b1122d..f062f720366 100644
--- a/source/blender/geometry/intern/subdivide_curves.cc
+++ b/source/blender/geometry/intern/subdivide_curves.cc
@@ -85,7 +85,7 @@ static void subdivide_attribute_linear(const 
bke::CurvesGeometry _curves,
 
   threading::parallel_for(curve_src.index_range().drop_back(1), 1024, 
[&](IndexRange range) {
 for (const int i : range) {
-  const IndexRange segment_points = curve_offsets[src_segments[i]];
+  const IndexRange segment_points = curve_offsets[i];
   linear_interpolation(curve_src[i], curve_src[i + 1], 
curve_dst.slice(segment_points));
 }
   });

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [31a505d1a5e] master: Functions: add debug utility for lazy function graphs

2023-01-20 Thread Jacques Lucke
Commit: 31a505d1a5ead4522460aaaef595ad1dea8841f6
Author: Jacques Lucke
Date:   Fri Jan 20 13:39:10 2023 +0100
Branches: master
https://developer.blender.org/rB31a505d1a5ead4522460aaaef595ad1dea8841f6

Functions: add debug utility for lazy function graphs

This makes it easier to print information about a socket. Just the
socket name is sometimes not enough information to know where
it is in the graph.

===

M   source/blender/functions/FN_lazy_function_graph.hh
M   source/blender/functions/intern/lazy_function_graph.cc

===

diff --git a/source/blender/functions/FN_lazy_function_graph.hh 
b/source/blender/functions/FN_lazy_function_graph.hh
index 6d66afafe82..a532f0dc7c3 100644
--- a/source/blender/functions/FN_lazy_function_graph.hh
+++ b/source/blender/functions/FN_lazy_function_graph.hh
@@ -78,6 +78,7 @@ class Socket : NonCopyable, NonMovable {
   const CPPType () const;
 
   std::string name() const;
+  std::string detailed_name() const;
 };
 
 class InputSocket : public Socket {
diff --git a/source/blender/functions/intern/lazy_function_graph.cc 
b/source/blender/functions/intern/lazy_function_graph.cc
index e07cce7204b..0047359ed26 100644
--- a/source/blender/functions/intern/lazy_function_graph.cc
+++ b/source/blender/functions/intern/lazy_function_graph.cc
@@ -147,6 +147,14 @@ std::string Socket::name() const
   return fallback_name;
 }
 
+std::string Socket::detailed_name() const
+{
+  std::stringstream ss;
+  ss << node_->name() << ":" << (is_input_ ? "IN" : "OUT") << ":" << 
index_in_node_ << ":"
+ << this->name();
+  return ss.str();
+}
+
 std::string Node::name() const
 {
   if (this->is_function()) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [127eb2e328b] master: Fix: wrong identifier int for interpolate curves node

2023-01-20 Thread Jacques Lucke
Commit: 127eb2e328af089176c73ad4e50f54a3600d
Author: Jacques Lucke
Date:   Fri Jan 20 12:16:49 2023 +0100
Branches: master
https://developer.blender.org/rB127eb2e328af089176c73ad4e50f54a3600d

Fix: wrong identifier int for interpolate curves node

This does not break existing files, because the idname is the ground truth.

===

M   source/blender/blenkernel/BKE_node.h

===

diff --git a/source/blender/blenkernel/BKE_node.h 
b/source/blender/blenkernel/BKE_node.h
index 386fe7fc77f..d57857bfdf3 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1533,6 +1533,7 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, 
struct Scene *scene, i
 #define GEO_NODE_IMAGE_INFO 1189
 #define GEO_NODE_BLUR_ATTRIBUTE 1190
 #define GEO_NODE_IMAGE 1191
+#define GEO_NODE_INTERPOLATE_CURVES 1192
 
 /** \} */
 
@@ -1562,8 +1563,6 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, 
struct Scene *scene, i
 
 /** \} */
 
-#define GEO_NODE_INTERPOLATE_CURVES 2000
-
 void BKE_node_system_init(void);
 void BKE_node_system_exit(void);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [85908e9edf3] master: Geometry Nodes: new Interpolate Curves node

2023-01-20 Thread Jacques Lucke
Commit: 85908e9edf3dfefdc36714f07a554f480ff5d230
Author: Jacques Lucke
Date:   Fri Jan 20 12:09:29 2023 +0100
Branches: master
https://developer.blender.org/rB85908e9edf3dfefdc36714f07a554f480ff5d230

Geometry Nodes: new Interpolate Curves node

This adds a new `Interpolate Curves` node. It allows generating new curves
between a set of existing guide curves. This is essential for procedural hair.

Usage:
- One has to provide a set of guide curves and a set of root positions for
  the generated curves. New curves are created starting from these root
  positions. The N closest guide curves are used for the interpolation.
- An additional up vector can be provided for every guide curve and
  root position. This is typically a surface normal or nothing. This allows
  generating child curves that are properly oriented based on the
  surface orientation.
- Sometimes a point should only be interpolated using a subset of the
  guides. This can be achieved using the `Guide Group ID` and
  `Point Group ID` inputs. The curve generated at a specific point will
  only take the guides with the same id into account. This allows e.g.
  for hair parting.
- The `Max Neighbors` input limits how many guide curves are taken
  into account for every interpolated curve.

Differential Revision: https://developer.blender.org/D16642

===

M   release/scripts/startup/bl_ui/node_add_menu_geometry.py
M   source/blender/blenkernel/BKE_node.h
M   source/blender/blenlib/BLI_length_parameterize.hh
M   source/blender/blenlib/BLI_task.hh
M   source/blender/blenlib/intern/offset_indices.cc
M   source/blender/nodes/NOD_static_types.h
M   source/blender/nodes/geometry/CMakeLists.txt
M   source/blender/nodes/geometry/node_geometry_register.cc
M   source/blender/nodes/geometry/node_geometry_register.hh
A   source/blender/nodes/geometry/nodes/node_geo_interpolate_curves.cc
M   tests/python/CMakeLists.txt

===

diff --git a/release/scripts/startup/bl_ui/node_add_menu_geometry.py 
b/release/scripts/startup/bl_ui/node_add_menu_geometry.py
index 2554734d903..cdbd05b74a3 100644
--- a/release/scripts/startup/bl_ui/node_add_menu_geometry.py
+++ b/release/scripts/startup/bl_ui/node_add_menu_geometry.py
@@ -101,6 +101,7 @@ class NODE_MT_geometry_node_GEO_CURVE_OPERATIONS(Menu):
 node_add_menu.add_node_type(layout, 
"GeometryNodeDeformCurvesOnSurface")
 node_add_menu.add_node_type(layout, "GeometryNodeFillCurve")
 node_add_menu.add_node_type(layout, "GeometryNodeFilletCurve")
+node_add_menu.add_node_type(layout, "GeometryNodeInterpolateCurves")
 node_add_menu.add_node_type(layout, "GeometryNodeResampleCurve")
 node_add_menu.add_node_type(layout, "GeometryNodeReverseCurve")
 node_add_menu.add_node_type(layout, "GeometryNodeSampleCurve")
diff --git a/source/blender/blenkernel/BKE_node.h 
b/source/blender/blenkernel/BKE_node.h
index 915ca87621a..386fe7fc77f 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -1562,6 +1562,8 @@ void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, 
struct Scene *scene, i
 
 /** \} */
 
+#define GEO_NODE_INTERPOLATE_CURVES 2000
+
 void BKE_node_system_init(void);
 void BKE_node_system_exit(void);
 
diff --git a/source/blender/blenlib/BLI_length_parameterize.hh 
b/source/blender/blenlib/BLI_length_parameterize.hh
index d81bcbe1e7a..df00e004060 100644
--- a/source/blender/blenlib/BLI_length_parameterize.hh
+++ b/source/blender/blenlib/BLI_length_parameterize.hh
@@ -105,7 +105,7 @@ inline void sample_at_length(const Span 
accumulated_segment_lengths,
 
   BLI_assert(lengths.size() > 0);
   BLI_assert(sample_length >= 0.0f);
-  BLI_assert(sample_length <= lengths.last());
+  BLI_assert(sample_length <= lengths.last() + 0.1f);
 
   if (hint != nullptr && hint->segment_index >= 0) {
 const float length_in_segment = sample_length - hint->segment_start;
diff --git a/source/blender/blenlib/BLI_task.hh 
b/source/blender/blenlib/BLI_task.hh
index e7d9a21439a..c726691ad46 100644
--- a/source/blender/blenlib/BLI_task.hh
+++ b/source/blender/blenlib/BLI_task.hh
@@ -37,7 +37,7 @@
 namespace blender::threading {
 
 template
-void parallel_for_each(Range , const Function )
+void parallel_for_each(Range &, const Function )
 {
 #ifdef WITH_TBB
   tbb::parallel_for_each(range, function);
diff --git a/source/blender/blenlib/intern/offset_indices.cc 
b/source/blender/blenlib/intern/offset_indices.cc
index fee57e32ffa..2ac11fe631e 100644
--- a/source/blender/blenlib/intern/offset_indices.cc
+++ b/source/blender/blenlib/intern/offset_indices.cc
@@ -9,7 +9,7 @@ void accumulate_counts_to_offsets(MutableSpan 
counts_to_offsets, const int
   int offset = start_offset;
   for 

[Bf-blender-cvs] [cf50a3eabce] master: Cleanup: remove is_same method for virtual arrays

2023-01-18 Thread Jacques Lucke
Commit: cf50a3eabce47810d38c093be63919487dfbe42c
Author: Jacques Lucke
Date:   Wed Jan 18 13:24:00 2023 +0100
Branches: master
https://developer.blender.org/rBcf50a3eabce47810d38c093be63919487dfbe42c

Cleanup: remove is_same method for virtual arrays

This abstraction is rarely used. It could be replaced by some more
general "query" API in the future. For now it's easier to just compare
pointers in the Set Position node where this was used.

This is possible now, because mesh positions are stored as flat `float3`
arrays (previously, they were stored as `MVert` with some other data
interleaved).

===

M   source/blender/blenlib/BLI_virtual_array.hh
M   source/blender/nodes/geometry/nodes/node_geo_set_position.cc

===

diff --git a/source/blender/blenlib/BLI_virtual_array.hh 
b/source/blender/blenlib/BLI_virtual_array.hh
index 819807843df..c57c1dae961 100644
--- a/source/blender/blenlib/BLI_virtual_array.hh
+++ b/source/blender/blenlib/BLI_virtual_array.hh
@@ -156,15 +156,6 @@ template class VArrayImpl {
   {
 return false;
   }
-
-  /**
-   * Return true when the other virtual array should be considered to be the 
same, e.g. because it
-   * shares the same underlying memory.
-   */
-  virtual bool is_same(const VArrayImpl & /*other*/) const
-  {
-return false;
-  }
 };
 
 /** Similar to #VArrayImpl, but adds methods that allow modifying the 
referenced elements. */
@@ -238,18 +229,6 @@ template class VArrayImpl_For_Span : public 
VMutableArrayImpl {
 return CommonVArrayInfo(CommonVArrayInfo::Type::Span, true, data_);
   }
 
-  bool is_same(const VArrayImpl ) const final
-  {
-if (other.size() != this->size_) {
-  return false;
-}
-const CommonVArrayInfo other_info = other.common_info();
-if (other_info.type != CommonVArrayInfo::Type::Span) {
-  return false;
-}
-return data_ == static_cast(other_info.data);
-  }
-
   void materialize(IndexMask mask, T *dst) const override
   {
 mask.foreach_index([&](const int64_t i) { dst[i] = data_[i]; });
@@ -482,23 +461,6 @@ class VArrayImpl_For_DerivedSpan final : public 
VMutableArrayImpl {
   }
 });
   }
-
-  bool is_same(const VArrayImpl ) const override
-  {
-if (other.size() != this->size_) {
-  return false;
-}
-if (const VArrayImpl_For_DerivedSpan *other_typed 
=
-dynamic_cast *>()) {
-  return other_typed->data_ == data_;
-}
-if (const VArrayImpl_For_DerivedSpan 
*other_typed =
-dynamic_cast *>(
-)) {
-  return other_typed->data_ == data_;
-}
-return false;
-  }
 };
 
 template class VArrayCommon {
 return *static_cast(info.data);
   }
 
-  /**
-   * Return true when the other virtual references the same underlying memory.
-   */
-  bool is_same(const VArrayCommon ) const
-  {
-if (!*this || !other) {
-  return false;
-}
-/* Check in both directions in case one does not know how to compare to 
the other
- * implementation. */
-if (impl_->is_same(*other.impl_)) {
-  return true;
-}
-if (other.impl_->is_same(*impl_)) {
-  return true;
-}
-return false;
-  }
-
   /** Copy the entire virtual array into a span. */
   void materialize(MutableSpan r_span) const
   {
diff --git a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc 
b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
index caa911a5f45..2ad126567d1 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_set_position.cc
@@ -29,9 +29,16 @@ static void 
set_computed_position_and_offset(GeometryComponent ,
  const IndexMask selection)
 {
   MutableAttributeAccessor attributes = *component.attributes_for_write();
+
+  /* Optimize the case when `in_positions` references the original positions 
array. */
   const VArray positions_read_only = 
attributes.lookup("position");
+  bool positions_are_original = false;
+  if (positions_read_only.is_span() && in_positions.is_span()) {
+positions_are_original = positions_read_only.get_internal_span().data() ==
+ in_positions.get_internal_span().data();
+  }
 
-  if (in_positions.is_same(positions_read_only)) {
+  if (positions_are_original) {
 if (const std::optional offset = in_offsets.get_if_single()) {
   if (math::is_zero(*offset)) {
 return;
@@ -81,7 +88,7 @@ static void 
set_computed_position_and_offset(GeometryComponent ,
 default: {
   AttributeWriter positions = 
attributes.lookup_for_write("position");
   MutableVArraySpan out_positions_span = positions.varray;
-  if (in_positions.is_same(positions_read_only)) {
+  if (positions_are_original) {
 devirtualiz

[Bf-blender-cvs] [2c2178549b6] master: Curves: add OffsetIndices abstraction

2023-01-18 Thread Jacques Lucke
Commit: 2c2178549b6c80154184958a55978e1aac7af6fc
Author: Jacques Lucke
Date:   Wed Jan 18 11:52:27 2023 +0100
Branches: master
https://developer.blender.org/rB2c2178549b6c80154184958a55978e1aac7af6fc

Curves: add OffsetIndices abstraction

This changes how we access the points that correspond to each curve in a 
`CurvesGeometry`.
Previously, `CurvesGeometry::points_for_curve(int curve_index) -> IndexRange`
was called for every curve in many loops. Now one has to call
`CurvesGeometry::points_by_curve() -> OffsetIndices` before the
loop and use the returned value inside the loop.

While this is a little bit more verbose in general, it has some benefits:
* Better standardization of how "offset indices" are used. The new data
  structure can be used independent of curves.
* Allows for better data oriented design. Generally, we want to retrieve
  all the arrays we need for a loop first and then do the processing.
  Accessing the old `CurvesGeometry::points_for_curve(...)` did not follow
  that design because it hid the underlying offset array.
* Makes it easier to pass the offsets to a function without having to
  pass the entire `CurvesGeometry`.
* Can improve performance in theory due to one less memory access
  because `this` does not have to be dereferenced every time.
  This likely doesn't have a noticable impact in practice.

Differential Revision: https://developer.blender.org/D17025

===

M   source/blender/blenkernel/BKE_curves.hh
M   source/blender/blenkernel/BKE_curves_utils.hh
M   source/blender/blenkernel/intern/curve_legacy_convert.cc
M   source/blender/blenkernel/intern/curve_to_mesh_convert.cc
M   source/blender/blenkernel/intern/curves_geometry.cc
M   source/blender/blenkernel/intern/curves_utils.cc
M   source/blender/blenkernel/intern/geometry_component_curves.cc
A   source/blender/blenlib/BLI_offset_indices.hh
M   source/blender/blenlib/CMakeLists.txt
A   source/blender/blenlib/intern/offset_indices.cc
M   source/blender/draw/intern/draw_cache_impl_curves.cc
M   source/blender/draw/intern/draw_curves.cc
M   source/blender/editors/curves/intern/curves_add.cc
M   source/blender/editors/curves/intern/curves_ops.cc
M   source/blender/editors/curves/intern/curves_selection.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_brush.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_comb.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_delete.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_grow_shrink.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_ops.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_pinch.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_puff.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_selection_paint.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_slide.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_smooth.cc
M   source/blender/editors/sculpt_paint/curves_sculpt_snake_hook.cc
M   source/blender/geometry/intern/add_curves_on_mesh.cc
M   source/blender/geometry/intern/fillet_curves.cc
M   source/blender/geometry/intern/resample_curves.cc
M   source/blender/geometry/intern/set_curve_type.cc
M   source/blender/geometry/intern/subdivide_curves.cc
M   source/blender/geometry/intern/trim_curves.cc
M   source/blender/nodes/geometry/nodes/node_geo_blur_attribute.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_endpoint_selection.cc
M   
source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_spline_parameter.cc
M   
source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc
M   source/blender/nodes/geometry/nodes/node_geo_deform_curves_on_surface.cc
M   source/blender/nodes/geometry/nodes/node_geo_duplicate_elements.cc
M   source/blender/nodes/geometry/nodes/node_geo_input_spline_length.cc
M   source/blender/nodes/geometry/nodes/node_geo_input_tangent.cc
M   source/blender/nodes/geometry/nodes/node_geo_offset_point_in_curve.cc

===

diff --git a/source/blender/blenkernel/BKE_curves.hh 
b/source/blender/blenkernel/BKE_curves.hh
index 1ed872c8ab8..6569629c71f 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -18,6 +18,7 @@
 #include "BLI_generic_virtual_array.hh"
 #include "BLI_index_mask.hh"
 #include "BLI_math_vector_types.hh"
+#include "BLI_offset_indices.hh"
 #include "BLI_shared_cache.hh"
 #include "BLI_span.hh"
 #include "BLI_task.hh"
@@ -164,23 +165,17 @@ class CurvesGeometry : public ::C

[Bf-blender-cvs] [737e7a63b16] master: Fix: incorrect curve type counts after adding curves of same type

2023-01-17 Thread Jacques Lucke
Commit: 737e7a63b1664d7cff0fdd9587ed6a4f2ccffe7e
Author: Jacques Lucke
Date:   Wed Jan 18 00:05:33 2023 +0100
Branches: master
https://developer.blender.org/rB737e7a63b1664d7cff0fdd9587ed6a4f2ccffe7e

Fix: incorrect curve type counts after adding curves of same type

===

M   source/blender/blenkernel/intern/curves_geometry.cc

===

diff --git a/source/blender/blenkernel/intern/curves_geometry.cc 
b/source/blender/blenkernel/intern/curves_geometry.cc
index 133521bc298..3d4f81019a7 100644
--- a/source/blender/blenkernel/intern/curves_geometry.cc
+++ b/source/blender/blenkernel/intern/curves_geometry.cc
@@ -263,7 +263,7 @@ void CurvesGeometry::fill_curve_types(const IndexMask 
selection, const CurveType
   }
   if (std::optional single_type = this->curve_types().get_if_single()) 
{
 if (single_type == type) {
-  /* No need for an array if the types are already a single with the 
correct type. */
+  this->fill_curve_types(type);
   return;
 }
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0d43e832235] temp-offset-array-ref: initial offset array

2023-01-17 Thread Jacques Lucke
Commit: 0d43e832235e1abde3a2acfde2b64006b0549868
Author: Jacques Lucke
Date:   Tue Jan 17 22:25:47 2023 +0100
Branches: temp-offset-array-ref
https://developer.blender.org/rB0d43e832235e1abde3a2acfde2b64006b0549868

initial offset array

===

M   source/blender/blenkernel/BKE_curves.hh
A   source/blender/blenlib/BLI_offset_array_ref.hh
M   source/blender/geometry/intern/trim_curves.cc
M   
source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   
source/blender/nodes/geometry/nodes/node_geo_curve_topology_points_of_curve.cc

===

diff --git a/source/blender/blenkernel/BKE_curves.hh 
b/source/blender/blenkernel/BKE_curves.hh
index 1ed872c8ab8..1530b2ea7eb 100644
--- a/source/blender/blenkernel/BKE_curves.hh
+++ b/source/blender/blenkernel/BKE_curves.hh
@@ -18,6 +18,7 @@
 #include "BLI_generic_virtual_array.hh"
 #include "BLI_index_mask.hh"
 #include "BLI_math_vector_types.hh"
+#include "BLI_offset_array_ref.hh"
 #include "BLI_shared_cache.hh"
 #include "BLI_span.hh"
 #include "BLI_task.hh"
@@ -176,6 +177,11 @@ class CurvesGeometry : public ::CurvesGeometry {
   Span offsets() const;
   MutableSpan offsets_for_write();
 
+  /**
+   * The offsets of every curve into arrays on the points domain.
+   */
+  OffsetArrayRef points_by_curve() const;
+
   /**
* Access a range of indices of point data for a specific curve.
*/
@@ -884,6 +890,11 @@ inline const std::array 
::curve_type_counts
   return this->runtime->type_counts;
 }
 
+inline OffsetArrayRef CurvesGeometry::points_by_curve() const
+{
+  return OffsetArrayRef({this->curve_offsets, this->curve_num + 1});
+}
+
 inline IndexRange CurvesGeometry::points_for_curve(const int index) const
 {
   /* Offsets are not allocated when there are no curves. */
diff --git a/source/blender/blenlib/BLI_offset_array_ref.hh 
b/source/blender/blenlib/BLI_offset_array_ref.hh
new file mode 100644
index 000..39d4386faab
--- /dev/null
+++ b/source/blender/blenlib/BLI_offset_array_ref.hh
@@ -0,0 +1,39 @@
+#pragma once
+
+#include "BLI_index_range.hh"
+#include "BLI_span.hh"
+
+namespace blender {
+
+template class OffsetArrayRef {
+ private:
+  static_assert(std::is_integral_v);
+
+  Span offsets_;
+
+ public:
+  OffsetArrayRef(const Span offsets) : offsets_(offsets)
+  {
+BLI_assert(std::is_sorted(offsets_.begin(), offsets_.end()));
+  }
+
+  IndexRange operator[](const int64_t index) const
+  {
+BLI_assert(index >= 0);
+BLI_assert(index < offsets_.size() - 1);
+const int64_t begin = offsets_[index];
+const int64_t end = offsets_[index + 1];
+const int64_t size = end - begin;
+return IndexRange(begin, size);
+  }
+
+  IndexRange operator[](const IndexRange indices) const
+  {
+const int64_t begin = offsets_[indices.start()];
+const int64_t end = offsets_[indices.one_after_last()];
+const int64_t size = end - begin;
+return IndexRange(begin, size);
+  }
+};
+
+}  // namespace blender
diff --git a/source/blender/geometry/intern/trim_curves.cc 
b/source/blender/geometry/intern/trim_curves.cc
index 361415aa540..b4b2b3e7d5f 100644
--- a/source/blender/geometry/intern/trim_curves.cc
+++ b/source/blender/geometry/intern/trim_curves.cc
@@ -617,11 +617,13 @@ static void trim_polygonal_curves(const 
bke::CurvesGeometry _curves,
 {
   const Span src_positions = src_curves.positions();
   MutableSpan dst_positions = dst_curves.positions_for_write();
+  const OffsetArrayRef src_points_by_curve = src_curves.points_by_curve();
+  const OffsetArrayRef dst_points_by_curve = dst_curves.points_by_curve();
 
   threading::parallel_for(selection.index_range(), 512, [&](const IndexRange 
range) {
 for (const int64_t curve_i : selection.slice(range)) {
-  const IndexRange src_points = src_curves.points_for_curve(curve_i);
-  const IndexRange dst_points = dst_curves.points_for_curve(curve_i);
+  const IndexRange src_points = src_points_by_curve[curve_i];
+  const IndexRange dst_points = dst_points_by_curve[curve_i];
 
   sample_interval_linear(src_positions.slice(src_points),
  dst_positions,
diff --git 
a/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc 
b/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
index 9f0d40bb0d7..f63d12e6c03 100644
--- 
a/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
+++ 
b/source/blender/nodes/geometry/nodes/node_geo_curve_handle_type_selection.cc
@@ -55,9 +55,10 @@ static void select_by_handle_type(const bke::CurvesGeometry 
,
   VArray curve_types = curves.curve_types();
   VArray left = curves.handle_types_left();

[Bf-blender-cvs] [1d253b66525] master: Fix T103945: incorrect anonymous attribute references

2023-01-17 Thread Jacques Lucke
Commit: 1d253b6652518a68731a5d8a5909c8b29174b894
Author: Jacques Lucke
Date:   Tue Jan 17 18:40:28 2023 +0100
Branches: master
https://developer.blender.org/rB1d253b6652518a68731a5d8a5909c8b29174b894

Fix T103945: incorrect anonymous attribute references

The case where the same field group input is evaluated on
more than one geometry inputs was not handled correctly.

===

M   source/blender/nodes/intern/geometry_nodes_lazy_function.cc

===

diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index 4aec8d405ea..54f8c3c912d 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -2250,15 +2250,18 @@ struct GeometryNodesLazyFunctionGraphBuilder {
   AttributeReferenceKey key;
   key.type = AttributeReferenceKeyType::InputField;
   key.index = relation.field_input;
-  r_attribute_reference_keys.add_new(key);
-  AttributeReferenceInfo info;
-  lf::OutputSocket _field_socket = *const_cast(
-  mapping_->group_input_sockets[relation.field_input]);
-  info.lf_attribute_set_socket = _get_attributes_node(lf_field_socket);
+  const int key_index = r_attribute_reference_keys.index_of_or_add(key);
+  if (key_index >= r_attribute_reference_infos.size()) {
+AttributeReferenceInfo info;
+lf::OutputSocket _field_socket = *const_cast(
+mapping_->group_input_sockets[relation.field_input]);
+info.lf_attribute_set_socket = 
_get_attributes_node(lf_field_socket);
+r_attribute_reference_infos.append(info);
+  }
+  AttributeReferenceInfo  = r_attribute_reference_infos[key_index];
   for (const bNode *bnode : btree_.group_input_nodes()) {
 
info.initial_geometry_sockets.append(>output_socket(relation.geometry_input));
   }
-  r_attribute_reference_infos.append(std::move(info));
 }
 /* Find group outputs that attributes need to be propagated to. */
 for (const aal::PropagateRelation  : 
tree_relations.propagate_relations) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [34326fec027] master: Fix: sample index node outputs default value

2023-01-17 Thread Jacques Lucke
Commit: 34326fec02709ffaeba4d4b59f24cb0c53e721a8
Author: Jacques Lucke
Date:   Tue Jan 17 18:29:25 2023 +0100
Branches: master
https://developer.blender.org/rB34326fec02709ffaeba4d4b59f24cb0c53e721a8

Fix: sample index node outputs default value

Error in rBb5105085139227a713f154446ff6a3255cb8be99.

===

M   source/blender/nodes/geometry/nodes/node_geo_sample_index.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc 
b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
index 850b2cfdd66..2ac19b02f9c 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
@@ -323,7 +323,7 @@ static void node_geo_exec(GeoNodeExecParams params)
 const GVArray  = evaluator.get_evaluated(0);
 BUFFER_FOR_CPP_TYPE_VALUE(cpp_type, buffer);
 data.get_to_uninitialized(index, buffer);
-output_field = fn::make_constant_field(cpp_type, cpp_type.default_value());
+output_field = fn::make_constant_field(cpp_type, buffer);
 cpp_type.destruct(buffer);
   }
   else {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8b660e1cbfb] master: Cleanup: use defaulted constructor

2023-01-17 Thread Jacques Lucke
Commit: 8b660e1cbfb7f2dba55d3fb4f327c8678e9799b3
Author: Jacques Lucke
Date:   Tue Jan 17 13:43:38 2023 +0100
Branches: master
https://developer.blender.org/rB8b660e1cbfb7f2dba55d3fb4f327c8678e9799b3

Cleanup: use defaulted constructor

===

M   source/blender/blenlib/BLI_color.hh

===

diff --git a/source/blender/blenlib/BLI_color.hh 
b/source/blender/blenlib/BLI_color.hh
index 0256cec667c..f334ade6dda 100644
--- a/source/blender/blenlib/BLI_color.hh
+++ b/source/blender/blenlib/BLI_color.hh
@@ -248,7 +248,7 @@ class ColorSceneLinearByteEncoded4b final
 template
 class ColorTheme4 final : public ColorRGBA {
  public:
-  constexpr ColorTheme4() : ColorRGBA(){};
+  constexpr ColorTheme4() = default;
 
   constexpr ColorTheme4(const ChannelStorageType *rgba)
   : ColorRGBA(rgba)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b5105085139] master: Geometry Nodes: optimize Sample Index node with constant index

2023-01-17 Thread Jacques Lucke
Commit: b5105085139227a713f154446ff6a3255cb8be99
Author: Jacques Lucke
Date:   Tue Jan 17 13:29:55 2023 +0100
Branches: master
https://developer.blender.org/rBb5105085139227a713f154446ff6a3255cb8be99

Geometry Nodes: optimize Sample Index node with constant index

Previously, the node would always evaluate the input field on the
entire geometry domain. This is good when most indices will be
accessed afterwards. However, it is quite a bad when only a single
index is used. Now the field is only evaluated for that one index.

===

M   source/blender/nodes/geometry/nodes/node_geo_sample_index.cc

===

diff --git a/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc 
b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
index 4f6062cb553..850b2cfdd66 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
@@ -299,12 +299,39 @@ static void node_geo_exec(GeoNodeExecParams params)
   const eCustomDataType data_type = eCustomDataType(storage.data_type);
   const eAttrDomain domain = eAttrDomain(storage.domain);
 
-  auto fn = std::make_shared(std::move(geometry),
-  
get_input_attribute_field(params, data_type),
-  domain,
-  bool(storage.clamp));
-  auto op = FieldOperation::Create(std::move(fn), 
{params.extract_input>("Index")});
-  output_attribute_field(params, GField(std::move(op)));
+  GField value_field = get_input_attribute_field(params, data_type);
+  ValueOrField index_value_or_field = 
params.extract_input>("Index");
+  const CPPType _type = value_field.cpp_type();
+
+  GField output_field;
+  if (index_value_or_field.is_field()) {
+/* If the index is a field, the output has to be a field that still 
depends on the input. */
+auto fn = std::make_shared(
+std::move(geometry), std::move(value_field), domain, 
bool(storage.clamp));
+auto op = FieldOperation::Create(std::move(fn), 
{index_value_or_field.as_field()});
+output_field = GField(std::move(op));
+  }
+  else if (const GeometryComponent *component = 
find_source_component(geometry, domain)) {
+/* Optimization for the case when the index is a single value. Here only 
that one index has to
+ * be evaluated. */
+const int index = index_value_or_field.as_value();
+const IndexMask mask = IndexRange(index, 1);
+bke::GeometryFieldContext geometry_context(*component, domain);
+FieldEvaluator evaluator(geometry_context, );
+evaluator.add(value_field);
+evaluator.evaluate();
+const GVArray  = evaluator.get_evaluated(0);
+BUFFER_FOR_CPP_TYPE_VALUE(cpp_type, buffer);
+data.get_to_uninitialized(index, buffer);
+output_field = fn::make_constant_field(cpp_type, cpp_type.default_value());
+cpp_type.destruct(buffer);
+  }
+  else {
+/* Output default value if there is no geometry. */
+output_field = fn::make_constant_field(cpp_type, cpp_type.default_value());
+  }
+
+  output_attribute_field(params, std::move(output_field));
 }
 
 }  // namespace blender::nodes::node_geo_sample_index_cc

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [03fab057f1e] master: Cleanup: correct asserts

2023-01-17 Thread Jacques Lucke
Commit: 03fab057f1e456a13191c13a6aa2454ecd60a442
Author: Jacques Lucke
Date:   Tue Jan 17 13:11:56 2023 +0100
Branches: master
https://developer.blender.org/rB03fab057f1e456a13191c13a6aa2454ecd60a442

Cleanup: correct asserts

===

M   source/blender/blenlib/intern/array_utils.cc

===

diff --git a/source/blender/blenlib/intern/array_utils.cc 
b/source/blender/blenlib/intern/array_utils.cc
index 1b5b071f0cd..1e1ef354461 100644
--- a/source/blender/blenlib/intern/array_utils.cc
+++ b/source/blender/blenlib/intern/array_utils.cc
@@ -10,7 +10,8 @@ void copy(const GVArray ,
   const int64_t grain_size)
 {
   BLI_assert(src.type() == dst.type());
-  BLI_assert(src.size() == dst.size());
+  BLI_assert(src.size() >= selection.min_array_size());
+  BLI_assert(dst.size() >= selection.min_array_size());
   threading::parallel_for(selection.index_range(), grain_size, [&](const 
IndexRange range) {
 src.materialize_to_uninitialized(selection.slice(range), dst.data());
   });

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1a79bdfbf12] master: BLI: inline index mask slice methods

2023-01-14 Thread Jacques Lucke
Commit: 1a79bdfbf120f5fe258a295732fb7ac21df9392d
Author: Jacques Lucke
Date:   Sat Jan 14 19:40:22 2023 +0100
Branches: master
https://developer.blender.org/rB1a79bdfbf120f5fe258a295732fb7ac21df9392d

BLI: inline index mask slice methods

Those are simple enough to be inlined.

===

M   source/blender/blenlib/BLI_index_mask.hh
M   source/blender/blenlib/intern/index_mask.cc

===

diff --git a/source/blender/blenlib/BLI_index_mask.hh 
b/source/blender/blenlib/BLI_index_mask.hh
index 2144955f4f5..c37820d648b 100644
--- a/source/blender/blenlib/BLI_index_mask.hh
+++ b/source/blender/blenlib/BLI_index_mask.hh
@@ -234,8 +234,15 @@ class IndexMask {
 return indices_.first() >= range.first() && indices_.last() <= 
range.last();
   }
 
-  IndexMask slice(int64_t start, int64_t size) const;
-  IndexMask slice(IndexRange slice) const;
+  IndexMask slice(const int64_t start, const int64_t size) const
+  {
+return IndexMask(indices_.slice(start, size));
+  }
+
+  IndexMask slice(const IndexRange slice) const
+  {
+return IndexMask(indices_.slice(slice));
+  }
 
   IndexMask slice_safe(int64_t start, int64_t size) const;
   IndexMask slice_safe(IndexRange slice) const;
diff --git a/source/blender/blenlib/intern/index_mask.cc 
b/source/blender/blenlib/intern/index_mask.cc
index 72282bc69f3..adcc2de8bdb 100644
--- a/source/blender/blenlib/intern/index_mask.cc
+++ b/source/blender/blenlib/intern/index_mask.cc
@@ -5,16 +5,6 @@
 
 namespace blender {
 
-IndexMask IndexMask::slice(int64_t start, int64_t size) const
-{
-  return this->slice(IndexRange(start, size));
-}
-
-IndexMask IndexMask::slice(IndexRange slice) const
-{
-  return IndexMask(indices_.slice(slice));
-}
-
 IndexMask IndexMask::slice_safe(int64_t start, int64_t size) const
 {
   return this->slice_safe(IndexRange(start, size));

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ff15edc6ab4] master: Cleanup: unify method parameters for virtual arrays

2023-01-14 Thread Jacques Lucke
Commit: ff15edc6ab4add3a814f8f80c2a96b1a67def65c
Author: Jacques Lucke
Date:   Sat Jan 14 19:13:51 2023 +0100
Branches: master
https://developer.blender.org/rBff15edc6ab4add3a814f8f80c2a96b1a67def65c

Cleanup: unify method parameters for virtual arrays

This makes `GVArrayImpl` and `VArrayImpl` more similar.
Only passing the pointer instead of the span also increases
efficiency a little bit. The downside is that a few asserts had
to be removed as well. However, in practice the same asserts
are in place at a higher level as well (in `VArrayCommon`).

===

M   source/blender/blenkernel/intern/geometry_component_mesh.cc
M   source/blender/blenlib/BLI_generic_virtual_array.hh
M   source/blender/blenlib/BLI_virtual_array.hh

===

diff --git a/source/blender/blenkernel/intern/geometry_component_mesh.cc 
b/source/blender/blenkernel/intern/geometry_component_mesh.cc
index 7b694be324a..bdb1b0edf8b 100644
--- a/source/blender/blenkernel/intern/geometry_component_mesh.cc
+++ b/source/blender/blenkernel/intern/geometry_component_mesh.cc
@@ -984,26 +984,26 @@ class VArrayImpl_For_VertexWeights final : public 
VMutableArrayImpl {
 });
   }
 
-  void materialize(IndexMask mask, MutableSpan r_span) const override
+  void materialize(IndexMask mask, float *dst) const override
   {
 if (dverts_ == nullptr) {
-  return r_span.fill_indices(mask, 0.0f);
+  mask.foreach_index([&](const int i) { dst[i] = 0.0f; });
 }
 threading::parallel_for(mask.index_range(), 4096, [&](const IndexRange 
range) {
   for (const int64_t i : mask.slice(range)) {
 if (const MDeformWeight *weight = this->find_weight_at_index(i)) {
-  r_span[i] = weight->weight;
+  dst[i] = weight->weight;
 }
 else {
-  r_span[i] = 0.0f;
+  dst[i] = 0.0f;
 }
   }
 });
   }
 
-  void materialize_to_uninitialized(IndexMask mask, MutableSpan r_span) 
const override
+  void materialize_to_uninitialized(IndexMask mask, float *dst) const override
   {
-this->materialize(mask, r_span);
+this->materialize(mask, dst);
   }
 
  private:
diff --git a/source/blender/blenlib/BLI_generic_virtual_array.hh 
b/source/blender/blenlib/BLI_generic_virtual_array.hh
index cba767341c1..cb45da5e495 100644
--- a/source/blender/blenlib/BLI_generic_virtual_array.hh
+++ b/source/blender/blenlib/BLI_generic_virtual_array.hh
@@ -388,25 +388,24 @@ template class VArrayImpl_For_GVArray : 
public VArrayImpl {
 return true;
   }
 
-  void materialize(IndexMask mask, MutableSpan r_span) const override
+  void materialize(IndexMask mask, T *dst) const override
   {
-varray_.materialize(mask, r_span.data());
+varray_.materialize(mask, dst);
   }
 
-  void materialize_to_uninitialized(IndexMask mask, MutableSpan r_span) 
const override
+  void materialize_to_uninitialized(IndexMask mask, T *dst) const override
   {
-varray_.materialize_to_uninitialized(mask, r_span.data());
+varray_.materialize_to_uninitialized(mask, dst);
   }
 
-  void materialize_compressed(IndexMask mask, MutableSpan r_span) const 
override
+  void materialize_compressed(IndexMask mask, T *dst) const override
   {
-varray_.materialize_compressed(mask, r_span.data());
+varray_.materialize_compressed(mask, dst);
   }
 
-  void materialize_compressed_to_uninitialized(IndexMask mask,
-   MutableSpan r_span) const 
override
+  void materialize_compressed_to_uninitialized(IndexMask mask, T *dst) const 
override
   {
-varray_.materialize_compressed_to_uninitialized(mask, r_span.data());
+varray_.materialize_compressed_to_uninitialized(mask, dst);
   }
 };
 
@@ -539,25 +538,24 @@ template class 
VMutableArrayImpl_For_GVMutableArray : public VMutabl
 return true;
   }
 
-  void materialize(IndexMask mask, MutableSpan r_span) const override
+  void materialize(IndexMask mask, T *dst) const override
   {
-varray_.materialize(mask, r_span.data());
+varray_.materialize(mask, dst);
   }
 
-  void materialize_to_uninitialized(IndexMask mask, MutableSpan r_span) 
const override
+  void materialize_to_uninitialized(IndexMask mask, T *dst) const override
   {
-varray_.materialize_to_uninitialized(mask, r_span.data());
+varray_.materialize_to_uninitialized(mask, dst);
   }
 
-  void materialize_compressed(IndexMask mask, MutableSpan r_span) const 
override
+  void materialize_compressed(IndexMask mask, T *dst) const override
   {
-varray_.materialize_compressed(mask, r_span.data());
+varray_.materialize_compressed(mask, dst);
   }
 
-  void materialize_compressed_to_uninitialized(IndexMask mask,
-   MutableSpan r_span) const 
override
+  void materialize_compressed_to_uninitialized(IndexMask mask, T *dst) const 
ove

[Bf-blender-cvs] [72cc68e2997] master: Functions: only allocate resource scope when it is actually used

2023-01-14 Thread Jacques Lucke
Commit: 72cc68e2997c273c8437146637f453178c8469de
Author: Jacques Lucke
Date:   Sat Jan 14 15:56:43 2023 +0100
Branches: master
https://developer.blender.org/rB72cc68e2997c273c8437146637f453178c8469de

Functions: only allocate resource scope when it is actually used

In most cases it is currently not used, so always having it there
causes unnecessary overhead. In my test file that causes
a 2 % performance improvement.

===

M   source/blender/functions/FN_multi_function_params.hh
M   source/blender/functions/intern/multi_function_params.cc

===

diff --git a/source/blender/functions/FN_multi_function_params.hh 
b/source/blender/functions/FN_multi_function_params.hh
index 98e03760d47..5ca9f45009b 100644
--- a/source/blender/functions/FN_multi_function_params.hh
+++ b/source/blender/functions/FN_multi_function_params.hh
@@ -25,7 +25,7 @@ namespace blender::fn::multi_function {
 
 class ParamsBuilder {
  private:
-  ResourceScope scope_;
+  std::unique_ptr scope_;
   const Signature *signature_;
   IndexMask mask_;
   int64_t min_array_size_;
@@ -90,13 +90,15 @@ class ParamsBuilder {
 
   void add_readonly_vector_input(const GVectorArray _array, StringRef 
expected_name = "")
   {
-
this->add_readonly_vector_input(scope_.construct(vector_array),
-expected_name);
+this->add_readonly_vector_input(
+
this->resource_scope().construct(vector_array),
+expected_name);
   }
   void add_readonly_vector_input(const GSpan single_vector, StringRef 
expected_name = "")
   {
 this->add_readonly_vector_input(
-scope_.construct(single_vector, 
min_array_size_),
+
this->resource_scope().construct(single_vector,
+
min_array_size_),
 expected_name);
   }
   void add_readonly_vector_input(const GVVectorArray , StringRef 
expected_name = "")
@@ -174,11 +176,6 @@ class ParamsBuilder {
 return *std::get(actual_params_[param_index]);
   }
 
-  ResourceScope _scope()
-  {
-return scope_;
-  }
-
  private:
   void assert_current_param_type(ParamType param_type, StringRef expected_name 
= "")
   {
@@ -214,6 +211,14 @@ class ParamsBuilder {
 return actual_params_.size();
   }
 
+  ResourceScope _scope()
+  {
+if (!scope_) {
+  scope_ = std::make_unique();
+}
+return *scope_;
+  }
+
   void add_unused_output_for_unsupporting_function(const CPPType );
 };
 
@@ -285,7 +290,7 @@ class Params {
   const VVectorArray _vector_input(int param_index, StringRef name 
= "")
   {
 const GVVectorArray _array = 
this->readonly_vector_input(param_index, name);
-return 
builder_->scope_.construct>(vector_array);
+return 
builder_->resource_scope().construct>(vector_array);
   }
   const GVVectorArray _vector_input(int param_index, StringRef name = 
"")
   {
diff --git a/source/blender/functions/intern/multi_function_params.cc 
b/source/blender/functions/intern/multi_function_params.cc
index ce5421e4b8c..17e41454b5d 100644
--- a/source/blender/functions/intern/multi_function_params.cc
+++ b/source/blender/functions/intern/multi_function_params.cc
@@ -6,12 +6,13 @@ namespace blender::fn::multi_function {
 
 void ParamsBuilder::add_unused_output_for_unsupporting_function(const CPPType 
)
 {
-  void *buffer = scope_.linear_allocator().allocate(type.size() * 
min_array_size_,
-type.alignment());
+  ResourceScope  = this->resource_scope();
+  void *buffer = scope.linear_allocator().allocate(type.size() * 
min_array_size_,
+   type.alignment());
   const GMutableSpan span{type, buffer, min_array_size_};
   actual_params_.append_unchecked_as(std::in_place_type, span);
   if (!type.is_trivially_destructible()) {
-scope_.add_destruct_call(
+scope.add_destruct_call(
 [, buffer, mask = mask_]() { type.destruct_indices(buffer, mask); 
});
   }
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [50980981e32] master: Cleanup: remove MF prefix from some classes in multi-function namespace

2023-01-14 Thread Jacques Lucke
Commit: 50980981e32667b1a4478a8013b1c78cf1cc5aa5
Author: Jacques Lucke
Date:   Sat Jan 14 15:42:52 2023 +0100
Branches: master
https://developer.blender.org/rB50980981e32667b1a4478a8013b1c78cf1cc5aa5

Cleanup: remove MF prefix from some classes in multi-function namespace

This was missing in rBeedcf1876a6651c38d8f4daa2e65d1fb81f77c5d.

===

M   source/blender/functions/FN_multi_function.hh
M   source/blender/functions/FN_multi_function_builder.hh
M   source/blender/functions/FN_multi_function_param_type.hh
M   source/blender/functions/FN_multi_function_params.hh
M   source/blender/functions/FN_multi_function_procedure.hh
M   source/blender/functions/FN_multi_function_procedure_executor.hh
M   source/blender/functions/FN_multi_function_signature.hh
M   source/blender/functions/intern/multi_function.cc
M   source/blender/functions/intern/multi_function_builder.cc
M   source/blender/functions/intern/multi_function_procedure.cc
M   source/blender/functions/intern/multi_function_procedure_executor.cc
M   source/blender/functions/tests/FN_field_test.cc
M   source/blender/functions/tests/FN_multi_function_test.cc
M   source/blender/functions/tests/FN_multi_function_test_common.hh
M   source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
M   source/blender/nodes/function/nodes/node_fn_input_special_characters.cc
M   source/blender/nodes/function/nodes/node_fn_separate_color.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
M   source/blender/nodes/geometry/nodes/node_geo_proximity.cc
M   source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
M   source/blender/nodes/shader/nodes/node_shader_color_ramp.cc
M   source/blender/nodes/shader/nodes/node_shader_curves.cc
M   source/blender/nodes/shader/nodes/node_shader_math.cc
M   source/blender/nodes/shader/nodes/node_shader_mix.cc
M   source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_brick.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_checker.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_magic.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_wave.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc

===

diff --git a/source/blender/functions/FN_multi_function.hh 
b/source/blender/functions/FN_multi_function.hh
index 7a281809e4e..c00b0eb7b40 100644
--- a/source/blender/functions/FN_multi_function.hh
+++ b/source/blender/functions/FN_multi_function.hh
@@ -18,8 +18,8 @@
  * combination of input and output).
  *
  * To call a multi-function, one has to provide three things:
- * - `MFParams`: This references the input and output arrays that the function 
works with. The
- *  arrays are not owned by MFParams.
+ * - `Params`: This references the input and output arrays that the function 
works with. The
+ *  arrays are not owned by Params.
  * - `IndexMask`: An array of indices indicating which indices in the provided 
arrays should be
  *  touched/processed.
  * - `Context`: Further information for the called function.
@@ -52,8 +52,8 @@ class MultiFunction {
* - Automatic index mask offsetting to avoid large temporary intermediate 
arrays that are mostly
*   unused.
*/
-  void call_auto(IndexMask mask, MFParams params, Context context) const;
-  virtual void call(IndexMask mask, MFParams params, Context context) const = 
0;
+  void call_auto(IndexMask mask, Params params, Context context) const;
+  virtual void call(IndexMask mask, Params params, Context context) const = 0;
 
   virtual uint64_t hash() const
   {
diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index bb366ea47ea..b1996ac8f43 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -371,12 +371,12 @@ template 
/*param_tags*/,
  std

[Bf-blender-cvs] [8625495b1c8] master: Functions: improve handling of unused multi-function outputs

2023-01-14 Thread Jacques Lucke
Commit: 8625495b1c8240e21abac4d255312ddd76fd794d
Author: Jacques Lucke
Date:   Sat Jan 14 15:35:44 2023 +0100
Branches: master
https://developer.blender.org/rB8625495b1c8240e21abac4d255312ddd76fd794d

Functions: improve handling of unused multi-function outputs

Previously, `ParamsBuilder` lazily allocated an array for an
output when it was unused, but the called multi-function
wanted to access it. Now, whether the multi-function supports
an output to be unused is part of the signature. This way, the
allocation can happen earlier when the parameters are build.
The benefit is that this makes all methods of `MFParams`
thread-safe again, removing the need for a mutex.

===

M   source/blender/functions/FN_multi_function_params.hh
M   source/blender/functions/FN_multi_function_signature.hh
M   source/blender/functions/intern/multi_function.cc
M   source/blender/functions/intern/multi_function_params.cc
M   source/blender/nodes/function/nodes/node_fn_separate_color.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
M   source/blender/nodes/geometry/nodes/node_geo_proximity.cc
M   source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_brick.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_checker.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_magic.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_wave.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc

===

diff --git a/source/blender/functions/FN_multi_function_params.hh 
b/source/blender/functions/FN_multi_function_params.hh
index 9865a62df1b..8f176b36a19 100644
--- a/source/blender/functions/FN_multi_function_params.hh
+++ b/source/blender/functions/FN_multi_function_params.hh
@@ -32,9 +32,6 @@ class ParamsBuilder {
   Vector>
   actual_params_;
 
-  std::mutex mutex_;
-  Vector> dummy_output_spans_;
-
   friend class MFParams;
 
   ParamsBuilder(const Signature , const IndexMask mask)
@@ -127,9 +124,15 @@ class ParamsBuilder {
 const ParamType _type = signature_->params[param_index].type;
 BLI_assert(param_type.category() == ParamCategory::SingleOutput);
 const CPPType  = param_type.data_type().single_type();
-/* An empty span indicates that this is ignored. */
-const GMutableSpan dummy_span{type};
-actual_params_.append_unchecked_as(std::in_place_type, 
dummy_span);
+
+if (bool(signature_->params[param_index].flag & 
ParamFlag::SupportsUnusedOutput)) {
+  /* An empty span indicates that this is ignored. */
+  const GMutableSpan dummy_span{type};
+  actual_params_.append_unchecked_as(std::in_place_type, 
dummy_span);
+}
+else {
+  this->add_unused_output_for_unsupporting_function(type);
+}
   }
 
   void add_vector_output(GVectorArray _array, StringRef expected_name = 
"")
@@ -210,6 +213,8 @@ class ParamsBuilder {
   {
 return actual_params_.size();
   }
+
+  void add_unused_output_for_unsupporting_function(const CPPType );
 };
 
 class MFParams {
@@ -252,13 +257,11 @@ class MFParams {
   GMutableSpan uninitialized_single_output(int param_index, StringRef name = 
"")
   {
 this->assert_correct_param(param_index, name, ParamCategory::SingleOutput);
+BLI_assert(
+!bool(builder_->signature_->params[param_index].flag & 
ParamFlag::SupportsUnusedOutput));
 GMutableSpan span = 
std::get(builder_->actual_params_[param_index]);
-if (!span.is_empty()) {
-  return span;
-}
-/* The output is ignored by the caller, but the multi-function does not 
handle this case. So
- * create a temporary buffer that the multi-function can write to. */
-return this->ensure_dummy_single_output(param_index);
+BLI_assert(span.size() >= builder_->min_array_size_);
+return span;
   }
 
   /**
@@ -273,6 +276,8 @@ class MFParams {
   GMutableSpan uninitialized_single_output_if_required(int param_index, 
StringRef name = "")
   {
 this->assert_correct_param(param_index, name, ParamCategory::SingleOutput);
+BLI_assert(
+bool(builder_->signature_->params[param_index].flag & 
ParamFlag::SupportsUnusedOutput));
 return std

[Bf-blender-cvs] [aea26830dc7] master: Cleanup: use std::get instead of std::get_if

2023-01-14 Thread Jacques Lucke
Commit: aea26830dc7b7f68508ad93d07e538652b767903
Author: Jacques Lucke
Date:   Sat Jan 14 14:16:51 2023 +0100
Branches: master
https://developer.blender.org/rBaea26830dc7b7f68508ad93d07e538652b767903

Cleanup: use std::get instead of std::get_if

`std::get` could not be used due to restrictions on macos.
However, the minimum requirement has been lifted in
{rB597aecc01644f0063fa4545dabadc5f73387e3d3}.

===

M   source/blender/functions/FN_multi_function_params.hh

===

diff --git a/source/blender/functions/FN_multi_function_params.hh 
b/source/blender/functions/FN_multi_function_params.hh
index caf43714e50..9865a62df1b 100644
--- a/source/blender/functions/FN_multi_function_params.hh
+++ b/source/blender/functions/FN_multi_function_params.hh
@@ -160,7 +160,7 @@ class ParamsBuilder {
 BLI_assert(ELEM(signature_->params[param_index].type.category(),
 ParamCategory::SingleOutput,
 ParamCategory::SingleMutable));
-return *std::get_if(_params_[param_index]);
+return std::get(actual_params_[param_index]);
   }
 
   GVectorArray _vector_array(int param_index)
@@ -168,7 +168,7 @@ class ParamsBuilder {
 BLI_assert(ELEM(signature_->params[param_index].type.category(),
 ParamCategory::VectorOutput,
 ParamCategory::VectorMutable));
-return **std::get_if(_params_[param_index]);
+return *std::get(actual_params_[param_index]);
   }
 
   ResourceScope _scope()
@@ -229,7 +229,7 @@ class MFParams {
   const GVArray _single_input(int param_index, StringRef name = "")
   {
 this->assert_correct_param(param_index, name, ParamCategory::SingleInput);
-return *std::get_if(_->actual_params_[param_index]);
+return std::get(builder_->actual_params_[param_index]);
   }
 
   /**
@@ -241,7 +241,7 @@ class MFParams {
   bool single_output_is_required(int param_index, StringRef name = "")
   {
 this->assert_correct_param(param_index, name, ParamCategory::SingleOutput);
-return 
!std::get_if(_->actual_params_[param_index])->is_empty();
+return 
!std::get(builder_->actual_params_[param_index]).is_empty();
   }
 
   template
@@ -252,7 +252,7 @@ class MFParams {
   GMutableSpan uninitialized_single_output(int param_index, StringRef name = 
"")
   {
 this->assert_correct_param(param_index, name, ParamCategory::SingleOutput);
-GMutableSpan span = 
*std::get_if(_->actual_params_[param_index]);
+GMutableSpan span = 
std::get(builder_->actual_params_[param_index]);
 if (!span.is_empty()) {
   return span;
 }
@@ -273,7 +273,7 @@ class MFParams {
   GMutableSpan uninitialized_single_output_if_required(int param_index, 
StringRef name = "")
   {
 this->assert_correct_param(param_index, name, ParamCategory::SingleOutput);
-return *std::get_if(_->actual_params_[param_index]);
+return std::get(builder_->actual_params_[param_index]);
   }
 
   template
@@ -285,7 +285,7 @@ class MFParams {
   const GVVectorArray _vector_input(int param_index, StringRef name = 
"")
   {
 this->assert_correct_param(param_index, name, ParamCategory::VectorInput);
-return **std::get_if(_->actual_params_[param_index]);
+return *std::get(builder_->actual_params_[param_index]);
   }
 
   template
@@ -296,7 +296,7 @@ class MFParams {
   GVectorArray _output(int param_index, StringRef name = "")
   {
 this->assert_correct_param(param_index, name, ParamCategory::VectorOutput);
-return **std::get_if(_->actual_params_[param_index]);
+return *std::get(builder_->actual_params_[param_index]);
   }
 
   template MutableSpan single_mutable(int param_index, 
StringRef name = "")
@@ -306,7 +306,7 @@ class MFParams {
   GMutableSpan single_mutable(int param_index, StringRef name = "")
   {
 this->assert_correct_param(param_index, name, 
ParamCategory::SingleMutable);
-return *std::get_if(_->actual_params_[param_index]);
+return std::get(builder_->actual_params_[param_index]);
   }
 
   template
@@ -317,7 +317,7 @@ class MFParams {
   GVectorArray _mutable(int param_index, StringRef name = "")
   {
 this->assert_correct_param(param_index, name, 
ParamCategory::VectorMutable);
-return **std::get_if(_->actual_params_[param_index]);
+return *std::get(builder_->actual_params_[param_index]);
   }
 
  private:

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8126d92073b] master: Cleanup: fix compile error in debug build

2023-01-14 Thread Jacques Lucke
Commit: 8126d92073b222ba6647c7988e728895ab3f14a8
Author: Jacques Lucke
Date:   Sat Jan 14 14:15:21 2023 +0100
Branches: master
https://developer.blender.org/rB8126d92073b222ba6647c7988e728895ab3f14a8

Cleanup: fix compile error in debug build

===

M   source/blender/blenkernel/intern/mesh_runtime.cc

===

diff --git a/source/blender/blenkernel/intern/mesh_runtime.cc 
b/source/blender/blenkernel/intern/mesh_runtime.cc
index b3e416c2b7b..9509eea39e0 100644
--- a/source/blender/blenkernel/intern/mesh_runtime.cc
+++ b/source/blender/blenkernel/intern/mesh_runtime.cc
@@ -341,22 +341,22 @@ bool BKE_mesh_runtime_is_valid(Mesh *me_eval)
   do_fixes,
   );
 
-  is_valid &= BKE_mesh_validate_arrays(
-  me_eval,
-  reinterpret_cast(positions.data()),
-  positions.size(),
-  edges.data(),
-  edges.size(),
-  static_cast(CustomData_get_layer(_eval->fdata, CD_MFACE)),
-  me_eval->totface,
-  loops.data(),
-  loops.size(),
-  polys.data(),
-  polys.size(),
-  me_eval->deform_verts_for_write().data(),
-  do_verbose,
-  do_fixes,
-  );
+  is_valid &= BKE_mesh_validate_arrays(me_eval,
+   
reinterpret_cast(positions.data()),
+   positions.size(),
+   edges.data(),
+   edges.size(),
+   static_cast(CustomData_get_layer_for_write(
+   _eval->fdata, CD_MFACE, 
me_eval->totface)),
+   me_eval->totface,
+   loops.data(),
+   loops.size(),
+   polys.data(),
+   polys.size(),
+   
me_eval->deform_verts_for_write().data(),
+   do_verbose,
+   do_fixes,
+   );
 
   BLI_assert(changed == false);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ba714198913] master: Cleanup: improve const correctness of bvh tree

2023-01-13 Thread Jacques Lucke
Commit: ba714198913cf580293ebd30fb638364b62f854b
Author: Jacques Lucke
Date:   Fri Jan 13 18:09:10 2023 +0100
Branches: master
https://developer.blender.org/rBba714198913cf580293ebd30fb638364b62f854b

Cleanup: improve const correctness of bvh tree

===

M   source/blender/blenlib/BLI_kdopbvh.h
M   source/blender/blenlib/intern/BLI_kdopbvh.c

===

diff --git a/source/blender/blenlib/BLI_kdopbvh.h 
b/source/blender/blenlib/BLI_kdopbvh.h
index 463c95cf4f3..ac083b71e33 100644
--- a/source/blender/blenlib/BLI_kdopbvh.h
+++ b/source/blender/blenlib/BLI_kdopbvh.h
@@ -203,7 +203,7 @@ BVHTreeOverlap *BLI_bvhtree_overlap_self(const BVHTree 
*tree,
  BVHTree_OverlapCallback callback,
  void *userdata);
 
-int *BLI_bvhtree_intersect_plane(BVHTree *tree, float plane[4], uint 
*r_intersect_num);
+int *BLI_bvhtree_intersect_plane(const BVHTree *tree, float plane[4], uint 
*r_intersect_num);
 
 /**
  * Number of times #BLI_bvhtree_insert has been called.
@@ -218,20 +218,20 @@ float BLI_bvhtree_get_epsilon(const BVHTree *tree);
 /**
  * This function returns the bounding box of the BVH tree.
  */
-void BLI_bvhtree_get_bounding_box(BVHTree *tree, float r_bb_min[3], float 
r_bb_max[3]);
+void BLI_bvhtree_get_bounding_box(const BVHTree *tree, float r_bb_min[3], 
float r_bb_max[3]);
 
 /**
  * Find nearest node to the given coordinates
  * (if nearest is given it will only search nodes where
  * square distance is smaller than nearest->dist).
  */
-int BLI_bvhtree_find_nearest_ex(BVHTree *tree,
+int BLI_bvhtree_find_nearest_ex(const BVHTree *tree,
 const float co[3],
 BVHTreeNearest *nearest,
 BVHTree_NearestPointCallback callback,
 void *userdata,
 int flag);
-int BLI_bvhtree_find_nearest(BVHTree *tree,
+int BLI_bvhtree_find_nearest(const BVHTree *tree,
  const float co[3],
  BVHTreeNearest *nearest,
  BVHTree_NearestPointCallback callback,
@@ -241,13 +241,13 @@ int BLI_bvhtree_find_nearest(BVHTree *tree,
  * Find the first node nearby.
  * Favors speed over quality since it doesn't find the best target node.
  */
-int BLI_bvhtree_find_nearest_first(BVHTree *tree,
+int BLI_bvhtree_find_nearest_first(const BVHTree *tree,
const float co[3],
float dist_sq,
BVHTree_NearestPointCallback callback,
void *userdata);
 
-int BLI_bvhtree_ray_cast_ex(BVHTree *tree,
+int BLI_bvhtree_ray_cast_ex(const BVHTree *tree,
 const float co[3],
 const float dir[3],
 float radius,
@@ -255,7 +255,7 @@ int BLI_bvhtree_ray_cast_ex(BVHTree *tree,
 BVHTree_RayCastCallback callback,
 void *userdata,
 int flag);
-int BLI_bvhtree_ray_cast(BVHTree *tree,
+int BLI_bvhtree_ray_cast(const BVHTree *tree,
  const float co[3],
  const float dir[3],
  float radius,
@@ -272,7 +272,7 @@ int BLI_bvhtree_ray_cast(BVHTree *tree,
  * It also avoid redundant argument and return value which aren't meaningful
  * when collecting multiple hits.
  */
-void BLI_bvhtree_ray_cast_all_ex(BVHTree *tree,
+void BLI_bvhtree_ray_cast_all_ex(const BVHTree *tree,
  const float co[3],
  const float dir[3],
  float radius,
@@ -280,7 +280,7 @@ void BLI_bvhtree_ray_cast_all_ex(BVHTree *tree,
  BVHTree_RayCastCallback callback,
  void *userdata,
  int flag);
-void BLI_bvhtree_ray_cast_all(BVHTree *tree,
+void BLI_bvhtree_ray_cast_all(const BVHTree *tree,
   const float co[3],
   const float dir[3],
   float radius,
@@ -296,10 +296,13 @@ float BLI_bvhtree_bb_raycast(const float bv[6],
 /**
  * Range query.
  */
-int BLI_bvhtree_range_query(
-BVHTree *tree, const float co[3], float radius, BVHTree_RangeQuery 
callback, void *userdata);
+int BLI_bvhtree_range_query(const BVHTree *tree,
+const float co[3],
+float radius,
+BVHTree_RangeQuery callback,
+void *userdata);
 
-int BLI_bvhtree_find_nearest_projected(BVHTree *tree,
+int BLI_bvhtree_find_nearest_projected(const BVHTree *t

[Bf-blender-cvs] [761e6b1b78d] master: Fix: crash when opening node add menu

2023-01-13 Thread Jacques Lucke
Commit: 761e6b1b78da9bcfdb4bafdd2a9db062c8d4963c
Author: Jacques Lucke
Date:   Fri Jan 13 17:25:20 2023 +0100
Branches: master
https://developer.blender.org/rB761e6b1b78da9bcfdb4bafdd2a9db062c8d4963c

Fix: crash when opening node add menu

Differential Revision: https://developer.blender.org/D16995

===

M   source/blender/editors/space_node/add_menu_assets.cc

===

diff --git a/source/blender/editors/space_node/add_menu_assets.cc 
b/source/blender/editors/space_node/add_menu_assets.cc
index 912493c3e7e..060e8914194 100644
--- a/source/blender/editors/space_node/add_menu_assets.cc
+++ b/source/blender/editors/space_node/add_menu_assets.cc
@@ -108,6 +108,9 @@ static AssetItemTree build_catalog_tree(const bContext , 
const bNodeTree *node
 
 const asset_system::AssetCatalog *catalog = 
all_library->catalog_service->find_catalog(
 meta_data.catalog_id);
+if (catalog == nullptr) {
+  return true;
+}
 assets_per_path.add(catalog->path, LibraryAsset{all_library_ref, asset});
 return true;
   });
@@ -121,6 +124,9 @@ static AssetItemTree build_catalog_tree(const bContext , 
const bNodeTree *node
 }
 asset_system::AssetCatalog *catalog = 
all_library->catalog_service->find_catalog(
 item.get_catalog_id());
+if (catalog == nullptr) {
+  return;
+}
 catalogs_with_node_assets.insert_item(*catalog);
   });

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5d07b0e6da7] master: Cleanup: delegate to string_view equality for StringRef

2023-01-11 Thread Jacques Lucke
Commit: 5d07b0e6da70d380a2d42fdade8caf02737342ad
Author: Jacques Lucke
Date:   Wed Jan 11 13:19:11 2023 +0100
Branches: master
https://developer.blender.org/rB5d07b0e6da70d380a2d42fdade8caf02737342ad

Cleanup: delegate to string_view equality for StringRef

This also fixes an issue introduced in rBd3e8d63a8c455d0,
where the function relied on the `StringRef` being null-terminated.

===

M   source/blender/blenlib/BLI_string_ref.hh

===

diff --git a/source/blender/blenlib/BLI_string_ref.hh 
b/source/blender/blenlib/BLI_string_ref.hh
index 4f6f2cbfa41..f7606ccc860 100644
--- a/source/blender/blenlib/BLI_string_ref.hh
+++ b/source/blender/blenlib/BLI_string_ref.hh
@@ -604,28 +604,12 @@ inline std::string operator+(StringRef a, StringRef b)
  * Ideally, we only use StringRef in our code to avoid this problem 
altogether. */
 constexpr bool operator==(StringRef a, StringRef b)
 {
-  if (a.size() != b.size()) {
-return false;
-  }
-  if (a.data() == b.data()) {
-/* This also avoids passing null to the call below when both are null,
- * which would results in an ASAN warning. */
-return true;
-  }
-  /* Account for a single value being null, resulting in an ASAN warning.
-   * Ensure an empty string is equal to a string with a null pointer. */
-  if (!a.data()) {
-return *b.data() == '\0';
-  }
-  if (!b.data()) {
-return *a.data() == '\0';
-  }
-  return STREQLEN(a.data(), b.data(), size_t(a.size()));
+  return std::string_view(a) == std::string_view(b);
 }
 
 constexpr bool operator!=(StringRef a, StringRef b)
 {
-  return !(a == b);
+  return std::string_view(a) != std::string_view(b);
 }
 
 constexpr bool operator<(StringRef a, StringRef b)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [8a3a1a0c144] master: Fix T103781: assert when connecting viewer node on mesh without faces

2023-01-10 Thread Jacques Lucke
Commit: 8a3a1a0c14468fd397548378ce4499e566b274a3
Author: Jacques Lucke
Date:   Tue Jan 10 17:13:12 2023 +0100
Branches: master
https://developer.blender.org/rB8a3a1a0c14468fd397548378ce4499e566b274a3

Fix T103781: assert when connecting viewer node on mesh without faces

`Span.data()` does not have to be `nullptr` when the size is zero.
This happens e.g. when slicing a span to a size of zero.

===

M   source/blender/blenlib/BLI_generic_array.hh

===

diff --git a/source/blender/blenlib/BLI_generic_array.hh 
b/source/blender/blenlib/BLI_generic_array.hh
index 03dc8814309..c46dbe0c907 100644
--- a/source/blender/blenlib/BLI_generic_array.hh
+++ b/source/blender/blenlib/BLI_generic_array.hh
@@ -89,11 +89,8 @@ class GArray {
*/
   GArray(const GSpan span, Allocator allocator = {}) : GArray(span.type(), 
span.size(), allocator)
   {
-if (span.data() != nullptr) {
-  BLI_assert(span.size() != 0);
-  /* Use copy assign rather than construct since the memory is already 
initialized. */
-  type_->copy_assign_n(span.data(), data_, size_);
-}
+/* Use copy assign rather than construct since the memory is already 
initialized. */
+type_->copy_assign_n(span.data(), data_, size_);
   }
 
   /**

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ca45c2dc59a] master: Fix T103756: wrong anonymous attribute tooltip

2023-01-09 Thread Jacques Lucke
Commit: ca45c2dc59ab663835d2c85e6b22a0f77ab46568
Author: Jacques Lucke
Date:   Mon Jan 9 14:52:06 2023 +0100
Branches: master
https://developer.blender.org/rBca45c2dc59ab663835d2c85e6b22a0f77ab46568

Fix T103756: wrong anonymous attribute tooltip

===

M   source/blender/blenkernel/BKE_anonymous_attribute_id.hh
M   source/blender/blenkernel/BKE_geometry_fields.hh
M   source/blender/blenkernel/intern/anonymous_attribute_id.cc
M   source/blender/nodes/NOD_geometry_exec.hh
M   source/blender/nodes/intern/node_geometry_exec.cc

===

diff --git a/source/blender/blenkernel/BKE_anonymous_attribute_id.hh 
b/source/blender/blenkernel/BKE_anonymous_attribute_id.hh
index b738ff50604..7e4ca4b7afd 100644
--- a/source/blender/blenkernel/BKE_anonymous_attribute_id.hh
+++ b/source/blender/blenkernel/BKE_anonymous_attribute_id.hh
@@ -47,6 +47,8 @@ class AnonymousAttributeID {
 return name_;
   }
 
+  virtual std::string user_name() const;
+
   void user_add() const
   {
 users_.fetch_add(1);
diff --git a/source/blender/blenkernel/BKE_geometry_fields.hh 
b/source/blender/blenkernel/BKE_geometry_fields.hh
index 967bb912cc6..085bade618c 100644
--- a/source/blender/blenkernel/BKE_geometry_fields.hh
+++ b/source/blender/blenkernel/BKE_geometry_fields.hh
@@ -268,7 +268,7 @@ class AnonymousAttributeFieldInput : public 
GeometryFieldInput {
   AnonymousAttributeFieldInput(AutoAnonymousAttributeID anonymous_id,
const CPPType ,
std::string producer_name)
-  : GeometryFieldInput(type, anonymous_id->name()),
+  : GeometryFieldInput(type, anonymous_id->user_name()),
 anonymous_id_(std::move(anonymous_id)),
 producer_name_(producer_name)
   {
diff --git a/source/blender/blenkernel/intern/anonymous_attribute_id.cc 
b/source/blender/blenkernel/intern/anonymous_attribute_id.cc
index e15ea6b643c..38f9c3df772 100644
--- a/source/blender/blenkernel/intern/anonymous_attribute_id.cc
+++ b/source/blender/blenkernel/intern/anonymous_attribute_id.cc
@@ -4,6 +4,11 @@
 
 namespace blender::bke {
 
+std::string AnonymousAttributeID::user_name() const
+{
+  return this->name();
+}
+
 bool AnonymousAttributePropagationInfo::propagate(const AnonymousAttributeID 
_id) const
 {
   if (this->propagate_all) {
diff --git a/source/blender/nodes/NOD_geometry_exec.hh 
b/source/blender/nodes/NOD_geometry_exec.hh
index ed0ba4105fd..088e076be35 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -49,12 +49,16 @@ using geo_eval_log::NodeWarningType;
  */
 class NodeAnonymousAttributeID : public AnonymousAttributeID {
   std::string long_name_;
+  std::string socket_name_;
 
  public:
   NodeAnonymousAttributeID(const Object ,
const ComputeContext _context,
const bNode ,
-   const StringRef identifier);
+   const StringRef identifier,
+   const StringRef name);
+
+  std::string user_name() const override;
 };
 
 class GeoNodeExecParams {
@@ -288,13 +292,15 @@ class GeoNodeExecParams {
 if (!this->anonymous_attribute_output_is_required(output_identifier) && 
!force_create) {
   return {};
 }
+const bNodeSocket _socket = 
node_.output_by_identifier(output_identifier);
 const GeoNodesLFUserData _data = *this->user_data();
 const ComputeContext _context = *user_data.compute_context;
 return MEM_new(__func__,
  
*user_data.modifier_data->self_object,
  compute_context,
  node_,
- output_identifier);
+ output_identifier,
+ output_socket.name);
   }
 
   /**
diff --git a/source/blender/nodes/intern/node_geometry_exec.cc 
b/source/blender/nodes/intern/node_geometry_exec.cc
index c338ecacbc9..1824ff965ea 100644
--- a/source/blender/nodes/intern/node_geometry_exec.cc
+++ b/source/blender/nodes/intern/node_geometry_exec.cc
@@ -18,7 +18,9 @@ namespace blender::nodes {
 NodeAnonymousAttributeID::NodeAnonymousAttributeID(const Object ,
const ComputeContext 
_context,
const bNode ,
-   const StringRef identifier)
+   const StringRef identifier,
+   const StringRef name)
+: socket_name_(name)
 {
   const ComputeContextHash  = compute_context.hash();
   {
@@ -36,6 +38,11 @@ NodeAnonymousAttributeID::N

[Bf-blender-cvs] [29a41ed6c2f] master: Fix T103747: crash when using rotation output of Curve to Points node

2023-01-09 Thread Jacques Lucke
Commit: 29a41ed6c2f86248516c3d983f807000685305ef
Author: Jacques Lucke
Date:   Mon Jan 9 14:31:36 2023 +0100
Branches: master
https://developer.blender.org/rB29a41ed6c2f86248516c3d983f807000685305ef

Fix T103747: crash when using rotation output of Curve to Points node

===

M   source/blender/nodes/NOD_geometry_exec.hh
M   source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc

===

diff --git a/source/blender/nodes/NOD_geometry_exec.hh 
b/source/blender/nodes/NOD_geometry_exec.hh
index 60f58f4c215..ed0ba4105fd 100644
--- a/source/blender/nodes/NOD_geometry_exec.hh
+++ b/source/blender/nodes/NOD_geometry_exec.hh
@@ -283,9 +283,9 @@ class GeoNodeExecParams {
* attribute is not needed.
*/
   AutoAnonymousAttributeID get_output_anonymous_attribute_id_if_needed(
-  const StringRef output_identifier)
+  const StringRef output_identifier, const bool force_create = false)
   {
-if (!this->anonymous_attribute_output_is_required(output_identifier)) {
+if (!this->anonymous_attribute_output_is_required(output_identifier) && 
!force_create) {
   return {};
 }
 const GeoNodesLFUserData _data = *this->user_data();
diff --git a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc 
b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
index 6e443f1efb7..ab7a9bef8db 100644
--- a/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
+++ b/source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
@@ -111,12 +111,13 @@ static void node_geo_exec(GeoNodeExecParams params)
 
   
GeometryComponentEditData::remember_deformed_curve_positions_if_necessary(geometry_set);
 
-  AutoAnonymousAttributeID tangent_anonymous_id =
-  params.get_output_anonymous_attribute_id_if_needed("Tangent");
-  AutoAnonymousAttributeID normal_anonymous_id =
-  params.get_output_anonymous_attribute_id_if_needed("Normal");
   AutoAnonymousAttributeID rotation_anonymous_id =
   params.get_output_anonymous_attribute_id_if_needed("Rotation");
+  const bool need_tangent_and_normal = bool(rotation_anonymous_id);
+  AutoAnonymousAttributeID tangent_anonymous_id =
+  params.get_output_anonymous_attribute_id_if_needed("Tangent", 
need_tangent_and_normal);
+  AutoAnonymousAttributeID normal_anonymous_id =
+  params.get_output_anonymous_attribute_id_if_needed("Normal", 
need_tangent_and_normal);
 
   geometry::ResampleCurvesOutputAttributeIDs resample_attributes;
   resample_attributes.tangent_id = tangent_anonymous_id.get();

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [73a2c79c074] master: Functions: free memory of unused sockets earlier

2023-01-08 Thread Jacques Lucke
Commit: 73a2c79c074ae0e3f5cbc970df0d502672aa2986
Author: Jacques Lucke
Date:   Sun Jan 8 21:09:33 2023 +0100
Branches: master
https://developer.blender.org/rB73a2c79c074ae0e3f5cbc970df0d502672aa2986

Functions: free memory of unused sockets earlier

During geometry nodes evaluation some sockets can be determined
to be unused, for example based on the condition input in a switch node.
Once a socket is determined to be unused, that information has to be
propagated backwards through the tree to free any memory that may
have been reserved for those sockets already. This is happening before
this commit already, but in a less ideal way.

Determining that sockets are unused early is good because it helps with
memory reuse and avoids copy-on-write copies caused by shared data.
Now, nodes that are scheduled because an output became unused have
priority over nodes scheduled for other reasons.

===

M   source/blender/functions/intern/lazy_function_graph_executor.cc

===

diff --git a/source/blender/functions/intern/lazy_function_graph_executor.cc 
b/source/blender/functions/intern/lazy_function_graph_executor.cc
index c7688f61460..4270885fc98 100644
--- a/source/blender/functions/intern/lazy_function_graph_executor.cc
+++ b/source/blender/functions/intern/lazy_function_graph_executor.cc
@@ -206,6 +206,44 @@ struct LockedNode {
 class Executor;
 class GraphExecutorLFParams;
 
+/**
+ * Keeps track of nodes that are currently scheduled on a thread. A node can 
only be scheduled by
+ * one thread at the same time.
+ */
+struct ScheduledNodes {
+ private:
+  /** Use two stacks of scheduled nodes for different priorities. */
+  Vector priority_;
+  Vector normal_;
+
+ public:
+  void schedule(const FunctionNode , const bool is_priority)
+  {
+if (is_priority) {
+  this->priority_.append();
+}
+else {
+  this->normal_.append();
+}
+  }
+
+  const FunctionNode *pop_next_node()
+  {
+if (!this->priority_.is_empty()) {
+  return this->priority_.pop_last();
+}
+if (!this->normal_.is_empty()) {
+  return this->normal_.pop_last();
+}
+return nullptr;
+  }
+
+  bool is_empty() const
+  {
+return this->priority_.is_empty() && this->normal_.is_empty();
+  }
+};
+
 struct CurrentTask {
   /**
* Mutex used to protect #scheduled_nodes when the executor uses 
multi-threading.
@@ -214,7 +252,7 @@ struct CurrentTask {
   /**
* Nodes that have been scheduled to execute next.
*/
-  Vector scheduled_nodes;
+  ScheduledNodes scheduled_nodes;
   /**
* Makes it cheaper to check if there are any scheduled nodes because it 
avoids locking the
* mutex.
@@ -330,7 +368,7 @@ class Executor {
   this->schedule_side_effect_nodes(side_effect_nodes, current_task);
 }
 
-this->schedule_newly_requested_outputs(current_task);
+this->schedule_for_new_output_usages(current_task);
 this->forward_newly_provided_inputs(current_task);
 
 this->run_task(current_task);
@@ -394,20 +432,29 @@ class Executor {
 std::destroy_at(_state);
   }
 
-  void schedule_newly_requested_outputs(CurrentTask _task)
+  /**
+   * When the usage of output values changed, propagate that information 
backwards.
+   */
+  void schedule_for_new_output_usages(CurrentTask _task)
   {
 for (const int graph_output_index : self_.graph_outputs_.index_range()) {
-  if (params_->get_output_usage(graph_output_index) != ValueUsage::Used) {
+  if (params_->output_was_set(graph_output_index)) {
 continue;
   }
-  if (params_->output_was_set(graph_output_index)) {
+  const ValueUsage output_usage = 
params_->get_output_usage(graph_output_index);
+  if (output_usage == ValueUsage::Maybe) {
 continue;
   }
   const InputSocket  = *self_.graph_outputs_[graph_output_index];
   const Node  = socket.node();
   NodeState _state = *node_states_[node.index_in_graph()];
   this->with_locked_node(node, node_state, current_task, [&](LockedNode 
_node) {
-this->set_input_required(locked_node, socket);
+if (output_usage == ValueUsage::Used) {
+  this->set_input_required(locked_node, socket);
+}
+else {
+  this->set_input_unused(locked_node, socket);
+}
   });
 }
   }
@@ -532,7 +579,7 @@ class Executor {
 for (const FunctionNode *node : side_effect_nodes) {
   NodeState _state = *node_states_[node->index_in_graph()];
   this->with_locked_node(*node, node_state, current_task, [&](LockedNode 
_node) {
-this->schedule_node(locked_node, current_task);
+this->schedule_node(locked_node, current_task, false);
   });
 }
   }
@@ -603,7 +650,7 @@ class Executor {
 return;
   }
   output_state.usage = ValueUsage::Used;
- 

[Bf-blender-cvs] [891b9730295] master: Functions: optimize multi-function evaluation in materialized mode

2023-01-08 Thread Jacques Lucke
Commit: 891b97302957dc4df3db6182c4121e39a0775e0b
Author: Jacques Lucke
Date:   Sun Jan 8 17:19:57 2023 +0100
Branches: master
https://developer.blender.org/rB891b97302957dc4df3db6182c4121e39a0775e0b

Functions: optimize multi-function evaluation in materialized mode

This allows auto-vectorization to happen when the a multi-function is
evaluated in "materialized" mode, i.e. it is processed in chunks where
all input and outputs values are stored in contiguous arrays.

It also unifies the handling input, mutable and output parameters a bit.
Now they all can use tempory buffers in the same way.

===

M   source/blender/functions/FN_multi_function_builder.hh

===

diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index 04849bcc221..bfe88e01f04 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -162,35 +162,24 @@ enum class MaterializeArgMode {
 
 template struct MaterializeArgInfo {
   MaterializeArgMode mode = MaterializeArgMode::Unknown;
-  Span internal_span;
+  const typename ParamTag::base_type *internal_span_data;
 };
 
 /**
- * Similar to #execute_array but accepts two mask inputs, one for inputs and 
one for outputs.
+ * Similar to #execute_array but is only used with arrays and does not need a 
mask.
  */
 template
-inline void execute_materialized_impl(TypeSequence 
/*param_tags*/,
-  const ElementFn element_fn,
-  const IndexRange in_mask,
-  const IndexMask out_mask,
-  Chunks &&__restrict... chunks)
+#if (defined(__GNUC__) && !defined(__clang__))
+[[gnu::optimize("-funroll-loops")]] [[gnu::optimize("O3")]]
+#endif
+inline void
+execute_materialized_impl(TypeSequence /*param_tags*/,
+  const ElementFn element_fn,
+  const int64_t size,
+  Chunks &&__restrict... chunks)
 {
-  BLI_assert(in_mask.size() == out_mask.size());
-  for (const int64_t i : IndexRange(in_mask.size())) {
-const int64_t in_i = in_mask[i];
-const int64_t out_i = out_mask[i];
-element_fn([&]() -> decltype(auto) {
-  using ParamTag = ParamTags;
-  if constexpr (ParamTag::category == ParamCategory::SingleInput) {
-return chunks[in_i];
-  }
-  else if constexpr (ParamTag::category == ParamCategory::SingleOutput) {
-return chunks[out_i];
-  }
-  else if constexpr (ParamTag::category == ParamCategory::SingleMutable) {
-return chunks[out_i];
-  }
-}()...);
+  for (int64_t i = 0; i < size; i++) {
+element_fn(chunks[i]...);
   }
 }
 
@@ -211,15 +200,12 @@ inline void 
execute_materialized(TypeSequence /* param_tags */,
* that large temporary arrays are needed. Using small chunks allows using 
small arrays, which
* are reused multiple times, which improves cache efficiency. The chunk 
size also shouldn't be
* too small, because then overhead of the outer loop over chunks becomes 
significant again. */
-  static constexpr int64_t MaxChunkSize = 32;
+  static constexpr int64_t MaxChunkSize = 64;
   const int64_t mask_size = mask.size();
-  const int64_t buffer_size = std::min(mask_size, MaxChunkSize);
-
-  /* Local buffers that are used to temporarily store values retrieved from 
virtual arrays. */
-  std::tuple...> 
buffers_owner;
+  const int64_t tmp_buffer_size = std::min(mask_size, MaxChunkSize);
 
-  /* A span for each parameter which is either empty or points to memory in 
#buffers_owner. */
-  std::tuple...> buffers;
+  /* Local buffers that are used to temporarily store values for processing. */
+  std::tuple...> 
temporary_buffers;
 
   /* Information about every parameter. */
   std::tuple...> args_info;
@@ -237,16 +223,17 @@ inline void 
execute_materialized(TypeSequence /* param_tags */,
   if (common_info.type == CommonVArrayInfo::Type::Single) {
 /* If an input #VArray is a single value, we have to fill the 
buffer with that value
  * only once. The same unchanged buffer can then be reused in 
every chunk. */
-MutableSpan in_chunk{std::get(buffers_owner).ptr(), 
buffer_size};
 const T _single = *static_cast(common_info.data);
-uninitialized_fill_n(in_chunk.data(), in_chunk.size(), in_single);
-std::get(buffers) = in_chunk;
+T *tmp_buffer = std::get(temporary_buffers).ptr();
+uninitialized_fill_n(tmp_buffer, tmp_buffer_size, in_single);
 arg_info.mode = MaterializeArgMode::Single;
   }
   else if (common_info.type == CommonVArrayInfo::Type::Span)

[Bf-blender-cvs] [710f8164b4e] master: Fix: crash when inserting reroute node

2023-01-08 Thread Jacques Lucke
Commit: 710f8164b4ed92f917f4b385bf834cc3dd34c80e
Author: Jacques Lucke
Date:   Sun Jan 8 15:19:39 2023 +0100
Branches: master
https://developer.blender.org/rB710f8164b4ed92f917f4b385bf834cc3dd34c80e

Fix: crash when inserting reroute node

===

M   source/blender/editors/space_node/node_edit.cc

===

diff --git a/source/blender/editors/space_node/node_edit.cc 
b/source/blender/editors/space_node/node_edit.cc
index fa26455f01c..ebcef77baef 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -1131,7 +1131,7 @@ bNodeSocket *node_find_indicated_socket(SpaceNode ,
 
   snode.edittree->ensure_topology_cache();
   const Span socket_locations = snode.runtime->all_socket_locations;
-  if (socket_locations.is_empty()) {
+  if (socket_locations.size() != snode.edittree->all_sockets().size()) {
 /* Sockets haven't been drawn yet, e.g. when the file is currently 
opening. */
 return nullptr;
   }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d8750aa1daf] master: Fix T103734: reroutes don't propagate attribute references correctly

2023-01-08 Thread Jacques Lucke
Commit: d8750aa1daf327bd3f369c2f4b467a72513bd92f
Author: Jacques Lucke
Date:   Sun Jan 8 15:17:09 2023 +0100
Branches: master
https://developer.blender.org/rBd8750aa1daf327bd3f369c2f4b467a72513bd92f

Fix T103734: reroutes don't propagate attribute references correctly

===

M   source/blender/blenkernel/intern/node_tree_anonymous_attributes.cc

===

diff --git a/source/blender/blenkernel/intern/node_tree_anonymous_attributes.cc 
b/source/blender/blenkernel/intern/node_tree_anonymous_attributes.cc
index 9ade129afb5..d355f6a768c 100644
--- a/source/blender/blenkernel/intern/node_tree_anonymous_attributes.cc
+++ b/source/blender/blenkernel/intern/node_tree_anonymous_attributes.cc
@@ -14,6 +14,11 @@ namespace blender::bke::anonymous_attribute_inferencing {
 namespace aal = nodes::aal;
 using nodes::NodeDeclaration;
 
+static bool socket_is_field(const bNodeSocket )
+{
+  return socket.display_shape == SOCK_DISPLAY_SHAPE_DIAMOND;
+}
+
 static const aal::RelationsInNode _relations_in_node(const bNode , 
ResourceScope )
 {
   if (node.is_group()) {
@@ -22,6 +27,25 @@ static const aal::RelationsInNode 
_relations_in_node(const bNode , Reso
   return *group->runtime->anonymous_attribute_relations;
 }
   }
+  if (node.is_reroute()) {
+const bNodeSocket  = node.input_socket(0);
+if (socket_is_field(socket)) {
+  static const aal::RelationsInNode field_relations = []() {
+aal::RelationsInNode relations;
+relations.reference_relations.append({0, 0});
+return relations;
+  }();
+  return field_relations;
+}
+if (socket.type == SOCK_GEOMETRY) {
+  static const aal::RelationsInNode geometry_relations = []() {
+aal::RelationsInNode relations;
+relations.propagate_relations.append({0, 0});
+return relations;
+  }();
+  return geometry_relations;
+}
+  }
   if (const NodeDeclaration *node_decl = node.declaration()) {
 if (const aal::RelationsInNode *relations = 
node_decl->anonymous_attribute_relations()) {
   return *relations;
@@ -41,11 +65,6 @@ Array 
get_relations_by_node(const bNodeTree ,
   return relations_by_node;
 }
 
-static bool socket_is_field(const bNodeSocket )
-{
-  return socket.display_shape == SOCK_DISPLAY_SHAPE_DIAMOND;
-}
-
 /**
  * Start at a group output socket and find all linked group inputs.
  */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [5f9a48ed597] master: Functions: improve compiler optimizability of multi-function evaluation

2023-01-08 Thread Jacques Lucke
Commit: 5f9a48ed59782e9b0b0c69bb7a2d869888434b07
Author: Jacques Lucke
Date:   Sun Jan 8 15:04:51 2023 +0100
Branches: master
https://developer.blender.org/rB5f9a48ed59782e9b0b0c69bb7a2d869888434b07

Functions: improve compiler optimizability of multi-function evaluation

This simplifies the code enough so that msvc is able to unroll and
vectorize some multi-functions like simple addition.

The performance improvements are almost as good as the GCC
improvements shown in D16942 (for add and multiply at least).

===

M   source/blender/functions/FN_multi_function_builder.hh

===

diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index 22c6e8a850e..04849bcc221 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -138,23 +138,18 @@ execute_array(TypeSequence /*param_tags*/,
* other. This is important for some compiler optimizations. */
   Args &&__restrict... args)
 {
-  for (const int64_t i : mask) {
-element_fn([&]() -> decltype(auto) {
-  using ParamTag = typename TypeSequence::template 
at_index;
-  if constexpr (ParamTag::category == ParamCategory::SingleInput) {
-/* For inputs, pass the value (or a reference to it) to the function. 
*/
-return args[i];
-  }
-  else if constexpr (ParamTag::category == ParamCategory::SingleOutput) {
-/* For outputs, pass a pointer to the function. This is done instead 
of passing a
- * reference, because the pointer points to uninitialized memory. */
-return args + i;
-  }
-  else if constexpr (ParamTag::category == ParamCategory::SingleMutable) {
-/* For mutables, pass a mutable reference to the function. */
-return args[i];
-  }
-}()...);
+  if constexpr (std::is_same_v, IndexRange>) {
+/* Having this explicit loop is necessary for msvc to be able to vectorize 
this. */
+const int64_t start = mask.start();
+const int64_t end = mask.one_after_last();
+for (int64_t i = start; i < end; i++) {
+  element_fn(args[i]...);
+}
+  }
+  else {
+for (const int32_t i : mask) {
+  element_fn(args[i]...);
+}
   }
 }
 
@@ -190,7 +185,7 @@ inline void 
execute_materialized_impl(TypeSequence /*param_tags*/,
 return chunks[in_i];
   }
   else if constexpr (ParamTag::category == ParamCategory::SingleOutput) {
-return chunks + out_i;
+return chunks[out_i];
   }
   else if constexpr (ParamTag::category == ParamCategory::SingleMutable) {
 return chunks[out_i];
@@ -472,7 +467,7 @@ inline auto 
build_multi_function_with_n_inputs_one_output(const char *name,
   constexpr auto param_tags = 
TypeSequence...,

MFParamTag>();
   auto call_fn = build_multi_function_call_from_element_fn(
-  [element_fn](const In &...in, Out *out) { new (out) 
Out(element_fn(in...)); },
+  [element_fn](const In &...in, Out ) { new () 
Out(element_fn(in...)); },
   exec_preset,
   param_tags);
   return CustomMF(name, call_fn, param_tags);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ef78811ac7b] master: Cleanup: add missing inline

2023-01-07 Thread Jacques Lucke
Commit: ef78811ac7b15f20d2aacd1a148998d0bbb25642
Author: Jacques Lucke
Date:   Sat Jan 7 23:49:36 2023 +0100
Branches: master
https://developer.blender.org/rBef78811ac7b15f20d2aacd1a148998d0bbb25642

Cleanup: add missing inline

===

M   source/blender/functions/FN_multi_function_builder.hh

===

diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index 20b28658932..22c6e8a850e 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -129,14 +129,14 @@ template /*param_tags*/,
-std::index_sequence /*indices*/,
-ElementFn element_fn,
-MaskT mask,
-/* Use restrict to tell the compiler that pointer inputs do not alias each
- * other. This is important for some compiler optimizations. */
-Args &&__restrict... args)
+inline void
+execute_array(TypeSequence /*param_tags*/,
+  std::index_sequence /*indices*/,
+  ElementFn element_fn,
+  MaskT mask,
+  /* Use restrict to tell the compiler that pointer inputs do not 
alias each
+   * other. This is important for some compiler optimizations. */
+  Args &&__restrict... args)
 {
   for (const int64_t i : mask) {
 element_fn([&]() -> decltype(auto) {
@@ -174,11 +174,11 @@ template struct MaterializeArgInfo {
  * Similar to #execute_array but accepts two mask inputs, one for inputs and 
one for outputs.
  */
 template
-void execute_materialized_impl(TypeSequence /*param_tags*/,
-   const ElementFn element_fn,
-   const IndexRange in_mask,
-   const IndexMask out_mask,
-   Chunks &&__restrict... chunks)
+inline void execute_materialized_impl(TypeSequence 
/*param_tags*/,
+  const ElementFn element_fn,
+  const IndexRange in_mask,
+  const IndexMask out_mask,
+  Chunks &&__restrict... chunks)
 {
   BLI_assert(in_mask.size() == out_mask.size());
   for (const int64_t i : IndexRange(in_mask.size())) {
@@ -205,11 +205,11 @@ void execute_materialized_impl(TypeSequence 
/*param_tags*/,
  * chunks, which reduces virtual function call overhead.
  */
 template
-void execute_materialized(TypeSequence /* param_tags */,
-  std::index_sequence /* indices */,
-  const ElementFn element_fn,
-  const IndexMask mask,
-  const std::tuple _params)
+inline void execute_materialized(TypeSequence /* param_tags */,
+ std::index_sequence /* indices */,
+ const ElementFn element_fn,
+ const IndexMask mask,
+ const std::tuple 
_params)
 {
 
   /* In theory, all elements could be processed in one chunk. However, that 
has the disadvantage

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e22247a965e] master: Fix: crash when opening file with visible node editor

2023-01-07 Thread Jacques Lucke
Commit: e22247a965e2c55be08a9b091f5663a55d7a59ca
Author: Jacques Lucke
Date:   Sat Jan 7 20:54:14 2023 +0100
Branches: master
https://developer.blender.org/rBe22247a965e2c55be08a9b091f5663a55d7a59ca

Fix: crash when opening file with visible node editor

Caused by rB87fd798ae383a344d51dcbd9f66d5834595bdc5a.

===

M   source/blender/editors/space_node/node_edit.cc

===

diff --git a/source/blender/editors/space_node/node_edit.cc 
b/source/blender/editors/space_node/node_edit.cc
index 336ed1cb6d3..fa26455f01c 100644
--- a/source/blender/editors/space_node/node_edit.cc
+++ b/source/blender/editors/space_node/node_edit.cc
@@ -1131,6 +1131,10 @@ bNodeSocket *node_find_indicated_socket(SpaceNode ,
 
   snode.edittree->ensure_topology_cache();
   const Span socket_locations = snode.runtime->all_socket_locations;
+  if (socket_locations.is_empty()) {
+/* Sockets haven't been drawn yet, e.g. when the file is currently 
opening. */
+return nullptr;
+  }
 
   const Span nodes = snode.edittree->all_nodes();
   for (int i = nodes.index_range().last(); i >= 0; i--) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [c4d4db39dc2] master: Functions: enable more gcc optimizations for multi-functions

2023-01-07 Thread Jacques Lucke
Commit: c4d4db39dc2e38fb9db50eb89caf9759e79da7e4
Author: Jacques Lucke
Date:   Sat Jan 7 20:23:20 2023 +0100
Branches: master
https://developer.blender.org/rBc4d4db39dc2e38fb9db50eb89caf9759e79da7e4

Functions: enable more gcc optimizations for multi-functions

This mainly helps GCC catch up with Clang in terms of field evaluation
performance in some cases. In some cases this patch can speedup
field evaluation 2-3x (e.g. when there are many float math nodes).
See D16942 for a more detailed benchmark.

===

M   source/blender/functions/FN_multi_function_builder.hh

===

diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index 997f52f4066..20b28658932 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -124,13 +124,19 @@ namespace detail {
  * instead of a `VArray`).
  */
 template
-void execute_array(TypeSequence /*param_tags*/,
-   std::index_sequence /*indices*/,
-   ElementFn element_fn,
-   MaskT mask,
-   /* Use restrict to tell the compiler that pointer inputs do 
not alias each
-* other. This is important for some compiler 
optimizations. */
-   Args &&__restrict... args)
+/* Perform additional optimizations on this loop because it is a very hot 
loop. For example, the
+ * math node in geometry nodes is processed here.  */
+#if (defined(__GNUC__) && !defined(__clang__))
+[[gnu::optimize("-funroll-loops")]] [[gnu::optimize("O3")]]
+#endif
+void execute_array(
+TypeSequence /*param_tags*/,
+std::index_sequence /*indices*/,
+ElementFn element_fn,
+MaskT mask,
+/* Use restrict to tell the compiler that pointer inputs do not alias each
+ * other. This is important for some compiler optimizations. */
+Args &&__restrict... args)
 {
   for (const int64_t i : mask) {
 element_fn([&]() -> decltype(auto) {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [a2ea32a600d] master: Cleanup: inline signatures into multi-function constructors

2023-01-07 Thread Jacques Lucke
Commit: a2ea32a600def98a1ee2d8d2eb63126e4d51fe53
Author: Jacques Lucke
Date:   Sat Jan 7 18:00:37 2023 +0100
Branches: master
https://developer.blender.org/rBa2ea32a600def98a1ee2d8d2eb63126e4d51fe53

Cleanup: inline signatures into multi-function constructors

This reduces the amount of code. Also the signature should be thought
of as being setup in the constructor, so it's good if the code is there as well.

===

M   source/blender/functions/tests/FN_multi_function_test.cc
M   source/blender/functions/tests/FN_multi_function_test_common.hh
M   source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
M   source/blender/nodes/function/nodes/node_fn_input_special_characters.cc
M   source/blender/nodes/function/nodes/node_fn_separate_color.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
M   source/blender/nodes/geometry/nodes/node_geo_proximity.cc
M   source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
M   source/blender/nodes/shader/nodes/node_shader_color_ramp.cc
M   source/blender/nodes/shader/nodes/node_shader_curves.cc
M   source/blender/nodes/shader/nodes/node_shader_mix.cc
M   source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_brick.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_checker.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_magic.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_wave.cc

===

diff --git a/source/blender/functions/tests/FN_multi_function_test.cc 
b/source/blender/functions/tests/FN_multi_function_test.cc
index f0db195960c..9be5e224f09 100644
--- a/source/blender/functions/tests/FN_multi_function_test.cc
+++ b/source/blender/functions/tests/FN_multi_function_test.cc
@@ -13,20 +13,17 @@ class AddFunction : public MultiFunction {
  public:
   AddFunction()
   {
-static Signature signature = create_signature();
+static Signature signature = []() {
+  Signature signature;
+  SignatureBuilder builder("Add", signature);
+  builder.single_input("A");
+  builder.single_input("B");
+  builder.single_output("Result");
+  return signature;
+}();
 this->set_signature();
   }
 
-  static Signature create_signature()
-  {
-Signature signature;
-SignatureBuilder builder("Add", signature);
-builder.single_input("A");
-builder.single_input("B");
-builder.single_output("Result");
-return signature;
-  }
-
   void call(IndexMask mask, MFParams params, Context /*context*/) const 
override
   {
 const VArray  = params.readonly_single_input(0, "A");
diff --git a/source/blender/functions/tests/FN_multi_function_test_common.hh 
b/source/blender/functions/tests/FN_multi_function_test_common.hh
index 2014e4fc74e..adf70498fa6 100644
--- a/source/blender/functions/tests/FN_multi_function_test_common.hh
+++ b/source/blender/functions/tests/FN_multi_function_test_common.hh
@@ -8,19 +8,16 @@ class AddPrefixFunction : public MultiFunction {
  public:
   AddPrefixFunction()
   {
-static Signature signature = create_signature();
+static const Signature signature = []() {
+  Signature signature;
+  SignatureBuilder builder{"Add Prefix", signature};
+  builder.single_input("Prefix");
+  builder.single_mutable("Strings");
+  return signature;
+}();
 this->set_signature();
   }
 
-  static Signature create_signature()
-  {
-Signature signature;
-SignatureBuilder builder{"Add Prefix", signature};
-builder.single_input("Prefix");
-builder.single_mutable("Strings");
-return signature;
-  }
-
   void call(IndexMask mask, MFParams params, Context /*context*/) const 
override
   {
 const VArray  = 
params.readonly_single_input(0, "Prefix");
@@ -36,19 +33,16 @@ class CreateRangeFunction : public MultiFunction {
  public:
   CreateRangeFunction()
   {
-static Signature signature = create_signature();
+static const Signature signature = []() {
+  Signature signature;
+  SignatureBuilder builder{"Create Range", signature};
+ 

[Bf-blender-cvs] [eedcf1876a6] master: Functions: introduce multi-function namespace

2023-01-07 Thread Jacques Lucke
Commit: eedcf1876a6651c38d8f4daa2e65d1fb81f77c5d
Author: Jacques Lucke
Date:   Sat Jan 7 17:32:28 2023 +0100
Branches: master
https://developer.blender.org/rBeedcf1876a6651c38d8f4daa2e65d1fb81f77c5d

Functions: introduce multi-function namespace

This moves all multi-function related code in the `functions` module
into a new `multi_function` namespace. This is similar to how there
is a `lazy_function` namespace.

The main benefit of this is that many types names that were prefixed
with `MF` (for "multi function") can be simplified.

There is also a common shorthand for the `multi_function` namespace: `mf`.
This is also similar to lazy-functions where the shortened namespace
is called `lf`.

===

M   source/blender/blenkernel/BKE_attribute.hh
M   source/blender/blenkernel/BKE_node.h
M   source/blender/blenkernel/BKE_type_conversions.hh
M   source/blender/blenkernel/intern/geometry_component_curves.cc
M   source/blender/blenkernel/intern/geometry_component_mesh.cc
M   source/blender/blenkernel/intern/type_conversions.cc
M   source/blender/functions/FN_field.hh
M   source/blender/functions/FN_lazy_function.hh
M   source/blender/functions/FN_multi_function.hh
M   source/blender/functions/FN_multi_function_builder.hh
M   source/blender/functions/FN_multi_function_context.hh
M   source/blender/functions/FN_multi_function_data_type.hh
M   source/blender/functions/FN_multi_function_param_type.hh
M   source/blender/functions/FN_multi_function_params.hh
M   source/blender/functions/FN_multi_function_procedure.hh
M   source/blender/functions/FN_multi_function_procedure_builder.hh
M   source/blender/functions/FN_multi_function_procedure_executor.hh
M   source/blender/functions/FN_multi_function_procedure_optimization.hh
M   source/blender/functions/FN_multi_function_signature.hh
M   source/blender/functions/intern/field.cc
M   source/blender/functions/intern/multi_function.cc
M   source/blender/functions/intern/multi_function_builder.cc
M   source/blender/functions/intern/multi_function_params.cc
M   source/blender/functions/intern/multi_function_procedure.cc
M   source/blender/functions/intern/multi_function_procedure_builder.cc
M   source/blender/functions/intern/multi_function_procedure_executor.cc
M   source/blender/functions/intern/multi_function_procedure_optimization.cc
M   source/blender/functions/tests/FN_field_test.cc
M   source/blender/functions/tests/FN_multi_function_procedure_test.cc
M   source/blender/functions/tests/FN_multi_function_test.cc
M   source/blender/functions/tests/FN_multi_function_test_common.hh
M   source/blender/geometry/intern/resample_curves.cc
M   source/blender/modifiers/intern/MOD_nodes.cc
M   source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
M   source/blender/nodes/NOD_math_functions.hh
M   source/blender/nodes/NOD_multi_function.hh
M   source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
M   source/blender/nodes/function/nodes/node_fn_boolean_math.cc
M   source/blender/nodes/function/nodes/node_fn_combine_color.cc
M   source/blender/nodes/function/nodes/node_fn_compare.cc
M   source/blender/nodes/function/nodes/node_fn_float_to_int.cc
M   source/blender/nodes/function/nodes/node_fn_input_bool.cc
M   source/blender/nodes/function/nodes/node_fn_input_color.cc
M   source/blender/nodes/function/nodes/node_fn_input_int.cc
M   source/blender/nodes/function/nodes/node_fn_input_special_characters.cc
M   source/blender/nodes/function/nodes/node_fn_input_string.cc
M   source/blender/nodes/function/nodes/node_fn_input_vector.cc
M   source/blender/nodes/function/nodes/node_fn_random_value.cc
M   source/blender/nodes/function/nodes/node_fn_replace_string.cc
M   source/blender/nodes/function/nodes/node_fn_rotate_euler.cc
M   source/blender/nodes/function/nodes/node_fn_separate_color.cc
M   source/blender/nodes/function/nodes/node_fn_slice_string.cc
M   source/blender/nodes/function/nodes/node_fn_string_length.cc
M   source/blender/nodes/function/nodes/node_fn_value_to_string.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
M   source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
M   source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc
M   source/blender/nodes/geometry/nodes/node_geo_proximity.cc
M   source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
M   source/ble

[Bf-blender-cvs] [a5b27f98588] master: Functions: simplify multi-function signature type

2023-01-07 Thread Jacques Lucke
Commit: a5b27f985881911c3174c3271b56b7c597d6b424
Author: Jacques Lucke
Date:   Sat Jan 7 16:51:26 2023 +0100
Branches: master
https://developer.blender.org/rBa5b27f985881911c3174c3271b56b7c597d6b424

Functions: simplify multi-function signature type

* `depends_on_context` was not used for a long time already.
* `param_data_indices` is not used since rB42b88c008861b6.
* The remaining data is moved to a single `Vector` to avoid
  having to do two allocations when the size signature becomes
  larger than fits into the inline buffer.

===

M   source/blender/functions/FN_multi_function.hh
M   source/blender/functions/FN_multi_function_params.hh
M   source/blender/functions/FN_multi_function_signature.hh
M   source/blender/functions/intern/multi_function_builder.cc
M   source/blender/functions/intern/multi_function_procedure_executor.cc

===

diff --git a/source/blender/functions/FN_multi_function.hh 
b/source/blender/functions/FN_multi_function.hh
index 7089f6895a7..53392e6acd2 100644
--- a/source/blender/functions/FN_multi_function.hh
+++ b/source/blender/functions/FN_multi_function.hh
@@ -67,22 +67,22 @@ class MultiFunction {
 
   int param_amount() const
   {
-return signature_ref_->param_types.size();
+return signature_ref_->params.size();
   }
 
   IndexRange param_indices() const
   {
-return signature_ref_->param_types.index_range();
+return signature_ref_->params.index_range();
   }
 
   MFParamType param_type(int param_index) const
   {
-return signature_ref_->param_types[param_index];
+return signature_ref_->params[param_index].type;
   }
 
   StringRefNull param_name(int param_index) const
   {
-return signature_ref_->param_names[param_index];
+return signature_ref_->params[param_index].name;
   }
 
   StringRefNull name() const
@@ -92,11 +92,6 @@ class MultiFunction {
 
   virtual std::string debug_name() const;
 
-  bool depends_on_context() const
-  {
-return signature_ref_->depends_on_context;
-  }
-
   const MFSignature () const
   {
 BLI_assert(signature_ref_ != nullptr);
diff --git a/source/blender/functions/FN_multi_function_params.hh 
b/source/blender/functions/FN_multi_function_params.hh
index cfcc930c67b..fec75ac8159 100644
--- a/source/blender/functions/FN_multi_function_params.hh
+++ b/source/blender/functions/FN_multi_function_params.hh
@@ -40,7 +40,7 @@ class MFParamsBuilder {
   MFParamsBuilder(const MFSignature , const IndexMask mask)
   : signature_(), mask_(mask), 
min_array_size_(mask.min_array_size())
   {
-actual_params_.reserve(signature.param_types.size());
+actual_params_.reserve(signature.params.size());
   }
 
  public:
@@ -124,7 +124,7 @@ class MFParamsBuilder {
   {
 this->assert_current_param_name(expected_name);
 const int param_index = this->current_param_index();
-const MFParamType _type = signature_->param_types[param_index];
+const MFParamType _type = signature_->params[param_index].type;
 BLI_assert(param_type.category() == MFParamCategory::SingleOutput);
 const CPPType  = param_type.data_type().single_type();
 /* An empty span indicates that this is ignored. */
@@ -157,7 +157,7 @@ class MFParamsBuilder {
 
   GMutableSpan computed_array(int param_index)
   {
-BLI_assert(ELEM(signature_->param_types[param_index].category(),
+BLI_assert(ELEM(signature_->params[param_index].type.category(),
 MFParamCategory::SingleOutput,
 MFParamCategory::SingleMutable));
 return *std::get_if(_params_[param_index]);
@@ -165,7 +165,7 @@ class MFParamsBuilder {
 
   GVectorArray _vector_array(int param_index)
   {
-BLI_assert(ELEM(signature_->param_types[param_index].category(),
+BLI_assert(ELEM(signature_->params[param_index].type.category(),
 MFParamCategory::VectorOutput,
 MFParamCategory::VectorMutable));
 return **std::get_if(_params_[param_index]);
@@ -184,11 +184,11 @@ class MFParamsBuilder {
 int param_index = this->current_param_index();
 
 if (expected_name != "") {
-  StringRef actual_name = signature_->param_names[param_index];
+  StringRef actual_name = signature_->params[param_index].name;
   BLI_assert(actual_name == expected_name);
 }
 
-MFParamType expected_type = signature_->param_types[param_index];
+MFParamType expected_type = signature_->params[param_index].type;
 BLI_assert(expected_type == param_type);
 #endif
   }
@@ -201,7 +201,7 @@ class MFParamsBuilder {
   return;
 }
 const int param_index = this->current_param_index();
-StringRef actual_name = signature_->param_names[param_index];
+StringRef actual_name = signature_->params[param_index].name;
 BLI_assert(actual_name == expected_

[Bf-blender-cvs] [577442a26fd] master: Functions: build multi-function signature in-place

2023-01-07 Thread Jacques Lucke
Commit: 577442a26fd3c5c17ddb04326e8da22e28bfca80
Author: Jacques Lucke
Date:   Sat Jan 7 16:30:56 2023 +0100
Branches: master
https://developer.blender.org/rB577442a26fd3c5c17ddb04326e8da22e28bfca80

Functions: build multi-function signature in-place

This avoids a move of the signature after building it. Tthe value had
to be moved out of `MFSignatureBuilder` in the `build` method.

This also makes the naming a bit less confusing where sometimes
both the `MFSignature` and `MFSignatureBuilder` were referred
to as "signature".

===

M   source/blender/functions/FN_multi_function_builder.hh
M   source/blender/functions/FN_multi_function_signature.hh
M   source/blender/functions/intern/multi_function_builder.cc
M   source/blender/functions/intern/multi_function_procedure_executor.cc
M   source/blender/functions/tests/FN_field_test.cc
M   source/blender/functions/tests/FN_multi_function_test.cc
M   source/blender/functions/tests/FN_multi_function_test_common.hh
M   source/blender/nodes/function/nodes/node_fn_align_euler_to_vector.cc
M   source/blender/nodes/function/nodes/node_fn_input_special_characters.cc
M   source/blender/nodes/function/nodes/node_fn_separate_color.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc
M   source/blender/nodes/geometry/nodes/node_geo_image_texture.cc
M   source/blender/nodes/geometry/nodes/node_geo_proximity.cc
M   source/blender/nodes/geometry/nodes/node_geo_raycast.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_index.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_nearest_surface.cc
M   source/blender/nodes/geometry/nodes/node_geo_sample_uv_surface.cc
M   source/blender/nodes/shader/nodes/node_shader_color_ramp.cc
M   source/blender/nodes/shader/nodes/node_shader_curves.cc
M   source/blender/nodes/shader/nodes/node_shader_mix.cc
M   source/blender/nodes/shader/nodes/node_shader_mix_rgb.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_brick.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_checker.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_gradient.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_magic.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_musgrave.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_noise.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_voronoi.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_wave.cc
M   source/blender/nodes/shader/nodes/node_shader_tex_white_noise.cc

===

diff --git a/source/blender/functions/FN_multi_function_builder.hh 
b/source/blender/functions/FN_multi_function_builder.hh
index 3a491a63e6c..f9f0890f4fb 100644
--- a/source/blender/functions/FN_multi_function_builder.hh
+++ b/source/blender/functions/FN_multi_function_builder.hh
@@ -445,10 +445,9 @@ template class 
CustomMF : public MultiFu
   CustomMF(const char *name, CallFn call_fn, TypeSequence 
/*param_tags*/)
   : call_fn_(std::move(call_fn))
   {
-MFSignatureBuilder signature{name};
+MFSignatureBuilder builder{name, signature_};
 /* Loop over all parameter types and add an entry for each in the 
signature. */
-([&] { signature.add(ParamTags(), ""); }(), ...);
-signature_ = signature.build();
+([&] { builder.add(ParamTags(), ""); }(), ...);
 this->set_signature(_);
   }
 
@@ -631,9 +630,8 @@ template class CustomMF_Constant : public 
MultiFunction {
  public:
   template CustomMF_Constant(U &) : 
value_(std::forward(value))
   {
-MFSignatureBuilder signature{"Constant"};
-signature.single_output("Value");
-signature_ = signature.build();
+MFSignatureBuilder builder{"Constant", signature_};
+builder.single_output("Value");
 this->set_signature(_);
   }
 
diff --git a/source/blender/functions/FN_multi_function_signature.hh 
b/source/blender/functions/FN_multi_function_signature.hh
index 1c2d645c1fd..44f2b84867d 100644
--- a/source/blender/functions/FN_multi_function_signature.hh
+++ b/source/blender/functions/FN_multi_function_signature.hh
@@ -32,19 +32,15 @@ struct MFSignature {
 
 class MFSignatureBuilder {
  private:
-  MFSignature signature_;
+  MFSignature _;
 
  public:
-  MFSignatureBuilder(const char *function_name)
+  MFSignatureBuilder(const char *function_name, MFSignature 
_to_build)
+  : signature_(signature_to_build)
   {
 signature_.function_name = function_name;
   }
 
-  MFSignature build() const
-  {
-return std::move(signature_);
-  }
-
   /* Input 

[Bf-blender-cvs] [b3146200a8c] master: Functions: refactor multi-function builder API

2023-01-07 Thread Jacques Lucke
Commit: b3146200a8c4265de7fba2e2d40ef84f99d979e2
Author: Jacques Lucke
Date:   Sat Jan 7 16:19:59 2023 +0100
Branches: master
https://developer.blender.org/rBb3146200a8c4265de7fba2e2d40ef84f99d979e2

Functions: refactor multi-function builder API

* New `build_mf` namespace for the multi-function builders.
* The type name of the created multi-functions is now "private",
  i.e. the caller has to use `auto`. This has the benefit that the
  implementation can change more freely without affecting
  the caller.
* `CustomMF` does not use `std::function` internally anymore.
  This reduces some overhead during code generation and at
  run-time.
* `CustomMF` now supports single-mutable parameters.

===

M   source/blender/blenkernel/intern/geometry_component_curves.cc
M   source/blender/blenkernel/intern/geometry_component_mesh.cc
M   source/blender/blenkernel/intern/type_conversions.cc
M   source/blender/functions/FN_multi_function_builder.hh
M   source/blender/functions/intern/field.cc
M   source/blender/functions/tests/FN_field_test.cc
M   source/blender/functions/tests/FN_multi_function_procedure_test.cc
M   source/blender/functions/tests/FN_multi_function_test.cc
M   source/blender/geometry/intern/resample_curves.cc
M   source/blender/nodes/NOD_math_functions.hh
M   source/blender/nodes/function/nodes/node_fn_boolean_math.cc
M   source/blender/nodes/function/nodes/node_fn_combine_color.cc
M   source/blender/nodes/function/nodes/node_fn_compare.cc
M   source/blender/nodes/function/nodes/node_fn_float_to_int.cc
M   source/blender/nodes/function/nodes/node_fn_random_value.cc
M   source/blender/nodes/function/nodes/node_fn_replace_string.cc
M   source/blender/nodes/function/nodes/node_fn_rotate_euler.cc
M   source/blender/nodes/function/nodes/node_fn_slice_string.cc
M   source/blender/nodes/function/nodes/node_fn_string_length.cc
M   source/blender/nodes/function/nodes/node_fn_value_to_string.cc
M   source/blender/nodes/geometry/nodes/node_geo_extrude_mesh.cc
M   source/blender/nodes/geometry/nodes/node_geo_mesh_to_points.cc
M   source/blender/nodes/geometry/nodes/node_geo_switch.cc
M   source/blender/nodes/shader/nodes/node_shader_clamp.cc
M   source/blender/nodes/shader/nodes/node_shader_map_range.cc
M   source/blender/nodes/shader/nodes/node_shader_math.cc
M   source/blender/nodes/shader/nodes/node_shader_mix.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_rgb.cc
M   source/blender/nodes/shader/nodes/node_shader_sepcomb_xyz.cc
M   source/blender/nodes/shader/nodes/node_shader_vector_math.cc
M   source/blender/nodes/shader/nodes/node_shader_vector_rotate.cc

===

diff --git a/source/blender/blenkernel/intern/geometry_component_curves.cc 
b/source/blender/blenkernel/intern/geometry_component_curves.cc
index debcb35699e..d1d0af2b725 100644
--- a/source/blender/blenkernel/intern/geometry_component_curves.cc
+++ b/source/blender/blenkernel/intern/geometry_component_curves.cc
@@ -440,12 +440,12 @@ static ComponentAttributeProviders 
create_attribute_providers_for_curve()
 
make_array_write_attribute,
 
tag_component_positions_changed);
 
-  static const fn::CustomMF_SI_SO handle_type_clamp{
+  static auto handle_type_clamp = fn::build_mf::SI1_SO(
   "Handle Type Validate",
   [](int8_t value) {
 return std::clamp(value, BEZIER_HANDLE_FREE, 
BEZIER_HANDLE_ALIGN);
   },
-  fn::CustomMF_presets::AllSpanOrSingle()};
+  fn::build_mf::exec_presets::AllSpanOrSingle());
   static BuiltinCustomDataLayerProvider handle_type_right("handle_type_right",
   ATTR_DOMAIN_POINT,
   CD_PROP_INT8,
@@ -484,10 +484,10 @@ static ComponentAttributeProviders 
create_attribute_providers_for_curve()
  
make_array_write_attribute,
  
tag_component_positions_changed);
 
-  static const fn::CustomMF_SI_SO nurbs_order_clamp{
+  static const auto nurbs_order_clamp = fn::build_mf::SI1_SO(
   "NURBS Order Validate",
   [](int8_t value) { return std::max(value, 0); },
-  fn::CustomMF_presets::AllSpanOrSingle()};
+  fn::build_mf::exec_presets::AllSpanOrSingle());
   static BuiltinCustomDataLayerProvider nurbs_order("nurbs_order",
 ATTR_DOMAIN_CURVE,
 CD_PROP_INT8,
@@ -501,12 +501,12 @@ static ComponentAttrib

[Bf-blender-cvs] [380db3edb31] master: Cleanup: add missing override

2023-01-07 Thread Jacques Lucke
Commit: 380db3edb314ecc8fea888a194045396f8deb589
Author: Jacques Lucke
Date:   Sat Jan 7 14:43:40 2023 +0100
Branches: master
https://developer.blender.org/rB380db3edb314ecc8fea888a194045396f8deb589

Cleanup: add missing override

===

M   source/blender/nodes/intern/geometry_nodes_lazy_function.cc

===

diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index 9c4f04e8248..8f59dea62e1 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -2708,7 +2708,7 @@ class UsedSocketVisualizeOptions : public 
lf::Graph::ToDotOptions {
 
   void add_edge_attributes(const lf::OutputSocket & /*from*/,
const lf::InputSocket ,
-   dot::DirectedEdge _edge) const
+   dot::DirectedEdge _edge) const override
   {
 if (builder_.socket_usage_inputs_.contains_as()) {
   // dot_edge.attributes.set("constraint", "false");

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [1bbf1ed03c0] master: Functions: improve devirtualization in multi-function builder

2023-01-07 Thread Jacques Lucke
Commit: 1bbf1ed03c081e61f5c76688a46d12e92da2856f
Author: Jacques Lucke
Date:   Sat Jan 7 12:55:48 2023 +0100
Branches: master
https://developer.blender.org/rB1bbf1ed03c081e61f5c76688a46d12e92da2856f

Functions: improve devirtualization in multi-function builder

This refactors how devirtualization is done in general and how
multi-functions use it.

* The old `Devirtualizer` class has been removed in favor of a simpler
  solution. It is also more general in the sense that it is not coupled
  with `IndexMask` and `VArray`. Instead there is a function that has
  inputs which control how different types are devirtualized. The
  new implementation is currently less general with regard to the number
  of parameters it supports. This can be changed in the future, but
  does not seem necessary now and would make the code less obvious.
* Devirtualizers for different types are now defined in their respective
  headers.
* The multi-function builder works with the `GVArray` stored in `MFParams`
  directly now, instead of first converting it to a `VArray`. This reduces
  some constant overhead, which makes the multi-function slightly
  faster. This is only noticable when very few elements are processed though.

No functional changes or performance regressions are expected.

===

M   source/blender/blenkernel/intern/curve_to_mesh_convert.cc
M   source/blender/blenlib/BLI_devirtualize_parameters.hh
M   source/blender/blenlib/BLI_generic_virtual_array.hh
M   source/blender/blenlib/BLI_index_mask.hh
M   source/blender/blenlib/BLI_virtual_array.hh
M   source/blender/draw/intern/draw_cache_impl_curves.cc
M   source/blender/editors/curves/intern/curves_ops.cc
M   source/blender/functions/FN_multi_function_builder.hh
M   source/blender/functions/FN_multi_function_param_type.hh
M   source/blender/geometry/intern/fillet_curves.cc
M   source/blender/geometry/intern/mesh_split_edges.cc
M   source/blender/geometry/intern/mesh_to_curve_convert.cc
M   source/blender/geometry/intern/realize_instances.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_sample.cc

===

diff --git a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc 
b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
index 14c41811505..9e8eaccb024 100644
--- a/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
+++ b/source/blender/blenkernel/intern/curve_to_mesh_convert.cc
@@ -1,7 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later */
 
 #include "BLI_array.hh"
-#include "BLI_devirtualize_parameters.hh"
 #include "BLI_set.hh"
 #include "BLI_task.hh"
 
diff --git a/source/blender/blenlib/BLI_devirtualize_parameters.hh 
b/source/blender/blenlib/BLI_devirtualize_parameters.hh
index 77b6223f310..2086c81b30d 100644
--- a/source/blender/blenlib/BLI_devirtualize_parameters.hh
+++ b/source/blender/blenlib/BLI_devirtualize_parameters.hh
@@ -26,302 +26,139 @@
  * times and binary sizes, depending on the number of parameters that are 
devirtualized separately.
  * So there is always a trade-off between run-time performance and 
compile-time/binary-size.
  *
- * This file provides a utility to devirtualize array parameters to a function 
using a high level
- * API. This makes it easy to experiment with different extremes of the 
mentioned trade-off and
- * allows finding a good compromise for each function.
+ * This file provides a utility to devirtualize function parameters using a 
high level API. This
+ * makes it easy to experiment with different extremes of the mentioned 
trade-off and allows
+ * finding a good compromise for each function.
  */
 
-#include "BLI_parameter_pack_utils.hh"
-#include "BLI_virtual_array.hh"
-
-namespace blender::devirtualize_parameters {
-
-/**
- * Bit flag that specifies how an individual parameter is or can be 
devirtualized.
- */
-enum class DeviMode {
-  /* This is used as zero-value to compare to, to avoid casting to int. */
-  None = 0,
-  /* Don't use devirtualization for that parameter, just pass it along. */
-  Keep = (1 << 0),
-  /* Devirtualize #Varray as #Span. */
-  Span = (1 << 1),
-  /* Devirtualize #VArray as #SingleAsSpan.  */
-  Single = (1 << 2),
-  /* Devirtualize #IndexMask as #IndexRange. */
-  Range = (1 << 3),
-};
-ENUM_OPERATORS(DeviMode, DeviMode::Range);
-
-/** Utility to encode multiple #DeviMode in a type. */
-template using DeviModeSequence = ValueSequence;
+namespace blender {
 
 /**
- * Main class that performs the devirtualization.
+ * Calls the given function with devirtualized parameters if possible. Note 
that using many
+ * non-trivial devirtualizers results in exponential code growth.
+ *
+ * \return True if the function has been called.
+ *
+ * Every devirtualizer is expected to have a `devirtualize(auto fn) -

[Bf-blender-cvs] [1942d55c074] master: Cleanup: remove unused code

2023-01-07 Thread Jacques Lucke
Commit: 1942d55c0745566f924ebe2da33c3b2c3281d278
Author: Jacques Lucke
Date:   Sat Jan 7 12:25:10 2023 +0100
Branches: master
https://developer.blender.org/rB1942d55c0745566f924ebe2da33c3b2c3281d278

Cleanup: remove unused code

===

M   source/blender/functions/FN_multi_function_context.hh

===

diff --git a/source/blender/functions/FN_multi_function_context.hh 
b/source/blender/functions/FN_multi_function_context.hh
index 7452bfced3b..0ffd58dfca9 100644
--- a/source/blender/functions/FN_multi_function_context.hh
+++ b/source/blender/functions/FN_multi_function_context.hh
@@ -21,18 +21,11 @@ namespace blender::fn {
 class MFContext;
 
 class MFContextBuilder {
- private:
-  friend MFContext;
-
- public:
 };
 
 class MFContext {
- private:
-  MFContextBuilder _;
-
  public:
-  MFContext(MFContextBuilder ) : builder_(builder)
+  MFContext(MFContextBuilder & /*builder*/)
   {
   }
 };

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ed1df2ce2b5] master: Cleanup: use slightly more efficient method to add multi-function parameter

2023-01-06 Thread Jacques Lucke
Commit: ed1df2ce2b5603de450994714d7510a131d01404
Author: Jacques Lucke
Date:   Fri Jan 6 22:50:51 2023 +0100
Branches: master
https://developer.blender.org/rBed1df2ce2b5603de450994714d7510a131d01404

Cleanup: use slightly more efficient method to add multi-function parameter

This avoids one `GVArray` move.

===

M   source/blender/nodes/intern/geometry_nodes_lazy_function.cc

===

diff --git a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc 
b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
index 9b26756f2ff..9c4f04e8248 100644
--- a/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
+++ b/source/blender/nodes/intern/geometry_nodes_lazy_function.cc
@@ -360,7 +360,7 @@ static void execute_multi_function_on_value_or_field(
   const ValueOrFieldCPPType  = *input_types[i];
   const void *value_or_field = input_values[i];
   const void *value = type.get_value_ptr(value_or_field);
-  params.add_readonly_single_input(GVArray::ForSingleRef(type.value, 1, 
value));
+  params.add_readonly_single_input(GPointer{type.value, value});
 }
 for (const int i : output_types.index_range()) {
   const ValueOrFieldCPPType  = *output_types[i];

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f7e9bc65abf] master: Cleanup: simplify getting value of generic ValueOrField

2023-01-06 Thread Jacques Lucke
Commit: f7e9bc65abf66f80a0efaef1d98ad58c2c278123
Author: Jacques Lucke
Date:   Fri Jan 6 22:30:02 2023 +0100
Branches: master
https://developer.blender.org/rBf7e9bc65abf66f80a0efaef1d98ad58c2c278123

Cleanup: simplify getting value of generic ValueOrField

===

M   source/blender/functions/FN_field_cpp_type.hh
M   source/blender/functions/FN_field_cpp_type_make.hh

===

diff --git a/source/blender/functions/FN_field_cpp_type.hh 
b/source/blender/functions/FN_field_cpp_type.hh
index cbb2a576272..dcb9efcd4f0 100644
--- a/source/blender/functions/FN_field_cpp_type.hh
+++ b/source/blender/functions/FN_field_cpp_type.hh
@@ -17,7 +17,6 @@ class ValueOrFieldCPPType {
  private:
   void (*construct_from_value_)(void *dst, const void *value);
   void (*construct_from_field_)(void *dst, GField field);
-  const void *(*get_value_ptr_)(const void *value_or_field);
   const GField *(*get_field_ptr_)(const void *value_or_field);
   bool (*is_field_)(const void *value_or_field);
   GField (*as_field_)(const void *value_or_field);
@@ -42,13 +41,14 @@ class ValueOrFieldCPPType {
 
   const void *get_value_ptr(const void *value_or_field) const
   {
-return get_value_ptr_(value_or_field);
+static_assert(offsetof(ValueOrField, value) == 0);
+return value_or_field;
   }
 
   void *get_value_ptr(void *value_or_field) const
   {
-/* Use `const_cast` to avoid duplicating the callback for the non-const 
case. */
-return const_cast(get_value_ptr_(value_or_field));
+static_assert(offsetof(ValueOrField, value) == 0);
+return value_or_field;
   }
 
   const GField *get_field_ptr(const void *value_or_field) const
diff --git a/source/blender/functions/FN_field_cpp_type_make.hh 
b/source/blender/functions/FN_field_cpp_type_make.hh
index 7a4112b432b..1ab0f591019 100644
--- a/source/blender/functions/FN_field_cpp_type_make.hh
+++ b/source/blender/functions/FN_field_cpp_type_make.hh
@@ -17,9 +17,6 @@ inline 
ValueOrFieldCPPType::ValueOrFieldCPPType(TypeTag /*value_type*
   construct_from_field_ = [](void *dst, GField field) {
 new (dst) ValueOrField(Field(std::move(field)));
   };
-  get_value_ptr_ = [](const void *value_or_field) {
-return (const void *)&((ValueOrField *)value_or_field)->value;
-  };
   get_field_ptr_ = [](const void *value_or_field) -> const GField * {
 return &((ValueOrField *)value_or_field)->field;
   };

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e756b0fea08] master: Cleanup: remove dead code

2023-01-06 Thread Jacques Lucke
Commit: e756b0fea08c315eb8bea67b3fbb7c34874e9728
Author: Jacques Lucke
Date:   Fri Jan 6 22:23:53 2023 +0100
Branches: master
https://developer.blender.org/rBe756b0fea08c315eb8bea67b3fbb7c34874e9728

Cleanup: remove dead code

===

M   source/blender/functions/FN_multi_function_context.hh

===

diff --git a/source/blender/functions/FN_multi_function_context.hh 
b/source/blender/functions/FN_multi_function_context.hh
index af5efb4cf88..7452bfced3b 100644
--- a/source/blender/functions/FN_multi_function_context.hh
+++ b/source/blender/functions/FN_multi_function_context.hh
@@ -22,15 +22,9 @@ class MFContext;
 
 class MFContextBuilder {
  private:
-  Map global_contexts_;
-
   friend MFContext;
 
  public:
-  template void add_global_context(std::string name, const T 
*context)
-  {
-global_contexts_.add_new(std::move(name), static_cast(context));
-  }
 };
 
 class MFContext {
@@ -41,13 +35,6 @@ class MFContext {
   MFContext(MFContextBuilder ) : builder_(builder)
   {
   }
-
-  template const T *get_global_context(StringRef name) const
-  {
-const void *context = builder_.global_contexts_.lookup_default_as(name, 
nullptr);
-/* TODO: Implement type checking. */
-return static_cast(context);
-  }
 };
 
 }  // namespace blender::fn

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [302cb349c7f] master: Cleanup: quiet compiler warning

2023-01-06 Thread Jacques Lucke
Commit: 302cb349c7f26446de3422e55c5972339ad65930
Author: Jacques Lucke
Date:   Fri Jan 6 18:04:41 2023 +0100
Branches: master
https://developer.blender.org/rB302cb349c7f26446de3422e55c5972339ad65930

Cleanup: quiet compiler warning

For some reason this resulted in a unused-variable warning (on gcc).
Think we had such false positives before when `constexpr` was used.

===

M   source/blender/blenlib/BLI_math_matrix.hh

===

diff --git a/source/blender/blenlib/BLI_math_matrix.hh 
b/source/blender/blenlib/BLI_math_matrix.hh
index a2d5abdc58b..a2884d04225 100644
--- a/source/blender/blenlib/BLI_math_matrix.hh
+++ b/source/blender/blenlib/BLI_math_matrix.hh
@@ -508,7 +508,7 @@ template
   using MatT = MatBase;
   BLI_STATIC_ASSERT(VectorT::type_length <= MatT::col_len - 1,
 "Translation should be at least 1 column less than the 
matrix.");
-  static constexpr int location_col = MatT::col_len - 1;
+  constexpr int location_col = MatT::col_len - 1;
   /* Avoid multiplying the last row if it exists.
* Allows using non square matrices like float3x2 and saves computation. */
   using IntermediateVecT =

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [34b24fb6025] master: BLI: use proper alignment for new matrix types

2023-01-06 Thread Jacques Lucke
Commit: 34b24fb6025011a28fcce4fc85e9132f7bf1cf57
Author: Jacques Lucke
Date:   Fri Jan 6 17:59:07 2023 +0100
Branches: master
https://developer.blender.org/rB34b24fb6025011a28fcce4fc85e9132f7bf1cf57

BLI: use proper alignment for new matrix types

===

M   source/blender/blenlib/BLI_math_matrix_types.hh

===

diff --git a/source/blender/blenlib/BLI_math_matrix_types.hh 
b/source/blender/blenlib/BLI_math_matrix_types.hh
index 6d6e738fc4b..f2cc66ebc1b 100644
--- a/source/blender/blenlib/BLI_math_matrix_types.hh
+++ b/source/blender/blenlib/BLI_math_matrix_types.hh
@@ -70,7 +70,7 @@ template<
 int NumRow,
 /* Alignment in bytes. Do not align matrices whose size is not a multiple 
of 4 component.
  * This is in order to avoid padding when using arrays of matrices. */
-int Alignment = (((NumCol * NumRow) % 4) ? 4 : 0) * sizeof(T)>
+int Alignment = (((NumCol * NumRow) % 4 == 0) ? 4 : 1) * alignof(T)>
 struct alignas(Alignment) MatBase : public vec_struct_base, NumCol> {
 
   using base_type = T;
@@ -923,8 +923,8 @@ using float4x4 = MatBase;
 
 /* These types are reserved to wrap C matrices without copy. Note the 
un-alignment. */
 /* TODO: It would be preferable to align all C matrices inside DNA structs. */
-using float4x4_view = MatView;
-using float4x4_mutableview = MutableMatView;
+using float4x4_view = MatView;
+using float4x4_mutableview = MutableMatView;
 
 using double2x2 = MatBase;
 using double2x3 = MatBase;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [e0d70e6a9d3] master: Nodes: avoid processing same node group multiple times to find textures

2023-01-06 Thread Jacques Lucke
Commit: e0d70e6a9d38812301d5c64f3586f8ca6ecc6ee9
Author: Jacques Lucke
Date:   Fri Jan 6 15:20:04 2023 +0100
Branches: master
https://developer.blender.org/rBe0d70e6a9d38812301d5c64f3586f8ca6ecc6ee9

Nodes: avoid processing same node group multiple times to find textures

This removes a lot of overhead when there are node groups that are
reused a lot and only need to be processed once.

===

M   source/blender/editors/space_buttons/buttons_texture.cc

===

diff --git a/source/blender/editors/space_buttons/buttons_texture.cc 
b/source/blender/editors/space_buttons/buttons_texture.cc
index 277402f1572..b4424474ebc 100644
--- a/source/blender/editors/space_buttons/buttons_texture.cc
+++ b/source/blender/editors/space_buttons/buttons_texture.cc
@@ -154,18 +154,23 @@ static void buttons_texture_users_find_nodetree(ListBase 
*users,
   }
 }
 
-static void buttons_texture_modifier_geonodes_users_add(Object *ob,
-NodesModifierData *nmd,
-bNodeTree *node_tree,
-ListBase *users)
+static void buttons_texture_modifier_geonodes_users_add(
+Object *ob,
+NodesModifierData *nmd,
+bNodeTree *node_tree,
+ListBase *users,
+blender::Set _groups)
 {
   PointerRNA ptr;
   PropertyRNA *prop;
 
   for (bNode *node : node_tree->all_nodes()) {
 if (node->type == NODE_GROUP && node->id) {
-  /* Recurse into the node group */
-  buttons_texture_modifier_geonodes_users_add(ob, nmd, (bNodeTree 
*)node->id, users);
+  if (handled_groups.add(reinterpret_cast(node->id))) {
+/* Recurse into the node group */
+buttons_texture_modifier_geonodes_users_add(
+ob, nmd, (bNodeTree *)node->id, users, handled_groups);
+  }
 }
 LISTBASE_FOREACH (bNodeSocket *, socket, >inputs) {
   if (socket->flag & SOCK_UNAVAIL) {
@@ -205,7 +210,8 @@ static void buttons_texture_modifier_foreach(void *userData,
   if (md->type == eModifierType_Nodes) {
 NodesModifierData *nmd = (NodesModifierData *)md;
 if (nmd->node_group != nullptr) {
-  buttons_texture_modifier_geonodes_users_add(ob, nmd, nmd->node_group, 
users);
+  blender::Set handled_groups;
+  buttons_texture_modifier_geonodes_users_add(ob, nmd, nmd->node_group, 
users, handled_groups);
 }
   }
   else {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [d49b850399a] master: Tests: run geometry nodes benchmarks multiple times to reduce noise

2023-01-06 Thread Jacques Lucke
Commit: d49b850399aa12ab1e62b40e38bec7c5d0096190
Author: Jacques Lucke
Date:   Fri Jan 6 13:01:22 2023 +0100
Branches: master
https://developer.blender.org/rBd49b850399aa12ab1e62b40e38bec7c5d0096190

Tests: run geometry nodes benchmarks multiple times to reduce noise

Ideally, we would also get variance information out of the test, but that
seems a bit more complex to implement. For now just run the test a couple
of times and average the timings.

The test now runs between 5 and 100 times, depending on how long it
to run the test once.

===

M   tests/performance/tests/geometry_nodes.py

===

diff --git a/tests/performance/tests/geometry_nodes.py 
b/tests/performance/tests/geometry_nodes.py
index 3505f5278bd..591c78045ae 100644
--- a/tests/performance/tests/geometry_nodes.py
+++ b/tests/performance/tests/geometry_nodes.py
@@ -11,18 +11,33 @@ def _run(args):
 # Evaluate objects once first, to avoid any possible lazy evaluation later.
 bpy.context.view_layer.update()
 
-# Tag all objects with geometry nodes modifiers to be recalculated.
-for ob in bpy.context.view_layer.objects:
-for modifier in ob.modifiers:
-if modifier.type == 'NODES':
-ob.update_tag()
-break
-
-start_time = time.time()
-bpy.context.view_layer.update()
-elapsed_time = time.time() - start_time
-
-result = {'time': elapsed_time}
+test_time_start = time.time()
+measured_times = []
+
+min_measurements = 5
+max_measurements = 100
+timeout = 5
+
+while True:
+# Tag all objects with geometry nodes modifiers to be recalculated.
+for ob in bpy.context.view_layer.objects:
+for modifier in ob.modifiers:
+if modifier.type == 'NODES':
+ob.update_tag()
+break
+
+start_time = time.time()
+bpy.context.view_layer.update()
+elapsed_time = time.time() - start_time
+measured_times.append(elapsed_time)
+
+if len(measured_times) >= min_measurements and test_time_start + 
timeout < time.time():
+break
+if len(measured_times) >= max_measurements:
+break
+
+average_time = sum(measured_times) / len(measured_times)
+result = {'time': average_time}
 return result

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [ae7163007d9] master: Allocator: improve protection against false sharing

2023-01-06 Thread Jacques Lucke
Commit: ae7163007d9b3d4ca457d095e39c64c673253fe9
Author: Jacques Lucke
Date:   Fri Jan 6 13:03:09 2023 +0100
Branches: master
https://developer.blender.org/rBae7163007d9b3d4ca457d095e39c64c673253fe9

Allocator: improve protection against false sharing

On Apple Silicon, the cache line size is 128 bytes.

===

M   intern/guardedalloc/intern/memory_usage.cc

===

diff --git a/intern/guardedalloc/intern/memory_usage.cc 
b/intern/guardedalloc/intern/memory_usage.cc
index d4abff32f79..2ea6fe7e85f 100644
--- a/intern/guardedalloc/intern/memory_usage.cc
+++ b/intern/guardedalloc/intern/memory_usage.cc
@@ -21,7 +21,7 @@ struct Global;
 /**
  * This is stored per thread. Align to cache line size to avoid false sharing.
  */
-struct alignas(64) Local {
+struct alignas(128) Local {
   /**
* Retain shared ownership of #Global to make sure that it is not destructed.
*/

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [3337838b499] master: Fix: retrieved writable attribute but did not write to it

2023-01-06 Thread Jacques Lucke
Commit: 3337838b4990ab92aca7644f36f5f2273ffb4abe
Author: Jacques Lucke
Date:   Fri Jan 6 12:54:08 2023 +0100
Branches: master
https://developer.blender.org/rB3337838b4990ab92aca7644f36f5f2273ffb4abe

Fix: retrieved writable attribute but did not write to it

This caused a warning because `attribute.finish` was not called.

===

M   source/blender/blenkernel/intern/geometry_fields.cc

===

diff --git a/source/blender/blenkernel/intern/geometry_fields.cc 
b/source/blender/blenkernel/intern/geometry_fields.cc
index 6fe822d6dc6..9c691cb5870 100644
--- a/source/blender/blenkernel/intern/geometry_fields.cc
+++ b/source/blender/blenkernel/intern/geometry_fields.cc
@@ -433,8 +433,10 @@ bool try_capture_field_on_geometry(GeometryComponent 
,
  GMutableSpan{type, buffer, domain_size});
   evaluator.evaluate();
 
-  if (GAttributeWriter attribute = attributes.lookup_for_write(attribute_id)) {
-if (attribute.domain == domain && attribute.varray.type() == type) {
+  const std::optional meta_data = 
attributes.lookup_meta_data(attribute_id);
+
+  if (meta_data && meta_data->domain == domain && meta_data->data_type == 
data_type) {
+if (GAttributeWriter attribute = 
attributes.lookup_for_write(attribute_id)) {
   attribute.varray.set_all(buffer);
   attribute.finish();
   type.destruct_n(buffer, domain_size);
@@ -442,6 +444,7 @@ bool try_capture_field_on_geometry(GeometryComponent 
,
   return true;
 }
   }
+
   attributes.remove(attribute_id);
   if (attributes.add(attribute_id, domain, data_type, 
bke::AttributeInitMoveArray{buffer})) {
 return true;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [006e905957a] master: Tests: support running benchmark when Blender prints unrelated text

2023-01-06 Thread Jacques Lucke
Commit: 006e905957ad7d5d76845876b4528acd40d59598
Author: Jacques Lucke
Date:   Fri Jan 6 12:57:34 2023 +0100
Branches: master
https://developer.blender.org/rB006e905957ad7d5d76845876b4528acd40d59598

Tests: support running benchmark when Blender prints unrelated text

I noticed that sometimes the geometry nodes benchmark would not work
if there were some left-over debug prints in the code. The reason it did
not work was because the prints were mixed with the test output print.
I also tried using explicit flusing and `atexit` for printing the test output,
but that didn't solve it. Just printing additional newlines to better separate
the test output from other printed output helped though.

===

M   tests/performance/api/environment.py

===

diff --git a/tests/performance/api/environment.py 
b/tests/performance/api/environment.py
index 1e2e4a84e81..094dbfa67ed 100644
--- a/tests/performance/api/environment.py
+++ b/tests/performance/api/environment.py
@@ -241,7 +241,7 @@ class TestEnvironment:
   f'args = pickle.loads(base64.b64decode({args}))\n'
   f'result = {modulename}.{functionname}(args)\n'
   f'result = base64.b64encode(pickle.dumps(result))\n'
-  f'print("{output_prefix}" + result.decode())\n')
+  f'print("\\n{output_prefix}" + result.decode() + 
"\\n")\n')
 
 expr_args = blender_args + ['--python-expr', expression]
 lines = self.call_blender(expr_args, foreground=foreground)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [42b88c00886] master: Functions: simplify multi-function parameters

2023-01-06 Thread Jacques Lucke
Commit: 42b88c008861b6b7a12687739161436fea78c499
Author: Jacques Lucke
Date:   Fri Jan 6 11:50:56 2023 +0100
Branches: master
https://developer.blender.org/rB42b88c008861b6b7a12687739161436fea78c499

Functions: simplify multi-function parameters

The use of `std::variant` allows combining the four vectors
into one which more closely matches the intend and avoids
a workaround used before.

Note that this uses `std::get_if` instead of `std::get` because
`std::get` is only available since macOS 10.14.

===

M   source/blender/functions/FN_multi_function_params.hh
M   source/blender/functions/FN_multi_function_signature.hh
M   source/blender/functions/intern/multi_function_params.cc

===

diff --git a/source/blender/functions/FN_multi_function_params.hh 
b/source/blender/functions/FN_multi_function_params.hh
index 16a33c9cda7..cfcc930c67b 100644
--- a/source/blender/functions/FN_multi_function_params.hh
+++ b/source/blender/functions/FN_multi_function_params.hh
@@ -12,6 +12,7 @@
  */
 
 #include 
+#include 
 
 #include "BLI_generic_pointer.hh"
 #include "BLI_generic_vector_array.hh"
@@ -28,10 +29,8 @@ class MFParamsBuilder {
   const MFSignature *signature_;
   IndexMask mask_;
   int64_t min_array_size_;
-  Vector virtual_arrays_;
-  Vector mutable_spans_;
-  Vector virtual_vector_arrays_;
-  Vector vector_arrays_;
+  Vector>
+  actual_params_;
 
   std::mutex mutex_;
   Vector> dummy_output_spans_;
@@ -41,10 +40,7 @@ class MFParamsBuilder {
   MFParamsBuilder(const MFSignature , const IndexMask mask)
   : signature_(), mask_(mask), 
min_array_size_(mask.min_array_size())
   {
-virtual_arrays_.reserve(signature.virtual_array_num);
-mutable_spans_.reserve(signature.span_num);
-virtual_vector_arrays_.reserve(signature.virtual_vector_array_num);
-vector_arrays_.reserve(signature.vector_array_num);
+actual_params_.reserve(signature.param_types.size());
   }
 
  public:
@@ -58,32 +54,41 @@ class MFParamsBuilder {
   template void add_readonly_single_input_value(T value, StringRef 
expected_name = "")
   {
 
this->assert_current_param_type(MFParamType::ForSingleInput(CPPType::get()), 
expected_name);
-virtual_arrays_.append_unchecked_as(
-varray_tag::single{}, CPPType::get(), min_array_size_, );
+actual_params_.append_unchecked_as(std::in_place_type,
+   varray_tag::single{},
+   CPPType::get(),
+   min_array_size_,
+   );
   }
   template void add_readonly_single_input(const T *value, 
StringRef expected_name = "")
   {
 
this->assert_current_param_type(MFParamType::ForSingleInput(CPPType::get()), 
expected_name);
-virtual_arrays_.append_unchecked_as(
-varray_tag::single_ref{}, CPPType::get(), min_array_size_, value);
+actual_params_.append_unchecked_as(std::in_place_type,
+   varray_tag::single_ref{},
+   CPPType::get(),
+   min_array_size_,
+   value);
   }
   void add_readonly_single_input(const GSpan span, StringRef expected_name = 
"")
   {
 this->assert_current_param_type(MFParamType::ForSingleInput(span.type()), 
expected_name);
 BLI_assert(span.size() >= min_array_size_);
-virtual_arrays_.append_unchecked_as(varray_tag::span{}, span);
+actual_params_.append_unchecked_as(std::in_place_type, 
varray_tag::span{}, span);
   }
   void add_readonly_single_input(GPointer value, StringRef expected_name = "")
   {
 
this->assert_current_param_type(MFParamType::ForSingleInput(*value.type()), 
expected_name);
-virtual_arrays_.append_unchecked_as(
-varray_tag::single_ref{}, *value.type(), min_array_size_, value.get());
+actual_params_.append_unchecked_as(std::in_place_type,
+   varray_tag::single_ref{},
+   *value.type(),
+   min_array_size_,
+   value.get());
   }
   void add_readonly_single_input(GVArray varray, StringRef expected_name = "")
   {
 
this->assert_current_param_type(MFParamType::ForSingleInput(varray.type()), 
expected_name);
 BLI_assert(varray.size() >= min_array_size_);
-virtual_arrays_.append_unchecked_as(std::move(varray));
+actual_params_.append_unchecked_as(std::in_place_type, 
std::move(varray));
   }
 
   void add_readonly_vector_input(const GVectorArray _array, StringRef 
expected_name = "")
@@ -101,7 +106,7 @@ class MFParamsBuilder {
   {
 this->assert_current_param_type(MFParamType::ForVectorI

[Bf-blender-cvs] [3819a9b15a1] master: Fix T103614: crash during geometry nodes evaluation with tbb disabled

2023-01-05 Thread Jacques Lucke
Commit: 3819a9b15a1936753cc50e4535d27aebe81ae568
Author: Jacques Lucke
Date:   Thu Jan 5 15:36:24 2023 +0100
Branches: master
https://developer.blender.org/rB3819a9b15a1936753cc50e4535d27aebe81ae568

Fix T103614: crash during geometry nodes evaluation with tbb disabled

===

M   source/blender/functions/intern/lazy_function_graph_executor.cc

===

diff --git a/source/blender/functions/intern/lazy_function_graph_executor.cc 
b/source/blender/functions/intern/lazy_function_graph_executor.cc
index fc74b3cd213..ab7dfba196a 100644
--- a/source/blender/functions/intern/lazy_function_graph_executor.cc
+++ b/source/blender/functions/intern/lazy_function_graph_executor.cc
@@ -1073,6 +1073,12 @@ class Executor {
 
   bool try_enable_multi_threading()
   {
+#ifndef WITH_TBB
+/* The non-tbb task pool has the property that it immediately executes 
tasks under some
+ * circumstances. This is not supported here because tasks might be 
scheduled while another
+ * node is in the middle of being executed on the same thread. */
+return false;
+#endif
 if (this->use_multi_threading()) {
   return true;
 }

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [862d08bb975] master: Fix: use-after-free when threadlocal is destructed after static variable

2023-01-05 Thread Jacques Lucke
Commit: 862d08bb975740e3abf3a9a4dfbdcd48275d944c
Author: Jacques Lucke
Date:   Thu Jan 5 14:38:14 2023 +0100
Branches: master
https://developer.blender.org/rB862d08bb975740e3abf3a9a4dfbdcd48275d944c

Fix: use-after-free when threadlocal is destructed after static variable

This issue was introduced in rB78f28b55d39288926634d0cc.

The fix is to use a `std::shared_ptr` to ensure that the `Global` will live
long enough until all `Local` objects are destructed.

===

M   intern/guardedalloc/intern/memory_usage.cc

===

diff --git a/intern/guardedalloc/intern/memory_usage.cc 
b/intern/guardedalloc/intern/memory_usage.cc
index 71987ac38d9..bb557eeda97 100644
--- a/intern/guardedalloc/intern/memory_usage.cc
+++ b/intern/guardedalloc/intern/memory_usage.cc
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -14,10 +15,18 @@
 
 namespace {
 
+struct Local;
+struct Global;
+
 /**
  * This is stored per thread. Align to cache line size to avoid false sharing.
  */
 struct alignas(64) Local {
+  /**
+   * Retain shared ownership of #Global to make sure that it is not destructed.
+   */
+  std::shared_ptr global;
+
   /** Helps to find bugs during program shutdown. */
   bool destructed = false;
   /**
@@ -49,7 +58,8 @@ struct alignas(64) Local {
 };
 
 /**
- * This is a singleton that stores global data.
+ * This is a singleton that stores global data. It's owned by a 
`std::shared_ptr` which is owned by
+ * the static variable in #get_global_ptr and all #Local objects.
  */
 struct Global {
   /**
@@ -98,12 +108,17 @@ static std::atomic use_local_counters = true;
  */
 static constexpr int64_t peak_update_threshold = 1024 * 1024;
 
-static Global _global()
+static std::shared_ptr _global_ptr()
 {
-  static Global global;
+  static std::shared_ptr global = std::make_shared();
   return global;
 }
 
+static Global _global()
+{
+  return *get_global_ptr();
+}
+
 static Local _local_data()
 {
   static thread_local Local local;
@@ -113,28 +128,28 @@ static Local _local_data()
 
 Local::Local()
 {
-  Global  = get_global();
-  std::lock_guard lock{global.locals_mutex};
+  this->global = get_global_ptr();
 
-  if (global.locals.empty()) {
+  std::lock_guard lock{this->global->locals_mutex};
+  if (this->global->locals.empty()) {
 /* This is the first thread creating #Local, it is therefore the main 
thread because it's
  * created through #memory_usage_init. */
 this->is_main = true;
   }
   /* Register self in the global list. */
-  global.locals.push_back(this);
+  this->global->locals.push_back(this);
 }
 
 Local::~Local()
 {
-  Global  = get_global();
-  std::lock_guard lock{global.locals_mutex};
+  std::lock_guard lock{this->global->locals_mutex};
 
   /* Unregister self from the global list. */
-  global.locals.erase(std::find(global.locals.begin(), global.locals.end(), 
this));
+  this->global->locals.erase(
+  std::find(this->global->locals.begin(), this->global->locals.end(), 
this));
   /* Don't forget the memory counts stored locally. */
-  global.blocks_num_outside_locals.fetch_add(this->blocks_num, 
std::memory_order_relaxed);
-  global.mem_in_use_outside_locals.fetch_add(this->mem_in_use, 
std::memory_order_relaxed);
+  this->global->blocks_num_outside_locals.fetch_add(this->blocks_num, 
std::memory_order_relaxed);
+  this->global->mem_in_use_outside_locals.fetch_add(this->mem_in_use, 
std::memory_order_relaxed);
 
   if (this->is_main) {
 /* The main thread started shutting down. Use global counters from now on 
to avoid accessing

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [2ffd08e9524] master: Geometry Nodes: deterministic anonymous attribute lifetimes

2023-01-05 Thread Jacques Lucke
Commit: 2ffd08e95249df2a068dd400cd3117cf8ca4a246
Author: Jacques Lucke
Date:   Thu Jan 5 14:05:30 2023 +0100
Branches: master
https://developer.blender.org/rB2ffd08e95249df2a068dd400cd3117cf8ca4a246

Geometry Nodes: deterministic anonymous attribute lifetimes

Previously, the lifetimes of anonymous attributes were determined by
reference counts which were non-deterministic when multiple threads
are used. Now the lifetimes of anonymous attributes are handled
more explicitly and deterministically. This is a prerequisite for any kind
of caching, because caching the output of nodes that do things
non-deterministically and have "invisible inputs" (reference counts)
doesn't really work.

For more details for how deterministic lifetimes are achieved, see D16858.

No functional changes are expected. Small performance changes are expected
as well (within few percent, anything larger regressions should be reported as
bugs).

Differential Revision: https://developer.blender.org/D16858

===

D   source/blender/blenkernel/BKE_anonymous_attribute.h
D   source/blender/blenkernel/BKE_anonymous_attribute.hh
A   source/blender/blenkernel/BKE_anonymous_attribute_id.hh
M   source/blender/blenkernel/BKE_attribute.hh
M   source/blender/blenkernel/BKE_curve_to_mesh.hh
M   source/blender/blenkernel/BKE_curves.hh
M   source/blender/blenkernel/BKE_customdata.h
M   source/blender/blenkernel/BKE_geometry_fields.hh
M   source/blender/blenkernel/BKE_geometry_set.hh
M   source/blender/blenkernel/BKE_instances.hh
M   source/blender/blenkernel/BKE_node_runtime.hh
M   source/blender/blenkernel/CMakeLists.txt
D   source/blender/blenkernel/intern/anonymous_attribute.cc
A   source/blender/blenkernel/intern/anonymous_attribute_id.cc
M   source/blender/blenkernel/intern/attribute_access.cc
M   source/blender/blenkernel/intern/attribute_access_intern.hh
M   source/blender/blenkernel/intern/cpp_types.cc
M   source/blender/blenkernel/intern/curve_to_mesh_convert.cc
M   source/blender/blenkernel/intern/curves_geometry.cc
M   source/blender/blenkernel/intern/customdata.cc
M   source/blender/blenkernel/intern/geometry_component_mesh.cc
M   source/blender/blenkernel/intern/geometry_fields.cc
M   source/blender/blenkernel/intern/geometry_set.cc
M   source/blender/blenkernel/intern/instances.cc
M   source/blender/blenkernel/intern/mesh_convert.cc
M   source/blender/blenkernel/intern/node.cc
A   source/blender/blenkernel/intern/node_tree_anonymous_attributes.cc
M   source/blender/blenkernel/intern/node_tree_update.cc
M   source/blender/editors/mesh/mesh_data.cc
M   source/blender/functions/FN_lazy_function_graph.hh
M   source/blender/functions/intern/lazy_function_graph.cc
M   source/blender/geometry/GEO_fillet_curves.hh
M   source/blender/geometry/GEO_mesh_split_edges.hh
M   source/blender/geometry/GEO_mesh_to_curve.hh
M   source/blender/geometry/GEO_point_merge_by_distance.hh
M   source/blender/geometry/GEO_realize_instances.hh
M   source/blender/geometry/GEO_resample_curves.hh
M   source/blender/geometry/GEO_set_curve_type.hh
M   source/blender/geometry/GEO_subdivide_curves.hh
M   source/blender/geometry/GEO_trim_curves.hh
M   source/blender/geometry/intern/add_curves_on_mesh.cc
M   source/blender/geometry/intern/fillet_curves.cc
M   source/blender/geometry/intern/mesh_split_edges.cc
M   source/blender/geometry/intern/mesh_to_curve_convert.cc
M   source/blender/geometry/intern/point_merge_by_distance.cc
M   source/blender/geometry/intern/realize_instances.cc
M   source/blender/geometry/intern/resample_curves.cc
M   source/blender/geometry/intern/set_curve_type.cc
M   source/blender/geometry/intern/subdivide_curves.cc
M   source/blender/geometry/intern/trim_curves.cc
M   source/blender/makesdna/DNA_customdata_types.h
M   source/blender/modifiers/intern/MOD_nodes.cc
M   source/blender/nodes/NOD_geometry_exec.hh
M   source/blender/nodes/NOD_geometry_nodes_lazy_function.hh
M   source/blender/nodes/geometry/node_geometry_util.hh
M   source/blender/nodes/geometry/nodes/node_geo_attribute_capture.cc
M   source/blender/nodes/geometry/nodes/node_geo_boolean.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_fillet.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_primitive_star.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_spline_type.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_subdivide.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_to_mesh.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_to_points.cc
M   source/blender/nodes/geometry/nodes/node_geo_curve_trim.cc
M   source/blender/nodes/geometry/nodes/node_geo_delete_geometry.cc
M   
source/blender/nodes/geom

  1   2   3   4   5   6   7   8   9   10   >