[Bf-blender-cvs] [38573d515e4] master: Cleanup: Remove unused IMB tile cache code

Jesse Yurkovich noreply at git.blender.org
Thu Nov 24 05:13:51 CET 2022


Commit: 38573d515e49f3e0b22b0e58c7b0357bae107a4d
Author: Jesse Yurkovich
Date:   Wed Nov 23 19:31:10 2022 -0800
Branches: master
https://developer.blender.org/rB38573d515e49f3e0b22b0e58c7b0357bae107a4d

Cleanup: Remove unused IMB tile cache code

This removes the unused code for the IBM tile cache APIs.  These have
been unused for as far back as I could manage to search.

Since TIFF was used for the cached images, this removal will allow for
an easier review when it comes time to move TIFF to OIIO as part of
T101413.

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

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

M	source/blender/imbuf/CMakeLists.txt
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/IMB_imbuf_types.h
M	source/blender/imbuf/intern/IMB_filetype.h
M	source/blender/imbuf/intern/allocimbuf.c
D	source/blender/imbuf/intern/cache.c
M	source/blender/imbuf/intern/filetype.c
M	source/blender/imbuf/intern/module.c
M	source/blender/imbuf/intern/readimage.c
M	source/blender/imbuf/intern/tiff.c

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

diff --git a/source/blender/imbuf/CMakeLists.txt b/source/blender/imbuf/CMakeLists.txt
index 1309e3810be..823866c75bb 100644
--- a/source/blender/imbuf/CMakeLists.txt
+++ b/source/blender/imbuf/CMakeLists.txt
@@ -24,7 +24,6 @@ set(SRC
   intern/allocimbuf.c
   intern/anim_movie.c
   intern/bmp.c
-  intern/cache.c
   intern/colormanagement.c
   intern/colormanagement_inline.c
   intern/divers.c
diff --git a/source/blender/imbuf/IMB_imbuf.h b/source/blender/imbuf/IMB_imbuf.h
index a05bc51fcea..a5bb34392b1 100644
--- a/source/blender/imbuf/IMB_imbuf.h
+++ b/source/blender/imbuf/IMB_imbuf.h
@@ -452,17 +452,6 @@ void IMB_makemipmap(struct ImBuf *ibuf, int use_filter);
 void IMB_remakemipmap(struct ImBuf *ibuf, int use_filter);
 struct ImBuf *IMB_getmipmap(struct ImBuf *ibuf, int level);
 
-/**
- * \attention Defined in cache.c
- */
-
-/**
- * Presumed to be called when no threads are running.
- */
-void IMB_tile_cache_params(int totthread, int maxmem);
-unsigned int *IMB_gettile(struct ImBuf *ibuf, int tx, int ty, int thread);
-void IMB_tiles_to_rect(struct ImBuf *ibuf);
-
 /**
  * \attention Defined in filter.c
  */
@@ -816,9 +805,6 @@ bool imb_addrectfloatImBuf(struct ImBuf *ibuf, const unsigned int channels);
 void imb_freerectfloatImBuf(struct ImBuf *ibuf);
 void imb_freemipmapImBuf(struct ImBuf *ibuf);
 
-bool imb_addtilesImBuf(struct ImBuf *ibuf);
-void imb_freetilesImBuf(struct ImBuf *ibuf);
-
 /** Free all pixel data (associated with image size). */
 void imb_freerectImbuf_all(struct ImBuf *ibuf);
 
diff --git a/source/blender/imbuf/IMB_imbuf_types.h b/source/blender/imbuf/IMB_imbuf_types.h
index 81e9420c8ba..0851aaa8669 100644
--- a/source/blender/imbuf/IMB_imbuf_types.h
+++ b/source/blender/imbuf/IMB_imbuf_types.h
@@ -144,8 +144,7 @@ typedef enum eImBufFlags {
   IB_multilayer = 1 << 7,
   IB_metadata = 1 << 8,
   IB_animdeinterlace = 1 << 9,
-  IB_tiles = 1 << 10,
-  IB_tilecache = 1 << 11,
+
   /** indicates whether image on disk have premul alpha */
   IB_alphamode_premul = 1 << 12,
   /** if this flag is set, alpha mode would be guessed from file */
@@ -202,11 +201,6 @@ typedef struct ImBuf {
   /** Resolution in pixels per meter. Multiply by `0.0254` for DPI. */
   double ppm[2];
 
-  /* tiled pixel storage */
-  int tilex, tiley;
-  int xtiles, ytiles;
-  unsigned int **tiles;
-
   /* zbuffer */
   /** z buffer data, original zbuffer */
   int *zbuf;
diff --git a/source/blender/imbuf/intern/IMB_filetype.h b/source/blender/imbuf/intern/IMB_filetype.h
index bd17316d173..8252b0dd0b3 100644
--- a/source/blender/imbuf/intern/IMB_filetype.h
+++ b/source/blender/imbuf/intern/IMB_filetype.h
@@ -49,12 +49,6 @@ typedef struct ImFileType {
                                            size_t *r_height);
   /** Save to a file (or memory if #IB_mem is set in `flags` and the format supports it). */
   bool (*save)(struct ImBuf *ibuf, const char *filepath, int flags);
-  void (*load_tile)(struct ImBuf *ibuf,
-                    const unsigned char *mem,
-                    size_t size,
-                    int tx,
-                    int ty,
-                    unsigned int *rect);
 
   int flag;
 
@@ -73,15 +67,6 @@ const ImFileType *IMB_file_type_from_ibuf(const struct ImBuf *ibuf);
 void imb_filetypes_init(void);
 void imb_filetypes_exit(void);
 
-void imb_tile_cache_init(void);
-void imb_tile_cache_exit(void);
-
-void imb_loadtile(struct ImBuf *ibuf, int tx, int ty, unsigned int *rect);
-/**
- * External free.
- */
-void imb_tile_cache_tile_free(struct ImBuf *ibuf, int tx, int ty);
-
 /** \} */
 
 /* Type Specific Functions */
@@ -235,8 +220,6 @@ struct ImBuf *imb_loadtiff(const unsigned char *mem,
                            size_t size,
                            int flags,
                            char colorspace[IM_MAX_SPACE]);
-void imb_loadtiletiff(
-    struct ImBuf *ibuf, const unsigned char *mem, size_t size, int tx, int ty, unsigned int *rect);
 /**
  * Saves a TIFF file.
  *
diff --git a/source/blender/imbuf/intern/allocimbuf.c b/source/blender/imbuf/intern/allocimbuf.c
index 2860944e948..db1325e16ff 100644
--- a/source/blender/imbuf/intern/allocimbuf.c
+++ b/source/blender/imbuf/intern/allocimbuf.c
@@ -110,31 +110,6 @@ void imb_freerectImBuf(ImBuf *ibuf)
   ibuf->mall &= ~IB_rect;
 }
 
-void imb_freetilesImBuf(ImBuf *ibuf)
-{
-  int tx, ty;
-
-  if (ibuf == NULL) {
-    return;
-  }
-
-  if (ibuf->tiles && (ibuf->mall & IB_tiles)) {
-    for (ty = 0; ty < ibuf->ytiles; ty++) {
-      for (tx = 0; tx < ibuf->xtiles; tx++) {
-        if (ibuf->tiles[ibuf->xtiles * ty + tx]) {
-          imb_tile_cache_tile_free(ibuf, tx, ty);
-          MEM_freeN(ibuf->tiles[ibuf->xtiles * ty + tx]);
-        }
-      }
-    }
-
-    MEM_freeN(ibuf->tiles);
-  }
-
-  ibuf->tiles = NULL;
-  ibuf->mall &= ~IB_tiles;
-}
-
 static void freeencodedbufferImBuf(ImBuf *ibuf)
 {
   if (ibuf == NULL) {
@@ -183,7 +158,6 @@ void imb_freerectImbuf_all(ImBuf *ibuf)
 {
   imb_freerectImBuf(ibuf);
   imb_freerectfloatImBuf(ibuf);
-  imb_freetilesImBuf(ibuf);
   IMB_freezbufImBuf(ibuf);
   IMB_freezbuffloatImBuf(ibuf);
   freeencodedbufferImBuf(ibuf);
@@ -476,21 +450,6 @@ struct ImBuf *IMB_allocFromBuffer(
   return ibuf;
 }
 
-bool imb_addtilesImBuf(ImBuf *ibuf)
-{
-  if (ibuf == NULL) {
-    return false;
-  }
-
-  if (!ibuf->tiles) {
-    if ((ibuf->tiles = MEM_callocN(sizeof(uint *) * ibuf->xtiles * ibuf->ytiles, "imb_tiles"))) {
-      ibuf->mall |= IB_tiles;
-    }
-  }
-
-  return (ibuf->tiles != NULL);
-}
-
 ImBuf *IMB_allocImBuf(uint x, uint y, uchar planes, uint flags)
 {
   ImBuf *ibuf;
@@ -670,10 +629,6 @@ size_t IMB_get_size_in_memory(ImBuf *ibuf)
     }
   }
 
-  if (ibuf->tiles) {
-    size += sizeof(uint) * ibuf->ytiles * ibuf->xtiles;
-  }
-
   return size;
 }
 
diff --git a/source/blender/imbuf/intern/cache.c b/source/blender/imbuf/intern/cache.c
deleted file mode 100644
index 98d33ac061f..00000000000
--- a/source/blender/imbuf/intern/cache.c
+++ /dev/null
@@ -1,473 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-
-/** \file
- * \ingroup imbuf
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_ghash.h"
-#include "BLI_listbase.h"
-#include "BLI_memarena.h"
-#include "BLI_threads.h"
-#include "BLI_utildefines.h"
-
-#include "IMB_filetype.h"
-#include "IMB_imbuf.h"
-#include "IMB_imbuf_types.h"
-
-#include "imbuf.h"
-
-/* -------------------------------------------------------------------- */
-/** \name Local Structs
- * \{ */
-
-/* We use a two level cache here. A per-thread cache with limited number of
- * tiles. This can be accessed without locking and so is hoped to lead to most
- * tile access being lock-free. The global cache is shared between all threads
- * and requires slow locking to access, and contains all tiles.
- *
- * The per-thread cache should be big enough that one might hope to not fall
- * back to the global cache every pixel, but not to big to keep too many tiles
- * locked and using memory. */
-
-#define IB_THREAD_CACHE_SIZE 100
-
-typedef struct ImGlobalTile {
-  struct ImGlobalTile *next, *prev;
-
-  ImBuf *ibuf;
-  int tx, ty;
-  int refcount;
-  volatile int loading;
-} ImGlobalTile;
-
-typedef struct ImThreadTile {
-  struct ImThreadTile *next, *prev;
-
-  ImBuf *ibuf;
-  int tx, ty;
-
-  ImGlobalTile *global;
-} ImThreadTile;
-
-typedef struct ImThreadTileCache {
-  ListBase tiles;
-  ListBase unused;
-  GHash *tilehash;
-} ImThreadTileCache;
-
-typedef struct ImGlobalTileCache {
-  ListBase tiles;
-  ListBase unused;
-  GHash *tilehash;
-
-  MemArena *memarena;
-  uintptr_t totmem, maxmem;
-
-  ImThreadTileCache thread_cache[BLENDER_MAX_THREADS + 1];
-  int totthread;
-
-  ThreadMutex mutex;
-
-  int initialized;
-} ImGlobalTileCache;
-
-static ImGlobalTileCache GLOBAL_CACHE;
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Hash Functions
- * \{ */
-
-static uint imb_global_tile_hash(const void *gtile_p)
-{
-  const ImGlobalTile *gtile = gtile_p;
-
-  return ((uint)(intptr_t)gtile->ibuf) * 769 + gtile->tx * 53 + gtile->ty * 97;
-}
-
-static bool imb_global_tile_cmp(const void *a_p, const void *b_p)
-{
-  const ImGlobalTile *a = a_p;
-  const ImGlobalTile *b = b_p;
-
-  return ((a->ibuf != b->ibuf) || (a->tx != b->tx) || (a->ty != b->ty));
-}
-
-static uint imb_thread_tile_hash(const void *ttile_p)
-{
-  const ImThreadTile *ttile = ttile_p;
-
-  return ((uint)(intptr_t)ttile->ibuf) * 769 + ttile->tx * 53 + ttile->ty * 97;
-}
-
-static bool imb_thread_tile_cmp(const void *a_p, const void *b_p)
-{
-  const ImThreadTile *a = a_p;
-  const ImThreadTile *b = b_p;
-
-  return ((a->ibuf != b->ibuf) || (a->tx != b->tx) || (a->ty != b->ty));
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Load/Unload
- * \{ */
-
-static void imb_global_cache_tile_load(ImGlobalTile *gtile)
-{
-  ImBuf *ibuf = gtile->ibuf;
-  int toffs = ibuf->xtiles * gtile->ty + gtile->tx;
-  uint *rect;
-
-  rect = MEM_callocN(sizeof(uint) * ibuf->tilex * ibuf->tiley, "imb_tile");
-  imb_loadtile(ibuf, gtile->tx, gtile->ty, rect);
-  ibuf->tiles[toffs] = rect;
-}
-
-static void imb_global_cache_tile_unload(ImGlobalTile *gtile)
-{
-  ImBuf *ibuf = gtile->ibuf;
-  int toffs = ibuf->xtiles * gtile->ty + gtile->tx;
-
-  MEM_freeN(ibuf->tiles[toffs]);
-  ibuf->tiles[toffs] = NULL;
-
-  GLOBAL_CACHE.totmem -= sizeof(uint) * ibuf->tilex * ibuf->tiley;
-}
-
-void imb_tile_cache_tile_free(ImBuf *ibuf, int tx, int ty)
-{
-  ImGlobalTile *gtile, lookuptile;
-
-  BLI_mutex_lock(&GLOBAL_CACHE.mutex);
-
-  lookuptile.ibuf = ibuf;
-  lookuptile.tx = tx;
-  lookuptile.ty = ty;
-  gtile = BLI_ghash_lookup(GLOBAL_CACHE.tilehash, &lookuptile);
-
-  if (gtile) {
-    /* in case another thread is loading this */
-    while (gtile->loading) {
-      /* pass */
-    }
-
-    BLI_ghash_remove(GLOBAL_CACHE.tilehash, gtile, NULL, NULL);
-    BLI_remlink(&GLOBAL_CACHE.tiles, gtile);
-    BLI_addtail(&GLOBAL_CACHE.unused, gtile);
-  }
-
-  BLI_mutex_unlock(&GLOBAL_CACHE.mutex);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Initialize/Exit
- * \{ */
-
-static void imb_thread_cache_init(ImThreadTileCache *cache

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list