[Bf-blender-cvs] [c988561debd] refactor-mesh-uv-map-generic: Remove lazy bool attribute allocation for BMesh.

Martijn Versteegh noreply at git.blender.org
Thu Nov 24 13:31:53 CET 2022


Commit: c988561debd5e30b560e0b96d71ca8217c2ba8ed
Author: Martijn Versteegh
Date:   Thu Nov 24 13:06:37 2022 +0100
Branches: refactor-mesh-uv-map-generic
https://developer.blender.org/rBc988561debd5e30b560e0b96d71ca8217c2ba8ed

Remove lazy bool attribute allocation for BMesh.

===================================================================

M	source/blender/bmesh/bmesh_class.h
M	source/blender/bmesh/intern/bmesh_interp.c
M	source/blender/bmesh/intern/bmesh_interp.h
M	source/blender/draw/intern/mesh_extractors/extract_mesh.cc
M	source/blender/editors/mesh/mesh_data.cc
M	source/blender/editors/sculpt_paint/sculpt_uv.c
M	source/blender/editors/uvedit/uvedit_ops.c
M	source/blender/editors/uvedit/uvedit_rip.c
M	source/blender/editors/uvedit/uvedit_select.c
M	source/blender/editors/uvedit/uvedit_unwrap_ops.c
M	source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_ico_sphere.cc
M	source/blender/python/bmesh/bmesh_py_types_meshdata.c

===================================================================

diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h
index ab6c17f92d7..a724a8783d4 100644
--- a/source/blender/bmesh/bmesh_class.h
+++ b/source/blender/bmesh/bmesh_class.h
@@ -533,9 +533,6 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, const BMLoop *, void *user_
 #define BM_ELEM_CD_GET_BOOL(ele, offset) \
   (BLI_assert(offset != -1), *((bool *)((char *)(ele)->head.data + (offset))))
 
