[Bf-blender-cvs] [9a0c100e6c9] soc-2019-npr: LANPR: GPU mode batch refresh method changes.

YimingWu noreply at git.blender.org
Tue Jul 16 13:35:53 CEST 2019


Commit: 9a0c100e6c95bdcd87e6c2858891ea822696b5e4
Author: YimingWu
Date:   Tue Jul 16 19:35:15 2019 +0800
Branches: soc-2019-npr
https://developer.blender.org/rB9a0c100e6c95bdcd87e6c2858891ea822696b5e4

LANPR: GPU mode batch refresh method changes.

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

M	source/blender/draw/engines/lanpr/lanpr_dpix.c
M	source/blender/draw/engines/lanpr/lanpr_engine.c
M	source/blender/editors/include/ED_lanpr.h
M	source/blender/editors/lanpr/lanpr_ops.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/draw/engines/lanpr/lanpr_dpix.c b/source/blender/draw/engines/lanpr/lanpr_dpix.c
index 14f15d2ed8a..b05728ccee1 100644
--- a/source/blender/draw/engines/lanpr/lanpr_dpix.c
+++ b/source/blender/draw/engines/lanpr/lanpr_dpix.c
@@ -81,7 +81,7 @@ void lanpr_init_atlas_inputs(void *ved)
     txl->dpix_out_length = NULL;
   }
 
