[Bf-blender-cvs] [973e64cf9cb] master: DRW: Make shaded batch validation more correct

Clément Foucault noreply at git.blender.org
Fri Apr 19 15:20:31 CEST 2019


Commit: 973e64cf9cb23b91e329ebac9a0f4c69647edf20
Author: Clément Foucault
Date:   Thu Apr 18 17:25:04 2019 +0200
Branches: master
https://developer.blender.org/rB973e64cf9cb23b91e329ebac9a0f4c69647edf20

DRW: Make shaded batch validation more correct

This is in order to support garbage collection of unused Custom data layer uploaded to the GPU.

Actual Garbage Collection is not added by this commit.

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

M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/makesrna/intern/rna_space.c

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

diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 630cbd20319..6b43fbed49f 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -4198,16 +4198,16 @@ GPUBatch **DRW_mesh_batch_cache_get_surface_shaded(Mesh *me,
 
   BLI_assert(gpumat_array_len == cache->mat_len);
 
-  bool cd_overlap = mesh_cd_layers_type_overlap(cache->cd_used, cd_needed);
-  if (!cd_overlap) {
-    mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed);
+  mesh_cd_layers_type_merge(&cache->cd_needed, cd_needed);
 
+  if (!mesh_cd_layers_type_overlap(cache->cd_used, cd_needed)) {
     mesh_cd_extract_auto_layers_names_and_srgb(me,
                                                cache->cd_needed,
                                                &cache->auto_layer_names,
                                                &cache->auto_layer_is_srgb,
                                                &cache->auto_layer_len);
   }
+
   if (auto_layer_names) {
     *auto_layer_names = cache->auto_layer_names;
     *auto_layer_is_srgb = cache->auto_layer_is_srgb;
@@ -4733,6 +4733,18 @@ void DRW_mesh_batch_cache_create_requested(
     drw_mesh_weight_state_clear(&wstate);
   }
 
+  /* Optimization : Only create orco layer if mesh is deformed. */
+  if (cache->cd_needed.orco != 0) {
+    CustomData *cd_vdata = (me->edit_mesh) ? &me->edit_mesh->bm->vdata : &me->vdata;
+    if (CustomData_get_layer(cd_vdata, CD_ORCO) != NULL && ob->modifiers.first != NULL) {
+      /* Orco layer is needed. */
+    }
+    else if (cache->cd_needed.tan_orco == 0) {
+      /* Skip orco calculation if not needed by tangent generation. */
+      cache->cd_needed.orco = 0;
+    }
+  }
+
   /* Verify that all surface batches have needed attribute layers. */
   /* TODO(fclem): We could be a bit smarter here and only do it per material. */
   bool cd_overlap = mesh_cd_layers_type_overlap(cache->cd_used, cache->cd_needed);
@@ -4929,15 +4941,7 @@ void DRW_mesh_batch_cache_create_requested(
         DRW_vbo_request(cache->surf_per_mat[i], &cache->ordered.loop_vcol);
       }
       if (cache->cd_used.orco != 0) {
-        /* OPTI : Only do that if there is modifiers that modify orcos. */
-        CustomData *cd_vdata = (me->edit_mesh) ? &me->edit_mesh->bm->vdata : &me->vdata;
-        if (CustomData_get_layer(cd_vdata, CD_ORCO) != NULL && ob->modifiers.first != NULL) {
-          DRW_vbo_request(cache->surf_per_mat[i], &cache->ordered.loop_orco);
-        }
-        else if (cache->cd_used.tan_orco == 0) {
-          /* Skip orco calculation if not needed by tangent generation. */
-          cache->cd_used.orco = 0;
-        }
+        DRW_vbo_request(cache->surf_per_mat[i], &cache->ordered.loop_orco);
       }
     }
   }
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index 984536b6907..ce6a2af8c8f 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -914,17 +914,6 @@ static void rna_3DViewShading_type_update(Main *bmain, Scene *scene, PointerRNA
     return;
   }
 
-  for (Material *ma = bmain->materials.first; ma; ma = ma->id.next) {
-    /* XXX Dependency graph does not support CD mask tracking,
-     * so we trigger  materials shading for until it's properly supported.
-     * This is to ensure material batches are all recreated when switching
-     * shading type. In the future DEG should replace this and just tag
-     * the meshes itself.
-     * This hack just tag BKE_MESH_BATCH_DIRTY_SHADING for every mesh that
-     * have a material. (see T55059) */
-    DEG_id_tag_update(&ma->id, ID_RECALC_SHADING);
-  }
-
   View3DShading *shading = ptr->data;
   if (shading->type == OB_MATERIAL ||
       (shading->type == OB_RENDER &&



More information about the Bf-blender-cvs mailing list