Skip to content

Commit

Permalink
Gamut/Softproof/Overexposed modes: bypass pixel cache
Browse files Browse the repository at this point in the history
We can't check the integrity of the internal params since they don't have internal params, so there is no cacheline invalidation possible. Then, we need to resync with the whole pipeline.

Fix #400
Fix #402
  • Loading branch information
aurelienpierre committed Jan 13, 2025
1 parent 56e9eec commit 6ea8110
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 21 deletions.
17 changes: 14 additions & 3 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,17 +261,28 @@ void dt_dev_pixelpipe_rebuild(dt_develop_t *dev)
dt_pthread_mutex_unlock(&dev->history_mutex);
}

void dt_dev_pixelpipe_resync(dt_develop_t *dev)
void dt_dev_pixelpipe_resync_main(dt_develop_t *dev)
{
if(!dev->gui_attached) return;

dt_atomic_set_int(&dev->pipe->shutdown, TRUE);
dt_atomic_set_int(&dev->preview_pipe->shutdown, TRUE);

dt_pthread_mutex_lock(&dev->history_mutex);
dev->pipe->changed |= DT_DEV_PIPE_SYNCH;
dt_pthread_mutex_unlock(&dev->history_mutex);
}

void dt_dev_pixelpipe_resync_all(dt_develop_t *dev)
{
if(!dev->gui_attached) return;

dt_atomic_set_int(&dev->preview_pipe->shutdown, TRUE);

dt_pthread_mutex_lock(&dev->history_mutex);
dev->preview_pipe->changed |= DT_DEV_PIPE_SYNCH;
dt_pthread_mutex_unlock(&dev->history_mutex);

dt_dev_pixelpipe_resync_main(dev);
}

void dt_dev_invalidate_real(dt_develop_t *dev)
Expand Down Expand Up @@ -917,7 +928,7 @@ void dt_dev_add_history_item_real(dt_develop_t *dev, dt_iop_module_t *module, gb
// a weird thing happens with that one, when drawing masks, that typically
// leads to 2 history items creation (one for mask manager, the next for the module
// capturing the drawing). So, resync the whole history for safety
dt_dev_pixelpipe_resync(dev);
dt_dev_pixelpipe_resync_all(dev);
}

dt_control_queue_redraw_center();
Expand Down
6 changes: 5 additions & 1 deletion src/develop/develop.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,11 @@ void dt_dev_invalidate_zoom_real(dt_develop_t *dev);

// Invalidate the main image and the thumbnail in darkroom.
// Resync the whole history, which may be expensive.
void dt_dev_pixelpipe_resync(dt_develop_t *dev);
void dt_dev_pixelpipe_resync_all(dt_develop_t *dev);

// Invalidate the main image in darkroom.
// Resync the whole history, which may be expensive.
void dt_dev_pixelpipe_resync_main(dt_develop_t *dev);


void dt_dev_set_histogram(dt_develop_t *dev);
Expand Down
5 changes: 5 additions & 0 deletions src/iop/colorout.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,11 @@ void commit_params(struct dt_iop_module_t *self, dt_iop_params_t *p1, dt_dev_pix

d->mode = (pipe->type & DT_DEV_PIXELPIPE_FULL) == DT_DEV_PIXELPIPE_FULL ? darktable.color_profiles->mode : DT_PROFILE_NORMAL;

// Softproof and gamut check take input from GUI and don't write it in internal parameters.
// The cacheline integrity hash will not be meaningful in this scenario,
// we need to bypass the cache entirely in these modes.
dt_iop_set_cache_bypass(self, (d->mode != DT_PROFILE_NORMAL));

if(d->xform)
{
cmsDeleteTransform(d->xform);
Expand Down
4 changes: 4 additions & 0 deletions src/iop/overexposed.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ void init(dt_iop_module_t *module)
module->default_enabled = 1;
module->params_size = sizeof(dt_iop_overexposed_t);
module->gui_data = NULL;

// This module permanently bypasses the cache because it takes input from GUI
// and doesn't leave internal parameters to compute an integrity hash on.
dt_iop_set_cache_bypass(module, TRUE);
}

// clang-format off
Expand Down
4 changes: 4 additions & 0 deletions src/iop/rawoverexposed.c
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,10 @@ void init(dt_iop_module_t *module)
module->default_enabled = 1;
module->params_size = sizeof(dt_iop_rawoverexposed_t);
module->gui_data = NULL;

// This module permanently bypasses the cache because it takes input from GUI
// and doesn't leave internal parameters to compute an integrity hash on.
dt_iop_set_cache_bypass(module, TRUE);
}

