[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

xserver-xorg-video-intel: Changes to 'debian-unstable'



 debian/changelog                                     |   10 
 debian/control                                       |    5 
 debian/patches/series                                |    2 
 debian/patches/sna-let-modesetting-handle-gen9+.diff |   40 +++
 src/sna/kgem.h                                       |    1 
 src/sna/sna_display.c                                |   22 +
 src/sna/sna_dri2.c                                   |  212 ++++++++++++-------
 7 files changed, 209 insertions(+), 83 deletions(-)

New commits:
commit e43d5b2191c5d9695e29ad2f5ac16c15dc1d9543
Author: Timo Aaltonen <tjaalton@debian.org>
Date:   Mon Mar 7 17:44:23 2016 +0200

    sna-let-modesetting-handle-gen9+.diff: Use modesetting+glamor on Skylake and up.

diff --git a/debian/changelog b/debian/changelog
index cf9a229..91d3321 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -3,6 +3,8 @@ xserver-xorg-video-intel (2:2.99.917+git20160307-1) UNRELEASED; urgency=medium
   * New upstream snapshot.
   * control: Update the description, older hw likely still wants this
     driver.
+  * sna-let-modesetting-handle-gen9+.diff: Use modesetting+glamor on
+    Skylake and up.
 
  -- Timo Aaltonen <tjaalton@debian.org>  Mon, 07 Mar 2016 15:20:56 +0200
 
diff --git a/debian/patches/series b/debian/patches/series
index a82d1b4..aa08141 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1 @@
-#placeholder
+sna-let-modesetting-handle-gen9+.diff
diff --git a/debian/patches/sna-let-modesetting-handle-gen9+.diff b/debian/patches/sna-let-modesetting-handle-gen9+.diff
new file mode 100644
index 0000000..00b6cdb
--- /dev/null
+++ b/debian/patches/sna-let-modesetting-handle-gen9+.diff
@@ -0,0 +1,40 @@
+Aihe: [Intel-gfx] [RFC/PATCH xf86-video-intel] sna: Let modestting + glamor handle gen9+
+Lähettäjä: Hans de Goede <hdegoede@redhat.com>
+Päiväys: 29.02.2016 16:47
+Vastaanottaja: intel-gfx@lists.freedesktop.org
+CC: Hans de Goede <hdegoede@redhat.com>, Rob Clark <rclark@redhat.com>, Adam Jackson <ajax@redhat.com>
+
+sna has no meaningfull accel for gen9+, this causes problems with i.e.
+apps using XVideo since the sprite XVideo support does not work well
+for many apps.
+
+Therefor it is better to just let the xserver fall back to modesetting +
+glamor. This is implemented by returning FALSE from the probe methods,
+just like how nouveau handles falling back to modesetting for newer cards.
+
+BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1305369
+Signed-off-by: Hans de Goede <hdegoede@redhat.com>
+---
+ src/intel_module.c | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/src/intel_module.c b/src/intel_module.c
+index 60835b9..5979cb9 100644
+--- a/src/intel_module.c
++++ b/src/intel_module.c
+@@ -571,6 +571,13 @@ intel_scrn_create(DriverPtr		driver,
+ 			return FALSE;
+ 	}
+ 
++	/*
++	 * We've no accel support for these, so let modesetting + glamor
++	 * handle them.
++	 */
++	if ((unsigned)((struct intel_device_info *)match_data)->gen >= 0110)
++		return FALSE;
++
+ 	scrn = xf86AllocateScreen(driver, flags);
+ 	if (scrn == NULL)
+ 		return FALSE;
+-- 2.7.2 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx
+

commit 38022bf64b442279cd271c5c9abf7dcb5ebe57ca
Author: Timo Aaltonen <tjaalton@debian.org>
Date:   Mon Mar 7 17:40:23 2016 +0200

    control: Update the description, older hw likely still wants this driver.

diff --git a/debian/changelog b/debian/changelog
index 7f3362b..cf9a229 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,11 @@
+xserver-xorg-video-intel (2:2.99.917+git20160307-1) UNRELEASED; urgency=medium
+
+  * New upstream snapshot.
+  * control: Update the description, older hw likely still wants this
+    driver.
+
+ -- Timo Aaltonen <tjaalton@debian.org>  Mon, 07 Mar 2016 15:20:56 +0200
+
 xserver-xorg-video-intel (2:2.99.917+git20160218-1) unstable; urgency=medium
 
   * New upstream snapshot.
diff --git a/debian/control b/debian/control
index 5506f73..4fa3c27 100644
--- a/debian/control
+++ b/debian/control
@@ -75,8 +75,9 @@ Description: X.Org X server -- Intel i8xx, i9xx display driver
  .
  This package is built from the X.org xf86-video-intel driver module.
  .
- This driver is deprecated in favor of the server builtin modesetting
- driver.
+ The use of this driver is discouraged if your hw is new enough (ca.
+ 2007 and newer). You can try uninstalling this driver and let the
+ server use it's builtin modesetting driver instead.
 
 Package: xserver-xorg-video-intel-dbg
 Architecture: amd64 i386 kfreebsd-amd64 kfreebsd-i386 x32

commit 0204e55b618af285eb31c6eecc3c57b54319a0f4
Author: Ville Syrjälä <ville.syrjala@linux.intel.com>
Date:   Mon Mar 7 09:27:50 2016 +0000

    sna: Restrict reflected rotations to be rotations
    
    After rolling the bits to the left and the right, ensure that only
    rotations remain in the reflection.
    
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index 78338e6..9821c59 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -1166,6 +1166,8 @@ rotation_reflect(unsigned rotation)
 	assert(rotation);
 	rotation <<= 2; /* RR_Rotate_0 -> RR_Rotate_180 etc */
 	rotation |= rotation >> 4; /* RR_Rotate_270' to RR_Rotate_90 */
+	rotation &= RR_Rotate_All;
+	assert(rotation);
 
 	return rotation | other_bits;
 }

