Proper mipmap size allocation for compressed textures Bug b/119620767 Change-Id: I2d0513ab4947e6794fb5122e625641ed1a7c84cb Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/28108 Tested-by: Alexis Hétu <sugoi@google.com> Reviewed-by: Nicolas Capens <nicolascapens@google.com>
diff --git a/src/Vulkan/VkImage.cpp b/src/Vulkan/VkImage.cpp index 4b559cf..afa5985 100644 --- a/src/Vulkan/VkImage.cpp +++ b/src/Vulkan/VkImage.cpp
@@ -375,10 +375,9 @@ int blockWidth = usedFormat.blockWidth(); int blockHeight = usedFormat.blockHeight(); - ASSERT(((extent.width % blockWidth) == 0) && ((extent.height % blockHeight) == 0)); // We can't offset within a block - - adjustedExtent.width /= blockWidth; - adjustedExtent.height /= blockHeight; + // Mip level allocations will round up to the next block for compressed texture + adjustedExtent.width = ((adjustedExtent.width + blockWidth - 1) / blockWidth); + adjustedExtent.height = ((adjustedExtent.height + blockHeight - 1) / blockHeight); } return adjustedExtent; } @@ -476,6 +475,12 @@ ASSERT((aspect & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) != (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)); VkExtent3D mipLevelExtent = getMipLevelExtent(mipLevel); + Format usedFormat = getFormat(aspect); + if(usedFormat.isCompressed()) + { + sw::align(mipLevelExtent.width, usedFormat.blockWidth()); + sw::align(mipLevelExtent.height, usedFormat.blockHeight()); + } return getFormat(aspect).sliceB(mipLevelExtent.width, mipLevelExtent.height, isCube() ? 1 : 0, true); }