[Bf-blender-cvs] [8d0713e8d21] tmp-drw-callbatching: DRW: Refactor replacing DRWCall by DRWCommand

Clément Foucault noreply at git.blender.org
Sat Aug 17 14:50:51 CEST 2019


Commit: 8d0713e8d21ed3cbe093fadf9f42b833c68a41f8
Author: Clément Foucault
Date:   Sat Jun 22 17:49:31 2019 +0200
Branches: tmp-drw-callbatching
https://developer.blender.org/rB8d0713e8d21ed3cbe093fadf9f42b833c68a41f8

DRW: Refactor replacing DRWCall by DRWCommand

DRWCall was fat and not very flexible. DRWCommand is very small and makes
it possible to have many kind of DRWCommand making the DRWManager more
extensible. Like adding the possibility of changing the stencil mask or
clear framebuffers in between drawcalls.

This commit breaks shgroup z sorting.

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

M	source/blender/draw/engines/gpencil/gpencil_draw_utils.c
M	source/blender/draw/intern/DRW_render.h
M	source/blender/draw/intern/draw_anim_viz.c
M	source/blender/draw/intern/draw_manager.c
M	source/blender/draw/intern/draw_manager.h
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/draw/intern/draw_manager_exec.c
M	source/blender/gpu/GPU_viewport.h
M	source/blender/gpu/intern/gpu_viewport.c

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

diff --git a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
index 835c875d71d..149ded06c0a 100644
--- a/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
+++ b/source/blender/draw/engines/gpencil/gpencil_draw_utils.c
@@ -1742,7 +1742,7 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data,
                                               scale,
                                               cache_ob->shading_type);
         if ((do_onion) || (elm->onion == false)) {
-          DRW_shgroup_call_range_obmat(shgrp, cache->b_stroke.batch, obmat, start_stroke, len);
+          DRW_shgroup_call_range(shgrp, cache->b_stroke.batch, start_stroke, len);
         }
         stl->storage->shgroup_id++;
         start_stroke = elm->vertex_idx;
@@ -1778,7 +1778,7 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data,
                                              cache_ob->shading_type);
 
         if ((do_onion) || (elm->onion == false)) {
-          DRW_shgroup_call_range_obmat(shgrp, cache->b_point.batch, obmat, start_point, len);
+          DRW_shgroup_call_range(shgrp, cache->b_point.batch, start_point, len);
         }
         stl->storage->shgroup_id++;
         start_point = elm->vertex_idx;
@@ -1804,7 +1804,7 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data,
                                             cache_ob->shading_type);
 
         if ((do_onion) || (elm->onion == false)) {
-          DRW_shgroup_call_range_obmat(shgrp, cache->b_fill.batch, obmat, start_fill, len);
+          DRW_shgroup_call_range(shgrp, cache->b_fill.batch, start_fill, len);
         }
         stl->storage->shgroup_id++;
         start_fill = elm->vertex_idx;
@@ -1822,8 +1822,8 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data,
           shgrp = DRW_shgroup_create_sub(stl->g_data->shgrps_edit_point);
           DRW_shgroup_uniform_mat4(shgrp, "gpModelMatrix", obmat);
           /* use always the same group */
-          DRW_shgroup_call_range_obmat(
-              stl->g_data->shgrps_edit_point, cache->b_edit.batch, obmat, start_edit, len);
+          DRW_shgroup_call_range(
+              stl->g_data->shgrps_edit_point, cache->b_edit.batch, start_edit, len);
 
           start_edit = elm->vertex_idx;
         }
@@ -1836,8 +1836,8 @@ static void gpencil_shgroups_create(GPENCIL_e_data *e_data,
           shgrp = DRW_shgroup_create_sub(stl->g_data->shgrps_edit_line);
           DRW_shgroup_uniform_mat4(shgrp, "gpModelMatrix", obmat);
           /* use always the same group */
-          DRW_shgroup_call_range_obmat(
-              stl->g_data->shgrps_edit_line, cache->b_edlin.batch, obmat, start_edlin, len);
+          DRW_shgroup_call_range(
+              stl->g_data->shgrps_edit_line, cache->b_edlin.batch, start_edlin, len);
 
           start_edlin = elm->vertex_idx;
         }
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
index 75bc2509a5c..6c3079171a3 100644
--- a/source/blender/draw/intern/DRW_render.h
+++ b/source/blender/draw/intern/DRW_render.h
@@ -84,8 +84,6 @@ typedef struct DRWPass DRWPass;
 typedef struct DRWShadingGroup DRWShadingGroup;
 typedef struct DRWUniform DRWUniform;
 typedef struct DRWView DRWView;
