Skip to contentSkip to conversation

drm/virtio: Damage clip fixes

PATCH Applied Lyude Paul 3 participants 6 messages Sep 3 – Sep 20

Subsystems (4)
lore
Share & tools
lore

Lyude Paul

author
#0 lore raw

cover drm/virtio: Damage clip fixes

A previous associate of mine asked if someone would be able to help with upstreaming some work that they had done recently for virtio, and I was more then happy to help. These fixes help maintain FB damage clips between framebuffer changes, which were previously discarded even when userspace provided accumulated per-buffer damage.

Patches apply on top of drm-misc/drm-misc-next.

Christian Hergert (2):
drm/virtio: preserve damage clips for rendered resources drm/virtio: Recalculate ignore_damage_clips on every update

 drivers/gpu/drm/virtio/virtgpu_plane.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

base-commit: f9c2f70ee41544717b3c209083073db1e21f919b

Signature · 1 line
2.55.0
author
#1 lore raw

PATCH 1/2 drm/virtio: preserve damage clips for rendered resources

From: Christian Hergert <[email protected]>

virtio_gpu_plane_atomic_check() unconditionally ignores FB_DAMAGE_CLIPS when the framebuffer changes. This forces a full resource flush on every page flip when a compositor rotates through multiple framebuffers, even when userspace supplies accumulated per-buffer damage.

The full update is required for dumb buffers because their contents are uploaded per buffer. Rendered resources are already coherent on the host, so replacing their damage with the full plane only discards useful information.

Restrict ignore_damage_clips to dumb buffers. This allows damage-aware compositors to propagate partial updates through RESOURCE_FLUSH while preserving the existing full-upload behavior for dumb buffers.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +6 -2
index 1d1b27ece62a7..d9579a4b4714c 100644
@@ -103,6 +103,7 @@ static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
 										 plane);
 	struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state,
 										 plane);
+	struct virtio_gpu_object *bo;
 	bool is_cursor = plane->type == DRM_PLANE_TYPE_CURSOR;
 	struct drm_crtc_state *crtc_state;
 	int ret;
@@ -113,9 +114,12 @@ static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
 	/*
 	 * Ignore damage clips if the framebuffer attached to the plane's state
 	 * has changed since the last plane update (page-flip). In this case, a
-	 * full plane update should happen because uploads are done per-buffer.
+	 * full plane update should happen for dumb buffers because uploads are
+	 * done per-buffer. Rendered resources are already coherent on the host,
+	 * so preserve userspace's accumulated per-buffer damage for those.
 	 */
-	if (old_plane_state->fb != new_plane_state->fb)
+	bo = gem_to_virtio_gpu_obj(new_plane_state->fb->obj[0]);
+	if (old_plane_state->fb != new_plane_state->fb && bo->dumb)
 		new_plane_state->ignore_damage_clips = true;
 
 	crtc_state = drm_atomic_get_crtc_state(state,
Signature · 1 line
2.55.0
author
#2 lore raw

PATCH 2/2 drm/virtio: Recalculate ignore_damage_clips on every update

In reply to Lyude Paul

From: Christian Hergert <[email protected]>

Plane state duplication preserves ignore_damage_clips. Once fbdev sets it for a dumb buffer, later updates using rendered resources continue to ignore damage because the flag is never cleared.

Assign ignore_damage_clips on every atomic check so rendered resources can use supplied damage after an earlier dumb-buffer update.

---
 drivers/gpu/drm/virtio/virtgpu_plane.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -2
index d9579a4b4714c..95ec688690d3a 100644
@@ -119,8 +119,8 @@ static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
 	 * so preserve userspace's accumulated per-buffer damage for those.
 	 */
 	bo = gem_to_virtio_gpu_obj(new_plane_state->fb->obj[0]);
-	if (old_plane_state->fb != new_plane_state->fb && bo->dumb)
-		new_plane_state->ignore_damage_clips = true;
+	new_plane_state->ignore_damage_clips =
+		old_plane_state->fb != new_plane_state->fb && bo->dumb;
 
 	crtc_state = drm_atomic_get_crtc_state(state,
 					       new_plane_state->crtc);
Signature · 1 line
2.55.0
#3 lore raw

Re: [PATCH 2/2] drm/virtio: Recalculate ignore_damage_clips on every update

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] Preexisting bug in vmwgfx: Plane state duplication permanently preserves ignore_damage_clips, disabling partial updates. --

