From 7c41ae5b61fbe99678e1bf1c7e3a33c59306d84f Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Fri, 10 Apr 2026 22:18:35 -0500 Subject: [PATCH] clamp lower bound of mipmap width/height Prior to this commit, width/height values could be right-shifted to zero (when loading non-square textures). --- source/main.cpp | 7 ++++++- tutorial/docs/index.md | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index d33f52d..bdce8ba 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #define VMA_IMPLEMENTATION #include #define GLM_FORCE_RADIANS @@ -344,7 +345,11 @@ int main(int argc, char* argv[]) copyRegions.push_back({ .bufferOffset = mipOffset, .imageSubresource{.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .mipLevel = (uint32_t)j, .layerCount = 1}, - .imageExtent{.width = ktxTexture->baseWidth >> j, .height = ktxTexture->baseHeight >> j, .depth = 1 }, + .imageExtent{ + .width = std::max(1, ktxTexture->baseWidth >> j), + .height = std::max(1, ktxTexture->baseHeight >> j), + .depth = 1 + }, }); } vkCmdCopyBufferToImage(cbOneTime, imgSrcBuffer, textures[i].image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, static_cast(copyRegions.size()), copyRegions.data()); diff --git a/tutorial/docs/index.md b/tutorial/docs/index.md index 1879bf2..0c3b80a 100644 --- a/tutorial/docs/index.md +++ b/tutorial/docs/index.md @@ -868,7 +868,11 @@ for (auto j = 0; j < ktxTexture->numLevels; j++) { copyRegions.push_back({ .bufferOffset = mipOffset, .imageSubresource{.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, .mipLevel = (uint32_t)j, .layerCount = 1}, - .imageExtent{.width = ktxTexture->baseWidth >> j, .height = ktxTexture->baseHeight >> j, .depth = 1 }, + .imageExtent{ + .width = std::max(1, ktxTexture->baseWidth >> j), + .height = std::max(1, ktxTexture->baseHeight >> j), + .depth = 1 + }, }); } vkCmdCopyBufferToImage(cbOneTime, imgSrcBuffer, textures[i].image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, static_cast(copyRegions.size()), copyRegions.data());