From 878a7d6de05938d4db9c2f2524de4492cfd3ccae Mon Sep 17 00:00:00 2001 From: Rebecca Mckeever Date: Tue, 26 Nov 2024 17:36:59 +0100 Subject: [PATCH] pan/texture: Accept holes in the pan_image_view::planes array We are about to add multiplanar depth/stencil support. A stencil only view of a multiplanar d32_s8 format will have NULL depth plane (plane0), so we need to prepare the texture logic to deal with that. Signed-off-by: Rebecca Mckeever Reviewed-by: Boris Brezillon Reviewed-by: Lars-Ivar Hesselberg Simonsen Part-of: --- src/panfrost/lib/pan_desc.c | 11 ++++++++--- src/panfrost/lib/pan_texture.c | 4 ++-- src/panfrost/lib/pan_texture.h | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/panfrost/lib/pan_desc.c b/src/panfrost/lib/pan_desc.c index c8f40b642b5..5875a91235c 100644 --- a/src/panfrost/lib/pan_desc.c +++ b/src/panfrost/lib/pan_desc.c @@ -66,8 +66,11 @@ mali_sampling_mode(const struct pan_image_view *view) unsigned nr_samples = pan_image_view_get_nr_samples(view); if (nr_samples > 1) { + ASSERTED const struct pan_image *first_plane = + pan_image_view_get_first_plane(view); + assert(view->nr_samples == nr_samples); - assert(view->planes[0]->layout.slices[0].surface_stride != 0); + assert(first_plane->layout.slices[0].surface_stride != 0); return MALI_MSAA_LAYERED; } @@ -86,7 +89,8 @@ static bool renderblock_fits_in_single_pass(const struct pan_image_view *view, unsigned tile_size) { - uint64_t mod = view->planes[0]->layout.modifier; + const struct pan_image *first_plane = pan_image_view_get_first_plane(view); + uint64_t mod = first_plane->layout.modifier; if (!drm_is_afbc(mod)) return tile_size >= 16 * 16; @@ -512,9 +516,10 @@ pan_prepare_rt(const struct pan_fb_info *fb, unsigned layer_idx, cfg->dithering_enable = true; + const struct pan_image *first_plane = pan_image_view_get_first_plane(rt); unsigned level = rt->first_level; ASSERTED unsigned layer_count = rt->dim == MALI_TEXTURE_DIMENSION_3D - ? rt->planes[0]->layout.depth + ? first_plane->layout.depth : rt->last_layer - rt->first_layer + 1; assert(rt->last_level == rt->first_level); diff --git a/src/panfrost/lib/pan_texture.c b/src/panfrost/lib/pan_texture.c index 77d9157f063..ea6de244143 100644 --- a/src/panfrost/lib/pan_texture.c +++ b/src/panfrost/lib/pan_texture.c @@ -622,10 +622,10 @@ void GENX(panfrost_new_texture)(const struct pan_image_view *iview, void *out, const struct panfrost_ptr *payload) { - const struct pan_image *base_image = pan_image_view_get_plane(iview, 0); - const struct pan_image_layout *layout = &base_image->layout; enum pipe_format format = iview->format; const struct util_format_description *desc = util_format_description(format); + const struct pan_image *first_plane = pan_image_view_get_first_plane(iview); + const struct pan_image_layout *layout = &first_plane->layout; uint32_t mali_format = GENX(panfrost_format_from_pipe_format)(format)->hw; unsigned char swizzle[4]; diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index f970be02f04..fcc050a3462 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -162,12 +162,39 @@ pan_image_view_get_plane(const struct pan_image_view *iview, uint32_t idx) return iview->planes[idx]; } +static inline unsigned +pan_image_view_get_plane_mask(const struct pan_image_view *iview) +{ + unsigned mask = 0; + + for (unsigned i = 0; i < ARRAY_SIZE(iview->planes); i++) { + if (iview->planes[i]) + mask |= BITFIELD_BIT(i); + } + + return mask; +} + +static inline unsigned +pan_image_view_get_first_plane_idx(const struct pan_image_view *iview) +{ + unsigned mask = pan_image_view_get_plane_mask(iview); + + assert(mask); + return ffs(mask) - 1; +} + +static inline const struct pan_image * +pan_image_view_get_first_plane(const struct pan_image_view *iview) +{ + unsigned first_plane_idx = pan_image_view_get_first_plane_idx(iview); + return pan_image_view_get_plane(iview, first_plane_idx); +} + static inline uint32_t pan_image_view_get_nr_samples(const struct pan_image_view *iview) { - /* All planes should have the same nr_samples value, so we - * just pick the first plane. */ - const struct pan_image *image = pan_image_view_get_plane(iview, 0); + const struct pan_image *image = pan_image_view_get_first_plane(iview); if (!image) return 0;