Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2012-17 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 #include <drm/display/drm_dsc_helper.h>
0026 #include "dscc_types.h"
0027 #include "rc_calc.h"
0028 
0029 static void copy_pps_fields(struct drm_dsc_config *to, const struct drm_dsc_config *from)
0030 {
0031     to->line_buf_depth           = from->line_buf_depth;
0032     to->bits_per_component       = from->bits_per_component;
0033     to->convert_rgb              = from->convert_rgb;
0034     to->slice_width              = from->slice_width;
0035     to->slice_height             = from->slice_height;
0036     to->simple_422               = from->simple_422;
0037     to->native_422               = from->native_422;
0038     to->native_420               = from->native_420;
0039     to->pic_width                = from->pic_width;
0040     to->pic_height               = from->pic_height;
0041     to->rc_tgt_offset_high       = from->rc_tgt_offset_high;
0042     to->rc_tgt_offset_low        = from->rc_tgt_offset_low;
0043     to->bits_per_pixel           = from->bits_per_pixel;
0044     to->rc_edge_factor           = from->rc_edge_factor;
0045     to->rc_quant_incr_limit1     = from->rc_quant_incr_limit1;
0046     to->rc_quant_incr_limit0     = from->rc_quant_incr_limit0;
0047     to->initial_xmit_delay       = from->initial_xmit_delay;
0048     to->initial_dec_delay        = from->initial_dec_delay;
0049     to->block_pred_enable        = from->block_pred_enable;
0050     to->first_line_bpg_offset    = from->first_line_bpg_offset;
0051     to->second_line_bpg_offset   = from->second_line_bpg_offset;
0052     to->initial_offset           = from->initial_offset;
0053     memcpy(&to->rc_buf_thresh, &from->rc_buf_thresh, sizeof(from->rc_buf_thresh));
0054     memcpy(&to->rc_range_params, &from->rc_range_params, sizeof(from->rc_range_params));
0055     to->rc_model_size            = from->rc_model_size;
0056     to->flatness_min_qp          = from->flatness_min_qp;
0057     to->flatness_max_qp          = from->flatness_max_qp;
0058     to->initial_scale_value      = from->initial_scale_value;
0059     to->scale_decrement_interval = from->scale_decrement_interval;
0060     to->scale_increment_interval = from->scale_increment_interval;
0061     to->nfl_bpg_offset           = from->nfl_bpg_offset;
0062     to->nsl_bpg_offset           = from->nsl_bpg_offset;
0063     to->slice_bpg_offset         = from->slice_bpg_offset;
0064     to->final_offset             = from->final_offset;
0065     to->vbr_enable               = from->vbr_enable;
0066     to->slice_chunk_size         = from->slice_chunk_size;
0067     to->second_line_offset_adj   = from->second_line_offset_adj;
0068     to->dsc_version_minor        = from->dsc_version_minor;
0069 }
0070 
0071 static void copy_rc_to_cfg(struct drm_dsc_config *dsc_cfg, const struct rc_params *rc)
0072 {
0073     int i;
0074 
0075     dsc_cfg->rc_quant_incr_limit0   = rc->rc_quant_incr_limit0;
0076     dsc_cfg->rc_quant_incr_limit1   = rc->rc_quant_incr_limit1;
0077     dsc_cfg->initial_offset         = rc->initial_fullness_offset;
0078     dsc_cfg->initial_xmit_delay     = rc->initial_xmit_delay;
0079     dsc_cfg->first_line_bpg_offset  = rc->first_line_bpg_offset;
0080     dsc_cfg->second_line_bpg_offset = rc->second_line_bpg_offset;
0081     dsc_cfg->flatness_min_qp        = rc->flatness_min_qp;
0082     dsc_cfg->flatness_max_qp        = rc->flatness_max_qp;
0083     for (i = 0; i < QP_SET_SIZE; ++i) {
0084         dsc_cfg->rc_range_params[i].range_min_qp     = rc->qp_min[i];
0085         dsc_cfg->rc_range_params[i].range_max_qp     = rc->qp_max[i];
0086         /* Truncate 8-bit signed value to 6-bit signed value */
0087         dsc_cfg->rc_range_params[i].range_bpg_offset = 0x3f & rc->ofs[i];
0088     }
0089     dsc_cfg->rc_model_size    = rc->rc_model_size;
0090     dsc_cfg->rc_edge_factor   = rc->rc_edge_factor;
0091     dsc_cfg->rc_tgt_offset_high = rc->rc_tgt_offset_hi;
0092     dsc_cfg->rc_tgt_offset_low = rc->rc_tgt_offset_lo;
0093 
0094     for (i = 0; i < QP_SET_SIZE - 1; ++i)
0095         dsc_cfg->rc_buf_thresh[i] = rc->rc_buf_thresh[i];
0096 }
0097 
0098 int dscc_compute_dsc_parameters(const struct drm_dsc_config *pps, struct dsc_parameters *dsc_params)
0099 {
0100     int              ret;
0101     struct rc_params rc;
0102     struct drm_dsc_config   dsc_cfg;
0103     unsigned long long tmp;
0104 
0105     calc_rc_params(&rc, pps);
0106     dsc_params->pps = *pps;
0107     dsc_params->pps.initial_scale_value = 8 * rc.rc_model_size / (rc.rc_model_size - rc.initial_fullness_offset);
0108 
0109     copy_pps_fields(&dsc_cfg, &dsc_params->pps);
0110     copy_rc_to_cfg(&dsc_cfg, &rc);
0111 
0112     dsc_cfg.mux_word_size = dsc_params->pps.bits_per_component <= 10 ? 48 : 64;
0113 
0114     ret = drm_dsc_compute_rc_parameters(&dsc_cfg);
0115     tmp = (unsigned long long)dsc_cfg.slice_chunk_size * 0x10000000 + (dsc_cfg.slice_width - 1);
0116     do_div(tmp, (uint32_t)dsc_cfg.slice_width);  //ROUND-UP
0117     dsc_params->bytes_per_pixel = (uint32_t)tmp;
0118 
0119     copy_pps_fields(&dsc_params->pps, &dsc_cfg);
0120     dsc_params->rc_buffer_model_size = dsc_cfg.rc_bits;
0121     return ret;
0122 }
0123