[Bf-blender-cvs] [77b51d4e583] master: VSE: Remove skip_disk_cache argument

Richard Antalik noreply at git.blender.org
Mon Jan 25 04:37:53 CET 2021


Commit: 77b51d4e583da417a004391724ba945d3f7de19d
Author: Richard Antalik
Date:   Mon Jan 25 04:28:13 2021 +0100
Branches: master
https://developer.blender.org/rB77b51d4e583da417a004391724ba945d3f7de19d

VSE: Remove skip_disk_cache argument

This argument was used to prevent infinite loop in lookups between disk
and RAM cache.

Code was refactored, so this can be handled internally in cache.

Reviewed By: sybren, sergey

Differential Revision: https://developer.blender.org/D9955

===================================================================

M	source/blender/sequencer/intern/image_cache.c
M	source/blender/sequencer/intern/image_cache.h
M	source/blender/sequencer/intern/prefetch.c
M	source/blender/sequencer/intern/render.c

===================================================================

diff --git a/source/blender/sequencer/intern/image_cache.c b/source/blender/sequencer/intern/image_cache.c
index 344b5af26aa..299ebffe8a8 100644
--- a/source/blender/sequencer/intern/image_cache.c
+++ b/source/blender/sequencer/intern/image_cache.c
@@ -824,16 +824,59 @@ static void seq_cache_valfree(void *val)
   BLI_mempool_free(item->cache_owner->items_pool, item);
 }
 
-static void seq_cache_put_ex(SeqCache *cache, SeqCacheKey *key, ImBuf *ibuf)
+static int get_stored_types_flag(Scene *scene, SeqCacheKey *key)
 {
+  int flag;
+  if (key->seq->cache_flag & SEQ_CACHE_OVERRIDE) {
+    flag = key->seq->cache_flag;
+  }
+  else {
+    flag = scene->ed->cache_flag;
+  }
+
+  /* SEQ_CACHE_STORE_FINAL_OUT can not be overridden by strip cache */
+  flag |= (scene->ed->cache_flag & SEQ_CACHE_STORE_FINAL_OUT);
+
+  return flag;
+}
+
+static void seq_cache_put_ex(Scene *scene, SeqCacheKey *key, ImBuf *ibuf)
+{
+  SeqCache *cache = seq_cache_get_from_scene(scene);
   SeqCacheItem *item;
   item = BLI_mempool_alloc(cache->items_pool);
   item->cache_owner = cache;
   item->ibuf = ibuf;
 
+  const int stored_types_flag = get_stored_types_flag(scene, key);
+
+  /* Item stored for later use. */
+  if (stored_types_flag & key->type) {
+    key->is_temp_cache = false;
+    key->link_prev = cache->last_key;
+  }
+
+  /* Store pointer to last cached key. */
+  SeqCacheKey *temp_last_key = cache->last_key;
+
   if (BLI_ghash_reinsert(cache->hash, key, item, seq_cache_keyfree, seq_cache_valfree)) {
     IMB_refImBuf(ibuf);
-    cache->last_key = key;
+
+    if (!key->is_temp_cache) {
+      cache->last_key = key;
+    }
+  }
+
+  /* Set last_key's reference to this key so we can look up chain backwards.
+   * Item is already put in cache, so cache->last_key points to current key.
+   */
+  if (!key->is_temp_cache && temp_last_key) {
+    temp_last_key->link_next = cache->last_key;
+  }
+
+  /* Reset linking. */
+  if (key->type == SEQ_CACHE_STORE_FINAL_OUT) {
+    cache->last_key = NULL;
   }
 }
 
@@ -1095,6 +1138,35 @@ static void seq_cache_create(Main *bmain, Scene *scene)
   BLI_mutex_unlock(&cache_create_lock);
 }
 
