drm/gud: Add some more pixel formats
Subsystems (3)
cover drm/gud: Add some more pixel formats
Hi,
This adds some more pixel formats and gives the user the ability to choose the xrgb8888 emulation format.
Pixel formats:
R8: For greyscale e-ink displays
RGB332: For e-ink displays and some niche displays
RGB888: Same color depth as XRGB8888 but the smaller buffer gives better fps
Noralf.
Noralf Trønnes (7):
drm/fourcc: Add R8 to drm_format_info drm/format-helper: Add drm_fb_xrgb8888_to_rgb332() drm/format-helper: Add drm_fb_xrgb8888_to_rgb888() drm/gud: Add GUD_PIXEL_FORMAT_R8
drm/gud: Add GUD_PIXEL_FORMAT_RGB332
drm/gud: Add GUD_PIXEL_FORMAT_RGB888
drm/gud: Add module parameter to control emulation: xrgb8888
drivers/gpu/drm/drm_format_helper.c | 85 +++++++++++++++++++++++++++++ drivers/gpu/drm/drm_fourcc.c | 1 + drivers/gpu/drm/gud/gud_drv.c | 19 ++++++- drivers/gpu/drm/gud/gud_internal.h | 12 ++++ drivers/gpu/drm/gud/gud_pipe.c | 6 ++ include/drm/drm_format_helper.h | 4 ++ include/drm/gud.h | 6 +- 7 files changed, 128 insertions(+), 5 deletions(-)
Signature · 1 line
2.32.0
PATCH 1/7 drm/fourcc: Add R8 to drm_format_info
Add an entry in drm_format_info for the existing format DRM_FORMAT_R8.
--- drivers/gpu/drm/drm_fourcc.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/drm_fourcc.c +1 -0
@@ -133,6 +133,7 @@ const struct drm_format_info *__drm_format_info(u32 format) {static const struct drm_format_info formats[] = { { .format =DRM_FORMAT_C8 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 }, + { .format =DRM_FORMAT_R8 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 }, { .format =DRM_FORMAT_RGB332 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 }, { .format =DRM_FORMAT_BGR233 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 }, { .format =DRM_FORMAT_XRGB4444 , .depth =0 , .num_planes =1 , .cpp = {2 ,0 ,0 }, .hsub =1 , .vsub =1 },
Signature · 1 line
2.32.0
Re: [PATCH 1/7] drm/fourcc: Add R8 to drm_format_info
Quoted 12 lines · Noralf Trønnes
Add an entry in
drm_format_infofor the existing formatDRM_FORMAT_R8.Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/drm_fourcc.c +0
-0
drivers/gpu/drm/drm_fourcc.c const struct drm_format_info *__drm_format_info(u32 format) · line 136
Quoted 4 lines
drivers/gpu/drm/drm_fourcc.c +1
-0@@ -133,6 +133,7 @@ const struct drm_format_info *__drm_format_info(u32 format) {static const struct drm_format_info formats[] = { { .format =DRM_FORMAT_C8 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 }, + { .format =DRM_FORMAT_R8 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 },
Uh the depth = 0 on these is all a big lie, same for the 332 formats below. The only format which is officially depth = 8 is the C8 one. I'm not sure it's a great idea to announce others as depth = 8 ...
Might be good to throw a patch on top to drop these. Same for the ARGB1555 ones and it's permutations.
Anyway it's consistent with what's there.
Quoted 6 lines
drivers/gpu/drm/drm_fourcc.c +0
-0{ .format = DRM_FORMAT_RGB332, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, { .format = DRM_FORMAT_BGR233, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, { .format = DRM_FORMAT_XRGB4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 1/7] drm/fourcc: Add R8 to drm_format_info
Quoted 8 lines · Daniel Vetter
Quoted 7 lines · Noralf Trønnes
Add an entry in
drm_format_infofor the existing formatDRM_FORMAT_R8.Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_fourcc.c | 1 + 1 file changed, 1 insertion(+)
Quoted 13 lines
drivers/gpu/drm/drm_fourcc.c const struct drm_format_info *__drm_format_info(u32 format) · line 136
Quoted 9 lines
drivers/gpu/drm/drm_fourcc.c +1
-0@@ -133,6 +133,7 @@ const struct drm_format_info *__drm_format_info(u32 format) {static const struct drm_format_info formats[] = { { .format =DRM_FORMAT_C8 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 }, + { .format =DRM_FORMAT_R8 , .depth =8 , .num_planes =1 , .cpp = {1 ,0 ,0 }, .hsub =1 , .vsub =1 },Uh the depth = 0 on these is all a big lie, same for the 332 formats below. The only format which is officially depth = 8 is the C8 one. I'm not sure it's a great idea to announce others as depth = 8 ...
btw if you really want to go fancy, full dithering for these might not be a complete waste of effort to type it. Temporal dithering probably too tricky, and also too many folks don't like that.
-Daniel
Quoted 18 lines
Might be good to throw a patch on top to drop these. Same for the ARGB1555 ones and it's permutations.
Anyway it's consistent with what's there.
Reviewed-by Daniel Vetter <[email protected]>Quoted 6 lines
drivers/gpu/drm/drm_fourcc.c +0
-0{ .format = DRM_FORMAT_RGB332, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, { .format = DRM_FORMAT_BGR233, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, { .format = DRM_FORMAT_XRGB4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 },Signature · 1 line
2.32.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 2/7 drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
In reply to Noralf TrønnesAdd XRGB8888 emulation support for devices that can only do RGB332.
--- drivers/gpu/drm/drm_format_helper.c | 47 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 49 insertions(+)
drivers/gpu/drm/drm_format_helper.c +47 -0
@@ -135,6 +135,53 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_swab); +static void drm_fb_xrgb8888_to_rgb332_line (u8 *dbuf,u32 *sbuf,unsigned int pixels) +{ +unsigned int x; + +for (x =0 ; x < pixels; x++) + dbuf[x] = ((sbuf[x] &0x00e00000 ) >>16 ) | + ((sbuf[x] &0x0000e000 ) >>11 ) | + ((sbuf[x] &0x000000c0 ) >>6 ); +} + +/** +* drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer +* @dst: RGB332 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB332 devices that don't natively support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination is a small buffer +* containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb332_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb332); +static void drm_fb_xrgb8888_to_rgb565_line (u16 *dbuf,u32 *sbuf,unsigned int pixels,bool swab)
include/drm/drm_format_helper.h +2 -0
@@ -16,6 +16,8 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vadd struct drm_rect *clip);void drm_fb_swab (void *dst,void *src,struct drm_framebuffer *fb,struct drm_rect *clip,bool cached); +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *vaddr,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb565 (void *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab);
Signature · 1 line
2.32.0
Re: [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
Quoted 14 lines · Noralf Trønnes
Add XRGB8888 emulation support for devices that can only do RGB332.
Cc Thomas Zimmermann <[email protected]>Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_format_helper.c | 47 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 49 insertions(+)drivers/gpu/drm/drm_format_helper.c +0
-0
drivers/gpu/drm/drm_format_helper.c void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, · line 143
Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +6
-0@@ -135,6 +135,53 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_swab); +static void drm_fb_xrgb8888_to_rgb332_line (u8 *dbuf,u32 *sbuf,unsigned int pixels) +{ +unsigned int x; + +for (x =0 ; x < pixels; x++) + dbuf[x] = ((sbuf[x] & 0x00e00000) >> 16) |
I think for 2/3 bits correct rounding would be useful, not just masking. i.e. before you shift add 0x00100000 here, and similar below.
Also I just realized we've totally ignored endianess on these, which is not great, because strictly speaking all the drm_fourcc codes should be little endian. But I'm also not sure that's worth fixing ...
Either way, lgtm:
Quoted 60 lines
drivers/gpu/drm/drm_format_helper.c +41
-0+ ((sbuf[x] &0x0000e000 ) >>11 ) | + ((sbuf[x] &0x000000c0 ) >>6 ); +} + +/** +* drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer +* @dst: RGB332 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB332 devices that don't natively support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination is a small buffer +* containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb332_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb332); +static void drm_fb_xrgb8888_to_rgb565_line (u16 *dbuf,u32 *sbuf,unsigned int pixels,bool swab)include/drm/drm_format_helper.h +2
-0@@ -16,6 +16,8 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vadd struct drm_rect *clip);void drm_fb_swab (void *dst,void *src,struct drm_framebuffer *fb,struct drm_rect *clip,bool cached); +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *vaddr,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb565 (void *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab);Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
Quoted 3 lines · Daniel Vetter
Also I just realized we've totally ignored endianess on these, which is not great, because strictly speaking all the
drm_fourcccodes should be little endian. But I'm also not sure that's worth fixing ...
We discussed framebuffer endianess when introducing the driver, in the thread linked near the FIXME comment in the code.
I proposed an untested fix but Noralf wanted to wait for testing, which I find fair. I don't think anyone has tested on BE yet.
It's on my nice-to-have list, but not at the top, and has blockers, so if anyone else can test on BE please do. I'd recommend testing with an actual device to compare LE and BE behavior easily.
Kind regards
//Peter
Re: [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
In reply to Daniel VetterDen 17.08.2021 15.56, skrev Daniel Vetter:
Quoted 18 lines · Noralf Trønnes
Quoted 17 lines
Add XRGB8888 emulation support for devices that can only do RGB332.
Cc Thomas Zimmermann <[email protected]>Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_format_helper.c | 47 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 49 insertions(+)drivers/gpu/drm/drm_format_helper.c +0
-0@@ -135,6 +135,53 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_swab);
Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, · line 143
Quoted 6 lines
drivers/gpu/drm/drm_format_helper.c +6
-0+static void drm_fb_xrgb8888_to_rgb332_line (u8 *dbuf,u32 *sbuf,unsigned int pixels) +{ +unsigned int x; + +for (x =0 ; x < pixels; x++) + dbuf[x] = ((sbuf[x] & 0x00e00000) >> 16) |I think for 2/3 bits correct rounding would be useful, not just masking. i.e. before you shift add
0x00100000here, and similar below.
Math isn't my strongest side and my brain failed to turn this into code.
Quoted 4 lines
Also I just realized we've totally ignored endianess on these, which is not great, because strictly speaking all the
drm_fourcccodes should be little endian. But I'm also not sure that's worth fixing ...
Is it as simple as using le32_to_cpu()?
static void drm_fb_xrgb8888_to_rgb332_line(u8 *dbuf, __le32 *sbuf, unsigned int pixels)
{
unsigned int x;
u32 pix;
for (x = 0; x < pixels; x++) {
pix = le32_to_cpu(sbuf[x]);
dbuf[x] = ((pix & 0x00e00000) >> 16) |
((pix & 0x0000e000) >> 11) |
((pix & 0x000000c0) >> 6);
}
}Noralf.
Quoted 65 lines
Either way, lgtm:
Reviewed-by Daniel Vetter <[email protected]>Quoted 60 lines
drivers/gpu/drm/drm_format_helper.c +41
-0+ ((sbuf[x] &0x0000e000 ) >>11 ) | + ((sbuf[x] &0x000000c0 ) >>6 ); +} + +/** +* drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer +* @dst: RGB332 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB332 devices that don't natively support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination is a small buffer +* containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb332_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb332); +static void drm_fb_xrgb8888_to_rgb565_line (u16 *dbuf,u32 *sbuf,unsigned int pixels,bool swab)include/drm/drm_format_helper.h +2
-0@@ -16,6 +16,8 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vadd struct drm_rect *clip);void drm_fb_swab (void *dst,void *src,struct drm_framebuffer *fb,struct drm_rect *clip,bool cached); +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *vaddr,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb565 (void *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab);Signature · 1 line
2.32.0
Re: [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
Quoted 32 lines · Noralf Trønnes
Den 17.08.2021 15.56, skrev Daniel Vetter:
Quoted 18 lines · Noralf Trønnes
Quoted 17 lines
Add XRGB8888 emulation support for devices that can only do RGB332.
Cc Thomas Zimmermann <[email protected]>Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_format_helper.c | 47 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 49 insertions(+)drivers/gpu/drm/drm_format_helper.c +0
-0@@ -135,6 +135,53 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_swab);Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, · line 143
Quoted 6 lines
drivers/gpu/drm/drm_format_helper.c +6
-0+static void drm_fb_xrgb8888_to_rgb332_line (u8 *dbuf,u32 *sbuf,unsigned int pixels) +{ +unsigned int x; + +for (x =0 ; x < pixels; x++) + dbuf[x] = ((sbuf[x] & 0x00e00000) >> 16) |I think for 2/3 bits correct rounding would be useful, not just masking. i.e. before you shift add
0x00100000here, and similar below.
Quoted 1 line
Math isn't my strongest side and my brain failed to turn this into code.
Essentially add half of the lowest bit before you mask, so
((sbuf[x] + 0x10) & 0xe0 )
I dropped the shift to make it clear what's going on. If you're mask is 0xc0, then you simply add 0x20 before masking.
Quoted 6 lines
Quoted 4 lines
Also I just realized we've totally ignored endianess on these, which is not great, because strictly speaking all the
drm_fourcccodes should be little endian. But I'm also not sure that's worth fixing ...Is it as simple as using
le32_to_cpu()?
I think so.
Plus on any format that has u16 output we'd need a cpu_to_le16 wrapped around the entire thing.
-Daniel
Quoted 81 lines
static void
drm_fb_xrgb8888_to_rgb332_line(u8 *dbuf, __le32 *sbuf, unsigned int pixels){ unsigned int x; u32 pix; for (x = 0; x < pixels; x++) { pix = le32_to_cpu(sbuf[x]); dbuf[x] = ((pix & 0x00e00000) >> 16) | ((pix & 0x0000e000) >> 11) | ((pix & 0x000000c0) >> 6); } }Noralf.
Quoted 65 lines
Either way, lgtm:
Reviewed-by Daniel Vetter <[email protected]>Quoted 60 lines
drivers/gpu/drm/drm_format_helper.c +41
-0+ ((sbuf[x] &0x0000e000 ) >>11 ) | + ((sbuf[x] &0x000000c0 ) >>6 ); +} + +/** +* drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer +* @dst: RGB332 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB332 devices that don't natively support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination is a small buffer +* containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb332_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb332); +static void drm_fb_xrgb8888_to_rgb565_line (u16 *dbuf,u32 *sbuf,unsigned int pixels,bool swab)include/drm/drm_format_helper.h +2
-0@@ -16,6 +16,8 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vadd struct drm_rect *clip);void drm_fb_swab (void *dst,void *src,struct drm_framebuffer *fb,struct drm_rect *clip,bool cached); +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *vaddr,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb565 (void *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab);Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
Den 31.08.2021 14.23, skrev Daniel Vetter:
Quoted 33 lines · Noralf Trønnes
Quoted 32 lines
Den 17.08.2021 15.56, skrev Daniel Vetter:
Quoted 28 lines · Noralf Trønnes
Quoted 14 lines
Add XRGB8888 emulation support for devices that can only do RGB332.
Cc Thomas Zimmermann <[email protected]>Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_format_helper.c | 47 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 49 insertions(+)drivers/gpu/drm/drm_format_helper.c +0
-0drivers/gpu/drm/drm_format_helper.c void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, · line 143
Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +6
-0@@ -135,6 +135,53 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_swab); +static void drm_fb_xrgb8888_to_rgb332_line (u8 *dbuf,u32 *sbuf,unsigned int pixels) +{ +unsigned int x; + +for (x =0 ; x < pixels; x++) + dbuf[x] = ((sbuf[x] & 0x00e00000) >> 16) |I think for 2/3 bits correct rounding would be useful, not just masking. i.e. before you shift add
0x00100000here, and similar below.
Quoted 6 lines
Quoted 1 line
Math isn't my strongest side and my brain failed to turn this into code.
Essentially add half of the lowest bit before you mask, so
((sbuf[x] +
0x10) &0xe0)
But what if the value is 0xff, it overflows:
((0xff + 0x10) & 0xe0 ) == 0x00
Should it be OR?
((0xff | 0x10) & 0xe0 ) == 0xe0
Noralf.
Quoted 98 lines
I dropped the shift to make it clear what's going on. If you're mask is
0xc0, then you simply add0x20before masking.Quoted 6 lines
Quoted 4 lines
Also I just realized we've totally ignored endianess on these, which is not great, because strictly speaking all the
drm_fourcccodes should be little endian. But I'm also not sure that's worth fixing ...Is it as simple as using
le32_to_cpu()?I think so.
Plus on any format that has u16 output we'd need a
cpu_to_le16wrapped around the entire thing.
-DanielQuoted 81 lines
static void
drm_fb_xrgb8888_to_rgb332_line(u8 *dbuf, __le32 *sbuf, unsigned int pixels){ unsigned int x; u32 pix; for (x = 0; x < pixels; x++) { pix = le32_to_cpu(sbuf[x]); dbuf[x] = ((pix & 0x00e00000) >> 16) | ((pix & 0x0000e000) >> 11) | ((pix & 0x000000c0) >> 6); } }Noralf.
Quoted 65 lines
Either way, lgtm:
Reviewed-by Daniel Vetter <[email protected]>Quoted 60 lines
drivers/gpu/drm/drm_format_helper.c +41
-0+ ((sbuf[x] &0x0000e000 ) >>11 ) | + ((sbuf[x] &0x000000c0 ) >>6 ); +} + +/** +* drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer +* @dst: RGB332 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB332 devices that don't natively support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination is a small buffer +* containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb332_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb332); +static void drm_fb_xrgb8888_to_rgb565_line (u16 *dbuf,u32 *sbuf,unsigned int pixels,bool swab)include/drm/drm_format_helper.h +2
-0@@ -16,6 +16,8 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vadd struct drm_rect *clip);void drm_fb_swab (void *dst,void *src,struct drm_framebuffer *fb,struct drm_rect *clip,bool cached); +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *vaddr,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb565 (void *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab);Signature · 1 line
2.32.0
Re: [PATCH 2/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb332()
Quoted 36 lines · Noralf Trønnes
Den 31.08.2021 14.23, skrev Daniel Vetter:
Quoted 33 lines · Noralf Trønnes
Quoted 32 lines
Den 17.08.2021 15.56, skrev Daniel Vetter:
Quoted 28 lines · Noralf Trønnes
Quoted 14 lines
Add XRGB8888 emulation support for devices that can only do RGB332.
Cc Thomas Zimmermann <[email protected]>Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_format_helper.c | 47 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 49 insertions(+)drivers/gpu/drm/drm_format_helper.c +0
-0drivers/gpu/drm/drm_format_helper.c void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, · line 143
Quoted 9 lines
drivers/gpu/drm/drm_format_helper.c +6
-0@@ -135,6 +135,53 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb, }EXPORT_SYMBOL (drm_fb_swab); +static void drm_fb_xrgb8888_to_rgb332_line (u8 *dbuf,u32 *sbuf,unsigned int pixels) +{ +unsigned int x; + +for (x =0 ; x < pixels; x++) + dbuf[x] = ((sbuf[x] & 0x00e00000) >> 16) |I think for 2/3 bits correct rounding would be useful, not just masking. i.e. before you shift add
0x00100000here, and similar below.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Math isn't my strongest side and my brain failed to turn this into code.
Essentially add half of the lowest bit before you mask, so
((sbuf[x] +
0x10) &0xe0)But what if the value is
0xff, it overflows:
Your math is better than mine ...
Quoted 5 lines
((
0xff+0x10) &0xe0) ==0x00Should it be OR?
((
0xff|0x10) &0xe0) ==0xe0
Probably need a max on top to limit the overflow:
max(sbuf[x] + 0x10, 0xe)
But also maybe really not worth the head-scratching :-) -Daniel
Quoted 101 lines
Noralf.
Quoted 98 lines
I dropped the shift to make it clear what's going on. If you're mask is
0xc0, then you simply add0x20before masking.Quoted 6 lines
Quoted 4 lines
Also I just realized we've totally ignored endianess on these, which is not great, because strictly speaking all the
drm_fourcccodes should be little endian. But I'm also not sure that's worth fixing ...Is it as simple as using
le32_to_cpu()?I think so.
Plus on any format that has u16 output we'd need a
cpu_to_le16wrapped around the entire thing.
-DanielQuoted 81 lines
static void
drm_fb_xrgb8888_to_rgb332_line(u8 *dbuf, __le32 *sbuf, unsigned int pixels){ unsigned int x; u32 pix; for (x = 0; x < pixels; x++) { pix = le32_to_cpu(sbuf[x]); dbuf[x] = ((pix & 0x00e00000) >> 16) | ((pix & 0x0000e000) >> 11) | ((pix & 0x000000c0) >> 6); } }Noralf.
Quoted 65 lines
Either way, lgtm:
Reviewed-by Daniel Vetter <[email protected]>Quoted 60 lines
drivers/gpu/drm/drm_format_helper.c +41
-0+ ((sbuf[x] &0x0000e000 ) >>11 ) | + ((sbuf[x] &0x000000c0 ) >>6 ); +} + +/** +* drm_fb_xrgb8888_to_rgb332 - Convert XRGB8888 to RGB332 clip buffer +* @dst: RGB332 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB332 devices that don't natively support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination is a small buffer +* containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb332_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb332); +static void drm_fb_xrgb8888_to_rgb565_line (u16 *dbuf,u32 *sbuf,unsigned int pixels,bool swab)include/drm/drm_format_helper.h +2
-0@@ -16,6 +16,8 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vadd struct drm_rect *clip);void drm_fb_swab (void *dst,void *src,struct drm_framebuffer *fb,struct drm_rect *clip,bool cached); +void drm_fb_xrgb8888_to_rgb332 (void *dst,void *vaddr,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb565 (void *dst,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab);Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 3/7 drm/format-helper: Add drm_fb_xrgb8888_to_rgb888()
In reply to Noralf TrønnesAdd XRGB8888 emulation support for devices that can only do RGB888.
--- drivers/gpu/drm/drm_format_helper.c | 38 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 40 insertions(+)
drivers/gpu/drm/drm_format_helper.c +38 -0
@@ -297,6 +297,44 @@ static void drm_fb_xrgb8888_to_rgb888_line(u8 *dbuf, u32 *sbuf, } } +/** +* drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer +* @dst: RGB888 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer +* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB888 devices that don't natively +* support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination +* is a small buffer containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb888 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip) +{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb888_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width *3 ; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb888); +/** * drm_fb_xrgb8888_to_rgb888_dstclip - Convert XRGB8888 to RGB888 clip buffer * @dst: RGB565 destination buffer (iomem)
include/drm/drm_format_helper.h +2 -0
@@ -24,6 +24,8 @@ void drm_fb_xrgb8888_to_rgb565(void *dst, void *vaddr,void drm_fb_xrgb8888_to_rgb565_dstclip (void __iomem *dst,unsigned int dst_pitch,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab); +void drm_fb_xrgb8888_to_rgb888 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb888_dstclip (void __iomem *dst,unsigned int dst_pitch,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip);
Signature · 1 line
2.32.0
Re: [PATCH 3/7] drm/format-helper: Add drm_fb_xrgb8888_to_rgb888()
Quoted 22 lines · Noralf Trønnes
Add XRGB8888 emulation support for devices that can only do RGB888.
Cc Thomas Zimmermann <[email protected]>Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/drm_format_helper.c | 38 +++++++++++++++++++++++++++++ include/drm/drm_format_helper.h | 2 ++ 2 files changed, 40 insertions(+)drivers/gpu/drm/drm_format_helper.c +5
-0@@ -297,6 +297,44 @@ static void drm_fb_xrgb8888_to_rgb888_line(u8 *dbuf, u32 *sbuf, } } +/** +* drm_fb_xrgb8888_to_rgb888 - Convert XRGB8888 to RGB888 clip buffer +* @dst: RGB888 destination buffer +* @src: XRGB8888 source buffer +* @fb: DRM framebuffer
drivers/gpu/drm/drm_format_helper.c static void drm_fb_xrgb8888_to_rgb888_line(u8 *dbuf, u32 *sbuf, · line 314
Quoted 10 lines
drivers/gpu/drm/drm_format_helper.c +10
-0+* @clip: Clip rectangle area to copy +* +* Drivers can use this function for RGB888 devices that don't natively +* support XRGB8888. +* +* This function does not apply clipping on dst, i.e. the destination +* is a small buffer containing the clip rect only. +*/ +void drm_fb_xrgb8888_to_rgb888 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip)
I do wonder whether we really need all the combinations here. E.g. if we allow dst_pitch == 0 and just automatically pick this one here, and then paper over the __iomem differences with dma_buf_map we wouldn't need two different functions.
Just an idea.
Quoted 42 lines
drivers/gpu/drm/drm_format_helper.c +23
-0+{ +size_t width =drm_rect_width (clip); +size_t src_len = width *sizeof (u32); +unsigned int y; +void *sbuf; + +/* Use a buffer to speed up access on buffers with uncached read mapping (i.e. WC) */ + sbuf =kmalloc (src_len,GFP_KERNEL ); +if (!sbuf) +return ; + + src +=clip_offset (clip, fb->pitches[0 ],sizeof (u32)); +for (y =0 ; y <drm_rect_height (clip); y++) { +memcpy (sbuf, src, src_len); +drm_fb_xrgb8888_to_rgb888_line (dst, sbuf, width); + src += fb->pitches[0 ]; + dst += width *3 ; + } + +kfree (sbuf); +} +EXPORT_SYMBOL (drm_fb_xrgb8888_to_rgb888); +/** * drm_fb_xrgb8888_to_rgb888_dstclip - Convert XRGB8888 to RGB888 clip buffer * @dst: RGB565 destination buffer (iomem) include/drm/drm_format_helper.h +2
-0@@ -24,6 +24,8 @@ void drm_fb_xrgb8888_to_rgb565(void *dst, void *vaddr,void drm_fb_xrgb8888_to_rgb565_dstclip (void __iomem *dst,unsigned int dst_pitch,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip,bool swab); +void drm_fb_xrgb8888_to_rgb888 (void *dst,void *src,struct drm_framebuffer *fb, +struct drm_rect *clip);void drm_fb_xrgb8888_to_rgb888_dstclip (void __iomem *dst,unsigned int dst_pitch,void *vaddr,struct drm_framebuffer *fb,struct drm_rect *clip);Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
PATCH 4/7 drm/gud: Add GUD_PIXEL_FORMAT_R8
In reply to Noralf TrønnesAdd support for 8-bit greyscale format.
--- drivers/gpu/drm/gud/gud_drv.c | 2 ++ drivers/gpu/drm/gud/gud_internal.h | 4 ++++ drivers/gpu/drm/gud/gud_pipe.c | 2 ++ include/drm/gud.h | 4 ++-- 4 files changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/gud/gud_drv.c +2 -0
@@ -523,6 +523,8 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)switch (format) {case GUD_DRM_FORMAT_R1 : fallthrough; +case DRM_FORMAT_R8 : + fallthrough;case GUD_DRM_FORMAT_XRGB1111 :if (!xrgb8888_emulation_format) xrgb8888_emulation_format = info;
drivers/gpu/drm/gud/gud_internal.h +4 -0
@@ -80,6 +80,8 @@ static inline u8 gud_from_fourcc(u32 fourcc)switch (fourcc) {case GUD_DRM_FORMAT_R1 :return GUD_PIXEL_FORMAT_R1 ; +case DRM_FORMAT_R8 : +return GUD_PIXEL_FORMAT_R8 ;case GUD_DRM_FORMAT_XRGB1111 :return GUD_PIXEL_FORMAT_XRGB1111 ;case DRM_FORMAT_RGB565 :
@@ -98,6 +100,8 @@ static inline u32 gud_to_fourcc(u8 format)switch (format) {case GUD_PIXEL_FORMAT_R1 :return GUD_DRM_FORMAT_R1 ; +case GUD_PIXEL_FORMAT_R8 : +return DRM_FORMAT_R8 ;case GUD_PIXEL_FORMAT_XRGB1111 :return GUD_DRM_FORMAT_XRGB1111 ;case GUD_PIXEL_FORMAT_RGB565 :
drivers/gpu/drm/gud/gud_pipe.c +2 -0
@@ -189,6 +189,8 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, ret = -ENOMEM ; goto end_cpu_access; } + }else if (format->format ==DRM_FORMAT_R8 ) { +drm_fb_xrgb8888_to_gray8 (buf, vaddr, fb, rect); }else if (format->format ==DRM_FORMAT_RGB565 ) {drm_fb_xrgb8888_to_rgb565 (buf, vaddr, fb, rect,gud_is_big_endian ()); }else {
include/drm/gud.h +2 -2
@@ -246,8 +246,8 @@ struct gud_state_req {/* Get supported pixel formats as a byte array of GUD_PIXEL_FORMAT_* */ #define GUD_REQ_GET_FORMATS 0x40#define GUD_FORMATS_MAX_NUM 32 -/* R1 is a 1-bit monochrome transfer format presented to userspace as XRGB8888 */ -#define GUD_PIXEL_FORMAT_R1 0x01 +#define GUD_PIXEL_FORMAT_R1 0x01/* 1-bit monochrome */ +#define GUD_PIXEL_FORMAT_R8 0x08/* 8-bit greyscale */ #define GUD_PIXEL_FORMAT_XRGB1111 0x20#define GUD_PIXEL_FORMAT_RGB565 0x40#define GUD_PIXEL_FORMAT_XRGB8888 0x80
Signature · 1 line
2.32.0
PATCH 5/7 drm/gud: Add GUD_PIXEL_FORMAT_RGB332
In reply to Noralf TrønnesAdd support for the RGB332 pixel format.
--- drivers/gpu/drm/gud/gud_drv.c | 2 ++ drivers/gpu/drm/gud/gud_internal.h | 4 ++++ drivers/gpu/drm/gud/gud_pipe.c | 2 ++ include/drm/gud.h | 1 + 4 files changed, 9 insertions(+)
drivers/gpu/drm/gud/gud_drv.c +2 -0
@@ -526,6 +526,8 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)case DRM_FORMAT_R8 : fallthrough;case GUD_DRM_FORMAT_XRGB1111 : + fallthrough; +case DRM_FORMAT_RGB332 :if (!xrgb8888_emulation_format) xrgb8888_emulation_format = info;break ;
drivers/gpu/drm/gud/gud_internal.h +4 -0
@@ -84,6 +84,8 @@ static inline u8 gud_from_fourcc(u32 fourcc)return GUD_PIXEL_FORMAT_R8 ;case GUD_DRM_FORMAT_XRGB1111 :return GUD_PIXEL_FORMAT_XRGB1111 ; +case DRM_FORMAT_RGB332 : +return GUD_PIXEL_FORMAT_RGB332 ;case DRM_FORMAT_RGB565 :return GUD_PIXEL_FORMAT_RGB565 ;case DRM_FORMAT_XRGB8888 :
@@ -104,6 +106,8 @@ static inline u32 gud_to_fourcc(u8 format)return DRM_FORMAT_R8 ;case GUD_PIXEL_FORMAT_XRGB1111 :return GUD_DRM_FORMAT_XRGB1111 ; +case GUD_PIXEL_FORMAT_RGB332 : +return DRM_FORMAT_RGB332 ;case GUD_PIXEL_FORMAT_RGB565 :return DRM_FORMAT_RGB565 ;case GUD_PIXEL_FORMAT_XRGB8888 :
drivers/gpu/drm/gud/gud_pipe.c +2 -0
@@ -191,6 +191,8 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb, } }else if (format->format ==DRM_FORMAT_R8 ) {drm_fb_xrgb8888_to_gray8 (buf, vaddr, fb, rect); + }else if (format->format ==DRM_FORMAT_RGB332 ) { +drm_fb_xrgb8888_to_rgb332 (buf, vaddr, fb, rect); }else if (format->format ==DRM_FORMAT_RGB565 ) {drm_fb_xrgb8888_to_rgb565 (buf, vaddr, fb, rect,gud_is_big_endian ()); }else {
include/drm/gud.h +1 -0
@@ -249,6 +249,7 @@ struct gud_state_req {#define GUD_PIXEL_FORMAT_R1 0x01/* 1-bit monochrome */ #define GUD_PIXEL_FORMAT_R8 0x08/* 8-bit greyscale */ #define GUD_PIXEL_FORMAT_XRGB1111 0x20 +#define GUD_PIXEL_FORMAT_RGB332 0x30#define GUD_PIXEL_FORMAT_RGB565 0x40#define GUD_PIXEL_FORMAT_XRGB8888 0x80#define GUD_PIXEL_FORMAT_ARGB8888 0x81
Signature · 1 line
2.32.0
PATCH 6/7 drm/gud: Add GUD_PIXEL_FORMAT_RGB888
In reply to Noralf TrønnesAdd support for the RGB888 pixel format.
--- drivers/gpu/drm/gud/gud_drv.c | 2 ++ drivers/gpu/drm/gud/gud_internal.h | 4 ++++ drivers/gpu/drm/gud/gud_pipe.c | 2 ++ include/drm/gud.h | 1 + 4 files changed, 9 insertions(+)
drivers/gpu/drm/gud/gud_drv.c +2 -0
@@ -528,6 +528,8 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)case GUD_DRM_FORMAT_XRGB1111 : fallthrough;case DRM_FORMAT_RGB332 : + fallthrough; +case DRM_FORMAT_RGB888 :if (!xrgb8888_emulation_format) xrgb8888_emulation_format = info;break ;
drivers/gpu/drm/gud/gud_internal.h +4 -0
@@ -88,6 +88,8 @@ static inline u8 gud_from_fourcc(u32 fourcc)return GUD_PIXEL_FORMAT_RGB332 ;case DRM_FORMAT_RGB565 :return GUD_PIXEL_FORMAT_RGB565 ; +case DRM_FORMAT_RGB888 : +return GUD_PIXEL_FORMAT_RGB888 ;case DRM_FORMAT_XRGB8888 :return GUD_PIXEL_FORMAT_XRGB8888 ;case DRM_FORMAT_ARGB8888 :
@@ -110,6 +112,8 @@ static inline u32 gud_to_fourcc(u8 format)return DRM_FORMAT_RGB332 ;case GUD_PIXEL_FORMAT_RGB565 :return DRM_FORMAT_RGB565 ; +case GUD_PIXEL_FORMAT_RGB888 : +return DRM_FORMAT_RGB888 ;case GUD_PIXEL_FORMAT_XRGB8888 :return DRM_FORMAT_XRGB8888 ;case GUD_PIXEL_FORMAT_ARGB8888 :
drivers/gpu/drm/gud/gud_pipe.c +2 -0
@@ -195,6 +195,8 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,drm_fb_xrgb8888_to_rgb332 (buf, vaddr, fb, rect); }else if (format->format ==DRM_FORMAT_RGB565 ) {drm_fb_xrgb8888_to_rgb565 (buf, vaddr, fb, rect,gud_is_big_endian ()); + }else if (format->format ==DRM_FORMAT_RGB888 ) { +drm_fb_xrgb8888_to_rgb888 (buf, vaddr, fb, rect); }else { len =gud_xrgb8888_to_color (buf, format, vaddr, fb, rect); }
include/drm/gud.h +1 -0
@@ -251,6 +251,7 @@ struct gud_state_req {#define GUD_PIXEL_FORMAT_XRGB1111 0x20#define GUD_PIXEL_FORMAT_RGB332 0x30#define GUD_PIXEL_FORMAT_RGB565 0x40 +#define GUD_PIXEL_FORMAT_RGB888 0x50#define GUD_PIXEL_FORMAT_XRGB8888 0x80#define GUD_PIXEL_FORMAT_ARGB8888 0x81
Signature · 1 line
2.32.0
PATCH 7/7 drm/gud: Add module parameter to control emulation: xrgb8888
In reply to Noralf TrønnesFor devices that don't support XRGB8888 give the user the ability to choose what's most important: Color depth or frames per second.
Add an 'xrgb8888' module parameter to override the emulation format.
Assume the user wants full control if xrgb8888 is set and don't set DRM_CAP_DUMB_PREFERRED_DEPTH if RGB565 is supported (AFAIK only X.org supports this).
--- drivers/gpu/drm/gud/gud_drv.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/gpu/drm/gud/gud_drv.c +10 -3
@@ -30,6 +30,10 @@#include "gud_internal.h" +static int gud_xrgb8888; +module_param_named (xrgb8888, gud_xrgb8888, int,0644 ); +MODULE_PARM_DESC (xrgb8888,"XRGB8888 emulation format: GUD_PIXEL_FORMAT_* value, 0=auto, -1=disable [default=auto]" ); +/* Only used internally */ static const struct drm_format_info gud_drm_format_r1 = { .format =GUD_DRM_FORMAT_R1 ,
@@ -530,12 +534,12 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)case DRM_FORMAT_RGB332 : fallthrough;case DRM_FORMAT_RGB888 : -if (!xrgb8888_emulation_format) +if (!gud_xrgb8888 && !xrgb8888_emulation_format) xrgb8888_emulation_format = info;break ;case DRM_FORMAT_RGB565 : rgb565_supported = true; -if (!xrgb8888_emulation_format) +if (!gud_xrgb8888 && !xrgb8888_emulation_format) xrgb8888_emulation_format = info;break ;case DRM_FORMAT_XRGB8888 :
@@ -543,6 +547,9 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)break ; } +if (gud_xrgb8888 == formats_dev[i]) + xrgb8888_emulation_format = info; + fmt_buf_size =drm_format_info_min_pitch (info,0 , drm->mode_config.max_width) * drm->mode_config.max_height; max_buffer_size =max (max_buffer_size, fmt_buf_size);
@@ -559,7 +566,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) }/* Prefer speed over color depth */ -if (rgb565_supported) +if (!gud_xrgb8888 && rgb565_supported) drm->mode_config.preferred_depth =16 ;if (!xrgb8888_supported && xrgb8888_emulation_format) {
Signature · 1 line
2.32.0
Re: [PATCH 7/7] drm/gud: Add module parameter to control emulation: xrgb8888
Quoted 30 lines · Noralf Trønnes
For devices that don't support XRGB8888 give the user the ability to choose what's most important: Color depth or frames per second.
Add an 'xrgb8888' module parameter to override the emulation format.
Assume the user wants full control if xrgb8888 is set and don't set
DRM_CAP_DUMB_PREFERRED_DEPTHif RGB565 is supported (AFAIK only X.org supports this).Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/gud/gud_drv.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/gud/gud_drv.c +4
-0@@ -30,6 +30,10 @@#include "gud_internal.h" +static int gud_xrgb8888; +module_param_named (xrgb8888, gud_xrgb8888, int,0644 ); +MODULE_PARM_DESC (xrgb8888,"XRGB8888 emulation format: GUD_PIXEL_FORMAT_* value, 0=auto, -1=disable [default=auto]" ); +/* Only used internally */ static const struct drm_format_info gud_drm_format_r1 = { .format =GUD_DRM_FORMAT_R1 ,
drivers/gpu/drm/gud/gud_drv.c static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) · line 538
Quoted 6 lines
drivers/gpu/drm/gud/gud_drv.c +1
-1@@ -530,12 +534,12 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)case DRM_FORMAT_RGB332 : fallthrough;case DRM_FORMAT_RGB888 : -if (!xrgb8888_emulation_format) +if (!gud_xrgb8888 && !xrgb8888_emulation_format) xrgb8888_emulation_format = info;
Shouldn't the emulation format be per drm_device instance? -Daniel
Quoted 30 lines
drivers/gpu/drm/gud/gud_drv.c +5
-2break ;case DRM_FORMAT_RGB565 : rgb565_supported = true; -if (!xrgb8888_emulation_format) +if (!gud_xrgb8888 && !xrgb8888_emulation_format) xrgb8888_emulation_format = info;break ;case DRM_FORMAT_XRGB8888 :@@ -543,6 +547,9 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)break ; } +if (gud_xrgb8888 == formats_dev[i]) + xrgb8888_emulation_format = info; + fmt_buf_size =drm_format_info_min_pitch (info,0 , drm->mode_config.max_width) * drm->mode_config.max_height; max_buffer_size =max (max_buffer_size, fmt_buf_size);@@ -559,7 +566,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) }/* Prefer speed over color depth */ -if (rgb565_supported) +if (!gud_xrgb8888 && rgb565_supported) drm->mode_config.preferred_depth =16 ;if (!xrgb8888_supported && xrgb8888_emulation_format) {Signature · 1 line
2.32.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH 7/7] drm/gud: Add module parameter to control emulation: xrgb8888
Den 17.08.2021 15.49, skrev Daniel Vetter:
Quoted 23 lines · Noralf Trønnes
Quoted 22 lines
For devices that don't support XRGB8888 give the user the ability to choose what's most important: Color depth or frames per second.
Add an 'xrgb8888' module parameter to override the emulation format.
Assume the user wants full control if xrgb8888 is set and don't set
DRM_CAP_DUMB_PREFERRED_DEPTHif RGB565 is supported (AFAIK only X.org supports this).Signed-off-by Noralf Trønnes <[email protected]>--- drivers/gpu/drm/gud/gud_drv.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/gpu/drm/gud/gud_drv.c +0
-0@@ -30,6 +30,10 @@#include "gud_internal.h"
Quoted 16 lines
Quoted 8 lines
drivers/gpu/drm/gud/gud_drv.c +4
-0+static int gud_xrgb8888; +module_param_named (xrgb8888, gud_xrgb8888, int,0644 ); +MODULE_PARM_DESC (xrgb8888,"XRGB8888 emulation format: GUD_PIXEL_FORMAT_* value, 0=auto, -1=disable [default=auto]" ); +/* Only used internally */ static const struct drm_format_info gud_drm_format_r1 = { .format =GUD_DRM_FORMAT_R1 ,drivers/gpu/drm/gud/gud_drv.c static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) · line 538
Quoted 6 lines
drivers/gpu/drm/gud/gud_drv.c +1
-1@@ -530,12 +534,12 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)case DRM_FORMAT_RGB332 : fallthrough;case DRM_FORMAT_RGB888 : -if (!xrgb8888_emulation_format) +if (!gud_xrgb8888 && !xrgb8888_emulation_format) xrgb8888_emulation_format = info;Shouldn't the emulation format be per
drm_deviceinstance?
Ideally yes, this happens during probe so I can only use a module parameter and I don't know how to differenciate the devices since the DRM minor is unknown at this point and implementing filtering on the various USB properties (VID:PID, serial number,..) will involve a lot of code. So I've kept it simple. It can be expanded on later should someone come up with a clever idea.
Noralf.
Quoted 33 lines
-Daniel
Quoted 30 lines
drivers/gpu/drm/gud/gud_drv.c +5
-2break ;case DRM_FORMAT_RGB565 : rgb565_supported = true; -if (!xrgb8888_emulation_format) +if (!gud_xrgb8888 && !xrgb8888_emulation_format) xrgb8888_emulation_format = info;break ;case DRM_FORMAT_XRGB8888 :@@ -543,6 +547,9 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id)break ; } +if (gud_xrgb8888 == formats_dev[i]) + xrgb8888_emulation_format = info; + fmt_buf_size =drm_format_info_min_pitch (info,0 , drm->mode_config.max_width) * drm->mode_config.max_height; max_buffer_size =max (max_buffer_size, fmt_buf_size);@@ -559,7 +566,7 @@ static int gud_probe(struct usb_interface *intf, const struct usb_device_id *id) }/* Prefer speed over color depth */ -if (rgb565_supported) +if (!gud_xrgb8888 && rgb565_supported) drm->mode_config.preferred_depth =16 ;if (!xrgb8888_supported && xrgb8888_emulation_format) {Signature · 1 line
2.32.0