xf86-video-intel: 7 commits - src/sna/kgem.c src/sna/sna_accel.c

Chris Wilson ickle at kemper.freedesktop.org
Mon Oct 28 06:39:44 PDT 2013


 src/sna/kgem.c      |   90 +++++++++++++++++++++++--------
 src/sna/sna_accel.c |  150 +++++++++++++++++++---------------------------------
 2 files changed, 125 insertions(+), 115 deletions(-)

New commits:
commit 54aaf14dbf33b0e81932507b8753a63d1c6c8e77
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 28 13:06:16 2013 +0000

    sna: Tidy RegionNil checks
    
    After computing the clip intersection, we immediately check for the
    empty result, so refactor the check into the common routine.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/sna_accel.c b/src/sna/sna_accel.c
index 9a78375..b7ee092 100644
--- a/src/sna/sna_accel.c
+++ b/src/sna/sna_accel.c
@@ -216,10 +216,12 @@ static inline void region_set(RegionRec *r, const BoxRec *b)
 	r->data = NULL;
 }
 
-static inline void region_maybe_clip(RegionRec *r, RegionRec *clip)
+static inline bool region_maybe_clip(RegionRec *r, RegionRec *clip)
 {
-	if (clip->data)
-		RegionIntersect(r, r, clip);
+	if (clip->data && !RegionIntersect(r, r, clip))
+		return false;
+
+	return !box_empty(&r->extents);
 }
 
 static inline bool region_is_singular(const RegionRec *r)
@@ -4754,8 +4756,8 @@ sna_put_image(DrawablePtr drawable, GCPtr gc, int depth,
 	    gc->pCompositeClip->extents.y1 > region.extents.y1 ||
 	    gc->pCompositeClip->extents.x2 < region.extents.x2 ||
 	    gc->pCompositeClip->extents.y2 < region.extents.y2) {
-		RegionIntersect(&region, &region, gc->pCompositeClip);
-		if (RegionNil(&region))
+		if (!RegionIntersect(&region, &region, gc->pCompositeClip) ||
+		    box_empty(&region.extents))
 			return;
 	}
 
@@ -6822,8 +6824,7 @@ no_damage_clipped:
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			return true;
 
 		assert(dx + clip.extents.x1 >= 0);
@@ -6923,8 +6924,7 @@ damage_clipped:
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			return true;
 
 		assert(dx + clip.extents.x1 >= 0);
@@ -7244,8 +7244,7 @@ sna_fill_spans(DrawablePtr drawable, GCPtr gc, int n,
 fallback:
 	DBG(("%s: fallback\n", __FUNCTION__));
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	if (!sna_gc_move_to_cpu(gc, drawable, &region))
@@ -7286,8 +7285,7 @@ sna_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
 
 fallback:
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	if (!sna_gc_move_to_cpu(gc, drawable, &region))
@@ -7739,7 +7737,7 @@ sna_copy_plane(DrawablePtr src, DrawablePtr dst, GCPtr gc,
 	     __FUNCTION__,
 	     region.extents.x1, region.extents.y1,
 	     region.extents.x2, region.extents.y2));
