[Bf-blender-cvs] [f41c7723c93] master: GPU: Remove cached full/scaled image texture.

Jeroen Bakker noreply at git.blender.org
Fri May 27 10:55:59 CEST 2022


Commit: f41c7723c93bc9e784634887da8b682787729538
Author: Jeroen Bakker
Date:   Fri May 27 10:52:49 2022 +0200
Branches: master
https://developer.blender.org/rBf41c7723c93bc9e784634887da8b682787729538

GPU: Remove cached full/scaled image texture.

full scaled image isn't used anymore. It was added to use a different scale when
displaying an image in the image editor. This was replaced by the image engine
redesign.

This change will reduce complexity of {T98375}.

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

M	source/blender/blenkernel/intern/image.cc
M	source/blender/blenkernel/intern/image_gpu.cc
M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/blenloader/intern/versioning_290.c
M	source/blender/editors/space_image/space_image.c
M	source/blender/gpu/GPU_capabilities.h
M	source/blender/gpu/intern/gpu_capabilities.cc
M	source/blender/imbuf/IMB_imbuf.h
M	source/blender/imbuf/intern/util_gpu.c
M	source/blender/makesdna/DNA_image_types.h
M	source/blender/makesrna/intern/rna_image.c
M	source/blender/makesrna/intern/rna_image_api.c

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

diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc
index 3d894f47ae0..bc21e706d1e 100644
--- a/source/blender/blenkernel/intern/image.cc
+++ b/source/blender/blenkernel/intern/image.cc
@@ -182,9 +182,7 @@ static void image_copy_data(Main *UNUSED(bmain), ID *id_dst, const ID *id_src, c
 
   for (int eye = 0; eye < 2; eye++) {
     for (int i = 0; i < TEXTARGET_COUNT; i++) {
-      for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
-        image_dst->gputexture[i][eye][resolution] = nullptr;
-      }
+      image_dst->gputexture[i][eye] = nullptr;
     }
   }
 
@@ -236,24 +234,21 @@ static void image_foreach_cache(ID *id,
   key.offset_in_ID = offsetof(Image, cache);
   function_callback(id, &key, (void **)&image->cache, 0, user_data);
 
-  auto gputexture_offset = [image](int target, int eye, int resolution) {
+  auto gputexture_offset = [image](int target, int eye) {
     constexpr size_t base_offset = offsetof(Image, gputexture);
-    struct GPUTexture **first = &image->gputexture[0][0][0];
-    const size_t array_offset = sizeof(*first) *
-                                (&image->gputexture[target][eye][resolution] - first);
+    struct GPUTexture **first = &image->gputexture[0][0];
+    const size_t array_offset = sizeof(*first) * (&image->gputexture[target][eye] - first);
     return base_offset + array_offset;
   };
 
   for (int eye = 0; eye < 2; eye++) {
     for (int a = 0; a < TEXTARGET_COUNT; a++) {
-      for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
-        GPUTexture *texture = image->gputexture[a][eye][resolution];
-        if (texture == nullptr) {
-          continue;
-        }
-        key.offset_in_ID = gputexture_offset(a, eye, resolution);
-        function_callback(id, &key, (void **)&image->gputexture[a][eye][resolution], 0, user_data);
+      GPUTexture *texture = image->gputexture[a][eye];
+      if (texture == nullptr) {
+        continue;
       }
+      key.offset_in_ID = gputexture_offset(a, eye);
+      function_callback(id, &key, (void **)&image->gputexture[a][eye], 0, user_data);
     }
   }
 
@@ -335,9 +330,7 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres
   ima->runtime.partial_update_user = nullptr;
   for (int i = 0; i < 3; i++) {
     for (int j = 0; j < 2; j++) {
-      for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
-        ima->gputexture[i][j][resolution] = nullptr;
-      }
+      ima->gputexture[i][j] = nullptr;
     }
   }
 
@@ -784,10 +777,8 @@ bool BKE_image_has_opengl_texture(Image *ima)
 {
   for (int eye = 0; eye < 2; eye++) {
     for (int i = 0; i < TEXTARGET_COUNT; i++) {
-      for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
-        if (ima->gputexture[i][eye][resolution] != nullptr) {
-          return true;
-        }
+      if (ima->gputexture[i][eye] != nullptr) {
+        return true;
       }
     }
   }
@@ -2864,11 +2855,9 @@ static void image_free_tile(Image *ima, ImageTile *tile)
     }
 
     for (int eye = 0; eye < 2; eye++) {
-      for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
-        if (ima->gputexture[i][eye][resolution] != nullptr) {
-          GPU_texture_free(ima->gputexture[i][eye][resolution]);
-          ima->gputexture[i][eye][resolution] = nullptr;
-        }
+      if (ima->gputexture[i][eye] != nullptr) {
+        GPU_texture_free(ima->gputexture[i][eye]);
+        ima->gputexture[i][eye] = nullptr;
       }
     }
   }
