* [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values
@ 2023-05-07 20:28 Maíra Canal
2023-05-07 20:28 ` [PATCH v2 2/2] drm/vkms: Fix RGB565 pixel conversion Maíra Canal
2023-05-11 19:35 ` [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values Arthur Grillo Queiroz Cabral
0 siblings, 2 replies; 4+ messages in thread
From: Maíra Canal @ 2023-05-07 20:28 UTC (permalink / raw)
To: David Airlie, Daniel Vetter, Rodrigo Siqueira, Melissa Wen,
Haneen Mohammed, Arthur Grillo
Cc: Maíra Canal, dri-devel
Create a new fixed-point helper to allow us to return the rounded value
of our fixed-point value.
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
v1 -> v2: https://lore.kernel.org/dri-devel/20230425153353.238844-1-mcanal@igalia.com/T/
* New patch
* Create the function drm_fixp2int_round() (Melissa Wen).
---
include/drm/drm_fixed.h | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/include/drm/drm_fixed.h b/include/drm/drm_fixed.h
index 255645c1f9a8..d695d0411e2d 100644
--- a/include/drm/drm_fixed.h
+++ b/include/drm/drm_fixed.h
@@ -71,6 +71,7 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)
}
#define DRM_FIXED_POINT 32
+#define DRM_FIXED_POINT_HALF 16
#define DRM_FIXED_ONE (1ULL << DRM_FIXED_POINT)
#define DRM_FIXED_DECIMAL_MASK (DRM_FIXED_ONE - 1)
#define DRM_FIXED_DIGITS_MASK (~DRM_FIXED_DECIMAL_MASK)
@@ -87,6 +88,11 @@ static inline int drm_fixp2int(s64 a)
return ((s64)a) >> DRM_FIXED_POINT;
}
+static inline int drm_fixp2int_round(s64 a)
+{
+ return ((s64)a + (1 << (DRM_FIXED_POINT_HALF - 1))) >> DRM_FIXED_POINT;
+}
+
static inline int drm_fixp2int_ceil(s64 a)
{
if (a > 0)
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] drm/vkms: Fix RGB565 pixel conversion
2023-05-07 20:28 [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values Maíra Canal
@ 2023-05-07 20:28 ` Maíra Canal
2023-05-11 19:41 ` Arthur Grillo Queiroz Cabral
2023-05-11 19:35 ` [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values Arthur Grillo Queiroz Cabral
1 sibling, 1 reply; 4+ messages in thread
From: Maíra Canal @ 2023-05-07 20:28 UTC (permalink / raw)
To: David Airlie, Daniel Vetter, Rodrigo Siqueira, Melissa Wen,
Haneen Mohammed, Arthur Grillo
Cc: Maíra Canal, dri-devel
Currently, the pixel conversion isn't rounding the fixed-point values
before assigning it to the RGB coefficients, which is causing the IGT
pixel-format tests to fail. So, use the drm_fixp2int_round() fixed-point
helper to round the values when assigning it to the RGB coefficients.
Tested with igt@kms_plane@pixel-format and igt@kms_plane@pixel-format-source-clamping.
Fixes: 89b03aeaef16 ("drm/vkms: fix 32bit compilation error by replacing macros")
Signed-off-by: Maíra Canal <mcanal@igalia.com>
---
v1 -> v2: https://lore.kernel.org/dri-devel/20230425153353.238844-1-mcanal@igalia.com/T/
* Use drm_fixp2int_round() to fix the pixel conversion instead of casting
the values to s32 (Melissa Wen).
---
drivers/gpu/drm/vkms/vkms_formats.c | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
index 8d948c73741e..b11342026485 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -97,9 +97,9 @@ static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
out_pixel->a = (u16)0xffff;
- out_pixel->r = drm_fixp2int(drm_fixp_mul(fp_r, fp_rb_ratio));
- out_pixel->g = drm_fixp2int(drm_fixp_mul(fp_g, fp_g_ratio));
- out_pixel->b = drm_fixp2int(drm_fixp_mul(fp_b, fp_rb_ratio));
+ out_pixel->r = drm_fixp2int_round(drm_fixp_mul(fp_r, fp_rb_ratio));
+ out_pixel->g = drm_fixp2int_round(drm_fixp_mul(fp_g, fp_g_ratio));
+ out_pixel->b = drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio));
}
void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y)
@@ -216,9 +216,9 @@ static void argb_u16_to_RGB565(struct vkms_frame_info *frame_info,
s64 fp_g = drm_int2fixp(in_pixels[x].g);
s64 fp_b = drm_int2fixp(in_pixels[x].b);
- u16 r = drm_fixp2int(drm_fixp_div(fp_r, fp_rb_ratio));
- u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio));
- u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio));
+ u16 r = drm_fixp2int_round(drm_fixp_div(fp_r, fp_rb_ratio));
+ u16 g = drm_fixp2int_round(drm_fixp_div(fp_g, fp_g_ratio));
+ u16 b = drm_fixp2int_round(drm_fixp_div(fp_b, fp_rb_ratio));
*dst_pixels = cpu_to_le16(r << 11 | g << 5 | b);
}
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values
2023-05-07 20:28 [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values Maíra Canal
2023-05-07 20:28 ` [PATCH v2 2/2] drm/vkms: Fix RGB565 pixel conversion Maíra Canal
@ 2023-05-11 19:35 ` Arthur Grillo Queiroz Cabral
1 sibling, 0 replies; 4+ messages in thread
From: Arthur Grillo Queiroz Cabral @ 2023-05-11 19:35 UTC (permalink / raw)
To: Maíra Canal, David Airlie, Daniel Vetter, Rodrigo Siqueira,
Melissa Wen, Haneen Mohammed
Cc: dri-devel
On 07/05/23 17:28, Maíra Canal wrote:
> Create a new fixed-point helper to allow us to return the rounded value
> of our fixed-point value.
>
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
>
> v1 -> v2: https://lore.kernel.org/dri-devel/20230425153353.238844-1-mcanal@igalia.com/T/
>
> * New patch
> * Create the function drm_fixp2int_round() (Melissa Wen).
>
> ---
> include/drm/drm_fixed.h | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/include/drm/drm_fixed.h b/include/drm/drm_fixed.h
> index 255645c1f9a8..d695d0411e2d 100644
> --- a/include/drm/drm_fixed.h
> +++ b/include/drm/drm_fixed.h
> @@ -71,6 +71,7 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)
> }
>
> #define DRM_FIXED_POINT 32
> +#define DRM_FIXED_POINT_HALF 16
> #define DRM_FIXED_ONE (1ULL << DRM_FIXED_POINT)
> #define DRM_FIXED_DECIMAL_MASK (DRM_FIXED_ONE - 1)
> #define DRM_FIXED_DIGITS_MASK (~DRM_FIXED_DECIMAL_MASK)
> @@ -87,6 +88,11 @@ static inline int drm_fixp2int(s64 a)
> return ((s64)a) >> DRM_FIXED_POINT;
> }
>
> +static inline int drm_fixp2int_round(s64 a)
> +{
> + return ((s64)a + (1 << (DRM_FIXED_POINT_HALF - 1))) >> DRM_FIXED_POINT;
I think it would be great to use drm_fixp2int, instead of shifting manually,
like drm_fixp2int_ceil does.
Best Regards,
~Arthur Grillo
> +}
> +
> static inline int drm_fixp2int_ceil(s64 a)
> {
> if (a > 0)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 2/2] drm/vkms: Fix RGB565 pixel conversion
2023-05-07 20:28 ` [PATCH v2 2/2] drm/vkms: Fix RGB565 pixel conversion Maíra Canal
@ 2023-05-11 19:41 ` Arthur Grillo Queiroz Cabral
0 siblings, 0 replies; 4+ messages in thread
From: Arthur Grillo Queiroz Cabral @ 2023-05-11 19:41 UTC (permalink / raw)
To: Maíra Canal, David Airlie, Daniel Vetter, Rodrigo Siqueira,
Melissa Wen, Haneen Mohammed
Cc: dri-devel
On 07/05/23 17:28, Maíra Canal wrote:
> Currently, the pixel conversion isn't rounding the fixed-point values
> before assigning it to the RGB coefficients, which is causing the IGT
> pixel-format tests to fail. So, use the drm_fixp2int_round() fixed-point
> helper to round the values when assigning it to the RGB coefficients.
>
> Tested with igt@kms_plane@pixel-format and igt@kms_plane@pixel-format-source-clamping.
>
> Fixes: 89b03aeaef16 ("drm/vkms: fix 32bit compilation error by replacing macros")
> Signed-off-by: Maíra Canal <mcanal@igalia.com>
> ---
Reviewed-by: Arthur Grillo <arthurgrillo@riseup.net>
Best Regards,
~Arthur Grillo
>
> v1 -> v2: https://lore.kernel.org/dri-devel/20230425153353.238844-1-mcanal@igalia.com/T/
>
> * Use drm_fixp2int_round() to fix the pixel conversion instead of casting
> the values to s32 (Melissa Wen).
>
> ---
> drivers/gpu/drm/vkms/vkms_formats.c | 12 ++++++------
> 1 file changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_formats.c b/drivers/gpu/drm/vkms/vkms_formats.c
> index 8d948c73741e..b11342026485 100644
> --- a/drivers/gpu/drm/vkms/vkms_formats.c
> +++ b/drivers/gpu/drm/vkms/vkms_formats.c
> @@ -97,9 +97,9 @@ static void RGB565_to_argb_u16(u8 *src_pixels, struct pixel_argb_u16 *out_pixel)
> s64 fp_b = drm_int2fixp(rgb_565 & 0x1f);
>
> out_pixel->a = (u16)0xffff;
> - out_pixel->r = drm_fixp2int(drm_fixp_mul(fp_r, fp_rb_ratio));
> - out_pixel->g = drm_fixp2int(drm_fixp_mul(fp_g, fp_g_ratio));
> - out_pixel->b = drm_fixp2int(drm_fixp_mul(fp_b, fp_rb_ratio));
> + out_pixel->r = drm_fixp2int_round(drm_fixp_mul(fp_r, fp_rb_ratio));
> + out_pixel->g = drm_fixp2int_round(drm_fixp_mul(fp_g, fp_g_ratio));
> + out_pixel->b = drm_fixp2int_round(drm_fixp_mul(fp_b, fp_rb_ratio));
> }
>
> void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y)
> @@ -216,9 +216,9 @@ static void argb_u16_to_RGB565(struct vkms_frame_info *frame_info,
> s64 fp_g = drm_int2fixp(in_pixels[x].g);
> s64 fp_b = drm_int2fixp(in_pixels[x].b);
>
> - u16 r = drm_fixp2int(drm_fixp_div(fp_r, fp_rb_ratio));
> - u16 g = drm_fixp2int(drm_fixp_div(fp_g, fp_g_ratio));
> - u16 b = drm_fixp2int(drm_fixp_div(fp_b, fp_rb_ratio));
> + u16 r = drm_fixp2int_round(drm_fixp_div(fp_r, fp_rb_ratio));
> + u16 g = drm_fixp2int_round(drm_fixp_div(fp_g, fp_g_ratio));
> + u16 b = drm_fixp2int_round(drm_fixp_div(fp_b, fp_rb_ratio));
>
> *dst_pixels = cpu_to_le16(r << 11 | g << 5 | b);
> }
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-05-11 19:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-07 20:28 [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values Maíra Canal
2023-05-07 20:28 ` [PATCH v2 2/2] drm/vkms: Fix RGB565 pixel conversion Maíra Canal
2023-05-11 19:41 ` Arthur Grillo Queiroz Cabral
2023-05-11 19:35 ` [PATCH v2 1/2] drm: Add fixed-point helper to get rounded integer values Arthur Grillo Queiroz Cabral
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).