[Bf-blender-cvs] [8bf1977d311] master: Fix T65955: GPencil: drawing shapes on surface causes intense viewport flickering

Antonioya noreply at git.blender.org
Sat Jun 22 16:50:11 CEST 2019


Commit: 8bf1977d311fc7d8b5979fdd6ac5b982076b1e60
Author: Antonioya
Date:   Sat Jun 22 16:47:18 2019 +0200
Branches: master
https://developer.blender.org/rB8bf1977d311fc7d8b5979fdd6ac5b982076b1e60

Fix T65955: GPencil: drawing shapes on surface causes intense viewport flickering

There were some problems in the engine because the data was saved inside e_data struct, but this struct is reset sometimes and the background texture is not valid.

Now, the data has been moved to stl->g_data and all creation and free has been moved to use stl->g_data. This fix also some small memory leak for the Buffer GPUBatch data.

The background texture has been moved to texture list because must be available all the time. When is not drawing, the texture is removed to safe memory. Also, if the mode is painting and the texture is not ready because it was removed by Draw Manager, the texture is reloaded with the background image again. This ensure the background image is always visible when painting.

Also I have used this patch to reduce the size of texture used for background to 16F instead of 32F and the blank texture to 1x1 pixels instead of 16x16.

Reviewed by: @fclem

See D5115 for more details

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

M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/engines/gpencil/gpencil_engine.c
M	source/blender/draw/engines/gpencil/gpencil_engine.h
M	source/blender/draw/engines/gpencil/gpencil_shader_fx.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 1300f7259f1..1b8684c66df 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -478,7 +478,7 @@ static DRWShadingGroup *DRW_gpencil_shgroup_fill_create(GPENCIL_e_data *e_data,
   }
   else {
     /* if no texture defined, need a blank texture to avoid errors in draw manager */
-    DRW_shgroup_uniform_texture(grp, "myTexture", e_data->gpencil_blank_texture);
+    DRW_shgroup_uniform_texture(grp, "myTexture", stl->g_data->gpencil_blank_texture);
     stl->shgroups[id].texture_clamp = 0;
     DRW_shgroup_uniform_int(grp, "texture_clamp", &stl->shgroups[id].texture_clamp, 1);
   }
@@ -643,7 +643,7 @@ DRWShadingGroup *DRW_gpencil_shgroup_stroke_create(GPENCIL_e_data *e_data,
   }
   else {
     /* if no texture defined, need a blank texture to avoid errors in draw manager */
-    DRW_shgroup_uniform_texture(grp, "myTexture", e_data->gpencil_blank_texture);
+    DRW_shgroup_uniform_texture(grp, "myTexture", stl->g_data->gpencil_blank_texture);
   }
 
   return grp;
@@ -801,7 +801,7 @@ static DRWShadingGroup *DRW_gpencil_shgroup_point_create(GPENCIL_e_data *e_data,
   }
   else {
     /* if no texture defined, need a blank texture to avoid errors in draw manager */
-    DRW_shgroup_uniform_texture(grp, "myTexture", e_data->gpencil_blank_texture);
+    DRW_shgroup_uniform_texture(grp, "myTexture", stl->g_data->gpencil_blank_texture);
   }
 
   return grp;
@@ -1539,23 +1539,17 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data,
               (const int *)stl->storage->shade_render);
         }
 
-        /* clean previous version of the batch */
-        if (stl->storage->buffer_stroke) {
-          GPU_BATCH_DISCARD_SAFE(e_data->batch_buffer_stroke);
-          MEM_SAFE_FREE(e_data->batch_buffer_stroke);
-          stl->storage->buffer_stroke = false;
-        }
-
         /* use unit matrix because the buffer is in screen space and does not need conversion */
         if (gpd->runtime.mode == GP_STYLE_MODE_LINE) {
-          e_data->batch_buffer_stroke = DRW_gpencil_get_buffer_stroke_geom(gpd, lthick);
+          stl->g_data->batch_buffer_stroke = DRW_gpencil_get_buffer_stroke_geom(gpd, lthick);
         }
         else {
-          e_data->batch_buffer_stroke = DRW_gpencil_get_buffer_point_geom(gpd, lthick);
+          stl->g_data->batch_buffer_stroke = DRW_gpencil_get_buffer_point_geom(gpd, lthick);
         }
 
         /* buffer strokes, must show stroke always */
