Use the common scoreboard code on Ivy/Haswell to remove the duplicated code
authorZhao Yakui <yakui.zhao@intel.com>
Mon, 14 Jan 2013 02:45:14 +0000 (10:45 +0800)
committerXiang, Haihao <haihao.xiang@intel.com>
Thu, 17 Jan 2013 05:08:40 +0000 (13:08 +0800)
Signed-off-by: Zhao Yakui <yakui.zhao@intel.com>
src/gen6_mfc_common.c
src/gen6_vme.h
src/gen75_vme.c
src/gen7_vme.c

index 329058e..1796003 100644 (file)
@@ -818,3 +818,174 @@ void intel_vme_update_mbmv_cost(VADriverContextP ctx,
        }
     }
 }
+
+
+#define                MB_SCOREBOARD_A         (1 << 0)
+#define                MB_SCOREBOARD_B         (1 << 1)
+#define                MB_SCOREBOARD_C         (1 << 2)
+void 
+gen7_vme_scoreboard_init(VADriverContextP ctx, struct gen6_vme_context *vme_context)
+{
+    vme_context->gpe_context.vfe_desc5.scoreboard0.enable = 1;
+    vme_context->gpe_context.vfe_desc5.scoreboard0.type = SCOREBOARD_STALLING;
+    vme_context->gpe_context.vfe_desc5.scoreboard0.mask = (MB_SCOREBOARD_A |
+                                                               MB_SCOREBOARD_B |
+                                                               MB_SCOREBOARD_C);
+
+    /* In VME prediction the current mb depends on the neighbour 
+     * A/B/C macroblock. So the left/up/up-right dependency should
+     * be considered.
+     */
+    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x0 = -1;
+    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y0 = 0;
+    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x1 = 0;
+    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y1 = -1;
+    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x2 = 1;
+    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y2 = -1;
+       
+    vme_context->gpe_context.vfe_desc7.dword = 0;
+    return;
+}
+
+/* check whether the mb of (x_index, y_index) is out of bound */
+static inline int loop_in_bounds(int x_index, int y_index, int first_mb, int num_mb, int mb_width, int mb_height)
+{
+       int mb_index;
+       if (x_index < 0 || x_index >= mb_width)
+               return -1;
+       if (y_index < 0 || y_index >= mb_height)
+               return -1;
+       
+       mb_index = y_index * mb_width + x_index;
+       if (mb_index < first_mb || mb_index > (first_mb + num_mb))
+               return -1;
+       return 0;
+}
+
+void
+gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx, 
+                              struct encode_state *encode_state,
+                              int mb_width, int mb_height,
+                              int kernel,
+                              int transform_8x8_mode_flag,
+                              struct intel_encoder_context *encoder_context)
+{
+    struct gen6_vme_context *vme_context = encoder_context->vme_context;
+    int mb_x = 0, mb_y = 0;
+    int mb_row;
+    int s;
+    unsigned int *command_ptr;
+    int temp;
+
+
+#define                USE_SCOREBOARD          (1 << 21)
+    dri_bo_map(vme_context->vme_batchbuffer.bo, 1);
+    command_ptr = vme_context->vme_batchbuffer.bo->virtual;
+
+    for (s = 0; s < encode_state->num_slice_params_ext; s++) {
+       VAEncSliceParameterBufferH264 *pSliceParameter = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[s]->buffer;
+       int first_mb = pSliceParameter->macroblock_address;
+       int num_mb = pSliceParameter->num_macroblocks;
+       unsigned int mb_intra_ub, score_dep;
+       int x_outer, y_outer, x_inner, y_inner;
+
+       x_outer = first_mb % mb_width;
+       y_outer = first_mb / mb_width;
+       mb_row = y_outer;
+                                
+       for (; x_outer < (mb_width -2 ) && !loop_in_bounds(x_outer, y_outer, first_mb, num_mb, mb_width, mb_height); ) {
+           x_inner = x_outer;
+           y_inner = y_outer;
+           for (; !loop_in_bounds(x_inner, y_inner, first_mb, num_mb, mb_width, mb_height);) {
+               mb_intra_ub = 0;
+               score_dep = 0;
+               if (x_inner != 0) {
+                   mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_AE;
+                   score_dep |= MB_SCOREBOARD_A; 
+               }
+               if (y_inner != mb_row) {
+                   mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_B;
+                   score_dep |= MB_SCOREBOARD_B;
+                   if (x_inner != 0)
+                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_D;
+                   if (x_inner != (mb_width -1)) {
+                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_C;
+                       score_dep |= MB_SCOREBOARD_C;
+                    }
+               }
+                                                       
+               *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
+               *command_ptr++ = kernel;
+               *command_ptr++ = USE_SCOREBOARD;
+               /* Indirect data */
+               *command_ptr++ = 0;
+               /* the (X, Y) term of scoreboard */
+               *command_ptr++ = ((y_inner << 16) | x_inner);
+               *command_ptr++ = score_dep;
+               /*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));
+               x_inner -= 2;
+               y_inner += 1;
+           }
+           x_outer += 1;
+       }
+
+       x_outer = mb_width - 2;
+       y_outer = first_mb / mb_width;
+       temp = 0;
+       for (;!loop_in_bounds(x_outer, y_outer, first_mb, num_mb, mb_width, mb_height); ) { 
+           y_inner = y_outer;
+           x_inner = x_outer;
+           for (; !loop_in_bounds(x_inner, y_inner, first_mb, num_mb, mb_width, mb_height);) {
+               mb_intra_ub = 0;
+               score_dep = 0;
+               if (x_inner != 0) {
+                   mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_AE;
+                   score_dep |= MB_SCOREBOARD_A; 
+               }
+               if (y_inner != mb_row) {
+                   mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_B;
+                   score_dep |= MB_SCOREBOARD_B;
+                   if (x_inner != 0)
+                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_D;
+
+                   if (x_inner != (mb_width -1)) {
+                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_C;
+                       score_dep |= MB_SCOREBOARD_C;
+                    }
+               }
+
+               *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
+               *command_ptr++ = kernel;
+               *command_ptr++ = USE_SCOREBOARD;
+               /* Indirect data */
+               *command_ptr++ = 0;
+               /* the (X, Y) term of scoreboard */
+               *command_ptr++ = ((y_inner << 16) | x_inner);
+               *command_ptr++ = score_dep;
+               /*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));
+
+               x_inner -= 2;
+               y_inner += 1;
+           }
+           temp++;
+           if (temp == 2) {
+               y_outer += 1;
+               temp = 0;
+               x_outer = mb_width - 2;
+           } else {
+               x_outer++;
+           }   
+       }
+    }
+
+    *command_ptr++ = 0;
+    *command_ptr++ = MI_BATCH_BUFFER_END;
+
+    dri_bo_unmap(vme_context->vme_batchbuffer.bo);
+}
+
index 70dee05..6295ec2 100644 (file)
@@ -120,4 +120,21 @@ Bool gen7_vme_context_init(VADriverContextP ctx, struct intel_encoder_context *e
 #define                MODE_INTER_MV6          18
 #define                MODE_INTER_MV7          19
 
+#define                INTRA_PRED_AVAIL_FLAG_AE        0x60
+#define                INTRA_PRED_AVAIL_FLAG_B         0x10
+#define                INTRA_PRED_AVAIL_FLAG_C         0x8
+#define                INTRA_PRED_AVAIL_FLAG_D         0x4
+#define                INTRA_PRED_AVAIL_FLAG_BCD_MASK  0x1C
+
+extern void
+gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx, 
+                              struct encode_state *encode_state,
+                              int mb_width, int mb_height,
+                              int kernel,
+                              int transform_8x8_mode_flag,
+                              struct intel_encoder_context *encoder_context);
+
+extern void 
+gen7_vme_scoreboard_init(VADriverContextP ctx, struct gen6_vme_context *vme_context);
+
 #endif /* _GEN6_VME_H_ */
index a263f58..e0d982b 100644 (file)
 
 #define VME_MSG_LENGTH         32
   
-#define                MB_SCOREBOARD_A         (1 << 0)
-#define                MB_SCOREBOARD_B         (1 << 1)
-#define                MB_SCOREBOARD_C         (1 << 2)
-
 static const uint32_t gen75_vme_intra_frame[][4] = {
 #include "shaders/vme/intra_frame_haswell.g75b"
 };
@@ -498,11 +494,6 @@ static VAStatus gen75_vme_vme_state_setup(VADriverContextP ctx,
     return VA_STATUS_SUCCESS;
 }
 
-#define                INTRA_PRED_AVAIL_FLAG_AE        0x60
-#define                INTRA_PRED_AVAIL_FLAG_B         0x10
-#define                INTRA_PRED_AVAIL_FLAG_C         0x8
-#define                INTRA_PRED_AVAIL_FLAG_D         0x4
-#define                INTRA_PRED_AVAIL_FLAG_BCD_MASK  0x1C
 
 static void
 gen75_vme_fill_vme_batchbuffer(VADriverContextP ctx, 
@@ -574,150 +565,6 @@ gen75_vme_fill_vme_batchbuffer(VADriverContextP ctx,
     dri_bo_unmap(vme_context->vme_batchbuffer.bo);
 }
 
-/* check whether the mb of (x_index, y_index) is out of bound */
-static inline int loop_in_bounds(int x_index, int y_index, int first_mb, int num_mb, int mb_width, int mb_height)
-{
-       int mb_index;
-       if (x_index < 0 || x_index >= mb_width)
-               return -1;
-       if (y_index < 0 || y_index >= mb_height)
-               return -1;
-       
-       mb_index = y_index * mb_width + x_index;
-       if (mb_index < first_mb || mb_index > (first_mb + num_mb))
-               return -1;
-       return 0;
-}
-
-
-static void
-gen75_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx, 
-                              struct encode_state *encode_state,
-                              int mb_width, int mb_height,
-                              int kernel,
-                              int transform_8x8_mode_flag,
-                              struct intel_encoder_context *encoder_context)
-{
-    struct gen6_vme_context *vme_context = encoder_context->vme_context;
-    int mb_x = 0, mb_y = 0;
-    int mb_row;
-    int s;
-    unsigned int *command_ptr;
-    int temp;
-
-
-#define                USE_SCOREBOARD          (1 << 21)
-    dri_bo_map(vme_context->vme_batchbuffer.bo, 1);
-    command_ptr = vme_context->vme_batchbuffer.bo->virtual;
-
-    for (s = 0; s < encode_state->num_slice_params_ext; s++) {
-        VAEncSliceParameterBufferH264 *pSliceParameter = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[s]->buffer; 
-        int first_mb = pSliceParameter->macroblock_address;
-        int num_mb = pSliceParameter->num_macroblocks;
-        unsigned int mb_intra_ub, score_dep;
-       int x_outer, y_outer, x_inner, y_inner;
-
-       x_outer = first_mb % mb_width;
-       y_outer = first_mb / mb_width;
-       mb_row = y_outer;
-                                
-       for (; x_outer < (mb_width -2 ) && !loop_in_bounds(x_outer, y_outer, first_mb, num_mb, mb_width, mb_height); ) {
-               x_inner = x_outer;
-               y_inner = y_outer;
-               for (; !loop_in_bounds(x_inner, y_inner, first_mb, num_mb, mb_width, mb_height);) {
-                       mb_intra_ub = 0;
-                       score_dep = 0;
-                       if (x_inner != 0) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_AE;
-                               score_dep |= MB_SCOREBOARD_A; 
-                       }
-                       if (y_inner != mb_row) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_B;
-                               score_dep |= MB_SCOREBOARD_B;
-                               if (x_inner != 0)
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_D;
-                               if (x_inner != (mb_width -1)) {
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_C;
-                                       score_dep |= MB_SCOREBOARD_C;
-                               }
-                       }
-                                                       
-                       *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
-                       *command_ptr++ = kernel;
-                       *command_ptr++ = USE_SCOREBOARD;
-                       /* Indirect data */
-                       *command_ptr++ = 0;
-                       /* the (X, Y) term of scoreboard */
-                       *command_ptr++ = ((y_inner << 16) | x_inner);
-                       *command_ptr++ = score_dep;
-
-                       /*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));
-                       x_inner -= 2;
-                       y_inner += 1;
-               }
-               x_outer += 1;
-       }
-
-       x_outer = mb_width - 2;
-       y_outer = first_mb / mb_width;
-       temp = 0;
-       for (;!loop_in_bounds(x_outer, y_outer, first_mb, num_mb, mb_width, mb_height); ) { 
-               y_inner = y_outer;
-               x_inner = x_outer;
-               for (; !loop_in_bounds(x_inner, y_inner, first_mb, num_mb, mb_width, mb_height);) {
-                       mb_intra_ub = 0;
-                       score_dep = 0;
-                       if (x_inner != 0) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_AE;
-                               score_dep |= MB_SCOREBOARD_A; 
-                       }
-                       if (y_inner != mb_row) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_B;
-                               score_dep |= MB_SCOREBOARD_B;
-                               if (x_inner != 0)
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_D;
-                               if (x_inner != (mb_width -1)) {
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_C;
-                                       score_dep |= MB_SCOREBOARD_C;
-                               }
-                       }
-
-                       *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
-                       *command_ptr++ = kernel;
-                       *command_ptr++ = USE_SCOREBOARD;
-                       /* Indirect data */
-                       *command_ptr++ = 0;
-                       /* the (X, Y) term of scoreboard */
-                       *command_ptr++ = ((y_inner << 16) | x_inner);
-                       *command_ptr++ = score_dep;
-
-                       /*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));
-
-                       x_inner -= 2;
-                       y_inner += 1;
-               }
-               temp++;
-               if (temp == 2) {
-                       y_outer += 1;
-                       temp = 0;
-                       x_outer = mb_width - 2;
-               } else {
-                       x_outer++;
-               }       
-       }
-    }
-
-    *command_ptr++ = 0;
-    *command_ptr++ = MI_BATCH_BUFFER_END;
-
-    dri_bo_unmap(vme_context->vme_batchbuffer.bo);
-}
-
 static void gen75_vme_media_init(VADriverContextP ctx, struct intel_encoder_context *encoder_context)
 {
     struct i965_driver_data *i965 = i965_driver_data(ctx);
@@ -773,7 +620,7 @@ static void gen75_vme_pipeline_programing(VADriverContextP ctx,
             kernel_shader = VME_INTER_SHADER;
    }
     if (allow_hwscore)
-       gen75_vme_walker_fill_vme_batchbuffer(ctx, 
+       gen7_vme_walker_fill_vme_batchbuffer(ctx, 
                                   encode_state,
                                   width_in_mbs, height_in_mbs,
                                   kernel_shader,
@@ -1184,24 +1031,7 @@ Bool gen75_vme_context_init(VADriverContextP ctx, struct intel_encoder_context *
     vme_context->gpe_context.vfe_state.urb_entry_size = 59 - 1;
     vme_context->gpe_context.vfe_state.curbe_allocation_size = CURBE_ALLOCATION_SIZE - 1;
 
-    vme_context->gpe_context.vfe_desc5.scoreboard0.enable = 1;
-    vme_context->gpe_context.vfe_desc5.scoreboard0.type = SCOREBOARD_STALLING;
-    vme_context->gpe_context.vfe_desc5.scoreboard0.mask = (MB_SCOREBOARD_A |
-                                                               MB_SCOREBOARD_B |
-                                                               MB_SCOREBOARD_C);
-
-    /* In VME prediction the current mb depends on the neighbour 
-     * A/B/C macroblock. So the left/up/up-right dependency should
-     * be considered.
-     */
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x0 = -1;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y0 = 0;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x1 = 0;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y1 = -1;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x2 = 1;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y2 = -1;
-       
-    vme_context->gpe_context.vfe_desc7.dword = 0;
+    gen7_vme_scoreboard_init(ctx, vme_context);
 
     i965_gpe_load_kernels(ctx,
                           &vme_context->gpe_context,
index f05dcac..9c8f4fe 100644 (file)
@@ -77,9 +77,6 @@ enum MPEG2_VME_KERNEL_TYPE{
     MPEG2_VME_KERNEL_SUM
 };
  
-#define                MB_SCOREBOARD_A         (1 << 0)
-#define                MB_SCOREBOARD_B         (1 << 1)
-#define                MB_SCOREBOARD_C         (1 << 2)
 
 static const uint32_t gen7_vme_intra_frame[][4] = {
 #include "shaders/vme/intra_frame_ivb.g7b"
@@ -543,12 +540,6 @@ static VAStatus gen7_vme_vme_state_setup(VADriverContextP ctx,
     return VA_STATUS_SUCCESS;
 }
 
-#define                INTRA_PRED_AVAIL_FLAG_AE        0x60
-#define                INTRA_PRED_AVAIL_FLAG_B         0x10
-#define                INTRA_PRED_AVAIL_FLAG_C         0x8
-#define                INTRA_PRED_AVAIL_FLAG_D         0x4
-#define                INTRA_PRED_AVAIL_FLAG_BCD_MASK  0x1C
-
 static void
 gen7_vme_fill_vme_batchbuffer(VADriverContextP ctx, 
                               struct encode_state *encode_state,
@@ -635,148 +626,6 @@ gen7_vme_fill_vme_batchbuffer(VADriverContextP ctx,
     dri_bo_unmap(vme_context->vme_batchbuffer.bo);
 }
 
-/* check whether the mb of (x_index, y_index) is out of bound */
-static inline int loop_in_bounds(int x_index, int y_index, int first_mb, int num_mb, int mb_width, int mb_height)
-{
-       int mb_index;
-       if (x_index < 0 || x_index >= mb_width)
-               return -1;
-       if (y_index < 0 || y_index >= mb_height)
-               return -1;
-       
-       mb_index = y_index * mb_width + x_index;
-       if (mb_index < first_mb || mb_index > (first_mb + num_mb))
-               return -1;
-       return 0;
-}
-
-static void
-gen7_vme_walker_fill_vme_batchbuffer(VADriverContextP ctx, 
-                              struct encode_state *encode_state,
-                              int mb_width, int mb_height,
-                              int kernel,
-                              int transform_8x8_mode_flag,
-                              struct intel_encoder_context *encoder_context)
-{
-    struct gen6_vme_context *vme_context = encoder_context->vme_context;
-    int mb_x = 0, mb_y = 0;
-    int mb_row;
-    int s;
-    unsigned int *command_ptr;
-    int temp;
-
-
-#define                USE_SCOREBOARD          (1 << 21)
-    dri_bo_map(vme_context->vme_batchbuffer.bo, 1);
-    command_ptr = vme_context->vme_batchbuffer.bo->virtual;
-
-    for (s = 0; s < encode_state->num_slice_params_ext; s++) {
-        VAEncSliceParameterBufferH264 *pSliceParameter = (VAEncSliceParameterBufferH264 *)encode_state->slice_params_ext[s]->buffer; 
-        int first_mb = pSliceParameter->macroblock_address;
-        int num_mb = pSliceParameter->num_macroblocks;
-        unsigned int mb_intra_ub, score_dep;
-       int x_outer, y_outer, x_inner, y_inner;
-
-       x_outer = first_mb % mb_width;
-       y_outer = first_mb / mb_width;
-       mb_row = y_outer;
-                                
-       for (; x_outer < (mb_width -2 ) && !loop_in_bounds(x_outer, y_outer, first_mb, num_mb, mb_width, mb_height); ) {
-               x_inner = x_outer;
-               y_inner = y_outer;
-               for (; !loop_in_bounds(x_inner, y_inner, first_mb, num_mb, mb_width, mb_height);) {
-                       mb_intra_ub = 0;
-                       score_dep = 0;
-                       if (x_inner != 0) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_AE;
-                               score_dep |= MB_SCOREBOARD_A; 
-                       }
-                       if (y_inner != mb_row) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_B;
-                               score_dep |= MB_SCOREBOARD_B;
-                               if (x_inner != 0)
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_D;
-                               if (x_inner != (mb_width -1)) {
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_C;
-                                       score_dep |= MB_SCOREBOARD_C;
-                               }
-                       }
-                                                       
-                       *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
-                       *command_ptr++ = kernel;
-                       *command_ptr++ = USE_SCOREBOARD;
-                       /* Indirect data */
-                       *command_ptr++ = 0;
-                       /* the (X, Y) term of scoreboard */
-                       *command_ptr++ = ((y_inner << 16) | x_inner);
-                       *command_ptr++ = score_dep;
-
-                       /*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));
-                       x_inner -= 2;
-                       y_inner += 1;
-               }
-               x_outer += 1;
-       }
-
-       x_outer = mb_width - 2;
-       y_outer = first_mb / mb_width;
-       temp = 0;
-       for (;!loop_in_bounds(x_outer, y_outer, first_mb, num_mb, mb_width, mb_height); ) { 
-               y_inner = y_outer;
-               x_inner = x_outer;
-               for (; !loop_in_bounds(x_inner, y_inner, first_mb, num_mb, mb_width, mb_height);) {
-                       mb_intra_ub = 0;
-                       score_dep = 0;
-                       if (x_inner != 0) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_AE;
-                               score_dep |= MB_SCOREBOARD_A; 
-                       }
-                       if (y_inner != mb_row) {
-                               mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_B;
-                               score_dep |= MB_SCOREBOARD_B;
-                               if (x_inner != 0)
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_D;
-                               if (x_inner != (mb_width -1)) {
-                                       mb_intra_ub |= INTRA_PRED_AVAIL_FLAG_C;
-                                       score_dep |= MB_SCOREBOARD_C;
-                               }
-                       }
-
-                       *command_ptr++ = (CMD_MEDIA_OBJECT | (8 - 2));
-                       *command_ptr++ = kernel;
-                       *command_ptr++ = USE_SCOREBOARD;
-                       /* Indirect data */
-                       *command_ptr++ = 0;
-                       /* the (X, Y) term of scoreboard */
-                       *command_ptr++ = ((y_inner << 16) | x_inner);
-                       *command_ptr++ = score_dep;
-
-                       /*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));
-
-                       x_inner -= 2;
-                       y_inner += 1;
-               }
-               temp++;
-               if (temp == 2) {
-                       y_outer += 1;
-                       temp = 0;
-                       x_outer = mb_width - 2;
-               } else {
-                       x_outer++;
-               }       
-       }
-    }
-
-    *command_ptr++ = 0;
-    *command_ptr++ = MI_BATCH_BUFFER_END;
-
-    dri_bo_unmap(vme_context->vme_batchbuffer.bo);
-}
 
 static void gen7_vme_media_init(VADriverContextP ctx, struct intel_encoder_context *encoder_context)
 {
@@ -1219,24 +1068,7 @@ Bool gen7_vme_context_init(VADriverContextP ctx, struct intel_encoder_context *e
     vme_context->gpe_context.vfe_state.urb_entry_size = 59 - 1;
     vme_context->gpe_context.vfe_state.curbe_allocation_size = CURBE_ALLOCATION_SIZE - 1;
 
-    vme_context->gpe_context.vfe_desc5.scoreboard0.enable = 1;
-    vme_context->gpe_context.vfe_desc5.scoreboard0.type = SCOREBOARD_STALLING;
-    vme_context->gpe_context.vfe_desc5.scoreboard0.mask = (MB_SCOREBOARD_A |
-                                                               MB_SCOREBOARD_B |
-                                                               MB_SCOREBOARD_C);
-
-    /* In VME prediction the current mb depends on the neighbour 
-     * A/B/C macroblock. So the left/up/up-right dependency should
-     * be considered.
-     */
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x0 = -1;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y0 = 0;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x1 = 0;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y1 = -1;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_x2 = 1;
-    vme_context->gpe_context.vfe_desc6.scoreboard1.delta_y2 = -1;
-       
-    vme_context->gpe_context.vfe_desc7.dword = 0;
+    gen7_vme_scoreboard_init(ctx, vme_context);
 
     if(encoder_context->profile == VAProfileH264Baseline ||
        encoder_context->profile == VAProfileH264Main     ||