panvk: sanity check block size for unorm format

panvk_meta_get_unorm_format_for_blk_size() requires a block size of 4
or less, but we didn't actually check for that before calling it. Fix
that, and also rename the function because what we actually care about
isn't whether it is a unorm format, but a blendable format.

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35771>
This commit is contained in:
Eric R. Smith 2025-10-24 14:36:54 -03:00 committed by Marge Bot
parent 43d98a3f1a
commit 09b5802f9f

View file

@ -48,7 +48,7 @@ panvk_meta_get_uint_format_for_blk_size(unsigned blk_sz)
}
static inline VkFormat
panvk_meta_get_unorm_format_for_blk_size(unsigned blk_sz)
panvk_meta_get_blendable_format_for_blk_size(unsigned blk_sz)
{
/* We expect _UINT formats to be used if the blocksize is greater than
* 32-bit.
@ -82,18 +82,17 @@ panvk_meta_copy_get_image_properties(struct panvk_image *img,
const bool is_afbc = drm_is_afbc(img->vk.drm_format_mod);
/* Format re-interpretation is not an option on Bifrost */
const bool preserve_img_fmt = is_afbc && PAN_ARCH <= 7;
/* We want UNORM when the image is the destination of a copy and a graphics
* pipeline is used to avoid blend shaders. On Bifrost, only UNORM/sRGB
/* We prefer to use formats that are blendable by the fixed function
* hardware to avoid blend shaders. On Bifrost, only UNORM/sRGB
* is allowed, so we use UNORM formats when creating depth/stencil views too.
*/
const bool use_unorm =
(use_gfx_pipeline && is_destination) || preserve_img_fmt;
const bool prefer_blendable = use_gfx_pipeline && is_destination;
if (vk_format_is_depth_or_stencil(img->vk.format)) {
switch (img->vk.format) {
case VK_FORMAT_S8_UINT:
props.stencil.view_format =
use_unorm ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
prefer_blendable ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
props.stencil.component_mask = BITFIELD_MASK(1);
break;
case VK_FORMAT_D24_UNORM_S8_UINT:
@ -101,19 +100,19 @@ panvk_meta_copy_get_image_properties(struct panvk_image *img,
if (img->planes[0].image.props.format ==
PIPE_FORMAT_Z24_UNORM_PACKED) {
props.depth.view_format =
use_unorm ? VK_FORMAT_R8G8B8_UNORM : VK_FORMAT_R8G8B8_UINT;
prefer_blendable ? VK_FORMAT_R8G8B8_UNORM : VK_FORMAT_R8G8B8_UINT;
} else {
assert(img->planes[0].image.props.format ==
PIPE_FORMAT_Z24X8_UNORM);
props.depth.view_format = use_unorm ? VK_FORMAT_R8G8B8A8_UNORM
props.depth.view_format = prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM
: VK_FORMAT_R8G8B8A8_UINT;
}
props.depth.component_mask = BITFIELD_MASK(3);
props.stencil.view_format =
use_unorm ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
prefer_blendable ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
props.stencil.component_mask = BITFIELD_BIT(0);
} else {
props.depth.view_format = use_unorm
props.depth.view_format = prefer_blendable
? VK_FORMAT_R8G8B8A8_UNORM
: VK_FORMAT_R8G8B8A8_UINT;
props.depth.component_mask = BITFIELD_MASK(3);
@ -123,25 +122,25 @@ panvk_meta_copy_get_image_properties(struct panvk_image *img,
break;
case VK_FORMAT_X8_D24_UNORM_PACK32:
props.depth.view_format =
use_unorm ? VK_FORMAT_R8G8B8A8_UNORM : VK_FORMAT_R8G8B8A8_UINT;
prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM : VK_FORMAT_R8G8B8A8_UINT;
props.depth.component_mask = BITFIELD_MASK(3);
break;
case VK_FORMAT_D32_SFLOAT_S8_UINT:
assert(panvk_image_is_planar_depth_stencil(img));
props.depth.view_format =
use_unorm ? VK_FORMAT_R8G8B8A8_UNORM : VK_FORMAT_R8G8B8A8_UINT;
prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM : VK_FORMAT_R8G8B8A8_UINT;
props.depth.component_mask = BITFIELD_MASK(4);
props.stencil.view_format =
use_unorm ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
prefer_blendable ? VK_FORMAT_R8_UNORM : VK_FORMAT_R8_UINT;
props.stencil.component_mask = BITFIELD_BIT(0);
break;
case VK_FORMAT_D16_UNORM:
props.depth.view_format =
use_unorm ? VK_FORMAT_R8G8_UNORM : VK_FORMAT_R8G8_UINT;
prefer_blendable ? VK_FORMAT_R8G8_UNORM : VK_FORMAT_R8G8_UINT;
props.depth.component_mask = BITFIELD_MASK(2);
break;
case VK_FORMAT_D32_SFLOAT:
props.depth.view_format = use_unorm ? VK_FORMAT_R8G8B8A8_UNORM
props.depth.view_format = prefer_blendable ? VK_FORMAT_R8G8B8A8_UNORM
: VK_FORMAT_R8G8B8A8_UINT;
props.depth.component_mask = BITFIELD_MASK(4);
break;
@ -153,22 +152,26 @@ panvk_meta_copy_get_image_properties(struct panvk_image *img,
for (uint32_t p = 0; p < ycbcr_info->n_planes; p++) {
unsigned blk_sz =
vk_format_get_blocksize(ycbcr_info->planes[p].format);
props.plane[p].view_format =
use_unorm ?
panvk_meta_get_unorm_format_for_blk_size(blk_sz) :
panvk_meta_get_uint_format_for_blk_size(blk_sz);
if (preserve_img_fmt) {
props.plane[p].view_format = ycbcr_info->planes[p].format;
} else {
props.plane[p].view_format =
/* there are no blendable formats with blk_sz > 4 */
(prefer_blendable && blk_sz <= 4) ?
panvk_meta_get_blendable_format_for_blk_size(blk_sz) :
panvk_meta_get_uint_format_for_blk_size(blk_sz);
}
}
} else {
unsigned blk_sz = util_format_get_blocksize(pfmt);
if (preserve_img_fmt) {
props.color.view_format = img->vk.format;
} else if (use_unorm) {
props.color.view_format =
panvk_meta_get_unorm_format_for_blk_size(blk_sz);
} else {
props.color.view_format =
/* there are no blendable formats with blk_sz > 4 */
(prefer_blendable && blk_sz <= 4) ?
panvk_meta_get_blendable_format_for_blk_size(blk_sz) :
panvk_meta_get_uint_format_for_blk_size(blk_sz);
}
}