panfrost: Remove enum panfrost_memory_layout
authorAlyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Tue, 18 Feb 2020 14:49:13 +0000 (09:49 -0500)
committerMarge Bot <eric+marge@anholt.net>
Tue, 18 Feb 2020 16:20:56 +0000 (16:20 +0000)
It duplicates mali_texture_layout. Let's use the native hardware enum
and spare a pointless translation.

Signed-off-by: Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com>
Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3854>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3854>

src/gallium/drivers/panfrost/pan_context.c
src/gallium/drivers/panfrost/pan_mfbd.c
src/gallium/drivers/panfrost/pan_resource.c
src/gallium/drivers/panfrost/pan_resource.h
src/gallium/drivers/panfrost/pan_sfbd.c

index 6f45901ee8114438da5855950227f2539065ba36..b0a5e784b040b897b54a9d550c3130ad02cd605f 100644 (file)
@@ -471,21 +471,6 @@ panfrost_upload_sampler_descriptors(struct panfrost_context *ctx)
         }
 }
 
-static enum mali_texture_layout
-panfrost_layout_for_texture(struct panfrost_resource *rsrc)
-{
-        switch (rsrc->layout) {
-        case PAN_AFBC:
-                return MALI_TEXTURE_AFBC;
-        case PAN_TILED:
-                return MALI_TEXTURE_TILED;
-        case PAN_LINEAR:
-                return MALI_TEXTURE_LINEAR;
-        default:
-                unreachable("Invalid texture layout");
-        }
-}
-
 static mali_ptr
 panfrost_upload_tex(
         struct panfrost_context *ctx,
@@ -532,7 +517,7 @@ panfrost_upload_tex(
         }
 
         /* Lower-bit is set when sampling from colour AFBC */
-        bool is_afbc = rsrc->layout == PAN_AFBC;
+        bool is_afbc = rsrc->layout == MALI_TEXTURE_AFBC;
         bool is_zs = rsrc->base.bind & PIPE_BIND_DEPTH_STENCIL;
         unsigned afbc_bit = (is_afbc && !is_zs) ? 1 : 0;
 
@@ -545,7 +530,7 @@ panfrost_upload_tex(
         /* Add the usage flags in, since they can change across the CSO
          * lifetime due to layout switches */
 
-        view->hw.format.layout = panfrost_layout_for_texture(rsrc);
+        view->hw.format.layout = rsrc->layout;
         view->hw.format.manual_stride = has_manual_stride;
 
         /* Inject the addresses in, interleaving array indices, mip levels,
@@ -2161,7 +2146,7 @@ panfrost_create_sampler_view(
         unsigned first_level = template->u.tex.first_level;
         unsigned last_level = template->u.tex.last_level;
 
-        if (prsrc->layout == PAN_LINEAR) {
+        if (prsrc->layout == MALI_TEXTURE_LINEAR) {
                 for (unsigned l = first_level; l <= last_level; ++l) {
                         unsigned actual_stride = prsrc->slices[l].stride;
                         unsigned width = u_minify(texture->width0, l);
@@ -2276,14 +2261,14 @@ panfrost_hint_afbc(
         for (unsigned i = 0; i < fb->nr_cbufs; ++i) {
                 struct pipe_surface *surf = fb->cbufs[i];
                 struct panfrost_resource *rsrc = pan_resource(surf->texture);
-                panfrost_resource_hint_layout(screen, rsrc, PAN_AFBC, 1);
+                panfrost_resource_hint_layout(screen, rsrc, MALI_TEXTURE_AFBC, 1);
         }
 
         /* Also hint it to the depth buffer */
 
         if (fb->zsbuf) {
                 struct panfrost_resource *rsrc = pan_resource(fb->zsbuf->texture);
-                panfrost_resource_hint_layout(screen, rsrc, PAN_AFBC, 1);
+                panfrost_resource_hint_layout(screen, rsrc, MALI_TEXTURE_AFBC, 1);
         }
 }
 
index 72a0743e9f3a187abd4b88a4bbf2dbf4cf29ee08..c2cc11d111968b6bc6510e5537ebfc6610a1eec6 100644 (file)
@@ -199,15 +199,15 @@ panfrost_mfbd_set_cbuf(
 
         /* Now, we set the layout specific pieces */
 
-        if (rsrc->layout == PAN_LINEAR) {
+        if (rsrc->layout == MALI_TEXTURE_LINEAR) {
                 rt->format.block = MALI_BLOCK_LINEAR;
                 rt->framebuffer = base;
                 rt->framebuffer_stride = stride / 16;
-        } else if (rsrc->layout == PAN_TILED) {
+        } else if (rsrc->layout == MALI_TEXTURE_TILED) {
                 rt->format.block = MALI_BLOCK_TILED;
                 rt->framebuffer = base;
                 rt->framebuffer_stride = stride;
-        } else if (rsrc->layout == PAN_AFBC) {
+        } else if (rsrc->layout == MALI_TEXTURE_AFBC) {
                 rt->format.block = MALI_BLOCK_AFBC;
 
                 unsigned header_size = rsrc->slices[level].header_size;
@@ -240,7 +240,7 @@ panfrost_mfbd_set_zsbuf(
 
         mali_ptr base = panfrost_get_texture_address(rsrc, level, first_layer);
 
-        if (rsrc->layout == PAN_AFBC) {
+        if (rsrc->layout == MALI_TEXTURE_AFBC) {
                 /* The only Z/S format we can compress is Z24S8 or variants
                  * thereof (handled by the state tracker) */
                 assert(panfrost_is_z24s8_variant(surf->format));
@@ -259,7 +259,7 @@ panfrost_mfbd_set_zsbuf(
 
                 fbx->ds_afbc.zero1 = 0x10009;
                 fbx->ds_afbc.padding = 0x1000;
-        } else if (rsrc->layout == PAN_LINEAR || rsrc->layout == PAN_TILED) {
+        } else if (rsrc->layout == MALI_TEXTURE_LINEAR || rsrc->layout == MALI_TEXTURE_TILED) {
                 /* TODO: Z32F(S8) support, which is always linear */
 
                 int stride = rsrc->slices[level].stride;
@@ -270,7 +270,7 @@ panfrost_mfbd_set_zsbuf(
 
                 fbx->ds_linear.depth = base;
 
-                if (rsrc->layout == PAN_LINEAR) {
+                if (rsrc->layout == MALI_TEXTURE_LINEAR) {
                         fbx->zs_block = MALI_BLOCK_LINEAR;
                         fbx->ds_linear.depth_stride = stride / 16;
                 } else {
index 6eeb4b832ed3d829bd2aa845773357858acf6b19..483450af9f84465eb36711936fe32825cbcb48cc 100644 (file)
@@ -85,6 +85,7 @@ panfrost_resource_from_handle(struct pipe_screen *pscreen,
 
         rsc->bo = panfrost_bo_import(screen, whandle->handle);
         rsc->internal_format = templat->format;
+        rsc->layout = MALI_TEXTURE_LINEAR;
         rsc->slices[0].stride = whandle->stride;
         rsc->slices[0].offset = whandle->offset;
         rsc->slices[0].initialized = true;
@@ -277,8 +278,8 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
 
         bool renderable = res->bind &
                           (PIPE_BIND_RENDER_TARGET | PIPE_BIND_DEPTH_STENCIL);
-        bool afbc = pres->layout == PAN_AFBC;
-        bool tiled = pres->layout == PAN_TILED;
+        bool afbc = pres->layout == MALI_TEXTURE_AFBC;
+        bool tiled = pres->layout == MALI_TEXTURE_TILED;
         bool should_align = renderable || tiled;
 
         /* We don't know how to specify a 2D stride for 3D textures */
@@ -319,7 +320,7 @@ panfrost_setup_slices(struct panfrost_resource *pres, size_t *bo_size)
                         stride /= 4;
 
                 /* ..but cache-line align it for performance */
-                if (can_align_stride && pres->layout == PAN_LINEAR)
+                if (can_align_stride && pres->layout == MALI_TEXTURE_LINEAR)
                         stride = ALIGN_POT(stride, 64);
 
                 slice->stride = stride;
@@ -420,7 +421,7 @@ panfrost_resource_create_bo(struct panfrost_screen *screen, struct panfrost_reso
 
         /* Set the layout appropriately */
         assert(!(must_tile && !can_tile)); /* must_tile => can_tile */
-        pres->layout = ((can_tile && should_tile) || must_tile) ? PAN_TILED : PAN_LINEAR;
+        pres->layout = ((can_tile && should_tile) || must_tile) ? MALI_TEXTURE_TILED : MALI_TEXTURE_LINEAR;
 
         size_t bo_size;
 
@@ -639,7 +640,7 @@ panfrost_transfer_map(struct pipe_context *pctx,
                 }
         }
 
-        if (rsrc->layout != PAN_LINEAR) {
+        if (rsrc->layout != MALI_TEXTURE_LINEAR) {
                 /* Non-linear resources need to be indirectly mapped */
 
                 if (usage & PIPE_TRANSFER_MAP_DIRECTLY)
@@ -651,9 +652,9 @@ panfrost_transfer_map(struct pipe_context *pctx,
                 assert(box->depth == 1);
 
                 if ((usage & PIPE_TRANSFER_READ) && rsrc->slices[level].initialized) {
-                        if (rsrc->layout == PAN_AFBC) {
+                        if (rsrc->layout == MALI_TEXTURE_AFBC) {
                                 DBG("Unimplemented: reads from AFBC");
-                        } else if (rsrc->layout == PAN_TILED) {
+                        } else if (rsrc->layout == MALI_TEXTURE_TILED) {
                                 panfrost_load_tiled_image(
                                         transfer->map,
                                         bo->cpu + rsrc->slices[level].offset,
@@ -700,9 +701,9 @@ panfrost_transfer_unmap(struct pipe_context *pctx,
                 struct panfrost_bo *bo = prsrc->bo;
 
                 if (transfer->usage & PIPE_TRANSFER_WRITE) {
-                        if (prsrc->layout == PAN_AFBC) {
+                        if (prsrc->layout == MALI_TEXTURE_AFBC) {
                                 DBG("Unimplemented: writes to AFBC\n");
-                        } else if (prsrc->layout == PAN_TILED) {
+                        } else if (prsrc->layout == MALI_TEXTURE_TILED) {
                                 assert(transfer->box.depth == 1);
 
                                 panfrost_store_tiled_image(
@@ -828,7 +829,7 @@ void
 panfrost_resource_hint_layout(
                 struct panfrost_screen *screen,
                 struct panfrost_resource *rsrc,
-                enum panfrost_memory_layout layout,
+                enum mali_texture_layout layout,
                 signed weight)
 {
         /* Nothing to do, although a sophisticated implementation might store
@@ -845,7 +846,7 @@ panfrost_resource_hint_layout(
 
         /* Check if the preferred layout is legal for this buffer */
 
-        if (layout == PAN_AFBC) {
+        if (layout == MALI_TEXTURE_AFBC) {
                 bool can_afbc = panfrost_format_supports_afbc(rsrc->base.format);
                 bool is_scanout = rsrc->base.bind &
                         (PIPE_BIND_DISPLAY_TARGET | PIPE_BIND_SCANOUT | PIPE_BIND_SHARED);
index 107c08dc628339f497bbb8b93b3c098e24284393..f3ba339add775c154930dff1b0e613d2928c6b96 100644 (file)
 #include "drm-uapi/drm.h"
 #include "util/u_range.h"
 
-/* Describes the memory layout of a BO */
-
-enum panfrost_memory_layout {
-        PAN_LINEAR,
-        PAN_TILED,
-        PAN_AFBC
-};
-
 struct panfrost_slice {
         unsigned offset;
         unsigned stride;
@@ -79,7 +71,7 @@ struct panfrost_resource {
         unsigned cubemap_stride;
 
         /* Internal layout (tiled?) */
-        enum panfrost_memory_layout layout;
+        enum mali_texture_layout layout;
 
         /* Is transaciton elimination enabled? */
         bool checksummed;
@@ -117,7 +109,7 @@ void
 panfrost_resource_hint_layout(
                 struct panfrost_screen *screen,
                 struct panfrost_resource *rsrc,
-                enum panfrost_memory_layout layout,
+                enum mali_texture_layout layout,
                 signed weight);
 
 /* AFBC */
index a4d29adc4602a32d1b20f0f429029b98c16c02e8..6e80649abf6496d945decdc81e30f40839088d84 100644 (file)
@@ -141,9 +141,9 @@ panfrost_sfbd_set_cbuf(
         fb->framebuffer = base;
         fb->stride = stride;
 
-        if (rsrc->layout == PAN_LINEAR)
+        if (rsrc->layout == MALI_TEXTURE_LINEAR)
                 fb->format.block = MALI_BLOCK_LINEAR;
-        else if (rsrc->layout == PAN_TILED) {
+        else if (rsrc->layout == MALI_TEXTURE_TILED) {
                 fb->format.block = MALI_BLOCK_TILED;
                 fb->stride *= 16;
         } else {
@@ -163,7 +163,7 @@ panfrost_sfbd_set_zsbuf(
         unsigned level = surf->u.tex.level;
         assert(surf->u.tex.first_layer == 0);
 
-        if (rsrc->layout != PAN_TILED)
+        if (rsrc->layout != MALI_TEXTURE_TILED)
                 unreachable("Invalid render layout.");
 
         fb->depth_buffer = rsrc->bo->gpu + rsrc->slices[level].offset;