-#define BM_ELEM_CD_GET_OPT_BOOL(ele, offset) \
-  (offset == -1 ? false : *((bool *)((char *)(ele)->head.data + (offset))))
-
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 #  define BM_ELEM_CD_GET_BOOL_P(ele, offset) \
     (BLI_assert(offset != -1), \
@@ -549,20 +546,6 @@ typedef bool (*BMLoopPairFilterFunc)(const BMLoop *, const BMLoop *, void *user_
     (BLI_assert(offset != -1), (bool *)((char *)(ele)->head.data + (offset)))
 #endif
 
-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
-#  define BM_ELEM_CD_GET_OPT_BOOL_P(ele, offset) \
-    ((offset != -1) ? \
-         _Generic(ele, \
-                  GENERIC_TYPE_ANY((bool *)POINTER_OFFSET((ele)->head.data, offset), \
-                                   _BM_GENERIC_TYPE_ELEM_NONCONST), \
-                  GENERIC_TYPE_ANY((const bool *)POINTER_OFFSET((ele)->head.data, offset), \
-                                   _BM_GENERIC_TYPE_ELEM_CONST)) : \
-         NULL)
-#else
-#  define BM_ELEM_CD_GET_OPT_BOOL_P(ele, offset) \
-    ((offset != -1) ? (bool *)((char *)(ele)->head.data + (offset)) : NULL)
-#endif
-
 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
 #  define BM_ELEM_CD_GET_VOID_P(ele, offset) \
     (BLI_assert(offset != -1), \
diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c
index 86f86d79fac..fdae1d71f04 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -881,6 +881,16 @@ void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const cha
   }
 }
 
+void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char *uv_map_name)
+{
+  char name[MAX_CUSTOMDATA_LAYER_NAME];
+  BM_data_layer_ensure_named(
+      bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_vert_selection_name(uv_map_name, name));
+  BM_data_layer_ensure_named(
+      bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_edge_selection_name(uv_map_name, name));
+  BM_data_layer_ensure_named(bm, &bm->ldata, CD_PROP_BOOL, get_uv_map_pin_name(uv_map_name, name));
+}
+
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char *uv_map_name)
 {
   char name[MAX_CUSTOMDATA_LAYER_NAME];
diff --git a/source/blender/bmesh/intern/bmesh_interp.h b/source/blender/bmesh/intern/bmesh_interp.h
index cebf47910e1..f8bb45af1e7 100644
--- a/source/blender/bmesh/intern/bmesh_interp.h
+++ b/source/blender/bmesh/intern/bmesh_interp.h
@@ -65,6 +65,7 @@ void BM_data_layer_add_named(BMesh *bm, CustomData *data, int type, const char *
 void BM_data_layer_ensure_named(BMesh *bm, CustomData *data, int type, const char *name);
 void BM_data_layer_free(BMesh *bm, CustomData *data, int type);
 
+void BM_uv_map_ensure_selection_pin_attributes(BMesh *bm, const char *uv_map_name);
 void BM_uv_map_ensure_vert_selection_attribute(BMesh *bm, const char *uv_map_name);
 void BM_uv_map_ensure_edge_selection_attribute(BMesh *bm, const char *uv_map_name);
 void BM_uv_map_ensure_pin_attribute(BMesh *bm, const char *uv_map_name);
diff --git a/source/blender/draw/intern/mesh_extractors/extract_mesh.cc b/source/blender/draw/intern/mesh_extractors/extract_mesh.cc
index 42336f7b416..98edb1c4e3c 100644
--- a/source/blender/draw/intern/mesh_extractors/extract_mesh.cc
+++ b/source/blender/draw/intern/mesh_extractors/extract_mesh.cc
@@ -127,7 +127,7 @@ void mesh_render_data_loop_flag(const MeshRenderData *mr,
   if (offsets.uv == -1) {
     return;
   }
-  if (BM_ELEM_CD_GET_OPT_BOOL(l, offsets.pin)) {
+  if (BM_ELEM_CD_GET_BOOL(l, offsets.pin)) {
     eattr->v_flag |= VFLAG_VERT_UV_PINNED;
   }
   if (uvedit_uv_select_test_ex(mr->toolsettings, l, offsets)) {
diff --git a/source/blender/editors/mesh/mesh_data.cc b/source/blender/editors/mesh/mesh_data.cc
index 249034de2d2..6a542c42d32 100644
--- a/source/blender/editors/mesh/mesh_data.cc
+++ b/source/blender/editors/mesh/mesh_data.cc
@@ -246,6 +246,7 @@ int ED_mesh_uv_add(
     }
 
     BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_PROP_FLOAT2, name);
+    BM_uv_map_ensure_selection_pin_attributes(em->bm, name);
     /* copy data from active UV */
     if (layernum_dst && do_init) {
       const int layernum_src = CustomData_get_active_layer(&em->bm->ldata, CD_PROP_FLOAT2);
@@ -271,6 +272,7 @@ int ED_mesh_uv_add(
                                  CustomData_get_layer(&me->ldata, CD_PROP_FLOAT2),
                                  me->totloop,
                                  name);
+
       is_init = true;
     }
     else {
diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c
index 81c499c923a..6e622a56515 100644
--- a/source/blender/editors/sculpt_paint/sculpt_uv.c
+++ b/source/blender/editors/sculpt_paint/sculpt_uv.c
@@ -757,7 +757,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
           data->uv[counter].element = element;
           data->uv[counter].uv = *luv;
           if (data->tool != UV_SCULPT_TOOL_GRAB) {
-            if (BM_ELEM_CD_GET_OPT_BOOL(element->l, offsets.pin)) {
+            if (BM_ELEM_CD_GET_BOOL(element->l, offsets.pin)) {
               data->uv[counter].is_locked = true;
             }
           }
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 8b08296b031..ae8aba5f5aa 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -1415,10 +1415,10 @@ static void UV_OT_pin(wmOperatorType *ot)
 /* check if we are selected or unselected based on 'bool_test' arg,
  * needed for select swap support */
 #define UV_VERT_SEL_TEST(l, bool_test) \
-  (BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_vert) == bool_test)
+  (BM_ELEM_CD_GET_BOOL(l, offsets.select_vert) == bool_test)
 
 #define UV_EDGE_SEL_TEST(l, bool_test) \
-  (BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_edge) == bool_test)
+  (BM_ELEM_CD_GET_BOOL(l, offsets.select_edge) == bool_test)
 
 /* is every UV vert selected or unselected depending on bool_test */
 static bool bm_face_is_all_uv_sel(BMFace *f, bool select_test, const BMUVOffsets offsets)
diff --git a/source/blender/editors/uvedit/uvedit_rip.c b/source/blender/editors/uvedit/uvedit_rip.c
index 5e98e0cfac5..2faa1220928 100644
--- a/source/blender/editors/uvedit/uvedit_rip.c
+++ b/source/blender/editors/uvedit/uvedit_rip.c
@@ -761,11 +761,11 @@ static bool uv_rip_object(Scene *scene, Object *obedit, const float co[2], const
     if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
       bool is_all = true;
       BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
-        if (BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_vert)) {
-          if (BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_edge)) {
+        if (BM_ELEM_CD_GET_BOOL(l, offsets.select_vert)) {
+          if (BM_ELEM_CD_GET_BOOL(l, offsets.select_edge)) {
             UL(l)->is_select_edge = true;
           }
-          else if (!BM_ELEM_CD_GET_OPT_BOOL(l->prev, offsets.select_edge)) {
+          else if (!BM_ELEM_CD_GET_BOOL(l->prev, offsets.select_edge)) {
             /* #bm_loop_uv_select_single_vert_validate validates below. */
             UL(l)->is_select_vert_single = true;
             is_all = false;
@@ -809,11 +809,11 @@ static bool uv_rip_object(Scene *scene, Object *obedit, const float co[2], const
     BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
       BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
         if (!UL(l)->is_select_all) {
-          if (BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_vert)) {
+          if (BM_ELEM_CD_GET_BOOL(l, offsets.select_vert)) {
             BM_ELEM_CD_SET_BOOL(l, offsets.select_vert, false);
             changed = true;
           }
-          if (BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_edge)) {
+          if (BM_ELEM_CD_GET_BOOL(l, offsets.select_edge)) {
             BM_ELEM_CD_SET_BOOL(l, offsets.select_edge, false);
             changed = true;
           }
diff --git a/source/blender/editors/uvedit/uvedit_select.c b/source/blender/editors/uvedit/uvedit_select.c
index faa7b0e9b73..4c1294cf384 100644
--- a/source/blender/editors/uvedit/uvedit_select.c
+++ b/source/blender/editors/uvedit/uvedit_select.c
@@ -236,12 +236,12 @@ bool uvedit_face_select_test_ex(const ToolSettings *ts, BMFace *efa, const BMUVO
 
   BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
     if (ts->uv_selectmode & UV_SELECT_VERTEX) {
-      if (!BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_vert)) {
+      if (!BM_ELEM_CD_GET_BOOL(l, offsets.select_vert)) {
         return false;
       }
     }
     else {
-      if (!BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_edge)) {
+      if (!BM_ELEM_CD_GET_BOOL(l, offsets.select_edge)) {
         return false;
       }
     }
@@ -381,10 +381,10 @@ bool uvedit_edge_select_test_ex(const ToolSettings *ts, BMLoop *l, const BMUVOff
   }
 
   if (ts->uv_selectmode & UV_SELECT_VERTEX) {
-    return BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_vert) &&
-           BM_ELEM_CD_GET_OPT_BOOL(l->next, offsets.select_vert);
+    return BM_ELEM_CD_GET_BOOL(l, offsets.select_vert) &&
+           BM_ELEM_CD_GET_BOOL(l->next, offsets.select_vert);
   }
-  return BM_ELEM_CD_GET_OPT_BOOL(l, offsets.select_edge);
+  return BM_ELEM_CD_GET_BOOL(l, offsets.select_edge);
 }
 
 bool uvedit_edge_select_test(const Scene *scene, BMLoop *l, const BMUVOffsets offsets)
@@ -447,13 +447,13 @@ void uvedit_edge_select_shared_vert(const Scene *scene,
   /* Vert selections. */
   BMLoop *l_iter = l;
   do {
-    if (select && BM_ELEM_CD_GET_OPT_BOOL(l_iter, offsets.select_edge)) {
+    if (select && BM_ELEM_CD_GET_BOOL(l_iter, offsets.select_edge)) {
       uvedit_uv_select_shared_vert(scene, em, l_iter, true, SI_STICKY_LOC, do_history, offsets);
       uvedit_uv_select_shared_vert(
           scene, em, l_iter->next

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list