commit 18671312bd2be6fe18c7092369d0bbfb67a39103
Author: Christian Hergert <[email protected]>

drm/virtio: Recalculate ignore_damage_clips on every update

Plane state duplication preserves ignore_damage_clips. Once fbdev sets it for a dumb buffer, later updates using rendered resources continue to ignore damage because the flag is never cleared.

Assign ignore_damage_clips on every atomic check so rendered resources can use supplied damage after an earlier dumb-buffer update.

drivers/gpu/drm/virtio/virtgpu_plane.c static int virtio_gpu_plane_atomic_check(struct drm_plane *plane, · line 123

Quoted 12 lines
drivers/gpu/drm/virtio/virtgpu_plane.c +2 -2
index d9579a4b4714c..95ec688690d3a 100644
@@ -119,8 +119,8 @@ static int virtio_gpu_plane_atomic_check(struct drm_plane *plane,
 	 * so preserve userspace's accumulated per-buffer damage for those.
 	 */
 	bo = gem_to_virtio_gpu_obj(new_plane_state->fb->obj[0]);
-	if (old_plane_state->fb != new_plane_state->fb && bo->dumb)
-		new_plane_state->ignore_damage_clips = true;
+	new_plane_state->ignore_damage_clips =
+		old_plane_state->fb != new_plane_state->fb && bo->dumb;

[Severity: High]
This is a pre-existing issue, but does the same problem exist in vmwgfx?

Looking at vmw_du_primary_plane_atomic_check() in
drivers/gpu/drm/vmwgfx/vmwgfx_kms.c:

	if (old_fb != new_fb)
		new_state->ignore_damage_clips = true;

When old_fb == new_fb, it fails to clear the flag.

Once the flag is set to true during a page flip, won't it remain permanently true across future state duplications?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
maintainer
#4 lore raw
In reply to Lyude Paul
Quoted 12 lines · Lyude Paul

A previous associate of mine asked if someone would be able to help with upstreaming some work that they had done recently for virtio, and I was more then happy to help. These fixes help maintain FB damage clips between framebuffer changes, which were previously discarded even when userspace provided accumulated per-buffer damage.

Patches apply on top of drm-misc/drm-misc-next.

Christian Hergert (2):
drm/virtio: preserve damage clips for rendered resources drm/virtio: Recalculate ignore_damage_clips on every update

Quoted 5 lines
 drivers/gpu/drm/virtio/virtgpu_plane.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

base-commit: f9c2f70ee41544717b3c209083073db1e21f919b

Looks okay. Will merge after testing.

Signature · 2 lines
Best regards,
Dmitry
maintainer Applied
#5 lore raw
In reply to Lyude Paul
Quoted 12 lines · Lyude Paul

A previous associate of mine asked if someone would be able to help with upstreaming some work that they had done recently for virtio, and I was more then happy to help. These fixes help maintain FB damage clips between framebuffer changes, which were previously discarded even when userspace provided accumulated per-buffer damage.

Patches apply on top of drm-misc/drm-misc-next.

Christian Hergert (2):
drm/virtio: preserve damage clips for rendered resources drm/virtio: Recalculate ignore_damage_clips on every update

Quoted 5 lines
 drivers/gpu/drm/virtio/virtgpu_plane.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

base-commit: f9c2f70ee41544717b3c209083073db1e21f919b

Applied to misc-next, thanks!

Signature · 2 lines
Best regards,
Dmitry