[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48630] branches/soc-2011-tomato: Color management: refactor of cache to deal better with movie clip cache

Sergey Sharybin sergey.vfx at gmail.com
Thu Jul 5 11:41:00 CEST 2012


Revision: 48630
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48630
Author:   nazgul
Date:     2012-07-05 09:41:00 +0000 (Thu, 05 Jul 2012)
Log Message:
-----------
Color management: refactor of cache to deal better with movie clip cache

There were some crashes discovered in some circumstances of using
color management within the clip editor which ended up some refactoring
of color management cache.

Switch from global movie cache instance to per-image buffer instances

This only means keys for color managed buffers could be much simpier
and that look up would happen much faster in there're lots of frames
cached. Memory limiter stuff is still global for all color management
and in fact it's also shared with movie clip cache .

This allowed to get rid of original image buffer stored in cache
key and allowed to easily remove all display buffers when source
image buffer is being freed. This was main culptrit leading to
crashes.

Additional changes:

- Add option to make moviecache verbose. If DEBUG_MESSAGES is
  defined in moviecache.c detailed logs would be printed to the
  console.

- Movie caches are now named which helps reading debug messages.

- Improved a bit behavior of cache element removing when buffer
  overflows on adding new display buffer and there're frames from
  movie clip.

Modified Paths:
--------------
    branches/soc-2011-tomato/intern/memutil/MEM_CacheLimiter.h
    branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
    branches/soc-2011-tomato/source/blender/blenkernel/intern/seqcache.c
    branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
    branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h
    branches/soc-2011-tomato/source/blender/imbuf/IMB_moviecache.h
    branches/soc-2011-tomato/source/blender/imbuf/intern/allocimbuf.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
    branches/soc-2011-tomato/source/blender/imbuf/intern/moviecache.c

Modified: branches/soc-2011-tomato/intern/memutil/MEM_CacheLimiter.h
===================================================================
--- branches/soc-2011-tomato/intern/memutil/MEM_CacheLimiter.h	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/intern/memutil/MEM_CacheLimiter.h	2012-07-05 09:41:00 UTC (rev 48630)
@@ -255,7 +255,7 @@
 			int priority;
 
 			/* by default 0 means higherst priority element */
