diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2019-04-26 15:02:58 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2019-04-26 16:33:49 +0300 |
commit | 50d75cd528b904760426ff9bcc31a3794e995edb (patch) | |
tree | ca5bdc2ce24bc944dc02951e74bd7e2e80d7990a /source/blender/draw/modes | |
parent | 03d482d212945eb46144524ccb8824d6889e8039 (diff) |
Fix T62880 Severe FPS drop with multiple bone shapes
Fix instancing batches not being reused by custom bone shapes.
Drawing thoses is now faster than 2.79 (40fps instead of 30fps)
Diffstat (limited to 'source/blender/draw/modes')
-rw-r--r-- | source/blender/draw/modes/edit_armature_mode.c | 1 | ||||
-rw-r--r-- | source/blender/draw/modes/object_mode.c | 12 | ||||
-rw-r--r-- | source/blender/draw/modes/pose_mode.c | 16 |
3 files changed, 28 insertions, 1 deletions
diff --git a/source/blender/draw/modes/edit_armature_mode.c b/source/blender/draw/modes/edit_armature_mode.c index 12bf4982ffb..d1ef0d0e104 100644 --- a/source/blender/draw/modes/edit_armature_mode.c +++ b/source/blender/draw/modes/edit_armature_mode.c @@ -126,6 +126,7 @@ static void EDIT_ARMATURE_cache_populate(void *vedata, Object *ob) .bone_envelope = psl->bone_envelope[ghost], .bone_axes = psl->bone_axes, .relationship_lines = psl->relationship[ghost], + .custom_shapes = NULL, /* Not needed in edit mode. */ }; DRW_shgroup_armature_edit(ob, passes, transp); } diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c index 7d42f59fea0..f7694f4a6f6 100644 --- a/source/blender/draw/modes/object_mode.c +++ b/source/blender/draw/modes/object_mode.c @@ -53,6 +53,8 @@ #include "BKE_particle.h" #include "BKE_tracking.h" +#include "BLI_ghash.h" + #include "ED_view3d.h" #include "GPU_batch.h" @@ -273,6 +275,8 @@ typedef struct OBJECT_PrivateData { OBJECT_ShadingGroupList sgl; OBJECT_ShadingGroupList sgl_ghost; + GHash *custom_shapes; + /* Outlines */ DRWShadingGroup *outlines_active; DRWShadingGroup *outlines_select; @@ -1040,6 +1044,8 @@ static void OBJECT_cache_init(void *vedata) g_data->xray_enabled_and_not_wire = g_data->xray_enabled && draw_ctx->v3d->shading.type > OB_WIRE; + g_data->custom_shapes = BLI_ghash_ptr_new(__func__); + { DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_WIRE; @@ -3288,6 +3294,7 @@ static void OBJECT_cache_populate(void *vedata, Object *ob) .bone_envelope = sgl->bone_envelope, .bone_axes = sgl->bone_axes, .relationship_lines = NULL, /* Don't draw relationship lines */ + .custom_shapes = stl->g_data->custom_shapes, }; DRW_shgroup_armature_object(ob, view_layer, passes, is_wire); } @@ -3395,6 +3402,11 @@ static void OBJECT_cache_finish(void *vedata) DRW_pass_sort_shgroup_z(stl->g_data->sgl.image_empties); DRW_pass_sort_shgroup_z(stl->g_data->sgl_ghost.image_empties); + + if (stl->g_data->custom_shapes) { + /* TODO(fclem): Do not free it for each frame but reuse it. Avoiding alloc cost. */ + BLI_ghash_free(stl->g_data->custom_shapes, NULL, NULL); + } } static void OBJECT_draw_scene(void *vedata) diff --git a/source/blender/draw/modes/pose_mode.c b/source/blender/draw/modes/pose_mode.c index 5e3353414f5..a37901a1fa9 100644 --- a/source/blender/draw/modes/pose_mode.c +++ b/source/blender/draw/modes/pose_mode.c @@ -72,6 +72,7 @@ typedef struct POSE_Data { typedef struct POSE_PrivateData { DRWShadingGroup *bone_selection_shgrp; DRWShadingGroup *bone_selection_invert_shgrp; + GHash *custom_shapes[2]; float blend_color[4]; float blend_color_invert[4]; bool transparent_bones; @@ -139,6 +140,8 @@ static void POSE_cache_init(void *vedata) state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS_EQUAL | DRW_STATE_BLEND | DRW_STATE_WIRE; psl->relationship[i] = DRW_pass_create("Bone Relationship Pass", state); + + ppd->custom_shapes[i] = BLI_ghash_ptr_new(__func__); } { @@ -213,6 +216,7 @@ static void POSE_cache_populate(void *vedata, Object *ob) .bone_envelope = psl->bone_envelope[ghost], .bone_axes = psl->bone_axes, .relationship_lines = psl->relationship[ghost], + .custom_shapes = ppd->custom_shapes[transp], }; DRW_shgroup_armature_pose(ob, passes, transp); } @@ -231,6 +235,16 @@ static void POSE_cache_populate(void *vedata, Object *ob) } } +static void POSE_cache_finish(void *vedata) +{ + POSE_PrivateData *ppd = ((POSE_Data *)vedata)->stl->g_data; + + /* TODO(fclem): Do not free it for each frame but reuse it. Avoiding alloc cost. */ + for (int i = 0; i < 2; i++) { + BLI_ghash_free(ppd->custom_shapes[i], NULL, NULL); + } +} + /** * Return true if armature should be handled by the pose mode engine. */ @@ -323,7 +337,7 @@ DrawEngineType draw_engine_pose_type = { &POSE_engine_free, &POSE_cache_init, &POSE_cache_populate, - NULL, + &POSE_cache_finish, NULL, &POSE_draw_scene, NULL, |