Skip to content

Commit 09cb922

Browse files
Samson Tamalexdeucher
authored andcommitted
drm/amd/display: Add debug options to change sharpen policies
[WHY] Add options to change sharpen policy based on surface format and scaling ratios. [HOW] Add sharpen_policy to change policy based on surface format and scale_to_sharpness_policy based on scaling ratios. Reviewed-by: Jun Lei <jun.lei@amd.com> Signed-off-by: Samson Tam <Samson.Tam@amd.com> Signed-off-by: Alex Hung <alex.hung@amd.com> Tested-by: Daniel Wheeler <daniel.wheeler@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 0765b2a commit 09cb922

6 files changed

Lines changed: 128 additions & 19 deletions

File tree

drivers/gpu/drm/amd/display/dc/dc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,8 @@ struct dc_debug_options {
10561056
unsigned int force_lls;
10571057
bool notify_dpia_hr_bw;
10581058
bool enable_ips_visual_confirm;
1059+
unsigned int sharpen_policy;
1060+
unsigned int scale_to_sharpness_policy;
10591061
};
10601062

10611063

drivers/gpu/drm/amd/display/dc/dc_spl_translate.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ void translate_SPL_in_params_from_pipe_ctx(struct pipe_ctx *pipe_ctx, struct spl
186186

187187
spl_in->h_active = pipe_ctx->plane_res.scl_data.h_active;
188188
spl_in->v_active = pipe_ctx->plane_res.scl_data.v_active;
189+
190+
spl_in->debug.sharpen_policy = (enum sharpen_policy)pipe_ctx->stream->ctx->dc->debug.sharpen_policy;
191+
spl_in->debug.scale_to_sharpness_policy =
192+
(enum scale_to_sharpness_policy)pipe_ctx->stream->ctx->dc->debug.scale_to_sharpness_policy;
193+
189194
/* Check if it is stream is in fullscreen and if its HDR.
190195
* Use this to determine sharpness levels
191196
*/

drivers/gpu/drm/amd/display/dc/spl/dc_spl.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -813,13 +813,22 @@ static bool enable_easf(struct spl_in *spl_in, struct spl_scratch *spl_scratch)
813813
return skip_easf;
814814
}
815815

