[Bf-blender-cvs] [3a72860c3df] tmp-drw-callbatching: Cleanup: DRW: move DRWShadingGroup uniform locations to DRWUniform

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


Commit: 3a72860c3df446953072637e3d91a0c25831c82e
Author: Clément Foucault
Date:   Sun Jun 2 22:59:42 2019 +0200
Branches: tmp-drw-callbatching
https://developer.blender.org/rB3a72860c3df446953072637e3d91a0c25831c82e

Cleanup: DRW: move DRWShadingGroup uniform locations to DRWUniform

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

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

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

diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
index 712fa712ec6..2670bc022b7 100644
--- a/source/blender/draw/intern/draw_manager.h
+++ b/source/blender/draw/intern/draw_manager.h
@@ -178,7 +178,14 @@ typedef enum {
   /** Per drawcall uniforms/UBO */
   DRW_UNIFORM_BLOCK_OBMATS,
   DRW_UNIFORM_BLOCK_OBINFOS,
+  DRW_UNIFORM_CALLID,
+  /** Legacy / Fallback */
   DRW_UNIFORM_BASE_INSTANCE,
+  DRW_UNIFORM_MODEL_MATRIX,
+  DRW_UNIFORM_MODEL_MATRIX_INVERSE,
+  DRW_UNIFORM_MODELVIEWPROJECTION_MATRIX,
+  /* WARNING: set DRWUniform->type
+   * bit length accordingly. */
 } DRWUniformType;
 
 struct DRWUniform {
@@ -218,13 +225,7 @@ struct DRWShadingGroup {
   /** Stencil mask to use for stencil test / write operations */
   uint stencil_mask;
 
-  /* Builtin uniforms locations
-   * (here for backward compatibilities with builtin shaders) */
-  int model;
-  int modelinverse;
-  int modelviewprojection;
   int objectinfo;
-  int callid;
 
   DRWPass *pass_parent; /* backlink to pass we're in */
 };
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
index e918c395e17..5a71468909a 100644
--- a/source/blender/draw/intern/draw_manager_data.c
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -896,24 +896,37 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
   int view_ubo_location = GPU_shader_get_uniform_block(shader, "viewBlock");
   int model_ubo_location = GPU_shader_get_uniform_block(shader, "modelBlock");
   int info_ubo_location = GPU_shader_get_uniform_block(shader, "infoBlock");
-  int drawid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_BASE_INSTANCE);
+  int baseinst_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_BASE_INSTANCE);
+  int callid_location = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_CALLID);
 
-  if (drawid_location != -1) {
-    drw_shgroup_uniform_create_ex(shgroup, drawid_location, DRW_UNIFORM_BASE_INSTANCE, NULL, 0, 1);
+  if (callid_location != -1) {
+    drw_shgroup_uniform_create_ex(shgroup, callid_location, DRW_UNIFORM_CALLID, NULL, 0, 1);
+  }
+
+  if (baseinst_location != -1) {
+    drw_shgroup_uniform_create_ex(
+        shgroup, baseinst_location, DRW_UNIFORM_BASE_INSTANCE, NULL, 0, 1);
   }
 
   if (model_ubo_location != -1) {
     drw_shgroup_uniform_create_ex(
         shgroup, model_ubo_location, DRW_UNIFORM_BLOCK_OBMATS, NULL, 0, 1);
-
-    shgroup->model = -1;
-    shgroup->modelinverse = -1;
-    shgroup->modelviewprojection = -1;
   }
   else {
-    shgroup->model = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODEL);
-    shgroup->modelinverse = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODEL_INV);
-    shgroup->modelviewprojection = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MVP);
+    int model = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODEL);
+    int modelinverse = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODEL_INV);
+    int modelviewprojection = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MVP);
+    if (model != -1) {
+      drw_shgroup_uniform_create_ex(shgroup, model, DRW_UNIFORM_MODEL_MATRIX, NULL, 0, 1);
+    }
+    if (modelinverse != -1) {
+      drw_shgroup_uniform_create_ex(
+          shgroup, modelinverse, DRW_UNIFORM_MODEL_MATRIX_INVERSE, NULL, 0, 1);
+    }
+    if (modelviewprojection != -1) {
+      drw_shgroup_uniform_create_ex(
+          shgroup, modelviewprojection, DRW_UNIFORM_MODELVIEWPROJECTION_MATRIX, NULL, 0, 1);
+    }
   }
 
   if (info_ubo_location != -1) {
@@ -948,9 +961,6 @@ static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
   BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW_INV) == -1);
   BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_MODELVIEW) == -1);
   BLI_assert(GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_NORMAL) == -1);
-
-  /* TODO remove or promote to uniform type. */
-  shgroup->callid = GPU_shader_get_builtin_uniform(shader, GPU_UNIFORM_CALLID);
 }
 
 static DRWShadingGroup *drw_shgroup_create_ex(struct GPUShader *shader, DRWPass *pass)
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
index f7b74502110..2ff6bed82ce 100644
--- a/source/blender/draw/intern/draw_manager_exec.c
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -574,27 +574,26 @@ static void draw_compute_culling(DRWView *view)
 /** \name Draw (DRW_draw)
  * \{ */
 
