d11d1f4
From 7c19437292c0da14bda555b3f55875eb8c0b2ed2 Mon Sep 17 00:00:00 2001
d11d1f4
From: Karol Herbst <kherbst@redhat.com>
d11d1f4
Date: Thu, 16 Sep 2021 13:07:31 -0400
d11d1f4
Subject: [PATCH 3/6] Revert "nouveau: Use format modifiers in buffer
d11d1f4
 allocation"
d11d1f4
d11d1f4
This reverts commit 129d83cac2accc4a66eae50c19ac245b864dc98c.
d11d1f4
---
d11d1f4
 .../drivers/nouveau/nvc0/nvc0_miptree.c       | 125 ++----------------
d11d1f4
 1 file changed, 8 insertions(+), 117 deletions(-)
d11d1f4
d11d1f4
diff --git a/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c b/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c
d11d1f4
index e0a9d48249f..8260a90f0d6 100644
d11d1f4
--- a/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c
d11d1f4
+++ b/src/gallium/drivers/nouveau/nvc0/nvc0_miptree.c
d11d1f4
@@ -184,7 +184,7 @@ nvc0_choose_tiled_storage_type(struct pipe_screen *pscreen,
d11d1f4
 
d11d1f4
 static uint32_t
d11d1f4
 nvc0_mt_choose_storage_type(struct pipe_screen *pscreen,
d11d1f4
-                            const struct nv50_miptree *mt,
d11d1f4
+                            struct nv50_miptree *mt,
d11d1f4
                             bool compressed)
d11d1f4
 {
d11d1f4
    const unsigned ms = util_logbase2(mt->base.base.nr_samples);
d11d1f4
@@ -249,7 +249,7 @@ nvc0_miptree_init_layout_video(struct nv50_miptree *mt)
d11d1f4
 }
d11d1f4
 
d11d1f4
 static void
d11d1f4
-nvc0_miptree_init_layout_tiled(struct nv50_miptree *mt, uint64_t modifier)
d11d1f4
+nvc0_miptree_init_layout_tiled(struct nv50_miptree *mt)
d11d1f4
 {
d11d1f4
    struct pipe_resource *pt = &mt->base.base;
d11d1f4
    unsigned w, h, d, l;
d11d1f4
@@ -266,9 +266,6 @@ nvc0_miptree_init_layout_tiled(struct nv50_miptree *mt, uint64_t modifier)
d11d1f4
    d = mt->layout_3d ? pt->depth0 : 1;
d11d1f4
 
d11d1f4
    assert(!mt->ms_mode || !pt->last_level);
d11d1f4
-   assert(modifier == DRM_FORMAT_MOD_INVALID ||
d11d1f4
-          (!pt->last_level && !mt->layout_3d));
d11d1f4
-   assert(modifier != DRM_FORMAT_MOD_LINEAR);
d11d1f4
 
d11d1f4
    for (l = 0; l <= pt->last_level; ++l) {
d11d1f4
       struct nv50_miptree_level *lvl = &mt->level[l];
d11d1f4
@@ -278,16 +275,7 @@ nvc0_miptree_init_layout_tiled(struct nv50_miptree *mt, uint64_t modifier)
d11d1f4
 
d11d1f4
       lvl->offset = mt->total_size;
d11d1f4
 
d11d1f4
-      if (modifier != DRM_FORMAT_MOD_INVALID)
d11d1f4
-         /* Extract the log2(block height) field from the modifier and pack it
d11d1f4
-          * into tile_mode's y field. Other tile dimensions are always 1
d11d1f4
-          * (represented using 0 here) for 2D surfaces, and non-2D surfaces are
d11d1f4
-          * not supported by the current modifiers (asserted above). Note the
d11d1f4
-          * modifier must be validated prior to calling this function.
d11d1f4
-          */
d11d1f4
-         lvl->tile_mode = ((uint32_t)modifier & 0xf) << 4;
d11d1f4
-      else
d11d1f4
-         lvl->tile_mode = nvc0_tex_choose_tile_dims(nbx, nby, d, mt->layout_3d);
d11d1f4
+      lvl->tile_mode = nvc0_tex_choose_tile_dims(nbx, nby, d, mt->layout_3d);
d11d1f4
 
d11d1f4
       tsx = NVC0_TILE_SIZE_X(lvl->tile_mode); /* x is tile row pitch in bytes */
d11d1f4
       tsy = NVC0_TILE_SIZE_Y(lvl->tile_mode);
d11d1f4
@@ -358,84 +346,6 @@ nvc0_miptree_get_handle(struct pipe_screen *pscreen,
d11d1f4
    return true;
d11d1f4
 }
d11d1f4
 
d11d1f4
-static uint64_t
d11d1f4
-nvc0_miptree_select_best_modifier(struct pipe_screen *pscreen,
d11d1f4
-                                  const struct nv50_miptree *mt,
d11d1f4
-                                  const uint64_t *modifiers,
d11d1f4
-                                  unsigned int count)
d11d1f4
-{
d11d1f4
-   /*
d11d1f4
-    * Supported block heights are 1,2,4,8,16,32, stored as log2() their
d11d1f4
-    * value. Reserve one slot for each, as well as the linear modifier.
d11d1f4
-    */
d11d1f4
-   uint64_t prio_supported_mods[] = {
d11d1f4
-      DRM_FORMAT_MOD_INVALID,
d11d1f4
-      DRM_FORMAT_MOD_INVALID,
d11d1f4
-      DRM_FORMAT_MOD_INVALID,
d11d1f4
-      DRM_FORMAT_MOD_INVALID,
d11d1f4
-      DRM_FORMAT_MOD_INVALID,
d11d1f4
-      DRM_FORMAT_MOD_INVALID,
d11d1f4
-      DRM_FORMAT_MOD_LINEAR,
d11d1f4
-   };
d11d1f4
-   const uint32_t uc_kind = nvc0_mt_choose_storage_type(pscreen, mt, false);
d11d1f4
-   int top_mod_slot = ARRAY_SIZE(prio_supported_mods);
d11d1f4
-   const uint32_t kind_gen = nvc0_get_kind_generation(pscreen);
d11d1f4
-   unsigned int i;
d11d1f4
-   int p;
d11d1f4
-
d11d1f4
-   if (uc_kind != 0u) {
d11d1f4
-      const struct pipe_resource *pt = &mt->base.base;
d11d1f4
-      const unsigned nbx = util_format_get_nblocksx(pt->format, pt->width0);
d11d1f4
-      const unsigned nby = util_format_get_nblocksy(pt->format, pt->height0);
d11d1f4
-      const uint32_t lbh_preferred =
d11d1f4
-         NVC0_TILE_MODE_Y(nvc0_tex_choose_tile_dims(nbx, nby, 1u, false));
d11d1f4
-      uint32_t lbh = lbh_preferred;
d11d1f4
-      bool dec_lbh = true;
d11d1f4
-      const uint8_t s = nouveau_screen(pscreen)->tegra_sector_layout ? 0 : 1;
d11d1f4
-
d11d1f4
-      for (i = 0; i < ARRAY_SIZE(prio_supported_mods) - 1; i++) {
d11d1f4
-         assert(lbh <= 5u);
d11d1f4
-         prio_supported_mods[i] =
d11d1f4
-            DRM_FORMAT_MOD_NVIDIA_BLOCK_LINEAR_2D(0, s, kind_gen, uc_kind, lbh);
d11d1f4
-
d11d1f4
-         /*
d11d1f4
-          * The preferred block height is the largest block size that doesn't
d11d1f4
-          * waste excessive space with unused padding bytes relative to the
d11d1f4
-          * height of the image.  Construct the priority array such that
d11d1f4
-          * the preferred block height is highest priority, followed by
d11d1f4
-          * progressively smaller block sizes down to a block height of one,
d11d1f4
-          * followed by progressively larger (more wasteful) block sizes up
d11d1f4
-          * to 5.
d11d1f4
-          */
d11d1f4
-         if (lbh == 0u) {
d11d1f4
-            lbh = lbh_preferred + 1u;
d11d1f4
-            dec_lbh = false;
d11d1f4
-         } else if (dec_lbh) {
d11d1f4
-            lbh--;
d11d1f4
-         } else {
d11d1f4
-            lbh++;
d11d1f4
-         }
d11d1f4
-      }
d11d1f4
-   }
d11d1f4
-
d11d1f4
-   assert(prio_supported_mods[ARRAY_SIZE(prio_supported_mods) - 1] ==
d11d1f4
-          DRM_FORMAT_MOD_LINEAR);
d11d1f4
-
d11d1f4
-   for (i = 0u; i < count; i++) {
d11d1f4
-      for (p = 0; p < ARRAY_SIZE(prio_supported_mods); p++) {
d11d1f4
-         if (prio_supported_mods[p] == modifiers[i]) {
d11d1f4
-            if (top_mod_slot > p) top_mod_slot = p;
d11d1f4
-            break;
d11d1f4
-         }
d11d1f4
-      }
d11d1f4
-   }
d11d1f4
-
d11d1f4
-   if (top_mod_slot >= ARRAY_SIZE(prio_supported_mods))
d11d1f4
-       return DRM_FORMAT_MOD_INVALID;
d11d1f4
-
d11d1f4
-   return prio_supported_mods[top_mod_slot];
d11d1f4
-}
d11d1f4
-
d11d1f4
 struct pipe_resource *
d11d1f4
 nvc0_miptree_create(struct pipe_screen *pscreen,
d11d1f4
                     const struct pipe_resource *templ,
d11d1f4
@@ -450,7 +360,6 @@ nvc0_miptree_create(struct pipe_screen *pscreen,
d11d1f4
    union nouveau_bo_config bo_config;
d11d1f4
    uint32_t bo_flags;
d11d1f4
    unsigned pitch_align;
d11d1f4
-   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
d11d1f4
 
d11d1f4
    if (!mt)
d11d1f4
       return NULL;
d11d1f4
@@ -460,9 +369,6 @@ nvc0_miptree_create(struct pipe_screen *pscreen,
d11d1f4
    pt->screen = pscreen;
d11d1f4
 
d11d1f4
    if (pt->usage == PIPE_USAGE_STAGING) {
d11d1f4
-      /* PIPE_USAGE_STAGING, and usage in general, should not be specified when
d11d1f4
-       * modifiers are used. */
d11d1f4
-      assert(count == 0);
d11d1f4
       switch (pt->target) {
d11d1f4
       case PIPE_TEXTURE_2D:
d11d1f4
       case PIPE_TEXTURE_RECT:
d11d1f4
@@ -476,27 +382,13 @@ nvc0_miptree_create(struct pipe_screen *pscreen,
d11d1f4
       }
d11d1f4
    }
d11d1f4
 
d11d1f4
-   if (pt->bind & PIPE_BIND_LINEAR)
d11d1f4
+   if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_LINEAR)
d11d1f4
       pt->flags |= NOUVEAU_RESOURCE_FLAG_LINEAR;
d11d1f4
 
d11d1f4
-   if (count > 0) {
d11d1f4
-      modifier = nvc0_miptree_select_best_modifier(pscreen, mt,
d11d1f4
-                                                   modifiers, count);
d11d1f4
-
d11d1f4
-      if (modifier == DRM_FORMAT_MOD_INVALID) {
d11d1f4
-         FREE(mt);
d11d1f4
-         return NULL;
d11d1f4
-      }
d11d1f4
+   if (pt->bind & PIPE_BIND_LINEAR)
d11d1f4
+      pt->flags |= NOUVEAU_RESOURCE_FLAG_LINEAR;
d11d1f4
 
d11d1f4
-      if (modifier == DRM_FORMAT_MOD_LINEAR) {
d11d1f4
-         pt->flags |= NOUVEAU_RESOURCE_FLAG_LINEAR;
d11d1f4
-         bo_config.nvc0.memtype = 0;
d11d1f4
-      } else {
d11d1f4
-         bo_config.nvc0.memtype = (modifier >> 12) & 0xff;
d11d1f4
-      }
d11d1f4
-   } else {
d11d1f4
-      bo_config.nvc0.memtype = nvc0_mt_choose_storage_type(pscreen, mt, compressed);
d11d1f4
-   }
d11d1f4
+   bo_config.nvc0.memtype = nvc0_mt_choose_storage_type(pscreen, mt, compressed);
d11d1f4
 
d11d1f4
    if (!nvc0_miptree_init_ms_mode(mt)) {
d11d1f4
       FREE(mt);
d11d1f4
@@ -504,11 +396,10 @@ nvc0_miptree_create(struct pipe_screen *pscreen,
d11d1f4
    }
d11d1f4
 
d11d1f4
    if (unlikely(pt->flags & NVC0_RESOURCE_FLAG_VIDEO)) {
d11d1f4
-      assert(modifier == DRM_FORMAT_MOD_INVALID);
d11d1f4
       nvc0_miptree_init_layout_video(mt);
d11d1f4
    } else
d11d1f4
    if (likely(bo_config.nvc0.memtype)) {
d11d1f4
-      nvc0_miptree_init_layout_tiled(mt, modifier);
d11d1f4
+      nvc0_miptree_init_layout_tiled(mt);
d11d1f4
    } else {
d11d1f4
       /* When modifiers are supplied, usage is zero. TODO: detect the
d11d1f4
        * modifiers+cursor case. */
d11d1f4
-- 
d11d1f4
2.31.1
d11d1f4