panfrost: Merge AFBC slab with BO backing
[mesa.git] / src / gallium / drivers / panfrost / pan_resource.c
index 027cd61f16d307baed30deb7cdf25681850a9ce3..d8f1a9b521f4328771ef911d67cda7a89af3867d 100644 (file)
@@ -197,6 +197,7 @@ panfrost_setup_slices(const struct pipe_resource *tmpl, struct panfrost_bo *bo)
 
         bool renderable = tmpl->bind &
                 (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL);
+        bool afbc = bo->layout == PAN_AFBC;
         bool tiled = bo->layout == PAN_TILED;
         bool should_align = renderable || tiled;
 
@@ -243,6 +244,14 @@ panfrost_setup_slices(const struct pipe_resource *tmpl, struct panfrost_bo *bo)
                 if (l == 0)
                         size_2d = slice_one_size;
 
+                /* Compute AFBC sizes if necessary */
+                if (afbc) {
+                        slice->header_size =
+                                panfrost_afbc_header_size(width, height);
+
+                        offset += slice->header_size;
+                }
+
                 offset += slice_full_size;
 
                 width = u_minify(width, 1);
@@ -295,20 +304,21 @@ panfrost_create_bo(struct panfrost_screen *screen, const struct pipe_resource *t
 
         bool should_tile = is_streaming && is_texture && is_2d;
 
+        /* Depth/stencil can't be tiled, only linear or AFBC */
+        should_tile &= !(template->bind & PIPE_BIND_DEPTH_STENCIL);
+
         /* Set the layout appropriately */
         bo->layout = should_tile ? PAN_TILED : PAN_LINEAR;
 
         panfrost_setup_slices(template, bo);
 
-        if (bo->layout == PAN_TILED || bo->layout == PAN_LINEAR) {
-                struct panfrost_memory mem;
+        struct panfrost_memory mem;
 
-                panfrost_drm_allocate_slab(screen, &mem, bo->size / 4096, true, 0, 0, 0);
+        panfrost_drm_allocate_slab(screen, &mem, bo->size / 4096, true, 0, 0, 0);
 
-                bo->cpu = mem.cpu;
-                bo->gpu = mem.gpu;
-                bo->gem_handle = mem.gem_handle;
-        }
+        bo->cpu = mem.cpu;
+        bo->gpu = mem.gpu;
+        bo->gem_handle = mem.gem_handle;
 
         return bo;
 }
@@ -375,8 +385,7 @@ panfrost_resource_create(struct pipe_screen *screen,
 static void
 panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *bo)
 {
-        if ((bo->layout == PAN_LINEAR || bo->layout == PAN_TILED) &&
-                        !bo->imported) {
+        if (!bo->imported) {
                 struct panfrost_memory mem = {
                         .cpu = bo->cpu,
                         .gpu = bo->gpu,
@@ -387,11 +396,6 @@ panfrost_destroy_bo(struct panfrost_screen *screen, struct panfrost_bo *bo)
                 panfrost_drm_free_slab(screen, &mem);
         }
 
-        if (bo->layout == PAN_AFBC) {
-                /* TODO */
-                DBG("--leaking afbc (%d bytes)--\n", bo->afbc_metadata_size);
-        }
-
         if (bo->has_checksum) {
                 struct panfrost_memory mem = {
                         .cpu = bo->checksum_slab.cpu,