![]() |
Ansel 0.0
A darktable fork - bloat + design vision
|
#include <inttypes.h>#include <glib.h>#include <stdlib.h>#include <signal.h>#include <string.h>#include "control/control.h"#include "develop/pixelpipe_cache.h"#include "common/darktable.h"#include "common/debug.h"#include "common/opencl.h"#include "develop/format.h"
Include dependency graph for pixelpipe_cache.c:Data Structures | |
| struct | dt_cache_clmem_t |
| struct | _cache_lru_t |
| struct | _cache_invalidate_t |
Typedefs | |
| typedef struct dt_cache_clmem_t | dt_cache_clmem_t |
| typedef struct _cache_lru_t | _cache_lru_t |
| typedef struct _cache_invalidate_t | _cache_invalidate_t |
Functions | |
| static dt_pixel_cache_entry_t * | _non_threadsafe_cache_get_entry (dt_dev_pixelpipe_cache_t *cache, GHashTable *table, const uint64_t key) |
| static const char * | _cache_debug_module_name (void) |
| static void | _trace_exact_hit (const char *phase, const uint64_t hash, dt_pixel_cache_entry_t *cache_entry, void *data, void *cl_mem_output, const int preferred_devid, const gboolean verbose) |
| const char * | dt_pixelpipe_cache_set_current_module (const char *module) |
| Set the current module name for cache diagnostics (thread-local). | |
| void | _non_thread_safe_cache_ref_count_entry (dt_dev_pixelpipe_cache_t *cache, gboolean lock, dt_pixel_cache_entry_t *cache_entry) |
| static void | _free_cache_entry (dt_pixel_cache_entry_t *cache_entry) |
| static void | _pixelpipe_cache_finalize_entry (dt_pixel_cache_entry_t *cache_entry, void **data, const char *message) |
| static dt_pixel_cache_entry_t * | _pixelpipe_cache_create_entry_locked (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, const size_t size, const char *name, const int id) |
| static dt_pixel_cache_entry_t * | dt_pixel_cache_new_entry (const uint64_t hash, const size_t size, const char *name, const int id, dt_dev_pixelpipe_cache_t *cache, gboolean alloc, GHashTable *table) |
| static void | _cache_entry_clmem_flush_device (dt_pixel_cache_entry_t *entry, const int devid, void *keep) |
| static gboolean | _cache_entry_materialize_host_data_locked (dt_pixel_cache_entry_t *entry, int preferred_devid, gboolean prefer_device_payload) |
| static dt_pixel_cache_entry_t * | _cache_entry_for_host_ptr_locked (dt_dev_pixelpipe_cache_t *cache, void *host_ptr) |
| dt_pixel_cache_entry_t * | dt_dev_pixelpipe_cache_get_entry (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash) |
| Get an internal reference to the cache entry matching hash. If you are going to access this entry more than once, keeping the reference and using it instead of hashes will prevent redundant lookups. | |
| size_t | dt_pixel_cache_get_size (dt_pixel_cache_entry_t *cache_entry) |
| void | dt_pixel_cache_message (dt_pixel_cache_entry_t *cache_entry, const char *message, gboolean verbose) |
| int | _non_thread_safe_cache_remove (dt_dev_pixelpipe_cache_t *cache, const gboolean force, dt_pixel_cache_entry_t *cache_entry, GHashTable *table) |
| int | dt_dev_pixelpipe_cache_remove (dt_dev_pixelpipe_cache_t *cache, const gboolean force, dt_pixel_cache_entry_t *cache_entry) |
| Arbitrarily remove the cache entry matching hash. Entries having a reference count > 0 (inter-thread locked) or being having their read/write lock locked will be ignored. If force is TRUE, we ignore reference count, but not locks. | |
| static gboolean | _cache_entry_materialize_host_data (dt_dev_pixelpipe_cache_t *cache, int preferred_devid, dt_pixel_cache_entry_t *entry) |
| void | dt_dev_pixelpipe_cache_flush_clmem (dt_dev_pixelpipe_cache_t *cache, const int devid, void *keep) |
| Release cached OpenCL buffers for a device (-1 for all). | |
| void | _cache_get_oldest (gpointer key, gpointer value, gpointer user_data) |
| void | _print_cache_lines (gpointer key, gpointer value, gpointer user_data) |
| static int | _non_thread_safe_pixel_pipe_cache_remove_lru (dt_dev_pixelpipe_cache_t *cache) |
| int | dt_dev_pixel_pipe_cache_remove_lru (dt_dev_pixelpipe_cache_t *cache) |
| void * | dt_pixel_cache_clmem_get (dt_pixel_cache_entry_t *entry, void *host_ptr, int devid, int width, int height, int bpp, int flags) |
| void * | dt_pixel_cache_clmem_ref (dt_pixel_cache_entry_t *entry, void *host_ptr, int devid, int width, int height, int bpp, int flags) |
| void | dt_pixel_cache_clmem_unref (dt_pixel_cache_entry_t *entry, void *mem) |
| void | dt_pixel_cache_clmem_put (dt_pixel_cache_entry_t *entry, void *host_ptr, int devid, int width, int height, int bpp, int flags, void *mem) |
| void | dt_pixel_cache_clmem_remove (dt_pixel_cache_entry_t *entry, void *mem) |
| void | dt_pixel_cache_clmem_flush (dt_pixel_cache_entry_t *entry) |
| void * | dt_dev_pixelpipe_cache_get_pinned_image (dt_dev_pixelpipe_cache_t *cache, void *host_ptr, dt_pixel_cache_entry_t *entry_hint, int devid, int width, int height, int bpp, int flags, gboolean *out_reused) |
| Acquire a pinned OpenCL image for a host buffer tracked by the pixelpipe cache. | |
| void | dt_dev_pixelpipe_cache_put_pinned_image (dt_dev_pixelpipe_cache_t *cache, void *host_ptr, dt_pixel_cache_entry_t *entry_hint, void **mem) |
Release or cache a pinned OpenCL image acquired with dt_dev_pixelpipe_cache_get_pinned_image(). | |
| void | dt_dev_pixelpipe_cache_flush_host_pinned_image (dt_dev_pixelpipe_cache_t *cache, void *host_ptr, dt_pixel_cache_entry_t *entry_hint, int devid) |
| Drop cached pinned OpenCL images associated with a given host buffer. | |
| void | dt_dev_pixelpipe_cache_resync_host_pinned_image (dt_dev_pixelpipe_cache_t *cache, void *host_ptr, dt_pixel_cache_entry_t *entry_hint, int devid) |
| Resynchronize cached pinned OpenCL images from an authoritative host buffer. | |
| dt_pixel_cache_entry_t * | dt_dev_pixelpipe_cache_ref_entry_for_host_ptr (dt_dev_pixelpipe_cache_t *cache, void *host_ptr) |
| Resolve and retain the cache entry owning a host pointer. | |
| static void * | _arena_alloc_with_defrag (dt_dev_pixelpipe_cache_t *cache, size_t request_size, size_t *actual_size) |
| static void | _arena_stats_bytes (dt_dev_pixelpipe_cache_t *cache, uint32_t *total_pages, uint32_t *largest_pages, size_t *total_bytes, size_t *largest_bytes) |
| static void | _log_arena_allocation_failure (dt_dev_pixelpipe_cache_t *cache, size_t request_size, const char *entry_name, const char *module, uint64_t hash, gboolean name_is_file) |
| void * | dt_pixel_cache_alloc (dt_dev_pixelpipe_cache_t *cache, dt_pixel_cache_entry_t *cache_entry) |
Actually allocate the memory buffer attached to the cache entry once you create it with dt_dev_pixelpipe_cache_get(). Sizes and everything are already saved in the entry, and the cache will have the needed space reserved. | |
| void * | dt_pixel_cache_entry_get_data (dt_pixel_cache_entry_t *entry) |
| size_t | dt_pixel_cache_entry_get_size (dt_pixel_cache_entry_t *entry) |
| Peek the size (in bytes) reserved for the host buffer of a cache entry. | |
| static int | _free_space_to_alloc (dt_dev_pixelpipe_cache_t *cache, const size_t size, const uint64_t hash, const char *name) |
| void * | dt_pixelpipe_cache_alloc_align_cache_impl (dt_dev_pixelpipe_cache_t *cache, size_t size, int id, const char *name) |
| Allocate aligned memory tracked by the pixelpipe cache. This allows LRU cache entries to be evicted if needed to make room. | |
| void | dt_pixelpipe_cache_free_align_cache (dt_dev_pixelpipe_cache_t *cache, void **mem, const char *message) |
| Free aligned memory allocated with dt_pixelpipe_cache_alloc_align_cache. | |
| dt_dev_pixelpipe_cache_t * | dt_dev_pixelpipe_cache_init (size_t max_memory) |
| void | dt_dev_pixelpipe_cache_cleanup (dt_dev_pixelpipe_cache_t *cache) |
| static dt_pixel_cache_entry_t * | _cache_try_rekey_reuse_locked (dt_dev_pixelpipe_cache_t *cache, const uint64_t new_hash, const size_t size, const dt_pixel_cache_entry_t *reuse_hint) |
| int | dt_dev_pixelpipe_cache_get (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, const size_t size, const char *name, const int id, const gboolean alloc, void **data, dt_pixel_cache_entry_t **entry) |
| Get a cache line from the cache. | |
| dt_dev_pixelpipe_cache_writable_status_t | dt_dev_pixelpipe_cache_get_writable (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, const size_t size, const char *name, const int id, const gboolean alloc, const gboolean allow_rekey_reuse, const dt_pixel_cache_entry_t *reuse_hint, void **data, dt_pixel_cache_entry_t **entry) |
| static void | _cache_clear_lookup_outputs (void **data, dt_pixel_cache_entry_t **entry) |
| static gboolean | _cache_entry_has_host_payload_ptr (const dt_pixel_cache_entry_t *cache_entry) |
| static gboolean | _cache_entry_has_device_payload (dt_pixel_cache_entry_t *cache_entry, const int preferred_devid) |
| static dt_pixel_cache_entry_t * | _cache_lookup_existing (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, void **data) |
| static gboolean | _cache_try_restore_device_payload (dt_pixel_cache_entry_t *cache_entry, const int preferred_devid, void **cl_mem_output) |
| static gboolean | _cache_try_restore_host_payload (dt_dev_pixelpipe_cache_t *cache, void **data, dt_pixel_cache_entry_t *cache_entry, const int preferred_devid) |
| gboolean | dt_dev_pixelpipe_cache_restore_host_payload (dt_dev_pixelpipe_cache_t *cache, dt_pixel_cache_entry_t *cache_entry, const int preferred_devid, void **data) |
| Materialize a host payload for a live cache entry from its cached device payload. | |
| static void | _cache_remove_invalid_exact_hit (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, dt_pixel_cache_entry_t *cache_entry, void **data, dt_pixel_cache_entry_t **entry) |
| gboolean | dt_dev_pixelpipe_cache_peek (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, void **data, dt_pixel_cache_entry_t **entry, const int preferred_devid, void **cl_mem_output) |
| Non-owning lookup of an existing cache line. | |
| gboolean | _for_each_remove (gpointer key, gpointer value, gpointer user_data) |
| void | dt_dev_pixelpipe_cache_flush (dt_dev_pixelpipe_cache_t *cache, const int id) |
| Remove cache lines matching id. Entries locked in read/write or having reference count greater than 0 are not removed. | |
| gboolean | _for_each_remove_old (gpointer key, gpointer value, gpointer user_data) |
| int | dt_dev_pixelpipe_cache_flush_old (dt_dev_pixelpipe_cache_t *cache) |
| Free cache entries older than 3 min, that are not locked and have been used 3 times or less. | |
| void | dt_dev_pixelpipe_cache_ref_count_entry (dt_dev_pixelpipe_cache_t *cache, gboolean lock, dt_pixel_cache_entry_t *cache_entry) |
| Increase/Decrease the reference count on the cache line as to prevent LRU item removal. This function should be called within a read/write lock-protected section to avoid changing an entry while or after it is deleted in parallel. | |
| void | dt_dev_pixelpipe_cache_wrlock_entry (dt_dev_pixelpipe_cache_t *cache, gboolean lock, dt_pixel_cache_entry_t *cache_entry) |
| Lock or release the write lock on the entry. | |
| void | dt_dev_pixelpipe_cache_rdlock_entry (dt_dev_pixelpipe_cache_t *cache, gboolean lock, dt_pixel_cache_entry_t *cache_entry) |
| Lock or release the read lock on the entry. | |
| void | dt_dev_pixelpipe_cache_flag_auto_destroy (dt_dev_pixelpipe_cache_t *cache, dt_pixel_cache_entry_t *cache_entry) |
Flag the cache entry as "auto_destroy". This is useful for short-lived/disposable cache entries, that won't be needed in the future. These will be freed out of the typical LRU, aged-based garbage collection. The thread that tagged this entry as "auto_destroy" is responsible for freeing it as soon as it is done with it, using dt_dev_pixelpipe_cache_auto_destroy_apply(). If not manually freed this way, the entry will be caught using the generic LRU garbage collection. | |
| void | dt_dev_pixelpipe_cache_auto_destroy_apply (dt_dev_pixelpipe_cache_t *cache, dt_pixel_cache_entry_t *cache_entry) |
Free the entry if it has the flag "auto_destroy". See dt_dev_pixelpipe_cache_flag_auto_destroy(). This will not check reference count nor read/write locks, so it has to happen in the thread that created the entry, flagged it and owns it. Ensure your hashes are truly unique and not shared between pipelines to ensure another thread will not free this or that another thread ends up using it. | |
| void * | dt_dev_pixelpipe_cache_get_read_only (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, dt_pixel_cache_entry_t **cache_entry) |
| Find the existing cache entry linked to hash if any, lock it in read mode and increase its ref_count all at once. | |
| void | dt_dev_pixelpipe_cache_close_read_only (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, dt_pixel_cache_entry_t *cache_entry) |
| Decrease the ref_count and release the read lock over cache_entry all at once. | |
| void * | dt_dev_pixelpipe_cache_get_ref_unlocked (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, dt_pixel_cache_entry_t **cache_entry) |
| Find an existing cache entry, synchronize once with a short read lock, then keep only a refcount (no long-lived read lock). | |
| void | dt_dev_pixelpipe_cache_unref_unlocked (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash, dt_pixel_cache_entry_t *cache_entry) |
| Decrease the refcount of an entry previously acquired with the transient realtime getter above. | |
| void | dt_dev_pixelpipe_cache_unref_hash (dt_dev_pixelpipe_cache_t *cache, const uint64_t hash) |
| Find the entry matching hash, and decrease its ref_count if found. | |
| int | dt_dev_pixelpipe_cache_rekey (dt_dev_pixelpipe_cache_t *cache, const uint64_t old_hash, const uint64_t new_hash, dt_pixel_cache_entry_t *entry) |
| Change the hash/key of an existing cache line in place, without freeing, reallocating or invalidating the underlying entry. | |
| void | dt_dev_pixelpipe_cache_print (dt_dev_pixelpipe_cache_t *cache) |
Variables | |
| static __thread const char * | dt_pixelpipe_cache_current_module = NULL |
| static int | garbage_collection = 0 |
| typedef struct _cache_invalidate_t _cache_invalidate_t |
| typedef struct _cache_lru_t _cache_lru_t |
| typedef struct dt_cache_clmem_t dt_cache_clmem_t |
|
inlinestatic |
References _non_thread_safe_pixel_pipe_cache_remove_lru(), dt_dev_pixelpipe_cache_t::arena, dt_cache_arena_alloc(), dt_cache_arena_calc(), dt_cache_arena_stats(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, and dt_dev_pixelpipe_cache_t::lock.
Referenced by dt_pixel_cache_alloc(), and dt_pixelpipe_cache_alloc_align_cache_impl().
|
inlinestatic |
References dt_dev_pixelpipe_cache_t::arena, dt_cache_arena_stats(), and dt_cache_arena_t::page_size.
Referenced by _log_arena_allocation_failure().
|
inlinestatic |
Referenced by _cache_remove_invalid_exact_hit(), and dt_dev_pixelpipe_cache_peek().
|
inlinestatic |
References dt_pixelpipe_cache_current_module.
Referenced by _cache_try_rekey_reuse_locked(), _trace_exact_hit(), dt_dev_pixelpipe_cache_rekey(), and dt_pixel_cache_message().
|
static |
References c, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_pixel_cache_entry_t::data, dt_atomic_get_int(), dt_free, dt_opencl_release_mem_object(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), and dt_pixel_cache_entry_t::refcount.
Referenced by dt_dev_pixelpipe_cache_flush_clmem().
|
static |
|
static |
References c, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), FALSE, TRUE, and void().
Referenced by dt_dev_pixelpipe_cache_peek().
|
inlinestatic |
References dt_pixel_cache_entry_get_data().
Referenced by _cache_try_restore_host_payload(), dt_dev_pixelpipe_cache_peek(), and dt_dev_pixelpipe_cache_restore_host_payload().
|
static |
|
static |
References dt_pixel_cache_entry_t::data, and void().
Referenced by _cache_entry_materialize_host_data().
| void _cache_get_oldest | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) |
References dt_pixel_cache_entry_t::age, _cache_lru_t::cache_entry, dt_atomic_get_int(), dt_pixel_cache_message(), dt_pthread_rwlock_trywrlock, dt_pthread_rwlock_unlock, _cache_lru_t::hash, dt_pixel_cache_entry_t::hash, dt_pixel_cache_entry_t::lock, _cache_lru_t::max_age, dt_pixel_cache_entry_t::refcount, TRUE, and value.
Referenced by _non_thread_safe_pixel_pipe_cache_remove_lru().
|
static |
References _non_threadsafe_cache_get_entry(), _pixelpipe_cache_finalize_entry(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, dt_dev_pixelpipe_cache_t::hits, dt_pixel_cache_entry_t::hits, dt_dev_pixelpipe_cache_t::lock, and dt_dev_pixelpipe_cache_t::queries.
Referenced by dt_dev_pixelpipe_cache_peek().
|
static |
References _cache_clear_lookup_outputs(), _trace_exact_hit(), DT_DEBUG_CACHE, dt_dev_pixelpipe_cache_remove(), dt_print(), FALSE, and TRUE.
Referenced by dt_dev_pixelpipe_cache_peek().
|
static |
References _cache_debug_module_name(), _non_thread_safe_cache_ref_count_entry(), _non_threadsafe_cache_get_entry(), dt_pixel_cache_entry_t::auto_destroy, c, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_pixel_cache_entry_t::data, dt_atomic_get_int(), DT_DEBUG_CACHE, dt_dev_pixelpipe_cache_ref_count_entry(), dt_dev_pixelpipe_cache_wrlock_entry(), dt_pixel_cache_clmem_flush(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_print(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, FALSE, dt_pixel_cache_entry_t::hash, dt_pixel_cache_entry_t::refcount, dt_pixel_cache_entry_t::serial, size, dt_pixel_cache_entry_t::size, and TRUE.
Referenced by dt_dev_pixelpipe_cache_get_writable().
|
static |
References FALSE.
Referenced by dt_dev_pixelpipe_cache_peek().
|
static |
| gboolean _for_each_remove | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) |
References dt_pthread_rwlock_trywrlock, dt_pthread_rwlock_unlock, dt_pixel_cache_entry_t::id, dt_pixel_cache_entry_t::lock, and value.
Referenced by dt_dev_pixelpipe_cache_flush().
| gboolean _for_each_remove_old | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) |
|
static |
References dt_dev_pixelpipe_cache_t::arena, c, dt_pixel_cache_entry_t::cache, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_dev_pixelpipe_cache_t::current_memory, dt_pixel_cache_entry_t::data, dt_cache_arena_free(), dt_free, dt_opencl_finish(), dt_opencl_get_mem_flags(), dt_pixel_cache_clmem_flush(), dt_pixel_cache_message(), dt_pthread_mutex_destroy(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_pthread_rwlock_destroy, FALSE, flags, dt_pixel_cache_entry_t::lock, dt_pixel_cache_entry_t::name, and dt_pixel_cache_entry_t::size.
Referenced by dt_dev_pixelpipe_cache_init().
|
static |
References _non_thread_safe_pixel_pipe_cache_remove_lru(), dt_dev_pixelpipe_cache_t::current_memory, dt_control_log(), dt_dev_pixelpipe_cache_t::entries, error(), dt_dev_pixelpipe_cache_t::max_memory, name, and size.
Referenced by dt_pixel_cache_new_entry(), and dt_pixelpipe_cache_alloc_align_cache_impl().
|
inlinestatic |
References _arena_stats_bytes(), dt_dev_pixelpipe_cache_t::current_memory, dt_control_log(), dt_dev_pixelpipe_cache_t::max_memory, and void().
Referenced by dt_pixel_cache_alloc(), and dt_pixelpipe_cache_alloc_align_cache_impl().
| void _non_thread_safe_cache_ref_count_entry | ( | dt_dev_pixelpipe_cache_t * | cache, |
| gboolean | lock, | ||
| dt_pixel_cache_entry_t * | cache_entry | ||
| ) |
References dt_atomic_add_int(), dt_atomic_sub_int(), dt_pixel_cache_message(), dt_pixel_cache_entry_t::refcount, and TRUE.
Referenced by _cache_try_rekey_reuse_locked(), _pixelpipe_cache_create_entry_locked(), dt_dev_pixelpipe_cache_get(), dt_dev_pixelpipe_cache_ref_count_entry(), dt_dev_pixelpipe_cache_ref_entry_for_host_ptr(), dt_pixelpipe_cache_alloc_align_cache_impl(), and dt_pixelpipe_cache_free_align_cache().
| int _non_thread_safe_cache_remove | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const gboolean | force, | ||
| dt_pixel_cache_entry_t * | cache_entry, | ||
| GHashTable * | table | ||
| ) |
References dt_atomic_get_int(), DT_DEBUG_CACHE, dt_pixel_cache_message(), dt_print(), dt_pthread_rwlock_trywrlock, dt_pthread_rwlock_unlock, dt_pixel_cache_entry_t::hash, dt_pixel_cache_entry_t::lock, dt_pixel_cache_entry_t::refcount, and TRUE.
Referenced by _non_thread_safe_pixel_pipe_cache_remove_lru(), dt_dev_pixelpipe_cache_get(), dt_dev_pixelpipe_cache_get_writable(), and dt_dev_pixelpipe_cache_remove().
|
static |
References _cache_get_oldest(), _non_thread_safe_cache_remove(), _print_cache_lines(), _cache_lru_t::cache_entry, dt_dev_pixelpipe_cache_t::current_memory, DT_DEBUG_CACHE, dt_free, dt_print(), dt_dev_pixelpipe_cache_t::entries, error(), FALSE, _cache_lru_t::hash, and _cache_lru_t::max_age.
Referenced by _arena_alloc_with_defrag(), _free_space_to_alloc(), and dt_dev_pixel_pipe_cache_remove_lru().
|
static |
References key.
Referenced by _cache_entry_for_host_ptr_locked(), _cache_lookup_existing(), _cache_try_rekey_reuse_locked(), dt_dev_pixelpipe_cache_get(), dt_dev_pixelpipe_cache_get_entry(), dt_dev_pixelpipe_cache_get_writable(), dt_dev_pixelpipe_cache_rekey(), dt_dev_pixelpipe_cache_unref_hash(), and dt_pixelpipe_cache_free_align_cache().
|
static |
|
static |
References dt_pixel_cache_entry_t::age, dt_pixel_cache_entry_t::data, DT_CACHELINE_BYTES, dt_pixel_cache_message(), and FALSE.
Referenced by _cache_lookup_existing(), dt_dev_pixelpipe_cache_get(), and dt_dev_pixelpipe_cache_get_writable().
| void _print_cache_lines | ( | gpointer | key, |
| gpointer | value, | ||
| gpointer | user_data | ||
| ) |
References dt_pixel_cache_message(), FALSE, and value.
Referenced by _non_thread_safe_pixel_pipe_cache_remove_lru().
|
static |
References _cache_debug_module_name(), dt_pixel_cache_entry_t::auto_destroy, darktable, dt_atomic_get_int(), DT_DEBUG_CACHE, DT_DEBUG_VERBOSE, DT_PIXELPIPE_CACHE_HASH_INVALID, dt_print(), dt_pixel_cache_entry_t::hash, dt_pixel_cache_entry_t::name, dt_pixel_cache_entry_t::refcount, dt_pixel_cache_entry_t::serial, and darktable_t::unmuted.
Referenced by _cache_remove_invalid_exact_hit(), and dt_dev_pixelpipe_cache_peek().
| int dt_dev_pixel_pipe_cache_remove_lru | ( | dt_dev_pixelpipe_cache_t * | cache | ) |
remove the least used cache entry
References _non_thread_safe_pixel_pipe_cache_remove_lru(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), error(), and dt_dev_pixelpipe_cache_t::lock.
Referenced by dt_tiling_piece_fits_host_memory().
| void dt_dev_pixelpipe_cache_auto_destroy_apply | ( | dt_dev_pixelpipe_cache_t * | cache, |
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Free the entry if it has the flag "auto_destroy". See dt_dev_pixelpipe_cache_flag_auto_destroy(). This will not check reference count nor read/write locks, so it has to happen in the thread that created the entry, flagged it and owns it. Ensure your hashes are truly unique and not shared between pipelines to ensure another thread will not free this or that another thread ends up using it.
| cache |
References dt_pixel_cache_entry_t::auto_destroy, dt_pixel_cache_message(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, FALSE, dt_pixel_cache_entry_t::hash, dt_dev_pixelpipe_cache_t::lock, and TRUE.
Referenced by _abort_module_shutdown_cleanup(), and dt_dev_pixelpipe_process_rec().
| void dt_dev_pixelpipe_cache_cleanup | ( | dt_dev_pixelpipe_cache_t * | cache | ) |
| void dt_dev_pixelpipe_cache_close_read_only | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash, | ||
| struct dt_pixel_cache_entry_t * | cache_entry | ||
| ) |
Decrease the ref_count and release the read lock over cache_entry all at once.
| cache | |
| hash | |
| cache_entry |
References dt_dev_pixelpipe_cache_rdlock_entry(), dt_dev_pixelpipe_cache_ref_count_entry(), and FALSE.
Referenced by _lib_navigation_draw_callback(), _pixelpipe_pick_from_image(), _process_histogram(), _process_vectorscope(), and _process_waveform().
| void dt_dev_pixelpipe_cache_flag_auto_destroy | ( | dt_dev_pixelpipe_cache_t * | cache, |
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Flag the cache entry as "auto_destroy". This is useful for short-lived/disposable cache entries, that won't be needed in the future. These will be freed out of the typical LRU, aged-based garbage collection. The thread that tagged this entry as "auto_destroy" is responsible for freeing it as soon as it is done with it, using dt_dev_pixelpipe_cache_auto_destroy_apply(). If not manually freed this way, the entry will be caught using the generic LRU garbage collection.
| cache |
References dt_pixel_cache_entry_t::auto_destroy, dt_pixel_cache_message(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::lock, and TRUE.
Referenced by _abort_module_shutdown_cleanup(), _init_base_buffer(), and dt_dev_pixelpipe_process_rec().
| void dt_dev_pixelpipe_cache_flush | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const int | id | ||
| ) |
Remove cache lines matching id. Entries locked in read/write or having reference count greater than 0 are not removed.
| cache | |
| id | ID of the pipeline owning the cache line, or -1 to remove all lines. |
References _for_each_remove(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, and dt_dev_pixelpipe_cache_t::lock.
Referenced by dt_dev_darkroom_pipeline(), and dt_dev_pixelpipe_reset_all().
| void dt_dev_pixelpipe_cache_flush_clmem | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const int | devid, | ||
| void * | keep | ||
| ) |
Release cached OpenCL buffers for a device (-1 for all).
This is intentionally a lightweight VRAM-pressure/retry helper: it drops cached cl_mem objects without taking per-entry write locks. Realtime paths rely on it to free scratch OpenCL buffers without stalling in-flight renders.
| keep | OpenCL buffer to keep. Typically, you want to keep the input if you are trying to make room for the output. |
References _cache_entry_clmem_flush_device(), dt_opencl_events_wait_for(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, key, dt_dev_pixelpipe_cache_t::lock, and value.
Referenced by dt_dev_pixelpipe_cleanup(), and leave().
| void dt_dev_pixelpipe_cache_flush_host_pinned_image | ( | dt_dev_pixelpipe_cache_t * | cache, |
| void * | host_ptr, | ||
| struct dt_pixel_cache_entry_t * | entry_hint, | ||
| int | devid | ||
| ) |
Drop cached pinned OpenCL images associated with a given host buffer.
This is meant for host buffers that remain alive and continue to be mutated by the CPU (for example, privately owned working patches). Reusing a stale CL_MEM_USE_HOST_PTR image for such buffers can hide later host-side edits on some drivers. Flushing the cached pinned images forces the next use to rebind the host storage.
| cache | Pixelpipe cache. |
| host_ptr | Host-backed image data. |
| entry_hint | Optional owning cache entry for regular cache lines, or NULL. |
| devid | Device id to flush, or -1 for all cached devices for that host buffer. |
References void().
Referenced by _rekey_shared_base_patch(), dt_dev_pixelpipe_gpu_flush_host_pinned_images(), dt_drawlayer_cache_flush_process_patch_to_base(), dt_drawlayer_cache_populate_process_patch_from_base(), dt_drawlayer_process_state_publish_locked(), and dt_drawlayer_worker_replay_finished_stroke_to_base_patch().
| int dt_dev_pixelpipe_cache_flush_old | ( | dt_dev_pixelpipe_cache_t * | cache | ) |
Free cache entries older than 3 min, that are not locked and have been used 3 times or less.
| cache |
References _for_each_remove_old(), dt_pthread_mutex_trylock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, and dt_dev_pixelpipe_cache_t::lock.
Referenced by dt_dev_pixelpipe_cache_init().
| int dt_dev_pixelpipe_cache_get | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash, | ||
| const size_t | size, | ||
| const char * | name, | ||
| const int | id, | ||
| const gboolean | alloc, | ||
| void ** | data, | ||
| struct dt_pixel_cache_entry_t ** | entry | ||
| ) |
Get a cache line from the cache.
WARNING: This internally increases the reference count, so you have to manually decrease it using dt_dev_pixelpipe_ref_count_entry() once the cache line content has been consumed or it will never be freed.
WARNING: if the cache line was newly allocated, a write lock is put on straight away. You will have to release it from the same calling thread next, to avoid dead locks.
| cache | |
| hash | State checksum of the cache line. |
| size | Buffer size in bytes. |
| name | Name of the cache line (for debugging). |
| id | ID of the pipeline owning the cache line. |
| data | Pointer to the buffer pointer (returned). |
| alloc | Whether or not we should actually alloc the buffer, or simply reserve it. If FALSE use dt_pixel_cache_alloc() when you actually need the buffer. |
| cache_entry | a reference to the cache entry, to be reused later. Can be NULL. The caller doesn't own the data and shouldn't free it. |
References _non_thread_safe_cache_ref_count_entry(), _non_thread_safe_cache_remove(), _non_threadsafe_cache_get_entry(), _pixelpipe_cache_create_entry_locked(), _pixelpipe_cache_finalize_entry(), dt_pixel_cache_entry_t::auto_destroy, dt_pixel_cache_entry_t::data, DT_DEBUG_CACHE, dt_dev_pixelpipe_cache_wrlock_entry(), dt_pixel_cache_alloc(), dt_pixel_cache_message(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_print(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, FALSE, dt_dev_pixelpipe_cache_t::hits, dt_pixel_cache_entry_t::hits, dt_dev_pixelpipe_cache_t::lock, name, dt_dev_pixelpipe_cache_t::queries, size, and TRUE.
Referenced by _init_base_buffer(), dt_drawlayer_cache_patch_alloc_shared(), and toneeq_process().
| dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_get_entry | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash | ||
| ) |
Get an internal reference to the cache entry matching hash. If you are going to access this entry more than once, keeping the reference and using it instead of hashes will prevent redundant lookups.
| cache | |
| hash |
References _non_threadsafe_cache_get_entry(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, and dt_dev_pixelpipe_cache_t::lock.
Referenced by _do_get_structure_auto(), _do_get_structure_lines(), _do_get_structure_quad(), _refresh_global_histogram_backbuf(), dt_dev_pixelpipe_cleanup(), and dt_dev_pixelpipe_process_rec().
| void * dt_dev_pixelpipe_cache_get_pinned_image | ( | dt_dev_pixelpipe_cache_t * | cache, |
| void * | host_ptr, | ||
| struct dt_pixel_cache_entry_t * | entry_hint, | ||
| int | devid, | ||
| int | width, | ||
| int | height, | ||
| int | bpp, | ||
| int | flags, | ||
| gboolean * | out_reused | ||
| ) |
Acquire a pinned OpenCL image for a host buffer tracked by the pixelpipe cache.
This is the public helper for modules that manage their own host buffers but still want the pixelpipe cache to own the reusable pinned cl_mem images. The helper accepts an optional cache-entry hint for normal cache lines. If that hint is NULL, it will try to resolve the host pointer against the cache's privately-owned external allocations.
On reuse, the helper synchronizes host memory to the OpenCL image before returning.
| cache | Pixelpipe cache. | |
| host_ptr | Host-backed image data. | |
| entry_hint | Optional owning cache entry for regular cache lines, or NULL. | |
| devid | OpenCL device id. | |
| width | Image width. | |
| height | Image height. | |
| bpp | Bytes per pixel. | |
| flags | OpenCL allocation flags (must include CL_MEM_USE_HOST_PTR). | |
| [out] | out_reused | Optional flag set TRUE when an existing pinned image was reused. |
cl_mem) or NULL on failure. | void * dt_dev_pixelpipe_cache_get_read_only | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash, | ||
| struct dt_pixel_cache_entry_t ** | cache_entry | ||
| ) |
Find the existing cache entry linked to hash if any, lock it in read mode and increase its ref_count all at once.
| cache | |
| hash | |
| cache_entry | Found cache entry if any, this is written by the function |
| pipe | Pixelpipe to recompute if we fail to find the cacheline associated to the hash |
References DT_CACHELINE_BYTES, dt_dev_pixelpipe_cache_peek(), dt_dev_pixelpipe_cache_ref_count_entry(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_pthread_rwlock_tryrdlock, and TRUE.
Referenced by _lib_navigation_draw_callback(), _pixelpipe_pick_from_image(), _process_histogram(), _process_vectorscope(), and _process_waveform().
| void * dt_dev_pixelpipe_cache_get_ref_unlocked | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash, | ||
| struct dt_pixel_cache_entry_t ** | cache_entry | ||
| ) |
Find an existing cache entry, synchronize once with a short read lock, then keep only a refcount (no long-lived read lock).
Intended for best-effort realtime display paths where pointer stability is preferred over lock contention:
tryrdlock + immediate unlock as a synchronization point,Consumers must tolerate concurrent writes after acquisition.
| cache | |
| hash | |
| cache_entry | Found cache entry if any, written by the function. |
References DT_CACHELINE_BYTES, dt_dev_pixelpipe_cache_peek(), dt_dev_pixelpipe_cache_ref_count_entry(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_pthread_rwlock_tryrdlock, dt_pthread_rwlock_unlock, and TRUE.
Referenced by _lock_pipe_surface().
| dt_dev_pixelpipe_cache_writable_status_t dt_dev_pixelpipe_cache_get_writable | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash, | ||
| const size_t | size, | ||
| const char * | name, | ||
| const int | id, | ||
| const gboolean | alloc, | ||
| const gboolean | allow_rekey_reuse, | ||
| const dt_pixel_cache_entry_t * | reuse_hint, | ||
| void ** | data, | ||
| dt_pixel_cache_entry_t ** | entry | ||
| ) |
References _cache_try_rekey_reuse_locked(), _non_thread_safe_cache_remove(), _non_threadsafe_cache_get_entry(), _pixelpipe_cache_create_entry_locked(), _pixelpipe_cache_finalize_entry(), dt_pixel_cache_entry_t::auto_destroy, dt_pixel_cache_entry_t::data, DT_DEV_PIXELPIPE_CACHE_WRITABLE_CREATED, DT_DEV_PIXELPIPE_CACHE_WRITABLE_ERROR, DT_DEV_PIXELPIPE_CACHE_WRITABLE_EXACT_HIT, DT_DEV_PIXELPIPE_CACHE_WRITABLE_REKEYED, dt_pixel_cache_alloc(), dt_pixel_cache_message(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, FALSE, dt_dev_pixelpipe_cache_t::lock, name, dt_dev_pixelpipe_cache_t::queries, and size.
Referenced by dt_dev_pixelpipe_process_rec().
| dt_dev_pixelpipe_cache_t * dt_dev_pixelpipe_cache_init | ( | size_t | max_memory | ) |
constructs a new cache with given cache line count (entries) and float buffer entry size in bytes.
| [out] | returns | 0 if fail to allocate mem cache. |
References _free_cache_entry(), dt_dev_pixelpipe_cache_t::arena, dt_dev_pixelpipe_cache_t::current_memory, dt_cache_arena_init(), dt_dev_pixelpipe_cache_flush_old(), dt_free, dt_free_gpointer(), dt_pthread_mutex_destroy(), dt_pthread_mutex_init(), dt_dev_pixelpipe_cache_t::entries, dt_dev_pixelpipe_cache_t::external_entries, garbage_collection, dt_dev_pixelpipe_cache_t::hits, dt_dev_pixelpipe_cache_t::lock, dt_dev_pixelpipe_cache_t::max_memory, dt_dev_pixelpipe_cache_t::next_serial, and dt_dev_pixelpipe_cache_t::queries.
Referenced by dt_init().
| gboolean dt_dev_pixelpipe_cache_peek | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash, | ||
| void ** | data, | ||
| struct dt_pixel_cache_entry_t ** | entry, | ||
| const int | preferred_devid, | ||
| void ** | cl_mem_output | ||
| ) |
Non-owning lookup of an existing cache line.
This does not create a new cache line and does not change reference counts or entry locks. Callers that need lifetime guarantees must retain the entry explicitly with dt_dev_pixelpipe_cache_ref_count_entry() and/or dt_dev_pixelpipe_cache_rdlock_entry().
If cl_mem_output != NULL, the lookup becomes authoritative for exact-hit consumers:
cl_mem_output when requested,References _cache_clear_lookup_outputs(), _cache_entry_has_device_payload(), _cache_entry_has_host_payload_ptr(), _cache_lookup_existing(), _cache_remove_invalid_exact_hit(), _cache_try_restore_device_payload(), _cache_try_restore_host_payload(), _trace_exact_hit(), dt_pixel_cache_entry_t::auto_destroy, dt_pixel_cache_entry_get_data(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_pthread_rwlock_tryrdlock, dt_pthread_rwlock_unlock, FALSE, dt_pixel_cache_entry_t::lock, and TRUE.
Referenced by _lock_pipe_surface(), _sample_picker_from_cache(), _sync_private_buffer_from_preview_cache(), dt_dev_pixelpipe_cache_get_read_only(), dt_dev_pixelpipe_cache_get_ref_unlocked(), dt_dev_pixelpipe_process(), dt_dev_pixelpipe_process_rec(), dt_dev_refresh_module_histogram(), dt_imageio_export_with_flags(), and gui_focus().
| void dt_dev_pixelpipe_cache_print | ( | dt_dev_pixelpipe_cache_t * | cache | ) |
print out cache lines/hashes (debug).
References dt_dev_pixelpipe_cache_t::current_memory, darktable, DT_DEBUG_CACHE, dt_print(), dt_dev_pixelpipe_cache_t::entries, dt_dev_pixelpipe_cache_t::hits, dt_dev_pixelpipe_cache_t::max_memory, dt_dev_pixelpipe_cache_t::queries, and darktable_t::unmuted.
Referenced by dt_dev_pixelpipe_process().
| void dt_dev_pixelpipe_cache_put_pinned_image | ( | dt_dev_pixelpipe_cache_t * | cache, |
| void * | host_ptr, | ||
| struct dt_pixel_cache_entry_t * | entry_hint, | ||
| void ** | mem | ||
| ) |
Release or cache a pinned OpenCL image acquired with dt_dev_pixelpipe_cache_get_pinned_image().
If the image is still a host-backed pinned allocation and an owning cache entry can be resolved, it is returned to that cache entry for reuse. Otherwise it is released.
| cache | Pixelpipe cache. | |
| host_ptr | Host-backed image data. | |
| entry_hint | Optional owning cache entry for regular cache lines, or NULL. | |
| [in,out] | mem | Pointer to the cl_mem handle (cleared on return). |
References void().
| void dt_dev_pixelpipe_cache_rdlock_entry | ( | dt_dev_pixelpipe_cache_t * | cache, |
| gboolean | lock, | ||
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Lock or release the read lock on the entry.
| cache | |
| lock | TRUE to lock, FALSE to release |
| entry | The cache entry object to lock. |
References dt_pixel_cache_message(), dt_pthread_rwlock_rdlock, dt_pthread_rwlock_unlock, dt_pixel_cache_entry_t::lock, and TRUE.
Referenced by _build_preview_fallback_surface(), _render_main_locked_surface(), _sample_picker_from_cache(), dt_dev_pixelpipe_cache_close_read_only(), dt_dev_pixelpipe_process_rec(), dt_dev_refresh_module_histogram(), dt_drawlayer_cache_patch_rdlock(), dt_drawlayer_cache_patch_rdunlock(), dt_imageio_export_with_flags(), gui_post_expose(), mouse_moved(), pixelpipe_process_on_CPU(), scrolled(), and update_histogram().
| void dt_dev_pixelpipe_cache_ref_count_entry | ( | dt_dev_pixelpipe_cache_t * | cache, |
| gboolean | lock, | ||
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Increase/Decrease the reference count on the cache line as to prevent LRU item removal. This function should be called within a read/write lock-protected section to avoid changing an entry while or after it is deleted in parallel.
WARNING: cache entries whose reference count is greater than 0 will never be deleted from cache.
| cache | |
| lock | TRUE to lock, FALSE to unlock |
References _non_thread_safe_cache_ref_count_entry(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), and dt_dev_pixelpipe_cache_t::lock.
Referenced by _abort_module_shutdown_cleanup(), _cache_try_rekey_reuse_locked(), _refresh_global_histogram_backbuf(), _retain_base_patch_loaded_ref(), _retain_base_patch_stroke_ref(), _sample_picker_from_cache(), _sync_private_buffer_from_preview_cache(), _update_backbuf_cache_reference(), dt_dev_pixelpipe_cache_close_read_only(), dt_dev_pixelpipe_cache_get_read_only(), dt_dev_pixelpipe_cache_get_ref_unlocked(), dt_dev_pixelpipe_cache_unref_hash(), dt_dev_pixelpipe_cache_unref_unlocked(), dt_dev_pixelpipe_process_rec(), dt_dev_refresh_module_histogram(), dt_drawlayer_cache_patch_alloc_shared(), dt_drawlayer_cache_patch_clear(), dt_drawlayer_release_all_base_patch_extra_refs(), dt_imageio_export_with_flags(), gui_cleanup(), gui_focus(), gui_post_expose(), invalidate_luminance_cache(), mouse_moved(), scrolled(), toneeq_process(), and update_histogram().
| dt_pixel_cache_entry_t * dt_dev_pixelpipe_cache_ref_entry_for_host_ptr | ( | dt_dev_pixelpipe_cache_t * | cache, |
| void * | host_ptr | ||
| ) |
Resolve and retain the cache entry owning a host pointer.
This helper searches both regular and external pixelpipe cache tables for the entry whose host buffer pointer exactly matches host_ptr.
On success it increments the entry refcount before returning, so callers can safely use the entry across asynchronous OpenCL operations. Release it with: dt_dev_pixelpipe_cache_ref_count_entry(cache, FALSE, entry).
| cache | Pixelpipe cache. |
| host_ptr | Host buffer pointer to resolve. |
References _cache_entry_for_host_ptr_locked(), _non_thread_safe_cache_ref_count_entry(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::lock, and TRUE.
Referenced by _ensure_external_patch_buffer(), and dt_drawlayer_cache_ensure_process_patch_buffer().
| int dt_dev_pixelpipe_cache_rekey | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | old_hash, | ||
| const uint64_t | new_hash, | ||
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Change the hash/key of an existing cache line in place, without freeing, reallocating or invalidating the underlying entry.
This is useful when a cache line remains the authoritative buffer but the caller needs its identity to follow a new logical snapshot (for example a new module-parameter hash). The entry contents, locks, refcount and storage are preserved; only the hash-table key and entry->hash are updated.
The operation fails if:
new_hash.| cache | |
| old_hash | Current key of the entry. |
| new_hash | Desired new key. |
| entry | Optional direct entry reference. May be NULL. |
References _cache_debug_module_name(), _non_threadsafe_cache_get_entry(), dt_pixel_cache_entry_t::auto_destroy, c, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_pixel_cache_entry_t::data, dt_atomic_get_int(), DT_DEBUG_CACHE, dt_pixel_cache_clmem_flush(), dt_print(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, dt_pixel_cache_entry_t::hash, dt_dev_pixelpipe_cache_t::lock, dt_pixel_cache_entry_t::refcount, and dt_pixel_cache_entry_t::serial.
Referenced by _rekey_shared_base_patch().
| int dt_dev_pixelpipe_cache_remove | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const gboolean | force, | ||
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Arbitrarily remove the cache entry matching hash. Entries having a reference count > 0 (inter-thread locked) or being having their read/write lock locked will be ignored. If force is TRUE, we ignore reference count, but not locks.
| cache | |
| force |
References _non_thread_safe_cache_remove(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, error(), and dt_dev_pixelpipe_cache_t::lock.
Referenced by _abort_module_shutdown_cleanup(), _cache_remove_invalid_exact_hit(), _do_get_structure_auto(), _do_get_structure_lines(), _do_get_structure_quad(), dt_dev_pixelpipe_cleanup(), dt_dev_pixelpipe_process_rec(), and toneeq_process().
| gboolean dt_dev_pixelpipe_cache_restore_host_payload | ( | dt_dev_pixelpipe_cache_t * | cache, |
| struct dt_pixel_cache_entry_t * | entry, | ||
| int | preferred_devid, | ||
| void ** | data | ||
| ) |
Materialize a host payload for a live cache entry from its cached device payload.
Recursive pixelpipe stages reopen transient upstream cache entries directly, before those entries become valid exact-hits. When such an entry only carries a GPU payload, the caller may still need a host pointer for CPU fallback or for a non-OpenCL module. This helper keeps the recovery local to the cache layer:
entry when needed,data.The function leaves the cache entry owned by the caller. It does not change refcounts.
| cache | Pixelpipe cache. | |
| entry | Live cache entry to restore. | |
| preferred_devid | Preferred OpenCL device id, or -1 for any. | |
| [out] | data | Restored host pointer, or NULL on failure. |
References _cache_entry_has_host_payload_ptr(), _cache_try_restore_host_payload(), dt_pixel_cache_entry_get_data(), FALSE, and TRUE.
| void dt_dev_pixelpipe_cache_resync_host_pinned_image | ( | dt_dev_pixelpipe_cache_t * | cache, |
| void * | host_ptr, | ||
| struct dt_pixel_cache_entry_t * | entry_hint, | ||
| int | devid | ||
| ) |
Resynchronize cached pinned OpenCL images from an authoritative host buffer.
This is meant for host-backed cachelines that stay valid but are rewritten in place by the CPU. Unlike dt_dev_pixelpipe_cache_flush_host_pinned_image(), this preserves reusable pinned CL_MEM_USE_HOST_PTR images when possible by pushing current host contents back to the cached OpenCL image objects. Any cached image that cannot be synchronized is dropped individually.
| cache | Pixelpipe cache. |
| host_ptr | Host-backed image data. |
| entry_hint | Optional owning cache entry for regular cache lines, or NULL. |
| devid | Device id to resynchronize, or -1 for all cached devices for that host buffer. |
References void().
| void dt_dev_pixelpipe_cache_unref_hash | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash | ||
| ) |
Find the entry matching hash, and decrease its ref_count if found.
| cache | |
| hash |
References _non_threadsafe_cache_get_entry(), dt_dev_pixelpipe_cache_ref_count_entry(), DT_PIXELPIPE_CACHE_HASH_INVALID, dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_dev_pixelpipe_cache_t::entries, FALSE, dt_dev_pixelpipe_cache_t::lock, and dt_dev_pixelpipe_cache_t::queries.
Referenced by _clear_histogram_backbuf(), _init_base_buffer(), _refresh_global_histogram_backbuf(), _update_backbuf_cache_reference(), dt_dev_pixelpipe_process(), and leave().
| void dt_dev_pixelpipe_cache_unref_unlocked | ( | dt_dev_pixelpipe_cache_t * | cache, |
| const uint64_t | hash, | ||
| dt_pixel_cache_entry_t * | cache_entry | ||
| ) |
Decrease the refcount of an entry previously acquired with the transient realtime getter above.
References dt_dev_pixelpipe_cache_ref_count_entry(), and FALSE.
Referenced by _lock_pipe_surface(), and _release_locked_surface().
| void dt_dev_pixelpipe_cache_wrlock_entry | ( | dt_dev_pixelpipe_cache_t * | cache, |
| gboolean | lock, | ||
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Lock or release the write lock on the entry.
| cache | |
| lock | TRUE to lock, FALSE to release |
References dt_pixel_cache_message(), dt_pthread_rwlock_unlock, dt_pthread_rwlock_wrlock, dt_pixel_cache_entry_t::lock, and TRUE.
Referenced by _cache_entry_materialize_host_data(), _cache_try_rekey_reuse_locked(), _init_base_buffer(), _pixelpipe_cache_create_entry_locked(), dt_dev_pixelpipe_cache_get(), dt_dev_pixelpipe_process_rec(), dt_drawlayer_cache_patch_alloc_shared(), dt_drawlayer_cache_patch_wrlock(), dt_drawlayer_cache_patch_wrunlock(), and toneeq_process().
| void * dt_pixel_cache_alloc | ( | dt_dev_pixelpipe_cache_t * | cache, |
| struct dt_pixel_cache_entry_t * | entry | ||
| ) |
Actually allocate the memory buffer attached to the cache entry once you create it with dt_dev_pixelpipe_cache_get(). Sizes and everything are already saved in the entry, and the cache will have the needed space reserved.
| cache | |
| entry | the cache entry |
References _arena_alloc_with_defrag(), _log_arena_allocation_failure(), dt_pixel_cache_entry_t::data, FALSE, dt_pixel_cache_entry_t::hash, dt_pixel_cache_entry_t::name, and dt_pixel_cache_entry_t::size.
Referenced by _cache_entry_materialize_host_data(), dt_dev_pixelpipe_cache_get(), dt_dev_pixelpipe_cache_get_writable(), dt_pixel_cache_new_entry(), and pixelpipe_process_on_CPU().
| void dt_pixel_cache_clmem_flush | ( | dt_pixel_cache_entry_t * | entry | ) |
References c, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_free, dt_opencl_release_mem_object(), dt_pthread_mutex_lock(), and dt_pthread_mutex_unlock().
Referenced by _cache_try_rekey_reuse_locked(), _free_cache_entry(), _init_base_buffer(), dt_dev_pixelpipe_cache_rekey(), and dt_dev_pixelpipe_process_rec().
| void * dt_pixel_cache_clmem_get | ( | struct dt_pixel_cache_entry_t * | entry, |
| void * | host_ptr, | ||
| int | devid, | ||
| int | width, | ||
| int | height, | ||
| int | bpp, | ||
| int | flags | ||
| ) |
OpenCL pinned buffer reuse tied to cache entries.
References bpp, c, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_free, dt_opencl_release_mem_object(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), flags, height, and width.
| void dt_pixel_cache_clmem_put | ( | dt_pixel_cache_entry_t * | entry, |
| void * | host_ptr, | ||
| int | devid, | ||
| int | width, | ||
| int | height, | ||
| int | bpp, | ||
| int | flags, | ||
| void * | mem | ||
| ) |
| void * dt_pixel_cache_clmem_ref | ( | dt_pixel_cache_entry_t * | entry, |
| void * | host_ptr, | ||
| int | devid, | ||
| int | width, | ||
| int | height, | ||
| int | bpp, | ||
| int | flags | ||
| ) |
| void dt_pixel_cache_clmem_remove | ( | dt_pixel_cache_entry_t * | entry, |
| void * | mem | ||
| ) |
| void dt_pixel_cache_clmem_unref | ( | dt_pixel_cache_entry_t * | entry, |
| void * | mem | ||
| ) |
| void * dt_pixel_cache_entry_get_data | ( | struct dt_pixel_cache_entry_t * | entry | ) |
Peek the host data pointer of a cache entry without allocating.
References dt_pixel_cache_entry_t::data.
Referenced by _cache_entry_has_host_payload_ptr(), _cache_entry_materialize_host_data(), _cache_try_restore_host_payload(), _lock_pipe_surface(), dt_dev_pixelpipe_cache_gpu_device_buffer(), dt_dev_pixelpipe_cache_peek(), dt_dev_pixelpipe_cache_restore_host_payload(), dt_dev_pixelpipe_process_rec(), gui_post_expose(), mouse_moved(), pixelpipe_process_on_CPU(), scrolled(), and update_histogram().
| size_t dt_pixel_cache_entry_get_size | ( | struct dt_pixel_cache_entry_t * | entry | ) |
Peek the size (in bytes) reserved for the host buffer of a cache entry.
The pixelpipe cache treats dt_pixel_cache_entry_t as an internal/private structure. External users (such as the pixelpipe implementation) should not access struct fields directly.
This accessor is intentionally "peek-only": it does not allocate and it does not change ownership.
References dt_pixel_cache_entry_t::size.
Referenced by _lock_pipe_surface(), and _update_backbuf_cache_reference().
| size_t dt_pixel_cache_get_size | ( | dt_pixel_cache_entry_t * | cache_entry | ) |
References dt_pixel_cache_entry_t::size.
Referenced by dt_pixel_cache_message().
| void dt_pixel_cache_message | ( | dt_pixel_cache_entry_t * | cache_entry, |
| const char * | message, | ||
| gboolean | verbose | ||
| ) |
References _cache_debug_module_name(), dt_pixel_cache_entry_t::age, dt_pixel_cache_entry_t::auto_destroy, darktable, dt_pixel_cache_entry_t::data, dt_atomic_get_int(), DT_DEBUG_CACHE, DT_DEBUG_VERBOSE, dt_pixel_cache_get_size(), dt_print(), dt_pixel_cache_entry_t::external_alloc, dt_pixel_cache_entry_t::hash, dt_pixel_cache_entry_t::hits, dt_pixel_cache_entry_t::id, dt_pixel_cache_entry_t::name, dt_pixel_cache_entry_t::refcount, dt_pixel_cache_entry_t::serial, and darktable_t::unmuted.
Referenced by _cache_get_oldest(), _free_cache_entry(), _non_thread_safe_cache_ref_count_entry(), _non_thread_safe_cache_remove(), _pixelpipe_cache_finalize_entry(), _print_cache_lines(), dt_dev_pixelpipe_cache_auto_destroy_apply(), dt_dev_pixelpipe_cache_flag_auto_destroy(), dt_dev_pixelpipe_cache_get(), dt_dev_pixelpipe_cache_get_writable(), dt_dev_pixelpipe_cache_rdlock_entry(), and dt_dev_pixelpipe_cache_wrlock_entry().
|
static |
References _free_space_to_alloc(), dt_pixel_cache_entry_t::age, dt_dev_pixelpipe_cache_t::arena, dt_pixel_cache_entry_t::auto_destroy, dt_pixel_cache_entry_t::cache, dt_pixel_cache_entry_t::cl_mem_list, dt_pixel_cache_entry_t::cl_mem_lock, dt_dev_pixelpipe_cache_t::current_memory, dt_pixel_cache_entry_t::data, dt_cache_arena_calc(), dt_free, dt_pixel_cache_alloc(), dt_pthread_mutex_destroy(), dt_pthread_mutex_init(), dt_pthread_rwlock_destroy, dt_pthread_rwlock_init, error(), dt_pixel_cache_entry_t::external_alloc, FALSE, dt_pixel_cache_entry_t::hash, dt_pixel_cache_entry_t::hits, dt_pixel_cache_entry_t::id, key, dt_pixel_cache_entry_t::lock, name, dt_pixel_cache_entry_t::name, dt_dev_pixelpipe_cache_t::next_serial, dt_pixel_cache_entry_t::refcount, dt_pixel_cache_entry_t::serial, size, and dt_pixel_cache_entry_t::size.
Referenced by _pixelpipe_cache_create_entry_locked(), and dt_pixelpipe_cache_alloc_align_cache_impl().
| void * dt_pixelpipe_cache_alloc_align_cache_impl | ( | dt_dev_pixelpipe_cache_t * | cache, |
| size_t | size, | ||
| int | id, | ||
| const char * | name | ||
| ) |
Allocate aligned memory tracked by the pixelpipe cache. This allows LRU cache entries to be evicted if needed to make room.
| cache | Pixelpipe cache to manage. |
| size | Buffer size in bytes. |
| id | Pipeline type owning the buffer. |
| name | Human-readable name. |
References _arena_alloc_with_defrag(), _free_space_to_alloc(), _log_arena_allocation_failure(), _non_thread_safe_cache_ref_count_entry(), dt_pixel_cache_entry_t::age, dt_dev_pixelpipe_cache_t::arena, dt_pixel_cache_entry_t::data, dt_cache_arena_free(), DT_CACHELINE_BYTES, dt_pixel_cache_new_entry(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), error(), dt_pixel_cache_entry_t::external_alloc, dt_dev_pixelpipe_cache_t::external_entries, FALSE, dt_dev_pixelpipe_cache_t::lock, name, size, and TRUE.
Referenced by dt_drawlayer_cache_alloc_temp_buffer(), and dt_pixelpipe_cache_alloc_perthread_impl().
| void dt_pixelpipe_cache_free_align_cache | ( | dt_dev_pixelpipe_cache_t * | cache, |
| void ** | mem, | ||
| const char * | message | ||
| ) |
Free aligned memory allocated with dt_pixelpipe_cache_alloc_align_cache.
| cache | Pixelpipe cache to manage. |
| mem | Pointer to the buffer pointer. Set to NULL on successful free. |
References _non_thread_safe_cache_ref_count_entry(), _non_threadsafe_cache_get_entry(), dt_pthread_mutex_lock(), dt_pthread_mutex_unlock(), dt_pixel_cache_entry_t::external_alloc, dt_dev_pixelpipe_cache_t::external_entries, FALSE, dt_pixel_cache_entry_t::hash, and dt_dev_pixelpipe_cache_t::lock.
Referenced by dt_drawlayer_cache_free_temp_buffer(), and dt_drawlayer_cache_patch_clear().
| const char * dt_pixelpipe_cache_set_current_module | ( | const char * | module | ) |
Set the current module name for cache diagnostics (thread-local).
| module | Module op name or NULL to clear. |
References dt_pixelpipe_cache_current_module.
Referenced by dt_dev_pixelpipe_process_rec().
|
static |
Referenced by _cache_debug_module_name(), and dt_pixelpipe_cache_set_current_module().
|
static |
Referenced by dt_dev_pixelpipe_cache_cleanup(), and dt_dev_pixelpipe_cache_init().