When linearizing (degamma), the input is an encoded signal bounded to [0,1] and PQ/sRGB EOTFs are steepest near 1. To increase precision in the brightest half without increasing total LUT usage, change region/segment distribution only for PQ/sRGB pre-defined degamma TF by halving the #pts as you go down, so 128 pts in the top region, then 64 in the next smaller, 32 etc. This way the spacing in [0.5,1] region is (1-0.5)/128, in [0.25,0.5] region it's (0.5-0.25)/64 == 0.5/128, and so on.
Suggested-by: Krunoslav Kovac <[email protected]> Signed-off-by: Melissa Wen <[email protected]> --- .../amd/display/dc/dcn30/dcn30_cm_common.c | 33 ++++++++++++++----- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c index b5cb2cd312ba..dc91054134ee 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c +++ b/drivers/gpu/drm/amd/display/dc/dcn30/dcn30_cm_common.c @@ -301,8 +301,6 @@ bool cm3_helper_translate_curve_to_hw_format(struct dc_context *ctx, return true; } -#define NUM_DEGAMMA_REGIONS 12 - /* Linear interpolation of tf_pts entries, where (i >> 4) is the integer tf_pts * index, (i & 0xf) is the 1/16 sub-position. */ @@ -343,17 +341,34 @@ bool cm3_helper_translate_curve_to_degamma_hw_format( memset(lut_params, 0, sizeof(struct pwl_params)); memset(seg_distr, 0, sizeof(seg_distr)); - region_start = -NUM_DEGAMMA_REGIONS; - region_end = 0; + if (output_tf->tf == TRANSFER_FUNCTION_PQ || + output_tf->tf == TRANSFER_FUNCTION_SRGB) { + /* 9 segments + * segments are from 2^-9 to 0 + */ + const uint8_t SEG_COUNT = 9; + seg_distr[0] = 0; // Since we only have one point in darkest region + for (k = 1; k < SEG_COUNT; k++) + seg_distr[k] = k - 1; // 2^(k-1) points per region; halves as k decreases + region_start = -SEG_COUNT; + region_end = 0; + } else { + /* 12 segments + * segments are from 2^-12 to 2^0 + * There are less than 256 points, for optimization + */ + const uint8_t SEG_COUNT = 12; + + for (i = 0; i < SEG_COUNT; i++) + seg_distr[i] = 4; + + region_start = -SEG_COUNT; + region_end = 0; + } for (i = region_end - region_start; i < MAX_REGIONS_NUMBER ; i++) seg_distr[i] = -1; - /* 12 segments - * segments are from 2^-12 to 0 - */ - for (i = 0; i < NUM_DEGAMMA_REGIONS ; i++) - seg_distr[i] = 4; for (k = 0; k < MAX_REGIONS_NUMBER; k++) { if (seg_distr[k] != -1) -- 2.53.0
