From 1dc37f650a61dea2768fa4a22eb2f1e786d461eb Mon Sep 17 00:00:00 2001 From: SoroushIMG Date: Sat, 17 Jun 2023 12:47:09 +0100 Subject: [PATCH] pvr: fix texture address offset when base level >0 Base level offseting only needs to be applied when creating non-compressed view of a compressed image. Additionally the logic when patching offset, did not fix up the rest of image state. Seen in: dEQP-VK.pipeline.monolithic.image_view.view_type.2d.format.r32_uint.subresource_range.lod_base_mip_level_array_layer_last Signed-off-by: SoroushIMG Acked-by: Alyssa Rosenzweig Part-of: --- src/imagination/vulkan/pvr_image.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/imagination/vulkan/pvr_image.c b/src/imagination/vulkan/pvr_image.c index 7f8a39a2a43..a8f6fed799b 100644 --- a/src/imagination/vulkan/pvr_image.c +++ b/src/imagination/vulkan/pvr_image.c @@ -277,6 +277,29 @@ void pvr_GetImageSubresourceLayout(VkDevice device, pvr_get_image_subresource_layout(image, subresource, layout); } +static void pvr_adjust_non_compressed_view(const struct pvr_image *image, + struct pvr_texture_state_info *info) +{ + const uint32_t base_level = info->base_level; + + if (!vk_format_is_compressed(image->vk.format) || + vk_format_is_compressed(info->format)) { + return; + } + + /* Cannot use the image state, as the miplevel sizes for an + * uncompressed chain view may not decrease by 2 each time compared to the + * compressed one e.g. (22x22,11x11,5x5) -> (6x6,3x3,2x2) + * Instead manually apply an offset and patch the size + */ + info->extent.width = u_minify(info->extent.width, base_level); + info->extent.height = u_minify(info->extent.height, base_level); + info->extent.depth = u_minify(info->extent.depth, base_level); + info->extent = vk_image_extent_to_elements(&image->vk, info->extent); + info->offset += image->mip_levels[base_level].offset; + info->base_level = 0; +} + VkResult pvr_CreateImageView(VkDevice _device, const VkImageViewCreateInfo *pCreateInfo, const VkAllocationCallbacks *pAllocator, @@ -308,8 +331,7 @@ VkResult pvr_CreateImageView(VkDevice _device, info.is_cube = (info.type == VK_IMAGE_VIEW_TYPE_CUBE || info.type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY); info.array_size = iview->vk.layer_count; - info.offset = iview->vk.base_array_layer * image->layer_size + - image->mip_levels[info.base_level].offset; + info.offset = iview->vk.base_array_layer * image->layer_size; info.mipmaps_present = (image->vk.mip_levels > 1) ? true : false; info.stride = image->physical_extent.width; info.tex_state_type = PVR_TEXTURE_STATE_SAMPLE; @@ -320,6 +342,8 @@ VkResult pvr_CreateImageView(VkDevice _device, info.format = pCreateInfo->format; + pvr_adjust_non_compressed_view(image, &info); + vk_component_mapping_to_pipe_swizzle(iview->vk.swizzle, input_swizzle); format_swizzle = pvr_get_format_swizzle(info.format); util_format_compose_swizzles(format_swizzle, input_swizzle, info.swizzle);