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