diff --git a/src/gallium/drivers/zink/zink_surface.c b/src/gallium/drivers/zink/zink_surface.c index 06b9d0ddd90..2e3309f43df 100644 --- a/src/gallium/drivers/zink/zink_surface.c +++ b/src/gallium/drivers/zink/zink_surface.c @@ -87,19 +87,7 @@ create_ivci(struct zink_screen *screen, ivci.subresourceRange.levelCount = 1; ivci.subresourceRange.baseArrayLayer = templ->u.tex.first_layer; ivci.subresourceRange.layerCount = 1 + templ->u.tex.last_layer - templ->u.tex.first_layer; - if (ivci.viewType == VK_IMAGE_VIEW_TYPE_CUBE || ivci.viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) { - if (templ->u.tex.first_layer == templ->u.tex.last_layer) - ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; - else if (ivci.viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY && - templ->u.tex.first_layer % 6 == 0 && - ivci.subresourceRange.layerCount % 6 == 0) - ivci.viewType = VK_IMAGE_VIEW_TYPE_CUBE; - else if (templ->u.tex.first_layer || ivci.subresourceRange.layerCount != res->base.array_size) - ivci.viewType = VK_IMAGE_VIEW_TYPE_2D_ARRAY; - } else if (ivci.viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY) { - if (templ->u.tex.first_layer == templ->u.tex.last_layer) - ivci.viewType = VK_IMAGE_VIEW_TYPE_2D; - } + ivci.viewType = zink_surface_clamp_viewtype(ivci.viewType, templ->u.tex.first_layer, templ->u.tex.last_layer, res->base.array_size); return ivci; } diff --git a/src/gallium/drivers/zink/zink_surface.h b/src/gallium/drivers/zink/zink_surface.h index fddc48be433..e3261e85ae2 100644 --- a/src/gallium/drivers/zink/zink_surface.h +++ b/src/gallium/drivers/zink/zink_surface.h @@ -58,5 +58,21 @@ zink_get_surface(struct zink_context *ctx, const struct pipe_surface *templ, VkImageViewCreateInfo *ivci); - +static inline VkImageViewType +zink_surface_clamp_viewtype(VkImageViewType viewType, unsigned first_layer, unsigned last_layer, unsigned array_size) +{ + unsigned layerCount = 1 + last_layer - first_layer; + if (viewType == VK_IMAGE_VIEW_TYPE_CUBE || viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY) { + if (first_layer == last_layer) + return VK_IMAGE_VIEW_TYPE_2D; + if (viewType == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY && first_layer % 6 == 0 && layerCount % 6 == 0) + return VK_IMAGE_VIEW_TYPE_CUBE; + if (first_layer || layerCount != array_size) + return VK_IMAGE_VIEW_TYPE_2D_ARRAY; + } else if (viewType == VK_IMAGE_VIEW_TYPE_2D_ARRAY) { + if (first_layer == last_layer) + return VK_IMAGE_VIEW_TYPE_2D; + } + return viewType; +} #endif