commit d1672806a5222f00dcc2eb24ccddd03f727f71bc
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Wed Feb 24 10:33:22 2016 +0000

    sna/dri2: Add active-scanout tracking to single CRTC flips
    
    When we do a partial flip (one CRTC of many) we install a fake
    frontbuffer for the window. This needs to be included in the
    active-scanout tracking like a normal frontbuffer to avoid being
    recycled too early.
    
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

diff --git a/src/sna/kgem.h b/src/sna/kgem.h
index 8bea755..0a941e0 100644
--- a/src/sna/kgem.h
+++ b/src/sna/kgem.h
@@ -404,6 +404,7 @@ void _kgem_bo_destroy(struct kgem *kgem, struct kgem_bo *bo);
 static inline void kgem_bo_destroy(struct kgem *kgem, struct kgem_bo *bo)
 {
 	assert(bo->refcnt);
+	assert(bo->refcnt > bo->active_scanout);
 	if (--bo->refcnt == 0)
 		_kgem_bo_destroy(kgem, bo);
 }
diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index 98fb8af..78338e6 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -1640,6 +1640,7 @@ static bool wait_for_shadow(struct sna *sna,
 			RegionSubtract(&sna->mode.shadow_region, &sna->mode.shadow_region, &region);
 		}
 
+		crtc->client_bo->active_scanout--;
 		kgem_bo_destroy(&sna->kgem, crtc->client_bo);
 		crtc->client_bo = NULL;
 		list_del(&crtc->shadow_link);
@@ -1865,7 +1866,8 @@ static void sna_crtc_disable_override(struct sna *sna, struct sna_crtc *crtc)
 	if (crtc->client_bo == NULL)
 		return;
 