-  if (lanpr->reloaded || !txl->dpix_in_pl) {
+  if (lanpr_share.dpix_reloaded || !txl->dpix_in_pl) {
     DRW_texture_ensure_2d(&txl->dpix_in_pl, texture_size, texture_size, GPU_RGBA32F, 0);
     DRW_texture_ensure_2d(&txl->dpix_in_pr, texture_size, texture_size, GPU_RGBA32F, 0);
     DRW_texture_ensure_2d(&txl->dpix_in_nl, texture_size, texture_size, GPU_RGBA32F, 0);
diff --git a/source/blender/draw/engines/lanpr/lanpr_engine.c b/source/blender/draw/engines/lanpr/lanpr_engine.c
index 26a61504ea9..d3d559518ed 100644
--- a/source/blender/draw/engines/lanpr/lanpr_engine.c
+++ b/source/blender/draw/engines/lanpr/lanpr_engine.c
@@ -198,6 +198,9 @@ static void lanpr_cache_init(void *vedata)
 
   static float normal_object_direction[3] = {0, 0, 1};
 
+  /* Transfer reload state */
+  lanpr_share.dpix_reloaded = lanpr_share.dpix_reloaded_deg;
+
   if (!stl->g_data) {
     /* Alloc transient pointers */
     stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
@@ -407,7 +410,7 @@ static void lanpr_cache_init(void *vedata)
     pd->begin_index = 0;
     int fsize = sizeof(float) * 4 * texture_size * texture_size;
 
-    if (lanpr->reloaded) {
+    if (lanpr_share.dpix_reloaded) {
       pd->atlas_pl = MEM_callocN(fsize, "atlas_point_l");
       pd->atlas_pr = MEM_callocN(fsize, "atlas_point_r");
       pd->atlas_nl = MEM_callocN(fsize, "atlas_normal_l");
@@ -497,7 +500,7 @@ static void lanpr_cache_populate(void *vedata, Object *ob)
     }
 
     int idx = pd->begin_index;
-    if (lanpr->reloaded) {
+    if (lanpr_share.dpix_reloaded) {
       pd->begin_index = lanpr_feed_atlas_data_obj(vedata,
                                                   pd->atlas_pl,
                                                   pd->atlas_pr,
@@ -524,7 +527,7 @@ static void lanpr_cache_finish(void *vedata)
 
   if (lanpr->master_mode == LANPR_MASTER_MODE_DPIX && lanpr->active_layer &&
       !lanpr_share.dpix_shader_error) {
-    if (lanpr->reloaded) {
+    if (lanpr_share.dpix_reloaded) {
       if (lanpr_share.render_buffer_shared) {
         lanpr_feed_atlas_data_intersection_cache(vedata,
                                                  pd->atlas_pl,
@@ -547,7 +550,7 @@ static void lanpr_cache_finish(void *vedata)
       MEM_freeN(pd->atlas_nr);
       MEM_freeN(pd->atlas_edge_mask);
       pd->atlas_pl = 0;
-      lanpr->reloaded = 0;
+      lanpr_share.dpix_reloaded = 0;
     }
 
     LANPR_BatchItem *bi;
@@ -748,7 +751,7 @@ static void lanpr_render_to_image(LANPR_Data *vedata,
                                  GPU_ATTACHMENT_LEAVE});
 
   lanpr_engine_init(vedata);
-  lanpr->reloaded = 1; /*  force dpix batch to re-create */
+  lanpr_share.dpix_reloaded_deg = 1; /*  force dpix batch to re-create */
   lanpr_cache_init(vedata);
   DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, LANPR_render_cache);
   lanpr_cache_finish(vedata);
@@ -797,7 +800,7 @@ static void lanpr_view_update(void *vedata)
   /*  our update flag is in SceneLANPR. */
   const DRWContextState *draw_ctx = DRW_context_state_get();
   SceneLANPR *lanpr = &DEG_get_evaluated_scene(draw_ctx->depsgraph)->lanpr;
-  //lanpr->reloaded = 1; /*  very bad solution, this will slow down animation. */
+  lanpr_share.dpix_reloaded_deg = 1; /*  very bad solution, this will slow down animation. */
 }
 
 /* This reserve for depsgraph auto updates. */
diff --git a/source/blender/editors/include/ED_lanpr.h b/source/blender/editors/include/ED_lanpr.h
index 6753ed04b5f..7699b41ad84 100644
--- a/source/blender/editors/include/ED_lanpr.h
+++ b/source/blender/editors/include/ED_lanpr.h
@@ -316,6 +316,8 @@ typedef struct LANPR_SharedResource {
   int dpix_shader_error;
   int texture_size;
   ListBase dpix_batch_list;
+  int dpix_reloaded;
+  int dpix_reloaded_deg;
 
   /* Software */
   struct GPUShader *software_shader;
diff --git a/source/blender/editors/lanpr/lanpr_ops.c b/source/blender/editors/lanpr/lanpr_ops.c
index abb0a7c5ae0..0c5edf23e45 100644
--- a/source/blender/editors/lanpr/lanpr_ops.c
+++ b/source/blender/editors/lanpr/lanpr_ops.c
@@ -52,6 +52,7 @@
 #include "RNA_define.h"
 
 #include "BLI_math.h"
+#include "BLI_callbacks.h"
 
 #include "bmesh.h"
 #include "bmesh_class.h"
@@ -4613,3 +4614,41 @@ void OBJECT_OT_lanpr_update_gp_source(struct wmOperatorType *ot)
   ot->poll = lanpr_active_is_source_object;
   ot->exec = lanpr_update_gp_source_exec;
 }
+
+/* Post-frame updater */
+
+
+static void lanpr_post_frame_updater(struct Main *UNUSED(_1),
+                                     struct ID *scene,
+                                     void *UNUSED(_3))
+{
+  Scene* s = scene;
+  if(s->lanpr.master_mode != LANPR_MASTER_MODE_SOFTWARE){
+    return;
+  }
+  if(strcmp(s->r.engine, RE_engine_id_BLENDER_LANPR)){
+    /* Not LANPR engine, do GPencil updates. */
+    /* LANPR engine will automatically update when drawing the viewport. */
+
+    /* No depsgraph reference here in the callback. Not working :? */
+    
+  }
+}
+
+static bCallbackFuncStore lanpr_post_frame_callback = {
+    NULL,
+    NULL,                            /* next, prev */
+    lanpr_post_frame_updater, /* func */
+    NULL,                            /* arg */
+    0,                               /* alloc */
+};
+
+static int lanpr_post_frame_regisetered = 0;
+
+void ED_register_lanpr_post_frame()
+{
+  if(!lanpr_post_frame_regisetered){
+    BLI_callback_add(&lanpr_post_frame_callback, BLI_CB_EVT_FRAME_CHANGE_POST);
+  }
+}
+
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index cd58a9d9484..1d31aef022c 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1671,17 +1671,12 @@ typedef struct SceneLANPR {
   float line_color[4];
   float background_color[4];
   int use_world_background; /* color only */
-  char _pad1[4];
 
   float depth_width_influence;
   float depth_width_curve;
   float depth_alpha_influence;
   float depth_alpha_curve;
 
-  /* states (needs optimization) */
-
-  int reloaded;
-
   /* edge split modifier will cause problems in LANPR. */
   int disable_edge_splits;
 
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index b2e106fb6d3..28877ce22ad 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -7146,11 +7146,6 @@ static void rna_def_scene_lanpr(BlenderRNA *brna)
   StructRNA *srna;
   PropertyRNA *prop;
 
-  static const EnumPropertyItem DEBUG_rna_enum_lanpr_reload[] = {
-      {0, "IDLE", 0, "Idle", "Idle"},
-      {1, "RELOAD", 0, "RELOAD", "Force reload the scene"},
-      {0, NULL, 0, NULL, NULL}};
-
   static const EnumPropertyItem rna_enum_lanpr_master_mode[] = {
       {LANPR_MASTER_MODE_SOFTWARE, "SOFTWARE", 0, "CPU", "Software edge calculation"},
       {LANPR_MASTER_MODE_DPIX, "DPIX", 0, "GPU", "DPIX GPU edge extraction"},
@@ -7217,13 +7212,6 @@ static void rna_def_scene_lanpr(BlenderRNA *brna)
                            "GPencil Overwrite",
                            "Overwrite existing strokes in the current frame of target GP objects");
 
-  prop = RNA_def_property(srna, "reloaded", PROP_ENUM, PROP_NONE);
-  RNA_def_property_enum_items(prop, DEBUG_rna_enum_lanpr_reload);
-  RNA_def_property_enum_default(prop, 0);
-  RNA_def_property_ui_text(prop, "Reload", "Reload the scene");
-  RNA_def_property_flag(prop, PROP_EDITABLE);
-  RNA_def_property_update(prop, NC_SCENE, NULL);
-
   prop = RNA_def_property(srna, "master_mode", PROP_ENUM, PROP_NONE);
   RNA_def_property_enum_items(prop, rna_enum_lanpr_master_mode);
   RNA_def_property_enum_default(prop, LANPR_MASTER_MODE_DPIX);



More information about the Bf-blender-cvs mailing list