Mesa (master): i965/bufmgr: Add a create_from_prime_tiled function

Jason Ekstrand jekstrand at kemper.freedesktop.org
Mon Jan 22 08:37:03 UTC 2018


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

Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date:   Thu Jan 18 20:39:50 2018 -0800

i965/bufmgr: Add a create_from_prime_tiled function

This new function is an import and a set tiling in one go.

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Cc: mesa-stable at lists.freedesktop.org

---

 src/mesa/drivers/dri/i965/brw_bufmgr.c | 39 +++++++++++++++++++++++++++-------
 src/mesa/drivers/dri/i965/brw_bufmgr.h |  4 ++++
 2 files changed, 35 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.c b/src/mesa/drivers/dri/i965/brw_bufmgr.c
index 52b5bf97a1..fb180289a0 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.c
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.c
@@ -1107,8 +1107,9 @@ brw_bo_get_tiling(struct brw_bo *bo, uint32_t *tiling_mode,
    return 0;
 }
 
-struct brw_bo *
-brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd)
+static struct brw_bo *
+brw_bo_gem_create_from_prime_internal(struct brw_bufmgr *bufmgr, int prime_fd,
+                                      int tiling_mode, uint32_t stride)
 {
    uint32_t handle;
    struct brw_bo *bo;
@@ -1157,13 +1158,17 @@ brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd)
    bo->reusable = false;
    bo->external = true;
 
-   struct drm_i915_gem_get_tiling get_tiling = { .handle = bo->gem_handle };
-   if (drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling))
-      goto err;
+   if (tiling_mode < 0) {
+      struct drm_i915_gem_get_tiling get_tiling = { .handle = bo->gem_handle };
+      if (drmIoctl(bufmgr->fd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling))
+         goto err;
 
-   bo->tiling_mode = get_tiling.tiling_mode;
-   bo->swizzle_mode = get_tiling.swizzle_mode;
-   /* XXX stride is unknown */
+      bo->tiling_mode = get_tiling.tiling_mode;
+      bo->swizzle_mode = get_tiling.swizzle_mode;
+      /* XXX stride is unknown */
+   } else {
+      bo_set_tiling_internal(bo, tiling_mode, stride);
+   }
 
 out:
    mtx_unlock(&bufmgr->lock);
@@ -1175,6 +1180,24 @@ err:
    return NULL;
 }
 
+struct brw_bo *
+brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr, int prime_fd)
+{
+   return brw_bo_gem_create_from_prime_internal(bufmgr, prime_fd, -1, 0);
+}
+
+struct brw_bo *
+brw_bo_gem_create_from_prime_tiled(struct brw_bufmgr *bufmgr, int prime_fd,
+                                   uint32_t tiling_mode, uint32_t stride)
+{
+   assert(tiling_mode == I915_TILING_NONE ||
+          tiling_mode == I915_TILING_X ||
+          tiling_mode == I915_TILING_Y);
+
+   return brw_bo_gem_create_from_prime_internal(bufmgr, prime_fd,
+                                                tiling_mode, stride);
+}
+
 static void
 brw_bo_make_external(struct brw_bo *bo)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_bufmgr.h b/src/mesa/drivers/dri/i965/brw_bufmgr.h
index 0ae541cda0..a3745d6667 100644
--- a/src/mesa/drivers/dri/i965/brw_bufmgr.h
+++ b/src/mesa/drivers/dri/i965/brw_bufmgr.h
@@ -336,6 +336,10 @@ void brw_destroy_hw_context(struct brw_bufmgr *bufmgr, uint32_t ctx_id);
 int brw_bo_gem_export_to_prime(struct brw_bo *bo, int *prime_fd);
 struct brw_bo *brw_bo_gem_create_from_prime(struct brw_bufmgr *bufmgr,
                                             int prime_fd);
+struct brw_bo *brw_bo_gem_create_from_prime_tiled(struct brw_bufmgr *bufmgr,
+                                                  int prime_fd,
+                                                  uint32_t tiling_mode,
+                                                  uint32_t stride);
 
 uint32_t brw_bo_export_gem_handle(struct brw_bo *bo);
 




More information about the mesa-commit mailing list