linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts
@ 2023-03-07 21:50 Javier Martinez Canillas
  2023-03-09 17:51 ` Arthur Grillo Queiroz Cabral
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Javier Martinez Canillas @ 2023-03-07 21:50 UTC (permalink / raw)
  To: linux-kernel
  Cc: Arthur Grillo, Maíra Canal, Thomas Zimmermann,
	Maxime Ripard, Javier Martinez Canillas, Daniel Vetter,
	David Airlie, David Gow, José Expósito, dri-devel

There are DRM fourcc formats that have pixels smaller than a byte, but the
conversion_buf_size() function assumes that pixels are a multiple of bytes
and use the struct drm_format_info .cpp field to calculate the dst_pitch.

Instead, calculate it by using the bits per pixel (bpp) and divide it by 8
to account for formats that have sub-byte pixels.

Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
---
Tested by making sure that the following command still succeeds:

./tools/testing/kunit/kunit.py run \
--kunitconfig=drivers/gpu/drm/tests/.kunitconfig

Changes in v2:
- Drop an unused variable, that was pointed out by the kernel robot.

 drivers/gpu/drm/tests/drm_format_helper_test.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 9536829c6e3a..84b5cc29c8fc 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -409,12 +409,15 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
 				  const struct drm_rect *clip)
 {
 	const struct drm_format_info *dst_fi = drm_format_info(dst_format);
+	unsigned int bpp;
 
 	if (!dst_fi)
 		return -EINVAL;
 
-	if (!dst_pitch)
-		dst_pitch = drm_rect_width(clip) * dst_fi->cpp[0];
+	if (!dst_pitch) {
+		bpp = drm_format_info_bpp(dst_fi, 0);
+		dst_pitch = DIV_ROUND_UP(drm_rect_width(clip) * bpp, 8);
+	}
 
 	return dst_pitch * drm_rect_height(clip);
 }
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts
  2023-03-07 21:50 [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts Javier Martinez Canillas
@ 2023-03-09 17:51 ` Arthur Grillo Queiroz Cabral
  2023-03-09 22:34 ` Maíra Canal
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Arthur Grillo Queiroz Cabral @ 2023-03-09 17:51 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Maíra Canal, Thomas Zimmermann, Maxime Ripard,
	Daniel Vetter, David Airlie, David Gow, José Expósito,
	dri-devel


Hi,

On 07/03/23 18:50, Javier Martinez Canillas wrote:
> There are DRM fourcc formats that have pixels smaller than a byte, but the
> conversion_buf_size() function assumes that pixels are a multiple of bytes
> and use the struct drm_format_info .cpp field to calculate the dst_pitch.
> 
> Instead, calculate it by using the bits per pixel (bpp) and divide it by 8
> to account for formats that have sub-byte pixels.
> 
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
> Tested by making sure that the following command still succeeds:
> 
> ./tools/testing/kunit/kunit.py run \
> --kunitconfig=drivers/gpu/drm/tests/.kunitconfig
> 
> Changes in v2:
> - Drop an unused variable, that was pointed out by the kernel robot.
> 
>  drivers/gpu/drm/tests/drm_format_helper_test.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 9536829c6e3a..84b5cc29c8fc 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -409,12 +409,15 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
>  				  const struct drm_rect *clip)
>  {
>  	const struct drm_format_info *dst_fi = drm_format_info(dst_format);
> +	unsigned int bpp;
>  
>  	if (!dst_fi)
>  		return -EINVAL;
>  
> -	if (!dst_pitch)
> -		dst_pitch = drm_rect_width(clip) * dst_fi->cpp[0];
> +	if (!dst_pitch) {
> +		bpp = drm_format_info_bpp(dst_fi, 0);
> +		dst_pitch = DIV_ROUND_UP(drm_rect_width(clip) * bpp, 8);
> +	}
>  
>  	return dst_pitch * drm_rect_height(clip);
>  }

Ran it on UML, arm and powerpc with my patch above it, All looks good
:).

Reviewed-by: Arthur Grillo <arthurgrillo@riseup.net>

Thanks,
Grillo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts
  2023-03-07 21:50 [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts Javier Martinez Canillas
  2023-03-09 17:51 ` Arthur Grillo Queiroz Cabral
@ 2023-03-09 22:34 ` Maíra Canal
  2023-03-10 11:46 ` Javier Martinez Canillas
  2023-03-16 16:30 ` Geert Uytterhoeven
  3 siblings, 0 replies; 6+ messages in thread
From: Maíra Canal @ 2023-03-09 22:34 UTC (permalink / raw)
  To: Javier Martinez Canillas, linux-kernel
  Cc: Arthur Grillo, Thomas Zimmermann, Maxime Ripard, Daniel Vetter,
	David Airlie, David Gow, José Expósito, dri-devel

On 3/7/23 18:50, Javier Martinez Canillas wrote:
> There are DRM fourcc formats that have pixels smaller than a byte, but the
> conversion_buf_size() function assumes that pixels are a multiple of bytes
> and use the struct drm_format_info .cpp field to calculate the dst_pitch.
> 
> Instead, calculate it by using the bits per pixel (bpp) and divide it by 8
> to account for formats that have sub-byte pixels.
> 
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>

Reviewed-by: Maíra Canal <mcanal@igalia.com>

Best Regards,
- Maíra Canal

> ---
> Tested by making sure that the following command still succeeds:
> 
> ./tools/testing/kunit/kunit.py run \
> --kunitconfig=drivers/gpu/drm/tests/.kunitconfig
> 
> Changes in v2:
> - Drop an unused variable, that was pointed out by the kernel robot.
> 
>   drivers/gpu/drm/tests/drm_format_helper_test.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 9536829c6e3a..84b5cc29c8fc 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -409,12 +409,15 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
>   				  const struct drm_rect *clip)
>   {
>   	const struct drm_format_info *dst_fi = drm_format_info(dst_format);
> +	unsigned int bpp;
>   
>   	if (!dst_fi)
>   		return -EINVAL;
>   
> -	if (!dst_pitch)
> -		dst_pitch = drm_rect_width(clip) * dst_fi->cpp[0];
> +	if (!dst_pitch) {
> +		bpp = drm_format_info_bpp(dst_fi, 0);
> +		dst_pitch = DIV_ROUND_UP(drm_rect_width(clip) * bpp, 8);
> +	}
>   
>   	return dst_pitch * drm_rect_height(clip);
>   }

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts
  2023-03-07 21:50 [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts Javier Martinez Canillas
  2023-03-09 17:51 ` Arthur Grillo Queiroz Cabral
  2023-03-09 22:34 ` Maíra Canal
@ 2023-03-10 11:46 ` Javier Martinez Canillas
  2023-03-16 16:30 ` Geert Uytterhoeven
  3 siblings, 0 replies; 6+ messages in thread
From: Javier Martinez Canillas @ 2023-03-10 11:46 UTC (permalink / raw)
  To: linux-kernel
  Cc: Arthur Grillo, Maíra Canal, Thomas Zimmermann,
	Maxime Ripard, Daniel Vetter, David Airlie, David Gow,
	José Expósito, dri-devel

Javier Martinez Canillas <javierm@redhat.com> writes:

> There are DRM fourcc formats that have pixels smaller than a byte, but the
> conversion_buf_size() function assumes that pixels are a multiple of bytes
> and use the struct drm_format_info .cpp field to calculate the dst_pitch.
>
> Instead, calculate it by using the bits per pixel (bpp) and divide it by 8
> to account for formats that have sub-byte pixels.
>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---

Pushed to drm-misc (drm-misc-next). Thanks!

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts
  2023-03-07 21:50 [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts Javier Martinez Canillas
                   ` (2 preceding siblings ...)
  2023-03-10 11:46 ` Javier Martinez Canillas
@ 2023-03-16 16:30 ` Geert Uytterhoeven
  2023-03-16 22:29   ` Javier Martinez Canillas
  3 siblings, 1 reply; 6+ messages in thread
From: Geert Uytterhoeven @ 2023-03-16 16:30 UTC (permalink / raw)
  To: Javier Martinez Canillas
  Cc: linux-kernel, Arthur Grillo, Maíra Canal, Thomas Zimmermann,
	Maxime Ripard, Daniel Vetter, David Airlie, David Gow,
	José Expósito, dri-devel

Hi Javier,

On Tue, Mar 7, 2023 at 10:54 PM Javier Martinez Canillas
<javierm@redhat.com> wrote:
> There are DRM fourcc formats that have pixels smaller than a byte, but the
> conversion_buf_size() function assumes that pixels are a multiple of bytes
> and use the struct drm_format_info .cpp field to calculate the dst_pitch.
>
> Instead, calculate it by using the bits per pixel (bpp) and divide it by 8
> to account for formats that have sub-byte pixels.
>
> Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
> ---
> Tested by making sure that the following command still succeeds:
>
> ./tools/testing/kunit/kunit.py run \
> --kunitconfig=drivers/gpu/drm/tests/.kunitconfig
>
> Changes in v2:
> - Drop an unused variable, that was pointed out by the kernel robot.

Thanks for your patch!

> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -409,12 +409,15 @@ static size_t conversion_buf_size(u32 dst_format, unsigned int dst_pitch,
>                                   const struct drm_rect *clip)
>  {
>         const struct drm_format_info *dst_fi = drm_format_info(dst_format);
> +       unsigned int bpp;
>
>         if (!dst_fi)
>                 return -EINVAL;
>
> -       if (!dst_pitch)
> -               dst_pitch = drm_rect_width(clip) * dst_fi->cpp[0];
> +       if (!dst_pitch) {
> +               bpp = drm_format_info_bpp(dst_fi, 0);
> +               dst_pitch = DIV_ROUND_UP(drm_rect_width(clip) * bpp, 8);

I know I'm a bit late to the party,  but here's actually a helper for that:

    dst_pitch = drm_format_info_min_pitch(info, 0, drm_rect_width(clip));

> +       }
>
>         return dst_pitch * drm_rect_height(clip);
>  }

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts
  2023-03-16 16:30 ` Geert Uytterhoeven
