From b3ea1e75dc7147addafe08af78a1f11d8e263ebc Mon Sep 17 00:00:00 2001 From: Aras Pranckevicius Date: Wed, 3 Apr 2024 17:12:46 +0200 Subject: [PATCH] Cleanup: comment why DDS DXT/S3TC needs power of two sizes, and clearer log message It is not immediately clear why DDS compressed (DXT/S3TC) textures need to be power of two in size (since nothing in DXT/S3TC intrinsically requires that). It is only needed due to the "flip the texture upside down" dance that we do for DDS at load time. While at it, when logging DXT related messages, tell which texture was it for, and dimensions. This changes logs like: ``` Unable to load non-power-of-two DXT image resolution, falling back to uncompressed. Unable to load non-power-of-two DXT image resolution, falling back to uncompressed. Unable to find a suitable DXT compression, falling back to uncompressed. ``` Into: ``` Unable to load non-power-of-two DXT image resolution, falling back to uncompressed (281splash-dxt1-mips.dds, 890x501). Unable to load non-power-of-two DXT image resolution, falling back to uncompressed (281splash-dxt5-mips.dds, 890x501). Unable to find a suitable DXT compression, falling back to uncompressed (281splash-rgba8-mips.dds, 890x501). ``` Pull Request: https://projects.blender.org/blender/blender/pulls/120210 --- source/blender/imbuf/intern/format_dds.cc | 10 +++++++--- source/blender/imbuf/intern/util_gpu.cc | 6 +++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/source/blender/imbuf/intern/format_dds.cc b/source/blender/imbuf/intern/format_dds.cc index be3e7341be2..e5e27746bab 100644 --- a/source/blender/imbuf/intern/format_dds.cc +++ b/source/blender/imbuf/intern/format_dds.cc @@ -1,5 +1,5 @@ /* SPDX-FileCopyrightText: 2009 Google Inc. All rights reserved. (BSD-3-Clause) - * SPDX-FileCopyrightText: 2023 Blender Authors (GPL-2.0-or-later). + * SPDX-FileCopyrightText: 2023-2024 Blender Authors (GPL-2.0-or-later). * * SPDX-License-Identifier: GPL-2.0-or-later AND BSD-3-Clause */ @@ -18,6 +18,7 @@ #include "IMB_filetype.hh" #include "IMB_imbuf_types.hh" +#include "BLI_math_base.h" #include "BLI_path_util.h" #include "BLI_string.h" @@ -209,8 +210,11 @@ static void FlipDXTCImage(ImBuf *ibuf) if (width == 0 || height == 0) { return; } - /* Height must be a power-of-two. */ - if ((height & (height - 1)) != 0) { + /* Height must be a power-of-two: not because something within DXT/S3TC + * needs it. Only because we want to flip the image upside down, by + * swapping and flipping block rows, and that in general case (with mipmaps) + * is only possible for POT height. */ + if (!is_power_of_2_i(height)) { return; } diff --git a/source/blender/imbuf/intern/util_gpu.cc b/source/blender/imbuf/intern/util_gpu.cc index ad03ec75678..0414821863a 100644 --- a/source/blender/imbuf/intern/util_gpu.cc +++ b/source/blender/imbuf/intern/util_gpu.cc @@ -335,6 +335,10 @@ GPUTexture *IMB_create_gpu_texture(const char *name, fprintf(stderr, "Unable to load DXT image resolution,"); } else if (!is_power_of_2_i(ibuf->x) || !is_power_of_2_i(ibuf->y)) { + /* We require POT DXT/S3TC texture sizes not because something in there + * intrinsically needs it, but because we flip them upside down at + * load time, and that (when mipmaps are involved) is only possible + * with POT height. */ fprintf(stderr, "Unable to load non-power-of-two DXT image resolution,"); } else { @@ -353,7 +357,7 @@ GPUTexture *IMB_create_gpu_texture(const char *name, fprintf(stderr, "ST3C support not found,"); } /* Fallback to uncompressed texture. */ - fprintf(stderr, " falling back to uncompressed.\n"); + fprintf(stderr, " falling back to uncompressed (%s, %ix%i).\n", name, ibuf->x, ibuf->y); } eGPUTextureFormat tex_format;