Commit 86eb4131 authored by Julien Isorce's avatar Julien Isorce Committed by Christian König

st/va: add headless support, i.e. VA_DISPLAY_DRM

This patch allows to use gallium vaapi without requiring
a X server running for your second graphic card.
Signed-off-by: default avatarJulien Isorce <j.isorce@samsung.com>
Reviewed-by: Emil Velikov's avatarEmil Velikov <emil.l.velikov@gmail.com>
Reviewed-by: Christian König's avatarChristian König <christian.koenig@amd.com>
parent 1bdea0e5
...@@ -30,6 +30,15 @@ AM_CFLAGS = \ ...@@ -30,6 +30,15 @@ AM_CFLAGS = \
$(VA_CFLAGS) \ $(VA_CFLAGS) \
-DVA_DRIVER_INIT_FUNC="__vaDriverInit_$(VA_MAJOR)_$(VA_MINOR)" -DVA_DRIVER_INIT_FUNC="__vaDriverInit_$(VA_MAJOR)_$(VA_MINOR)"
AM_CFLAGS += \
$(GALLIUM_PIPE_LOADER_DEFINES) \
-DPIPE_SEARCH_DIR=\"$(libdir)/gallium-pipe\"
if HAVE_GALLIUM_STATIC_TARGETS
AM_CFLAGS += \
-DGALLIUM_STATIC_TARGETS=1
endif
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-I$(top_srcdir)/include -I$(top_srcdir)/include
......
...@@ -28,7 +28,8 @@ ...@@ -28,7 +28,8 @@
#include "pipe/p_screen.h" #include "pipe/p_screen.h"
#include "pipe/p_video_codec.h" #include "pipe/p_video_codec.h"
#include "pipe-loader/pipe_loader.h"
#include "state_tracker/drm_driver.h"
#include "util/u_memory.h" #include "util/u_memory.h"
#include "util/u_handle_table.h" #include "util/u_handle_table.h"
#include "util/u_video.h" #include "util/u_video.h"
...@@ -36,6 +37,8 @@ ...@@ -36,6 +37,8 @@
#include "va_private.h" #include "va_private.h"
#include <va/va_drmcommon.h>
static struct VADriverVTable vtable = static struct VADriverVTable vtable =
{ {
&vlVaTerminate, &vlVaTerminate,
...@@ -99,6 +102,8 @@ PUBLIC VAStatus ...@@ -99,6 +102,8 @@ PUBLIC VAStatus
VA_DRIVER_INIT_FUNC(VADriverContextP ctx) VA_DRIVER_INIT_FUNC(VADriverContextP ctx)
{ {
vlVaDriver *drv; vlVaDriver *drv;
int drm_fd;
struct drm_state *drm_info;
if (!ctx) if (!ctx)
return VA_STATUS_ERROR_INVALID_CONTEXT; return VA_STATUS_ERROR_INVALID_CONTEXT;
...@@ -107,9 +112,56 @@ VA_DRIVER_INIT_FUNC(VADriverContextP ctx) ...@@ -107,9 +112,56 @@ VA_DRIVER_INIT_FUNC(VADriverContextP ctx)
if (!drv) if (!drv)
return VA_STATUS_ERROR_ALLOCATION_FAILED; return VA_STATUS_ERROR_ALLOCATION_FAILED;
switch (ctx->display_type) {
case VA_DISPLAY_ANDROID:
case VA_DISPLAY_WAYLAND:
FREE(drv);
return VA_STATUS_ERROR_UNIMPLEMENTED;
case VA_DISPLAY_GLX:
case VA_DISPLAY_X11:
drv->vscreen = vl_screen_create(ctx->native_dpy, ctx->x11_screen); drv->vscreen = vl_screen_create(ctx->native_dpy, ctx->x11_screen);
if (!drv->vscreen) if (!drv->vscreen)
goto error_screen; goto error_screen;
break;
case VA_DISPLAY_DRM:
case VA_DISPLAY_DRM_RENDERNODES: {
drm_info = (struct drm_state *) ctx->drm_state;
if (!drm_info) {
FREE(drv);
return VA_STATUS_ERROR_INVALID_PARAMETER;
}
#if GALLIUM_STATIC_TARGETS
drm_fd = drm_info->fd;
#else
drm_fd = dup(drm_info->fd);
#endif
if (drm_fd < 0) {
FREE(drv);
return VA_STATUS_ERROR_INVALID_PARAMETER;
}
drv->vscreen = CALLOC_STRUCT(vl_screen);
if (!drv->vscreen)
goto error_screen;
#if GALLIUM_STATIC_TARGETS
drv->vscreen->pscreen = dd_create_screen(drm_fd);
#else
if (pipe_loader_drm_probe_fd(&drv->dev, drm_fd))
drv->vscreen->pscreen = pipe_loader_create_screen(drv->dev, PIPE_SEARCH_DIR);
#endif
if (!drv->vscreen->pscreen)
goto error_pipe;
}
break;
default:
FREE(drv);
return VA_STATUS_ERROR_INVALID_DISPLAY;
}
drv->pipe = drv->vscreen->pscreen->context_create(drv->vscreen->pscreen, drv->pipe = drv->vscreen->pscreen->context_create(drv->vscreen->pscreen,
drv->vscreen, 0); drv->vscreen, 0);
...@@ -145,7 +197,10 @@ error_htab: ...@@ -145,7 +197,10 @@ error_htab:
drv->pipe->destroy(drv->pipe); drv->pipe->destroy(drv->pipe);
error_pipe: error_pipe:
if (ctx->display_type == VA_DISPLAY_GLX || ctx->display_type == VA_DISPLAY_X11)
vl_screen_destroy(drv->vscreen); vl_screen_destroy(drv->vscreen);
else
FREE(drv->vscreen);
error_screen: error_screen:
FREE(drv); FREE(drv);
...@@ -282,7 +337,10 @@ vlVaTerminate(VADriverContextP ctx) ...@@ -282,7 +337,10 @@ vlVaTerminate(VADriverContextP ctx)
vl_compositor_cleanup_state(&drv->cstate); vl_compositor_cleanup_state(&drv->cstate);
vl_compositor_cleanup(&drv->compositor); vl_compositor_cleanup(&drv->compositor);
drv->pipe->destroy(drv->pipe); drv->pipe->destroy(drv->pipe);
if (ctx->display_type == VA_DISPLAY_GLX || ctx->display_type == VA_DISPLAY_X11)
vl_screen_destroy(drv->vscreen); vl_screen_destroy(drv->vscreen);
else
FREE(drv->vscreen);
handle_table_destroy(drv->htab); handle_table_destroy(drv->htab);
FREE(drv); FREE(drv);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment