From b9e7b29705cb17ef7f88d346db823c9b99810249 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 18 Jan 2018 20:39:50 -0800 Subject: [PATCH] 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 Cc: mesa-stable@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 52b5bf97a16..fb180289a0c 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 0ae541cda0d..a3745d6667a 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); -- 2.30.2