zink: add extra validation for resource creation
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 20 Apr 2022 16:57:47 +0000 (12:57 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 18 May 2022 02:29:18 +0000 (02:29 +0000)
check image params against driver's returned limits to avoid
failing later

cc: mesa-stable

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16563>

src/gallium/drivers/zink/zink_resource.c

index 0bb1d1c..6e4b807 100644 (file)
@@ -227,7 +227,17 @@ check_ici(struct zink_screen *screen, VkImageCreateInfo *ici, uint64_t modifier)
    } else
       ret = VKSCR(GetPhysicalDeviceImageFormatProperties)(screen->pdev, ici->format, ici->imageType,
                                                    ici->tiling, ici->usage, ici->flags, &image_props);
-   return ret == VK_SUCCESS;
+   if (ret != VK_SUCCESS)
+      return false;
+   if (ici->extent.depth > image_props.maxExtent.depth ||
+       ici->extent.height > image_props.maxExtent.height ||
+       ici->extent.width > image_props.maxExtent.width)
+      return false;
+   if (ici->mipLevels > image_props.maxMipLevels)
+      return false;
+   if (ici->arrayLayers > image_props.maxArrayLayers)
+      return false;
+   return true;
 }
 
 static VkImageUsageFlags