pan/layout: Get rid of pan_image_surface_{offset,stride}()

For AFBC images it's not clear what the offset/stride refers to (header
or body). Let's clear the confusion by dropping the helper and letting
the callers dereference the layout directly.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: Lars-Ivar Hesselberg Simonsen <lars-ivar.simonsen@arm.com>
Reviewed-by: Eric R. Smith <eric.smith@collabora.com>
Tested-by: Eric R. Smith <eric.smith@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35555>
This commit is contained in:
Boris Brezillon 2025-06-16 17:18:40 +02:00
parent 0825eccb47
commit 8b93e8c33e
5 changed files with 42 additions and 59 deletions

View file

@ -2048,12 +2048,20 @@ emit_image_bufs(struct panfrost_batch *batch, enum pipe_shader_type shader,
bool is_3d = rsrc->base.target == PIPE_TEXTURE_3D;
bool is_buffer = rsrc->base.target == PIPE_BUFFER;
unsigned offset =
is_buffer ? image->u.buf.offset
: pan_image_surface_offset(
&rsrc->plane.layout, image->u.tex.level,
(is_3d || is_msaa) ? 0 : image->u.tex.first_layer,
(is_3d || is_msaa) ? image->u.tex.first_layer : 0);
unsigned offset;
if (is_buffer) {
offset = image->u.buf.offset;
} else {
const struct pan_image_layout *layout = &rsrc->plane.layout;
const struct pan_image_slice_layout *slayout =
&layout->slices[image->u.tex.level];
offset = slayout->offset_B +
(image->u.tex.first_layer *
(is_3d || is_msaa ? slayout->surface_stride_B
: layout->array_stride_B));
}
panfrost_track_image_access(batch, shader, image);
@ -2081,6 +2089,9 @@ emit_image_bufs(struct panfrost_batch *batch, enum pipe_shader_type shader,
cfg) {
unsigned level = image->u.tex.level;
unsigned samples = rsrc->image.props.nr_samples;
unsigned slice_stride =
is_3d ? rsrc->plane.layout.slices[level].surface_stride_B
: rsrc->plane.layout.array_stride_B;
cfg.s_dimension = u_minify(rsrc->base.width0, level);
cfg.t_dimension = u_minify(rsrc->base.height0, level);
@ -2089,16 +2100,11 @@ emit_image_bufs(struct panfrost_batch *batch, enum pipe_shader_type shader,
: (image->u.tex.last_layer - image->u.tex.first_layer + 1);
cfg.row_stride = rsrc->plane.layout.slices[level].row_stride_B;
if (cfg.r_dimension > 1) {
cfg.slice_stride = pan_image_surface_stride(
&rsrc->image.props, &rsrc->plane.layout, level);
}
if (cfg.r_dimension > 1)
cfg.slice_stride = slice_stride;
if (is_msaa) {
if (cfg.r_dimension == 1) {
unsigned slice_stride = pan_image_surface_stride(
&rsrc->image.props, &rsrc->plane.layout, level);
/* regular multisampled images get the sample index in
the R dimension */
cfg.r_dimension = samples;

View file

@ -1304,8 +1304,9 @@ panfrost_load_tiled_images(struct panfrost_transfer *transfer,
return;
struct panfrost_bo *bo = rsrc->bo;
unsigned stride =
pan_image_surface_stride(&rsrc->image.props, &rsrc->plane.layout, level);
unsigned stride = rsrc->image.props.dim == MALI_TEXTURE_DIMENSION_3D
? rsrc->plane.layout.slices[level].surface_stride_B
: rsrc->plane.layout.array_stride_B;
/* Otherwise, load each layer separately, required to load from 3D and
* array textures.
@ -1458,8 +1459,9 @@ panfrost_store_tiled_images(struct panfrost_transfer *transfer,
struct panfrost_bo *bo = rsrc->bo;
struct pipe_transfer *ptrans = &transfer->base;
unsigned level = ptrans->level;
unsigned stride =
pan_image_surface_stride(&rsrc->image.props, &rsrc->plane.layout, level);
unsigned stride = rsrc->image.props.dim == MALI_TEXTURE_DIMENSION_3D
? rsrc->plane.layout.slices[level].surface_stride_B
: rsrc->plane.layout.array_stride_B;
/* Otherwise, store each layer separately, required to store to 3D and
* array textures.
@ -1541,8 +1543,10 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource,
* on this LOD.
*/
transfer->base.stride = staging->plane.layout.slices[0].row_stride_B;
transfer->base.layer_stride = pan_image_surface_stride(
&staging->image.props, &staging->plane.layout, 0);
transfer->base.layer_stride =
staging->image.props.dim == MALI_TEXTURE_DIMENSION_3D
? staging->plane.layout.slices[0].surface_stride_B
: staging->plane.layout.array_stride_B;
transfer->staging.rsrc = &staging->base;
@ -1717,8 +1721,10 @@ panfrost_ptr_map(struct pipe_context *pctx, struct pipe_resource *resource,
return NULL;
transfer->base.stride = rsrc->plane.layout.slices[level].row_stride_B;
transfer->base.layer_stride = pan_image_surface_stride(
&rsrc->image.props, &rsrc->plane.layout, level);
transfer->base.layer_stride =
rsrc->image.props.dim == MALI_TEXTURE_DIMENSION_3D
? rsrc->plane.layout.slices[level].surface_stride_B
: rsrc->plane.layout.array_stride_B;
/* By mapping direct-write, we're implicitly already
* initialized (maybe), so be conservative */

View file

@ -138,18 +138,6 @@ init_slice_crc_info(unsigned arch, struct pan_image_slice_layout *slice,
slice->crc.size_B = slice->crc.stride_B * tile_count_y;
}
unsigned
pan_image_surface_stride(const struct pan_image_props *props,
const struct pan_image_layout *layout, unsigned level)
{
if (props->dim != MALI_TEXTURE_DIMENSION_3D)
return layout->array_stride_B;
else if (drm_is_afbc(props->modifier))
return layout->slices[level].afbc.surface_stride_B;
else
return layout->slices[level].surface_stride_B;
}
static unsigned
get_plane_blocksize(enum pipe_format format, unsigned plane_idx)
{
@ -315,18 +303,6 @@ wsi_row_pitch_to_row_stride(
return true;
}
/* Computes the offset of an image surface at a particular level/face. Add to
* the base address of a texture to get the address to that level/face */
unsigned
pan_image_surface_offset(const struct pan_image_layout *layout, unsigned level,
unsigned array_idx, unsigned surface_idx)
{
return layout->slices[level].offset_B +
(array_idx * layout->array_stride_B) +
(surface_idx * layout->slices[level].surface_stride_B);
}
bool
pan_image_layout_init(
unsigned arch, const struct pan_image_props *props, unsigned plane_idx,

View file

@ -144,14 +144,6 @@ struct pan_image_block_size
pan_image_renderblock_size_el(uint64_t modifier, enum pipe_format format,
unsigned plane_idx);
unsigned pan_image_surface_stride(const struct pan_image_props *props,
const struct pan_image_layout *layout,
unsigned level);
unsigned pan_image_surface_offset(const struct pan_image_layout *layout,
unsigned level, unsigned array_idx,
unsigned surface_idx);
static inline uint64_t
pan_image_mip_level_size(const struct pan_image_props *props,
const struct pan_image_layout *layout, unsigned level)

View file

@ -245,10 +245,13 @@ prepare_attr_buf_descs(struct panvk_image_view *view)
&image->planes[plane_idx].image.props;
const struct pan_image_layout *plane_layout =
&image->planes[plane_idx].plane.layout;
const struct pan_image_slice_layout *slayout =
&plane_layout->slices[view->pview.first_level];
bool is_3d = plane_props->dim == MALI_TEXTURE_DIMENSION_3D;
unsigned offset = pan_image_surface_offset(
plane_layout, view->pview.first_level,
is_3d ? 0 : view->pview.first_layer, is_3d ? view->pview.first_layer : 0);
unsigned offset =
slayout->offset_B +
(view->pview.first_layer *
(is_3d ? slayout->surface_stride_B : plane_layout->array_stride_B));
pan_pack(&view->descs.img_attrib_buf[0], ATTRIBUTE_BUFFER, cfg) {
/* The format is the only thing we lack to emit attribute descriptors
@ -287,9 +290,9 @@ prepare_attr_buf_descs(struct panvk_image_view *view)
cfg.row_stride =
image->planes[plane_idx].plane.layout.slices[level].row_stride_B;
if (cfg.r_dimension > 1) {
cfg.slice_stride = pan_image_surface_stride(
&image->planes[plane_idx].image.props,
&image->planes[plane_idx].plane.layout, level);
cfg.slice_stride = view->pview.dim == MALI_TEXTURE_DIMENSION_3D
? slayout->surface_stride_B
: plane_layout->array_stride_B;
}
}
}