Mesa (main): lima: fix buffer overallocation for index, vertex and constant buffers

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Jun 29 09:39:31 UTC 2022


Module: Mesa
Branch: main
Commit: 7c7b9007105e54cce70003297f16a180646b2f78
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=7c7b9007105e54cce70003297f16a180646b2f78

Author: Vasily Khoruzhick <anarsoul at gmail.com>
Date:   Tue Jun 28 08:58:55 2022 -0700

lima: fix buffer overallocation for index, vertex and constant buffers

24be0119016f ("lima: wire up MSAA 4x support") switched to aligning all the
buffers to tile size and it resulted in allocating 16x more memory for
index, vertex and constant buffers.

We only want to align textures and render targets to tile size, not
other buffers, so restore old logic, but relax it.

Fixes: 24be0119016f ("lima: wire up MSAA 4x support")
Acked-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Signed-off-by: Vasily Khoruzhick <anarsoul at gmail.com>
Reviewed-by: Erico Nunes <nunes.erico at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17283>

---

 src/gallium/drivers/lima/lima_resource.c | 33 ++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/lima/lima_resource.c b/src/gallium/drivers/lima/lima_resource.c
index 86c7fd9e283..10c471424f9 100644
--- a/src/gallium/drivers/lima/lima_resource.c
+++ b/src/gallium/drivers/lima/lima_resource.c
@@ -89,7 +89,8 @@ lima_resource_create_scanout(struct pipe_screen *pscreen,
 
 static uint32_t
 setup_miptree(struct lima_resource *res,
-              unsigned width0, unsigned height0)
+              unsigned width0, unsigned height0,
+              bool align_to_tile)
 {
    struct pipe_resource *pres = &res->base;
    unsigned level;
@@ -105,8 +106,13 @@ setup_miptree(struct lima_resource *res,
       unsigned aligned_width;
       unsigned aligned_height;
 
-      aligned_width = align(width, 16);
-      aligned_height = align(height, 16);
+      if (align_to_tile) {
+         aligned_width = align(width, 16);
+         aligned_height = align(height, 16);
+      } else {
+         aligned_width = width;
+         aligned_height = height;
+      }
 
       stride = util_format_get_stride(pres->format, aligned_width);
       actual_level_size = stride *
@@ -139,7 +145,8 @@ setup_miptree(struct lima_resource *res,
 static struct pipe_resource *
 lima_resource_create_bo(struct pipe_screen *pscreen,
                         const struct pipe_resource *templat,
-                        unsigned width, unsigned height)
+                        unsigned width, unsigned height,
+                        bool align_to_tile)
 {
    struct lima_screen *screen = lima_screen(pscreen);
    struct lima_resource *res;
@@ -155,7 +162,7 @@ lima_resource_create_bo(struct pipe_screen *pscreen,
 
    pres = &res->base;
 
-   uint32_t size = setup_miptree(res, width, height);
+   uint32_t size = setup_miptree(res, width, height, align_to_tile);
    size = align(size, LIMA_PAGE_SIZE);
 
    res->bo = lima_bo_create(screen, size, 0);
@@ -177,6 +184,7 @@ _lima_resource_create_with_modifiers(struct pipe_screen *pscreen,
    bool should_tile = lima_debug & LIMA_DEBUG_NO_TILING ? false : true;
    unsigned width, height;
    bool has_user_modifiers = true;
+   bool align_to_tile = false;
 
    if (count == 1 && modifiers[0] == DRM_FORMAT_MOD_INVALID)
       has_user_modifiers = false;
@@ -197,14 +205,23 @@ _lima_resource_create_with_modifiers(struct pipe_screen *pscreen,
                          modifiers, count))
       should_tile = false;
 
-   width = align(templat->width0, 16);
-   height = align(templat->height0, 16);
+   /* Don't align index, vertex or constant buffers */
+   if (templat->bind & (PIPE_BIND_INDEX_BUFFER |
+                        PIPE_BIND_VERTEX_BUFFER |
+                        PIPE_BIND_CONSTANT_BUFFER)) {
+      width = templat->width0;
+      height = templat->height0;
+   } else {
+      width = align(templat->width0, 16);
+      height = align(templat->height0, 16);
+      align_to_tile = true;
+   }
 
    struct pipe_resource *pres;
    if (screen->ro && (templat->bind & PIPE_BIND_SCANOUT))
       pres = lima_resource_create_scanout(pscreen, templat, width, height);
    else
-      pres = lima_resource_create_bo(pscreen, templat, width, height);
+      pres = lima_resource_create_bo(pscreen, templat, width, height, align_to_tile);
 
    if (pres) {
       struct lima_resource *res = lima_resource(pres);



More information about the mesa-commit mailing list