diff options
author | Jeroen Bakker <jbakker> | 2021-09-08 10:52:06 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-09-08 10:56:13 +0300 |
commit | 2b2d427bbac6716092336f0d0f698706a390f4ad (patch) | |
tree | cd89cda1501ad4a499383569f33ba8c609e21d2e /source/blender/blenkernel/intern/image.c | |
parent | 54f5c174a8cf480d934f3be8ecc85c76537ad148 (diff) |
Fix T90825: Performance texture painting with limited scale.
Improve texture painting/uv editing performance when limited scale is active.
Cause of the slow down is that the image editor draws the image in maximum resolution,
but the 3d viewport uses the limited scale. The variation reuses the same GPU texture
and needed to be uploaded/scaled twice to the GPU.
This patch will adds texture slots that can hold the scaled down and the maximum
resolution image. This would allow better cache hits and reuse of existing caches.
Maximum resolution textures are reused for limited scale when they fit to reduce memory
and CPU footprint.
Reviewed By: fclem
Differential Revision: https://developer.blender.org/D12388
Diffstat (limited to 'source/blender/blenkernel/intern/image.c')
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 67 |
1 files changed, 41 insertions, 26 deletions
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index d87290e1eb4..966dd0595da 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -155,7 +155,9 @@ 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++) { - image_dst->gputexture[i][eye] = NULL; + for (int slot = 0; slot < IMA_TEXTURE_RESOLUTION_LEN; slot++) { + image_dst->gputexture[i][eye][slot] = NULL; + } } } @@ -208,9 +210,11 @@ static void image_foreach_cache(ID *id, for (int eye = 0; eye < 2; eye++) { for (int a = 0; a < TEXTARGET_COUNT; a++) { - key.offset_in_ID = offsetof(Image, gputexture[a][eye]); - key.cache_v = image->gputexture[a][eye]; - function_callback(id, &key, (void **)&image->gputexture[a][eye], 0, user_data); + for (int slot = 0; slot < IMA_TEXTURE_RESOLUTION_LEN; slot++) { + key.offset_in_ID = offsetof(Image, gputexture[a][eye][slot]); + key.cache_v = image->gputexture[a][eye]; + function_callback(id, &key, (void **)&image->gputexture[a][eye][slot], 0, user_data); + } } } @@ -239,7 +243,9 @@ static void image_blend_write(BlendWriter *writer, ID *id, const void *id_addres BLI_listbase_clear(&ima->gpu_refresh_areas); for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { - ima->gputexture[i][j] = NULL; + for (int slot = 0; slot < IMA_TEXTURE_RESOLUTION_LEN; slot++) { + ima->gputexture[i][j][slot] = NULL; + } } } @@ -677,8 +683,10 @@ bool BKE_image_has_opengl_texture(Image *ima) { for (int eye = 0; eye < 2; eye++) { for (int i = 0; i < TEXTARGET_COUNT; i++) { - if (ima->gputexture[i][eye] != NULL) { - return true; + for (int slot = 0; slot < IMA_TEXTURE_RESOLUTION_LEN; slot++) { + if (ima->gputexture[i][eye][slot] != NULL) { + return true; + } } } } @@ -3531,9 +3539,11 @@ static void image_free_tile(Image *ima, ImageTile *tile) } for (int eye = 0; eye < 2; eye++) { - if (ima->gputexture[i][eye] != NULL) { - GPU_texture_free(ima->gputexture[i][eye]); - ima->gputexture[i][eye] = NULL; + for (int slot = 0; slot < IMA_TEXTURE_RESOLUTION_LEN; slot++) { + if (ima->gputexture[i][eye][slot] != NULL) { + GPU_texture_free(ima->gputexture[i][eye][slot]); + ima->gputexture[i][eye][slot] = NULL; + } } } } @@ -3801,14 +3811,16 @@ ImageTile *BKE_image_add_tile(struct Image *ima, int tile_number, const char *la } for (int eye = 0; eye < 2; eye++) { - /* Reallocate GPU tile array. */ - if (ima->gputexture[TEXTARGET_2D_ARRAY][eye] != NULL) { - GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye]); - ima->gputexture[TEXTARGET_2D_ARRAY][eye] = NULL; - } - if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye] != NULL) { - GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye]); - ima->gputexture[TEXTARGET_TILE_MAPPING][eye] = NULL; + for (int slot = 0; slot < IMA_TEXTURE_RESOLUTION_LEN; slot++) { + /* Reallocate GPU tile array. */ + if (ima->gputexture[TEXTARGET_2D_ARRAY][eye][slot] != NULL) { + GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye][slot]); + ima->gputexture[TEXTARGET_2D_ARRAY][eye][slot] = NULL; + } + if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye][slot] != NULL) { + GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye][slot]); + ima->gputexture[TEXTARGET_TILE_MAPPING][eye][slot] = NULL; + } } } @@ -3863,14 +3875,17 @@ void BKE_image_reassign_tile(struct Image *ima, ImageTile *tile, int new_tile_nu } for (int eye = 0; eye < 2; eye++) { - /* Reallocate GPU tile array. */ - if (ima->gputexture[TEXTARGET_2D_ARRAY][eye] != NULL) { - GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye]); - ima->gputexture[TEXTARGET_2D_ARRAY][eye] = NULL; - } - if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye] != NULL) { - GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye]); - ima->gputexture[TEXTARGET_TILE_MAPPING][eye] = NULL; + for (int slot = 0; slot < IMA_TEXTURE_RESOLUTION_LEN; slot++) { + + /* Reallocate GPU tile array. */ + if (ima->gputexture[TEXTARGET_2D_ARRAY][eye][slot] != NULL) { + GPU_texture_free(ima->gputexture[TEXTARGET_2D_ARRAY][eye][slot]); + ima->gputexture[TEXTARGET_2D_ARRAY][eye][slot] = NULL; + } + if (ima->gputexture[TEXTARGET_TILE_MAPPING][eye][slot] != NULL) { + GPU_texture_free(ima->gputexture[TEXTARGET_TILE_MAPPING][eye][slot]); + ima->gputexture[TEXTARGET_TILE_MAPPING][eye][slot] = NULL; + } } } } |