+static void seq_cache_populate_key(SeqCacheKey *key,
+                                   const SeqRenderData *context,
+                                   Sequence *seq,
+                                   const float timeline_frame,
+                                   const int type)
+{
+  key->cache_owner = seq_cache_get_from_scene(context->scene);
+  key->seq = seq;
+  key->context = *context;
+  key->frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type);
+  key->timeline_frame = timeline_frame;
+  key->type = type;
+  key->link_prev = NULL;
+  key->link_next = NULL;
+  key->is_temp_cache = true;
+  key->task_id = context->task_id;
+}
+
+static SeqCacheKey *seq_cache_allocate_key(SeqCache *cache,
+                                           const SeqRenderData *context,
+                                           Sequence *seq,
+                                           const float timeline_frame,
+                                           const int type)
+{
+  SeqCacheKey *key = BLI_mempool_alloc(cache->keys_pool);
+  seq_cache_populate_key(key, context, seq, timeline_frame, type);
+  return key;
+}
+
 /* ***************************** API ****************************** */
 
 void seq_cache_free_temp_cache(Scene *scene, short id, int timeline_frame)
@@ -1243,8 +1315,7 @@ void seq_cache_cleanup_sequence(Scene *scene,
 struct ImBuf *seq_cache_get(const SeqRenderData *context,
                             Sequence *seq,
                             float timeline_frame,
-                            int type,
-                            bool skip_disk_cache)
+                            int type)
 {
 
   if (context->skip_cache || context->is_proxy_render || !seq) {
@@ -1274,11 +1345,7 @@ struct ImBuf *seq_cache_get(const SeqRenderData *context,
 
   /* Try RAM cache: */
   if (cache && seq) {
-    key.seq = seq;
-    key.context = *context;
-    key.frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type);
-    key.type = type;
-
+    seq_cache_populate_key(&key, context, seq, timeline_frame, type);
     ibuf = seq_cache_get_ex(cache, &key);
   }
   seq_cache_unlock(scene);
@@ -1288,7 +1355,7 @@ struct ImBuf *seq_cache_get(const SeqRenderData *context,
   }
 
   /* Try disk cache: */
-  if (!skip_disk_cache && seq_disk_cache_is_enabled(context->bmain)) {
+  if (seq_disk_cache_is_enabled(context->bmain)) {
     if (cache->disk_cache == NULL) {
       seq_disk_cache_create(context->bmain, context->scene);
     }
@@ -1296,25 +1363,23 @@ struct ImBuf *seq_cache_get(const SeqRenderData *context,
     BLI_mutex_lock(&cache->disk_cache->read_write_mutex);
     ibuf = seq_disk_cache_read_file(cache->disk_cache, &key);
     BLI_mutex_unlock(&cache->disk_cache->read_write_mutex);
-    if (ibuf) {
-      if (key.type == SEQ_CACHE_STORE_FINAL_OUT) {
-        seq_cache_put_if_possible(context, seq, timeline_frame, type, ibuf, true);
-      }
-      else {
-        seq_cache_put(context, seq, timeline_frame, type, ibuf, true);
-      }
+
+    if (ibuf == NULL) {
+      return NULL;
+    }
+
+    /* Store read image in RAM. Only recycle item for final type. */
+    if (key.type != SEQ_CACHE_STORE_FINAL_OUT || seq_cache_recycle_item(scene)) {
+      SeqCacheKey *new_key = seq_cache_allocate_key(cache, context, seq, timeline_frame, type);
+      seq_cache_put_ex(scene, new_key, ibuf);
     }
   }
 
   return ibuf;
 }
 
-bool seq_cache_put_if_possible(const SeqRenderData *context,
-                               Sequence *seq,
-                               float timeline_frame,
-                               int type,
-                               ImBuf *ibuf,
-                               bool skip_disk_cache)
+bool seq_cache_put_if_possible(
+    const SeqRenderData *context, Sequence *seq, float timeline_frame, int type, ImBuf *ibuf)
 {
   Scene *scene = context->scene;
 
@@ -1329,7 +1394,7 @@ bool seq_cache_put_if_possible(const SeqRenderData *context,
   }
 
   if (seq_cache_recycle_item(scene)) {
-    seq_cache_put(context, seq, timeline_frame, type, ibuf, skip_disk_cache);
+    seq_cache_put(context, seq, timeline_frame, type, ibuf);
     return true;
   }
 
@@ -1338,12 +1403,8 @@ bool seq_cache_put_if_possible(const SeqRenderData *context,
   return false;
 }
 
-void seq_cache_put(const SeqRenderData *context,
-                   Sequence *seq,
-                   float timeline_frame,
-                   int type,
-                   ImBuf *i,
-                   bool skip_disk_cache)
+void seq_cache_put(
+    const SeqRenderData *context, Sequence *seq, float timeline_frame, int type, ImBuf *i)
 {
   if (i == NULL || context->skip_cache || context->is_proxy_render || !seq) {
     return;
@@ -1359,7 +1420,7 @@ void seq_cache_put(const SeqRenderData *context,
   }
 
   /* Prevent reinserting, it breaks cache key linking. */
-  ImBuf *test = seq_cache_get(context, seq, timeline_frame, type, true);
+  ImBuf *test = seq_cache_get(context, seq, timeline_frame, type);
   if (test) {
     IMB_freeImBuf(test);
     return;
@@ -1370,63 +1431,12 @@ void seq_cache_put(const SeqRenderData *context,
   }
 
   seq_cache_lock(scene);
-
   SeqCache *cache = seq_cache_get_from_scene(scene);
-  int flag;
-
-  if (seq->cache_flag & SEQ_CACHE_OVERRIDE) {
-    flag = seq->cache_flag;
-    /* Final_out is invalid in context of sequence override. */
-    flag -= seq->cache_flag & SEQ_CACHE_STORE_FINAL_OUT;
-    /* If global setting is enabled however, use it. */
-    flag |= scene->ed->cache_flag & SEQ_CACHE_STORE_FINAL_OUT;
-  }
-  else {
-    flag = scene->ed->cache_flag;
-  }
-
-  SeqCacheKey *key;
-  key = BLI_mempool_alloc(cache->keys_pool);
-  key->cache_owner = cache;
-  key->seq = seq;
-  key->context = *context;
-  key->frame_index = seq_cache_timeline_frame_to_frame_index(seq, timeline_frame, type);
-  key->timeline_frame = timeline_frame;
-  key->type = type;
-  key->link_prev = NULL;
-  key->link_next = NULL;
-  key->is_temp_cache = true;
-  key->task_id = context->task_id;
-
-  /* Item stored for later use */
-  if (flag & type) {
-    key->is_temp_cache = false;
-    key->link_prev = cache->last_key;
-  }
-
-  SeqCacheKey *temp_last_key = cache->last_key;
-  seq_cache_put_ex(cache, key, i);
-
-  /* Restore pointer to previous item as this one will be freed when stack is rendered. */
-  if (key->is_temp_cache) {
-    cache->last_key = temp_last_key;
-  }
-
-  /* Set last_key's reference to this key so we can look up chain backwards.
-   * Item is already put in cache, so cache->last_key points to current key.
-   */
-  if (flag & type && temp_last_key) {
-    temp_last_key->link_next = cache->last_key;
-  }
-
-  /* Reset linking. */
-  if (key->type == SEQ_CACHE_STORE_FINAL_OUT) {
-    cache->last_key = NULL;
-  }
-
+  SeqCacheKey *key = seq_cache_allocate_key(cache, context, seq, timeline_frame, type);
+  seq_cache_put_ex(scene, key, i);
   seq_cache_unlock(scene);
 
-  if (!key->is_temp_cache && !skip_disk_cache) {
+  if (!key->is_temp_cache) {
     if (seq_disk_cache_is_enabled(context->bmain)) {
       if (cache->disk_cache == NULL) {
         seq_disk_cache_create(context->bmain, context->scene);
diff --git a/source/blender/sequencer/intern/image_cache.h b/source/blender/sequencer/intern/image_cache.h
index 41e8c4d1d48..63c559caee9 100644
--- a/source/blender/sequencer/intern/image_cache.h
+++ b/source/blender/sequencer/intern/image_cache.h
@@ -40,20 +40,17 @@ struct Sequence;
 struct ImBuf *seq_cache_get(const struct SeqRenderData *context,
                             struct Sequence *seq,
                             float timeline_frame,
-                            int type,
-                            bool skip_disk_cache);
+                            int type);
 void seq_cache_put(const struct SeqRenderData *context,
                    struct Sequence *seq,
                    float timeline_frame,
                    int type,
-                   struct ImBuf *i,
-                   bool skip_disk_cache);
+                   struct ImBuf *i);
 bool seq_cache_put_if_possible(const struct SeqR

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list