816+
/* Check if video is in fullscreen mode */
817+
static bool spl_is_video_fullscreen(struct spl_in *spl_in)
818+
{
819+
if (spl_is_yuv420(spl_in->basic_in.format) && spl_in->is_fullscreen)
820+
return true;
821+
return false;
822+
}
823+
816824
static bool spl_get_isharp_en(struct spl_in *spl_in,
817825
struct spl_scratch *spl_scratch)
818826
{
819827
bool enable_isharp = false;
820828
int vratio = 0;
821829
int hratio = 0;
822830
struct spl_taps taps = spl_scratch->scl_data.taps;
831+
bool fullscreen = spl_is_video_fullscreen(spl_in);
823832

824833
/* Return if adaptive sharpness is disabled */
825834
if (spl_in->adaptive_sharpness.enable == false)
@@ -835,9 +844,15 @@ static bool spl_get_isharp_en(struct spl_in *spl_in,
835844
// Scaling is up to 1:1 (no scaling) or upscaling
836845

837846
/*
838-
* Apply sharpness to all RGB surfaces and to
839-
* NV12/P010 surfaces
847+
* Apply sharpness to RGB and YUV (NV12/P010)
848+
* surfaces based on policy setting
840849
*/
850+
if (!spl_is_yuv420(spl_in->basic_in.format) &&
851+
(spl_in->debug.sharpen_policy == SHARPEN_YUV))
852+
return enable_isharp;
853+
else if ((spl_is_yuv420(spl_in->basic_in.format) && !fullscreen) &&
854+
(spl_in->debug.sharpen_policy == SHARPEN_RGB_FULLSCREEN_YUV))
855+
return enable_isharp;
841856

842857
/*
843858
* Apply sharpness if supports horizontal taps 4,6 AND
@@ -1562,14 +1577,19 @@ static void spl_set_isharp_data(struct dscl_prog_data *dscl_prog_data,
15621577
struct adaptive_sharpness adp_sharpness, bool enable_isharp,
15631578
enum linear_light_scaling lls_pref, enum spl_pixel_format format,
15641579
const struct spl_scaler_data *data, struct spl_fixed31_32 ratio,
1565-
enum system_setup setup)
1580+
enum system_setup setup, enum scale_to_sharpness_policy scale_to_sharpness_policy)
15661581
{
15671582
/* Turn off sharpener if not required */
15681583
if (!enable_isharp) {
15691584
dscl_prog_data->isharp_en = 0;
15701585
return;
15711586
}
15721587

1588+
spl_build_isharp_1dlut_from_reference_curve(ratio, setup, adp_sharpness,
1589+
scale_to_sharpness_policy);
1590+
dscl_prog_data->isharp_delta = spl_get_pregen_filter_isharp_1D_lut(setup);
1591+
dscl_prog_data->sharpness_level = adp_sharpness.sharpness_level;
1592+
15731593
dscl_prog_data->isharp_en = 1; // ISHARP_EN
15741594
// Set ISHARP_NOISEDET_MODE if htaps = 6-tap
15751595
if (data->taps.h_taps == 6) {
@@ -1667,11 +1687,6 @@ static void spl_set_isharp_data(struct dscl_prog_data *dscl_prog_data,
16671687
dscl_prog_data->isharp_lba.base_seg[5] = 0; // ISHARP LBA PWL for Seg 5. BASE value in U0.6 format
16681688
}
16691689

1670-
1671-
spl_build_isharp_1dlut_from_reference_curve(ratio, setup, adp_sharpness);
1672-
dscl_prog_data->isharp_delta = spl_get_pregen_filter_isharp_1D_lut(setup);
1673-
dscl_prog_data->sharpness_level = adp_sharpness.sharpness_level;
1674-
16751690
// Program the nldelta soft clip values
16761691
if (lls_pref == LLS_PREF_YES) {
16771692
dscl_prog_data->isharp_nldelta_sclip.enable_p = 0; /* ISHARP_NLDELTA_SCLIP_EN_P */
@@ -1766,7 +1781,8 @@ bool spl_calculate_scaler_params(struct spl_in *spl_in, struct spl_out *spl_out)
17661781
isharp_scale_ratio = spl_scratch.scl_data.recip_ratios.horz;
17671782

17681783
spl_set_isharp_data(spl_out->dscl_prog_data, spl_in->adaptive_sharpness, enable_isharp,
1769-
spl_in->lls_pref, spl_in->basic_in.format, data, isharp_scale_ratio, setup);
1784+
spl_in->lls_pref, spl_in->basic_in.format, data, isharp_scale_ratio, setup,
1785+
spl_in->debug.scale_to_sharpness_policy);
17701786

17711787
return res;
17721788
}

drivers/gpu/drm/amd/display/dc/spl/dc_spl_isharp_filters.c

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,15 @@ struct isharp_1D_lut_pregen filter_isharp_1D_lut_pregen[NUM_SHARPNESS_SETUPS] =
500500
},
501501
};
502502

503+
struct scale_ratio_to_sharpness_level_adj sharpness_level_adj[NUM_SHARPNESS_ADJ_LEVELS] = {
504+
{1125, 1000, 0},
505+
{11, 10, 1},
506+
{1075, 1000, 2},
507+
{105, 100, 3},
508+
{1025, 1000, 4},
509+
{1, 1, 5},
510+
};
511+
503512
const uint32_t *spl_get_filter_isharp_1D_lut_0(void)
504513
{
505514
return filter_isharp_1D_lut_0;
@@ -541,35 +550,99 @@ uint16_t *spl_get_filter_isharp_bs_3tap_64p(void)
541550
return filter_isharp_bs_3tap_64p_s1_12;
542551
}
543552

