diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c index 96c552f2150..0353497f553 100644 --- a/src/gallium/drivers/panfrost/pan_resource.c +++ b/src/gallium/drivers/panfrost/pan_resource.c @@ -128,8 +128,19 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen, } if (drm_is_afbc(whandle->modifier)) { + unsigned tile_w = + panfrost_block_dim(whandle->modifier, true, 0); + unsigned tile_h = + panfrost_block_dim(whandle->modifier, false, 0); + + rsc->layout.slices[0].afbc.body_size = + rsc->layout.slices[0].row_stride * + DIV_ROUND_UP(templat->height0, tile_h); rsc->layout.slices[0].afbc.header_size = panfrost_afbc_header_size(templat->width0, templat->height0); + rsc->layout.slices[0].afbc.row_stride = + DIV_ROUND_UP(templat->width0, tile_w) * + AFBC_HEADER_BYTES_PER_TILE; } if (dev->ro) { @@ -403,14 +414,28 @@ panfrost_setup_layout(struct panfrost_device *dev, slice->afbc.header_size = panfrost_afbc_header_size(width, height); + /* Stride between two rows of AFBC headers */ + slice->afbc.row_stride = + (effective_width / tile_w) * + AFBC_HEADER_BYTES_PER_TILE; + + /* AFBC body size */ + slice->afbc.body_size = slice_one_size; + /* 3D AFBC resources have all headers placed at the * beginning instead of having them split per depth * level */ - if (is_3d) + if (is_3d) { + slice->afbc.surface_stride = + slice->afbc.header_size; slice->afbc.header_size *= effective_depth; - else + slice->afbc.body_size *= effective_depth; + offset += slice->afbc.header_size; + } else { slice_one_size += slice->afbc.header_size; + slice->afbc.surface_stride = slice_one_size; + } } unsigned slice_full_size = diff --git a/src/panfrost/lib/pan_afbc.c b/src/panfrost/lib/pan_afbc.c index cfd715f608f..7b1bfb32d9d 100644 --- a/src/panfrost/lib/pan_afbc.c +++ b/src/panfrost/lib/pan_afbc.c @@ -68,7 +68,6 @@ #define AFBC_TILE_WIDTH 16 #define AFBC_TILE_HEIGHT 16 -#define AFBC_HEADER_BYTES_PER_TILE 16 #define AFBC_CACHE_ALIGN 64 /* Is it possible to AFBC compress a particular format? Common formats (and diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index a8d4a006eec..aa5440a3939 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -47,6 +47,20 @@ struct panfrost_slice { struct { /* Size of the AFBC header preceding each slice */ unsigned header_size; + + /* Size of the AFBC body */ + unsigned body_size; + + /* Stride between two rows of AFBC headers */ + unsigned row_stride; + + /* Stride between AFBC headers of two consecutive surfaces. + * For 3D textures, this must be set to header size since + * AFBC headers are allocated together, for 2D arrays this + * should be set to size0, since AFBC headers are placed at + * the beginning of each layer + */ + unsigned surface_stride; } afbc; /* If checksumming is enabled following the slice, what @@ -90,6 +104,8 @@ panfrost_compute_checksum_size( bool panfrost_format_supports_afbc(enum pipe_format format); +#define AFBC_HEADER_BYTES_PER_TILE 16 + unsigned panfrost_afbc_header_size(unsigned width, unsigned height);