From 2e73efa9b8d32de57fbf27657273f2d1b078010a Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Feb 2018 10:42:22 +0100 Subject: Depsgraph: Fix crash using --debug-depsgraph and --debug-depsgraph-no-threads Was accessing past the array boundaries. Should be safe for 2.79a. --- source/blender/blenkernel/intern/scene.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 423ed2af057..2e5b14cd902 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1518,6 +1518,8 @@ typedef struct ThreadedObjectUpdateState { bool has_mballs; #endif + int num_threads; + /* Execution statistics */ bool has_updated_objects; ListBase *statistics; @@ -1617,7 +1619,6 @@ static void scene_update_object_add_task(void *node, void *user_data) static void print_threads_statistics(ThreadedObjectUpdateState *state) { - int i, tot_thread; double finish_time; if ((G.debug & G_DEBUG_DEPSGRAPH) == 0) { @@ -1645,10 +1646,9 @@ static void print_threads_statistics(ThreadedObjectUpdateState *state) } #else finish_time = PIL_check_seconds_timer(); - tot_thread = BLI_system_thread_count(); int total_objects = 0; - for (i = 0; i < tot_thread; i++) { + for (int i = 0; i < state->num_threads; i++) { int thread_total_objects = 0; double thread_total_time = 0.0; StatisicsEntry *entry; @@ -1745,6 +1745,7 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene "scene update objects stats"); state.has_updated_objects = false; state.base_time = PIL_check_seconds_timer(); + state.num_threads = tot_thread; } #ifdef MBALL_SINGLETHREAD_HACK -- cgit v1.2.3 From fe1a508e551bc8309f552d69da0b74f7f5f5d46f Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Feb 2018 10:44:36 +0100 Subject: Depsgraph: Split debug flags Now it's possible to have debug messages for following things: - Graph construction - Graph evaluation - Graph tagging --- source/blender/blenkernel/BKE_global.h | 13 ++++++++----- source/blender/blenkernel/intern/anim_sys.c | 2 +- source/blender/blenkernel/intern/armature_update.c | 4 ++-- source/blender/blenkernel/intern/curve.c | 2 +- source/blender/blenkernel/intern/depsgraph.c | 2 +- source/blender/blenkernel/intern/mask_evaluate.c | 2 +- source/blender/blenkernel/intern/mesh.c | 2 +- source/blender/blenkernel/intern/movieclip.c | 2 +- source/blender/blenkernel/intern/object.c | 2 +- source/blender/blenkernel/intern/object_update.c | 6 +++--- source/blender/blenkernel/intern/particle_system.c | 2 +- source/blender/blenkernel/intern/rigidbody.c | 6 +++--- source/blender/blenkernel/intern/scene.c | 8 ++++---- source/blender/depsgraph/intern/depsgraph_intern.h | 2 +- source/blender/python/intern/bpy_app.c | 3 +++ source/creator/creator_args.c | 17 ++++++++++++++++- 16 files changed, 48 insertions(+), 27 deletions(-) diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h index 790c8051ace..f3d44164b1e 100644 --- a/source/blender/blenkernel/BKE_global.h +++ b/source/blender/blenkernel/BKE_global.h @@ -122,12 +122,15 @@ enum { G_DEBUG_WM = (1 << 5), /* operator, undo */ G_DEBUG_JOBS = (1 << 6), /* jobs time profiling */ G_DEBUG_FREESTYLE = (1 << 7), /* freestyle messages */ - G_DEBUG_DEPSGRAPH = (1 << 8), /* depsgraph messages */ - G_DEBUG_SIMDATA = (1 << 9), /* sim debug data display */ - G_DEBUG_GPU_MEM = (1 << 10), /* gpu memory in status bar */ + G_DEBUG_DEPSGRAPH_BUILD = (1 << 8), /* depsgraph construction messages */ + G_DEBUG_DEPSGRAPH_EVAL = (1 << 9), /* depsgraph evaluation messages */ + G_DEBUG_DEPSGRAPH_TAG = (1 << 10), /* depsgraph tagging messages */ G_DEBUG_DEPSGRAPH_NO_THREADS = (1 << 11), /* single threaded depsgraph */ - G_DEBUG_GPU = (1 << 12), /* gpu debug */ - G_DEBUG_IO = (1 << 13), /* IO Debugging (for Collada, ...)*/ + G_DEBUG_DEPSGRAPH = (G_DEBUG_DEPSGRAPH_BUILD | G_DEBUG_DEPSGRAPH_EVAL | G_DEBUG_DEPSGRAPH_TAG), + G_DEBUG_SIMDATA = (1 << 12), /* sim debug data display */ + G_DEBUG_GPU_MEM = (1 << 13), /* gpu memory in status bar */ + G_DEBUG_GPU = (1 << 14), /* gpu debug */ + G_DEBUG_IO = (1 << 15), /* IO Debugging (for Collada, ...)*/ }; #define G_DEBUG_ALL (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM | G_DEBUG_JOBS | \ diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c index 9037122c4f8..95d9a769749 100644 --- a/source/blender/blenkernel/intern/anim_sys.c +++ b/source/blender/blenkernel/intern/anim_sys.c @@ -2918,7 +2918,7 @@ void BKE_animsys_evaluate_all_animation(Main *main, Scene *scene, float ctime) /* ************** */ /* Evaluation API */ -#define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf +#define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf void BKE_animsys_eval_animdata(EvaluationContext *eval_ctx, ID *id) { diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c index cc1bd9716b1..2e9b2f7d20f 100644 --- a/source/blender/blenkernel/intern/armature_update.c +++ b/source/blender/blenkernel/intern/armature_update.c @@ -54,9 +54,9 @@ #include "DEG_depsgraph.h" #ifdef WITH_LEGACY_DEPSGRAPH -# define DEBUG_PRINT if (!DEG_depsgraph_use_legacy() && G.debug & G_DEBUG_DEPSGRAPH) printf +# define DEBUG_PRINT if (!DEG_depsgraph_use_legacy() && G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf #else -# define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf +# define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf #endif /* ********************** SPLINE IK SOLVER ******************* */ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index d18fda632aa..f0759748fee 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -5253,7 +5253,7 @@ void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *t void BKE_curve_eval_geometry(EvaluationContext *UNUSED(eval_ctx), Curve *curve) { - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s on %s\n", __func__, curve->id.name); } if (curve->bb == NULL || (curve->bb->flag & BOUNDBOX_DIRTY)) { diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c index 149158b9f5d..0fb9c4408d6 100644 --- a/source/blender/blenkernel/intern/depsgraph.c +++ b/source/blender/blenkernel/intern/depsgraph.c @@ -3002,7 +3002,7 @@ void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag) if (id == NULL) return; - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_TAG) { printf("%s: id=%s flag=%d\n", __func__, id->name, flag); } diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c index 0d71cc548c7..9875b74548a 100644 --- a/source/blender/blenkernel/intern/mask_evaluate.c +++ b/source/blender/blenkernel/intern/mask_evaluate.c @@ -897,7 +897,7 @@ void BKE_mask_layer_evaluate_deform(MaskLayer *masklay, const float ctime) } } -#define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf +#define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf void BKE_mask_eval_animation(struct EvaluationContext *eval_ctx, Mask *mask) { diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index 689ebc7e909..81a06ff17cc 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -2633,7 +2633,7 @@ Mesh *BKE_mesh_new_from_object( void BKE_mesh_eval_geometry(EvaluationContext *UNUSED(eval_ctx), Mesh *mesh) { - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s on %s\n", __func__, mesh->id.name); } if (mesh->bb == NULL || (mesh->bb->flag & BOUNDBOX_DIRTY)) { diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index a416de07c6d..f67560fe006 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -77,7 +77,7 @@ # include "intern/openexr/openexr_multi.h" #endif -#define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf +#define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf /*********************** movieclip buffer loaders *************************/ diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index c6b4e3fb0c7..acc652fb1be 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -2646,7 +2646,7 @@ void BKE_object_handle_update_ex(EvaluationContext *eval_ctx, * which is only in BKE_object_where_is_calc now */ /* XXX: should this case be OB_RECALC_OB instead? */ if (ob->recalc & OB_RECALC_ALL) { - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("recalcob %s\n", ob->id.name + 2); } /* Handle proxy copy for target. */ diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c index 84d2f624577..85cf7d8560d 100644 --- a/source/blender/blenkernel/intern/object_update.c +++ b/source/blender/blenkernel/intern/object_update.c @@ -62,9 +62,9 @@ #include "DEG_depsgraph.h" #ifdef WITH_LEGACY_DEPSGRAPH -# define DEBUG_PRINT if (!DEG_depsgraph_use_legacy() && G.debug & G_DEBUG_DEPSGRAPH) printf +# define DEBUG_PRINT if (!DEG_depsgraph_use_legacy() && G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf #else -# define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH) printf +# define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf #endif static ThreadMutex material_lock = BLI_MUTEX_INITIALIZER; @@ -153,7 +153,7 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx, Key *key; float ctime = BKE_scene_frame_get(scene); - if (G.debug & G_DEBUG_DEPSGRAPH) + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf("recalcdata %s\n", ob->id.name + 2); /* TODO(sergey): Only used by legacy depsgraph. */ diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c index e4dcf6618fa..2a1e0f559d7 100644 --- a/source/blender/blenkernel/intern/particle_system.c +++ b/source/blender/blenkernel/intern/particle_system.c @@ -4405,7 +4405,7 @@ void BKE_particle_system_eval_init(EvaluationContext *UNUSED(eval_ctx), Scene *scene, Object *ob) { - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s on %s\n", __func__, ob->id.name); } BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH); diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c index 39b0668f0b9..56e65b6f2c5 100644 --- a/source/blender/blenkernel/intern/rigidbody.c +++ b/source/blender/blenkernel/intern/rigidbody.c @@ -1690,7 +1690,7 @@ void BKE_rigidbody_rebuild_sim(EvaluationContext *UNUSED(eval_ctx), { float ctime = BKE_scene_frame_get(scene); - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s at %f\n", __func__, ctime); } @@ -1705,7 +1705,7 @@ void BKE_rigidbody_eval_simulation(EvaluationContext *UNUSED(eval_ctx), { float ctime = BKE_scene_frame_get(scene); - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s at %f\n", __func__, ctime); } @@ -1722,7 +1722,7 @@ void BKE_rigidbody_object_sync_transforms(EvaluationContext *UNUSED(eval_ctx), RigidBodyWorld *rbw = scene->rigidbody_world; float ctime = BKE_scene_frame_get(scene); - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { printf("%s on %s\n", __func__, ob->id.name); } diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index 2e5b14cd902..3f27e136e8c 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1568,7 +1568,7 @@ static void scene_update_object_func(TaskPool * __restrict pool, void *taskdata, double start_time = 0.0; bool add_to_stats = false; - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { if (object->recalc & OB_RECALC_ALL) { printf("Thread %d: update object %s\n", threadid, object->id.name); } @@ -1621,7 +1621,7 @@ static void print_threads_statistics(ThreadedObjectUpdateState *state) { double finish_time; - if ((G.debug & G_DEBUG_DEPSGRAPH) == 0) { + if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) { return; } @@ -1739,7 +1739,7 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene } /* Those are only needed when blender is run with --debug argument. */ - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { const int tot_thread = BLI_task_scheduler_num_threads(task_scheduler); state.statistics = MEM_callocN(tot_thread * sizeof(*state.statistics), "scene update objects stats"); @@ -1758,7 +1758,7 @@ static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene BLI_task_pool_work_and_wait(task_pool); BLI_task_pool_free(task_pool); - if (G.debug & G_DEBUG_DEPSGRAPH) { + if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) { print_threads_statistics(&state); MEM_freeN(state.statistics); } diff --git a/source/blender/depsgraph/intern/depsgraph_intern.h b/source/blender/depsgraph/intern/depsgraph_intern.h index 40229ef8f37..87d3d5e0e07 100644 --- a/source/blender/depsgraph/intern/depsgraph_intern.h +++ b/source/blender/depsgraph/intern/depsgraph_intern.h @@ -111,7 +111,7 @@ void deg_editors_scene_update(struct Main *bmain, struct Scene *scene, bool upda #define DEG_DEBUG_PRINTF(...) \ do { \ - if (G.debug & G_DEBUG_DEPSGRAPH) { \ + if (G.debug & G_DEBUG_DEPSGRAPH_BUILD) { \ fprintf(stderr, __VA_ARGS__); \ } \ } while (0) diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c index f44401afd7d..c5ff2592746 100644 --- a/source/blender/python/intern/bpy_app.c +++ b/source/blender/python/intern/bpy_app.c @@ -357,6 +357,9 @@ static PyGetSetDef bpy_app_getsets[] = { {(char *)"debug_handlers", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_HANDLERS}, {(char *)"debug_wm", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_WM}, {(char *)"debug_depsgraph", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH}, + {(char *)"debug_depsgraph_build", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH_BUILD}, + {(char *)"debug_depsgraph_eval", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH_EVAL}, + {(char *)"debug_depsgraph_tag", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH_TAG}, {(char *)"debug_simdata", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_SIMDATA}, {(char *)"debug_gpumem", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_GPU_MEM}, diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c index c9cdc1c9ccf..45af1581740 100644 --- a/source/creator/creator_args.c +++ b/source/creator/creator_args.c @@ -551,6 +551,9 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo BLI_argsPrintArgDoc(ba, "--debug-jobs"); BLI_argsPrintArgDoc(ba, "--debug-python"); BLI_argsPrintArgDoc(ba, "--debug-depsgraph"); + BLI_argsPrintArgDoc(ba, "--debug-depsgraph-eval"); + BLI_argsPrintArgDoc(ba, "--debug-depsgraph-build"); + BLI_argsPrintArgDoc(ba, "--debug-depsgraph-tag"); BLI_argsPrintArgDoc(ba, "--debug-depsgraph-no-threads"); BLI_argsPrintArgDoc(ba, "--debug-gpumem"); @@ -747,7 +750,13 @@ static const char arg_handle_debug_mode_generic_set_doc_jobs[] = static const char arg_handle_debug_mode_generic_set_doc_gpu[] = "\n\tEnable gpu debug context and information for OpenGL 4.3+."; static const char arg_handle_debug_mode_generic_set_doc_depsgraph[] = -"\n\tEnable debug messages from dependency graph."; +"\n\tEnable all debug messages from dependency graph."; +static const char arg_handle_debug_mode_generic_set_doc_depsgraph_build[] = +"\n\tEnable debug messages from dependency graph related on graph construction."; +static const char arg_handle_debug_mode_generic_set_doc_depsgraph_tag[] = +"\n\tEnable debug messages from dependency graph related on tagging."; +static const char arg_handle_debug_mode_generic_set_doc_depsgraph_eval[] = +"\n\tEnable debug messages from dependency graph related on evaluation."; static const char arg_handle_debug_mode_generic_set_doc_depsgraph_no_threads[] = "\n\tSwitch dependency graph to a single threaded evaluation."; static const char arg_handle_debug_mode_generic_set_doc_gpumem[] = @@ -1857,6 +1866,12 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle) CB_EX(arg_handle_debug_mode_generic_set, gpu), (void *)G_DEBUG_GPU); BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph", CB_EX(arg_handle_debug_mode_generic_set, depsgraph), (void *)G_DEBUG_DEPSGRAPH); + BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph-build", + CB_EX(arg_handle_debug_mode_generic_set, depsgraph_build), (void *)G_DEBUG_DEPSGRAPH_BUILD); + BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph-eval", + CB_EX(arg_handle_debug_mode_generic_set, depsgraph_eval), (void *)G_DEBUG_DEPSGRAPH_EVAL); + BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph-tag", + CB_EX(arg_handle_debug_mode_generic_set, depsgraph_tag), (void *)G_DEBUG_DEPSGRAPH_TAG); BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph-no-threads", CB_EX(arg_handle_debug_mode_generic_set, depsgraph_no_threads), (void *)G_DEBUG_DEPSGRAPH_NO_THREADS); BLI_argsAdd(ba, 1, NULL, "--debug-gpumem", -- cgit v1.2.3