544-
static unsigned int spl_calculate_sharpness_level(int discrete_sharpness_level, enum system_setup setup,
545-
struct spl_sharpness_range sharpness_range)
553+
static unsigned int spl_calculate_sharpness_level_adj(struct spl_fixed31_32 ratio)
554+
{
555+
int j;
556+
struct spl_fixed31_32 ratio_level;
557+
struct scale_ratio_to_sharpness_level_adj *lookup_ptr;
558+
unsigned int sharpness_level_down_adj;
559+
560+
/*
561+
* Adjust sharpness level based on current scaling ratio
562+
*
563+
* We have 5 discrete scaling ratios which we will use to adjust the
564+
* sharpness level down by 1 as we pass each ratio. The ratios
565+
* are
566+
*
567+
* 1.125 upscale and higher - no adj
568+
* 1.100 - under 1.125 - adj level down 1
569+
* 1.075 - under 1.100 - adj level down 2
570+
* 1.050 - under 1.075 - adj level down 3
571+
* 1.025 - under 1.050 - adj level down 4
572+
* 1.000 - under 1.025 - adj level down 5
573+
*
574+
*/
575+
j = 0;
576+
sharpness_level_down_adj = 0;
577+
lookup_ptr = sharpness_level_adj;
578+
while (j < NUM_SHARPNESS_ADJ_LEVELS) {
579+
ratio_level = spl_fixpt_from_fraction(lookup_ptr->ratio_numer,
580+
lookup_ptr->ratio_denom);
581+
if (ratio.value >= ratio_level.value) {
582+
sharpness_level_down_adj = lookup_ptr->level_down_adj;
583+
break;
584+
}
585+
lookup_ptr++;
586+
j++;
587+
}
588+
return sharpness_level_down_adj;
589+
}
590+
591+
static unsigned int spl_calculate_sharpness_level(struct spl_fixed31_32 ratio,
592+
int discrete_sharpness_level, enum system_setup setup,
593+
struct spl_sharpness_range sharpness_range,
594+
enum scale_to_sharpness_policy scale_to_sharpness_policy)
546595
{
547596
unsigned int sharpness_level = 0;
597+
unsigned int sharpness_level_down_adj = 0;
548598

549599
int min_sharpness, max_sharpness, mid_sharpness;
550600

601+
/*
602+
* Adjust sharpness level if policy requires we adjust it based on
603+
* scale ratio. Based on scale ratio, we may adjust the sharpness
604+
* level down by a certain number of steps. We will not select
605+
* a sharpness value of 0 so the lowest sharpness level will be
606+
* 0 or 1 depending on what the min_sharpness is
607+
*
608+
* If the policy is no required, this code maybe removed at a later
609+
* date
610+
*/
551611
switch (setup) {
552612

553613
case HDR_L:
554614
min_sharpness = sharpness_range.hdr_rgb_min;
555615
max_sharpness = sharpness_range.hdr_rgb_max;
556616
mid_sharpness = sharpness_range.hdr_rgb_mid;
617+
if (scale_to_sharpness_policy == SCALE_TO_SHARPNESS_ADJ_ALL)
618+
sharpness_level_down_adj = spl_calculate_sharpness_level_adj(ratio);
557619
break;
558620
case HDR_NL:
559621
/* currently no use case, use Non-linear SDR values for now */
560622
case SDR_NL:
561623
min_sharpness = sharpness_range.sdr_yuv_min;
562624
max_sharpness = sharpness_range.sdr_yuv_max;
563625
mid_sharpness = sharpness_range.sdr_yuv_mid;
626+
if (scale_to_sharpness_policy >= SCALE_TO_SHARPNESS_ADJ_YUV)
627+
sharpness_level_down_adj = spl_calculate_sharpness_level_adj(ratio);
564628
break;
565629
case SDR_L:
566630
default:
567631
min_sharpness = sharpness_range.sdr_rgb_min;
568632
max_sharpness = sharpness_range.sdr_rgb_max;
569633
mid_sharpness = sharpness_range.sdr_rgb_mid;
634+
if (scale_to_sharpness_policy == SCALE_TO_SHARPNESS_ADJ_ALL)
635+
sharpness_level_down_adj = spl_calculate_sharpness_level_adj(ratio);
570636
break;
571637
}
572638

639+
if ((min_sharpness == 0) && (sharpness_level_down_adj >= discrete_sharpness_level))
640+
discrete_sharpness_level = 1;
641+
else if (sharpness_level_down_adj >= discrete_sharpness_level)
642+
discrete_sharpness_level = 0;
643+
else
644+
discrete_sharpness_level -= sharpness_level_down_adj;
645+
573646
int lower_half_step_size = (mid_sharpness - min_sharpness) / 5;
574647
int upper_half_step_size = (max_sharpness - mid_sharpness) / 5;
575648

@@ -584,7 +657,7 @@ static unsigned int spl_calculate_sharpness_level(int discrete_sharpness_level,
584657
}
585658

586659
void spl_build_isharp_1dlut_from_reference_curve(struct spl_fixed31_32 ratio, enum system_setup setup,
587-
struct adaptive_sharpness sharpness)
660+
struct adaptive_sharpness sharpness, enum scale_to_sharpness_policy scale_to_sharpness_policy)
588661
{
589662
uint8_t *byte_ptr_1dlut_src, *byte_ptr_1dlut_dst;
590663
struct spl_fixed31_32 sharp_base, sharp_calc, sharp_level;
@@ -594,8 +667,9 @@ void spl_build_isharp_1dlut_from_reference_curve(struct spl_fixed31_32 ratio, en
594667
uint32_t filter_pregen_store[ISHARP_LUT_TABLE_SIZE];
595668

596669
/* Custom sharpnessX1000 value */
597-
unsigned int sharpnessX1000 = spl_calculate_sharpness_level(sharpness.sharpness_level,
598-
setup, sharpness.sharpness_range);
670+
unsigned int sharpnessX1000 = spl_calculate_sharpness_level(ratio,
671+
sharpness.sharpness_level, setup,
672+
sharpness.sharpness_range, scale_to_sharpness_policy);
599673
sharp_level = spl_fixpt_from_fraction(sharpnessX1000, 1000);
600674

601675
/*
@@ -606,7 +680,6 @@ void spl_build_isharp_1dlut_from_reference_curve(struct spl_fixed31_32 ratio, en
606680
(filter_isharp_1D_lut_pregen[setup].sharpness_denom == 1000))
607681
return;
608682

609-
610683
/*
611684
* Calculate LUT_128_gained with this equation:
612685
*

drivers/gpu/drm/amd/display/dc/spl/dc_spl_isharp_filters.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ uint16_t *spl_get_filter_isharp_bs_3tap_64p(void);
2020
const uint16_t *spl_get_filter_isharp_wide_6tap_64p(void);
2121
uint16_t *spl_dscl_get_blur_scale_coeffs_64p(int taps);
2222

23-
struct scale_ratio_to_sharpness_level_lookup {
23+
#define NUM_SHARPNESS_ADJ_LEVELS 6
24+
struct scale_ratio_to_sharpness_level_adj {
2425
unsigned int ratio_numer;
2526
unsigned int ratio_denom;
26-
unsigned int sharpness_numer;
27-
unsigned int sharpness_denom;
27+
unsigned int level_down_adj; /* adjust sharpness level down */
2828
};
2929

3030
struct isharp_1D_lut_pregen {
@@ -45,6 +45,7 @@ void spl_init_blur_scale_coeffs(void);
4545
void spl_set_blur_scale_data(struct dscl_prog_data *dscl_prog_data,
4646
const struct spl_scaler_data *data);
4747

48-
void spl_build_isharp_1dlut_from_reference_curve(struct spl_fixed31_32 ratio, enum system_setup setup, struct adaptive_sharpness sharpness);
48+
void spl_build_isharp_1dlut_from_reference_curve(struct spl_fixed31_32 ratio, enum system_setup setup,
49+
struct adaptive_sharpness sharpness, enum scale_to_sharpness_policy scale_to_sharpness_policy);
4950
uint32_t *spl_get_pregen_filter_isharp_1D_lut(enum system_setup setup);
5051
#endif /* __DC_SPL_ISHARP_FILTERS_H__ */

drivers/gpu/drm/amd/display/dc/spl/dc_spl_types.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,16 @@ enum linear_light_scaling { // convert it in translation logic
487487
LLS_PREF_YES,
488488
LLS_PREF_NO
489489
};
490+
enum sharpen_policy {
491+
SHARPEN_ALWAYS = 0,
492+
SHARPEN_YUV = 1,
493+
SHARPEN_RGB_FULLSCREEN_YUV = 2
494+
};
495+
enum scale_to_sharpness_policy {
496+
NO_SCALE_TO_SHARPNESS_ADJ = 0,
497+
SCALE_TO_SHARPNESS_ADJ_YUV = 1,
498+
SCALE_TO_SHARPNESS_ADJ_ALL = 2
499+
};
490500
struct spl_funcs {
491501
void (*spl_calc_lb_num_partitions)
492502
(bool alpha_en,
@@ -499,6 +509,8 @@ struct spl_funcs {
499509
struct spl_debug {
500510
int visual_confirm_base_offset;
501511
int visual_confirm_dpp_offset;
512+
enum sharpen_policy sharpen_policy;
513+
enum scale_to_sharpness_policy scale_to_sharpness_policy;
502514
};
503515

504516
struct spl_in {

0 commit comments

Comments
 (0)