zink: verify format caps and add storage image usage when possible in creation
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Tue, 17 Nov 2020 23:26:01 +0000 (18:26 -0500)
committerMarge Bot <eric+marge@anholt.net>
Thu, 21 Jan 2021 19:48:44 +0000 (19:48 +0000)
this is a huge perf hog that will be improved on later, but it's necessary for now
in order to correctly determine whether we can use resources as shader images
since gallium gives us no info about usage

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8504>

src/gallium/drivers/zink/zink_resource.c

index 8ce0975..15b16f1 100644 (file)
@@ -229,8 +229,18 @@ resource_create(struct pipe_screen *pscreen,
                   VK_IMAGE_USAGE_TRANSFER_DST_BIT |
                   VK_IMAGE_USAGE_SAMPLED_BIT;
 
-      if (templ->bind & PIPE_BIND_SHADER_IMAGE)
-         ici.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
+      if ((templ->nr_samples <= 1 || screen->info.feats.features.shaderStorageImageMultisample) &&
+          (templ->bind & PIPE_BIND_SHADER_IMAGE ||
+          (templ->bind & PIPE_BIND_SAMPLER_VIEW && templ->flags & PIPE_RESOURCE_FLAG_TEXTURING_MORE_LIKELY))) {
+         VkFormatProperties props;
+         vkGetPhysicalDeviceFormatProperties(screen->pdev, res->format, &props);
+         /* gallium doesn't provide any way to actually know whether this will be used as a shader image,
+          * so we have to just assume and set the bit if it's available
+          */
+         if ((ici.tiling == VK_IMAGE_TILING_LINEAR && props.linearTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ||
+             (ici.tiling == VK_IMAGE_TILING_OPTIMAL && props.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
+            ici.usage |= VK_IMAGE_USAGE_STORAGE_BIT;
+      }
 
       if (templ->bind & PIPE_BIND_RENDER_TARGET)
          ici.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;