From 5ef9c552b2e72e727b6c4b4994e727ffa9c72bbd Mon Sep 17 00:00:00 2001 From: Frank Binns Date: Tue, 12 Mar 2024 10:39:35 +0000 Subject: [PATCH] pvr: fix image size calculation when mipLevels is 1 When calculating the size of an image, the driver was always factoring in space for a full mip chain. However, this isn't necessary when mipLevels is 1 and this resulted in applications needing to allocate more memory for these images than is strictly necessary. Fix this by calculating the size of additional mip levels (those greater than mipLevels) when more than 1 mip level has been requested. Fixes: 2a3aa6da503 ("pvr: Fix cubemap layer stride") Signed-off-by: Frank Binns Acked-by: Alyssa Rosenzweig Part-of: --- src/imagination/vulkan/pvr_image.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/imagination/vulkan/pvr_image.c b/src/imagination/vulkan/pvr_image.c index 7d8bc25ced7..57f3ff35ecd 100644 --- a/src/imagination/vulkan/pvr_image.c +++ b/src/imagination/vulkan/pvr_image.c @@ -115,19 +115,21 @@ static void pvr_image_setup_mip_levels(struct pvr_image *image) extent.depth = u_minify(extent.depth, 1); } - /* The hw calculates layer strides as if a full mip chain up until 1x1x1 - * were present so we need to account for that in the `layer_size`. - */ - while (extent.height != 1 || extent.width != 1 || extent.depth != 1) { - const uint32_t height_pitch = ALIGN(extent.height, extent_alignment); - const uint32_t pitch = cpp * ALIGN(extent.width, extent_alignment); + if (image->vk.mip_levels > 1) { + /* The hw calculates layer strides as if a full mip chain up until 1x1x1 + * were present so we need to account for that in the `layer_size`. + */ + while (extent.height != 1 || extent.width != 1 || extent.depth != 1) { + const uint32_t height_pitch = ALIGN(extent.height, extent_alignment); + const uint32_t pitch = cpp * ALIGN(extent.width, extent_alignment); - image->layer_size += image->vk.samples * pitch * height_pitch * - ALIGN(extent.depth, extent_alignment); + image->layer_size += image->vk.samples * pitch * height_pitch * + ALIGN(extent.depth, extent_alignment); - extent.height = u_minify(extent.height, 1); - extent.width = u_minify(extent.width, 1); - extent.depth = u_minify(extent.depth, 1); + extent.height = u_minify(extent.height, 1); + extent.width = u_minify(extent.width, 1); + extent.depth = u_minify(extent.depth, 1); + } } /* TODO: It might be useful to store the alignment in the image so it can be