[Bf-blender-cvs] [b11a463e4fc] master: Refactor: Do not keep a copy of depth buffer in RegionView3D

Germano Cavalcante noreply at git.blender.org
Mon Jun 21 21:42:48 CEST 2021


Commit: b11a463e4fcd98f2fff6e05a03e97e71b93b8274
Author: Germano Cavalcante
Date:   Mon Jun 21 16:25:53 2021 -0300
Branches: master
https://developer.blender.org/rBb11a463e4fcd98f2fff6e05a03e97e71b93b8274

Refactor: Do not keep a copy of depth buffer in RegionView3D

The depth cache (located in `RegionView3D::depths`) is used for quick
and simple occlusion testing in:
- particle selection,
- "Draw Curve" operator and
- "Interactive Light Track to Cursor" operator,

However, keeping a texture buffer in cache is not a recommended practice.

For displays with high resolution like 8k this represents something
around 132MB.

Also, currently, each call to `ED_view3d_depth_override` invalidates
the depth cache. So that depth is never reused in multiple calls from
an operator (this was not the case in blender 2.79).

This commit allows to create a depth cache and release it in the same
operator. Thus, the buffer is kept in cache for a short time, freeing
up space.

No functional changes.

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

M	source/blender/blenkernel/intern/screen.c
M	source/blender/editors/curve/editcurve_paint.c
M	source/blender/editors/gpencil/annotate_paint.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/include/ED_particle.h
M	source/blender/editors/include/ED_view3d.h
M	source/blender/editors/object/object_transform.c
M	source/blender/editors/physics/particle_edit.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/editors/space_view3d/view3d_edit.c
M	source/blender/editors/space_view3d/view3d_intern.h
M	source/blender/editors/space_view3d/view3d_select.c
M	source/blender/editors/space_view3d/view3d_utils.c
M	source/blender/makesdna/DNA_view3d_types.h

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

diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 269aeaebe82..7a5892baaf6 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -1467,7 +1467,6 @@ static void direct_link_region(BlendDataReader *reader, ARegion *region, int spa
         BLO_read_data_address(reader, &rv3d->localvd);
         BLO_read_data_address(reader, &rv3d->clipbb);
 
-        rv3d->depths = NULL;
         rv3d->render_engine = NULL;
         rv3d->sms = NULL;
         rv3d->smooth_timer = NULL;
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 03c120df28b..94c227dfa75 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -128,6 +128,7 @@ struct CurveDrawData {
   } prev;
 
   ViewContext vc;
+  ViewDepths *depths;
   enum {
     CURVE_DRAW_IDLE = 0,
     CURVE_DRAW_PAINTING = 1,
@@ -188,7 +189,6 @@ static bool stroke_elem_project(const struct CurveDrawData *cdd,
                                 float r_normal_world[3])
 {
   ARegion *region = cdd->vc.region;
-  RegionView3D *rv3d = cdd->vc.rv3d;
 
   bool is_location_world_set = false;
 
@@ -204,7 +204,7 @@ static bool stroke_elem_project(const struct CurveDrawData *cdd,
     }
   }
   else {
-    const ViewDepths *depths = rv3d->depths;
+    const ViewDepths *depths = cdd->depths;
     if (depths && ((uint)mval_i[0] < depths->w) && ((uint)mval_i[1] < depths->h)) {
       float depth_fl = 1.0f;
       ED_view3d_depth_read_cached(depths, mval_i, 0, &depth_fl);
@@ -219,7 +219,7 @@ static bool stroke_elem_project(const struct CurveDrawData *cdd,
           if (surface_offset != 0.0f) {
             const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
             float normal[3];
-            if (ED_view3d_depth_read_cached_normal(&cdd->vc, mval_i, normal)) {
+            if (ED_view3d_depth_read_cached_normal(region, depths, mval_i, normal)) {
               madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
               if (r_normal_world) {
                 copy_v3_v3(r_normal_world, normal);
@@ -528,7 +528,7 @@ static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
     if (ELEM(cps->surface_plane,
              CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW,
              CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE)) {
-      if (ED_view3d_depth_read_cached_normal(&cdd->vc, event->mval, normal)) {
+      if (ED_view3d_depth_read_cached_normal(cdd->vc.region, cdd->depths, event->mval, normal)) {
         if (cps->surface_plane == CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW) {
           float cross_a[3], cross_b[3];
           cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
@@ -622,6 +622,10 @@ static void curve_draw_exit(wmOperator *op)
       BLI_mempool_destroy(cdd->stroke_elem_pool);
     }
 
+    if (cdd->depths) {
+      ED_view3d_depths_free(cdd->depths);
+      MEM_freeN(cdd->depths);
+    }
     MEM_freeN(cdd);
     op->customdata = NULL;
   }
@@ -1084,10 +1088,14 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
         /* needed or else the draw matrix can be incorrect */
         view3d_operator_needs_opengl(C);
 
-        ED_view3d_depth_override(
-            cdd->vc.depsgraph, cdd->vc.region, cdd->vc.v3d, NULL, V3D_DEPTH_NO_GPENCIL, true);
+        ED_view3d_depth_override(cdd->vc.depsgraph,
+                                 cdd->vc.region,
+                                 cdd->vc.v3d,
+                                 NULL,
+                                 V3D_DEPTH_NO_GPENCIL,
+                                 &cdd->depths);
 
-        if (cdd->vc.rv3d->depths != NULL) {
+        if (cdd->depths != NULL) {
           cdd->project.use_depth = true;
         }
         else {
diff --git a/source/blender/editors/gpencil/annotate_paint.c b/source/blender/editors/gpencil/annotate_paint.c
index c155587e95a..e3c6fd8f878 100644
--- a/source/blender/editors/gpencil/annotate_paint.c
+++ b/source/blender/editors/gpencil/annotate_paint.c
@@ -667,7 +667,7 @@ static short annotation_stroke_addpoint(tGPsdata *p,
                                  (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
                                      V3D_DEPTH_GPENCIL_ONLY :
                                      V3D_DEPTH_NO_GPENCIL,
-                                 false);
+                                 NULL);
       }
 
       /* convert screen-coordinates to appropriate coordinates (and store them) */
@@ -1226,7 +1226,7 @@ static void annotation_stroke_doeraser(tGPsdata *p)
     if (p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH) {
       View3D *v3d = p->area->spacedata.first;
       view3d_region_operator_needs_opengl(p->win, p->region);
-      ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+      ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
     }
   }
 
@@ -1706,7 +1706,7 @@ static void annotation_paint_strokeend(tGPsdata *p)
                              (ts->annotate_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
                                  V3D_DEPTH_GPENCIL_ONLY :
                                  V3D_DEPTH_NO_GPENCIL,
-                             false);
+                             NULL);
   }
 
   /* check if doing eraser or not */
diff --git a/source/blender/editors/gpencil/gpencil_fill.c b/source/blender/editors/gpencil/gpencil_fill.c
index f74e211dd65..5c4e2de6aa8 100644
--- a/source/blender/editors/gpencil/gpencil_fill.c
+++ b/source/blender/editors/gpencil/gpencil_fill.c
@@ -1373,7 +1373,7 @@ static void gpencil_get_depth_array(tGPDfill *tgpf)
     /* need to restore the original projection settings before packing up */
     view3d_region_operator_needs_opengl(tgpf->win, tgpf->region);
     ED_view3d_depth_override(
-        tgpf->depsgraph, tgpf->region, tgpf->v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+        tgpf->depsgraph, tgpf->region, tgpf->v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
 
     /* Since strokes are so fine, when using their depth we need a margin
      * otherwise they might get missed. */
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index e40748e5f6e..638994bbc2a 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -1744,7 +1744,7 @@ static void gpencil_stroke_doeraser(tGPsdata *p)
     if ((gp_settings != NULL) && (gp_settings->flag & GP_BRUSH_OCCLUDE_ERASER)) {
       View3D *v3d = p->area->spacedata.first;
       view3d_region_operator_needs_opengl(p->win, p->region);
-      ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+      ED_view3d_depth_override(p->depsgraph, p->region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
     }
   }
 
@@ -2334,7 +2334,7 @@ static void gpencil_paint_strokeend(tGPsdata *p)
                              (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
                                  V3D_DEPTH_GPENCIL_ONLY :
                                  V3D_DEPTH_NO_GPENCIL,
-                             false);
+                             NULL);
   }
 
   /* check if doing eraser or not */
diff --git a/source/blender/editors/gpencil/gpencil_primitive.c b/source/blender/editors/gpencil/gpencil_primitive.c
index 5f02bbf0a77..a2b4e5dee64 100644
--- a/source/blender/editors/gpencil/gpencil_primitive.c
+++ b/source/blender/editors/gpencil/gpencil_primitive.c
@@ -792,7 +792,7 @@ static void gpencil_primitive_update_strokes(bContext *C, tGPDprimitive *tgpi)
                              (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ?
                                  V3D_DEPTH_GPENCIL_ONLY :
                                  V3D_DEPTH_NO_GPENCIL,
-                             false);
+                             NULL);
 
     depth_arr = MEM_mallocN(sizeof(float) * gps->totpoints, "depth_points");
     tGPspoint *ptc = &points2D[0];
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index c9ef340b9d3..4da21bd05ee 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -680,7 +680,7 @@ void gpencil_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc)
     view3d_operator_needs_opengl(C);
 
     view3d_region_operator_needs_opengl(win, region);
-    ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, false);
+    ED_view3d_depth_override(depsgraph, region, v3d, NULL, V3D_DEPTH_NO_GPENCIL, NULL);
 
     /* for camera view set the subrect */
     if (rv3d->persp == RV3D_CAMOB) {
diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h
index e84298bd9c2..6d0172e724a 100644
--- a/source/blender/editors/include/ED_particle.h
+++ b/source/blender/editors/include/ED_particle.h
@@ -34,6 +34,7 @@ struct ParticleSystem;
 struct Scene;
 struct UndoType;
 struct ViewLayer;
+struct wmGenericUserData;
 struct bContext;
 struct rcti;
 
@@ -68,7 +69,11 @@ void PE_update_object(struct Depsgraph *depsgraph,
 bool PE_mouse_particles(
     struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle);
 bool PE_box_select(struct bContext *C, const struct rcti *rect, const int sel_op);
-bool PE_circle_select(struct bContext *C, const int sel_op, const int mval[2], float rad);
+bool PE_circle_select(struct bContext *C,
+                      struct wmGenericUserData *wm_userdata,
+                      const int sel_op,
+                      const int mval[2],
+                      float rad);
 int PE_lasso_select(struct bContext *C,
                     const int mcoords[][2],
                     const int mcoords_len,
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index d86041aa6e8..64883ed5f1d 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -90,8 +90,6 @@ typedef struct ViewDepths {
   short x, y; /* only fo

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list