1 // SPDX-License-Identifier: MIT
3 * Copyright © 2018 Intel Corp
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/errno.h>
13 #include <linux/byteorder/generic.h>
15 #include <drm/display/drm_dp_helper.h>
16 #include <drm/display/drm_dsc_helper.h>
17 #include <drm/drm_print.h>
22 * VESA specification for DP 1.4 adds a new feature called Display Stream
23 * Compression (DSC) used to compress the pixel bits before sending it on
24 * DP/eDP/MIPI DSI interface. DSC is required to be enabled so that the existing
25 * display interfaces can support high resolutions at higher frames rates uisng
26 * the maximum available link capacity of these interfaces.
28 * These functions contain some common logic and helpers to deal with VESA
29 * Display Stream Compression standard required for DSC on Display Port/eDP or
30 * MIPI display interfaces.
34 * drm_dsc_dp_pps_header_init() - Initializes the PPS Header
35 * for DisplayPort as per the DP 1.4 spec.
36 * @pps_header: Secondary data packet header for DSC Picture
37 * Parameter Set as defined in &struct dp_sdp_header
39 * DP 1.4 spec defines the secondary data packet for sending the
40 * picture parameter infoframes from the source to the sink.
41 * This function populates the SDP header defined in
42 * &struct dp_sdp_header.
44 void drm_dsc_dp_pps_header_init(struct dp_sdp_header *pps_header)
46 memset(pps_header, 0, sizeof(*pps_header));
48 pps_header->HB1 = DP_SDP_PPS;
49 pps_header->HB2 = DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1;
51 EXPORT_SYMBOL(drm_dsc_dp_pps_header_init);
54 * drm_dsc_dp_rc_buffer_size - get rc buffer size in bytes
55 * @rc_buffer_block_size: block size code, according to DPCD offset 62h
56 * @rc_buffer_size: number of blocks - 1, according to DPCD offset 63h
59 * buffer size in bytes, or 0 on invalid input
61 int drm_dsc_dp_rc_buffer_size(u8 rc_buffer_block_size, u8 rc_buffer_size)
63 int size = 1024 * (rc_buffer_size + 1);
65 switch (rc_buffer_block_size) {
66 case DP_DSC_RC_BUF_BLK_SIZE_1:
68 case DP_DSC_RC_BUF_BLK_SIZE_4:
70 case DP_DSC_RC_BUF_BLK_SIZE_16:
72 case DP_DSC_RC_BUF_BLK_SIZE_64:
78 EXPORT_SYMBOL(drm_dsc_dp_rc_buffer_size);
81 * drm_dsc_pps_payload_pack() - Populates the DSC PPS
84 * Bitwise struct for DSC Picture Parameter Set. This is defined
85 * by &struct drm_dsc_picture_parameter_set
87 * DSC Configuration data filled by driver as defined by
88 * &struct drm_dsc_config
90 * DSC source device sends a picture parameter set (PPS) containing the
91 * information required by the sink to decode the compressed frame. Driver
92 * populates the DSC PPS struct using the DSC configuration parameters in
93 * the order expected by the DSC Display Sink device. For the DSC, the sink
94 * device expects the PPS payload in big endian format for fields
95 * that span more than 1 byte.
97 void drm_dsc_pps_payload_pack(struct drm_dsc_picture_parameter_set *pps_payload,
98 const struct drm_dsc_config *dsc_cfg)
102 /* Protect against someone accidentally changing struct size */
103 BUILD_BUG_ON(sizeof(*pps_payload) !=
104 DP_SDP_PPS_HEADER_PAYLOAD_BYTES_MINUS_1 + 1);
106 memset(pps_payload, 0, sizeof(*pps_payload));
109 pps_payload->dsc_version =
110 dsc_cfg->dsc_version_minor |
111 dsc_cfg->dsc_version_major << DSC_PPS_VERSION_MAJOR_SHIFT;
117 dsc_cfg->line_buf_depth |
118 dsc_cfg->bits_per_component << DSC_PPS_BPC_SHIFT;
122 ((dsc_cfg->bits_per_pixel & DSC_PPS_BPP_HIGH_MASK) >>
124 dsc_cfg->vbr_enable << DSC_PPS_VBR_EN_SHIFT |
125 dsc_cfg->simple_422 << DSC_PPS_SIMPLE422_SHIFT |
126 dsc_cfg->convert_rgb << DSC_PPS_CONVERT_RGB_SHIFT |
127 dsc_cfg->block_pred_enable << DSC_PPS_BLOCK_PRED_EN_SHIFT;
130 pps_payload->bits_per_pixel_low =
131 (dsc_cfg->bits_per_pixel & DSC_PPS_LSB_MASK);
134 * The DSC panel expects the PPS packet to have big endian format
135 * for data spanning 2 bytes. Use a macro cpu_to_be16() to convert
136 * to big endian format. If format is little endian, it will swap
137 * bytes to convert to Big endian else keep it unchanged.
141 pps_payload->pic_height = cpu_to_be16(dsc_cfg->pic_height);
144 pps_payload->pic_width = cpu_to_be16(dsc_cfg->pic_width);
147 pps_payload->slice_height = cpu_to_be16(dsc_cfg->slice_height);
150 pps_payload->slice_width = cpu_to_be16(dsc_cfg->slice_width);
153 pps_payload->chunk_size = cpu_to_be16(dsc_cfg->slice_chunk_size);
156 pps_payload->initial_xmit_delay_high =
157 ((dsc_cfg->initial_xmit_delay &
158 DSC_PPS_INIT_XMIT_DELAY_HIGH_MASK) >>
162 pps_payload->initial_xmit_delay_low =
163 (dsc_cfg->initial_xmit_delay & DSC_PPS_LSB_MASK);
166 pps_payload->initial_dec_delay =
167 cpu_to_be16(dsc_cfg->initial_dec_delay);
172 pps_payload->initial_scale_value =
173 dsc_cfg->initial_scale_value;
176 pps_payload->scale_increment_interval =
177 cpu_to_be16(dsc_cfg->scale_increment_interval);
180 pps_payload->scale_decrement_interval_high =
181 ((dsc_cfg->scale_decrement_interval &
182 DSC_PPS_SCALE_DEC_INT_HIGH_MASK) >>
186 pps_payload->scale_decrement_interval_low =
187 (dsc_cfg->scale_decrement_interval & DSC_PPS_LSB_MASK);
189 /* PPS 26[7:0], PPS 27[7:5] RESERVED */
192 pps_payload->first_line_bpg_offset =
193 dsc_cfg->first_line_bpg_offset;
196 pps_payload->nfl_bpg_offset =
197 cpu_to_be16(dsc_cfg->nfl_bpg_offset);
200 pps_payload->slice_bpg_offset =
201 cpu_to_be16(dsc_cfg->slice_bpg_offset);
204 pps_payload->initial_offset =
205 cpu_to_be16(dsc_cfg->initial_offset);
208 pps_payload->final_offset = cpu_to_be16(dsc_cfg->final_offset);
211 pps_payload->flatness_min_qp = dsc_cfg->flatness_min_qp;
214 pps_payload->flatness_max_qp = dsc_cfg->flatness_max_qp;
217 pps_payload->rc_model_size = cpu_to_be16(dsc_cfg->rc_model_size);
220 pps_payload->rc_edge_factor = DSC_RC_EDGE_FACTOR_CONST;
223 pps_payload->rc_quant_incr_limit0 =
224 dsc_cfg->rc_quant_incr_limit0;
227 pps_payload->rc_quant_incr_limit1 =
228 dsc_cfg->rc_quant_incr_limit1;
231 pps_payload->rc_tgt_offset = DSC_RC_TGT_OFFSET_LO_CONST |
232 DSC_RC_TGT_OFFSET_HI_CONST << DSC_PPS_RC_TGT_OFFSET_HI_SHIFT;
235 for (i = 0; i < DSC_NUM_BUF_RANGES - 1; i++)
236 pps_payload->rc_buf_thresh[i] =
237 dsc_cfg->rc_buf_thresh[i];
241 * For DSC sink programming the RC Range parameter fields
242 * are as follows: Min_qp[15:11], max_qp[10:6], offset[5:0]
244 for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
245 pps_payload->rc_range_parameters[i] =
246 cpu_to_be16((dsc_cfg->rc_range_params[i].range_min_qp <<
247 DSC_PPS_RC_RANGE_MINQP_SHIFT) |
248 (dsc_cfg->rc_range_params[i].range_max_qp <<
249 DSC_PPS_RC_RANGE_MAXQP_SHIFT) |
250 (dsc_cfg->rc_range_params[i].range_bpg_offset));
254 pps_payload->native_422_420 = dsc_cfg->native_422 |
255 dsc_cfg->native_420 << DSC_PPS_NATIVE_420_SHIFT;
258 pps_payload->second_line_bpg_offset =
259 dsc_cfg->second_line_bpg_offset;
262 pps_payload->nsl_bpg_offset =
263 cpu_to_be16(dsc_cfg->nsl_bpg_offset);
266 pps_payload->second_line_offset_adj =
267 cpu_to_be16(dsc_cfg->second_line_offset_adj);
269 /* PPS 94 - 127 are O */
271 EXPORT_SYMBOL(drm_dsc_pps_payload_pack);
273 /* From DSC_v1.11 spec, rc_parameter_Set syntax element typically constant */
274 static const u16 drm_dsc_rc_buf_thresh[] = {
275 896, 1792, 2688, 3584, 4480, 5376, 6272, 6720, 7168, 7616,
276 7744, 7872, 8000, 8064
280 * drm_dsc_set_rc_buf_thresh() - Set thresholds for the RC model
281 * in accordance with the DSC 1.2 specification.
283 * @vdsc_cfg: DSC Configuration data partially filled by driver
285 void drm_dsc_set_rc_buf_thresh(struct drm_dsc_config *vdsc_cfg)
289 BUILD_BUG_ON(ARRAY_SIZE(drm_dsc_rc_buf_thresh) !=
290 DSC_NUM_BUF_RANGES - 1);
291 BUILD_BUG_ON(ARRAY_SIZE(drm_dsc_rc_buf_thresh) !=
292 ARRAY_SIZE(vdsc_cfg->rc_buf_thresh));
294 for (i = 0; i < ARRAY_SIZE(drm_dsc_rc_buf_thresh); i++)
295 vdsc_cfg->rc_buf_thresh[i] = drm_dsc_rc_buf_thresh[i] >> 6;
298 * For 6bpp, RC Buffer threshold 12 and 13 need a different value
301 if (vdsc_cfg->bits_per_pixel == 6 << 4) {
302 vdsc_cfg->rc_buf_thresh[12] = 7936 >> 6;
303 vdsc_cfg->rc_buf_thresh[13] = 8000 >> 6;
306 EXPORT_SYMBOL(drm_dsc_set_rc_buf_thresh);
308 struct rc_parameters {
309 u16 initial_xmit_delay;
310 u8 first_line_bpg_offset;
314 u8 rc_quant_incr_limit0;
315 u8 rc_quant_incr_limit1;
316 struct drm_dsc_rc_range_parameters rc_range_params[DSC_NUM_BUF_RANGES];
319 struct rc_parameters_data {
322 struct rc_parameters params;
325 #define DSC_BPP(bpp) ((bpp) << 4)
328 * Rate Control Related Parameter Recommended Values from DSC_v1.1 spec prior
329 * to DSC 1.1 fractional bpp underflow SCR (DSC_v1.1_E1.pdf)
331 * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
333 static const struct rc_parameters_data rc_parameters_pre_scr[] = {
335 .bpp = DSC_BPP(6), .bpc = 8,
336 { 683, 15, 6144, 3, 13, 11, 11, {
337 { 0, 2, 0 }, { 1, 4, -2 }, { 3, 6, -2 }, { 4, 6, -4 },
338 { 5, 7, -6 }, { 5, 7, -6 }, { 6, 7, -6 }, { 6, 8, -8 },
339 { 7, 9, -8 }, { 8, 10, -10 }, { 9, 11, -10 }, { 10, 12, -12 },
340 { 10, 13, -12 }, { 12, 14, -12 }, { 15, 15, -12 }
345 .bpp = DSC_BPP(8), .bpc = 8,
346 { 512, 12, 6144, 3, 12, 11, 11, {
347 { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
348 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
349 { 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 }, { 5, 12, -12 },
350 { 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
355 .bpp = DSC_BPP(8), .bpc = 10,
356 { 512, 12, 6144, 7, 16, 15, 15, {
358 * DSC model/pre-SCR-cfg has 8 for range_max_qp[0], however
359 * VESA DSC 1.1 Table E-5 sets it to 4.
361 { 0, 4, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
362 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
363 { 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
364 { 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
369 .bpp = DSC_BPP(8), .bpc = 12,
370 { 512, 12, 6144, 11, 20, 19, 19, {
371 { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
372 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
373 { 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
374 { 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
380 .bpp = DSC_BPP(10), .bpc = 8,
381 { 410, 12, 5632, 3, 12, 11, 11, {
382 { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
383 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
384 { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 11, -10 },
385 { 5, 12, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
390 .bpp = DSC_BPP(10), .bpc = 10,
391 { 410, 12, 5632, 7, 16, 15, 15, {
392 { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
393 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
394 { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 15, -10 },
395 { 9, 16, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
400 .bpp = DSC_BPP(10), .bpc = 12,
401 { 410, 12, 5632, 11, 20, 19, 19, {
402 { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
403 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
404 { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
405 { 13, 19, -10 }, { 13, 20, -12 }, { 15, 21, -12 },
411 .bpp = DSC_BPP(12), .bpc = 8,
412 { 341, 15, 2048, 3, 12, 11, 11, {
413 { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
414 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
415 { 3, 9, -8 }, { 3, 10, -10 }, { 5, 11, -10 },
416 { 5, 12, -12 }, { 5, 13, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
421 .bpp = DSC_BPP(12), .bpc = 10,
422 { 341, 15, 2048, 7, 16, 15, 15, {
423 { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
424 { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
425 { 7, 13, -8 }, { 7, 14, -10 }, { 9, 15, -10 }, { 9, 16, -12 },
426 { 9, 17, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
431 .bpp = DSC_BPP(12), .bpc = 12,
432 { 341, 15, 2048, 11, 20, 19, 19, {
433 { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
434 { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
435 { 11, 17, -8 }, { 11, 18, -10 }, { 13, 19, -10 },
436 { 13, 20, -12 }, { 13, 21, -12 }, { 15, 21, -12 },
442 .bpp = DSC_BPP(15), .bpc = 8,
443 { 273, 15, 2048, 3, 12, 11, 11, {
444 { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
445 { 1, 2, 2 }, { 1, 3, 0 }, { 1, 4, -2 }, { 2, 4, -4 },
446 { 3, 4, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 5, 7, -10 },
447 { 5, 8, -12 }, { 7, 13, -12 }, { 13, 15, -12 }
452 .bpp = DSC_BPP(15), .bpc = 10,
453 { 273, 15, 2048, 7, 16, 15, 15, {
454 { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
455 { 5, 6, 2 }, { 5, 7, 0 }, { 5, 8, -2 }, { 6, 8, -4 },
456 { 7, 8, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 9, 11, -10 },
457 { 9, 12, -12 }, { 11, 17, -12 }, { 17, 19, -12 }
462 .bpp = DSC_BPP(15), .bpc = 12,
463 { 273, 15, 2048, 11, 20, 19, 19, {
464 { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
465 { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
466 { 11, 12, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
467 { 13, 15, -10 }, { 13, 16, -12 }, { 15, 21, -12 },
476 * Selected Rate Control Related Parameter Recommended Values from DSC v1.2, v1.2a, v1.2b and
479 * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
481 static const struct rc_parameters_data rc_parameters_1_2_444[] = {
483 .bpp = DSC_BPP(6), .bpc = 8,
484 { 768, 15, 6144, 3, 13, 11, 11, {
485 { 0, 4, 0 }, { 1, 6, -2 }, { 3, 8, -2 }, { 4, 8, -4 },
486 { 5, 9, -6 }, { 5, 9, -6 }, { 6, 9, -6 }, { 6, 10, -8 },
487 { 7, 11, -8 }, { 8, 12, -10 }, { 9, 12, -10 }, { 10, 12, -12 },
488 { 10, 12, -12 }, { 11, 12, -12 }, { 13, 14, -12 }
493 .bpp = DSC_BPP(6), .bpc = 10,
494 { 768, 15, 6144, 7, 17, 15, 15, {
495 { 0, 8, 0 }, { 3, 10, -2 }, { 7, 12, -2 }, { 8, 12, -4 },
496 { 9, 13, -6 }, { 9, 13, -6 }, { 10, 13, -6 }, { 10, 14, -8 },
497 { 11, 15, -8 }, { 12, 16, -10 }, { 13, 16, -10 },
498 { 14, 16, -12 }, { 14, 16, -12 }, { 15, 16, -12 },
504 .bpp = DSC_BPP(6), .bpc = 12,
505 { 768, 15, 6144, 11, 21, 19, 19, {
506 { 0, 12, 0 }, { 5, 14, -2 }, { 11, 16, -2 }, { 12, 16, -4 },
507 { 13, 17, -6 }, { 13, 17, -6 }, { 14, 17, -6 }, { 14, 18, -8 },
508 { 15, 19, -8 }, { 16, 20, -10 }, { 17, 20, -10 },
509 { 18, 20, -12 }, { 18, 20, -12 }, { 19, 20, -12 },
515 .bpp = DSC_BPP(6), .bpc = 14,
516 { 768, 15, 6144, 15, 25, 23, 23, {
517 { 0, 16, 0 }, { 7, 18, -2 }, { 15, 20, -2 }, { 16, 20, -4 },
518 { 17, 21, -6 }, { 17, 21, -6 }, { 18, 21, -6 }, { 18, 22, -8 },
519 { 19, 23, -8 }, { 20, 24, -10 }, { 21, 24, -10 },
520 { 22, 24, -12 }, { 22, 24, -12 }, { 23, 24, -12 },
526 .bpp = DSC_BPP(6), .bpc = 16,
527 { 768, 15, 6144, 19, 29, 27, 27, {
528 { 0, 20, 0 }, { 9, 22, -2 }, { 19, 24, -2 }, { 20, 24, -4 },
529 { 21, 25, -6 }, { 21, 25, -6 }, { 22, 25, -6 }, { 22, 26, -8 },
530 { 23, 27, -8 }, { 24, 28, -10 }, { 25, 28, -10 },
531 { 26, 28, -12 }, { 26, 28, -12 }, { 27, 28, -12 },
537 .bpp = DSC_BPP(8), .bpc = 8,
538 { 512, 12, 6144, 3, 12, 11, 11, {
539 { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
540 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
541 { 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
542 { 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
547 .bpp = DSC_BPP(8), .bpc = 10,
548 { 512, 12, 6144, 7, 16, 15, 15, {
549 { 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
550 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
551 { 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
552 { 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
557 .bpp = DSC_BPP(8), .bpc = 12,
558 { 512, 12, 6144, 11, 20, 19, 19, {
559 { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
560 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
561 { 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
562 { 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
568 .bpp = DSC_BPP(8), .bpc = 14,
569 { 512, 12, 6144, 15, 24, 23, 23, {
570 { 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
571 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
572 { 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
573 { 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
579 .bpp = DSC_BPP(8), .bpc = 16,
580 { 512, 12, 6144, 19, 28, 27, 27, {
581 { 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
582 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
583 { 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
584 { 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
590 .bpp = DSC_BPP(10), .bpc = 8,
591 { 410, 15, 5632, 3, 12, 11, 11, {
592 { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
593 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
594 { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
595 { 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
600 .bpp = DSC_BPP(10), .bpc = 10,
601 { 410, 15, 5632, 7, 16, 15, 15, {
602 { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
603 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
604 { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
605 { 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
610 .bpp = DSC_BPP(10), .bpc = 12,
611 { 410, 15, 5632, 11, 20, 19, 19, {
612 { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
613 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
614 { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
615 { 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
621 .bpp = DSC_BPP(10), .bpc = 14,
622 { 410, 15, 5632, 15, 24, 23, 23, {
623 { 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
624 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
625 { 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
626 { 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
632 .bpp = DSC_BPP(10), .bpc = 16,
633 { 410, 15, 5632, 19, 28, 27, 27, {
634 { 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
635 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
636 { 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
637 { 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
643 .bpp = DSC_BPP(12), .bpc = 8,
644 { 341, 15, 2048, 3, 12, 11, 11, {
645 { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
646 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
647 { 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
648 { 5, 9, -12 }, { 7, 10, -12 }, { 10, 11, -12 }
653 .bpp = DSC_BPP(12), .bpc = 10,
654 { 341, 15, 2048, 7, 16, 15, 15, {
655 { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
656 { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
657 { 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
658 { 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
663 .bpp = DSC_BPP(12), .bpc = 12,
664 { 341, 15, 2048, 11, 20, 19, 19, {
665 { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
666 { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
667 { 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
668 { 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
674 .bpp = DSC_BPP(12), .bpc = 14,
675 { 341, 15, 2048, 15, 24, 23, 23, {
676 { 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
677 { 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
678 { 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
679 { 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
685 .bpp = DSC_BPP(12), .bpc = 16,
686 { 341, 15, 2048, 19, 28, 27, 27, {
687 { 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
688 { 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
689 { 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
690 { 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
696 .bpp = DSC_BPP(15), .bpc = 8,
697 { 273, 15, 2048, 3, 12, 11, 11, {
698 { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
699 { 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
700 { 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
701 { 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
706 .bpp = DSC_BPP(15), .bpc = 10,
707 { 273, 15, 2048, 7, 16, 15, 15, {
708 { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
709 { 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
710 { 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
711 { 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
716 .bpp = DSC_BPP(15), .bpc = 12,
717 { 273, 15, 2048, 11, 20, 19, 19, {
718 { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
719 { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
720 { 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
721 { 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
727 .bpp = DSC_BPP(15), .bpc = 14,
728 { 273, 15, 2048, 15, 24, 23, 23, {
729 { 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
730 { 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
731 { 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
732 { 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
738 .bpp = DSC_BPP(15), .bpc = 16,
739 { 273, 15, 2048, 19, 28, 27, 27, {
740 { 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
741 { 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
742 { 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
743 { 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
752 * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from
753 * DSC v1.2, v1.2a, v1.2b
755 * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
757 static const struct rc_parameters_data rc_parameters_1_2_422[] = {
759 .bpp = DSC_BPP(6), .bpc = 8,
760 { 512, 15, 6144, 3, 12, 11, 11, {
761 { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
762 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
763 { 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
764 { 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
769 .bpp = DSC_BPP(6), .bpc = 10,
770 { 512, 15, 6144, 7, 16, 15, 15, {
771 { 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
772 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
773 { 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
774 { 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
779 .bpp = DSC_BPP(6), .bpc = 12,
780 { 512, 15, 6144, 11, 20, 19, 19, {
781 { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
782 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
783 { 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
784 { 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
790 .bpp = DSC_BPP(6), .bpc = 14,
791 { 512, 15, 6144, 15, 24, 23, 23, {
792 { 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
793 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
794 { 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
795 { 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
801 .bpp = DSC_BPP(6), .bpc = 16,
802 { 512, 15, 6144, 19, 28, 27, 27, {
803 { 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
804 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
805 { 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
806 { 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
812 .bpp = DSC_BPP(7), .bpc = 8,
813 { 410, 15, 5632, 3, 12, 11, 11, {
814 { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
815 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
816 { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
817 { 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
822 .bpp = DSC_BPP(7), .bpc = 10,
823 { 410, 15, 5632, 7, 16, 15, 15, {
824 { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
825 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
826 { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
827 { 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
832 .bpp = DSC_BPP(7), .bpc = 12,
833 { 410, 15, 5632, 11, 20, 19, 19, {
834 { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
835 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
836 { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
837 { 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
843 .bpp = DSC_BPP(7), .bpc = 14,
844 { 410, 15, 5632, 15, 24, 23, 23, {
845 { 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
846 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
847 { 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
848 { 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
854 .bpp = DSC_BPP(7), .bpc = 16,
855 { 410, 15, 5632, 19, 28, 27, 27, {
856 { 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
857 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
858 { 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
859 { 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
865 .bpp = DSC_BPP(8), .bpc = 8,
866 { 341, 15, 2048, 3, 12, 11, 11, {
867 { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
868 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
869 { 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
870 { 5, 9, -12 }, { 7, 10, -12 }, { 10, 11, -12 }
875 .bpp = DSC_BPP(8), .bpc = 10,
876 { 341, 15, 2048, 7, 16, 15, 15, {
877 { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
878 { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
879 { 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
880 { 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
885 .bpp = DSC_BPP(8), .bpc = 12,
886 { 341, 15, 2048, 11, 20, 19, 19, {
887 { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
888 { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
889 { 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
890 { 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
896 .bpp = DSC_BPP(8), .bpc = 14,
897 { 341, 15, 2048, 15, 24, 23, 23, {
898 { 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
899 { 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
900 { 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
901 { 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
907 .bpp = DSC_BPP(8), .bpc = 16,
908 { 341, 15, 2048, 19, 28, 27, 27, {
909 { 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
910 { 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
911 { 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
912 { 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
918 .bpp = DSC_BPP(10), .bpc = 8,
919 { 273, 15, 2048, 3, 12, 11, 11, {
920 { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
921 { 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
922 { 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
923 { 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
928 .bpp = DSC_BPP(10), .bpc = 10,
929 { 273, 15, 2048, 7, 16, 15, 15, {
930 { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
931 { 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
932 { 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
933 { 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
938 .bpp = DSC_BPP(10), .bpc = 12,
939 { 273, 15, 2048, 11, 20, 19, 19, {
940 { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
941 { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
942 { 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
943 { 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
949 .bpp = DSC_BPP(10), .bpc = 14,
950 { 273, 15, 2048, 15, 24, 23, 23, {
951 { 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
952 { 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
953 { 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
954 { 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
960 .bpp = DSC_BPP(10), .bpc = 16,
961 { 273, 15, 2048, 19, 28, 27, 27, {
962 { 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
963 { 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
964 { 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
965 { 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
974 * Selected Rate Control Related Parameter Recommended Values for 4:2:2 from
975 * DSC v1.2, v1.2a, v1.2b
977 * Cross-checked against C Model releases: DSC_model_20161212 and 20210623
979 static const struct rc_parameters_data rc_parameters_1_2_420[] = {
981 .bpp = DSC_BPP(4), .bpc = 8,
982 { 512, 12, 6144, 3, 12, 11, 11, {
983 { 0, 4, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
984 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
985 { 3, 9, -8 }, { 3, 10, -10 }, { 5, 10, -10 }, { 5, 11, -12 },
986 { 5, 11, -12 }, { 9, 12, -12 }, { 12, 13, -12 }
991 .bpp = DSC_BPP(4), .bpc = 10,
992 { 512, 12, 6144, 7, 16, 15, 15, {
993 { 0, 8, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 5, 10, -2 },
994 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
995 { 7, 13, -8 }, { 7, 14, -10 }, { 9, 14, -10 }, { 9, 15, -12 },
996 { 9, 15, -12 }, { 13, 16, -12 }, { 16, 17, -12 }
1001 .bpp = DSC_BPP(4), .bpc = 12,
1002 { 512, 12, 6144, 11, 20, 19, 19, {
1003 { 0, 12, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 9, 14, -2 },
1004 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
1005 { 11, 17, -8 }, { 11, 18, -10 }, { 13, 18, -10 },
1006 { 13, 19, -12 }, { 13, 19, -12 }, { 17, 20, -12 },
1012 .bpp = DSC_BPP(4), .bpc = 14,
1013 { 512, 12, 6144, 15, 24, 23, 23, {
1014 { 0, 12, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 12, 17, -2 },
1015 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
1016 { 15, 21, -8 }, { 15, 22, -10 }, { 17, 22, -10 },
1017 { 17, 23, -12 }, { 17, 23, -12 }, { 21, 24, -12 },
1023 .bpp = DSC_BPP(4), .bpc = 16,
1024 { 512, 12, 6144, 19, 28, 27, 27, {
1025 { 0, 12, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 15, 20, -2 },
1026 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
1027 { 19, 25, -8 }, { 19, 26, -10 }, { 21, 26, -10 },
1028 { 21, 27, -12 }, { 21, 27, -12 }, { 25, 28, -12 },
1034 .bpp = DSC_BPP(5), .bpc = 8,
1035 { 410, 15, 5632, 3, 12, 11, 11, {
1036 { 0, 3, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 2, 6, -2 },
1037 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
1038 { 3, 9, -8 }, { 3, 9, -10 }, { 5, 10, -10 }, { 5, 10, -10 },
1039 { 5, 11, -12 }, { 7, 11, -12 }, { 11, 12, -12 }
1044 .bpp = DSC_BPP(5), .bpc = 10,
1045 { 410, 15, 5632, 7, 16, 15, 15, {
1046 { 0, 7, 2 }, { 4, 8, 0 }, { 5, 9, 0 }, { 6, 10, -2 },
1047 { 7, 11, -4 }, { 7, 11, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
1048 { 7, 13, -8 }, { 7, 13, -10 }, { 9, 14, -10 }, { 9, 14, -10 },
1049 { 9, 15, -12 }, { 11, 15, -12 }, { 15, 16, -12 }
1054 .bpp = DSC_BPP(5), .bpc = 12,
1055 { 410, 15, 5632, 11, 20, 19, 19, {
1056 { 0, 11, 2 }, { 4, 12, 0 }, { 9, 13, 0 }, { 10, 14, -2 },
1057 { 11, 15, -4 }, { 11, 15, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
1058 { 11, 17, -8 }, { 11, 17, -10 }, { 13, 18, -10 },
1059 { 13, 18, -10 }, { 13, 19, -12 }, { 15, 19, -12 },
1065 .bpp = DSC_BPP(5), .bpc = 14,
1066 { 410, 15, 5632, 15, 24, 23, 23, {
1067 { 0, 11, 2 }, { 5, 13, 0 }, { 11, 15, 0 }, { 13, 18, -2 },
1068 { 15, 19, -4 }, { 15, 19, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
1069 { 15, 21, -8 }, { 15, 21, -10 }, { 17, 22, -10 },
1070 { 17, 22, -10 }, { 17, 23, -12 }, { 19, 23, -12 },
1076 .bpp = DSC_BPP(5), .bpc = 16,
1077 { 410, 15, 5632, 19, 28, 27, 27, {
1078 { 0, 11, 2 }, { 6, 14, 0 }, { 13, 17, 0 }, { 16, 20, -2 },
1079 { 19, 23, -4 }, { 19, 23, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
1080 { 19, 25, -8 }, { 19, 25, -10 }, { 21, 26, -10 },
1081 { 21, 26, -10 }, { 21, 27, -12 }, { 23, 27, -12 },
1087 .bpp = DSC_BPP(6), .bpc = 8,
1088 { 341, 15, 2048, 3, 12, 11, 11, {
1089 { 0, 2, 2 }, { 0, 4, 0 }, { 1, 5, 0 }, { 1, 6, -2 },
1090 { 3, 7, -4 }, { 3, 7, -6 }, { 3, 7, -8 }, { 3, 8, -8 },
1091 { 3, 8, -8 }, { 3, 9, -10 }, { 5, 9, -10 }, { 5, 9, -12 },
1092 { 5, 9, -12 }, { 7, 10, -12 }, { 10, 12, -12 }
1097 .bpp = DSC_BPP(6), .bpc = 10,
1098 { 341, 15, 2048, 7, 16, 15, 15, {
1099 { 0, 2, 2 }, { 2, 5, 0 }, { 3, 7, 0 }, { 4, 8, -2 },
1100 { 6, 9, -4 }, { 7, 10, -6 }, { 7, 11, -8 }, { 7, 12, -8 },
1101 { 7, 12, -8 }, { 7, 13, -10 }, { 9, 13, -10 }, { 9, 13, -12 },
1102 { 9, 13, -12 }, { 11, 14, -12 }, { 14, 15, -12 }
1107 .bpp = DSC_BPP(6), .bpc = 12,
1108 { 341, 15, 2048, 11, 20, 19, 19, {
1109 { 0, 6, 2 }, { 4, 9, 0 }, { 7, 11, 0 }, { 8, 12, -2 },
1110 { 10, 13, -4 }, { 11, 14, -6 }, { 11, 15, -8 }, { 11, 16, -8 },
1111 { 11, 16, -8 }, { 11, 17, -10 }, { 13, 17, -10 },
1112 { 13, 17, -12 }, { 13, 17, -12 }, { 15, 18, -12 },
1118 .bpp = DSC_BPP(6), .bpc = 14,
1119 { 341, 15, 2048, 15, 24, 23, 23, {
1120 { 0, 6, 2 }, { 7, 10, 0 }, { 9, 13, 0 }, { 11, 16, -2 },
1121 { 14, 17, -4 }, { 15, 18, -6 }, { 15, 19, -8 }, { 15, 20, -8 },
1122 { 15, 20, -8 }, { 15, 21, -10 }, { 17, 21, -10 },
1123 { 17, 21, -12 }, { 17, 21, -12 }, { 19, 22, -12 },
1129 .bpp = DSC_BPP(6), .bpc = 16,
1130 { 341, 15, 2048, 19, 28, 27, 27, {
1131 { 0, 6, 2 }, { 6, 11, 0 }, { 11, 15, 0 }, { 14, 18, -2 },
1132 { 18, 21, -4 }, { 19, 22, -6 }, { 19, 23, -8 }, { 19, 24, -8 },
1133 { 19, 24, -8 }, { 19, 25, -10 }, { 21, 25, -10 },
1134 { 21, 25, -12 }, { 21, 25, -12 }, { 23, 26, -12 },
1140 .bpp = DSC_BPP(8), .bpc = 8,
1141 { 256, 15, 2048, 3, 12, 11, 11, {
1142 { 0, 0, 10 }, { 0, 1, 8 }, { 0, 1, 6 }, { 0, 2, 4 },
1143 { 1, 2, 2 }, { 1, 3, 0 }, { 1, 3, -2 }, { 2, 4, -4 },
1144 { 2, 5, -6 }, { 3, 5, -8 }, { 4, 6, -10 }, { 4, 7, -10 },
1145 { 5, 7, -12 }, { 7, 8, -12 }, { 8, 9, -12 }
1150 .bpp = DSC_BPP(8), .bpc = 10,
1151 { 256, 15, 2048, 7, 16, 15, 15, {
1152 { 0, 2, 10 }, { 2, 5, 8 }, { 3, 5, 6 }, { 4, 6, 4 },
1153 { 5, 6, 2 }, { 5, 7, 0 }, { 5, 7, -2 }, { 6, 8, -4 },
1154 { 6, 9, -6 }, { 7, 9, -8 }, { 8, 10, -10 }, { 8, 11, -10 },
1155 { 9, 11, -12 }, { 11, 12, -12 }, { 12, 13, -12 }
1160 .bpp = DSC_BPP(8), .bpc = 12,
1161 { 256, 15, 2048, 11, 20, 19, 19, {
1162 { 0, 4, 10 }, { 2, 7, 8 }, { 4, 9, 6 }, { 6, 11, 4 },
1163 { 9, 11, 2 }, { 9, 11, 0 }, { 9, 12, -2 }, { 10, 12, -4 },
1164 { 11, 13, -6 }, { 11, 13, -8 }, { 12, 14, -10 },
1165 { 13, 15, -10 }, { 13, 15, -12 }, { 15, 16, -12 },
1171 .bpp = DSC_BPP(8), .bpc = 14,
1172 { 256, 15, 2048, 15, 24, 23, 23, {
1173 { 0, 4, 10 }, { 3, 8, 8 }, { 6, 11, 6 }, { 9, 14, 4 },
1174 { 13, 15, 2 }, { 13, 15, 0 }, { 13, 16, -2 }, { 14, 16, -4 },
1175 { 15, 17, -6 }, { 15, 17, -8 }, { 16, 18, -10 },
1176 { 17, 19, -10 }, { 17, 19, -12 }, { 19, 20, -12 },
1182 .bpp = DSC_BPP(8), .bpc = 16,
1183 { 256, 15, 2048, 19, 28, 27, 27, {
1184 { 0, 4, 10 }, { 4, 9, 8 }, { 8, 13, 6 }, { 12, 17, 4 },
1185 { 17, 19, 2 }, { 17, 20, 0 }, { 17, 20, -2 }, { 18, 20, -4 },
1186 { 19, 21, -6 }, { 19, 21, -8 }, { 20, 22, -10 },
1187 { 21, 23, -10 }, { 21, 23, -12 }, { 23, 24, -12 },
1195 static const struct rc_parameters *get_rc_params(const struct rc_parameters_data *rc_parameters,
1197 u8 bits_per_component)
1201 for (i = 0; rc_parameters[i].bpp; i++)
1202 if (rc_parameters[i].bpp == dsc_bpp &&
1203 rc_parameters[i].bpc == bits_per_component)
1204 return &rc_parameters[i].params;
1210 * drm_dsc_setup_rc_params() - Set parameters and limits for RC model in
1211 * accordance with the DSC 1.1 or 1.2 specification and DSC C Model
1212 * Required bits_per_pixel and bits_per_component to be set before calling this
1215 * @vdsc_cfg: DSC Configuration data partially filled by driver
1216 * @type: operating mode and standard to follow
1218 * Return: 0 or -error code in case of an error
1220 int drm_dsc_setup_rc_params(struct drm_dsc_config *vdsc_cfg, enum drm_dsc_params_type type)
1222 const struct rc_parameters_data *data;
1223 const struct rc_parameters *rc_params;
1226 if (WARN_ON_ONCE(!vdsc_cfg->bits_per_pixel ||
1227 !vdsc_cfg->bits_per_component))
1231 case DRM_DSC_1_2_444:
1232 data = rc_parameters_1_2_444;
1234 case DRM_DSC_1_1_PRE_SCR:
1235 data = rc_parameters_pre_scr;
1237 case DRM_DSC_1_2_422:
1238 data = rc_parameters_1_2_422;
1240 case DRM_DSC_1_2_420:
1241 data = rc_parameters_1_2_420;
1247 rc_params = get_rc_params(data,
1248 vdsc_cfg->bits_per_pixel,
1249 vdsc_cfg->bits_per_component);
1253 vdsc_cfg->first_line_bpg_offset = rc_params->first_line_bpg_offset;
1254 vdsc_cfg->initial_xmit_delay = rc_params->initial_xmit_delay;
1255 vdsc_cfg->initial_offset = rc_params->initial_offset;
1256 vdsc_cfg->flatness_min_qp = rc_params->flatness_min_qp;
1257 vdsc_cfg->flatness_max_qp = rc_params->flatness_max_qp;
1258 vdsc_cfg->rc_quant_incr_limit0 = rc_params->rc_quant_incr_limit0;
1259 vdsc_cfg->rc_quant_incr_limit1 = rc_params->rc_quant_incr_limit1;
1261 for (i = 0; i < DSC_NUM_BUF_RANGES; i++) {
1262 vdsc_cfg->rc_range_params[i].range_min_qp =
1263 rc_params->rc_range_params[i].range_min_qp;
1264 vdsc_cfg->rc_range_params[i].range_max_qp =
1265 rc_params->rc_range_params[i].range_max_qp;
1267 * Range BPG Offset uses 2's complement and is only a 6 bits. So
1268 * mask it to get only 6 bits.
1270 vdsc_cfg->rc_range_params[i].range_bpg_offset =
1271 rc_params->rc_range_params[i].range_bpg_offset &
1272 DSC_RANGE_BPG_OFFSET_MASK;
1277 EXPORT_SYMBOL(drm_dsc_setup_rc_params);
1280 * drm_dsc_compute_rc_parameters() - Write rate control
1281 * parameters to the dsc configuration defined in
1282 * &struct drm_dsc_config in accordance with the DSC 1.2
1283 * specification. Some configuration fields must be present
1287 * DSC Configuration data partially filled by driver
1289 int drm_dsc_compute_rc_parameters(struct drm_dsc_config *vdsc_cfg)
1291 unsigned long groups_per_line = 0;
1292 unsigned long groups_total = 0;
1293 unsigned long num_extra_mux_bits = 0;
1294 unsigned long slice_bits = 0;
1295 unsigned long hrd_delay = 0;
1296 unsigned long final_scale = 0;
1297 unsigned long rbs_min = 0;
1299 if (vdsc_cfg->native_420 || vdsc_cfg->native_422) {
1300 /* Number of groups used to code each line of a slice */
1301 groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width / 2,
1302 DSC_RC_PIXELS_PER_GROUP);
1304 /* chunksize in Bytes */
1305 vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width / 2 *
1306 vdsc_cfg->bits_per_pixel,
1309 /* Number of groups used to code each line of a slice */
1310 groups_per_line = DIV_ROUND_UP(vdsc_cfg->slice_width,
1311 DSC_RC_PIXELS_PER_GROUP);
1313 /* chunksize in Bytes */
1314 vdsc_cfg->slice_chunk_size = DIV_ROUND_UP(vdsc_cfg->slice_width *
1315 vdsc_cfg->bits_per_pixel,
1319 if (vdsc_cfg->convert_rgb)
1320 num_extra_mux_bits = 3 * (vdsc_cfg->mux_word_size +
1321 (4 * vdsc_cfg->bits_per_component + 4)
1323 else if (vdsc_cfg->native_422)
1324 num_extra_mux_bits = 4 * vdsc_cfg->mux_word_size +
1325 (4 * vdsc_cfg->bits_per_component + 4) +
1326 3 * (4 * vdsc_cfg->bits_per_component) - 2;
1328 num_extra_mux_bits = 3 * vdsc_cfg->mux_word_size +
1329 (4 * vdsc_cfg->bits_per_component + 4) +
1330 2 * (4 * vdsc_cfg->bits_per_component) - 2;
1331 /* Number of bits in one Slice */
1332 slice_bits = 8 * vdsc_cfg->slice_chunk_size * vdsc_cfg->slice_height;
1334 while ((num_extra_mux_bits > 0) &&
1335 ((slice_bits - num_extra_mux_bits) % vdsc_cfg->mux_word_size))
1336 num_extra_mux_bits--;
1338 if (groups_per_line < vdsc_cfg->initial_scale_value - 8)
1339 vdsc_cfg->initial_scale_value = groups_per_line + 8;
1341 /* scale_decrement_interval calculation according to DSC spec 1.11 */
1342 if (vdsc_cfg->initial_scale_value > 8)
1343 vdsc_cfg->scale_decrement_interval = groups_per_line /
1344 (vdsc_cfg->initial_scale_value - 8);
1346 vdsc_cfg->scale_decrement_interval = DSC_SCALE_DECREMENT_INTERVAL_MAX;
1348 vdsc_cfg->final_offset = vdsc_cfg->rc_model_size -
1349 (vdsc_cfg->initial_xmit_delay *
1350 vdsc_cfg->bits_per_pixel + 8) / 16 + num_extra_mux_bits;
1352 if (vdsc_cfg->final_offset >= vdsc_cfg->rc_model_size) {
1353 DRM_DEBUG_KMS("FinalOfs < RcModelSze for this InitialXmitDelay\n");
1357 final_scale = (vdsc_cfg->rc_model_size * 8) /
1358 (vdsc_cfg->rc_model_size - vdsc_cfg->final_offset);
1359 if (vdsc_cfg->slice_height > 1)
1361 * NflBpgOffset is 16 bit value with 11 fractional bits
1362 * hence we multiply by 2^11 for preserving the
1365 vdsc_cfg->nfl_bpg_offset = DIV_ROUND_UP((vdsc_cfg->first_line_bpg_offset << 11),
1366 (vdsc_cfg->slice_height - 1));
1368 vdsc_cfg->nfl_bpg_offset = 0;
1370 /* Number of groups used to code the entire slice */
1371 groups_total = groups_per_line * vdsc_cfg->slice_height;
1373 /* slice_bpg_offset is 16 bit value with 11 fractional bits */
1374 vdsc_cfg->slice_bpg_offset = DIV_ROUND_UP(((vdsc_cfg->rc_model_size -
1375 vdsc_cfg->initial_offset +
1376 num_extra_mux_bits) << 11),
1379 if (final_scale > 9) {
1381 * ScaleIncrementInterval =
1382 * finaloffset/((NflBpgOffset + SliceBpgOffset)*8(finalscale - 1.125))
1383 * as (NflBpgOffset + SliceBpgOffset) has 11 bit fractional value,
1384 * we need divide by 2^11 from pstDscCfg values
1386 vdsc_cfg->scale_increment_interval =
1387 (vdsc_cfg->final_offset * (1 << 11)) /
1388 ((vdsc_cfg->nfl_bpg_offset +
1389 vdsc_cfg->slice_bpg_offset) *
1393 * If finalScaleValue is less than or equal to 9, a value of 0 should
1394 * be used to disable the scale increment at the end of the slice
1396 vdsc_cfg->scale_increment_interval = 0;
1400 * DSC spec mentions that bits_per_pixel specifies the target
1401 * bits/pixel (bpp) rate that is used by the encoder,
1402 * in steps of 1/16 of a bit per pixel
1404 rbs_min = vdsc_cfg->rc_model_size - vdsc_cfg->initial_offset +
1405 DIV_ROUND_UP(vdsc_cfg->initial_xmit_delay *
1406 vdsc_cfg->bits_per_pixel, 16) +
1407 groups_per_line * vdsc_cfg->first_line_bpg_offset;
1409 hrd_delay = DIV_ROUND_UP((rbs_min * 16), vdsc_cfg->bits_per_pixel);
1410 vdsc_cfg->rc_bits = (hrd_delay * vdsc_cfg->bits_per_pixel) / 16;
1411 vdsc_cfg->initial_dec_delay = hrd_delay - vdsc_cfg->initial_xmit_delay;
1415 EXPORT_SYMBOL(drm_dsc_compute_rc_parameters);