<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 10, 2017 at 4:21 PM, Mark Thompson <span dir="ltr"><<a href="mailto:sw@jkqxz.net" target="_blank">sw@jkqxz.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">On 10/01/17 22:02, Sean V Kelley wrote:<br>
> From: "Xiang, Haihao" <<a href="mailto:haihao.xiang@intel.com">haihao.xiang@intel.com</a>><br>
><br>
> Currently only one temporal layer is supported<br>
><br>
> Signed-off-by: Xiang, Haihao <<a href="mailto:haihao.xiang@intel.com">haihao.xiang@intel.com</a>><br>
> Reviewed-by: Sean V Kelley <<a href="mailto:seanvk@posteo.de">seanvk@posteo.de</a>><br>
> ---<br>
>  src/Makefile.am        |    3 +<br>
>  src/gen8_encoder_vp8.c |  140 +<br>
>  src/gen8_mfc.c         |    8 +-<br>
>  src/gen8_vme.c         |    5 +<br>
>  src/i965_defines.h     |   10 +<br>
>  src/i965_encoder.c     |    2 +<br>
>  src/i965_encoder_vp8.c | 6697 ++++++++++++++++++++++++++++++<wbr>++++++++++++++++++<br>
>  src/i965_encoder_vp8.h | 2643 +++++++++++++++++++<br>
>  8 files changed, 9507 insertions(+), 1 deletion(-)<br>
<br>
I had a go with this on Kaby Lake.  In general, big win - looks like it can be under half the bitrate at comparable quality (though it was pretty terrible before...).<br>
<br>
However, the rate control seems to do odd things at low bitrate relative to the frame size?  I can get GPU hangs and wildly varying output bitrate with it, though it seems ok at high bitrate.<br></blockquote><div><br></div><div>That's a concern.  Please report the <span style="font-size:12.800000190734863px">If it really is a</span><span style="font-size:12.800000190734863px"> </span><span class="gmail-il" style="font-size:12.800000190734863px">GPU</span><span style="font-size:12.800000190734863px"> </span><span class="gmail-il" style="font-size:12.800000190734863px">hang</span><span style="font-size:12.800000190734863px">, I need the</span><span style="font-size:12.800000190734863px"> </span><span class="gmail-il" style="font-size:12.800000190734863px">error</span><span style="font-size:12.800000190734863px"> </span><span style="font-size:12.800000190734863px">report for the DRM card0 log.</span></div><div><span style="font-size:12.800000190734863px"><br></span></div><div><span style="font-size:12.800000190734863px">cat /sys/class/drm/card0/error</span></div><div class="gmail_extra" style="font-size:12.800000190734863px"><br></div><div class="gmail_extra" style="font-size:12.800000190734863px">Please rerun and capture the DRM (i915) card0 <span class="gmail-il">error</span> log.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
I had a look around the rate control and found two minor issues in the RC configuration, though I don't think either of them are relevant to my problem (see below).  I can try to make a reproducer if this is not already known?<br>
<br></blockquote><div>Please do attempt to reproduce.  That's why I've put the patches out here to test.</div><div><br></div><div>Thanks,</div><div><br></div><div>Sean</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Thanks,<br>
<br>
- Mark<br>
<br>
<br>
> ...<br>
> +<br>
> +static void<br>
> +i965_encoder_vp8_get_misc_<wbr>parameters(VADriverContextP ctx,<br>
> +                                     struct encode_state *encode_state,<br>
> +                                     struct intel_encoder_context *encoder_context)<br>
> +{<br>
> +    struct i965_encoder_vp8_context *vp8_context = encoder_context->vme_context;<br>
> +<br>
> +    if (vp8_context->internal_rate_<wbr>mode == I965_BRC_CQP) {<br>
> +        vp8_context->init_vbv_buffer_<wbr>fullness_in_bit = 0;<br>
> +        vp8_context->vbv_buffer_size_<wbr>in_bit = 0;<br>
> +        vp8_context->target_bit_rate = 0;<br>
> +        vp8_context->max_bit_rate = 0;<br>
> +        vp8_context->min_bit_rate = 0;<br>
> +        vp8_context->brc_need_reset = 0;<br>
> +    } else {<br>
> +        vp8_context->gop_size = encoder_context->brc.gop_size;<br>
> +<br>
> +        if (encoder_context->brc.need_<wbr>reset) {<br>
> +            vp8_context->framerate = encoder_context->brc.<wbr>framerate[0];<br>
> +            vp8_context->vbv_buffer_size_<wbr>in_bit = encoder_context->brc.hrd_<wbr>buffer_size;<br>
> +            vp8_context->init_vbv_buffer_<wbr>fullness_in_bit = encoder_context->brc.hrd_<wbr>initial_buffer_fullness;<br>
> +            vp8_context->max_bit_rate = encoder_context->brc.bits_per_<wbr>second[0]; // currently only one layer is supported<br>
> +            vp8_context->brc_need_reset = (vp8_context->brc_initted && encoder_context->brc.need_<wbr>reset);<br>
> +<br>
> +            if (vp8_context->internal_rate_<wbr>mode == I965_BRC_CBR) {<br>
> +                vp8_context->min_bit_rate = vp8_context->max_bit_rate;<br>
> +                vp8_context->target_bit_rate = vp8_context->max_bit_rate;<br>
> +            } else {<br>
> +                assert(vp8_context->internal_<wbr>rate_mode == I965_BRC_VBR);<br>
> +                vp8_context->min_bit_rate = vp8_context->max_bit_rate * (2 * encoder_context->brc.target_<wbr>percentage[0] - 100) / 100;<br>
<br>
If target percentage is < 50 then (2 * encoder_context->brc.target_<wbr>percentage[0] - 100) is negative.  Since it's unsigned, you end up with a garbage number in min_bit_rate.<br></blockquote><div><br></div><div>That's a concern, also we may need to reconcile this with our handling for VP9 encode.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
> +                vp8_context->target_bit_rate = vp8_context->max_bit_rate * encoder_context->brc.target_<wbr>percentage[0] / 100;<br>
> +            }<br>
> +        }<br>
> +    }<br>
> +<br>
> +    if (encoder_context->quality_<wbr>level == ENCODER_LOW_QUALITY)<br>
> +        vp8_context->hme_16x_supported = 0;<br>
> +}<br>
> +<br>
> ...<br>
> +<br>
> +static void<br>
> +i965_encoder_vp8_vme_brc_<wbr>init_reset_set_curbe(<wbr>VADriverContextP ctx,<br>
> +                                              struct encode_state *encode_state,<br>
> +                                              struct intel_encoder_context *encoder_context,<br>
> +                                              struct i965_gpe_context *gpe_context)<br>
> +{<br>
> +    struct i965_encoder_vp8_context *vp8_context = encoder_context->vme_context;<br>
> +    VAEncPictureParameterBufferVP8 *pic_param = (<wbr>VAEncPictureParameterBufferVP8 *)encode_state->pic_param_ext-<wbr>>buffer;<br>
> +    struct vp8_brc_init_reset_curbe_data *pcmd = i965_gpe_context_map_curbe(<wbr>gpe_context);<br>
> +    double input_bits_per_frame, bps_ratio;<br>
> +<br>
> +    memset(pcmd, 0, sizeof(*pcmd));<br>
> +<br>
> +    pcmd->dw0.profile_level_max_<wbr>frame = vp8_context->frame_width * vp8_context->frame_height;<br>
> +    pcmd->dw1.init_buf_full_in_<wbr>bits = vp8_context->init_vbv_buffer_<wbr>fullness_in_bit;<br>
> +    pcmd->dw2.buf_size_in_bits = vp8_context->vbv_buffer_size_<wbr>in_bit;<br>
> +    pcmd->dw3.average_bitrate = ALIGN(vp8_context->target_bit_<wbr>rate, VP8_BRC_KBPS) / VP8_BRC_KBPS * VP8_BRC_KBPS;<br>
> +    pcmd->dw4.max_bitrate = ALIGN(vp8_context->max_bit_<wbr>rate, VP8_BRC_KBPS) / VP8_BRC_KBPS * VP8_BRC_KBPS;<br>
<br>
VP8_BRC_KBPS is 1000 which is not a power of two, so the ALIGN macro isn't doing anything sensible here.<br></blockquote><div><br></div><div>Agree...</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
> +    pcmd->dw6.frame_rate_m = vp8_context->framerate.num;<br>
> +    pcmd->dw7.frame_rate_d = vp8_context->framerate.den;<br>
> +    pcmd->dw8.brc_flag = 0;<br>
> +    pcmd->dw8.gop_minus1 = vp8_context->gop_size - 1;<br>
> +<br>
> +    if (vp8_context->internal_rate_<wbr>mode == I965_BRC_CBR) {<br>
> +        pcmd->dw4.max_bitrate = pcmd->dw3.average_bitrate;<br>
> +<br>
> +        pcmd->dw8.brc_flag = pcmd->dw8.brc_flag | BRC_KERNEL_CBR;<br>
> +    } else if (vp8_context->internal_rate_<wbr>mode == I965_BRC_VBR) {<br>
> +        if (pcmd->dw4.max_bitrate < pcmd->dw3.average_bitrate) {<br>
> +            pcmd->dw4.max_bitrate = 2 * pcmd->dw3.average_bitrate;<br>
> +        }<br>
> +<br>
> +        pcmd->dw8.brc_flag = pcmd->dw8.brc_flag | BRC_KERNEL_VBR;<br>
> +    }<br>
> +<br>
> +    input_bits_per_frame =<br>
> +        ((double)(pcmd->dw4.max_<wbr>bitrate) * (double)(pcmd->dw7.frame_rate_<wbr>d) /<br>
> +         (double)(pcmd->dw6.frame_rate_<wbr>m));<br>
> +<br>
> +    if (pcmd->dw2.buf_size_in_bits < (unsigned int)input_bits_per_frame * 4) {<br>
> +        pcmd->dw2.buf_size_in_bits = (unsigned int)input_bits_per_frame * 4;<br>
> +    }<br>
> +<br>
> +    if (pcmd->dw1.init_buf_full_in_<wbr>bits == 0) {<br>
> +        pcmd->dw1.init_buf_full_in_<wbr>bits = 7 * pcmd->dw2.buf_size_in_bits / 8;<br>
> +    }<br>
> +<br>
> +    if (pcmd->dw1.init_buf_full_in_<wbr>bits < (unsigned int)(input_bits_per_frame * 2)) {<br>
> +        pcmd->dw1.init_buf_full_in_<wbr>bits = (unsigned int)(input_bits_per_frame * 2);<br>
> +    }<br>
> +<br>
> +    if (pcmd->dw1.init_buf_full_in_<wbr>bits > pcmd->dw2.buf_size_in_bits) {<br>
> +        pcmd->dw1.init_buf_full_in_<wbr>bits = pcmd->dw2.buf_size_in_bits;<br>
> +    }<br>
> +<br>
> +    bps_ratio = input_bits_per_frame / ((double)(pcmd->dw2.buf_size_<wbr>in_bits) / 30);<br>
> +    bps_ratio = (bps_ratio < 0.1) ? 0.1 : (bps_ratio > 3.5) ? 3.5 : bps_ratio;<br>
> +<br>
> +    pcmd->dw9.frame_width_in_bytes = vp8_context->frame_width;<br>
> +    pcmd->dw10.frame_height_in_<wbr>bytes = vp8_context->frame_height;<br>
> +    pcmd->dw10.avbr_accuracy = 30;<br>
> +    pcmd->dw11.avbr_convergence = 150;<br>
> +    pcmd->dw11.min_qp = pic_param->clamp_qindex_low;<br>
> +    pcmd->dw12.max_qp = pic_param->clamp_qindex_high;<br>
> +    pcmd->dw12.level_qp = 60;<br>
> +<br>
> +    // DW13 default 100<br>
> +    pcmd->dw13.max_section_pct = 100;<br>
> +    pcmd->dw13.under_shoot_cbr_pct = 115;<br>
> +<br>
> +    // DW14 default 100<br>
> +    pcmd->dw14.min_section_pct = 100;<br>
> +    pcmd->dw14.vbr_bias_pct = 100;<br>
> +    pcmd->dw15.instant_rate_<wbr>threshold_0_for_p = 30;<br>
> +    pcmd->dw15.instant_rate_<wbr>threshold_1_for_p = 50;<br>
> +    pcmd->dw15.instant_rate_<wbr>threshold_2_for_p = 70;<br>
> +    pcmd->dw15.instant_rate_<wbr>threshold_3_for_p = 120;<br>
> +<br>
> +    pcmd->dw17.instant_rate_<wbr>threshold_0_for_i = 30;<br>
> +    pcmd->dw17.instant_rate_<wbr>threshold_1_for_i = 50;<br>
> +    pcmd->dw17.instant_rate_<wbr>threshold_2_for_i = 90;<br>
> +    pcmd->dw17.instant_rate_<wbr>threshold_3_for_i = 115;<br>
> +    pcmd->dw18.deviation_<wbr>threshold_0_for_p = (unsigned int)(-50 * pow(0.9, bps_ratio));<br>
> +    pcmd->dw18.deviation_<wbr>threshold_1_for_p = (unsigned int)(-50 * pow(0.66, bps_ratio));<br>
> +    pcmd->dw18.deviation_<wbr>threshold_2_for_p = (unsigned int)(-50 * pow(0.46, bps_ratio));<br>
> +    pcmd->dw18.deviation_<wbr>threshold_3_for_p = (unsigned int)(-50 * pow(0.3, bps_ratio));<br>
> +    pcmd->dw19.deviation_<wbr>threshold_4_for_p = (unsigned int)(50 * pow(0.3, bps_ratio));<br>
> +    pcmd->dw19.deviation_<wbr>threshold_5_for_p = (unsigned int)(50 * pow(0.46, bps_ratio));<br>
> +    pcmd->dw19.deviation_<wbr>threshold_6_for_p = (unsigned int)(50 * pow(0.7, bps_ratio));<br>
> +    pcmd->dw19.deviation_<wbr>threshold_7_for_p = (unsigned int)(50 * pow(0.9, bps_ratio));<br>
> +    pcmd->dw20.deviation_<wbr>threshold_0_for_vbr = (unsigned int)(-50 * pow(0.9, bps_ratio));<br>
> +    pcmd->dw20.deviation_<wbr>threshold_1_for_vbr = (unsigned int)(-50 * pow(0.7, bps_ratio));<br>
> +    pcmd->dw20.deviation_<wbr>threshold_2_for_vbr = (unsigned int)(-50 * pow(0.5, bps_ratio));<br>
> +    pcmd->dw20.deviation_<wbr>threshold_3_for_vbr = (unsigned int)(-50 * pow(0.3, bps_ratio));<br>
> +    pcmd->dw21.deviation_<wbr>threshold_4_for_vbr = (unsigned int)(100 * pow(0.4, bps_ratio));<br>
> +    pcmd->dw21.deviation_<wbr>threshold_5_for_vbr = (unsigned int)(100 * pow(0.5, bps_ratio));<br>
> +    pcmd->dw21.deviation_<wbr>threshold_6_for_vbr = (unsigned int)(100 * pow(0.75, bps_ratio));<br>
> +    pcmd->dw21.deviation_<wbr>threshold_7_for_vbr = (unsigned int)(100 * pow(0.9, bps_ratio));<br>
> +    pcmd->dw22.deviation_<wbr>threshold_0_for_i = (unsigned int)(-50 * pow(0.8, bps_ratio));<br>
> +    pcmd->dw22.deviation_<wbr>threshold_1_for_i = (unsigned int)(-50 * pow(0.6, bps_ratio));<br>
> +    pcmd->dw22.deviation_<wbr>threshold_2_for_i = (unsigned int)(-50 * pow(0.34, bps_ratio));<br>
> +    pcmd->dw22.deviation_<wbr>threshold_3_for_i = (unsigned int)(-50 * pow(0.2, bps_ratio));<br>
> +    pcmd->dw23.deviation_<wbr>threshold_4_for_i = (unsigned int)(50 * pow(0.2, bps_ratio));<br>
> +    pcmd->dw23.deviation_<wbr>threshold_5_for_i = (unsigned int)(50 * pow(0.4, bps_ratio));<br>
> +    pcmd->dw23.deviation_<wbr>threshold_6_for_i = (unsigned int)(50 * pow(0.66, bps_ratio));<br>
> +    pcmd->dw23.deviation_<wbr>threshold_7_for_i = (unsigned int)(50 * pow(0.9, bps_ratio));<br>
> +<br>
> +    // Default: 1<br>
> +    pcmd->dw24.num_t_levels = 1;<br>
> +<br>
> +    if (!vp8_context->brc_initted) {<br>
> +        vp8_context->brc_init_current_<wbr>target_buf_full_in_bits = pcmd->dw1.init_buf_full_in_<wbr>bits;<br>
> +    }<br>
> +<br>
> +    vp8_context->brc_init_reset_<wbr>buf_size_in_bits = pcmd->dw2.buf_size_in_bits;<br>
> +    vp8_context->brc_init_reset_<wbr>input_bits_per_frame = input_bits_per_frame;<br>
> +<br>
> +    pcmd->dw26.history_buffer_bti = VP8_BTI_BRC_INIT_RESET_<wbr>HISTORY;<br>
> +    pcmd->dw27.distortion_buffer_<wbr>bti = VP8_BTI_BRC_INIT_RESET_<wbr>DISTORTION;<br>
> +<br>
> +    i965_gpe_context_unmap_curbe(<wbr>gpe_context);<br>
> +}<br>
> +<br>
> ...<br>
______________________________<wbr>_________________<br>
Libva mailing list<br>
<a href="mailto:Libva@lists.freedesktop.org">Libva@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/libva" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/libva</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">Sean V. Kelley <<a href="mailto:sean.v.kelley@intel.com" target="_blank">sean.v.kelley@intel.com</a>><br>Open Source Technology Center / SSG<br>Intel Corp.<br></div>
</div></div>