[PATCH xf86-video-amdgpu 05/10] Wait for pending flips synchronously before turning off a CRTC

Michel Dänzer michel at daenzer.net
Fri Aug 18 08:53:17 UTC 2017


From: Michel Dänzer <michel.daenzer at amd.com>

Allows removing drmmode_clear_pending_flip and the pending_dpms_mode
field and cleaning up the code considerably.

(Ported from radeon commit e6d7dc2070f4d21a6900916bb70a31839112882c)

Signed-off-by: Michel Dänzer <michel.daenzer at amd.com>
---
 src/amdgpu_kms.c      | 12 ++++++-----
 src/amdgpu_present.c  |  2 +-
 src/amdgpu_video.c    |  2 +-
 src/drmmode_display.c | 60 ++++++++++-----------------------------------------
 src/drmmode_display.h |  5 +----
 5 files changed, 21 insertions(+), 60 deletions(-)

diff --git a/src/amdgpu_kms.c b/src/amdgpu_kms.c
index 3e2112578..d8f667df0 100644
--- a/src/amdgpu_kms.c
+++ b/src/amdgpu_kms.c
@@ -634,7 +634,7 @@ amdgpu_prime_scanout_update(PixmapDirtyUpdatePtr dirty)
 	drmmode_crtc = xf86_crtc->driver_private;
 	if (drmmode_crtc->scanout_update_pending ||
 	    !drmmode_crtc->scanout[drmmode_crtc->scanout_id].pixmap ||
-	    drmmode_crtc->pending_dpms_mode != DPMSModeOn)
+	    drmmode_crtc->dpms_mode != DPMSModeOn)
 		return;
 
 	drm_queue_seq = amdgpu_drm_queue_alloc(xf86_crtc,
@@ -663,10 +663,12 @@ amdgpu_prime_scanout_update(PixmapDirtyUpdatePtr dirty)
 static void
 amdgpu_prime_scanout_flip_abort(xf86CrtcPtr crtc, void *event_data)
 {
+	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(crtc->scrn);
 	drmmode_crtc_private_ptr drmmode_crtc = event_data;
 
 	drmmode_crtc->scanout_update_pending = FALSE;
-	drmmode_clear_pending_flip(crtc);
+	drmmode_fb_reference(pAMDGPUEnt->fd, &drmmode_crtc->flip_pending,
+			     NULL);
 }
 
 static void
@@ -698,7 +700,7 @@ amdgpu_prime_scanout_flip(PixmapDirtyUpdatePtr ent)
 	drmmode_crtc = crtc->driver_private;
 	if (drmmode_crtc->scanout_update_pending ||
 	    !drmmode_crtc->scanout[drmmode_crtc->scanout_id].pixmap ||
-	    drmmode_crtc->pending_dpms_mode != DPMSModeOn)
+	    drmmode_crtc->dpms_mode != DPMSModeOn)
 		return;
 
 	scanout_id = drmmode_crtc->scanout_id ^ 1;
@@ -916,7 +918,7 @@ amdgpu_scanout_update(xf86CrtcPtr xf86_crtc)
 
 	if (!xf86_crtc->enabled ||
 	    drmmode_crtc->scanout_update_pending ||
-	    drmmode_crtc->pending_dpms_mode != DPMSModeOn)
+	    drmmode_crtc->dpms_mode != DPMSModeOn)
 		return;
 
 	pDamage = drmmode_crtc->scanout_damage;
@@ -982,7 +984,7 @@ amdgpu_scanout_flip(ScreenPtr pScreen, AMDGPUInfoPtr info,
 	unsigned scanout_id;
 
 	if (drmmode_crtc->scanout_update_pending ||
-	    drmmode_crtc->pending_dpms_mode != DPMSModeOn)
+	    drmmode_crtc->dpms_mode != DPMSModeOn)
 		return;
 
 	scanout_id = drmmode_crtc->scanout_id ^ 1;
diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index b6792f361..c7fc402cd 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -361,7 +361,7 @@ modeset:
 		if (!crtc->enabled)
 			continue;
 
