[Mesa-dev] [PATCH 3/3] radeon/winsys: explicitly sync BOs

Christian König deathsimple at vodafone.de
Thu Sep 18 08:34:23 PDT 2014


From: Christian König <christian.koenig at amd.com>

For now syncs all engines accessing a BO using the
new kernel interface, older kernels should ignore
the new chunk and maintain the old behavior.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 src/gallium/winsys/radeon/drm/radeon_drm_cs.c | 30 ++++++++++++++++++++++++---
 src/gallium/winsys/radeon/drm/radeon_drm_cs.h |  5 +++--
 2 files changed, 30 insertions(+), 5 deletions(-)

diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
index e821b6f..587719b 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.c
@@ -72,6 +72,9 @@
 #include <stdint.h>
 #include <xf86drm.h>
 
+#ifndef RADEON_CHUNK_ID_WAIT_FOR
+#define RADEON_CHUNK_ID_WAIT_FOR 0x05
+#endif
 
 #define RELOC_DWORDS (sizeof(struct drm_radeon_cs_reloc) / sizeof(uint32_t))
 
@@ -100,6 +103,13 @@ static boolean radeon_init_cs_context(struct radeon_cs_context *csc,
         return FALSE;
     }
 
+    csc->cs_ids = CALLOC(csc->nrelocs, sizeof(uint64_t));
+    if (!csc->cs_ids) {
+        FREE(csc->relocs_bo);
+        FREE(csc->relocs);
+        return FALSE;
+    }
+
     csc->chunks[0].chunk_id = RADEON_CHUNK_ID_IB;
     csc->chunks[0].length_dw = 0;
     csc->chunks[0].chunk_data = (uint64_t)(uintptr_t)csc->buf;
@@ -109,13 +119,17 @@ static boolean radeon_init_cs_context(struct radeon_cs_context *csc,
     csc->chunks[2].chunk_id = RADEON_CHUNK_ID_FLAGS;
     csc->chunks[2].length_dw = 5;
     csc->chunks[2].chunk_data = (uint64_t)(uintptr_t)&csc->flags;
+    csc->chunks[3].chunk_id = RADEON_CHUNK_ID_WAIT_FOR;
+    csc->chunks[3].length_dw = 0;
+    csc->chunks[3].chunk_data = (uint64_t)(uintptr_t)csc->cs_ids;
 
     csc->chunk_array[0] = (uint64_t)(uintptr_t)&csc->chunks[0];
     csc->chunk_array[1] = (uint64_t)(uintptr_t)&csc->chunks[1];
     csc->chunk_array[2] = (uint64_t)(uintptr_t)&csc->chunks[2];
+    csc->chunk_array[3] = (uint64_t)(uintptr_t)&csc->chunks[3];
 
     csc->cs.chunks = (uint64_t)(uintptr_t)csc->chunk_array;
-    csc->cs.num_chunks = 3;
+    csc->cs.num_chunks = 4;
 
     for (i = 0; i < Elements(csc->reloc_indices_hashlist); i++) {
         csc->reloc_indices_hashlist[i] = -1;
@@ -285,8 +299,11 @@ static unsigned radeon_add_reloc(struct radeon_drm_cs *cs,
 
         size = csc->nrelocs * sizeof(struct drm_radeon_cs_reloc);
         csc->relocs = realloc(csc->relocs, size);
-
         csc->chunks[1].chunk_data = (uint64_t)(uintptr_t)csc->relocs;
+
+        size = csc->nrelocs * sizeof(uint64_t);
+        csc->cs_ids = realloc(csc->cs_ids, size);
+        csc->chunks[3].chunk_data = (uint64_t)(uintptr_t)csc->cs_ids;
     }
 
     /* Initialize the new relocation. */
@@ -383,7 +400,14 @@ static boolean radeon_drm_cs_memory_below_limit(struct radeon_winsys_cs *rcs, ui
 void radeon_drm_cs_emit_ioctl_oneshot(struct radeon_drm_cs *cs, struct radeon_cs_context *csc)
 {
     uint64_t id;
-    unsigned i;
+    unsigned i, c;
+
+    for (i = 0, c = 0; i < csc->crelocs; i++) {
+        id = csc->relocs_bo[i]->last_cs_id;
+        if (id)
+            csc->cs_ids[c++] = id;
+    }
+    csc->chunks[3].length_dw = c * 2;
 
     if (drmCommandWriteRead(csc->fd, DRM_RADEON_CS,
                             &csc->cs, sizeof(struct drm_radeon_cs))) {
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_cs.h b/src/gallium/winsys/radeon/drm/radeon_drm_cs.h
index 1d0bc64..f903b5d 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_cs.h
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_cs.h
@@ -35,8 +35,8 @@ struct radeon_cs_context {
 
     int                         fd;
     struct drm_radeon_cs        cs;
-    struct drm_radeon_cs_chunk  chunks[3];
-    uint64_t                    chunk_array[3];
+    struct drm_radeon_cs_chunk  chunks[4];
+    uint64_t                    chunk_array[4];
     uint32_t                    flags[5];
 
     uint32_t                    cs_trace_id;
@@ -47,6 +47,7 @@ struct radeon_cs_context {
     unsigned                    validated_crelocs;
     struct radeon_bo            **relocs_bo;
     struct drm_radeon_cs_reloc  *relocs;
+    uint64_t                    *cs_ids;
 
     int                         reloc_indices_hashlist[512];
 
-- 
1.9.1



More information about the mesa-dev mailing list