ReactOS 0.4.17-dev-934-g091855f
d3d11_main.c File Reference
#include "d3d11_private.h"
Include dependency graph for d3d11_main.c:

Go to the source code of this file.

Macros

#define D3D11_INIT_GUID
 
#define D3D11_TO_STR(x)   case x: return #x
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (d3d11)
 
static const char * debug_d3d_driver_type (D3D_DRIVER_TYPE driver_type)
 
static HRESULT WINAPI layer_init (enum dxgi_device_layer_id id, DWORD *count, DWORD *values)
 
static UINT WINAPI layer_get_size (enum dxgi_device_layer_id id, struct layer_get_size_args *args, DWORD unknown0)
 
static HRESULT WINAPI layer_create (enum dxgi_device_layer_id id, void **layer_base, DWORD unknown0, void *device_object, REFIID riid, void **device_layer)
 
HRESULT WINAPI D3D11CoreRegisterLayers (void)
 
HRESULT WINAPI D3D11CoreCreateDevice (IDXGIFactory *factory, IDXGIAdapter *adapter, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, ID3D11Device **device)
 
static HRESULT d3d11_create_device (IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context)
 
HRESULT WINAPI D3D11CreateDevice (IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context)
 
HRESULT WINAPI D3D11CreateDeviceAndSwapChain (IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, const DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context)
 
HRESULT WINAPI D3D11On12CreateDevice (IUnknown *device, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT feature_level_count, IUnknown *const *queues, UINT queue_count, UINT node_mask, ID3D11Device **d3d11_device, ID3D11DeviceContext **d3d11_immediate_context, D3D_FEATURE_LEVEL *obtained_feature_level)
 

Macro Definition Documentation

◆ D3D11_INIT_GUID

#define D3D11_INIT_GUID

Definition at line 23 of file d3d11_main.c.

◆ D3D11_TO_STR

#define D3D11_TO_STR (   x)    case x: return #x

Function Documentation

◆ d3d11_create_device()

static HRESULT d3d11_create_device ( IDXGIAdapter *  adapter,
D3D_DRIVER_TYPE  driver_type,
HMODULE  swrast,
UINT  flags,
const D3D_FEATURE_LEVEL *  feature_levels,
UINT  levels,
UINT  sdk_version,
ID3D11Device **  device_out,
D3D_FEATURE_LEVEL *  obtained_feature_level,
ID3D11DeviceContext **  immediate_context 
)
static

Definition at line 144 of file d3d11_main.c.

