Trivial code cleanup around color resources
Subsystems (3)
cover Trivial code cleanup around color resources
Hi,
Sorry for the noise, but while I've been working on wiring 3D LUT support to AMD display driver [1] I found some annoying code style issues in the shared-code part. So I'm just sending what I've been cleaning to better examine the code.
Most seem trivial, except the last one "remove unused _calculate_degamma_curve" since this could just be a matter of missing parts. If so, happy to remove the patch and include a comment describing the situation (or the potential usage of it).
Thanks,
Melissa
[1] https://lore.kernel.org/dri-devel/[email protected]/
Melissa Wen (6):
drm/amd/display: ident braces in dcn30_acquire_post_bldn_3dlut
correctly
drm/amd/display: clean code-style issues in dcn30_set_mpc_shaper_3dlut drm/amd/display: camel case cleanup in color_gamma file drm/amd/display: unset initial value for tf since it's never used drm/amd/display: remove unused func declaration from resource headers drm/amd/display: remove unused _calculate_degamma_curve function
.../drm/amd/display/dc/dcn30/dcn30_hwseq.c | 37 ++--- .../drm/amd/display/dc/dcn30/dcn30_resource.c | 2 +- drivers/gpu/drm/amd/display/dc/inc/resource.h | 4 - .../amd/display/modules/color/color_gamma.c | 140 ++++-------------- .../amd/display/modules/color/color_gamma.h | 3 - 5 files changed, 48 insertions(+), 138 deletions(-)
Signature · 1 line
2.39.0
PATCH 1/6 drm/amd/display: ident braces in dcn30_acquire_post_bldn_3dlut correctly
--- drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/display/dc/dcn30/dcn30_resource.c +1 -1
@@ -1477,8 +1477,8 @@ bool dcn30_acquire_post_bldn_3dlut( state->bits.mpc_rmu2_mux = mpcc_id; ret = true;break ; - } } + }return ret; }
Signature · 1 line
2.39.0
PATCH 2/6 drm/amd/display: clean code-style issues in dcn30_set_mpc_shaper_3dlut
In reply to Melissa WenThis function has many conditions and all code style issues (identation, missing braces, etc.) make reading it really annoying.
--- .../drm/amd/display/dc/dcn30/dcn30_hwseq.c | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-)
drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c +19 -18
@@ -90,8 +90,8 @@ bool dcn30_set_blend_lut(return result; } -static bool dcn30_set_mpc_shaper_3dlut ( -struct pipe_ctx *pipe_ctx,const struct dc_stream_state *stream) +static bool dcn30_set_mpc_shaper_3dlut (struct pipe_ctx *pipe_ctx, +const struct dc_stream_state *stream) {struct dpp *dpp_base = pipe_ctx->plane_res.dpp;int mpcc_id = pipe_ctx->plane_res.hubp->inst;
@@ -103,19 +103,18 @@ static bool dcn30_set_mpc_shaper_3dlut(const struct pwl_params *shaper_lut =NULL ;//get the shaper lut params if (stream->func_shaper) { -if (stream->func_shaper->type ==TF_TYPE_HWPWL ) +if (stream->func_shaper->type ==TF_TYPE_HWPWL ) { shaper_lut = &stream->func_shaper->pwl; -else if (stream->func_shaper->type ==TF_TYPE_DISTRIBUTED_POINTS ) { -cm_helper_translate_curve_to_hw_format ( - stream->func_shaper, - &dpp_base->shaper_params, true); + }else if (stream->func_shaper->type ==TF_TYPE_DISTRIBUTED_POINTS ) { +cm_helper_translate_curve_to_hw_format (stream->func_shaper, + &dpp_base->shaper_params, true); shaper_lut = &dpp_base->shaper_params; } }if (stream->lut3d_func && - stream->lut3d_func->state.bits.initialized ==1 && - stream->lut3d_func->state.bits.rmu_idx_valid ==1 ) { + stream->lut3d_func->state.bits.initialized ==1 && + stream->lut3d_func->state.bits.rmu_idx_valid ==1 ) {if (stream->lut3d_func->state.bits.rmu_mux_num ==0 ) mpcc_id_projected = stream->lut3d_func->state.bits.mpc_rmu0_mux;else if (stream->lut3d_func->state.bits.rmu_mux_num ==1 )
@@ -124,20 +123,22 @@ static bool dcn30_set_mpc_shaper_3dlut( mpcc_id_projected = stream->lut3d_func->state.bits.mpc_rmu2_mux;if (mpcc_id_projected != mpcc_id)BREAK_TO_DEBUGGER (); -/*find the reason why logical layer assigned a differant mpcc_id into acquire_post_bldn_3dlut*/ +/* find the reason why logical layer assigned a different +* mpcc_id into acquire_post_bldn_3dlut +*/ acquired_rmu = mpc->funcs->acquire_rmu (mpc, mpcc_id, - stream->lut3d_func->state.bits.rmu_mux_num); + stream->lut3d_func->state.bits.rmu_mux_num);if (acquired_rmu != stream->lut3d_func->state.bits.rmu_mux_num)BREAK_TO_DEBUGGER (); - result = mpc->funcs->program_3dlut (mpc, - &stream->lut3d_func->lut_3d, - stream->lut3d_func->state.bits.rmu_mux_num); + + result = mpc->funcs->program_3dlut (mpc, &stream->lut3d_func->lut_3d, + stream->lut3d_func->state.bits.rmu_mux_num); result = mpc->funcs->program_shaper (mpc, shaper_lut, - stream->lut3d_func->state.bits.rmu_mux_num); - }else -/*loop through the available mux and release the requested mpcc_id*/ + stream->lut3d_func->state.bits.rmu_mux_num); + }else { +// loop through the available mux and release the requested mpcc_id mpc->funcs->release_rmu (mpc, mpcc_id); - + }return result; }
Signature · 1 line
2.39.0
PATCH 3/6 drm/amd/display: camel case cleanup in color_gamma file
In reply to Melissa WenRename mapUserRamp to map_user_ramp and doClamping to do_clamping
--- .../amd/display/modules/color/color_gamma.c | 50 ++++++++++--------- 1 file changed, 26 insertions(+), 24 deletions(-)
drivers/gpu/drm/amd/display/modules/color/color_gamma.c +26 -24
@@ -1715,8 +1715,8 @@ static bool map_regamma_hw_to_x_user(const struct pwl_float_data_ex *rgb_regamma, uint32_t hw_points_num, struct dc_transfer_func_distributed_points *tf_pts, - bool mapUserRamp, - bool doClamping) + bool map_user_ramp, + bool do_clamping) {/* setup to spare calculated ideal regamma values */
@@ -1724,7 +1724,7 @@ static bool map_regamma_hw_to_x_user(struct hw_x_point *coords = coords_x;const struct pwl_float_data_ex *regamma = rgb_regamma; -if (ramp && mapUserRamp) { +if (ramp && map_user_ramp) {copy_rgb_regamma_to_coordinates_x (coords, hw_points_num, rgb_regamma);
@@ -1744,7 +1744,7 @@ static bool map_regamma_hw_to_x_user( } } -if (doClamping) { +if (do_clamping) {/* this should be named differently, all it does is clamp to 0-1 */ build_new_custom_resulted_curve (hw_points_num, tf_pts); }
@@ -1875,7 +1875,7 @@ bool calculate_user_regamma_ramp(struct dc_transfer_func *output_tf,bool mod_color_calculate_degamma_params (struct dc_color_caps *dc_caps,struct dc_transfer_func *input_tf, -const struct dc_gamma *ramp,bool mapUserRamp) +const struct dc_gamma *ramp,bool map_user_ramp) {struct dc_transfer_func_distributed_points *tf_pts = &input_tf->tf_pts;struct dividers dividers;
@@ -1891,12 +1891,12 @@ bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps,return false;/* we can use hardcoded curve for plain SRGB TF -* If linear, it's bypass if on user ramp +* If linear, it's bypass if no user ramp */ if (input_tf->type ==TF_TYPE_PREDEFINED ) {if ((input_tf->tf ==TRANSFER_FUNCTION_SRGB || input_tf->tf ==TRANSFER_FUNCTION_LINEAR ) && - !mapUserRamp) + !map_user_ramp)return true; if (dc_caps != NULL &&
@@ -1919,7 +1919,7 @@ bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps, input_tf->type =TF_TYPE_DISTRIBUTED_POINTS ; -if (mapUserRamp && ramp && ramp->type ==GAMMA_RGB_256 ) { +if (map_user_ramp && ramp && ramp->type ==GAMMA_RGB_256 ) { rgb_user =kvcalloc (ramp->num_entries + _EXTRA_POINTS,sizeof (*rgb_user),GFP_KERNEL );
@@ -2007,7 +2007,7 @@ bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps,map_regamma_hw_to_x_user (ramp, coeff, rgb_user, coordinates_x, axis_x, curve,MAX_HW_POINTS , tf_pts, - mapUserRamp && ramp && ramp->type ==GAMMA_RGB_256 , + map_user_ramp && ramp && ramp->type ==GAMMA_RGB_256 , true); }
@@ -2112,9 +2112,11 @@ static bool calculate_curve(enum dc_transfer_func_predefined trans, }bool mod_color_calculate_regamma_params (struct dc_transfer_func *output_tf, -const struct dc_gamma *ramp,bool mapUserRamp,bool canRomBeUsed, -const struct hdr_tm_params *fs_params, -struct calculate_buffer *cal_buffer) +const struct dc_gamma *ramp, +bool map_user_ramp, +bool can_rom_be_used, +const struct hdr_tm_params *fs_params, +struct calculate_buffer *cal_buffer) {struct dc_transfer_func_distributed_points *tf_pts = &output_tf->tf_pts;struct dividers dividers;
@@ -2124,26 +2126,26 @@ bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf,struct gamma_pixel *axis_x =NULL ;struct pixel_gamma_point *coeff =NULL ;enum dc_transfer_func_predefined tf =TRANSFER_FUNCTION_SRGB ; -bool doClamping = true; +bool do_clamping = true;bool ret = false;if (output_tf->type ==TF_TYPE_BYPASS )return false;/* we can use hardcoded curve for plain SRGB TF */ -if (output_tf->type ==TF_TYPE_PREDEFINED && canRomBeUsed == true && +if (output_tf->type ==TF_TYPE_PREDEFINED && can_rom_be_used == true && output_tf->tf ==TRANSFER_FUNCTION_SRGB ) {if (ramp ==NULL )return true;if ((ramp->is_identity && ramp->type !=GAMMA_CS_TFM_1D ) || - (!mapUserRamp && ramp->type ==GAMMA_RGB_256 )) + (!map_user_ramp && ramp->type ==GAMMA_RGB_256 ))return true; } output_tf->type =TF_TYPE_DISTRIBUTED_POINTS ;if (ramp && ramp->type !=GAMMA_CS_TFM_1D && - (mapUserRamp || ramp->type !=GAMMA_RGB_256 )) { + (map_user_ramp || ramp->type !=GAMMA_RGB_256 )) { rgb_user =kvcalloc (ramp->num_entries + _EXTRA_POINTS,sizeof (*rgb_user),GFP_KERNEL );
@@ -2164,7 +2166,7 @@ bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf, ramp->num_entries, dividers); -if (ramp->type ==GAMMA_RGB_256 && mapUserRamp) +if (ramp->type ==GAMMA_RGB_256 && map_user_ramp)scale_gamma (rgb_user, ramp, dividers);else if (ramp->type ==GAMMA_RGB_FLOAT_1024 )scale_gamma_dx (rgb_user, ramp, dividers);
@@ -2191,15 +2193,15 @@ bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf, cal_buffer);if (ret) { - doClamping = !(output_tf->tf ==TRANSFER_FUNCTION_GAMMA22 && - fs_params !=NULL && fs_params->skip_tm ==0 ); + do_clamping = !(output_tf->tf ==TRANSFER_FUNCTION_GAMMA22 && + fs_params !=NULL && fs_params->skip_tm ==0 );map_regamma_hw_to_x_user (ramp, coeff, rgb_user, - coordinates_x, axis_x, rgb_regamma, -MAX_HW_POINTS , tf_pts, - (mapUserRamp || (ramp && ramp->type !=GAMMA_RGB_256 )) && - (ramp && ramp->type !=GAMMA_CS_TFM_1D ), - doClamping); + coordinates_x, axis_x, rgb_regamma, +MAX_HW_POINTS , tf_pts, + (map_user_ramp || (ramp && ramp->type !=GAMMA_RGB_256 )) && + (ramp && ramp->type !=GAMMA_CS_TFM_1D ), + do_clamping);if (ramp && ramp->type ==GAMMA_CS_TFM_1D )apply_lut_1d (ramp,MAX_HW_POINTS , tf_pts);
Signature · 1 line
2.39.0
PATCH 4/6 drm/amd/display: unset initial value for tf since it's never used
In reply to Melissa WenIn mod_color_calculate_{degamma/regamma}_params(), a tf variable is initialized as TRANSFER_FUNCTION_SRGB but tf is only used after tf = input->tf, therefore, better to just remove this initial value and avoid misleading interpretations.
--- drivers/gpu/drm/amd/display/modules/color/color_gamma.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/modules/color/color_gamma.c +2 -2
@@ -1883,7 +1883,7 @@ bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps,struct pwl_float_data_ex *curve =NULL ;struct gamma_pixel *axis_x =NULL ;struct pixel_gamma_point *coeff =NULL ; -enum dc_transfer_func_predefined tf =TRANSFER_FUNCTION_SRGB ; +enum dc_transfer_func_predefined tf;uint32_t i;bool ret = false;
@@ -2125,7 +2125,7 @@ bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf,struct pwl_float_data_ex *rgb_regamma =NULL ;struct gamma_pixel *axis_x =NULL ;struct pixel_gamma_point *coeff =NULL ; -enum dc_transfer_func_predefined tf =TRANSFER_FUNCTION_SRGB ; +enum dc_transfer_func_predefined tf;bool do_clamping = true;bool ret = false;
Signature · 1 line
2.39.0
PATCH 5/6 drm/amd/display: remove unused func declaration from resource headers
In reply to Melissa WenThe function resource_validate_ctx_update_pointer_after_copy() is declared in resource.h but never defined, therefore, remove its declaration from headers.
--- drivers/gpu/drm/amd/display/dc/inc/resource.h | 4 ---- 1 file changed, 4 deletions(-)
drivers/gpu/drm/amd/display/dc/inc/resource.h +0 -4
@@ -165,10 +165,6 @@ bool resource_validate_attach_surfaces(struct dc_state *context, const struct resource_pool *pool); -void resource_validate_ctx_update_pointer_after_copy ( -const struct dc_state *src_ctx, -struct dc_state *dst_ctx); - enum dc_status resource_map_clock_resources( const struct dc *dc, struct dc_state *context,
Signature · 1 line
2.39.0
PATCH 6/6 drm/amd/display: remove unused _calculate_degamma_curve function
In reply to Melissa WenWe don't use this function anywhere, therefore, remove it.
--- .../amd/display/modules/color/color_gamma.c | 86 ------------------- .../amd/display/modules/color/color_gamma.h | 3 - 2 files changed, 89 deletions(-)
drivers/gpu/drm/amd/display/modules/color/color_gamma.c +0 -86
@@ -2217,89 +2217,3 @@ bool mod_color_calculate_regamma_params(struct dc_transfer_func *output_tf, rgb_user_alloc_fail:return ret; } - -bool mod_color_calculate_degamma_curve (enum dc_transfer_func_predefined trans, -struct dc_transfer_func_distributed_points *points) -{ -uint32_t i; -bool ret = false; -struct pwl_float_data_ex *rgb_degamma =NULL ; - -if (trans ==TRANSFER_FUNCTION_UNITY || - trans ==TRANSFER_FUNCTION_LINEAR ) { - -for (i =0 ; i <=MAX_HW_POINTS ; i++) { - points->red[i] = coordinates_x[i].x; - points->green[i] = coordinates_x[i].x; - points->blue[i] = coordinates_x[i].x; - } - ret = true; - }else if (trans ==TRANSFER_FUNCTION_PQ ) { - rgb_degamma =kvcalloc (MAX_HW_POINTS + _EXTRA_POINTS, -sizeof (*rgb_degamma), -GFP_KERNEL ); -if (!rgb_degamma) - goto rgb_degamma_alloc_fail; - - -build_de_pq (rgb_degamma, -MAX_HW_POINTS , - coordinates_x); -for (i =0 ; i <=MAX_HW_POINTS ; i++) { - points->red[i] = rgb_degamma[i].r; - points->green[i] = rgb_degamma[i].g; - points->blue[i] = rgb_degamma[i].b; - } - ret = true; - -kvfree (rgb_degamma); - }else if (trans ==TRANSFER_FUNCTION_SRGB || - trans ==TRANSFER_FUNCTION_BT709 || - trans ==TRANSFER_FUNCTION_GAMMA22 || - trans ==TRANSFER_FUNCTION_GAMMA24 || - trans ==TRANSFER_FUNCTION_GAMMA26 ) { - rgb_degamma =kvcalloc (MAX_HW_POINTS + _EXTRA_POINTS, -sizeof (*rgb_degamma), -GFP_KERNEL ); -if (!rgb_degamma) - goto rgb_degamma_alloc_fail; - -build_degamma (rgb_degamma, -MAX_HW_POINTS , - coordinates_x, - trans); -for (i =0 ; i <=MAX_HW_POINTS ; i++) { - points->red[i] = rgb_degamma[i].r; - points->green[i] = rgb_degamma[i].g; - points->blue[i] = rgb_degamma[i].b; - } - ret = true; - -kvfree (rgb_degamma); - }else if (trans ==TRANSFER_FUNCTION_HLG ) { - rgb_degamma =kvcalloc (MAX_HW_POINTS + _EXTRA_POINTS, -sizeof (*rgb_degamma), -GFP_KERNEL ); -if (!rgb_degamma) - goto rgb_degamma_alloc_fail; - -build_hlg_degamma (rgb_degamma, -MAX_HW_POINTS , - coordinates_x, -80 ,1000 ); -for (i =0 ; i <=MAX_HW_POINTS ; i++) { - points->red[i] = rgb_degamma[i].r; - points->green[i] = rgb_degamma[i].g; - points->blue[i] = rgb_degamma[i].b; - } - ret = true; -kvfree (rgb_degamma); - } - points->end_exponent =0 ; - points->x_point_at_y1_red =1 ; - points->x_point_at_y1_green =1 ; - points->x_point_at_y1_blue =1 ; - -rgb_degamma_alloc_fail: -return ret; -}
drivers/gpu/drm/amd/display/modules/color/color_gamma.h +0 -3
@@ -115,9 +115,6 @@ bool mod_color_calculate_degamma_params(struct dc_color_caps *dc_caps,struct dc_transfer_func *output_tf, const struct dc_gamma *ramp, bool mapUserRamp); -bool mod_color_calculate_degamma_curve (enum dc_transfer_func_predefined trans, -struct dc_transfer_func_distributed_points *points); - bool calculate_user_regamma_coeff(struct dc_transfer_func *output_tf, const struct regamma_lut *regamma, struct calculate_buffer *cal_buffer,
Signature · 1 line
2.39.0
Am 14.02.23 um 13:14 schrieb Melissa Wen:
Quoted 11 lines
Hi,
Sorry for the noise, but while I've been working on wiring 3D LUT support to AMD display driver [1] I found some annoying code style issues in the shared-code part. So I'm just sending what I've been cleaning to better examine the code.
Most seem trivial, except the last one "remove unused
_calculate_degamma_curve" since this could just be a matter of missing parts. If so, happy to remove the patch and include a comment describing the situation (or the potential usage of it).
The display stack is not my field of expertise, but those cleanups are so obvious that I think I can safely give my Reviewed-by: Christian König <[email protected]> for the entire series.
Thanks,
Christian.
Quoted 23 lines
Thanks,
Melissa
[1] https://lore.kernel.org/dri-devel/[email protected]/
Melissa Wen (6):
drm/amd/display: ident braces indcn30_acquire_post_bldn_3dlut
correctly
drm/amd/display: clean code-style issues indcn30_set_mpc_shaper_3dlutdrm/amd/display: camel case cleanup incolor_gammafile drm/amd/display: unset initial value for tf since it's never used drm/amd/display: remove unused func declaration from resource headers drm/amd/display: remove unused_calculate_degamma_curvefunction.../drm/amd/display/dc/dcn30/dcn30_hwseq.c | 37 ++--- .../drm/amd/display/dc/dcn30/dcn30_resource.c | 2 +- drivers/gpu/drm/amd/display/dc/inc/resource.h | 4 - .../amd/display/modules/color/color_gamma.c | 140 ++++-------------- .../amd/display/modules/color/color_gamma.h | 3 - 5 files changed, 48 insertions(+), 138 deletions(-)
Alex Deucher
AppliedApplied. Thanks!
Alex
Quoted 45 lines · Christian König
Am 14.02.23 um 13:14 schrieb Melissa Wen:
Quoted 11 lines
Hi,
Sorry for the noise, but while I've been working on wiring 3D LUT support to AMD display driver [1] I found some annoying code style issues in the shared-code part. So I'm just sending what I've been cleaning to better examine the code.
Most seem trivial, except the last one "remove unused
_calculate_degamma_curve" since this could just be a matter of missing parts. If so, happy to remove the patch and include a comment describing the situation (or the potential usage of it).The display stack is not my field of expertise, but those cleanups are so obvious that I think I can safely give my Reviewed-by: Christian König <[email protected]> for the entire series.
Thanks,
Christian.Quoted 23 lines
Thanks,
Melissa
[1] https://lore.kernel.org/dri-devel/[email protected]/
Melissa Wen (6):
drm/amd/display: ident braces indcn30_acquire_post_bldn_3dlut
correctly
drm/amd/display: clean code-style issues indcn30_set_mpc_shaper_3dlutdrm/amd/display: camel case cleanup incolor_gammafile drm/amd/display: unset initial value for tf since it's never used drm/amd/display: remove unused func declaration from resource headers drm/amd/display: remove unused_calculate_degamma_curvefunction.../drm/amd/display/dc/dcn30/dcn30_hwseq.c | 37 ++--- .../drm/amd/display/dc/dcn30/dcn30_resource.c | 2 +- drivers/gpu/drm/amd/display/dc/inc/resource.h | 4 - .../amd/display/modules/color/color_gamma.c | 140 ++++-------------- .../amd/display/modules/color/color_gamma.h | 3 - 5 files changed, 48 insertions(+), 138 deletions(-)