-		if (drmmode_crtc->pending_dpms_mode == DPMSModeOn)
+		if (drmmode_crtc->dpms_mode == DPMSModeOn)
 			crtc->funcs->set_mode_major(crtc, &crtc->mode, crtc->rotation,
 						    crtc->x, crtc->y);
 		else
diff --git a/src/amdgpu_video.c b/src/amdgpu_video.c
index 3f441e79a..8f9a2b977 100644
--- a/src/amdgpu_video.c
+++ b/src/amdgpu_video.c
@@ -67,7 +67,7 @@ static int amdgpu_box_area(BoxPtr box)
 Bool amdgpu_crtc_is_enabled(xf86CrtcPtr crtc)
 {
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	return drmmode_crtc->pending_dpms_mode == DPMSModeOn;
+	return drmmode_crtc->dpms_mode == DPMSModeOn;
 }
 
 xf86CrtcPtr
diff --git a/src/drmmode_display.c b/src/drmmode_display.c
index bdd3866b8..0d5aa26d2 100644
--- a/src/drmmode_display.c
+++ b/src/drmmode_display.c
@@ -284,14 +284,11 @@ drmmode_do_crtc_dpms(xf86CrtcPtr crtc, int mode)
 	CARD64 ust;
 	int ret;
 
-	drmmode_crtc->pending_dpms_mode = mode;
-
 	if (drmmode_crtc->dpms_mode == DPMSModeOn && mode != DPMSModeOn) {
 		uint32_t seq;
 
-		/* Wait for any pending flip to finish */
-		if (drmmode_crtc->flip_pending)
-			return;
+		drmmode_crtc_wait_pending_event(drmmode_crtc, pAMDGPUEnt->fd,
+						drmmode_crtc->flip_pending);
 
 		/*
 		 * On->Off transition: record the last vblank time,
@@ -345,10 +342,8 @@ drmmode_crtc_dpms(xf86CrtcPtr crtc, int mode)
 
 	/* Disable unused CRTCs and enable/disable active CRTCs */
 	if (!crtc->enabled || mode != DPMSModeOn) {
-		/* Wait for any pending flip to finish */
-		if (drmmode_crtc->flip_pending)
-			return;
-
+		drmmode_crtc_wait_pending_event(drmmode_crtc, pAMDGPUEnt->fd,
+						drmmode_crtc->flip_pending);
 		drmModeSetCrtc(pAMDGPUEnt->fd, drmmode_crtc->mode_crtc->crtc_id,
 			       0, 0, 0, NULL, 0, NULL);
 		drmmode_fb_reference(pAMDGPUEnt->fd, &drmmode_crtc->fb, NULL);
@@ -1369,7 +1364,6 @@ drmmode_crtc_init(ScrnInfoPtr pScrn, drmmode_ptr drmmode, drmModeResPtr mode_res
 	    drmModeGetCrtc(pAMDGPUEnt->fd, mode_res->crtcs[num]);
 	drmmode_crtc->drmmode = drmmode;
 	drmmode_crtc->dpms_mode = DPMSModeOff;
-	drmmode_crtc->pending_dpms_mode = DPMSModeOff;
 	crtc->driver_private = drmmode_crtc;
 	drmmode_crtc_hw_id(crtc);
 
@@ -1497,16 +1491,9 @@ static void drmmode_output_dpms(xf86OutputPtr output, int mode)
 	if (!koutput)
 		return;
 
-	if (mode != DPMSModeOn && crtc) {
-		drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-
+	if (mode != DPMSModeOn && crtc)
 		drmmode_do_crtc_dpms(crtc, mode);
 
-		/* Wait for any pending flip to finish */
-		if (drmmode_crtc->flip_pending)
-			return;
-	}
-
 	drmModeConnectorSetProperty(pAMDGPUEnt->fd, koutput->connector_id,
 				    drmmode_output->dpms_enum_id, mode);
 
@@ -2229,38 +2216,11 @@ static const xf86CrtcConfigFuncsRec drmmode_xf86crtc_config_funcs = {
 	drmmode_xf86crtc_resize
 };
 
-void
-drmmode_clear_pending_flip(xf86CrtcPtr crtc)
-{
-	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	ScrnInfoPtr scrn = crtc->scrn;
-	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(scrn);
-
-	drmmode_fb_reference(pAMDGPUEnt->fd, &drmmode_crtc->flip_pending,
-			     NULL);
-
-	if (!crtc->enabled ||
-	    (drmmode_crtc->pending_dpms_mode != DPMSModeOn &&
-	     drmmode_crtc->dpms_mode != drmmode_crtc->pending_dpms_mode)) {
-		xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(crtc->scrn);
-		int o;
-
-		for (o = 0; o < xf86_config->num_output; o++) {
-			xf86OutputPtr output = xf86_config->output[o];
-
-			if (output->crtc != crtc)
-				continue;
-
-			drmmode_output_dpms(output, drmmode_crtc->pending_dpms_mode);
-		}
-
-		drmmode_crtc_dpms(crtc, drmmode_crtc->pending_dpms_mode);
-	}
-}
-
 static void
 drmmode_flip_abort(xf86CrtcPtr crtc, void *event_data)
 {
+	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
+	AMDGPUEntPtr pAMDGPUEnt = AMDGPUEntPriv(crtc->scrn);
 	drmmode_flipdata_ptr flipdata = event_data;
 
 	if (--flipdata->flip_count == 0) {
@@ -2270,7 +2230,8 @@ drmmode_flip_abort(xf86CrtcPtr crtc, void *event_data)
 		free(flipdata);
 	}
 
-	drmmode_clear_pending_flip(crtc);
+	drmmode_fb_reference(pAMDGPUEnt->fd, &drmmode_crtc->flip_pending,
+			     NULL);
 }
 
 static void
@@ -2302,7 +2263,8 @@ drmmode_flip_handler(xf86CrtcPtr crtc, uint32_t frame, uint64_t usec, void *even
 
 	drmmode_fb_reference(pAMDGPUEnt->fd, &drmmode_crtc->fb,
 			     drmmode_crtc->flip_pending);
-	drmmode_clear_pending_flip(crtc);
+	drmmode_fb_reference(pAMDGPUEnt->fd, &drmmode_crtc->flip_pending,
+			     NULL);
 }
 
 #if HAVE_NOTIFY_FD
diff --git a/src/drmmode_display.h b/src/drmmode_display.h
index ba7ec68e1..38bf14494 100644
--- a/src/drmmode_display.h
+++ b/src/drmmode_display.h
@@ -88,8 +88,6 @@ typedef struct {
 	PixmapPtr prime_scanout_pixmap;
 
 	int dpms_mode;
-	/* For when a flip is pending when DPMS off requested */
-	int pending_dpms_mode;
 	CARD64 dpms_last_ust;
 	uint32_t dpms_last_seq;
 	int dpms_last_fps;
@@ -138,7 +136,7 @@ drmmode_crtc_can_flip(xf86CrtcPtr crtc)
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
 
 	return crtc->enabled &&
-		drmmode_crtc->pending_dpms_mode == DPMSModeOn &&
+		drmmode_crtc->dpms_mode == DPMSModeOn &&
 		!drmmode_crtc->rotate.bo &&
 		!drmmode_crtc->scanout[drmmode_crtc->scanout_id].bo;
 }
@@ -206,7 +204,6 @@ extern void drmmode_uevent_fini(ScrnInfoPtr scrn, drmmode_ptr drmmode);
 
 extern int drmmode_get_crtc_id(xf86CrtcPtr crtc);
 extern int drmmode_get_pitch_align(ScrnInfoPtr scrn, int bpe);
-extern void drmmode_clear_pending_flip(xf86CrtcPtr crtc);
 Bool amdgpu_do_pageflip(ScrnInfoPtr scrn, ClientPtr client,
 			PixmapPtr new_front, uint64_t id, void *data,
 			xf86CrtcPtr ref_crtc, amdgpu_drm_handler_proc handler,
-- 
2.14.1



More information about the amd-gfx mailing list