147{
148 static const D3D_FEATURE_LEVEL default_feature_levels[] =
149 {
156 };
158 ID3D11Device *device;
159 HRESULT hr;
160
161 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, feature_levels %p, levels %u, sdk_version %u, "
162 "device %p, obtained_feature_level %p, immediate_context %p.\n",
165
166 if (device_out)
167 *device_out = NULL;
172
173 if (adapter)
174 {
175 IDXGIAdapter_AddRef(adapter);
176 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
177 if (FAILED(hr))
178 {
179 WARN("Failed to get dxgi factory, returning %#lx.\n", hr);
180 return hr;
181 }
182 }
183 else
184 {
185 hr = CreateDXGIFactory1(&IID_IDXGIFactory, (void **)&factory);
186 if (FAILED(hr))
187 {
188 WARN("Failed to create dxgi factory, returning %#lx.\n", hr);
189 return hr;
190 }
191
192 switch(driver_type)
193 {
195 FIXME("WARP driver not implemented, falling back to hardware.\n");
197 {
198 hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
199 if (FAILED(hr))
200 {
201 WARN("No adapters found, returning %#lx.\n", hr);
202 IDXGIFactory_Release(factory);
203 return hr;
204 }
205 break;
206 }
207
209 FIXME("NULL device not implemented, falling back to refrast.\n");
210 /* fall through, for now */
212 {
213 HMODULE refrast = LoadLibraryA("d3d11ref.dll");
214 if (!refrast)
215 {
216 WARN("Failed to load refrast, returning E_FAIL.\n");
217 IDXGIFactory_Release(factory);
218 return E_FAIL;
219 }
220 hr = IDXGIFactory_CreateSoftwareAdapter(factory, refrast, &adapter);
221 FreeLibrary(refrast);
222 if (FAILED(hr))
223 {
224 WARN("Failed to create a software adapter, returning %#lx.\n", hr);
225 IDXGIFactory_Release(factory);
226 return hr;
227 }
228 break;
229 }
230
232 {
233 if (!swrast)
234 {
235 WARN("Software device requested, but NULL swrast passed, returning E_FAIL.\n");
236 IDXGIFactory_Release(factory);
237 return E_FAIL;
238 }
239 hr = IDXGIFactory_CreateSoftwareAdapter(factory, swrast, &adapter);
240 if (FAILED(hr))
241 {
242 WARN("Failed to create a software adapter, returning %#lx.\n", hr);
243 IDXGIFactory_Release(factory);
244 return hr;
245 }
246 break;
247 }
248
249 default:
250 FIXME("Unhandled driver type %#x.\n", driver_type);
251 IDXGIFactory_Release(factory);
252 return E_FAIL;
253 }
254 }
255
256 if (!feature_levels)
257 {
258 feature_levels = default_feature_levels;
259 levels = ARRAY_SIZE(default_feature_levels);
260 }
262 IDXGIAdapter_Release(adapter);
263 IDXGIFactory_Release(factory);
264 if (FAILED(hr))
265 {
266 WARN("Failed to create a device, returning %#lx.\n", hr);
267 return hr;
268 }
269
270 TRACE("Created ID3D11Device %p.\n", device);
271
273 *obtained_feature_level = ID3D11Device_GetFeatureLevel(device);
274
276 ID3D11Device_GetImmediateContext(device, immediate_context);
277
278 if (device_out)
280 else
281 ID3D11Device_Release(device);
282
284}
#define ARRAY_SIZE(A)
Definition: main.h:20
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
HRESULT WINAPI D3D11CoreCreateDevice(IDXGIFactory *factory, IDXGIAdapter *adapter, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, ID3D11Device **device)
Definition: d3d11_main.c:107
static const char * debug_d3d_driver_type(D3D_DRIVER_TYPE driver_type)
Definition: d3d11_main.c:28
D3D_FEATURE_LEVEL
Definition: d3dcommon.idl:102
@ D3D_FEATURE_LEVEL_10_0
Definition: d3dcommon.idl:107
@ D3D_FEATURE_LEVEL_9_1
Definition: d3dcommon.idl:104
@ D3D_FEATURE_LEVEL_9_2
Definition: d3dcommon.idl:105
@ D3D_FEATURE_LEVEL_9_3
Definition: d3dcommon.idl:106
@ D3D_FEATURE_LEVEL_10_1
Definition: d3dcommon.idl:108
@ D3D_FEATURE_LEVEL_11_0
Definition: d3dcommon.idl:109
@ D3D_DRIVER_TYPE_HARDWARE
Definition: d3dcommon.idl:94
@ D3D_DRIVER_TYPE_NULL
Definition: d3dcommon.idl:96
@ D3D_DRIVER_TYPE_SOFTWARE
Definition: d3dcommon.idl:97
@ D3D_DRIVER_TYPE_REFERENCE
Definition: d3dcommon.idl:95
@ D3D_DRIVER_TYPE_WARP
Definition: d3dcommon.idl:98
#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 CreateDXGIFactory1(REFIID iid, void **factory)
Definition: dxgi_main.c:66
return adapter
GLbitfield flags
Definition: glext.h:7161
GLsizei levels
Definition: glext.h:7884
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT sdk_version
Definition: hlsl_d3d11.c:29
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT ID3D11Device ** device_out
Definition: hlsl_d3d11.c:29
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT ID3D11Device D3D_FEATURE_LEVEL * obtained_feature_level
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
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL * feature_levels
Definition: hlsl_d3d11.c:28
static D3D_DRIVER_TYPE HMODULE UINT const D3D_FEATURE_LEVEL UINT UINT ID3D11Device D3D_FEATURE_LEVEL ID3D11DeviceContext ** immediate_context
Definition: hlsl_d3d11.c:30
#define S_OK
Definition: intsafe.h:52
#define FAILED(hr)
Definition: intsafe.h:51
#define TRACE(s)
Definition: solgame.cpp:4
Definition: devices.h:37
Definition: main.c:439
#define S_FALSE
Definition: winerror.h:3451

