[Mesa-dev] [PATCH 3/7] r600g, radeonsi: set correct initial domain for shared resources

Marek Olšák maraeo at gmail.com
Mon Feb 24 15:48:30 PST 2014


From: Marek Olšák <marek.olsak at amd.com>

This depends on the kernel patch.
---
 src/gallium/drivers/radeon/r600_texture.c     |  2 +-
 src/gallium/winsys/radeon/drm/radeon_drm_bo.c | 51 +++++++++++++++++++++++----
 src/gallium/winsys/radeon/drm/radeon_winsys.h |  5 +++
 3 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/src/gallium/drivers/radeon/r600_texture.c b/src/gallium/drivers/radeon/r600_texture.c
index 1966251..0b572ed 100644
--- a/src/gallium/drivers/radeon/r600_texture.c
+++ b/src/gallium/drivers/radeon/r600_texture.c
@@ -624,7 +624,7 @@ r600_texture_create_object(struct pipe_screen *screen,
 	} else {
 		resource->buf = buf;
 		resource->cs_buf = rscreen->ws->buffer_get_cs_handle(buf);
-		resource->domains = RADEON_DOMAIN_GTT | RADEON_DOMAIN_VRAM;
+		resource->domains = rscreen->ws->buffer_get_initial_domain(resource->cs_buf);
 	}
 
 	if (rtex->cmask.size) {
diff --git a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
index 9665613..4c01295 100644
--- a/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
+++ b/src/gallium/winsys/radeon/drm/radeon_drm_bo.c
@@ -92,6 +92,19 @@ struct drm_radeon_gem_va {
 #define DRM_RADEON_GEM_VA   0x2b
 #endif
 
+#ifndef DRM_RADEON_GEM_OP
+#define DRM_RADEON_GEM_OP		0x2c
+
+/* Sets or returns a value associated with a buffer. */
+struct drm_radeon_gem_op {
+    uint32_t handle; /* buffer */
+    uint32_t op;     /* RADEON_GEM_OP_* */
+    uint64_t value;  /* input or return value */
+};
+
+#define RADEON_GEM_OP_GET_INITIAL_DOMAIN	0
+#define RADEON_GEM_OP_SET_INITIAL_DOMAIN	1
+#endif
 
 
 extern const struct pb_vtbl radeon_bo_vtbl;
@@ -201,6 +214,18 @@ static boolean radeon_bo_is_busy(struct pb_buffer *_buf,
     }
 }
 
+static enum radeon_bo_domain get_valid_domain(enum radeon_bo_domain domain)
+{
+    /* Zero domains the driver doesn't understand. */
+    domain &= RADEON_DOMAIN_VRAM_GTT;
+
+    /* If no domain is set, we must set something... */
+    if (!domain)
+        domain = RADEON_DOMAIN_VRAM_GTT;
+
+    return domain;
+}
+
 static enum radeon_bo_domain radeon_bo_get_current_domain(
 		struct radeon_winsys_cs_handle *buf)
 {
@@ -214,14 +239,27 @@ static enum radeon_bo_domain radeon_bo_get_current_domain(
                         &args, sizeof(args));
 
     /* GEM domains and winsys domains are defined the same. */
-    /* Zero domains the driver doesn't understand. */
-    args.domain &= RADEON_DOMAIN_VRAM_GTT;
+    return get_valid_domain(args.domain);
+}
 
-    /* If no domain is set, we must set something... */
-    if (!args.domain)
-        args.domain = RADEON_DOMAIN_VRAM_GTT;
+static enum radeon_bo_domain radeon_bo_get_initial_domain(
+		struct radeon_winsys_cs_handle *buf)
+{
+    struct radeon_bo *bo = (struct radeon_bo*)buf;
+    struct drm_radeon_gem_op args;
+
+    if (bo->rws->info.drm_minor < 38)
+        return RADEON_DOMAIN_VRAM_GTT;
 
-    return args.domain;
+    memset(&args, 0, sizeof(args));
+    args.handle = bo->handle;
+    args.op = RADEON_GEM_OP_GET_INITIAL_DOMAIN;
+
+    drmCommandWriteRead(bo->rws->fd, DRM_RADEON_GEM_OP,
+                        &args, sizeof(args));
+
+    /* GEM domains and winsys domains are defined the same. */
+    return get_valid_domain(args.value);
 }
 
 static uint64_t radeon_bomgr_find_va(struct radeon_bomgr *mgr, uint64_t size, uint64_t alignment)
@@ -1113,4 +1151,5 @@ void radeon_bomgr_init_functions(struct radeon_drm_winsys *ws)
     ws->base.buffer_get_handle = radeon_winsys_bo_get_handle;
     ws->base.buffer_get_virtual_address = radeon_winsys_bo_va;
     ws->base.buffer_get_current_domain = radeon_bo_get_current_domain;
+    ws->base.buffer_get_initial_domain = radeon_bo_get_initial_domain;
 }
diff --git a/src/gallium/winsys/radeon/drm/radeon_winsys.h b/src/gallium/winsys/radeon/drm/radeon_winsys.h
index dc34f95..4e614ec 100644
--- a/src/gallium/winsys/radeon/drm/radeon_winsys.h
+++ b/src/gallium/winsys/radeon/drm/radeon_winsys.h
@@ -384,6 +384,11 @@ struct radeon_winsys {
      */
     enum radeon_bo_domain (*buffer_get_current_domain)(struct radeon_winsys_cs_handle *buf);
 
+    /**
+     * Query the initial placement of the buffer from the kernel driver.
+     */
+    enum radeon_bo_domain (*buffer_get_initial_domain)(struct radeon_winsys_cs_handle *buf);
+
     /**************************************************************************
      * Command submission.
      *
-- 
1.8.3.2



More information about the mesa-dev mailing list