-	if (RegionNil(&region))
+	if (box_empty(&region.extents))
 		goto empty;
 
 	RegionTranslate(&region,
@@ -7997,8 +7995,7 @@ sna_poly_point(DrawablePtr drawable, GCPtr gc,
 fallback:
 	DBG(("%s: fallback\n", __FUNCTION__));
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	if (!sna_gc_move_to_cpu(gc, drawable, &region))
@@ -8054,8 +8051,7 @@ sna_poly_zero_line_blt(DrawablePtr drawable,
 
 	region_set(&clip, extents);
 	if (clipped) {
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			return true;
 	}
 
@@ -8481,8 +8477,7 @@ sna_poly_line_blt(DrawablePtr drawable,
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			return true;
 
 		last.x = pt->x + drawable->x;
@@ -8928,9 +8923,8 @@ spans_fallback:
 						sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
 					sna_gc_ops__tmp.PolyPoint = sna_poly_point__fill;
 				} else {
-					region_maybe_clip(&data.region,
-							  gc->pCompositeClip);
-					if (RegionNil(&data.region))
+					if (!region_maybe_clip(&data.region,
+							       gc->pCompositeClip))
 						return;
 
 					if (region_is_singular(&data.region)) {
@@ -8957,9 +8951,8 @@ spans_fallback:
 						sna_gc_ops__tmp.FillSpans = sna_fill_spans__dash;
 					sna_gc_ops__tmp.PolyPoint = sna_poly_point__dash;
 				} else {
-					region_maybe_clip(&data.region,
-							  gc->pCompositeClip);
-					if (RegionNil(&data.region))
+					if (!region_maybe_clip(&data.region,
+							       gc->pCompositeClip))
 						return;
 
 					if (region_is_singular(&data.region)) {
@@ -9042,8 +9035,7 @@ spans_fallback:
 
 fallback:
 	DBG(("%s: fallback\n", __FUNCTION__));
-	region_maybe_clip(&data.region, gc->pCompositeClip);
-	if (RegionNil(&data.region))
+	if (!region_maybe_clip(&data.region, gc->pCompositeClip))
 		return;
 
 	if (!sna_gc_move_to_cpu(gc, drawable, &data.region))
@@ -9173,8 +9165,7 @@ sna_poly_segment_blt(DrawablePtr drawable,
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			goto done;
 
 		if (clip.data) {
@@ -9280,8 +9271,7 @@ sna_poly_zero_segment_blt(DrawablePtr drawable,
 
 	region_set(&clip, extents);
 	if (clipped) {
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			return true;
 	}
 	DBG(("%s: [clipped] extents=(%d, %d), (%d, %d), delta=(%d, %d)\n",
@@ -9849,9 +9839,8 @@ spans_fallback:
 					sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
 				sna_gc_ops__tmp.PolyPoint = sna_poly_point__fill;
 			} else {
-				region_maybe_clip(&data.region,
-						  gc->pCompositeClip);
-				if (RegionNil(&data.region))
+				if (!region_maybe_clip(&data.region,
+						       gc->pCompositeClip))
 					return;
 
 				if (region_is_singular(&data.region)) {
@@ -9894,8 +9883,7 @@ spans_fallback:
 
 fallback:
 	DBG(("%s: fallback\n", __FUNCTION__));
-	region_maybe_clip(&data.region, gc->pCompositeClip);
-	if (RegionNil(&data.region))
+	if (!region_maybe_clip(&data.region, gc->pCompositeClip))
 		return;
 
 	if (!sna_gc_move_to_cpu(gc, drawable, &data.region))
@@ -10050,8 +10038,7 @@ zero_clipped:
 		int count;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			goto done;
 
 		if (clip.data) {
@@ -10192,13 +10179,13 @@ wide_clipped:
 		int16_t offset3 = offset2 - offset1;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
+			goto done;
+
 		DBG(("%s: wide clipped: extents=((%d, %d), (%d, %d))\n",
 		     __FUNCTION__,
 		     clip.extents.x1, clip.extents.y1,
 		     clip.extents.x2, clip.extents.y2));
-		if (RegionNil(&clip))
-			goto done;
 
 		if (clip.data) {
 			const BoxRec * const clip_start = RegionBoxptr(&clip);
@@ -10505,8 +10492,7 @@ fallback:
 	DBG(("%s: fallback\n", __FUNCTION__));
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	if (!sna_gc_move_to_cpu(gc, drawable, &region))
@@ -10646,9 +10632,8 @@ sna_poly_arc(DrawablePtr drawable, GCPtr gc, int n, xArc *arc)
 						sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
 					sna_gc_ops__tmp.PolyPoint = sna_poly_point__fill;
 				} else {
-					region_maybe_clip(&data.region,
-							  gc->pCompositeClip);
-					if (RegionNil(&data.region))
+					if (!region_maybe_clip(&data.region,
+							       gc->pCompositeClip))
 						return;
 
 					if (region_is_singular(&data.region)) {
@@ -10670,9 +10655,8 @@ sna_poly_arc(DrawablePtr drawable, GCPtr gc, int n, xArc *arc)
 
 				fill.done(data.sna, &fill);
 			} else {
-				region_maybe_clip(&data.region,
-						  gc->pCompositeClip);
-				if (RegionNil(&data.region))
+				if (!region_maybe_clip(&data.region,
+						       gc->pCompositeClip))
 					return;
 
 				sna_gc_ops__tmp.FillSpans = sna_fill_spans__gpu;
@@ -10707,8 +10691,7 @@ sna_poly_arc(DrawablePtr drawable, GCPtr gc, int n, xArc *arc)
 
 fallback:
 	DBG(("%s -- fallback\n", __FUNCTION__));
-	region_maybe_clip(&data.region, gc->pCompositeClip);
-	if (RegionNil(&data.region))
+	if (!region_maybe_clip(&data.region, gc->pCompositeClip))
 		return;
 
 	if (!sna_gc_move_to_cpu(gc, drawable, &data.region))
@@ -10852,8 +10835,7 @@ sna_poly_fill_rect_blt(DrawablePtr drawable,
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			goto done;
 
 		if (clip.data == NULL) {
@@ -11023,9 +11005,8 @@ sna_poly_fill_polygon(DrawablePtr draw, GCPtr gc,
 				else
 					sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
 			} else {
-				region_maybe_clip(&data.region,
-						  gc->pCompositeClip);
-				if (RegionNil(&data.region))
+				if (!region_maybe_clip(&data.region,
+						       gc->pCompositeClip))
 					return;
 
 				if (region_is_singular(&data.region))
@@ -11061,8 +11042,7 @@ fallback:
 	DBG(("%s: fallback (%d, %d), (%d, %d)\n", __FUNCTION__,
 	     data.region.extents.x1, data.region.extents.y1,
 	     data.region.extents.x2, data.region.extents.y2));
-	region_maybe_clip(&data.region, gc->pCompositeClip);
-	if (RegionNil(&data.region)) {
+	if (!region_maybe_clip(&data.region, gc->pCompositeClip)) {
 		DBG(("%s: nothing to do, all clipped\n", __FUNCTION__));
 		return;
 	}
@@ -11275,8 +11255,7 @@ sna_poly_fill_rect_tiled_8x8_blt(DrawablePtr drawable,
 		uint16_t unwind_batch, unwind_reloc;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			goto done;
 
 		unwind_batch = sna->kgem.nbatch;
@@ -11625,8 +11604,7 @@ sna_poly_fill_rect_tiled_blt(DrawablePtr drawable,
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			goto done;
 
 		if (clip.data == NULL) {
@@ -11904,8 +11882,7 @@ sna_poly_fill_rect_stippled_8x8_blt(DrawablePtr drawable,
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			return true;
 
 		b = sna->kgem.batch + sna->kgem.nbatch;
@@ -12238,8 +12215,7 @@ sna_poly_fill_rect_stippled_1_blt(DrawablePtr drawable,
 		DDXPointRec pat;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip))
+		if (!region_maybe_clip(&clip, gc->pCompositeClip))
 			return true;
 
 		pat.x = origin->x + drawable->x;
@@ -12850,8 +12826,7 @@ sna_poly_fill_rect_stippled_n_blt__imm(DrawablePtr drawable,
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip)) {
+		if (!region_maybe_clip(&clip, gc->pCompositeClip)) {
 			DBG(("%s: all clipped\n", __FUNCTION__));
 			return true;
 		}
@@ -12995,8 +12970,7 @@ sna_poly_fill_rect_stippled_n_blt(DrawablePtr drawable,
 		RegionRec clip;
 
 		region_set(&clip, extents);
-		region_maybe_clip(&clip, gc->pCompositeClip);
-		if (RegionNil(&clip)) {
+		if (!region_maybe_clip(&clip, gc->pCompositeClip)) {
 			DBG(("%s: all clipped\n", __FUNCTION__));
 			return true;
 		}
@@ -13342,8 +13316,7 @@ fallback:
 	     region.extents.x1, region.extents.y1,
 	     region.extents.x2, region.extents.y2));
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region)) {
+	if (!region_maybe_clip(&region, gc->pCompositeClip)) {
 		DBG(("%s: nothing to do, all clipped\n", __FUNCTION__));
 		return;
 	}
@@ -13476,9 +13449,8 @@ sna_poly_fill_arc(DrawablePtr draw, GCPtr gc, int n, xArc *arc)
 				else
 					sna_gc_ops__tmp.FillSpans = sna_fill_spans__fill;
 			} else {
-				region_maybe_clip(&data.region,
-						  gc->pCompositeClip);
-				if (RegionNil(&data.region))
+				if (!region_maybe_clip(&data.region,
+						       gc->pCompositeClip))
 					return;
 
 				if (region_is_singular(&data.region))
@@ -13514,8 +13486,7 @@ fallback:
 	DBG(("%s: fallback (%d, %d), (%d, %d)\n", __FUNCTION__,
 	     data.region.extents.x1, data.region.extents.y1,
 	     data.region.extents.x2, data.region.extents.y2));
-	region_maybe_clip(&data.region, gc->pCompositeClip);
-	if (RegionNil(&data.region)) {
+	if (!region_maybe_clip(&data.region, gc->pCompositeClip)) {
 		DBG(("%s: nothing to do, all clipped\n", __FUNCTION__));
 		return;
 	}
@@ -13989,8 +13960,7 @@ sna_poly_text8(DrawablePtr drawable, GCPtr gc,
 		return x + extents.overallRight;
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return x + extents.overallRight;
 
 	if (FORCE_FALLBACK)
@@ -14065,8 +14035,7 @@ sna_poly_text16(DrawablePtr drawable, GCPtr gc,
 		return x + extents.overallRight;
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return x + extents.overallRight;
 
 	if (FORCE_FALLBACK)
@@ -14148,8 +14117,7 @@ sna_image_text8(DrawablePtr drawable, GCPtr gc,
 		return;
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
@@ -14231,8 +14199,7 @@ sna_image_text16(DrawablePtr drawable, GCPtr gc,
 		return;
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	DBG(("%s: clipped extents (%d, %d), (%d, %d)\n",
@@ -14556,8 +14523,7 @@ sna_image_glyph(DrawablePtr drawable, GCPtr gc,
 	     region.extents.x2, region.extents.y2));
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	if (FORCE_FALLBACK)
@@ -14639,8 +14605,7 @@ sna_poly_glyph(DrawablePtr drawable, GCPtr gc,
 	     region.extents.x2, region.extents.y2));
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	if (FORCE_FALLBACK)
@@ -14842,8 +14807,7 @@ sna_push_pixels(GCPtr gc, PixmapPtr bitmap, DrawablePtr drawable,
 	     region.extents.x2, region.extents.y2));
 
 	region.data = NULL;
-	region_maybe_clip(&region, gc->pCompositeClip);
-	if (RegionNil(&region))
+	if (!region_maybe_clip(&region, gc->pCompositeClip))
 		return;
 
 	switch (gc->fillStyle) {
@@ -15274,7 +15238,7 @@ sna_copy_window(WindowPtr win, DDXPointRec origin, RegionPtr src)
 
 	RegionNull(&dst);
 	RegionIntersect(&dst, &win->borderClip, src);
-	if (RegionNil(&dst))
+	if (box_empty(&dst.extents))
 		return;
 
 #ifdef COMPOSITE
commit 003f26a571cd0a0eda2499b4ae350c34bdb39b72
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 28 11:29:13 2013 +0000

    sna: And be pessimistic when checking aperture limits
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index 8659765..0f5b9ab 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -4646,6 +4646,7 @@ static bool aperture_check(struct kgem *kgem, unsigned num_pages)
 		if (!kgem->has_llc)
 			aperture.aper_available_size -= 2 * kgem->nexec * PAGE_SIZE;
 
+		aperture.aper_available_size -= aperture.aper_size - aperture.aper_available_size;
 		if (num_pages < aperture.aper_available_size / PAGE_SIZE)
 			return true;
 	}
commit 671e4b44b2b2809e032a3d2a9b45ecf3af547100
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 28 11:28:01 2013 +0000

    sna: Account for extra guard pages around snooped BO in aperture checks
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index f4ad469..8659765 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -4643,6 +4643,8 @@ static bool aperture_check(struct kgem *kgem, unsigned num_pages)
 		aperture.aper_available_size -= 4 * 1024 * 1024;
 		if (kgem->gen < 040)
 			aperture.aper_available_size -= kgem->aperture_fenced * PAGE_SIZE;
+		if (!kgem->has_llc)
+			aperture.aper_available_size -= 2 * kgem->nexec * PAGE_SIZE;
 
 		if (num_pages < aperture.aper_available_size / PAGE_SIZE)
 			return true;
commit f7d1da8ca5e1695b0459f87e85c587b26193e633
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 28 11:16:29 2013 +0000

    sna: Defer opportunistic flush if all bo are current on the GPU
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index 1e1da04..f4ad469 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -4674,6 +4674,7 @@ bool kgem_check_bo(struct kgem *kgem, ...)
 	int num_exec = 0;
 	int num_pages = 0;
 	bool flush = false;
+	bool active = true;
 
 	va_start(ap, kgem);
 	while ((bo = va_arg(ap, struct kgem_bo *))) {
@@ -4691,6 +4692,7 @@ bool kgem_check_bo(struct kgem *kgem, ...)
 		num_exec++;
 
 		flush |= bo->flush;
+		active &= bo->rq != NULL;
 	}
 	va_end(ap);
 
@@ -4713,6 +4715,9 @@ bool kgem_check_bo(struct kgem *kgem, ...)
 			return false;
 	}
 
+	if (active)
+		return true;
+
 	return kgem_flush(kgem, flush);
 }
 
@@ -4793,6 +4798,9 @@ bool kgem_check_bo_fenced(struct kgem *kgem, struct kgem_bo *bo)
 			return false;
 	}
 
+	if (bo->rq)
+		return true;
+
 	return kgem_flush(kgem, bo->flush);
 }
 
@@ -4805,6 +4813,7 @@ bool kgem_check_many_bo_fenced(struct kgem *kgem, ...)
 	int num_pages = 0;
 	int fenced_size = 0;
 	bool flush = false;
+	bool active = true;
 
 	va_start(ap, kgem);
 	while ((bo = va_arg(ap, struct kgem_bo *))) {
@@ -4838,6 +4847,7 @@ bool kgem_check_many_bo_fenced(struct kgem *kgem, ...)
 		}
 
 		flush |= bo->flush;
+		active &= bo->rq != NULL;
 	}
 	va_end(ap);
 
@@ -4876,6 +4886,9 @@ bool kgem_check_many_bo_fenced(struct kgem *kgem, ...)
 			return false;
 	}
 
+	if (active)
+		return true;
+
 	return kgem_flush(kgem, flush);
 }
 
commit d69a4f118a729edfb82498501ddb99caf2f3fb93
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 28 10:33:57 2013 +0000

    sna: Leave extra room in the mappable aperture for fence alignment
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index ecd3674..1e1da04 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -4641,6 +4641,8 @@ static bool aperture_check(struct kgem *kgem, unsigned num_pages)
 
 		/* Leave some space in case of alignment issues */
 		aperture.aper_available_size -= 4 * 1024 * 1024;
+		if (kgem->gen < 040)
+			aperture.aper_available_size -= kgem->aperture_fenced * PAGE_SIZE;
 
 		if (num_pages < aperture.aper_available_size / PAGE_SIZE)
 			return true;
commit 40d4199f151a39ecebf127cf468b4470d2906f4e
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Mon Oct 28 10:45:52 2013 +0000

    sna: Use page-count for mappable aperture size
    
    For consistency with the other aperture metrics and correctness when
    passing around required number of pages.
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index 5fdeebd..ecd3674 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -1368,6 +1368,7 @@ void kgem_init(struct kgem *kgem, int fd, struct pci_device *dev, unsigned gen)
 	     kgem->max_upload_tile_size, kgem->max_copy_tile_size));
 
 	/* Convert the aperture thresholds to pages */
+	kgem->aperture_mappable /= PAGE_SIZE;
 	kgem->aperture_low /= PAGE_SIZE;
 	kgem->aperture_high /= PAGE_SIZE;
 	kgem->aperture_total /= PAGE_SIZE;
@@ -2808,10 +2809,10 @@ void _kgem_submit(struct kgem *kgem)
 	batch_end = kgem_end_batch(kgem);
 	kgem_sna_flush(kgem);
 
-	DBG(("batch[%d/%d, flags=%x]: %d %d %d %d, nreloc=%d, nexec=%d, nfence=%d, aperture=%d\n",
+	DBG(("batch[%d/%d, flags=%x]: %d %d %d %d, nreloc=%d, nexec=%d, nfence=%d, aperture=%d [fenced=%]\n",
 	     kgem->mode, kgem->ring, kgem->batch_flags,
 	     batch_end, kgem->nbatch, kgem->surface, kgem->batch_size,
-	     kgem->nreloc, kgem->nexec, kgem->nfence, kgem->aperture));
+	     kgem->nreloc, kgem->nexec, kgem->nfence, kgem->aperture, kgem->aperture_fenced));
 
 	assert(kgem->nbatch <= kgem->batch_size);
 	assert(kgem->nbatch <= kgem->surface);
@@ -2902,9 +2903,9 @@ void _kgem_submit(struct kgem *kgem)
 
 #if !NDEBUG
 				ret = errno;
-				ErrorF("batch[%d/%d]: %d %d %d, nreloc=%d, nexec=%d, nfence=%d, aperture=%d: errno=%d\n",
+				ErrorF("batch[%d/%d]: %d %d %d, nreloc=%d, nexec=%d, nfence=%d, aperture=%d, fenced=%d, high=%d: errno=%d\n",
 				       kgem->mode, kgem->ring, batch_end, kgem->nbatch, kgem->surface,
-				       kgem->nreloc, kgem->nexec, kgem->nfence, kgem->aperture, errno);
+				       kgem->nreloc, kgem->nexec, kgem->nfence, kgem->aperture, kgem->aperture_fenced, kgem->aperture_high, errno);
 
 				for (i = 0; i < kgem->nexec; i++) {
 					struct kgem_bo *bo, *found = NULL;
@@ -3797,7 +3798,7 @@ unsigned kgem_can_create_2d(struct kgem *kgem,
 			flags |= KGEM_CAN_CREATE_CPU;
 		if (size <= kgem->max_gpu_size)
 			flags |= KGEM_CAN_CREATE_GPU;
-		if (size <= kgem->aperture_mappable/4)
+		if (size <= PAGE_SIZE*kgem->aperture_mappable/4)
 			flags |= KGEM_CAN_CREATE_GTT;
 		if (size > kgem->large_object_size)
 			flags |= KGEM_CAN_CREATE_LARGE;
@@ -3817,7 +3818,7 @@ unsigned kgem_can_create_2d(struct kgem *kgem,
 		DBG(("%s: tiled[%d] size=%d\n", __FUNCTION__, tiling, size));
 		if (size > 0 && size <= kgem->max_gpu_size)
 			flags |= KGEM_CAN_CREATE_GPU;
-		if (size > 0 && size <= kgem->aperture_mappable/4)
+		if (size > 0 && size <= PAGE_SIZE*kgem->aperture_mappable/4)
 			flags |= KGEM_CAN_CREATE_GTT;
 		if (size > kgem->large_object_size)
 			flags |= KGEM_CAN_CREATE_LARGE;
@@ -3840,10 +3841,10 @@ inline int kgem_bo_fenced_size(struct kgem *kgem, struct kgem_bo *bo)
 	assert(kgem->gen < 040);
 
 	if (kgem->gen < 030)
-		size = 512 * 1024;
+		size = 512 * 1024 / PAGE_SIZE;
 	else
-		size = 1024 * 1024;
-	while (size < bytes(bo))
+		size = 1024 * 1024 / PAGE_SIZE;
+	while (size < num_pages(bo))
 		size *= 2;
 
 	return size;
@@ -4715,8 +4716,6 @@ bool kgem_check_bo(struct kgem *kgem, ...)
 
 bool kgem_check_bo_fenced(struct kgem *kgem, struct kgem_bo *bo)
 {
-	uint32_t size;
-
 	assert(bo->refcnt);
 	while (bo->proxy)
 		bo = bo->proxy;
@@ -4726,18 +4725,26 @@ bool kgem_check_bo_fenced(struct kgem *kgem, struct kgem_bo *bo)
 		if (kgem->gen < 040 &&
 		    bo->tiling != I915_TILING_NONE &&
 		    (bo->exec->flags & EXEC_OBJECT_NEEDS_FENCE) == 0) {
+			uint32_t size;
+
 			assert(bo->tiling == I915_TILING_X);
 
 			if (kgem->nfence >= kgem->fence_max)
 				return false;
 
-			if (3*kgem->aperture_fenced > (kgem->aperture_mappable - kgem->aperture) &&
+			size = 3*kgem->aperture_fenced;
+			if (kgem->aperture_total == kgem->aperture_mappable)
+				size += kgem->aperture;
+			if (size > kgem->aperture_mappable &&
 			    kgem_ring_is_idle(kgem, kgem->ring))
 				return false;
 
 			size = kgem->aperture_fenced;
 			size += kgem_bo_fenced_size(kgem, bo);
-			if (3*size > 2*(kgem->aperture_mappable - kgem->aperture))
+			size *= 2;
+			if (kgem->aperture_total == kgem->aperture_mappable)
+				size += kgem->aperture;
+			if (size > kgem->aperture_mappable)
 				return false;
 		}
 
@@ -4754,22 +4761,30 @@ bool kgem_check_bo_fenced(struct kgem *kgem, struct kgem_bo *bo)
 
 	assert_tiling(kgem, bo);
 	if (kgem->gen < 040 && bo->tiling != I915_TILING_NONE) {
+		uint32_t size;
+
 		assert(bo->tiling == I915_TILING_X);
 
 		if (kgem->nfence >= kgem->fence_max)
 			return false;
 
-		if (3*kgem->aperture_fenced > (kgem->aperture_mappable - kgem->aperture) &&
+		size = 3*kgem->aperture_fenced;
+		if (kgem->aperture_total == kgem->aperture_mappable)
+			size += kgem->aperture;
+		if (size > kgem->aperture_mappable &&
 		    kgem_ring_is_idle(kgem, kgem->ring))
 			return false;
 
 		size = kgem->aperture_fenced;
 		size += kgem_bo_fenced_size(kgem, bo);
-		if (3*size > 2*(kgem->aperture_mappable - kgem->aperture))
+		size *= 2;
+		if (kgem->aperture_total == kgem->aperture_mappable)
+			size += kgem->aperture;
+		if (size > kgem->aperture_mappable)
 			return false;
 	}
 
-	if (kgem->aperture + num_pages(bo) > kgem->aperture_high - kgem->aperture_fenced) {
+	if (kgem->aperture + kgem->aperture_fenced + num_pages(bo) > kgem->aperture_high) {
 		DBG(("%s: final aperture usage (%d) is greater than high water mark (%d)\n",
 		     __FUNCTION__, num_pages(bo) + kgem->aperture, kgem->aperture_high));
 		if (!aperture_check(kgem, num_pages(bo) + kgem->aperture + kgem->aperture_fenced))
@@ -4825,14 +4840,24 @@ bool kgem_check_many_bo_fenced(struct kgem *kgem, ...)
 	va_end(ap);
 
 	if (num_fence) {
+		uint32_t size;
+
 		if (kgem->nfence + num_fence > kgem->fence_max)
 			return false;
 
-		if (3*kgem->aperture_fenced > (kgem->aperture_mappable - kgem->aperture) &&
+		size = 3*kgem->aperture_fenced;
+		if (kgem->aperture_total == kgem->aperture_mappable)
+			size += kgem->aperture;
+		if (size > kgem->aperture_mappable &&
 		    kgem_ring_is_idle(kgem, kgem->ring))
 			return false;
 
-		if (3*(fenced_size + kgem->aperture_fenced) > 2*(kgem->aperture_mappable - kgem->aperture))
+		size = kgem->aperture_fenced;
+		size += fenced_size;
+		size *= 2;
+		if (kgem->aperture_total == kgem->aperture_mappable)
+			size += kgem->aperture;
+		if (size > kgem->aperture_mappable)
 			return false;
 	}
 
@@ -5730,9 +5755,9 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
 		alloc = PAGE_ALIGN(size);
 	assert(alloc);
 
+	alloc /= PAGE_SIZE;
 	if (alloc > kgem->aperture_mappable / 4)
 		flags &= ~KGEM_BUFFER_INPLACE;
-	alloc /= PAGE_SIZE;
 
 	if (kgem->has_llc &&
 	    (flags & KGEM_BUFFER_WRITE_INPLACE) != KGEM_BUFFER_WRITE_INPLACE) {
commit 9266e35b42e17293be59cff4c5097f7755112349
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Sun Oct 27 16:45:53 2013 +0000

    sna: Fallthrough to opportunistic flushing after aperture checks
    
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index 36190fa..5fdeebd 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -4706,7 +4706,8 @@ bool kgem_check_bo(struct kgem *kgem, ...)
 	if (num_pages + kgem->aperture > kgem->aperture_high) {
 		DBG(("%s: final aperture usage (%d) is greater than high water mark (%d)\n",
 		     __FUNCTION__, num_pages + kgem->aperture, kgem->aperture_high));
-		return aperture_check(kgem, num_pages + kgem->aperture);
+		if (!aperture_check(kgem, num_pages + kgem->aperture))
+			return false;
 	}
 
 	return kgem_flush(kgem, flush);
@@ -4771,7 +4772,8 @@ bool kgem_check_bo_fenced(struct kgem *kgem, struct kgem_bo *bo)
 	if (kgem->aperture + num_pages(bo) > kgem->aperture_high - kgem->aperture_fenced) {
 		DBG(("%s: final aperture usage (%d) is greater than high water mark (%d)\n",
 		     __FUNCTION__, num_pages(bo) + kgem->aperture, kgem->aperture_high));
-		return aperture_check(kgem, num_pages(bo) + kgem->aperture + kgem->aperture_fenced);
+		if (!aperture_check(kgem, num_pages(bo) + kgem->aperture + kgem->aperture_fenced))
+			return false;
 	}
 
 	return kgem_flush(kgem, bo->flush);
@@ -4843,7 +4845,8 @@ bool kgem_check_many_bo_fenced(struct kgem *kgem, ...)
 	if (num_pages + kgem->aperture > kgem->aperture_high - kgem->aperture_fenced) {
 		DBG(("%s: final aperture usage (%d) is greater than high water mark (%d)\n",
 		     __FUNCTION__, num_pages + kgem->aperture, kgem->aperture_high));
-		return aperture_check(kgem, num_pages + kgem->aperture + kgem->aperture_fenced);
+		if (!aperture_check(kgem, num_pages + kgem->aperture + kgem->aperture_fenced))
+			return false;
 	}
 
 	return kgem_flush(kgem, flush);


More information about the xorg-commit mailing list