-
-/* Opaque type to avoid usage as a DRWCall but it is exactly the same thing. */
 typedef struct DRWCallBuffer DRWCallBuffer;
 
 /* TODO Put it somewhere else? */
@@ -407,35 +405,29 @@ void DRW_shgroup_call_ex(DRWShadingGroup *shgroup,
                          Object *ob,
                          float (*obmat)[4],
                          struct GPUBatch *geom,
-                         uint v_sta,
-                         uint v_ct,
                          bool bypass_culling,
                          void *user_data);
 
 /* If ob is NULL, unit modelmatrix is assumed and culling is bypassed. */
-#define DRW_shgroup_call(shgrp, geom, ob) \
-  DRW_shgroup_call_ex(shgrp, ob, NULL, geom, 0, 0, false, NULL)
+#define DRW_shgroup_call(shgrp, geom, ob) DRW_shgroup_call_ex(shgrp, ob, NULL, geom, false, NULL)
 
 /* Same as DRW_shgroup_call but override the obmat. Not culled. */
 #define DRW_shgroup_call_obmat(shgrp, geom, obmat) \
-  DRW_shgroup_call_ex(shgrp, NULL, obmat, geom, 0, 0, false, NULL)
+  DRW_shgroup_call_ex(shgrp, NULL, obmat, geom, false, NULL)
 
 /* TODO(fclem) remove this when we have DRWView */
 /* user_data is used by DRWCallVisibilityFn defined in DRWView. */
 #define DRW_shgroup_call_with_callback(shgrp, geom, ob, user_data) \
-  DRW_shgroup_call_ex(shgrp, ob, NULL, geom, 0, 0, false, user_data)
+  DRW_shgroup_call_ex(shgrp, ob, NULL, geom, false, user_data)
 
 /* Same as DRW_shgroup_call but bypass culling even if ob is not NULL. */
 #define DRW_shgroup_call_no_cull(shgrp, geom, ob) \
-  DRW_shgroup_call_ex(shgrp, ob, NULL, geom, 0, 0, true, NULL)
-
-/* Only draw a certain range of geom. */
-#define DRW_shgroup_call_range(shgrp, geom, ob, v_sta, v_ct) \
-  DRW_shgroup_call_ex(shgrp, ob, NULL, geom, v_sta, v_ct, false, NULL)
+  DRW_shgroup_call_ex(shgrp, ob, NULL, geom, true, NULL)
 
-/* Same as DRW_shgroup_call_range but override the obmat. Special for gpencil. */
-#define DRW_shgroup_call_range_obmat(shgrp, geom, obmat, v_sta, v_ct) \
-  DRW_shgroup_call_ex(shgrp, NULL, obmat, geom, v_sta, v_ct, false, NULL)
+void DRW_shgroup_call_range(DRWShadingGroup *shgroup,
+                            struct GPUBatch *geom,
+                            uint v_sta,
+                            uint v_ct);
 
 void DRW_shgroup_call_procedural_points(DRWShadingGroup *sh, Object *ob, uint point_ct);
 void DRW_shgroup_call_procedural_lines(DRWShadingGroup *sh, Object *ob, uint line_ct);
diff --git a/source/blender/draw/intern/draw_anim_viz.c b/source/blender/draw/intern/draw_anim_viz.c
index 72459309133..2d71fdf0782 100644
--- a/source/blender/draw/intern/draw_anim_viz.c
+++ b/source/blender/draw/intern/draw_anim_viz.c
@@ -215,7 +215,7 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl,
       DRW_shgroup_uniform_vec3(shgrp, "customColor", mpath->color, 1);
     }
     /* Only draw the required range. */
-    DRW_shgroup_call_range(shgrp, mpath_batch_line_get(mpath), NULL, start_index, len);
+    DRW_shgroup_call_range(shgrp, mpath_batch_line_get(mpath), start_index, len);
   }
 
   /* Draw points. */
@@ -231,7 +231,7 @@ static void MPATH_cache_motion_path(MPATH_PassList *psl,
     DRW_shgroup_uniform_vec3(shgrp, "customColor", mpath->color, 1);
   }
   /* Only draw the required range. */
