ReactOS 0.4.17-dev-934-g091855f
d3d10_main.c
Go to the documentation of this file.
1/*
2 * Direct3D 10
3 *
4 * Copyright 2007 Andras Kovacs
5 * Copyright 2009 Henri Verbeet for CodeWeavers
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 *
21 */
22
23#include "d3d10_private.h"
24
26
27#define WINE_D3D10_TO_STR(x) case x: return #x
28
30{
31 switch (driver_type)
32 {
38 default:
39 FIXME("Unrecognised D3D10_DRIVER_TYPE %#x.\n", driver_type);
40 return "unrecognised";
41 }
42}
43
44#undef WINE_D3D10_TO_STR
45
48{
50 HRESULT hr;
51
52 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %#x, device %p.\n",
54
56 {
57 WARN("Invalid SDK version %#x.\n", sdk_version);
58 return E_INVALIDARG;
59 }
60
61 if (adapter)
62 {
63 IDXGIAdapter_AddRef(adapter);
64 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
65 if (FAILED(hr))
66 {
67 WARN("Failed to get dxgi factory, returning %#lx.\n", hr);
68 return hr;
69 }
70 }
71 else
72 {
73 hr = CreateDXGIFactory(&IID_IDXGIFactory, (void **)&factory);
74 if (FAILED(hr))
75 {
76 WARN("Failed to create dxgi factory, returning %#lx.\n", hr);
77 return hr;
78 }
79
80 switch (driver_type)
81 {
83 FIXME("WARP driver not implemented, falling back to hardware.\n");
85 {
86 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
87 if (FAILED(hr))
88 {
89 WARN("No adapters found, returning %#lx.\n", hr);
90 IDXGIFactory_Release(factory);
91 return hr;
92 }
93 break;
94 }
95
97 FIXME("NULL device not implemented, falling back to refrast.\n");
98 /* fall through, for now */
100 {
101 HMODULE refrast = LoadLibraryA("d3d10ref.dll");
102 if (!refrast)
103 {
104 WARN("Failed to load refrast, returning E_FAIL.\n");
105 IDXGIFactory_Release(factory);
106 return E_FAIL;
107 }
108 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
109 FreeLibrary(refrast);
110 if (FAILED(hr))
111 {
112 WARN("Failed to create a software adapter, returning %#lx.\n", hr);
113 IDXGIFactory_Release(factory);
114 return hr;
115 }
116 break;
117 }
118
120 {
121 if (!swrast)
122 {
123 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
124 IDXGIFactory_Release(factory);
125 return E_FAIL;
126 }
127 hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
128 if (FAILED(hr))
129 {
130 WARN("Failed to create a software adapter, returning %#lx.\n", hr);
131 IDXGIFactory_Release(factory);
132 return hr;
133 }
134 break;
135 }
136
137 default:
138 FIXME("Unhandled driver type %#x.\n", driver_type);
139 IDXGIFactory_Release(factory);
140 return E_FAIL;
141 }
142 }
143
145 IDXGIAdapter_Release(adapter);
146 IDXGIFactory_Release(factory);
147 if (FAILED(hr))
148 {
149 WARN("Failed to create a device, returning %#lx.\n", hr);
150 return hr;
151 }
152
153 TRACE("Created ID3D10Device %p.\n", *device);
154
155 return hr;
156}
157
160{
162}
163
166 IDXGISwapChain **swapchain, ID3D10Device **device)
167{
168 IDXGIDevice *dxgi_device;
170 HRESULT hr;
171
172 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, "
173 "swapchain_desc %p, swapchain %p, device %p\n",
175 swapchain_desc, swapchain, device);
176
177 /* Avoid forwarding to D3D10CreateDevice(), since it breaks applications
178 * hooking these entry-points. */
180 {
181 WARN("Failed to create a device, returning %#lx.\n", hr);
182 *device = NULL;
183 return hr;
184 }
185
186 TRACE("Created ID3D10Device %p\n", *device);
187
188 hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device);
189 if (FAILED(hr))
190 {
191 ERR("Failed to get a dxgi device from the d3d10 device, returning %#lx.\n", hr);
192 ID3D10Device_Release(*device);
193 *device = NULL;
194 return hr;
195 }
196
197 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
198 IDXGIDevice_Release(dxgi_device);
199 if (FAILED(hr))
200 {
201 ERR("Failed to get the device adapter, returning %#lx.\n", hr);
202 ID3D10Device_Release(*device);
203 *device = NULL;
204 return hr;
205 }
206
207 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
208 IDXGIAdapter_Release(adapter);
209 if (FAILED(hr))
210 {
211 ERR("Failed to get the adapter factory, returning %#lx.\n", hr);
212 ID3D10Device_Release(*device);
213 *device = NULL;
214 return hr;
215 }
216
217 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain);
218 IDXGIFactory_Release(factory);
219 if (FAILED(hr))
220 {
221 ID3D10Device_Release(*device);
222 *device = NULL;
223
224 WARN("Failed to create a swapchain, returning %#lx.\n", hr);
225 return hr;
226 }
227
228 TRACE("Created IDXGISwapChain %p\n", *swapchain);
229
230 return S_OK;
231}
232
234 const D3D10_SHADER_MACRO *defines, ID3D10Include *include, UINT hlsl_flags, UINT fx_flags,
235 ID3D10Blob **effect, ID3D10Blob **errors)
236{
237 TRACE("data %p, data_size %Iu, filename %s, defines %p, include %p, "
238 "hlsl_flags %#x, fx_flags %#x, effect %p, errors %p.\n",
240 hlsl_flags, fx_flags, effect, errors);
241
242 return D3DCompileFromMemory(data, data_size, filename, defines, include,
243 NULL, "fx_4_0", hlsl_flags, fx_flags, effect, errors);
244}
245
247{
248 FIXME("device %p stub!\n", device);
249
250 return "vs_4_0";
251}
252
254{
255 FIXME("device %p stub!\n", device);
256
257 return "gs_4_0";
258}
259
261{
262 FIXME("device %p stub!\n", device);
263
264 return "ps_4_0";
265}
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
const unsigned int D3D10_SDK_VERSION
Definition: d3d10.idl:248
const char *WINAPI D3D10GetPixelShaderProfile(ID3D10Device *device)
Definition: d3d10_main.c:260
HRESULT WINAPI D3D10CompileEffectFromMemory(void *data, SIZE_T data_size, const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, UINT hlsl_flags, UINT fx_flags, ID3D10Blob **effect, ID3D10Blob **errors)
Definition: d3d10_main.c:233
#define WINE_D3D10_TO_STR(x)
Definition: d3d10_main.c:27
const char *WINAPI D3D10GetVertexShaderProfile(ID3D10Device *device)
Definition: d3d10_main.c:246
HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D10Device **device)
Definition: d3d10_main.c:164
static const char * debug_d3d10_driver_type(D3D10_DRIVER_TYPE driver_type)
Definition: d3d10_main.c:29
static HRESULT d3d10_create_device(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
Definition: d3d10_main.c:46
const char *WINAPI D3D10GetGeometryShaderProfile(ID3D10Device *device)
Definition: d3d10_main.c:253
HRESULT WINAPI D3D10CreateDevice(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, UINT sdk_version, ID3D10Device **device)
Definition: d3d10_main.c:158
HRESULT WINAPI D3DCompileFromMemory(const void *data, SIZE_T data_size, const char *filename, const D3D_SHADER_MACRO *defines, ID3DInclude *include, const char *entrypoint, const char *target, UINT sflags, UINT eflags, ID3DBlob **shader, ID3DBlob **error_messages)
HRESULT WINAPI D3D10CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter, unsigned int flags, D3D_FEATURE_LEVEL feature_level, ID3D10Device **device)
D3D10_DRIVER_TYPE
Definition: d3d10misc.h:28
@ D3D10_DRIVER_TYPE_SOFTWARE
Definition: d3d10misc.h:32
@ D3D10_DRIVER_TYPE_REFERENCE
Definition: d3d10misc.h:30
@ D3D10_DRIVER_TYPE_NULL
Definition: d3d10misc.h:31
@ D3D10_DRIVER_TYPE_HARDWARE
Definition: d3d10misc.h:29
@ D3D10_DRIVER_TYPE_WARP
Definition: d3d10misc.h:33
@ D3D_FEATURE_LEVEL_10_0
Definition: d3dcommon.idl:107
static SIZE_T const char const D3D_SHADER_MACRO ID3DInclude * include
Definition: asm.c:31
static SIZE_T const char const D3D_SHADER_MACRO * defines
Definition: asm.c:31
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_FAIL
Definition: ddrawi.h:102
HRESULT hr
Definition: delayimp.cpp:582
#define NULL
Definition: types.h:112
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
HRESULT WINAPI CreateDXGIFactory(REFIID iid, void **factory)
Definition: dxgi_main.c:73
return adapter
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
unsigned int UINT
Definition: sysinfo.c:13
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT sdk_version
Definition: hlsl_d3d11.c:29
static D3D_DRIVER_TYPE driver_type
Definition: hlsl_d3d11.c:27
static D3D_DRIVER_TYPE HMODULE swrast
Definition: hlsl_d3d11.c:28
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
const char * filename
Definition: ioapi.h:137
int int static __inline const char * wine_dbgstr_a(const char *s)
Definition: debug.h:160
#define TRACE(s)
Definition: solgame.cpp:4
Definition: devices.h:37
Definition: main.c:439
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define WINAPI
Definition: msvc.h:6