DRW: Make Cache timing global and not per object.

This is to fix some performance bottleneck.
This commit is contained in:
Clément Foucault 2017-08-11 15:39:09 +02:00
parent 22872857d4
commit 2087158d5b
1 changed files with 14 additions and 20 deletions

View File

@ -360,6 +360,9 @@ static struct DRWGlobalState {
struct DRWTextStore **text_store_p;
ListBase enabled_engines; /* RenderEngineType */
/* Profiling */
double cache_time;
} DST = {NULL};
static struct DRWMatrixOveride {
@ -2676,13 +2679,9 @@ static void DRW_engines_cache_init(void)
DST.text_store_p = &data->text_draw_cache;
}
PROFILE_START(stime);
data->cache_time = 0.0;
if (engine->cache_init) {
engine->cache_init(data);
}
PROFILE_END_ACCUM(data->cache_time, stime);
}
}
@ -2691,13 +2690,10 @@ static void DRW_engines_cache_populate(Object *ob)
for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
DrawEngineType *engine = link->data;
ViewportEngineData *data = DRW_viewport_engine_data_get(engine);
PROFILE_START(stime);
if (engine->cache_populate) {
engine->cache_populate(data, ob);
}
PROFILE_END_ACCUM(data->cache_time, stime);
}
}
@ -2706,13 +2702,10 @@ static void DRW_engines_cache_finish(void)
for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
DrawEngineType *engine = link->data;
ViewportEngineData *data = DRW_viewport_engine_data_get(engine);
PROFILE_START(stime);
if (engine->cache_finish) {
engine->cache_finish(data);
}
PROFILE_END_ACCUM(data->cache_time, stime);
}
}
@ -2988,7 +2981,7 @@ static void draw_stat(rcti *rect, int u, int v, const char *txt, const int size)
static void DRW_debug_cpu_stats(void)
{
int u, v;
double cache_tot_time = 0.0, init_tot_time = 0.0, background_tot_time = 0.0, render_tot_time = 0.0, tot_time = 0.0;
double init_tot_time = 0.0, background_tot_time = 0.0, render_tot_time = 0.0, tot_time = 0.0;
/* local coordinate visible rect inside region, to accomodate overlapping ui */
rcti rect;
struct ARegion *ar = DST.draw_ctx.ar;
@ -3002,8 +2995,6 @@ static void DRW_debug_cpu_stats(void)
char col_label[32];
sprintf(col_label, "Engine");
draw_stat(&rect, u++, v, col_label, sizeof(col_label));
sprintf(col_label, "Cache");
draw_stat(&rect, u++, v, col_label, sizeof(col_label));
sprintf(col_label, "Init");
draw_stat(&rect, u++, v, col_label, sizeof(col_label));
sprintf(col_label, "Background");
@ -3023,10 +3014,6 @@ static void DRW_debug_cpu_stats(void)
draw_stat(&rect, u++, v, engine->idname, sizeof(engine->idname));
cache_tot_time += data->cache_time;
sprintf(time_to_txt, "%.2fms", data->cache_time);
draw_stat(&rect, u++, v, time_to_txt, sizeof(time_to_txt));
init_tot_time += data->init_time;
sprintf(time_to_txt, "%.2fms", data->init_time);
draw_stat(&rect, u++, v, time_to_txt, sizeof(time_to_txt));
@ -3049,8 +3036,6 @@ static void DRW_debug_cpu_stats(void)
u = 0;
sprintf(col_label, "Sub Total");
draw_stat(&rect, u++, v, col_label, sizeof(col_label));
sprintf(time_to_txt, "%.2fms", cache_tot_time);
draw_stat(&rect, u++, v, time_to_txt, sizeof(time_to_txt));
sprintf(time_to_txt, "%.2fms", init_tot_time);
draw_stat(&rect, u++, v, time_to_txt, sizeof(time_to_txt));
sprintf(time_to_txt, "%.2fms", background_tot_time);
@ -3059,6 +3044,13 @@ static void DRW_debug_cpu_stats(void)
draw_stat(&rect, u++, v, time_to_txt, sizeof(time_to_txt));
sprintf(time_to_txt, "%.2fms", tot_time);
draw_stat(&rect, u++, v, time_to_txt, sizeof(time_to_txt));
v += 2;
u = 0;
sprintf(col_label, "Cache Time");
draw_stat(&rect, u++, v, col_label, sizeof(col_label));
sprintf(time_to_txt, "%.2fms", DST.cache_time);
draw_stat(&rect, u++, v, time_to_txt, sizeof(time_to_txt));
}
/* Display GPU time for each passes */
@ -3071,7 +3063,7 @@ static void DRW_debug_gpu_stats(void)
UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
int v = BLI_listbase_count(&DST.enabled_engines) + 3;
int v = BLI_listbase_count(&DST.enabled_engines) + 5;
char stat_string[32];
@ -3162,6 +3154,7 @@ void DRW_draw_render_loop_ex(
/* ideally only refresh when objects are added/removed */
/* or render properties / materials change */
if (cache_is_dirty) {
PROFILE_START(stime);
DRW_engines_cache_init();
DEG_OBJECT_ITER(graph, ob, DEG_OBJECT_ITER_FLAG_ALL);
@ -3173,6 +3166,7 @@ void DRW_draw_render_loop_ex(
DEG_OBJECT_ITER_END
DRW_engines_cache_finish();
PROFILE_END_ACCUM(DST.cache_time, stime);
}
DRW_stats_begin();