[Bf-blender-cvs] [5f6fb5bb41e] master: Cleanup: Split gpu_texture_image.c into BKE and IMB modules

Clément Foucault noreply at git.blender.org
Wed Jul 29 23:06:47 CEST 2020


Commit: 5f6fb5bb41ed0057f0e2f0ccded717fbf04e55e2
Author: Clément Foucault
Date:   Wed Jul 29 18:13:19 2020 +0200
Branches: master
https://developer.blender.org/rB5f6fb5bb41ed0057f0e2f0ccded717fbf04e55e2

Cleanup: Split gpu_texture_image.c into BKE and IMB modules

This is in order to disolve GPU_draw.h into more meaningful code blocks.

All the Image related function are in `image_gpu.c`.
All the MovieClip related function are in `movieclip.c`.

The IMB module now has a connection with GPU. This is not strickly
necessary and the code could be move to `image_gpu.c` if needed.

The Image garbage collection is also ported to `image_gpu.c`.

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

M	source/blender/blenkernel/BKE_image.h
M	source/blender/blenkernel/BKE_movieclip.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/image.c
R063	source/blender/gpu/intern/gpu_texture_image.c	source/blender/blenkernel/intern/image_gpu.c
M	source/blender/blenkernel/intern/movieclip.c
M	source/blender/draw/engines/eevee/eevee_engine.c
M	source/blender/draw/engines/gpencil/gpencil_draw_data.c
M	source/blender/draw/engines/overlay/overlay_image.c
M	source/blender/draw/engines/overlay/overlay_paint.c
M	source/blender/draw/engines/workbench/workbench_materials.c
M	source/blender/draw/intern/draw_manager_data.c
M	source/blender/editors/object/object_bake.c
M	source/blender/editors/object/object_bake_api.c
M	source/blender/editors/sculpt_paint/paint_image.c
M	source/blender/editors/sculpt_paint/paint_image_2d.c
M	source/blender/editors/sculpt_paint/paint_image_proj.c
M	source/blender/editors/space_image/image_ops.c
M	source/blender/editors/space_image/image_undo.c
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_draw.h
M	source/blender/gpu/GPU_extensions.h
M	source/blender/gpu/GPU_state.h
M	source/blender/gpu/GPU_texture.h
M	source/blender/gpu/intern/gpu_extensions.cc
M	source/blender/gpu/intern/gpu_shader_builtin.c
M	source/blender/gpu/intern/gpu_state.cc
M	source/blender/gpu/intern/gpu_texture.cc
M	source/blender/imbuf/CMakeLists.txt
M	source/blender/imbuf/IMB_imbuf.h
A	source/blender/imbuf/intern/util_gpu.c
M	source/blender/makesrna/intern/rna_image.c
M	source/blender/makesrna/intern/rna_image_api.c
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/windowmanager/intern/wm_draw.c
M	source/blender/windowmanager/intern/wm_init_exit.c

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

diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h
index 1e5573ab014..c5221baf7d7 100644
--- a/source/blender/blenkernel/BKE_image.h
+++ b/source/blender/blenkernel/BKE_image.h
@@ -55,6 +55,7 @@ void BKE_image_free_packedfiles(struct Image *image);
 void BKE_image_free_views(struct Image *image);
 void BKE_image_free_buffers(struct Image *image);
 void BKE_image_free_buffers_ex(struct Image *image, bool do_lock);
+void BKE_image_free_gputextures(struct Image *ima);
 /* call from library */
 void BKE_image_free(struct Image *image);
 
@@ -274,6 +275,10 @@ void BKE_image_free_anim_ibufs(struct Image *ima, int except_frame);
 /* does all images with type MOVIE or SEQUENCE */
 void BKE_image_all_free_anim_ibufs(struct Main *bmain, int except_frame);
 
