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
This commit is contained in:
Aras Pranckevicius 2024-04-03 17:12:46 +02:00 committed by Aras Pranckevicius
parent 4889aed8ac
commit b3ea1e75dc
2 changed files with 12 additions and 4 deletions

View File

@ -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;
}

View File

@ -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;