freedreno/a5xx+a6xx: split LRZ layout to per-gen
authorRob Clark <robdclark@chromium.org>
Tue, 10 Dec 2019 22:24:59 +0000 (14:24 -0800)
committerRob Clark <robdclark@gmail.com>
Tue, 10 Dec 2019 22:55:21 +0000 (22:55 +0000)
Seems to be a bit different for a6xx, so let's split this out.

Signed-off-by: Rob Clark <robdclark@chromium.org>
src/gallium/drivers/freedreno/a5xx/fd5_resource.c
src/gallium/drivers/freedreno/a6xx/fd6_resource.c
src/gallium/drivers/freedreno/freedreno_resource.c
src/gallium/drivers/freedreno/freedreno_resource.h

index 7e1497630b09b3d8f8ec610e550f315f5901e5f9..0d356286eb55badd8ac3b6c8888f75c386b9848d 100644 (file)
@@ -127,11 +127,42 @@ setup_slices(struct fd_resource *rsc, uint32_t alignment, enum pipe_format forma
        return size;
 }
 
+static void
+setup_lrz(struct fd_resource *rsc)
+{
+       struct fd_screen *screen = fd_screen(rsc->base.screen);
+       const uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
+                       DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
+       unsigned lrz_pitch  = align(DIV_ROUND_UP(rsc->base.width0, 8), 64);
+       unsigned lrz_height = DIV_ROUND_UP(rsc->base.height0, 8);
+
+       /* LRZ buffer is super-sampled: */
+       switch (rsc->base.nr_samples) {
+       case 4:
+               lrz_pitch *= 2;
+               /* fallthrough */
+       case 2:
+               lrz_height *= 2;
+       }
+
+       unsigned size = lrz_pitch * lrz_height * 2;
+
+       size += 0x1000; /* for GRAS_LRZ_FAST_CLEAR_BUFFER */
+
+       rsc->lrz_height = lrz_height;
+       rsc->lrz_width = lrz_pitch;
+       rsc->lrz_pitch = lrz_pitch;
+       rsc->lrz = fd_bo_new(screen->dev, size, flags, "lrz");
+}
+
 uint32_t
 fd5_setup_slices(struct fd_resource *rsc)
 {
        uint32_t alignment;
 
+       if ((fd_mesa_debug & FD_DBG_LRZ) && has_depth(rsc->base.format))
+               setup_lrz(rsc);
+
        switch (rsc->base.target) {
        case PIPE_TEXTURE_3D:
                rsc->layout.layer_first = false;
index 430044aebbb243ab4243314088092696c85c16b1..f75ca0666be500d697ce177be567c3a74918d53e 100644 (file)
@@ -289,11 +289,42 @@ fd6_validate_format(struct fd_context *ctx, struct fd_resource *rsc,
        fd_resource_uncompress(ctx, rsc);
 }
 
+static void
+setup_lrz(struct fd_resource *rsc)
+{
+       struct fd_screen *screen = fd_screen(rsc->base.screen);
+       const uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
+                       DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
+       unsigned lrz_pitch  = align(DIV_ROUND_UP(rsc->base.width0, 8), 64);
+       unsigned lrz_height = DIV_ROUND_UP(rsc->base.height0, 8);
+
+       /* LRZ buffer is super-sampled: */
+       switch (rsc->base.nr_samples) {
+       case 4:
+               lrz_pitch *= 2;
+               /* fallthrough */
+       case 2:
+               lrz_height *= 2;
+       }
+
+       unsigned size = lrz_pitch * lrz_height * 2;
+
+       size += 0x1000; /* for GRAS_LRZ_FAST_CLEAR_BUFFER */
+
+       rsc->lrz_height = lrz_height;
+       rsc->lrz_width = lrz_pitch;
+       rsc->lrz_pitch = lrz_pitch;
+       rsc->lrz = fd_bo_new(screen->dev, size, flags, "lrz");
+}
+
 uint32_t
 fd6_setup_slices(struct fd_resource *rsc)
 {
        uint32_t alignment;
 
+       if ((fd_mesa_debug & FD_DBG_LRZ) && has_depth(rsc->base.format))
+               setup_lrz(rsc);
+
        switch (rsc->base.target) {
        case PIPE_TEXTURE_3D:
                rsc->layout.layer_first = false;
index b998bac36ebbfda73ef82a4688d84cf6a43aa625..c17bd365f1a507f52fe68cd046f3930f728bc4dd 100644 (file)
@@ -877,25 +877,6 @@ fd_resource_resize(struct pipe_resource *prsc, uint32_t sz)
        realloc_bo(rsc, fd_screen(prsc->screen)->setup_slices(rsc));
 }
 
-// TODO common helper?
-static bool
-has_depth(enum pipe_format format)
-{
-       switch (format) {
-       case PIPE_FORMAT_Z16_UNORM:
-       case PIPE_FORMAT_Z32_UNORM:
-       case PIPE_FORMAT_Z32_FLOAT:
-       case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
-       case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-       case PIPE_FORMAT_S8_UINT_Z24_UNORM:
-       case PIPE_FORMAT_Z24X8_UNORM:
-       case PIPE_FORMAT_X8Z24_UNORM:
-               return true;
-       default:
-               return false;
-       }
-}
-
 static void
 fd_resource_layout_init(struct pipe_resource *prsc)
 {
@@ -1009,32 +990,6 @@ fd_resource_create_with_modifiers(struct pipe_screen *pscreen,
 
        rsc->internal_format = format;
 
-       // XXX probably need some extra work if we hit rsc shadowing path w/ lrz..
-       if ((is_a5xx(screen) || is_a6xx(screen)) &&
-                (fd_mesa_debug & FD_DBG_LRZ) && has_depth(format)) {
-               const uint32_t flags = DRM_FREEDRENO_GEM_CACHE_WCOMBINE |
-                               DRM_FREEDRENO_GEM_TYPE_KMEM; /* TODO */
-               unsigned lrz_pitch  = align(DIV_ROUND_UP(tmpl->width0, 8), 64);
-               unsigned lrz_height = DIV_ROUND_UP(tmpl->height0, 8);
-
-               /* LRZ buffer is super-sampled: */
-               switch (prsc->nr_samples) {
-               case 4:
-                       lrz_pitch *= 2;
-               case 2:
-                       lrz_height *= 2;
-               }
-
-               unsigned size = lrz_pitch * lrz_height * 2;
-
-               size += 0x1000; /* for GRAS_LRZ_FAST_CLEAR_BUFFER */
-
-               rsc->lrz_height = lrz_height;
-               rsc->lrz_width = lrz_pitch;
-               rsc->lrz_pitch = lrz_pitch;
-               rsc->lrz = fd_bo_new(screen->dev, size, flags, "lrz");
-       }
-
        size = screen->setup_slices(rsc);
 
        if (allow_ubwc && screen->fill_ubwc_buffer_sizes && rsc->layout.tile_mode)
index bc972297a3523b2bce1a9a17d3c5c8844ed0166f..7a4f9fe2930645e9ed0d667580ae15f219cd7178 100644 (file)
@@ -113,6 +113,14 @@ pending(struct fd_resource *rsc, bool write)
        return false;
 }
 
+static inline bool
+has_depth(enum pipe_format format)
+{
+       const struct util_format_description *desc =
+                       util_format_description(format);
+       return util_format_has_depth(desc);
+}
+
 struct fd_transfer {
        struct pipe_transfer base;
        struct pipe_resource *staging_prsc;