zink: break out surface viewtype clamping into util function

Reviewed-by: Adam Jackson <ajax@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9685>
This commit is contained in:
Mike Blumenkrantz
2021-03-18 10:45:16 -04:00
committed by Marge Bot
parent 70d87dd41d
commit 813a7e64bd
2 changed files with 18 additions and 14 deletions
+1 -13
View File
@@ -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;
}
+17 -1
View File
@@ -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