From 6690c74f6d81d953aab8471ff3da2ac6843a8fdc Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Wed, 4 Jun 2025 12:45:33 -0700 Subject: [PATCH] pan/layout: refactor wsi layout query This change splits pan_image_layout_get_wsi_layout into separate queries to prepare for making pan_image_wsi_layout an input layout constraint. Reviewed-by: Boris Brezillon Part-of: --- src/gallium/drivers/panfrost/pan_resource.c | 16 +++---- src/panfrost/lib/pan_layout.c | 46 +++++++++------------ src/panfrost/lib/pan_layout.h | 15 ++++--- src/panfrost/lib/tests/test-layout.cpp | 10 ++--- 4 files changed, 41 insertions(+), 46 deletions(-) diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 06820c411cf..172de042573 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -261,12 +261,11 @@ panfrost_resource_get_handle(struct pipe_screen *pscreen, return false; } - struct pan_image_wsi_layout wsi_layout = pan_image_layout_get_wsi_layout( + handle->stride = pan_image_get_wsi_row_pitch( &rsrc->image.props, handle->plane, &rsrc->image.planes[handle->plane]->layout, 0); - - handle->stride = wsi_layout.row_pitch_B; - handle->offset = wsi_layout.offset_B; + handle->offset = + pan_image_get_wsi_offset(&rsrc->image.planes[handle->plane]->layout, 0); return true; } @@ -282,14 +281,11 @@ panfrost_resource_get_param(struct pipe_screen *pscreen, switch (param) { case PIPE_RESOURCE_PARAM_STRIDE: - *value = pan_image_layout_get_wsi_layout(&rsrc->image.props, plane, - &rsrc->plane.layout, level) - .row_pitch_B; + *value = pan_image_get_wsi_row_pitch(&rsrc->image.props, plane, + &rsrc->plane.layout, level); return true; case PIPE_RESOURCE_PARAM_OFFSET: - *value = pan_image_layout_get_wsi_layout(&rsrc->image.props, plane, - &rsrc->plane.layout, level) - .offset_B; + *value = pan_image_get_wsi_offset(&rsrc->plane.layout, level); return true; case PIPE_RESOURCE_PARAM_MODIFIER: *value = rsrc->modifier; diff --git a/src/panfrost/lib/pan_layout.c b/src/panfrost/lib/pan_layout.c index 68a630c2003..fbc3ef80c30 100644 --- a/src/panfrost/lib/pan_layout.c +++ b/src/panfrost/lib/pan_layout.c @@ -206,44 +206,38 @@ get_plane_blocksize(enum pipe_format format, unsigned plane_idx) } } -struct pan_image_wsi_layout -pan_image_layout_get_wsi_layout(const struct pan_image_props *props, - unsigned plane_idx, - const struct pan_image_layout *layout, - unsigned level) +unsigned +pan_image_get_wsi_row_pitch(const struct pan_image_props *props, + unsigned plane_idx, + const struct pan_image_layout *layout, + unsigned level) { - unsigned row_stride_B = layout->slices[level].row_stride_B; - struct pan_image_block_size block_size_el = + const unsigned row_stride_B = layout->slices[level].row_stride_B; + const struct pan_image_block_size block_size_el = pan_image_renderblock_size_el(props->modifier, props->format, plane_idx); if (drm_is_afbc(props->modifier)) { - struct pan_image_block_size afbc_tile_extent_el = + const struct pan_image_block_size afbc_tile_extent_el = pan_image_block_size_el(props->modifier, props->format, plane_idx); - unsigned afbc_tile_payload_size_B = + const unsigned afbc_tile_payload_size_B = afbc_tile_extent_el.width * afbc_tile_extent_el.height * get_plane_blocksize(props->format, plane_idx); - unsigned afbc_tile_row_payload_size_B = + const unsigned afbc_tile_row_payload_size_B = pan_afbc_stride_blocks(props->modifier, row_stride_B) * afbc_tile_payload_size_B; - return (struct pan_image_wsi_layout){ - .offset_B = layout->slices[level].offset_B, - .row_pitch_B = afbc_tile_row_payload_size_B / - pan_afbc_superblock_height(props->modifier), - }; - } else if (drm_is_afrc(props->modifier)) { - struct pan_image_block_size tile_size_px = + + return afbc_tile_row_payload_size_B / + pan_afbc_superblock_height(props->modifier); + } + + if (drm_is_afrc(props->modifier)) { + const struct pan_image_block_size tile_size_px = pan_afrc_tile_size(props->format, props->modifier); - return (struct pan_image_wsi_layout){ - .offset_B = layout->slices[level].offset_B, - .row_pitch_B = row_stride_B / tile_size_px.height, - }; - } else { - return (struct pan_image_wsi_layout){ - .offset_B = layout->slices[level].offset_B, - .row_pitch_B = row_stride_B / block_size_el.height, - }; + return row_stride_B / tile_size_px.height; } + + return row_stride_B / block_size_el.height; } static bool diff --git a/src/panfrost/lib/pan_layout.h b/src/panfrost/lib/pan_layout.h index edef9b8efe0..e7cc6f3a690 100644 --- a/src/panfrost/lib/pan_layout.h +++ b/src/panfrost/lib/pan_layout.h @@ -156,11 +156,16 @@ bool pan_image_layout_init(unsigned arch, const struct pan_image_props *props, const struct pan_image_wsi_layout *wsi_layout, struct pan_image_layout *layout); -struct pan_image_wsi_layout -pan_image_layout_get_wsi_layout(const struct pan_image_props *props, - unsigned plane_idx, - const struct pan_image_layout *layout, - unsigned level); +static inline unsigned +pan_image_get_wsi_offset(const struct pan_image_layout *layout, unsigned level) +{ + return layout->slices[level].offset_B; +} + +unsigned pan_image_get_wsi_row_pitch(const struct pan_image_props *props, + unsigned plane_idx, + const struct pan_image_layout *layout, + unsigned level); #ifdef __cplusplus } /* extern C */ diff --git a/src/panfrost/lib/tests/test-layout.cpp b/src/panfrost/lib/tests/test-layout.cpp index b2789619892..ee17bae1ee8 100644 --- a/src/panfrost/lib/tests/test-layout.cpp +++ b/src/panfrost/lib/tests/test-layout.cpp @@ -516,11 +516,11 @@ static unsigned archs[] = {4, 5, 6, 7, 9, 12, 13}; if (!__result) \ break; \ \ - struct pan_image_wsi_layout __export_wsi_layout = \ - pan_image_layout_get_wsi_layout(&iprops, __plane, &layout, 0); \ - EXPECT_TRUE(__export_wsi_layout.row_pitch_B == \ - (__wsi_layout)->row_pitch_B && \ - __export_wsi_layout.offset_B == (__wsi_layout)->offset_B) \ + unsigned __export_row_pitch_B = \ + pan_image_get_wsi_row_pitch(&iprops, __plane, &layout, 0); \ + unsigned __export_offset_B = pan_image_get_wsi_offset(&layout, 0); \ + EXPECT_TRUE(__export_row_pitch_B == (__wsi_layout)->row_pitch_B && \ + __export_offset_B == (__wsi_layout)->offset_B) \ << " mismatch between import and export for