[Libva] [PATCH 02/14] Encoding: Setup one cost_table surface state for VME shader

Pengfei Qu Pengfei.Qu at intel.com
Thu Jun 30 02:32:59 UTC 2016


From: Zhao Yakui <yakui.zhao at intel.com>

v1:
format/style aligment accordingly to avoid the warning.
Currently the length of VME MEDIA_OBJECT command on Ivy can't exceed 8 dwords. If more parameter needs to be passed, the buffer length should be enlarged.
Pass the Qp parameter into VME shader

Signed-off-by: Zhao Yakui <yakui.zhao at intel.com>
Signed-off-by: pjl <ceciliapeng at intel.com>
Signed-off-by: Pengfei Qu <Pengfei.Qu at intel.com>
---
 src/gen6_mfc_common.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++--
 src/gen6_vme.h        |  6 ++++++
 src/gen75_vme.c       | 29 +++++++++++++++++++++-----
 src/gen7_vme.c        | 30 ++++++++++++++++++++++-----
 src/gen8_vme.c        | 29 +++++++++++++++++++++-----
 5 files changed, 134 insertions(+), 17 deletions(-)

diff --git a/src/gen6_mfc_common.c b/src/gen6_mfc_common.c
index bb02c83..baa8ec4 100644
--- a/src/gen6_mfc_common.c
+++ b/src/gen6_mfc_common.c
@@ -1017,6 +1017,16 @@ gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx,
     int mb_row;
     int s;
     unsigned int *command_ptr;
+    struct gen6_mfc_context *mfc_context = encoder_context->mfc_context;
+    VAEncPictureParameterBufferH264 *pic_param = (VAEncPictureParameterBufferH264 *)encode_state->pic_param_ext->buffer;
+    VAEncSliceParameterBufferH264 *slice_param = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[0]->buffer;
+    int qp,qp_mb;
+    int slice_type = intel_avc_enc_slice_type_fixup(slice_param->slice_type);
+
+    if (encoder_context->rate_control_mode == VA_RC_CQP)
+        qp = pic_param->pic_init_qp + slice_param->slice_qp_delta;
+    else
+        qp = mfc_context->bit_rate_control_context[slice_type].QpPrimeY;
 
 #define		USE_SCOREBOARD		(1 << 21)
  
@@ -1056,7 +1066,7 @@ gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx,
                     }
                 }
 
-                *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
+                *command_ptr++ = (CMD_MEDIA_OBJECT | (9 - 2));
                 *command_ptr++ = kernel;
                 *command_ptr++ = USE_SCOREBOARD;
                 /* Indirect data */
@@ -1067,6 +1077,8 @@ gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx,
                 /*inline data */
                 *command_ptr++ = (mb_width << 16 | y_inner << 8 | x_inner);
                 *command_ptr++ = ((1 << 18) | (1 << 16) | transform_8x8_mode_flag | (mb_intra_ub << 8));
+                /* qp occupies one byte */
+                *command_ptr++ = qp_mb;
                 x_inner -= 2;
                 y_inner += 1;
             }
@@ -1100,7 +1112,7 @@ gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx,
                     }
                 }
 
-                *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
+                *command_ptr++ = (CMD_MEDIA_OBJECT | (9 - 2));
                 *command_ptr++ = kernel;
                 *command_ptr++ = USE_SCOREBOARD;
                 /* Indirect data */
@@ -1111,6 +1123,8 @@ gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx,
                 /*inline data */
                 *command_ptr++ = (mb_width << 16 | y_inner << 8 | x_inner);
                 *command_ptr++ = ((1 << 18) | (1 << 16) | transform_8x8_mode_flag | (mb_intra_ub << 8));
+                /* qp occupies one byte */
+                *command_ptr++ = qp_mb;
 
                 x_inner -= 2;
                 y_inner += 1;
@@ -1700,6 +1714,45 @@ intel_h264_initialize_mbmv_cost(VADriverContextP ctx,
     return;
 }
 
