]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/display: extend delta clamping logic to CM3 LUT helper
authorMelissa Wen <mwen@igalia.com>
Mon, 8 Dec 2025 23:44:15 +0000 (22:44 -0100)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 3 Feb 2026 21:47:25 +0000 (16:47 -0500)
Commit 27fc10d1095f ("drm/amd/display: Fix the delta clamping for shaper
LUT") fixed banding when using plane shaper LUT in DCN10 CM helper.  The
problem is also present in DCN30 CM helper, fix banding by extending the
same bug delta clamping fix to CM3.

Signed-off-by: Melissa Wen <mwen@igalia.com>
Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c
drivers/gpu/drm/amd/display/dc/dwb/dcn30/dcn30_cm_common.h
drivers/gpu/drm/amd/display/dc/hwss/dcn30/dcn30_hwseq.c
drivers/gpu/drm/amd/display/dc/hwss/dcn32/dcn32_hwseq.c
drivers/gpu/drm/amd/display/dc/hwss/dcn401/dcn401_hwseq.c

index a4f14b16564c2f164ea1aad58b95215a50edf5b5..227aa8672d17ba048805dfc34c8e033d309db053 100644 (file)
@@ -105,9 +105,12 @@ void cm_helper_program_gamcor_xfer_func(
 #define NUMBER_REGIONS     32
 #define NUMBER_SW_SEGMENTS 16
 
-bool cm3_helper_translate_curve_to_hw_format(
-                               const struct dc_transfer_func *output_tf,
-                               struct pwl_params *lut_params, bool fixpoint)
+#define DC_LOGGER \
+               ctx->logger
+
+bool cm3_helper_translate_curve_to_hw_format(struct dc_context *ctx,
+                                            const struct dc_transfer_func *output_tf,
+                                            struct pwl_params *lut_params, bool fixpoint)
 {
        struct curve_points3 *corner_points;
        struct pwl_result_data *rgb_resulted;
@@ -251,6 +254,10 @@ bool cm3_helper_translate_curve_to_hw_format(
        if (fixpoint == true) {
                i = 1;
                while (i != hw_points + 2) {
+                       uint32_t red_clamp;
+                       uint32_t green_clamp;
+                       uint32_t blue_clamp;
+
                        if (i >= hw_points) {
                                if (dc_fixpt_lt(rgb_plus_1->red, rgb->red))
                                        rgb_plus_1->red = dc_fixpt_add(rgb->red,
@@ -263,9 +270,20 @@ bool cm3_helper_translate_curve_to_hw_format(
                                                        rgb_minus_1->delta_blue);
                        }
 
-                       rgb->delta_red_reg   = dc_fixpt_clamp_u0d10(rgb->delta_red);
-                       rgb->delta_green_reg = dc_fixpt_clamp_u0d10(rgb->delta_green);
-                       rgb->delta_blue_reg  = dc_fixpt_clamp_u0d10(rgb->delta_blue);
+                       rgb->delta_red   = dc_fixpt_sub(rgb_plus_1->red,   rgb->red);
+                       rgb->delta_green = dc_fixpt_sub(rgb_plus_1->green, rgb->green);
+                       rgb->delta_blue  = dc_fixpt_sub(rgb_plus_1->blue,  rgb->blue);
+
+                       red_clamp = dc_fixpt_clamp_u0d14(rgb->delta_red);
+                       green_clamp = dc_fixpt_clamp_u0d14(rgb->delta_green);
+                       blue_clamp = dc_fixpt_clamp_u0d14(rgb->delta_blue);
+
+                       if (red_clamp >> 10 || green_clamp >> 10 || blue_clamp >> 10)
+                               DC_LOG_ERROR("Losing delta precision while programming shaper LUT.");
+
+                       rgb->delta_red_reg   = red_clamp & 0x3ff;
+                       rgb->delta_green_reg = green_clamp & 0x3ff;
+                       rgb->delta_blue_reg  = blue_clamp & 0x3ff;
                        rgb->red_reg         = dc_fixpt_clamp_u0d14(rgb->red);
                        rgb->green_reg       = dc_fixpt_clamp_u0d14(rgb->green);
                        rgb->blue_reg        = dc_fixpt_clamp_u0d14(rgb->blue);
index b86347c9b0389d1ba18aace0c1785d953ecd9932..95f9318a54efcec083dadf8c1c30228a7bbe81ab 100644 (file)
@@ -59,7 +59,7 @@ void cm_helper_program_gamcor_xfer_func(
        const struct pwl_params *params,
        const struct dcn3_xfer_func_reg *reg);
 
-bool cm3_helper_translate_curve_to_hw_format(
+bool cm3_helper_translate_curve_to_hw_format(struct dc_context *ctx,
        const struct dc_transfer_func *output_tf,
        struct pwl_params *lut_params, bool fixpoint);
 
index d58f2cf2615c0701c42ade5ee97a69cc2cd7f8d0..d04cfd403b7ee1b282ee12f00c0e05e14bcfdd1a 100644 (file)
@@ -241,7 +241,7 @@ bool dcn30_set_blend_lut(
        if (plane_state->blend_tf.type == TF_TYPE_HWPWL)
                blend_lut = &plane_state->blend_tf.pwl;
        else if (plane_state->blend_tf.type == TF_TYPE_DISTRIBUTED_POINTS) {
-               result = cm3_helper_translate_curve_to_hw_format(
+               result = cm3_helper_translate_curve_to_hw_format(plane_state->ctx,
                                &plane_state->blend_tf, &dpp_base->regamma_params, false);
                if (!result)
                        return result;
@@ -336,8 +336,9 @@ bool dcn30_set_input_transfer_func(struct dc *dc,
        if (plane_state->in_transfer_func.type == TF_TYPE_HWPWL)
                params = &plane_state->in_transfer_func.pwl;
        else if (plane_state->in_transfer_func.type == TF_TYPE_DISTRIBUTED_POINTS &&
-               cm3_helper_translate_curve_to_hw_format(&plane_state->in_transfer_func,
-                               &dpp_base->degamma_params, false))
+               cm3_helper_translate_curve_to_hw_format(plane_state->ctx,
+                                                       &plane_state->in_transfer_func,
+                                                       &dpp_base->degamma_params, false))
                params = &dpp_base->degamma_params;
 
        result = dpp_base->funcs->dpp_program_gamcor_lut(dpp_base, params);
@@ -408,7 +409,7 @@ bool dcn30_set_output_transfer_func(struct dc *dc,
                                params = &stream->out_transfer_func.pwl;
                        else if (pipe_ctx->stream->out_transfer_func.type ==
                                        TF_TYPE_DISTRIBUTED_POINTS &&
-                                       cm3_helper_translate_curve_to_hw_format(
+                                       cm3_helper_translate_curve_to_hw_format(stream->ctx,
                                        &stream->out_transfer_func,
                                        &mpc->blender_params, false))
                                params = &mpc->blender_params;
index 37300e12e64552d297e9ad11335545df0d8eb26c..1be12134967297bc341664560488838ffebc3137 100644 (file)
@@ -493,8 +493,9 @@ bool dcn32_set_mcm_luts(
        if (plane_state->blend_tf.type == TF_TYPE_HWPWL)
                lut_params = &plane_state->blend_tf.pwl;
        else if (plane_state->blend_tf.type == TF_TYPE_DISTRIBUTED_POINTS) {
-               result = cm3_helper_translate_curve_to_hw_format(&plane_state->blend_tf,
-                               &dpp_base->regamma_params, false);
+               result = cm3_helper_translate_curve_to_hw_format(plane_state->ctx,
+                                                                &plane_state->blend_tf,
+                                                                &dpp_base->regamma_params, false);
                if (!result)
                        return result;
 
@@ -509,8 +510,9 @@ bool dcn32_set_mcm_luts(
        else if (plane_state->in_shaper_func.type == TF_TYPE_DISTRIBUTED_POINTS) {
                // TODO: dpp_base replace
                ASSERT(false);
-               cm3_helper_translate_curve_to_hw_format(&plane_state->in_shaper_func,
-                               &dpp_base->shaper_params, true);
+               cm3_helper_translate_curve_to_hw_format(plane_state->ctx,
+                                                       &plane_state->in_shaper_func,
+                                                       &dpp_base->shaper_params, true);
                lut_params = &dpp_base->shaper_params;
        }
 
@@ -550,8 +552,9 @@ bool dcn32_set_input_transfer_func(struct dc *dc,
        if (plane_state->in_transfer_func.type == TF_TYPE_HWPWL)
                params = &plane_state->in_transfer_func.pwl;
        else if (plane_state->in_transfer_func.type == TF_TYPE_DISTRIBUTED_POINTS &&
-               cm3_helper_translate_curve_to_hw_format(&plane_state->in_transfer_func,
-                               &dpp_base->degamma_params, false))
+               cm3_helper_translate_curve_to_hw_format(plane_state->ctx,
+                                                       &plane_state->in_transfer_func,
+                                                       &dpp_base->degamma_params, false))
                params = &dpp_base->degamma_params;
 
        dpp_base->funcs->dpp_program_gamcor_lut(dpp_base, params);
@@ -582,7 +585,7 @@ bool dcn32_set_output_transfer_func(struct dc *dc,
                                params = &stream->out_transfer_func.pwl;
                        else if (pipe_ctx->stream->out_transfer_func.type ==
                                        TF_TYPE_DISTRIBUTED_POINTS &&
-                                       cm3_helper_translate_curve_to_hw_format(
+                                       cm3_helper_translate_curve_to_hw_format(stream->ctx,
                                        &stream->out_transfer_func,
                                        &mpc->blender_params, false))
                                params = &mpc->blender_params;
index 9cda39d0ed95fe833b0b3c921a3a99dd5ad01374..b91517b9fedcf203c6f353cd232a271282a32431 100644 (file)
@@ -432,7 +432,7 @@ void dcn401_populate_mcm_luts(struct dc *dc,
                if (mcm_luts.lut1d_func->type == TF_TYPE_HWPWL)
                        m_lut_params.pwl = &mcm_luts.lut1d_func->pwl;
                else if (mcm_luts.lut1d_func->type == TF_TYPE_DISTRIBUTED_POINTS) {
-                       rval = cm3_helper_translate_curve_to_hw_format(
+                       rval = cm3_helper_translate_curve_to_hw_format(mpc->ctx,
                                        mcm_luts.lut1d_func,
                                        &dpp_base->regamma_params, false);
                        m_lut_params.pwl = rval ? &dpp_base->regamma_params : NULL;
@@ -452,7 +452,7 @@ void dcn401_populate_mcm_luts(struct dc *dc,
                        m_lut_params.pwl = &mcm_luts.shaper->pwl;
                else if (mcm_luts.shaper->type == TF_TYPE_DISTRIBUTED_POINTS) {
                        ASSERT(false);
-                       rval = cm3_helper_translate_curve_to_hw_format(
+                       rval = cm3_helper_translate_curve_to_hw_format(mpc->ctx,
                                        mcm_luts.shaper,
                                        &dpp_base->regamma_params, true);
                        m_lut_params.pwl = rval ? &dpp_base->regamma_params : NULL;
@@ -629,8 +629,9 @@ bool dcn401_set_mcm_luts(struct pipe_ctx *pipe_ctx,
        if (plane_state->blend_tf.type == TF_TYPE_HWPWL)
                lut_params = &plane_state->blend_tf.pwl;
        else if (plane_state->blend_tf.type == TF_TYPE_DISTRIBUTED_POINTS) {
-               rval = cm3_helper_translate_curve_to_hw_format(&plane_state->blend_tf,
-                               &dpp_base->regamma_params, false);
+               rval = cm3_helper_translate_curve_to_hw_format(plane_state->ctx,
+                                                              &plane_state->blend_tf,
+                                                              &dpp_base->regamma_params, false);
                lut_params = rval ? &dpp_base->regamma_params : NULL;
        }
        result = mpc->funcs->program_1dlut(mpc, lut_params, mpcc_id);
@@ -641,8 +642,9 @@ bool dcn401_set_mcm_luts(struct pipe_ctx *pipe_ctx,
                lut_params = &plane_state->in_shaper_func.pwl;
        else if (plane_state->in_shaper_func.type == TF_TYPE_DISTRIBUTED_POINTS) {
                // TODO: dpp_base replace
-               rval = cm3_helper_translate_curve_to_hw_format(&plane_state->in_shaper_func,
-                               &dpp_base->shaper_params, true);
+               rval = cm3_helper_translate_curve_to_hw_format(plane_state->ctx,
+                                                              &plane_state->in_shaper_func,
+                                                              &dpp_base->shaper_params, true);
                lut_params = rval ? &dpp_base->shaper_params : NULL;
        }
        result &= mpc->funcs->program_shaper(mpc, lut_params, mpcc_id);
@@ -676,7 +678,7 @@ bool dcn401_set_output_transfer_func(struct dc *dc,
                                params = &stream->out_transfer_func.pwl;
                        else if (pipe_ctx->stream->out_transfer_func.type ==
                                        TF_TYPE_DISTRIBUTED_POINTS &&
-                                       cm3_helper_translate_curve_to_hw_format(
+                                       cm3_helper_translate_curve_to_hw_format(stream->ctx,
                                        &stream->out_transfer_func,
                                        &mpc->blender_params, false))
                                params = &mpc->blender_params;