-        DRW_shgroup_call(stl->g_data->shgrps_drawing_stroke, e_data->batch_buffer_stroke, NULL);
+        DRW_shgroup_call(
+            stl->g_data->shgrps_drawing_stroke, stl->g_data->batch_buffer_stroke, NULL);
 
         if ((gpd->runtime.sbuffer_size >= 3) &&
             (gpd->runtime.sfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) &&
@@ -1569,18 +1563,9 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data,
           stl->g_data->shgrps_drawing_fill = DRW_shgroup_create(e_data->gpencil_drawing_fill_sh,
                                                                 psl->drawing_pass);
 
-          /* clean previous version of the batch */
-          if (stl->storage->buffer_fill) {
-            GPU_BATCH_DISCARD_SAFE(e_data->batch_buffer_fill);
-            MEM_SAFE_FREE(e_data->batch_buffer_fill);
-            stl->storage->buffer_fill = false;
-          }
-
-          e_data->batch_buffer_fill = DRW_gpencil_get_buffer_fill_geom(gpd);
-          DRW_shgroup_call(stl->g_data->shgrps_drawing_fill, e_data->batch_buffer_fill, NULL);
-          stl->storage->buffer_fill = true;
+          stl->g_data->batch_buffer_fill = DRW_gpencil_get_buffer_fill_geom(gpd);
+          DRW_shgroup_call(stl->g_data->shgrps_drawing_fill, stl->g_data->batch_buffer_fill, NULL);
         }
-        stl->storage->buffer_stroke = true;
       }
     }
   }
@@ -1598,18 +1583,9 @@ void DRW_gpencil_populate_buffer_strokes(GPENCIL_e_data *e_data,
     const float *viewport_size = DRW_viewport_size_get();
     DRW_shgroup_uniform_vec2(shgrp, "Viewport", viewport_size, 1);
 
-    /* clean previous version of the batch */
-    if (stl->storage->buffer_ctrlpoint) {
-      GPU_BATCH_DISCARD_SAFE(e_data->batch_buffer_ctrlpoint);
-      MEM_SAFE_FREE(e_data->batch_buffer_ctrlpoint);
-      stl->storage->buffer_ctrlpoint = false;
-    }
-
-    e_data->batch_buffer_ctrlpoint = DRW_gpencil_get_buffer_ctrlpoint_geom(gpd);
-
-    DRW_shgroup_call(shgrp, e_data->batch_buffer_ctrlpoint, NULL);
+    stl->g_data->batch_buffer_ctrlpoint = DRW_gpencil_get_buffer_ctrlpoint_geom(gpd);
 
-    stl->storage->buffer_ctrlpoint = true;
+    DRW_shgroup_call(shgrp, stl->g_data->batch_buffer_ctrlpoint, NULL);
   }
 }
 
