Mesa (staging/22.0): iris: handle IRIS_MEMZONE_BINDER with a real vma_heap like the others

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Feb 16 23:00:49 UTC 2022


Module: Mesa
Branch: staging/22.0
Commit: af43668ef5b198bd54ebdb37cd29a61cc4c36a87
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=af43668ef5b198bd54ebdb37cd29a61cc4c36a87

Author: Paulo Zanoni <paulo.r.zanoni at intel.com>
Date:   Fri May 21 16:14:02 2021 -0700

iris: handle IRIS_MEMZONE_BINDER with a real vma_heap like the others

We're moving towards a path where all contexts share the same virtual
memory - because this will make implementing vm_bind much easier - ,
and to achieve that we need to rework the binder memzone. As it is,
different contexts will choose overlapping addresses. So in this patch
we adjust the Binder to be 1GB - per Ken's suggestion - and use a real
vma_heap for it. As a bonus the code gets simpler since it just reuses
the same pattern we already have for the other memzones.

Credits to Kenneth Granunke for helping me with this change.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Signed-off-by: Paulo Zanoni <paulo.r.zanoni at intel.com>
(cherry picked from commit 70dcffde4e584f326b8ced58986061d824d9f318)

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15036>

---

 src/gallium/drivers/iris/iris_binder.c | 16 ++--------------
 src/gallium/drivers/iris/iris_bufmgr.c | 19 +++++--------------
 src/gallium/drivers/iris/iris_bufmgr.h |  5 ++---
 3 files changed, 9 insertions(+), 31 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_binder.c b/src/gallium/drivers/iris/iris_binder.c
index 9266215d3e4..a6e444c976a 100644
--- a/src/gallium/drivers/iris/iris_binder.c
+++ b/src/gallium/drivers/iris/iris_binder.c
@@ -36,7 +36,7 @@
  * binding table entries are full 32-bit pointers.)
  *
  * To handle this, we split a 4GB region of VMA into two memory zones.
- * IRIS_MEMZONE_BINDER is a small region at the bottom able to hold a few
+ * IRIS_MEMZONE_BINDER is a 1GB region at the bottom able to hold a few
  * binder BOs.  IRIS_MEMZONE_SURFACE contains the rest of the 4GB, and is
  * always at a higher address than the binders.  This allows us to program
  * Surface State Base Address to the binder BO's address, and offset the
@@ -71,23 +71,11 @@ binder_realloc(struct iris_context *ice)
    struct iris_bufmgr *bufmgr = screen->bufmgr;
    struct iris_binder *binder = &ice->state.binder;
 
-   uint64_t next_address = IRIS_MEMZONE_BINDER_START;
-
-   if (binder->bo) {
-      /* Place the new binder just after the old binder, unless we've hit the
-       * end of the memory zone...then wrap around to the start again.
-       */
-      next_address = binder->bo->address + IRIS_BINDER_SIZE;
-      if (next_address >= IRIS_MEMZONE_BINDLESS_START)
-         next_address = IRIS_MEMZONE_BINDER_START;
-
+   if (binder->bo)
       iris_bo_unreference(binder->bo);
-   }
-
 
    binder->bo = iris_bo_alloc(bufmgr, "binder", IRIS_BINDER_SIZE, 1,
                               IRIS_MEMZONE_BINDER, 0);
-   binder->bo->address = next_address;
    binder->map = iris_bo_map(NULL, binder->bo, MAP_WRITE);
    binder->insert_point = INIT_INSERT_POINT;
 