+extern void
+intel_h264_setup_cost_surface(VADriverContextP ctx,
+                              struct encode_state *encode_state,
+                              struct intel_encoder_context *encoder_context,
+                              unsigned long binding_table_offset,
+                              unsigned long surface_state_offset)
+{
+    struct i965_driver_data *i965 = i965_driver_data(ctx);
+    struct gen6_vme_context *vme_context = encoder_context->vme_context;
+    VAEncSliceParameterBufferH264 *slice_param = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[0]->buffer;
+    int qp;
+    dri_bo *bo;
+
+
+    struct i965_buffer_surface cost_table;
+
+    int slice_type = intel_avc_enc_slice_type_fixup(slice_param->slice_type);
+
+
+    if (slice_type == SLICE_TYPE_I) {
+        bo = vme_context->i_qp_cost_table;
+    } else if (slice_type == SLICE_TYPE_P) {
+        bo = vme_context->p_qp_cost_table;
+    } else {
+        bo = vme_context->b_qp_cost_table;
+    }
+
+    cost_table.bo = bo;
+    cost_table.num_blocks = QP_MAX;
+    cost_table.pitch = 16;
+    cost_table.size_block = 32;
+
+    vme_context->vme_buffer_suface_setup(ctx,
+                                         &vme_context->gpe_context,
+                                         &cost_table,
+                                         binding_table_offset,
+                                         surface_state_offset);
+}
+
 /* HEVC */
 static int
 hevc_temporal_find_surface(VAPictureHEVC *curr_pic,
diff --git a/src/gen6_vme.h b/src/gen6_vme.h
index ea9918b..7059831 100644
--- a/src/gen6_vme.h
+++ b/src/gen6_vme.h
@@ -213,4 +213,10 @@ intel_h264_initialize_mbmv_cost(VADriverContextP ctx,
                                 struct encode_state *encode_state,
                                 struct intel_encoder_context *encoder_context);
 
+extern void
+intel_h264_setup_cost_surface(VADriverContextP ctx,
+                              struct encode_state *encode_state,
+                              struct intel_encoder_context *encoder_context,
+                              unsigned long binding_table_offset,
+                              unsigned long surface_state_offset);
 #endif /* _GEN6_VME_H_ */
diff --git a/src/gen75_vme.c b/src/gen75_vme.c
index a85d6b3..8434e6f 100644
--- a/src/gen75_vme.c
+++ b/src/gen75_vme.c
@@ -280,6 +280,9 @@ gen75_vme_surface_setup(VADriverContextP ctx,
     /* VME output */
     gen75_vme_output_buffer_setup(ctx, encode_state, 3, encoder_context);
     gen75_vme_output_vme_batchbuffer_setup(ctx, encode_state, 5, encoder_context);
+    intel_h264_setup_cost_surface(ctx, encode_state, encoder_context,
+                                 BINDING_TABLE_OFFSET(INTEL_COST_TABLE_OFFSET),
+                                 SURFACE_STATE_OFFSET(INTEL_COST_TABLE_OFFSET));
 
     return VA_STATUS_SUCCESS;
 }
@@ -643,11 +646,12 @@ static VAStatus gen75_vme_prepare(VADriverContextP ctx,
 
     if (!vme_context->h264_level ||
         (vme_context->h264_level != pSequenceParameter->level_idc)) {
-	vme_context->h264_level = pSequenceParameter->level_idc;	
-    }	
+            vme_context->h264_level = pSequenceParameter->level_idc;
+    }
 
     intel_vme_update_mbmv_cost(ctx, encode_state, encoder_context);
-    	
+    intel_h264_initialize_mbmv_cost(ctx, encode_state, encoder_context);
+
     /*Setup all the memory object*/
     gen75_vme_surface_setup(ctx, encode_state, is_intra, encoder_context);
     gen75_vme_interface_setup(ctx, encode_state, encoder_context);
@@ -1003,8 +1007,23 @@ gen75_vme_context_destroy(void *context)
     vme_context->vme_batchbuffer.bo = NULL;
 
     if (vme_context->vme_state_message) {
-	free(vme_context->vme_state_message);
-	vme_context->vme_state_message = NULL;
+        free(vme_context->vme_state_message);
+        vme_context->vme_state_message = NULL;
+    }
+
+    if (vme_context->i_qp_cost_table) {
+        dri_bo_unreference(vme_context->i_qp_cost_table);
+        vme_context->i_qp_cost_table = NULL;
+    }
+
+    if (vme_context->p_qp_cost_table) {
+        dri_bo_unreference(vme_context->p_qp_cost_table);
+        vme_context->p_qp_cost_table = NULL;
+    }
+
+    if (vme_context->b_qp_cost_table) {
+        dri_bo_unreference(vme_context->b_qp_cost_table);
+        vme_context->b_qp_cost_table = NULL;
     }
 
     free(vme_context);
diff --git a/src/gen7_vme.c b/src/gen7_vme.c
index 9da44d1..6dd13a8 100644
--- a/src/gen7_vme.c
+++ b/src/gen7_vme.c
@@ -227,7 +227,7 @@ gen7_vme_output_vme_batchbuffer_setup(VADriverContextP ctx,
     int height_in_mbs = pSequenceParameter->picture_height_in_mbs;
 
     vme_context->vme_batchbuffer.num_blocks = width_in_mbs * height_in_mbs + 1;
-    vme_context->vme_batchbuffer.size_block = 32; /* 2 OWORDs */
+    vme_context->vme_batchbuffer.size_block = 64; /* 4 OWORDs */
     vme_context->vme_batchbuffer.pitch = 16;
     vme_context->vme_batchbuffer.bo = dri_bo_alloc(i965->intel.bufmgr, 
                                                    "VME batchbuffer",
@@ -270,6 +270,9 @@ gen7_vme_surface_setup(VADriverContextP ctx,
     /* VME output */
     gen7_vme_output_buffer_setup(ctx, encode_state, 3, encoder_context);
     gen7_vme_output_vme_batchbuffer_setup(ctx, encode_state, 5, encoder_context);
+    intel_h264_setup_cost_surface(ctx, encode_state, encoder_context,
+                                  BINDING_TABLE_OFFSET(INTEL_COST_TABLE_OFFSET),
+                                  SURFACE_STATE_OFFSET(INTEL_COST_TABLE_OFFSET));
 
     return VA_STATUS_SUCCESS;
 }
@@ -667,10 +670,12 @@ static VAStatus gen7_vme_prepare(VADriverContextP ctx,
 
     if (!vme_context->h264_level ||
         (vme_context->h264_level != pSequenceParameter->level_idc)) {
-	vme_context->h264_level = pSequenceParameter->level_idc;	
+            vme_context->h264_level = pSequenceParameter->level_idc;
     }
-	
+
     intel_vme_update_mbmv_cost(ctx, encode_state, encoder_context);
+    intel_h264_initialize_mbmv_cost(ctx, encode_state, encoder_context);
+
     /*Setup all the memory object*/
     gen7_vme_surface_setup(ctx, encode_state, is_intra, encoder_context);
     gen7_vme_interface_setup(ctx, encode_state, encoder_context);
@@ -1019,8 +1024,23 @@ gen7_vme_context_destroy(void *context)
     vme_context->vme_batchbuffer.bo = NULL;
 
     if (vme_context->vme_state_message) {
-	free(vme_context->vme_state_message);
-	vme_context->vme_state_message = NULL;
+        free(vme_context->vme_state_message);
+        vme_context->vme_state_message = NULL;
+    }
+
+    if (vme_context->i_qp_cost_table) {
+        dri_bo_unreference(vme_context->i_qp_cost_table);
+        vme_context->i_qp_cost_table = NULL;
+    }
+
+    if (vme_context->p_qp_cost_table) {
+        dri_bo_unreference(vme_context->p_qp_cost_table);
+        vme_context->p_qp_cost_table = NULL;
+    }
+
+    if (vme_context->b_qp_cost_table) {
+        dri_bo_unreference(vme_context->b_qp_cost_table);
+        vme_context->b_qp_cost_table = NULL;
     }
 
     free(vme_context);
diff --git a/src/gen8_vme.c b/src/gen8_vme.c
index edf6060..07dc462 100644
--- a/src/gen8_vme.c
+++ b/src/gen8_vme.c
@@ -314,6 +314,9 @@ gen8_vme_surface_setup(VADriverContextP ctx,
     /* VME output */
     gen8_vme_avc_output_buffer_setup(ctx, encode_state, 3, encoder_context);
     gen8_vme_avc_output_vme_batchbuffer_setup(ctx, encode_state, 5, encoder_context);
+    intel_h264_setup_cost_surface(ctx, encode_state, encoder_context,
+                                  BINDING_TABLE_OFFSET(INTEL_COST_TABLE_OFFSET),
+                                  SURFACE_STATE_OFFSET(INTEL_COST_TABLE_OFFSET));
 
     return VA_STATUS_SUCCESS;
 }
@@ -717,11 +720,12 @@ static VAStatus gen8_vme_prepare(VADriverContextP ctx,
 
     if (!vme_context->h264_level ||
         (vme_context->h264_level != pSequenceParameter->level_idc)) {
-	vme_context->h264_level = pSequenceParameter->level_idc;	
-    }	
+            vme_context->h264_level = pSequenceParameter->level_idc;
+    }
 
     intel_vme_update_mbmv_cost(ctx, encode_state, encoder_context);
-    	
+    intel_h264_initialize_mbmv_cost(ctx, encode_state, encoder_context);
+
     /*Setup all the memory object*/
     gen8_vme_surface_setup(ctx, encode_state, is_intra, encoder_context);
     gen8_vme_interface_setup(ctx, encode_state, encoder_context);
@@ -1288,8 +1292,23 @@ gen8_vme_context_destroy(void *context)
     vme_context->vme_batchbuffer.bo = NULL;
 
     if (vme_context->vme_state_message) {
-	free(vme_context->vme_state_message);
-	vme_context->vme_state_message = NULL;
+        free(vme_context->vme_state_message);
+        vme_context->vme_state_message = NULL;
+    }
+
+    if (vme_context->i_qp_cost_table) {
+        dri_bo_unreference(vme_context->i_qp_cost_table);
+        vme_context->i_qp_cost_table = NULL;
+    }
+
+    if (vme_context->p_qp_cost_table) {
+        dri_bo_unreference(vme_context->p_qp_cost_table);
+        vme_context->p_qp_cost_table = NULL;
+    }
+
+    if (vme_context->b_qp_cost_table) {
+        dri_bo_unreference(vme_context->b_qp_cost_table);
+        vme_context->b_qp_cost_table = NULL;
     }
 
     free(vme_context);
-- 
2.7.4



More information about the Libva mailing list