[Bf-blender-cvs] [4498e0ea6b9] temp-T96710-pbvh-pixels: Small cleanup in code and comments.

Jeroen Bakker noreply at git.blender.org
Mon Apr 11 14:45:30 CEST 2022


Commit: 4498e0ea6b939100799f03ff58f7e6af3fa71188
Author: Jeroen Bakker
Date:   Mon Apr 11 14:38:23 2022 +0200
Branches: temp-T96710-pbvh-pixels
https://developer.blender.org/rB4498e0ea6b939100799f03ff58f7e6af3fa71188

Small cleanup in code and comments.

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

M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/BKE_pbvh.hh
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_intern.h
M	source/blender/blenkernel/intern/pbvh_pixels.cc
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/sculpt_paint/sculpt_paint_color.c
M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc

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

diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index 2a5e3d83794..e442c6bd72c 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -52,7 +52,11 @@ typedef struct {
 } PBVHColorBufferNode;
 
 typedef struct PBVHPixelsNode {
-  /* points to blender::bke::pbvh::pixels::NodeData */
+  /**
+   * Contains triangle/pixel data used during texture painting.
+   *
+   * Contains #blender::bke::pbvh::pixels::NodeData.
+   */
   void *node_data;
 } PBVHPixelsNode;
 
@@ -294,8 +298,6 @@ bool BKE_pbvh_bmesh_update_topology(PBVH *pbvh,
 void BKE_pbvh_node_mark_update(PBVHNode *node);
 void BKE_pbvh_node_mark_update_mask(PBVHNode *node);
 void BKE_pbvh_node_mark_update_color(PBVHNode *node);
-void BKE_pbvh_node_mark_update_pixels(PBVHNode *node);
-void BKE_pbvh_mark_update_pixels(PBVH *pbvh);
 void BKE_pbvh_node_mark_update_visibility(PBVHNode *node);
 void BKE_pbvh_node_mark_rebuild_draw(PBVHNode *node);
 void BKE_pbvh_node_mark_redraw(PBVHNode *node);
@@ -308,6 +310,7 @@ bool BKE_pbvh_node_fully_masked_get(PBVHNode *node);
 void BKE_pbvh_node_fully_unmasked_set(PBVHNode *node, int fully_masked);
 bool BKE_pbvh_node_fully_unmasked_get(PBVHNode *node);
 
+void BKE_pbvh_mark_update_pixels(PBVH *pbvh);
 void BKE_pbvh_vert_mark_update(PBVH *pbvh, int index);
 
 void BKE_pbvh_node_get_grids(PBVH *pbvh,
diff --git a/source/blender/blenkernel/BKE_pbvh.hh b/source/blender/blenkernel/BKE_pbvh.hh
index 7dc511e68cc..f5eceb56f2b 100644
--- a/source/blender/blenkernel/BKE_pbvh.hh
+++ b/source/blender/blenkernel/BKE_pbvh.hh
@@ -1,4 +1,5 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
 
 #pragma once
 
@@ -103,20 +104,21 @@ struct TrianglePaintInput {
 };
 
 /**
- * Pixels of the same triangle share some data.
- *
- * Data is stored as a list of structs, grouped by usage to improve performance as it improves CPU
- * cache prefetching.
+ * Data shared between pixels that belong to the same triangle.
  *
+ * Data is stored as a list of structs, grouped by usage to improve performance (improves CPU
+ * cache prefetching).
  */
 struct Triangles {
-  /** Paint input per triangle. */
+  /** Data accessed by the inner loop of the painting brush. */
   Vector<TrianglePaintInput> paint_input;
-  /** Polygon index per triangle. */
+  /** Per triangle the index of the polygon it belongs to. */
   Vector<int> poly_indices;
   /**
    * Loop indices per triangle.
-   * NOTE: is only available during building the triangles.
+   *
+   * NOTE: is only available during building the triangles. Kept here as in the future we need
+   * the data to calculate normals.
    */
   Vector<EncodedLoopIndices> loop_indices;
 
@@ -168,7 +170,7 @@ struct Triangles {
 };
 
 /**
- * Encode multiple sequential pixels to reduce memory footprint.
+ * Encode sequential pixels to reduce memory footprint.
  */
 struct PixelsPackage {
   /** Barycentric coordinate of the first pixel. */
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index c8d9e0c951b..8b0ea0ab097 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -1784,17 +1784,12 @@ void BKE_pbvh_node_mark_update_color(PBVHNode *node)
   node->flag |= PBVH_UpdateColor | PBVH_UpdateDrawBuffers | PBVH_UpdateRedraw;
 }
 
-void BKE_pbvh_node_mark_update_pixels(PBVHNode *node)
-{
-  node->flag |= PBVH_UpdatePixels;
-}
-
 void BKE_pbvh_mark_update_pixels(PBVH *pbvh)
 {
   for (int n = 0; n < pbvh->totnode; n++) {
     PBVHNode *node = &pbvh->nodes[n];
     if (node->flag & PBVH_Leaf) {
-      BKE_pbvh_node_mark_update_pixels(node);
+      node->flag |= PBVH_UpdatePixels;
     }
   }
 }
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 7c4344a30d8..f75bd1e36f8 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -256,7 +256,7 @@ bool pbvh_bmesh_node_nearest_to_ray(PBVHNode *node,
 
 void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode);
 
-/* pbvh_pixels.bb */
+/* pbvh_pixels.hh */
 void pbvh_pixels_free(PBVHNode *node);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc b/source/blender/blenkernel/intern/pbvh_pixels.cc
index 5f7b6639dd5..7dcc79b9eff 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -14,8 +14,6 @@
 #include "BLI_math.h"
 #include "BLI_task.h"
 
-#include "PIL_time_utildefines.h"
-
 #include "BKE_image_wrappers.hh"
 
 #include "bmesh.h"
@@ -33,7 +31,7 @@ constexpr bool USE_WATERTIGHT_SEAM_CHECK = true;
  * Keep track of visited polygons.
  *
  * Uses a std::vector<bool> to reduce memory requirements.
- * TODO(jbakker): Should be replaced by BLI bool vector when available.
+ * TODO(jbakker): Should be replaced by BLI bool vector when available {D14006}.
  */
 class VisitedPolygons : std::vector<bool> {
  public:
@@ -56,6 +54,17 @@ class VisitedPolygons : std::vector<bool> {
 /**
  * @brief Calculate the delta of two neighbour uv coordinates in the given image buffer.
  */
+static float3 calc_barycentric_delta(const float2 uvs[3],
+                                     const float2 start_uv,
+                                     const float2 end_uv)
+{
+
+  const BarycentricWeights start_barycentric(uvs[0], uvs[1], uvs[2], start_uv);
+  const BarycentricWeights end_barycentric(uvs[0], uvs[1], uvs[2], end_uv);
+  const float3 delta_barycentric = end_barycentric - start_barycentric;
+  return delta_barycentric;
+}
+
 static float3 calc_barycentric_delta_x(const ImBuf *image_buffer,
                                        const float2 uvs[3],
                                        const int x,
@@ -63,10 +72,7 @@ static float3 calc_barycentric_delta_x(const ImBuf *image_buffer,
 {
   const float2 start_uv(float(x) / image_buffer->x, float(y) / image_buffer->y);
   const float2 end_uv(float(x + 1) / image_buffer->x, float(y) / image_buffer->y);
-  const BarycentricWeights start_barycentric(uvs[0], uvs[1], uvs[2], start_uv);
-  const BarycentricWeights end_barycentric(uvs[0], uvs[1], uvs[2], end_uv);
-  const float3 delta_barycentric = end_barycentric - start_barycentric;
-  return delta_barycentric;
+  return calc_barycentric_delta(uvs, start_uv, end_uv);
 }
 
 static float3 calc_barycentric_delta_y(const ImBuf *image_buffer,
@@ -76,10 +82,7 @@ static float3 calc_barycentric_delta_y(const ImBuf *image_buffer,
 {
   const float2 start_uv(float(x) / image_buffer->x, float(y) / image_buffer->y);
   const float2 end_uv(float(x) / image_buffer->x, float(y + 1) / image_buffer->y);
-  const BarycentricWeights start_barycentric(uvs[0], uvs[1], uvs[2], start_uv);
-  const BarycentricWeights end_barycentric(uvs[0], uvs[1], uvs[2], end_uv);
-  const float3 delta_barycentric = end_barycentric - start_barycentric;
-  return delta_barycentric;
+  return calc_barycentric_delta(uvs, start_uv, end_uv);
 }
 
 static void extract_barycentric_pixels(TileData &tile_data,
@@ -232,7 +235,7 @@ static bool should_pixels_be_updated(PBVHNode *node)
 }
 
 /**
- * Does this the given node contains a list with owning polygons.
+ * Does the given node contains a list with polygons it owns.
  *
  * The owning polygons are stored per triangle inside the node.
  */
@@ -370,8 +373,6 @@ static void update_pixels(PBVH *pbvh,
   if (!find_nodes_to_update(pbvh, nodes_to_update, visited_polygons)) {
     return;
   }
-  TIMEIT_START(update_pixels);
-  printf(" - updating %ld nodes\n", nodes_to_update.size());
 
   MLoopUV *ldata_uv = static_cast<MLoopUV *>(CustomData_get_layer(ldata, CD_MLOOPUV));
   if (ldata_uv == nullptr) {
@@ -431,7 +432,6 @@ static void update_pixels(PBVH *pbvh,
            float(compressed_data_len) / num_pixels);
   }
 #endif
-  TIMEIT_END(update_pixels);
 }
 
 }  // namespace blender::bke::pbvh::pixels::extractor
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index e978afb5eb0..d008deea485 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -2757,9 +2757,9 @@ static void update_brush_local_mat(Sculpt *sd, Object *ob)
 
 static bool sculpt_needs_pbvh_pixels(const PaintModeSettings *paint_mode_settings,
                                      const Brush *brush,
-                                     Object *ob /*, const PaintModeSettings *settings*/)
+                                     Object *ob)
 {
-  if (brush->sculpt_tool == SCULPT_TOOL_PAINT /*&& U.experimental.use_sculpt_texture_paint*/) {
+  if (brush->sculpt_tool == SCULPT_TOOL_PAINT && U.experimental.use_sculpt_texture_paint) {
     Image *image;
     ImageUser *image_user;
     return SCULPT_paint_image_canvas_get(paint_mode_settings, ob, &image, &image_user);
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index 197a78afba8..97f191a1860 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1636,12 +1636,9 @@ void SCULPT_do_paint_brush(const struct PaintModeSettings *paint_mode_settings,
 /**
  * @brief Get the image canvas for painting on the given object.
  *
- * @note this is a temporary function. Would actually need to be replaced by logic provided by
- * {D14455}.
- *
  * @return #true if an image is found. The #r_image and #r_image_user fields are filled with the
  * image and image user. Returns false when the image isn't found. In the later case the r_image
- * and r_image_user would not be modified.
+ * and r_image_user are set to nullptr/NULL.
  */
 bool SCULPT_paint_image_canvas_get(const struct PaintModeSettings *paint_mode_settings,
                                    struct Object *ob,
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_color.c b/source/blender/editors/sculpt_paint/sculpt_paint_color.c
index 6fd5e081e07..ca753f7f5f1 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_color.c
+++ b/sour

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list