-BLI_INLINE void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWResourceHandle handle)
+BLI_INLINE void draw_legacy_matrix_update(DRWShadingGroup *shgroup,
+                                          DRWResourceHandle handle,
+                                          float obmat_loc,
+                                          float obinv_loc,
+                                          float mvp_loc)
 {
   /* Still supported for compatibility with gpu_shader_* but should be forbidden. */
-  if (shgroup->model != -1 || shgroup->modelinverse != -1 || shgroup->modelviewprojection != -1) {
-    DRWObjectMatrix *ob_mats = BLI_memblock_elem_get(
-        DST.vmempool->obmats, handle.chunk, handle.id);
-    if (shgroup->model != -1) {
-      GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)ob_mats->model);
-    }
-    if (shgroup->modelinverse != -1) {
-      GPU_shader_uniform_vector(
-          shgroup->shader, shgroup->modelinverse, 16, 1, (float *)ob_mats->modelinverse);
-    }
-    /* Still supported for compatibility with gpu_shader_* but should be forbidden
-     * and is slow (since it does not cache the result). */
-    if (shgroup->modelviewprojection != -1) {
-      float mvp[4][4];
-      mul_m4_m4m4(mvp, DST.view_active->storage.persmat, ob_mats->model);
-      GPU_shader_uniform_vector(
-          shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)mvp);
-    }
+  DRWObjectMatrix *ob_mats = BLI_memblock_elem_get(DST.vmempool->obmats, handle.chunk, handle.id);
+  if (obmat_loc != -1) {
+    GPU_shader_uniform_vector(shgroup->shader, obmat_loc, 16, 1, (float *)ob_mats->model);
+  }
+  if (obinv_loc != -1) {
+    GPU_shader_uniform_vector(shgroup->shader, obinv_loc, 16, 1, (float *)ob_mats->modelinverse);
+  }
+  /* Still supported for compatibility with gpu_shader_* but should be forbidden
+   * and is slow (since it does not cache the result). */
+  if (mvp_loc != -1) {
+    float mvp[4][4];
+    mul_m4_m4m4(mvp, DST.view_active->storage.persmat, ob_mats->model);
+    GPU_shader_uniform_vector(shgroup->shader, mvp_loc, 16, 1, (float *)mvp);
   }
 }
 
@@ -800,7 +799,11 @@ static void release_ubo_slots(bool with_persist)
 static void draw_update_uniforms(DRWShadingGroup *shgroup,
                                  int *obmats_loc,
                                  int *obinfos_loc,
-                                 int *baseinst_loc)
+                                 int *baseinst_loc,
+                                 int *callid_loc,
+                                 int *obmat_loc,
+                                 int *obinv_loc,
+                                 int *mvp_loc)
 {
   for (DRWUniformChunk *unichunk = shgroup->uniforms; unichunk; unichunk = unichunk->next) {
     DRWUniform *uni = unichunk->uniforms;
@@ -873,9 +876,22 @@ static void draw_update_uniforms(DRWShadingGroup *shgroup,
           GPU_uniformbuffer_bind(ubo, 1);
           GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
           break;
+        case DRW_UNIFORM_CALLID:
+          *callid_loc = uni->location;
+          break;
+          /* Legacy/Fallback support. */
         case DRW_UNIFORM_BASE_INSTANCE:
           *baseinst_loc = uni->location;
           break;
+        case DRW_UNIFORM_MODEL_MATRIX:
+          *obmat_loc = uni->location;
+          break;
+        case DRW_UNIFORM_MODEL_MATRIX_INVERSE:
+          *obinv_loc = uni->location;
+          break;
+        case DRW_UNIFORM_MODELVIEWPROJECTION_MATRIX:
+          *mvp_loc = uni->location;
+          break;
       }
     }
   }
@@ -967,6 +983,11 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
   int obmats_loc = -1;
   int obinfos_loc = -1;
   int baseinst_loc = -1;
+  int callid_loc = -1;
+  /* Legacy matrix support. */
+  int obmat_loc = -1;
+  int obinv_loc = -1;
+  int mvp_loc = -1;
 
   if (shader_changed) {
     if (DST.shader) {
@@ -988,7 +1009,14 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
   drw_state_set((pass_state & shgroup->state_extra_disable) | shgroup->state_extra);
   drw_stencil_set(shgroup->stencil_mask);
 
-  draw_update_uniforms(shgroup, &obmats_loc, &obinfos_loc, &baseinst_loc);
+  draw_update_uniforms(shgroup,
+                       &obmats_loc,
+                       &obinfos_loc,
+                       &baseinst_loc,
+                       &callid_loc,
+                       &obmat_loc,
+                       &obinv_loc,
+                       &mvp_loc);
 
   /* Rendering Calls */
   {
@@ -1009,8 +1037,8 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
       }
 
       /* XXX small exception/optimisation for outline rendering. */
-      if (shgroup->callid != -1) {
-        GPU_shader_uniform_vector_int(shgroup->shader, shgroup->callid, 1, 1, &callid);
+      if (callid_loc != -1) {
+        GPU_shader_uniform_vector_int(shgroup->shader, callid_loc, 1, 1, &callid);
         callid += 1;
       }
 
@@ -1043,9 +1071,9 @@ static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
         base_inst = handle.id;
       }
 
-      if (obmats_loc == -1 || obinfos_loc == -1) {
+      if (obmats_loc == -1 && (obmat_loc != -1 || obinv_loc != -1 || mvp_loc != -1)) {
         /* TODO This is Legacy. Need to be removed. */
-        draw_geometry_prepare(shgroup, handle);
+        draw_legacy_matrix_update(shgroup, handle, obmat_loc, obinv_loc, mvp_loc);
       }
 
       if (draw_select_do_call(shgroup, call, base_inst)) {



More information about the Bf-blender-cvs mailing list