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 <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33075>
This commit is contained in:
Iván Briano
2025-01-16 16:50:03 -08:00
committed by Marge Bot
parent c9007999f6
commit de244bcdb0
+23 -1
View File
@@ -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 =