frontend/va: Support QVBR rate control mode
authorSil Vilerino <sivileri@microsoft.com>
Sat, 15 Apr 2023 19:43:34 +0000 (15:43 -0400)
committerMarge Bot <emma+marge@anholt.net>
Mon, 17 Apr 2023 21:58:35 +0000 (21:58 +0000)
Reviewed-by: Boyuan Zhang <Boyuan.Zhang@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22530>

src/gallium/frontends/va/config.c
src/gallium/frontends/va/picture_h264_enc.c
src/gallium/frontends/va/picture_hevc_enc.c
src/gallium/include/pipe/p_video_enums.h
src/gallium/include/pipe/p_video_state.h

index d7b31ed..1b3a487 100644 (file)
@@ -213,8 +213,17 @@ vlVaGetConfigAttributes(VADriverContextP ctx, VAProfile profile, VAEntrypoint en
                                                        PIPE_VIDEO_ENTRYPOINT_ENCODE);
             break;
          case VAConfigAttribRateControl:
+         {
+            /* Legacy behavior reports these three modes for all drivers */
             value = VA_RC_CQP | VA_RC_CBR | VA_RC_VBR;
-            break;
+
+            /* Check for optional mode QVBR */
+            int supports_qvbr = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
+                                             PIPE_VIDEO_ENTRYPOINT_ENCODE,
+                                             PIPE_VIDEO_CAP_ENC_RATE_CONTROL_QVBR);
+            if (supports_qvbr > 0)
+               value |= VA_RC_QVBR;
+         } break;
          case VAConfigAttribEncRateControlExt:
             value = pscreen->get_video_param(pscreen, ProfileToPipe(profile),
                                              PIPE_VIDEO_ENTRYPOINT_ENCODE,
@@ -524,6 +533,8 @@ vlVaCreateConfig(VADriverContextP ctx, VAProfile profile, VAEntrypoint entrypoin
             config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE;
          else if (attrib_list[i].value == VA_RC_CQP)
             config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_DISABLE;
+         else if (attrib_list[i].value == VA_RC_QVBR)
+            config->rc = PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE;
          else {
             FREE(config);
             return VA_STATUS_ERROR_INVALID_VALUE;
index 0cdb6a6..0ba2baf 100644 (file)
@@ -269,6 +269,11 @@ vlVaHandleVAEncMiscParameterTypeRateControlH264(vlVaContext *context, VAEncMiscP
    context->desc.h264enc.rate_ctrl[temporal_id].max_qp = rc->max_qp;
    context->desc.h264enc.rate_ctrl[temporal_id].min_qp = rc->min_qp;
 
+   if (context->desc.h264enc.rate_ctrl[0].rate_ctrl_method ==
+       PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE)
+      context->desc.h264enc.rate_ctrl[temporal_id].vbr_quality_factor =
+         rc->quality_factor;
+
    return VA_STATUS_SUCCESS;
 }
 
index 4a9aa59..14013a6 100644 (file)
@@ -240,6 +240,11 @@ vlVaHandleVAEncMiscParameterTypeRateControlHEVC(vlVaContext *context, VAEncMiscP
    context->desc.h265enc.rc.max_qp = rc->max_qp;
    context->desc.h265enc.rc.min_qp = rc->min_qp;
 
+   if (context->desc.h265enc.rc.rate_ctrl_method ==
+       PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE)
+      context->desc.h265enc.rc.vbr_quality_factor =
+         rc->quality_factor;
+
    return VA_STATUS_SUCCESS;
 }
 
index a55a79b..c547f92 100644 (file)
@@ -131,7 +131,8 @@ enum pipe_video_cap
    PIPE_VIDEO_CAP_ENC_SUPPORTS_ASYNC_OPERATION = 33,
 
    PIPE_VIDEO_CAP_MIN_WIDTH = 34,
-   PIPE_VIDEO_CAP_MIN_HEIGHT = 35
+   PIPE_VIDEO_CAP_MIN_HEIGHT = 35,
+   PIPE_VIDEO_CAP_ENC_RATE_CONTROL_QVBR = 36
 };
 
 /* To be used with PIPE_VIDEO_CAP_VPP_ORIENTATION_MODES and for VPP state*/
index d203844..f06e88d 100644 (file)
@@ -143,7 +143,8 @@ enum pipe_h2645_enc_rate_control_method
    PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT_SKIP = 0x01,
    PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE_SKIP = 0x02,
    PIPE_H2645_ENC_RATE_CONTROL_METHOD_CONSTANT = 0x03,
-   PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE = 0x04
+   PIPE_H2645_ENC_RATE_CONTROL_METHOD_VARIABLE = 0x04,
+   PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE = 0x05
 };
 
 enum pipe_slice_buffer_placement_type
@@ -417,6 +418,9 @@ struct pipe_h264_enc_rate_control
    unsigned max_au_size;
    unsigned max_qp;
    unsigned min_qp;
+
+   /* Used with PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE */
+   unsigned vbr_quality_factor;
 };
 
 struct pipe_h264_enc_motion_estimation
@@ -617,6 +621,9 @@ struct pipe_h265_enc_rate_control
    unsigned max_au_size;
    unsigned max_qp;
    unsigned min_qp;
+
+   /* Used with PIPE_H2645_ENC_RATE_CONTROL_METHOD_QUALITY_VARIABLE */
+   unsigned vbr_quality_factor;
 };
 
 struct pipe_h265_enc_picture_desc