From de244bcdb09f337693148705396135a4f0f84ce5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Briano?= Date: Thu, 16 Jan 2025 16:50:03 -0800 Subject: [PATCH] vulkan: calculate remaining layers of 2d view of 3d image correctly When a 2D_ARRAY view of a 3D image is created, the layer count of the 2D view should be based on the depth of the 3D image. When VK_REMAINING_ARRAY_LAYERS is used, we were incorrectly calculating them from the layer count of the base image. Fixes future tests: dEQP-VK.renderpass*.remaining_array_layers.* Reviewed-by: Samuel Pitoiset Part-of: --- src/vulkan/runtime/vk_image.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c index fb20949d2ab..ac229178fd3 100644 --- a/src/vulkan/runtime/vk_image.c +++ b/src/vulkan/runtime/vk_image.c @@ -521,7 +521,6 @@ vk_image_view_init(struct vk_device *device, image_view->base_mip_level = range->baseMipLevel; image_view->level_count = vk_image_subresource_level_count(image, range); image_view->base_array_layer = range->baseArrayLayer; - image_view->layer_count = vk_image_subresource_layer_count(image, range); const VkImageViewMinLodCreateInfoEXT *min_lod_info = vk_find_struct_const(pCreateInfo, IMAGE_VIEW_MIN_LOD_CREATE_INFO_EXT); @@ -540,6 +539,29 @@ vk_image_view_init(struct vk_device *device, image_view->extent = vk_image_mip_level_extent(image, image_view->base_mip_level); + /* From the Vulkan 1.4.304 spec: + * + * VUID-VkImageViewCreateInfo-image-02724 + * + * "If image is a 3D image created with + * VK_IMAGE_CREATE_2D_ARRAY_COMPATIBLE_BIT set, and viewType is + * VK_IMAGE_VIEW_TYPE_2D or VK_IMAGE_VIEW_TYPE_2D_ARRAY, + * subresourceRange.baseArrayLayer must be less than the depth computed + * from baseMipLevel and extent.depth specified in VkImageCreateInfo + * when image was created, according to the formula defined in Image + * Mip Level Sizing" + */ + if (image->image_type == VK_IMAGE_TYPE_3D && + (image_view->view_type == VK_IMAGE_VIEW_TYPE_2D || + image_view->view_type == VK_IMAGE_VIEW_TYPE_2D_ARRAY)) { + image_view->layer_count = + range->layerCount == VK_REMAINING_ARRAY_LAYERS ? + image_view->extent.depth - range->baseArrayLayer : + range->layerCount; + } else { + image_view->layer_count = vk_image_subresource_layer_count(image, range); + } + if (vk_format_is_compressed(image->format) && !vk_format_is_compressed(image_view->format)) { const struct util_format_description *fmt =