Introduce a post-blend color pipeline with the same colorop blocks as
the pre-blend color pipeline.
Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
---
drivers/gpu/drm/vkms/vkms_colorop.c | 98 ++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/vkms/vkms_composer.c | 5 +-
drivers/gpu/drm/vkms/vkms_crtc.c | 1 +
drivers/gpu/drm/vkms/vkms_drv.h | 1 +
4 files changed, 104 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
index 5924ae2bd40fc904048f99bc9b96308140709e25..54c512db68eef16435d5f79453784f7784d540fb 100644
--- a/drivers/gpu/drm/vkms/vkms_colorop.c
+++ b/drivers/gpu/drm/vkms/vkms_colorop.c
@@ -98,6 +98,86 @@ vkms_initialize_pre_blend_color_pipeline(struct drm_plane *plane,
return ret;
}
+static int
+vkms_initialize_post_blend_color_pipeline(struct drm_crtc *crtc,
+ struct drm_prop_enum_list *list)
+{
+ struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS];
+ struct drm_device *dev = crtc->dev;
+ int ret;
+ int i = 0;
+
+ memset(ops, 0, sizeof(ops));
+
+ /* 1st op: 1d curve */
+ ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
+ if (!ops[i]) {
+ ret = -ENOMEM;
+ goto cleanup;
+ }
+
+ ret = drm_crtc_colorop_curve_1d_init(dev, ops[i], crtc, supported_tfs,
+ DRM_COLOROP_FLAG_ALLOW_BYPASS);
+ if (ret)
+ goto cleanup;
+
+ list->type = ops[i]->base.id;
+ list->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[i]->base.id);
+
+ i++;
+
+ /* 2nd op: 3x4 matrix */
+ ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
+ if (!ops[i]) {
+ ret = -ENOMEM;
+ goto cleanup;
+ }
+
+ ret = drm_crtc_colorop_ctm_3x4_init(dev, ops[i], crtc, DRM_COLOROP_FLAG_ALLOW_BYPASS);
+ if (ret)
+ goto cleanup;
+
+ drm_colorop_set_next_property(ops[i - 1], ops[i]);
+
+ i++;
+
+ /* 3rd op: 3x4 matrix */
+ ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
+ if (!ops[i]) {
+ ret = -ENOMEM;
+ goto cleanup;
+ }
+
+ ret = drm_crtc_colorop_ctm_3x4_init(dev, ops[i], crtc, DRM_COLOROP_FLAG_ALLOW_BYPASS);
+ if (ret)
+ goto cleanup;
+
+ drm_colorop_set_next_property(ops[i - 1], ops[i]);
+
+ i++;
+
+ /* 4th op: 1d curve */
+ ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
+ if (!ops[i]) {
+ ret = -ENOMEM;
+ goto cleanup;
+ }
+
+ ret = drm_crtc_colorop_curve_1d_init(dev, ops[i], crtc, supported_tfs,
+ DRM_COLOROP_FLAG_ALLOW_BYPASS);
+ if (ret)
+ goto cleanup;
+
+ drm_colorop_set_next_property(ops[i - 1], ops[i]);
+
+ return 0;
+
+cleanup:
+ drm_colorop_pipeline_destroy(dev);
+
+ return ret;
+}
+
int vkms_initialize_pre_blend_colorops(struct drm_plane *plane)
{
struct drm_prop_enum_list pipeline;
@@ -115,3 +195,21 @@ int vkms_initialize_pre_blend_colorops(struct drm_plane *plane)
return 0;
}
+
+int vkms_initialize_post_blend_colorops(struct drm_crtc *crtc)
+{
+ struct drm_prop_enum_list pipeline;
+ int ret;
+
+ /* Add color pipeline */
+ ret = vkms_initialize_post_blend_color_pipeline(crtc, &pipeline);
+ if (ret)
+ return ret;
+
+ /* Create COLOR_PIPELINE property and attach */
+ ret = drm_crtc_create_color_pipeline_property(crtc, &pipeline, 1);
+ if (ret)
+ return ret;
+
+ return 0;
+}
diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
index 05e1551d6330e4dc14563d3a399b3544d11c6576..efe09538768b01108a305f0ace765246220b487b 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -495,7 +495,10 @@ static void blend(struct vkms_writeback_job *wb,
blend_line(plane[i], y, crtc_x_limit, stage_buffer, output_buffer);
}
- apply_lut(crtc_state, output_buffer);
+ if (crtc_state->base.color_pipeline_enabled)
+ color_transform(crtc_state->base.color_pipeline, output_buffer);
+ else
+ apply_lut(crtc_state, output_buffer);
*crc32 = crc32_le(*crc32, (void *)output_buffer->pixels, row_size);
diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
index e60573e0f3e9510252e1f198b00e28bcc7987620..04737c1fb70e4f0aef480a180e57a76fbc279dfa 100644
--- a/drivers/gpu/drm/vkms/vkms_crtc.c
+++ b/drivers/gpu/drm/vkms/vkms_crtc.c
@@ -295,6 +295,7 @@ struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *pri
}
drm_crtc_enable_color_mgmt(crtc, 0, false, VKMS_LUT_SIZE);
+ vkms_initialize_post_blend_colorops(crtc);
spin_lock_init(&vkms_out->lock);
spin_lock_init(&vkms_out->composer_lock);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 37ee569474223b2cf01e3cc0e4f119777533ae23..a0308c2263d1858a72906853960ea7d1bbecd03e 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -306,5 +306,6 @@ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_out
/* Colorops */
int vkms_initialize_pre_blend_colorops(struct drm_plane *plane);
+int vkms_initialize_post_blend_colorops(struct drm_crtc *crtc);
#endif /* _VKMS_DRV_H_ */
--
2.50.1
Le 18/09/2025 à 02:43, Nícolas F. R. A. Prado a écrit :
> Introduce a post-blend color pipeline with the same colorop blocks as
> the pre-blend color pipeline.
>
> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
> ---
> drivers/gpu/drm/vkms/vkms_colorop.c | 98 ++++++++++++++++++++++++++++++++++++
> drivers/gpu/drm/vkms/vkms_composer.c | 5 +-
> drivers/gpu/drm/vkms/vkms_crtc.c | 1 +
> drivers/gpu/drm/vkms/vkms_drv.h | 1 +
> 4 files changed, 104 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/vkms/vkms_colorop.c
> index 5924ae2bd40fc904048f99bc9b96308140709e25..54c512db68eef16435d5f79453784f7784d540fb 100644
> --- a/drivers/gpu/drm/vkms/vkms_colorop.c
> +++ b/drivers/gpu/drm/vkms/vkms_colorop.c
> @@ -98,6 +98,86 @@ vkms_initialize_pre_blend_color_pipeline(struct drm_plane *plane,
> return ret;
> }
>
> +static int
> +vkms_initialize_post_blend_color_pipeline(struct drm_crtc *crtc,
> + struct drm_prop_enum_list *list)
> +{
> + struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS];
> + struct drm_device *dev = crtc->dev;
> + int ret;
> + int i = 0;
> +
> + memset(ops, 0, sizeof(ops));
> +
> + /* 1st op: 1d curve */
> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
> + if (!ops[i]) {
> + ret = -ENOMEM;
> + goto cleanup;
> + }
> +
> + ret = drm_crtc_colorop_curve_1d_init(dev, ops[i], crtc, supported_tfs,
> + DRM_COLOROP_FLAG_ALLOW_BYPASS);
> + if (ret)
> + goto cleanup;
> +
> + list->type = ops[i]->base.id;
> + list->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[i]->base.id);
> +
> + i++;
> +
> + /* 2nd op: 3x4 matrix */
> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
> + if (!ops[i]) {
> + ret = -ENOMEM;
> + goto cleanup;
> + }
> +
> + ret = drm_crtc_colorop_ctm_3x4_init(dev, ops[i], crtc, DRM_COLOROP_FLAG_ALLOW_BYPASS);
> + if (ret)
> + goto cleanup;
> +
> + drm_colorop_set_next_property(ops[i - 1], ops[i]);
> +
> + i++;
> +
> + /* 3rd op: 3x4 matrix */
> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
> + if (!ops[i]) {
> + ret = -ENOMEM;
> + goto cleanup;
> + }
> +
> + ret = drm_crtc_colorop_ctm_3x4_init(dev, ops[i], crtc, DRM_COLOROP_FLAG_ALLOW_BYPASS);
> + if (ret)
> + goto cleanup;
> +
> + drm_colorop_set_next_property(ops[i - 1], ops[i]);
> +
> + i++;
> +
> + /* 4th op: 1d curve */
> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
> + if (!ops[i]) {
> + ret = -ENOMEM;
> + goto cleanup;
> + }
> +
> + ret = drm_crtc_colorop_curve_1d_init(dev, ops[i], crtc, supported_tfs,
> + DRM_COLOROP_FLAG_ALLOW_BYPASS);
> + if (ret)
> + goto cleanup;
> +
> + drm_colorop_set_next_property(ops[i - 1], ops[i]);
> +
> + return 0;
> +
> +cleanup:
> + drm_colorop_pipeline_destroy(dev);
Same comment as for pre_blend colorops, it feel strange to destroy all
the pipelines here.
The suggestion in [1] is better (don't forget to add the kfree).
[1]:
https://lore.kernel.org/all/73f01810-df2d-4e39-a20b-fc1cec2c5e12@amd.com/
> + return ret;
> +}
> +
> int vkms_initialize_pre_blend_colorops(struct drm_plane *plane)
> {
> struct drm_prop_enum_list pipeline;
> @@ -115,3 +195,21 @@ int vkms_initialize_pre_blend_colorops(struct drm_plane *plane)
>
> return 0;
> }
> +
> +int vkms_initialize_post_blend_colorops(struct drm_crtc *crtc)
> +{
> + struct drm_prop_enum_list pipeline;
> + int ret;
> +
> + /* Add color pipeline */
> + ret = vkms_initialize_post_blend_color_pipeline(crtc, &pipeline);
> + if (ret)
> + return ret;
> +
> + /* Create COLOR_PIPELINE property and attach */
> + ret = drm_crtc_create_color_pipeline_property(crtc, &pipeline, 1);
> + if (ret)
> + return ret;
> +
> + return 0;
> +}
> diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c
> index 05e1551d6330e4dc14563d3a399b3544d11c6576..efe09538768b01108a305f0ace765246220b487b 100644
> --- a/drivers/gpu/drm/vkms/vkms_composer.c
> +++ b/drivers/gpu/drm/vkms/vkms_composer.c
> @@ -495,7 +495,10 @@ static void blend(struct vkms_writeback_job *wb,
> blend_line(plane[i], y, crtc_x_limit, stage_buffer, output_buffer);
> }
>
> - apply_lut(crtc_state, output_buffer);
> + if (crtc_state->base.color_pipeline_enabled)
> + color_transform(crtc_state->base.color_pipeline, output_buffer);
> + else
> + apply_lut(crtc_state, output_buffer);
>
> *crc32 = crc32_le(*crc32, (void *)output_buffer->pixels, row_size);
>
> diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c
> index e60573e0f3e9510252e1f198b00e28bcc7987620..04737c1fb70e4f0aef480a180e57a76fbc279dfa 100644
> --- a/drivers/gpu/drm/vkms/vkms_crtc.c
> +++ b/drivers/gpu/drm/vkms/vkms_crtc.c
> @@ -295,6 +295,7 @@ struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *pri
> }
>
> drm_crtc_enable_color_mgmt(crtc, 0, false, VKMS_LUT_SIZE);
> + vkms_initialize_post_blend_colorops(crtc);
>
> spin_lock_init(&vkms_out->lock);
> spin_lock_init(&vkms_out->composer_lock);
> diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
> index 37ee569474223b2cf01e3cc0e4f119777533ae23..a0308c2263d1858a72906853960ea7d1bbecd03e 100644
> --- a/drivers/gpu/drm/vkms/vkms_drv.h
> +++ b/drivers/gpu/drm/vkms/vkms_drv.h
> @@ -306,5 +306,6 @@ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_out
>
> /* Colorops */
> int vkms_initialize_pre_blend_colorops(struct drm_plane *plane);
> +int vkms_initialize_post_blend_colorops(struct drm_crtc *crtc);
>
> #endif /* _VKMS_DRV_H_ */
>
--
--
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Louis,
On 9/19/25 9:50 AM, Louis Chauvet wrote:
>
>
> Le 18/09/2025 à 02:43, Nícolas F. R. A. Prado a écrit :
>> Introduce a post-blend color pipeline with the same colorop blocks as
>> the pre-blend color pipeline.
>>
>> Signed-off-by: Nícolas F. R. A. Prado <nfraprado@collabora.com>
>> ---
>> drivers/gpu/drm/vkms/vkms_colorop.c | 98 ++++++++++++++++++++++++++
>> ++++++++++
>> drivers/gpu/drm/vkms/vkms_composer.c | 5 +-
>> drivers/gpu/drm/vkms/vkms_crtc.c | 1 +
>> drivers/gpu/drm/vkms/vkms_drv.h | 1 +
>> 4 files changed, 104 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/vkms/vkms_colorop.c b/drivers/gpu/drm/
>> vkms/vkms_colorop.c
>> index
>> 5924ae2bd40fc904048f99bc9b96308140709e25..54c512db68eef16435d5f79453784f7784d540fb 100644
>> --- a/drivers/gpu/drm/vkms/vkms_colorop.c
>> +++ b/drivers/gpu/drm/vkms/vkms_colorop.c
>> @@ -98,6 +98,86 @@ vkms_initialize_pre_blend_color_pipeline(struct
>> drm_plane *plane,
>> return ret;
>> }
>> +static int
>> +vkms_initialize_post_blend_color_pipeline(struct drm_crtc *crtc,
>> + struct drm_prop_enum_list *list)
>> +{
>> + struct drm_colorop *ops[MAX_COLOR_PIPELINE_OPS];
>> + struct drm_device *dev = crtc->dev;
>> + int ret;
>> + int i = 0;
>> +
>> + memset(ops, 0, sizeof(ops));
>> +
>> + /* 1st op: 1d curve */
>> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
>> + if (!ops[i]) {
>> + ret = -ENOMEM;
>> + goto cleanup;
>> + }
>> +
>> + ret = drm_crtc_colorop_curve_1d_init(dev, ops[i], crtc,
>> supported_tfs,
>> + DRM_COLOROP_FLAG_ALLOW_BYPASS);
>> + if (ret)
>> + goto cleanup;
>> +
>> + list->type = ops[i]->base.id;
>> + list->name = kasprintf(GFP_KERNEL, "Color Pipeline %d", ops[i]-
>> >base.id);
>> +
>> + i++;
>> +
>> + /* 2nd op: 3x4 matrix */
>> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
>> + if (!ops[i]) {
>> + ret = -ENOMEM;
>> + goto cleanup;
>> + }
>> +
>> + ret = drm_crtc_colorop_ctm_3x4_init(dev, ops[i], crtc,
>> DRM_COLOROP_FLAG_ALLOW_BYPASS);
>> + if (ret)
>> + goto cleanup;
>> +
>> + drm_colorop_set_next_property(ops[i - 1], ops[i]);
>> +
>> + i++;
>> +
>> + /* 3rd op: 3x4 matrix */
>> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
>> + if (!ops[i]) {
>> + ret = -ENOMEM;
>> + goto cleanup;
>> + }
>> +
>> + ret = drm_crtc_colorop_ctm_3x4_init(dev, ops[i], crtc,
>> DRM_COLOROP_FLAG_ALLOW_BYPASS);
>> + if (ret)
>> + goto cleanup;
>> +
>> + drm_colorop_set_next_property(ops[i - 1], ops[i]);
>> +
>> + i++;
>> +
>> + /* 4th op: 1d curve */
>> + ops[i] = kzalloc(sizeof(*ops[i]), GFP_KERNEL);
>> + if (!ops[i]) {
>> + ret = -ENOMEM;
>> + goto cleanup;
>> + }
>> +
>> + ret = drm_crtc_colorop_curve_1d_init(dev, ops[i], crtc,
>> supported_tfs,
>> + DRM_COLOROP_FLAG_ALLOW_BYPASS);
>> + if (ret)
>> + goto cleanup;
>> +
>> + drm_colorop_set_next_property(ops[i - 1], ops[i]);
>> +
>> + return 0;
>> +
>> +cleanup:
>> + drm_colorop_pipeline_destroy(dev);
>
> Same comment as for pre_blend colorops, it feel strange to destroy all
> the pipelines here.
>
> The suggestion in [1] is better (don't forget to add the kfree).
>
> [1]: https://lore.kernel.org/all/73f01810-df2d-4e39-a20b-
> fc1cec2c5e12@amd.com/
Ack, will be addressed in v3.
Regards,
--
Ariel D'Alessandro
Software Engineer
Collabora Ltd.
Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, UK
Registered in England & Wales, no. 5513718
© 2016 - 2026 Red Hat, Inc.