Skip to content

Commit c32d613

Browse files
masterpigaTurboGit
authored andcommitted
Improvements to mask distort efficiency.
Via incremental caching and reduced malloc/free cycles.
1 parent aa344e0 commit c32d613

4 files changed

Lines changed: 380 additions & 57 deletions

File tree

src/develop/blend.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,12 @@ static void _refine_with_detail_mask(dt_iop_module_t *self,
273273
float *lum = dt_masks_calc_detail_mask(piece, threshold, detail);
274274
if(lum == NULL) goto error;
275275

276+
// src_hash encodes what the thresholded mask depends on (scharr data + slider value),
277+
// so the distortion cache is invalidated when the details slider changes.
278+
const dt_hash_t src_hash = dt_hash(p->scharr.hash, &level, sizeof(level));
279+
276280
// here we have the slightly blurred full detail mask available
277-
float *warp_mask = dt_dev_distort_detail_mask(piece, lum, self);
281+
float *warp_mask = dt_dev_distort_detail_mask(piece, lum, self, src_hash);
278282
dt_free_align(lum);
279283

280284
if(warp_mask == NULL) goto error;
@@ -815,8 +819,12 @@ static void _refine_with_detail_mask_cl(dt_iop_module_t *self,
815819
out = NULL;
816820
blur = NULL;
817821

822+
// src_hash encodes what the thresholded mask depends on (scharr data + slider value),
823+
// so the distortion cache is invalidated when the details slider changes.
824+
const dt_hash_t src_hash = dt_hash(p->scharr.hash, &level, sizeof(level));
825+
818826
// here we have the slightly blurred full detail mask available
819-
float *warp_mask = dt_dev_distort_detail_mask(piece, lum, self);
827+
float *warp_mask = dt_dev_distort_detail_mask(piece, lum, self, src_hash);
820828
dt_free_align(lum);
821829
if(warp_mask == NULL)
822830
{

src/develop/develop.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,11 +1373,16 @@ static void _dev_add_history_item(dt_develop_t *dev,
13731373
|| module != dev->gui_module)
13741374
dt_dev_invalidate_all(dev);
13751375

1376+
dt_pthread_mutex_unlock(&dev->history_mutex);
1377+
1378+
// Signal after releasing history_mutex to avoid deadlock: raising
1379+
// DT_SIGNAL_DEVELOP_HISTORY_CHANGE while holding history_mutex can trigger
1380+
// signal handlers (e.g. neural_restore) that call dt_control_get_mouse_over_id,
1381+
// which acquires global_mutex — conflicting with dt_dev_zoom_move and
1382+
// dt_dev_get_viewport_params which hold global_mutex and then acquire history_mutex.
13761383
if(need_end_record)
13771384
dt_dev_undo_end_record(dev);
13781385

1379-
dt_pthread_mutex_unlock(&dev->history_mutex);
1380-
13811386
if(dev->gui_attached)
13821387
{
13831388
/* signal that history has changed */

0 commit comments

Comments
 (0)