[Libva] [PATCH 1/4] decoder: factor out frame store context.

Gwenole Beauchesne gb.devel at gmail.com
Mon Jun 2 10:58:39 PDT 2014


Introduce new frame store context (GenFrameStoreContext) that holds
the existing reference frames. This is in view to simplifying the
tracking of used or retired frames.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/gen6_mfd.c           |   45 +++++++++++-----------------
 src/gen6_mfd.h           |    2 +-
 src/gen75_mfd.c          |   74 +++++++++++++++++++---------------------------
 src/gen7_mfd.c           |   44 +++++++++++----------------
 src/gen7_mfd.h           |    2 +-
 src/gen8_mfd.c           |   46 ++++++++++++----------------
 src/i965_avc_bsd.c       |   24 ++++++++-------
 src/i965_decoder.h       |    8 +++++
 src/i965_decoder_utils.c |   13 ++++++++
 src/i965_media_h264.c    |   16 +++++-----
 src/i965_media_h264.h    |    3 +-
 11 files changed, 128 insertions(+), 149 deletions(-)

diff --git a/src/gen6_mfd.c b/src/gen6_mfd.c
index 327056e..dbdebbc 100755
--- a/src/gen6_mfd.c
+++ b/src/gen6_mfd.c
@@ -199,14 +199,11 @@ gen6_mfd_pipe_buf_addr_state(VADriverContextP ctx,
         OUT_BCS_BATCH(batch, 0);
 
     /* DW 7..22 */
-    for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->reference_surface); i++) {
-        struct object_surface *obj_surface;
-
-        if (gen6_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen6_mfd_context->reference_surface[i].obj_surface &&
-            gen6_mfd_context->reference_surface[i].obj_surface->bo) {
-            obj_surface = gen6_mfd_context->reference_surface[i].obj_surface;
+    for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->fsc.used_frames); i++) {
+        struct object_surface * const obj_surface =
+            gen6_mfd_context->fsc.used_frames[i].obj_surface;
 
+        if (obj_surface && obj_surface->bo) {
             OUT_BCS_RELOC(batch, obj_surface->bo,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
                           0);
@@ -426,12 +423,10 @@ gen6_mfd_avc_directmode_state(VADriverContextP ctx,
     OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2));
 
     /* reference surfaces 0..15 */
-    for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->reference_surface); i++) {
-        if (gen6_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen6_mfd_context->reference_surface[i].obj_surface &&
-            gen6_mfd_context->reference_surface[i].obj_surface->private_data) {
+    for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen6_mfd_context->fsc.used_frames[i].obj_surface;
 
-            obj_surface = gen6_mfd_context->reference_surface[i].obj_surface;
+        if (obj_surface && obj_surface->private_data) {
             gen6_avc_surface = obj_surface->private_data;
             OUT_BCS_RELOC(batch, gen6_avc_surface->dmv_top,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
@@ -471,11 +466,11 @@ gen6_mfd_avc_directmode_state(VADriverContextP ctx,
                       0);
 
     /* POC List */
-    for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->reference_surface); i++) {
-        if (gen6_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
-            int found = 0;
+    for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen6_mfd_context->fsc.used_frames[i].obj_surface;
 
-            assert(gen6_mfd_context->reference_surface[i].obj_surface != NULL);
+        if (obj_surface) {
+            int found = 0;
 
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -483,7 +478,7 @@ gen6_mfd_avc_directmode_state(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == gen6_mfd_context->reference_surface[i].surface_id) {
+                if (va_pic->picture_id == obj_surface->base.id) {
                     found = 1;
                     break;
                 }
@@ -666,7 +661,7 @@ gen6_mfd_avc_ref_idx_state(VADriverContextP ctx,
     gen6_send_avc_ref_idx_state(
         gen6_mfd_context->base.batch,
         slice_param,
-        gen6_mfd_context->reference_surface
+        gen6_mfd_context->fsc.used_frames
     );
 }
 
@@ -837,7 +832,8 @@ gen6_mfd_avc_decode_init(VADriverContextP ctx,
 
     assert(decode_state->pic_param && decode_state->pic_param->buffer);
     pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
-    intel_update_avc_frame_store_index(ctx, decode_state, pic_param, gen6_mfd_context->reference_surface);
+    intel_update_avc_frame_store_index(ctx, decode_state, pic_param,
+        gen6_mfd_context->fsc.used_frames);
     width_in_mbs = ((pic_param->picture_width_in_mbs_minus1 + 1) & 0xff);
 
     /* Current decoded picture */
@@ -982,7 +978,7 @@ gen6_mfd_mpeg2_decode_init(VADriverContextP ctx,
 
     mpeg2_set_reference_surfaces(
         ctx,
-        gen6_mfd_context->reference_surface,
+        gen6_mfd_context->fsc.used_frames,
         decode_state,
         pic_param
     );
@@ -1298,7 +1294,7 @@ gen6_mfd_vc1_decode_init(VADriverContextP ctx,
     intel_update_vc1_frame_store_index(ctx,
                                        decode_state,
                                        pic_param,
-                                       gen6_mfd_context->reference_surface);
+                                       gen6_mfd_context->fsc.used_frames);
 
     /* Current decoded picture */
     obj_surface = decode_state->render_object;
@@ -1927,17 +1923,12 @@ gen6_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
 {
     struct intel_driver_data *intel = intel_driver_data(ctx);
     struct gen6_mfd_context *gen6_mfd_context = calloc(1, sizeof(struct gen6_mfd_context));
-    int i;
 
     gen6_mfd_context->base.destroy = gen6_mfd_context_destroy;
     gen6_mfd_context->base.run = gen6_mfd_decode_picture;
     gen6_mfd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER, 0);
 
-    for (i = 0; i < ARRAY_ELEMS(gen6_mfd_context->reference_surface); i++) {
-        gen6_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
-        gen6_mfd_context->reference_surface[i].frame_store_id = -1;
-        gen6_mfd_context->reference_surface[i].obj_surface = NULL;
-    }
+    gen_frame_store_context_init(&gen6_mfd_context->fsc);
 
     gen6_mfd_context->wa_mpeg2_slice_vertical_position = -1;
     
diff --git a/src/gen6_mfd.h b/src/gen6_mfd.h
index de131d6..ae7689f 100644
--- a/src/gen6_mfd.h
+++ b/src/gen6_mfd.h
@@ -62,7 +62,7 @@ struct gen6_mfd_context
         VAIQMatrixBufferMPEG2 mpeg2;
     } iq_matrix;
 
-    GenFrameStore       reference_surface[MAX_GEN_REFERENCE_FRAMES];
+    GenFrameStoreContext fsc;
     GenBuffer           post_deblocking_output;
     GenBuffer           pre_deblocking_output;
     GenBuffer           intra_row_store_scratch_buffer;
diff --git a/src/gen75_mfd.c b/src/gen75_mfd.c
index a0311d9..be481c6 100644
--- a/src/gen75_mfd.c
+++ b/src/gen75_mfd.c
@@ -231,14 +231,11 @@ gen75_mfd_pipe_buf_addr_state_bplus(VADriverContextP ctx,
 	OUT_BCS_BATCH(batch, 0);
 
     /* DW 19..50 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        struct object_surface *obj_surface;
-
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->bo) {
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        struct object_surface * const obj_surface =
+            gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
+        if (obj_surface && obj_surface->bo) {
             OUT_BCS_RELOC(batch, obj_surface->bo,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
                           0);
@@ -315,14 +312,11 @@ gen75_mfd_pipe_buf_addr_state(VADriverContextP ctx,
         OUT_BCS_BATCH(batch, 0);
 
     /* DW 7..22 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        struct object_surface *obj_surface;
-
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->bo) {
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        struct object_surface * const obj_surface =
+            gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
+        if (obj_surface && obj_surface->bo) {
             OUT_BCS_RELOC(batch, obj_surface->bo,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
                           0);
@@ -670,13 +664,12 @@ gen75_mfd_avc_directmode_state_bplus(VADriverContextP ctx,
     OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (71 - 2));
 
     /* reference surfaces 0..15 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->private_data) {
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+        if (obj_surface && obj_surface->private_data) {
             gen7_avc_surface = obj_surface->private_data;
+
             OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
                           0);
@@ -703,11 +696,11 @@ gen75_mfd_avc_directmode_state_bplus(VADriverContextP ctx,
     OUT_BCS_BATCH(batch, 0);
 
     /* POC List */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
-            int found = 0;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            assert(gen7_mfd_context->reference_surface[i].obj_surface != NULL);
+        if (obj_surface) {
+            int found = 0;
 
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -715,7 +708,7 @@ gen75_mfd_avc_directmode_state_bplus(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == gen7_mfd_context->reference_surface[i].surface_id) {
+                if (va_pic->picture_id == obj_surface->base.id) {
                     found = 1;
                     break;
                 }
@@ -764,12 +757,10 @@ gen75_mfd_avc_directmode_state(VADriverContextP ctx,
     OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2));
 
     /* reference surfaces 0..15 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->private_data) {
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+        if (obj_surface && obj_surface->private_data) {
             gen7_avc_surface = obj_surface->private_data;
 
             OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
@@ -810,11 +801,11 @@ gen75_mfd_avc_directmode_state(VADriverContextP ctx,
                       0);
 
     /* POC List */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
-            int found = 0;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            assert(gen7_mfd_context->reference_surface[i].obj_surface != NULL);
+        if (obj_surface) {
+            int found = 0;
 
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -822,7 +813,7 @@ gen75_mfd_avc_directmode_state(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == gen7_mfd_context->reference_surface[i].surface_id) {
+                if (va_pic->picture_id == obj_surface->base.id) {
                     found = 1;
                     break;
                 }
@@ -941,7 +932,7 @@ gen75_mfd_avc_ref_idx_state(VADriverContextP ctx,
     gen6_send_avc_ref_idx_state(
         gen7_mfd_context->base.batch,
         slice_param,
-        gen7_mfd_context->reference_surface
+        gen7_mfd_context->fsc.used_frames
     );
 }
 
@@ -1078,7 +1069,7 @@ gen75_mfd_avc_decode_init(VADriverContextP ctx,
 
     assert(decode_state->pic_param && decode_state->pic_param->buffer);
     pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
-    intel_update_avc_frame_store_index(ctx, decode_state, pic_param, gen7_mfd_context->reference_surface);
+    intel_update_avc_frame_store_index(ctx, decode_state, pic_param, gen7_mfd_context->fsc.used_frames);
     width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
     height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1;
     assert(width_in_mbs > 0 && width_in_mbs <= 256); /* 4K */
@@ -1222,7 +1213,7 @@ gen75_mfd_mpeg2_decode_init(VADriverContextP ctx,
 
     mpeg2_set_reference_surfaces(
         ctx,
-        gen7_mfd_context->reference_surface,
+        gen7_mfd_context->fsc.used_frames,
         decode_state,
         pic_param
     );
@@ -1561,7 +1552,7 @@ gen75_mfd_vc1_decode_init(VADriverContextP ctx,
     intel_update_vc1_frame_store_index(ctx,
                                        decode_state,
                                        pic_param,
-                                       gen7_mfd_context->reference_surface);
+                                       gen7_mfd_context->fsc.used_frames);
 
     /* Current decoded picture */
     obj_surface = decode_state->render_object;
@@ -3256,17 +3247,12 @@ gen75_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config
 {
     struct intel_driver_data *intel = intel_driver_data(ctx);
     struct gen7_mfd_context *gen7_mfd_context = calloc(1, sizeof(struct gen7_mfd_context));
-    int i;
 
     gen7_mfd_context->base.destroy = gen75_mfd_context_destroy;
     gen7_mfd_context->base.run = gen75_mfd_decode_picture;
     gen7_mfd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER, 0);
 
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        gen7_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
-        gen7_mfd_context->reference_surface[i].frame_store_id = -1;
-        gen7_mfd_context->reference_surface[i].obj_surface = NULL;
-    }
+    gen_frame_store_context_init(&gen7_mfd_context->fsc);
 
     gen7_mfd_context->jpeg_wa_surface_id = VA_INVALID_SURFACE;
     gen7_mfd_context->jpeg_wa_surface_object = NULL;
diff --git a/src/gen7_mfd.c b/src/gen7_mfd.c
index 3379b40..19cf1d9 100755
--- a/src/gen7_mfd.c
+++ b/src/gen7_mfd.c
@@ -211,14 +211,11 @@ gen7_mfd_pipe_buf_addr_state(VADriverContextP ctx,
         OUT_BCS_BATCH(batch, 0);
 
     /* DW 7..22 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        struct object_surface *obj_surface;
-
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->bo) {
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        struct object_surface * const obj_surface =
+            gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
+        if (obj_surface && obj_surface->bo) {
             OUT_BCS_RELOC(batch, obj_surface->bo,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
                           0);
@@ -435,12 +432,10 @@ gen7_mfd_avc_directmode_state(VADriverContextP ctx,
     OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (69 - 2));
 
     /* reference surfaces 0..15 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->private_data) {
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+        if (obj_surface && obj_surface->private_data) {
             gen7_avc_surface = obj_surface->private_data;
             OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
@@ -480,11 +475,11 @@ gen7_mfd_avc_directmode_state(VADriverContextP ctx,
                       0);
 
     /* POC List */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
-            int found = 0;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            assert(gen7_mfd_context->reference_surface[i].obj_surface != NULL);
+        if (obj_surface) {
+            int found = 0;
 
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -492,7 +487,7 @@ gen7_mfd_avc_directmode_state(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == gen7_mfd_context->reference_surface[i].surface_id) {
+                if (va_pic->picture_id == gen7_mfd_context->fsc.used_frames[i].surface_id) {
                     found = 1;
                     break;
                 }
@@ -611,7 +606,7 @@ gen7_mfd_avc_ref_idx_state(VADriverContextP ctx,
     gen6_send_avc_ref_idx_state(
         gen7_mfd_context->base.batch,
         slice_param,
-        gen7_mfd_context->reference_surface
+        gen7_mfd_context->fsc.used_frames
     );
 }
 
@@ -752,7 +747,7 @@ gen7_mfd_avc_decode_init(VADriverContextP ctx,
 
     assert(decode_state->pic_param && decode_state->pic_param->buffer);
     pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
-    intel_update_avc_frame_store_index(ctx, decode_state, pic_param, gen7_mfd_context->reference_surface);
+    intel_update_avc_frame_store_index(ctx, decode_state, pic_param, gen7_mfd_context->fsc.used_frames);
     width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
     height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1;
     assert(width_in_mbs > 0 && width_in_mbs <= 256); /* 4K */
@@ -895,7 +890,7 @@ gen7_mfd_mpeg2_decode_init(VADriverContextP ctx,
 
     mpeg2_set_reference_surfaces(
         ctx,
-        gen7_mfd_context->reference_surface,
+        gen7_mfd_context->fsc.used_frames,
         decode_state,
         pic_param
     );
@@ -1239,7 +1234,7 @@ gen7_mfd_vc1_decode_init(VADriverContextP ctx,
     intel_update_vc1_frame_store_index(ctx,
                                        decode_state,
                                        pic_param,
-                                       gen7_mfd_context->reference_surface);
+                                       gen7_mfd_context->fsc.used_frames);
 
     /* Current decoded picture */
     obj_surface = decode_state->render_object;
@@ -2679,17 +2674,12 @@ gen7_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
 {
     struct intel_driver_data *intel = intel_driver_data(ctx);
     struct gen7_mfd_context *gen7_mfd_context = calloc(1, sizeof(struct gen7_mfd_context));
-    int i;
 
     gen7_mfd_context->base.destroy = gen7_mfd_context_destroy;
     gen7_mfd_context->base.run = gen7_mfd_decode_picture;
     gen7_mfd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER, 0);
 
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        gen7_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
-        gen7_mfd_context->reference_surface[i].frame_store_id = -1;
-        gen7_mfd_context->reference_surface[i].obj_surface = NULL;
-    }
+    gen_frame_store_context_init(&gen7_mfd_context->fsc);
 
     gen7_mfd_context->jpeg_wa_surface_id = VA_INVALID_SURFACE;
     gen7_mfd_context->jpeg_wa_surface_object = NULL;
diff --git a/src/gen7_mfd.h b/src/gen7_mfd.h
index 0200216..ef1b84a 100644
--- a/src/gen7_mfd.h
+++ b/src/gen7_mfd.h
@@ -77,7 +77,7 @@ struct gen7_mfd_context
         VAIQMatrixBufferH264  h264;     /* flat scaling lists (default) */
     } iq_matrix;
 
-    GenFrameStore       reference_surface[MAX_GEN_REFERENCE_FRAMES];
+    GenFrameStoreContext fsc;
     GenBuffer           post_deblocking_output;
     GenBuffer           pre_deblocking_output;
     GenBuffer           intra_row_store_scratch_buffer;
diff --git a/src/gen8_mfd.c b/src/gen8_mfd.c
index ac2e842..459c430 100644
--- a/src/gen8_mfd.c
+++ b/src/gen8_mfd.c
@@ -239,14 +239,11 @@ gen8_mfd_pipe_buf_addr_state(VADriverContextP ctx,
 	OUT_BCS_BATCH(batch, 0);
 
     /* DW 19..50 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        struct object_surface *obj_surface;
-
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->bo) {
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        struct object_surface * const obj_surface =
+            gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
+        if (obj_surface && obj_surface->bo) {
             OUT_BCS_RELOC(batch, obj_surface->bo,
                           I915_GEM_DOMAIN_INSTRUCTION, 0,
                           0);
@@ -537,12 +534,10 @@ gen8_mfd_avc_directmode_state(VADriverContextP ctx,
     OUT_BCS_BATCH(batch, MFX_AVC_DIRECTMODE_STATE | (71 - 2));
 
     /* reference surfaces 0..15 */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID &&
-            gen7_mfd_context->reference_surface[i].obj_surface &&
-            gen7_mfd_context->reference_surface[i].obj_surface->private_data) {
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            obj_surface = gen7_mfd_context->reference_surface[i].obj_surface;
+        if (obj_surface && obj_surface->private_data) {
             gen7_avc_surface = obj_surface->private_data;
 
             OUT_BCS_RELOC(batch, gen7_avc_surface->dmv_top,
@@ -571,11 +566,11 @@ gen8_mfd_avc_directmode_state(VADriverContextP ctx,
     OUT_BCS_BATCH(batch, 0);
 
     /* POC List */
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        if (gen7_mfd_context->reference_surface[i].surface_id != VA_INVALID_ID) {
-            int found = 0;
+    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->fsc.used_frames); i++) {
+        obj_surface = gen7_mfd_context->fsc.used_frames[i].obj_surface;
 
-            assert(gen7_mfd_context->reference_surface[i].obj_surface != NULL);
+        if (obj_surface) {
+            int found = 0;
 
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -583,7 +578,7 @@ gen8_mfd_avc_directmode_state(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == gen7_mfd_context->reference_surface[i].surface_id) {
+                if (va_pic->picture_id == obj_surface->base.id) {
                     found = 1;
                     break;
                 }
@@ -702,7 +697,7 @@ gen8_mfd_avc_ref_idx_state(VADriverContextP ctx,
     gen6_send_avc_ref_idx_state(
         gen7_mfd_context->base.batch,
         slice_param,
-        gen7_mfd_context->reference_surface
+        gen7_mfd_context->fsc.used_frames
     );
 }
 
@@ -839,7 +834,8 @@ gen8_mfd_avc_decode_init(VADriverContextP ctx,
 
     assert(decode_state->pic_param && decode_state->pic_param->buffer);
     pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
-    intel_update_avc_frame_store_index(ctx, decode_state, pic_param, gen7_mfd_context->reference_surface);
+    intel_update_avc_frame_store_index(ctx, decode_state, pic_param,
+        gen7_mfd_context->fsc.used_frames);
     width_in_mbs = pic_param->picture_width_in_mbs_minus1 + 1;
     height_in_mbs = pic_param->picture_height_in_mbs_minus1 + 1;
     assert(width_in_mbs > 0 && width_in_mbs <= 256); /* 4K */
@@ -983,7 +979,7 @@ gen8_mfd_mpeg2_decode_init(VADriverContextP ctx,
 
     mpeg2_set_reference_surfaces(
         ctx,
-        gen7_mfd_context->reference_surface,
+        gen7_mfd_context->fsc.used_frames,
         decode_state,
         pic_param
     );
@@ -1322,7 +1318,7 @@ gen8_mfd_vc1_decode_init(VADriverContextP ctx,
     intel_update_vc1_frame_store_index(ctx,
                                        decode_state,
                                        pic_param,
-                                       gen7_mfd_context->reference_surface);
+                                       gen7_mfd_context->fsc.used_frames);
 
     /* Current decoded picture */
     obj_surface = decode_state->render_object;
@@ -2765,7 +2761,7 @@ gen8_mfd_vp8_decode_init(VADriverContextP ctx,
     intel_update_vp8_frame_store_index(ctx,
                                        decode_state,
                                        pic_param,
-                                       gen7_mfd_context->reference_surface);
+                                       gen7_mfd_context->fsc.used_frames);
 
     /* Current decoded picture */
     obj_surface = decode_state->render_object;
@@ -3182,16 +3178,12 @@ gen8_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config)
 {
     struct intel_driver_data *intel = intel_driver_data(ctx);
     struct gen7_mfd_context *gen7_mfd_context = calloc(1, sizeof(struct gen7_mfd_context));
-    int i;
 
     gen7_mfd_context->base.destroy = gen8_mfd_context_destroy;
     gen7_mfd_context->base.run = gen8_mfd_decode_picture;
     gen7_mfd_context->base.batch = intel_batchbuffer_new(intel, I915_EXEC_RENDER, 0);
 
-    for (i = 0; i < ARRAY_ELEMS(gen7_mfd_context->reference_surface); i++) {
-        gen7_mfd_context->reference_surface[i].surface_id = VA_INVALID_ID;
-        gen7_mfd_context->reference_surface[i].frame_store_id = -1;
-    }
+    gen_frame_store_context_init(&gen7_mfd_context->fsc);
 
     gen7_mfd_context->jpeg_wa_surface_id = VA_INVALID_SURFACE;
     gen7_mfd_context->segmentation_buffer.valid = 0;
diff --git a/src/i965_avc_bsd.c b/src/i965_avc_bsd.c
index ef0bc13..d2c70f6 100644
--- a/src/i965_avc_bsd.c
+++ b/src/i965_avc_bsd.c
@@ -293,7 +293,7 @@ i965_avc_bsd_slice_state(VADriverContextP ctx,
         gen5_fill_avc_ref_idx_state(
             ref_idx_state,
             va_pic, num_va_pics,
-            i965_h264_context->fsid_list
+            i965_h264_context->fs_context.used_frames
         );            
         intel_batchbuffer_data(batch, ref_idx_state, sizeof(ref_idx_state));
     }
@@ -407,10 +407,10 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx,
     else
         OUT_BCS_BATCH(batch, 0);
 
-    for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fsid_list); i++) {
-        if (i965_h264_context->fsid_list[i].surface_id != VA_INVALID_ID &&
-            i965_h264_context->fsid_list[i].obj_surface &&
-            i965_h264_context->fsid_list[i].obj_surface->private_data) {
+    for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fs_context.used_frames); i++) {
+        obj_surface = i965_h264_context->fs_context.used_frames[i].obj_surface;
+
+        if (obj_surface && obj_surface->private_data) {
             int found = 0;
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -418,14 +418,13 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == i965_h264_context->fsid_list[i].surface_id) {
+                if (va_pic->picture_id == obj_surface->base.id) {
                     found = 1;
                     break;
                 }
             }
 
             assert(found == 1);
-            obj_surface = i965_h264_context->fsid_list[i].obj_surface;
             avc_bsd_surface = obj_surface->private_data;
             
             OUT_BCS_RELOC(batch, avc_bsd_surface->dmv_top,
@@ -481,8 +480,10 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx,
                       0);
 
     /* POC List */
-    for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fsid_list); i++) {
-        if (i965_h264_context->fsid_list[i].surface_id != VA_INVALID_ID) {
+    for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fs_context.used_frames); i++) {
+        obj_surface = i965_h264_context->fs_context.used_frames[i].obj_surface;
+
+        if (obj_surface) {
             int found = 0;
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -490,7 +491,7 @@ i965_avc_bsd_buf_base_state(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == i965_h264_context->fsid_list[i].surface_id) {
+                if (va_pic->picture_id == obj_surface->base.id) {
                     found = 1;
                     break;
                 }
@@ -821,7 +822,8 @@ i965_avc_bsd_pipeline(VADriverContextP ctx, struct decode_state *decode_state, v
 
     assert(decode_state->pic_param && decode_state->pic_param->buffer);
     pic_param = (VAPictureParameterBufferH264 *)decode_state->pic_param->buffer;
-    intel_update_avc_frame_store_index(ctx, decode_state, pic_param, i965_h264_context->fsid_list);
+    intel_update_avc_frame_store_index(ctx, decode_state, pic_param,
+        i965_h264_context->fs_context.used_frames);
 
     i965_h264_context->enable_avc_ildb = 0;
     i965_h264_context->picture.i_flag = 1;
diff --git a/src/i965_decoder.h b/src/i965_decoder.h
index 01c093f..fbf1d20 100644
--- a/src/i965_decoder.h
+++ b/src/i965_decoder.h
@@ -41,12 +41,20 @@ struct gen_frame_store {
     struct      object_surface *obj_surface;
 };
 
+typedef struct gen_frame_store_context GenFrameStoreContext;
+struct gen_frame_store_context {
+    GenFrameStore used_frames[MAX_GEN_REFERENCE_FRAMES];
+};
+
 typedef struct gen_buffer GenBuffer;
 struct gen_buffer {
     dri_bo     *bo;
     int         valid;
 };
 
+void
+gen_frame_store_context_init(GenFrameStoreContext *fsc);
+
 struct hw_context *
 gen75_dec_hw_context_init(VADriverContextP ctx, struct object_config *obj_config);
 
diff --git a/src/i965_decoder_utils.c b/src/i965_decoder_utils.c
index 98d31c3..b834a0e 100644
--- a/src/i965_decoder_utils.c
+++ b/src/i965_decoder_utils.c
@@ -421,6 +421,19 @@ gen6_send_avc_ref_idx_state(
 }
 
 void
+gen_frame_store_context_init(GenFrameStoreContext *fsc)
+{
+    int i;
+
+    for (i = 0; i < ARRAY_ELEMS(fsc->used_frames); i++) {
+        GenFrameStore * const fs = &fsc->used_frames[i];
+        fs->surface_id = VA_INVALID_ID;
+        fs->obj_surface = NULL;
+        fs->frame_store_id = -1;
+    }
+}
+
+void
 intel_update_avc_frame_store_index(
     VADriverContextP              ctx,
     struct decode_state          *decode_state,
diff --git a/src/i965_media_h264.c b/src/i965_media_h264.c
index 9de4e09..b291886 100644
--- a/src/i965_media_h264.c
+++ b/src/i965_media_h264.c
@@ -374,9 +374,11 @@ i965_media_h264_surfaces_setup(VADriverContextP ctx,
                                   media_context);
 
     /* Reference Pictures */
-    for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fsid_list); i++) {
-        if (i965_h264_context->fsid_list[i].surface_id != VA_INVALID_ID &&
-            i965_h264_context->fsid_list[i].obj_surface != NULL) {
+    for (i = 0; i < ARRAY_ELEMS(i965_h264_context->fs_context.used_frames); i++) {
+        struct object_surface * const obj_surface =
+            i965_h264_context->fs_context.used_frames[i].obj_surface;
+
+        if (obj_surface) {
             int found = 0;
             for (j = 0; j < ARRAY_ELEMS(pic_param->ReferenceFrames); j++) {
                 va_pic = &pic_param->ReferenceFrames[j];
@@ -384,7 +386,7 @@ i965_media_h264_surfaces_setup(VADriverContextP ctx,
                 if (va_pic->flags & VA_PICTURE_H264_INVALID)
                     continue;
 
-                if (va_pic->picture_id == i965_h264_context->fsid_list[i].surface_id) {
+                if (va_pic->picture_id == obj_surface->base.id) {
                     found = 1;
                     break;
                 }
@@ -392,7 +394,6 @@ i965_media_h264_surfaces_setup(VADriverContextP ctx,
 
             assert(found == 1);
 
-            obj_surface = i965_h264_context->fsid_list[i].obj_surface;
             w = obj_surface->width;
             h = obj_surface->height;
             field_picture = !!(va_pic->flags & (VA_PICTURE_H264_TOP_FIELD | VA_PICTURE_H264_BOTTOM_FIELD));
@@ -875,10 +876,7 @@ i965_media_h264_dec_context_init(VADriverContextP ctx, struct i965_media_context
         dri_bo_subdata(kernel->bo, 0, kernel->size, kernel->bin);
     }
 
-    for (i = 0; i < 16; i++) {
-        i965_h264_context->fsid_list[i].surface_id = VA_INVALID_ID;
-        i965_h264_context->fsid_list[i].frame_store_id = -1;
-    }
+    gen_frame_store_context_init(&i965_h264_context->fs_context);
 
     i965_h264_context->batch = media_context->base.batch;
 
diff --git a/src/i965_media_h264.h b/src/i965_media_h264.h
index 490213c..7d879a4 100644
--- a/src/i965_media_h264.h
+++ b/src/i965_media_h264.h
@@ -57,12 +57,11 @@ struct i965_h264_context
     char weight128_offset0_flag;
     short weight128_offset0;
 
+    GenFrameStoreContext fs_context;
     struct i965_avc_bsd_context i965_avc_bsd_context;
     struct i965_avc_hw_scoreboard_context avc_hw_scoreboard_context;
     struct i965_avc_ildb_context avc_ildb_context;
 
-    GenFrameStore fsid_list[MAX_GEN_REFERENCE_FRAMES];
-
     struct i965_kernel avc_kernels[NUM_H264_AVC_KERNELS];
     struct intel_batchbuffer *batch;
 };
-- 
1.7.9.5



More information about the Libva mailing list