From a909e1e6ff9be660c287caadef726289ed47c4de Mon Sep 17 00:00:00 2001 From: Boris Brezillon Date: Thu, 26 Jun 2025 08:48:42 +0200 Subject: [PATCH] pan/image: Provide two helpers to check image viability pan_image_test_props() checks all the image properties at once, and pan_image_test_modifier_with_format() just a pair. This will allow us to use the check done in pan_mod instead of duplicating the same set of rules in panvk/panfrost and possibly having one that's ahead of the other. There are still checks we can't do at the pan_mod/image level, like anything involving format lowering, but that's okay. Signed-off-by: Boris Brezillon Reviewed-by: Lars-Ivar Hesselberg Simonsen Reviewed-by: Eric R. Smith Acked-by: Daniel Stone Part-of: --- src/panfrost/lib/pan_image.h | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/panfrost/lib/pan_image.h b/src/panfrost/lib/pan_image.h index 4356510a30e..2faf094b444 100644 --- a/src/panfrost/lib/pan_image.h +++ b/src/panfrost/lib/pan_image.h @@ -17,6 +17,9 @@ #include "pan_format.h" #include "pan_layout.h" #include "pan_mod.h" +#include "pan_props.h" + +#include "kmod/pan_kmod.h" #include "util/log.h" @@ -249,6 +252,62 @@ bool pan_image_layout_init( unsigned arch, struct pan_image *image, unsigned plane_idx, const struct pan_image_layout_constraints *explicit_layout_constraints); +static inline bool +pan_image_test_props(const struct pan_kmod_dev_props *dprops, + const struct pan_image_props *iprops) +{ + const unsigned arch = pan_arch(dprops->gpu_id); + struct pan_image image = { + .props = *iprops, + .mod_handler = pan_mod_get_handler(arch, iprops->modifier), + }; + + if (!image.mod_handler) + return false; + + if (!image.mod_handler->test_props(dprops, &image.props)) + return false; + + /* Now make sure the layout can be properly initialized on all planes. */ + uint32_t plane_count = util_format_get_num_planes(image.props.format); + for (uint32_t p = 0; p < plane_count; p++) { + struct pan_image_plane plane; + + memset(&plane, 0, sizeof(plane)); + image.planes[p] = &plane; + + if (!pan_image_layout_init(arch, &image, p, NULL)) + return false; + } + + return true; +} + +static inline bool +pan_image_test_modifier_with_format(const struct pan_kmod_dev_props *dprops, + uint64_t modifier, enum pipe_format format) +{ + /* To check if a pair is supported, we define the smallest + * possible 2D image (or 3D image if this is a 3D compressed format). */ + const struct pan_image_props iprops = { + .modifier = modifier, + .format = format, + .extent_px = { + .width = util_format_get_blockwidth(format), + .height = util_format_get_blockheight(format), + .depth = util_format_get_blockdepth(format), + }, + .nr_samples = 1, + .dim = util_format_get_blockdepth(format) > 1 ? MALI_TEXTURE_DIMENSION_3D + : MALI_TEXTURE_DIMENSION_2D, + .nr_slices = 1, + .array_size = 1, + }; + + return pan_image_test_props(dprops, &iprops); +} + + #ifdef __cplusplus } /* extern C */ #endif