Re: [Mesa-dev] [PATCH v2 4/7] st/va: implement VaCreateSurfaces2 and VaQuerySurfaceAttributes

2015-10-23 Thread Julien Isorce
This patch is missing "memset(, 0, sizeof(templat));" so I am going
to submit a v3 for this one.

On 20 October 2015 at 17:34, Julien Isorce  wrote:

> Inspired from http://cgit.freedesktop.org/vaapi/intel-driver/
> especially src/i965_drv_video.c::i965_CreateSurfaces2.
>
> This patch is mainly to support gstreamer-vaapi and tools that uses
> this newer libva API. The first advantage of using VaCreateSurfaces2
> over existing VaCreateSurfaces, is that it is possible to select which
> the pixel format for the surface. Indeed with the simple VaCreateSurfaces
> function it is only possible to create a NV12 surface. It can be useful
> to create a RGBA surface to use with video post processing.
>
> The avaible pixel formats can be query with VaQuerySurfaceAttributes.
>
> Signed-off-by: Julien Isorce 
> ---
>  src/gallium/state_trackers/va/context.c|   5 +-
>  src/gallium/state_trackers/va/surface.c| 294
> -
>  src/gallium/state_trackers/va/va_private.h |   6 +-
>  3 files changed, 253 insertions(+), 52 deletions(-)
>
> diff --git a/src/gallium/state_trackers/va/context.c
> b/src/gallium/state_trackers/va/context.c
> index 8b003ae..9be9085 100644
> --- a/src/gallium/state_trackers/va/context.c
> +++ b/src/gallium/state_trackers/va/context.c
> @@ -81,7 +81,10 @@ static struct VADriverVTable vtable =
> ,
> ,
> ,
> -   
> +   ,
> +   NULL, /* DEPRECATED VaGetSurfaceAttributes */
> +   ,
> +   
>  };
>
>  PUBLIC VAStatus
> diff --git a/src/gallium/state_trackers/va/surface.c
> b/src/gallium/state_trackers/va/surface.c
> index 8d4487b..62fdf3c 100644
> --- a/src/gallium/state_trackers/va/surface.c
> +++ b/src/gallium/state_trackers/va/surface.c
> @@ -36,6 +36,7 @@
>  #include "util/u_surface.h"
>
>  #include "vl/vl_compositor.h"
> +#include "vl/vl_video_buffer.h"
>  #include "vl/vl_winsys.h"
>
>  #include "va_private.h"
> @@ -44,56 +45,8 @@ VAStatus
>  vlVaCreateSurfaces(VADriverContextP ctx, int width, int height, int
> format,
> int num_surfaces, VASurfaceID *surfaces)
>  {
> -   struct pipe_video_buffer templat = {};
> -   struct pipe_screen *pscreen;
> -   vlVaDriver *drv;
> -   int i;
> -
> -   if (!ctx)
> -  return VA_STATUS_ERROR_INVALID_CONTEXT;
> -
> -   if (!(width && height))
> -  return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
> -
> -   drv = VL_VA_DRIVER(ctx);
> -   pscreen = VL_VA_PSCREEN(ctx);
> -
> -   templat.buffer_format = pscreen->get_video_param
> -   (
> -  pscreen,
> -  PIPE_VIDEO_PROFILE_UNKNOWN,
> -  PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
> -  PIPE_VIDEO_CAP_PREFERED_FORMAT
> -   );
> -   templat.chroma_format = ChromaToPipe(format);
> -   templat.width = width;
> -   templat.height = height;
> -   templat.interlaced = pscreen->get_video_param
> -   (
> -  pscreen,
> -  PIPE_VIDEO_PROFILE_UNKNOWN,
> -  PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
> -  PIPE_VIDEO_CAP_PREFERS_INTERLACED
> -   );
> -
> -   for (i = 0; i < num_surfaces; ++i) {
> -  vlVaSurface *surf = CALLOC(1, sizeof(vlVaSurface));
> -  if (!surf)
> - goto no_res;
> -
> -  surf->templat = templat;
> -  surf->buffer = drv->pipe->create_video_buffer(drv->pipe, );
> -  util_dynarray_init(>subpics);
> -  surfaces[i] = handle_table_add(drv->htab, surf);
> -   }
> -
> -   return VA_STATUS_SUCCESS;
> -
> -no_res:
> -   if (i)
> -  vlVaDestroySurfaces(ctx, surfaces, i);
> -
> -   return VA_STATUS_ERROR_ALLOCATION_FAILED;
> +   return vlVaCreateSurfaces2(ctx, format, width, height, surfaces,
> num_surfaces,
> +  NULL, 0);
>  }
>
>  VAStatus
> @@ -349,3 +302,244 @@ vlVaUnlockSurface(VADriverContextP ctx, VASurfaceID
> surface)
>
> return VA_STATUS_ERROR_UNIMPLEMENTED;
>  }
> +
> +VAStatus
> +vlVaQuerySurfaceAttributes(VADriverContextP ctx, VAConfigID config,
> +   VASurfaceAttrib *attrib_list, unsigned int
> *num_attribs)
> +{
> +vlVaDriver *drv;
> +VASurfaceAttrib *attribs;
> +struct pipe_screen *pscreen;
> +int i;
> +
> +if (config == VA_INVALID_ID)
> +return VA_STATUS_ERROR_INVALID_CONFIG;
> +
> +if (!attrib_list && !num_attribs)
> +return VA_STATUS_ERROR_INVALID_PARAMETER;
> +
> +if (!attrib_list) {
> +*num_attribs = VASurfaceAttribCount;
> +return VA_STATUS_SUCCESS;
> +}
> +
> +if (!ctx)
> +   return VA_STATUS_ERROR_INVALID_CONTEXT;
> +
> +drv = VL_VA_DRIVER(ctx);
> +
> +if (!drv)
> +return VA_STATUS_ERROR_INVALID_CONTEXT;
> +
> +pscreen = VL_VA_PSCREEN(ctx);
> +
> +if (!pscreen)
> +   return VA_STATUS_ERROR_INVALID_CONTEXT;
> +
> +attribs = CALLOC(VASurfaceAttribCount, sizeof(VASurfaceAttrib));
> +
> +if (!attribs)
> +return VA_STATUS_ERROR_ALLOCATION_FAILED;
> +
> +i = 0;
> +
> +if (config == PIPE_VIDEO_PROFILE_UNKNOWN) {
> +   /* Assume VAEntrypointVideoProc for now. */
> +   

[Mesa-dev] [PATCH v2 4/7] st/va: implement VaCreateSurfaces2 and VaQuerySurfaceAttributes

2015-10-20 Thread Julien Isorce
Inspired from http://cgit.freedesktop.org/vaapi/intel-driver/
especially src/i965_drv_video.c::i965_CreateSurfaces2.

This patch is mainly to support gstreamer-vaapi and tools that uses
this newer libva API. The first advantage of using VaCreateSurfaces2
over existing VaCreateSurfaces, is that it is possible to select which
the pixel format for the surface. Indeed with the simple VaCreateSurfaces
function it is only possible to create a NV12 surface. It can be useful
to create a RGBA surface to use with video post processing.

The avaible pixel formats can be query with VaQuerySurfaceAttributes.

Signed-off-by: Julien Isorce 
---
 src/gallium/state_trackers/va/context.c|   5 +-
 src/gallium/state_trackers/va/surface.c| 294 -
 src/gallium/state_trackers/va/va_private.h |   6 +-
 3 files changed, 253 insertions(+), 52 deletions(-)

diff --git a/src/gallium/state_trackers/va/context.c 
b/src/gallium/state_trackers/va/context.c
index 8b003ae..9be9085 100644
--- a/src/gallium/state_trackers/va/context.c
+++ b/src/gallium/state_trackers/va/context.c
@@ -81,7 +81,10 @@ static struct VADriverVTable vtable =
,
,
,
-   
+   ,
+   NULL, /* DEPRECATED VaGetSurfaceAttributes */
+   ,
+   
 };
 
 PUBLIC VAStatus
diff --git a/src/gallium/state_trackers/va/surface.c 
b/src/gallium/state_trackers/va/surface.c
index 8d4487b..62fdf3c 100644
--- a/src/gallium/state_trackers/va/surface.c
+++ b/src/gallium/state_trackers/va/surface.c
@@ -36,6 +36,7 @@
 #include "util/u_surface.h"
 
 #include "vl/vl_compositor.h"
+#include "vl/vl_video_buffer.h"
 #include "vl/vl_winsys.h"
 
 #include "va_private.h"
@@ -44,56 +45,8 @@ VAStatus
 vlVaCreateSurfaces(VADriverContextP ctx, int width, int height, int format,
int num_surfaces, VASurfaceID *surfaces)
 {
-   struct pipe_video_buffer templat = {};
-   struct pipe_screen *pscreen;
-   vlVaDriver *drv;
-   int i;
-
-   if (!ctx)
-  return VA_STATUS_ERROR_INVALID_CONTEXT;
-
-   if (!(width && height))
-  return VA_STATUS_ERROR_INVALID_IMAGE_FORMAT;
-
-   drv = VL_VA_DRIVER(ctx);
-   pscreen = VL_VA_PSCREEN(ctx);
-
-   templat.buffer_format = pscreen->get_video_param
-   (
-  pscreen,
-  PIPE_VIDEO_PROFILE_UNKNOWN,
-  PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
-  PIPE_VIDEO_CAP_PREFERED_FORMAT
-   );
-   templat.chroma_format = ChromaToPipe(format);
-   templat.width = width;
-   templat.height = height;
-   templat.interlaced = pscreen->get_video_param
-   (
-  pscreen,
-  PIPE_VIDEO_PROFILE_UNKNOWN,
-  PIPE_VIDEO_ENTRYPOINT_BITSTREAM,
-  PIPE_VIDEO_CAP_PREFERS_INTERLACED
-   );
-
-   for (i = 0; i < num_surfaces; ++i) {
-  vlVaSurface *surf = CALLOC(1, sizeof(vlVaSurface));
-  if (!surf)
- goto no_res;
-
-  surf->templat = templat;
-  surf->buffer = drv->pipe->create_video_buffer(drv->pipe, );
-  util_dynarray_init(>subpics);
-  surfaces[i] = handle_table_add(drv->htab, surf);
-   }
-
-   return VA_STATUS_SUCCESS;
-
-no_res:
-   if (i)
-  vlVaDestroySurfaces(ctx, surfaces, i);
-
-   return VA_STATUS_ERROR_ALLOCATION_FAILED;
+   return vlVaCreateSurfaces2(ctx, format, width, height, surfaces, 
num_surfaces,
+  NULL, 0);
 }
 
 VAStatus
@@ -349,3 +302,244 @@ vlVaUnlockSurface(VADriverContextP ctx, VASurfaceID 
surface)
 
return VA_STATUS_ERROR_UNIMPLEMENTED;
 }
