diff mbox series

[2/2] drm/i915: Ensure damage clip area is within pipe area

Message ID 20220506054834.2822650-3-jouni.hogander@intel.com (mailing list archive)
State New, archived
Headers show
Series Fixes for selective fetch area calculation | expand

Commit Message

Hogander, Jouni May 6, 2022, 5:48 a.m. UTC
Current update area calculation is not handling situation where
e.g. cursor plane is fully or partially outside pipe area.

Fix this by checking damage area against pipe_src area using
drm_rect_intersect.

Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/5440
Cc: José Roberto de Souza <jose.souza@intel.com>
Cc: Mika Kahola <mika.kahola@intel.com>
Tested-by: Mark Pearson <markpearson@lenovo.com>
Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
---
 drivers/gpu/drm/i915/display/intel_psr.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

Comments

Souza, Jose May 6, 2022, 3:43 p.m. UTC | #1
On Fri, 2022-05-06 at 08:48 +0300, Jouni Högander wrote:
> Current update area calculation is not handling situation where
> e.g. cursor plane is fully or partially outside pipe area.
> 
> Fix this by checking damage area against pipe_src area using
> drm_rect_intersect.
> 
> Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/5440
> Cc: José Roberto de Souza <jose.souza@intel.com>
> Cc: Mika Kahola <mika.kahola@intel.com>
> Tested-by: Mark Pearson <markpearson@lenovo.com>
> Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_psr.c | 17 +++++++++++++----
>  1 file changed, 13 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/display/intel_psr.c b/drivers/gpu/drm/i915/display/intel_psr.c
> index 8c099d24de86..5229ba89a079 100644
> --- a/drivers/gpu/drm/i915/display/intel_psr.c
> +++ b/drivers/gpu/drm/i915/display/intel_psr.c
> @@ -1724,6 +1724,10 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,
>  			break;
>  		}
>  
> +		/* Set x1 and x2 for drm_rect_intersect usage */
> +		damaged_area.x1 = 0;
> +		damaged_area.x2 = INT_MAX;

Move the above to the variable definition and initialization.

> +
>  		/*
>  		 * If visibility or plane moved, mark the whole plane area as
>  		 * damaged as it needs to be complete redraw in the new and old
> @@ -1735,20 +1739,23 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,
>  			if (old_plane_state->uapi.visible) {
>  				damaged_area.y1 = old_plane_state->uapi.dst.y1;
>  				damaged_area.y2 = old_plane_state->uapi.dst.y2;
> -				clip_area_update(&pipe_clip, &damaged_area);
> +				if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> +					clip_area_update(&pipe_clip, &damaged_area);
>  			}
>  
>  			if (new_plane_state->uapi.visible) {
>  				damaged_area.y1 = new_plane_state->uapi.dst.y1;
>  				damaged_area.y2 = new_plane_state->uapi.dst.y2;
> -				clip_area_update(&pipe_clip, &damaged_area);
> +				if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> +					clip_area_update(&pipe_clip, &damaged_area);
>  			}
>  			continue;
>  		} else if (new_plane_state->uapi.alpha != old_plane_state->uapi.alpha) {
>  			/* If alpha changed mark the whole plane area as damaged */
>  			damaged_area.y1 = new_plane_state->uapi.dst.y1;
>  			damaged_area.y2 = new_plane_state->uapi.dst.y2;
> -			clip_area_update(&pipe_clip, &damaged_area);
> +			if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> +				clip_area_update(&pipe_clip, &damaged_area);
>  			continue;
>  		}
>  
> @@ -1767,7 +1774,9 @@ int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,
>  
>  		damaged_area.y1 += new_plane_state->uapi.dst.y1 - src.y1;
>  		damaged_area.y2 += new_plane_state->uapi.dst.y1 - src.y1;
> -		clip_area_update(&pipe_clip, &damaged_area);
> +
> +		if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> +			clip_area_update(&pipe_clip, &damaged_area);

As it is repeating move the drm_rect_intersect() call to clip_area_update(), adding a crtc_state parameter or pipe_src, your call.

Also please include a Fixes tag to some commit that makes sense so this patch is backported to older kernels with selective fetch enabled.

>  	}
>  
>  	if (pipe_clip.y1 == -1)
Hogander, Jouni May 9, 2022, 7:25 a.m. UTC | #2
On Fri, 2022-05-06 at 15:43 +0000, Souza, Jose wrote:
> On Fri, 2022-05-06 at 08:48 +0300, Jouni Högander wrote:
> > Current update area calculation is not handling situation where
> > e.g. cursor plane is fully or partially outside pipe area.
> > 
> > Fix this by checking damage area against pipe_src area using
> > drm_rect_intersect.
> > 
> > Closes: https://gitlab.freedesktop.org/drm/intel/-/issues/5440
> > Cc: José Roberto de Souza <jose.souza@intel.com>
> > Cc: Mika Kahola <mika.kahola@intel.com>
> > Tested-by: Mark Pearson <markpearson@lenovo.com>
> > Signed-off-by: Jouni Högander <jouni.hogander@intel.com>
> > ---
> >  drivers/gpu/drm/i915/display/intel_psr.c | 17 +++++++++++++----
> >  1 file changed, 13 insertions(+), 4 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/i915/display/intel_psr.c
> > b/drivers/gpu/drm/i915/display/intel_psr.c
> > index 8c099d24de86..5229ba89a079 100644
> > --- a/drivers/gpu/drm/i915/display/intel_psr.c
> > +++ b/drivers/gpu/drm/i915/display/intel_psr.c
> > @@ -1724,6 +1724,10 @@ int intel_psr2_sel_fetch_update(struct
> > intel_atomic_state *state,
> >  break;
> >  }
> > 
> > +/* Set x1 and x2 for drm_rect_intersect usage */
> > +damaged_area.x1 = 0;
> > +damaged_area.x2 = INT_MAX;
> 
> Move the above to the variable definition and initialization.
> 

Fixed, please check new version.

> > +
> >  /*
> >   * If visibility or plane moved, mark the whole plane area as
> >   * damaged as it needs to be complete redraw in the new and old
> > @@ -1735,20 +1739,23 @@ int intel_psr2_sel_fetch_update(struct
> > intel_atomic_state *state,
> >  if (old_plane_state->uapi.visible) {
> >  damaged_area.y1 = old_plane_state->uapi.dst.y1;
> >  damaged_area.y2 = old_plane_state->uapi.dst.y2;
> > -clip_area_update(&pipe_clip, &damaged_area);
> > +if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> > +clip_area_update(&pipe_clip, &damaged_area);
> >  }
> > 
> >  if (new_plane_state->uapi.visible) {
> >  damaged_area.y1 = new_plane_state->uapi.dst.y1;
> >  damaged_area.y2 = new_plane_state->uapi.dst.y2;
> > -clip_area_update(&pipe_clip, &damaged_area);
> > +if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> > +clip_area_update(&pipe_clip, &damaged_area);
> >  }
> >  continue;
> >  } else if (new_plane_state->uapi.alpha != old_plane_state-
> > >uapi.alpha) {
> >  /* If alpha changed mark the whole plane area as damaged */
> >  damaged_area.y1 = new_plane_state->uapi.dst.y1;
> >  damaged_area.y2 = new_plane_state->uapi.dst.y2;
> > -clip_area_update(&pipe_clip, &damaged_area);
> > +if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> > +clip_area_update(&pipe_clip, &damaged_area);
> >  continue;
> >  }
> > 
> > @@ -1767,7 +1774,9 @@ int intel_psr2_sel_fetch_update(struct
> > intel_atomic_state *state,
> > 
> >  damaged_area.y1 += new_plane_state->uapi.dst.y1 - src.y1;
> >  damaged_area.y2 += new_plane_state->uapi.dst.y1 - src.y1;
> > -clip_area_update(&pipe_clip, &damaged_area);
> > +
> > +if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
> > +clip_area_update(&pipe_clip, &damaged_area);
> 
> As it is repeating move the drm_rect_intersect() call to
> clip_area_update(), adding a crtc_state parameter or pipe_src, your
> call.
> 
> Also please include a Fixes tag to some commit that makes sense so
> this patch is backported to older kernels with selective fetch
> enabled.
> 
> >  }
> > 
> >  if (pipe_clip.y1 == -1)
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/display/intel_psr.c b/drivers/gpu/drm/i915/display/intel_psr.c
index 8c099d24de86..5229ba89a079 100644
--- a/drivers/gpu/drm/i915/display/intel_psr.c
+++ b/drivers/gpu/drm/i915/display/intel_psr.c
@@ -1724,6 +1724,10 @@  int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,
 			break;
 		}
 
+		/* Set x1 and x2 for drm_rect_intersect usage */
+		damaged_area.x1 = 0;
+		damaged_area.x2 = INT_MAX;
+
 		/*
 		 * If visibility or plane moved, mark the whole plane area as
 		 * damaged as it needs to be complete redraw in the new and old
@@ -1735,20 +1739,23 @@  int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,
 			if (old_plane_state->uapi.visible) {
 				damaged_area.y1 = old_plane_state->uapi.dst.y1;
 				damaged_area.y2 = old_plane_state->uapi.dst.y2;
-				clip_area_update(&pipe_clip, &damaged_area);
+				if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
+					clip_area_update(&pipe_clip, &damaged_area);
 			}
 
 			if (new_plane_state->uapi.visible) {
 				damaged_area.y1 = new_plane_state->uapi.dst.y1;
 				damaged_area.y2 = new_plane_state->uapi.dst.y2;
-				clip_area_update(&pipe_clip, &damaged_area);
+				if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
+					clip_area_update(&pipe_clip, &damaged_area);
 			}
 			continue;
 		} else if (new_plane_state->uapi.alpha != old_plane_state->uapi.alpha) {
 			/* If alpha changed mark the whole plane area as damaged */
 			damaged_area.y1 = new_plane_state->uapi.dst.y1;
 			damaged_area.y2 = new_plane_state->uapi.dst.y2;
-			clip_area_update(&pipe_clip, &damaged_area);
+			if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
+				clip_area_update(&pipe_clip, &damaged_area);
 			continue;
 		}
 
@@ -1767,7 +1774,9 @@  int intel_psr2_sel_fetch_update(struct intel_atomic_state *state,
 
 		damaged_area.y1 += new_plane_state->uapi.dst.y1 - src.y1;
 		damaged_area.y2 += new_plane_state->uapi.dst.y1 - src.y1;
-		clip_area_update(&pipe_clip, &damaged_area);
+
+		if (drm_rect_intersect(&damaged_area, &crtc_state->pipe_src))
+			clip_area_update(&pipe_clip, &damaged_area);
 	}
 
 	if (pipe_clip.y1 == -1)