diff options
Diffstat (limited to 'source/blender/draw/intern/draw_manager.c')
-rw-r--r-- | source/blender/draw/intern/draw_manager.c | 118 |
1 files changed, 68 insertions, 50 deletions
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c index cc618c76ccd..e7dff422105 100644 --- a/source/blender/draw/intern/draw_manager.c +++ b/source/blender/draw/intern/draw_manager.c @@ -27,14 +27,15 @@ #include "BLI_memblock.h" #include "BLI_rect.h" #include "BLI_string.h" +#include "BLI_task.h" #include "BLI_threads.h" #include "BLF_api.h" -#include "BKE_anim.h" #include "BKE_colortools.h" #include "BKE_context.h" #include "BKE_curve.h" +#include "BKE_duplilist.h" #include "BKE_editmesh.h" #include "BKE_global.h" #include "BKE_gpencil.h" @@ -63,11 +64,11 @@ #include "ED_space_api.h" #include "ED_view3d.h" -#include "GPU_draw.h" #include "GPU_extensions.h" #include "GPU_framebuffer.h" #include "GPU_immediate.h" #include "GPU_matrix.h" +#include "GPU_state.h" #include "GPU_uniformbuffer.h" #include "GPU_viewport.h" @@ -111,17 +112,6 @@ static ListBase DRW_engines = {NULL, NULL}; static void drw_state_prepare_clean_for_draw(DRWManager *dst) { memset(dst, 0x0, offsetof(DRWManager, gl_context)); - - /* Maybe not the best place for this. */ - if (!DST.uniform_names.buffer) { - DST.uniform_names.buffer = MEM_callocN(DRW_UNIFORM_BUFFER_NAME, "Name Buffer"); - DST.uniform_names.buffer_len = DRW_UNIFORM_BUFFER_NAME; - } - else if (DST.uniform_names.buffer_len > DRW_UNIFORM_BUFFER_NAME) { - DST.uniform_names.buffer = MEM_reallocN(DST.uniform_names.buffer, DRW_UNIFORM_BUFFER_NAME); - DST.uniform_names.buffer_len = DRW_UNIFORM_BUFFER_NAME; - } - DST.uniform_names.buffer_ofs = 0; } /* This function is used to reset draw manager to a state @@ -136,6 +126,23 @@ static void drw_state_ensure_not_reused(DRWManager *dst) #endif /* -------------------------------------------------------------------- */ +/** \name Threading + * \{ */ +static void drw_task_graph_init(void) +{ + BLI_assert(DST.task_graph == NULL); + DST.task_graph = BLI_task_graph_create(); +} + +static void drw_task_graph_deinit(void) +{ + BLI_task_graph_work_and_wait(DST.task_graph); + BLI_task_graph_free(DST.task_graph); + DST.task_graph = NULL; +} +/* \} */ + +/* -------------------------------------------------------------------- */ /** \name Settings * \{ */ @@ -145,11 +152,8 @@ bool DRW_object_is_renderable(const Object *ob) if (ob->type == OB_MESH) { if ((ob == DST.draw_ctx.object_edit) || DRW_object_is_in_edit_mode(ob)) { - View3D *v3d = DST.draw_ctx.v3d; - const int mask = (V3D_OVERLAY_EDIT_OCCLUDE_WIRE | V3D_OVERLAY_EDIT_WEIGHT); - - if (v3d && v3d->overlay.edit_flag & mask) { + if (v3d && v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) { return false; } } @@ -587,9 +591,6 @@ static void drw_viewport_var_init(void) ED_view3d_init_mats_rv3d(DST.draw_ctx.object_edit, rv3d); } - /* Alloc array of texture reference. */ - memset(&DST.RST, 0x0, sizeof(DST.RST)); - if (G_draw.view_ubo == NULL) { G_draw.view_ubo = DRW_uniformbuffer_create(sizeof(DRWViewUboStorage), NULL); } @@ -693,8 +694,7 @@ void **DRW_duplidata_get(void *vedata) void *DRW_view_layer_engine_data_get(DrawEngineType *engine_type) { - for (ViewLayerEngineData *sled = DST.draw_ctx.view_layer->drawdata.first; sled; - sled = sled->next) { + LISTBASE_FOREACH (ViewLayerEngineData *, sled, &DST.draw_ctx.view_layer->drawdata) { if (sled->engine_type == engine_type) { return sled->storage; } @@ -925,7 +925,7 @@ void DRW_cache_free_old_batches(Main *bmain) static void drw_engines_init(void) { - for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &DST.enabled_engines) { DrawEngineType *engine = link->data; ViewportEngineData *data = drw_viewport_engine_data_ensure(engine); PROFILE_START(stime); @@ -969,7 +969,7 @@ static void drw_engines_world_update(Scene *scene) return; } - for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &DST.enabled_engines) { DrawEngineType *engine = link->data; ViewportEngineData *data = drw_viewport_engine_data_ensure(engine); @@ -1035,7 +1035,7 @@ static void drw_engines_cache_finish(void) static void drw_engines_draw_scene(void) { - for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &DST.enabled_engines) { DrawEngineType *engine = link->data; ViewportEngineData *data = drw_viewport_engine_data_ensure(engine); PROFILE_START(stime); @@ -1058,7 +1058,7 @@ static void drw_engines_draw_scene(void) static void drw_engines_draw_text(void) { - for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &DST.enabled_engines) { DrawEngineType *engine = link->data; ViewportEngineData *data = drw_viewport_engine_data_ensure(engine); PROFILE_START(stime); @@ -1072,9 +1072,9 @@ static void drw_engines_draw_text(void) } /* Draw render engine info. */ -void DRW_draw_region_engine_info(int xoffset, int yoffset) +void DRW_draw_region_engine_info(int xoffset, int *yoffset, int line_height) { - for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &DST.enabled_engines) { DrawEngineType *engine = link->data; ViewportEngineData *data = drw_viewport_engine_data_ensure(engine); @@ -1095,8 +1095,8 @@ void DRW_draw_region_engine_info(int xoffset, int yoffset) if (*chr_current == '\n') { char info[GPU_INFO_SIZE]; BLI_strncpy(info, chr_start, line_len + 1); - yoffset -= U.widget_unit; - BLF_draw_default(xoffset, yoffset, 0.0f, info, sizeof(info)); + *yoffset -= line_height; + BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info)); /* Re-start counting. */ chr_start = chr_current + 1; @@ -1106,8 +1106,8 @@ void DRW_draw_region_engine_info(int xoffset, int yoffset) char info[GPU_INFO_SIZE]; BLI_strncpy(info, chr_start, line_len + 1); - yoffset -= U.widget_unit; - BLF_draw_default(xoffset, yoffset, 0.0f, info, sizeof(info)); + *yoffset -= line_height; + BLF_draw_default(xoffset, *yoffset, 0.0f, info, sizeof(info)); BLF_disable(font_id, BLF_SHADOW); } @@ -1181,7 +1181,7 @@ static void drw_engines_data_validate(void) void **engine_handle_array = BLI_array_alloca(engine_handle_array, enabled_engines + 1); int i = 0; - for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &DST.enabled_engines) { DrawEngineType *engine = link->data; engine_handle_array[i++] = engine; } @@ -1248,7 +1248,7 @@ void DRW_notify_view_update(const DRWUpdateContext *update_ctx) drw_engines_enable(view_layer, engine_type, gpencil_engine_needed); drw_engines_data_validate(); - for (LinkData *link = DST.enabled_engines.first; link; link = link->next) { + LISTBASE_FOREACH (LinkData *, link, &DST.enabled_engines) { DrawEngineType *draw_engine = link->data; ViewportEngineData *data = drw_viewport_engine_data_ensure(draw_engine); @@ -1300,9 +1300,6 @@ void DRW_draw_callbacks_post_scene(void) DRW_state_reset(); GPU_framebuffer_bind(dfbl->overlay_fb); - /* Disable sRGB encoding from the fixed function pipeline since all the drawing in this - * function is done with sRGB color. Avoid double transform. */ - glDisable(GL_FRAMEBUFFER_SRGB); GPU_matrix_projection_set(rv3d->winmat); GPU_matrix_set(rv3d->viewmat); @@ -1431,6 +1428,7 @@ void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph, /* reuse if caller sets */ .evil_C = DST.draw_ctx.evil_C, }; + drw_task_graph_init(); drw_context_state_init(); drw_viewport_var_init(); @@ -1495,6 +1493,7 @@ void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph, #endif } + drw_task_graph_deinit(); DRW_stats_begin(); GPU_framebuffer_bind(DST.default_framebuffer); @@ -1514,6 +1513,8 @@ void DRW_draw_render_loop_ex(struct Depsgraph *depsgraph, /* Fix 3D view being "laggy" on macos and win+nvidia. (See T56996, T61474) */ GPU_flush(); + DRW_stats_reset(); + DRW_draw_callbacks_post_scene(); if (WM_draw_region_get_bound_viewport(region)) { @@ -1773,7 +1774,6 @@ void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph) DST.options.is_image_render = true; DST.options.is_scene_render = true; DST.options.draw_background = scene->r.alphamode == R_ADDSKY; - DST.draw_ctx = (DRWContextState){ .scene = scene, .view_layer = view_layer, @@ -1858,9 +1858,9 @@ void DRW_render_object_iter( void (*callback)(void *vedata, Object *ob, RenderEngine *engine, struct Depsgraph *depsgraph)) { const DRWContextState *draw_ctx = DRW_context_state_get(); - DRW_hair_init(); + drw_task_graph_init(); const int object_type_exclude_viewport = draw_ctx->v3d ? draw_ctx->v3d->object_type_exclude_viewport : 0; @@ -1883,6 +1883,7 @@ void DRW_render_object_iter( DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END; drw_duplidata_free(); + drw_task_graph_deinit(); } /* Assume a valid gl context is bound (and that the gl_context_mutex has been acquired). @@ -2032,7 +2033,7 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph, Object *obweight = OBWEIGHTPAINT_FROM_OBACT(obact); if (obweight) { /* Only use Armature pose selection, when connected armature is in pose mode. */ - Object *ob_armature = modifiers_isDeformedByArmature(obweight); + Object *ob_armature = BKE_modifiers_is_deformed_by_armature(obweight); if (ob_armature && ob_armature->mode == OB_MODE_POSE) { obpose = ob_armature; } @@ -2054,14 +2055,16 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph, DST.viewport = viewport; DST.options.is_select = true; - + drw_task_graph_init(); /* Get list of enabled engines */ if (use_obedit) { drw_engines_enable_overlays(); } else if (!draw_surface) { /* grease pencil selection */ - use_drw_engine(&draw_engine_gpencil_type); + if (drw_gpencil_engine_needed(depsgraph, v3d)) { + use_drw_engine(&draw_engine_gpencil_type); + } drw_engines_enable_overlays(); } @@ -2069,7 +2072,9 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph, /* Draw surface for occlusion. */ drw_engines_enable_basic(); /* grease pencil selection */ - use_drw_engine(&draw_engine_gpencil_type); + if (drw_gpencil_engine_needed(depsgraph, v3d)) { + use_drw_engine(&draw_engine_gpencil_type); + } drw_engines_enable_overlays(); } @@ -2160,6 +2165,7 @@ void DRW_draw_select_loop(struct Depsgraph *depsgraph, } drw_duplidata_free(); + drw_task_graph_deinit(); drw_engines_cache_finish(); DRW_render_instance_buffer_finish(); @@ -2240,7 +2246,7 @@ static void drw_draw_depth_loop_imp(struct Depsgraph *depsgraph, .engine_type = engine_type, .depsgraph = depsgraph, }; - + drw_task_graph_init(); drw_engines_data_validate(); /* Setup framebuffer */ @@ -2284,6 +2290,7 @@ static void drw_draw_depth_loop_imp(struct Depsgraph *depsgraph, DRW_render_instance_buffer_finish(); } + drw_task_graph_deinit(); /* Start Drawing */ DRW_state_reset(); @@ -2373,7 +2380,7 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons .obact = OBACT(view_layer), .depsgraph = depsgraph, }; - + drw_task_graph_init(); drw_context_state_init(); /* Setup viewport */ @@ -2408,6 +2415,7 @@ void DRW_draw_select_id(Depsgraph *depsgraph, ARegion *region, View3D *v3d, cons drw_resource_buffer_finish(DST.vmempool); #endif } + drw_task_graph_deinit(); /* Start Drawing */ DRW_state_reset(); @@ -2433,7 +2441,8 @@ static void draw_world_clip_planes_from_rv3d(GPUBatch *batch, const float world_ /** * Clears the Depth Buffer and draws only the specified object. */ -void DRW_draw_depth_object(ARegion *region, View3D *v3d, GPUViewport *viewport, Object *object) +void DRW_draw_depth_object( + Scene *scene, ARegion *region, View3D *v3d, GPUViewport *viewport, Object *object) { RegionView3D *rv3d = region->regiondata; @@ -2470,8 +2479,10 @@ void DRW_draw_depth_object(ARegion *region, View3D *v3d, GPUViewport *viewport, else { batch = DRW_mesh_batch_cache_get_surface(me); } - - DRW_mesh_batch_cache_create_requested(object, me, NULL, false, true); + struct TaskGraph *task_graph = BLI_task_graph_create(); + DRW_mesh_batch_cache_create_requested(task_graph, object, me, scene, false, true); + BLI_task_graph_work_and_wait(task_graph); + BLI_task_graph_free(task_graph); const eGPUShaderConfig sh_cfg = world_clip_planes ? GPU_SHADER_CFG_CLIPPED : GPU_SHADER_CFG_DEFAULT; @@ -2575,6 +2586,15 @@ bool DRW_state_is_playback(void) } /** + * Is the user navigating the region. + */ +bool DRW_state_is_navigating(void) +{ + const RegionView3D *rv3d = DST.draw_ctx.rv3d; + return (rv3d) && (rv3d->rflag & (RV3D_NAVIGATING | RV3D_PAINTING)); +} + +/** * Should text draw in this mode? */ bool DRW_state_show_text(void) @@ -2705,8 +2725,6 @@ void DRW_engines_free(void) DRW_TEXTURE_FREE_SAFE(G_draw.ramp); DRW_TEXTURE_FREE_SAFE(G_draw.weight_ramp); - MEM_SAFE_FREE(DST.uniform_names.buffer); - if (DST.draw_list) { GPU_draw_list_discard(DST.draw_list); } |