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

dvpapi.cpp « gpudirect « intern - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 56b58e0a348afee3bddf308af4edaa4a28601a43 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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