panfrost: Merge AFBC slab with BO backing

Rather than tracking AFBC memory "specially", just use the same codepath
as linear and tiled. Less things to mess up, I figure. This allows us to
use the standard setup_slices() call with AFBC resources, allowing
mipmapped AFBC resources.

Unfortunately, we do have to disable AFBC (and checksumming) in the
meantime to avoid functional regressions, as we don't know _a priori_ if
we'll need to access a resource from software (which is not yet hooked
up with AFBC) and we don't yet have routines to switch the layout of a
BO at runtime.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
diff --git a/src/gallium/drivers/panfrost/pan_afbc.c b/src/gallium/drivers/panfrost/pan_afbc.c
index 5621d1f..c9487b5 100644
--- a/src/gallium/drivers/panfrost/pan_afbc.c
+++ b/src/gallium/drivers/panfrost/pan_afbc.c
@@ -101,22 +101,9 @@
         return false;
 }
 
-/* AFBC is enabled on a per-resource basis (AFBC enabling is theoretically
- * indepdent between color buffers and depth/stencil). To enable, we allocate
- * the AFBC metadata buffer and mark that it is enabled. We do -not- actually
- * edit the fragment job here. This routine should be called ONCE per
- * AFBC-compressed buffer, rather than on every frame. */
-
-void
-panfrost_enable_afbc(struct panfrost_context *ctx, struct panfrost_resource *rsrc, bool ds)
+unsigned
+panfrost_afbc_header_size(unsigned width, unsigned height)
 {
-        struct pipe_context *gallium = (struct pipe_context *) ctx;
-        struct panfrost_screen *screen = pan_screen(gallium->screen);
-
-        unsigned width  = rsrc->base.width0;
-        unsigned height = rsrc->base.height0;
-        unsigned bytes_per_pixel = util_format_get_blocksize(rsrc->base.format);
-
         /* Align to tile */
         unsigned aligned_width  = ALIGN(width,  AFBC_TILE_WIDTH);
         unsigned aligned_height = ALIGN(height, AFBC_TILE_HEIGHT);
@@ -126,26 +113,10 @@
         unsigned tile_count_y = aligned_height / AFBC_TILE_HEIGHT;
         unsigned tile_count = tile_count_x * tile_count_y;
 
+        /* Multiply to find the header size */
         unsigned header_bytes = tile_count * AFBC_HEADER_BYTES_PER_TILE;
-        unsigned header_size = ALIGN(header_bytes, AFBC_CACHE_ALIGN);
 
-        /* The stride is a normal stride, but aligned */
-        unsigned unaligned_stride = aligned_width * bytes_per_pixel;
-        unsigned stride = ALIGN(unaligned_stride, AFBC_CACHE_ALIGN);
+        /* Align and go */
+        return ALIGN(header_bytes, AFBC_CACHE_ALIGN);
 
-        /* Compute the entire buffer size */
-        unsigned body_size = stride * aligned_height;
-        unsigned buffer_size = header_size + body_size;
-
-        /* Allocate the AFBC slab itself, large enough to hold the above */
-        panfrost_drm_allocate_slab(screen, &rsrc->bo->afbc_slab,
-                               ALIGN(buffer_size, 4096) / 4096,
-                               true, 0, 0, 0);
-
-        /* Compressed textured reads use a tagged pointer to the metadata */
-        rsrc->bo->layout = PAN_AFBC;
-        rsrc->bo->gpu = rsrc->bo->afbc_slab.gpu | (ds ? 0 : 1);
-        rsrc->bo->cpu = rsrc->bo->afbc_slab.cpu;
-        rsrc->bo->gem_handle = rsrc->bo->afbc_slab.gem_handle;
-        rsrc->bo->afbc_metadata_size = header_size;
 }