Referenced by D3D11CreateDevice(), and D3D11CreateDeviceAndSwapChain().

◆ D3D11CoreCreateDevice()

HRESULT WINAPI D3D11CoreCreateDevice ( IDXGIFactory *  factory,
IDXGIAdapter *  adapter,
UINT  flags,
const D3D_FEATURE_LEVEL *  feature_levels,
UINT  levels,
ID3D11Device **  device 
)

Definition at line 107 of file d3d11_main.c.

109{
110 struct d3d_device *d3d_device;
112 HMODULE d3d11;
113 HRESULT hr;
114
115 TRACE("factory %p, adapter %p, flags %#x, feature_levels %p, levels %u, device %p.\n",
117
118 d3d11 = GetModuleHandleA("d3d11.dll");
120 if (FAILED(hr))
121 {
122 WARN("Failed to create device, returning %#lx.\n", hr);
123 return hr;
124 }
125
126 hr = IUnknown_QueryInterface(dxgi_device, &IID_ID3D11Device, (void **)device);
127 IUnknown_Release(dxgi_device);
128 if (FAILED(hr))
129 {
130 ERR("Failed to query ID3D11Device interface, returning E_FAIL.\n");
131 return E_FAIL;
132 }
133
135 {
136 ERR("Failed to retrieve device impl, returning E_FAIL.\n");
137 return E_FAIL;
138 }
140
141 return S_OK;
142}
#define ERR(fmt,...)
Definition: precomp.h:57
HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d11, IDXGIFactory *factory, IDXGIAdapter *adapter, unsigned int flags, const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count, void **device)
Definition: dxgi_main.c:135
static struct d3d_device * impl_from_ID3D11Device(ID3D11Device *iface)
#define TRUE
Definition: types.h:120
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812

Referenced by d3d11_create_device().

◆ D3D11CoreRegisterLayers()

HRESULT WINAPI D3D11CoreRegisterLayers ( void  )

Definition at line 95 of file d3d11_main.c.

96{
97 static const struct dxgi_device_layer layers[] =
98 {
100 };
101
102 DXGID3D10RegisterLayers(layers, ARRAY_SIZE(layers));
103
104 return S_OK;
105}
static UINT WINAPI layer_get_size(enum dxgi_device_layer_id id, struct layer_get_size_args *args, DWORD unknown0)
Definition: d3d11_main.c:58
static HRESULT WINAPI layer_create(enum dxgi_device_layer_id id, void **layer_base, DWORD unknown0, void *device_object, REFIID riid, void **device_layer)
Definition: d3d11_main.c:71
static HRESULT WINAPI layer_init(enum dxgi_device_layer_id id, DWORD *count, DWORD *values)
Definition: d3d11_main.c:45
HRESULT WINAPI DXGID3D10RegisterLayers(const struct dxgi_device_layer *layers, UINT layer_count)
Definition: dxgi_main.c:209
@ DXGI_DEVICE_LAYER_D3D10_DEVICE

◆ D3D11CreateDevice()

HRESULT WINAPI D3D11CreateDevice ( IDXGIAdapter *  adapter,
D3D_DRIVER_TYPE  driver_type,
HMODULE  swrast,
UINT  flags,
const D3D_FEATURE_LEVEL *  feature_levels,
UINT  levels,
UINT  sdk_version,
ID3D11Device **  device_out,
D3D_FEATURE_LEVEL *  obtained_feature_level,
ID3D11DeviceContext **  immediate_context 
)

Definition at line 286 of file d3d11_main.c.

289{
292}
static HRESULT d3d11_create_device(IDXGIAdapter *adapter, D3D_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, const D3D_FEATURE_LEVEL *feature_levels, UINT levels, UINT sdk_version, ID3D11Device **device_out, D3D_FEATURE_LEVEL *obtained_feature_level, ID3D11DeviceContext **immediate_context)
Definition: d3d11_main.c:144

◆ D3D11CreateDeviceAndSwapChain()

HRESULT WINAPI D3D11CreateDeviceAndSwapChain ( IDXGIAdapter *  adapter,
D3D_DRIVER_TYPE  driver_type,
HMODULE  swrast,
UINT  flags,
const D3D_FEATURE_LEVEL *  feature_levels,
UINT  levels,
UINT  sdk_version,
const DXGI_SWAP_CHAIN_DESC *  swapchain_desc,
IDXGISwapChain **  swapchain,
ID3D11Device **  device_out,
D3D_FEATURE_LEVEL *  obtained_feature_level,
ID3D11DeviceContext **  immediate_context 
)

Definition at line 294 of file d3d11_main.c.

298{
300 IDXGIDevice *dxgi_device;
302 ID3D11Device *device;
303 HRESULT hr;
304
305 TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, feature_levels %p, levels %u, sdk_version %u, "
306 "swapchain_desc %p, swapchain %p, device %p, obtained_feature_level %p, immediate_context %p.\n",
308 swapchain_desc, swapchain, device_out, obtained_feature_level, immediate_context);
309
310 if (swapchain)
311 *swapchain = NULL;
312 if (device_out)
313 *device_out = NULL;
314
315 /* Avoid forwarding to D3D11CreateDevice(), since it breaks applications
316 * hooking these entry-points. */
319 {
320 WARN("Failed to create a device, returning %#lx.\n", hr);
321 return hr;
322 }
323
324 if (swapchain)
325 {
326 if (FAILED(hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device)))
327 {
328 ERR("Failed to get a dxgi device from the d3d11 device, returning %#lx.\n", hr);
329 goto cleanup;
330 }
331
332 hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
333 IDXGIDevice_Release(dxgi_device);
334 if (FAILED(hr))
335 {
336 ERR("Failed to get the device adapter, returning %#lx.\n", hr);
337 goto cleanup;
338 }
339
340 hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory);
341 IDXGIAdapter_Release(adapter);
342 if (FAILED(hr))
343 {
344 ERR("Failed to get the adapter factory, returning %#lx.\n", hr);
345 goto cleanup;
346 }
347
348 desc = *swapchain_desc;
349 hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, swapchain);
350 IDXGIFactory_Release(factory);
351 if (FAILED(hr))
352 {
353 WARN("Failed to create a swapchain, returning %#lx.\n", hr);
354 goto cleanup;
355 }
356
357 TRACE("Created IDXGISwapChain %p.\n", *swapchain);
358 }
359
360 if (device_out)
362 else
363 ID3D11Device_Release(device);
364
365 return (swapchain || device_out || immediate_context) ? S_OK : S_FALSE;
366
367cleanup:
368 ID3D11Device_Release(device);
372 {
373 ID3D11DeviceContext_Release(*immediate_context);
375 }
376
377 return hr;
378}
static void cleanup(void)
Definition: main.c:1335
D3D11_SHADER_VARIABLE_DESC desc
Definition: reflection.c:1683

◆ D3D11On12CreateDevice()

