[143/190] drm/i915: Track display alignment on VMA
diff mbox

Message ID 1452510091-6833-2-git-send-email-chris@chris-wilson.co.uk
State New
Headers show

Commit Message

Chris Wilson Jan. 11, 2016, 11 a.m. UTC
When using the aliasing ppgtt and pagefliping with the shrinker/eviction
active, we note that we often have to rebind the backbuffer before
flipping onto the scanout because it has an invalid alignment. If we
store the worst-case alignment required for a VMA, we can avoid having
to rebind at critical junctures.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 drivers/gpu/drm/i915/i915_gem.c     | 20 ++++++++------------
 drivers/gpu/drm/i915/i915_gem_gtt.h |  2 +-
 2 files changed, 9 insertions(+), 13 deletions(-)

Patch
diff mbox

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 52e099ac29bf..fa518764c32c 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2804,7 +2804,6 @@  i915_vma_insert(struct i915_vma *vma,
 	struct drm_device *dev = obj->base.dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	u64 start, end;
-	u64 min_alignment;
 	int ret;
 
 	GEM_BUG_ON(vma->bound);
@@ -2814,16 +2813,10 @@  i915_vma_insert(struct i915_vma *vma,
 	if (flags & PIN_MAPPABLE)
 		size = i915_gem_get_gtt_size(dev, size, obj->tiling_mode);
 
-	min_alignment =
-		i915_gem_get_gtt_alignment(dev, size, obj->tiling_mode,
-					   flags & PIN_MAPPABLE);
-	if (alignment == 0)
-		alignment = min_alignment;
-	if (alignment & (min_alignment - 1)) {
-		DRM_DEBUG("Invalid object alignment requested %llu, minimum %llu\n",
-			  alignment, min_alignment);
-		return -EINVAL;
-	}
+	alignment = max_t(u64, max(alignment, vma->display_alignment),
+			  i915_gem_get_gtt_alignment(dev, size,
+						     obj->tiling_mode,
+						     flags & PIN_MAPPABLE));
 
 	start = flags & PIN_OFFSET_BIAS ? flags & PIN_OFFSET_MASK : 0;
 
@@ -3341,6 +3334,8 @@  i915_gem_object_pin_to_display_plane(struct drm_i915_gem_object *obj,
 	if (IS_ERR(vma))
 		goto err_unpin_display;
 
+	vma->display_alignment = max_t(u64, vma->display_alignment, alignment);
+
 	WARN_ON(obj->pin_display > vma->pin_count);
 
 	i915_gem_object_flush_cpu_write_domain(obj);
@@ -3374,8 +3369,9 @@  i915_gem_object_unpin_from_display_plane(struct i915_vma *vma)
 	if (WARN_ON(vma->obj->pin_display == 0))
 		return;
 
-	vma->obj->pin_display--;
 	vma->obj->pages_pin_count--;
+	if (--vma->obj->pin_display == 0)
+		vma->display_alignment = 0;
 
 	i915_vma_unpin(vma);
 	WARN_ON(vma->obj->pin_display > vma->pin_count);
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h
index c0ada0402335..dd446b69921b 100644
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h
@@ -190,7 +190,7 @@  struct i915_vma {
 	struct i915_address_space *vm;
 	struct drm_i915_fence_reg *fence;
 	void *iomap;
-	u64 size;
+	u64 size, display_alignment;
 
 	struct i915_gem_active last_read[I915_NUM_RINGS];
 	struct i915_gem_active last_fence;