Commit: 3dd8f287e1fd0993eef8cac782c30a264ebb0d71
Author: Sergey Sharybin
Date:   Wed Jul 22 11:24:38 2015 +0200
Branches: master
https://developer.blender.org/rB3dd8f287e1fd0993eef8cac782c30a264ebb0d71

Render preview: Make preview render database lazily loaded

Gives about 5-10% of startup time improvement here.

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

M       source/blender/editors/include/ED_render.h
M       source/blender/editors/render/render_preview.c
M       source/blender/windowmanager/intern/wm_init_exit.c

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

diff --git a/source/blender/editors/include/ED_render.h 
b/source/blender/editors/include/ED_render.h
index ba58ae6..1898b9c 100644
--- a/source/blender/editors/include/ED_render.h
+++ b/source/blender/editors/include/ED_render.h
@@ -70,7 +70,7 @@ enum {
        PR_ICON_DEFERRED = 3,
 };
 
-void ED_preview_init_dbase(void);
+void ED_preview_ensure_dbase(void);
 void ED_preview_free_dbase(void);
 
 void ED_preview_shader_job(const struct bContext *C, void *owner, struct ID 
*id, struct ID *parent, struct MTex *slot, int sizex, int sizey, int method);
diff --git a/source/blender/editors/render/render_preview.c 
b/source/blender/editors/render/render_preview.c
index 0a7455b..6dfd2b3 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -94,7 +94,10 @@
 #include "ED_datafiles.h"
 #include "ED_render.h"
 
-
+#ifndef NDEBUG
+/* Used for database init assert(). */
+#  include "BLI_threads.h"
+#endif
 
 ImBuf *get_brush_icon(Brush *brush)
 {
@@ -204,11 +207,16 @@ static Main *load_main_from_memory(const void *blend, int 
blend_size)
 }
 #endif
 
-void ED_preview_init_dbase(void)
+void ED_preview_ensure_dbase(void)
 {
 #ifndef WITH_HEADLESS
-       G_pr_main = load_main_from_memory(datatoc_preview_blend, 
datatoc_preview_blend_size);
-       G_pr_main_cycles = load_main_from_memory(datatoc_preview_cycles_blend, 
datatoc_preview_cycles_blend_size);
+       static bool base_initialized = false;
+       BLI_assert(BLI_thread_is_main());
+       if (!base_initialized) {
+               G_pr_main = load_main_from_memory(datatoc_preview_blend, 
datatoc_preview_blend_size);
+               G_pr_main_cycles = 
load_main_from_memory(datatoc_preview_cycles_blend, 
datatoc_preview_cycles_blend_size);
+               base_initialized = true;
+       }
 #endif
 }
 
@@ -1152,6 +1160,8 @@ void ED_preview_icon_render(Main *bmain, Scene *scene, ID 
*id, unsigned int *rec
        short stop = false, update = false;
        float progress = 0.0f;
 
+       ED_preview_ensure_dbase();
+
        ip.bmain = bmain;
        ip.scene = scene;
        ip.owner = id;
@@ -1170,7 +1180,9 @@ void ED_preview_icon_job(const bContext *C, void *owner, 
ID *id, unsigned int *r
 {
        wmJob *wm_job;
        IconPreview *ip, *old_ip;
-       
+
+       ED_preview_ensure_dbase();
+
        /* suspended start means it starts after 1 timer step, see 
WM_jobs_timer below */
        wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, "Icon 
Preview",
                             WM_JOB_EXCL_RENDER | WM_JOB_SUSPEND, 
WM_JOB_TYPE_RENDER_PREVIEW);
@@ -1212,6 +1224,8 @@ void ED_preview_shader_job(const bContext *C, void 
*owner, ID *id, ID *parent, M
                return;
        }
 
+       ED_preview_ensure_dbase();
+
        wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), owner, 
"Shader Preview",
                            WM_JOB_EXCL_RENDER, WM_JOB_TYPE_RENDER_PREVIEW);
        sp = MEM_callocN(sizeof(ShaderPreview), "shader preview");
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c 
b/source/blender/windowmanager/intern/wm_init_exit.c
index ad7044c..a1d0939 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -229,9 +229,7 @@ void WM_init(bContext *C, int argc, const char **argv)
        ED_render_clear_mtex_copybuf();
 
        // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-               
-       ED_preview_init_dbase();
-       
+
        wm_read_history();
 
        /* allow a path of "", this is what happens when making a new file */

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to