// clang-format off
Expand Down
35 changes: 18 additions & 17 deletions src/views/darkroom.c
Original file line number Diff line number Diff line change
Expand Up @@ -1036,12 +1036,19 @@ static void _guides_view_changed(gpointer instance, dt_view_t *old_view, dt_view
dt_guides_update_button_state();
}

/**
* DOC
* Overexposed and gamut modules are inserted inplace in pipeline at runtime,
* only for the main preview, and don't add history items.
* They all need a full history -> pipeline resynchronization.
*/

/* overexposed */
static void _overexposed_quickbutton_clicked(GtkWidget *w, gpointer user_data)
{
dt_develop_t *d = (dt_develop_t *)user_data;
d->overexposed.enabled = !d->overexposed.enabled;
dt_dev_invalidate(d);
dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1051,9 +1058,8 @@ static void colorscheme_callback(GtkWidget *combo, gpointer user_data)
d->overexposed.colorscheme = dt_bauhaus_combobox_get(combo);
if(d->overexposed.enabled == FALSE)
gtk_button_clicked(GTK_BUTTON(d->overexposed.button));
else
dt_dev_invalidate(d);

dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1063,9 +1069,8 @@ static void lower_callback(GtkWidget *slider, gpointer user_data)
d->overexposed.lower = dt_bauhaus_slider_get(slider);
if(d->overexposed.enabled == FALSE)
gtk_button_clicked(GTK_BUTTON(d->overexposed.button));
else
dt_dev_invalidate(d);

dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1075,9 +1080,8 @@ static void upper_callback(GtkWidget *slider, gpointer user_data)
d->overexposed.upper = dt_bauhaus_slider_get(slider);
if(d->overexposed.enabled == FALSE)
gtk_button_clicked(GTK_BUTTON(d->overexposed.button));
else
dt_dev_invalidate(d);

dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1098,7 +1102,7 @@ static void _rawoverexposed_quickbutton_clicked(GtkWidget *w, gpointer user_data
{
dt_develop_t *d = (dt_develop_t *)user_data;
d->rawoverexposed.enabled = !d->rawoverexposed.enabled;
dt_dev_invalidate(d);
dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1108,9 +1112,8 @@ static void rawoverexposed_mode_callback(GtkWidget *combo, gpointer user_data)
d->rawoverexposed.mode = dt_bauhaus_combobox_get(combo);
if(d->rawoverexposed.enabled == FALSE)
gtk_button_clicked(GTK_BUTTON(d->rawoverexposed.button));
else
dt_dev_invalidate(d);

dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1120,9 +1123,8 @@ static void rawoverexposed_colorscheme_callback(GtkWidget *combo, gpointer user_
d->rawoverexposed.colorscheme = dt_bauhaus_combobox_get(combo);
if(d->rawoverexposed.enabled == FALSE)
gtk_button_clicked(GTK_BUTTON(d->rawoverexposed.button));
else
dt_dev_invalidate(d);

dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1132,9 +1134,8 @@ static void rawoverexposed_threshold_callback(GtkWidget *slider, gpointer user_d
d->rawoverexposed.threshold = dt_bauhaus_slider_get(slider);
if(d->rawoverexposed.enabled == FALSE)
gtk_button_clicked(GTK_BUTTON(d->rawoverexposed.button));
else
dt_dev_invalidate(d);

dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1149,7 +1150,7 @@ static void _softproof_quickbutton_clicked(GtkWidget *w, gpointer user_data)

_update_softproof_gamut_checking(d);

dt_dev_invalidate(d);
dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand All @@ -1164,7 +1165,7 @@ static void _gamut_quickbutton_clicked(GtkWidget *w, gpointer user_data)

_update_softproof_gamut_checking(d);

dt_dev_invalidate(d);
dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}

Expand Down Expand Up @@ -1216,7 +1217,7 @@ static void softproof_profile_callback(GtkWidget *combo, gpointer user_data)
if(profile_changed)
{
DT_DEBUG_CONTROL_SIGNAL_RAISE(darktable.signals, DT_SIGNAL_CONTROL_PROFILE_USER_CHANGED, DT_COLORSPACES_PROFILE_TYPE_SOFTPROOF);
dt_dev_invalidate_all(d);
dt_dev_pixelpipe_resync_main(d);
dt_dev_refresh_ui_images(d);
}
}
Expand Down

0 comments on commit 6ea8110

Please sign in to comment.