2 * Copyright 2014 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
22 #include "wine/debug.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d10
);
29 HRESULT WINAPI
D3D10CoreCreateDevice(IDXGIFactory
*factory
, IDXGIAdapter
*adapter
,
30 unsigned int flags
, D3D_FEATURE_LEVEL feature_level
, ID3D10Device
**device
);
32 #define WINE_D3D10_TO_STR(x) case x: return #x
34 static const char *debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type
)
38 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_HARDWARE
);
39 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_REFERENCE
);
40 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_NULL
);
41 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_SOFTWARE
);
42 WINE_D3D10_TO_STR(D3D10_DRIVER_TYPE_WARP
);
44 FIXME("Unrecognized D3D10_DRIVER_TYPE %#x.\n", driver_type
);
45 return "unrecognized";
49 static const char *debug_d3d10_feature_level(D3D10_FEATURE_LEVEL1 feature_level
)
51 switch (feature_level
)
53 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_10_0
);
54 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_10_1
);
55 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_1
);
56 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_2
);
57 WINE_D3D10_TO_STR(D3D10_FEATURE_LEVEL_9_3
);
59 FIXME("Unrecognized D3D10_FEATURE_LEVEL1 %#x.\n", feature_level
);
60 return "unrecognized";
64 #undef WINE_D3D10_TO_STR
66 HRESULT WINAPI
D3D10CreateDevice1(IDXGIAdapter
*adapter
, D3D10_DRIVER_TYPE driver_type
, HMODULE swrast
,
67 UINT flags
, D3D10_FEATURE_LEVEL1 hw_level
, UINT sdk_version
, ID3D10Device1
**device
)
69 IDXGIFactory
*factory
;
72 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, hw_level %s, sdk_version %d, device %p.\n",
73 adapter
, debug_d3d10_driver_type(driver_type
), swrast
, flags
,
74 debug_d3d10_feature_level(hw_level
), sdk_version
, device
);
86 IDXGIAdapter_AddRef(adapter
);
87 if (FAILED(hr
= IDXGIAdapter_GetParent(adapter
, &IID_IDXGIFactory
, (void **)&factory
)))
89 WARN("Failed to get dxgi factory, hr %#x.\n", hr
);
95 if (FAILED(hr
= CreateDXGIFactory(&IID_IDXGIFactory
, (void **)&factory
)))
97 WARN("Failed to create dxgi factory, hr %#x.\n", hr
);
103 case D3D10_DRIVER_TYPE_WARP
:
104 FIXME("WARP driver not implemented, falling back to hardware.\n");
105 case D3D10_DRIVER_TYPE_HARDWARE
:
107 if (FAILED(hr
= IDXGIFactory_EnumAdapters(factory
, 0, &adapter
)))
109 WARN("No adapters found, hr %#x.\n", hr
);
110 IDXGIFactory_Release(factory
);
116 case D3D10_DRIVER_TYPE_NULL
:
117 FIXME("NULL device not implemented, falling back to refrast.\n");
118 /* Fall through, for now. */
119 case D3D10_DRIVER_TYPE_REFERENCE
:
123 if (!(refrast
= LoadLibraryA("d3d10ref.dll")))
125 WARN("Failed to load refrast, returning E_FAIL.\n");
126 IDXGIFactory_Release(factory
);
129 hr
= IDXGIFactory_CreateSoftwareAdapter(factory
, refrast
, &adapter
);
130 FreeLibrary(refrast
);
133 WARN("Failed to create a software adapter, hr %#x.\n", hr
);
134 IDXGIFactory_Release(factory
);
140 case D3D10_DRIVER_TYPE_SOFTWARE
:
144 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
145 IDXGIFactory_Release(factory
);
148 if (FAILED(hr
= IDXGIFactory_CreateSoftwareAdapter(factory
, swrast
, &adapter
)))
150 WARN("Failed to create a software adapter, hr %#x.\n", hr
);
151 IDXGIFactory_Release(factory
);
158 FIXME("Unhandled driver type %#x.\n", driver_type
);
159 IDXGIFactory_Release(factory
);
164 hr
= D3D10CoreCreateDevice(factory
, adapter
, flags
, hw_level
, (ID3D10Device
**)device
);
165 IDXGIAdapter_Release(adapter
);
166 IDXGIFactory_Release(factory
);
169 WARN("Failed to create a device, hr %#x.\n", hr
);
173 TRACE("Created device %p.\n", *device
);
178 HRESULT WINAPI
D3D10CreateDeviceAndSwapChain1(IDXGIAdapter
*adapter
, D3D10_DRIVER_TYPE driver_type
,
179 HMODULE swrast
, UINT flags
, D3D10_FEATURE_LEVEL1 feature_level
, UINT sdk_version
,
180 DXGI_SWAP_CHAIN_DESC
*swapchain_desc
, IDXGISwapChain
**swapchain
, ID3D10Device1
**device
)
182 IDXGIDevice
*dxgi_device
;
183 IDXGIFactory
*factory
;
186 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, "
187 "feature_level %s, sdk_version %d, swapchain_desc %p, swapchain %p, device %p.\n",
188 adapter
, debug_d3d10_driver_type(driver_type
), swrast
, flags
,
189 debug_d3d10_feature_level(feature_level
), sdk_version
, swapchain_desc
, swapchain
, device
);
197 if (FAILED(hr
= D3D10CreateDevice1(adapter
, driver_type
, swrast
, flags
, feature_level
, sdk_version
, device
)))
199 WARN("Failed to create a device, returning %#x.\n", hr
);
206 if (FAILED(hr
= ID3D10Device1_QueryInterface(*device
, &IID_IDXGIDevice
, (void **)&dxgi_device
)))
208 ERR("Failed to get a dxgi device from the d3d10 device, returning %#x.\n", hr
);
212 hr
= IDXGIDevice_GetAdapter(dxgi_device
, &adapter
);
213 IDXGIDevice_Release(dxgi_device
);
216 ERR("Failed to get the device adapter, returning %#x.\n", hr
);
220 hr
= IDXGIAdapter_GetParent(adapter
, &IID_IDXGIFactory
, (void **)&factory
);
221 IDXGIAdapter_Release(adapter
);
224 ERR("Failed to get the adapter factory, returning %#x.\n", hr
);
228 hr
= IDXGIFactory_CreateSwapChain(factory
, (IUnknown
*)*device
, swapchain_desc
, swapchain
);
229 IDXGIFactory_Release(factory
);
232 WARN("Failed to create a swapchain, returning %#x.\n", hr
);
236 TRACE("Created IDXGISwapChain %p.\n", *swapchain
);
242 ID3D10Device1_Release(*device
);