In vkms_plane_atomic_check(), validate that when a color pipeline
is active and the framebuffer format is YUV:
  - The first colorop must be DRM_COLOROP_FIXED_MATRIX
  - The fixed matrix colorop must not be bypassed

In vkms_plane_atomic_update(), when a color pipeline is active,
read the fixed_matrix_type from the first colorop state and map
it to the appropriate (color_encoding, color_range) pair for the
existing get_conversion_matrix_to_argb_u16() function.

In apply_colorop(), add a no-op case for DRM_COLOROP_FIXED_MATRIX
since the actual YUV-to-RGB conversion is already performed at
format read time via the conversion matrix.

Assisted-by: Claude:claude-opus-4.6
Signed-off-by: Harry Wentland <[email protected]>
Reviewed-by: Alex Hung <[email protected]>
Reviewed-by: Robert Mader <[email protected]>
---
 drivers/gpu/drm/vkms/tests/vkms_format_test.c |  2 +-
 drivers/gpu/drm/vkms/vkms_composer.c          |  6 ++
 drivers/gpu/drm/vkms/vkms_formats.c           |  9 +++
 drivers/gpu/drm/vkms/vkms_formats.h           |  2 +-
 drivers/gpu/drm/vkms/vkms_plane.c             | 55 ++++++++++++++++++-
 5 files changed, 71 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/vkms/tests/vkms_format_test.c 
b/drivers/gpu/drm/vkms/tests/vkms_format_test.c
index e746b18bf37b..e931cdfafae7 100644
--- a/drivers/gpu/drm/vkms/tests/vkms_format_test.c
+++ b/drivers/gpu/drm/vkms/tests/vkms_format_test.c
@@ -232,7 +232,7 @@ static void vkms_format_test_yuv_u16_to_argb_u16(struct 
kunit *test)
                struct conversion_matrix matrix;
 
                get_conversion_matrix_to_argb_u16
-                       (DRM_FORMAT_NV12, param->encoding, param->range, 
&matrix);
+                       (DRM_FORMAT_NV12, param->encoding, param->range, false, 
&matrix);
 
                argb = argb_u16_from_yuv161616(&matrix, color->yuv.y, 
color->yuv.u,
                                               color->yuv.v);
diff --git a/drivers/gpu/drm/vkms/vkms_composer.c 
b/drivers/gpu/drm/vkms/vkms_composer.c
index 83d217085ad0..899120cd07ac 100644
--- a/drivers/gpu/drm/vkms/vkms_composer.c
+++ b/drivers/gpu/drm/vkms/vkms_composer.c
@@ -187,6 +187,12 @@ static void apply_colorop(struct pixel_argb_s32 *pixel, 
struct drm_colorop *colo
                if (colorop_state->data)
                        apply_3x4_matrix(pixel,
                                         (struct drm_color_ctm_3x4 
*)colorop_state->data->data);
+       } else if (colorop->type == DRM_COLOROP_FIXED_MATRIX) {
+               /*
+                * Fixed Matrix is a no-op here. YUV-to-RGB conversion
+                * is handled at format read time via the
+                * conversion_matrix set in vkms_plane_atomic_update().
+                */
        }
 }
 
diff --git a/drivers/gpu/drm/vkms/vkms_formats.c 
b/drivers/gpu/drm/vkms/vkms_formats.c
index 4d5fcaeb82c5..964b574d9ed7 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.c
+++ b/drivers/gpu/drm/vkms/vkms_formats.c
@@ -895,16 +895,25 @@ static void swap_uv_columns(struct conversion_matrix 
*matrix)
  * @format: DRM_FORMAT_* value for which to obtain a conversion function (see 
[drm_fourcc.h])
  * @encoding: DRM_COLOR_* value for which to obtain a conversion matrix
  * @range: DRM_COLOR_*_RANGE value for which to obtain a conversion matrix
