st/va: properly defines VAImageFormat formats and improve VaCreateImage
authorJulien Isorce <j.isorce@samsung.com>
Fri, 30 Oct 2015 11:42:44 +0000 (11:42 +0000)
committerChristian König <christian.koenig@amd.com>
Fri, 30 Oct 2015 12:05:23 +0000 (13:05 +0100)
Added PIPE_VIDEO_CHROMA_FORMAT_NONE in p_format.h
and return it by default in ChromaToPipe.

Renamed YCbCrToPipe to VaFourccToPipeFormat because it now
contains RGB.

Implemented PipeFormatToVaFourcc which will be used later in
VlVaDeriveImage.

Note that gstreamer-vaapi check all the VAImageFormat fields.

Signed-off-by: Julien Isorce <j.isorce@samsung.com>
Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
src/gallium/include/pipe/p_format.h
src/gallium/state_trackers/va/image.c
src/gallium/state_trackers/va/va_private.h

index b2646d44c74e5d8b6e4d2eada9c0987ff5a40931..5f0690e5ae6ac3d0f00945a0b8ad7784a8b87fad 100644 (file)
@@ -444,7 +444,8 @@ enum pipe_video_chroma_format
    PIPE_VIDEO_CHROMA_FORMAT_400,
    PIPE_VIDEO_CHROMA_FORMAT_420,
    PIPE_VIDEO_CHROMA_FORMAT_422,
-   PIPE_VIDEO_CHROMA_FORMAT_444
+   PIPE_VIDEO_CHROMA_FORMAT_444,
+   PIPE_VIDEO_CHROMA_FORMAT_NONE
 };
 
 #ifdef __cplusplus
index b37a97144376cc178af219aedd2fe220cba51e2f..0d961b1f8a2cc6c95405a9428ccdf924cd2eece7 100644 (file)
 
 #include "va_private.h"
 
-static const VAImageFormat formats[VL_VA_MAX_IMAGE_FORMATS] =
+static const VAImageFormat formats[] =
 {
    {VA_FOURCC('N','V','1','2')},
    {VA_FOURCC('I','4','2','0')},
    {VA_FOURCC('Y','V','1','2')},
    {VA_FOURCC('Y','U','Y','V')},
    {VA_FOURCC('U','Y','V','Y')},
-   {VA_FOURCC('B','G','R','A')}
+   {.fourcc = VA_FOURCC('B','G','R','A'), .byte_order = VA_LSB_FIRST, 32, 32,
+    0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000},
+   {.fourcc = VA_FOURCC('R','G','B','A'), .byte_order = VA_LSB_FIRST, 32, 32,
+    0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000},
+   {.fourcc = VA_FOURCC('B','G','R','X'), .byte_order = VA_LSB_FIRST, 32, 24,
+    0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000},
+   {.fourcc = VA_FOURCC('R','G','B','X'), .byte_order = VA_LSB_FIRST, 32, 24,
+    0x000000ff, 0x0000ff00, 0x00ff0000, 0x00000000}
 };
 
 static void