@@ -3208,16 +3197,14 @@ ImageTile *BKE_image_add_tile(struct Image *ima, int tile_number, const char *la
   }
 
   for (int eye = 0; eye < 2; eye++) {
-    for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
-      /* Reallocate GPU tile array. */
-      if (ima->gputexture[TEXTARGET_2D_ARRAY][eye][resolution] != nullptr) {
-        GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye][resolution]);
-        ima->gputexture[TEXTARGET_2D_ARRAY][eye][resolution] = nullptr;
-      }
-      if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye][resolution] != nullptr) {
-        GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye][resolution]);
-        ima->gputexture[TEXTARGET_TILE_MAPPING][eye][resolution] = nullptr;
-      }
+    /* Reallocate GPU tile array. */
+    if (ima->gputexture[TEXTARGET_2D_ARRAY][eye] != nullptr) {
+      GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye]);
+      ima->gputexture[TEXTARGET_2D_ARRAY][eye] = nullptr;
+    }
+    if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye] != nullptr) {
+      GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye]);
+      ima->gputexture[TEXTARGET_TILE_MAPPING][eye] = nullptr;
     }
   }
   BKE_image_partial_update_mark_full_update(ima);
@@ -3273,17 +3260,14 @@ void BKE_image_reassign_tile(struct Image *ima, ImageTile *tile, int new_tile_nu
   }
 
   for (int eye = 0; eye < 2; eye++) {
-    for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
-
-      /* Reallocate GPU tile array. */
-      if (ima->gputexture[TEXTARGET_2D_ARRAY][eye][resolution] != nullptr) {
-        GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye][resolution]);
-        ima->gputexture[TEXTARGET_2D_ARRAY][eye][resolution] = nullptr;
-      }
-      if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye][resolution] != nullptr) {
-        GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye][resolution]);
-        ima->gputexture[TEXTARGET_TILE_MAPPING][eye][resolution] = nullptr;
-      }
+    /* Reallocate GPU tile array. */
+    if (ima->gputexture[TEXTARGET_2D_ARRAY][eye] != nullptr) {
+      GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye]);
+      ima->gputexture[TEXTARGET_2D_ARRAY][eye] = nullptr;
+    }
+    if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye] != nullptr) {
+      GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye]);
+      ima->gputexture[TEXTARGET_TILE_MAPPING][eye] = nullptr;
     }
   }
   BKE_image_partial_update_mark_full_update(ima);
