diff --git a/src/panfrost/vulkan/panvk_image_view.h b/src/panfrost/vulkan/panvk_image_view.h index fb85e12a2aa..41230eb923f 100644 --- a/src/panfrost/vulkan/panvk_image_view.h +++ b/src/panfrost/vulkan/panvk_image_view.h @@ -48,6 +48,27 @@ struct panvk_image_view { VK_DEFINE_NONDISP_HANDLE_CASTS(panvk_image_view, vk.base, VkImageView, VK_OBJECT_TYPE_IMAGE_VIEW); +static inline uint32_t +panvk_image_view_plane_index(struct panvk_image_view *view) +{ + struct panvk_image *image = + container_of(view->vk.image, struct panvk_image, vk); + + if (vk_format_is_depth_or_stencil(view->vk.image->format) && + view->vk.aspects == VK_IMAGE_ASPECT_COLOR_BIT) { + /* Color views of ZS is needed for meta copies. 1 byte format is always + * stencil, and if it's not the stencil component the caller wants, it + * has to be the depth. + */ + if (vk_format_get_blocksize(view->vk.view_format)) + return panvk_plane_index(image, VK_IMAGE_ASPECT_STENCIL_BIT); + else + return panvk_plane_index(image, VK_IMAGE_ASPECT_DEPTH_BIT); + } else { + return panvk_plane_index(image, view->vk.aspects); + } +} + static_assert(offsetof(struct panvk_image_view, descs.zs.tex) == offsetof(struct panvk_image_view, descs.tex), "ZS texture descriptor must alias with color texture descriptor"); diff --git a/src/panfrost/vulkan/panvk_vX_image_view.c b/src/panfrost/vulkan/panvk_vX_image_view.c index 21ff443cd4e..d40c937919c 100644 --- a/src/panfrost/vulkan/panvk_vX_image_view.c +++ b/src/panfrost/vulkan/panvk_vX_image_view.c @@ -225,18 +225,7 @@ prepare_attr_buf_descs(struct panvk_image_view *view) { struct panvk_image *image = container_of(view->vk.image, struct panvk_image, vk); - unsigned plane_idx = 0; - - /* Stencil is on plane 1 in a D32_S8 image. The special color case is for - * vk_meta copies which create color views of depth/stencil images. In - * that case, we base the stencil vs depth detection on the format block - * size. - */ - if (image->vk.format == VK_FORMAT_D32_SFLOAT_S8_UINT && - (view->vk.aspects == VK_IMAGE_ASPECT_STENCIL_BIT || - (view->vk.aspects == VK_IMAGE_ASPECT_COLOR_BIT && - vk_format_get_blocksize(view->vk.view_format) == 1))) - plane_idx = 1; + unsigned plane_idx = panvk_image_view_plane_index(view); const struct pan_image_props *plane_props = &image->planes[plane_idx].image.props;