xf86-video-amdgpu: Branch 'master' - 4 commits

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Wed Apr 20 14:34:20 UTC 2022


 src/amdgpu_dri2.c    |    3 
 src/amdgpu_drv.h     |    4 -
 src/amdgpu_present.c |   16 ----
 src/amdgpu_video.c   |  195 +++++++++++++++++++++++++++++++++++++--------------
 src/compat-api.h     |    3 
 5 files changed, 150 insertions(+), 71 deletions(-)

New commits:
commit f3f57a58342c286808220bdbe6dc6bb7098763b9
Author: Lukasz Spintzyk <lukasz.spintzyk at displaylink.com>
Date:   Fri Jun 11 14:54:35 2021 +0200

    Do not consider disabled crtc anymore when looking for xf86crtc covering drawable.
    
    This is commit is removing obsolete switch done in
    
    xf86-video-ati at sha 61d0aec40e2521488c2fe43e7a6823e5c87d94d7:  video: add option to include disabled CRTCs in best CRTC search
    This is not required anymore as with commit done in
    xorg-server at sha 5c5c1b77982a9af7279a90bc3c2be48adaa9c778:     present: Add Present extension
    That in case of lack of crtc is using fake_crtc with render 1Hz frequency
    
    When consider_disabled is removed then amdgpu_pick_best_crtc is doing the same what rr_crtc_covering_box is doing
    so it can be reimplemented to reuse that function.
    
    Signed-off-by: Łukasz Spintzyk <lukasz.spintzyk at synaptics.com>
    Signed-off-by: Shashank Sharma <contactshashanksharma at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/amdgpu_dri2.c b/src/amdgpu_dri2.c
