Re: [Libva] [PATCH v1 8/9] ENC: add MFX pipeline for AVC encoder

2017-01-18 Thread Qu, Pengfei


-Original Message-
From: Zhao, Yakui 
Sent: Tuesday, January 17, 2017 10:47 AM
To: Qu, Pengfei 
Cc: libva@lists.freedesktop.org
Subject: Re: [Libva] [PATCH v1 8/9] ENC: add MFX pipeline for AVC encoder

On 01/13/2017 05:24 PM, Pengfei Qu wrote:
> MFX pipeline:
> add MFX command for AVC encoder
> add MFX Picture slice level command init for AVC
> add MFX pipeline init prepare run for AVC encode
> add VME/MFX context init for AVC encoder
>

Please see the inline comment.

> Reviewed-by: Sean V Kelley
> Signed-off-by: Pengfei Qu
> ---
>   src/gen9_avc_encoder.c | 1887 
> +++-
>   1 file changed, 1886 insertions(+), 1 deletion(-)
>
> diff --git a/src/gen9_avc_encoder.c b/src/gen9_avc_encoder.c
> index 5caa9f4..a7545f1 100755
> --- a/src/gen9_avc_encoder.c
> +++ b/src/gen9_avc_encoder.c
> @@ -5742,4 +5742,1889 @@ gen9_avc_kernel_init(VADriverContextP ctx,
>   generic_ctx->pfn_send_brc_mb_update_surface = 
> gen9_avc_send_surface_brc_mb_update;
>   generic_ctx->pfn_send_sfd_surface = gen9_avc_send_surface_sfd;
>   generic_ctx->pfn_send_wp_surface = gen9_avc_send_surface_wp;
> -}
> \ No newline at end of file
> +}
> +
> +/*
> +PAK pipeline related function
> +*/
> +extern int
> +intel_avc_enc_slice_type_fixup(int slice_type);
> +
> +static void
> +gen9_mfc_avc_pipe_mode_select(VADriverContextP ctx,
> +  struct encode_state *encode_state,
> +  struct intel_encoder_context *encoder_context)
> +{
> +struct encoder_vme_mfc_context * pak_context = (struct 
> encoder_vme_mfc_context *)encoder_context->vme_context;
> +struct gen9_avc_encoder_context * avc_ctx = (struct 
> gen9_avc_encoder_context * )pak_context->private_enc_ctx;
> +struct generic_enc_codec_state * generic_state = (struct 
> generic_enc_codec_state * )pak_context->generic_enc_state;
> +struct intel_batchbuffer *batch = encoder_context->base.batch;
> +
> +BEGIN_BCS_BATCH(batch, 5);
> +
> +OUT_BCS_BATCH(batch, MFX_PIPE_MODE_SELECT | (5 - 2));
> +OUT_BCS_BATCH(batch,
> +  (0<<  29) |
> +  (MFX_LONG_MODE<<  17) |   /* Must be long format for 
> encoder */
> +  (MFD_MODE_VLD<<  15) |
> +  (0<<  13) |   /* VDEnc mode  is 1*/
> +  ((generic_state->curr_pak_pass != 
> (generic_state->num_pak_passes -1))<<  10) |   /* Stream-Out 
> Enable */
> +  ((!!avc_ctx->res_post_deblocking_output.bo)<<  9)  |/* 
> Post Deblocking Output */
> +  ((!!avc_ctx->res_pre_deblocking_output.bo)<<  8)  | /* 
> Pre Deblocking Output */
> +  (0<<  7)  |   /* Scaled surface enable */
> +  (0<<  6)  |   /* Frame statistics stream 
> out enable, always '1' in VDEnc mode */
> +  (0<<  5)  |   /* not in stitch mode */
> +  (1<<  4)  |   /* encoding mode */
> +  (MFX_FORMAT_AVC<<  0));
> +OUT_BCS_BATCH(batch,
> +  (0<<  7)  | /* expand NOA bus flag */
> +  (0<<  6)  | /* disable slice-level clock gating */
> +  (0<<  5)  | /* disable clock gating for NOA */
> +  (0<<  4)  | /* terminate if AVC motion and POC table error 
> occurs */
> +  (0<<  3)  | /* terminate if AVC mbdata error occurs */
> +  (0<<  2)  | /* terminate if AVC CABAC/CAVLC decode error 
> occurs */
> +  (0<<  1)  |
> +  (0<<  0));
> +OUT_BCS_BATCH(batch, 0);
> +OUT_BCS_BATCH(batch, 0);
> +
> +ADVANCE_BCS_BATCH(batch);
> +}
> +
> +static void
> +gen9_mfc_avc_surface_state(VADriverContextP ctx,
> +   struct intel_encoder_context *encoder_context,
> +   struct i965_gpe_resource *gpe_resource,
> +   int id)
> +{
> +struct intel_batchbuffer *batch = encoder_context->base.batch;
> +
> +BEGIN_BCS_BATCH(batch, 6);
> +
> +OUT_BCS_BATCH(batch, MFX_SURFACE_STATE | (6 - 2));
> +OUT_BCS_BATCH(batch, id);
> +OUT_BCS_BATCH(batch,
> +  ((gpe_resource->height - 1)<<  18) |
> +  ((gpe_resource->width - 1)<<  4));
> +OUT_BCS_BATCH(batch,
> +  (MFX_SURFACE_PLANAR_420_8<<  28) |/* 420 planar YUV 
> surface */
> +  

Re: [Libva] [PATCH v1 8/9] ENC: add MFX pipeline for AVC encoder

2017-01-16 Thread Zhao Yakui

On 01/13/2017 05:24 PM, Pengfei Qu wrote:

MFX pipeline:
add MFX command for AVC encoder
add MFX Picture slice level command init for AVC
add MFX pipeline init prepare run for AVC encode
add VME/MFX context init for AVC encoder



Please see the inline comment.


Reviewed-by: Sean V Kelley
Signed-off-by: Pengfei Qu
---
  src/gen9_avc_encoder.c | 1887 +++-
  1 file changed, 1886 insertions(+), 1 deletion(-)

diff --git a/src/gen9_avc_encoder.c b/src/gen9_avc_encoder.c
index 5caa9f4..a7545f1 100755
--- a/src/gen9_avc_encoder.c
+++ b/src/gen9_avc_encoder.c
@@ -5742,4 +5742,1889 @@ gen9_avc_kernel_init(VADriverContextP ctx,
  generic_ctx->pfn_send_brc_mb_update_surface = 
gen9_avc_send_surface_brc_mb_update;
  generic_ctx->pfn_send_sfd_surface = gen9_avc_send_surface_sfd;
  generic_ctx->pfn_send_wp_surface = gen9_avc_send_surface_wp;
-}
\ No newline at end of file
+}
+
+/*
+PAK pipeline related function
+*/
+extern int
+intel_avc_enc_slice_type_fixup(int slice_type);
+
+static void
+gen9_mfc_avc_pipe_mode_select(VADriverContextP ctx,
+  struct encode_state *encode_state,
+  struct intel_encoder_context *encoder_context)
+{
+struct encoder_vme_mfc_context * pak_context = (struct 
encoder_vme_mfc_context *)encoder_context->vme_context;
+struct gen9_avc_encoder_context * avc_ctx = (struct gen9_avc_encoder_context 
* )pak_context->private_enc_ctx;
+struct generic_enc_codec_state * generic_state = (struct 
generic_enc_codec_state * )pak_context->generic_enc_state;
+struct intel_batchbuffer *batch = encoder_context->base.batch;
+
+BEGIN_BCS_BATCH(batch, 5);
+
+OUT_BCS_BATCH(batch, MFX_PIPE_MODE_SELECT | (5 - 2));
+OUT_BCS_BATCH(batch,
+  (0<<  29) |
+  (MFX_LONG_MODE<<  17) |   /* Must be long format for 
encoder */
+  (MFD_MODE_VLD<<  15) |
+  (0<<  13) |   /* VDEnc mode  is 1*/
+  ((generic_state->curr_pak_pass != (generic_state->num_pak_passes 
-1))<<  10) |   /* Stream-Out Enable */
+  ((!!avc_ctx->res_post_deblocking_output.bo)<<  9)  |/* 
Post Deblocking Output */
+  ((!!avc_ctx->res_pre_deblocking_output.bo)<<  8)  | /* 
Pre Deblocking Output */
+  (0<<  7)  |   /* Scaled surface enable */
+  (0<<  6)  |   /* Frame statistics stream out 
enable, always '1' in VDEnc mode */
+  (0<<  5)  |   /* not in stitch mode */
+  (1<<  4)  |   /* encoding mode */
+  (MFX_FORMAT_AVC<<  0));
+OUT_BCS_BATCH(batch,
+  (0<<  7)  | /* expand NOA bus flag */
+  (0<<  6)  | /* disable slice-level clock gating */
+  (0<<  5)  | /* disable clock gating for NOA */
+  (0<<  4)  | /* terminate if AVC motion and POC table error 
occurs */
+  (0<<  3)  | /* terminate if AVC mbdata error occurs */
+  (0<<  2)  | /* terminate if AVC CABAC/CAVLC decode error 
occurs */
+  (0<<  1)  |
+  (0<<  0));
+OUT_BCS_BATCH(batch, 0);
+OUT_BCS_BATCH(batch, 0);
+
+ADVANCE_BCS_BATCH(batch);
+}
+
+static void
+gen9_mfc_avc_surface_state(VADriverContextP ctx,
+   struct intel_encoder_context *encoder_context,
+   struct i965_gpe_resource *gpe_resource,
+   int id)
+{
+struct intel_batchbuffer *batch = encoder_context->base.batch;
+
+BEGIN_BCS_BATCH(batch, 6);
+
+OUT_BCS_BATCH(batch, MFX_SURFACE_STATE | (6 - 2));
+OUT_BCS_BATCH(batch, id);
+OUT_BCS_BATCH(batch,
+  ((gpe_resource->height - 1)<<  18) |
+  ((gpe_resource->width - 1)<<  4));
+OUT_BCS_BATCH(batch,
+  (MFX_SURFACE_PLANAR_420_8<<  28) |/* 420 planar YUV 
surface */
+  (1<<  27) |   /* must be 1 for 
interleave U/V, hardware requirement */
+  ((gpe_resource->pitch - 1)<<  3) |/* pitch */
+  (0<<  2)  |   /* must be 0 for 
interleave U/V */
+  (1<<  1)  |   /* must be tiled */
+  (I965_TILEWALK_YMAJOR<<  0)); /* tile walk, 
TILEWALK_YMAJOR */
+OUT_BCS_BATCH(batch,
+  (0<<  16) |/* must be 0 for 
interleave U/V */
+  (gpe_resource->y_cb_offset)); /* y offset for U(cb) 
*/
+OUT_BCS_BATCH(batch,
+  (0<<  16) |/* must be 0 for 
interleave U/V */
+  (gpe_resource->y_cb_offset)); /* y offset for U(cb) 
*/
+
+ADVANCE_BCS_BATCH(batch);
+}
+
+static void
+gen9_mfc_avc_pipe_buf_addr_

[Libva] [PATCH v1 8/9] ENC: add MFX pipeline for AVC encoder

2017-01-13 Thread Pengfei Qu
MFX pipeline:
add MFX command for AVC encoder
add MFX Picture slice level command init for AVC
add MFX pipeline init prepare run for AVC encode
add VME/MFX context init for AVC encoder

Reviewed-by: Sean V Kelley
Signed-off-by: Pengfei Qu 
---
 src/gen9_avc_encoder.c | 1887 +++-
 1 file changed, 1886 insertions(+), 1 deletion(-)

diff --git a/src/gen9_avc_encoder.c b/src/gen9_avc_encoder.c
index 5caa9f4..a7545f1 100755
--- a/src/gen9_avc_encoder.c
+++ b/src/gen9_avc_encoder.c
@@ -5742,4 +5742,1889 @@ gen9_avc_kernel_init(VADriverContextP ctx,
 generic_ctx->pfn_send_brc_mb_update_surface = 
gen9_avc_send_surface_brc_mb_update;
 generic_ctx->pfn_send_sfd_surface = gen9_avc_send_surface_sfd;
 generic_ctx->pfn_send_wp_surface = gen9_avc_send_surface_wp;
-}
\ No newline at end of file
+}
+
+/*
+PAK pipeline related function
+*/
+extern int
+intel_avc_enc_slice_type_fixup(int slice_type);
+
+static void
+gen9_mfc_avc_pipe_mode_select(VADriverContextP ctx,
+  struct encode_state *encode_state,
+  struct intel_encoder_context *encoder_context)
+{
+struct encoder_vme_mfc_context * pak_context = (struct 
encoder_vme_mfc_context *)encoder_context->vme_context;
+struct gen9_avc_encoder_context * avc_ctx = (struct 
gen9_avc_encoder_context * )pak_context->private_enc_ctx;
+struct generic_enc_codec_state * generic_state = (struct 
generic_enc_codec_state * )pak_context->generic_enc_state;
+struct intel_batchbuffer *batch = encoder_context->base.batch;
+
+BEGIN_BCS_BATCH(batch, 5);
+
+OUT_BCS_BATCH(batch, MFX_PIPE_MODE_SELECT | (5 - 2));
+OUT_BCS_BATCH(batch,
+  (0 << 29) |
+  (MFX_LONG_MODE << 17) |   /* Must be long format for 
encoder */
+  (MFD_MODE_VLD << 15) |
+  (0 << 13) |   /* VDEnc mode  is 1*/
+  ((generic_state->curr_pak_pass != 
(generic_state->num_pak_passes -1)) << 10) |   /* Stream-Out 
Enable */
+  ((!!avc_ctx->res_post_deblocking_output.bo) << 9)  |/* 
Post Deblocking Output */
+  ((!!avc_ctx->res_pre_deblocking_output.bo) << 8)  | /* 
Pre Deblocking Output */
+  (0 << 7)  |   /* Scaled surface enable */
+  (0 << 6)  |   /* Frame statistics stream out 
enable, always '1' in VDEnc mode */
+  (0 << 5)  |   /* not in stitch mode */
+  (1 << 4)  |   /* encoding mode */
+  (MFX_FORMAT_AVC << 0));
+OUT_BCS_BATCH(batch,
+  (0 << 7)  | /* expand NOA bus flag */
+  (0 << 6)  | /* disable slice-level clock gating */
+  (0 << 5)  | /* disable clock gating for NOA */
+  (0 << 4)  | /* terminate if AVC motion and POC table error 
occurs */
+  (0 << 3)  | /* terminate if AVC mbdata error occurs */
+  (0 << 2)  | /* terminate if AVC CABAC/CAVLC decode error 
occurs */
+  (0 << 1)  |
+  (0 << 0));
+OUT_BCS_BATCH(batch, 0);
+OUT_BCS_BATCH(batch, 0);
+
+ADVANCE_BCS_BATCH(batch);
+}
+
+static void
+gen9_mfc_avc_surface_state(VADriverContextP ctx,
+   struct intel_encoder_context *encoder_context,
+   struct i965_gpe_resource *gpe_resource,
+   int id)
+{
+struct intel_batchbuffer *batch = encoder_context->base.batch;
+
+BEGIN_BCS_BATCH(batch, 6);
+
+OUT_BCS_BATCH(batch, MFX_SURFACE_STATE | (6 - 2));
+OUT_BCS_BATCH(batch, id);
+OUT_BCS_BATCH(batch,
+  ((gpe_resource->height - 1) << 18) |
+  ((gpe_resource->width - 1) << 4));
+OUT_BCS_BATCH(batch,
+  (MFX_SURFACE_PLANAR_420_8 << 28) |/* 420 planar YUV 
surface */
+  (1 << 27) |   /* must be 1 for 
interleave U/V, hardware requirement */
+  ((gpe_resource->pitch - 1) << 3) |/* pitch */
+  (0 << 2)  |   /* must be 0 for 
interleave U/V */
+  (1 << 1)  |   /* must be tiled */
+  (I965_TILEWALK_YMAJOR << 0)); /* tile walk, 
TILEWALK_YMAJOR */
+OUT_BCS_BATCH(batch,
+  (0 << 16) |  /* must be 0 for 
interleave U/V */
+  (gpe_resource->y_cb_offset)); /* y offset for U(cb) 
*/
+OUT_BCS_BATCH(batch,
+  (0 << 16) |  /* must be 0 for 
interleave U/V */
+  (gpe_resource->y_cb_offset)); /* y offset for U(cb) 
*/
+
+ADVANCE_BCS_BATCH(batch);
+}
+
+static void
+gen9_mfc_avc_pipe_buf_addr_state(VADriverContextP ctx, struct 
intel_encoder_context *encoder_context)
+{
+st