@@ -72,6 +79,8 @@ vlVaQueryImageFormats(VADriverContextP ctx, VAImageFormat *format_list, int *num
    enum pipe_format format;
    int i;
 
+   STATIC_ASSERT(ARRAY_SIZE(formats) == VL_VA_MAX_IMAGE_FORMATS);
+
    if (!ctx)
       return VA_STATUS_ERROR_INVALID_CONTEXT;
 
@@ -80,8 +89,8 @@ vlVaQueryImageFormats(VADriverContextP ctx, VAImageFormat *format_list, int *num
 
    *num_formats = 0;
    pscreen = VL_VA_PSCREEN(ctx);
-   for (i = 0; i < VL_VA_MAX_IMAGE_FORMATS; ++i) {
-      format = YCbCrToPipe(formats[i].fourcc);
+   for (i = 0; i < ARRAY_SIZE(formats); ++i) {
+      format = VaFourccToPipeFormat(formats[i].fourcc);
       if (pscreen->is_video_format_supported(pscreen, format,
           PIPE_VIDEO_PROFILE_UNKNOWN,
           PIPE_VIDEO_ENTRYPOINT_BITSTREAM))
@@ -149,6 +158,9 @@ vlVaCreateImage(VADriverContextP ctx, VAImageFormat *format, int width, int heig
       break;
 
    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'):
       img->num_planes = 1;
       img->pitches[0] = w * 4;
       img->offsets[0] = 0;
@@ -235,7 +247,7 @@ vlVaGetImage(VADriverContextP ctx, VASurfaceID surface, int x, int y,
    if (!img_buf)
       return VA_STATUS_ERROR_INVALID_BUFFER;
 
-   format = YCbCrToPipe(vaimage->format.fourcc);
+   format = VaFourccToPipeFormat(vaimage->format.fourcc);
    if (format == PIPE_FORMAT_NONE)
       return VA_STATUS_ERROR_OPERATION_FAILED;
 
@@ -330,7 +342,7 @@ vlVaPutImage(VADriverContextP ctx, VASurfaceID surface, VAImageID image,
    if (!img_buf)
       return VA_STATUS_ERROR_INVALID_BUFFER;
 
-   format = YCbCrToPipe(vaimage->format.fourcc);
+   format = VaFourccToPipeFormat(vaimage->format.fourcc);
    if (format == PIPE_FORMAT_NONE)
       return VA_STATUS_ERROR_OPERATION_FAILED;
 
index 93af1be19a7fc96e13442c5773d1938808ee0561..56c6b029ff2c6ffd0ba4643e0f111deb3a7634c3 100644 (file)
@@ -46,7 +46,7 @@
 #define VL_VA_DRIVER(ctx) ((vlVaDriver *)ctx->pDriverData)
 #define VL_VA_PSCREEN(ctx) (VL_VA_DRIVER(ctx)->vscreen->pscreen)
 
-#define VL_VA_MAX_IMAGE_FORMATS 6
+#define VL_VA_MAX_IMAGE_FORMATS 9
 
 static inline enum pipe_video_chroma_format
 ChromaToPipe(int format)
@@ -59,13 +59,12 @@ ChromaToPipe(int format)
    case VA_RT_FORMAT_YUV444:
       return PIPE_VIDEO_CHROMA_FORMAT_444;
    default:
-      assert(0);
-      return PIPE_VIDEO_CHROMA_FORMAT_420;
+      return PIPE_VIDEO_CHROMA_FORMAT_NONE;
    }
 }
 
 static inline enum pipe_format
-YCbCrToPipe(unsigned format)
+VaFourccToPipeFormat(unsigned format)
 {
    switch(format) {
    case VA_FOURCC('N','V','1','2'):
@@ -80,12 +79,46 @@ YCbCrToPipe(unsigned format)
       return PIPE_FORMAT_UYVY;
    case VA_FOURCC('B','G','R','A'):
       return PIPE_FORMAT_B8G8R8A8_UNORM;
+   case VA_FOURCC('R','G','B','A'):
+      return PIPE_FORMAT_R8G8B8A8_UNORM;
+   case VA_FOURCC('B','G','R','X'):
+      return PIPE_FORMAT_B8G8R8X8_UNORM;
+   case VA_FOURCC('R','G','B','X'):
+      return PIPE_FORMAT_R8G8B8X8_UNORM;
    default:
       assert(0);
       return PIPE_FORMAT_NONE;
    }
 }
 
+static inline unsigned
+PipeFormatToVaFourcc(enum pipe_format p_format)
+{
+   switch (p_format) {
+   case PIPE_FORMAT_NV12:
+      return VA_FOURCC('N','V','1','2');
+   case PIPE_FORMAT_IYUV:
+      return VA_FOURCC('I','4','2','0');
+   case PIPE_FORMAT_YV12:
+      return VA_FOURCC('Y','V','1','2');
+   case PIPE_FORMAT_UYVY:
+      return VA_FOURCC('U','Y','V','Y');
+   case PIPE_FORMAT_YUYV:
+      return VA_FOURCC('Y','U','Y','V');
+   case PIPE_FORMAT_B8G8R8A8_UNORM:
+      return VA_FOURCC('B','G','R','A');
+   case PIPE_FORMAT_R8G8B8A8_UNORM:
+      return VA_FOURCC('R','G','B','A');
+   case PIPE_FORMAT_B8G8R8X8_UNORM:
+      return VA_FOURCC('B','G','R','X');
+   case PIPE_FORMAT_R8G8B8X8_UNORM:
+      return VA_FOURCC('R','G','B','X');
+   default:
+      assert(0);
+      return -1;
+   }
+}
+
 static inline VAProfile
 PipeToProfile(enum pipe_video_profile profile)
 {