[Libva] [PATCH 2/4] add rgbx->nv12 conversion in post-processing

Zhao Halley halley.zhao at intel.com
Thu Jul 12 22:41:43 PDT 2012


---
 src/i965_drv_video.c       |   78 ++++++++++++++++++++++++++++++---
 src/i965_post_processing.c |  104 +++++++++++++++++++++++++++++++++++++++++--
 src/i965_post_processing.h |    3 +-
 3 files changed, 173 insertions(+), 12 deletions(-)

diff --git a/src/i965_drv_video.c b/src/i965_drv_video.c
index 41f8b0f..ac5a1f1 100755
--- a/src/i965_drv_video.c
+++ b/src/i965_drv_video.c
@@ -2073,10 +2073,11 @@ i965_CreateImage(VADriverContextP ctx,
         image->component_order[1]  = 'G';
         image->component_order[2]  = 'B';
         break;
-    case VA_FOURCC('A','R','G','B'):
-    case VA_FOURCC('A','B','G','R'):
     case VA_FOURCC('B','G','R','A'):
     case VA_FOURCC('R','G','B','A'):
+    case VA_FOURCC('B','G','R','X'):
+    case VA_FOURCC('R','G','B','X'):
+    case VA_FOURCC('A','Y','U','V'):
         image->num_planes = 1;
         image->pitches[0] = width * 4;
         image->offsets[0] = 0;
@@ -2172,7 +2173,12 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
         assert(fourcc == VA_FOURCC('N', 'V', '1', '2') ||
                fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
                fourcc == VA_FOURCC('I', 'M', 'C', '3') || 
-               fourcc == VA_FOURCC('Y','U', 'Y', '2'));
+               fourcc == VA_FOURCC('A', 'Y', 'U', 'V') || 
+               fourcc == VA_FOURCC('R', 'G', 'B', 'A') || 
+               fourcc == VA_FOURCC('R', 'G', 'B', 'X') || 
+               fourcc == VA_FOURCC('B', 'G', 'R', 'A') || 
+               fourcc == VA_FOURCC('B', 'G', 'R', 'X') || 
+               fourcc == VA_FOURCC('Y', 'U', 'Y', '2'));
 
         obj_surface->width = ALIGN(obj_surface->orig_width, 128);
         obj_surface->height = ALIGN(obj_surface->orig_height, 32);
@@ -2188,6 +2194,14 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             obj_surface->cb_cr_pitch = obj_surface->width * 2;
             region_width = obj_surface->width * 2;
         }
+        else if (fourcc == VA_FOURCC('A', 'Y', 'U', 'V') || 
+                 fourcc == VA_FOURCC('R', 'G', 'B', 'A') || 
+                 fourcc == VA_FOURCC('R', 'G', 'B', 'X') || 
+                 fourcc == VA_FOURCC('B', 'G', 'R', 'A') || 
+                 fourcc == VA_FOURCC('B', 'G', 'R', 'X')) {
+            obj_surface->cb_cr_pitch = obj_surface->width * 4;
+            region_width = obj_surface->width * 4;
+        }
         else {
             assert(0);
         }