index a77e4e3..bfc14f3 100644
--- a/src/amdgpu_dri2.c
+++ b/src/amdgpu_dri2.c
@@ -417,8 +417,7 @@ static
 xf86CrtcPtr amdgpu_dri2_drawable_crtc(DrawablePtr pDraw)
 {
 	ScreenPtr pScreen = pDraw->pScreen;
-	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
-	xf86CrtcPtr crtc = amdgpu_pick_best_crtc(pScrn, TRUE,
+	xf86CrtcPtr crtc = amdgpu_pick_best_crtc(pScreen,
 						 pDraw->x, pDraw->x + pDraw->width,
 						 pDraw->y, pDraw->y + pDraw->height);
 
diff --git a/src/amdgpu_drv.h b/src/amdgpu_drv.h
index 3f9e2e0..2952b7b 100644
--- a/src/amdgpu_drv.h
+++ b/src/amdgpu_drv.h
@@ -372,8 +372,7 @@ extern void amdgpu_sync_close(ScreenPtr screen);
 /* amdgpu_video.c */
 extern void AMDGPUInitVideo(ScreenPtr pScreen);
 extern void AMDGPUResetVideo(ScrnInfoPtr pScrn);
-extern xf86CrtcPtr amdgpu_pick_best_crtc(ScrnInfoPtr pScrn,
-					 Bool consider_disabled,
+extern xf86CrtcPtr amdgpu_pick_best_crtc(ScreenPtr pScreen,
 					 int x1, int x2, int y1, int y2);
 extern RRCrtcPtr amdgpu_randr_crtc_covering_drawable(DrawablePtr pDraw);
 
diff --git a/src/amdgpu_video.c b/src/amdgpu_video.c
index d00e9c4..9cf8ea1 100644
--- a/src/amdgpu_video.c
+++ b/src/amdgpu_video.c
@@ -50,19 +50,6 @@ static void amdgpu_box_intersect(BoxPtr dest, BoxPtr a, BoxPtr b)
 		dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0;
 }
 
-static void amdgpu_crtc_box(xf86CrtcPtr crtc, BoxPtr crtc_box)
-{
-	if (crtc->enabled) {
-		crtc_box->x1 = crtc->x;
-		crtc_box->x2 =
-		    crtc->x + xf86ModeWidth(&crtc->mode, crtc->rotation);
-		crtc_box->y1 = crtc->y;
-		crtc_box->y2 =
-		    crtc->y + xf86ModeHeight(&crtc->mode, crtc->rotation);
-	} else
-		crtc_box->x1 = crtc_box->x2 = crtc_box->y1 = crtc_box->y2 = 0;
-}
-
 static int amdgpu_box_area(BoxPtr box)
 {
 	return (int)(box->x2 - box->x1) * (int)(box->y2 - box->y1);
@@ -76,60 +63,6 @@ amdgpu_crtc_is_enabled(xf86CrtcPtr crtc)
 	return crtc->enabled && drmmode_crtc->dpms_mode == DPMSModeOn;
 }
 
-xf86CrtcPtr
-amdgpu_pick_best_crtc(ScrnInfoPtr pScrn, Bool consider_disabled,
-		      int x1, int x2, int y1, int y2)
-{
-	xf86CrtcConfigPtr xf86_config = XF86_CRTC_CONFIG_PTR(pScrn);
-	int coverage, best_coverage, c, cd;
-	BoxRec box, crtc_box, cover_box;
-	RROutputPtr primary_output = NULL;
-	xf86CrtcPtr best_crtc = NULL, primary_crtc = NULL;
-
-	if (!pScrn->vtSema)
-		return NULL;
-
-	box.x1 = x1;
-	box.x2 = x2;
-	box.y1 = y1;
-	box.y2 = y2;
-	best_coverage = 0;
-
-	/* Prefer the CRTC of the primary output */
-	if (dixPrivateKeyRegistered(rrPrivKey))
-	{
-		primary_output = RRFirstOutput(pScrn->pScreen);
-	}
-	if (primary_output && primary_output->crtc)
-		primary_crtc = primary_output->crtc->devPrivate;
-
-	/* first consider only enabled CRTCs
-	 * then on second pass consider disabled ones
-	 */
-	for (cd = 0; cd < (consider_disabled ? 2 : 1); cd++) {
-		for (c = 0; c < xf86_config->num_crtc; c++) {
-			xf86CrtcPtr crtc = xf86_config->crtc[c];
-
-			if (!cd && !xf86_crtc_on(crtc))
-				continue;
-
-			amdgpu_crtc_box(crtc, &crtc_box);
-			box_intersect(&cover_box, &crtc_box, &box);
-			coverage = box_area(&cover_box);
-			if (coverage > best_coverage ||
-			    (coverage == best_coverage &&
-			     crtc == primary_crtc)) {
-				best_crtc = crtc;
-				best_coverage = coverage;
-			}
-		}
-		if (best_crtc)
-			break;
-	}
-
-	return best_crtc;
-}
-
 static void amdgpu_crtc_box(RRCrtcPtr crtc, BoxPtr crtc_box)
 {
 	if (crtc->mode) {
@@ -258,6 +191,30 @@ amdgpu_randr_crtc_covering_drawable(DrawablePtr pDraw)
 	return crtc;
 }
 
+xf86CrtcPtr
+amdgpu_pick_best_crtc(ScreenPtr pScreen,
+		      int x1, int x2, int y1, int y2)
+{
+	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
+
+	if (!pScrn->vtSema)
+		return NULL;
+
+	RRCrtcPtr crtc = NULL;
+	BoxRec box;
+
+	box.x1 = x1;
+	box.x2 = x2;
+	box.y1 = y1;
+	box.y2 = y2;
+
+	crtc = amdgpu_crtc_covering_box(pScreen, &box, TRUE);
+	if (crtc) {
+		return crtc->devPrivate;
+	}
+	return NULL;
+}
+
 void AMDGPUInitVideo(ScreenPtr pScreen)
 {
 	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
commit e39a3ee07c9dea73b0452b71b1ef633b6cd6f389
Author: Lukasz Spintzyk <lukasz.spintzyk at displaylink.com>
Date:   Mon Jun 21 11:41:40 2021 +0200

    Prefer crtc of primary output for synchronization when screen has to crtcs with the same coverage
    
    This is adjusting randr_crtc_covering_drawable to cover scenario fixed in
    9151f3b1c2ebcc34e63195888ba696f2183ba5e2
    
    Signed-off-by: Łukasz Spintzyk <lukasz.spintzyk at synaptics.com>
    Signed-off-by: Shashank Sharma <contactshashanksharma at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/amdgpu_video.c b/src/amdgpu_video.c
index b4e3fa4..d00e9c4 100644
--- a/src/amdgpu_video.c
+++ b/src/amdgpu_video.c
@@ -172,13 +172,16 @@ static RRCrtcPtr
 amdgpu_crtc_covering_box(ScreenPtr pScreen, BoxPtr box, Bool screen_is_xf86_hint)
 {
 	rrScrPrivPtr pScrPriv;
-	RRCrtcPtr crtc, best_crtc;
+	RRCrtcPtr crtc, best_crtc, primary_crtc;
 	int coverage, best_coverage;
 	int c;
 	BoxRec crtc_box, cover_box;
+	RROutputPtr primary_output;
 
 	best_crtc = NULL;
 	best_coverage = 0;
+	primary_crtc = NULL;
+	primary_output = NULL;
 
 	if (!dixPrivateKeyRegistered(rrPrivKey))
 		return NULL;
@@ -188,6 +191,10 @@ amdgpu_crtc_covering_box(ScreenPtr pScreen, BoxPtr box, Bool screen_is_xf86_hint
 	if (!pScrPriv)
 		return NULL;
 
+	primary_output = RRFirstOutput(pScreen);
+	if (primary_output && primary_output->crtc)
+		primary_crtc = primary_output->crtc->devPrivate;
+
 	for (c = 0; c < pScrPriv->numCrtcs; c++) {
 		crtc = pScrPriv->crtcs[c];
 
@@ -198,7 +205,8 @@ amdgpu_crtc_covering_box(ScreenPtr pScreen, BoxPtr box, Bool screen_is_xf86_hint
 		amdgpu_crtc_box(crtc, &crtc_box);
 		amdgpu_box_intersect(&cover_box, &crtc_box, box);
 		coverage = amdgpu_box_area(&cover_box);
-		if (coverage > best_coverage) {
+		if (coverage > best_coverage ||
+		   (crtc == primary_crtc && coverage == best_coverage)) {
 			best_crtc = crtc;
 			best_coverage = coverage;
 		}
commit 92fb43b8e96bbda77e03b7313ccbba75a304a1b1
Author: Lukasz Spintzyk <lukasz.spintzyk at displaylink.com>
Date:   Fri Jun 11 08:52:58 2021 +0200

    Use randr_crtc_covering_drawable used in modesetting
    
    Use implementation from modesetting driver that is fixing issue:
    https://gitlab.freedesktop.org/xorg/xserver/-/issues/1028
    
    Instead of returning primary crtc as fallback we can now find and return crtc that belongs to secondary outputs.
    
    v2:
      restore original naming scheme for amdgpu_crtc_is_enabled, amdgpu_box_intersect, amdgpu_box_area functions
    
    Signed-off-by: Łukasz Spintzyk <lukasz.spintzyk at synaptics.com>
    Signed-off-by: Emilia Majewska <emilia.majewska at synaptics.com>
    Signed-off-by: Shashank Sharma <contactshashanksharma at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/amdgpu_drv.h b/src/amdgpu_drv.h
index 200f0ba..3f9e2e0 100644
--- a/src/amdgpu_drv.h
+++ b/src/amdgpu_drv.h
@@ -375,6 +375,7 @@ extern void AMDGPUResetVideo(ScrnInfoPtr pScrn);
 extern xf86CrtcPtr amdgpu_pick_best_crtc(ScrnInfoPtr pScrn,
 					 Bool consider_disabled,
 					 int x1, int x2, int y1, int y2);
+extern RRCrtcPtr amdgpu_randr_crtc_covering_drawable(DrawablePtr pDraw);
 
 extern AMDGPUEntPtr AMDGPUEntPriv(ScrnInfoPtr pScrn);
 
diff --git a/src/amdgpu_present.c b/src/amdgpu_present.c
index f768dd2..ca905d1 100644
--- a/src/amdgpu_present.c
+++ b/src/amdgpu_present.c
@@ -58,21 +58,7 @@ struct amdgpu_present_vblank_event {
 static RRCrtcPtr
 amdgpu_present_get_crtc(WindowPtr window)
 {
-	ScreenPtr screen = window->drawable.pScreen;
-	ScrnInfoPtr pScrn = xf86ScreenToScrn(screen);
-	xf86CrtcPtr crtc;
-	RRCrtcPtr randr_crtc = NULL;
-
-	crtc = amdgpu_pick_best_crtc(pScrn, FALSE,
-				     window->drawable.x,
-				     window->drawable.x + window->drawable.width,
-				     window->drawable.y,
-				     window->drawable.y + window->drawable.height);
-
-	if (crtc)
-		randr_crtc = crtc->randr_crtc;
-
-	return randr_crtc;
+	return amdgpu_randr_crtc_covering_drawable(&window->drawable);
 }
 
 static int
diff --git a/src/amdgpu_video.c b/src/amdgpu_video.c
index 94ae170..b4e3fa4 100644
--- a/src/amdgpu_video.c
+++ b/src/amdgpu_video.c
@@ -39,10 +39,14 @@ static void amdgpu_box_intersect(BoxPtr dest, BoxPtr a, BoxPtr b)
 {
 	dest->x1 = a->x1 > b->x1 ? a->x1 : b->x1;
 	dest->x2 = a->x2 < b->x2 ? a->x2 : b->x2;
+	if (dest->x1 >= dest->x2) {
+		dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0;
+		return;
+	}
+
 	dest->y1 = a->y1 > b->y1 ? a->y1 : b->y1;
 	dest->y2 = a->y2 < b->y2 ? a->y2 : b->y2;
-
-	if (dest->x1 >= dest->x2 || dest->y1 >= dest->y2)
+	if (dest->y1 >= dest->y2)
 		dest->x1 = dest->x2 = dest->y1 = dest->y2 = 0;
 }
 
@@ -64,10 +68,12 @@ static int amdgpu_box_area(BoxPtr box)
 	return (int)(box->x2 - box->x1) * (int)(box->y2 - box->y1);
 }
 
-Bool amdgpu_crtc_is_enabled(xf86CrtcPtr crtc)
+Bool
+amdgpu_crtc_is_enabled(xf86CrtcPtr crtc)
 {
 	drmmode_crtc_private_ptr drmmode_crtc = crtc->driver_private;
-	return drmmode_crtc->dpms_mode == DPMSModeOn;
+
+	return crtc->enabled && drmmode_crtc->dpms_mode == DPMSModeOn;
 }
 
 xf86CrtcPtr
@@ -104,12 +110,12 @@ amdgpu_pick_best_crtc(ScrnInfoPtr pScrn, Bool consider_disabled,
 		for (c = 0; c < xf86_config->num_crtc; c++) {
 			xf86CrtcPtr crtc = xf86_config->crtc[c];
 
-			if (!cd && !amdgpu_crtc_is_enabled(crtc))
+			if (!cd && !xf86_crtc_on(crtc))
 				continue;
 
 			amdgpu_crtc_box(crtc, &crtc_box);
-			amdgpu_box_intersect(&cover_box, &crtc_box, &box);
-			coverage = amdgpu_box_area(&cover_box);
+			box_intersect(&cover_box, &crtc_box, &box);
+			coverage = box_area(&cover_box);
 			if (coverage > best_coverage ||
 			    (coverage == best_coverage &&
 			     crtc == primary_crtc)) {
@@ -124,6 +130,126 @@ amdgpu_pick_best_crtc(ScrnInfoPtr pScrn, Bool consider_disabled,
 	return best_crtc;
 }
 
+static void amdgpu_crtc_box(RRCrtcPtr crtc, BoxPtr crtc_box)
+{
+	if (crtc->mode) {
+		crtc_box->x1 = crtc->x;
+		crtc_box->y1 = crtc->y;
+		switch (crtc->rotation) {
+		case RR_Rotate_0:
+		case RR_Rotate_180:
+		default:
+			crtc_box->x2 = crtc->x + crtc->mode->mode.width;
+			crtc_box->y2 = crtc->y + crtc->mode->mode.height;
+			break;
+		case RR_Rotate_90:
+		case RR_Rotate_270:
+			crtc_box->x2 = crtc->x + crtc->mode->mode.height;
+			crtc_box->y2 = crtc->y + crtc->mode->mode.width;
+			break;
+		}
+	} else
+		crtc_box->x1 = crtc_box->x2 = crtc_box->y1 = crtc_box->y2 = 0;
+}
+
+static Bool amdgpu_crtc_on(RRCrtcPtr crtc, Bool crtc_is_xf86_hint)
+{
+	if (!crtc) {
+		return FALSE;
+	}
+	if (crtc_is_xf86_hint && crtc->devPrivate) {
+		return amdgpu_crtc_is_enabled(crtc->devPrivate);
+	} else {
+		return !!crtc->mode;
+	}
+}
+
+/*
+ * Return the crtc covering 'box'. If two crtcs cover a portion of
+ * 'box', then prefer the crtc with greater coverage.
+ */
+static RRCrtcPtr
+amdgpu_crtc_covering_box(ScreenPtr pScreen, BoxPtr box, Bool screen_is_xf86_hint)
+{
+	rrScrPrivPtr pScrPriv;
+	RRCrtcPtr crtc, best_crtc;
+	int coverage, best_coverage;
+	int c;
+	BoxRec crtc_box, cover_box;
+
+	best_crtc = NULL;
+	best_coverage = 0;
+
+	if (!dixPrivateKeyRegistered(rrPrivKey))
+		return NULL;
+
+	pScrPriv = rrGetScrPriv(pScreen);
+
+	if (!pScrPriv)
+		return NULL;
+
+	for (c = 0; c < pScrPriv->numCrtcs; c++) {
+		crtc = pScrPriv->crtcs[c];
+
+		/* If the CRTC is off, treat it as not covering */
+		if (!amdgpu_crtc_on(crtc, screen_is_xf86_hint))
+			continue;
+
+		amdgpu_crtc_box(crtc, &crtc_box);
+		amdgpu_box_intersect(&cover_box, &crtc_box, box);
+		coverage = amdgpu_box_area(&cover_box);
+		if (coverage > best_coverage) {
+			best_crtc = crtc;
+			best_coverage = coverage;
+		}
+	}
+
+	return best_crtc;
+}
+
+#if ABI_VIDEODRV_VERSION >= SET_ABI_VERSION(23, 0)
+static RRCrtcPtr
+amdgpu_crtc_covering_box_on_secondary(ScreenPtr pScreen, BoxPtr box)
+{
+	if (!pScreen->isGPU) {
+		ScreenPtr secondary;
+		RRCrtcPtr crtc = NULL;
+
+		xorg_list_for_each_entry(secondary, &pScreen->secondary_list, secondary_head) {
+			if (!secondary->is_output_secondary)
+				continue;
+
+			crtc = amdgpu_crtc_covering_box(secondary, box, FALSE);
+			if (crtc)
+				return crtc;
+		}
+	}
+
+	return NULL;
+}
+#endif
+
+RRCrtcPtr
+amdgpu_randr_crtc_covering_drawable(DrawablePtr pDraw)
+{
+	ScreenPtr pScreen = pDraw->pScreen;
+	RRCrtcPtr crtc = NULL;
+	BoxRec box;
+
+	box.x1 = pDraw->x;
+	box.y1 = pDraw->y;
+	box.x2 = box.x1 + pDraw->width;
+	box.y2 = box.y1 + pDraw->height;
+
+	crtc = amdgpu_crtc_covering_box(pScreen, &box, TRUE);
+#if ABI_VIDEODRV_VERSION >= SET_ABI_VERSION(23, 0)
+	if (!crtc) {
+		crtc = amdgpu_crtc_covering_box_on_secondary(pScreen, &box);
+	}
+#endif
+	return crtc;
+}
+
 void AMDGPUInitVideo(ScreenPtr pScreen)
 {
 	ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
commit 57740ae2357ca7b973f78be31327365aaa60ed41
Author: Łukasz Spintzyk <lukasz.spintzyk at synaptics.com>
Date:   Tue Jun 22 07:36:42 2021 +0200

    amdgpu: fixup driver for new X server ABI
    
    Signed-off-by: Łukasz Spintzyk <lukasz.spintzyk at synaptics.com>
    Signed-off-by: Shashank Sharma <contactshashanksharma at gmail.com>
    Reviewed-by: Alex Deucher <alexander.deucher at amd.com>

diff --git a/src/compat-api.h b/src/compat-api.h
index aca3b07..d60050d 100644
--- a/src/compat-api.h
+++ b/src/compat-api.h
@@ -42,6 +42,9 @@
 #define current_primary current_master
 #define primary_pixmap master_pixmap
 #define secondary_dst slave_dst
+#define secondary_list slave_list
+#define secondary_head slave_head
+#define is_output_secondary is_output_slave
 #endif
 
 #endif


More information about the xorg-commit mailing list