<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<div id="appendonsend"></div>
<div style="font-family:Calibri,Arial,Helvetica,sans-serif; font-size:12pt; color:rgb(0,0,0)">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b> Koenig, Christian <Christian.Koenig@amd.com><br>
<b>Sent:</b> Friday, September 24, 2021 1:33 AM<br>
<b>To:</b> Zhuo, Qingqing <Qingqing.Zhuo@amd.com>; amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Jacob, Anson <Anson.Jacob@amd.com>; Wu, Hersen <hersenxs.wu@amd.com>; Wentland, Harry <Harry.Wentland@amd.com>; Siqueira, Rodrigo <Rodrigo.Siqueira@amd.com><br>
<b>Subject:</b> Re: [PATCH v2] drm/amd/display: move FPU associated DSC code to DML folder</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">Am 24.09.21 um 05:22 schrieb Qingqing Zhuo:<br>
> As part of the FPU isolation work documented in<br>
> <a href="https://patchwork.freedesktop.org/series/93042/">https://patchwork.freedesktop.org/series/93042/</a>, isolate<br>
> code that uses FPU in DSC to DML, where all FPU code<br>
> should locate.<br>
><br>
> This change does not refactor any fuctions but move code<br>
> around.<br>
><br>
> v2: remove more floating point related flags in dml/Makefile<br>
><br>
> Cc: Anson Jacob <Anson.Jacob@amd.com><br>
> Cc: Christian König <christian.koenig@amd.com><br>
> Cc: Hersen Wu <hersenxs.wu@amd.com><br>
> Cc: Harry Wentland <harry.wentland@amd.com><br>
> Cc: Rodrigo Siqueira <Rodrigo.Siqueira@amd.com><br>
> Signed-off-by: Qingqing Zhuo <qingqing.zhuo@amd.com><br>
> ---<br>
> dc/dml/dsc/rc_calc_fpu.c | 291 ++++++++++++++++++<br>
> dc/dml/dsc/rc_calc_fpu.h | 98 ++++++<br>
> drivers/gpu/drm/amd/display/dc/dml/Makefile | 3 +<br>
> .../amd/display/dc/{ => dml}/dsc/qp_tables.h | 0<br>
> .../drm/amd/display/dc/dml/dsc/rc_calc_fpu.c | 287 +++++++++++++++++<br>
> .../drm/amd/display/dc/dml/dsc/rc_calc_fpu.h | 89 ++++++<br>
> drivers/gpu/drm/amd/display/dc/dsc/Makefile | 29 --<br>
> drivers/gpu/drm/amd/display/dc/dsc/rc_calc.c | 257 ----------------<br>
> drivers/gpu/drm/amd/display/dc/dsc/rc_calc.h | 50 +--<br>
> .../gpu/drm/amd/display/dc/dsc/rc_calc_dpi.c | 1 -<br>
> 10 files changed, 769 insertions(+), 336 deletions(-)<br>
> create mode 100644 dc/dml/dsc/rc_calc_fpu.c<br>
> create mode 100644 dc/dml/dsc/rc_calc_fpu.h<br>
> rename drivers/gpu/drm/amd/display/dc/{ => dml}/dsc/qp_tables.h (100%)<br>
> create mode 100644 drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.c<br>
> create mode 100644 drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.h<br>
<br>
That looks like the diff is somehow a bit messed up.<br>
<br>
Why do you have both dc/dml/dsc/rc_calc_fpu.c and <br>
drm/amd/display/dc/dml/dsc/rc_calc_fpu.c ?<br>
<br>
Regards,<br>
Christian.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">--<br>
</div>
<div class="PlainText">Hi Christian,</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">Thanks for catching that! It seems that my repo got messed up. I will fix up and send out v3.</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">Thank you,</div>
<div class="PlainText">Lillian<br>
</div>
<div class="PlainText"><br>
</div>
<div class="PlainText">><br>
> diff --git a/dc/dml/dsc/rc_calc_fpu.c b/dc/dml/dsc/rc_calc_fpu.c<br>
> new file mode 100644<br>
> index 000000000000..e9b40cbefd6d<br>
> --- /dev/null<br>
> +++ b/dc/dml/dsc/rc_calc_fpu.c<br>
> @@ -0,0 +1,291 @@<br>
> +/*<br>
> + * Copyright 2021 Advanced Micro Devices, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included in<br>
> + * all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Authors: AMD<br>
> + *<br>
> + */<br>
> +<br>
> +#include "rc_calc_fpu.h"<br>
> +<br>
> +#include "qp_tables.h"<br>
> +#include "amdgpu_dm/dc_fpu.h"<br>
> +<br>
> +#define table_hash(mode, bpc, max_min) ((mode << 16) | (bpc << 8) | max_min)<br>
> +<br>
> +#define MODE_SELECT(val444, val422, val420) \<br>
> + (cm == CM_444 || cm == CM_RGB) ? (val444) : (cm == CM_422 ? (val422) : (val420))<br>
> +<br>
> +<br>
> +#define TABLE_CASE(mode, bpc, max) case (table_hash(mode, BPC_##bpc, max)): \<br>
> + table = qp_table_##mode##_##bpc##bpc_##max; \<br>
> + table_size = sizeof(qp_table_##mode##_##bpc##bpc_##max)/sizeof(*qp_table_##mode##_##bpc##bpc_##max); \<br>
> + break<br>
> +<br>
> +static int median3(int a, int b, int c)<br>
> +{<br>
> + if (a > b)<br>
> + swap(a, b);<br>
> + if (b > c)<br>
> + swap(b, c);<br>
> + if (a > b)<br>
> + swap(b, c);<br>
> +<br>
> + return b;<br>
> +}<br>
> +<br>
> +static double dsc_roundf(double num)<br>
> +{<br>
> + if (num < 0.0)<br>
> + num = num - 0.5;<br>
> + else<br>
> + num = num + 0.5;<br>
> +<br>
> + return (int)(num);<br>
> +}<br>
> +<br>
> +static double dsc_ceil(double num)<br>
> +{<br>
> + double retval = (int)num;<br>
> +<br>
> + if (retval != num && num > 0)<br>
> + retval = num + 1;<br>
> +<br>
> + return (int)retval;<br>
> +}<br>
> +<br>
> +static void get_qp_set(qp_set qps, enum colour_mode cm, enum bits_per_comp bpc,<br>
> + enum max_min max_min, float bpp)<br>
> +{<br>
> + int mode = MODE_SELECT(444, 422, 420);<br>
> + int sel = table_hash(mode, bpc, max_min);<br>
> + int table_size = 0;<br>
> + int index;<br>
> + const struct qp_entry *table = 0L;<br>
> +<br>
> + // alias enum<br>
> + enum { min = DAL_MM_MIN, max = DAL_MM_MAX };<br>
> + switch (sel) {<br>
> + TABLE_CASE(444, 8, max);<br>
> + TABLE_CASE(444, 8, min);<br>
> + TABLE_CASE(444, 10, max);<br>
> + TABLE_CASE(444, 10, min);<br>
> + TABLE_CASE(444, 12, max);<br>
> + TABLE_CASE(444, 12, min);<br>
> + TABLE_CASE(422, 8, max);<br>
> + TABLE_CASE(422, 8, min);<br>
> + TABLE_CASE(422, 10, max);<br>
> + TABLE_CASE(422, 10, min);<br>
> + TABLE_CASE(422, 12, max);<br>
> + TABLE_CASE(422, 12, min);<br>
> + TABLE_CASE(420, 8, max);<br>
> + TABLE_CASE(420, 8, min);<br>
> + TABLE_CASE(420, 10, max);<br>
> + TABLE_CASE(420, 10, min);<br>
> + TABLE_CASE(420, 12, max);<br>
> + TABLE_CASE(420, 12, min);<br>
> + }<br>
> +<br>
> + if (table == 0)<br>
> + return;<br>
> +<br>
> + index = (bpp - table[0].bpp) * 2;<br>
> +<br>
> + /* requested size is bigger than the table */<br>
> + if (index >= table_size) {<br>
> + dm_error("ERROR: Requested rc_calc to find a bpp entry that exceeds the table size\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + memcpy(qps, table[index].qps, sizeof(qp_set));<br>
> +}<br>
> +<br>
> +static void get_ofs_set(qp_set ofs, enum colour_mode mode, float bpp)<br>
> +{<br>
> + int *p = ofs;<br>
> +<br>
> + if (mode == CM_444 || mode == CM_RGB) {<br>
> + *p++ = (bpp <= 6) ? (0) : ((((bpp >= 8) && (bpp <= 12))) ? (2) : ((bpp >= 15) ? (10) : ((((bpp > 6) && (bpp < 8))) ? (0 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (2 + dsc_roundf((bpp - 12) * (8 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-2) : ((((bpp >= 8) && (bpp <= 12))) ? (0) : ((bpp >= 15) ? (8) : ((((bpp > 6) && (bpp < 8))) ? (-2 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (0 + dsc_roundf((bpp - 12) * (8 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-2) : ((((bpp >= 8) && (bpp <= 12))) ? (0) : ((bpp >= 15) ? (6) : ((((bpp > 6) && (bpp < 8))) ? (-2 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (0 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-4) : ((((bpp >= 8) && (bpp <= 12))) ? (-2) : ((bpp >= 15) ? (4) : ((((bpp > 6) && (bpp < 8))) ? (-4 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (-2 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-6) : ((((bpp >= 8) && (bpp <= 12))) ? (-4) : ((bpp >= 15) ? (2) : ((((bpp > 6) && (bpp < 8))) ? (-6 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (-4 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> + *p++ = (bpp <= 12) ? (-6) : ((bpp >= 15) ? (0) : (-6 + dsc_roundf((bpp - 12) * (6 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-2) : (-8 + dsc_roundf((bpp - 12) * (6 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-4) : (-8 + dsc_roundf((bpp - 12) * (4 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-6) : (-8 + dsc_roundf((bpp - 12) * (2 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-10) : ((bpp >= 15) ? (-8) : (-10 + dsc_roundf((bpp - 12) * (2 / 3.0))));<br>
> + *p++ = -10;<br>
> + *p++ = (bpp <= 6) ? (-12) : ((bpp >= 8) ? (-10) : (-12 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + } else if (mode == CM_422) {<br>
> + *p++ = (bpp <= 8) ? (2) : ((bpp >= 10) ? (10) : (2 + dsc_roundf((bpp - 8) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (0) : ((bpp >= 10) ? (8) : (0 + dsc_roundf((bpp - 8) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (0) : ((bpp >= 10) ? (6) : (0 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-2) : ((bpp >= 10) ? (4) : (-2 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-4) : ((bpp >= 10) ? (2) : (-4 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-6) : ((bpp >= 10) ? (0) : (-6 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-2) : (-8 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-4) : (-8 + dsc_roundf((bpp - 8) * (4 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-6) : (-8 + dsc_roundf((bpp - 8) * (2 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-10) : ((bpp >= 10) ? (-8) : (-10 + dsc_roundf((bpp - 8) * (2 / 2.0))));<br>
> + *p++ = -10;<br>
> + *p++ = (bpp <= 6) ? (-12) : ((bpp >= 7) ? (-10) : (-12 + dsc_roundf((bpp - 6) * (2.0 / 1))));<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + } else {<br>
> + *p++ = (bpp <= 6) ? (2) : ((bpp >= 8) ? (10) : (2 + dsc_roundf((bpp - 6) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (0) : ((bpp >= 8) ? (8) : (0 + dsc_roundf((bpp - 6) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (0) : ((bpp >= 8) ? (6) : (0 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-2) : ((bpp >= 8) ? (4) : (-2 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-4) : ((bpp >= 8) ? (2) : (-4 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-6) : ((bpp >= 8) ? (0) : (-6 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-2) : (-8 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-4) : (-8 + dsc_roundf((bpp - 6) * (4 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-6) : (-8 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-10) : ((bpp >= 8) ? (-8) : (-10 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> + *p++ = -10;<br>
> + *p++ = (bpp <= 4) ? (-12) : ((bpp >= 5) ? (-10) : (-12 + dsc_roundf((bpp - 4) * (2 / 1.0))));<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + }<br>
> +}<br>
> +<br>
> +void _do_calc_rc_params(struct rc_params *rc,<br>
> + enum colour_mode cm,<br>
> + enum bits_per_comp bpc,<br>
> + u16 drm_bpp,<br>
> + bool is_navite_422_or_420,<br>
> + int slice_width,<br>
> + int slice_height,<br>
> + int minor_version)<br>
> +{<br>
> + float bpp;<br>
> + float bpp_group;<br>
> + float initial_xmit_delay_factor;<br>
> + int padding_pixels;<br>
> + int i;<br>
> +<br>
> + dc_assert_fp_enabled();<br>
> +<br>
> + bpp = ((float)drm_bpp / 16.0);<br>
> + /* in native_422 or native_420 modes, the bits_per_pixel is double the<br>
> + * target bpp (the latter is what calc_rc_params expects)<br>
> + */<br>
> + if (is_navite_422_or_420)<br>
> + bpp /= 2.0;<br>
> +<br>
> + rc->rc_quant_incr_limit0 = ((bpc == BPC_8) ? 11 : (bpc == BPC_10 ? 15 : 19)) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> + rc->rc_quant_incr_limit1 = ((bpc == BPC_8) ? 11 : (bpc == BPC_10 ? 15 : 19)) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> +<br>
> + bpp_group = MODE_SELECT(bpp, bpp * 2.0, bpp * 2.0);<br>
> +<br>
> + switch (cm) {<br>
> + case CM_420:<br>
> + rc->initial_fullness_offset = (bpp >= 6) ? (2048) : ((bpp <= 4) ? (6144) : ((((bpp > 4) && (bpp <= 5))) ? (6144 - dsc_roundf((bpp - 4) * (512))) : (5632 - dsc_roundf((bpp - 5) * (3584)))));<br>
> + rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)((3 * bpc * 3) - (3 * bpp_group)));<br>
> + rc->second_line_bpg_offset = median3(0, 12, (int)((3 * bpc * 3) - (3 * bpp_group)));<br>
> + break;<br>
> + case CM_422:<br>
> + rc->initial_fullness_offset = (bpp >= 8) ? (2048) : ((bpp <= 7) ? (5632) : (5632 - dsc_roundf((bpp - 7) * (3584))));<br>
> + rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)((3 * bpc * 4) - (3 * bpp_group)));<br>
> + rc->second_line_bpg_offset = 0;<br>
> + break;<br>
> + case CM_444:<br>
> + case CM_RGB:<br>
> + rc->initial_fullness_offset = (bpp >= 12) ? (2048) : ((bpp <= 8) ? (6144) : ((((bpp > 8) && (bpp <= 10))) ? (6144 - dsc_roundf((bpp - 8) * (512 / 2))) : (5632 - dsc_roundf((bpp - 10) * (3584 / 2)))));<br>
> + rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)(((3 * bpc + (cm == CM_444 ? 0 : 2)) * 3) - (3 * bpp_group)));<br>
> + rc->second_line_bpg_offset = 0;<br>
> + break;<br>
> + }<br>
> +<br>
> + initial_xmit_delay_factor = (cm == CM_444 || cm == CM_RGB) ? 1.0 : 2.0;<br>
> + rc->initial_xmit_delay = dsc_roundf(8192.0/2.0/bpp/initial_xmit_delay_factor);<br>
> +<br>
> + if (cm == CM_422 || cm == CM_420)<br>
> + slice_width /= 2;<br>
> +<br>
> + padding_pixels = ((slice_width % 3) != 0) ? (3 - (slice_width % 3)) * (rc->initial_xmit_delay / slice_width) : 0;<br>
> + if (3 * bpp_group >= (((rc->initial_xmit_delay + 2) / 3) * (3 + (cm == CM_422)))) {<br>
> + if ((rc->initial_xmit_delay + padding_pixels) % 3 == 1)<br>
> + rc->initial_xmit_delay++;<br>
> + }<br>
> +<br>
> + rc->flatness_min_qp = ((bpc == BPC_8) ? (3) : ((bpc == BPC_10) ? (7) : (11))) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> + rc->flatness_max_qp = ((bpc == BPC_8) ? (12) : ((bpc == BPC_10) ? (16) : (20))) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> + rc->flatness_det_thresh = 2 << (bpc - 8);<br>
> +<br>
> + get_qp_set(rc->qp_min, cm, bpc, DAL_MM_MIN, bpp);<br>
> + get_qp_set(rc->qp_max, cm, bpc, DAL_MM_MAX, bpp);<br>
> + if (cm == CM_444 && minor_version == 1) {<br>
> + for (i = 0; i < QP_SET_SIZE; ++i) {<br>
> + rc->qp_min[i] = rc->qp_min[i] > 0 ? rc->qp_min[i] - 1 : 0;<br>
> + rc->qp_max[i] = rc->qp_max[i] > 0 ? rc->qp_max[i] - 1 : 0;<br>
> + }<br>
> + }<br>
> + get_ofs_set(rc->ofs, cm, bpp);<br>
> +<br>
> + /* fixed parameters */<br>
> + rc->rc_model_size = 8192;<br>
> + rc->rc_edge_factor = 6;<br>
> + rc->rc_tgt_offset_hi = 3;<br>
> + rc->rc_tgt_offset_lo = 3;<br>
> +<br>
> + rc->rc_buf_thresh[0] = 896;<br>
> + rc->rc_buf_thresh[1] = 1792;<br>
> + rc->rc_buf_thresh[2] = 2688;<br>
> + rc->rc_buf_thresh[3] = 3584;<br>
> + rc->rc_buf_thresh[4] = 4480;<br>
> + rc->rc_buf_thresh[5] = 5376;<br>
> + rc->rc_buf_thresh[6] = 6272;<br>
> + rc->rc_buf_thresh[7] = 6720;<br>
> + rc->rc_buf_thresh[8] = 7168;<br>
> + rc->rc_buf_thresh[9] = 7616;<br>
> + rc->rc_buf_thresh[10] = 7744;<br>
> + rc->rc_buf_thresh[11] = 7872;<br>
> + rc->rc_buf_thresh[12] = 8000;<br>
> + rc->rc_buf_thresh[13] = 8064;<br>
> +}<br>
> +<br>
> +u32 _do_bytes_per_pixel_calc(int slice_width,<br>
> + u16 drm_bpp,<br>
> + bool is_navite_422_or_420)<br>
> +{<br>
> + float bpp;<br>
> + u32 bytes_per_pixel;<br>
> + double d_bytes_per_pixel;<br>
> +<br>
> + dc_assert_fp_enabled();<br>
> +<br>
> + bpp = ((float)drm_bpp / 16.0);<br>
> + d_bytes_per_pixel = dsc_ceil(bpp * slice_width / 8.0) / slice_width;<br>
> + // TODO: Make sure the formula for calculating this is precise (ceiling<br>
> + // vs. floor, and at what point they should be applied)<br>
> + if (is_navite_422_or_420)<br>
> + d_bytes_per_pixel /= 2;<br>
> +<br>
> + bytes_per_pixel = (u32)dsc_ceil(d_bytes_per_pixel * 0x10000000);<br>
> +<br>
> + return bytes_per_pixel;<br>
> +}<br>
> \ No newline at end of file<br>
> diff --git a/dc/dml/dsc/rc_calc_fpu.h b/dc/dml/dsc/rc_calc_fpu.h<br>
> new file mode 100644<br>
> index 000000000000..8f2cd1364b13<br>
> --- /dev/null<br>
> +++ b/dc/dml/dsc/rc_calc_fpu.h<br>
> @@ -0,0 +1,98 @@<br>
> +/*<br>
> + * Copyright 2021 Advanced Micro Devices, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included in<br>
> + * all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Authors: AMD<br>
> + *<br>
> + */<br>
> +<br>
> +#ifndef __RC_CALC_FPU_H__<br>
> +#define __RC_CALC_FPU_H__<br>
> +<br>
> +#include "os_types.h"<br>
> +#ifdef LINUX_DM<br>
> +#include <drm/drm_dsc.h><br>
> +#else<br>
> +#include <include/drm_dsc_dc.h><br>
> +#endif<br>
> +<br>
> +#define QP_SET_SIZE 15<br>
> +<br>
> +typedef int qp_set[QP_SET_SIZE];<br>
> +<br>
> +struct rc_params {<br>
> + int rc_quant_incr_limit0;<br>
> + int rc_quant_incr_limit1;<br>
> + int initial_fullness_offset;<br>
> + int initial_xmit_delay;<br>
> + int first_line_bpg_offset;<br>
> + int second_line_bpg_offset;<br>
> + int flatness_min_qp;<br>
> + int flatness_max_qp;<br>
> + int flatness_det_thresh;<br>
> + qp_set qp_min;<br>
> + qp_set qp_max;<br>
> + qp_set ofs;<br>
> + int rc_model_size;<br>
> + int rc_edge_factor;<br>
> + int rc_tgt_offset_hi;<br>
> + int rc_tgt_offset_lo;<br>
> + int rc_buf_thresh[QP_SET_SIZE - 1];<br>
> +};<br>
> +<br>
> +enum colour_mode {<br>
> + CM_RGB, /* 444 RGB */<br>
> + CM_444, /* 444 YUV or simple 422 */<br>
> + CM_422, /* native 422 */<br>
> + CM_420 /* native 420 */<br>
> +};<br>
> +<br>
> +enum bits_per_comp {<br>
> + BPC_8 = 8,<br>
> + BPC_10 = 10,<br>
> + BPC_12 = 12<br>
> +};<br>
> +<br>
> +enum max_min {<br>
> + DAL_MM_MIN = 0,<br>
> + DAL_MM_MAX = 1<br>
> +};<br>
> +<br>
> +struct qp_entry {<br>
> + float bpp;<br>
> + const qp_set qps;<br>
> +};<br>
> +<br>
> +typedef struct qp_entry qp_table[];<br>
> +<br>
> +u32 _do_bytes_per_pixel_calc(int slice_width,<br>
> + u16 drm_bpp,<br>
> + bool is_navite_422_or_420);<br>
> +<br>
> +void _do_calc_rc_params(struct rc_params *rc,<br>
> + enum colour_mode cm,<br>
> + enum bits_per_comp bpc,<br>
> + u16 drm_bpp,<br>
> + bool is_navite_422_or_420,<br>
> + int slice_width,<br>
> + int slice_height,<br>
> + int minor_version);<br>
> +<br>
> +#endif<br>
> \ No newline at end of file<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/Makefile b/drivers/gpu/drm/amd/display/dc/dml/Makefile<br>
> index 56055df2e8d2..9009b92490f3 100644<br>
> --- a/drivers/gpu/drm/amd/display/dc/dml/Makefile<br>
> +++ b/drivers/gpu/drm/amd/display/dc/dml/Makefile<br>
> @@ -70,6 +70,7 @@ CFLAGS_$(AMDDALPATH)/dc/dml/dcn30/display_mode_vba_30.o := $(dml_ccflags) $(fram<br>
> CFLAGS_$(AMDDALPATH)/dc/dml/dcn30/display_rq_dlg_calc_30.o := $(dml_ccflags)<br>
> CFLAGS_$(AMDDALPATH)/dc/dml/dcn31/display_mode_vba_31.o := $(dml_ccflags) $(frame_warn_flag)<br>
> CFLAGS_$(AMDDALPATH)/dc/dml/dcn31/display_rq_dlg_calc_31.o := $(dml_ccflags)<br>
> +CFLAGS_$(AMDDALPATH)/dc/dml/dsc/rc_calc_fpu.o := $(dml_ccflags)<br>
> CFLAGS_$(AMDDALPATH)/dc/dml/display_mode_lib.o := $(dml_ccflags)<br>
> CFLAGS_REMOVE_$(AMDDALPATH)/dc/dml/display_mode_vba.o := $(dml_rcflags)<br>
> CFLAGS_REMOVE_$(AMDDALPATH)/dc/dml/dcn2x/dcn2x.o := $(dml_rcflags)<br>
> @@ -84,6 +85,7 @@ CFLAGS_REMOVE_$(AMDDALPATH)/dc/dml/dcn30/display_rq_dlg_calc_30.o := $(dml_rcfla<br>
> CFLAGS_REMOVE_$(AMDDALPATH)/dc/dml/dcn31/display_mode_vba_31.o := $(dml_rcflags)<br>
> CFLAGS_REMOVE_$(AMDDALPATH)/dc/dml/dcn31/display_rq_dlg_calc_31.o := $(dml_rcflags)<br>
> CFLAGS_REMOVE_$(AMDDALPATH)/dc/dml/display_mode_lib.o := $(dml_rcflags)<br>
> +CFLAGS_REMOVE_$(AMDDALPATH)/dc/dml/dsc/rc_calc_fpu.o := $(dml_rcflags)<br>
> endif<br>
> CFLAGS_$(AMDDALPATH)/dc/dml/dml1_display_rq_dlg_calc.o := $(dml_ccflags)<br>
> CFLAGS_$(AMDDALPATH)/dc/dml/display_rq_dlg_helpers.o := $(dml_ccflags)<br>
> @@ -99,6 +101,7 @@ DML += dcn20/display_rq_dlg_calc_20v2.o dcn20/display_mode_vba_20v2.o<br>
> DML += dcn21/display_rq_dlg_calc_21.o dcn21/display_mode_vba_21.o<br>
> DML += dcn30/display_mode_vba_30.o dcn30/display_rq_dlg_calc_30.o<br>
> DML += dcn31/display_mode_vba_31.o dcn31/display_rq_dlg_calc_31.o<br>
> +DML += dsc/rc_calc_fpu.o<br>
> endif<br>
> <br>
> AMD_DAL_DML = $(addprefix $(AMDDALPATH)/dc/dml/,$(DML))<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dsc/qp_tables.h b/drivers/gpu/drm/amd/display/dc/dml/dsc/qp_tables.h<br>
> similarity index 100%<br>
> rename from drivers/gpu/drm/amd/display/dc/dsc/qp_tables.h<br>
> rename to drivers/gpu/drm/amd/display/dc/dml/dsc/qp_tables.h<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.c b/drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.c<br>
> new file mode 100644<br>
> index 000000000000..0436fc64948f<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.c<br>
> @@ -0,0 +1,287 @@<br>
> +/*<br>
> + * Copyright 2021 Advanced Micro Devices, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included in<br>
> + * all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Authors: AMD<br>
> + *<br>
> + */<br>
> +<br>
> +#include "rc_calc_fpu.h"<br>
> +<br>
> +#include "qp_tables.h"<br>
> +#include "amdgpu_dm/dc_fpu.h"<br>
> +<br>
> +#define table_hash(mode, bpc, max_min) ((mode << 16) | (bpc << 8) | max_min)<br>
> +<br>
> +#define MODE_SELECT(val444, val422, val420) \<br>
> + (cm == CM_444 || cm == CM_RGB) ? (val444) : (cm == CM_422 ? (val422) : (val420))<br>
> +<br>
> +<br>
> +#define TABLE_CASE(mode, bpc, max) case (table_hash(mode, BPC_##bpc, max)): \<br>
> + table = qp_table_##mode##_##bpc##bpc_##max; \<br>
> + table_size = sizeof(qp_table_##mode##_##bpc##bpc_##max)/sizeof(*qp_table_##mode##_##bpc##bpc_##max); \<br>
> + break<br>
> +<br>
> +static int median3(int a, int b, int c)<br>
> +{<br>
> + if (a > b)<br>
> + swap(a, b);<br>
> + if (b > c)<br>
> + swap(b, c);<br>
> + if (a > b)<br>
> + swap(b, c);<br>
> +<br>
> + return b;<br>
> +}<br>
> +<br>
> +static double dsc_roundf(double num)<br>
> +{<br>
> + if (num < 0.0)<br>
> + num = num - 0.5;<br>
> + else<br>
> + num = num + 0.5;<br>
> +<br>
> + return (int)(num);<br>
> +}<br>
> +<br>
> +static double dsc_ceil(double num)<br>
> +{<br>
> + double retval = (int)num;<br>
> +<br>
> + if (retval != num && num > 0)<br>
> + retval = num + 1;<br>
> +<br>
> + return (int)retval;<br>
> +}<br>
> +<br>
> +static void get_qp_set(qp_set qps, enum colour_mode cm, enum bits_per_comp bpc,<br>
> + enum max_min max_min, float bpp)<br>
> +{<br>
> + int mode = MODE_SELECT(444, 422, 420);<br>
> + int sel = table_hash(mode, bpc, max_min);<br>
> + int table_size = 0;<br>
> + int index;<br>
> + const struct qp_entry *table = 0L;<br>
> +<br>
> + // alias enum<br>
> + enum { min = DAL_MM_MIN, max = DAL_MM_MAX };<br>
> + switch (sel) {<br>
> + TABLE_CASE(444, 8, max);<br>
> + TABLE_CASE(444, 8, min);<br>
> + TABLE_CASE(444, 10, max);<br>
> + TABLE_CASE(444, 10, min);<br>
> + TABLE_CASE(444, 12, max);<br>
> + TABLE_CASE(444, 12, min);<br>
> + TABLE_CASE(422, 8, max);<br>
> + TABLE_CASE(422, 8, min);<br>
> + TABLE_CASE(422, 10, max);<br>
> + TABLE_CASE(422, 10, min);<br>
> + TABLE_CASE(422, 12, max);<br>
> + TABLE_CASE(422, 12, min);<br>
> + TABLE_CASE(420, 8, max);<br>
> + TABLE_CASE(420, 8, min);<br>
> + TABLE_CASE(420, 10, max);<br>
> + TABLE_CASE(420, 10, min);<br>
> + TABLE_CASE(420, 12, max);<br>
> + TABLE_CASE(420, 12, min);<br>
> + }<br>
> +<br>
> + if (table == 0)<br>
> + return;<br>
> +<br>
> + index = (bpp - table[0].bpp) * 2;<br>
> +<br>
> + /* requested size is bigger than the table */<br>
> + if (index >= table_size) {<br>
> + dm_error("ERROR: Requested rc_calc to find a bpp entry that exceeds the table size\n");<br>
> + return;<br>
> + }<br>
> +<br>
> + memcpy(qps, table[index].qps, sizeof(qp_set));<br>
> +}<br>
> +<br>
> +static void get_ofs_set(qp_set ofs, enum colour_mode mode, float bpp)<br>
> +{<br>
> + int *p = ofs;<br>
> +<br>
> + if (mode == CM_444 || mode == CM_RGB) {<br>
> + *p++ = (bpp <= 6) ? (0) : ((((bpp >= 8) && (bpp <= 12))) ? (2) : ((bpp >= 15) ? (10) : ((((bpp > 6) && (bpp < 8))) ? (0 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (2 + dsc_roundf((bpp - 12) * (8 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-2) : ((((bpp >= 8) && (bpp <= 12))) ? (0) : ((bpp >= 15) ? (8) : ((((bpp > 6) && (bpp < 8))) ? (-2 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (0 + dsc_roundf((bpp - 12) * (8 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-2) : ((((bpp >= 8) && (bpp <= 12))) ? (0) : ((bpp >= 15) ? (6) : ((((bpp > 6) && (bpp < 8))) ? (-2 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (0 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-4) : ((((bpp >= 8) && (bpp <= 12))) ? (-2) : ((bpp >= 15) ? (4) : ((((bpp > 6) && (bpp < 8))) ? (-4 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (-2 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> + *p++ = (bpp <= 6) ? (-6) : ((((bpp >= 8) && (bpp <= 12))) ? (-4) : ((bpp >= 15) ? (2) : ((((bpp > 6) && (bpp < 8))) ? (-6 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (-4 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> + *p++ = (bpp <= 12) ? (-6) : ((bpp >= 15) ? (0) : (-6 + dsc_roundf((bpp - 12) * (6 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-2) : (-8 + dsc_roundf((bpp - 12) * (6 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-4) : (-8 + dsc_roundf((bpp - 12) * (4 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-6) : (-8 + dsc_roundf((bpp - 12) * (2 / 3.0))));<br>
> + *p++ = (bpp <= 12) ? (-10) : ((bpp >= 15) ? (-8) : (-10 + dsc_roundf((bpp - 12) * (2 / 3.0))));<br>
> + *p++ = -10;<br>
> + *p++ = (bpp <= 6) ? (-12) : ((bpp >= 8) ? (-10) : (-12 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + } else if (mode == CM_422) {<br>
> + *p++ = (bpp <= 8) ? (2) : ((bpp >= 10) ? (10) : (2 + dsc_roundf((bpp - 8) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (0) : ((bpp >= 10) ? (8) : (0 + dsc_roundf((bpp - 8) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (0) : ((bpp >= 10) ? (6) : (0 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-2) : ((bpp >= 10) ? (4) : (-2 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-4) : ((bpp >= 10) ? (2) : (-4 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-6) : ((bpp >= 10) ? (0) : (-6 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-2) : (-8 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-4) : (-8 + dsc_roundf((bpp - 8) * (4 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-6) : (-8 + dsc_roundf((bpp - 8) * (2 / 2.0))));<br>
> + *p++ = (bpp <= 8) ? (-10) : ((bpp >= 10) ? (-8) : (-10 + dsc_roundf((bpp - 8) * (2 / 2.0))));<br>
> + *p++ = -10;<br>
> + *p++ = (bpp <= 6) ? (-12) : ((bpp >= 7) ? (-10) : (-12 + dsc_roundf((bpp - 6) * (2.0 / 1))));<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + } else {<br>
> + *p++ = (bpp <= 6) ? (2) : ((bpp >= 8) ? (10) : (2 + dsc_roundf((bpp - 6) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (0) : ((bpp >= 8) ? (8) : (0 + dsc_roundf((bpp - 6) * (8 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (0) : ((bpp >= 8) ? (6) : (0 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-2) : ((bpp >= 8) ? (4) : (-2 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-4) : ((bpp >= 8) ? (2) : (-4 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-6) : ((bpp >= 8) ? (0) : (-6 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-2) : (-8 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-4) : (-8 + dsc_roundf((bpp - 6) * (4 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-6) : (-8 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> + *p++ = (bpp <= 6) ? (-10) : ((bpp >= 8) ? (-8) : (-10 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> + *p++ = -10;<br>
> + *p++ = (bpp <= 4) ? (-12) : ((bpp >= 5) ? (-10) : (-12 + dsc_roundf((bpp - 4) * (2 / 1.0))));<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + *p++ = -12;<br>
> + }<br>
> +}<br>
> +<br>
> +void _do_calc_rc_params(struct rc_params *rc, enum colour_mode cm,<br>
> + enum bits_per_comp bpc, u16 drm_bpp,<br>
> + bool is_navite_422_or_420,<br>
> + int slice_width, int slice_height,<br>
> + int minor_version)<br>
> +{<br>
> + float bpp;<br>
> + float bpp_group;<br>
> + float initial_xmit_delay_factor;<br>
> + int padding_pixels;<br>
> + int i;<br>
> +<br>
> + dc_assert_fp_enabled();<br>
> +<br>
> + bpp = ((float)drm_bpp / 16.0);<br>
> + /* in native_422 or native_420 modes, the bits_per_pixel is double the<br>
> + * target bpp (the latter is what calc_rc_params expects)<br>
> + */<br>
> + if (is_navite_422_or_420)<br>
> + bpp /= 2.0;<br>
> +<br>
> + rc->rc_quant_incr_limit0 = ((bpc == BPC_8) ? 11 : (bpc == BPC_10 ? 15 : 19)) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> + rc->rc_quant_incr_limit1 = ((bpc == BPC_8) ? 11 : (bpc == BPC_10 ? 15 : 19)) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> +<br>
> + bpp_group = MODE_SELECT(bpp, bpp * 2.0, bpp * 2.0);<br>
> +<br>
> + switch (cm) {<br>
> + case CM_420:<br>
> + rc->initial_fullness_offset = (bpp >= 6) ? (2048) : ((bpp <= 4) ? (6144) : ((((bpp > 4) && (bpp <= 5))) ? (6144 - dsc_roundf((bpp - 4) * (512))) : (5632 - dsc_roundf((bpp - 5) * (3584)))));<br>
> + rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)((3 * bpc * 3) - (3 * bpp_group)));<br>
> + rc->second_line_bpg_offset = median3(0, 12, (int)((3 * bpc * 3) - (3 * bpp_group)));<br>
> + break;<br>
> + case CM_422:<br>
> + rc->initial_fullness_offset = (bpp >= 8) ? (2048) : ((bpp <= 7) ? (5632) : (5632 - dsc_roundf((bpp - 7) * (3584))));<br>
> + rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)((3 * bpc * 4) - (3 * bpp_group)));<br>
> + rc->second_line_bpg_offset = 0;<br>
> + break;<br>
> + case CM_444:<br>
> + case CM_RGB:<br>
> + rc->initial_fullness_offset = (bpp >= 12) ? (2048) : ((bpp <= 8) ? (6144) : ((((bpp > 8) && (bpp <= 10))) ? (6144 - dsc_roundf((bpp - 8) * (512 / 2))) : (5632 - dsc_roundf((bpp - 10) * (3584 / 2)))));<br>
> + rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)(((3 * bpc + (cm == CM_444 ? 0 : 2)) * 3) - (3 * bpp_group)));<br>
> + rc->second_line_bpg_offset = 0;<br>
> + break;<br>
> + }<br>
> +<br>
> + initial_xmit_delay_factor = (cm == CM_444 || cm == CM_RGB) ? 1.0 : 2.0;<br>
> + rc->initial_xmit_delay = dsc_roundf(8192.0/2.0/bpp/initial_xmit_delay_factor);<br>
> +<br>
> + if (cm == CM_422 || cm == CM_420)<br>
> + slice_width /= 2;<br>
> +<br>
> + padding_pixels = ((slice_width % 3) != 0) ? (3 - (slice_width % 3)) * (rc->initial_xmit_delay / slice_width) : 0;<br>
> + if (3 * bpp_group >= (((rc->initial_xmit_delay + 2) / 3) * (3 + (cm == CM_422)))) {<br>
> + if ((rc->initial_xmit_delay + padding_pixels) % 3 == 1)<br>
> + rc->initial_xmit_delay++;<br>
> + }<br>
> +<br>
> + rc->flatness_min_qp = ((bpc == BPC_8) ? (3) : ((bpc == BPC_10) ? (7) : (11))) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> + rc->flatness_max_qp = ((bpc == BPC_8) ? (12) : ((bpc == BPC_10) ? (16) : (20))) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> + rc->flatness_det_thresh = 2 << (bpc - 8);<br>
> +<br>
> + get_qp_set(rc->qp_min, cm, bpc, DAL_MM_MIN, bpp);<br>
> + get_qp_set(rc->qp_max, cm, bpc, DAL_MM_MAX, bpp);<br>
> + if (cm == CM_444 && minor_version == 1) {<br>
> + for (i = 0; i < QP_SET_SIZE; ++i) {<br>
> + rc->qp_min[i] = rc->qp_min[i] > 0 ? rc->qp_min[i] - 1 : 0;<br>
> + rc->qp_max[i] = rc->qp_max[i] > 0 ? rc->qp_max[i] - 1 : 0;<br>
> + }<br>
> + }<br>
> + get_ofs_set(rc->ofs, cm, bpp);<br>
> +<br>
> + /* fixed parameters */<br>
> + rc->rc_model_size = 8192;<br>
> + rc->rc_edge_factor = 6;<br>
> + rc->rc_tgt_offset_hi = 3;<br>
> + rc->rc_tgt_offset_lo = 3;<br>
> +<br>
> + rc->rc_buf_thresh[0] = 896;<br>
> + rc->rc_buf_thresh[1] = 1792;<br>
> + rc->rc_buf_thresh[2] = 2688;<br>
> + rc->rc_buf_thresh[3] = 3584;<br>
> + rc->rc_buf_thresh[4] = 4480;<br>
> + rc->rc_buf_thresh[5] = 5376;<br>
> + rc->rc_buf_thresh[6] = 6272;<br>
> + rc->rc_buf_thresh[7] = 6720;<br>
> + rc->rc_buf_thresh[8] = 7168;<br>
> + rc->rc_buf_thresh[9] = 7616;<br>
> + rc->rc_buf_thresh[10] = 7744;<br>
> + rc->rc_buf_thresh[11] = 7872;<br>
> + rc->rc_buf_thresh[12] = 8000;<br>
> + rc->rc_buf_thresh[13] = 8064;<br>
> +}<br>
> +<br>
> +u32 _do_bytes_per_pixel_calc(int slice_width, u16 drm_bpp,<br>
> + bool is_navite_422_or_420)<br>
> +{<br>
> + float bpp;<br>
> + u32 bytes_per_pixel;<br>
> + double d_bytes_per_pixel;<br>
> +<br>
> + dc_assert_fp_enabled();<br>
> +<br>
> + bpp = ((float)drm_bpp / 16.0);<br>
> + d_bytes_per_pixel = dsc_ceil(bpp * slice_width / 8.0) / slice_width;<br>
> + // TODO: Make sure the formula for calculating this is precise (ceiling<br>
> + // vs. floor, and at what point they should be applied)<br>
> + if (is_navite_422_or_420)<br>
> + d_bytes_per_pixel /= 2;<br>
> +<br>
> + bytes_per_pixel = (u32)dsc_ceil(d_bytes_per_pixel * 0x10000000);<br>
> +<br>
> + return bytes_per_pixel;<br>
> +}<br>
> \ No newline at end of file<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.h b/drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.h<br>
> new file mode 100644<br>
> index 000000000000..d3900ff7fa89<br>
> --- /dev/null<br>
> +++ b/drivers/gpu/drm/amd/display/dc/dml/dsc/rc_calc_fpu.h<br>
> @@ -0,0 +1,89 @@<br>
> +/*<br>
> + * Copyright 2021 Advanced Micro Devices, Inc.<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice shall be included in<br>
> + * all copies or substantial portions of the Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> + *<br>
> + * Authors: AMD<br>
> + *<br>
> + */<br>
> +<br>
> +#ifndef __RC_CALC_FPU_H__<br>
> +#define __RC_CALC_FPU_H__<br>
> +<br>
> +#include "os_types.h"<br>
> +<br>
> +#define QP_SET_SIZE 15<br>
> +<br>
> +typedef int qp_set[QP_SET_SIZE];<br>
> +<br>
> +struct rc_params {<br>
> + int rc_quant_incr_limit0;<br>
> + int rc_quant_incr_limit1;<br>
> + int initial_fullness_offset;<br>
> + int initial_xmit_delay;<br>
> + int first_line_bpg_offset;<br>
> + int second_line_bpg_offset;<br>
> + int flatness_min_qp;<br>
> + int flatness_max_qp;<br>
> + int flatness_det_thresh;<br>
> + qp_set qp_min;<br>
> + qp_set qp_max;<br>
> + qp_set ofs;<br>
> + int rc_model_size;<br>
> + int rc_edge_factor;<br>
> + int rc_tgt_offset_hi;<br>
> + int rc_tgt_offset_lo;<br>
> + int rc_buf_thresh[QP_SET_SIZE - 1];<br>
> +};<br>
> +<br>
> +enum colour_mode {<br>
> + CM_RGB, /* 444 RGB */<br>
> + CM_444, /* 444 YUV or simple 422 */<br>
> + CM_422, /* native 422 */<br>
> + CM_420 /* native 420 */<br>
> +};<br>
> +<br>
> +enum bits_per_comp {<br>
> + BPC_8 = 8,<br>
> + BPC_10 = 10,<br>
> + BPC_12 = 12<br>
> +};<br>
> +<br>
> +enum max_min {<br>
> + DAL_MM_MIN = 0,<br>
> + DAL_MM_MAX = 1<br>
> +};<br>
> +<br>
> +struct qp_entry {<br>
> + float bpp;<br>
> + const qp_set qps;<br>
> +};<br>
> +<br>
> +typedef struct qp_entry qp_table[];<br>
> +<br>
> +u32 _do_bytes_per_pixel_calc(int slice_width, u16 drm_bpp,<br>
> + bool is_navite_422_or_420);<br>
> +<br>
> +void _do_calc_rc_params(struct rc_params *rc, enum colour_mode cm,<br>
> + enum bits_per_comp bpc, u16 drm_bpp,<br>
> + bool is_navite_422_or_420,<br>
> + int slice_width, int slice_height,<br>
> + int minor_version);<br>
> +<br>
> +#endif<br>
> \ No newline at end of file<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dsc/Makefile b/drivers/gpu/drm/amd/display/dc/dsc/Makefile<br>
> index 8d31eb75c6a6..a2537229ee88 100644<br>
> --- a/drivers/gpu/drm/amd/display/dc/dsc/Makefile<br>
> +++ b/drivers/gpu/drm/amd/display/dc/dsc/Makefile<br>
> @@ -1,35 +1,6 @@<br>
> # SPDX-License-Identifier: MIT<br>
> #<br>
> # Makefile for the 'dsc' sub-component of DAL.<br>
> -<br>
> -ifdef CONFIG_X86<br>
> -dsc_ccflags := -mhard-float -msse<br>
> -endif<br>
> -<br>
> -ifdef CONFIG_PPC64<br>
> -dsc_ccflags := -mhard-float -maltivec<br>
> -endif<br>
> -<br>
> -ifdef CONFIG_CC_IS_GCC<br>
> -ifeq ($(call cc-ifversion, -lt, 0701, y), y)<br>
> -IS_OLD_GCC = 1<br>
> -endif<br>
> -endif<br>
> -<br>
> -ifdef CONFIG_X86<br>
> -ifdef IS_OLD_GCC<br>
> -# Stack alignment mismatch, proceed with caution.<br>
> -# GCC < 7.1 cannot compile code using `double` and -mpreferred-stack-boundary=3<br>
> -# (8B stack alignment).<br>
> -dsc_ccflags += -mpreferred-stack-boundary=4<br>
> -else<br>
> -dsc_ccflags += -msse2<br>
> -endif<br>
> -endif<br>
> -<br>
> -CFLAGS_$(AMDDALPATH)/dc/dsc/rc_calc.o := $(dsc_ccflags)<br>
> -CFLAGS_REMOVE_$(AMDDALPATH)/dc/dsc/rc_calc.o := $(dsc_rcflags)<br>
> -<br>
> DSC = dc_dsc.o rc_calc.o rc_calc_dpi.o<br>
> <br>
> AMD_DAL_DSC = $(addprefix $(AMDDALPATH)/dc/dsc/,$(DSC))<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.c b/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.c<br>
> index 7b294f637881..87acec33b8d8 100644<br>
> --- a/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.c<br>
> +++ b/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.c<br>
> @@ -25,264 +25,7 @@<br>
> */<br>
> #include <drm/drm_dsc.h><br>
> <br>
> -#include "os_types.h"<br>
> #include "rc_calc.h"<br>
> -#include "qp_tables.h"<br>
> -<br>
> -#define table_hash(mode, bpc, max_min) ((mode << 16) | (bpc << 8) | max_min)<br>
> -<br>
> -#define MODE_SELECT(val444, val422, val420) \<br>
> - (cm == CM_444 || cm == CM_RGB) ? (val444) : (cm == CM_422 ? (val422) : (val420))<br>
> -<br>
> -<br>
> -#define TABLE_CASE(mode, bpc, max) case (table_hash(mode, BPC_##bpc, max)): \<br>
> - table = qp_table_##mode##_##bpc##bpc_##max; \<br>
> - table_size = sizeof(qp_table_##mode##_##bpc##bpc_##max)/sizeof(*qp_table_##mode##_##bpc##bpc_##max); \<br>
> - break<br>
> -<br>
> -<br>
> -static void get_qp_set(qp_set qps, enum colour_mode cm, enum bits_per_comp bpc,<br>
> - enum max_min max_min, float bpp)<br>
> -{<br>
> - int mode = MODE_SELECT(444, 422, 420);<br>
> - int sel = table_hash(mode, bpc, max_min);<br>
> - int table_size = 0;<br>
> - int index;<br>
> - const struct qp_entry *table = 0L;<br>
> -<br>
> - // alias enum<br>
> - enum { min = DAL_MM_MIN, max = DAL_MM_MAX };<br>
> - switch (sel) {<br>
> - TABLE_CASE(444, 8, max);<br>
> - TABLE_CASE(444, 8, min);<br>
> - TABLE_CASE(444, 10, max);<br>
> - TABLE_CASE(444, 10, min);<br>
> - TABLE_CASE(444, 12, max);<br>
> - TABLE_CASE(444, 12, min);<br>
> - TABLE_CASE(422, 8, max);<br>
> - TABLE_CASE(422, 8, min);<br>
> - TABLE_CASE(422, 10, max);<br>
> - TABLE_CASE(422, 10, min);<br>
> - TABLE_CASE(422, 12, max);<br>
> - TABLE_CASE(422, 12, min);<br>
> - TABLE_CASE(420, 8, max);<br>
> - TABLE_CASE(420, 8, min);<br>
> - TABLE_CASE(420, 10, max);<br>
> - TABLE_CASE(420, 10, min);<br>
> - TABLE_CASE(420, 12, max);<br>
> - TABLE_CASE(420, 12, min);<br>
> - }<br>
> -<br>
> - if (table == 0)<br>
> - return;<br>
> -<br>
> - index = (bpp - table[0].bpp) * 2;<br>
> -<br>
> - /* requested size is bigger than the table */<br>
> - if (index >= table_size) {<br>
> - dm_error("ERROR: Requested rc_calc to find a bpp entry that exceeds the table size\n");<br>
> - return;<br>
> - }<br>
> -<br>
> - memcpy(qps, table[index].qps, sizeof(qp_set));<br>
> -}<br>
> -<br>
> -static double dsc_roundf(double num)<br>
> -{<br>
> - if (num < 0.0)<br>
> - num = num - 0.5;<br>
> - else<br>
> - num = num + 0.5;<br>
> -<br>
> - return (int)(num);<br>
> -}<br>
> -<br>
> -static double dsc_ceil(double num)<br>
> -{<br>
> - double retval = (int)num;<br>
> -<br>
> - if (retval != num && num > 0)<br>
> - retval = num + 1;<br>
> -<br>
> - return (int)retval;<br>
> -}<br>
> -<br>
> -static void get_ofs_set(qp_set ofs, enum colour_mode mode, float bpp)<br>
> -{<br>
> - int *p = ofs;<br>
> -<br>
> - if (mode == CM_444 || mode == CM_RGB) {<br>
> - *p++ = (bpp <= 6) ? (0) : ((((bpp >= 8) && (bpp <= 12))) ? (2) : ((bpp >= 15) ? (10) : ((((bpp > 6) && (bpp < 8))) ? (0 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (2 + dsc_roundf((bpp - 12) * (8 / 3.0))))));<br>
> - *p++ = (bpp <= 6) ? (-2) : ((((bpp >= 8) && (bpp <= 12))) ? (0) : ((bpp >= 15) ? (8) : ((((bpp > 6) && (bpp < 8))) ? (-2 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (0 + dsc_roundf((bpp - 12) * (8 / 3.0))))));<br>
> - *p++ = (bpp <= 6) ? (-2) : ((((bpp >= 8) && (bpp <= 12))) ? (0) : ((bpp >= 15) ? (6) : ((((bpp > 6) && (bpp < 8))) ? (-2 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (0 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> - *p++ = (bpp <= 6) ? (-4) : ((((bpp >= 8) && (bpp <= 12))) ? (-2) : ((bpp >= 15) ? (4) : ((((bpp > 6) && (bpp < 8))) ? (-4 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (-2 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> - *p++ = (bpp <= 6) ? (-6) : ((((bpp >= 8) && (bpp <= 12))) ? (-4) : ((bpp >= 15) ? (2) : ((((bpp > 6) && (bpp < 8))) ? (-6 + dsc_roundf((bpp - 6) * (2 / 2.0))) : (-4 + dsc_roundf((bpp - 12) * (6 / 3.0))))));<br>
> - *p++ = (bpp <= 12) ? (-6) : ((bpp >= 15) ? (0) : (-6 + dsc_roundf((bpp - 12) * (6 / 3.0))));<br>
> - *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-2) : (-8 + dsc_roundf((bpp - 12) * (6 / 3.0))));<br>
> - *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-4) : (-8 + dsc_roundf((bpp - 12) * (4 / 3.0))));<br>
> - *p++ = (bpp <= 12) ? (-8) : ((bpp >= 15) ? (-6) : (-8 + dsc_roundf((bpp - 12) * (2 / 3.0))));<br>
> - *p++ = (bpp <= 12) ? (-10) : ((bpp >= 15) ? (-8) : (-10 + dsc_roundf((bpp - 12) * (2 / 3.0))));<br>
> - *p++ = -10;<br>
> - *p++ = (bpp <= 6) ? (-12) : ((bpp >= 8) ? (-10) : (-12 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> - *p++ = -12;<br>
> - *p++ = -12;<br>
> - *p++ = -12;<br>
> - } else if (mode == CM_422) {<br>
> - *p++ = (bpp <= 8) ? (2) : ((bpp >= 10) ? (10) : (2 + dsc_roundf((bpp - 8) * (8 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (0) : ((bpp >= 10) ? (8) : (0 + dsc_roundf((bpp - 8) * (8 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (0) : ((bpp >= 10) ? (6) : (0 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (-2) : ((bpp >= 10) ? (4) : (-2 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (-4) : ((bpp >= 10) ? (2) : (-4 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (-6) : ((bpp >= 10) ? (0) : (-6 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-2) : (-8 + dsc_roundf((bpp - 8) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-4) : (-8 + dsc_roundf((bpp - 8) * (4 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (-8) : ((bpp >= 10) ? (-6) : (-8 + dsc_roundf((bpp - 8) * (2 / 2.0))));<br>
> - *p++ = (bpp <= 8) ? (-10) : ((bpp >= 10) ? (-8) : (-10 + dsc_roundf((bpp - 8) * (2 / 2.0))));<br>
> - *p++ = -10;<br>
> - *p++ = (bpp <= 6) ? (-12) : ((bpp >= 7) ? (-10) : (-12 + dsc_roundf((bpp - 6) * (2.0 / 1))));<br>
> - *p++ = -12;<br>
> - *p++ = -12;<br>
> - *p++ = -12;<br>
> - } else {<br>
> - *p++ = (bpp <= 6) ? (2) : ((bpp >= 8) ? (10) : (2 + dsc_roundf((bpp - 6) * (8 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (0) : ((bpp >= 8) ? (8) : (0 + dsc_roundf((bpp - 6) * (8 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (0) : ((bpp >= 8) ? (6) : (0 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (-2) : ((bpp >= 8) ? (4) : (-2 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (-4) : ((bpp >= 8) ? (2) : (-4 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (-6) : ((bpp >= 8) ? (0) : (-6 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-2) : (-8 + dsc_roundf((bpp - 6) * (6 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-4) : (-8 + dsc_roundf((bpp - 6) * (4 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (-8) : ((bpp >= 8) ? (-6) : (-8 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> - *p++ = (bpp <= 6) ? (-10) : ((bpp >= 8) ? (-8) : (-10 + dsc_roundf((bpp - 6) * (2 / 2.0))));<br>
> - *p++ = -10;<br>
> - *p++ = (bpp <= 4) ? (-12) : ((bpp >= 5) ? (-10) : (-12 + dsc_roundf((bpp - 4) * (2 / 1.0))));<br>
> - *p++ = -12;<br>
> - *p++ = -12;<br>
> - *p++ = -12;<br>
> - }<br>
> -}<br>
> -<br>
> -static int median3(int a, int b, int c)<br>
> -{<br>
> - if (a > b)<br>
> - swap(a, b);<br>
> - if (b > c)<br>
> - swap(b, c);<br>
> - if (a > b)<br>
> - swap(b, c);<br>
> -<br>
> - return b;<br>
> -}<br>
> -<br>
> -static void _do_calc_rc_params(struct rc_params *rc, enum colour_mode cm,<br>
> - enum bits_per_comp bpc, u16 drm_bpp,<br>
> - bool is_navite_422_or_420,<br>
> - int slice_width, int slice_height,<br>
> - int minor_version)<br>
> -{<br>
> - float bpp;<br>
> - float bpp_group;<br>
> - float initial_xmit_delay_factor;<br>
> - int padding_pixels;<br>
> - int i;<br>
> -<br>
> - bpp = ((float)drm_bpp / 16.0);<br>
> - /* in native_422 or native_420 modes, the bits_per_pixel is double the<br>
> - * target bpp (the latter is what calc_rc_params expects)<br>
> - */<br>
> - if (is_navite_422_or_420)<br>
> - bpp /= 2.0;<br>
> -<br>
> - rc->rc_quant_incr_limit0 = ((bpc == BPC_8) ? 11 : (bpc == BPC_10 ? 15 : 19)) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> - rc->rc_quant_incr_limit1 = ((bpc == BPC_8) ? 11 : (bpc == BPC_10 ? 15 : 19)) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> -<br>
> - bpp_group = MODE_SELECT(bpp, bpp * 2.0, bpp * 2.0);<br>
> -<br>
> - switch (cm) {<br>
> - case CM_420:<br>
> - rc->initial_fullness_offset = (bpp >= 6) ? (2048) : ((bpp <= 4) ? (6144) : ((((bpp > 4) && (bpp <= 5))) ? (6144 - dsc_roundf((bpp - 4) * (512))) : (5632 - dsc_roundf((bpp - 5) * (3584)))));<br>
> - rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)((3 * bpc * 3) - (3 * bpp_group)));<br>
> - rc->second_line_bpg_offset = median3(0, 12, (int)((3 * bpc * 3) - (3 * bpp_group)));<br>
> - break;<br>
> - case CM_422:<br>
> - rc->initial_fullness_offset = (bpp >= 8) ? (2048) : ((bpp <= 7) ? (5632) : (5632 - dsc_roundf((bpp - 7) * (3584))));<br>
> - rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)((3 * bpc * 4) - (3 * bpp_group)));<br>
> - rc->second_line_bpg_offset = 0;<br>
> - break;<br>
> - case CM_444:<br>
> - case CM_RGB:<br>
> - rc->initial_fullness_offset = (bpp >= 12) ? (2048) : ((bpp <= 8) ? (6144) : ((((bpp > 8) && (bpp <= 10))) ? (6144 - dsc_roundf((bpp - 8) * (512 / 2))) : (5632 - dsc_roundf((bpp - 10) * (3584 / 2)))));<br>
> - rc->first_line_bpg_offset = median3(0, (12 + (int) (0.09 * min(34, slice_height - 8))), (int)(((3 * bpc + (cm == CM_444 ? 0 : 2)) * 3) - (3 * bpp_group)));<br>
> - rc->second_line_bpg_offset = 0;<br>
> - break;<br>
> - }<br>
> -<br>
> - initial_xmit_delay_factor = (cm == CM_444 || cm == CM_RGB) ? 1.0 : 2.0;<br>
> - rc->initial_xmit_delay = dsc_roundf(8192.0/2.0/bpp/initial_xmit_delay_factor);<br>
> -<br>
> - if (cm == CM_422 || cm == CM_420)<br>
> - slice_width /= 2;<br>
> -<br>
> - padding_pixels = ((slice_width % 3) != 0) ? (3 - (slice_width % 3)) * (rc->initial_xmit_delay / slice_width) : 0;<br>
> - if (3 * bpp_group >= (((rc->initial_xmit_delay + 2) / 3) * (3 + (cm == CM_422)))) {<br>
> - if ((rc->initial_xmit_delay + padding_pixels) % 3 == 1)<br>
> - rc->initial_xmit_delay++;<br>
> - }<br>
> -<br>
> - rc->flatness_min_qp = ((bpc == BPC_8) ? (3) : ((bpc == BPC_10) ? (7) : (11))) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> - rc->flatness_max_qp = ((bpc == BPC_8) ? (12) : ((bpc == BPC_10) ? (16) : (20))) - ((minor_version == 1 && cm == CM_444) ? 1 : 0);<br>
> - rc->flatness_det_thresh = 2 << (bpc - 8);<br>
> -<br>
> - get_qp_set(rc->qp_min, cm, bpc, DAL_MM_MIN, bpp);<br>
> - get_qp_set(rc->qp_max, cm, bpc, DAL_MM_MAX, bpp);<br>
> - if (cm == CM_444 && minor_version == 1) {<br>
> - for (i = 0; i < QP_SET_SIZE; ++i) {<br>
> - rc->qp_min[i] = rc->qp_min[i] > 0 ? rc->qp_min[i] - 1 : 0;<br>
> - rc->qp_max[i] = rc->qp_max[i] > 0 ? rc->qp_max[i] - 1 : 0;<br>
> - }<br>
> - }<br>
> - get_ofs_set(rc->ofs, cm, bpp);<br>
> -<br>
> - /* fixed parameters */<br>
> - rc->rc_model_size = 8192;<br>
> - rc->rc_edge_factor = 6;<br>
> - rc->rc_tgt_offset_hi = 3;<br>
> - rc->rc_tgt_offset_lo = 3;<br>
> -<br>
> - rc->rc_buf_thresh[0] = 896;<br>
> - rc->rc_buf_thresh[1] = 1792;<br>
> - rc->rc_buf_thresh[2] = 2688;<br>
> - rc->rc_buf_thresh[3] = 3584;<br>
> - rc->rc_buf_thresh[4] = 4480;<br>
> - rc->rc_buf_thresh[5] = 5376;<br>
> - rc->rc_buf_thresh[6] = 6272;<br>
> - rc->rc_buf_thresh[7] = 6720;<br>
> - rc->rc_buf_thresh[8] = 7168;<br>
> - rc->rc_buf_thresh[9] = 7616;<br>
> - rc->rc_buf_thresh[10] = 7744;<br>
> - rc->rc_buf_thresh[11] = 7872;<br>
> - rc->rc_buf_thresh[12] = 8000;<br>
> - rc->rc_buf_thresh[13] = 8064;<br>
> -}<br>
> -<br>
> -static u32 _do_bytes_per_pixel_calc(int slice_width, u16 drm_bpp,<br>
> - bool is_navite_422_or_420)<br>
> -{<br>
> - float bpp;<br>
> - u32 bytes_per_pixel;<br>
> - double d_bytes_per_pixel;<br>
> -<br>
> - bpp = ((float)drm_bpp / 16.0);<br>
> - d_bytes_per_pixel = dsc_ceil(bpp * slice_width / 8.0) / slice_width;<br>
> - // TODO: Make sure the formula for calculating this is precise (ceiling<br>
> - // vs. floor, and at what point they should be applied)<br>
> - if (is_navite_422_or_420)<br>
> - d_bytes_per_pixel /= 2;<br>
> -<br>
> - bytes_per_pixel = (u32)dsc_ceil(d_bytes_per_pixel * 0x10000000);<br>
> -<br>
> - return bytes_per_pixel;<br>
> -}<br>
> <br>
> /**<br>
> * calc_rc_params - reads the user's cmdline mode<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.h b/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.h<br>
> index 262f06afcbf9..c2340e001b57 100644<br>
> --- a/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.h<br>
> +++ b/drivers/gpu/drm/amd/display/dc/dsc/rc_calc.h<br>
> @@ -27,55 +27,7 @@<br>
> #ifndef __RC_CALC_H__<br>
> #define __RC_CALC_H__<br>
> <br>
> -<br>
> -#define QP_SET_SIZE 15<br>
> -<br>
> -typedef int qp_set[QP_SET_SIZE];<br>
> -<br>
> -struct rc_params {<br>
> - int rc_quant_incr_limit0;<br>
> - int rc_quant_incr_limit1;<br>
> - int initial_fullness_offset;<br>
> - int initial_xmit_delay;<br>
> - int first_line_bpg_offset;<br>
> - int second_line_bpg_offset;<br>
> - int flatness_min_qp;<br>
> - int flatness_max_qp;<br>
> - int flatness_det_thresh;<br>
> - qp_set qp_min;<br>
> - qp_set qp_max;<br>
> - qp_set ofs;<br>
> - int rc_model_size;<br>
> - int rc_edge_factor;<br>
> - int rc_tgt_offset_hi;<br>
> - int rc_tgt_offset_lo;<br>
> - int rc_buf_thresh[QP_SET_SIZE - 1];<br>
> -};<br>
> -<br>
> -enum colour_mode {<br>
> - CM_RGB, /* 444 RGB */<br>
> - CM_444, /* 444 YUV or simple 422 */<br>
> - CM_422, /* native 422 */<br>
> - CM_420 /* native 420 */<br>
> -};<br>
> -<br>
> -enum bits_per_comp {<br>
> - BPC_8 = 8,<br>
> - BPC_10 = 10,<br>
> - BPC_12 = 12<br>
> -};<br>
> -<br>
> -enum max_min {<br>
> - DAL_MM_MIN = 0,<br>
> - DAL_MM_MAX = 1<br>
> -};<br>
> -<br>
> -struct qp_entry {<br>
> - float bpp;<br>
> - const qp_set qps;<br>
> -};<br>
> -<br>
> -typedef struct qp_entry qp_table[];<br>
> +#include "dml/dsc/rc_calc_fpu.h"<br>
> <br>
> void calc_rc_params(struct rc_params *rc, const struct drm_dsc_config *pps);<br>
> u32 calc_dsc_bytes_per_pixel(const struct drm_dsc_config *pps);<br>
> diff --git a/drivers/gpu/drm/amd/display/dc/dsc/rc_calc_dpi.c b/drivers/gpu/drm/amd/display/dc/dsc/rc_calc_dpi.c<br>
> index ef830aded5b1..1e19dd674e5a 100644<br>
> --- a/drivers/gpu/drm/amd/display/dc/dsc/rc_calc_dpi.c<br>
> +++ b/drivers/gpu/drm/amd/display/dc/dsc/rc_calc_dpi.c<br>
> @@ -22,7 +22,6 @@<br>
> * Authors: AMD<br>
> *<br>
> */<br>
> -#include "os_types.h"<br>
> #include <drm/drm_dsc.h><br>
> #include "dscc_types.h"<br>
> #include "rc_calc.h"<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>