Skip to contentSkip to conversation

drm/gud: Merge damage clips in full update mode

PATCH Superseded Sophie D 4 participants 7 messages Sep 7 – Sep 12

Subsystems (4)
lore
Share & tools
lore

Sophie D

author
#0 lore raw

PATCH 1/1 drm/gud: Merge damage clips in full update mode

When running in full update mode, previously small updates (such as moving the mouse across the screen) would cause many full frames to be generated. This would bog down the bus and lower the effective framerate significantly - I was seeing a drop from 60 FPS to 2 FPS.

This patch fixes the bug by merging damage clips together.

Fixes 73cfd166e045 ("drm/gud: Replace simple display pipe with DRM atomic helpers")
Cc <[email protected]> # 6.18.x
---
 drivers/gpu/drm/gud/gud_pipe.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/gud/gud_pipe.c +8 -3
index 5ef887d84..20418bf81 100644
@@ -647,9 +647,14 @@ void gud_plane_atomic_update(struct drm_plane *plane,
 	if (ret)
 		goto out;
 
-	drm_atomic_helper_damage_iter_init(&iter, old_state, new_state);
-	drm_atomic_for_each_plane_damage(&iter, &damage)
-		gud_fb_handle_damage(gdrm, fb, &shadow_plane_state->data[0], &damage);
+	if (gdrm->flags & GUD_DISPLAY_FLAG_FULL_UPDATE) {
+		if (drm_atomic_helper_damage_merged(old_state, new_state, &damage))
+			gud_fb_handle_damage(gdrm, fb, &shadow_plane_state->data[0], &damage);
+	} else {
+		drm_atomic_helper_damage_iter_init(&iter, old_state, new_state);
+		drm_atomic_for_each_plane_damage(&iter, &damage)
+			gud_fb_handle_damage(gdrm, fb, &shadow_plane_state->data[0], &damage);
+	}
 
 	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
 
Signature · 1 line
2.55.0
#1 lore raw

Hi

Am 08.09.26 um 01:08 schrieb Sophie D:

Quoted 23 lines

When running in full update mode, previously small updates (such as moving the mouse across the screen) would cause many full frames to be generated. This would bog down the bus and lower the effective framerate significantly - I was seeing a drop from 60 FPS to 2 FPS.

This patch fixes the bug by merging damage clips together.

Fixes 73cfd166e045 ("drm/gud: Replace simple display pipe with DRM atomic helpers")
Cc <[email protected]> # 6.18.x
---
  drivers/gpu/drm/gud/gud_pipe.c | 11 ++++++++---
  1 file changed, 8 insertions(+), 3 deletions(-)
drivers/gpu/drm/gud/gud_pipe.c +0 -1
index 5ef887d84..20418bf81 100644
@@ -647,9 +647,14 @@ void gud_plane_atomic_update(struct drm_plane *plane,
  	if (ret)
  		goto out;
 
-	drm_atomic_helper_damage_iter_init(&iter, old_state, new_state);

drivers/gpu/drm/gud/gud_pipe.c void gud_plane_atomic_update(struct drm_plane *plane, · line 657

Quoted 10 lines
drivers/gpu/drm/gud/gud_pipe.c +8 -2
-	drm_atomic_for_each_plane_damage(&iter, &damage)
-		gud_fb_handle_damage(gdrm, fb, &shadow_plane_state->data[0], &damage);
+	if (gdrm->flags & GUD_DISPLAY_FLAG_FULL_UPDATE) {
+		if (drm_atomic_helper_damage_merged(old_state, new_state, &damage))
+			gud_fb_handle_damage(gdrm, fb, &shadow_plane_state->data[0], &damage);
+	} else {
+		drm_atomic_helper_damage_iter_init(&iter, old_state, new_state);
+		drm_atomic_for_each_plane_damage(&iter, &damage)
+			gud_fb_handle_damage(gdrm, fb, &shadow_plane_state->data[0], &damage);
+	}

Such state needs to be checked much earlier. Please set plane_state->ignore_damage_clips [1] at the end of gud_plane_atomic_check [2] if in full-update mode.  The damage iterator will then do the right thing.

[1] https://elixir.bootlin.com/linux/v7.2.2/source/include/drm/drm_plane.h#L207
[2] https://elixir.bootlin.com/linux/v7.2.2/source/drivers/gpu/drm/gud/gud_pipe.c#L569

Best regards
Thomas

Quoted 3 lines
drivers/gpu/drm/gud/gud_pipe.c +0 -0
  	drm_gem_fb_end_cpu_access(fb, DMA_FROM_DEVICE);
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
author
#2 lore raw

Hello,

Quoted 5 lines

Such state needs to be checked much earlier. Please set plane_state->ignore_damage_clips [1] at the end of gud_plane_atomic_check [2] if in full-update mode.  The damage iterator will then do the right thing.

Thank you for reviewing! I've made this change and have tested it on my hardware.

Sophie

author
#3 lore raw

PATCH v2 1/1 drm/gud: Ignore damage clips in full update mode

In reply to Sophie D

When running in full update mode, previously small updates (such as moving the mouse across the screen) would cause many full frames to be generated. This would bog down the bus and lower the effective framerate significantly - I was seeing a drop from 60 FPS to 2 FPS.

Set ignore_damage_clips in full update mode so the damage iterator yields a single full-plane rectangle instead of one per clip.

Fixes 73cfd166e045 ("drm/gud: Replace simple display pipe with DRM atomic helpers")
Cc <[email protected]> # 6.18.x

---
v2: set ignore_damage_clips in atomic_check instead of merging clips in
atomic_update (Thomas Zimmermann)

 drivers/gpu/drm/gud/gud_pipe.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/gud/gud_pipe.c +3 -0
index 5ef887d84..3388fdc8e 100644
@@ -482,6 +482,9 @@ int gud_plane_atomic_check(struct drm_plane *plane,
 	if (!new_plane_state->visible)
 		return 0;
 
+	if (gdrm->flags & GUD_DISPLAY_FLAG_FULL_UPDATE)
+		new_plane_state->ignore_damage_clips = true;
+
 	if (old_plane_state->rotation != new_plane_state->rotation)
 		crtc_state->mode_changed = true;
 
Signature · 1 line
2.55.0
#4 lore raw

Re: [PATCH v2] drm/gud: Ignore damage clips in full update mode

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The iterator variable connector_state leaks out of for_each_new_connector_in_state, bypassing the fallback search. --

commit 4deed33a0bafa9e2ff82e53d1da0f3130451d673
Author: Sophie D <[email protected]>

drm/gud: Ignore damage clips in full update mode

When running in full update mode, previously small updates (such as moving the mouse across the screen) would cause many full frames to be generated. This would bog down the bus and lower the effective framerate significantly - I was seeing a drop from 60 FPS to 2 FPS.

Quoted 5 lines
drivers/gpu/drm/gud/gud_pipe.c +0 -0
index 5ef887d8485a3..3388fdc8ea7b5 100644

drivers/gpu/drm/gud/gud_pipe.c int gud_plane_atomic_check(struct drm_plane *plane, · line 490

Quoted 9 lines
drivers/gpu/drm/gud/gud_pipe.c +3 -0
@@ -482,6 +482,9 @@ int gud_plane_atomic_check(struct drm_plane *plane,
 	if (!new_plane_state->visible)
 		return 0;
 
+	if (gdrm->flags & GUD_DISPLAY_FLAG_FULL_UPDATE)
+		new_plane_state->ignore_damage_clips = true;
+
 	if (old_plane_state->rotation != new_plane_state->rotation)
 		crtc_state->mode_changed = true;
 

[Severity: High]
This isn't a bug introduced by this patch, but while reviewing gud_plane_atomic_check(), I noticed an issue with the fallback search for the connector.

Does connector_state bypass the fallback search here?

	for_each_new_connector_in_state(state, connector, connector_state, i) {
		if (connector_state->crtc)
			break;
	}

	/*
	 * DRM_IOCTL_MODE_OBJ_SETPROPERTY on the rotation property will not have
	 * the connector included in the state.
	 */
	if (!connector_state) {
		struct drm_connector_list_iter conn_iter;

If the loop finishes without finding a matching CRTC, connector_state retains the pointer to the last evaluated connector rather than evaluating to NULL. This happens because short-circuit evaluation prevents the macro's assignment block from running on the final iteration.

Could this cause the driver to extract properties and the connector index from an unrelated or disconnected connector and send them to the hardware device during the atomic check phase, leading to hardware misconfiguration?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer Reviewed-by on v2 1/1
#5 lore raw

Re: [PATCH v2] drm/gud: Ignore damage clips in full update mode

In reply to Sophie D

Am 10.09.26 um 03:49 schrieb Sophie D:

Quoted 11 lines

When running in full update mode, previously small updates (such as moving the mouse across the screen) would cause many full frames to be generated. This would bog down the bus and lower the effective framerate significantly - I was seeing a drop from 60 FPS to 2 FPS.

Set ignore_damage_clips in full update mode so the damage iterator yields a single full-plane rectangle instead of one per clip.

Fixes 73cfd166e045 ("drm/gud: Replace simple display pipe with DRM atomic helpers")
Cc <[email protected]> # 6.18.x

Thanks for the fix.

Quoted 21 lines

---
v2: set ignore_damage_clips in atomic_check instead of merging clips in
atomic_update (Thomas Zimmermann)

  drivers/gpu/drm/gud/gud_pipe.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/gud/gud_pipe.c +3 -0
index 5ef887d84..3388fdc8e 100644
@@ -482,6 +482,9 @@ int gud_plane_atomic_check(struct drm_plane *plane,
  	if (!new_plane_state->visible)
  		return 0;
 
+	if (gdrm->flags & GUD_DISPLAY_FLAG_FULL_UPDATE)
+		new_plane_state->ignore_damage_clips = true;
+
  	if (old_plane_state->rotation != new_plane_state->rotation)
  		crtc_state->mode_changed = true;
 
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, (HRB 36809, AG Nürnberg)
maintainer Acked-by
#6 lore raw

Re: [PATCH v2] drm/gud: Ignore damage clips in full update mode

Quoted 7 lines · Thomas Zimmermann

Am 10.09.26 um 03:49 schrieb Sophie D:

Quoted 5 lines

When running in full update mode, previously small updates (such as moving the mouse across the screen) would cause many full frames to be generated. This would bog down the bus and lower the effective framerate significantly - I was seeing a drop from 60 FPS to 2 FPS.

Quoted 8 lines
Quoted 6 lines

Set ignore_damage_clips in full update mode so the damage iterator yields a single full-plane rectangle instead of one per clip.

Fixes 73cfd166e045 ("drm/gud: Replace simple display pipe with DRM atomic helpers")
Cc <[email protected]> # 6.18.x
Quoted 24 lines

Thanks for the fix.

Quoted 21 lines

---
v2: set ignore_damage_clips in atomic_check instead of merging clips in
atomic_update (Thomas Zimmermann)

  drivers/gpu/drm/gud/gud_pipe.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/gud/gud_pipe.c +3 -0
index 5ef887d84..3388fdc8e 100644
@@ -482,6 +482,9 @@ int gud_plane_atomic_check(struct drm_plane *plane,
  	if (!new_plane_state->visible)
  		return 0;
 
+	if (gdrm->flags & GUD_DISPLAY_FLAG_FULL_UPDATE)
+		new_plane_state->ignore_damage_clips = true;
+
  	if (old_plane_state->rotation != new_plane_state->rotation)
  		crtc_state->mode_changed = true;