4 * Copyright 2007 Andras Kovacs
5 * Copyright 2009 Henri Verbeet for CodeWeavers
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.
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.
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
24 #include "wine/port.h"
26 #include "d3d10_private.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d10
);
30 static HRESULT
d3d10_create_device(IDXGIAdapter
*adapter
, D3D10_DRIVER_TYPE driver_type
,
31 HMODULE swrast
, UINT flags
, UINT sdk_version
, ID3D10Device
**device
)
33 IDXGIFactory
*factory
;
36 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %#x, device %p.\n",
37 adapter
, debug_d3d10_driver_type(driver_type
), swrast
, flags
, sdk_version
, device
);
39 if (sdk_version
!= D3D10_SDK_VERSION
)
41 WARN("Invalid SDK version %#x.\n", sdk_version
);
47 IDXGIAdapter_AddRef(adapter
);
48 hr
= IDXGIAdapter_GetParent(adapter
, &IID_IDXGIFactory
, (void **)&factory
);
51 WARN("Failed to get dxgi factory, returning %#x.\n", hr
);
57 hr
= CreateDXGIFactory(&IID_IDXGIFactory
, (void **)&factory
);
60 WARN("Failed to create dxgi factory, returning %#x.\n", hr
);
66 case D3D10_DRIVER_TYPE_WARP
:
67 FIXME("WARP driver not implemented, falling back to hardware.\n");
68 case D3D10_DRIVER_TYPE_HARDWARE
:
70 hr
= IDXGIFactory_EnumAdapters(factory
, 0, &adapter
);
73 WARN("No adapters found, returning %#x.\n", hr
);
74 IDXGIFactory_Release(factory
);
80 case D3D10_DRIVER_TYPE_NULL
:
81 FIXME("NULL device not implemented, falling back to refrast.\n");
82 /* fall through, for now */
83 case D3D10_DRIVER_TYPE_REFERENCE
:
85 HMODULE refrast
= LoadLibraryA("d3d10ref.dll");
88 WARN("Failed to load refrast, returning E_FAIL.\n");
89 IDXGIFactory_Release(factory
);
92 hr
= IDXGIFactory_CreateSoftwareAdapter(factory
, refrast
, &adapter
);
96 WARN("Failed to create a software adapter, returning %#x.\n", hr
);
97 IDXGIFactory_Release(factory
);
103 case D3D10_DRIVER_TYPE_SOFTWARE
:
107 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
108 IDXGIFactory_Release(factory
);
111 hr
= IDXGIFactory_CreateSoftwareAdapter(factory
, swrast
, &adapter
);
114 WARN("Failed to create a software adapter, returning %#x.\n", hr
);
115 IDXGIFactory_Release(factory
);
122 FIXME("Unhandled driver type %#x.\n", driver_type
);
123 IDXGIFactory_Release(factory
);
128 hr
= D3D10CoreCreateDevice(factory
, adapter
, flags
, D3D_FEATURE_LEVEL_10_0
, device
);
129 IDXGIAdapter_Release(adapter
);
130 IDXGIFactory_Release(factory
);
133 WARN("Failed to create a device, returning %#x.\n", hr
);
137 TRACE("Created ID3D10Device %p.\n", *device
);
142 HRESULT WINAPI
D3D10CreateDevice(IDXGIAdapter
*adapter
, D3D10_DRIVER_TYPE driver_type
,
143 HMODULE swrast
, UINT flags
, UINT sdk_version
, ID3D10Device
**device
)
145 return d3d10_create_device(adapter
, driver_type
, swrast
, flags
, sdk_version
, device
);
148 HRESULT WINAPI
D3D10CreateDeviceAndSwapChain(IDXGIAdapter
*adapter
, D3D10_DRIVER_TYPE driver_type
,
149 HMODULE swrast
, UINT flags
, UINT sdk_version
, DXGI_SWAP_CHAIN_DESC
*swapchain_desc
,
150 IDXGISwapChain
**swapchain
, ID3D10Device
**device
)
152 IDXGIDevice
*dxgi_device
;
153 IDXGIFactory
*factory
;
156 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d, "
157 "swapchain_desc %p, swapchain %p, device %p\n",
158 adapter
, debug_d3d10_driver_type(driver_type
), swrast
, flags
, sdk_version
,
159 swapchain_desc
, swapchain
, device
);
161 /* Avoid forwarding to D3D10CreateDevice(), since it breaks applications
162 * hooking these entry-points. */
163 if (FAILED(hr
= d3d10_create_device(adapter
, driver_type
, swrast
, flags
, sdk_version
, device
)))
165 WARN("Failed to create a device, returning %#x\n", hr
);
170 TRACE("Created ID3D10Device %p\n", *device
);
172 hr
= ID3D10Device_QueryInterface(*device
, &IID_IDXGIDevice
, (void **)&dxgi_device
);
175 ERR("Failed to get a dxgi device from the d3d10 device, returning %#x\n", hr
);
176 ID3D10Device_Release(*device
);
181 hr
= IDXGIDevice_GetAdapter(dxgi_device
, &adapter
);
182 IDXGIDevice_Release(dxgi_device
);
185 ERR("Failed to get the device adapter, returning %#x\n", hr
);
186 ID3D10Device_Release(*device
);
191 hr
= IDXGIAdapter_GetParent(adapter
, &IID_IDXGIFactory
, (void **)&factory
);
192 IDXGIAdapter_Release(adapter
);
195 ERR("Failed to get the adapter factory, returning %#x\n", hr
);
196 ID3D10Device_Release(*device
);
201 hr
= IDXGIFactory_CreateSwapChain(factory
, (IUnknown
*)*device
, swapchain_desc
, swapchain
);
202 IDXGIFactory_Release(factory
);
205 ID3D10Device_Release(*device
);
208 WARN("Failed to create a swapchain, returning %#x\n", hr
);
212 TRACE("Created IDXGISwapChain %p\n", *swapchain
);
217 static int d3d10_effect_type_compare(const void *key
, const struct wine_rb_entry
*entry
)
219 const struct d3d10_effect_type
*t
= WINE_RB_ENTRY_VALUE(entry
, const struct d3d10_effect_type
, entry
);
220 const DWORD
*id
= key
;
225 HRESULT WINAPI
D3D10CreateEffectFromMemory(void *data
, SIZE_T data_size
, UINT flags
,
226 ID3D10Device
*device
, ID3D10EffectPool
*effect_pool
, ID3D10Effect
**effect
)
228 struct d3d10_effect
*object
;
231 FIXME("data %p, data_size %lu, flags %#x, device %p, effect_pool %p, effect %p stub!\n",
232 data
, data_size
, flags
, device
, effect_pool
, effect
);
234 if (!(object
= heap_alloc_zero(sizeof(*object
))))
236 ERR("Failed to allocate D3D10 effect object memory\n");
237 return E_OUTOFMEMORY
;
240 wine_rb_init(&object
->types
, d3d10_effect_type_compare
);
241 object
->ID3D10Effect_iface
.lpVtbl
= &d3d10_effect_vtbl
;
242 object
->refcount
= 1;
243 ID3D10Device_AddRef(device
);
244 object
->device
= device
;
246 hr
= d3d10_effect_parse(object
, data
, data_size
);
249 ERR("Failed to parse effect\n");
250 IUnknown_Release(&object
->ID3D10Effect_iface
);
254 *effect
= &object
->ID3D10Effect_iface
;
256 TRACE("Created ID3D10Effect %p\n", object
);
261 HRESULT WINAPI
D3D10CompileEffectFromMemory(void *data
, SIZE_T data_size
, const char *filename
,
262 const D3D10_SHADER_MACRO
*defines
, ID3D10Include
*include
, UINT hlsl_flags
, UINT fx_flags
,
263 ID3D10Blob
**effect
, ID3D10Blob
**errors
)
265 TRACE("data %p, data_size %lu, filename %s, defines %p, include %p, "
266 "hlsl_flags %#x, fx_flags %#x, effect %p, errors %p.\n",
267 data
, data_size
, wine_dbgstr_a(filename
), defines
, include
,
268 hlsl_flags
, fx_flags
, effect
, errors
);
270 return D3DCompile(data
, data_size
, filename
, defines
, include
,
271 NULL
, "fx_4_0", hlsl_flags
, fx_flags
, effect
, errors
);
274 HRESULT WINAPI
D3D10CreateEffectPoolFromMemory(void *data
, SIZE_T data_size
, UINT fx_flags
,
275 ID3D10Device
*device
, ID3D10EffectPool
**effect_pool
)
277 FIXME("data %p, data_size %lu, fx_flags %#x, device %p, effect_pool %p stub.\n",
278 data
, data_size
, fx_flags
, device
, effect_pool
);
283 const char * WINAPI
D3D10GetVertexShaderProfile(ID3D10Device
*device
)
285 FIXME("device %p stub!\n", device
);
290 const char * WINAPI
D3D10GetGeometryShaderProfile(ID3D10Device
*device
)
292 FIXME("device %p stub!\n", device
);
297 const char * WINAPI
D3D10GetPixelShaderProfile(ID3D10Device
*device
)
299 FIXME("device %p stub!\n", device
);
304 HRESULT WINAPI
D3D10ReflectShader(const void *data
, SIZE_T data_size
, ID3D10ShaderReflection
**reflector
)
306 struct d3d10_shader_reflection
*object
;
308 FIXME("data %p, data_size %lu, reflector %p stub!\n", data
, data_size
, reflector
);
310 if (!(object
= heap_alloc_zero(sizeof(*object
))))
312 ERR("Failed to allocate D3D10 shader reflection object memory\n");
313 return E_OUTOFMEMORY
;
316 object
->ID3D10ShaderReflection_iface
.lpVtbl
= &d3d10_shader_reflection_vtbl
;
317 object
->refcount
= 1;
319 *reflector
= &object
->ID3D10ShaderReflection_iface
;
321 TRACE("Created ID3D10ShaderReflection %p\n", object
);