For subsampled formats we need to use GAMCOR instead of the DEGAM block. The color module can create a LUT for that if we set map_user_ramp to true. So do that when we have subsampled formats.
Co-developed by Claude Sonnet 4.5. Signed-off-by: Harry Wentland <[email protected]> --- .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 34 ++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c index d13b1b2d54cf..0d58eb45552d 100644 --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c @@ -1471,6 +1471,8 @@ __set_colorop_in_tf_1d_curve(struct dc_plane_state *dc_plane_state, struct dc_transfer_func *tf = &dc_plane_state->in_transfer_func; struct drm_colorop *colorop = colorop_state->colorop; struct drm_device *drm = colorop->dev; + struct dc_color_caps *color_caps = NULL; + bool is_subsampled_format; if (colorop->type != DRM_COLOROP_1D_CURVE) return -EINVAL; @@ -1486,9 +1488,39 @@ __set_colorop_in_tf_1d_curve(struct dc_plane_state *dc_plane_state, drm_dbg(drm, "Degamma colorop with ID: %d\n", colorop->base.id); - tf->type = TF_TYPE_PREDEFINED; + /* Check if format requires post-scale color processing (subsampled formats) */ + is_subsampled_format = (dc_plane_state->format >= SURFACE_PIXEL_FORMAT_VIDEO_BEGIN && + dc_plane_state->format < SURFACE_PIXEL_FORMAT_SUBSAMPLE_END); + tf->tf = amdgpu_colorop_tf_to_dc_tf(colorop_state->curve_1d_type); + if (is_subsampled_format) { + /* + * For subsampled formats (P010, NV12), we need color processing + * to happen AFTER scaling (to expand UV channels first). + * Convert predefined TF to PWL so DC will use GAMCOR (post-scale) + * instead of PRE_DEGAM (pre-scale). + * + * IMPORTANT: We must pass map_user_ramp=true to force PWL conversion. + * Without it, mod_color_calculate_degamma_params() returns early for + * SRGB/Linear TFs without converting to TF_TYPE_DISTRIBUTED_POINTS. + */ + tf->type = TF_TYPE_PREDEFINED; + + if (dc_plane_state->ctx && dc_plane_state->ctx->dc) + color_caps = &dc_plane_state->ctx->dc->caps.color; + + if (!mod_color_calculate_degamma_params(color_caps, tf, NULL, true)) { + drm_err(drm, "Failed to calculate degamma params for subsampled format\n"); + return -EINVAL; + } + + /* mod_color_calculate_degamma_params sets tf->type to TF_TYPE_DISTRIBUTED_POINTS */ + } else { + /* For non-subsampled formats (RGB, XR30), use predefined ROM LUT (PRE_DEGAM) */ + tf->type = TF_TYPE_PREDEFINED; + } + return 0; } -- 2.53.0