HRESULT WINAPI D3D11On12CreateDevice ( IUnknown *  device,
UINT  flags,
const D3D_FEATURE_LEVEL *  feature_levels,
UINT  feature_level_count,
IUnknown *const *  queues,
UINT  queue_count,
UINT  node_mask,
ID3D11Device **  d3d11_device,
ID3D11DeviceContext **  d3d11_immediate_context,
D3D_FEATURE_LEVEL *  obtained_feature_level 
)

Definition at line 380 of file d3d11_main.c.

385{
386 FIXME("device %p, flags %#x, feature_levels %p, feature_level_count %u, "
387 "queues %p, queue_count %u, node_mask 0x%08x, "
388 "d3d11_device %p, d3d11_immediate_context %p, obtained_feature_level %p stub!\n",
389 device, flags, feature_levels, feature_level_count, queues, queue_count,
390 node_mask, d3d11_device, d3d11_immediate_context, obtained_feature_level);
391
392 return E_NOTIMPL;
393}
#define E_NOTIMPL
Definition: ddrawi.h:99

◆ debug_d3d_driver_type()

static const char * debug_d3d_driver_type ( D3D_DRIVER_TYPE  driver_type)
static

Definition at line 28 of file d3d11_main.c.

29{
30 switch (driver_type)
31 {
32#define D3D11_TO_STR(x) case x: return #x
39#undef D3D11_TO_STR
40 default:
41 return wine_dbg_sprintf("Unrecognized D3D_DRIVER_TYPE %#x\n", driver_type);
42 }
43}
#define D3D11_TO_STR(x)
@ D3D_DRIVER_TYPE_UNKNOWN
Definition: d3dcommon.idl:93
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:296

Referenced by d3d11_create_device(), and D3D11CreateDeviceAndSwapChain().

◆ layer_create()

static HRESULT WINAPI layer_create ( enum dxgi_device_layer_id  id,
void **  layer_base,
DWORD  unknown0,
void *  device_object,
REFIID  riid,
void **  device_layer 
)
static

Definition at line 71 of file d3d11_main.c.

73{
74 struct d3d_device *object;
75
76 TRACE("id %#x, layer_base %p, unknown0 %#lx, device_object %p, riid %s, device_layer %p.\n",
77 id, layer_base, unknown0, device_object, debugstr_guid(riid), device_layer);
78
80 {
81 WARN("Unknown layer id %#x\n", id);
82 *device_layer = NULL;
83 return E_NOTIMPL;
84 }
85
86 object = *layer_base;
87 d3d_device_init(object, device_object);
88 *device_layer = &object->IUnknown_inner;
89
90 TRACE("Created d3d10 device at %p\n", object);
91
92 return S_OK;
93}
void d3d_device_init(struct d3d_device *device, void *outer_unknown)
Definition: device.c:7756
REFIID riid
Definition: atlbase.h:39
#define debugstr_guid
Definition: kernel32.h:35

Referenced by D3D11CoreRegisterLayers().

◆ layer_get_size()

static UINT WINAPI layer_get_size ( enum dxgi_device_layer_id  id,
struct layer_get_size_args *  args,
DWORD  unknown0 
)
static

Definition at line 58 of file d3d11_main.c.

59{
60 TRACE("id %#x, args %p, unknown0 %#lx.\n", id, args, unknown0);
61
63 {
64 WARN("Unknown layer id %#x\n", id);
65 return 0;
66 }
67
68 return sizeof(struct d3d_device);
69}
Definition: match.c:390

Referenced by D3D11CoreRegisterLayers().

◆ layer_init()

static HRESULT WINAPI layer_init ( enum dxgi_device_layer_id  id,
DWORD *  count,
DWORD *  values 
)
static

Definition at line 45 of file d3d11_main.c.

46{
47 TRACE("id %#x, count %p, values %p\n", id, count, values);
48
50 {
51 WARN("Unknown layer id %#x\n", id);
52 return E_NOTIMPL;
53 }
54
55 return S_OK;
56}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLboolean GLenum GLenum GLvoid * values
Definition: glext.h:5666

Referenced by D3D11CoreRegisterLayers().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( d3d11  )