[Mesa-dev] [PATCH 14/21] winsys/amdgpu: add sparse buffer data structures

Nicolai Hähnle nhaehnle at gmail.com
Wed Feb 8 12:42:56 UTC 2017


From: Nicolai Hähnle <nicolai.haehnle at amd.com>

---
 src/gallium/winsys/amdgpu/drm/amdgpu_bo.c |  9 +++++++
 src/gallium/winsys/amdgpu/drm/amdgpu_bo.h | 44 ++++++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
index 5b9bd8c..f998eae 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.c
@@ -38,6 +38,11 @@
 #include <stdio.h>
 #include <inttypes.h>
 
+
+struct amdgpu_sparse_backing_chunk {
+   uint32_t begin, end;
+};
+
 static struct pb_buffer *
 amdgpu_bo_create(struct radeon_winsys *rws,
                  uint64_t size,
@@ -210,6 +215,8 @@ static void *amdgpu_bo_map(struct pb_buffer *buf,
    void *cpu = NULL;
    uint64_t offset = 0;
 
+   assert(!bo->sparse);
+
    /* If it's not unsynchronized bo_map, flush CS if needed and then wait. */
    if (!(usage & PIPE_TRANSFER_UNSYNCHRONIZED)) {
       /* DONTBLOCK doesn't make sense with UNSYNCHRONIZED. */
@@ -322,6 +329,8 @@ static void amdgpu_bo_unmap(struct pb_buffer *buf)
    struct amdgpu_winsys_bo *bo = (struct amdgpu_winsys_bo*)buf;
    struct amdgpu_winsys_bo *real;
 
+   assert(!bo->sparse);
+
    if (bo->user_ptr)
       return;
 
diff --git a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h
index 1e25897..7c66bc4 100644
--- a/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h
+++ b/src/gallium/winsys/amdgpu/drm/amdgpu_bo.h
@@ -37,6 +37,32 @@
 
 #include "pipebuffer/pb_slab.h"
 
+struct amdgpu_sparse_backing_chunk;
+
+/*
+ * Sub-allocation information for a real buffer used as backing memory of a
+ * sparse buffer.
+ */
+struct amdgpu_sparse_backing {
+   struct list_head list;
+
+   struct amdgpu_winsys_bo *bo;
+
+   /* Sorted list of free chunks. */
+   struct amdgpu_sparse_backing_chunk *chunks;
+   uint32_t max_chunks;
+   uint32_t num_chunks;
+};
+
+struct amdgpu_sparse_commitment {
+   struct list_head list;
+
+   struct amdgpu_sparse_backing *backing;
+   uint32_t num_pages;
+   uint32_t va_page_offset;
+   uint32_t backing_page_offset;
+};
+
 struct amdgpu_winsys_bo {
    struct pb_buffer base;
    union {
@@ -53,12 +79,28 @@ struct amdgpu_winsys_bo {
          struct pb_slab_entry entry;
          struct amdgpu_winsys_bo *real;
       } slab;
+      struct {
+         pipe_mutex commit_lock;
+         amdgpu_va_handle va_handle;
+         enum radeon_bo_flag flags;
+
+         uint32_t total_backing_pages;
+
+         struct list_head backing;
+
+         /* Sorted list of existing commitments.
+          * The embedded sentinel represents a commitment past the end of the
+          * virtual memory area.
+          */
+         struct amdgpu_sparse_commitment commitments;
+      } sparse;
    } u;
 
    struct amdgpu_winsys *ws;
    void *user_ptr; /* from buffer_from_ptr */
 
-   amdgpu_bo_handle bo; /* NULL for slab entries */
+   amdgpu_bo_handle bo; /* NULL for slab entries and sparse buffers */
+   bool sparse;
    uint32_t unique_id;
    uint64_t va;
    enum radeon_bo_domain initial_domain;
-- 
2.9.3



More information about the mesa-dev mailing list