@@ -2202,7 +2216,12 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             region_height = obj_surface->height + ALIGN(obj_surface->cb_cr_height, 32);
         } else if (fourcc == VA_FOURCC('I', 'M', 'C', '1') ||
                    fourcc == VA_FOURCC('I', 'M', 'C', '3') ||
-                   fourcc == VA_FOURCC('Y','U', 'Y', '2')) {
+                   fourcc == VA_FOURCC('A', 'Y', 'U', 'V') || 
+                   fourcc == VA_FOURCC('R', 'G', 'B', 'A') || 
+                   fourcc == VA_FOURCC('R', 'G', 'B', 'X') || 
+                   fourcc == VA_FOURCC('B', 'G', 'R', 'A') || 
+                   fourcc == VA_FOURCC('B', 'G', 'R', 'X') || 
+                   fourcc == VA_FOURCC('Y', 'U', 'Y', '2')) {
             switch (subsampling) {
             case SUBSAMPLE_YUV400:
                 obj_surface->cb_cr_width = 0;
@@ -2253,6 +2272,15 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
                 obj_surface->y_cr_offset = 0; 
                 region_height = obj_surface->height;
             }
+            else if (fourcc == VA_FOURCC('A', 'Y', 'U', 'V') || 
+                     fourcc == VA_FOURCC('R', 'G', 'B', 'A') || 
+                     fourcc == VA_FOURCC('R', 'G', 'B', 'X') || 
+                     fourcc == VA_FOURCC('B', 'G', 'R', 'A') || 
+                     fourcc == VA_FOURCC('B', 'G', 'R', 'X')) {
+                obj_surface->y_cb_offset = 0; 
+                obj_surface->y_cr_offset = 0; 
+                region_height = obj_surface->height;
+            }
         }
     } else {
         assert(fourcc != VA_FOURCC('I', 'M', 'C', '1') &&
@@ -2297,6 +2325,19 @@ i965_check_alloc_surface_bo(VADriverContextP ctx,
             region_width = obj_surface->width * 2;
             region_height = obj_surface->height;
             break;
+        case VA_FOURCC('A', 'Y', 'U', 'V'):
+        case VA_FOURCC('R', 'G', 'B', 'A'):
+        case VA_FOURCC('R', 'G', 'B', 'X'):
+        case VA_FOURCC('B', 'G', 'R', 'A'):
+        case VA_FOURCC('B', 'G', 'R', 'X'):
+            obj_surface->y_cb_offset = 0;
+            obj_surface->y_cr_offset = 0;
+            obj_surface->cb_cr_width = obj_surface->orig_width ;
+            obj_surface->cb_cr_height = obj_surface->orig_height;
+            obj_surface->cb_cr_pitch = obj_surface->width * 4;
+            region_width = obj_surface->width * 4;
+            region_height = obj_surface->height;
+            break;
 
         default:
             assert(0);
@@ -2428,6 +2469,14 @@ VAStatus i965_DeriveImage(VADriverContextP ctx,
         image->pitches[2] = obj_surface->width * 2; /* V */
         image->offsets[2] = 0;
         break;
+    case VA_FOURCC('A', 'Y', 'U', 'V'):
+    case VA_FOURCC('R', 'G', 'B', 'A'):
+    case VA_FOURCC('R', 'G', 'B', 'X'):
+    case VA_FOURCC('B', 'G', 'R', 'A'):
+    case VA_FOURCC('B', 'G', 'R', 'X'):
+        image->num_planes = 1;
+        image->pitches[0] = obj_surface->width * 4;
+        break;
     default:
         goto error;
     }
@@ -2542,6 +2591,13 @@ get_sampling_from_fourcc(unsigned int fourcc)
     case VA_FOURCC('Y', 'U', 'Y', '2'):
         surface_sampling = SUBSAMPLE_YUV422H;
         break;
+    case VA_FOURCC('A','Y','U','V'):
+    case VA_FOURCC('R','G','B','A'):
+    case VA_FOURCC('R','G','B','X'):
+    case VA_FOURCC('B','G','R','A'):
+    case VA_FOURCC('B','G','R','X'):
+    surface_sampling = SUBSAMPLE_YUV444; 
+        break;
     default:
         break;
     }
@@ -3642,7 +3698,12 @@ i965_GetSurfaceAttributes(
                         if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2') &&
                             attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0') &&
                             attrib_list[i].value.value.i != VA_FOURCC('Y', 'V', '1', '2') && 
-                            attrib_list[i].value.value.i != VA_FOURCC('Y', 'U', 'Y', '2')) {
+                            attrib_list[i].value.value.i != VA_FOURCC('Y', 'U', 'Y', '2') &&
+                            attrib_list[i].value.value.i != VA_FOURCC('A', 'Y', 'U', 'V') && 
+                            attrib_list[i].value.value.i != VA_FOURCC('B', 'G', 'R', 'A') &&
+                            attrib_list[i].value.value.i != VA_FOURCC('B', 'G', 'R', 'X') && 
+                            attrib_list[i].value.value.i != VA_FOURCC('R', 'G', 'B', 'X') && 
+                            attrib_list[i].value.value.i != VA_FOURCC('R', 'G', 'B', 'A')) {
                             attrib_list[i].value.value.i = 0;                            
                             attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                         }
@@ -3656,7 +3717,12 @@ i965_GetSurfaceAttributes(
                         if (attrib_list[i].value.value.i != VA_FOURCC('N', 'V', '1', '2') &&
                             attrib_list[i].value.value.i != VA_FOURCC('I', '4', '2', '0') &&
                             attrib_list[i].value.value.i != VA_FOURCC('Y', 'V', '1', '2') && 
-                            attrib_list[i].value.value.i != VA_FOURCC('Y', 'U', 'Y', '2')) {
+                            attrib_list[i].value.value.i != VA_FOURCC('Y', 'U', 'Y', '2') &&
+                            attrib_list[i].value.value.i != VA_FOURCC('A', 'Y', 'U', 'V') && 
+                            attrib_list[i].value.value.i != VA_FOURCC('B', 'G', 'R', 'A') &&
+                            attrib_list[i].value.value.i != VA_FOURCC('B', 'G', 'R', 'X') && 
+                            attrib_list[i].value.value.i != VA_FOURCC('R', 'G', 'B', 'X') && 
+                            attrib_list[i].value.value.i != VA_FOURCC('R', 'G', 'B', 'A')) {
                             attrib_list[i].value.value.i = 0;                            
                             attrib_list[i].flags &= ~VA_SURFACE_ATTRIB_SETTABLE;
                         }
diff --git a/src/i965_post_processing.c b/src/i965_post_processing.c
index b3d5f81..01d286b 100755
--- a/src/i965_post_processing.c
+++ b/src/i965_post_processing.c
@@ -107,6 +107,10 @@ static const uint32_t pp_pa_load_save_pl3_gen5[][4] = {
 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g4b.gen5"
 };
 
+static const uint32_t pp_rgbx_load_save_nv12_gen5[][4] = {
+#include "shaders/post_processing/gen5_6/rgbx_load_save_nv12.g4b.gen5"
+};
+
 static VAStatus pp_null_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
                                    const struct i965_surface *src_surface,
                                    const VARectangle *src_rect,
@@ -307,6 +311,18 @@ static struct pp_module pp_modules_gen5[] = {
         pp_plx_load_save_plx_initialize,
     },
 
+    {
+        {
+            "RGBX_NV12 module",
+            PP_RGBX_LOAD_SAVE_NV12,
+            pp_rgbx_load_save_nv12_gen5,
+            sizeof(pp_rgbx_load_save_nv12_gen5),
+            NULL,
+        },
+    
+        pp_plx_load_save_plx_initialize,
+    },
+            
 };
 
 static const uint32_t pp_null_gen6[][4] = {
@@ -361,6 +377,10 @@ static const uint32_t pp_pa_load_save_pl3_gen6[][4] = {
 #include "shaders/post_processing/gen5_6/pa_load_save_pl3.g6b"
 };
 
+static const uint32_t pp_rgbx_load_save_nv12_gen6[][4] = {
+#include "shaders/post_processing/gen5_6/rgbx_load_save_nv12.g6b"
+};
+
 static struct pp_module pp_modules_gen6[] = {
     {
         {
@@ -517,6 +537,18 @@ static struct pp_module pp_modules_gen6[] = {
         pp_plx_load_save_plx_initialize,
     },
     
+    {
+        {
+            "RGBX_NV12 module",
+            PP_RGBX_LOAD_SAVE_NV12,
+            pp_rgbx_load_save_nv12_gen6,
+            sizeof(pp_rgbx_load_save_nv12_gen6),
+            NULL,
+        },
+    
+        pp_plx_load_save_plx_initialize,
+    },
+
 };
 
 static const uint32_t pp_null_gen7[][4] = {
@@ -564,6 +596,8 @@ static const uint32_t pp_pa_load_save_nv12_gen7[][4] = {
 static const uint32_t pp_pa_load_save_pl3_gen7[][4] = {
 #include "shaders/post_processing/gen7/pa_to_pl3.g7b"
 };
+static const uint32_t pp_rgbx_load_save_nv12_gen7[][4] = {
+};
 
 static VAStatus gen7_pp_plx_avs_initialize(VADriverContextP ctx, struct i965_post_processing_context *pp_context,
                                            const struct i965_surface *src_surface,
@@ -740,6 +774,18 @@ static struct pp_module pp_modules_gen7[] = {
         gen7_pp_plx_avs_initialize,
     },
     
+    {
+        {
+            "RGBX_NV12 module",
+            PP_RGBX_LOAD_SAVE_NV12,
+            pp_rgbx_load_save_nv12_gen7,
+            sizeof(pp_rgbx_load_save_nv12_gen7),
+            NULL,
+        },
+    
+        pp_plx_load_save_plx_initialize,
+    },
+
 };
 
 static int
@@ -1264,7 +1310,12 @@ pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processin
     const int UV = 1;
     int interleaved_uv = fourcc == VA_FOURCC('N', 'V', '1', '2');
     int packed_yuv = (fourcc == VA_FOURCC('Y', 'U', 'Y', '2') || fourcc == VA_FOURCC('U', 'Y', 'V', 'Y')); 
-
+    int full_packed_format = (fourcc == VA_FOURCC('A', 'Y', 'U', 'V') || 
+                              fourcc == VA_FOURCC('R', 'G', 'B', 'A') || 
+                              fourcc == VA_FOURCC('R', 'G', 'B', 'X') || 
+                              fourcc == VA_FOURCC('B', 'G', 'R', 'A') || 
+                              fourcc == VA_FOURCC('B', 'G', 'R', 'X'));
+                              
     if (surface->type == I965_SURFACE_TYPE_SURFACE) {
         obj_surface = SURFACE(surface->id);
         bo = obj_surface->bo;
@@ -1273,7 +1324,11 @@ pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processin
         pitch[0] = obj_surface->width;
         offset[0] = 0;
 
-        if (packed_yuv ) {
+        if (full_packed_format) {
+            width[0] = obj_surface->orig_width * 4; 
+            pitch[0] = obj_surface->width * 4;
+        }
+        else if (packed_yuv ) {
             width[0] = obj_surface->orig_width * 2; 
             pitch[0] = obj_surface->width * 2;
         }
@@ -1300,7 +1355,10 @@ pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processin
         pitch[0] = obj_image->image.pitches[0];
         offset[0] = obj_image->image.offsets[0];
 
-        if (packed_yuv ) {
+        if (full_packed_format) {
+            width[0] = obj_image->image.width * 4;
+        }
+        else if (packed_yuv ) {
             width[0] = obj_image->image.width * 2;
         }
         else if (interleaved_uv) {
@@ -1326,7 +1384,7 @@ pp_set_media_rw_message_surface(VADriverContextP ctx, struct i965_post_processin
                               width[Y] / 4, height[Y], pitch[Y], I965_SURFACEFORMAT_R8_UNORM,
                               base_index, is_target);
 
-    if (!packed_yuv) {
+    if (!packed_yuv && !full_packed_format) {
         if (interleaved_uv) {
             i965_pp_set_surface_state(ctx, pp_context,
                                       bo, offset[UV],
@@ -3999,6 +4057,35 @@ i965_post_processing(
 }       
 
 static VAStatus
+i965_image_pl1_rgbx_processing(VADriverContextP ctx,
+                          const struct i965_surface *src_surface,
+                          const VARectangle *src_rect,
+                          struct i965_surface *dst_surface,
+                          const VARectangle *dst_rect)
+{
+    struct i965_driver_data *i965 = i965_driver_data(ctx);
+    struct i965_post_processing_context *pp_context = i965->pp_context;
+    int fourcc = pp_get_surface_fourcc(ctx, dst_surface);
+
+    if (fourcc == VA_FOURCC('N', 'V', '1', '2')) {
+        i965_post_processing_internal(ctx, i965->pp_context,
+                                      src_surface,
+                                      src_rect,
+                                      dst_surface,
+                                      dst_rect,
+                                      PP_RGBX_LOAD_SAVE_NV12,
+                                      NULL);
+    } else {
+        assert(0);
+        return VA_STATUS_ERROR_UNKNOWN;
+    }
+
+    intel_batchbuffer_flush(pp_context->batch);
+
+    return VA_STATUS_SUCCESS;
+}
+
+static VAStatus
 i965_image_pl3_processing(VADriverContextP ctx,
                           const struct i965_surface *src_surface,
                           const VARectangle *src_rect,
@@ -4176,7 +4263,14 @@ i965_image_processing(VADriverContextP ctx,
                                                dst_surface,
                                                dst_rect);
             break;
-
+        case VA_FOURCC('B', 'G', 'R', 'A'):
+        case VA_FOURCC('B', 'G', 'R', 'X'):
+            status = i965_image_pl1_rgbx_processing(ctx,
+                                               src_surface,
+                                               src_rect,
+                                               dst_surface,
+                                               dst_rect);
+            break;
         default:
             status = VA_STATUS_ERROR_UNIMPLEMENTED;
             break;
diff --git a/src/i965_post_processing.h b/src/i965_post_processing.h
index 21e525c..64229e8 100755
--- a/src/i965_post_processing.h
+++ b/src/i965_post_processing.h
@@ -51,9 +51,10 @@ enum
     PP_PL3_LOAD_SAVE_PA,
     PP_PA_LOAD_SAVE_NV12,
     PP_PA_LOAD_SAVE_PL3,
+    PP_RGBX_LOAD_SAVE_NV12,
 };
 
-#define NUM_PP_MODULES                  13
+#define NUM_PP_MODULES                  14
 
 struct i965_post_processing_context;
 
-- 
1.7.4.1



More information about the Libva mailing list