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 <boris.brezillon@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35299>
This commit is contained in:
Yiwei Zhang 2025-06-04 12:45:33 -07:00 committed by Marge Bot
parent 1d77569cbc
commit 6690c74f6d
4 changed files with 41 additions and 46 deletions

View file

@ -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;

View file

@ -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

View file

@ -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 */

View file

@ -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 <format=" \
<< util_format_name(iprops.format) << ",plane=" << __plane \
<< ",mod=" << std::hex << (__iprops)->modifier << std::dec \