/* * Copyright 2019 Advanced Micro Devices, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Author: AMD
*/
/* Need to account for padding due to pixel-to-symbol packing * for uncompressed 128b/132b streams.
*/ static uint32_t apply_128b_132b_stream_overhead( conststruct dc_crtc_timing *timing, const uint32_t kbps)
{
uint32_t total_kbps = kbps;
if (disable_128b_132b_stream_overhead) return kbps;
if (!timing->flags.DSC) { struct fixed31_32 bpp; struct fixed31_32 overhead_factor;
if (!dsc_bpp_increment_div_from_dpcd(dpcd_dsc_basic_data[DP_DSC_BITS_PER_PIXEL_INC - DP_DSC_SUPPORT],
&dsc_sink_caps->bpp_increment_div)) returnfalse;
if (dc->debug.dsc_bpp_increment_div) { /* dsc_bpp_increment_div should onl be 1, 2, 4, 8 or 16, but rather than rejecting invalid values, * we'll accept all and get it into range. This also makes the above check against 0 redundant, * but that one stresses out the override will be only used if it's not 0.
*/ if (dc->debug.dsc_bpp_increment_div >= 1)
dsc_sink_caps->bpp_increment_div = 1; if (dc->debug.dsc_bpp_increment_div >= 2)
dsc_sink_caps->bpp_increment_div = 2; if (dc->debug.dsc_bpp_increment_div >= 4)
dsc_sink_caps->bpp_increment_div = 4; if (dc->debug.dsc_bpp_increment_div >= 8)
dsc_sink_caps->bpp_increment_div = 8; if (dc->debug.dsc_bpp_increment_div >= 16)
dsc_sink_caps->bpp_increment_div = 16;
}
/* Extended caps */ if (dpcd_dsc_branch_decoder_caps == NULL) { // branch decoder DPCD DSC data can be null for non branch device
dsc_sink_caps->branch_overall_throughput_0_mps = 0;
dsc_sink_caps->branch_overall_throughput_1_mps = 0;
dsc_sink_caps->branch_max_line_width = 0; returntrue;
}
/* expand per DSC capabilities to global */
max_odm_combine_factor = dc->caps.max_odm_combine_factor;
num_dsc = dc->res_pool->res_cap->num_dsc;
max_odm_combine_factor = min(max_odm_combine_factor, num_dsc);
dsc_enc_caps->max_total_throughput_mps =
single_dsc_enc_caps.max_total_throughput_mps *
max_odm_combine_factor;
/* check slice counts possible for with ODM combine */
build_dsc_enc_combined_slice_caps(&single_dsc_enc_caps, dsc_enc_caps, max_odm_combine_factor);
}
/* get max pixel rate and combine caps */
max_dispclk_khz = dsc_enc_caps->max_total_throughput_mps * 1000; if (dsc && dsc->ctx->dc) { if (dsc->ctx->dc->clk_mgr &&
dsc->ctx->dc->clk_mgr->funcs->get_max_clock_khz) { /* dispclk is available */
max_dispclk_khz = dsc->ctx->dc->clk_mgr->funcs->get_max_clock_khz(dsc->ctx->dc->clk_mgr, CLK_TYPE_DISPCLK);
}
}
if (!dsc || !dsc->ctx || !dsc->ctx->dc || dsc->ctx->dc->debug.disable_dsc) return;
/* check if reported cap global or only for a single DCN DSC enc */ if (dsc->funcs->dsc_get_enc_caps) {
dsc->funcs->dsc_get_enc_caps(dsc_enc_caps, pixel_clock_100Hz);
} else {
build_dsc_enc_caps(dsc, dsc_enc_caps);
}
if (dsc->ctx->dc->debug.native422_support)
dsc_enc_caps->color_formats.bits.YCBCR_NATIVE_422 = 1;
}
/* Returns 'false' if no intersection was found for at least one capability. * It also implicitly validates some sink caps against invalid value of zero.
*/ staticbool intersect_dsc_caps( conststruct dsc_dec_dpcd_caps *dsc_sink_caps, conststruct dsc_enc_caps *dsc_enc_caps, enum dc_pixel_encoding pixel_encoding, struct dsc_enc_caps *dsc_common_caps)
{
int32_t max_slices;
int32_t total_sink_throughput;
// TODO DSC: Remove this workaround for N422 and 420 once it's fixed, or move it to get_dsc_encoder_caps() if (pixel_encoding == PIXEL_ENCODING_YCBCR422 || pixel_encoding == PIXEL_ENCODING_YCBCR420)
dsc_common_caps->bpp_increment_div = min(dsc_common_caps->bpp_increment_div, (uint32_t)8);
/* Decide DSC bandwidth range based on signal, timing, specs specific and input min and max * requirements. * The range output includes decided min/max target bpp, the respective bandwidth requirements * and native timing bandwidth requirement when DSC is not used.
*/ staticbool decide_dsc_bandwidth_range( const uint32_t min_bpp_x16, const uint32_t max_bpp_x16, const uint32_t num_slices_h, conststruct dsc_enc_caps *dsc_caps, conststruct dc_crtc_timing *timing, constenum dc_link_encoding_format link_encoding, struct dc_dsc_bw_range *range)
{
uint32_t preferred_bpp_x16 = timing->dsc_fixed_bits_per_pixel_x16;
memset(range, 0, sizeof(*range));
/* apply signal, timing, specs and explicitly specified DSC range requirements */ if (preferred_bpp_x16) { if (preferred_bpp_x16 <= max_bpp_x16 &&
preferred_bpp_x16 >= min_bpp_x16) {
range->max_target_bpp_x16 = preferred_bpp_x16;
range->min_target_bpp_x16 = preferred_bpp_x16;
}
} /* TODO - make this value generic to all signal types */ elseif (dsc_caps->edp_sink_max_bits_per_pixel) { /* apply max bpp limitation from edp sink */
range->max_target_bpp_x16 = MIN(dsc_caps->edp_sink_max_bits_per_pixel,
max_bpp_x16);
range->min_target_bpp_x16 = min_bpp_x16;
} else {
range->max_target_bpp_x16 = max_bpp_x16;
range->min_target_bpp_x16 = min_bpp_x16;
}
/* Decides if DSC should be used and calculates target bpp if it should, applying DSC policy. * * Returns: * - 'true' if target bpp is decided * - 'false' if target bpp cannot be decided (e.g. cannot fit even with min DSC bpp),
*/ staticbool decide_dsc_target_bpp_x16( conststruct dc_dsc_policy *policy, conststruct dc_dsc_config_options *options, conststruct dsc_enc_caps *dsc_common_caps, constint target_bandwidth_kbps, conststruct dc_crtc_timing *timing, constint num_slices_h, constenum dc_link_encoding_format link_encoding, int *target_bpp_x16)
{ struct dc_dsc_bw_range range;
*target_bpp_x16 = 0;
if (decide_dsc_bandwidth_range(policy->min_target_bpp * 16, policy->max_target_bpp * 16,
num_slices_h, dsc_common_caps, timing, link_encoding, &range)) { if (target_bandwidth_kbps >= range.stream_kbps) { if (policy->enable_dsc_when_not_needed || options->force_dsc_when_not_needed) /* enable max bpp even dsc is not needed */
*target_bpp_x16 = range.max_target_bpp_x16;
} elseif (target_bandwidth_kbps >= range.max_kbps) { /* use max target bpp allowed */
*target_bpp_x16 = range.max_target_bpp_x16;
} elseif (target_bandwidth_kbps >= range.min_kbps) { /* use target bpp that can take entire target bandwidth */
*target_bpp_x16 = compute_bpp_x16_from_target_bandwidth(
target_bandwidth_kbps, timing, num_slices_h,
dsc_common_caps->bpp_increment_div,
dsc_common_caps->is_dp);
}
}
return *target_bpp_x16 != 0;
}
#define MIN_AVAILABLE_SLICES_SIZE 6
staticint get_available_dsc_slices(union dsc_enc_slice_caps slice_caps, int *available_slices)
{ int idx = 0;
if (slice_caps.bits.NUM_SLICES_1)
available_slices[idx++] = 1;
if (slice_caps.bits.NUM_SLICES_2)
available_slices[idx++] = 2;
if (slice_caps.bits.NUM_SLICES_4)
available_slices[idx++] = 4;
if (slice_caps.bits.NUM_SLICES_8)
available_slices[idx++] = 8;
if (slice_caps.bits.NUM_SLICES_12)
available_slices[idx++] = 12;
if (slice_caps.bits.NUM_SLICES_16)
available_slices[idx++] = 16;
return idx;
}
staticint get_max_dsc_slices(union dsc_enc_slice_caps slice_caps)
{ int max_slices = 0; int available_slices[MIN_AVAILABLE_SLICES_SIZE]; int end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]);
if (end_idx > 0)
max_slices = available_slices[end_idx - 1];
return max_slices;
}
// Increment slice number in available slice numbers stops if possible, or just increment if not staticint inc_num_slices(union dsc_enc_slice_caps slice_caps, int num_slices)
{ // Get next bigger num slices available in common caps int available_slices[MIN_AVAILABLE_SLICES_SIZE]; int end_idx; int i; int new_num_slices = num_slices;
end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]); if (end_idx == 0) { // No available slices found
new_num_slices++; return new_num_slices;
}
// Numbers of slices found - get the next bigger number for (i = 0; i < end_idx; i++) { if (new_num_slices < available_slices[i]) {
new_num_slices = available_slices[i]; break;
}
}
if (new_num_slices == num_slices) // No bigger number of slices found
new_num_slices++;
return new_num_slices;
}
// Decrement slice number in available slice numbers stops if possible, or just decrement if not. Stop at zero. staticint dec_num_slices(union dsc_enc_slice_caps slice_caps, int num_slices)
{ // Get next bigger num slices available in common caps int available_slices[MIN_AVAILABLE_SLICES_SIZE]; int end_idx; int i; int new_num_slices = num_slices;
end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]); if (end_idx == 0 && new_num_slices > 0) { // No numbers of slices found
new_num_slices++; return new_num_slices;
}
// Numbers of slices found - get the next smaller number for (i = end_idx - 1; i >= 0; i--) { if (new_num_slices > available_slices[i]) {
new_num_slices = available_slices[i]; break;
}
}
if (new_num_slices == num_slices) { // No smaller number of slices found
new_num_slices--; if (new_num_slices < 0)
new_num_slices = 0;
}
return new_num_slices;
}
// Choose next bigger number of slices if the requested number of slices is not available staticint fit_num_slices_up(union dsc_enc_slice_caps slice_caps, int num_slices)
{ // Get next bigger num slices available in common caps int available_slices[MIN_AVAILABLE_SLICES_SIZE]; int end_idx; int i; int new_num_slices = num_slices;
end_idx = get_available_dsc_slices(slice_caps, &available_slices[0]); if (end_idx == 0) { // No available slices found
new_num_slices++; return new_num_slices;
}
// Numbers of slices found - get the equal or next bigger number for (i = 0; i < end_idx; i++) { if (new_num_slices <= available_slices[i]) {
new_num_slices = available_slices[i]; break;
}
}
return new_num_slices;
}
/* Attempts to set DSC configuration for the stream, applying DSC policy. * Returns 'true' if successful or 'false' if not. * * Parameters: * * dsc_sink_caps - DSC sink decoder capabilities (from DPCD) * * dsc_enc_caps - DSC encoder capabilities * * target_bandwidth_kbps - Target bandwidth to fit the stream into. * If 0, do not calculate target bpp. * * timing - The stream timing to fit into 'target_bandwidth_kbps' or apply * maximum compression to, if 'target_badwidth == 0' * * dsc_cfg - DSC configuration to use if it was possible to come up with * one for the given inputs. * The target bitrate after DSC can be calculated by multiplying * dsc_cfg.bits_per_pixel (in U6.4 format) by pixel rate, e.g. * * dsc_stream_bitrate_kbps = (int)ceil(timing->pix_clk_khz * dsc_cfg.bits_per_pixel / 16.0);
*/ staticbool setup_dsc_config( conststruct dsc_dec_dpcd_caps *dsc_sink_caps, conststruct dsc_enc_caps *dsc_enc_caps, int target_bandwidth_kbps, conststruct dc_crtc_timing *timing, conststruct dc_dsc_config_options *options, constenum dc_link_encoding_format link_encoding, int min_slices_h, struct dc_dsc_config *dsc_cfg)
{ struct dsc_enc_caps dsc_common_caps; int max_slices_h = 0; int num_slices_h = 0; int pic_width; int slice_width; int target_bpp; int sink_per_slice_throughput_mps; int branch_max_throughput_mps = 0; bool is_dsc_possible = false; int pic_height; int slice_height; struct dc_dsc_policy policy;
if (policy.use_min_slices_h) { if (min_slices_h > 0)
num_slices_h = min_slices_h; elseif (max_slices_h > 0) { // Fall back to max slices if min slices is not working out if (policy.max_slices_h)
num_slices_h = min(policy.max_slices_h, max_slices_h); else
num_slices_h = max_slices_h;
} else
is_dsc_possible = false;
} else { if (max_slices_h > 0) { if (policy.max_slices_h)
num_slices_h = min(policy.max_slices_h, max_slices_h); else
num_slices_h = max_slices_h;
} elseif (min_slices_h > 0) // Fall back to min slices if max slices is not possible
num_slices_h = min_slices_h; else
is_dsc_possible = false;
} // When we force ODM, num dsc h slices must be divisible by num odm h slices switch (options->dsc_force_odm_hslice_override) { case 0: case 1: break; case 2: if (num_slices_h < 2)
num_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, 2); break; case 3: if (dsc_common_caps.slice_caps.bits.NUM_SLICES_12)
num_slices_h = 12; else
num_slices_h = 0; break; case 4: if (num_slices_h < 4)
num_slices_h = fit_num_slices_up(dsc_common_caps.slice_caps, 4); break; default: break;
} if (num_slices_h == 0)
is_dsc_possible = false; if (!is_dsc_possible) goto done;
is_dsc_possible = slice_width <= dsc_common_caps.max_slice_width; if (!is_dsc_possible) goto done;
// Slice height (i.e. number of slices per column): start with policy and pick the first one that height is divisible by. // For 4:2:0 make sure the slice height is divisible by 2 as well. if (options->dsc_min_slice_height_override == 0)
slice_height = min(policy.min_slice_height, pic_height); else
slice_height = min((int)(options->dsc_min_slice_height_override), pic_height);
if (timing->pixel_encoding == PIXEL_ENCODING_YCBCR420) // For the case when pic_height < dsc_policy.min_sice_height
is_dsc_possible = (slice_height % 2 == 0);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.