[Mesa-dev] [PATCH] implement NV_vdpau_interop v2
Marek Olšák
maraeo at gmail.com
Fri Sep 20 08:39:16 PDT 2013
On Fri, Sep 20, 2013 at 4:34 PM, Christian König
<deathsimple at vodafone.de> wrote:
> From: Christian König <christian.koenig at amd.com>
>
> v2: Actually implement interop between the gallium
> state tracker and the VDPAU backend.
>
> Signed-off-by: Christian König <christian.koenig at amd.com>
> ---
> src/gallium/include/state_tracker/vdpau_interop.h | 49 ++++
> src/gallium/state_trackers/vdpau/ftab.c | 31 ++-
> src/gallium/state_trackers/vdpau/output.c | 11 +
> src/gallium/state_trackers/vdpau/surface.c | 21 ++
> src/gallium/state_trackers/vdpau/vdpau_private.h | 6 +
> src/mapi/glapi/gen/Makefile.am | 1 +
> src/mapi/glapi/gen/NV_vdpau_interop.xml | 69 ++++++
> src/mapi/glapi/gen/gl_API.xml | 2 +
> src/mapi/glapi/gen/gl_genexec.py | 1 +
> src/mesa/Makefile.sources | 4 +-
> src/mesa/main/dd.h | 14 ++
> src/mesa/main/extensions.c | 1 +
> src/mesa/main/mtypes.h | 9 +
> src/mesa/main/vdpau.c | 279 ++++++++++++++++++++++
> src/mesa/main/vdpau.h | 72 ++++++
> src/mesa/state_tracker/st_context.c | 3 +
> src/mesa/state_tracker/st_extensions.c | 1 +
> src/mesa/state_tracker/st_vdpau.c | 170 +++++++++++++
> src/mesa/state_tracker/st_vdpau.h | 42 ++++
> 19 files changed, 777 insertions(+), 9 deletions(-)
> create mode 100644 src/gallium/include/state_tracker/vdpau_interop.h
> create mode 100644 src/mapi/glapi/gen/NV_vdpau_interop.xml
> create mode 100644 src/mesa/main/vdpau.c
> create mode 100644 src/mesa/main/vdpau.h
> create mode 100644 src/mesa/state_tracker/st_vdpau.c
> create mode 100644 src/mesa/state_tracker/st_vdpau.h
>
> diff --git a/src/gallium/include/state_tracker/vdpau_interop.h b/src/gallium/include/state_tracker/vdpau_interop.h
> new file mode 100644
> index 0000000..4069d20
> --- /dev/null
> +++ b/src/gallium/include/state_tracker/vdpau_interop.h
> @@ -0,0 +1,49 @@
> +/**************************************************************************
> + *
> + * Copyright 2013 Advanced Micro Devices, Inc.
> + * All Rights Reserved.
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sub license, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial portions
> + * of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
> + * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR
> + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
> + *
> + **************************************************************************/
> +
> +/*
> + * Authors:
> + * Christian König <christian.koenig at amd.com>
> + *
> + */
> +
> +#ifndef _VDPAU_INTEROP_H_
> +#define _VDPAU_INTEROP_H_
> +
> +/* driver specific functions for NV_vdpau_interop */
> +
> +#define VDP_FUNC_ID_BASE_DRIVER 0x2000
> +#define VDP_FUNC_ID_VIDEO_SURFACE_GALLIUM (VDP_FUNC_ID_BASE_DRIVER + 0)
> +#define VDP_FUNC_ID_OUTPUT_SURFACE_GALLIUM (VDP_FUNC_ID_BASE_DRIVER + 1)
> +
> +struct pipe_surface;
> +struct pipe_video_buffer;
> +
> +typedef struct pipe_video_buffer *VdpVideoSurfaceGallium(uint32_t surface);
> +typedef struct pipe_surface *VdpOutputSurfaceGallium(uint32_t surface);
> +
> +#endif /* _VDPAU_INTEROP_H_ */
> diff --git a/src/gallium/state_trackers/vdpau/ftab.c b/src/gallium/state_trackers/vdpau/ftab.c
> index 81d16ec..2c84554 100644
> --- a/src/gallium/state_trackers/vdpau/ftab.c
> +++ b/src/gallium/state_trackers/vdpau/ftab.c
> @@ -26,6 +26,9 @@
> **************************************************************************/
>
> #include <assert.h>
> +
> +#include "util/u_memory.h"
> +
> #include "vdpau_private.h"
>
> static void* ftab[67] =
> @@ -104,19 +107,31 @@ static void* ftab_winsys[1] =
> &vlVdpPresentationQueueTargetCreateX11 /* VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_CREATE_X11 */
> };
>
> +static void* ftab_driver[2] =
> +{
> + &vlVdpVideoSurfaceGallium, /* VDP_FUNC_ID_SURFACE_GALLIUM */
> + &vlVdpOutputSurfaceGallium /* VDP_FUNC_ID_OUTPUT_SURFACE_GALLIUM */
> +};
> +
> boolean vlGetFuncFTAB(VdpFuncId function_id, void **func)
> {
> assert(func);
> + *func = NULL;
> +
> if (function_id < VDP_FUNC_ID_BASE_WINSYS) {
> - if (function_id > 66)
> - return FALSE;
> - *func = ftab[function_id];
> - }
> - else {
> + if (function_id < Elements(ftab))
> + *func = ftab[function_id];
> +
> + } else if (function_id < VDP_FUNC_ID_BASE_DRIVER) {
> function_id -= VDP_FUNC_ID_BASE_WINSYS;
> - if (function_id > 0)
> - return FALSE;
> - *func = ftab_winsys[function_id];
> + if (function_id < Elements(ftab_winsys))
> + *func = ftab_winsys[function_id];
> +
> + } else {
> + function_id -= VDP_FUNC_ID_BASE_DRIVER;
> + if (function_id < Elements(ftab_driver))
> + *func = ftab_driver[function_id];
> }
> +
> return *func != NULL;
> }
> diff --git a/src/gallium/state_trackers/vdpau/output.c b/src/gallium/state_trackers/vdpau/output.c
> index 7266cdb..2154f7a 100644
> --- a/src/gallium/state_trackers/vdpau/output.c
> +++ b/src/gallium/state_trackers/vdpau/output.c
> @@ -724,3 +724,14 @@ vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface,
>
> return VDP_STATUS_OK;
> }
> +
> +struct pipe_surface *vlVdpOutputSurfaceGallium(VdpOutputSurface surface)
> +{
> + vlVdpOutputSurface *vlsurface;
> +
> + vlsurface = vlGetDataHTAB(surface);
> + if (!vlsurface)
> + return NULL;
> +
> + return vlsurface->surface;
> +}
> diff --git a/src/gallium/state_trackers/vdpau/surface.c b/src/gallium/state_trackers/vdpau/surface.c
> index 8e39d68..dd434aa 100644
> --- a/src/gallium/state_trackers/vdpau/surface.c
> +++ b/src/gallium/state_trackers/vdpau/surface.c
> @@ -359,3 +359,24 @@ vlVdpVideoSurfaceClear(vlVdpSurface *vlsurf)
> }
> pipe->flush(pipe, NULL, 0);
> }
> +
> +/**
> + * Interop to mesa state tracker
> + */
> +struct pipe_video_buffer *vlVdpVideoSurfaceGallium(VdpVideoSurface surface)
> +{
> + vlVdpSurface *p_surf = vlGetDataHTAB(surface);
> + if (!p_surf)
> + return NULL;
> +
> + pipe_mutex_lock(p_surf->device->mutex);
> + if (p_surf->video_buffer == NULL) {
> + struct pipe_context *pipe = p_surf->device->context;
> +
> + /* try to create a video buffer if we don't already have one */
> + p_surf->video_buffer = pipe->create_video_buffer(pipe, &p_surf->templat);
> + }
> + pipe_mutex_unlock(p_surf->device->mutex);
> +
> + return p_surf->video_buffer;
> +}
> diff --git a/src/gallium/state_trackers/vdpau/vdpau_private.h b/src/gallium/state_trackers/vdpau/vdpau_private.h
> index 54545fe..fe3bc3e 100644
> --- a/src/gallium/state_trackers/vdpau/vdpau_private.h
> +++ b/src/gallium/state_trackers/vdpau/vdpau_private.h
> @@ -36,6 +36,8 @@
> #include "pipe/p_compiler.h"
> #include "pipe/p_video_codec.h"
>
> +#include "state_tracker/vdpau_interop.h"
> +
> #include "util/u_debug.h"
> #include "util/u_rect.h"
> #include "os/os_thread.h"
> @@ -474,6 +476,10 @@ VdpVideoMixerGetAttributeValues vlVdpVideoMixerGetAttributeValues;
> VdpVideoMixerDestroy vlVdpVideoMixerDestroy;
> VdpGenerateCSCMatrix vlVdpGenerateCSCMatrix;
>
> +/* interop to mesa state tracker */
> +VdpVideoSurfaceGallium vlVdpVideoSurfaceGallium;
> +VdpOutputSurfaceGallium vlVdpOutputSurfaceGallium;
> +
> #define VDPAU_OUT 0
> #define VDPAU_ERR 1
> #define VDPAU_WARN 2
> diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am
> index d4fbd35..bd82e54 100644
> --- a/src/mapi/glapi/gen/Makefile.am
> +++ b/src/mapi/glapi/gen/Makefile.am
> @@ -131,6 +131,7 @@ API_XML = \
> NV_conditional_render.xml \
> NV_primitive_restart.xml \
> NV_texture_barrier.xml \
> + NV_vdpau_interop.xml \
> OES_EGL_image.xml \
> GL3x.xml
>
> diff --git a/src/mapi/glapi/gen/NV_vdpau_interop.xml b/src/mapi/glapi/gen/NV_vdpau_interop.xml
> new file mode 100644
> index 0000000..cf5f0ed
> --- /dev/null
> +++ b/src/mapi/glapi/gen/NV_vdpau_interop.xml
> @@ -0,0 +1,69 @@
> +<?xml version="1.0"?>
> +<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd">
> +
> +<OpenGLAPI>
> +
> +<category name="GL_NV_vdpau_interop" number="396">
> +
> + <function name="VDPAUInitNV" offset="assign">
> + <param name="vdpDevice" type="const GLvoid *"/>
> + <param name="getProcAddress" type="const GLvoid *"/>
> + </function>
> +
> + <function name="VDPAUFiniNV" offset="assign"/>
> +
> + <function name="VDPAURegisterVideoSurfaceNV" offset="assign">
> + <return type="GLintptr"/>
> + <param name="vdpSurface" type="const GLvoid *"/>
> + <param name="target" type="GLenum"/>
> + <param name="numTextureNames" type="GLsizei"/>
> + <param name="textureNames" type="const GLuint *"/>
> + </function>
> +
> + <function name="VDPAURegisterOutputSurfaceNV" offset="assign">
> + <return type="GLintptr"/>
> + <param name="vdpSurface" type="const GLvoid *"/>
> + <param name="target" type="GLenum"/>
> + <param name="numTextureNames" type="GLsizei"/>
> + <param name="textureNames" type="const GLuint *"/>
> + </function>
> +
> + <function name="VDPAUIsSurfaceNV" offset="assign">
> + <param name="surface" type="GLintptr"/>
> + </function>
> +
> + <function name="VDPAUUnregisterSurfaceNV" offset="assign">
> + <param name="surface" type="GLintptr"/>
> + </function>
> +
> + <function name="VDPAUGetSurfaceivNV" offset="assign">
> + <param name="surface" type="GLintptr"/>
> + <param name="pname" type="GLenum"/>
> + <param name="bufSize" type="GLsizei"/>
> + <param name="length" type="GLsizei *"/>
> + <param name="values" type="GLint *"/>
> + </function>
> +
> + <function name="VDPAUSurfaceAccessNV" offset="assign">
> + <param name="surface" type="GLintptr"/>
> + <param name="access" type="GLenum"/>
> + </function>
> +
> + <function name="VDPAUMapSurfacesNV" offset="assign">
> + <param name="numSurfaces" type="GLsizei"/>
> + <param name="surfaces" type="const GLintptr *"/>
> + </function>
> +
> + <function name="VDPAUUnmapSurfacesNV" offset="assign">
> + <param name="numSurfaces" type="GLsizei"/>
> + <param name="surfaces" type="const GLintptr *"/>
> + </function>
> +
> + <enum name="SURFACE_STATE_NV" value="0x86EB"/>
> + <enum name="SURFACE_REGISTERED_NV" value="0x86FD"/>
> + <enum name="SURFACE_MAPPED_NV" value="0x8700"/>
> + <enum name="WRITE_DISCARD_NV" value="0x88BE"/>
> +
> +</category>
> +
> +</OpenGLAPI>
> diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml
> index 71aa9a7..5700caa 100644
> --- a/src/mapi/glapi/gen/gl_API.xml
> +++ b/src/mapi/glapi/gen/gl_API.xml
> @@ -13148,4 +13148,6 @@
>
> <xi:include href="EXT_transform_feedback.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
>
> +<xi:include href="NV_vdpau_interop.xml" xmlns:xi="http://www.w3.org/2001/XInclude"/>
> +
> </OpenGLAPI>
> diff --git a/src/mapi/glapi/gen/gl_genexec.py b/src/mapi/glapi/gen/gl_genexec.py
> index be82f90..d76c7ae 100644
> --- a/src/mapi/glapi/gen/gl_genexec.py
> +++ b/src/mapi/glapi/gen/gl_genexec.py
> @@ -110,6 +110,7 @@ header = """/**
> #include "main/syncobj.h"
> #include "main/formatquery.h"
> #include "main/dispatch.h"
> +#include "main/vdpau.h"
> #include "vbo/vbo.h"
>
>
> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources
> index 122ea8e..85b4fe1 100644
> --- a/src/mesa/Makefile.sources
> +++ b/src/mesa/Makefile.sources
> @@ -107,6 +107,7 @@ MAIN_FILES = \
> $(SRCDIR)main/uniforms.c \
> $(SRCDIR)main/uniform_query.cpp \
> $(SRCDIR)main/varray.c \
> + $(SRCDIR)main/vdpau.c \
> $(SRCDIR)main/version.c \
> $(SRCDIR)main/viewport.c \
> $(SRCDIR)main/vtxfmt.c \
> @@ -247,7 +248,8 @@ STATETRACKER_FILES = \
> $(SRCDIR)state_tracker/st_manager.c \
> $(SRCDIR)state_tracker/st_mesa_to_tgsi.c \
> $(SRCDIR)state_tracker/st_program.c \
> - $(SRCDIR)state_tracker/st_texture.c
> + $(SRCDIR)state_tracker/st_texture.c \
> + $(SRCDIR)state_tracker/st_vdpau.c
>
> PROGRAM_FILES = \
> $(SRCDIR)program/arbprogparse.c \
> diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
> index c1d9b2c..a3ee0b7 100644
> --- a/src/mesa/main/dd.h
> +++ b/src/mesa/main/dd.h
> @@ -843,6 +843,20 @@ struct dd_function_table {
> struct gl_framebuffer *fb,
> GLuint index,
> GLfloat *outValue);
> +
> + /**
> + * \name NV_vdpau_interop interface
> + */
> + void (*VDPAUMapSurface)(struct gl_context *ctx, GLenum target,
> + GLenum access, GLboolean output,
> + struct gl_texture_object *texObj,
> + struct gl_texture_image *texImage,
> + const GLvoid *vdpSurface, GLuint index);
> + void (*VDPAUUnmapSurface)(struct gl_context *ctx, GLenum target,
> + GLenum access, GLboolean output,
> + struct gl_texture_object *texObj,
> + struct gl_texture_image *texImage,
> + const GLvoid *vdpSurface, GLuint index);
> };
>
>
> diff --git a/src/mesa/main/extensions.c b/src/mesa/main/extensions.c
> index 34615e3..7070812 100644
> --- a/src/mesa/main/extensions.c
> +++ b/src/mesa/main/extensions.c
> @@ -332,6 +332,7 @@ static const struct extension extension_table[] = {
> { "GL_NV_texture_barrier", o(NV_texture_barrier), GL, 2009 },
> { "GL_NV_texture_env_combine4", o(NV_texture_env_combine4), GLL, 1999 },
> { "GL_NV_texture_rectangle", o(NV_texture_rectangle), GLL, 2000 },
> + { "GL_NV_vdpau_interop", o(NV_vdpau_interop), GLL, 2010 },
GLL means the extension will only be exposed in a legacy context
(GL<=3.0). I think you meant GL instead.
Marek
More information about the mesa-dev
mailing list