diff --git a/source/blender/draw/engines/gpencil/gpencil_engine.c b/source/blender/draw/engines/gpencil/gpencil_engine.c
index ae3bf8cead6..916f2eed575 100644
--- a/source/blender/draw/engines/gpencil/gpencil_engine.c
+++ b/source/blender/draw/engines/gpencil/gpencil_engine.c
@@ -102,6 +102,7 @@ static void GPENCIL_create_framebuffers(void *vedata)
 {
   GPENCIL_FramebufferList *fbl = ((GPENCIL_Data *)vedata)->fbl;
   GPENCIL_StorageList *stl = ((GPENCIL_Data *)vedata)->stl;
+  GPENCIL_TextureList *txl = ((GPENCIL_Data *)vedata)->txl;
 
   /* Go full 32bits for rendering */
   eGPUTextureFormat fb_format = DRW_state_is_image_render() ? GPU_RGBA32F : GPU_RGBA16F;
@@ -119,50 +120,57 @@ static void GPENCIL_create_framebuffers(void *vedata)
     /* Framebufers for basic object drawing */
     if (stl->storage->framebuffer_flag & GP_FRAMEBUFFER_BASIC) {
       /* temp textures for ping-pong buffers */
-      e_data.temp_depth_tx_a = DRW_texture_pool_query_2d(
+      stl->g_data->temp_depth_tx_a = DRW_texture_pool_query_2d(
           size[0], size[1], GPU_DEPTH_COMPONENT24, &draw_engine_gpencil_type);
-      e_data.temp_color_tx_a = DRW_texture_pool_query_2d(
+      stl->g_data->temp_color_tx_a = DRW_texture_pool_query_2d(
           size[0], size[1], fb_format, &draw_engine_gpencil_type);
       GPU_framebuffer_ensure_config(&fbl->temp_fb_a,
                                     {
-                                        GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_a),
-                                        GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_a),
+                                        GPU_ATTACHMENT_TEXTURE(stl->g_data->temp_depth_tx_a),
+                                        GPU_ATTACHMENT_TEXTURE(stl->g_data->temp_color_tx_a),
                                     });
 
-      e_data.temp_depth_tx_b = DRW_texture_pool_query_2d(
+      stl->g_data->temp_depth_tx_b = DRW_texture_pool_query_2d(
           size[0], size[1], GPU_DEPTH_COMPONENT24, &draw_engine_gpencil_type);
-      e_data.temp_color_tx_b = DRW_texture_pool_query_2d(
+      stl->g_data->temp_color_tx_b = DRW_texture_pool_query_2d(
           size[0], size[1], fb_format, &draw_engine_gpencil_type);
       GPU_framebuffer_ensure_config(&fbl->temp_fb_b,
                                     {
-                                        GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_b),
-                                        GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_b),
+                                        GPU_ATTACHMENT_TEXTURE(stl->g_data->temp_depth_tx_b),
+                                        GPU_ATTACHMENT_TEXTURE(stl->g_data->temp_color_tx_b),
                                     });
 
       /* used for FX effects and Layer blending */
-      e_data.temp_depth_tx_fx = DRW_texture_pool_query_2d(
+      stl->g_data->temp_depth_tx_fx = DRW_texture_pool_query_2d(
           size[0], size[1], GPU_DEPTH_COMPONENT24, &draw_engine_gpencil_type);
-      e_data.temp_color_tx_fx = DRW_texture_pool_query_2d(
+      stl->g_data->temp_color_tx_fx = DRW_texture_pool_query_2d(
           size[0], size[1], fb_format, &draw_engine_gpencil_type);
       GPU_framebuffer_ensure_config(&fbl->temp_fb_fx,
                                     {
-                                        GPU_ATTACHMENT_TEXTURE(e_data.temp_depth_tx_fx),
-                                        GPU_ATTACHMENT_TEXTURE(e_data.temp_color_tx_fx),
+                                        GPU_ATTACHMENT_TEXTURE(stl->g_data->temp_depth_tx_fx),
+                                        GPU_ATTACHMENT_TEXTURE(stl->g_data->temp_color_tx_fx),
                                     });
     }
 
-    /* background framebuffer to speed up drawing process (always 16 bits) */
+    /* background framebuffer to speed up drawing process */
     if (stl->storage->framebuffer_flag & GP_FRAMEBUFFER_DRAW) {
-      e_data.background_depth_tx = DRW_texture_pool_query_2d(
-          size[0], size[1], GPU_DEPTH_COMPONENT24, &draw_engine_gpencil_type);
-      e_data.background_color_tx = DRW_texture_pool_query_2d(
-          size[0], size[1], GPU_RGBA32F, &draw_engine_gpencil_type);
+      if (txl->background_color_tx == NULL) {
+        stl->storage->background_ready = false;
+      }
+      DRW_texture_ensure_2d(
+          &txl->background_depth_tx, size[0], size[1], GPU_DEPTH_COMPONENT24, DRW_TEX_FILTER);
+      DRW_texture_ensure_2d(
+          &txl->background_color_tx, size[0], size[1], GPU_RGBA16F, DRW_TEX_FILTER);
       GPU_framebuffer_ensure_config(&fbl->background_fb,
                                     {
-                                        GPU_ATTACHMENT_TEXTURE(e_data.background_depth_tx),
-                                        GPU_ATTACHMENT_TEXTURE(e_data.background_color_tx),
+                                        GPU_ATTACHMENT_TEXTURE(txl->background_depth_tx),
+                                        GPU_ATTACHMENT_TEXTURE(txl->background_color_tx),
                                     });
     }
+    else {
+      DRW_TEXTURE_FREE_SAFE(txl->background_depth_tx);
+      DRW_TEXTURE_FREE_SAFE(txl->background_color_tx);
+    }
   }
 }
 
@@ -262,13 +270,6 @@ void GPENCIL_engine_init(void *vedata)
   /* create shaders */
   GPENCIL_create_shaders();
   GPENCIL_create_fx_shaders(&e_data);
-
-  /* blank texture used if no texture defined for fill shader */
-  

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list