diff options
author | Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com> | 2017-11-28 16:20:45 -0500 |
---|---|---|
committer | Alex Deucher <alexander.deucher@amd.com> | 2017-12-14 11:00:53 -0500 |
commit | 78b56c52349596374dd47584d1f1db4d08609b7b (patch) | |
tree | 46ab247d6c38b42fa0ffbb02189159eaa61bb663 | |
parent | 51ca0b036223660e0db10e2bf6097a0689f5fa44 (diff) |
drm/amd/display: use clamping rather than truncation for CM fp conversions
Signed-off-by: Dmytro Laktyushkin <Dmytro.Laktyushkin@amd.com>
Reviewed-by: Tony Cheng <Tony.Cheng@amd.com>
Acked-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
-rw-r--r-- | drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c | 24 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/display/dc/dcn10/dcn10_cm_common.c | 14 | ||||
-rw-r--r-- | drivers/gpu/drm/amd/display/include/fixed31_32.h | 4 |
3 files changed, 29 insertions, 13 deletions
diff --git a/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c b/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c index 13f8b8c02212..011a97f82fb6 100644 --- a/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c +++ b/drivers/gpu/drm/amd/display/dc/basics/fixpt31_32.c | |||
@@ -554,6 +554,22 @@ static inline uint32_t ux_dy( | |||
554 | return result | fractional_part; | 554 | return result | fractional_part; |
555 | } | 555 | } |
556 | 556 | ||
557 | static inline uint32_t clamp_ux_dy( | ||
558 | int64_t value, | ||
559 | uint32_t integer_bits, | ||
560 | uint32_t fractional_bits, | ||
561 | uint32_t min_clamp) | ||
562 | { | ||
563 | uint32_t truncated_val = ux_dy(value, integer_bits, fractional_bits); | ||
564 | |||
565 | if (value >= (1LL << (integer_bits + FIXED31_32_BITS_PER_FRACTIONAL_PART))) | ||
566 | return (1 << (integer_bits + fractional_bits)) - 1; | ||
567 | else if (truncated_val > min_clamp) | ||
568 | return truncated_val; | ||
569 | else | ||
570 | return min_clamp; | ||
571 | } | ||
572 | |||
557 | uint32_t dal_fixed31_32_u2d19( | 573 | uint32_t dal_fixed31_32_u2d19( |
558 | struct fixed31_32 arg) | 574 | struct fixed31_32 arg) |
559 | { | 575 | { |
@@ -566,14 +582,14 @@ uint32_t dal_fixed31_32_u0d19( | |||
566 | return ux_dy(arg.value, 0, 19); | 582 | return ux_dy(arg.value, 0, 19); |
567 | } | 583 | } |
568 | 584 | ||
569 | uint32_t dal_fixed31_32_u0d14( | 585 | uint32_t dal_fixed31_32_clamp_u0d14( |
570 | struct fixed31_32 arg) | 586 | struct fixed31_32 arg) |
571 | { | 587 | { |
572 | return ux_dy(arg.value, 1, 14); | 588 | return clamp_ux_dy(arg.value, 0, 14, 1); |
573 | } | 589 | } |
574 | 590 | ||
575 | uint32_t dal_fixed31_32_u0d10( | 591 | uint32_t dal_fixed31_32_clamp_u0d10( |
576 | struct fixed31_32 arg) | 592 | struct fixed31_32 arg) |
577 | { | 593 | { |
578 | return ux_dy(arg.value, 1, 10); | 594 | return clamp_ux_dy(arg.value, 0, 10, 1); |
579 | } | 595 | } |
diff --git a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_cm_common.c b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_cm_common.c index 352ae7bf9a3f..53ba3600ee6a 100644 --- a/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_cm_common.c +++ b/drivers/gpu/drm/amd/display/dc/dcn10/dcn10_cm_common.c | |||
@@ -169,7 +169,7 @@ bool cm_helper_convert_to_custom_float( | |||
169 | } | 169 | } |
170 | 170 | ||
171 | if (fixpoint == true) | 171 | if (fixpoint == true) |
172 | arr_points[1].custom_float_y = dal_fixed31_32_u0d14(arr_points[1].y); | 172 | arr_points[1].custom_float_y = dal_fixed31_32_clamp_u0d14(arr_points[1].y); |
173 | else if (!convert_to_custom_float_format(arr_points[1].y, &fmt, | 173 | else if (!convert_to_custom_float_format(arr_points[1].y, &fmt, |
174 | &arr_points[1].custom_float_y)) { | 174 | &arr_points[1].custom_float_y)) { |
175 | BREAK_TO_DEBUGGER(); | 175 | BREAK_TO_DEBUGGER(); |
@@ -395,12 +395,12 @@ bool cm_helper_translate_curve_to_hw_format( | |||
395 | rgb->delta_blue = dal_fixed31_32_sub(rgb_plus_1->blue, rgb->blue); | 395 | rgb->delta_blue = dal_fixed31_32_sub(rgb_plus_1->blue, rgb->blue); |
396 | 396 | ||
397 | if (fixpoint == true) { | 397 | if (fixpoint == true) { |
398 | rgb->delta_red_reg = dal_fixed31_32_u0d10(rgb->delta_red); | 398 | rgb->delta_red_reg = dal_fixed31_32_clamp_u0d10(rgb->delta_red); |
399 | rgb->delta_green_reg = dal_fixed31_32_u0d10(rgb->delta_green); | 399 | rgb->delta_green_reg = dal_fixed31_32_clamp_u0d10(rgb->delta_green); |
400 | rgb->delta_blue_reg = dal_fixed31_32_u0d10(rgb->delta_blue); | 400 | rgb->delta_blue_reg = dal_fixed31_32_clamp_u0d10(rgb->delta_blue); |
401 | rgb->red_reg = dal_fixed31_32_u0d14(rgb->red); | 401 | rgb->red_reg = dal_fixed31_32_clamp_u0d14(rgb->red); |
402 | rgb->green_reg = dal_fixed31_32_u0d14(rgb->green); | 402 | rgb->green_reg = dal_fixed31_32_clamp_u0d14(rgb->green); |
403 | rgb->blue_reg = dal_fixed31_32_u0d14(rgb->blue); | 403 | rgb->blue_reg = dal_fixed31_32_clamp_u0d14(rgb->blue); |
404 | } | 404 | } |
405 | 405 | ||
406 | ++rgb_plus_1; | 406 | ++rgb_plus_1; |
diff --git a/drivers/gpu/drm/amd/display/include/fixed31_32.h b/drivers/gpu/drm/amd/display/include/fixed31_32.h index c4848fadc70e..4badaedbaadd 100644 --- a/drivers/gpu/drm/amd/display/include/fixed31_32.h +++ b/drivers/gpu/drm/amd/display/include/fixed31_32.h | |||
@@ -464,10 +464,10 @@ uint32_t dal_fixed31_32_u0d19( | |||
464 | struct fixed31_32 arg); | 464 | struct fixed31_32 arg); |
465 | 465 | ||
466 | 466 | ||
467 | uint32_t dal_fixed31_32_u0d14( | 467 | uint32_t dal_fixed31_32_clamp_u0d14( |
468 | struct fixed31_32 arg); | 468 | struct fixed31_32 arg); |
469 | 469 | ||
470 | uint32_t dal_fixed31_32_u0d10( | 470 | uint32_t dal_fixed31_32_clamp_u0d10( |
471 | struct fixed31_32 arg); | 471 | struct fixed31_32 arg); |
472 | 472 | ||
473 | #endif | 473 | #endif |