+
+VAStatus
+vlVaQuerySurfaceAttributes(VADriverContextP ctx, VAConfigID config,
+   VASurfaceAttrib *attrib_list, unsigned int 
*num_attribs)
+{
+vlVaDriver *drv;
+VASurfaceAttrib *attribs;
+struct pipe_screen *pscreen;
+int i;
+
+if (config == VA_INVALID_ID)
+return VA_STATUS_ERROR_INVALID_CONFIG;
+
+if (!attrib_list && !num_attribs)
+return VA_STATUS_ERROR_INVALID_PARAMETER;
+
+if (!attrib_list) {
+*num_attribs = VASurfaceAttribCount;
+return VA_STATUS_SUCCESS;
+}
+
+if (!ctx)
+   return VA_STATUS_ERROR_INVALID_CONTEXT;
+
+drv = VL_VA_DRIVER(ctx);
+
+if (!drv)
+return VA_STATUS_ERROR_INVALID_CONTEXT;
+
+pscreen = VL_VA_PSCREEN(ctx);
+
+if (!pscreen)
+   return VA_STATUS_ERROR_INVALID_CONTEXT;
+
+attribs = CALLOC(VASurfaceAttribCount, sizeof(VASurfaceAttrib));
+
+if (!attribs)
+return VA_STATUS_ERROR_ALLOCATION_FAILED;
+
+i = 0;
+
+if (config == PIPE_VIDEO_PROFILE_UNKNOWN) {
+   /* Assume VAEntrypointVideoProc for now. */
+   attribs[i].type = VASurfaceAttribPixelFormat;
+   attribs[i].value.type = VAGenericValueTypeInteger;
+   attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | 
VA_SURFACE_ATTRIB_SETTABLE;
+   attribs[i].value.value.i = VA_FOURCC_BGRA;
+   i++;
+
+   attribs[i].type = VASurfaceAttribPixelFormat;
+   attribs[i].value.type = VAGenericValueTypeInteger;
+   attribs[i].flags = VA_SURFACE_ATTRIB_GETTABLE | 
VA_SURFACE_ATTRIB_SETTABLE;
+