+ * @bypass: If true, return an identity (no-op) matrix that passes the samples
+ *          through unchanged, ignoring @encoding and @range. Used when a fixed
+ *          matrix colorop is present but bypassed.
  * @matrix: Pointer to store the value into
  */
 void get_conversion_matrix_to_argb_u16(u32 format,
                                       enum drm_color_encoding encoding,
                                       enum drm_color_range range,
+                                      bool bypass,
                                       struct conversion_matrix *matrix)
 {
        const struct conversion_matrix *matrix_to_copy;
        bool limited_range;
 
+       if (bypass) {
+               memcpy(matrix, &no_operation, sizeof(no_operation));
+               return;
+       }
+
        switch (range) {
        case DRM_COLOR_YCBCR_LIMITED_RANGE:
                limited_range = true;
diff --git a/drivers/gpu/drm/vkms/vkms_formats.h 
b/drivers/gpu/drm/vkms/vkms_formats.h
index eeb208cdd6b1..d969cc669a5e 100644
--- a/drivers/gpu/drm/vkms/vkms_formats.h
+++ b/drivers/gpu/drm/vkms/vkms_formats.h
@@ -10,7 +10,7 @@ pixel_read_line_t get_pixel_read_line_function(u32 format);
 pixel_write_t get_pixel_write_function(u32 format);
 
 void get_conversion_matrix_to_argb_u16(u32 format, enum drm_color_encoding 
encoding,
-                                      enum drm_color_range range,
+                                      enum drm_color_range range, bool bypass,
                                       struct conversion_matrix *matrix);
 
 #if IS_ENABLED(CONFIG_KUNIT)
diff --git a/drivers/gpu/drm/vkms/vkms_plane.c 
b/drivers/gpu/drm/vkms/vkms_plane.c
index 68cb2a3335e6..6ee5c3f3207c 100644
--- a/drivers/gpu/drm/vkms/vkms_plane.c
+++ b/drivers/gpu/drm/vkms/vkms_plane.c
@@ -6,6 +6,7 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_blend.h>
+#include <drm/drm_colorop.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_gem_atomic_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
@@ -131,6 +132,9 @@ static void vkms_plane_atomic_update(struct drm_plane 
*plane,
        struct drm_framebuffer *fb = new_state->fb;
        struct vkms_frame_info *frame_info;
        u32 fmt;
+       enum drm_color_encoding encoding = new_state->color_encoding;
+       enum drm_color_range range = new_state->color_range;
+       bool bypass = false;
 
        if (!new_state->crtc || !fb)
                return;
@@ -148,7 +152,49 @@ static void vkms_plane_atomic_update(struct drm_plane 
*plane,
        frame_info->rotation = new_state->rotation;
 
        vkms_plane_state->pixel_read_line = get_pixel_read_line_function(fmt);
-       get_conversion_matrix_to_argb_u16(fmt, new_state->color_encoding, 
new_state->color_range,
+
+       if (new_state->color_pipeline) {
+               struct drm_colorop *colorop = new_state->color_pipeline;
+               struct drm_colorop_state *colorop_state;
+
+               colorop_state = drm_atomic_get_new_colorop_state(state, 
colorop);
+               bypass = !colorop_state || colorop_state->bypass;
+
+               if (!bypass) {
+                       switch (colorop_state->fixed_matrix_type) {
+                       case DRM_COLOROP_FM_YCBCR601_FULL_RGB:
+                               encoding = DRM_COLOR_YCBCR_BT601;
+                               range = DRM_COLOR_YCBCR_FULL_RANGE;
+                               break;
+                       case DRM_COLOROP_FM_YCBCR601_LIMITED_RGB:
+                               encoding = DRM_COLOR_YCBCR_BT601;
+                               range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+                               break;
+                       case DRM_COLOROP_FM_YCBCR709_FULL_RGB:
+                               encoding = DRM_COLOR_YCBCR_BT709;
+                               range = DRM_COLOR_YCBCR_FULL_RANGE;
+                               break;
+                       case DRM_COLOROP_FM_YCBCR709_LIMITED_RGB:
+                               encoding = DRM_COLOR_YCBCR_BT709;
+                               range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+                               break;
+                       case DRM_COLOROP_FM_YCBCR2020_NC_FULL_RGB:
+                               encoding = DRM_COLOR_YCBCR_BT2020;
+                               range = DRM_COLOR_YCBCR_FULL_RANGE;
+                               break;
+                       case DRM_COLOROP_FM_YCBCR2020_NC_LIMITED_RGB:
+                               encoding = DRM_COLOR_YCBCR_BT2020;
+                               range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+                               break;
+                       default:
+                               encoding = DRM_COLOR_YCBCR_BT709;
+                               range = DRM_COLOR_YCBCR_LIMITED_RANGE;
+                               break;
+                       }
+               }
+       }
+
+       get_conversion_matrix_to_argb_u16(fmt, encoding, range, bypass,
                                          &vkms_plane_state->conversion_matrix);
 }
 
@@ -175,6 +221,13 @@ static int vkms_plane_atomic_check(struct drm_plane *plane,
        if (ret != 0)
                return ret;
 
+       if (new_plane_state->color_pipeline && 
new_plane_state->fb->format->is_yuv) {
+               struct drm_colorop *colorop = new_plane_state->color_pipeline;
+
+               if (colorop->type != DRM_COLOROP_FIXED_MATRIX)
+                       return -EINVAL;
+       }
+
        return 0;
 }
 
-- 
2.55.0

Reply via email to