-	assert(crtc->client_bo->refcnt > crtc->client_bo->active_scanout);
+	assert(crtc->client_bo->refcnt >= crtc->client_bo->active_scanout);
+	crtc->client_bo->active_scanout--;
 
 	if (!crtc->transform) {
 		DrawableRec tmp;
@@ -4366,6 +4368,7 @@ gather_encoders(struct sna *sna, uint32_t id, int count,
 	DBG(("%s(%d): expected count=%d\n", __FUNCTION__, id, count));
 
 	VG_CLEAR(compat_conn);
+	VG_CLEAR(enc);
 	memset(out, 0, sizeof(*out));
 
 	do {
@@ -4390,6 +4393,7 @@ gather_encoders(struct sna *sna, uint32_t id, int count,
 			compat_conn.conn.count_encoders = count = 0;
 		}
 
+		VG(VALGRIND_MAKE_MEM_DEFINED(ids, sizeof(uint32_t)*compat_conn.conn.count_encoders));
 		if (count == compat_conn.conn.count_encoders)
 			break;
 
@@ -8391,12 +8395,14 @@ void sna_shadow_set_crtc(struct sna *sna,
 
 	if (sna_crtc->client_bo != bo) {
 		if (sna_crtc->client_bo) {
-			assert(sna_crtc->client_bo->refcnt > sna_crtc->client_bo->active_scanout);
+			assert(sna_crtc->client_bo->refcnt >= sna_crtc->client_bo->active_scanout);
+			sna_crtc->client_bo->active_scanout--;
 			kgem_bo_destroy(&sna->kgem, sna_crtc->client_bo);
 		}
 
 		sna_crtc->client_bo = kgem_bo_reference(bo);
-		assert(sna_crtc->client_bo->refcnt > sna_crtc->client_bo->active_scanout);
+		sna_crtc->client_bo->active_scanout++;
+		assert(sna_crtc->client_bo->refcnt >= sna_crtc->client_bo->active_scanout);
 		sna_crtc_damage(crtc);
 	}
 
@@ -8451,7 +8457,8 @@ void sna_shadow_unset_crtc(struct sna *sna,
 	if (sna_crtc->client_bo == NULL)
 		return;
 
-	assert(sna_crtc->client_bo->refcnt > sna_crtc->client_bo->active_scanout);
+	assert(sna_crtc->client_bo->refcnt >= sna_crtc->client_bo->active_scanout);
+	sna_crtc->client_bo->active_scanout--;
 	kgem_bo_destroy(&sna->kgem, sna_crtc->client_bo);
 	sna_crtc->client_bo = NULL;
 	list_del(&sna_crtc->shadow_link);
diff --git a/src/sna/sna_dri2.c b/src/sna/sna_dri2.c
index 2fcda87..2ed698d 100644
--- a/src/sna/sna_dri2.c
+++ b/src/sna/sna_dri2.c
@@ -171,6 +171,7 @@ inline static void
 __sna_dri2_copy_event(struct sna_dri2_event *info, unsigned flags)
 {
 	DBG(("%s: flags = %x\n", __FUNCTION__, flags));
+	assert(info->front != info->back);
 	info->bo = __sna_dri2_copy_region(info->sna, info->draw, NULL,
 					  info->back, info->front,
 					  flags);
@@ -282,12 +283,16 @@ sna_dri2_get_back(struct sna *sna,
 		     __FUNCTION__, c->bo ? c->bo->handle : 0, c->bo ? c->bo->active_scanout : -1));
 		assert(c->bo);
 		if (c->bo->active_scanout == 0) {
+			_list_del(&c->link);
+			if (c->bo == NULL) {
+				free(c);
+				goto out;
+			}
 			bo = c->bo;
 			name = c->name;
 			flags = c->flags;
 			DBG(("%s: reuse cache handle=%d, name=%d, flags=%d\n", __FUNCTION__, bo->handle, name, flags));
 			c->bo = NULL;
-			_list_del(&c->link);
 			break;
 		}
 	}
@@ -360,6 +365,7 @@ sna_dri2_get_back(struct sna *sna,
 	assert(back->pitch);
 	assert(back->name);
 
+out:
 	get_private(back)->stale = false;
 }
 
@@ -368,11 +374,13 @@ dri2_chain(DrawablePtr d)
 {
 	struct dri2_window *priv = dri2_window((WindowPtr)d);
 	assert(priv != NULL);
+	assert(priv->chain == NULL || priv->chain->chained);
 	return priv->chain;
 }
 inline static DRI2BufferPtr dri2_window_get_front(WindowPtr win)
 {
 	struct dri2_window *priv = dri2_window(win);
+	assert(priv->front == NULL || get_private(priv->front)->bo->active_scanout);
 	return priv ? priv->front : NULL;
 }
 #else
@@ -627,11 +635,13 @@ sna_dri2_create_buffer(DrawablePtr draw,
 			     private->bo->handle, buffer->name,
 			     private->bo->active_scanout));
 
+			assert(buffer->attachment == DRI2BufferFrontLeft);
 			assert(private->pixmap == pixmap);
 			assert(sna_pixmap(pixmap)->flush);
 			assert(sna_pixmap(pixmap)->pinned & PIN_DRI2);
 			assert(kgem_bo_flink(&sna->kgem, private->bo) == buffer->name);
 			assert(private->bo->pitch == buffer->pitch);
+			assert(private->bo->active_scanout);
 
 			private->refcnt++;
 			return buffer;
@@ -864,9 +874,10 @@ static void _sna_dri2_destroy_buffer(struct sna *sna,
 	if (buffer == NULL)
 		return;
 
-	DBG(("%s: %p [handle=%d] -- refcnt=%d, pixmap=%ld\n",
+	DBG(("%s: %p [handle=%d] -- refcnt=%d, pixmap=%ld, proxy?=%d\n",
 	     __FUNCTION__, buffer, private->bo->handle, private->refcnt,
-	     private->pixmap ? private->pixmap->drawable.serialNumber : 0));
+	     private->pixmap ? private->pixmap->drawable.serialNumber : 0,
+	     private->proxy != NULL));
 	assert(private->refcnt > 0);
 	if (--private->refcnt)
 		return;
@@ -875,6 +886,9 @@ static void _sna_dri2_destroy_buffer(struct sna *sna,
 
 	if (private->proxy) {
 		DBG(("%s: destroying proxy\n", __FUNCTION__));
+		assert(private->bo->active_scanout > 0);
+		private->bo->active_scanout--;
+
 		_sna_dri2_destroy_buffer(sna, draw, private->proxy);
 		private->pixmap = NULL;
 	}
@@ -889,6 +903,8 @@ static void _sna_dri2_destroy_buffer(struct sna *sna,
 		assert(priv->pinned & PIN_DRI2);
 		assert(priv->flush);
 
+		DBG(("%s: removing active_scanout=%d from pixmap handle=%d\n",
+		     __FUNCTION__, priv->gpu_bo->active_scanout, priv->gpu_bo->handle));
 		assert(priv->gpu_bo->active_scanout > 0);
 		priv->gpu_bo->active_scanout--;
 
@@ -928,6 +944,7 @@ static void sna_dri2_destroy_buffer(DrawablePtr draw, DRI2Buffer2Ptr buffer)
 
 static DRI2BufferPtr sna_dri2_reference_buffer(DRI2BufferPtr buffer)
 {
+	assert(get_private(buffer)->refcnt > 0);
 	get_private(buffer)->refcnt++;
 	return buffer;
 }
@@ -1616,7 +1633,6 @@ sna_dri2_remove_event(struct sna_dri2_event *info)
 {
 	WindowPtr win = (WindowPtr)info->draw;
 	struct dri2_window *priv;
-	struct sna_dri2_event *chain;
 
 	assert(win->drawable.type == DRAWABLE_WINDOW);
 	DBG(("%s: remove[%p] from window %ld, active? %d\n",
@@ -1630,9 +1646,11 @@ sna_dri2_remove_event(struct sna_dri2_event *info)
 	info->chained = false;
 
 	if (priv->chain != info) {
-		chain = priv->chain;
-		while (chain->chain != info)
+		struct sna_dri2_event *chain = priv->chain;
+		while (chain->chain != info) {
+			assert(chain->chained);
 			chain = chain->chain;
+		}
 		assert(chain != info);
 		assert(info->chain != chain);
 		chain->chain = info->chain;
@@ -1669,6 +1687,7 @@ sna_dri2_event_free(struct sna_dri2_event *info)
 	if (info->chained)
 		sna_dri2_remove_event(info);
 
+	assert((info->front == NULL && info->back == NULL) || info->front != info->back);
 	_sna_dri2_destroy_buffer(info->sna, info->draw, info->front);
 	_sna_dri2_destroy_buffer(info->sna, info->draw, info->back);
 
@@ -1809,8 +1828,10 @@ void sna_dri2_decouple_window(WindowPtr win)
 
 	if (priv->front) {
 		struct sna *sna = to_sna_from_drawable(&win->drawable);
+
 		assert(priv->crtc);
 		sna_shadow_unset_crtc(sna, priv->crtc);
+
 		_sna_dri2_destroy_buffer(sna, NULL, priv->front);
 		priv->front = NULL;
 	}
@@ -1833,6 +1854,7 @@ void sna_dri2_destroy_window(WindowPtr win)
 	if (priv->front) {
 		assert(priv->crtc);
 		sna_shadow_unset_crtc(sna, priv->crtc);
+
 		_sna_dri2_destroy_buffer(sna, NULL, priv->front);
 	}
 
@@ -1947,6 +1969,7 @@ sna_dri2_flip(struct sna_dri2_event *info)
 	info->front->pitch = info->back->pitch;
 	get_private(info->front)->bo = bo;
 	bo->active_scanout++;
+	assert(bo->active_scanout <= bo->refcnt);
 
 	info->back->flags = tmp_flags;
 	info->back->name = tmp_name;
@@ -2338,6 +2361,7 @@ sna_dri2_xchg(DrawablePtr draw, DRI2BufferPtr front, DRI2BufferPtr back)
 	assert(front_bo->active_scanout > 0);
 	front_bo->active_scanout--;
 	back_bo->active_scanout++;
+	assert(back_bo->active_scanout <= back_bo->refcnt);
 
 	tmp = front->name;
 	front->name = back->name;
@@ -2364,8 +2388,6 @@ static void sna_dri2_xchg_crtc(struct sna *sna, DrawablePtr draw, xf86CrtcPtr cr
 {
 	WindowPtr win = (WindowPtr)draw;
 	struct dri2_window *priv = dri2_window(win);
-	DRI2Buffer2Ptr tmp;
-	struct kgem_bo *bo;
 
 	DBG(("%s: exchange front=%d/%d and back=%d/%d, win id=%lu, pixmap=%ld %dx%d\n",
 	     __FUNCTION__,
@@ -2375,7 +2397,7 @@ static void sna_dri2_xchg_crtc(struct sna *sna, DrawablePtr draw, xf86CrtcPtr cr
 	     get_window_pixmap(win)->drawable.serialNumber,
 	     get_window_pixmap(win)->drawable.width,
 	     get_window_pixmap(win)->drawable.height));
-	assert(can_xchg_crtc(to_sna_from_drawable(draw), draw, crtc, front, back));
+	assert(can_xchg_crtc(sna, draw, crtc, front, back));
 
 	if (APPLY_DAMAGE) {
 		DBG(("%s: marking drawable as damaged\n", __FUNCTION__));
@@ -2388,69 +2410,72 @@ static void sna_dri2_xchg_crtc(struct sna *sna, DrawablePtr draw, xf86CrtcPtr cr
 		sna->ignore_copy_area = false;
 	}
 
-	tmp = calloc(1, sizeof(*tmp) + sizeof(struct sna_dri2_private));
-	if (tmp == NULL) {
-		back->attachment = -1;
-		if (get_private(back)->proxy == NULL) {
-			get_private(back)->pixmap = get_private(front)->pixmap;
-			get_private(back)->proxy = sna_dri2_reference_buffer(get_private(front)->proxy ?: front);
+	if (priv->front == NULL) {
+		DRI2Buffer2Ptr tmp;
+
+		tmp = calloc(1, sizeof(*tmp) + sizeof(struct sna_dri2_private));
+		if (tmp == NULL) {
+			sna_shadow_unset_crtc(sna, crtc);
+			return;
 		}
 
-		if (priv->front) {
-			assert(front == priv->front);
-			assert(get_private(priv->front)->refcnt > 1);
-			get_private(priv->front)->refcnt--;
+		tmp->attachment = DRI2BufferFrontLeft;
+		tmp->driverPrivate = tmp + 1;
+		tmp->cpp = back->cpp;
+		tmp->format = back->format;
+
+		get_private(tmp)->refcnt = 1;
+		get_private(tmp)->bo = kgem_create_2d(&sna->kgem,
+						      draw->width, draw->height, draw->bitsPerPixel,
+						      get_private(back)->bo->tiling,
+						      CREATE_SCANOUT | CREATE_EXACT);
+		if (get_private(tmp)->bo != NULL) {
+			tmp->pitch = get_private(tmp)->bo->pitch;
+			tmp->name = kgem_bo_flink(&sna->kgem, get_private(tmp)->bo);
 		}
-		priv->front = sna_dri2_reference_buffer(back);
-		return;
+		if (tmp->name == 0) {
+			if (get_private(tmp)->bo != NULL)
+				kgem_bo_destroy(&sna->kgem, get_private(tmp)->bo);
+			sna_shadow_unset_crtc(sna, crtc);
+			return;
+		}
+		get_private(tmp)->size = get_private(back)->size;
+		get_private(tmp)->pixmap = get_private(front)->pixmap;
+		get_private(tmp)->proxy = sna_dri2_reference_buffer(front);
+		get_private(tmp)->bo->active_scanout++;
+
+		priv->front = front = tmp;
 	}
+	assert(front == priv->front);
 
-	*tmp = *back;
-	tmp->attachment = DRI2BufferFrontLeft;
-	tmp->driverPrivate = tmp + 1;
-	get_private(tmp)->refcnt = 1;
-	get_private(tmp)->bo = get_private(back)->bo;
-	get_private(tmp)->size = get_private(back)->size;
-	get_private(tmp)->pixmap = get_private(front)->pixmap;
-	get_private(tmp)->proxy = sna_dri2_reference_buffer(get_private(front)->proxy ?: front);
-	mark_stale(back);
+	{
+		struct kgem_bo *front_bo = get_private(front)->bo;
+		struct kgem_bo *back_bo = get_private(back)->bo;
+		unsigned tmp;
 
-	if (priv->front) {
-		DBG(("%s: replacing Window frontbuffer (was handle=%d) now handle=%d\n",
-		     __FUNCTION__,
-		     get_private(priv->front)->bo->handle,
-		     get_private(tmp)->bo->handle));
-		assert(front == priv->front);
-		assert(get_private(priv->front)->refcnt > 1);
-		get_private(priv->front)->refcnt--;
-	}
-	priv->front = tmp;
-
-	if (get_private(front)->proxy) {
-		DBG(("%s: reusing current proxy frontbuffer\n", __FUNCTION__));
-		front->attachment = DRI2BufferBackLeft;
-		ref(get_private(tmp)->bo);
-		back->attachment = DRI2BufferFrontLeft;
-	} else {
-		DBG(("%s: allocating new backbuffer\n", __FUNCTION__));
-		back->name = 0;
-		back->flags = 0;
-		bo = kgem_create_2d(&sna->kgem,
-				    draw->width, draw->height, draw->bitsPerPixel,
-				    get_private(back)->bo->tiling,
-				    CREATE_SCANOUT | CREATE_EXACT);
-		if (bo != NULL) {
-			get_private(back)->bo = bo;
-			back->pitch = bo->pitch;
-			get_private(back)->size = draw->height << 16 | draw->width;
-			back->name = kgem_bo_flink(&sna->kgem, bo);
-		}
-		if (back->name == 0) {
-			if (bo != NULL)
-				kgem_bo_destroy(&sna->kgem, bo);
-			get_private(back)->bo = NULL;
-			back->attachment = DRI2BufferFrontLeft;
-		}
+		assert(front_bo->refcnt);
+		assert(back_bo->refcnt);
+
+		get_private(back)->bo = front_bo;
+		get_private(front)->bo = back_bo;
+		mark_stale(back);
+
+		assert(front_bo->active_scanout > 0);
+		front_bo->active_scanout--;
+		back_bo->active_scanout++;
+		assert(back_bo->active_scanout <= back_bo->refcnt);
+
+		tmp = front->name;
+		front->name = back->name;
+		back->name = tmp;
+
+		tmp = front->pitch;
+		front->pitch = back->pitch;
+		back->pitch = tmp;
+
+		tmp = front->flags;
+		front->flags = back->flags;
+		back->flags = tmp;
 	}
 }
 
@@ -2562,6 +2587,7 @@ void sna_dri2_vblank_handler(struct drm_event_vblank *event)
 		goto done;
 	}
 
+	assert((info->front == NULL && info->back == NULL) || info->front != info->back);
 	switch (info->type) {
 	case FLIP:
 		/* If we can still flip... */
@@ -2611,6 +2637,12 @@ void sna_dri2_vblank_handler(struct drm_event_vblank *event)
 		}
 
 		if (info->pending.bo) {
+			DBG(("%s: swapping old back handle=%d [name=%d, active=%d] for pending handle=%d [name=%d, active=%d], front handle=%d [name=%d, active=%d]\n",
+			     __FUNCTION__,
+			     get_private(info->back)->bo->handle, info->back->name, get_private(info->back)->bo->active_scanout,
+			     info->pending.bo->handle, info->pending.name, info->pending.bo->active_scanout,
+			     get_private(info->front)->bo->handle, info->front->name, get_private(info->front)->bo->active_scanout));
+
 			if (sna->mode.shadow && sna->mode.shadow_wait) {
 				/* recursed from wait_for_shadow(), simply requeue */
 				DBG(("%s -- recursed from wait_for_shadow(), requeuing\n", __FUNCTION__));
@@ -2693,14 +2725,14 @@ sna_dri2_immediate_blit(struct sna *sna,
 			struct sna_dri2_event *info,
 			bool sync)
 {
-	DrawablePtr draw = info->draw;
-	struct sna_dri2_event *chain = dri2_chain(draw);
+	struct sna_dri2_event *chain = dri2_chain(info->draw);
 
 	if (sna->flags & SNA_NO_WAIT)
 		sync = false;
 
 	DBG(("%s: emitting immediate blit, throttling client, synced? %d, chained? %d, pipe %d\n",
 	     __FUNCTION__, sync, chain != info, info->pipe));
+	assert(chain);
 
 	info->type = SWAP_COMPLETE;
 	info->sync = sync;
@@ -2709,6 +2741,7 @@ sna_dri2_immediate_blit(struct sna *sna,
 	if (chain == info) {
 		DBG(("%s: no pending blit, starting chain\n", __FUNCTION__));
 
+		assert(info->front != info->back);
 		if (can_xchg(info->sna, info->draw, info->front, info->back)) {
 			sna_dri2_xchg(info->draw, info->front, info->back);
 		} else if (can_xchg_crtc(info->sna, info->draw, info->crtc,
@@ -2720,7 +2753,7 @@ sna_dri2_immediate_blit(struct sna *sna,
 
 		assert(info->signal);
 
-		if ((!swap_limit(draw, 2 + !sync) && !sync) ||
+		if ((!swap_limit(info->draw, 2 + !sync) && !sync) ||
 		    !sna_next_vblank(info)) {
 			DBG(("%s: fake triple buffering, unblocking client\n", __FUNCTION__));
 			frame_swap_complete(info, DRI2_BLIT_COMPLETE);
@@ -2729,8 +2762,13 @@ sna_dri2_immediate_blit(struct sna *sna,
 		return;
 	}
 
+	DBG(("%s: current event front=%d [name=%d, active?=%d], back=%d [name=%d, active?=%d]\n", __FUNCTION__,
+	     get_private(chain->front)->bo->handle, chain->front->name, get_private(chain->front)->bo->active_scanout,
+	     get_private(chain->back)->bo->handle, chain->back->name, get_private(chain->back)->bo->active_scanout));
+
 	if (chain->type == SWAP_COMPLETE) {
 		assert(chain->draw == info->draw);
+		assert(chain->front = info->front);
 		assert(chain->client == info->client);
 		assert(chain->event_complete == info->event_complete);
 		assert(chain->event_data == info->event_data);
@@ -2756,7 +2794,7 @@ sna_dri2_immediate_blit(struct sna *sna,
 			chain->pending.bo = NULL;
 		}
 
-		if (chain->pending.bo == NULL && swap_limit(draw, 2 + !sync)) {
+		if (chain->pending.bo == NULL && swap_limit(info->draw, 2 + !sync)) {
 			DBG(("%s: setting handle=%d as pending blit (current event front=%d, back=%d)\n", __FUNCTION__,
 			     get_private(info->back)->bo->handle,
 			     get_private(chain->front)->bo->handle,
@@ -3076,14 +3114,18 @@ sna_dri2_schedule_flip(ClientPtr client, DrawablePtr draw, xf86CrtcPtr crtc,
 		if (info && info->draw == draw) {
 			assert(info->type != FLIP);
 			assert(info->queued);
+			assert(info->front != info->back);
 			if (info->front != front) {
-				assert(info->front == NULL);
+				assert(info->front != NULL);
+				_sna_dri2_destroy_buffer(sna, draw, info->front);
 				info->front = sna_dri2_reference_buffer(front);
 			}
 			if (info->back != back) {
+				assert(info->back != NULL);
 				_sna_dri2_destroy_buffer(sna, draw, info->back);
 				info->back = sna_dri2_reference_buffer(back);
 			}
+			assert(info->front != info->back);
 			DBG(("%s: executing xchg of pending flip: flip_continue=%d, keepalive=%d, chain?=%d\n", __FUNCTION__, info->flip_continue, info->keepalive, current_msc < *target_msc));
 			sna_dri2_xchg(draw, front, back);
 			info->keepalive = KEEPALIVE;
@@ -3111,6 +3153,7 @@ sna_dri2_schedule_flip(ClientPtr client, DrawablePtr draw, xf86CrtcPtr crtc,
 		assert(info->draw);
 		info->signal = true;
 
+		assert(front != back);
 		info->front = sna_dri2_reference_buffer(front);
 		info->back = sna_dri2_reference_buffer(back);
 
@@ -3174,6 +3217,7 @@ queue:
 	info->signal = true;
 	info->type = FLIP;
 
+	assert(front != back);
 	info->front = sna_dri2_reference_buffer(front);
 	info->back = sna_dri2_reference_buffer(back);
 
@@ -3271,8 +3315,11 @@ sna_dri2_schedule_swap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
 		WindowPtr win = (WindowPtr)draw;
 		struct dri2_window *priv = dri2_window(win);
 
-		if (priv->front)
+		if (priv->front) {
 			front = priv->front;
+			assert(front->attachment == DRI2BufferFrontLeft);
+			assert(get_private(front)->refcnt);
+		}
 
 		if (win->clipList.extents.x2 <= win->clipList.extents.x1 ||
 		    win->clipList.extents.y2 <= win->clipList.extents.y1) {
@@ -3286,6 +3333,8 @@ sna_dri2_schedule_swap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
 		}
 	}
 
+	DBG(("%s: using front handle=%d, active_scanout?=%d\n", __FUNCTION__, get_private(front)->bo->handle, get_private(front)->bo->active_scanout));
+	assert(get_private(front)->bo->active_scanout);
 	if (get_private(front)->pixmap != get_drawable_pixmap(draw)) {
 		DBG(("%s: decoupled DRI2 front pixmap=%ld, actual pixmap=%ld\n",
 		     __FUNCTION__,
@@ -3331,6 +3380,7 @@ sna_dri2_schedule_swap(ClientPtr client, DrawablePtr draw, DRI2BufferPtr front,
 	assert(info->draw);
 	info->signal = true;
 
+	assert(front != back);
 	info->front = sna_dri2_reference_buffer(front);
 	info->back = sna_dri2_reference_buffer(back);
 
@@ -3396,8 +3446,10 @@ skip:
 		assert(info->draw);
 		info->signal = true;
 
-		info->front = sna_dri2_reference_buffer(front);
-		info->back = sna_dri2_reference_buffer(back);
+		if (info->front == NULL)
+			info->front = sna_dri2_reference_buffer(front);
+		if (info->back == NULL)
+			info->back = sna_dri2_reference_buffer(back);
 
 		if (!sna_next_vblank(info))
 			goto fake;

commit 4cd43faa646e368624079b73b216f6546ede5c16
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Tue Feb 23 14:40:39 2016 +0000

    sna: Flush the DRM event queue after a modeset
    
    Changing the mode will cause the DRM events(pageflips, vblanks) to
    be completed and the queue flushed. After applying the CRTC, drain the
    event queue.
    
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index 4870429..98fb8af 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -6988,6 +6988,9 @@ sna_crtc_config_notify(ScreenPtr screen)
 		return;
 	}
 
+	/* Flush any events completed by the modeset */
+	sna_mode_wakeup(sna);
+
 	update_flush_interval(sna);
 	sna->cursor.disable = false; /* Reset HW cursor until the next fail */
 	sna_cursors_reload(sna);

commit 3593a2d18928f74ee470f824dc34b8b5b148ce2d
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Tue Feb 23 14:36:10 2016 +0000

    sna/dri2: Reset front pointer on frame event across a modeset
    
    If the root window's pixmap is changed (e.g. to resizing the
    framebuffer) then an outstanding flip becomes invalid. The invalid flip
    is marked as having a stale front, and that triggers an assertion if the
    user then tries to schedule flip before the pending flip event is
    processed.
    
    References: https://bugs.freedesktop.org/show_bug.cgi?id=9425
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

diff --git a/src/sna/sna_dri2.c b/src/sna/sna_dri2.c
index 9398c0a..2fcda87 100644
--- a/src/sna/sna_dri2.c
+++ b/src/sna/sna_dri2.c
@@ -3075,8 +3075,11 @@ sna_dri2_schedule_flip(ClientPtr client, DrawablePtr draw, xf86CrtcPtr crtc,
 
 		if (info && info->draw == draw) {
 			assert(info->type != FLIP);
-			assert(info->front == front);
 			assert(info->queued);
+			if (info->front != front) {
+				assert(info->front == NULL);
+				info->front = sna_dri2_reference_buffer(front);
+			}
 			if (info->back != back) {
 				_sna_dri2_destroy_buffer(sna, draw, info->back);
 				info->back = sna_dri2_reference_buffer(back);
@@ -3129,6 +3132,7 @@ sna_dri2_schedule_flip(ClientPtr client, DrawablePtr draw, xf86CrtcPtr crtc,
 			info->type = use_triple_buffer(sna, client, *target_msc == 0);
 			if (!sna_dri2_flip(info)) {
 				DBG(("%s: flip failed, falling back\n", __FUNCTION__));
+				info->signal = false;
 				sna_dri2_event_free(info);
 				return false;
 			}
@@ -3179,6 +3183,7 @@ queue:
 		/* Account for 1 frame extra pageflip delay */
 		if (!sna_wait_vblank(info,
 				     draw_target_seq(draw, *target_msc - 1))) {
+			info->signal = false;
 			sna_dri2_event_free(info);
 			return false;
 		}

commit 64b1b1f10da59f15a91141c9f76d7d09517f8ea8
Author: Chris Wilson <chris@chris-wilson.co.uk>
Date:   Tue Feb 23 09:32:57 2016 +0000

    sna/dri2: Ensure the flipqueue is drained on pageflip failure
    
    If we fail to queue a flip for a CRTC, we attempt to restore the
    original mode. However, if the failure is on a second CRTC, the queued
    flip on the first will still complete causing us to process the event
    twice.
    
    References: https://bugs.freedesktop.org/show_bug.cgi?id=94250
    Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>

diff --git a/src/sna/sna_display.c b/src/sna/sna_display.c
index a1e1ffb..4870429 100644
--- a/src/sna/sna_display.c
+++ b/src/sna/sna_display.c
@@ -6374,6 +6374,8 @@ static void sna_mode_restore(struct sna *sna)
 		}
 	}
 	sna_mode_wakeup(sna);
+	while (sna->mode.flip_active && sna_mode_wakeup(sna))
+		;
 	update_flush_interval(sna);
 	sna_cursors_reload(sna);
 	sna->mode.dirty = false;
diff --git a/src/sna/sna_dri2.c b/src/sna/sna_dri2.c
index fcfbd9d..9398c0a 100644
--- a/src/sna/sna_dri2.c
+++ b/src/sna/sna_dri2.c
@@ -1914,6 +1914,7 @@ sna_dri2_flip(struct sna_dri2_event *info)
 		return false;
 	}
 
+	assert(!info->queued);
 	if (!sna_page_flip(info->sna, bo, sna_dri2_flip_handler,
 			   info->type == FLIP_ASYNC ? NULL : info))
 		return false;
@@ -2797,6 +2798,7 @@ sna_dri2_flip_continue(struct sna_dri2_event *info)
 	if (bo != sna_pixmap(info->sna->front)->gpu_bo)
 		return false;
 
+	assert(!info->queued);
 	if (!sna_page_flip(info->sna, bo, sna_dri2_flip_handler, info))
 		return false;
 
@@ -2868,8 +2870,9 @@ static void sna_dri2_flip_event(struct sna_dri2_event *flip)
 {
 	struct sna *sna = flip->sna;
 
-	DBG(("%s flip=%p (pipe=%d, event=%d)\n", __FUNCTION__, flip, flip->pipe, flip->type));
-	assert(flip->queued);
+	DBG(("%s flip=%p (pipe=%d, event=%d, queued?=%d)\n", __FUNCTION__, flip, flip->pipe, flip->type, flip->queued));
+	if (!flip->queued) /* pageflip died whilst being queued */
+		return;
 	flip->queued = false;
 
 	if (sna->dri2.flip_pending == flip)


Reply to: