Mesa (main): iris: Add a BO_ALLOC_SMEM flag for allocating from system memory

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jun 7 18:49:17 UTC 2021


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

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Tue May 11 14:56:58 2021 -0700

iris: Add a BO_ALLOC_SMEM flag for allocating from system memory

Most allocations will want to be in device local memory (if it exists),
so we default to LMEM in the absence of a flag.  However, some buffers
are expected to be read/written from the CPU multiple times, and we may
want to explicitly place those buffers in system memory.

This patch adds the infrastructure for deciding on the allocation,
and sets the flags, but does not actually hook up the flag to do
anything, as the kernel infrastructure for LMEM support hasn't landed.

Reviewed-by: Tapani Pälli <tapani.palli at intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11169>

---

 src/gallium/drivers/iris/iris_bufmgr.h   |  1 +
 src/gallium/drivers/iris/iris_resource.c | 37 ++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h
index 9c0a243d7d2..4a44051ac12 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.h
+++ b/src/gallium/drivers/iris/iris_bufmgr.h
@@ -242,6 +242,7 @@ struct iris_bo {
 
 #define BO_ALLOC_ZEROED     (1<<0)
 #define BO_ALLOC_COHERENT   (1<<1)
+#define BO_ALLOC_SMEM       (1<<2)
 
 /**
  * Allocate a buffer object.
diff --git a/src/gallium/drivers/iris/iris_resource.c b/src/gallium/drivers/iris/iris_resource.c
index 3d28c83c3ad..0d1f493909e 100644
--- a/src/gallium/drivers/iris/iris_resource.c
+++ b/src/gallium/drivers/iris/iris_resource.c
@@ -436,6 +436,33 @@ iris_resource_disable_aux(struct iris_resource *res)
    res->aux.state = NULL;
 }
 
+static uint32_t
+iris_resource_alloc_flags(const struct iris_screen *screen,
+                          const struct pipe_resource *templ)
+{
+   uint32_t flags = 0;
+
+   switch (templ->usage) {
+   case PIPE_USAGE_STAGING:
+      flags |= BO_ALLOC_SMEM | BO_ALLOC_COHERENT;
+      break;
+   case PIPE_USAGE_STREAM:
+      flags |= BO_ALLOC_SMEM;
+      break;
+   case PIPE_USAGE_DYNAMIC:
+   case PIPE_USAGE_DEFAULT:
+   case PIPE_USAGE_IMMUTABLE:
+      /* Use LMEM for these if possible */
+      break;
+   }
+
+   if (templ->flags & (PIPE_RESOURCE_FLAG_MAP_COHERENT |
+                       PIPE_RESOURCE_FLAG_MAP_PERSISTENT))
+      flags |= BO_ALLOC_SMEM;
+
+   return flags;
+}
+
 static void
 iris_resource_destroy(struct pipe_screen *screen,
                       struct pipe_resource *p_res)
@@ -950,7 +977,11 @@ iris_resource_create_for_buffer(struct pipe_screen *pscreen,
       name = "dynamic state";
    }
 
-   res->bo = iris_bo_alloc(screen->bufmgr, name, templ->width0, 1, memzone, 0);
+   unsigned flags = iris_resource_alloc_flags(screen, templ);
+
+   res->bo =
+      iris_bo_alloc(screen->bufmgr, name, templ->width0, 1, memzone, flags);
+
    if (!res->bo) {
       iris_resource_destroy(pscreen, &res->base.b);
       return NULL;
@@ -992,9 +1023,7 @@ iris_resource_create_with_modifiers(struct pipe_screen *pscreen,
    const char *name = "miptree";
    enum iris_memory_zone memzone = IRIS_MEMZONE_OTHER;
 
-   unsigned int flags = 0;
-   if (templ->usage == PIPE_USAGE_STAGING)
-      flags |= BO_ALLOC_COHERENT;
+   unsigned int flags = iris_resource_alloc_flags(screen, templ);
 
    /* These are for u_upload_mgr buffers only */
    assert(!(templ->flags & (IRIS_RESOURCE_FLAG_SHADER_MEMZONE |



More information about the mesa-commit mailing list