Skip to contentSkip to conversation

amd/display: improve atomic cursor checks

PATCH In review Simon Ser 2 participants 15 messages Mar 10, 2021 – Aug 17, 2023

Subsystems (3)
lore
Share & tools
lore

Simon Ser

author
#0 lore raw

v2 cover amd/display: improve atomic cursor checks

Changes in v2: drop "amd/display: fail on cursor plane without an underlying plane". This retains the current behavior instead.

Simon Ser (5):
amd/display: convert DRM_DEBUG_ATOMIC to drm_dbg_atomic amd/display: check cursor plane matches underlying plane amd/display: add cursor check for YUV underlying pipe amd/display: add cursor alpha and blend mode checks amd/display: re-introduce cursor plane rotation prop

 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 57 ++++++++++++++-----
 1 file changed, 42 insertions(+), 15 deletions(-)
Signature · 6 lines
2.30.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#1 lore raw

PATCH v2 1/5 amd/display: convert DRM_DEBUG_ATOMIC to drm_dbg_atomic

This allows to tie the log message to a specific DRM device.

Cc Alex Deucher <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Nicholas Kazlauskas <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -1
index 2506e85a19b6..f736c1fa1fb4 100644
@@ -9484,7 +9484,7 @@ static int dm_check_crtc_cursor(struct drm_atomic_state *state,
 
 	if (cursor_scale_w != primary_scale_w ||
 	    cursor_scale_h != primary_scale_h) {
-		DRM_DEBUG_ATOMIC("Cursor plane scaling doesn't match primary plane\n");
+		drm_dbg_atomic(crtc->dev, "Cursor plane scaling doesn't match primary plane\n");
 		return -EINVAL;
 	}
 
Signature · 6 lines
2.30.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#2 lore raw

PATCH v2 2/5 amd/display: check cursor plane matches underlying plane

In reply to Simon Ser

The current logic checks whether the cursor plane blending properties match the primary plane's. However that's wrong, because the cursor uses the topmost pipe.

Instead, grab the topmost enabled plane, and check that the cursor plane blending properties matches it.

Fixes 12f4849a1cfd ("drm/amd/display: check cursor scaling")
Cc Alex Deucher <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Nicholas Kazlauskas <[email protected]>
---
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 32 +++++++++++--------
 1 file changed, 19 insertions(+), 13 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +19 -13
index f736c1fa1fb4..b54ed708e114 100644
@@ -9458,33 +9458,39 @@ static int dm_check_crtc_cursor(struct drm_atomic_state *state,
 				struct drm_crtc *crtc,
 				struct drm_crtc_state *new_crtc_state)
 {
-	struct drm_plane_state *new_cursor_state, *new_primary_state;
-	int cursor_scale_w, cursor_scale_h, primary_scale_w, primary_scale_h;
+	int i;
+	struct drm_plane *plane;
+	struct drm_plane_state *new_cursor_state, *new_underlying_state, *new_plane_state;
+	int cursor_scale_w, cursor_scale_h, underlying_scale_w, underlying_scale_h;
 
 	/* On DCE and DCN there is no dedicated hardware cursor plane. We get a
 	 * cursor per pipe but it's going to inherit the scaling and
 	 * positioning from the underlying pipe. Check the cursor plane's
-	 * blending properties match the primary plane's. */
+	 * blending properties match the underlying plane's. */
+
+	new_underlying_state = NULL;
+	for_each_new_plane_in_state(state, plane, new_plane_state, i) {
+		if (new_plane_state->crtc == crtc && plane != crtc->cursor)
+			new_underlying_state = new_plane_state;
+	}
 
 	new_cursor_state = drm_atomic_get_new_plane_state(state, crtc->cursor);
-	new_primary_state = drm_atomic_get_new_plane_state(state, crtc->primary);
-	if (!new_cursor_state || !new_primary_state || !new_cursor_state->fb) {
+	if (!new_cursor_state || !new_underlying_state || !new_cursor_state->fb)
 		return 0;
-	}
 
 	cursor_scale_w = new_cursor_state->crtc_w * 1000 /
 			 (new_cursor_state->src_w >> 16);
 	cursor_scale_h = new_cursor_state->crtc_h * 1000 /
 			 (new_cursor_state->src_h >> 16);
 
-	primary_scale_w = new_primary_state->crtc_w * 1000 /
-			 (new_primary_state->src_w >> 16);
-	primary_scale_h = new_primary_state->crtc_h * 1000 /
-			 (new_primary_state->src_h >> 16);
+	underlying_scale_w = new_underlying_state->crtc_w * 1000 /
+			 (new_underlying_state->src_w >> 16);
+	underlying_scale_h = new_underlying_state->crtc_h * 1000 /
+			 (new_underlying_state->src_h >> 16);
 
-	if (cursor_scale_w != primary_scale_w ||
-	    cursor_scale_h != primary_scale_h) {
-		drm_dbg_atomic(crtc->dev, "Cursor plane scaling doesn't match primary plane\n");
+	if (cursor_scale_w != underlying_scale_w ||
+	    cursor_scale_h != underlying_scale_h) {
+		drm_dbg_atomic(crtc->dev, "Cursor plane scaling doesn't match underlying plane\n");
 		return -EINVAL;
 	}
 
Signature · 6 lines
2.30.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#3 lore raw

PATCH v2 3/5 amd/display: add cursor check for YUV underlying pipe

In reply to Simon Ser

The cursor plane can't be displayed if the underlying pipe isn't using an RGB format. Reject such atomic commits so that user-space can have a fallback instead of an invisible cursor.

In theory we could support YUV if the cursor is also YUV, but at the moment only ARGB8888 cursors are supported.

Cc Alex Deucher <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Nicholas Kazlauskas <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7 -0
index b54ed708e114..98df550c3979 100644
@@ -9494,6 +9494,13 @@ static int dm_check_crtc_cursor(struct drm_atomic_state *state,
 		return -EINVAL;
 	}
 
+	/* In theory we could probably support YUV cursors when the underlying
+	 * plane uses a YUV format, but there's no use-case for it yet. */
+	if (new_underlying_state->fb->format->is_yuv) {
+		drm_dbg_atomic(crtc->dev, "Cursor plane can't be used with YUV underlying plane\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
Signature · 6 lines
2.30.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#4 lore raw

PATCH v2 4/5 amd/display: add cursor alpha and blend mode checks

In reply to Simon Ser

We don't want a semi-transparent overlay to make the cursor plane semi-transparent as well. Same for the pixel blend mode.

Cc Alex Deucher <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Nicholas Kazlauskas <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10 -0
index 98df550c3979..b4f6e2985b8a 100644
@@ -9501,6 +9501,16 @@ static int dm_check_crtc_cursor(struct drm_atomic_state *state,
 		return -EINVAL;
 	}
 
+	if (new_underlying_state->alpha != DRM_BLEND_ALPHA_OPAQUE) {
+		drm_dbg_atomic(crtc->dev, "Cursor plane can't be used with non-opaque underlying plane\n");
+		return -EINVAL;
+	}
+
+	if (new_underlying_state->pixel_blend_mode != DRM_MODE_BLEND_PREMULTI) {
+		drm_dbg_atomic(crtc->dev, "Cursor plane can't be used with non-premultiplied underlying plane\n");
+		return -EINVAL;
+	}
+
 	return 0;
 }
 
Signature · 6 lines
2.30.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#5 lore raw

PATCH v2 5/5 amd/display: re-introduce cursor plane rotation prop

In reply to Simon Ser

The commit 1347385fe187 ("drm/amd/display: don't expose rotation prop for cursor plane") removed the rotation property for the cursor plane, assuming the cursor would always be displayed without any rotation. However the rotation is inherited from the underlying plane.

As a result, if the primary plane is rotated, then the cursor plane will incorrectly be rotated as well even though it doesn't have a rotation property.

To fix this, re-introduce the cursor rotation property, and check that its value matches the underlying plane's.

Cc Alex Deucher <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Nicholas Kazlauskas <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -2
index b4f6e2985b8a..36ee52104007 100644
@@ -6897,8 +6897,7 @@ static int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
 		DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
 		DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
 
-	if (dm->adev->asic_type >= CHIP_BONAIRE &&
-	    plane->type != DRM_PLANE_TYPE_CURSOR)
+	if (dm->adev->asic_type >= CHIP_BONAIRE)
 		drm_plane_create_rotation_property(plane, DRM_MODE_ROTATE_0,
 						   supported_rotations);
 
@@ -9494,6 +9493,11 @@ static int dm_check_crtc_cursor(struct drm_atomic_state *state,
 		return -EINVAL;
 	}
 
+	if (new_underlying_state->rotation != new_cursor_state->rotation) {
+		drm_dbg_atomic(crtc->dev, "Cursor plane rotation doesn't match underlying plane\n");
+		return -EINVAL;
+	}
+
 	/* In theory we could probably support YUV cursors when the underlying
 	 * plane uses a YUV format, but there's no use-case for it yet. */
 	if (new_underlying_state->fb->format->is_yuv) {
Signature · 6 lines
2.30.2

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
#6 lore raw

Re: [PATCH v2,5/5] amd/display: re-introduce cursor plane rotation prop

Why is this patch marked as rejected in patchwork? Something like this seems required for a Wayland compositor to use the HW cursor with rotated primary/overlay planes.

Quoted 47 lines · Simon Ser

The commit 1347385fe187 ("drm/amd/display: don't expose rotation prop for cursor plane") removed the rotation property for the cursor plane, assuming the cursor would always be displayed without any rotation. However the rotation is inherited from the underlying plane.

As a result, if the primary plane is rotated, then the cursor plane will incorrectly be rotated as well even though it doesn't have a rotation property.

To fix this, re-introduce the cursor rotation property, and check that its value matches the underlying plane's.

Cc Alex Deucher <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Nicholas Kazlauskas <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -2
index b4f6e2985b8a..36ee52104007 100644
@@ -6897,8 +6897,7 @@ static int amdgpu_dm_plane_init(struct amdgpu_display_manager *dm,
 		DRM_MODE_ROTATE_0 | DRM_MODE_ROTATE_90 |
 		DRM_MODE_ROTATE_180 | DRM_MODE_ROTATE_270;
 
-	if (dm->adev->asic_type >= CHIP_BONAIRE &&
-	    plane->type != DRM_PLANE_TYPE_CURSOR)
+	if (dm->adev->asic_type >= CHIP_BONAIRE)
 		drm_plane_create_rotation_property(plane, DRM_MODE_ROTATE_0,
 						   supported_rotations);
 
@@ -9494,6 +9493,11 @@ static int dm_check_crtc_cursor(struct drm_atomic_state *state,
 		return -EINVAL;
 	}
 
+	if (new_underlying_state->rotation != new_cursor_state->rotation) {
+		drm_dbg_atomic(crtc->dev, "Cursor plane rotation doesn't match underlying plane\n");
+		return -EINVAL;
+	}
+
 	/* In theory we could probably support YUV cursors when the underlying
 	 * plane uses a YUV format, but there's no use-case for it yet. */
 	if (new_underlying_state->fb->format->is_yuv) {
Signature · 2 lines
Earthling Michel Dänzer            |                  https://redhat.com
Libre software enthusiast          |         Mesa and Xwayland developer
#7 lore raw
In reply to Simon Ser
Quoted 2 lines · Simon Ser

Changes in v2: drop "amd/display: fail on cursor plane without an underlying plane". This retains the current behavior instead.

Patches 2 & 3 (and possibly 4? not sure) would still cause the same issue in the scenario discussed in follow-ups to the dropped patch (disabling an ARGB overlay plane with a YUV primary plane and the cursor plane enabled), wouldn't they?

Signature · 6 lines
Earthling Michel Dänzer               |               https://redhat.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#8 lore raw
Quoted 9 lines · Michel Dänzer
Quoted 2 lines · Simon Ser

Changes in v2: drop "amd/display: fail on cursor plane without an underlying plane". This retains the current behavior instead.

Patches 2 & 3 (and possibly 4? not sure) would still cause the same issue in the scenario discussed in follow-ups to the dropped patch (disabling an ARGB overlay plane with a YUV primary plane and the cursor plane enabled), wouldn't they?

Yes, but that shouldn't be too much of an issue in practice, since user-space using YUV and overlays also uses atomic. Dropping the patch avoids the issue to be triggered with legacy user-space.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#9 lore raw
Quoted 6 lines · Simon Ser
Quoted 5 lines · Michel Dänzer
Quoted 2 lines · Simon Ser

Changes in v2: drop "amd/display: fail on cursor plane without an underlying plane". This retains the current behavior instead.

Quoted 8 lines
Quoted 4 lines

Patches 2 & 3 (and possibly 4? not sure) would still cause the same issue in the scenario discussed in follow-ups to the dropped patch (disabling an ARGB overlay plane with a YUV primary plane and the cursor plane enabled), wouldn't they?

Yes, but that shouldn't be too much of an issue in practice, since user-space using YUV and overlays also uses atomic. Dropping the patch avoids the issue to be triggered with legacy user-space.

The last scenario discussed is about atomic KMS user space trying to disable the overlay plane. Daniel seems to agree that not being able to disable an overlay plane is too surprising.

Signature · 6 lines
Earthling Michel Dänzer               |               https://redhat.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#10 lore raw
Quoted 12 lines · Michel Dänzer
Quoted 11 lines · Simon Ser
Quoted 9 lines · Michel Dänzer
Quoted 2 lines · Simon Ser

Changes in v2: drop "amd/display: fail on cursor plane without an underlying plane". This retains the current behavior instead.

Patches 2 & 3 (and possibly 4? not sure) would still cause the same issue in the scenario discussed in follow-ups to the dropped patch (disabling an ARGB overlay plane with a YUV primary plane and the cursor plane enabled), wouldn't they?

Quoted 7 lines
Quoted 3 lines

Yes, but that shouldn't be too much of an issue in practice, since user-space using YUV and overlays also uses atomic. Dropping the patch avoids the issue to be triggered with legacy user-space.

The last scenario discussed is about atomic KMS user space trying to disable the overlay plane. Daniel seems to agree that not being able to disable an overlay plane is too surprising.

Well, amdgpu can already return a failure if user-space tries to disable the overlay:

- User-space sets up the primary plane with a scaled FB.
- User-space enables the overlay and cursor planes without scaling.
- User-space tries to disable the overlay, kernel returns a failure because a non-scaled cursor is incompatible with a scaled underlying plane.

So this series just adds a new error condition.

I'm not a fan of adding kernel hacks like setting up a transparent FB, when user-space can just avoid the failure with atomic test-only commits (and e.g. use the overlay to display the cursor image instead of the cursor plane).
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#11 lore raw
Quoted 25 lines · Simon Ser
Quoted 12 lines · Michel Dänzer
Quoted 11 lines · Simon Ser
Quoted 9 lines · Michel Dänzer
Quoted 2 lines · Simon Ser

Changes in v2: drop "amd/display: fail on cursor plane without an underlying plane". This retains the current behavior instead.

Patches 2 & 3 (and possibly 4? not sure) would still cause the same issue in the scenario discussed in follow-ups to the dropped patch (disabling an ARGB overlay plane with a YUV primary plane and the cursor plane enabled), wouldn't they?

Quoted 7 lines
Quoted 3 lines

Yes, but that shouldn't be too much of an issue in practice, since user-space using YUV and overlays also uses atomic. Dropping the patch avoids the issue to be triggered with legacy user-space.

The last scenario discussed is about atomic KMS user space trying to disable the overlay plane. Daniel seems to agree that not being able to disable an overlay plane is too surprising.

Well, amdgpu can already return a failure if user-space tries to disable the overlay:

Quoted 6 lines

- User-space sets up the primary plane with a scaled FB.
- User-space enables the overlay and cursor planes without scaling.
- User-space tries to disable the overlay, kernel returns a failure because a non-scaled cursor is incompatible with a scaled underlying plane.

So this series just adds a new error condition.

This is why I wrote "Houston, we have a problem". I only realized at that point that we've painted ourselves into an uncomfortable corner.

Quoted 3 lines

I'm not a fan of adding kernel hacks like setting up a transparent FB, when user-space can just avoid the failure with atomic test-only commits (and e.g. use the overlay to display the cursor image instead of the cursor plane).

I'm not a fan of requiring each atomic client to handle this complexity.

Signature · 6 lines
Earthling Michel Dänzer               |               https://redhat.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#12 lore raw
Quoted 5 lines · Michel Dänzer
Quoted 3 lines

I'm not a fan of adding kernel hacks like setting up a transparent FB, when user-space can just avoid the failure with atomic test-only commits (and e.g. use the overlay to display the cursor image instead of the cursor plane).

I'm not a fan of requiring each atomic client to handle this complexity.

That's just how atomic works though. User-space is expected to incrementally build the atomic request, bailing out if something doesn't work along the way. Doing it the old way (ie. issuing singular atomic commits, ie. using the atomic API just like the legacy API is used) won't work in many situations anyways.

Plus, a library such as libliftoff will just handle all of that complexity for you.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

#13 lore raw

[ Adding Daniel again ]

Quoted 10 lines · Simon Ser
Quoted 5 lines · Michel Dänzer
Quoted 3 lines

I'm not a fan of adding kernel hacks like setting up a transparent FB, when user-space can just avoid the failure with atomic test-only commits (and e.g. use the overlay to display the cursor image instead of the cursor plane).

I'm not a fan of requiring each atomic client to handle this complexity.

That's just how atomic works though. User-space is expected to incrementally build the atomic request, bailing out if something doesn't work along the way.

Being unable to disable a plane which is currently enabled is quite different from being unable to enable a plane which is currently disabled. How is user space supposed to react to that, other than maybe disabling everything and starting from scratch?

Quoted 2 lines

Doing it the old way (ie. issuing singular atomic commits, ie. using the atomic API just like the legacy API is used) won't work in many situations anyways.

This isn't about that, not sure why you keep bringing it up.

Signature · 6 lines
Earthling Michel Dänzer               |               https://redhat.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
author
#14 lore raw
Quoted 9 lines · Michel Dänzer
Quoted 8 lines · Simon Ser
Quoted 5 lines · Michel Dänzer
Quoted 3 lines

I'm not a fan of adding kernel hacks like setting up a transparent FB, when user-space can just avoid the failure with atomic test-only commits (and e.g. use the overlay to display the cursor image instead of the cursor plane).

I'm not a fan of requiring each atomic client to handle this complexity.

Quoted 7 lines
Quoted 2 lines

That's just how atomic works though. User-space is expected to incrementally build the atomic request, bailing out if something doesn't work along the way.

Being unable to disable a plane which is currently enabled is quite different from being unable to enable a plane which is currently disabled. How is user space supposed to react to that, other than maybe disabling everything and starting from scratch?

What I mean by "singular atomic commit" is an atomic commit that tries to change a single thing, and expects that to just work. Whether it's about disabling a plane or not doesn't matter much from my point of view. For instance, maybe scaling is enabled and user-space wants to disable scaling, but the driver can't? This would be surprising to user-space because "user-space is just trying to disable $feature", just like the the case we're talking about.

Quoted 4 lines
Quoted 2 lines

Doing it the old way (ie. issuing singular atomic commits, ie. using the atomic API just like the legacy API is used) won't work in many situations anyways.

This isn't about that, not sure why you keep bringing it up.

Well, a client that incrementally builds the full atomic commit (like Weston and libliftoff) won't have this issue.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx