Skip to content

Commit

Permalink
Pipeline threads: remove the private memcopy since it's not kept aliv…
Browse files Browse the repository at this point in the history
…e anymore

Doesn't matter if we lock the mipmap cache
  • Loading branch information
aurelienpierre committed Jan 17, 2025
1 parent 2810020 commit a203d53
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/develop/develop.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,17 +347,19 @@ void dt_dev_invalidate_all_real(dt_develop_t *dev)
dt_dev_invalidate_preview(dev);
}

float * _get_input_copy(const int32_t imgid, dt_mipmap_size_t type, int *width, int *height, float *iscale)
static dt_mipmap_buffer_t _get_input_copy(const int32_t imgid, dt_mipmap_size_t type, int *width, int *height, float *iscale)
{
dt_mipmap_buffer_t buf;
dt_mipmap_cache_get(darktable.mipmap_cache, &buf, imgid, type, DT_MIPMAP_BLOCKING, 'r');

gboolean error = (!buf.buf || !buf.width || !buf.height);
//gboolean error = (!buf.buf || !buf.width || !buf.height);

// keep our own copy of the input buffer to release the cache lock ASAP
*width = buf.width;
*height = buf.height;
*iscale = buf.iscale;

/*
const size_t buf_size = buf.cache_entry->data_size;
float *buffer = NULL;
Expand All @@ -373,11 +375,11 @@ float * _get_input_copy(const int32_t imgid, dt_mipmap_size_t type, int *width,
dt_mipmap_cache_release(darktable.mipmap_cache, &buf);
return buffer;
*/

return buf;
}

// Keep threads alive for 2 minutes after the last run
// In case we can't stop them for some reason...
#define KEEP_ALIVE 120.

void dt_dev_process_preview_job(dt_develop_t *dev)
{
Expand All @@ -388,13 +390,13 @@ void dt_dev_process_preview_job(dt_develop_t *dev)
// always process the whole downsampled mipf buffer, to allow for fast scrolling and mip4 write-through.
int width, height;
float iscale;
float *buffer = _get_input_copy(dev->image_storage.id, DT_MIPMAP_F, &width, &height, &iscale);
dt_mipmap_buffer_t buf = _get_input_copy(dev->image_storage.id, DT_MIPMAP_F, &width, &height, &iscale);

gboolean finish_on_error = (buffer == NULL);
gboolean finish_on_error = (!buf.buf || !buf.width || !buf.height);

if(!finish_on_error)
{
dt_dev_pixelpipe_set_input(pipe, dev, buffer, width, height, iscale);
dt_dev_pixelpipe_set_input(pipe, dev, (float *)buf.buf, width, height, iscale);
dt_print(DT_DEBUG_DEV, "[pixelpipe] Started thumbnail preview recompute at %i×%i px\n", width, height);
}

Expand Down Expand Up @@ -458,7 +460,7 @@ void dt_dev_process_preview_job(dt_develop_t *dev)
dt_iop_nap(200);
}

if(buffer) dt_free_align(buffer);
dt_mipmap_cache_release(darktable.mipmap_cache, &buf);
pipe->running = 0;
dt_print(DT_DEBUG_DEV, "[pixelpipe] exiting preview pipe thread\n");
}
Expand All @@ -480,12 +482,12 @@ void dt_dev_process_image_job(dt_develop_t *dev)

int width, height;
float iscale;
float *buffer = _get_input_copy(dev->image_storage.id, DT_MIPMAP_FULL, &width, &height, &iscale);
dt_mipmap_buffer_t buf = _get_input_copy(dev->image_storage.id, DT_MIPMAP_FULL, &width, &height, &iscale);

gboolean finish_on_error = (buffer == NULL);
gboolean finish_on_error = (!buf.buf || !buf.width || !buf.height);

if(!finish_on_error)
dt_dev_pixelpipe_set_input(pipe, dev, buffer, width, height, 1.0);
dt_dev_pixelpipe_set_input(pipe, dev, (float *)buf.buf, width, height, 1.0);

float scale = 1.f, zoom_x = 1.f, zoom_y = 1.f;
while(!dev->exit && !finish_on_error && (pipe->status != DT_DEV_PIXELPIPE_VALID))
Expand Down Expand Up @@ -587,7 +589,7 @@ void dt_dev_process_image_job(dt_develop_t *dev)
dt_iop_nap(200);
}

if(buffer) dt_free_align(buffer);
dt_mipmap_cache_release(darktable.mipmap_cache, &buf);
pipe->running = 0;
dt_print(DT_DEBUG_DEV, "[pixelpipe] exiting main image pipe thread\n");
}
Expand Down

0 comments on commit a203d53

Please sign in to comment.