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}.
This commit is contained in:
parent
da9e14b0b9
commit
f41c7723c9
Notes:
blender-bot
2023-04-11 09:09:03 +02:00
Referenced by issue #98375, GPU: Share GPU Textures when using the same file path. Referenced by pull request #106173, Image Editor: Remove drawing artifacts Referenced by issue #106092, Regression: Image Editor Speed & Quality Regression
|
@ -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);
|
||||
|
|
|
@ -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_RuntimeTextureSlot *tile_runtime = &tile->runtime.slots[resolution];
|
||||
ImageTile_Runtime *tile_runtime = &tile->runtime;
|
||||
int *tileoffset = tile_runtime->tilearray_offset;
|
||||
int *tilesize = tile_runtime->tilearray_size;
|
||||
|
||||
|
@ -210,7 +201,7 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima,
|
|||
|
||||
/* Upload each tile one by one. */
|
||||
LISTBASE_FOREACH (ImageTile *, tile, &ima->tiles) {
|
||||
ImageTile_RuntimeTextureSlot *tile_runtime = &tile->runtime.slots[resolution];
|
||||
ImageTile_Runtime *tile_runtime = &tile->runtime;
|
||||
int tilelayer = tile_runtime->tilearray_layer;
|
||||
int *tileoffset = tile_runtime->tilearray_offset;
|
||||
int *tilesize = tile_runtime->tilearray_size;
|
||||
|
@ -258,33 +249,16 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima,
|
|||
/** \name Regular gpu texture
|
||||
* \{ */
|
||||
|
||||
static bool image_max_resolution_texture_fits_in_limited_scale(Image *ima,
|
||||
eGPUTextureTarget textarget,
|
||||
const int multiview_eye)
|
||||
{
|
||||
BLI_assert_msg(U.glreslimit != 0,
|
||||
"limited scale function called without limited scale being set.");
|
||||
GPUTexture *max_resolution_texture =
|
||||
ima->gputexture[textarget][multiview_eye][IMA_TEXTURE_RESOLUTION_FULL];
|
||||
if (max_resolution_texture && GPU_texture_width(max_resolution_texture) <= U.glreslimit &&
|
||||
GPU_texture_height(max_resolution_texture) <= U.glreslimit) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static GPUTexture **get_image_gpu_texture_ptr(Image *ima,
|
||||
eGPUTextureTarget textarget,
|
||||
const int multiview_eye,
|
||||
const eImageTextureResolution texture_resolution)
|
||||
const int multiview_eye)
|
||||
{
|
||||
const bool in_range = (textarget >= 0) && (textarget < TEXTARGET_COUNT);
|
||||
BLI_assert(in_range);
|
||||
BLI_assert(ELEM(multiview_eye, 0, 1));
|
||||
const int resolution = (texture_resolution == IMA_TEXTURE_RESOLUTION_LIMITED) ? 1 : 0;
|
||||
|
||||
if (in_range) {
|
||||
return &(ima->gputexture[textarget][multiview_eye][resolution]);
|
||||
return &(ima->gputexture[textarget][multiview_eye]);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
@ -303,21 +277,6 @@ static GPUTexture *image_gpu_texture_error_create(eGPUTextureTarget textarget)
|
|||
}
|
||||
}
|
||||
|
||||
static void image_update_reusable_textures(Image *ima,
|
||||
eGPUTextureTarget textarget,
|
||||
const int multiview_eye)
|
||||
{
|
||||
if ((ima->gpuflag & IMA_GPU_HAS_LIMITED_SCALE_TEXTURES) == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ELEM(textarget, TEXTARGET_2D, TEXTARGET_2D_ARRAY)) {
|
||||
if (image_max_resolution_texture_fits_in_limited_scale(ima, textarget, multiview_eye)) {
|
||||
image_free_gpu_limited_scale(ima);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void image_gpu_texture_partial_update_changes_available(
|
||||
Image *image, PartialUpdateChecker<ImageTileData>::CollectResult &changes)
|
||||
{
|
||||
|
@ -412,14 +371,7 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
|
|||
if (current_view >= 2) {
|
||||
current_view = 0;
|
||||
}
|
||||
const bool limit_resolution = U.glreslimit != 0 &&
|
||||
((iuser && (iuser->flag & IMA_SHOW_MAX_RESOLUTION) == 0) ||
|
||||
(iuser == nullptr)) &&
|
||||
((ima->gpuflag & IMA_GPU_REUSE_MAX_RESOLUTION) == 0);
|
||||
const eImageTextureResolution texture_resolution = limit_resolution ?
|
||||
IMA_TEXTURE_RESOLUTION_LIMITED :
|
||||
IMA_TEXTURE_RESOLUTION_FULL;
|
||||
GPUTexture **tex = get_image_gpu_texture_ptr(ima, textarget, current_view, texture_resolution);
|
||||
GPUTexture **tex = get_image_gpu_texture_ptr(ima, textarget, current_view);
|
||||
if (*tex) {
|
||||
return *tex;
|
||||
}
|
||||
|
@ -443,11 +395,10 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
|
|||
}
|
||||
|
||||
if (textarget == TEXTARGET_2D_ARRAY) {
|
||||
*tex = gpu_texture_create_tile_array(ima, ibuf_intern, texture_resolution);
|
||||
*tex = gpu_texture_create_tile_array(ima, ibuf_intern);
|
||||
}
|
||||
else if (textarget == TEXTARGET_TILE_MAPPING) {
|
||||
*tex = gpu_texture_create_tile_mapping(
|
||||
ima, iuser ? iuser->multiview_eye : 0, texture_resolution);
|
||||
*tex = gpu_texture_create_tile_mapping(ima, iuser ? iuser->multiview_eye : 0);
|
||||
}
|
||||
else {
|
||||
const bool use_high_bitdepth = (ima->flag & IMA_HIGH_BITDEPTH);
|
||||
|
@ -455,7 +406,7 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
|
|||
ibuf_intern);
|
||||
|
||||
*tex = IMB_create_gpu_texture(
|
||||
ima->id.name + 2, ibuf_intern, use_high_bitdepth, store_premultiplied, limit_resolution);
|
||||
ima->id.name + 2, ibuf_intern, use_high_bitdepth, store_premultiplied);
|
||||
|
||||
if (*tex) {
|
||||
GPU_texture_wrap_mode(*tex, true, false);
|
||||
|
@ -473,20 +424,6 @@ static GPUTexture *image_get_gpu_texture(Image *ima,
|
|||
}
|
||||
}
|
||||
|
||||
switch (texture_resolution) {
|
||||
case IMA_TEXTURE_RESOLUTION_LIMITED:
|
||||
ima->gpuflag |= IMA_GPU_HAS_LIMITED_SCALE_TEXTURES;
|
||||
break;
|
||||
|
||||
case IMA_TEXTURE_RESOLUTION_FULL:
|
||||
image_update_reusable_textures(ima, textarget, current_view);
|
||||
break;
|
||||
|
||||
case IMA_TEXTURE_RESOLUTION_LEN:
|
||||
BLI_assert_unreachable();
|
||||
break;
|
||||
}
|
||||
|
||||
if (*tex) {
|
||||
GPU_texture_orig_size_set(*tex, ibuf_intern->x, ibuf_intern->y);
|
||||
}
|
||||
|
@ -558,39 +495,22 @@ static void image_free_gpu(Image *ima, const bool immediate)
|
|||
{
|
||||
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) {
|
||||
if (immediate) {
|
||||
GPU_texture_free(ima->gputexture[i][eye][resolution]);
|
||||
}
|
||||
else {
|
||||
BLI_mutex_lock(&gpu_texture_queue_mutex);
|
||||
BLI_linklist_prepend(&gpu_texture_free_queue, ima->gputexture[i][eye][resolution]);
|
||||
BLI_mutex_unlock(&gpu_texture_queue_mutex);
|
||||
}
|
||||
|
||||
ima->gputexture[i][eye][resolution] = nullptr;
|
||||
if (ima->gputexture[i][eye] != nullptr) {
|
||||
if (immediate) {
|
||||
GPU_texture_free(ima->gputexture[i][eye]);
|
||||
}
|
||||
else {
|
||||
BLI_mutex_lock(&gpu_texture_queue_mutex);
|
||||
BLI_linklist_prepend(&gpu_texture_free_queue, ima->gputexture[i][eye]);
|
||||
BLI_mutex_unlock(&gpu_texture_queue_mutex);
|
||||
}
|
||||
|
||||
ima->gputexture[i][eye] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ima->gpuflag &= ~(IMA_GPU_MIPMAP_COMPLETE | IMA_GPU_HAS_LIMITED_SCALE_TEXTURES);
|
||||
}
|
||||
|
||||
static void image_free_gpu_limited_scale(Image *ima)
|
||||
{
|
||||
const eImageTextureResolution resolution = IMA_TEXTURE_RESOLUTION_LIMITED;
|
||||
for (int eye = 0; eye < 2; eye++) {
|
||||
for (int i = 0; i < TEXTARGET_COUNT; i++) {
|
||||
if (ima->gputexture[i][eye][resolution] != nullptr) {
|
||||
GPU_texture_free(ima->gputexture[i][eye][resolution]);
|
||||
ima->gputexture[i][eye][resolution] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ima->gpuflag &= ~(IMA_GPU_MIPMAP_COMPLETE | IMA_GPU_HAS_LIMITED_SCALE_TEXTURES);
|
||||
ima->gpuflag &= ~IMA_GPU_MIPMAP_COMPLETE;
|
||||
}
|
||||
|
||||
void BKE_image_free_gputextures(Image *ima)
|
||||
|
@ -767,20 +687,12 @@ static void gpu_texture_update_unscaled(GPUTexture *tex,
|
|||
GPU_unpack_row_length_set(0);
|
||||
}
|
||||
|
||||
static void gpu_texture_update_from_ibuf(GPUTexture *tex,
|
||||
Image *ima,
|
||||
ImBuf *ibuf,
|
||||
ImageTile *tile,
|
||||
int x,
|
||||
int y,
|
||||
int w,
|
||||
int h,
|
||||
eImageTextureResolution texture_resolution)
|
||||
static void gpu_texture_update_from_ibuf(
|
||||
GPUTexture *tex, Image *ima, ImBuf *ibuf, ImageTile *tile, int x, int y, int w, int h)
|
||||
{
|
||||
const int resolution = texture_resolution == IMA_TEXTURE_RESOLUTION_LIMITED ? 1 : 0;
|
||||
bool scaled;
|
||||
if (tile != nullptr) {
|
||||
ImageTile_RuntimeTextureSlot *tile_runtime = &tile->runtime.slots[resolution];
|
||||
ImageTile_Runtime *tile_runtime = &tile->runtime;
|
||||
int *tilesize = tile_runtime->tilearray_size;
|
||||
scaled = (ibuf->x != tilesize[0]) || (ibuf->y != tilesize[1]);
|
||||
}
|
||||
|
@ -845,7 +757,7 @@ static void gpu_texture_update_from_ibuf(GPUTexture *tex,
|
|||
if (scaled) {
|
||||
/* Slower update where we first have to scale the input pixels. */
|
||||
if (tile != nullptr) {
|
||||
ImageTile_RuntimeTextureSlot *tile_runtime = &tile->runtime.slots[resolution];
|
||||
ImageTile_Runtime *tile_runtime = &tile->runtime;
|
||||
int *tileoffset = tile_runtime->tilearray_offset;
|
||||
int *tilesize = tile_runtime->tilearray_size;
|
||||
int tilelayer = tile_runtime->tilearray_layer;
|
||||
|
@ -860,7 +772,7 @@ static void gpu_texture_update_from_ibuf(GPUTexture *tex,
|
|||
else {
|
||||
/* Fast update at same resolution. */
|
||||
if (tile != nullptr) {
|
||||
ImageTile_RuntimeTextureSlot *tile_runtime = &tile->runtime.slots[resolution];
|
||||
ImageTile_Runtime *tile_runtime = &tile->runtime;
|
||||
int *tileoffset = tile_runtime->tilearray_offset;
|
||||
int tilelayer = tile_runtime->tilearray_layer;
|
||||
gpu_texture_update_unscaled(
|
||||
|
@ -894,19 +806,16 @@ static void image_update_gputexture_ex(
|
|||
Image *ima, ImageTile *tile, ImBuf *ibuf, int x, int y, int w, int h)
|
||||
{
|
||||
const int eye = 0;
|
||||
for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
|
||||
GPUTexture *tex = ima->gputexture[TEXTARGET_2D][eye][resolution];
|
||||
eImageTextureResolution texture_resolution = static_cast<eImageTextureResolution>(resolution);
|
||||
/* Check if we need to update the main gputexture. */
|
||||
if (tex != nullptr && tile == ima->tiles.first) {
|
||||
gpu_texture_update_from_ibuf(tex, ima, ibuf, nullptr, x, y, w, h, texture_resolution);
|
||||
}
|
||||
GPUTexture *tex = ima->gputexture[TEXTARGET_2D][eye];
|
||||
/* Check if we need to update the main gputexture. */
|
||||
if (tex != nullptr && tile == ima->tiles.first) {
|
||||
gpu_texture_update_from_ibuf(tex, ima, ibuf, nullptr, x, y, w, h);
|
||||
}
|
||||
|
||||
/* Check if we need to update the array gputexture. */
|
||||
tex = ima->gputexture[TEXTARGET_2D_ARRAY][eye][resolution];
|
||||
if (tex != nullptr) {
|
||||
gpu_texture_update_from_ibuf(tex, ima, ibuf, tile, x, y, w, h, texture_resolution);
|
||||
}
|
||||
/* Check if we need to update the array gputexture. */
|
||||
tex = ima->gputexture[TEXTARGET_2D_ARRAY][eye];
|
||||
if (tex != nullptr) {
|
||||
gpu_texture_update_from_ibuf(tex, ima, ibuf, tile, x, y, w, h);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -946,11 +855,9 @@ void BKE_image_paint_set_mipmap(Main *bmain, bool mipmap)
|
|||
for (int a = 0; a < TEXTARGET_COUNT; a++) {
|
||||
if (ELEM(a, TEXTARGET_2D, TEXTARGET_2D_ARRAY)) {
|
||||
for (int eye = 0; eye < 2; eye++) {
|
||||
for (int resolution = 0; resolution < IMA_TEXTURE_RESOLUTION_LEN; resolution++) {
|
||||
GPUTexture *tex = ima->gputexture[a][eye][resolution];
|
||||
if (tex != nullptr) {
|
||||
GPU_texture_mipmap_mode(tex, mipmap, true);
|
||||
}
|
||||
GPUTexture *tex = ima->gputexture[a][eye];
|
||||
if (tex != nullptr) {
|
||||
GPU_texture_mipmap_mode(tex, mipmap, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2085,8 +2085,7 @@ GPUTexture *BKE_movieclip_get_gpu_texture(MovieClip *clip, MovieClipUser *cuser)
|
|||
/* This only means RGBA16F instead of RGBA32F. */
|
||||
const bool high_bitdepth = false;
|
||||
const bool store_premultiplied = ibuf->rect_float ? false : true;
|
||||
*tex = IMB_create_gpu_texture(
|
||||
clip->id.name + 2, ibuf, high_bitdepth, store_premultiplied, false);
|
||||
*tex = IMB_create_gpu_texture(clip->id.name + 2, ibuf, high_bitdepth, store_premultiplied);
|
||||
|
||||
/* Do not generate mips for movieclips... too slow. */
|
||||
GPU_texture_mipmap_mode(*tex, false, true);
|
||||
|
|
|
@ -1666,13 +1666,8 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
|
|||
LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
|
||||
LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
|
||||
LISTBASE_FOREACH (SpaceLink *, space, &area->spacedata) {
|
||||
/* UV/Image Max resolution images in image editor. */
|
||||
if (space->spacetype == SPACE_IMAGE) {
|
||||
SpaceImage *sima = (SpaceImage *)space;
|
||||
sima->iuser.flag |= IMA_SHOW_MAX_RESOLUTION;
|
||||
}
|
||||
/* Enable Outliner render visibility column. */
|
||||
else if (space->spacetype == SPACE_OUTLINER) {
|
||||
if (space->spacetype == SPACE_OUTLINER) {
|
||||
SpaceOutliner *space_outliner = (SpaceOutliner *)space;
|
||||
space_outliner->show_restrict_flags |= SO_RESTRICT_RENDER;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,7 @@ static SpaceLink *image_create(const ScrArea *UNUSED(area), const Scene *UNUSED(
|
|||
simage->overlay.flag = SI_OVERLAY_SHOW_OVERLAYS | SI_OVERLAY_SHOW_GRID_BACKGROUND;
|
||||
|
||||
BKE_imageuser_default(&simage->iuser);
|
||||
simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS | IMA_SHOW_MAX_RESOLUTION;
|
||||
simage->iuser.flag = IMA_SHOW_STEREO | IMA_ANIM_ALWAYS;
|
||||
|
||||
BKE_scopes_new(&simage->scopes);
|
||||
simage->sample_line_hist.height = 100;
|
||||
|
|
|
@ -35,7 +35,7 @@ int GPU_max_compute_shader_storage_blocks(void);
|
|||
int GPU_extensions_len(void);
|
||||
const char *GPU_extension_get(int i);
|
||||
|
||||
int GPU_texture_size_with_limit(int res, bool limit_gl_texture_size);
|
||||
int GPU_texture_size_with_limit(int res);
|
||||
|
||||
bool GPU_mip_render_workaround(void);
|
||||
bool GPU_depth_blitting_workaround(void);
|
||||
|
|
|
@ -33,11 +33,10 @@ int GPU_max_texture_size()
|
|||
return GCaps.max_texture_size;
|
||||
}
|
||||
|
||||
int GPU_texture_size_with_limit(int res, bool limit_gl_texture_size)
|
||||
int GPU_texture_size_with_limit(int res)
|
||||
{
|
||||
int size = GPU_max_texture_size();
|
||||
int reslimit = (limit_gl_texture_size && (U.glreslimit != 0)) ? min_ii(U.glreslimit, size) :
|
||||
size;
|
||||
int reslimit = (U.glreslimit != 0) ? min_ii(U.glreslimit, size) : size;
|
||||
return min_ii(reslimit, res);
|
||||
}
|
||||
|
||||
|
|
|
@ -936,8 +936,7 @@ const char *IMB_ffmpeg_last_error(void);
|
|||
struct GPUTexture *IMB_create_gpu_texture(const char *name,
|
||||
struct ImBuf *ibuf,
|
||||
bool use_high_bitdepth,
|
||||
bool use_premult,
|
||||
bool limit_gl_texture_size);
|
||||
bool use_premult);
|
||||
/**
|
||||
* The `ibuf` is only here to detect the storage type. The produced texture will have undefined
|
||||
* content. It will need to be populated by using #IMB_update_gpu_texture_sub().
|
||||
|
|
|
@ -197,12 +197,10 @@ void IMB_update_gpu_texture_sub(GPUTexture *tex,
|
|||
GPUTexture *IMB_create_gpu_texture(const char *name,
|
||||
ImBuf *ibuf,
|
||||
bool use_high_bitdepth,
|
||||
bool use_premult,
|
||||
bool limit_gl_texture_size)
|
||||
bool use_premult)
|
||||
{
|
||||
GPUTexture *tex = NULL;
|
||||
int size[2] = {GPU_texture_size_with_limit(ibuf->x, limit_gl_texture_size),
|
||||
GPU_texture_size_with_limit(ibuf->y, limit_gl_texture_size)};
|
||||
int size[2] = {GPU_texture_size_with_limit(ibuf->x), GPU_texture_size_with_limit(ibuf->y)};
|
||||
bool do_rescale = (ibuf->x != size[0]) || (ibuf->y != size[1]);
|
||||
|
||||
#ifdef WITH_DDS
|
||||
|
|
|
@ -80,17 +80,11 @@ typedef struct RenderSlot {
|
|||
struct RenderResult *render;
|
||||
} RenderSlot;
|
||||
|
||||
typedef struct ImageTile_RuntimeTextureSlot {
|
||||
typedef struct ImageTile_Runtime {
|
||||
int tilearray_layer;
|
||||
int _pad;
|
||||
int tilearray_offset[2];
|
||||
int tilearray_size[2];
|
||||
} ImageTile_RuntimeTextureSlot;
|
||||
|
||||
typedef struct ImageTile_Runtime {
|
||||
/* Data per `eImageTextureResolution`.
|
||||
* Should match `IMA_TEXTURE_RESOLUTION_LEN` */
|
||||
ImageTile_RuntimeTextureSlot slots[2];
|
||||
} ImageTile_Runtime;
|
||||
|
||||
typedef struct ImageTile {
|
||||
|
@ -109,10 +103,7 @@ typedef struct ImageTile {
|
|||
/* #define IMA_UNUSED_2 (1 << 2) */
|
||||
#define IMA_NEED_FRAME_RECALC (1 << 3)
|
||||
#define IMA_SHOW_STEREO (1 << 4)
|
||||
/* Do not limit the resolution by the limit texture size option in the user preferences.
|
||||
* Images in the image editor or used as a backdrop are always shown using the maximum
|
||||
* possible resolution. */
|
||||
#define IMA_SHOW_MAX_RESOLUTION (1 << 5)
|
||||
/* #define IMA_UNUSED_5 (1 << 5) */
|
||||
|
||||
/* Used to get the correct gpu texture from an Image datablock. */
|
||||
typedef enum eGPUTextureTarget {
|
||||
|
@ -122,15 +113,6 @@ typedef enum eGPUTextureTarget {
|
|||
TEXTARGET_COUNT,
|
||||
} eGPUTextureTarget;
|
||||
|
||||
/* Resolution variations that can be cached for an image. */
|
||||
typedef enum eImageTextureResolution {
|
||||
IMA_TEXTURE_RESOLUTION_FULL = 0,
|
||||
IMA_TEXTURE_RESOLUTION_LIMITED,
|
||||
|
||||
/* Not an option, but holds the number of options defined for this struct. */
|
||||
IMA_TEXTURE_RESOLUTION_LEN
|
||||
} eImageTextureResolution;
|
||||
|
||||
/* Defined in BKE_image.h. */
|
||||
struct PartialUpdateRegister;
|
||||
struct PartialUpdateUser;
|
||||
|
@ -155,8 +137,8 @@ typedef struct Image {
|
|||
|
||||
/** Not written in file. */
|
||||
struct MovieCache *cache;
|
||||
/** Not written in file 3 = TEXTARGET_COUNT, 2 = stereo eyes, 2 = IMA_TEXTURE_RESOLUTION_LEN. */
|
||||
struct GPUTexture *gputexture[3][2][2];
|
||||
/** Not written in file 3 = TEXTARGET_COUNT, 2 = stereo eyes. */
|
||||
struct GPUTexture *gputexture[3][2];
|
||||
|
||||
/* sources from: */
|
||||
ListBase anims;
|
||||
|
@ -244,11 +226,6 @@ enum {
|
|||
enum {
|
||||
/** All mipmap levels in OpenGL texture set? */
|
||||
IMA_GPU_MIPMAP_COMPLETE = (1 << 0),
|
||||
/* Reuse the max resolution textures as they fit in the limited scale. */
|
||||
IMA_GPU_REUSE_MAX_RESOLUTION = (1 << 1),
|
||||
/* Has any limited scale textures been allocated.
|
||||
* Adds additional checks to reuse max resolution images when they fit inside limited scale. */
|
||||
IMA_GPU_HAS_LIMITED_SCALE_TEXTURES = (1 << 2),
|
||||
};
|
||||
|
||||
/* Image.source, where the image comes from */
|
||||
|
|
|
@ -397,7 +397,7 @@ static void rna_Image_resolution_set(PointerRNA *ptr, const float *values)
|
|||
static int rna_Image_bindcode_get(PointerRNA *ptr)
|
||||
{
|
||||
Image *ima = (Image *)ptr->data;
|
||||
GPUTexture *tex = ima->gputexture[TEXTARGET_2D][0][IMA_TEXTURE_RESOLUTION_FULL];
|
||||
GPUTexture *tex = ima->gputexture[TEXTARGET_2D][0];
|
||||
return (tex) ? GPU_texture_opengl_bindcode(tex) : 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -198,7 +198,7 @@ static int rna_Image_gl_touch(
|
|||
|
||||
BKE_image_tag_time(image);
|
||||
|
||||
if (image->gputexture[TEXTARGET_2D][0][IMA_TEXTURE_RESOLUTION_FULL] == NULL) {
|
||||
if (image->gputexture[TEXTARGET_2D][0] == NULL) {
|
||||
error = rna_Image_gl_load(image, reports, frame, layer_index, pass_index);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue