[PATCH i-g-t] lib/kms: Add secondary sort key (vrefresh) to DRM mode sorting func()

Samala, Pranay pranay.samala at intel.com
Wed May 21 10:49:47 UTC 2025


Hi Swati,

> -----Original Message-----
> From: igt-dev <igt-dev-bounces at lists.freedesktop.org> On Behalf Of Swati
> Sharma
> Sent: Wednesday, May 21, 2025 12:20 PM
> To: igt-dev at lists.freedesktop.org
> Cc: Sharma, Swati2 <swati2.sharma at intel.com>
> Subject: [PATCH i-g-t] lib/kms: Add secondary sort key (vrefresh) to DRM mode
> sorting func()
> 
> Extend sort_drm_modes_by_res_dsc() and sort_drm_modes_by_res_asc() to use
> vrefresh as a secondary key when hdisplay values are equal.

When both hdisplay and vrefresh values are equal, then in such modes can we use 
vdisplay as 3rd key comparison?

Regards,
Pranay Samala
> 
> Signed-off-by: Swati Sharma <swati2.sharma at intel.com>
> ---
>  lib/igt_kms.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c index 9ee03e870..e5c0a51ae 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -1887,7 +1887,11 @@ int sort_drm_modes_by_res_dsc(const void *a, const
> void *b)  {
>  	const drmModeModeInfo *mode1 = a, *mode2 = b;
> 
> -	return (mode1->hdisplay < mode2->hdisplay) - (mode2->hdisplay <
> mode1->hdisplay);
> +	int cmp = (mode1->hdisplay < mode2->hdisplay) - (mode2->hdisplay <
> mode1->hdisplay);
> +	if (cmp == 0)
> +		cmp = (mode1->vrefresh < mode2->vrefresh) - (mode2->vrefresh
> <
> +mode1->vrefresh);
> +
> +	return cmp;
>  }
> 
>  /**
> @@ -1904,7 +1908,11 @@ int sort_drm_modes_by_res_asc(const void *a, const
> void *b)  {
>  	const drmModeModeInfo *mode1 = a, *mode2 = b;
> 
> -	return (mode1->hdisplay > mode2->hdisplay) - (mode2->hdisplay >
> mode1->hdisplay);
> +	int cmp = (mode1->hdisplay > mode2->hdisplay) - (mode2->hdisplay >
> mode1->hdisplay);
> +	if (cmp == 0)
> +		cmp = (mode1->vrefresh > mode2->vrefresh) - (mode2->vrefresh
> >
> +mode1->vrefresh);
> +
> +	return cmp;
>  }
> 
>  /**
> --
> 2.25.1



More information about the igt-dev mailing list