From 792c2956ac352c17fdf9a05d9a0a5455ba44cc0f Mon Sep 17 00:00:00 2001 From: Mike Blumenkrantz Date: Wed, 26 Apr 2023 09:52:23 -0400 Subject: [PATCH] zink: break out VkImageViewUsageCreateInfo applying for reuse no functional changes cc: mesa-stable Part-of: --- src/gallium/drivers/zink/zink_surface.c | 42 +++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/gallium/drivers/zink/zink_surface.c b/src/gallium/drivers/zink/zink_surface.c index 596c0f0..8886d34 100644 --- a/src/gallium/drivers/zink/zink_surface.c +++ b/src/gallium/drivers/zink/zink_surface.c @@ -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); -- 2.7.4