anv: advertise emulated formats
authorChia-I Wu <olvaffe@gmail.com>
Thu, 28 Sep 2023 17:37:11 +0000 (10:37 -0700)
committerMarge Bot <emma+marge@anholt.net>
Sat, 14 Oct 2023 02:36:40 +0000 (02:36 +0000)
Advertise required features for emulated formats.

v2: no sparse residency support

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25467>

src/intel/vulkan/anv_formats.c
src/intel/vulkan/anv_sparse.c

index 03d41d2..79acf61 100644 (file)
@@ -538,6 +538,23 @@ anv_get_image_format_features2(const struct anv_physical_device *physical_device
    assert((isl_mod_info != NULL) ==
           (vk_tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT));
 
+   if (anv_is_format_emulated(physical_device, vk_format)) {
+      assert(isl_format_is_compressed(anv_format->planes[0].isl_format));
+
+      /* require optimal tiling so that we can decompress on upload */
+      if (vk_tiling != VK_IMAGE_TILING_OPTIMAL)
+         return 0;
+
+      /* required features for compressed formats */
+      flags |= VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_BIT |
+               VK_FORMAT_FEATURE_2_BLIT_SRC_BIT |
+               VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_FILTER_LINEAR_BIT |
+               VK_FORMAT_FEATURE_2_TRANSFER_SRC_BIT |
+               VK_FORMAT_FEATURE_2_TRANSFER_DST_BIT;
+
+      return flags;
+   }
+
    const VkImageAspectFlags aspects = vk_format_aspects(vk_format);
 
    if (aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) {
@@ -1310,6 +1327,12 @@ anv_get_image_format_properties(
           !(info->flags & VK_IMAGE_CREATE_EXTENDED_USAGE_BIT))
          goto unsupported;
 
+      /* We don't want emulated formats to gain unexpected usage (storage in
+       * particular) from its compatible view formats.
+       */
+      if (anv_is_format_emulated(physical_device, info->format))
+         goto unsupported;
+
       /* From the Vulkan 1.3.224 spec "43.1.6. Format Compatibility Classes":
        *
        *    "Each depth/stencil format is only compatible with itself."
index cc494e1..37c0b2a 100644 (file)
@@ -766,6 +766,13 @@ anv_sparse_image_check_support(struct anv_physical_device *pdevice,
     *    VK_IMAGE_TILING_LINEAR tiling is not supported."
     */
 
+   /* We choose not to support sparse residency on emulated compressed
+    * formats due to the additional image plane. It would make the
+    * implementation extremely complicated.
+    */
+   if (anv_is_format_emulated(pdevice, vk_format))
+      return VK_ERROR_FORMAT_NOT_SUPPORTED;
+
    /* While the spec itself says linear is not supported (see above), deqp-vk
     * tries anyway to create linear sparse images, so we have to check for it.
     * This is also said in VUID-VkImageCreateInfo-tiling-04121: