From 23cad7c695c0e95e50c4cb3996d86e3f5e261d73 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Thu, 26 Sep 2024 19:30:05 +0200 Subject: [PATCH] panfrost: check fmt.bitfeat_bit for compressed-support Because we map compressed formats to the interchange-formats on V9 and later, we end up not actually checking for compressed support here, but instead always checking bit 0, which is reserved in the spec. So let's instead explicitly check bitfeat_bit here instead, which we conveniently stored away in the previous commit. Use 1u instead of 1 for the shifted constant, to avoid undefined behavior when we're testing bit 31. Fixes: 0c1fde956bf ("panfrost: Add Valhall compressed formats") Reviewed-by: Boris Brezillon Part-of: --- src/gallium/drivers/panfrost/pan_device.c | 13 +++++-------- src/gallium/drivers/panfrost/pan_device.h | 2 +- src/gallium/drivers/panfrost/pan_screen.c | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_device.c b/src/gallium/drivers/panfrost/pan_device.c index afd2cec7716..dde0ec0f11b 100644 --- a/src/gallium/drivers/panfrost/pan_device.c +++ b/src/gallium/drivers/panfrost/pan_device.c @@ -43,15 +43,12 @@ * compressed formats, so we offer a helper to test if a format is supported */ bool -panfrost_supports_compressed_format(struct panfrost_device *dev, unsigned fmt) +panfrost_supports_compressed_format(struct panfrost_device *dev, + unsigned texfeat_bit) { - if (MALI_EXTRACT_TYPE(fmt) != MALI_FORMAT_COMPRESSED) - return true; - - unsigned idx = fmt & ~MALI_FORMAT_COMPRESSED; - assert(idx < 32); - - return panfrost_query_compressed_formats(&dev->kmod.props) & (1 << idx); + assert(texfeat_bit < 32); + return panfrost_query_compressed_formats(&dev->kmod.props) & + BITFIELD_BIT(texfeat_bit); } void diff --git a/src/gallium/drivers/panfrost/pan_device.h b/src/gallium/drivers/panfrost/pan_device.h index c90e3e8f72f..6e71499e319 100644 --- a/src/gallium/drivers/panfrost/pan_device.h +++ b/src/gallium/drivers/panfrost/pan_device.h @@ -214,7 +214,7 @@ void panfrost_open_device(void *memctx, int fd, struct panfrost_device *dev); void panfrost_close_device(struct panfrost_device *dev); bool panfrost_supports_compressed_format(struct panfrost_device *dev, - unsigned fmt); + unsigned texfeat_bit); static inline struct panfrost_bo * pan_lookup_bo(struct panfrost_device *dev, uint32_t gem_handle) diff --git a/src/gallium/drivers/panfrost/pan_screen.c b/src/gallium/drivers/panfrost/pan_screen.c index 13e7f33e635..ce1f78ed3e9 100644 --- a/src/gallium/drivers/panfrost/pan_screen.c +++ b/src/gallium/drivers/panfrost/pan_screen.c @@ -628,7 +628,8 @@ panfrost_is_format_supported(struct pipe_screen *screen, * differences. */ bool supported = - panfrost_supports_compressed_format(dev, MALI_EXTRACT_INDEX(fmt.hw)); + !util_format_is_compressed(format) || + panfrost_supports_compressed_format(dev, fmt.texfeat_bit); if (!supported) return false;