Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenoit Bolsee <benoit.bolsee@online.be>2016-06-10 11:09:26 +0300
committerBenoit Bolsee <benoit.bolsee@online.be>2016-06-11 23:26:05 +0300
commiteea89417f4a3e2221e25c9c3ae6a601a61a05c22 (patch)
tree105930e1631fe5f4a14fa02e1d0cede90cd82071 /intern/gpudirect
parentc0bf881ebfa93784946ee3d03ccf15122c1b74c3 (diff)
BGE: DeckLink card support for video capture and streaming.
You can capture and stream video in the BGE using the DeckLink video cards from Black Magic Design. You need a card and Desktop Video software version 10.4 or above to use these features in the BGE. Many thanks to Nuno Estanquiero who tested the patch extensively on a variety of Decklink products, it wouldn't have been possible without his help. You can find a brief summary of the decklink features here: https://wiki.blender.org/index.php/Dev:Source/GameEngine/Decklink The full API details and samples are in the Python API documentation. bge.texture.VideoDeckLink(format, capture=0): Use this object to capture a video stream. the format argument describes the video and pixel formats and the capture argument the card number. This object can be used as a source for bge.texture.Texture so that the frame is sent to the GPU, or by itself using the new refresh method to get the video frame in a buffer. The frames are usually not in RGB but in YUV format (8bit or 10bit); they require a shader to extract the RGB components in the GPU. Details and sample shaders in the documentation. 3D video capture is supported: the frames are double height with left and right eyes in top-bottom order. The 'eye' uniform (see setUniformEyef) can be used to sample the 3D frame when the BGE is also in stereo mode. This allows to composite a 3D video stream with a 3D scene and render it in stereo. In Windows, and if you have a nVidia Quadro GPU, you can benefit of an additional performance boost by using 'GPUDirect': a method to send a video frame to the GPU without going through the OGL driver. The 'pinned memory' OGL extension is also supported (only on high-end AMD GPU) with the same effect. bge.texture.DeckLink(cardIdx=0, format=""): Use this object to send video frame to a DeckLink card. Only the immediate mode is supported, the scheduled mode is not implemented. This object is similar to bge.texture.Texture: you need to attach a image source and call refresh() to compute and send the frame to the card. This object is best suited for video keying: a video stream (not captured) flows through the card and the frame you send to the card are displayed above it (the card does the compositing automatically based on the alpha channel). At the time of this commit, 3D video keying is supported in the BGE but not in the DeckLink card due to a color space issue.
Diffstat (limited to 'intern/gpudirect')
-rw-r--r--intern/gpudirect/CMakeLists.txt41
-rw-r--r--intern/gpudirect/dvpapi.cpp147
-rw-r--r--intern/gpudirect/dvpapi.h667
3 files changed, 855 insertions, 0 deletions
diff --git a/intern/gpudirect/CMakeLists.txt b/intern/gpudirect/CMakeLists.txt
new file mode 100644
index 00000000000..88c09a663b8
--- /dev/null
+++ b/intern/gpudirect/CMakeLists.txt
@@ -0,0 +1,41 @@
+# ***** BEGIN GPL LICENSE BLOCK *****
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2015, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Blender Foundation.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+ # XXX, bad level include!
+ ../../source/blender/blenlib
+)
+
+set(INC_SYS
+ ${GLEW_INCLUDE_PATH}
+)
+
+set(SRC
+ dvpapi.cpp
+ dvpapi.h
+)
+
+blender_add_lib(bf_intern_gpudirect "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/intern/gpudirect/dvpapi.cpp b/intern/gpudirect/dvpapi.cpp
new file mode 100644
index 00000000000..8ae5cdbf17b
--- /dev/null
+++ b/intern/gpudirect/dvpapi.cpp
@@ -0,0 +1,147 @@
+/*
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* The Original Code is Copyright (C) 2015, Blender Foundation
+* All rights reserved.
+*
+* The Original Code is: all of this file.
+*
+* Contributor(s): Blender Foundation.
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+/** \file gpudirect/dvpapi.c
+* \ingroup gpudirect
+*/
+
+#ifdef WIN32
+
+#include <stdlib.h>
+#include "dvpapi.h"
+
+extern "C" {
+#include "BLI_dynlib.h"
+}
+
+#define KDVPAPI_Name "dvp.dll"
+
+typedef DVPStatus (DVPAPIENTRY * PFNDVPINITGLCONTEXT) (uint32_t flags);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPCLOSEGLCONTEXT) (void);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPGETLIBRARYVERSION)(uint32_t *major, uint32_t *minor);
+
+static uint32_t __dvpMajorVersion = 0;
+static uint32_t __dvpMinorVersion = 0;
+static PFNDVPGETLIBRARYVERSION __dvpGetLibrayVersion = NULL;
+static PFNDVPINITGLCONTEXT __dvpInitGLContext = NULL;
+static PFNDVPCLOSEGLCONTEXT __dvpCloseGLContext = NULL;
+PFNDVPBEGIN __dvpBegin = NULL;
+PFNDVPEND __dvpEnd = NULL;
+PFNDVPCREATEBUFFER __dvpCreateBuffer = NULL;
+PFNDVPDESTROYBUFFER __dvpDestroyBuffer = NULL;
+PFNDVPFREEBUFFER __dvpFreeBuffer = NULL;
+PFNDVPMEMCPYLINED __dvpMemcpyLined = NULL;
+PFNDVPMEMCPY __dvpMemcpy = NULL;
+PFNDVPIMPORTSYNCOBJECT __dvpImportSyncObject = NULL;
+PFNDVPFREESYNCOBJECT __dvpFreeSyncObject = NULL;
+PFNDVPMAPBUFFERENDAPI __dvpMapBufferEndAPI = NULL;
+PFNDVPMAPBUFFERWAITDVP __dvpMapBufferWaitDVP = NULL;
+PFNDVPMAPBUFFERENDDVP __dvpMapBufferEndDVP = NULL;
+PFNDVPMAPBUFFERWAITAPI __dvpMapBufferWaitAPI = NULL;
+PFNDVPBINDTOGLCTX __dvpBindToGLCtx = NULL;
+PFNDVPGETREQUIREDCONSTANTSGLCTX __dvpGetRequiredConstantsGLCtx = NULL;
+PFNDVPCREATEGPUTEXTUREGL __dvpCreateGPUTextureGL = NULL;
+PFNDVPUNBINDFROMGLCTX __dvpUnbindFromGLCtx = NULL;
+
+static DynamicLibrary *__dvpLibrary = NULL;
+
+DVPStatus dvpGetLibrayVersion(uint32_t *major, uint32_t *minor)
+{
+ if (!__dvpLibrary)
+ return DVP_STATUS_ERROR;
+ *major = __dvpMajorVersion;
+ *minor = __dvpMinorVersion;
+ return DVP_STATUS_OK;
+}
+
+DVPStatus dvpInitGLContext(uint32_t flags)
+{
+ DVPStatus status;
+ if (!__dvpLibrary) {
+ __dvpLibrary = BLI_dynlib_open(KDVPAPI_Name);
+ if (!__dvpLibrary) {
+ return DVP_STATUS_ERROR;
+ }
+// "?dvpInitGLContext@@YA?AW4DVPStatus@@I@Z";
+ __dvpInitGLContext = (PFNDVPINITGLCONTEXT)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpInitGLContext@@YA?AW4DVPStatus@@I@Z");
+ __dvpCloseGLContext = (PFNDVPCLOSEGLCONTEXT)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpCloseGLContext@@YA?AW4DVPStatus@@XZ");
+ __dvpGetLibrayVersion = (PFNDVPGETLIBRARYVERSION)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpGetLibrayVersion@@YA?AW4DVPStatus@@PEAI0@Z");
+ __dvpBegin = (PFNDVPBEGIN)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpBegin@@YA?AW4DVPStatus@@XZ");
+ __dvpEnd = (PFNDVPEND)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpEnd@@YA?AW4DVPStatus@@XZ");
+ __dvpCreateBuffer = (PFNDVPCREATEBUFFER)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpCreateBuffer@@YA?AW4DVPStatus@@PEAUDVPSysmemBufferDescRec@@PEA_K@Z");
+ __dvpDestroyBuffer = (PFNDVPDESTROYBUFFER)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpDestroyBuffer@@YA?AW4DVPStatus@@_K@Z");
+ __dvpFreeBuffer = (PFNDVPFREEBUFFER)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpFreeBuffer@@YA?AW4DVPStatus@@_K@Z");
+ __dvpMemcpyLined = (PFNDVPMEMCPYLINED)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpMemcpyLined@@YA?AW4DVPStatus@@_K0I000III@Z");
+ __dvpMemcpy = (PFNDVPMEMCPY)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpMemcpy2D@@YA?AW4DVPStatus@@_K0I000IIIII@Z");
+ __dvpImportSyncObject = (PFNDVPIMPORTSYNCOBJECT)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpImportSyncObject@@YA?AW4DVPStatus@@PEAUDVPSyncObjectDescRec@@PEA_K@Z");
+ __dvpFreeSyncObject = (PFNDVPFREESYNCOBJECT)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpFreeSyncObject@@YA?AW4DVPStatus@@_K@Z");
+ __dvpMapBufferEndAPI = (PFNDVPMAPBUFFERENDAPI)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpMapBufferEndAPI@@YA?AW4DVPStatus@@_K@Z");
+ __dvpMapBufferWaitDVP = (PFNDVPMAPBUFFERWAITDVP)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpMapBufferWaitDVP@@YA?AW4DVPStatus@@_K@Z");
+ __dvpMapBufferEndDVP = (PFNDVPMAPBUFFERENDDVP)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpMapBufferEndDVP@@YA?AW4DVPStatus@@_K@Z");
+ __dvpMapBufferWaitAPI = (PFNDVPMAPBUFFERWAITAPI)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpMapBufferWaitAPI@@YA?AW4DVPStatus@@_K@Z");
+ __dvpBindToGLCtx = (PFNDVPBINDTOGLCTX)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpBindToGLCtx@@YA?AW4DVPStatus@@_K@Z");
+ __dvpGetRequiredConstantsGLCtx = (PFNDVPGETREQUIREDCONSTANTSGLCTX)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpGetRequiredConstantsGLCtx@@YA?AW4DVPStatus@@PEAI00000@Z");
+ __dvpCreateGPUTextureGL = (PFNDVPCREATEGPUTEXTUREGL)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpCreateGPUTextureGL@@YA?AW4DVPStatus@@IPEA_K@Z");
+ __dvpUnbindFromGLCtx = (PFNDVPUNBINDFROMGLCTX)BLI_dynlib_find_symbol(__dvpLibrary, "?dvpUnbindFromGLCtx@@YA?AW4DVPStatus@@_K@Z");
+ if (!__dvpInitGLContext ||
+ !__dvpCloseGLContext ||
+ !__dvpGetLibrayVersion ||
+ !__dvpBegin ||
+ !__dvpEnd ||
+ !__dvpCreateBuffer ||
+ !__dvpDestroyBuffer ||
+ !__dvpFreeBuffer ||
+ !__dvpMemcpyLined ||
+ !__dvpMemcpy ||
+ !__dvpImportSyncObject ||
+ !__dvpFreeSyncObject ||
+ !__dvpMapBufferEndAPI ||
+ !__dvpMapBufferWaitDVP ||
+ !__dvpMapBufferEndDVP ||
+ !__dvpMapBufferWaitAPI ||
+ !__dvpBindToGLCtx ||
+ !__dvpGetRequiredConstantsGLCtx ||
+ !__dvpCreateGPUTextureGL ||
+ !__dvpUnbindFromGLCtx)
+ {
+ return DVP_STATUS_ERROR;
+ }
+ // check that the library version is what we want
+ if ((status = __dvpGetLibrayVersion(&__dvpMajorVersion, &__dvpMinorVersion)) != DVP_STATUS_OK)
+ return status;
+ if (__dvpMajorVersion != DVP_MAJOR_VERSION || __dvpMinorVersion < DVP_MINOR_VERSION)
+ return DVP_STATUS_ERROR;
+ }
+ return (!__dvpInitGLContext) ? DVP_STATUS_ERROR : __dvpInitGLContext(flags);
+}
+
+DVPStatus dvpCloseGLContext(void)
+{
+ return (!__dvpCloseGLContext) ? DVP_STATUS_ERROR : __dvpCloseGLContext();
+}
+
+#endif // WIN32
diff --git a/intern/gpudirect/dvpapi.h b/intern/gpudirect/dvpapi.h
new file mode 100644
index 00000000000..4cc259f0fe8
--- /dev/null
+++ b/intern/gpudirect/dvpapi.h
@@ -0,0 +1,667 @@
+/*
+* ***** BEGIN GPL LICENSE BLOCK *****
+*
+* This program is free software; you can redistribute it and/or
+* modify it under the terms of the GNU General Public License
+* as published by the Free Software Foundation; either version 2
+* of the License, or (at your option) any later version.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU General Public License for more details.
+*
+* You should have received a copy of the GNU General Public License
+* along with this program; if not, write to the Free Software Foundation,
+* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+*
+* The Original Code is Copyright (C) 2015, Blender Foundation
+* All rights reserved.
+*
+* The Original Code is: all of this file.
+*
+* Contributor(s): Blender Foundation.
+*
+* ***** END GPL LICENSE BLOCK *****
+*/
+
+/** \file gpudirect/dvpapi.h
+* \ingroup gpudirect
+*/
+
+#ifndef __DVPAPI_H__
+#define __DVPAPI_H__
+
+#ifdef WIN32
+
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "GL/glew.h"
+
+#if defined(__GNUC__) && __GNUC__>=4
+# define DVPAPI extern __attribute__ ((visibility("default")))
+#elif defined(__SUNPRO_C) || defined(__SUNPRO_CC)
+# define DVPAPI extern __global
+#else
+# define DVPAPI extern
+#endif
+
+#define DVPAPIENTRY
+#define DVP_MAJOR_VERSION 1
+#define DVP_MINOR_VERSION 63
+
+typedef uint64_t DVPBufferHandle;
+typedef uint64_t DVPSyncObjectHandle;
+
+typedef enum {
+ DVP_STATUS_OK = 0,
+ DVP_STATUS_INVALID_PARAMETER = 1,
+ DVP_STATUS_UNSUPPORTED = 2,
+ DVP_STATUS_END_ENUMERATION = 3,
+ DVP_STATUS_INVALID_DEVICE = 4,
+ DVP_STATUS_OUT_OF_MEMORY = 5,
+ DVP_STATUS_INVALID_OPERATION = 6,
+ DVP_STATUS_TIMEOUT = 7,
+ DVP_STATUS_INVALID_CONTEXT = 8,
+ DVP_STATUS_INVALID_RESOURCE_TYPE = 9,
+ DVP_STATUS_INVALID_FORMAT_OR_TYPE = 10,
+ DVP_STATUS_DEVICE_UNINITIALIZED = 11,
+ DVP_STATUS_UNSIGNALED = 12,
+ DVP_STATUS_SYNC_ERROR = 13,
+ DVP_STATUS_SYNC_STILL_BOUND = 14,
+ DVP_STATUS_ERROR = -1,
+} DVPStatus;
+
+// Pixel component formats stored in the system memory buffer
+// analogous to those defined in the OpenGL API, except for
+// DVP_BUFFER and the DVP_CUDA_* types. DVP_BUFFER provides
+// an unspecified format type to allow for general interpretation
+// of the bytes at a later stage (in GPU shader). Note that not
+// all paths will achieve optimal speeds due to lack of HW support
+// for the transformation. The CUDA types are to be used when
+// copying to/from a system memory buffer from-to a CUDA array, as the
+// CUDA array implies a memory layout that matches the array.
+typedef enum {
+ DVP_BUFFER, // Buffer treated as a raw buffer
+ // and copied directly into GPU buffer
+ // without any interpretation of the
+ // stored bytes.
+ DVP_DEPTH_COMPONENT,
+ DVP_RGBA,
+ DVP_BGRA,
+ DVP_RED,
+ DVP_GREEN,
+ DVP_BLUE,
+ DVP_ALPHA,
+ DVP_RGB,
+ DVP_BGR,
+ DVP_LUMINANCE,
+ DVP_LUMINANCE_ALPHA,
+ DVP_CUDA_1_CHANNEL,
+ DVP_CUDA_2_CHANNELS,
+ DVP_CUDA_4_CHANNELS,
+ DVP_RGBA_INTEGER,
+ DVP_BGRA_INTEGER,
+ DVP_RED_INTEGER,
+ DVP_GREEN_INTEGER,
+ DVP_BLUE_INTEGER,
+ DVP_ALPHA_INTEGER,
+ DVP_RGB_INTEGER,
+ DVP_BGR_INTEGER,
+ DVP_LUMINANCE_INTEGER,
+ DVP_LUMINANCE_ALPHA_INTEGER,
+} DVPBufferFormats;
+
+// Possible pixel component storage types for system memory buffers
+typedef enum {
+ DVP_UNSIGNED_BYTE,
+ DVP_BYTE,
+ DVP_UNSIGNED_SHORT,
+ DVP_SHORT,
+ DVP_UNSIGNED_INT,
+ DVP_INT,
+ DVP_FLOAT,
+ DVP_HALF_FLOAT,
+ DVP_UNSIGNED_BYTE_3_3_2,
+ DVP_UNSIGNED_BYTE_2_3_3_REV,
+ DVP_UNSIGNED_SHORT_5_6_5,
+ DVP_UNSIGNED_SHORT_5_6_5_REV,
+ DVP_UNSIGNED_SHORT_4_4_4_4,
+ DVP_UNSIGNED_SHORT_4_4_4_4_REV,
+ DVP_UNSIGNED_SHORT_5_5_5_1,
+ DVP_UNSIGNED_SHORT_1_5_5_5_REV,
+ DVP_UNSIGNED_INT_8_8_8_8,
+ DVP_UNSIGNED_INT_8_8_8_8_REV,
+ DVP_UNSIGNED_INT_10_10_10_2,
+ DVP_UNSIGNED_INT_2_10_10_10_REV,
+} DVPBufferTypes;
+
+// System memory descriptor describing the size and storage formats
+// of the buffer
+typedef struct DVPSysmemBufferDescRec {
+ uint32_t width; // Buffer Width
+ uint32_t height; // Buffer Height
+ uint32_t stride; // Stride
+ uint32_t size; // Specifies the surface size if
+ // format == DVP_BUFFER
+ DVPBufferFormats format; // see enum above
+ DVPBufferTypes type; // see enum above
+ void *bufAddr; // Buffer memory address
+} DVPSysmemBufferDesc;
+
+// Flags specified at sync object creation:
+// ----------------------------------------
+// Tells the implementation to use events wherever
+// possible instead of software spin loops. Note if HW
+// wait operations are supported by the implementation
+// then events will not be used in the dvpMemcpy*
+// functions. In such a case, events may still be used
+// in dvpSyncObjClientWait* functions.
+#define DVP_SYNC_OBJECT_FLAGS_USE_EVENTS 0x00000001
+
+typedef struct DVPSyncObjectDescRec {
+ uint32_t *sem; // Location to write semaphore value
+ uint32_t flags; // See above DVP_SYNC_OBJECT_FLAGS_* bits
+ DVPStatus (*externalClientWaitFunc) (DVPSyncObjectHandle sync,
+ uint32_t value,
+ bool GEQ, // If true then the function should wait for the sync value to be
+ // greater than or equal to the value parameter. Otherwise just a
+ // straight forward equality comparison should be performed.
+ uint64_t timeout);
+ // If non-null, externalClientWaitFunc allows the DVP library
+ // to call the application to wait for a sync object to be
+ // released. This allows the application to create events,
+ // which can be triggered on device interrupts instead of
+ // using spin loops inside the DVP library. Upon succeeding
+ // the function must return DVP_STATUS_OK, non-zero for failure
+ // and DVP_STATUS_TIMEOUT on timeout. The externalClientWaitFunc should
+ // not alter the current GL or CUDA context state
+} DVPSyncObjectDesc;
+
+// Time used when event timeouts should be ignored
+#define DVP_TIMEOUT_IGNORED 0xFFFFFFFFFFFFFFFFull
+
+typedef DVPStatus (DVPAPIENTRY * PFNDVPBEGIN) (void);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPEND) (void);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPCREATEBUFFER)(DVPSysmemBufferDesc *desc, DVPBufferHandle *hBuf);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPDESTROYBUFFER)(DVPBufferHandle hBuf);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPFREEBUFFER)(DVPBufferHandle gpuBufferHandle);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPMEMCPYLINED)(DVPBufferHandle srcBuffer,
+ DVPSyncObjectHandle srcSync,
+ uint32_t srcAcquireValue,
+ uint64_t timeout,
+ DVPBufferHandle dstBuffer,
+ DVPSyncObjectHandle dstSync,
+ uint32_t dstReleaseValue,
+ uint32_t startingLine,
+ uint32_t numberOfLines);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPMEMCPY)(DVPBufferHandle srcBuffer,
+ DVPSyncObjectHandle srcSync,
+ uint32_t srcAcquireValue,
+ uint64_t timeout,
+ DVPBufferHandle dstBuffer,
+ DVPSyncObjectHandle dstSync,
+ uint32_t dstReleaseValue,
+ uint32_t srcOffset,
+ uint32_t dstOffset,
+ uint32_t count);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPIMPORTSYNCOBJECT)(DVPSyncObjectDesc *desc,
+ DVPSyncObjectHandle *syncObject);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPFREESYNCOBJECT)(DVPSyncObjectHandle syncObject);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPGETREQUIREDCONSTANTSGLCTX)(uint32_t *bufferAddrAlignment,
+ uint32_t *bufferGPUStrideAlignment,
+ uint32_t *semaphoreAddrAlignment,
+ uint32_t *semaphoreAllocSize,
+ uint32_t *semaphorePayloadOffset,
+ uint32_t *semaphorePayloadSize);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPBINDTOGLCTX)(DVPBufferHandle hBuf);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPUNBINDFROMGLCTX)(DVPBufferHandle hBuf);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPMAPBUFFERENDAPI)(DVPBufferHandle gpuBufferHandle);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPMAPBUFFERWAITDVP)(DVPBufferHandle gpuBufferHandle);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPMAPBUFFERENDDVP)(DVPBufferHandle gpuBufferHandle);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPMAPBUFFERWAITAPI)(DVPBufferHandle gpuBufferHandle);
+typedef DVPStatus (DVPAPIENTRY * PFNDVPCREATEGPUTEXTUREGL)(GLuint texID,
+ DVPBufferHandle *bufferHandle);
+
+// Flags supplied to the dvpInit* functions:
+//
+// DVP_DEVICE_FLAGS_SHARE_APP_CONTEXT is only supported for OpenGL
+// contexts and is the only supported flag for CUDA. It allows for
+// certain cases to be optimized by sharing the context
+// of the application for the DVP operations. This removes the
+// need to do certain synchronizations. See issue 5 for parallel
+// issues. When used, the app's GL context must be current for all calls
+// to the DVP library.
+// the DVP library.
+#define DVP_DEVICE_FLAGS_SHARE_APP_CONTEXT 0x000000001
+
+//------------------------------------------------------------------------
+// Function: dvpInitGLContext
+//
+// To be called before any DVP resources are allocated.
+// This call allows for specification of flags that may
+// change the way DVP operations are performed. See above
+// for the list of flags.
+//
+// The OpenGL context must be current at time of call.
+//
+// Parameters: flags[IN] - Buffer description structure
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+extern DVPStatus dvpInitGLContext(uint32_t flags);
+
+//------------------------------------------------------------------------
+// Function: dvpCloseGLContext
+//
+// Function to be called when app closes to allow freeing
+// of any DVP library allocated resources.
+//
+// The OpenGL context must be current at time of call.
+//
+// Parameters: none
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+extern DVPStatus dvpCloseGLContext();
+
+//------------------------------------------------------------------------
+// Function: dvpGetLibrayVersion
+//
+// Description: Returns the current version of the library
+//
+// Parameters: major[OUT] - returned major version
+// minor[OUT] - returned minor version
+//
+// Returns: DVP_STATUS_OK
+//------------------------------------------------------------------------
+extern DVPStatus dvpGetLibrayVersion(uint32_t *major, uint32_t *minor);
+
+//------------------------------------------------------------------------
+// Function: dvpBegin
+//
+// Description: dvpBegin must be called before any combination of DVP
+// function calls dvpMemCpy*, dvpMapBufferWaitDVP,
+// dvpSyncObjClientWait*, and dvpMapBufferEndDVP. After
+// the last of these functions has been called is dvpEnd
+// must be called. This allows for more efficient batched
+// DVP operations.
+//
+// Parameters: none
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpBegin DVPAPI_GET_FUN(__dvpBegin)
+
+//------------------------------------------------------------------------
+// Function: dvpEnd
+//
+// Description: dvpEnd signals the end of a batch of DVP function calls
+// that began with dvpBegin
+//
+// Parameters: none
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpEnd DVPAPI_GET_FUN(__dvpEnd)
+
+
+//------------------------------------------------------------------------
+// Function: dvpCreateBuffer
+//
+// Description: Create a DVP buffer using system memory, wrapping a user
+// passed pointer. The pointer must be aligned
+// to values returned by dvpGetRequiredAlignments*
+//
+// Parameters: desc[IN] - Buffer description structure
+// hBuf[OUT] - DVP Buffer handle
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpCreateBuffer DVPAPI_GET_FUN(__dvpCreateBuffer)
+
+
+//------------------------------------------------------------------------
+// Function: dvpDestroyBuffer
+//
+// Description: Destroy a previously created DVP buffer.
+//
+// Parameters: hBuf[IN] - DVP Buffer handle
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpDestroyBuffer DVPAPI_GET_FUN(__dvpDestroyBuffer)
+
+//------------------------------------------------------------------------
+// Function: dvpFreeBuffer
+//
+// Description: dvpFreeBuffer frees the DVP buffer reference
+//
+// Parameters: gpuBufferHandle[IN] - DVP Buffer handle
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpFreeBuffer DVPAPI_GET_FUN(__dvpFreeBuffer)
+
+//------------------------------------------------------------------------
+// Function: dvpMemcpyLined
+//
+// Description: dvpMemcpyLined provides buffer copies between a
+// DVP sysmem buffer and a graphics API texture (as opposed to
+// a buffer type). Other buffer types (such
+// as graphics API buffers) return DVP_STATUS_INVALID_PARAMETER.
+//
+// In addition, see "dvpMemcpy* general comments" above.
+//
+// Parameters: srcBuffer[IN] - src buffer handle
+// srcSync[IN] - sync to acquire on before transfer
+// srcAcquireValue[IN] - value to acquire on before transfer
+// timeout[IN] - time out value in nanoseconds.
+// dstBuffer[IN] - src buffer handle
+// dstSync[IN] - sync to release on transfer completion
+// dstReleaseValue[IN] - value to release on completion
+// startingLine[IN] - starting line of buffer
+// numberOfLines[IN] - number of lines to copy
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//
+// GL state effected: The following GL state may be altered by this
+// function (not relevant if no GL source or destination
+// is used):
+// -GL_PACK_SKIP_ROWS, GL_PACK_SKIP_PIXELS,
+// GL_PACK_ROW_LENGTH
+// -The buffer bound to GL_PIXEL_PACK_BUFFER
+// -The current bound framebuffer (GL_FRAMEBUFFER_EXT)
+// -GL_UNPACK_SKIP_ROWS, GL_UNPACK_SKIP_PIXELS,
+// GL_UNPACK_ROW_LENGTH
+// -The buffer bound to GL_PIXEL_UNPACK_BUFFER
+// -The texture bound to GL_TEXTURE_2D
+//------------------------------------------------------------------------
+#define dvpMemcpyLined DVPAPI_GET_FUN(__dvpMemcpyLined)
+
+
+//------------------------------------------------------------------------
+// Function: dvpMemcpy
+//
+// Description: dvpMemcpy provides buffer copies between a
+// DVP sysmem buffer and a graphics API pure buffer (as
+// opposed to a texture type). Other buffer types (such
+// as graphics API textures) return
+// DVP_STATUS_INVALID_PARAMETER.
+//
+// The start address of the srcBuffer is given by srcOffset
+// and the dstBuffer start address is given by dstOffset.
+//
+// In addition, see "dvpMemcpy* general comments" above.
+//
+// Parameters: srcBuffer[IN] - src buffer handle
+// srcSync[IN] - sync to acquire on before transfer
+// srcAcquireValue[IN] - value to acquire on before transfer
+// timeout[IN] - time out value in nanoseconds.
+// dstBuffer[IN] - src buffer handle
+// dstSync[IN] - sync to release on completion
+// dstReleaseValue[IN] - value to release on completion
+// uint32_t srcOffset[IN] - byte offset of srcBuffer
+// uint32_t dstOffset[IN] - byte offset of dstBuffer
+// uint32_t count[IN] - number of bytes to copy
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//
+// GL state effected: The following GL state may be altered by this
+// function (not relevant if no GL source or destination
+// is used):
+// - The buffer bound to GL_COPY_WRITE_BUFFER
+// - The buffer bound to GL_COPY_READ_BUFFER
+//
+//------------------------------------------------------------------------
+#define dvpMemcpy DVPAPI_GET_FUN(__dvpMemcpy)
+
+//------------------------------------------------------------------------
+// Function: dvpImportSyncObject
+//
+// Description: dvpImportSyncObject creates a DVPSyncObject from the
+// DVPSyncObjectDesc. Note that a sync object is not
+// supported for copy operations targeting different APIs.
+// This means, for example, it is illegal to call dvpMemCpy*
+// for source or target GL texture with sync object A and
+// then later use that same sync object in dvpMemCpy*
+// operation for a source or target CUDA buffer. The same
+// semaphore memory can still be used for two different sync
+// objects.
+//
+// Parameters: desc[IN] - data describing the sync object
+// syncObject[OUT] - handle to sync object
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpImportSyncObject DVPAPI_GET_FUN(__dvpImportSyncObject)
+
+//------------------------------------------------------------------------
+// Function: dvpFreeSyncObject
+//
+// Description: dvpFreeSyncObject waits for any outstanding releases on
+// this sync object before freeing the resources allocated for
+// the specified sync object. The application must make sure
+// any outstanding acquire operations have already been
+// completed.
+//
+// If OpenGL is being used and the app's GL context is being
+// shared (via the DVP_DEVICE_FLAGS_SHARE_APP_CONTEXT flag),
+// then dvpFreeSyncObject needs to be called while each context,
+// on which the sync object was used, is current. If
+// DVP_DEVICE_FLAGS_SHARE_APP_CONTEXT is used and there are out
+// standing contexts from which this sync object must be free'd
+// then dvpFreeSyncObject will return DVP_STATUS_SYNC_STILL_BOUND.
+//
+// Parameters: syncObject[IN] - handle to sync object to be free'd
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+// DVP_STATUS_SYNC_STILL_BOUND
+//------------------------------------------------------------------------
+#define dvpFreeSyncObject DVPAPI_GET_FUN(__dvpFreeSyncObject)
+
+
+//------------------------------------------------------------------------
+// Function: dvpMapBufferEndAPI
+//
+// Description: Tells DVP to setup a signal for this buffer in the
+// callers API context or device. The signal follows all
+// previous API operations up to this point and, thus,
+// allows subsequent DVP calls to know when then this buffer
+// is ready for use within the DVP library. This function
+// would be followed by a call to dvpMapBufferWaitDVP to
+// synchronize rendering in the API stream and the DVP
+// stream.
+//
+// If OpenGL or CUDA is used, the OpenGL/CUDA context
+// must be current at time of call.
+//
+// The use of dvpMapBufferEndAPI is NOT recommended for
+// CUDA synchronisation, as it is more optimal to use a
+// applcation CUDA stream in conjunction with
+// dvpMapBufferEndCUDAStream. This allows the driver to
+// do optimisations, such as parllelise the copy operations
+// and compute.
+//
+// This must be called outside the dvpBegin/dvpEnd pair. In
+// addition, this call is not thread safe and must be called
+// from or fenced against the rendering thread associated with
+// the context or device.
+//
+// Parameters: gpuBufferHandle[IN] - buffer to track
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+// DVP_STATUS_UNSIGNALED - returned if the API is
+// unable to place a signal in the API context queue
+//------------------------------------------------------------------------
+#define dvpMapBufferEndAPI DVPAPI_GET_FUN(__dvpMapBufferEndAPI)
+
+//------------------------------------------------------------------------
+// Function: dvpMapBufferEndAPI
+//
+// Description: Tells DVP to setup a signal for this buffer in the
+// callers API context or device. The signal follows all
+// previous API operations up to this point and, thus,
+// allows subsequent DVP calls to know when then this buffer
+// is ready for use within the DVP library. This function
+// would be followed by a call to dvpMapBufferWaitDVP to
+// synchronize rendering in the API stream and the DVP
+// stream.
+//
+// If OpenGL or CUDA is used, the OpenGL/CUDA context
+// must be current at time of call.
+//
+// The use of dvpMapBufferEndAPI is NOT recommended for
+// CUDA synchronisation, as it is more optimal to use a
+// applcation CUDA stream in conjunction with
+// dvpMapBufferEndCUDAStream. This allows the driver to
+// do optimisations, such as parllelise the copy operations
+// and compute.
+//
+// This must be called outside the dvpBegin/dvpEnd pair. In
+// addition, this call is not thread safe and must be called
+// from or fenced against the rendering thread associated with
+// the context or device.
+//
+// Parameters: gpuBufferHandle[IN] - buffer to track
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+// DVP_STATUS_UNSIGNALED - returned if the API is
+// unable to place a signal in the API context queue
+//------------------------------------------------------------------------
+#define dvpMapBufferEndAPI DVPAPI_GET_FUN(__dvpMapBufferEndAPI)
+
+//------------------------------------------------------------------------
+// Function: dvpMapBufferWaitDVP
+//
+// Description: Tells DVP to make the DVP stream wait for a previous
+// signal triggered by a dvpMapBufferEndAPI call.
+//
+// This must be called inside the dvpBegin/dvpEnd pair.
+//
+// Parameters: gpuBufferHandle[IN] - buffer to track
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpMapBufferWaitDVP DVPAPI_GET_FUN(__dvpMapBufferWaitDVP)
+
+//------------------------------------------------------------------------
+// Function: dvpMapBufferEndDVP
+//
+// Description: Tells DVP to setup a signal for this buffer after
+// DVP operations are complete. The signal allows
+// the API to know when then this buffer is
+// ready for use within a API stream. This function would
+// be followed by a call to dvpMapBufferWaitAPI to
+// synchronize copies in the DVP stream and the API
+// rendering stream.
+//
+// This must be called inside the dvpBegin/dvpEnd pair.
+//
+// Parameters: gpuBufferHandle[IN] - buffer to track
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpMapBufferEndDVP DVPAPI_GET_FUN(__dvpMapBufferEndDVP)
+
+//------------------------------------------------------------------------
+// Function: dvpMapBufferWaitAPI
+//
+// Description: Tells DVP to make the current API context or device to
+// wait for a previous signal triggered by a
+// dvpMapBufferEndDVP call.
+//
+// The use of dvpMapBufferWaitCUDAStream is NOT recommended for
+// CUDA synchronisation, as it is more optimal to use a
+// applcation CUDA stream in conjunction with
+// dvpMapBufferEndCUDAStream. This allows the driver to
+// do optimisations, such as parllelise the copy operations
+// and compute.
+//
+// If OpenGL or CUDA is used, the OpenGL/CUDA context
+// must be current at time of call.
+//
+// This must be called outside the dvpBegin/dvpEnd pair. In
+// addition, this call is not thread safe and must be called
+// from or fenced against the rendering thread associated with
+// the context or device.
+//
+// Parameters: gpuBufferHandle[IN] - buffer to track
+//
+// Returns: DVP_STATUS_OK
+// DVP_STATUS_INVALID_PARAMETER
+// DVP_STATUS_ERROR
+//------------------------------------------------------------------------
+#define dvpMapBufferWaitAPI DVPAPI_GET_FUN(__dvpMapBufferWaitAPI)
+
+//------------------------------------------------------------------------
+// If the multiple GL contexts used in the application access the same
+// sysmem buffers, then application must create those GL contexts with
+// display list shared.
+//------------------------------------------------------------------------
+#define dvpBindToGLCtx DVPAPI_GET_FUN(__dvpBindToGLCtx)
+#define dvpGetRequiredConstantsGLCtx DVPAPI_GET_FUN(__dvpGetRequiredConstantsGLCtx)
+#define dvpCreateGPUTextureGL DVPAPI_GET_FUN(__dvpCreateGPUTextureGL)
+#define dvpUnbindFromGLCtx DVPAPI_GET_FUN(__dvpUnbindFromGLCtx)
+
+
+DVPAPI PFNDVPBEGIN __dvpBegin;
+DVPAPI PFNDVPEND __dvpEnd;
+DVPAPI PFNDVPCREATEBUFFER __dvpCreateBuffer;
+DVPAPI PFNDVPDESTROYBUFFER __dvpDestroyBuffer;
+DVPAPI PFNDVPFREEBUFFER __dvpFreeBuffer;
+DVPAPI PFNDVPMEMCPYLINED __dvpMemcpyLined;
+DVPAPI PFNDVPMEMCPY __dvpMemcpy;
+DVPAPI PFNDVPIMPORTSYNCOBJECT __dvpImportSyncObject;
+DVPAPI PFNDVPFREESYNCOBJECT __dvpFreeSyncObject;
+DVPAPI PFNDVPMAPBUFFERENDAPI __dvpMapBufferEndAPI;
+DVPAPI PFNDVPMAPBUFFERWAITDVP __dvpMapBufferWaitDVP;
+DVPAPI PFNDVPMAPBUFFERENDDVP __dvpMapBufferEndDVP;
+DVPAPI PFNDVPMAPBUFFERWAITAPI __dvpMapBufferWaitAPI;
+
+
+//------------------------------------------------------------------------
+// If the multiple GL contexts used in the application access the same
+// sysmem buffers, then application must create those GL contexts with
+// display list shared.
+//------------------------------------------------------------------------
+DVPAPI PFNDVPBINDTOGLCTX __dvpBindToGLCtx;
+DVPAPI PFNDVPGETREQUIREDCONSTANTSGLCTX __dvpGetRequiredConstantsGLCtx;
+DVPAPI PFNDVPCREATEGPUTEXTUREGL __dvpCreateGPUTextureGL;
+DVPAPI PFNDVPUNBINDFROMGLCTX __dvpUnbindFromGLCtx;
+
+#define DVPAPI_GET_FUN(x) x
+
+#endif // WIN32
+
+#endif // __DVPAPI_H__
+