+void BKE_image_free_all_gputextures(struct Main *bmain);
+void BKE_image_free_anim_gputextures(struct Main *bmain);
+void BKE_image_free_old_gputextures(struct Main *bmain);
+
 bool BKE_image_memorypack(struct Image *ima);
 void BKE_image_packfiles(struct ReportList *reports, struct Image *ima, const char *basepath);
 void BKE_image_packfiles_from_mem(struct ReportList *reports,
@@ -362,6 +367,30 @@ bool BKE_image_has_loaded_ibuf(struct Image *image);
 struct ImBuf *BKE_image_get_ibuf_with_name(struct Image *image, const char *name);
 struct ImBuf *BKE_image_get_first_ibuf(struct Image *image);
 
+/* Not to be use directly. */
+struct GPUTexture *BKE_image_create_gpu_texture_from_ibuf(struct Image *image, struct ImBuf *ibuf);
+
+/* Get the GPUTexture for a given `Image`.
+ *
+ * `iuser` and `ibuf` are mutual exclusive parameters. The caller can pass the `ibuf` when already
+ * available. It is also required when requesting the GPUTexture for a render result. */
+struct GPUTexture *BKE_image_get_gpu_texture(struct Image *image,
+                                             struct ImageUser *iuser,
+                                             struct ImBuf *ibuf);
+struct GPUTexture *BKE_image_get_gpu_tiles(struct Image *image,
+                                           struct ImageUser *iuser,
+                                           struct ImBuf *ibuf);
+struct GPUTexture *BKE_image_get_gpu_tilemap(struct Image *image,
+                                             struct ImageUser *iuser,
+                                             struct ImBuf *ibuf);
+
+void BKE_image_update_gputexture(
+    struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h);
+void BKE_image_paint_set_mipmap(struct Main *bmain, bool mipmap);
+
+/* Delayed free of OpenGL buffers by main thread */
+void BKE_image_free_unused_gpu_textures(void);
+
 struct RenderSlot *BKE_image_add_renderslot(struct Image *ima, const char *name);
 bool BKE_image_remove_renderslot(struct Image *ima, struct ImageUser *iuser, int slot);
 struct RenderSlot *BKE_image_get_renderslot(struct Image *ima, int slot);
diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h
index dbd6eb15bf2..bba01dd84d2 100644
--- a/source/blender/blenkernel/BKE_movieclip.h
+++ b/source/blender/blenkernel/BKE_movieclip.h
@@ -113,6 +113,11 @@ bool BKE_movieclip_put_frame_if_possible(struct MovieClip *clip,
                                          struct MovieClipUser *user,
                                          struct ImBuf *ibuf);
 
+struct GPUTexture *BKE_movieclip_get_gpu_texture(struct MovieClip *clip,
+                                                 struct MovieClipUser *cuser);
+
+void BKE_movieclip_free_gputexture(struct MovieClip *clip);
+
 /* Dependency graph evaluation. */
 
 void BKE_movieclip_eval_update(struct Depsgraph *depsgraph,
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index d702da55ea8..95f06d02055 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -134,6 +134,7 @@ set(SRC
   intern/idtype.c
   intern/image.c
   intern/image_gen.c
+  intern/image_gpu.c
   intern/image_save.c
   intern/ipo.c
   intern/kelvinlet.c
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 042a5233978..fa0be9ea441 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -90,7 +90,6 @@
 
 #include "RE_pipeline.h"
 
-#include "GPU_draw.h"
 #include "GPU_texture.h"
 
 #include "BLI_sys_types.h"  // for intptr_t support
@@ -393,7 +392,7 @@ void BKE_image_free_buffers_ex(Image *ima, bool do_lock)
     ima->rr = NULL;
   }
 
-  GPU_free_image(ima);
+  BKE_image_free_gputextures(ima);
 
   LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
     tile->ok = IMA_OK;
diff --git a/source/blender/gpu/intern/gpu_texture_image.c b/source/blender/blenkernel/intern/image_gpu.c
similarity index 63%
rename from source/blender/gpu/intern/gpu_texture_image.c
rename to source/blender/blenkernel/intern/image_gpu.c
index aa0637c2c3f..b02b6e1453c 100644
--- a/source/blender/gpu/intern/gpu_texture_image.c
+++ b/source/blender/blenkernel/intern/image_gpu.c
@@ -13,36 +13,24 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
  * All rights reserved.
  */
 
 /** \file
- * \ingroup gpu
- *
- * Utility functions for dealing with OpenGL texture & material context,
- * mipmap generation and light objects.
- *
- * These are some obscure rendering functions shared between the game engine (not anymore)
- * and the blender, in this module to avoid duplication
- * and abstract them away from the rest a bit.
+ * \ingroup bke
  */
 
-#include <string.h>
+#include "MEM_guardedalloc.h"
 
-#include "BLI_blenlib.h"
 #include "BLI_boxpack_2d.h"
 #include "BLI_linklist.h"
-#include "BLI_math.h"
+#include "BLI_listbase.h"
 #include "BLI_threads.h"
-#include "BLI_utildefines.h"
 
 #include "DNA_image_types.h"
-#include "DNA_movieclip_types.h"
 #include "DNA_userdef_types.h"
 
-#include "MEM_guardedalloc.h"
-
 #include "IMB_colormanagement.h"
 #include "IMB_imbuf.h"
 #include "IMB_imbuf_types.h"
@@ -50,218 +38,31 @@
 #include "BKE_global.h"
 #include "BKE_image.h"
 #include "BKE_main.h"
-#include "BKE_movieclip.h"
 
-#include "GPU_draw.h"
 #include "GPU_extensions.h"
+#include "GPU_state.h"
 #include "GPU_texture.h"
 
 #include "PIL_time.h"
 
-static void gpu_free_image(Image *ima, const bool immediate);
+/* Prototypes. */
 static void gpu_free_unused_buffers(void);
-
-/** \} */
+static void image_free_gpu(Image *ima, const bool immediate);
 
 /* -------------------------------------------------------------------- */
-/** \name Utility functions
+/** \name UDIM gpu texture
  * \{ */
 
-/** Checking powers of two for images since OpenGL ES requires it */
-#ifdef WITH_DDS
-static bool is_power_of_2_resolution(int w, int h)
-{
-  return is_power_of_2_i(w) && is_power_of_2_i(h);
-}
-#endif
-
 static bool is_over_resolution_limit(int w, int h)
 {
-  int size = GPU_max_texture_size();
-  int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, size) : size;
-
-  return (w > reslimit || h > reslimit);
+  return (w > GPU_texture_size_with_limit(w) || h > GPU_texture_size_with_limit(h));
 }
 
 static int smaller_power_of_2_limit(int num)
 {
-  int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, GPU_max_texture_size()) :
-                                       GPU_max_texture_size();
-  /* take texture clamping into account */
-  if (num > reslimit) {
-    return reslimit;
-  }
-
-  return power_of_2_min_i(num);
-}
-
-static GPUTexture **gpu_get_image_gputexture(Image *ima,
-                                             eGPUTextureTarget textarget,
-                                             const int multiview_eye)
-{
-  const bool in_range = (textarget >= 0) && (textarget < TEXTARGET_COUNT);
-  BLI_assert(in_range);
-
-  if (in_range) {
-    return &(ima->gputexture[textarget][multiview_eye]);
-  }
-  return NULL;
-}
-
-static GPUTexture **gpu_get_movieclip_gputexture(MovieClip *clip,
-                                                 MovieClipUser *cuser,
-                                                 eGPUTextureTarget textarget)
-{
-  LISTBASE_FOREACH (MovieClip_RuntimeGPUTexture *, tex, &clip->runtime.gputextures) {
-    if (memcmp(&tex->user, cuser, sizeof(MovieClipUser)) == 0) {
-      if (tex == NULL) {
-        tex = (MovieClip_RuntimeGPUTexture *)MEM_mallocN(sizeof(MovieClip_RuntimeGPUTexture),
-                                                         __func__);
-
-        for (int i = 0; i < TEXTARGET_COUNT; i++) {
-          tex->gputexture[i] = NULL;
-        }
-
-        memcpy(&tex->user, cuser, sizeof(MovieClipUser));
-        BLI_addtail(&clip->runtime.gputextures, tex);
-      }
-
-      return &tex->gputexture[textarget];
-    }
-  }
-  return NULL;
-}
-
-/**
- * Apply colormanagement and scale buffer if needed.
- * *r_freedata is set to true if the returned buffer need to be manually freed.
- **/
-static void *IMB_gpu_get_data(const ImBuf *ibuf,
-                              const bool do_rescale,
-                              const int rescale_size[2],
-                              const bool compress_as_srgb,
-                              const bool store_premultiplied,
-                              bool *r_freedata)
-{
-  const bool is_float_rect = (ibuf->rect_float != NULL);
-  void *data_rect = (is_float_rect) ? (void *)ibuf->rect_float : (void *)ibuf->rect;
-
-  if (is_float_rect) {
-    /* Float image is already in scene linear colorspace or non-color data by
-     * convention, no colorspace conversion needed. But we do require 4 channels
-     * currently. */
-    if (ibuf->channels != 4 || !store_premultiplied) {
-      data_rect = MEM_mallocN(sizeof(float) * 4 * ibuf->x * ibuf->y, __func__);
-      *r_freedata = true;
-
-      if (data_rect == NULL) {
-        return NULL;
-      }
-
-      IMB_colormanagement_imbuf_to_float_texture(
-          (float *)data_rect, 0, 0, ibuf->x, ibuf->y, ibuf, store_premultiplied);
-    }
-  }
-  else {
-    /* Byte image 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list