[Intel-gfx] [PATCH] intel: Check the physical swizzle mode for the object

Chris Wilson chris at chris-wilson.co.uk
Sun Jun 28 05:54:18 PDT 2015


The existing GET_TILING ABI tells white lies. It tries to hide bit17
swizzling from userspace (because then swizzling depends upon the
physical address of the individual pages for an object). This of course
means that all swizzling to such objects is incorrect (at least half of
the time!). The GET_TILING interface was then extended to supply this
information, so make use of it!

Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
---
 intel/intel_bufmgr_gem.c | 47 +++++++++++++++++++++++++++--------------------
 1 file changed, 27 insertions(+), 20 deletions(-)

diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
index b0544af..3ea78c2 100644
--- a/intel/intel_bufmgr_gem.c
+++ b/intel/intel_bufmgr_gem.c
@@ -1008,6 +1008,29 @@ check_bo_alloc_userptr(drm_intel_bufmgr *bufmgr,
 					  tiling_mode, stride, size, flags);
 }
 
+static int
+__drm_intel_bo_gem_get_tiling(drm_intel_bo_gem *bo_gem)
+{
+	drm_intel_bufmgr_gem *bufmgr_gem =
+		(drm_intel_bufmgr_gem *) bo_gem->bo.bufmgr;
+	struct drm_i915_gem_get_tiling get_tiling;
+
+	memclear(get_tiling);
+	get_tiling.handle = bo_gem->gem_handle;
+	if (drmIoctl(bufmgr_gem->fd,
+		     DRM_IOCTL_I915_GEM_GET_TILING,
+		     &get_tiling))
+		return -errno;
+
+	bo_gem->tiling_mode = get_tiling.tiling_mode;
+	if (get_tiling.phys_swizzle_mode == get_tiling.swizzle_mode)
+		bo_gem->swizzle_mode = get_tiling.swizzle_mode;
+	else
+		bo_gem->swizzle_mode = I915_BIT_6_SWIZZLE_UNKNOWN;
+
+	return 0;
+}
+
 /**
  * Returns a drm_intel_bo wrapping the given buffer object handle.
  *
@@ -1023,7 +1046,6 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
 	drm_intel_bo_gem *bo_gem;
 	int ret;
 	struct drm_gem_open open_arg;
-	struct drm_i915_gem_get_tiling get_tiling;
 	drmMMListHead *list;
 
 	/* At the moment most applications only have a few named bo.
@@ -1089,18 +1111,12 @@ drm_intel_bo_gem_create_from_name(drm_intel_bufmgr *bufmgr,
 	bo_gem->global_name = handle;
 	bo_gem->reusable = false;
 
-	memclear(get_tiling);
-	get_tiling.handle = bo_gem->gem_handle;
-	ret = drmIoctl(bufmgr_gem->fd,
-		       DRM_IOCTL_I915_GEM_GET_TILING,
-		       &get_tiling);
+	ret = __drm_intel_bo_gem_get_tiling(bo_gem);
 	if (ret != 0) {
 		drm_intel_gem_bo_unreference(&bo_gem->bo);
 		pthread_mutex_unlock(&bufmgr_gem->lock);
 		return NULL;
 	}
-	bo_gem->tiling_mode = get_tiling.tiling_mode;
-	bo_gem->swizzle_mode = get_tiling.swizzle_mode;
 	/* XXX stride is unknown */
 	drm_intel_bo_gem_set_in_aperture_size(bufmgr_gem, bo_gem);
 
@@ -2716,10 +2732,8 @@ drm_intel_gem_bo_set_tiling_internal(drm_intel_bo *bo,
 	if (ret == -1)
 		return -errno;
 
-	bo_gem->tiling_mode = set_tiling.tiling_mode;
-	bo_gem->swizzle_mode = set_tiling.swizzle_mode;
 	bo_gem->stride = set_tiling.stride;
-	return 0;
+	return __drm_intel_bo_gem_get_tiling(bo_gem);
 }
 
 static int
@@ -2768,7 +2782,6 @@ drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int s
 	int ret;
 	uint32_t handle;
 	drm_intel_bo_gem *bo_gem;
-	struct drm_i915_gem_get_tiling get_tiling;
 	drmMMListHead *list;
 
 	ret = drmPrimeFDToHandle(bufmgr_gem->fd, prime_fd, &handle);
@@ -2830,17 +2843,11 @@ drm_intel_bo_gem_create_from_prime(drm_intel_bufmgr *bufmgr, int prime_fd, int s
 	DRMLISTADDTAIL(&bo_gem->name_list, &bufmgr_gem->named);
 	pthread_mutex_unlock(&bufmgr_gem->lock);
 
-	memclear(get_tiling);
-	get_tiling.handle = bo_gem->gem_handle;
-	ret = drmIoctl(bufmgr_gem->fd,
-		       DRM_IOCTL_I915_GEM_GET_TILING,
-		       &get_tiling);
-	if (ret != 0) {
+	ret = __drm_intel_bo_gem_get_tiling(bo_gem);
+	if (ret) {
 		drm_intel_gem_bo_unreference(&bo_gem->bo);
 		return NULL;
 	}
-	bo_gem->tiling_mode = get_tiling.tiling_mode;
-	bo_gem->swizzle_mode = get_tiling.swizzle_mode;
 	/* XXX stride is unknown */
 	drm_intel_bo_gem_set_in_aperture_size(bufmgr_gem, bo_gem);
 
-- 
2.1.4



More information about the Intel-gfx mailing list