Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/frontends/d3d10umd/Adapter.cpp
4565 views
1
/**************************************************************************
2
*
3
* Copyright 2012-2021 VMware, Inc.
4
* All Rights Reserved.
5
*
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
13
*
14
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
17
* THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
18
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
19
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20
* USE OR OTHER DEALINGS IN THE SOFTWARE.
21
*
22
* The above copyright notice and this permission notice (including the
23
* next paragraph) shall be included in all copies or substantial portions
24
* of the Software.
25
*
26
**************************************************************************/
27
28
/*
29
* Adpater.cpp --
30
* Driver entry point.
31
*/
32
33
34
#include "DriverIncludes.h"
35
#include "Device.h"
36
#include "State.h"
37
38
#include "Debug.h"
39
40
#include "util/u_memory.h"
41
42
43
EXTERN_C struct pipe_screen *
44
d3d10_create_screen(void);
45
46
47
static HRESULT APIENTRY CloseAdapter(D3D10DDI_HADAPTER hAdapter);
48
49
static unsigned long numAdapters = 0;
50
#if 0
51
static unsigned long memdbg_no = 0;
52
#endif
53
54
/*
55
* ----------------------------------------------------------------------
56
*
57
* OpenAdapterCommon --
58
*
59
* Common code for OpenAdapter10 and OpenAdapter10_2
60
*
61
* ----------------------------------------------------------------------
62
*/
63
64
65
static HRESULT
66
OpenAdapterCommon(__inout D3D10DDIARG_OPENADAPTER *pOpenData) // IN
67
{
68
#if 0
69
if (numAdapters == 0) {
70
memdbg_no = debug_memory_begin();
71
}
72
#endif
73
++numAdapters;
74
75
Adapter *pAdaptor = (Adapter *)calloc(sizeof *pAdaptor, 1);
76
if (!pAdaptor) {
77
--numAdapters;
78
return E_OUTOFMEMORY;
79
}
80
81
pAdaptor->screen = d3d10_create_screen();
82
if (!pAdaptor->screen) {
83
free(pAdaptor);
84
--numAdapters;
85
return E_OUTOFMEMORY;
86
}
87
88
pOpenData->hAdapter.pDrvPrivate = pAdaptor;
89
90
pOpenData->pAdapterFuncs->pfnCalcPrivateDeviceSize = CalcPrivateDeviceSize;
91
pOpenData->pAdapterFuncs->pfnCreateDevice = CreateDevice;
92
pOpenData->pAdapterFuncs->pfnCloseAdapter = CloseAdapter;
93
94
return S_OK;
95
}
96
97
98
/*
99
* ----------------------------------------------------------------------
100
*
101
* OpenAdapter10 --
102
*
103
* The OpenAdapter10 function creates a graphics adapter object
104
* that is referenced in subsequent calls.
105
*
106
* ----------------------------------------------------------------------
107
*/
108
109
110
EXTERN_C HRESULT APIENTRY
111
OpenAdapter10(__inout D3D10DDIARG_OPENADAPTER *pOpenData) // IN
112
{
113
LOG_ENTRYPOINT();
114
115
/*
116
* This is checked here and not on the common code because MSDN docs
117
* state that it should be ignored on OpenAdapter10_2.
118
*/
119
switch (pOpenData->Interface) {
120
case D3D10_0_DDI_INTERFACE_VERSION:
121
case D3D10_0_x_DDI_INTERFACE_VERSION:
122
case D3D10_0_7_DDI_INTERFACE_VERSION:
123
#if SUPPORT_D3D10_1
124
case D3D10_1_DDI_INTERFACE_VERSION:
125
case D3D10_1_x_DDI_INTERFACE_VERSION:
126
case D3D10_1_7_DDI_INTERFACE_VERSION:
127
#endif
128
#if SUPPORT_D3D11
129
case D3D11_0_DDI_INTERFACE_VERSION:
130
case D3D11_0_7_DDI_INTERFACE_VERSION:
131
#endif
132
break;
133
default:
134
if (0) {
135
DebugPrintf("%s: unsupported interface version 0x%08x\n",
136
__FUNCTION__, pOpenData->Interface);
137
}
138
return E_FAIL;
139
}
140
141
return OpenAdapterCommon(pOpenData);
142
}
143
144
145
static const UINT64
146
SupportedDDIInterfaceVersions[] = {
147
D3D10_0_DDI_SUPPORTED,
148
D3D10_0_x_DDI_SUPPORTED,
149
D3D10_0_7_DDI_SUPPORTED,
150
#if SUPPORT_D3D10_1
151
D3D10_1_DDI_SUPPORTED,
152
D3D10_1_x_DDI_SUPPORTED,
153
D3D10_1_7_DDI_SUPPORTED,
154
#endif
155
#if SUPPORT_D3D11
156
D3D11_0_DDI_SUPPORTED,
157
D3D11_0_7_DDI_SUPPORTED,
158
#endif
159
};
160
161
162
/*
163
* ----------------------------------------------------------------------
164
*
165
* GetSupportedVersions --
166
*
167
* Return a list of interface versions supported by the graphics
168
* adapter.
169
*
170
* ----------------------------------------------------------------------
171
*/
172
173
static HRESULT APIENTRY
174
GetSupportedVersions(D3D10DDI_HADAPTER hAdapter,
175
UINT32 *puEntries,
176
UINT64 *pSupportedDDIInterfaceVersions)
177
{
178
LOG_ENTRYPOINT();
179
180
if (pSupportedDDIInterfaceVersions &&
181
*puEntries < ARRAYSIZE(SupportedDDIInterfaceVersions)) {
182
return E_OUTOFMEMORY;
183
}
184
185
*puEntries = ARRAYSIZE(SupportedDDIInterfaceVersions);
186
187
if (pSupportedDDIInterfaceVersions) {
188
memcpy(pSupportedDDIInterfaceVersions,
189
SupportedDDIInterfaceVersions,
190
sizeof SupportedDDIInterfaceVersions);
191
}
192
193
return S_OK;
194
}
195
196
197
/*
198
* ----------------------------------------------------------------------
199
*
200
* GetCaps --
201
*
202
* Return the capabilities of the graphics adapter.
203
*
204
* ----------------------------------------------------------------------
205
*/
206
207
static HRESULT APIENTRY
208
GetCaps(D3D10DDI_HADAPTER hAdapter,
209
const D3D10_2DDIARG_GETCAPS *pData)
210
{
211
LOG_ENTRYPOINT();
212
memset(pData->pData, 0, pData->DataSize);
213
return S_OK;
214
}
215
216
217
/*
218
* ----------------------------------------------------------------------
219
*
220
* OpenAdapter10 --
221
*
222
* The OpenAdapter10 function creates a graphics adapter object
223
* that is referenced in subsequent calls.
224
*
225
* ----------------------------------------------------------------------
226
*/
227
228
229
EXTERN_C HRESULT APIENTRY
230
OpenAdapter10_2(__inout D3D10DDIARG_OPENADAPTER *pOpenData) // IN
231
{
232
LOG_ENTRYPOINT();
233
234
HRESULT hr = OpenAdapterCommon(pOpenData);
235
236
if (SUCCEEDED(hr)) {
237
pOpenData->pAdapterFuncs_2->pfnGetSupportedVersions = GetSupportedVersions;
238
pOpenData->pAdapterFuncs_2->pfnGetCaps = GetCaps;
239
}
240
241
return hr;
242
}
243
244
245
/*
246
* ----------------------------------------------------------------------
247
*
248
* CloseAdapter --
249
*
250
* The CloseAdapter function releases resources for a
251
* graphics adapter object.
252
*
253
* ----------------------------------------------------------------------
254
*/
255
256
HRESULT APIENTRY
257
CloseAdapter(D3D10DDI_HADAPTER hAdapter) // IN
258
{
259
LOG_ENTRYPOINT();
260
261
Adapter *pAdapter = CastAdapter(hAdapter);
262
struct pipe_screen *screen = pAdapter->screen;
263
screen->destroy(screen);
264
free(pAdapter);
265
266
--numAdapters;
267
#if 0
268
if (numAdapters == 0) {
269
debug_memory_end(memdbg_no);
270
}
271
#endif
272
273
return S_OK;
274
}
275
276