zink: break out VkImageViewUsageCreateInfo applying for reuse
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 26 Apr 2023 13:52:23 +0000 (09:52 -0400)
committerMarge Bot <emma+marge@anholt.net>
Wed, 26 Apr 2023 21:22:43 +0000 (21:22 +0000)
no functional changes

cc: mesa-stable

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22713>

src/gallium/drivers/zink/zink_surface.c

index 596c0f0..8886d34 100644 (file)
@@ -141,6 +141,29 @@ init_pipe_surface_info(struct pipe_context *pctx, struct pipe_surface *psurf, co
    psurf->u.tex.last_layer = templ->u.tex.last_layer;
 }
 
+static void
+apply_view_usage_for_format(struct zink_screen *screen, struct zink_resource *res, struct zink_surface *surface, enum pipe_format format, VkImageViewCreateInfo *ivci)
+{
+   VkFormatFeatureFlags feats = res->linear ?
+                                screen->format_props[format].linearTilingFeatures :
+                                screen->format_props[format].optimalTilingFeatures;
+   VkImageUsageFlags attachment = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
+   surface->usage_info.usage = res->obj->vkusage & ~attachment;
+   if (res->obj->modifier_aspect) {
+      feats = res->obj->vkfeats;
+      /* intersect format features for current modifier */
+      for (unsigned i = 0; i < screen->modifier_props[format].drmFormatModifierCount; i++) {
+         if (res->obj->modifier == screen->modifier_props[format].pDrmFormatModifierProperties[i].drmFormatModifier)
+            feats &= screen->modifier_props[format].pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
+      }
+   }
+   /* if the format features don't support framebuffer attachment, use VkImageViewUsageCreateInfo to remove it */
+   if ((res->obj->vkusage & attachment) &&
+       !(feats & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))) {
+      ivci->pNext = &surface->usage_info;
+   }
+}
+
 static struct zink_surface *
 create_surface(struct pipe_context *pctx,
                struct pipe_resource *pres,
@@ -157,24 +180,7 @@ create_surface(struct pipe_context *pctx,
 
    surface->usage_info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_USAGE_CREATE_INFO;
    surface->usage_info.pNext = NULL;
-   VkFormatFeatureFlags feats = res->linear ?
-                                screen->format_props[templ->format].linearTilingFeatures :
-                                screen->format_props[templ->format].optimalTilingFeatures;
-   VkImageUsageFlags attachment = (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT | VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT);
-   surface->usage_info.usage = res->obj->vkusage & ~attachment;
-   if (res->obj->modifier_aspect) {
-      feats = res->obj->vkfeats;
-      /* intersect format features for current modifier */
-      for (unsigned i = 0; i < screen->modifier_props[templ->format].drmFormatModifierCount; i++) {
-         if (res->obj->modifier == screen->modifier_props[templ->format].pDrmFormatModifierProperties[i].drmFormatModifier)
-            feats &= screen->modifier_props[templ->format].pDrmFormatModifierProperties[i].drmFormatModifierTilingFeatures;
-      }
-   }
-   /* if the format features don't support framebuffer attachment, use VkImageViewUsageCreateInfo to remove it */
-   if ((res->obj->vkusage & attachment) &&
-       !(feats & (VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT | VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT))) {
-      ivci->pNext = &surface->usage_info;
-   }
+   apply_view_usage_for_format(screen, res, surface, templ->format, ivci);
 
    pipe_resource_reference(&surface->base.texture, pres);
    pipe_reference_init(&surface->base.reference, 1);