@ 2023-03-16 22:29   ` Javier Martinez Canillas
  0 siblings, 0 replies; 6+ messages in thread
From: Javier Martinez Canillas @ 2023-03-16 22:29 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: linux-kernel, Arthur Grillo, Maíra Canal, Thomas Zimmermann,
	Maxime Ripard, Daniel Vetter, David Airlie, David Gow,
	José Expósito, dri-devel

Geert Uytterhoeven <geert@linux-m68k.org> writes:

Hello Geert,

[...]

>> +       if (!dst_pitch) {
>> +               bpp = drm_format_info_bpp(dst_fi, 0);
>> +               dst_pitch = DIV_ROUND_UP(drm_rect_width(clip) * bpp, 8);
>
> I know I'm a bit late to the party,  but here's actually a helper for that:
>
>     dst_pitch = drm_format_info_min_pitch(info, 0, drm_rect_width(clip));
>

Nice, I didn't notice this. I'll send a follow-up patch. Thanks!

-- 
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-16 22:31 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-07 21:50 [PATCH v2] drm/format-helper: Make conversion_buf_size() support sub-byte pixel fmts Javier Martinez Canillas
2023-03-09 17:51 ` Arthur Grillo Queiroz Cabral
2023-03-09 22:34 ` Maíra Canal
2023-03-10 11:46 ` Javier Martinez Canillas
2023-03-16 16:30 ` Geert Uytterhoeven
2023-03-16 22:29   ` Javier Martinez Canillas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).