[Libva] [PATCH] vc1: fix and optimize bitplane data buffer layout (IVB).

Gwenole Beauchesne gb.devel at gmail.com
Thu Oct 18 10:12:30 PDT 2012


The layout of the bitplane data buffer is clearly defined by VA-API.
By strictly following the specification, we can directly upload the
user-provided bitplane data buffer to the GPU without extra buffer
processing. This also fixes odd-sized videos.

I have also tested this on SNB, in a separate patch. Pending platforms
are ILK and HSW.

Note: this requires FFmpeg and GStreamer/VA-API changes that I will
push at the same time as this one. This change only affects the Intel
HD Graphics driver. Others don't care of the bitplanes anyway; they
parse the bitstream themselves. i.e. compatibillity with PowerVR,
NVIDIA and AMD drivers is maintained.

This is not meant to be pushed right away, just reviewing, as other
patches are coming along.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/gen7_mfd.c |   39 ++++++---------------------------------
 1 file changed, 6 insertions(+), 33 deletions(-)

diff --git a/src/gen7_mfd.c b/src/gen7_mfd.c
index 852fb03..bad192f 100755
--- a/src/gen7_mfd.c
+++ b/src/gen7_mfd.c
@@ -1443,47 +1443,20 @@ gen7_mfd_vc1_decode_init(VADriverContextP ctx,
     dri_bo_unreference(gen7_mfd_context->bitplane_read_buffer.bo);
     
     if (gen7_mfd_context->bitplane_read_buffer.valid) {
-        int width_in_mbs = ALIGN(pic_param->coded_width, 16) / 16;
-        int height_in_mbs = ALIGN(pic_param->coded_height, 16) / 16;
-        int bitplane_width = ALIGN(width_in_mbs, 2) / 2;
-        int src_w, src_h;
-        uint8_t *src = NULL, *dst = NULL;
+        const int width_in_mbs  = ALIGN(pic_param->coded_width,  16) / 16;
+        const int height_in_mbs = ALIGN(pic_param->coded_height, 16) / 16;
+        const int bitplane_size = height_in_mbs * (width_in_mbs + 1) / 2;
 
+        /* XXX: validate size of buffer store */
         assert(decode_state->bit_plane->buffer);
-        src = decode_state->bit_plane->buffer;
 
         bo = dri_bo_alloc(i965->intel.bufmgr,
                           "VC-1 Bitplane",
-                          bitplane_width * height_in_mbs,
+                          bitplane_size,
                           0x1000);
         assert(bo);
         gen7_mfd_context->bitplane_read_buffer.bo = bo;
-
-        dri_bo_map(bo, True);
-        assert(bo->virtual);
-        dst = bo->virtual;
-
-        for (src_h = 0; src_h < height_in_mbs; src_h++) {
-            for(src_w = 0; src_w < width_in_mbs; src_w++) {
-                int src_index, dst_index;
-                int src_shift;
-                uint8_t src_value;
-
-                src_index = (src_h * width_in_mbs + src_w) / 2;
-                src_shift = !((src_h * width_in_mbs + src_w) & 1) * 4;
-                src_value = ((src[src_index] >> src_shift) & 0xf);
-
-                dst_index = src_w / 2;
-                dst[dst_index] = ((dst[dst_index] >> 4) | (src_value << 4));
-            }
-
-            if (src_w & 1)
-                dst[src_w / 2] >>= 4;
-
-            dst += bitplane_width;
-        }
-
-        dri_bo_unmap(bo);
+        dri_bo_subdata(bo, 0, bitplane_size, decode_state->bit_plane->buffer);
     } else
         gen7_mfd_context->bitplane_read_buffer.bo = NULL;
 }
-- 
1.7.9.5



More information about the Libva mailing list