diff --git a/src/gallium/drivers/iris/iris_bufmgr.c b/src/gallium/drivers/iris/iris_bufmgr.c
index 947b84275f4..34bb14be754 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.c
+++ b/src/gallium/drivers/iris/iris_bufmgr.c
@@ -395,10 +395,6 @@ vma_alloc(struct iris_bufmgr *bufmgr,
    if (memzone == IRIS_MEMZONE_BORDER_COLOR_POOL)
       return IRIS_BORDER_COLOR_POOL_ADDRESS;
 
-   /* The binder handles its own allocations.  Return non-zero here. */
-   if (memzone == IRIS_MEMZONE_BINDER)
-      return IRIS_MEMZONE_BINDER_START;
-
    uint64_t addr =
       util_vma_heap_alloc(&bufmgr->vma_allocator[memzone], size, alignment);
 
@@ -426,10 +422,6 @@ vma_free(struct iris_bufmgr *bufmgr,
 
    enum iris_memory_zone memzone = iris_memzone_for_address(address);
 
-   /* The binder handles its own allocations. */
-   if (memzone == IRIS_MEMZONE_BINDER)
-      return;
-
    assert(memzone < ARRAY_SIZE(bufmgr->vma_allocator));
 
    util_vma_heap_free(&bufmgr->vma_allocator[memzone], address, size);
@@ -1787,10 +1779,8 @@ iris_bufmgr_destroy(struct iris_bufmgr *bufmgr)
    _mesa_hash_table_destroy(bufmgr->name_table, NULL);
    _mesa_hash_table_destroy(bufmgr->handle_table, NULL);
 
-   for (int z = 0; z < IRIS_MEMZONE_COUNT; z++) {
-      if (z != IRIS_MEMZONE_BINDER)
+   for (int z = 0; z < IRIS_MEMZONE_COUNT; z++)
          util_vma_heap_finish(&bufmgr->vma_allocator[z]);
-   }
 
    close(bufmgr->fd);
 
@@ -2386,18 +2376,19 @@ iris_bufmgr_create(struct intel_device_info *devinfo, int fd, bool bo_reuse)
    STATIC_ASSERT(IRIS_MEMZONE_SHADER_START == 0ull);
    const uint64_t _4GB = 1ull << 32;
    const uint64_t _2GB = 1ul << 31;
+   const uint64_t _1GB = 1ul << 30;
 
    /* The STATE_BASE_ADDRESS size field can only hold 1 page shy of 4GB */
    const uint64_t _4GB_minus_1 = _4GB - PAGE_SIZE;
 
    util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_SHADER],
                       PAGE_SIZE, _4GB_minus_1 - PAGE_SIZE);
+   util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_BINDER],
+                      IRIS_MEMZONE_BINDER_START, _1GB - IRIS_BINDLESS_SIZE);
    util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_BINDLESS],
                       IRIS_MEMZONE_BINDLESS_START, IRIS_BINDLESS_SIZE);
    util_vma_heap_init(&bufmgr->vma_allocator[IRIS_MEMZONE_SURFACE],
-                      IRIS_MEMZONE_SURFACE_START,
-                      _4GB_minus_1 - IRIS_MAX_BINDERS * IRIS_BINDER_SIZE -
-                     IRIS_BINDLESS_SIZE);
+                      IRIS_MEMZONE_SURFACE_START, _4GB_minus_1 - _1GB);
    /* TODO: Why does limiting to 2GB help some state items on gfx12?
     *  - CC Viewport Pointer
     *  - Blend State Pointer
diff --git a/src/gallium/drivers/iris/iris_bufmgr.h b/src/gallium/drivers/iris/iris_bufmgr.h
index 24cd418965d..1d9259f715c 100644
--- a/src/gallium/drivers/iris/iris_bufmgr.h
+++ b/src/gallium/drivers/iris/iris_bufmgr.h
@@ -84,13 +84,12 @@ enum iris_memory_zone {
 #define IRIS_MEMZONE_COUNT (IRIS_MEMZONE_OTHER + 1)
 
 #define IRIS_BINDER_SIZE (64 * 1024)
-#define IRIS_MAX_BINDERS 100
 #define IRIS_BINDLESS_SIZE (8 * 1024 * 1024)
 
 #define IRIS_MEMZONE_SHADER_START     (0ull * (1ull << 32))
 #define IRIS_MEMZONE_BINDER_START     (1ull * (1ull << 32))
-#define IRIS_MEMZONE_BINDLESS_START   (IRIS_MEMZONE_BINDER_START + IRIS_MAX_BINDERS * IRIS_BINDER_SIZE)
-#define IRIS_MEMZONE_SURFACE_START    (IRIS_MEMZONE_BINDLESS_START + IRIS_BINDLESS_SIZE)
+#define IRIS_MEMZONE_BINDLESS_START   (IRIS_MEMZONE_BINDER_START + (1ull << 30) - IRIS_BINDLESS_SIZE)
+#define IRIS_MEMZONE_SURFACE_START    (IRIS_MEMZONE_BINDER_START + (1ull << 30))
 #define IRIS_MEMZONE_DYNAMIC_START    (2ull * (1ull << 32))
 #define IRIS_MEMZONE_OTHER_START      (3ull * (1ull << 32))
 



More information about the mesa-commit mailing list