Add DRM pixel blend mode support to R-Car DU
Subsystems (5)
cover Add DRM pixel blend mode support to R-Car DU
The series of patches adds support for DRM pixel blend mode to R-Car DU. The current R-Car DU implicitly supports "Coverage" only.
Unfortunately, this changes the default blending mode of R-Car DU to "Pre-multiplied" which is the default when pixel blend mode is supported.
Takanari Hayama (3):
media: vsp1: save pixel alpha info in vsp1_rwpf
media: vsp1: add blend mode support
drm: rcar-du: Add DRM blend mode support
drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 17 +++++++++++++++++ drivers/media/platform/renesas/vsp1/vsp1_drm.c | 12 ++++++++++++ drivers/media/platform/renesas/vsp1/vsp1_rpf.c | 6 +++--- drivers/media/platform/renesas/vsp1/vsp1_rwpf.h | 2 ++ include/media/vsp1.h | 14 ++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/3 media: vsp1: save pixel alpha info in vsp1_rwpf
In order to support DRM blend mode, we need to able to override pixel alpha flag. When DRM_MODE_BLEND_PIXEL_NONE is desired, we'd like to let VSP1 to ignore the pixel alpha by overriding the flag.
--- drivers/media/platform/renesas/vsp1/vsp1_drm.c | 1 + drivers/media/platform/renesas/vsp1/vsp1_rpf.c | 6 +++--- drivers/media/platform/renesas/vsp1/vsp1_rwpf.h | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-)
drivers/media/platform/renesas/vsp1/vsp1_drm.c +1 -0
@@ -600,6 +600,7 @@ static int vsp1_du_pipeline_set_rwpf_format(struct vsp1_device *vsp1, rwpf->format.num_planes = fmtinfo->planes; rwpf->format.plane_fmt[0 ].bytesperline = pitch; rwpf->format.plane_fmt[1 ].bytesperline = pitch / chroma_hsub; + rwpf->pixel_alpha = fmtinfo->alpha;return 0 ; }
drivers/media/platform/renesas/vsp1/vsp1_rpf.c +3 -3
@@ -152,13 +152,13 @@ static void rpf_configure_stream(struct vsp1_entity *entity,* In all cases, disable color keying. */ vsp1_rpf_write (rpf, dlb,VI6_RPF_ALPH_SEL ,VI6_RPF_ALPH_SEL_AEXT_EXT | - (fmtinfo->alpha ?VI6_RPF_ALPH_SEL_ASEL_PACKED - :VI6_RPF_ALPH_SEL_ASEL_FIXED )); + (rpf->pixel_alpha ?VI6_RPF_ALPH_SEL_ASEL_PACKED + :VI6_RPF_ALPH_SEL_ASEL_FIXED ));if (entity->vsp1->info->gen ==3 ) {u32 mult; -if (fmtinfo->alpha) { +if (rpf->pixel_alpha) {/* * When the input contains an alpha channel enable the * alpha multiplier. If the input is premultiplied we
drivers/media/platform/renesas/vsp1/vsp1_rwpf.h +2 -0
@@ -43,6 +43,8 @@ struct vsp1_rwpf {const struct vsp1_format_info *fmtinfo;unsigned int brx_input; +bool pixel_alpha; +unsigned int alpha;u32 mult_alpha;
Signature · 1 line
2.25.1
Re: [PATCH 1/3] media: vsp1: save pixel alpha info in vsp1_rwpf
Hello Hayama-san,
Thank you for the patch (and sorry for the long delay).
Quoted 34 lines · Takanari Hayama
In order to support DRM blend mode, we need to able to override pixel alpha flag. When
DRM_MODE_BLEND_PIXEL_NONEis desired, we'd like to let VSP1 to ignore the pixel alpha by overriding the flag.Signed-off-by Takanari Hayama <[email protected]>--- drivers/media/platform/renesas/vsp1/vsp1_drm.c | 1 + drivers/media/platform/renesas/vsp1/vsp1_rpf.c | 6 +++--- drivers/media/platform/renesas/vsp1/vsp1_rwpf.h | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-)drivers/media/platform/renesas/vsp1/vsp1_drm.c +1
-0@@ -600,6 +600,7 @@ static int vsp1_du_pipeline_set_rwpf_format(struct vsp1_device *vsp1, rwpf->format.num_planes = fmtinfo->planes; rwpf->format.plane_fmt[0 ].bytesperline = pitch; rwpf->format.plane_fmt[1 ].bytesperline = pitch / chroma_hsub; + rwpf->pixel_alpha = fmtinfo->alpha;return 0 ; }drivers/media/platform/renesas/vsp1/vsp1_rpf.c +1
-2@@ -152,13 +152,13 @@ static void rpf_configure_stream(struct vsp1_entity *entity,* In all cases, disable color keying. */ vsp1_rpf_write(rpf, dlb, VI6_RPF_ALPH_SEL, VI6_RPF_ALPH_SEL_AEXT_EXT | - (fmtinfo->alpha ?VI6_RPF_ALPH_SEL_ASEL_PACKED - :VI6_RPF_ALPH_SEL_ASEL_FIXED )); + (rpf->pixel_alpha ? VI6_RPF_ALPH_SEL_ASEL_PACKED
drivers/media/platform/renesas/vsp1/vsp1_rpf.c static void rpf_configure_stream(struct vsp1_entity *entity, · line 164
Quoted 10 lines
drivers/media/platform/renesas/vsp1/vsp1_rpf.c +2
-1+ : VI6_RPF_ALPH_SEL_ASEL_FIXED));if (entity->vsp1->info->gen ==3 ) {u32 mult; -if (fmtinfo->alpha) { +if (rpf->pixel_alpha) {/* * When the input contains an alpha channel enable the * alpha multiplier. If the input is premultiplied we
From a DRM point of view this looks fine. vsp1_du_pipeline_set_rwpf_format() is called upon .atomic_update(), and rpf_configure_stream() upon .atomic_flush(), and every update is guaranteed to be followed by a flush (through code paths that are way too convoluted, but that's a story for a different day).
However, VSP instances that are exposed through V4L2 will see a regression with this patch. rwpf->pixel_alpha will never be set, so alpha-enabled formats will break. Several test case from
https://git.ideasonboard.com/renesas/vsp-tests.git report failures, for instance
# ./vsp-unit-test-0001.sh Testing WPF packing in RGB332: pass Testing WPF packing in ARGB555: pass Testing WPF packing in XRGB555: pass Testing WPF packing in RGB565: pass Testing WPF packing in BGR24: pass Testing WPF packing in RGB24: pass Testing WPF packing in ABGR32: fail Testing WPF packing in ARGB32: fail Testing WPF packing in XBGR32: pass Testing WPF packing in XRGB32: pass
It seems that this could be fixed fairly easily by setting rpf->pixel_alpha in vsp1_video_set_format():
drivers/media/platform/renesas/vsp1/vsp1_video.c +1 -0
@@ -1015,6 +1015,7 @@ vsp1_video_set_format(struct file *file, void *fh, struct v4l2_format *format) video->rwpf->format = format->fmt.pix_mp; video->rwpf->fmtinfo = info; + video->rwpf->pixel_alpha = info->alpha; done:mutex_unlock (&video->lock);
I've tested that and it fixes the tests, so with this change,
No need to submit a v2 if no other changes are needed in subsequent patches, I can apply this change when merging the patches.
Quoted 13 lines
drivers/media/platform/renesas/vsp1/vsp1_rwpf.h +2
-0@@ -43,6 +43,8 @@ struct vsp1_rwpf {const struct vsp1_format_info *fmtinfo;unsigned int brx_input; +bool pixel_alpha; +unsigned int alpha;u32 mult_alpha;
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 2/3 media: vsp1: add blend mode support
In reply to Takanari HayamaTo support DRM blend mode in R-Car DU driver, we must add blend mode support in VSP1. Although VSP1 hardware is capable to support all blend mode defined in DRM, the current R-Car DU driver implicitly supports DRM_MODE_BLEND_COVERAGE only.
We add a new property to vsp1_du_atomic_config, so that R-Car DU driver can pass the desired blend mode.
--- drivers/media/platform/renesas/vsp1/vsp1_drm.c | 11 +++++++++++ include/media/vsp1.h | 14 ++++++++++++++ 2 files changed, 25 insertions(+)
drivers/media/platform/renesas/vsp1/vsp1_drm.c +11 -0
@@ -861,6 +861,17 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index, vsp1->drm->inputs[rpf_index].compose = cfg->dst; vsp1->drm->inputs[rpf_index].zpos = cfg->zpos; +switch (cfg->blend_mode) { +case VSP1_DU_BLEND_MODE_PREMULTI : + rpf->format.flags =V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ; +break ; +case VSP1_DU_BLEND_MODE_PIXEL_NONE : + rpf->pixel_alpha = false; + fallthrough; +case VSP1_DU_BLEND_MODE_COVERAGE : + rpf->format.flags =0 ; + } + drm_pipe->pipe.inputs[rpf_index] = rpf;return 0 ;
include/media/vsp1.h +14 -0
@@ -42,6 +42,18 @@ struct vsp1_du_lif_config {int vsp1_du_setup_lif (struct device *dev,unsigned int pipe_index,const struct vsp1_du_lif_config *cfg); +/** +* enum vsp1_du_blend_mode - Pixel blend mode +* @VSP1_DU_BLEND_MODE_PREMULTI: Pixel alpha is pre-mutiplied +* @VSP1_DU_BLEND_MODE_COVERAGE: Pixel alpha is not pre-mutiplied +* @VSP1_DU_BLEND_MODE_PIXEL_NONE: Ignores the pixel alpha +*/ +enum vsp1_du_blend_mode { +VSP1_DU_BLEND_MODE_PREMULTI , +VSP1_DU_BLEND_MODE_COVERAGE , +VSP1_DU_BLEND_MODE_PIXEL_NONE , +}; +/** * struct vsp1_du_atomic_config - VSP atomic configuration parameters * @pixelformat: plane pixel format (V4L2 4CC)
@@ -51,6 +63,7 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,* @dst: destination rectangle on the display (integer coordinates) * @alpha: alpha value (0: fully transparent, 255: fully opaque) * @zpos: Z position of the plane (from 0 to number of planes minus 1) +* @blend_mode: Pixel blend mode of the plane */ struct vsp1_du_atomic_config {u32 pixelformat;
@@ -60,6 +73,7 @@ struct vsp1_du_atomic_config {struct v4l2_rect dst;unsigned int alpha;unsigned int zpos; +enum vsp1_du_blend_mode blend_mode; };/**
Signature · 1 line
2.25.1
Laurent Pinchart
maintainerRe: [PATCH 2/3] media: vsp1: add blend mode support
Hi Hayama-san,
Thank you for the patch.
Quoted 22 lines · Takanari Hayama
To support DRM blend mode in R-Car DU driver, we must add blend mode support in VSP1. Although VSP1 hardware is capable to support all blend mode defined in DRM, the current R-Car DU driver implicitly supports
DRM_MODE_BLEND_COVERAGEonly.We add a new property to
vsp1_du_atomic_config, so that R-Car DU driver can pass the desired blend mode.Signed-off-by Takanari Hayama <[email protected]>--- drivers/media/platform/renesas/vsp1/vsp1_drm.c | 11 +++++++++++ include/media/vsp1.h | 14 ++++++++++++++ 2 files changed, 25 insertions(+)drivers/media/platform/renesas/vsp1/vsp1_drm.c +0
-0@@ -861,6 +861,17 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index, vsp1->drm->inputs[rpf_index].compose = cfg->dst; vsp1->drm->inputs[rpf_index].zpos = cfg->zpos;
drivers/media/platform/renesas/vsp1/vsp1_drm.c int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index, · line 873
Quoted 10 lines
drivers/media/platform/renesas/vsp1/vsp1_drm.c +10
-0+switch (cfg->blend_mode) { +case VSP1_DU_BLEND_MODE_PREMULTI : + rpf->format.flags =V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ; +break ; +case VSP1_DU_BLEND_MODE_PIXEL_NONE : + rpf->pixel_alpha = false; + fallthrough; +case VSP1_DU_BLEND_MODE_COVERAGE : + rpf->format.flags =0 ; + }
This should work, but wouldn't it be simpler to override the format passed in cfg->pixelformat in rcar_du_vsp_plane_setup() with the non-alpha variant when state->state.pixel_blend_mode is set to DRM_MODE_BLEND_PIXEL_NONE ? That way you could drop rpf->pixel_alpha, turn cfg->blend_mode into a premult bool flag, and drop the vsp1_du_blend_mode enum. There's only three formats with an alpha channel that the rcar-du driver supports (DRM_FORMAT_ARGB4444, DRM_FORMAT_ARGB1555 and DRM_FORMAT_ARGB8888), so the override could be as simple as a switch (state->format->fourcc) when the blend mode is NONE.
Quoted 43 lines
drivers/media/platform/renesas/vsp1/vsp1_drm.c +1
-0+ drm_pipe->pipe.inputs[rpf_index] = rpf;return 0 ;include/media/vsp1.h +14
-0@@ -42,6 +42,18 @@ struct vsp1_du_lif_config {int vsp1_du_setup_lif (struct device *dev,unsigned int pipe_index,const struct vsp1_du_lif_config *cfg); +/** +* enum vsp1_du_blend_mode - Pixel blend mode +* @VSP1_DU_BLEND_MODE_PREMULTI: Pixel alpha is pre-mutiplied +* @VSP1_DU_BLEND_MODE_COVERAGE: Pixel alpha is not pre-mutiplied +* @VSP1_DU_BLEND_MODE_PIXEL_NONE: Ignores the pixel alpha +*/ +enum vsp1_du_blend_mode { +VSP1_DU_BLEND_MODE_PREMULTI , +VSP1_DU_BLEND_MODE_COVERAGE , +VSP1_DU_BLEND_MODE_PIXEL_NONE , +}; +/** * struct vsp1_du_atomic_config - VSP atomic configuration parameters * @pixelformat: plane pixel format (V4L2 4CC) @@ -51,6 +63,7 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,* @dst: destination rectangle on the display (integer coordinates) * @alpha: alpha value (0: fully transparent, 255: fully opaque) * @zpos: Z position of the plane (from 0 to number of planes minus 1) +* @blend_mode: Pixel blend mode of the plane */ struct vsp1_du_atomic_config {u32 pixelformat;@@ -60,6 +73,7 @@ struct vsp1_du_atomic_config {struct v4l2_rect dst;unsigned int alpha;unsigned int zpos; +enum vsp1_du_blend_mode blend_mode; };/**
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 2/3] media: vsp1: add blend mode support
Hi Laurent,
Thank you for reviewing the patch.
Quoted 42 lines
2022/07/31 7:36、Laurent Pinchart <[email protected]>のメール:
Hi Hayama-san,
Thank you for the patch.
Quoted 22 lines · Takanari Hayama
To support DRM blend mode in R-Car DU driver, we must add blend mode support in VSP1. Although VSP1 hardware is capable to support all blend mode defined in DRM, the current R-Car DU driver implicitly supports
DRM_MODE_BLEND_COVERAGEonly.We add a new property to
vsp1_du_atomic_config, so that R-Car DU driver can pass the desired blend mode.Signed-off-by Takanari Hayama <[email protected]>---
drivers/media/platform/renesas/vsp1/vsp1_drm.c| 11 +++++++++++include/media/vsp1.h| 14 ++++++++++++++2 files changed, 25 insertions(+)drivers/media/platform/renesas/vsp1/vsp1_drm.c +0
-0@@ -861,6 +861,17 @@ int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index, vsp1->drm->inputs[rpf_index].compose = cfg->dst; vsp1->drm->inputs[rpf_index].zpos = cfg->zpos;drivers/media/platform/renesas/vsp1/vsp1_drm.c int vsp1_du_atomic_update(struct device *dev, unsigned int pipe_index, · line 873
Quoted 10 lines
drivers/media/platform/renesas/vsp1/vsp1_drm.c +10
-0+switch (cfg->blend_mode) { +case VSP1_DU_BLEND_MODE_PREMULTI : + rpf->format.flags =V4L2_PIX_FMT_FLAG_PREMUL_ALPHA ; +break ; +case VSP1_DU_BLEND_MODE_PIXEL_NONE : + rpf->pixel_alpha = false; + fallthrough; +case VSP1_DU_BLEND_MODE_COVERAGE : + rpf->format.flags =0 ; + }This should work, but wouldn't it be simpler to override the format passed in
cfg->pixelformatinrcar_du_vsp_plane_setup()with the
Quoted 8 lines
non-alpha variant when
state->state.pixel_blend_modeis set toDRM_MODE_BLEND_PIXEL_NONE? That way you could droprpf->pixel_alpha, turncfg->blend_modeinto a premult bool flag, and drop thevsp1_du_blend_modeenum. There's only three formats with an alpha channel that the rcar-du driver supports (DRM_FORMAT_ARGB4444,DRM_FORMAT_ARGB1555andDRM_FORMAT_ARGB8888), so the override could be as simple as a switch (state->format->fourcc) when the blend mode is NONE.
You’re right. I’ll make the suggested changes and submit V2.
Quoted 43 lines
Quoted 43 lines
drivers/media/platform/renesas/vsp1/vsp1_drm.c +1
-0+ drm_pipe->pipe.inputs[rpf_index] = rpf;return 0 ;include/media/vsp1.h +14
-0@@ -42,6 +42,18 @@ struct vsp1_du_lif_config {int vsp1_du_setup_lif (struct device *dev,unsigned int pipe_index,const struct vsp1_du_lif_config *cfg); +/** +* enum vsp1_du_blend_mode - Pixel blend mode +* @VSP1_DU_BLEND_MODE_PREMULTI: Pixel alpha is pre-mutiplied +* @VSP1_DU_BLEND_MODE_COVERAGE: Pixel alpha is not pre-mutiplied +* @VSP1_DU_BLEND_MODE_PIXEL_NONE: Ignores the pixel alpha +*/ +enum vsp1_du_blend_mode { +VSP1_DU_BLEND_MODE_PREMULTI , +VSP1_DU_BLEND_MODE_COVERAGE , +VSP1_DU_BLEND_MODE_PIXEL_NONE , +}; +/** * struct vsp1_du_atomic_config - VSP atomic configuration parameters * @pixelformat: plane pixel format (V4L2 4CC) @@ -51,6 +63,7 @@ int vsp1_du_setup_lif(struct device *dev, unsigned int pipe_index,* @dst: destination rectangle on the display (integer coordinates) * @alpha: alpha value (0: fully transparent, 255: fully opaque) * @zpos: Z position of the plane (from 0 to number of planes minus 1) +* @blend_mode: Pixel blend mode of the plane */ struct vsp1_du_atomic_config {u32 pixelformat;@@ -60,6 +73,7 @@ struct vsp1_du_atomic_config {struct v4l2_rect dst;unsigned int alpha;unsigned int zpos; +enum vsp1_du_blend_mode blend_mode; };
Quoted 6 lines
Quoted 1 line
include/media/vsp1.h +0
-0/** Signature · 3 lines
Regards, Laurent Pinchart
Cheers,
Takanari Hayama, Ph.D. <[email protected]>
IGEL Co., Ltd.
https://www.igel.co.jp/
PATCH 3/3 drm: rcar-du: Add DRM blend mode support
In reply to Takanari HayamaR-Car DU supports different blend modes via VSP1. Add DRM blend mode supports to make it configurable.
As drm_plane_create_blend_mode_property() creates the blend mode property with the default value of DRM_MODE_BLEND_PREMULTI, it changes the default blending behavior on R-Car DU. The rcar-du's blend mode was same as DRM_MODE_BLEND_COVERAGE, i.e., pixel color values have not been pre-multitplied.
--- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
drivers/gpu/drm/rcar-du/rcar_du_vsp.c +17 -0
@@ -170,6 +170,18 @@ static void rcar_du_vsp_plane_setup(struct rcar_du_vsp_plane *plane) format =rcar_du_format_info (state->format->fourcc); cfg.pixelformat = format->v4l2; +switch (state->state.pixel_blend_mode) { +case DRM_MODE_BLEND_PREMULTI : + cfg.blend_mode =VSP1_DU_BLEND_MODE_PREMULTI ; +break ; +case DRM_MODE_BLEND_COVERAGE : + cfg.blend_mode =VSP1_DU_BLEND_MODE_COVERAGE ; +break ; +case DRM_MODE_BLEND_PIXEL_NONE : + cfg.blend_mode =VSP1_DU_BLEND_MODE_PIXEL_NONE ; +break ; + } +vsp1_du_atomic_update (plane->vsp->vsp, crtc->vsp_pipe, plane->index, &cfg); }
@@ -444,6 +456,11 @@ int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, num_planes - 1); } +drm_plane_create_blend_mode_property (&plane->plane, +BIT (DRM_MODE_BLEND_PIXEL_NONE ) | +BIT (DRM_MODE_BLEND_PREMULTI ) | +BIT (DRM_MODE_BLEND_COVERAGE )); + vsp->num_planes++; }
Signature · 1 line
2.25.1
Re: [PATCH 3/3] drm: rcar-du: Add DRM blend mode support
Hi Hayama-san,
Thank you for the patch.
Quoted 8 lines · Takanari Hayama
R-Car DU supports different blend modes via VSP1. Add DRM blend mode supports to make it configurable.
As
drm_plane_create_blend_mode_property()creates the blend mode property with the default value ofDRM_MODE_BLEND_PREMULTI, it changes the default blending behavior on R-Car DU. The rcar-du's blend mode was same asDRM_MODE_BLEND_COVERAGE, i.e., pixel color values have not been pre-multitplied.
If that's what KMS userspace requires I'm fine with it.
Quoted 1 line
Signed-off-by Takanari Hayama <[email protected]>
but I expect this patch to change based on my suggestions for 2/3.
Quoted 39 lines
--- drivers/gpu/drm/rcar-du/rcar_du_vsp.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)drivers/gpu/drm/rcar-du/rcar_du_vsp.c +17
-0@@ -170,6 +170,18 @@ static void rcar_du_vsp_plane_setup(struct rcar_du_vsp_plane *plane) format =rcar_du_format_info (state->format->fourcc); cfg.pixelformat = format->v4l2; +switch (state->state.pixel_blend_mode) { +case DRM_MODE_BLEND_PREMULTI : + cfg.blend_mode =VSP1_DU_BLEND_MODE_PREMULTI ; +break ; +case DRM_MODE_BLEND_COVERAGE : + cfg.blend_mode =VSP1_DU_BLEND_MODE_COVERAGE ; +break ; +case DRM_MODE_BLEND_PIXEL_NONE : + cfg.blend_mode =VSP1_DU_BLEND_MODE_PIXEL_NONE ; +break ; + } +vsp1_du_atomic_update (plane->vsp->vsp, crtc->vsp_pipe, plane->index, &cfg); }@@ -444,6 +456,11 @@ int rcar_du_vsp_init(struct rcar_du_vsp *vsp, struct device_node *np, num_planes - 1); } +drm_plane_create_blend_mode_property (&plane->plane, +BIT (DRM_MODE_BLEND_PIXEL_NONE ) | +BIT (DRM_MODE_BLEND_PREMULTI ) | +BIT (DRM_MODE_BLEND_COVERAGE )); + vsp->num_planes++; }
Signature · 3 lines
Regards, Laurent Pinchart