-  DRW_shgroup_call_range(shgrp, mpath_batch_points_get(mpath), NULL, start_index, len);
+  DRW_shgroup_call_range(shgrp, mpath_batch_points_get(mpath), start_index, len);
 
   /* Draw frame numbers at each framestep value */
   bool show_kf_no = (avs->path_viewflag & MOTIONPATH_VIEW_KFNOS) != 0;
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
index 6037d1e6435..be66a9a1a32 100644
--- a/source/blender/draw/intern/draw_manager.c
+++ b/source/blender/draw/intern/draw_manager.c
@@ -540,7 +540,9 @@ static void drw_viewport_cache_resize(void)
       GPU_texture_free(*tex);
     }
 
-    BLI_memblock_clear(DST.vmempool->calls, NULL);
+    BLI_memblock_clear(DST.vmempool->commands, NULL);
+    BLI_memblock_clear(DST.vmempool->commands_small, NULL);
+    BLI_memblock_clear(DST.vmempool->callbuffers, NULL);
     BLI_memblock_clear(DST.vmempool->obmats, NULL);
     BLI_memblock_clear(DST.vmempool->obinfos, NULL);
     BLI_memblock_clear(DST.vmempool->cullstates, NULL);
@@ -635,8 +637,14 @@ static void drw_viewport_var_init(void)
 
     DST.vmempool = GPU_viewport_mempool_get(DST.viewport);
 
-    if (DST.vmempool->calls == NULL) {
-      DST.vmempool->calls = BLI_memblock_create(sizeof(DRWCallChunk));
+    if (DST.vmempool->commands == NULL) {
+      DST.vmempool->commands = BLI_memblock_create(sizeof(DRWCommandChunk));
+    }
+    if (DST.vmempool->commands_small == NULL) {
+      DST.vmempool->commands_small = BLI_memblock_create(sizeof(DRWCommandSmallChunk));
+    }
+    if (DST.vmempool->callbuffers == NULL) {
+      DST.vmempool->callbuffers = BLI_memblock_create(sizeof(DRWCallBuffer));
     }
     if (DST.vmempool->obmats == NULL) {
       uint chunk_len = sizeof(DRWObjectMatrix) * DRW_RESOURCE_CHUNK_LEN;
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index 60d9ad3c064..c0fd361dbc2 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -94,11 +94,6 @@
  *                           > DRWUniform
  */
 
-/* Used by DRWCallState.flag */
-enum {
-  DRW_CALL_NEGSCALE = (1 << 0),
-};
-
 typedef struct DRWCullingState {
   uint32_t mask;
   /* Culling: Using Bounding Sphere for now for faster culling.
@@ -154,20 +149,62 @@ typedef struct DRWObjectInfos {
 BLI_STATIC_ASSERT_ALIGN(DRWObjectMatrix, 16)
 BLI_STATIC_ASSERT_ALIGN(DRWObjectInfos, 16)
 
-typedef struct DRWCall {
+typedef enum {
+  /* Draw Commands */
+  DRW_CMD_DRAW = 0, /* Only sortable type. Must be 0. */
+  DRW_CMD_DRAW_RANGE = 1,
+  DRW_CMD_DRAW_INSTANCE = 2,
+  DRW_CMD_DRAW_PROCEDURAL = 3,
+  /* Other Commands */
+  DRW_CMD_SELECTID = 15,
+  /* Needs to fit in 4bits */
+} eDRWCommandType;
+
+typedef struct DRWCommandDraw {
+  GPUBatch *batch;
+  DRWResourceHandle handle;
+} DRWCommandDraw;
+
+/* Assume DRWResourceHandle to be 0. */
+typedef struct DRWCommandDrawRange {
   GPUBatch *batch;
-  int vert_first;
-  int vert_count;
-  int inst_count;
+  uint vert_first;
+  uint vert_count;
+} DRWCommandDrawRange;
 
+typedef struct DRWCommandDrawInstance {
+  GPUBatch *batch;
   DRWResourceHandle handle;
+  uint inst_count;
+} DRWCommandDrawInstance;
 
-#ifdef USE_GPU_SELECT
-  /* TODO(fclem) remove once we have a dedicated selection engine. */
-  int select_id;
-  GPUVertBuf *inst_selectid;
-#endif
-} DRWCall;
+typedef struct DRWCommandDrawProcedural {
+  GPUBatch *batch;
+  DRWResourceHandle handle;
+  uint vert_count;
+} DRWCommandDrawProcedural;
+
+typedef struct DRWCommandSetSelectID {
+  GPUVertBuf *select_buf;
+  uint select_id;
+} DRWCommandSetSelectID;
+
+typedef union DRWCommand {
+  /* Only 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list