diff --git a/source/blender/blenkernel/intern/image_gpu.cc b/source/blender/blenkernel/intern/image_gpu.cc
index 0d470c5b663..bed79a318e8 100644
--- a/source/blender/blenkernel/intern/image_gpu.cc
+++ b/source/blender/blenkernel/intern/image_gpu.cc
@@ -38,7 +38,6 @@ extern "C" {
 /* Prototypes. */
 static void gpu_free_unused_buffers();
 static void image_free_gpu(Image *ima, const bool immediate);
-static void image_free_gpu_limited_scale(Image *ima);
 static void image_update_gputexture_ex(
     Image *ima, ImageTile *tile, ImBuf *ibuf, int x, int y, int w, int h);
 
@@ -68,22 +67,19 @@ bool BKE_image_has_gpu_texture_premultiplied_alpha(Image *image, ImBuf *ibuf)
 /** \name UDIM GPU Texture
  * \{ */
 
-static bool is_over_resolution_limit(int w, int h, bool limit_gl_texture_size)
+static bool is_over_resolution_limit(int w, int h)
 {
-  return (w > GPU_texture_size_with_limit(w, limit_gl_texture_size) ||
-          h > GPU_texture_size_with_limit(h, limit_gl_texture_size));
+  return (w > GPU_texture_size_with_limit(w) || h > GPU_texture_size_with_limit(h));
 }
 
-static int smaller_power_of_2_limit(int num, bool limit_gl_texture_size)
+static int smaller_power_of_2_limit(int num)
 {
-  return power_of_2_min_i(GPU_texture_size_with_limit(num, limit_gl_texture_size));
+  return power_of_2_min_i(GPU_texture_size_with_limit(num));
 }
 
-static GPUTexture *gpu_texture_create_tile_mapping(
-    Image *ima, const int multiview_eye, const eImageTextureResolution texture_resolution)
+static GPUTexture *gpu_texture_create_tile_mapping(Image *ima, const int multiview_eye)
 {
-  const int resolution = (texture_resolution == IMA_TEXTURE_RESOLUTION_LIMITED) ? 1 : 0;
-  GPUTexture *tilearray = ima->gputexture[TEXTARGET_2D_ARRAY][multiview_eye][resolution];
+  GPUTexture *tilearray = ima->gputexture[TEXTARGET_2D_ARRAY][multiview_eye];
 
   if (tilearray == nullptr) {
     return nullptr;
@@ -105,7 +101,7 @@ static GPUTexture *gpu_texture_create_tile_mapping(
   }
   LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
     int i = tile->tile_number - 1001;
-    ImageTile_RuntimeTextureSlot *tile_runtime = &tile->runtime.slots[resolution];
+    ImageTile_Runtime *tile_runtime = &tile->runtime;
     data[4 * i] = tile_runtime->tilearray_layer;
 
     float *tile_info = &data[4 * width + 4 * i];
@@ -137,12 +133,8 @@ static int compare_packtile(const void *a, const void *b)
   return tile_a->pack_score < tile_b->pack_score;
 }
 
-static GPUTexture *gpu_texture_create_tile_array(Image *ima,
-                                                 ImBuf *main_ibuf,
-                                                 const eImageTextureResolution texture_resolution)
+static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
 {
-  const bool limit_gl_texture_size = texture_resolution == IMA_TEXTURE_RESOLUTION_LIMITED;
-  const int resolution = texture_resolution == IMA_TEXTURE_RESOLUTION_LIMITED ? 1 : 0;
   int arraywidth = 0, arrayheight = 0;
   ListBase boxes = {nullptr};
 
@@ -158,10 +150,9 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima,
       packtile->boxpack.w = ibuf->x;
       packtile->boxpack.h = ibuf->y;
 
-      if (is_over_resolution_limit(
-              packtile->boxpack.w, packtile->boxpack.h, limit_gl_texture_size)) {
-        packtile->boxpack.w = smaller_power_of_2_limit(packtile->boxpack.w, limit_gl_texture_size);
-        packtile->boxpack.h = smaller_power_of_2_limit(packtile->boxpack.h, limit_gl_texture_size);
+      if (is_over_resolution_limit(packtile->boxpack.w, packtile->boxpack.h)) {
+        packtile->boxpack.w = smaller_power_of_2_limit(packtile->boxpack.w);
+        packtile->boxpack.h = smaller_power_of_2_limit(packtile->boxpack.h);
       }
       arraywidth = max_ii(arraywidth, packtile->boxpack.w);
       arrayheight = max_ii(arrayheight, packtile->boxpack.h);
@@ -188,7 +179,7 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima,
 
     LISTBASE_FOREACH (PackTile *, packtile, &packed) {
       ImageTile *tile = packtile->tile;
-      ImageTile_Run

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list