-			priority = queue.size() - i - 1;
+			priority = -(queue.size() - i - 1);
 
 			if (getItemPriority) {
 				priority = getItemPriority(elem->get()->get_data(), priority);

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/movieclip.c	2012-07-05 09:41:00 UTC (rev 48630)
@@ -437,9 +437,12 @@
 	if (!clip->cache) {
 		struct MovieCache *moviecache;
 
+		// char cache_name[64];
+		// BLI_snprintf(cache_name, sizeof(cache_name), "movie %s", clip->id.name);
+
 		clip->cache = MEM_callocN(sizeof(MovieClipCache), "movieClipCache");
 
-		moviecache = IMB_moviecache_create(sizeof(MovieClipImBufCacheKey), moviecache_hashhash, moviecache_hashcmp);
+		moviecache = IMB_moviecache_create("movieclip", sizeof(MovieClipImBufCacheKey), moviecache_hashhash, moviecache_hashcmp);
 
 		IMB_moviecache_set_getdata_callback(moviecache, moviecache_keydata);
 		IMB_moviecache_set_priority_callback(moviecache, moviecache_getprioritydata, moviecache_getitempriority,

Modified: branches/soc-2011-tomato/source/blender/blenkernel/intern/seqcache.c
===================================================================
--- branches/soc-2011-tomato/source/blender/blenkernel/intern/seqcache.c	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/source/blender/blenkernel/intern/seqcache.c	2012-07-05 09:41:00 UTC (rev 48630)
@@ -98,7 +98,7 @@
 {
 	if (moviecache) {
 		IMB_moviecache_free(moviecache);
-		moviecache = IMB_moviecache_create(sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp);
+		moviecache = IMB_moviecache_create("seqcache", sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp);
 	}
 }
 
@@ -132,7 +132,7 @@
 	}
 
 	if (!moviecache) {
-		moviecache = IMB_moviecache_create(sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp);
+		moviecache = IMB_moviecache_create("seqcache", sizeof(SeqCacheKey), seqcache_hashhash, seqcache_hashcmp);
 	}
 
 	key.seq = seq;

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_colormanagement.h	2012-07-05 09:41:00 UTC (rev 48630)
@@ -49,11 +49,8 @@
 
 /* ** Public display buffers interfaces ** */
 
-void IMB_colormanage_flags_allocate(struct ImBuf *ibuf);
-void IMB_colormanage_flags_free(struct ImBuf *ibuf);
+void IMB_colormanage_cache_free(struct ImBuf *ibuf);
 
-void IMB_colormanage_cache_data_free(struct ImBuf *ibuf);
-
 unsigned char *IMB_display_buffer_acquire(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,
                                           const struct ColorManagedDisplaySettings *display_settings, void **cache_handle);
 void IMB_display_buffer_to_imbuf_rect(struct ImBuf *ibuf, const struct ColorManagedViewSettings *view_settings,

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_imbuf_types.h	2012-07-05 09:41:00 UTC (rev 48630)
@@ -128,11 +128,9 @@
 	unsigned int   encodedbuffersize; /* Size of encodedbuffer */
 
 	/* color management */
-	int colormanage_refcounter;
-	unsigned int colormanage_flags;
 	unsigned int *display_buffer_flags;  /* array of per-display display buffers dirty flags */
-	void *colormanage_cache_data;        /* cache data which is being assigned when */
-	                                     /* put ImBuf to colormanage cache */
+	struct ColormanageCache *colormanage_cache;  /* cache used by color management */
+
 	/* information for compressed textures */
 	struct DDSData dds_data;
 } ImBuf;
@@ -258,7 +256,4 @@
 extern const char *imb_ext_movie[];
 extern const char *imb_ext_audio[];
 
-/* colormanage flags */
-#define IMB_COLORMANAGED		(1 << 0)
-
 #endif

Modified: branches/soc-2011-tomato/source/blender/imbuf/IMB_moviecache.h
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/IMB_moviecache.h	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/source/blender/imbuf/IMB_moviecache.h	2012-07-05 09:41:00 UTC (rev 48630)
@@ -53,7 +53,7 @@
 void IMB_moviecache_init(void);
 void IMB_moviecache_destruct(void);
 
-struct MovieCache *IMB_moviecache_create(int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp);
+struct MovieCache *IMB_moviecache_create(const char *name, int keysize, GHashHashFP hashfp, GHashCmpFP cmpfp);
 void IMB_moviecache_set_key_deleter_callback(struct MovieCache *cache, MovieCacheKeyDeleterFP keydeleterfp);
 void IMB_moviecache_set_getdata_callback(struct MovieCache *cache, MovieCacheGetKeyDataFP getdatafp);
 void IMB_moviecache_set_check_unused_callback(struct MovieCache *cache, MovieCacheCheckKeyUnusedFP checkkeyunusedfp);

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/allocimbuf.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/allocimbuf.c	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/allocimbuf.c	2012-07-05 09:41:00 UTC (rev 48630)
@@ -163,8 +163,7 @@
 			IMB_freezbuffloatImBuf(ibuf);
 			freeencodedbufferImBuf(ibuf);
 			IMB_metadata_free(ibuf);
-			IMB_colormanage_flags_free(ibuf);
-			IMB_colormanage_cache_data_free(ibuf);
+			IMB_colormanage_cache_free(ibuf);
 
 			if (ibuf->dds_data.data != NULL) {
 				free(ibuf->dds_data.data); /* dds_data.data is allocated by DirectDrawSurface::readData(), so don't use MEM_freeN! */
@@ -448,11 +447,8 @@
 
 	*ibuf2 = tbuf;
 
-	IMB_display_buffer_invalidate(ibuf2);
-	IMB_colormanage_cache_data_free(ibuf2);
+	IMB_colormanage_cache_free(ibuf2);
 
-	ibuf2->colormanage_flags &= ~ IMB_COLORMANAGED;
-
 	return(ibuf2);
 }
 

Modified: branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c
===================================================================
--- branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-05 09:40:53 UTC (rev 48629)
+++ branches/soc-2011-tomato/source/blender/imbuf/intern/colormanagement.c	2012-07-05 09:41:00 UTC (rev 48630)
@@ -83,46 +83,59 @@
 
 /*********************** Color managed cache *************************/
 
-/* Currently it's original ImBuf pointer is used to distinguish which
- * datablock, frame number, possible postprocessing display buffer was
- * created for.
+/* Cache Implementation Notes
+ * ==========================
  *
- * This makes it's possible to easy define key for color managed cache
- * which would work for Images, Movie Clips, Sequencer Strips and so.
+ * All color management cache stuff is stored in two properties of
+ * image buffers:
  *
- * This also allows to easily control memory usage -- all color managed
- * buffers are concentrated in single cache and it's really easy to
- * control maximal memory usage for all color management related stuff
- * (currently supports only maximal memory usage, but it could be
- * improved further to support removing buffers when they are not needed
- * anymore but memory usage didn't exceed it's limit).
+ *   1. display_buffer_flags
  *
- * This ImBuf is being referenced by cache key, so it could accessed
- * anytime on runtime while cache element is valid. This is needed to
- * support removing display buffers from cache when ImBuf they were
- * created for is being freed.
+ *      This is a bit field which used to mark calculated transformations
+ *      for particular image buffer. Index inside of this array means index
+ *      of a color managed display. Element with given index matches view
+ *      transformations applied for a given display. So if bit B of array
+ *      element B is set to 1, this means display buffer with display index
+ *      of A and view transform of B was ever calculated for this imbuf.
  *
- * Technically it works in the following way:
- * - ImBuf is being referenced first time when display buffer is
- *   creating for it and being put into the cache
- * - On any further display buffer created for this ImBuf user
- *   reference counter is not being incremented
- * - There's count of color management users in ImBuf which is
- *   being incremented every time display buffer is creating for
- *   giver ImBuf.
- * - Hence, we always know how many display buffers is created
- *   for the ImBuf and if there's any display buffers created
- *   this ImBuf would be referenced by color management stuff and
- *   actual data for it wouldn't be freed even when this ImBuf is
- *   being freed by user, who created it.
- * - When all external users finished working with this ImBuf it's
- *   reference counter would be 0.
- * - On every new display buffer adding to the cache review of
- *   the cache happens and all cached display buffers who's ImBuf's
- *   user counter is zero are being removed from the cache.
- * - On every display buffer removed from the cache ImBuf's color
- *   management user counter is being decremented. As soon as it's
- *   becoming zero, original ImBuf is being freed completely.
+ *      In contrast with indices in global lists of displays and views this
+ *      indices are 0-based, not 1-based. This is needed to save some bytes
+ *      of memory.
+ *
+ *   2. colormanage_cache
+ *
+ *      This is a pointer to a structure which holds all data which is
+ *      needed for color management cache to work.
+ *
+ *      It contains two parts:
+ *        - data
+ *        - moviecache
+ *

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list