wined3d: Pass map flags to wined3d_context_copy_bo_address().
[wine.git] / dlls / wined3d / directx.c
blobeb0e5e9bad02a492c2a1538be3dd9a3088b499c5
1 /*
2 * Copyright 2002-2004 Jason Edmeades
3 * Copyright 2003-2004 Raphael Junqueira
4 * Copyright 2004 Christian Costa
5 * Copyright 2005 Oliver Stieber
6 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
7 * Copyright 2009-2011 Henri Verbeet for CodeWeavers
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wined3d_private.h"
25 #include "winternl.h"
26 #include "wine/list.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
29 WINE_DECLARE_DEBUG_CHANNEL(winediag);
31 #define DEFAULT_REFRESH_RATE 0
33 enum wined3d_driver_model
35 DRIVER_MODEL_GENERIC,
36 DRIVER_MODEL_WIN9X,
37 DRIVER_MODEL_NT40,
38 DRIVER_MODEL_NT5X,
39 DRIVER_MODEL_NT6X
42 struct wined3d_adapter_budget_change_notification
44 const struct wined3d_adapter *adapter;
45 HANDLE event;
46 DWORD cookie;
47 UINT64 last_local_budget;
48 UINT64 last_non_local_budget;
49 struct list entry;
52 static struct list adapter_budget_change_notifications = LIST_INIT( adapter_budget_change_notifications );
53 static HANDLE notification_thread, notification_thread_stop_event;
55 /* The d3d device ID */
56 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
58 /**********************************************************
59 * Utility functions follow
60 **********************************************************/
62 const struct min_lookup minMipLookup[] =
64 /* NONE POINT LINEAR */
65 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
66 {{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
67 {{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
70 const GLenum magLookup[] =
72 /* NONE POINT LINEAR */
73 GL_NEAREST, GL_NEAREST, GL_LINEAR,
76 void CDECL wined3d_output_release_ownership(const struct wined3d_output *output)
78 D3DKMT_SETVIDPNSOURCEOWNER set_owner_desc = {0};
80 TRACE("output %p.\n", output);
82 set_owner_desc.hDevice = output->kmt_device;
83 D3DKMTSetVidPnSourceOwner(&set_owner_desc);
86 HRESULT CDECL wined3d_output_take_ownership(const struct wined3d_output *output, BOOL exclusive)
88 D3DKMT_SETVIDPNSOURCEOWNER set_owner_desc;
89 D3DKMT_VIDPNSOURCEOWNER_TYPE owner_type;
90 NTSTATUS status;
92 TRACE("output %p, exclusive %#x.\n", output, exclusive);
94 owner_type = exclusive ? D3DKMT_VIDPNSOURCEOWNER_EXCLUSIVE : D3DKMT_VIDPNSOURCEOWNER_SHARED;
95 set_owner_desc.pType = &owner_type;
96 set_owner_desc.pVidPnSourceId = &output->vidpn_source_id;
97 set_owner_desc.VidPnSourceCount = 1;
98 set_owner_desc.hDevice = output->kmt_device;
99 status = D3DKMTSetVidPnSourceOwner(&set_owner_desc);
101 switch (status)
103 case STATUS_GRAPHICS_VIDPN_SOURCE_IN_USE:
104 return DXGI_ERROR_NOT_CURRENTLY_AVAILABLE;
105 case STATUS_INVALID_PARAMETER:
106 return E_INVALIDARG;
107 case STATUS_PROCEDURE_NOT_FOUND:
108 return E_NOINTERFACE;
109 case STATUS_SUCCESS:
110 return S_OK;
111 default:
112 FIXME("Unhandled error %#lx.\n", status);
113 return E_FAIL;
117 static void wined3d_output_cleanup(const struct wined3d_output *output)
119 D3DKMT_DESTROYDEVICE destroy_device_desc;
121 TRACE("output %p.\n", output);
123 destroy_device_desc.hDevice = output->kmt_device;
124 D3DKMTDestroyDevice(&destroy_device_desc);
127 static HRESULT wined3d_output_init(struct wined3d_output *output, unsigned int ordinal,
128 struct wined3d_adapter *adapter, const WCHAR *device_name)
130 D3DKMT_OPENADAPTERFROMGDIDISPLAYNAME open_adapter_desc;
131 D3DKMT_CREATEDEVICE create_device_desc = {{0}};
132 D3DKMT_CLOSEADAPTER close_adapter_desc;
134 TRACE("output %p, device_name %s.\n", output, wine_dbgstr_w(device_name));
136 lstrcpyW(open_adapter_desc.DeviceName, device_name);
137 if (D3DKMTOpenAdapterFromGdiDisplayName(&open_adapter_desc))
138 return E_INVALIDARG;
139 close_adapter_desc.hAdapter = open_adapter_desc.hAdapter;
140 D3DKMTCloseAdapter(&close_adapter_desc);
142 create_device_desc.hAdapter = adapter->kmt_adapter;
143 if (D3DKMTCreateDevice(&create_device_desc))
144 return E_FAIL;
146 output->ordinal = ordinal;
147 lstrcpyW(output->device_name, device_name);
148 output->adapter = adapter;
149 output->screen_format = WINED3DFMT_UNKNOWN;
150 output->kmt_device = create_device_desc.hDevice;
151 output->vidpn_source_id = open_adapter_desc.VidPnSourceId;
153 return WINED3D_OK;
156 /* Adjust the amount of used texture memory */
157 UINT64 adapter_adjust_memory(struct wined3d_adapter *adapter, INT64 amount)
159 adapter->vram_bytes_used += amount;
160 TRACE("Adjusted used adapter memory by 0x%s to 0x%s.\n",
161 wine_dbgstr_longlong(amount),
162 wine_dbgstr_longlong(adapter->vram_bytes_used));
163 return adapter->vram_bytes_used;
166 ssize_t adapter_adjust_mapped_memory(struct wined3d_adapter *adapter, ssize_t size)
168 /* Note that this needs to be thread-safe; the Vulkan adapter may map from
169 * client threads. */
170 ssize_t ret = InterlockedExchangeAddSizeT(&adapter->mapped_size, size) + size;
171 TRACE("Adjusted mapped adapter memory by %Id to %Id.\n", size, ret);
172 return ret;
175 void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
177 D3DKMT_CLOSEADAPTER close_adapter_desc;
178 unsigned int output_idx;
180 for (output_idx = 0; output_idx < adapter->output_count; ++output_idx)
181 wined3d_output_cleanup(&adapter->outputs[output_idx]);
182 heap_free(adapter->outputs);
183 heap_free(adapter->formats);
184 close_adapter_desc.hAdapter = adapter->kmt_adapter;
185 D3DKMTCloseAdapter(&close_adapter_desc);
188 ULONG CDECL wined3d_incref(struct wined3d *wined3d)
190 unsigned int refcount = InterlockedIncrement(&wined3d->ref);
192 TRACE("%p increasing refcount to %u.\n", wined3d, refcount);
194 return refcount;
197 ULONG CDECL wined3d_decref(struct wined3d *wined3d)
199 unsigned int refcount = InterlockedDecrement(&wined3d->ref);
201 TRACE("%p decreasing refcount to %u.\n", wined3d, refcount);
203 if (!refcount)
205 unsigned int i;
207 wined3d_mutex_lock();
208 for (i = 0; i < wined3d->adapter_count; ++i)
210 struct wined3d_adapter *adapter = wined3d->adapters[i];
212 adapter->adapter_ops->adapter_destroy(adapter);
214 heap_free(wined3d);
215 wined3d_mutex_unlock();
218 return refcount;
221 /* Certain applications (e.g. Steam) complain if we report an outdated driver
222 * version.
224 * The driver version has the form "x.y.z.w".
226 * "x" is the Windows version / driver model the driver is meant for:
227 * 4 -> 95/98/NT4
228 * 5 -> 2000
229 * 6 -> XP
230 * 7 -> Vista - WDDM 1.0
231 * 8 -> Windows 7 - WDDM 1.1
232 * 9 -> Windows 8 - WDDM 1.2
233 * 10 -> Windows 8.1 - WDDM 1.3
234 * 20 -> Windows 10 - WDDM 2.0
235 * 21 -> Windows 10 Anniversary Update - WDDM 2.1
236 * 22 -> Windows 10 Creators Update - WDDM 2.2
237 * 23 -> Windows 10 Fall Creators Update - WDDM 2.3
238 * 24 -> Windows 10 April 2018 Update - WDDM 2.4
239 * 25 -> Windows 10 October 2018 Update - WDDM 2.5
240 * 26 -> Windows 10 May 2019 Update - WDDM 2.6
242 * "y" is the maximum Direct3D version / feature level the driver supports.
243 * 11 -> 6
244 * 12 -> 7
245 * 13 -> 8
246 * 14 -> 9
247 * 15 -> 10_0
248 * 16 -> 10_1
249 * 17 -> 11_0
250 * 18 -> 11_1
251 * 19 -> 12_0
252 * 20 -> 12_1
253 * 21 -> 12_x
255 * "z" is the subversion number.
257 * "w" is the vendor specific driver build number.
259 * In practice the reported version is tied to the driver, not the actual
260 * Windows version or feature level. E.g. NVIDIA driver 445.87 advertises the
261 * exact same version 26.21.14.4587 on Windows 7 as it does on Windows 10
262 * (it's in fact the same driver). Similarly for driver 310.90 that advertises
263 * itself as 9.18.13.1090 on Windows Vista with a GeForce 9600M. */
265 struct driver_version_information
267 enum wined3d_display_driver driver;
268 enum wined3d_driver_model driver_model;
269 const char *driver_name; /* name of Windows driver */
270 WORD subversion; /* subversion word ('z'), contained in high word of DriverVersion.LowPart */
271 WORD build; /* build number ('w'), contained in low word of DriverVersion.LowPart */
274 /* The driver version table contains driver information for different devices on several OS versions. */
275 static const struct driver_version_information driver_version_table[] =
277 /* AMD
278 * - Radeon HD2x00 (R600) and up supported by current drivers.
279 * - Radeon 9500 (R300) - X1*00 (R5xx) supported up to Catalyst 9.3 (Linux) and 10.2 (XP/Vista/Win7)
280 * - Radeon 7xxx (R100) - 9250 (RV250) supported up to Catalyst 6.11 (XP)
281 * - Rage 128 supported up to XP, latest official build 6.13.3279 dated October 2001 */
282 {DRIVER_AMD_RAGE_128PRO, DRIVER_MODEL_NT5X, "ati2dvaa.dll", 3279, 0},
283 {DRIVER_AMD_R100, DRIVER_MODEL_NT5X, "ati2dvag.dll", 10, 6614},
284 {DRIVER_AMD_R300, DRIVER_MODEL_NT5X, "ati2dvag.dll", 10, 6764},
285 {DRIVER_AMD_R600, DRIVER_MODEL_NT5X, "ati2dvag.dll", 10, 1280},
286 {DRIVER_AMD_R300, DRIVER_MODEL_NT6X, "atiumdag.dll", 10, 741 },
287 {DRIVER_AMD_R600, DRIVER_MODEL_NT6X, "atiumdag.dll", 10, 1280},
288 {DRIVER_AMD_RX, DRIVER_MODEL_NT6X, "aticfx32.dll", 15002, 61},
290 /* Intel
291 * The drivers are unified but not all versions support all GPUs. At some point the 2k/xp
292 * drivers used ialmrnt5.dll for GMA800/GMA900 but at some point the file was renamed to
293 * igxprd32.dll but the GMA800 driver was never updated. */
294 {DRIVER_INTEL_GMA800, DRIVER_MODEL_NT5X, "ialmrnt5.dll", 10, 3889},
295 {DRIVER_INTEL_GMA900, DRIVER_MODEL_NT5X, "igxprd32.dll", 10, 4764},
296 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT5X, "igxprd32.dll", 10, 4926},
297 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT5X, "igxprd32.dll", 10, 5218},
298 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT6X, "igdumd32.dll", 10, 1504},
299 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT6X, "igdumd32.dll", 10, 1666},
300 {DRIVER_INTEL_HD4000, DRIVER_MODEL_NT6X, "igdumdim32.dll", 15, 4352},
302 /* Nvidia
303 * - Geforce8 and newer is supported by the current 340.52 driver on XP-Win8
304 * - Geforce6 and 7 support is up to 307.83 on XP-Win8
305 * - GeforceFX support is up to 173.x on <= XP
306 * - Geforce2MX/3/4 up to 96.x on <= XP
307 * - TNT/Geforce1/2 up to 71.x on <= XP
308 * All version numbers used below are from the Linux nvidia drivers. */
309 {DRIVER_NVIDIA_TNT, DRIVER_MODEL_NT5X, "nv4_disp.dll", 10, 7186},
310 {DRIVER_NVIDIA_GEFORCE2MX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 10, 9371},
311 {DRIVER_NVIDIA_GEFORCEFX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 11, 7516},
312 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT5X, "nv4_disp.dll", 13, 783},
313 {DRIVER_NVIDIA_GEFORCE8, DRIVER_MODEL_NT5X, "nv4_disp.dll", 13, 4052},
314 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT6X, "nvd3dum.dll", 13, 783},
315 {DRIVER_NVIDIA_GEFORCE8, DRIVER_MODEL_NT6X, "nvd3dum.dll", 13, 4052},
316 {DRIVER_NVIDIA_FERMI, DRIVER_MODEL_NT6X, "nvd3dum.dll", 13, 9135},
317 {DRIVER_NVIDIA_KEPLER, DRIVER_MODEL_NT6X, "nvd3dum.dll", 14, 4587},
319 /* Red Hat */
320 {DRIVER_REDHAT_VIRGL, DRIVER_MODEL_GENERIC, "virgl.dll", 0, 0},
322 /* VMware */
323 {DRIVER_VMWARE, DRIVER_MODEL_NT5X, "vm3dum.dll", 1, 1134},
325 /* Wine */
326 {DRIVER_WINE, DRIVER_MODEL_GENERIC, "wined3d.dll", 0, 0},
329 /* The amount of video memory stored in the gpu description table is the minimum amount of video memory
330 * found on a board containing a specific GPU. */
331 static const struct wined3d_gpu_description gpu_description_table[] =
333 /* Nvidia cards */
334 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_128, "NVIDIA RIVA 128", DRIVER_NVIDIA_TNT, 4 },
335 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", DRIVER_NVIDIA_TNT, 16 },
336 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", DRIVER_NVIDIA_TNT, 32 },
337 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", DRIVER_NVIDIA_TNT, 32 },
338 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", DRIVER_NVIDIA_TNT, 32 },
339 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", DRIVER_NVIDIA_GEFORCE2MX,32 },
340 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", DRIVER_NVIDIA_GEFORCE2MX,64 },
341 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", DRIVER_NVIDIA_GEFORCE2MX,64 },
342 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", DRIVER_NVIDIA_GEFORCE2MX,64, },
343 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", DRIVER_NVIDIA_GEFORCEFX, 64 },
344 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", DRIVER_NVIDIA_GEFORCEFX, 128 },
345 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", DRIVER_NVIDIA_GEFORCEFX, 256 },
346 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", DRIVER_NVIDIA_GEFORCE6, 64 },
347 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", DRIVER_NVIDIA_GEFORCE6, 128 },
348 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", DRIVER_NVIDIA_GEFORCE6, 128 },
349 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", DRIVER_NVIDIA_GEFORCE6, 256 },
350 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", DRIVER_NVIDIA_GEFORCE6, 256 },
351 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
352 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
353 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8200, "NVIDIA GeForce 8200", DRIVER_NVIDIA_GEFORCE8, 512 },
354 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", DRIVER_NVIDIA_GEFORCE8, 128 },
355 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8400GS, "NVIDIA GeForce 8400 GS", DRIVER_NVIDIA_GEFORCE8, 128 },
356 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8500GT, "NVIDIA GeForce 8500 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
357 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
358 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", DRIVER_NVIDIA_GEFORCE8, 512 },
359 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", DRIVER_NVIDIA_GEFORCE8, 320 },
360 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTX, "NVIDIA GeForce 8800 GTX", DRIVER_NVIDIA_GEFORCE8, 768 },
361 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", DRIVER_NVIDIA_GEFORCE8, 256 },
362 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9300, "NVIDIA GeForce 9300", DRIVER_NVIDIA_GEFORCE8, 256 },
363 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400M, "NVIDIA GeForce 9400M", DRIVER_NVIDIA_GEFORCE8, 256 },
364 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
365 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", DRIVER_NVIDIA_GEFORCE8, 256 },
366 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", DRIVER_NVIDIA_GEFORCE8, 512 },
367 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9700MGT, "NVIDIA GeForce 9700M GT", DRIVER_NVIDIA_GEFORCE8, 512 },
368 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", DRIVER_NVIDIA_GEFORCE8, 512 },
369 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_210, "NVIDIA GeForce 210", DRIVER_NVIDIA_GEFORCE8, 512 },
370 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT220, "NVIDIA GeForce GT 220", DRIVER_NVIDIA_GEFORCE8, 512 },
371 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT240, "NVIDIA GeForce GT 240", DRIVER_NVIDIA_GEFORCE8, 512 },
372 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS250, "NVIDIA GeForce GTS 250", DRIVER_NVIDIA_GEFORCE8, 1024},
373 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", DRIVER_NVIDIA_GEFORCE8, 1024},
374 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", DRIVER_NVIDIA_GEFORCE8, 896 },
375 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", DRIVER_NVIDIA_GEFORCE8, 1024},
376 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_315M, "NVIDIA GeForce 315M", DRIVER_NVIDIA_GEFORCE8, 512 },
377 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_320M, "NVIDIA GeForce 320M", DRIVER_NVIDIA_GEFORCE8, 256},
378 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT320M, "NVIDIA GeForce GT 320M", DRIVER_NVIDIA_GEFORCE8, 1024},
379 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT325M, "NVIDIA GeForce GT 325M", DRIVER_NVIDIA_GEFORCE8, 1024},
380 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT330, "NVIDIA GeForce GT 330", DRIVER_NVIDIA_GEFORCE8, 1024},
381 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS350M, "NVIDIA GeForce GTS 350M", DRIVER_NVIDIA_GEFORCE8, 1024},
382 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_410M, "NVIDIA GeForce 410M", DRIVER_NVIDIA_FERMI, 512},
383 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT420, "NVIDIA GeForce GT 420", DRIVER_NVIDIA_FERMI, 2048},
384 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT425M, "NVIDIA GeForce GT 425M", DRIVER_NVIDIA_FERMI, 1024},
385 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT430, "NVIDIA GeForce GT 430", DRIVER_NVIDIA_FERMI, 1024},
386 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT440, "NVIDIA GeForce GT 440", DRIVER_NVIDIA_FERMI, 1024},
387 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS450, "NVIDIA GeForce GTS 450", DRIVER_NVIDIA_FERMI, 1024},
388 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460, "NVIDIA GeForce GTX 460", DRIVER_NVIDIA_FERMI, 768 },
389 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460M, "NVIDIA GeForce GTX 460M", DRIVER_NVIDIA_FERMI, 1536},
390 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX465, "NVIDIA GeForce GTX 465", DRIVER_NVIDIA_FERMI, 1024},
391 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX470, "NVIDIA GeForce GTX 470", DRIVER_NVIDIA_FERMI, 1280},
392 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX480, "NVIDIA GeForce GTX 480", DRIVER_NVIDIA_FERMI, 1536},
393 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT520, "NVIDIA GeForce GT 520", DRIVER_NVIDIA_FERMI, 1024},
394 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT525M, "NVIDIA GeForce GT 525M", DRIVER_NVIDIA_FERMI, 1024},
395 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT540M, "NVIDIA GeForce GT 540M", DRIVER_NVIDIA_FERMI, 1024},
396 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX550, "NVIDIA GeForce GTX 550 Ti", DRIVER_NVIDIA_FERMI, 1024},
397 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT555M, "NVIDIA GeForce GT 555M", DRIVER_NVIDIA_FERMI, 1024},
398 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560TI, "NVIDIA GeForce GTX 560 Ti", DRIVER_NVIDIA_FERMI, 1024},
399 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560M, "NVIDIA GeForce GTX 560M", DRIVER_NVIDIA_FERMI, 3072},
400 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560, "NVIDIA GeForce GTX 560", DRIVER_NVIDIA_FERMI, 1024},
401 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX570, "NVIDIA GeForce GTX 570", DRIVER_NVIDIA_FERMI, 1280},
402 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX580, "NVIDIA GeForce GTX 580", DRIVER_NVIDIA_FERMI, 1536},
403 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT610, "NVIDIA GeForce GT 610", DRIVER_NVIDIA_FERMI, 1024},
404 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630, "NVIDIA GeForce GT 630", DRIVER_NVIDIA_KEPLER, 1024},
405 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630M, "NVIDIA GeForce GT 630M", DRIVER_NVIDIA_FERMI, 1024},
406 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT640, "NVIDIA GeForce GT 640", DRIVER_NVIDIA_KEPLER, 1024},
407 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT640M, "NVIDIA GeForce GT 640M", DRIVER_NVIDIA_KEPLER, 1024},
408 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT650M, "NVIDIA GeForce GT 650M", DRIVER_NVIDIA_KEPLER, 2048},
409 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650, "NVIDIA GeForce GTX 650", DRIVER_NVIDIA_KEPLER, 1024},
410 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650TI, "NVIDIA GeForce GTX 650 Ti", DRIVER_NVIDIA_KEPLER, 1024},
411 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660, "NVIDIA GeForce GTX 660", DRIVER_NVIDIA_KEPLER, 2048},
412 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660M, "NVIDIA GeForce GTX 660M", DRIVER_NVIDIA_KEPLER, 2048},
413 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660TI, "NVIDIA GeForce GTX 660 Ti", DRIVER_NVIDIA_KEPLER, 2048},
414 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670, "NVIDIA GeForce GTX 670", DRIVER_NVIDIA_KEPLER, 2048},
415 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670MX, "NVIDIA GeForce GTX 670MX", DRIVER_NVIDIA_KEPLER, 3072},
416 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX675MX_1, "NVIDIA GeForce GTX 675MX", DRIVER_NVIDIA_KEPLER, 4096},
417 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX675MX_2, "NVIDIA GeForce GTX 675MX", DRIVER_NVIDIA_KEPLER, 2048},
418 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX680, "NVIDIA GeForce GTX 680", DRIVER_NVIDIA_KEPLER, 2048},
419 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX690, "NVIDIA GeForce GTX 690", DRIVER_NVIDIA_KEPLER, 2048},
420 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT720, "NVIDIA GeForce GT 720", DRIVER_NVIDIA_KEPLER, 2048},
421 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT730, "NVIDIA GeForce GT 730", DRIVER_NVIDIA_KEPLER, 2048},
422 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT730M, "NVIDIA GeForce GT 730M", DRIVER_NVIDIA_KEPLER, 1024},
423 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT740M, "NVIDIA GeForce GT 740M", DRIVER_NVIDIA_KEPLER, 2048},
424 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT750M, "NVIDIA GeForce GT 750M", DRIVER_NVIDIA_KEPLER, 1024},
425 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT755M, "NVIDIA GeForce GT 755M", DRIVER_NVIDIA_KEPLER, 1024},
426 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX750, "NVIDIA GeForce GTX 750", DRIVER_NVIDIA_KEPLER, 1024},
427 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX750TI, "NVIDIA GeForce GTX 750 Ti", DRIVER_NVIDIA_KEPLER, 2048},
428 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX760, "NVIDIA GeForce GTX 760", DRIVER_NVIDIA_KEPLER, 2048},
429 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX760TI, "NVIDIA GeForce GTX 760 Ti", DRIVER_NVIDIA_KEPLER, 2048},
430 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX765M, "NVIDIA GeForce GTX 765M", DRIVER_NVIDIA_KEPLER, 2048},
431 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770M, "NVIDIA GeForce GTX 770M", DRIVER_NVIDIA_KEPLER, 3072},
432 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770, "NVIDIA GeForce GTX 770", DRIVER_NVIDIA_KEPLER, 2048},
433 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX775M, "NVIDIA GeForce GTX 775M", DRIVER_NVIDIA_KEPLER, 3072},
434 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX780, "NVIDIA GeForce GTX 780", DRIVER_NVIDIA_KEPLER, 3072},
435 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX780M, "NVIDIA GeForce GTX 780M", DRIVER_NVIDIA_KEPLER, 4096},
436 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX780TI, "NVIDIA GeForce GTX 780 Ti", DRIVER_NVIDIA_KEPLER, 3072},
437 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTXTITAN, "NVIDIA GeForce GTX TITAN", DRIVER_NVIDIA_KEPLER, 6144},
438 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTXTITANB, "NVIDIA GeForce GTX TITAN Black", DRIVER_NVIDIA_KEPLER, 6144},
439 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTXTITANX, "NVIDIA GeForce GTX TITAN X", DRIVER_NVIDIA_KEPLER, 12288},
440 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTXTITANZ, "NVIDIA GeForce GTX TITAN Z", DRIVER_NVIDIA_KEPLER, 12288},
441 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_820M, "NVIDIA GeForce 820M", DRIVER_NVIDIA_FERMI, 2048},
442 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_830M, "NVIDIA GeForce 830M", DRIVER_NVIDIA_KEPLER, 2048},
443 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_840M, "NVIDIA GeForce 840M", DRIVER_NVIDIA_KEPLER, 2048},
444 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_845M, "NVIDIA GeForce 845M", DRIVER_NVIDIA_KEPLER, 2048},
445 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX850M, "NVIDIA GeForce GTX 850M", DRIVER_NVIDIA_KEPLER, 2048},
446 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX860M, "NVIDIA GeForce GTX 860M", DRIVER_NVIDIA_KEPLER, 2048},
447 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX870M, "NVIDIA GeForce GTX 870M", DRIVER_NVIDIA_KEPLER, 3072},
448 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX880M, "NVIDIA GeForce GTX 880M", DRIVER_NVIDIA_KEPLER, 4096},
449 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_940M, "NVIDIA GeForce 940M", DRIVER_NVIDIA_KEPLER, 4096},
450 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX950, "NVIDIA GeForce GTX 950", DRIVER_NVIDIA_KEPLER, 2048},
451 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX950M, "NVIDIA GeForce GTX 950M", DRIVER_NVIDIA_KEPLER, 4096},
452 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX960, "NVIDIA GeForce GTX 960", DRIVER_NVIDIA_KEPLER, 4096},
453 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX960M, "NVIDIA GeForce GTX 960M", DRIVER_NVIDIA_KEPLER, 2048},
454 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX970, "NVIDIA GeForce GTX 970", DRIVER_NVIDIA_KEPLER, 4096},
455 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX970M, "NVIDIA GeForce GTX 970M", DRIVER_NVIDIA_KEPLER, 3072},
456 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX980, "NVIDIA GeForce GTX 980", DRIVER_NVIDIA_KEPLER, 4096},
457 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX980TI, "NVIDIA GeForce GTX 980 Ti", DRIVER_NVIDIA_KEPLER, 6144},
458 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT1030, "NVIDIA GeForce GT 1030", DRIVER_NVIDIA_KEPLER, 2048},
459 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1050, "NVIDIA GeForce GTX 1050", DRIVER_NVIDIA_KEPLER, 2048},
460 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1050TI, "NVIDIA GeForce GTX 1050 Ti", DRIVER_NVIDIA_KEPLER, 4096},
461 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1060_3GB,"NVIDIA GeForce GTX 1060 3GB", DRIVER_NVIDIA_KEPLER, 3072},
462 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1060, "NVIDIA GeForce GTX 1060", DRIVER_NVIDIA_KEPLER, 6144},
463 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1060M, "NVIDIA GeForce GTX 1060M", DRIVER_NVIDIA_KEPLER, 6144},
464 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1070, "NVIDIA GeForce GTX 1070", DRIVER_NVIDIA_KEPLER, 8192},
465 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1080, "NVIDIA GeForce GTX 1080", DRIVER_NVIDIA_KEPLER, 8192},
466 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1080M, "NVIDIA GeForce GTX 1080M", DRIVER_NVIDIA_KEPLER, 8192},
467 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1080TI, "NVIDIA GeForce GTX 1080 Ti", DRIVER_NVIDIA_KEPLER, 11264},
468 {HW_VENDOR_NVIDIA, CARD_NVIDIA_TITANX_PASCAL, "NVIDIA TITAN X (Pascal)", DRIVER_NVIDIA_KEPLER, 12288},
469 {HW_VENDOR_NVIDIA, CARD_NVIDIA_TITANV, "NVIDIA TITAN V", DRIVER_NVIDIA_KEPLER, 12288},
470 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1650SUPER,"NVIDIA GeForce GTX 1650 SUPER", DRIVER_NVIDIA_KEPLER, 4096},
471 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1660SUPER,"NVIDIA GeForce GTX 1660 SUPER", DRIVER_NVIDIA_KEPLER, 6144},
472 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX1660TI, "NVIDIA GeForce GTX 1660 Ti", DRIVER_NVIDIA_KEPLER, 6144},
473 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_RTX2060, "NVIDIA GeForce RTX 2060", DRIVER_NVIDIA_KEPLER, 6144},
474 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_RTX2070, "NVIDIA GeForce RTX 2070", DRIVER_NVIDIA_KEPLER, 8192},
475 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_RTX2080, "NVIDIA GeForce RTX 2080", DRIVER_NVIDIA_KEPLER, 8192},
476 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_RTX2080TI, "NVIDIA GeForce RTX 2080 Ti", DRIVER_NVIDIA_KEPLER, 11264},
477 {HW_VENDOR_NVIDIA, CARD_NVIDIA_TESLA_T4, "NVIDIA Tesla T4", DRIVER_NVIDIA_KEPLER, 16384},
478 {HW_VENDOR_NVIDIA, CARD_NVIDIA_AMPERE_A10, "NVIDIA Ampere A10", DRIVER_NVIDIA_KEPLER, 24576},
480 /* AMD cards */
481 {HW_VENDOR_AMD, CARD_AMD_RAGE_128PRO, "ATI Rage Fury", DRIVER_AMD_RAGE_128PRO, 16 },
482 {HW_VENDOR_AMD, CARD_AMD_RADEON_7200, "ATI RADEON 7200 SERIES", DRIVER_AMD_R100, 32 },
483 {HW_VENDOR_AMD, CARD_AMD_RADEON_8500, "ATI RADEON 8500 SERIES", DRIVER_AMD_R100, 64 },
484 {HW_VENDOR_AMD, CARD_AMD_RADEON_9500, "ATI Radeon 9500", DRIVER_AMD_R300, 64 },
485 {HW_VENDOR_AMD, CARD_AMD_RADEON_XPRESS_200M, "ATI RADEON XPRESS 200M Series", DRIVER_AMD_R300, 64 },
486 {HW_VENDOR_AMD, CARD_AMD_RADEON_X700, "ATI Radeon X700 SE", DRIVER_AMD_R300, 128 },
487 {HW_VENDOR_AMD, CARD_AMD_RADEON_X1600, "ATI Radeon X1600 Series", DRIVER_AMD_R300, 128 },
488 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2350, "ATI Mobility Radeon HD 2350", DRIVER_AMD_R600, 256 },
489 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2600, "ATI Mobility Radeon HD 2600", DRIVER_AMD_R600, 256 },
490 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2900, "ATI Radeon HD 2900 XT", DRIVER_AMD_R600, 512 },
491 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD3200, "ATI Radeon HD 3200 Graphics", DRIVER_AMD_R600, 128 },
492 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD3850, "ATI Radeon HD 3850 AGP", DRIVER_AMD_R600, 512 },
493 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4200M, "ATI Mobility Radeon HD 4200", DRIVER_AMD_R600, 256 },
494 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4350, "ATI Radeon HD 4350", DRIVER_AMD_R600, 256 },
495 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4600, "ATI Radeon HD 4600 Series", DRIVER_AMD_R600, 512 },
496 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4700, "ATI Radeon HD 4700 Series", DRIVER_AMD_R600, 512 },
497 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4800, "ATI Radeon HD 4800 Series", DRIVER_AMD_R600, 512 },
498 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5400, "ATI Radeon HD 5400 Series", DRIVER_AMD_R600, 512 },
499 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5600, "ATI Radeon HD 5600 Series", DRIVER_AMD_R600, 512 },
500 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5700, "ATI Radeon HD 5700 Series", DRIVER_AMD_R600, 512 },
501 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5800, "ATI Radeon HD 5800 Series", DRIVER_AMD_R600, 1024},
502 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5900, "ATI Radeon HD 5900 Series", DRIVER_AMD_R600, 1024},
503 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6300, "AMD Radeon HD 6300 series Graphics", DRIVER_AMD_R600, 1024},
504 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6400, "AMD Radeon HD 6400 Series", DRIVER_AMD_R600, 1024},
505 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6410D, "AMD Radeon HD 6410D", DRIVER_AMD_R600, 1024},
506 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6480G, "AMD Radeon HD 6480G", DRIVER_AMD_R600, 512 },
507 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6490M, "AMD Radeon HD 6490M", DRIVER_AMD_R600, 1024},
508 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6550D, "AMD Radeon HD 6550D", DRIVER_AMD_R600, 1024},
509 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600, "AMD Radeon HD 6600 Series", DRIVER_AMD_R600, 1024},
510 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600M, "AMD Radeon HD 6600M Series", DRIVER_AMD_R600, 512 },
511 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6700, "AMD Radeon HD 6700 Series", DRIVER_AMD_R600, 1024},
512 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6800, "AMD Radeon HD 6800 Series", DRIVER_AMD_R600, 1024},
513 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6900, "AMD Radeon HD 6900 Series", DRIVER_AMD_R600, 2048},
514 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7660D, "AMD Radeon HD 7660D", DRIVER_AMD_R600, 2048},
515 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7700, "AMD Radeon HD 7700 Series", DRIVER_AMD_R600, 1024},
516 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7800, "AMD Radeon HD 7800 Series", DRIVER_AMD_R600, 2048},
517 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7870, "AMD Radeon HD 7870 Series", DRIVER_AMD_R600, 2048},
518 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7900, "AMD Radeon HD 7900 Series", DRIVER_AMD_R600, 2048},
519 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD8600M, "AMD Radeon HD 8600M Series", DRIVER_AMD_R600, 1024},
520 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD8670, "AMD Radeon HD 8670", DRIVER_AMD_R600, 2048},
521 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD8770, "AMD Radeon HD 8770", DRIVER_AMD_R600, 2048},
522 {HW_VENDOR_AMD, CARD_AMD_RADEON_R3, "AMD Radeon HD 8400 / R3 Series", DRIVER_AMD_R600, 2048},
523 {HW_VENDOR_AMD, CARD_AMD_RADEON_R7, "AMD Radeon(TM) R7 Graphics", DRIVER_AMD_R600, 2048},
524 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9_285, "AMD Radeon R9 285", DRIVER_AMD_RX, 2048},
525 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9_290, "AMD Radeon R9 290", DRIVER_AMD_RX, 4096},
526 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9_290X, "AMD Radeon R9 290X", DRIVER_AMD_RX, 4096},
527 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9_FURY, "AMD Radeon (TM) R9 Fury Series", DRIVER_AMD_RX, 4096},
528 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9_M370X, "AMD Radeon R9 M370X", DRIVER_AMD_RX, 2048},
529 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9_M380, "AMD Radeon R9 M380", DRIVER_AMD_RX, 2048},
530 {HW_VENDOR_AMD, CARD_AMD_RADEON_R9_M395X, "AMD Radeon R9 M395X", DRIVER_AMD_RX, 4096},
531 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_460, "Radeon(TM) RX 460 Graphics", DRIVER_AMD_RX, 4096},
532 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_480, "Radeon (TM) RX 480 Graphics", DRIVER_AMD_RX, 4096},
533 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_VEGA_10, "Radeon RX Vega", DRIVER_AMD_RX, 8192},
534 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_VEGA_12, "Radeon Pro Vega 20", DRIVER_AMD_RX, 4096},
535 {HW_VENDOR_AMD, CARD_AMD_RADEON_RAVEN, "AMD Radeon(TM) Vega 10 Mobile Graphics", DRIVER_AMD_RX, 1024},
536 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_VEGA_20, "Radeon RX Vega 20", DRIVER_AMD_RX, 4096},
537 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_NAVI_10, "Radeon RX 5700 / 5700 XT", DRIVER_AMD_RX, 8192},
538 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_NAVI_14, "Radeon RX 5500M", DRIVER_AMD_RX, 4096},
539 {HW_VENDOR_AMD, CARD_AMD_RADEON_RX_NAVI_21, "Radeon RX 6800/6800 XT / 6900 XT", DRIVER_AMD_RX, 16384},
540 {HW_VENDOR_AMD, CARD_AMD_RADEON_PRO_V620, "Radeon Pro V620", DRIVER_AMD_RX, 32768},
541 {HW_VENDOR_AMD, CARD_AMD_RADEON_PRO_V620_VF, "Radeon Pro V620 VF", DRIVER_AMD_RX, 32768},
542 {HW_VENDOR_AMD, CARD_AMD_VANGOGH, "AMD VANGOGH", DRIVER_AMD_RX, 4096},
543 {HW_VENDOR_AMD, CARD_AMD_RAPHAEL, "AMD Radeon(TM) Graphics", DRIVER_AMD_RX, 4096},
545 /* Red Hat */
546 {HW_VENDOR_REDHAT, CARD_REDHAT_VIRGL, "Red Hat VirtIO GPU", DRIVER_REDHAT_VIRGL, 1024},
548 /* VMware */
549 {HW_VENDOR_VMWARE, CARD_VMWARE_SVGA3D, "VMware SVGA 3D (Microsoft Corporation - WDDM)", DRIVER_VMWARE, 1024},
551 /* Intel cards */
552 {HW_VENDOR_INTEL, CARD_INTEL_830M, "Intel(R) 82830M Graphics Controller", DRIVER_INTEL_GMA800, 32 },
553 {HW_VENDOR_INTEL, CARD_INTEL_855GM, "Intel(R) 82852/82855 GM/GME Graphics Controller", DRIVER_INTEL_GMA800, 32 },
554 {HW_VENDOR_INTEL, CARD_INTEL_845G, "Intel(R) 845G", DRIVER_INTEL_GMA800, 32 },
555 {HW_VENDOR_INTEL, CARD_INTEL_865G, "Intel(R) 82865G Graphics Controller", DRIVER_INTEL_GMA800, 32 },
556 {HW_VENDOR_INTEL, CARD_INTEL_915G, "Intel(R) 82915G/GV/910GL Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
557 {HW_VENDOR_INTEL, CARD_INTEL_E7221G, "Intel(R) E7221G", DRIVER_INTEL_GMA900, 64 },
558 {HW_VENDOR_INTEL, CARD_INTEL_915GM, "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
559 {HW_VENDOR_INTEL, CARD_INTEL_945G, "Intel(R) 945G", DRIVER_INTEL_GMA950, 64 },
560 {HW_VENDOR_INTEL, CARD_INTEL_945GM, "Mobile Intel(R) 945GM Express Chipset Family", DRIVER_INTEL_GMA950, 64 },
561 {HW_VENDOR_INTEL, CARD_INTEL_945GME, "Intel(R) 945GME", DRIVER_INTEL_GMA950, 64 },
562 {HW_VENDOR_INTEL, CARD_INTEL_Q35, "Intel(R) Q35", DRIVER_INTEL_GMA950, 64 },
563 {HW_VENDOR_INTEL, CARD_INTEL_G33, "Intel(R) G33", DRIVER_INTEL_GMA950, 64 },
564 {HW_VENDOR_INTEL, CARD_INTEL_Q33, "Intel(R) Q33", DRIVER_INTEL_GMA950, 64 },
565 {HW_VENDOR_INTEL, CARD_INTEL_PNVG, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
566 {HW_VENDOR_INTEL, CARD_INTEL_PNVM, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
567 {HW_VENDOR_INTEL, CARD_INTEL_965Q, "Intel(R) 965Q", DRIVER_INTEL_GMA3000, 128},
568 {HW_VENDOR_INTEL, CARD_INTEL_965G, "Intel(R) 965G", DRIVER_INTEL_GMA3000, 128},
569 {HW_VENDOR_INTEL, CARD_INTEL_946GZ, "Intel(R) 946GZ", DRIVER_INTEL_GMA3000, 128},
570 {HW_VENDOR_INTEL, CARD_INTEL_965GM, "Mobile Intel(R) 965 Express Chipset Family", DRIVER_INTEL_GMA3000, 128},
571 {HW_VENDOR_INTEL, CARD_INTEL_965GME, "Intel(R) 965GME", DRIVER_INTEL_GMA3000, 128},
572 {HW_VENDOR_INTEL, CARD_INTEL_GM45, "Mobile Intel(R) GM45 Express Chipset Family", DRIVER_INTEL_GMA3000, 512},
573 {HW_VENDOR_INTEL, CARD_INTEL_IGD, "Intel(R) Integrated Graphics Device", DRIVER_INTEL_GMA3000, 512},
574 {HW_VENDOR_INTEL, CARD_INTEL_G45, "Intel(R) G45/G43", DRIVER_INTEL_GMA3000, 512},
575 {HW_VENDOR_INTEL, CARD_INTEL_Q45, "Intel(R) Q45/Q43", DRIVER_INTEL_GMA3000, 512},
576 {HW_VENDOR_INTEL, CARD_INTEL_G41, "Intel(R) G41", DRIVER_INTEL_GMA3000, 512},
577 {HW_VENDOR_INTEL, CARD_INTEL_B43, "Intel(R) B43", DRIVER_INTEL_GMA3000, 512},
578 {HW_VENDOR_INTEL, CARD_INTEL_ILKD, "Intel(R) HD Graphics", DRIVER_INTEL_GMA3000, 1536},
579 {HW_VENDOR_INTEL, CARD_INTEL_ILKM, "Intel(R) HD Graphics", DRIVER_INTEL_GMA3000, 1536},
580 {HW_VENDOR_INTEL, CARD_INTEL_SNBD, "Intel(R) HD Graphics 3000", DRIVER_INTEL_GMA3000, 1536},
581 {HW_VENDOR_INTEL, CARD_INTEL_SNBM, "Intel(R) HD Graphics 3000", DRIVER_INTEL_GMA3000, 1536},
582 {HW_VENDOR_INTEL, CARD_INTEL_SNBS, "Intel(R) HD Graphics Family", DRIVER_INTEL_GMA3000, 1536},
583 {HW_VENDOR_INTEL, CARD_INTEL_IVBD, "Intel(R) HD Graphics 4000", DRIVER_INTEL_HD4000, 1536},
584 {HW_VENDOR_INTEL, CARD_INTEL_IVBM, "Intel(R) HD Graphics 4000", DRIVER_INTEL_HD4000, 1536},
585 {HW_VENDOR_INTEL, CARD_INTEL_IVBS, "Intel(R) HD Graphics Family", DRIVER_INTEL_HD4000, 1536},
586 {HW_VENDOR_INTEL, CARD_INTEL_HWD, "Intel(R) HD Graphics 4600", DRIVER_INTEL_HD4000, 1536},
587 {HW_VENDOR_INTEL, CARD_INTEL_HWM, "Intel(R) HD Graphics 4600", DRIVER_INTEL_HD4000, 1536},
588 {HW_VENDOR_INTEL, CARD_INTEL_HD5000_1, "Intel(R) HD Graphics 5000", DRIVER_INTEL_HD4000, 1536},
589 {HW_VENDOR_INTEL, CARD_INTEL_HD5000_2, "Intel(R) HD Graphics 5000", DRIVER_INTEL_HD4000, 1536},
590 {HW_VENDOR_INTEL, CARD_INTEL_I5100_1, "Intel(R) Iris(TM) Graphics 5100", DRIVER_INTEL_HD4000, 1536},
591 {HW_VENDOR_INTEL, CARD_INTEL_I5100_2, "Intel(R) Iris(TM) Graphics 5100", DRIVER_INTEL_HD4000, 1536},
592 {HW_VENDOR_INTEL, CARD_INTEL_I5100_3, "Intel(R) Iris(TM) Graphics 5100", DRIVER_INTEL_HD4000, 1536},
593 {HW_VENDOR_INTEL, CARD_INTEL_I5100_4, "Intel(R) Iris(TM) Graphics 5100", DRIVER_INTEL_HD4000, 1536},
594 {HW_VENDOR_INTEL, CARD_INTEL_IP5200_1, "Intel(R) Iris(TM) Pro Graphics 5200", DRIVER_INTEL_HD4000, 1536},
595 {HW_VENDOR_INTEL, CARD_INTEL_IP5200_2, "Intel(R) Iris(TM) Pro Graphics 5200", DRIVER_INTEL_HD4000, 1536},
596 {HW_VENDOR_INTEL, CARD_INTEL_IP5200_3, "Intel(R) Iris(TM) Pro Graphics 5200", DRIVER_INTEL_HD4000, 1536},
597 {HW_VENDOR_INTEL, CARD_INTEL_IP5200_4, "Intel(R) Iris(TM) Pro Graphics 5200", DRIVER_INTEL_HD4000, 1536},
598 {HW_VENDOR_INTEL, CARD_INTEL_IP5200_5, "Intel(R) Iris(TM) Pro Graphics 5200", DRIVER_INTEL_HD4000, 1536},
599 {HW_VENDOR_INTEL, CARD_INTEL_IP5200_6, "Intel(R) Iris(TM) Pro Graphics 5200", DRIVER_INTEL_HD4000, 2048},
600 {HW_VENDOR_INTEL, CARD_INTEL_HD5300, "Intel(R) HD Graphics 5300", DRIVER_INTEL_HD4000, 2048},
601 {HW_VENDOR_INTEL, CARD_INTEL_HD5500, "Intel(R) HD Graphics 5500", DRIVER_INTEL_HD4000, 2048},
602 {HW_VENDOR_INTEL, CARD_INTEL_HD5600, "Intel(R) HD Graphics 5600", DRIVER_INTEL_HD4000, 2048},
603 {HW_VENDOR_INTEL, CARD_INTEL_HD6000, "Intel(R) HD Graphics 6000", DRIVER_INTEL_HD4000, 2048},
604 {HW_VENDOR_INTEL, CARD_INTEL_I6100, "Intel(R) Iris(TM) Graphics 6100", DRIVER_INTEL_HD4000, 2048},
605 {HW_VENDOR_INTEL, CARD_INTEL_IP6200, "Intel(R) Iris(TM) Pro Graphics 6200", DRIVER_INTEL_HD4000, 2048},
606 {HW_VENDOR_INTEL, CARD_INTEL_IPP6300, "Intel(R) Iris(TM) Pro Graphics P6300", DRIVER_INTEL_HD4000, 2048},
607 {HW_VENDOR_INTEL, CARD_INTEL_HD510_1, "Intel(R) HD Graphics 510", DRIVER_INTEL_HD4000, 2048},
608 {HW_VENDOR_INTEL, CARD_INTEL_HD510_2, "Intel(R) HD Graphics 510", DRIVER_INTEL_HD4000, 2048},
609 {HW_VENDOR_INTEL, CARD_INTEL_HD510_3, "Intel(R) HD Graphics 510", DRIVER_INTEL_HD4000, 2048},
610 {HW_VENDOR_INTEL, CARD_INTEL_HD515, "Intel(R) HD Graphics 515", DRIVER_INTEL_HD4000, 2048},
611 {HW_VENDOR_INTEL, CARD_INTEL_HD520_1, "Intel(R) HD Graphics 520", DRIVER_INTEL_HD4000, 2048},
612 {HW_VENDOR_INTEL, CARD_INTEL_HD520_2, "Intel(R) HD Graphics 520", DRIVER_INTEL_HD4000, 2048},
613 {HW_VENDOR_INTEL, CARD_INTEL_HD530_1, "Intel(R) HD Graphics 530", DRIVER_INTEL_HD4000, 2048},
614 {HW_VENDOR_INTEL, CARD_INTEL_HD530_2, "Intel(R) HD Graphics 530", DRIVER_INTEL_HD4000, 2048},
615 {HW_VENDOR_INTEL, CARD_INTEL_HDP530, "Intel(R) HD Graphics P530", DRIVER_INTEL_HD4000, 2048},
616 {HW_VENDOR_INTEL, CARD_INTEL_I540, "Intel(R) Iris(TM) Graphics 540", DRIVER_INTEL_HD4000, 2048},
617 {HW_VENDOR_INTEL, CARD_INTEL_I550, "Intel(R) Iris(TM) Graphics 550", DRIVER_INTEL_HD4000, 2048},
618 {HW_VENDOR_INTEL, CARD_INTEL_I555, "Intel(R) Iris(TM) Graphics 555", DRIVER_INTEL_HD4000, 2048},
619 {HW_VENDOR_INTEL, CARD_INTEL_IP555, "Intel(R) Iris(TM) Graphics P555", DRIVER_INTEL_HD4000, 2048},
620 {HW_VENDOR_INTEL, CARD_INTEL_IP580_1, "Intel(R) Iris(TM) Pro Graphics 580", DRIVER_INTEL_HD4000, 2048},
621 {HW_VENDOR_INTEL, CARD_INTEL_IP580_2, "Intel(R) Iris(TM) Pro Graphics 580", DRIVER_INTEL_HD4000, 2048},
622 {HW_VENDOR_INTEL, CARD_INTEL_IPP580_1, "Intel(R) Iris(TM) Pro Graphics P580", DRIVER_INTEL_HD4000, 2048},
623 {HW_VENDOR_INTEL, CARD_INTEL_IPP580_2, "Intel(R) Iris(TM) Pro Graphics P580", DRIVER_INTEL_HD4000, 2048},
624 {HW_VENDOR_INTEL, CARD_INTEL_UHD617, "Intel(R) UHD Graphics 617", DRIVER_INTEL_HD4000, 2048},
625 {HW_VENDOR_INTEL, CARD_INTEL_UHD620, "Intel(R) UHD Graphics 620", DRIVER_INTEL_HD4000, 3072},
626 {HW_VENDOR_INTEL, CARD_INTEL_HD615, "Intel(R) HD Graphics 615", DRIVER_INTEL_HD4000, 2048},
627 {HW_VENDOR_INTEL, CARD_INTEL_HD620, "Intel(R) HD Graphics 620", DRIVER_INTEL_HD4000, 3072},
628 {HW_VENDOR_INTEL, CARD_INTEL_HD630_1, "Intel(R) HD Graphics 630", DRIVER_INTEL_HD4000, 3072},
629 {HW_VENDOR_INTEL, CARD_INTEL_HD630_2, "Intel(R) HD Graphics 630", DRIVER_INTEL_HD4000, 3072},
630 {HW_VENDOR_INTEL, CARD_INTEL_UHD630_1, "Intel(R) UHD Graphics 630", DRIVER_INTEL_HD4000, 3072},
631 {HW_VENDOR_INTEL, CARD_INTEL_UHD630_2, "Intel(R) UHD Graphics 630", DRIVER_INTEL_HD4000, 3072},
634 static const struct driver_version_information *get_driver_version_info(enum wined3d_display_driver driver,
635 enum wined3d_driver_model driver_model)
637 unsigned int i;
639 TRACE("Looking up version info for driver %#x, driver_model %#x.\n", driver, driver_model);
641 for (i = 0; i < ARRAY_SIZE(driver_version_table); ++i)
643 const struct driver_version_information *entry = &driver_version_table[i];
645 if (entry->driver == driver && (driver_model == DRIVER_MODEL_GENERIC
646 || entry->driver_model == driver_model))
648 TRACE("Found driver \"%s\", subversion %u, build %u.\n",
649 entry->driver_name, entry->subversion, entry->build);
650 return entry;
653 return NULL;
656 const struct wined3d_gpu_description *wined3d_get_gpu_description(enum wined3d_pci_vendor vendor,
657 enum wined3d_pci_device device)
659 unsigned int i;
661 for (i = 0; i < ARRAY_SIZE(gpu_description_table); ++i)
663 if (vendor == gpu_description_table[i].vendor && device == gpu_description_table[i].device)
664 return &gpu_description_table[i];
667 return NULL;
670 const struct wined3d_gpu_description *wined3d_get_user_override_gpu_description(enum wined3d_pci_vendor vendor,
671 enum wined3d_pci_device device)
673 const struct wined3d_gpu_description *gpu_desc;
674 static unsigned int once;
676 if (wined3d_settings.pci_vendor_id == PCI_VENDOR_NONE && wined3d_settings.pci_device_id == PCI_DEVICE_NONE)
677 return NULL;
679 if (wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
681 vendor = wined3d_settings.pci_vendor_id;
682 TRACE("Overriding vendor PCI ID with 0x%04x.\n", vendor);
684 if (wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
686 device = wined3d_settings.pci_device_id;
687 TRACE("Overriding device PCI ID with 0x%04x.\n", device);
690 if (!(gpu_desc = wined3d_get_gpu_description(vendor, device)) && !once++)
691 ERR_(winediag)("Invalid GPU override %04x:%04x specified, ignoring.\n", vendor, device);
693 return gpu_desc;
696 static void wined3d_copy_name(char *dst, const char *src, unsigned int dst_size)
698 size_t len;
700 if (dst_size)
702 len = min(strlen(src), dst_size - 1);
703 memcpy(dst, src, len);
704 memset(&dst[len], 0, dst_size - len);
708 bool wined3d_driver_info_init(struct wined3d_driver_info *driver_info,
709 const struct wined3d_gpu_description *gpu_desc, enum wined3d_feature_level feature_level,
710 UINT64 vram_bytes, UINT64 sysmem_bytes)
712 const struct driver_version_information *version_info;
713 WORD driver_os_version, driver_feature_level = 10;
714 enum wined3d_driver_model driver_model;
715 enum wined3d_display_driver driver;
716 MEMORYSTATUSEX memory_status;
717 OSVERSIONINFOW os_version;
719 memset(&os_version, 0, sizeof(os_version));
720 os_version.dwOSVersionInfoSize = sizeof(os_version);
721 if (!GetVersionExW(&os_version))
723 ERR("Failed to get OS version, reporting 2000/XP.\n");
724 driver_os_version = 6;
725 driver_model = DRIVER_MODEL_NT5X;
727 else
729 TRACE("OS version %lu.%lu.\n", os_version.dwMajorVersion, os_version.dwMinorVersion);
730 switch (os_version.dwMajorVersion)
732 case 2:
733 case 3:
734 case 4:
735 /* If needed we could distinguish between 9x and NT4, but this code won't make
736 * sense for NT4 since it had no way to obtain this info through DirectDraw 3.0.
738 driver_os_version = 4;
739 driver_model = DRIVER_MODEL_WIN9X;
740 break;
742 case 5:
743 driver_os_version = 6;
744 driver_model = DRIVER_MODEL_NT5X;
745 break;
747 case 6:
748 if (os_version.dwMinorVersion == 0)
750 driver_os_version = 7;
751 driver_model = DRIVER_MODEL_NT6X;
753 else if (os_version.dwMinorVersion == 1)
755 driver_os_version = 8;
756 driver_model = DRIVER_MODEL_NT6X;
758 else if (os_version.dwMinorVersion == 2)
760 driver_os_version = 9;
761 driver_model = DRIVER_MODEL_NT6X;
763 else
765 if (os_version.dwMinorVersion > 3)
767 FIXME("Unhandled OS version %lu.%lu, reporting Windows 8.1.\n",
768 os_version.dwMajorVersion, os_version.dwMinorVersion);
770 driver_os_version = 10;
771 driver_model = DRIVER_MODEL_NT6X;
773 break;
775 case 10:
776 driver_os_version = 26;
777 driver_model = DRIVER_MODEL_NT6X;
778 break;
780 default:
781 FIXME("Unhandled OS version %lu.%lu, reporting Windows 7.\n",
782 os_version.dwMajorVersion, os_version.dwMinorVersion);
783 driver_os_version = 8;
784 driver_model = DRIVER_MODEL_NT6X;
785 break;
789 TRACE("GPU maximum feature level %#x.\n", feature_level);
790 switch (feature_level)
792 case WINED3D_FEATURE_LEVEL_NONE:
793 case WINED3D_FEATURE_LEVEL_5:
794 if (driver_model == DRIVER_MODEL_WIN9X)
795 driver_feature_level = 5;
796 else
797 driver_feature_level = 10;
798 break;
799 case WINED3D_FEATURE_LEVEL_6:
800 driver_feature_level = 11;
801 break;
802 case WINED3D_FEATURE_LEVEL_7:
803 driver_feature_level = 12;
804 break;
805 case WINED3D_FEATURE_LEVEL_8:
806 driver_feature_level = 13;
807 break;
808 case WINED3D_FEATURE_LEVEL_9_1:
809 case WINED3D_FEATURE_LEVEL_9_2:
810 case WINED3D_FEATURE_LEVEL_9_3:
811 driver_feature_level = 14;
812 break;
813 case WINED3D_FEATURE_LEVEL_10:
814 driver_feature_level = 15;
815 break;
816 case WINED3D_FEATURE_LEVEL_10_1:
817 driver_feature_level = 16;
818 break;
819 case WINED3D_FEATURE_LEVEL_11:
820 driver_feature_level = 17;
821 break;
822 case WINED3D_FEATURE_LEVEL_11_1:
823 /* Advertise support for everything up to FL 12_x. */
824 driver_feature_level = 21;
825 break;
827 if (os_version.dwMajorVersion == 6 && !os_version.dwMinorVersion)
828 driver_feature_level = min(driver_feature_level, 18);
829 else if (os_version.dwMajorVersion < 6)
830 driver_feature_level = min(driver_feature_level, 14);
832 driver_info->vendor = gpu_desc->vendor;
833 driver_info->device = gpu_desc->device;
834 wined3d_copy_name(driver_info->description, gpu_desc->description, ARRAY_SIZE(driver_info->description));
835 driver_info->vram_bytes = vram_bytes ? vram_bytes : (UINT64)gpu_desc->vidmem * 1024 * 1024;
836 driver = gpu_desc->driver;
838 if (wined3d_settings.emulated_textureram)
840 driver_info->vram_bytes = wined3d_settings.emulated_textureram;
841 TRACE("Overriding amount of video memory with 0x%s bytes.\n",
842 wine_dbgstr_longlong(driver_info->vram_bytes));
846 * Diablo 2 crashes when the amount of video memory is greater than 0x7fffffff.
847 * In order to avoid this application bug we limit the amount of video memory
848 * to LONG_MAX for older Windows versions.
850 if (driver_model < DRIVER_MODEL_NT6X && driver_info->vram_bytes > LONG_MAX)
852 TRACE("Limiting amount of video memory to %#lx bytes for OS version older than Vista.\n", LONG_MAX);
853 driver_info->vram_bytes = LONG_MAX;
856 if (!(driver_info->sysmem_bytes = sysmem_bytes))
858 driver_info->sysmem_bytes = 64 * 1024 * 1024;
859 memory_status.dwLength = sizeof(memory_status);
860 if (GlobalMemoryStatusEx(&memory_status))
861 driver_info->sysmem_bytes = max(memory_status.ullTotalPhys / 2, driver_info->sysmem_bytes);
862 else
863 ERR("Failed to get global memory status.\n");
866 /* Try to obtain driver version information for the current Windows version. This fails in
867 * some cases:
868 * - the gpu is not available on the currently selected OS version:
869 * - Geforce GTX480 on Win98. When running applications in compatibility mode on Windows,
870 * version information for the current Windows version is returned instead of faked info.
871 * We do the same and assume the default Windows version to emulate is WinXP.
873 * - Videocard is a Riva TNT but winver is set to win7 (there are no drivers for this beast)
874 * For now return the XP driver info. Perhaps later on we should return VESA.
876 * - the gpu is not in our database (can happen when the user overrides the vendor_id / device_id)
877 * This could be an indication that our database is not up to date, so this should be fixed.
879 if ((version_info = get_driver_version_info(driver, driver_model))
880 || (version_info = get_driver_version_info(driver, DRIVER_MODEL_GENERIC)))
882 driver_info->name = version_info->driver_name;
883 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, driver_feature_level);
884 driver_info->version_low = MAKEDWORD_VERSION(version_info->subversion, version_info->build);
886 return true;
889 ERR("No driver version info found for device %04x:%04x, driver model %#x.\n",
890 driver_info->vendor, driver_info->device, driver_model);
891 return false;
894 enum wined3d_pci_device wined3d_gpu_from_feature_level(enum wined3d_pci_vendor *vendor,
895 enum wined3d_feature_level feature_level)
897 static const struct wined3d_fallback_card
899 enum wined3d_feature_level feature_level;
900 enum wined3d_pci_device device_id;
902 card_fallback_nvidia[] =
904 {WINED3D_FEATURE_LEVEL_5, CARD_NVIDIA_RIVA_128},
905 {WINED3D_FEATURE_LEVEL_6, CARD_NVIDIA_RIVA_TNT},
906 {WINED3D_FEATURE_LEVEL_7, CARD_NVIDIA_GEFORCE},
907 {WINED3D_FEATURE_LEVEL_8, CARD_NVIDIA_GEFORCE3},
908 {WINED3D_FEATURE_LEVEL_9_2, CARD_NVIDIA_GEFORCEFX_5800},
909 {WINED3D_FEATURE_LEVEL_9_3, CARD_NVIDIA_GEFORCE_6800},
910 {WINED3D_FEATURE_LEVEL_10, CARD_NVIDIA_GEFORCE_8800GTX},
911 {WINED3D_FEATURE_LEVEL_11, CARD_NVIDIA_GEFORCE_GTX470},
912 {WINED3D_FEATURE_LEVEL_NONE},
914 card_fallback_amd[] =
916 {WINED3D_FEATURE_LEVEL_5, CARD_AMD_RAGE_128PRO},
917 {WINED3D_FEATURE_LEVEL_7, CARD_AMD_RADEON_7200},
918 {WINED3D_FEATURE_LEVEL_8, CARD_AMD_RADEON_8500},
919 {WINED3D_FEATURE_LEVEL_9_1, CARD_AMD_RADEON_9500},
920 {WINED3D_FEATURE_LEVEL_9_3, CARD_AMD_RADEON_X1600},
921 {WINED3D_FEATURE_LEVEL_10, CARD_AMD_RADEON_HD2900},
922 {WINED3D_FEATURE_LEVEL_11, CARD_AMD_RADEON_HD5600},
923 {WINED3D_FEATURE_LEVEL_NONE},
925 card_fallback_intel[] =
927 {WINED3D_FEATURE_LEVEL_5, CARD_INTEL_845G},
928 {WINED3D_FEATURE_LEVEL_8, CARD_INTEL_915G},
929 {WINED3D_FEATURE_LEVEL_9_3, CARD_INTEL_945G},
930 {WINED3D_FEATURE_LEVEL_10, CARD_INTEL_G45},
931 {WINED3D_FEATURE_LEVEL_11, CARD_INTEL_IVBD},
932 {WINED3D_FEATURE_LEVEL_NONE},
935 static const struct
937 enum wined3d_pci_vendor vendor;
938 const struct wined3d_fallback_card *cards;
940 fallbacks[] =
942 {HW_VENDOR_AMD, card_fallback_amd},
943 {HW_VENDOR_NVIDIA, card_fallback_nvidia},
944 {HW_VENDOR_VMWARE, card_fallback_amd},
945 {HW_VENDOR_INTEL, card_fallback_intel},
948 const struct wined3d_fallback_card *cards;
949 enum wined3d_pci_device device_id;
950 unsigned int i;
952 cards = NULL;
953 for (i = 0; i < ARRAY_SIZE(fallbacks); ++i)
955 if (*vendor == fallbacks[i].vendor)
956 cards = fallbacks[i].cards;
958 if (!cards)
960 *vendor = HW_VENDOR_NVIDIA;
961 cards = card_fallback_nvidia;
964 device_id = cards->device_id;
965 for (i = 0; cards[i].feature_level; ++i)
967 if (feature_level >= cards[i].feature_level)
968 device_id = cards[i].device_id;
970 return device_id;
973 struct wined3d_adapter * CDECL wined3d_get_adapter(const struct wined3d *wined3d, unsigned int idx)
975 TRACE("wined3d %p, idx %u.\n", wined3d, idx);
977 if (idx >= wined3d->adapter_count)
978 return NULL;
980 return wined3d->adapters[idx];
983 UINT CDECL wined3d_get_adapter_count(const struct wined3d *wined3d)
985 TRACE("wined3d %p, reporting %u adapters.\n",
986 wined3d, wined3d->adapter_count);
988 return wined3d->adapter_count;
991 struct wined3d_output * CDECL wined3d_adapter_get_output(const struct wined3d_adapter *adapter,
992 unsigned int idx)
994 TRACE("adapter %p, idx %u.\n", adapter, idx);
996 if (idx >= adapter->output_count)
997 return NULL;
999 return &adapter->outputs[idx];
1002 unsigned int CDECL wined3d_adapter_get_output_count(const struct wined3d_adapter *adapter)
1004 TRACE("adapter %p, reporting %Iu outputs.\n", adapter, adapter->output_count);
1006 return adapter->output_count;
1009 HRESULT CDECL wined3d_adapter_get_video_memory_info(const struct wined3d_adapter *adapter,
1010 unsigned int node_idx, enum wined3d_memory_segment_group group,
1011 struct wined3d_video_memory_info *info)
1013 static unsigned int once;
1014 D3DKMT_QUERYVIDEOMEMORYINFO query_memory_info;
1015 struct wined3d_adapter_identifier adapter_id;
1016 NTSTATUS status;
1017 HRESULT hr;
1019 TRACE("adapter %p, node_idx %u, group %d, info %p.\n", adapter, node_idx, group, info);
1021 if (group > WINED3D_MEMORY_SEGMENT_GROUP_NON_LOCAL)
1023 WARN("Invalid memory segment group %#x.\n", group);
1024 return E_INVALIDARG;
1027 query_memory_info.hProcess = NULL;
1028 query_memory_info.hAdapter = adapter->kmt_adapter;
1029 query_memory_info.PhysicalAdapterIndex = node_idx;
1030 query_memory_info.MemorySegmentGroup = (D3DKMT_MEMORY_SEGMENT_GROUP)group;
1031 status = D3DKMTQueryVideoMemoryInfo(&query_memory_info);
1032 if (status == STATUS_SUCCESS)
1034 info->budget = query_memory_info.Budget;
1035 info->current_usage = query_memory_info.CurrentUsage;
1036 info->current_reservation = query_memory_info.CurrentReservation;
1037 info->available_reservation = query_memory_info.AvailableForReservation;
1038 return WINED3D_OK;
1041 /* D3DKMTQueryVideoMemoryInfo() failed, fallback to fake memory info */
1042 if (!once++)
1043 FIXME("Returning fake video memory info.\n");
1045 if (node_idx)
1046 FIXME("Ignoring node index %u.\n", node_idx);
1048 adapter_id.driver_size = 0;
1049 adapter_id.description_size = 0;
1050 if (FAILED(hr = wined3d_adapter_get_identifier(adapter, 0, &adapter_id)))
1051 return hr;
1053 switch (group)
1055 case WINED3D_MEMORY_SEGMENT_GROUP_LOCAL:
1056 info->budget = adapter_id.video_memory;
1057 info->current_usage = adapter->vram_bytes_used;
1058 info->available_reservation = adapter_id.video_memory / 2;
1059 info->current_reservation = 0;
1060 break;
1061 case WINED3D_MEMORY_SEGMENT_GROUP_NON_LOCAL:
1062 memset(info, 0, sizeof(*info));
1063 break;
1065 return WINED3D_OK;
1068 static DWORD CALLBACK notification_thread_func(void *stop_event)
1070 struct wined3d_adapter_budget_change_notification *notification;
1071 struct wined3d_video_memory_info info;
1072 HRESULT hr;
1074 SetThreadDescription(GetCurrentThread(), L"wined3d_budget_change_notification");
1076 while (TRUE)
1078 wined3d_mutex_lock();
1079 LIST_FOR_EACH_ENTRY(notification, &adapter_budget_change_notifications,
1080 struct wined3d_adapter_budget_change_notification, entry)
1082 hr = wined3d_adapter_get_video_memory_info(notification->adapter, 0,
1083 WINED3D_MEMORY_SEGMENT_GROUP_LOCAL, &info);
1084 if (SUCCEEDED(hr) && info.budget != notification->last_local_budget)
1086 notification->last_local_budget = info.budget;
1087 SetEvent(notification->event);
1088 continue;
1091 hr = wined3d_adapter_get_video_memory_info(notification->adapter, 0,
1092 WINED3D_MEMORY_SEGMENT_GROUP_NON_LOCAL, &info);
1093 if (SUCCEEDED(hr) && info.budget != notification->last_non_local_budget)
1095 notification->last_non_local_budget = info.budget;
1096 SetEvent(notification->event);
1099 wined3d_mutex_unlock();
1101 if (WaitForSingleObject(stop_event, 1000) == WAIT_OBJECT_0)
1102 break;
1105 return TRUE;
1108 HRESULT CDECL wined3d_adapter_register_budget_change_notification(const struct wined3d_adapter *adapter,
1109 HANDLE event, DWORD *cookie)
1111 static DWORD cookie_counter;
1112 static BOOL wrapped;
1113 struct wined3d_adapter_budget_change_notification *notification, *new_notification;
1114 BOOL found = FALSE;
1116 new_notification = heap_alloc_zero(sizeof(*new_notification));
1117 if (!new_notification)
1118 return E_OUTOFMEMORY;
1120 wined3d_mutex_lock();
1121 new_notification->adapter = adapter;
1122 new_notification->event = event;
1123 new_notification->cookie = cookie_counter++;
1124 if (cookie_counter < new_notification->cookie)
1125 wrapped = TRUE;
1126 if (wrapped)
1128 while (TRUE)
1130 LIST_FOR_EACH_ENTRY(notification, &adapter_budget_change_notifications,
1131 struct wined3d_adapter_budget_change_notification, entry)
1133 if (notification->cookie == new_notification->cookie)
1135 found = TRUE;
1136 break;
1140 if (!found)
1141 break;
1143 new_notification->cookie = cookie_counter++;
1147 *cookie = new_notification->cookie;
1148 list_add_head(&adapter_budget_change_notifications, &new_notification->entry);
1150 if (!notification_thread)
1152 notification_thread_stop_event = CreateEventW(0, FALSE, FALSE, NULL);
1153 notification_thread = CreateThread(NULL, 0, notification_thread_func,
1154 notification_thread_stop_event, 0, NULL);
1156 wined3d_mutex_unlock();
1157 return WINED3D_OK;
1160 HRESULT CDECL wined3d_adapter_unregister_budget_change_notification(DWORD cookie)
1162 struct wined3d_adapter_budget_change_notification *notification;
1163 HANDLE thread, thread_stop_event;
1165 wined3d_mutex_lock();
1166 LIST_FOR_EACH_ENTRY(notification, &adapter_budget_change_notifications,
1167 struct wined3d_adapter_budget_change_notification, entry)
1169 if (notification->cookie == cookie)
1171 list_remove(&notification->entry);
1172 heap_free(notification);
1173 break;
1177 if (!list_empty(&adapter_budget_change_notifications))
1179 wined3d_mutex_unlock();
1180 return WINED3D_OK;
1183 thread = notification_thread;
1184 thread_stop_event = notification_thread_stop_event;
1185 notification_thread = NULL;
1186 notification_thread_stop_event = NULL;
1187 wined3d_mutex_unlock();
1188 SetEvent(thread_stop_event);
1189 WaitForSingleObject(thread, INFINITE);
1190 CloseHandle(thread);
1191 CloseHandle(thread_stop_event);
1192 return WINED3D_OK;
1195 HRESULT CDECL wined3d_register_software_device(struct wined3d *wined3d, void *init_function)
1197 FIXME("wined3d %p, init_function %p stub!\n", wined3d, init_function);
1199 return WINED3D_OK;
1202 static BOOL CALLBACK enum_monitor_proc(HMONITOR monitor, HDC hdc, RECT *rect, LPARAM lparam)
1204 struct wined3d_output_desc *desc = (struct wined3d_output_desc *)lparam;
1205 MONITORINFOEXW monitor_info;
1207 monitor_info.cbSize = sizeof(monitor_info);
1208 if (GetMonitorInfoW(monitor, (MONITORINFO *)&monitor_info) &&
1209 !lstrcmpiW(desc->device_name, monitor_info.szDevice))
1211 desc->monitor = monitor;
1212 desc->desktop_rect = monitor_info.rcMonitor;
1213 desc->attached_to_desktop = TRUE;
1214 return FALSE;
1217 return TRUE;
1220 HRESULT CDECL wined3d_output_get_desc(const struct wined3d_output *output,
1221 struct wined3d_output_desc *desc)
1223 TRACE("output %p, desc %p.\n", output, desc);
1225 memset(desc, 0, sizeof(*desc));
1226 desc->ordinal = output->ordinal;
1227 lstrcpyW(desc->device_name, output->device_name);
1228 EnumDisplayMonitors(NULL, NULL, enum_monitor_proc, (LPARAM)desc);
1229 return WINED3D_OK;
1232 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
1233 of the same bpp but different resolutions */
1235 static void wined3d_output_update_modes(struct wined3d_output *output, bool cached)
1237 struct wined3d_display_mode *wined3d_mode;
1238 DEVMODEW mode = {.dmSize = sizeof(mode)};
1239 unsigned int i;
1241 if (output->modes_valid && cached)
1242 return;
1244 output->mode_count = 0;
1246 for (i = 0; EnumDisplaySettingsExW(output->device_name, i, &mode, 0); ++i)
1248 if (!wined3d_array_reserve((void **)&output->modes, &output->modes_size,
1249 output->mode_count + 1, sizeof(*output->modes)))
1250 return;
1252 wined3d_mode = &output->modes[output->mode_count++];
1253 wined3d_mode->width = mode.dmPelsWidth;
1254 wined3d_mode->height = mode.dmPelsHeight;
1255 wined3d_mode->format_id = pixelformat_for_depth(mode.dmBitsPerPel);
1257 if (mode.dmFields & DM_DISPLAYFREQUENCY)
1258 wined3d_mode->refresh_rate = mode.dmDisplayFrequency;
1259 else
1260 wined3d_mode->refresh_rate = DEFAULT_REFRESH_RATE;
1262 if (mode.dmFields & DM_DISPLAYFLAGS)
1264 if (mode.dmDisplayFlags & DM_INTERLACED)
1265 wined3d_mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
1266 else
1267 wined3d_mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
1269 else
1271 wined3d_mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
1275 output->modes_valid = true;
1278 static bool mode_matches_filter(const struct wined3d_adapter *adapter, const struct wined3d_display_mode *mode,
1279 const struct wined3d_format *format, enum wined3d_scanline_ordering scanline_ordering)
1281 if (scanline_ordering != WINED3D_SCANLINE_ORDERING_UNKNOWN
1282 && mode->scanline_ordering != WINED3D_SCANLINE_ORDERING_UNKNOWN
1283 && scanline_ordering != mode->scanline_ordering)
1284 return false;
1286 if (format->id == WINED3DFMT_UNKNOWN)
1288 /* This is for d3d8, do not enumerate P8 here. */
1289 if (mode->format_id != WINED3DFMT_B5G6R5_UNORM && mode->format_id != WINED3DFMT_B8G8R8X8_UNORM)
1290 return false;
1292 else
1294 const struct wined3d_format *mode_format = wined3d_get_format(adapter,
1295 mode->format_id, WINED3D_BIND_RENDER_TARGET);
1297 if (format->byte_count != mode_format->byte_count)
1298 return false;
1301 return true;
1304 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1305 unsigned int CDECL wined3d_output_get_mode_count(struct wined3d_output *output,
1306 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering, bool cached)
1308 const struct wined3d_adapter *adapter;
1309 const struct wined3d_format *format;
1310 unsigned int count = 0;
1311 SIZE_T i;
1313 TRACE("output %p, format %s, scanline_ordering %#x.\n",
1314 output, debug_d3dformat(format_id), scanline_ordering);
1316 adapter = output->adapter;
1317 format = wined3d_get_format(adapter, format_id, WINED3D_BIND_RENDER_TARGET);
1319 wined3d_output_update_modes(output, cached);
1321 for (i = 0; i < output->mode_count; ++i)
1323 if (mode_matches_filter(adapter, &output->modes[i], format, scanline_ordering))
1324 ++count;
1327 TRACE("Returning %u matching modes (out of %Iu total).\n", count, output->mode_count);
1329 return count;
1332 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
1333 HRESULT CDECL wined3d_output_get_mode(struct wined3d_output *output,
1334 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering,
1335 unsigned int mode_idx, struct wined3d_display_mode *mode, bool cached)
1337 const struct wined3d_adapter *adapter;
1338 const struct wined3d_format *format;
1339 SIZE_T i, match_idx = 0;
1341 TRACE("output %p, format %s, scanline_ordering %#x, mode_idx %u, mode %p.\n",
1342 output, debug_d3dformat(format_id), scanline_ordering, mode_idx, mode);
1344 if (!mode)
1345 return WINED3DERR_INVALIDCALL;
1347 adapter = output->adapter;
1348 format = wined3d_get_format(adapter, format_id, WINED3D_BIND_RENDER_TARGET);
1350 wined3d_output_update_modes(output, cached);
1352 for (i = 0; i < output->mode_count; ++i)
1354 const struct wined3d_display_mode *wined3d_mode = &output->modes[i];
1356 if (mode_matches_filter(adapter, wined3d_mode, format, scanline_ordering) && match_idx++ == mode_idx)
1358 *mode = *wined3d_mode;
1359 if (format_id != WINED3DFMT_UNKNOWN)
1360 mode->format_id = format_id;
1362 TRACE("%ux%u@%u %u bpp, %s %#x.\n", mode->width, mode->height, mode->refresh_rate,
1363 wined3d_get_format(adapter, mode->format_id, WINED3D_BIND_RENDER_TARGET)->byte_count * CHAR_BIT,
1364 debug_d3dformat(mode->format_id), mode->scanline_ordering);
1365 return WINED3D_OK;
1369 WARN("Invalid mode_idx %u.\n", mode_idx);
1370 return WINED3DERR_INVALIDCALL;
1373 HRESULT CDECL wined3d_output_find_closest_matching_mode(struct wined3d_output *output,
1374 struct wined3d_display_mode *mode)
1376 unsigned int i, j, mode_count, matching_mode_count, closest;
1377 struct wined3d_display_mode **matching_modes;
1378 struct wined3d_display_mode *modes;
1379 HRESULT hr;
1381 TRACE("output %p, mode %p.\n", output, mode);
1383 if (!(mode_count = wined3d_output_get_mode_count(output, mode->format_id,
1384 WINED3D_SCANLINE_ORDERING_UNKNOWN, false)))
1386 WARN("Output has 0 matching modes.\n");
1387 return E_FAIL;
1390 if (!(modes = heap_calloc(mode_count, sizeof(*modes))))
1391 return E_OUTOFMEMORY;
1392 if (!(matching_modes = heap_calloc(mode_count, sizeof(*matching_modes))))
1394 heap_free(modes);
1395 return E_OUTOFMEMORY;
1398 for (i = 0; i < mode_count; ++i)
1400 if (FAILED(hr = wined3d_output_get_mode(output, mode->format_id,
1401 WINED3D_SCANLINE_ORDERING_UNKNOWN, i, &modes[i], true)))
1403 heap_free(matching_modes);
1404 heap_free(modes);
1405 return hr;
1407 matching_modes[i] = &modes[i];
1410 matching_mode_count = mode_count;
1412 if (mode->scanline_ordering != WINED3D_SCANLINE_ORDERING_UNKNOWN)
1414 for (i = 0, j = 0; i < matching_mode_count; ++i)
1416 if (matching_modes[i]->scanline_ordering == mode->scanline_ordering)
1417 matching_modes[j++] = matching_modes[i];
1419 if (j > 0)
1420 matching_mode_count = j;
1423 if (mode->refresh_rate)
1425 for (i = 0, j = 0; i < matching_mode_count; ++i)
1427 if (matching_modes[i]->refresh_rate == mode->refresh_rate)
1428 matching_modes[j++] = matching_modes[i];
1430 if (j > 0)
1431 matching_mode_count = j;
1434 if (!mode->width || !mode->height)
1436 struct wined3d_display_mode current_mode;
1437 if (FAILED(hr = wined3d_output_get_display_mode(output, &current_mode, NULL)))
1439 heap_free(matching_modes);
1440 heap_free(modes);
1441 return hr;
1443 mode->width = current_mode.width;
1444 mode->height = current_mode.height;
1447 closest = ~0u;
1448 for (i = 0, j = 0; i < matching_mode_count; ++i)
1450 unsigned int d = abs((int)(mode->width - matching_modes[i]->width))
1451 + abs((int)(mode->height - matching_modes[i]->height));
1453 if (closest > d)
1455 closest = d;
1456 j = i;
1460 *mode = *matching_modes[j];
1462 heap_free(matching_modes);
1463 heap_free(modes);
1465 TRACE("Returning %ux%u@%u %s %#x.\n", mode->width, mode->height,
1466 mode->refresh_rate, debug_d3dformat(mode->format_id),
1467 mode->scanline_ordering);
1469 return WINED3D_OK;
1472 struct wined3d_adapter * CDECL wined3d_output_get_adapter(const struct wined3d_output *output)
1474 TRACE("output %p.\n", output);
1476 return output->adapter;
1479 HRESULT CDECL wined3d_output_get_display_mode(const struct wined3d_output *output,
1480 struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
1482 DEVMODEW m;
1484 TRACE("output %p, display_mode %p, rotation %p.\n", output, mode, rotation);
1486 if (!mode)
1487 return WINED3DERR_INVALIDCALL;
1489 memset(&m, 0, sizeof(m));
1490 m.dmSize = sizeof(m);
1492 EnumDisplaySettingsExW(output->device_name, ENUM_CURRENT_SETTINGS, &m, 0);
1493 mode->width = m.dmPelsWidth;
1494 mode->height = m.dmPelsHeight;
1495 mode->refresh_rate = DEFAULT_REFRESH_RATE;
1496 if (m.dmFields & DM_DISPLAYFREQUENCY)
1497 mode->refresh_rate = m.dmDisplayFrequency;
1498 mode->format_id = pixelformat_for_depth(m.dmBitsPerPel);
1500 /* Lie about the format. X11 can't change the color depth, and some apps
1501 * are pretty angry if they SetDisplayMode from 24 to 16 bpp and find out
1502 * that GetDisplayMode still returns 24 bpp. This should probably be
1503 * handled in winex11 instead. */
1504 if (output->screen_format && output->screen_format != mode->format_id)
1506 WARN("Overriding format %s with stored format %s.\n",
1507 debug_d3dformat(mode->format_id),
1508 debug_d3dformat(output->screen_format));
1509 mode->format_id = output->screen_format;
1512 if (!(m.dmFields & DM_DISPLAYFLAGS))
1513 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
1514 else if (m.dmDisplayFlags & DM_INTERLACED)
1515 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
1516 else
1517 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
1519 if (rotation)
1521 switch (m.dmDisplayOrientation)
1523 case DMDO_DEFAULT:
1524 *rotation = WINED3D_DISPLAY_ROTATION_0;
1525 break;
1526 case DMDO_90:
1527 *rotation = WINED3D_DISPLAY_ROTATION_90;
1528 break;
1529 case DMDO_180:
1530 *rotation = WINED3D_DISPLAY_ROTATION_180;
1531 break;
1532 case DMDO_270:
1533 *rotation = WINED3D_DISPLAY_ROTATION_270;
1534 break;
1535 default:
1536 FIXME("Unhandled display rotation %#lx.\n", m.dmDisplayOrientation);
1537 *rotation = WINED3D_DISPLAY_ROTATION_UNSPECIFIED;
1538 break;
1542 TRACE("Returning %ux%u@%u %s %#x.\n", mode->width, mode->height,
1543 mode->refresh_rate, debug_d3dformat(mode->format_id),
1544 mode->scanline_ordering);
1545 return WINED3D_OK;
1548 static BOOL equal_display_mode(const DEVMODEW *mode1, const DEVMODEW *mode2)
1550 if (mode1->dmFields & mode2->dmFields & DM_PELSWIDTH
1551 && mode1->dmPelsWidth != mode2->dmPelsWidth)
1552 return FALSE;
1554 if (mode1->dmFields & mode2->dmFields & DM_PELSHEIGHT
1555 && mode1->dmPelsHeight != mode2->dmPelsHeight)
1556 return FALSE;
1558 if (mode1->dmFields & mode2->dmFields & DM_BITSPERPEL
1559 && mode1->dmBitsPerPel != mode2->dmBitsPerPel)
1560 return FALSE;
1562 if (mode1->dmFields & mode2->dmFields & DM_DISPLAYFLAGS
1563 && mode1->dmDisplayFlags != mode2->dmDisplayFlags)
1564 return FALSE;
1566 if (mode1->dmFields & mode2->dmFields & DM_DISPLAYFREQUENCY
1567 && mode1->dmDisplayFrequency != mode2->dmDisplayFrequency)
1568 return FALSE;
1570 if (mode1->dmFields & mode2->dmFields & DM_DISPLAYORIENTATION
1571 && mode1->dmDisplayOrientation != mode2->dmDisplayOrientation)
1572 return FALSE;
1574 if (mode1->dmFields & mode2->dmFields & DM_POSITION
1575 && (mode1->dmPosition.x != mode2->dmPosition.x
1576 || mode1->dmPosition.y != mode2->dmPosition.y))
1577 return FALSE;
1579 return TRUE;
1582 HRESULT CDECL wined3d_restore_display_modes(struct wined3d *wined3d)
1584 unsigned int adapter_idx, output_idx = 0;
1585 DEVMODEW current_mode, registry_mode;
1586 struct wined3d_adapter *adapter;
1587 DISPLAY_DEVICEW display_device;
1588 struct wined3d_output *output;
1589 BOOL do_mode_change = FALSE;
1590 LONG ret;
1592 TRACE("wined3d %p.\n", wined3d);
1594 memset(&current_mode, 0, sizeof(current_mode));
1595 memset(&registry_mode, 0, sizeof(registry_mode));
1596 current_mode.dmSize = sizeof(current_mode);
1597 registry_mode.dmSize = sizeof(registry_mode);
1598 display_device.cb = sizeof(display_device);
1599 while (EnumDisplayDevicesW(NULL, output_idx++, &display_device, 0))
1601 if (!EnumDisplaySettingsExW(display_device.DeviceName, ENUM_CURRENT_SETTINGS, &current_mode, 0))
1603 ERR("Failed to read the current display mode for %s.\n",
1604 wine_dbgstr_w(display_device.DeviceName));
1605 return WINED3DERR_NOTAVAILABLE;
1608 if (!EnumDisplaySettingsExW(display_device.DeviceName, ENUM_REGISTRY_SETTINGS, &registry_mode, 0))
1610 ERR("Failed to read the registry display mode for %s.\n",
1611 wine_dbgstr_w(display_device.DeviceName));
1612 return WINED3DERR_NOTAVAILABLE;
1615 if (!equal_display_mode(&current_mode, &registry_mode))
1617 do_mode_change = TRUE;
1618 break;
1622 if (do_mode_change)
1624 ret = ChangeDisplaySettingsExW(NULL, NULL, NULL, 0, NULL);
1625 if (ret != DISP_CHANGE_SUCCESSFUL)
1627 ERR("Failed to restore all outputs to their registry display settings, error %ld.\n", ret);
1628 return WINED3DERR_NOTAVAILABLE;
1631 else
1633 TRACE("Skipping redundant mode setting call.\n");
1636 for (adapter_idx = 0; adapter_idx < wined3d->adapter_count; ++adapter_idx)
1638 adapter = wined3d->adapters[adapter_idx];
1639 for (output_idx = 0; output_idx < adapter->output_count; ++output_idx)
1641 output = &adapter->outputs[output_idx];
1643 if (!EnumDisplaySettingsExW(output->device_name, ENUM_CURRENT_SETTINGS, &current_mode, 0))
1645 ERR("Failed to read the current display mode for %s.\n",
1646 wine_dbgstr_w(output->device_name));
1647 return WINED3DERR_NOTAVAILABLE;
1650 output->screen_format = pixelformat_for_depth(current_mode.dmBitsPerPel);
1654 return WINED3D_OK;
1657 HRESULT CDECL wined3d_output_set_display_mode(struct wined3d_output *output,
1658 const struct wined3d_display_mode *mode)
1660 enum wined3d_format_id new_format_id;
1661 const struct wined3d_format *format;
1662 DEVMODEW new_mode, current_mode;
1663 LONG ret;
1665 TRACE("output %p, mode %p.\n", output, mode);
1666 TRACE("mode %ux%u@%u %s %#x.\n", mode->width, mode->height, mode->refresh_rate,
1667 debug_d3dformat(mode->format_id), mode->scanline_ordering);
1669 memset(&new_mode, 0, sizeof(new_mode));
1670 new_mode.dmSize = sizeof(new_mode);
1671 memset(&current_mode, 0, sizeof(current_mode));
1672 current_mode.dmSize = sizeof(current_mode);
1674 format = wined3d_get_format(output->adapter, mode->format_id, WINED3D_BIND_RENDER_TARGET);
1676 new_mode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
1677 new_mode.dmBitsPerPel = format->byte_count * CHAR_BIT;
1678 new_mode.dmPelsWidth = mode->width;
1679 new_mode.dmPelsHeight = mode->height;
1680 new_mode.dmDisplayFrequency = mode->refresh_rate;
1681 if (mode->refresh_rate)
1682 new_mode.dmFields |= DM_DISPLAYFREQUENCY;
1683 if (mode->scanline_ordering != WINED3D_SCANLINE_ORDERING_UNKNOWN)
1685 new_mode.dmFields |= DM_DISPLAYFLAGS;
1686 if (mode->scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED)
1687 new_mode.dmDisplayFlags |= DM_INTERLACED;
1689 new_format_id = mode->format_id;
1691 /* Only change the mode if necessary. */
1692 if (!EnumDisplaySettingsW(output->device_name, ENUM_CURRENT_SETTINGS, &current_mode))
1694 ERR("Failed to get current display mode.\n");
1696 else if (equal_display_mode(&current_mode, &new_mode))
1698 TRACE("Skipping redundant mode setting call.\n");
1699 output->screen_format = new_format_id;
1700 return WINED3D_OK;
1703 ret = ChangeDisplaySettingsExW(output->device_name, &new_mode, NULL, CDS_FULLSCREEN, NULL);
1704 if (ret != DISP_CHANGE_SUCCESSFUL)
1706 if (new_mode.dmFields & DM_DISPLAYFREQUENCY)
1708 WARN("ChangeDisplaySettingsExW failed, trying without the refresh rate.\n");
1709 new_mode.dmFields &= ~DM_DISPLAYFREQUENCY;
1710 new_mode.dmDisplayFrequency = 0;
1711 ret = ChangeDisplaySettingsExW(output->device_name, &new_mode, NULL, CDS_FULLSCREEN, NULL);
1713 if (ret != DISP_CHANGE_SUCCESSFUL)
1714 return WINED3DERR_NOTAVAILABLE;
1717 /* Store the new values. */
1718 output->screen_format = new_format_id;
1720 return WINED3D_OK;
1723 HRESULT CDECL wined3d_output_set_gamma_ramp(struct wined3d_output *output, const struct wined3d_gamma_ramp *ramp)
1725 HDC dc;
1727 TRACE("output %p, ramp %p.\n", output, ramp);
1729 dc = CreateDCW(output->device_name, NULL, NULL, NULL);
1730 SetDeviceGammaRamp(dc, (void *)ramp);
1731 DeleteDC(dc);
1733 return WINED3D_OK;
1736 HRESULT wined3d_output_get_gamma_ramp(struct wined3d_output *output, struct wined3d_gamma_ramp *ramp)
1738 HDC dc;
1740 TRACE("output %p, ramp %p.\n", output, ramp);
1742 dc = CreateDCW(output->device_name, NULL, NULL, NULL);
1743 GetDeviceGammaRamp(dc, ramp);
1744 DeleteDC(dc);
1746 return WINED3D_OK;
1749 HRESULT CDECL wined3d_adapter_get_identifier(const struct wined3d_adapter *adapter,
1750 uint32_t flags, struct wined3d_adapter_identifier *identifier)
1752 TRACE("adapter %p, flags %#x, identifier %p.\n", adapter, flags, identifier);
1754 wined3d_mutex_lock();
1756 wined3d_copy_name(identifier->driver, adapter->driver_info.name, identifier->driver_size);
1757 wined3d_copy_name(identifier->description, adapter->driver_info.description, identifier->description_size);
1759 identifier->driver_version.u.HighPart = adapter->driver_info.version_high;
1760 identifier->driver_version.u.LowPart = adapter->driver_info.version_low;
1761 identifier->vendor_id = adapter->driver_info.vendor;
1762 identifier->device_id = adapter->driver_info.device;
1763 identifier->subsystem_id = 0;
1764 identifier->revision = 0;
1765 identifier->device_identifier = IID_D3DDEVICE_D3DUID;
1766 identifier->driver_uuid = adapter->driver_uuid;
1767 identifier->device_uuid = adapter->device_uuid;
1768 identifier->whql_level = (flags & WINED3DENUM_WHQL_LEVEL) ? 1 : 0;
1769 identifier->adapter_luid = adapter->luid;
1770 identifier->video_memory = min(~(SIZE_T)0, adapter->driver_info.vram_bytes);
1771 identifier->shared_system_memory = min(~(SIZE_T)0, adapter->driver_info.sysmem_bytes);
1773 wined3d_mutex_unlock();
1775 return WINED3D_OK;
1778 HRESULT CDECL wined3d_output_get_raster_status(const struct wined3d_output *output,
1779 struct wined3d_raster_status *raster_status)
1781 LONGLONG freq_per_frame, freq_per_line;
1782 LARGE_INTEGER counter, freq_per_sec;
1783 struct wined3d_display_mode mode;
1784 static UINT once;
1786 if (!once++)
1787 FIXME("output %p, raster_status %p semi-stub!\n", output, raster_status);
1788 else
1789 WARN("output %p, raster_status %p semi-stub!\n", output, raster_status);
1791 /* Obtaining the raster status is a widely implemented but optional
1792 * feature. When this method returns OK StarCraft 2 expects the
1793 * raster_status->InVBlank value to actually change over time.
1794 * And Endless Alice Crysis doesn't care even if this method fails.
1795 * Thus this method returns OK and fakes raster_status by
1796 * QueryPerformanceCounter. */
1798 if (!QueryPerformanceCounter(&counter) || !QueryPerformanceFrequency(&freq_per_sec))
1799 return WINED3DERR_INVALIDCALL;
1800 if (FAILED(wined3d_output_get_display_mode(output, &mode, NULL)))
1801 return WINED3DERR_INVALIDCALL;
1802 if (mode.refresh_rate == DEFAULT_REFRESH_RATE)
1803 mode.refresh_rate = 60;
1805 freq_per_frame = freq_per_sec.QuadPart / mode.refresh_rate;
1806 /* Assume 20 scan lines in the vertical blank. */
1807 freq_per_line = freq_per_frame / (mode.height + 20);
1808 raster_status->scan_line = (counter.QuadPart % freq_per_frame) / freq_per_line;
1809 if (raster_status->scan_line < mode.height)
1810 raster_status->in_vblank = FALSE;
1811 else
1813 raster_status->scan_line = 0;
1814 raster_status->in_vblank = TRUE;
1817 TRACE("Returning fake value, in_vblank %u, scan_line %u.\n",
1818 raster_status->in_vblank, raster_status->scan_line);
1820 return WINED3D_OK;
1823 HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d_adapter *adapter,
1824 enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id,
1825 enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id)
1827 const struct wined3d_format *rt_format;
1828 const struct wined3d_format *ds_format;
1830 TRACE("adapter %p, device_type %s, adapter_format %s, render_target_format %s, "
1831 "depth_stencil_format %s.\n",
1832 adapter, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
1833 debug_d3dformat(render_target_format_id), debug_d3dformat(depth_stencil_format_id));
1835 rt_format = wined3d_get_format(adapter, render_target_format_id, WINED3D_BIND_RENDER_TARGET);
1836 ds_format = wined3d_get_format(adapter, depth_stencil_format_id, WINED3D_BIND_DEPTH_STENCIL);
1838 if (!(rt_format->caps[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3D_FORMAT_CAP_RENDERTARGET))
1840 WARN("Format %s is not render target format.\n", debug_d3dformat(rt_format->id));
1841 return WINED3DERR_NOTAVAILABLE;
1843 if (!(ds_format->caps[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3D_FORMAT_CAP_DEPTH_STENCIL))
1845 WARN("Format %s is not depth/stencil format.\n", debug_d3dformat(ds_format->id));
1846 return WINED3DERR_NOTAVAILABLE;
1849 if (adapter->adapter_ops->adapter_check_format(adapter, NULL, rt_format, ds_format))
1851 TRACE("Formats match.\n");
1852 return WINED3D_OK;
1855 TRACE("Unsupported format pair: %s and %s.\n",
1856 debug_d3dformat(render_target_format_id),
1857 debug_d3dformat(depth_stencil_format_id));
1859 return WINED3DERR_NOTAVAILABLE;
1862 HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d_adapter *adapter,
1863 enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed,
1864 enum wined3d_multisample_type multisample_type, unsigned int *quality_levels)
1866 const struct wined3d_format *format;
1867 HRESULT hr = WINED3D_OK;
1869 TRACE("adapter %p, device_type %s, surface_format %s, "
1870 "windowed %#x, multisample_type %#x, quality_levels %p.\n",
1871 adapter, debug_d3ddevicetype(device_type), debug_d3dformat(surface_format_id),
1872 windowed, multisample_type, quality_levels);
1874 if (surface_format_id == WINED3DFMT_UNKNOWN)
1875 return WINED3DERR_INVALIDCALL;
1876 if (multisample_type < WINED3D_MULTISAMPLE_NONE)
1877 return WINED3DERR_INVALIDCALL;
1878 if (multisample_type > WINED3D_MULTISAMPLE_16_SAMPLES)
1880 FIXME("multisample_type %u not handled yet.\n", multisample_type);
1881 return WINED3DERR_NOTAVAILABLE;
1884 format = wined3d_get_format(adapter, surface_format_id, 0);
1886 if (multisample_type && !(format->multisample_types & 1u << (multisample_type - 1)))
1887 hr = WINED3DERR_NOTAVAILABLE;
1889 if (SUCCEEDED(hr) || (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE && format->multisample_types))
1891 if (quality_levels)
1893 if (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
1894 *quality_levels = wined3d_popcount(format->multisample_types);
1895 else
1896 *quality_levels = 1;
1898 return WINED3D_OK;
1901 TRACE("Returning not supported.\n");
1902 return hr;
1905 static BOOL wined3d_check_depth_stencil_format(const struct wined3d_adapter *adapter,
1906 const struct wined3d_format *adapter_format, const struct wined3d_format *ds_format,
1907 enum wined3d_gl_resource_type gl_type)
1909 if (!ds_format->depth_size && !ds_format->stencil_size)
1910 return FALSE;
1912 return adapter->adapter_ops->adapter_check_format(adapter, adapter_format, NULL, ds_format);
1915 static BOOL wined3d_check_surface_format(const struct wined3d_format *format)
1917 if ((format->caps[WINED3D_GL_RES_TYPE_TEX_2D] | format->caps[WINED3D_GL_RES_TYPE_RB])
1918 & WINED3D_FORMAT_CAP_BLIT)
1919 return TRUE;
1921 if ((format->attrs & WINED3D_FORMAT_ATTR_EXTENSION)
1922 && (format->caps[WINED3D_GL_RES_TYPE_TEX_2D] & WINED3D_FORMAT_CAP_TEXTURE))
1923 return TRUE;
1925 return FALSE;
1928 /* OpenGL supports mipmapping on all formats. Wrapping is unsupported, but we
1929 * have to report mipmapping so we cannot reject WRAPANDMIP. Tests show that
1930 * Windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to
1931 * show that wrapping is supported. The lack of filtering will sort out the
1932 * mipmapping capability anyway.
1934 * For now lets report this on all formats, but in the future we may want to
1935 * restrict it to some should applications need that. */
1936 HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d,
1937 const struct wined3d_adapter *adapter, enum wined3d_device_type device_type,
1938 enum wined3d_format_id adapter_format_id, uint32_t usage, unsigned int bind_flags,
1939 enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id)
1941 const struct wined3d_format *adapter_format, *format;
1942 enum wined3d_gl_resource_type gl_type, gl_type_end;
1943 unsigned int format_caps = 0, format_attrs = 0;
1944 BOOL mipmap_gen_supported = TRUE;
1945 unsigned int allowed_bind_flags;
1946 uint32_t allowed_usage;
1948 TRACE("wined3d %p, adapter %p, device_type %s, adapter_format %s, usage %s, "
1949 "bind_flags %s, resource_type %s, check_format %s.\n",
1950 wined3d, adapter, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
1951 debug_d3dusage(usage), wined3d_debug_bind_flags(bind_flags),
1952 debug_d3dresourcetype(resource_type), debug_d3dformat(check_format_id));
1954 adapter_format = wined3d_get_format(adapter, adapter_format_id, WINED3D_BIND_RENDER_TARGET);
1955 format = wined3d_get_format(adapter, check_format_id, bind_flags);
1957 switch (resource_type)
1959 case WINED3D_RTYPE_NONE:
1960 allowed_usage = 0;
1961 allowed_bind_flags = WINED3D_BIND_RENDER_TARGET
1962 | WINED3D_BIND_DEPTH_STENCIL
1963 | WINED3D_BIND_UNORDERED_ACCESS;
1964 gl_type = WINED3D_GL_RES_TYPE_TEX_2D;
1965 gl_type_end = WINED3D_GL_RES_TYPE_TEX_3D;
1966 break;
1968 case WINED3D_RTYPE_TEXTURE_1D:
1969 allowed_usage = WINED3DUSAGE_DYNAMIC
1970 | WINED3DUSAGE_SOFTWAREPROCESSING
1971 | WINED3DUSAGE_QUERY_FILTER
1972 | WINED3DUSAGE_QUERY_GENMIPMAP
1973 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
1974 | WINED3DUSAGE_QUERY_SRGBREAD
1975 | WINED3DUSAGE_QUERY_SRGBWRITE
1976 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
1977 | WINED3DUSAGE_QUERY_WRAPANDMIP;
1978 allowed_bind_flags = WINED3D_BIND_SHADER_RESOURCE
1979 | WINED3D_BIND_UNORDERED_ACCESS;
1980 gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_1D;
1981 break;
1983 case WINED3D_RTYPE_TEXTURE_2D:
1984 allowed_usage = WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
1985 if (bind_flags & WINED3D_BIND_RENDER_TARGET)
1986 allowed_usage |= WINED3DUSAGE_QUERY_SRGBWRITE;
1987 allowed_bind_flags = WINED3D_BIND_RENDER_TARGET
1988 | WINED3D_BIND_DEPTH_STENCIL
1989 | WINED3D_BIND_UNORDERED_ACCESS;
1990 gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_2D;
1991 if (!(bind_flags & WINED3D_BIND_SHADER_RESOURCE))
1993 if (!wined3d_check_surface_format(format))
1995 TRACE("%s is not supported for plain surfaces.\n", debug_d3dformat(format->id));
1996 return WINED3DERR_NOTAVAILABLE;
1998 break;
2000 allowed_usage |= WINED3DUSAGE_DYNAMIC
2001 | WINED3DUSAGE_LEGACY_CUBEMAP
2002 | WINED3DUSAGE_SOFTWAREPROCESSING
2003 | WINED3DUSAGE_QUERY_FILTER
2004 | WINED3DUSAGE_QUERY_GENMIPMAP
2005 | WINED3DUSAGE_QUERY_LEGACYBUMPMAP
2006 | WINED3DUSAGE_QUERY_SRGBREAD
2007 | WINED3DUSAGE_QUERY_SRGBWRITE
2008 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
2009 | WINED3DUSAGE_QUERY_WRAPANDMIP;
2010 allowed_bind_flags |= WINED3D_BIND_SHADER_RESOURCE;
2011 if (usage & WINED3DUSAGE_LEGACY_CUBEMAP)
2013 allowed_usage &= ~WINED3DUSAGE_QUERY_LEGACYBUMPMAP;
2014 allowed_bind_flags &= ~WINED3D_BIND_DEPTH_STENCIL;
2015 gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_CUBE;
2017 break;
2019 case WINED3D_RTYPE_TEXTURE_3D:
2020 allowed_usage = WINED3DUSAGE_DYNAMIC
2021 | WINED3DUSAGE_SOFTWAREPROCESSING
2022 | WINED3DUSAGE_QUERY_FILTER
2023 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
2024 | WINED3DUSAGE_QUERY_SRGBREAD
2025 | WINED3DUSAGE_QUERY_SRGBWRITE
2026 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
2027 | WINED3DUSAGE_QUERY_WRAPANDMIP;
2028 allowed_bind_flags = WINED3D_BIND_SHADER_RESOURCE
2029 | WINED3D_BIND_UNORDERED_ACCESS;
2030 gl_type = gl_type_end = WINED3D_GL_RES_TYPE_TEX_3D;
2031 break;
2033 case WINED3D_RTYPE_BUFFER:
2034 if (wined3d_format_is_typeless(format))
2036 TRACE("Requested WINED3D_RTYPE_BUFFER, but format %s is typeless.\n", debug_d3dformat(check_format_id));
2037 return WINED3DERR_NOTAVAILABLE;
2040 allowed_usage = WINED3DUSAGE_DYNAMIC;
2041 allowed_bind_flags = WINED3D_BIND_SHADER_RESOURCE
2042 | WINED3D_BIND_UNORDERED_ACCESS
2043 | WINED3D_BIND_VERTEX_BUFFER
2044 | WINED3D_BIND_INDEX_BUFFER;
2045 gl_type = gl_type_end = WINED3D_GL_RES_TYPE_BUFFER;
2046 break;
2048 default:
2049 FIXME("Unhandled resource type %s.\n", debug_d3dresourcetype(resource_type));
2050 return WINED3DERR_NOTAVAILABLE;
2053 if ((usage & allowed_usage) != usage)
2055 TRACE("Requested usage %#x, but resource type %s only allows %#x.\n",
2056 usage, debug_d3dresourcetype(resource_type), allowed_usage);
2057 return WINED3DERR_NOTAVAILABLE;
2060 if ((bind_flags & allowed_bind_flags) != bind_flags)
2062 TRACE("Requested bind flags %s, but resource type %s only allows %s.\n",
2063 wined3d_debug_bind_flags(bind_flags), debug_d3dresourcetype(resource_type),
2064 wined3d_debug_bind_flags(allowed_bind_flags));
2065 return WINED3DERR_NOTAVAILABLE;
2068 if (bind_flags & WINED3D_BIND_SHADER_RESOURCE)
2069 format_caps |= WINED3D_FORMAT_CAP_TEXTURE;
2070 if (bind_flags & WINED3D_BIND_RENDER_TARGET)
2071 format_caps |= WINED3D_FORMAT_CAP_RENDERTARGET;
2072 if (bind_flags & WINED3D_BIND_DEPTH_STENCIL)
2073 format_caps |= WINED3D_FORMAT_CAP_DEPTH_STENCIL;
2074 if (bind_flags & WINED3D_BIND_UNORDERED_ACCESS)
2075 format_caps |= WINED3D_FORMAT_CAP_UNORDERED_ACCESS;
2076 if (bind_flags & WINED3D_BIND_VERTEX_BUFFER)
2077 format_caps |= WINED3D_FORMAT_CAP_VERTEX_ATTRIBUTE;
2078 if (bind_flags & WINED3D_BIND_INDEX_BUFFER)
2079 format_caps |= WINED3D_FORMAT_CAP_INDEX_BUFFER;
2081 if (usage & WINED3DUSAGE_QUERY_FILTER)
2082 format_caps |= WINED3D_FORMAT_CAP_FILTERING;
2083 if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
2084 format_caps |= WINED3D_FORMAT_CAP_POSTPIXELSHADER_BLENDING;
2085 if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
2086 format_caps |= WINED3D_FORMAT_CAP_SRGB_READ;
2087 if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
2088 format_caps |= WINED3D_FORMAT_CAP_SRGB_WRITE;
2089 if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
2090 format_caps |= WINED3D_FORMAT_CAP_VTF;
2091 if (usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
2092 format_attrs |= WINED3D_FORMAT_ATTR_BUMPMAP;
2094 if ((format_caps & WINED3D_FORMAT_CAP_TEXTURE) && (wined3d->flags & WINED3D_NO3D))
2096 TRACE("Requested texturing support, but wined3d was created with WINED3D_NO3D.\n");
2097 return WINED3DERR_NOTAVAILABLE;
2100 if ((format->attrs & format_attrs) != format_attrs)
2102 TRACE("Requested format attributes %#x, but format %s only has %#x.\n",
2103 format_attrs, debug_d3dformat(check_format_id), format->attrs);
2104 return WINED3DERR_NOTAVAILABLE;
2107 for (; gl_type <= gl_type_end; ++gl_type)
2109 unsigned int caps = format->caps[gl_type];
2111 if (gl_type == WINED3D_GL_RES_TYPE_TEX_2D && !(bind_flags & WINED3D_BIND_SHADER_RESOURCE))
2112 caps |= format->caps[WINED3D_GL_RES_TYPE_RB];
2114 if ((bind_flags & WINED3D_BIND_RENDER_TARGET)
2115 && !adapter->adapter_ops->adapter_check_format(adapter, adapter_format, format, NULL))
2117 TRACE("Requested WINED3D_BIND_RENDER_TARGET, but format %s is not supported for render targets.\n",
2118 debug_d3dformat(check_format_id));
2119 return WINED3DERR_NOTAVAILABLE;
2122 /* 3D depth / stencil textures are never supported. */
2123 if (bind_flags == WINED3D_BIND_DEPTH_STENCIL && gl_type == WINED3D_GL_RES_TYPE_TEX_3D)
2124 continue;
2126 if ((bind_flags & WINED3D_BIND_DEPTH_STENCIL)
2127 && !wined3d_check_depth_stencil_format(adapter, adapter_format, format, gl_type))
2129 TRACE("Requested WINED3D_BIND_DEPTH_STENCIL, but format %s is not supported for depth/stencil buffers.\n",
2130 debug_d3dformat(check_format_id));
2131 return WINED3DERR_NOTAVAILABLE;
2134 if ((bind_flags & WINED3D_BIND_UNORDERED_ACCESS) && wined3d_format_is_typeless(format))
2136 TRACE("Requested WINED3D_BIND_UNORDERED_ACCESS, but format %s is typeless.\n",
2137 debug_d3dformat(check_format_id));
2138 return WINED3DERR_NOTAVAILABLE;
2141 if ((caps & format_caps) != format_caps)
2143 TRACE("Requested format caps %#x, but format %s only has %#x.\n",
2144 format_caps, debug_d3dformat(check_format_id), caps);
2145 return WINED3DERR_NOTAVAILABLE;
2148 if (!(caps & WINED3D_FORMAT_CAP_GEN_MIPMAP))
2149 mipmap_gen_supported = FALSE;
2152 if ((usage & WINED3DUSAGE_QUERY_GENMIPMAP) && !mipmap_gen_supported)
2154 TRACE("No WINED3DUSAGE_AUTOGENMIPMAP support, returning WINED3DOK_NOAUTOGEN.\n");
2155 return WINED3DOK_NOMIPGEN;
2158 return WINED3D_OK;
2161 unsigned int CDECL wined3d_calculate_format_pitch(const struct wined3d_adapter *adapter,
2162 enum wined3d_format_id format_id, unsigned int width)
2164 unsigned int row_pitch, slice_pitch;
2166 TRACE("adapter %p, format_id %s, width %u.\n", adapter, debug_d3dformat(format_id), width);
2168 wined3d_format_calculate_pitch(wined3d_get_format(adapter, format_id, 0),
2169 1, width, 1, &row_pitch, &slice_pitch);
2171 return row_pitch;
2174 HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d_output *output,
2175 enum wined3d_device_type device_type, enum wined3d_format_id src_format,
2176 enum wined3d_format_id dst_format)
2178 FIXME("output %p, device_type %s, src_format %s, dst_format %s stub!\n",
2179 output, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
2180 debug_d3dformat(dst_format));
2182 return WINED3D_OK;
2185 HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d,
2186 struct wined3d_output *output, enum wined3d_device_type device_type,
2187 enum wined3d_format_id display_format, enum wined3d_format_id backbuffer_format,
2188 BOOL windowed)
2190 BOOL present_conversion = wined3d->flags & WINED3D_PRESENT_CONVERSION;
2192 TRACE("wined3d %p, output %p, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
2193 wined3d, output, debug_d3ddevicetype(device_type), debug_d3dformat(display_format),
2194 debug_d3dformat(backbuffer_format), windowed);
2196 /* The task of this function is to check whether a certain display / backbuffer format
2197 * combination is available on the given output. In fullscreen mode microsoft specified
2198 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
2199 * and display format should match exactly.
2200 * In windowed mode format conversion can occur and this depends on the driver. */
2202 /* There are only 4 display formats. */
2203 if (!(display_format == WINED3DFMT_B5G6R5_UNORM
2204 || display_format == WINED3DFMT_B5G5R5X1_UNORM
2205 || display_format == WINED3DFMT_B8G8R8X8_UNORM
2206 || display_format == WINED3DFMT_B10G10R10A2_UNORM))
2208 TRACE("Format %s is not supported as display format.\n", debug_d3dformat(display_format));
2209 return WINED3DERR_NOTAVAILABLE;
2212 if (!windowed)
2214 /* If the requested display format is not available, don't continue. */
2215 if (!wined3d_output_get_mode_count(output, display_format,
2216 WINED3D_SCANLINE_ORDERING_UNKNOWN, false))
2218 TRACE("No available modes for display format %s.\n", debug_d3dformat(display_format));
2219 return WINED3DERR_NOTAVAILABLE;
2222 present_conversion = FALSE;
2224 else if (display_format == WINED3DFMT_B10G10R10A2_UNORM)
2226 /* WINED3DFMT_B10G10R10A2_UNORM is only allowed in fullscreen mode. */
2227 TRACE("Unsupported format combination %s / %s in windowed mode.\n",
2228 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
2229 return WINED3DERR_NOTAVAILABLE;
2232 if (present_conversion)
2234 /* Use the display format as back buffer format if the latter is
2235 * WINED3DFMT_UNKNOWN. */
2236 if (backbuffer_format == WINED3DFMT_UNKNOWN)
2237 backbuffer_format = display_format;
2239 if (FAILED(wined3d_check_device_format_conversion(output, device_type, backbuffer_format,
2240 display_format)))
2242 TRACE("Format conversion from %s to %s not supported.\n",
2243 debug_d3dformat(backbuffer_format), debug_d3dformat(display_format));
2244 return WINED3DERR_NOTAVAILABLE;
2247 else
2249 /* When format conversion from the back buffer format to the display
2250 * format is not allowed, only a limited number of combinations are
2251 * valid. */
2253 if (display_format == WINED3DFMT_B5G6R5_UNORM && backbuffer_format != WINED3DFMT_B5G6R5_UNORM)
2255 TRACE("Unsupported format combination %s / %s.\n",
2256 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
2257 return WINED3DERR_NOTAVAILABLE;
2260 if (display_format == WINED3DFMT_B5G5R5X1_UNORM
2261 && !(backbuffer_format == WINED3DFMT_B5G5R5X1_UNORM || backbuffer_format == WINED3DFMT_B5G5R5A1_UNORM))
2263 TRACE("Unsupported format combination %s / %s.\n",
2264 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
2265 return WINED3DERR_NOTAVAILABLE;
2268 if (display_format == WINED3DFMT_B8G8R8X8_UNORM
2269 && !(backbuffer_format == WINED3DFMT_B8G8R8X8_UNORM || backbuffer_format == WINED3DFMT_B8G8R8A8_UNORM))
2271 TRACE("Unsupported format combination %s / %s.\n",
2272 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
2273 return WINED3DERR_NOTAVAILABLE;
2276 if (display_format == WINED3DFMT_B10G10R10A2_UNORM
2277 && backbuffer_format != WINED3DFMT_B10G10R10A2_UNORM)
2279 TRACE("Unsupported format combination %s / %s.\n",
2280 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
2281 return WINED3DERR_NOTAVAILABLE;
2285 /* Validate that the back buffer format is usable for render targets. */
2286 if (FAILED(wined3d_check_device_format(wined3d, output->adapter, device_type,
2287 display_format, 0, WINED3D_BIND_RENDER_TARGET, WINED3D_RTYPE_TEXTURE_2D,
2288 backbuffer_format)))
2290 TRACE("Format %s not allowed for render targets.\n", debug_d3dformat(backbuffer_format));
2291 return WINED3DERR_NOTAVAILABLE;
2294 return WINED3D_OK;
2297 HRESULT CDECL wined3d_get_device_caps(const struct wined3d_adapter *adapter,
2298 enum wined3d_device_type device_type, struct wined3d_caps *caps)
2300 const struct wined3d_d3d_info *d3d_info;
2301 struct wined3d_vertex_caps vertex_caps;
2302 DWORD ckey_caps, blit_caps, fx_caps;
2303 struct fragment_caps fragment_caps;
2304 struct shader_caps shader_caps;
2306 TRACE("adapter %p, device_type %s, caps %p.\n",
2307 adapter, debug_d3ddevicetype(device_type), caps);
2309 d3d_info = &adapter->d3d_info;
2311 caps->DeviceType = (device_type == WINED3D_DEVICE_TYPE_HAL) ? WINED3D_DEVICE_TYPE_HAL : WINED3D_DEVICE_TYPE_REF;
2313 caps->Caps = 0;
2314 caps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
2315 WINED3DCAPS2_FULLSCREENGAMMA |
2316 WINED3DCAPS2_DYNAMICTEXTURES;
2318 caps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
2319 WINED3DCAPS3_COPY_TO_VIDMEM |
2320 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
2322 caps->CursorCaps = WINED3DCURSORCAPS_COLOR |
2323 WINED3DCURSORCAPS_LOWRES;
2325 caps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
2326 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
2327 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
2328 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
2329 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
2330 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
2331 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
2332 WINED3DDEVCAPS_PUREDEVICE |
2333 WINED3DDEVCAPS_HWRASTERIZATION |
2334 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
2335 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
2336 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
2337 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
2338 WINED3DDEVCAPS_DRAWPRIMITIVES2EX;
2340 caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
2341 WINED3DPMISCCAPS_CULLCCW |
2342 WINED3DPMISCCAPS_CULLCW |
2343 WINED3DPMISCCAPS_COLORWRITEENABLE |
2344 WINED3DPMISCCAPS_CLIPTLVERTS |
2345 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
2346 WINED3DPMISCCAPS_MASKZ |
2347 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
2348 /* TODO:
2349 WINED3DPMISCCAPS_NULLREFERENCE
2350 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
2351 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
2353 caps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
2354 WINED3DPRASTERCAPS_PAT |
2355 WINED3DPRASTERCAPS_WFOG |
2356 WINED3DPRASTERCAPS_ZFOG |
2357 WINED3DPRASTERCAPS_FOGVERTEX |
2358 WINED3DPRASTERCAPS_FOGTABLE |
2359 WINED3DPRASTERCAPS_STIPPLE |
2360 WINED3DPRASTERCAPS_SUBPIXEL |
2361 WINED3DPRASTERCAPS_ZTEST |
2362 WINED3DPRASTERCAPS_SCISSORTEST |
2363 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
2364 WINED3DPRASTERCAPS_DEPTHBIAS;
2366 caps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2367 WINED3DPCMPCAPS_EQUAL |
2368 WINED3DPCMPCAPS_GREATER |
2369 WINED3DPCMPCAPS_GREATEREQUAL |
2370 WINED3DPCMPCAPS_LESS |
2371 WINED3DPCMPCAPS_LESSEQUAL |
2372 WINED3DPCMPCAPS_NEVER |
2373 WINED3DPCMPCAPS_NOTEQUAL;
2375 /* WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA
2376 * are legacy settings for srcblend only. */
2377 caps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
2378 WINED3DPBLENDCAPS_BOTHSRCALPHA |
2379 WINED3DPBLENDCAPS_DESTALPHA |
2380 WINED3DPBLENDCAPS_DESTCOLOR |
2381 WINED3DPBLENDCAPS_INVDESTALPHA |
2382 WINED3DPBLENDCAPS_INVDESTCOLOR |
2383 WINED3DPBLENDCAPS_INVSRCALPHA |
2384 WINED3DPBLENDCAPS_INVSRCCOLOR |
2385 WINED3DPBLENDCAPS_ONE |
2386 WINED3DPBLENDCAPS_SRCALPHA |
2387 WINED3DPBLENDCAPS_SRCALPHASAT |
2388 WINED3DPBLENDCAPS_SRCCOLOR |
2389 WINED3DPBLENDCAPS_ZERO;
2391 caps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
2392 WINED3DPBLENDCAPS_DESTCOLOR |
2393 WINED3DPBLENDCAPS_INVDESTALPHA |
2394 WINED3DPBLENDCAPS_INVDESTCOLOR |
2395 WINED3DPBLENDCAPS_INVSRCALPHA |
2396 WINED3DPBLENDCAPS_INVSRCCOLOR |
2397 WINED3DPBLENDCAPS_ONE |
2398 WINED3DPBLENDCAPS_SRCALPHA |
2399 WINED3DPBLENDCAPS_SRCCOLOR |
2400 WINED3DPBLENDCAPS_ZERO;
2402 caps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
2403 WINED3DPCMPCAPS_EQUAL |
2404 WINED3DPCMPCAPS_GREATER |
2405 WINED3DPCMPCAPS_GREATEREQUAL |
2406 WINED3DPCMPCAPS_LESS |
2407 WINED3DPCMPCAPS_LESSEQUAL |
2408 WINED3DPCMPCAPS_NEVER |
2409 WINED3DPCMPCAPS_NOTEQUAL;
2411 caps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
2412 WINED3DPSHADECAPS_COLORGOURAUDRGB |
2413 WINED3DPSHADECAPS_ALPHAFLATBLEND |
2414 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
2415 WINED3DPSHADECAPS_COLORFLATRGB |
2416 WINED3DPSHADECAPS_FOGFLAT |
2417 WINED3DPSHADECAPS_FOGGOURAUD |
2418 WINED3DPSHADECAPS_SPECULARFLATRGB;
2420 caps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
2421 WINED3DPTEXTURECAPS_ALPHAPALETTE |
2422 WINED3DPTEXTURECAPS_TRANSPARENCY |
2423 WINED3DPTEXTURECAPS_BORDER |
2424 WINED3DPTEXTURECAPS_MIPMAP |
2425 WINED3DPTEXTURECAPS_PROJECTED |
2426 WINED3DPTEXTURECAPS_PERSPECTIVE;
2428 if (!d3d_info->texture_npot)
2430 caps->TextureCaps |= WINED3DPTEXTURECAPS_POW2;
2431 if (d3d_info->texture_npot_conditional)
2432 caps->TextureCaps |= WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
2435 caps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
2436 WINED3DPTFILTERCAPS_MAGFPOINT |
2437 WINED3DPTFILTERCAPS_MINFLINEAR |
2438 WINED3DPTFILTERCAPS_MINFPOINT |
2439 WINED3DPTFILTERCAPS_MIPFLINEAR |
2440 WINED3DPTFILTERCAPS_MIPFPOINT |
2441 WINED3DPTFILTERCAPS_LINEAR |
2442 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
2443 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
2444 WINED3DPTFILTERCAPS_MIPLINEAR |
2445 WINED3DPTFILTERCAPS_MIPNEAREST |
2446 WINED3DPTFILTERCAPS_NEAREST;
2448 caps->CubeTextureFilterCaps = 0;
2449 caps->VolumeTextureFilterCaps = 0;
2451 caps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
2452 WINED3DPTADDRESSCAPS_CLAMP |
2453 WINED3DPTADDRESSCAPS_WRAP;
2455 caps->VolumeTextureAddressCaps = 0;
2457 caps->LineCaps = WINED3DLINECAPS_TEXTURE |
2458 WINED3DLINECAPS_ZTEST |
2459 WINED3DLINECAPS_BLEND |
2460 WINED3DLINECAPS_ALPHACMP |
2461 WINED3DLINECAPS_FOG;
2462 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
2463 * idea how generating the smoothing alpha values works; the result is different
2466 caps->MaxTextureWidth = d3d_info->limits.texture_size;
2467 caps->MaxTextureHeight = d3d_info->limits.texture_size;
2469 caps->MaxVolumeExtent = 0;
2471 caps->MaxTextureRepeat = 32768;
2472 caps->MaxTextureAspectRatio = d3d_info->limits.texture_size;
2473 caps->MaxVertexW = 1e10f;
2475 caps->GuardBandLeft = -32768.0f;
2476 caps->GuardBandTop = -32768.0f;
2477 caps->GuardBandRight = 32768.0f;
2478 caps->GuardBandBottom = 32768.0f;
2480 caps->ExtentsAdjust = 0.0f;
2482 caps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
2483 WINED3DSTENCILCAPS_INCRSAT |
2484 WINED3DSTENCILCAPS_INVERT |
2485 WINED3DSTENCILCAPS_KEEP |
2486 WINED3DSTENCILCAPS_REPLACE |
2487 WINED3DSTENCILCAPS_ZERO;
2489 caps->MaxAnisotropy = 0;
2490 caps->MaxPointSize = d3d_info->limits.pointsize_max;
2492 caps->MaxPrimitiveCount = 0x555555; /* Taken from an AMD Radeon HD 5700 (Evergreen) GPU. */
2493 caps->MaxVertexIndex = 0xffffff; /* Taken from an AMD Radeon HD 5700 (Evergreen) GPU. */
2494 caps->MaxStreams = WINED3D_MAX_STREAMS;
2495 caps->MaxStreamStride = 1024;
2497 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
2498 caps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
2499 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
2500 caps->MaxNpatchTessellationLevel = 0;
2502 caps->NumSimultaneousRTs = d3d_info->limits.max_rt_count;
2504 caps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
2505 WINED3DPTFILTERCAPS_MAGFPOINT |
2506 WINED3DPTFILTERCAPS_MINFLINEAR |
2507 WINED3DPTFILTERCAPS_MAGFLINEAR;
2508 caps->VertexTextureFilterCaps = 0;
2510 adapter->shader_backend->shader_get_caps(adapter, &shader_caps);
2511 adapter->fragment_pipe->get_caps(adapter, &fragment_caps);
2512 adapter->vertex_pipe->vp_get_caps(adapter, &vertex_caps);
2514 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
2515 caps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
2517 caps->VertexShaderVersion = shader_caps.vs_version;
2518 caps->MaxVertexShaderConst = shader_caps.vs_uniform_count;
2520 caps->PixelShaderVersion = shader_caps.ps_version;
2521 caps->PixelShader1xMaxValue = shader_caps.ps_1x_max_value;
2523 caps->TextureOpCaps = fragment_caps.TextureOpCaps;
2524 caps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
2525 caps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
2527 caps->MaxUserClipPlanes = vertex_caps.max_user_clip_planes;
2528 caps->MaxActiveLights = vertex_caps.max_active_lights;
2529 caps->MaxVertexBlendMatrices = vertex_caps.max_vertex_blend_matrices;
2530 caps->MaxVertexBlendMatrixIndex = vertex_caps.max_vertex_blend_matrix_index;
2531 caps->VertexProcessingCaps = vertex_caps.vertex_processing_caps;
2532 caps->FVFCaps = vertex_caps.fvf_caps;
2533 caps->RasterCaps |= vertex_caps.raster_caps;
2535 /* The following caps are shader specific, but they are things we cannot detect, or which
2536 * are the same among all shader models. So to avoid code duplication set the shader version
2537 * specific, but otherwise constant caps here
2539 if (caps->VertexShaderVersion >= 3)
2541 /* Where possible set the caps based on OpenGL extensions and if they
2542 * aren't set (in case of software rendering) use the VS 3.0 from
2543 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
2544 * VS3.0 value. */
2545 caps->VS20Caps.caps = WINED3DVS20CAPS_PREDICATION;
2546 /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
2547 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH;
2548 caps->VS20Caps.temp_count = 32;
2549 /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
2550 caps->VS20Caps.static_flow_control_depth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH;
2552 caps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
2553 caps->MaxVertexShader30InstructionSlots = WINED3DMIN30SHADERINSTRUCTIONS;
2554 caps->VertexTextureFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT | WINED3DPTFILTERCAPS_MAGFPOINT;
2556 else if (caps->VertexShaderVersion == 2)
2558 caps->VS20Caps.caps = 0;
2559 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
2560 caps->VS20Caps.temp_count = WINED3DVS20_MIN_NUMTEMPS;
2561 caps->VS20Caps.static_flow_control_depth = 1;
2563 caps->MaxVShaderInstructionsExecuted = 65535;
2564 caps->MaxVertexShader30InstructionSlots = 0;
2566 else /* VS 1.x */
2568 caps->VS20Caps.caps = 0;
2569 caps->VS20Caps.dynamic_flow_control_depth = 0;
2570 caps->VS20Caps.temp_count = 0;
2571 caps->VS20Caps.static_flow_control_depth = 0;
2573 caps->MaxVShaderInstructionsExecuted = 0;
2574 caps->MaxVertexShader30InstructionSlots = 0;
2577 if (caps->PixelShaderVersion >= 3)
2579 /* Where possible set the caps based on OpenGL extensions and if they
2580 * aren't set (in case of software rendering) use the PS 3.0 from
2581 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
2582 * PS 3.0 value. */
2584 /* Caps is more or less undocumented on MSDN but it appears to be
2585 * used for PS20Caps based on results from R9600/FX5900/Geforce6800
2586 * cards from Windows */
2587 caps->PS20Caps.caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
2588 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
2589 WINED3DPS20CAPS_PREDICATION |
2590 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
2591 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
2592 /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
2593 caps->PS20Caps.dynamic_flow_control_depth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH;
2594 caps->PS20Caps.temp_count = 32;
2595 /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
2596 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH;
2597 /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
2598 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS;
2600 caps->MaxPShaderInstructionsExecuted = 65535;
2601 caps->MaxPixelShader30InstructionSlots = WINED3DMIN30SHADERINSTRUCTIONS;
2603 else if (caps->PixelShaderVersion == 2)
2605 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
2606 caps->PS20Caps.caps = 0;
2607 caps->PS20Caps.dynamic_flow_control_depth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
2608 caps->PS20Caps.temp_count = WINED3DPS20_MIN_NUMTEMPS;
2609 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
2610 /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
2611 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS;
2613 caps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
2614 caps->MaxPixelShader30InstructionSlots = 0;
2616 else /* PS 1.x */
2618 caps->PS20Caps.caps = 0;
2619 caps->PS20Caps.dynamic_flow_control_depth = 0;
2620 caps->PS20Caps.temp_count = 0;
2621 caps->PS20Caps.static_flow_control_depth = 0;
2622 caps->PS20Caps.instruction_slot_count = 0;
2624 caps->MaxPShaderInstructionsExecuted = 0;
2625 caps->MaxPixelShader30InstructionSlots = 0;
2628 if (caps->VertexShaderVersion >= 2)
2630 /* OpenGL supports all the formats below, perhaps not always
2631 * without conversion, but it supports them.
2632 * Further GLSL doesn't seem to have an official unsigned type so
2633 * don't advertise it yet as I'm not sure how we handle it.
2634 * We might need to add some clamping in the shader engine to
2635 * support it.
2636 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
2637 caps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
2638 WINED3DDTCAPS_UBYTE4N |
2639 WINED3DDTCAPS_SHORT2N |
2640 WINED3DDTCAPS_SHORT4N;
2642 else
2644 caps->DeclTypes = 0;
2647 /* Set DirectDraw helper Caps */
2648 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
2649 WINEDDCKEYCAPS_SRCBLT;
2650 fx_caps = WINEDDFXCAPS_BLTALPHA |
2651 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
2652 WINEDDFXCAPS_BLTMIRRORUPDOWN |
2653 WINEDDFXCAPS_BLTROTATION90 |
2654 WINEDDFXCAPS_BLTSHRINKX |
2655 WINEDDFXCAPS_BLTSHRINKXN |
2656 WINEDDFXCAPS_BLTSHRINKY |
2657 WINEDDFXCAPS_BLTSHRINKYN |
2658 WINEDDFXCAPS_BLTSTRETCHX |
2659 WINEDDFXCAPS_BLTSTRETCHXN |
2660 WINEDDFXCAPS_BLTSTRETCHY |
2661 WINEDDFXCAPS_BLTSTRETCHYN;
2662 blit_caps = WINEDDCAPS_BLT |
2663 WINEDDCAPS_BLTCOLORFILL |
2664 WINEDDCAPS_BLTDEPTHFILL |
2665 WINEDDCAPS_BLTSTRETCH |
2666 WINEDDCAPS_CANBLTSYSMEM |
2667 WINEDDCAPS_CANCLIP |
2668 WINEDDCAPS_CANCLIPSTRETCHED |
2669 WINEDDCAPS_COLORKEY |
2670 WINEDDCAPS_COLORKEYHWASSIST;
2672 /* Fill the ddraw caps structure */
2673 caps->ddraw_caps.caps = WINEDDCAPS_GDI |
2674 WINEDDCAPS_PALETTE |
2675 blit_caps;
2676 caps->ddraw_caps.caps2 = WINEDDCAPS2_CERTIFIED |
2677 WINEDDCAPS2_NOPAGELOCKREQUIRED |
2678 WINEDDCAPS2_PRIMARYGAMMA |
2679 WINEDDCAPS2_WIDESURFACES |
2680 WINEDDCAPS2_CANRENDERWINDOWED;
2681 caps->ddraw_caps.color_key_caps = ckey_caps;
2682 caps->ddraw_caps.fx_caps = fx_caps;
2683 caps->ddraw_caps.svb_caps = blit_caps;
2684 caps->ddraw_caps.svb_color_key_caps = ckey_caps;
2685 caps->ddraw_caps.svb_fx_caps = fx_caps;
2686 caps->ddraw_caps.vsb_caps = blit_caps;
2687 caps->ddraw_caps.vsb_color_key_caps = ckey_caps;
2688 caps->ddraw_caps.vsb_fx_caps = fx_caps;
2689 caps->ddraw_caps.ssb_caps = blit_caps;
2690 caps->ddraw_caps.ssb_color_key_caps = ckey_caps;
2691 caps->ddraw_caps.ssb_fx_caps = fx_caps;
2693 caps->ddraw_caps.dds_caps = WINEDDSCAPS_FLIP
2694 | WINEDDSCAPS_OFFSCREENPLAIN
2695 | WINEDDSCAPS_PALETTE
2696 | WINEDDSCAPS_PRIMARYSURFACE
2697 | WINEDDSCAPS_TEXTURE
2698 | WINEDDSCAPS_ZBUFFER
2699 | WINEDDSCAPS_MIPMAP;
2701 caps->shader_double_precision = d3d_info->shader_double_precision;
2702 caps->viewport_array_index_any_shader = d3d_info->viewport_array_index_any_shader;
2704 caps->max_feature_level = d3d_info->feature_level;
2706 adapter->adapter_ops->adapter_get_wined3d_caps(adapter, caps);
2708 return WINED3D_OK;
2711 HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, struct wined3d_adapter *adapter,
2712 enum wined3d_device_type device_type, HWND focus_window, uint32_t flags, BYTE surface_alignment,
2713 const enum wined3d_feature_level *feature_levels, unsigned int feature_level_count,
2714 struct wined3d_device_parent *device_parent, struct wined3d_device **device)
2716 struct wined3d_device *object;
2717 HRESULT hr;
2719 TRACE("wined3d %p, adapter %p, device_type %#x, focus_window %p, flags %#x, "
2720 "surface_alignment %u, feature_levels %p, feature_level_count %u, device_parent %p, device %p.\n",
2721 wined3d, adapter, device_type, focus_window, flags, surface_alignment,
2722 feature_levels, feature_level_count, device_parent, device);
2724 if (FAILED(hr = adapter->adapter_ops->adapter_create_device(wined3d, adapter,
2725 device_type, focus_window, flags, surface_alignment,
2726 feature_levels, feature_level_count, device_parent, &object)))
2727 return hr;
2729 TRACE("Created device %p.\n", object);
2730 *device = object;
2732 device_parent->ops->wined3d_device_created(device_parent, *device);
2734 return WINED3D_OK;
2737 static const struct wined3d_state_entry_template misc_state_template_no3d[] =
2739 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_VERTEX), {STATE_VDECL}},
2740 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_HULL), {STATE_VDECL}},
2741 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_DOMAIN), {STATE_VDECL}},
2742 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_GEOMETRY), {STATE_VDECL}},
2743 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_PIXEL), {STATE_VDECL}},
2744 {STATE_CONSTANT_BUFFER(WINED3D_SHADER_TYPE_COMPUTE), {STATE_VDECL}},
2745 {STATE_GRAPHICS_SHADER_RESOURCE_BINDING, {STATE_VDECL}},
2746 {STATE_GRAPHICS_UNORDERED_ACCESS_VIEW_BINDING, {STATE_VDECL}},
2747 {STATE_COMPUTE_SHADER_RESOURCE_BINDING, {STATE_VDECL}},
2748 {STATE_COMPUTE_UNORDERED_ACCESS_VIEW_BINDING, {STATE_VDECL}},
2749 {STATE_STREAM_OUTPUT, {STATE_VDECL}},
2750 {STATE_BLEND, {STATE_VDECL}},
2751 {STATE_BLEND_FACTOR, {STATE_VDECL}},
2752 {STATE_SAMPLE_MASK, {STATE_VDECL}},
2753 {STATE_DEPTH_STENCIL, {STATE_VDECL}},
2754 {STATE_STENCIL_REF, {STATE_VDECL}},
2755 {STATE_DEPTH_BOUNDS, {STATE_VDECL}},
2756 {STATE_STREAMSRC, {STATE_VDECL}},
2757 {STATE_VDECL, {STATE_VDECL, state_nop}},
2758 {STATE_RASTERIZER, {STATE_VDECL}},
2759 {STATE_SCISSORRECT, {STATE_VDECL}},
2760 {STATE_POINTSPRITECOORDORIGIN, {STATE_VDECL}},
2762 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2763 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2764 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2765 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2766 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2767 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2768 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2769 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2770 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2771 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2772 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2773 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2774 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2775 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2776 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2777 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2778 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2779 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2780 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2781 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2782 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2783 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2784 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2785 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2786 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2787 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2788 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2789 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2790 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT00), {STATE_VDECL}},
2791 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT01), {STATE_VDECL}},
2792 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT10), {STATE_VDECL}},
2793 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_MAT11), {STATE_VDECL}},
2794 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2795 {STATE_TEXTURESTAGE(0, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2796 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2797 {STATE_TEXTURESTAGE(1, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2798 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2799 {STATE_TEXTURESTAGE(2, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2800 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2801 {STATE_TEXTURESTAGE(3, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2802 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2803 {STATE_TEXTURESTAGE(4, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2804 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2805 {STATE_TEXTURESTAGE(5, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2806 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2807 {STATE_TEXTURESTAGE(6, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2808 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LSCALE), {STATE_VDECL}},
2809 {STATE_TEXTURESTAGE(7, WINED3D_TSS_BUMPENV_LOFFSET), {STATE_VDECL}},
2811 {STATE_VIEWPORT, {STATE_VDECL}},
2812 {STATE_INDEXBUFFER, {STATE_VDECL}},
2813 {STATE_RENDER(WINED3D_RS_LINEPATTERN), {STATE_VDECL}},
2814 {STATE_RENDER(WINED3D_RS_ZFUNC), {STATE_VDECL}},
2815 {STATE_RENDER(WINED3D_RS_DITHERENABLE), {STATE_VDECL}},
2816 {STATE_RENDER(WINED3D_RS_MULTISAMPLEANTIALIAS), {STATE_VDECL}},
2817 /* Samplers */
2818 {STATE_SAMPLER(0), {STATE_VDECL}},
2819 {STATE_SAMPLER(1), {STATE_VDECL}},
2820 {STATE_SAMPLER(2), {STATE_VDECL}},
2821 {STATE_SAMPLER(3), {STATE_VDECL}},
2822 {STATE_SAMPLER(4), {STATE_VDECL}},
2823 {STATE_SAMPLER(5), {STATE_VDECL}},
2824 {STATE_SAMPLER(6), {STATE_VDECL}},
2825 {STATE_SAMPLER(7), {STATE_VDECL}},
2826 {STATE_SAMPLER(8), {STATE_VDECL}},
2827 {STATE_SAMPLER(9), {STATE_VDECL}},
2828 {STATE_SAMPLER(10), {STATE_VDECL}},
2829 {STATE_SAMPLER(11), {STATE_VDECL}},
2830 {STATE_SAMPLER(12), {STATE_VDECL}},
2831 {STATE_SAMPLER(13), {STATE_VDECL}},
2832 {STATE_SAMPLER(14), {STATE_VDECL}},
2833 {STATE_SAMPLER(15), {STATE_VDECL}},
2834 {STATE_SAMPLER(16), /* Vertex sampler 0 */ {STATE_VDECL}},
2835 {STATE_SAMPLER(17), /* Vertex sampler 1 */ {STATE_VDECL}},
2836 {STATE_SAMPLER(18), /* Vertex sampler 2 */ {STATE_VDECL}},
2837 {STATE_SAMPLER(19), /* Vertex sampler 3 */ {STATE_VDECL}},
2838 {STATE_BASEVERTEXINDEX, {STATE_VDECL}},
2839 {STATE_FRAMEBUFFER, {STATE_VDECL}},
2840 {STATE_SHADER(WINED3D_SHADER_TYPE_PIXEL), {STATE_VDECL}},
2841 {STATE_SHADER(WINED3D_SHADER_TYPE_HULL), {STATE_VDECL}},
2842 {STATE_SHADER(WINED3D_SHADER_TYPE_DOMAIN), {STATE_VDECL}},
2843 {STATE_SHADER(WINED3D_SHADER_TYPE_GEOMETRY), {STATE_VDECL}},
2844 {STATE_SHADER(WINED3D_SHADER_TYPE_COMPUTE), {STATE_VDECL}},
2845 {0}, /* Terminate */
2848 static void adapter_no3d_destroy(struct wined3d_adapter *adapter)
2850 wined3d_adapter_cleanup(adapter);
2851 heap_free(adapter);
2854 static HRESULT adapter_no3d_create_device(struct wined3d *wined3d, const struct wined3d_adapter *adapter,
2855 enum wined3d_device_type device_type, HWND focus_window, unsigned int flags, BYTE surface_alignment,
2856 const enum wined3d_feature_level *levels, unsigned int level_count,
2857 struct wined3d_device_parent *device_parent, struct wined3d_device **device)
2859 /* No extensions in the state table, only extension 0, which is implicitly supported. */
2860 static const BOOL supported_extensions[] = {TRUE};
2861 struct wined3d_device_no3d *device_no3d;
2862 HRESULT hr;
2864 if (!(device_no3d = heap_alloc_zero(sizeof(*device_no3d))))
2865 return E_OUTOFMEMORY;
2867 if (FAILED(hr = wined3d_device_init(&device_no3d->d, wined3d, adapter->ordinal, device_type, focus_window,
2868 flags, surface_alignment, levels, level_count, supported_extensions, device_parent)))
2870 WARN("Failed to initialize device, hr %#lx.\n", hr);
2871 heap_free(device_no3d);
2872 return hr;
2875 *device = &device_no3d->d;
2877 return WINED3D_OK;
2880 static void adapter_no3d_destroy_device(struct wined3d_device *device)
2882 wined3d_device_cleanup(device);
2883 heap_free(device);
2886 static struct wined3d_context *adapter_no3d_acquire_context(struct wined3d_device *device,
2887 struct wined3d_texture *texture, unsigned int sub_resource_idx)
2889 TRACE("device %p, texture %p, sub_resource_idx %u.\n", device, texture, sub_resource_idx);
2891 wined3d_from_cs(device->cs);
2893 if (!device->context_count)
2894 return NULL;
2896 return &wined3d_device_no3d(device)->context_no3d;
2899 static void adapter_no3d_release_context(struct wined3d_context *context)
2901 TRACE("context %p.\n", context);
2904 static void adapter_no3d_get_wined3d_caps(const struct wined3d_adapter *adapter, struct wined3d_caps *caps)
2908 static BOOL adapter_no3d_check_format(const struct wined3d_adapter *adapter,
2909 const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
2910 const struct wined3d_format *ds_format)
2912 return TRUE;
2915 static HRESULT adapter_no3d_init_3d(struct wined3d_device *device)
2917 struct wined3d_context *context_no3d;
2918 HRESULT hr;
2920 TRACE("device %p.\n", device);
2922 context_no3d = &wined3d_device_no3d(device)->context_no3d;
2923 if (FAILED(hr = wined3d_context_no3d_init(context_no3d, device->swapchains[0])))
2925 WARN("Failed to initialise context.\n");
2926 return hr;
2929 if (!device_context_add(device, context_no3d))
2931 ERR("Failed to add the newly created context to the context list.\n");
2932 wined3d_context_cleanup(context_no3d);
2933 return E_FAIL;
2936 TRACE("Initialised context %p.\n", context_no3d);
2938 if (!(device->blitter = wined3d_cpu_blitter_create()))
2940 ERR("Failed to create CPU blitter.\n");
2941 device_context_remove(device, context_no3d);
2942 wined3d_context_cleanup(context_no3d);
2943 return E_FAIL;
2946 return WINED3D_OK;
2949 static void adapter_no3d_uninit_3d(struct wined3d_device *device)
2951 struct wined3d_context *context_no3d;
2953 TRACE("device %p.\n", device);
2955 context_no3d = &wined3d_device_no3d(device)->context_no3d;
2956 device->blitter->ops->blitter_destroy(device->blitter, NULL);
2957 wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
2959 device_context_remove(device, context_no3d);
2960 wined3d_context_cleanup(context_no3d);
2963 static void *adapter_no3d_map_bo_address(struct wined3d_context *context,
2964 const struct wined3d_bo_address *data, size_t size, uint32_t map_flags)
2966 if (data->buffer_object)
2968 ERR("Unsupported buffer object %p.\n", data->buffer_object);
2969 return NULL;
2972 return data->addr;
2975 static void adapter_no3d_unmap_bo_address(struct wined3d_context *context,
2976 const struct wined3d_bo_address *data, unsigned int range_count, const struct wined3d_range *ranges)
2978 if (data->buffer_object)
2979 ERR("Unsupported buffer object %p.\n", data->buffer_object);
2982 static void adapter_no3d_copy_bo_address(struct wined3d_context *context,
2983 const struct wined3d_bo_address *dst, const struct wined3d_bo_address *src,
2984 unsigned int range_count, const struct wined3d_range *ranges, uint32_t map_flags)
2986 unsigned int i;
2988 if (dst->buffer_object)
2989 ERR("Unsupported dst buffer object %p.\n", dst->buffer_object);
2990 if (src->buffer_object)
2991 ERR("Unsupported src buffer object %p.\n", src->buffer_object);
2992 if (dst->buffer_object || src->buffer_object)
2993 return;
2995 for (i = 0; i < range_count; ++i)
2996 memcpy(dst->addr + ranges[i].offset, src->addr + ranges[i].offset, ranges[i].size);
2999 static void adapter_no3d_flush_bo_address(struct wined3d_context *context,
3000 const struct wined3d_const_bo_address *data, size_t size)
3004 static bool adapter_no3d_alloc_bo(struct wined3d_device *device, struct wined3d_resource *resource,
3005 unsigned int sub_resource_idx, struct wined3d_bo_address *addr)
3007 return false;
3010 static void adapter_no3d_destroy_bo(struct wined3d_context *context, struct wined3d_bo *bo)
3014 static HRESULT adapter_no3d_create_swapchain(struct wined3d_device *device,
3015 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain_state_parent *state_parent,
3016 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_swapchain **swapchain)
3018 struct wined3d_swapchain *swapchain_no3d;
3019 HRESULT hr;
3021 TRACE("device %p, desc %p, state_parent %p, parent %p, parent_ops %p, swapchain %p.\n",
3022 device, desc, state_parent, parent, parent_ops, swapchain);
3024 if (!(swapchain_no3d = heap_alloc_zero(sizeof(*swapchain_no3d))))
3025 return E_OUTOFMEMORY;
3027 if (FAILED(hr = wined3d_swapchain_no3d_init(swapchain_no3d, device, desc, state_parent, parent,
3028 parent_ops)))
3030 WARN("Failed to initialise swapchain, hr %#lx.\n", hr);
3031 heap_free(swapchain_no3d);
3032 return hr;
3035 TRACE("Created swapchain %p.\n", swapchain_no3d);
3036 *swapchain = swapchain_no3d;
3038 return hr;
3041 static void adapter_no3d_destroy_swapchain(struct wined3d_swapchain *swapchain)
3043 wined3d_swapchain_cleanup(swapchain);
3044 heap_free(swapchain);
3047 static HRESULT adapter_no3d_create_buffer(struct wined3d_device *device,
3048 const struct wined3d_buffer_desc *desc, const struct wined3d_sub_resource_data *data,
3049 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_buffer **buffer)
3051 struct wined3d_buffer *buffer_no3d;
3052 HRESULT hr;
3054 TRACE("device %p, desc %p, data %p, parent %p, parent_ops %p, buffer %p.\n",
3055 device, desc, data, parent, parent_ops, buffer);
3057 if (!(buffer_no3d = heap_alloc_zero(sizeof(*buffer_no3d))))
3058 return E_OUTOFMEMORY;
3060 if (FAILED(hr = wined3d_buffer_no3d_init(buffer_no3d, device, desc, data, parent, parent_ops)))
3062 WARN("Failed to initialise buffer, hr %#lx.\n", hr);
3063 heap_free(buffer_no3d);
3064 return hr;
3067 TRACE("Created buffer %p.\n", buffer_no3d);
3068 *buffer = buffer_no3d;
3070 return hr;
3073 static void adapter_no3d_destroy_buffer(struct wined3d_buffer *buffer)
3075 struct wined3d_device *device = buffer->resource.device;
3076 unsigned int swapchain_count = device->swapchain_count;
3078 TRACE("buffer %p.\n", buffer);
3080 /* Take a reference to the device, in case releasing the buffer would
3081 * cause the device to be destroyed. However, swapchain resources don't
3082 * take a reference to the device, and we wouldn't want to increment the
3083 * refcount on a device that's in the process of being destroyed. */
3084 if (swapchain_count)
3085 wined3d_device_incref(device);
3086 wined3d_buffer_cleanup(buffer);
3087 wined3d_cs_destroy_object(device->cs, heap_free, buffer);
3088 if (swapchain_count)
3089 wined3d_device_decref(device);
3092 static HRESULT adapter_no3d_create_texture(struct wined3d_device *device,
3093 const struct wined3d_resource_desc *desc, unsigned int layer_count, unsigned int level_count,
3094 uint32_t flags, void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_texture **texture)
3096 struct wined3d_texture *texture_no3d;
3097 HRESULT hr;
3099 TRACE("device %p, desc %p, layer_count %u, level_count %u, flags %#x, parent %p, parent_ops %p, texture %p.\n",
3100 device, desc, layer_count, level_count, flags, parent, parent_ops, texture);
3102 if (!(texture_no3d = wined3d_texture_allocate_object_memory(sizeof(*texture_no3d), level_count, layer_count)))
3103 return E_OUTOFMEMORY;
3105 if (FAILED(hr = wined3d_texture_no3d_init(texture_no3d, device, desc,
3106 layer_count, level_count, flags, parent, parent_ops)))
3108 WARN("Failed to initialise texture, hr %#lx.\n", hr);
3109 heap_free(texture_no3d);
3110 return hr;
3113 TRACE("Created texture %p.\n", texture_no3d);
3114 *texture = texture_no3d;
3116 return hr;
3119 static void adapter_no3d_destroy_texture(struct wined3d_texture *texture)
3121 struct wined3d_device *device = texture->resource.device;
3122 unsigned int swapchain_count = device->swapchain_count;
3124 TRACE("texture %p.\n", texture);
3126 /* Take a reference to the device, in case releasing the texture would
3127 * cause the device to be destroyed. However, swapchain resources don't
3128 * take a reference to the device, and we wouldn't want to increment the
3129 * refcount on a device that's in the process of being destroyed. */
3130 if (swapchain_count)
3131 wined3d_device_incref(device);
3133 wined3d_texture_sub_resources_destroyed(texture);
3134 texture->resource.parent_ops->wined3d_object_destroyed(texture->resource.parent);
3136 wined3d_texture_cleanup(texture);
3137 wined3d_cs_destroy_object(device->cs, heap_free, texture);
3139 if (swapchain_count)
3140 wined3d_device_decref(device);
3143 static HRESULT adapter_no3d_create_rendertarget_view(const struct wined3d_view_desc *desc,
3144 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
3145 struct wined3d_rendertarget_view **view)
3147 struct wined3d_rendertarget_view *view_no3d;
3148 HRESULT hr;
3150 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
3151 wined3d_debug_view_desc(desc, resource), resource, parent, parent_ops, view);
3153 if (!(view_no3d = heap_alloc_zero(sizeof(*view_no3d))))
3154 return E_OUTOFMEMORY;
3156 if (FAILED(hr = wined3d_rendertarget_view_no3d_init(view_no3d, desc, resource, parent, parent_ops)))
3158 WARN("Failed to initialise view, hr %#lx.\n", hr);
3159 heap_free(view_no3d);
3160 return hr;
3163 TRACE("Created render target view %p.\n", view_no3d);
3164 *view = view_no3d;
3166 return hr;
3169 static void adapter_no3d_destroy_rendertarget_view(struct wined3d_rendertarget_view *view)
3171 struct wined3d_device *device = view->resource->device;
3172 unsigned int swapchain_count = device->swapchain_count;
3174 TRACE("view %p.\n", view);
3176 /* Take a reference to the device, in case releasing the view's resource
3177 * would cause the device to be destroyed. However, swapchain resources
3178 * don't take a reference to the device, and we wouldn't want to increment
3179 * the refcount on a device that's in the process of being destroyed. */
3180 if (swapchain_count)
3181 wined3d_device_incref(device);
3182 wined3d_rendertarget_view_cleanup(view);
3183 wined3d_cs_destroy_object(device->cs, heap_free, view);
3184 if (swapchain_count)
3185 wined3d_device_decref(device);
3188 static HRESULT adapter_no3d_create_shader_resource_view(const struct wined3d_view_desc *desc,
3189 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
3190 struct wined3d_shader_resource_view **view)
3192 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
3193 wined3d_debug_view_desc(desc, resource), resource, parent, parent_ops, view);
3195 return E_NOTIMPL;
3198 static void adapter_no3d_destroy_shader_resource_view(struct wined3d_shader_resource_view *view)
3200 TRACE("view %p.\n", view);
3203 static HRESULT adapter_no3d_create_unordered_access_view(const struct wined3d_view_desc *desc,
3204 struct wined3d_resource *resource, void *parent, const struct wined3d_parent_ops *parent_ops,
3205 struct wined3d_unordered_access_view **view)
3207 TRACE("desc %s, resource %p, parent %p, parent_ops %p, view %p.\n",
3208 wined3d_debug_view_desc(desc, resource), resource, parent, parent_ops, view);
3210 return E_NOTIMPL;
3213 static void adapter_no3d_destroy_unordered_access_view(struct wined3d_unordered_access_view *view)
3215 TRACE("view %p.\n", view);
3218 static HRESULT adapter_no3d_create_sampler(struct wined3d_device *device, const struct wined3d_sampler_desc *desc,
3219 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_sampler **sampler)
3221 TRACE("device %p, desc %p, parent %p, parent_ops %p, sampler %p.\n",
3222 device, desc, parent, parent_ops, sampler);
3224 return E_NOTIMPL;
3227 static void adapter_no3d_destroy_sampler(struct wined3d_sampler *sampler)
3229 TRACE("sampler %p.\n", sampler);
3232 static HRESULT adapter_no3d_create_query(struct wined3d_device *device, enum wined3d_query_type type,
3233 void *parent, const struct wined3d_parent_ops *parent_ops, struct wined3d_query **query)
3235 TRACE("device %p, type %#x, parent %p, parent_ops %p, query %p.\n",
3236 device, type, parent, parent_ops, query);
3238 return WINED3DERR_NOTAVAILABLE;
3241 static void adapter_no3d_destroy_query(struct wined3d_query *query)
3243 TRACE("query %p.\n", query);
3246 static void adapter_no3d_flush_context(struct wined3d_context *context)
3248 TRACE("context %p.\n", context);
3251 static void adapter_no3d_draw_primitive(struct wined3d_device *device,
3252 const struct wined3d_state *state, const struct wined3d_draw_parameters *parameters)
3254 ERR("device %p, state %p, parameters %p.\n", device, state, parameters);
3257 static void adapter_no3d_dispatch_compute(struct wined3d_device *device,
3258 const struct wined3d_state *state, const struct wined3d_dispatch_parameters *parameters)
3260 ERR("device %p, state %p, parameters %p.\n", device, state, parameters);
3263 static void adapter_no3d_clear_uav(struct wined3d_context *context,
3264 struct wined3d_unordered_access_view *view, const struct wined3d_uvec4 *clear_value, bool fp)
3266 ERR("context %p, view %p, clear_value %s, fp %#x.\n", context, view, debug_uvec4(clear_value), fp);
3269 static const struct wined3d_adapter_ops wined3d_adapter_no3d_ops =
3271 .adapter_destroy = adapter_no3d_destroy,
3272 .adapter_create_device = adapter_no3d_create_device,
3273 .adapter_destroy_device = adapter_no3d_destroy_device,
3274 .adapter_acquire_context = adapter_no3d_acquire_context,
3275 .adapter_release_context = adapter_no3d_release_context,
3276 .adapter_get_wined3d_caps = adapter_no3d_get_wined3d_caps,
3277 .adapter_check_format = adapter_no3d_check_format,
3278 .adapter_init_3d = adapter_no3d_init_3d,
3279 .adapter_uninit_3d = adapter_no3d_uninit_3d,
3280 .adapter_map_bo_address = adapter_no3d_map_bo_address,
3281 .adapter_unmap_bo_address = adapter_no3d_unmap_bo_address,
3282 .adapter_copy_bo_address = adapter_no3d_copy_bo_address,
3283 .adapter_flush_bo_address = adapter_no3d_flush_bo_address,
3284 .adapter_alloc_bo = adapter_no3d_alloc_bo,
3285 .adapter_destroy_bo = adapter_no3d_destroy_bo,
3286 .adapter_create_swapchain = adapter_no3d_create_swapchain,
3287 .adapter_destroy_swapchain = adapter_no3d_destroy_swapchain,
3288 .adapter_create_buffer = adapter_no3d_create_buffer,
3289 .adapter_destroy_buffer = adapter_no3d_destroy_buffer,
3290 .adapter_create_texture = adapter_no3d_create_texture,
3291 .adapter_destroy_texture = adapter_no3d_destroy_texture,
3292 .adapter_create_rendertarget_view = adapter_no3d_create_rendertarget_view,
3293 .adapter_destroy_rendertarget_view = adapter_no3d_destroy_rendertarget_view,
3294 .adapter_create_shader_resource_view = adapter_no3d_create_shader_resource_view,
3295 .adapter_destroy_shader_resource_view = adapter_no3d_destroy_shader_resource_view,
3296 .adapter_create_unordered_access_view = adapter_no3d_create_unordered_access_view,
3297 .adapter_destroy_unordered_access_view = adapter_no3d_destroy_unordered_access_view,
3298 .adapter_create_sampler = adapter_no3d_create_sampler,
3299 .adapter_destroy_sampler = adapter_no3d_destroy_sampler,
3300 .adapter_create_query = adapter_no3d_create_query,
3301 .adapter_destroy_query = adapter_no3d_destroy_query,
3302 .adapter_flush_context = adapter_no3d_flush_context,
3303 .adapter_draw_primitive = adapter_no3d_draw_primitive,
3304 .adapter_dispatch_compute = adapter_no3d_dispatch_compute,
3305 .adapter_clear_uav = adapter_no3d_clear_uav,
3308 static void wined3d_adapter_no3d_init_d3d_info(struct wined3d_adapter *adapter, unsigned int wined3d_creation_flags)
3310 struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
3312 d3d_info->wined3d_creation_flags = wined3d_creation_flags;
3313 d3d_info->texture_npot = TRUE;
3314 d3d_info->feature_level = WINED3D_FEATURE_LEVEL_5;
3317 static struct wined3d_adapter *wined3d_adapter_no3d_create(unsigned int ordinal, unsigned int wined3d_creation_flags)
3319 struct wined3d_adapter *adapter;
3320 LUID primary_luid, *luid = NULL;
3322 static const struct wined3d_gpu_description gpu_description =
3324 HW_VENDOR_SOFTWARE, CARD_WINE, "WineD3D DirectDraw Emulation", DRIVER_WINE, 128,
3327 TRACE("ordinal %u, wined3d_creation_flags %#x.\n", ordinal, wined3d_creation_flags);
3329 if (!(adapter = heap_alloc_zero(sizeof(*adapter))))
3330 return NULL;
3332 if (ordinal == 0 && wined3d_get_primary_adapter_luid(&primary_luid))
3333 luid = &primary_luid;
3335 if (!wined3d_adapter_init(adapter, ordinal, luid, &wined3d_adapter_no3d_ops))
3337 heap_free(adapter);
3338 return NULL;
3341 if (!wined3d_adapter_no3d_init_format_info(adapter))
3343 wined3d_adapter_cleanup(adapter);
3344 heap_free(adapter);
3345 return NULL;
3348 if (!wined3d_driver_info_init(&adapter->driver_info, &gpu_description, WINED3D_FEATURE_LEVEL_NONE, 0, 0))
3350 wined3d_adapter_cleanup(adapter);
3351 heap_free(adapter);
3352 return NULL;
3354 adapter->vram_bytes_used = 0;
3355 TRACE("Emulating 0x%s bytes of video ram.\n", wine_dbgstr_longlong(adapter->driver_info.vram_bytes));
3357 adapter->vertex_pipe = &none_vertex_pipe;
3358 adapter->fragment_pipe = &none_fragment_pipe;
3359 adapter->misc_state_template = misc_state_template_no3d;
3360 adapter->shader_backend = &none_shader_backend;
3362 wined3d_adapter_no3d_init_d3d_info(adapter, wined3d_creation_flags);
3364 TRACE("Created adapter %p.\n", adapter);
3366 return adapter;
3369 static BOOL wined3d_adapter_create_output(struct wined3d_adapter *adapter, const WCHAR *output_name)
3371 HRESULT hr;
3373 if (!wined3d_array_reserve((void **)&adapter->outputs, &adapter->outputs_size,
3374 adapter->output_count + 1, sizeof(*adapter->outputs)))
3375 return FALSE;
3377 if (FAILED(hr = wined3d_output_init(&adapter->outputs[adapter->output_count],
3378 adapter->output_count, adapter, output_name)))
3380 ERR("Failed to initialise output %s, hr %#lx.\n", wine_dbgstr_w(output_name), hr);
3381 return FALSE;
3384 ++adapter->output_count;
3385 TRACE("Initialised output %s.\n", wine_dbgstr_w(output_name));
3386 return TRUE;
3389 BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, unsigned int ordinal, const LUID *luid,
3390 const struct wined3d_adapter_ops *adapter_ops)
3392 D3DKMT_OPENADAPTERFROMLUID open_adapter_desc;
3393 unsigned int output_idx = 0, primary_idx = 0;
3394 D3DKMT_CLOSEADAPTER close_adapter_desc;
3395 DISPLAY_DEVICEW display_device;
3396 BOOL ret = FALSE;
3398 adapter->ordinal = ordinal;
3399 adapter->output_count = 0;
3400 adapter->outputs = NULL;
3402 if (luid)
3404 adapter->luid = *luid;
3406 else
3408 WARN("Allocating a random LUID.\n");
3409 if (!AllocateLocallyUniqueId(&adapter->luid))
3411 ERR("Failed to allocate a LUID, error %#lx.\n", GetLastError());
3412 return FALSE;
3415 TRACE("adapter %p LUID %08lx:%08lx.\n", adapter, adapter->luid.HighPart, adapter->luid.LowPart);
3417 open_adapter_desc.AdapterLuid = adapter->luid;
3418 if (D3DKMTOpenAdapterFromLuid(&open_adapter_desc))
3419 return FALSE;
3420 adapter->kmt_adapter = open_adapter_desc.hAdapter;
3422 display_device.cb = sizeof(display_device);
3423 while (EnumDisplayDevicesW(NULL, output_idx++, &display_device, 0))
3425 /* Detached outputs are not enumerated */
3426 if (!(display_device.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP))
3427 continue;
3429 if (display_device.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE)
3430 primary_idx = adapter->output_count;
3432 if (!wined3d_adapter_create_output(adapter, display_device.DeviceName))
3433 goto done;
3435 TRACE("Initialised %Iu outputs for adapter %p.\n", adapter->output_count, adapter);
3437 /* Make the primary output first */
3438 if (primary_idx)
3440 struct wined3d_output tmp = adapter->outputs[0];
3441 adapter->outputs[0] = adapter->outputs[primary_idx];
3442 adapter->outputs[0].ordinal = 0;
3443 adapter->outputs[primary_idx] = tmp;
3444 adapter->outputs[primary_idx].ordinal = primary_idx;
3447 memset(&adapter->driver_uuid, 0, sizeof(adapter->driver_uuid));
3448 memset(&adapter->device_uuid, 0, sizeof(adapter->device_uuid));
3450 adapter->formats = NULL;
3451 adapter->adapter_ops = adapter_ops;
3452 ret = TRUE;
3453 done:
3454 if (!ret)
3456 for (output_idx = 0; output_idx < adapter->output_count; ++output_idx)
3457 wined3d_output_cleanup(&adapter->outputs[output_idx]);
3458 heap_free(adapter->outputs);
3459 close_adapter_desc.hAdapter = adapter->kmt_adapter;
3460 D3DKMTCloseAdapter(&close_adapter_desc);
3462 return ret;
3465 static struct wined3d_adapter *wined3d_adapter_create(unsigned int ordinal, DWORD wined3d_creation_flags)
3467 if (wined3d_creation_flags & WINED3D_NO3D)
3468 return wined3d_adapter_no3d_create(ordinal, wined3d_creation_flags);
3470 if (wined3d_settings.renderer == WINED3D_RENDERER_VULKAN)
3471 return wined3d_adapter_vk_create(ordinal, wined3d_creation_flags);
3473 return wined3d_adapter_gl_create(ordinal, wined3d_creation_flags);
3476 static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
3478 const struct wined3d_parent_ops wined3d_null_parent_ops =
3480 wined3d_null_wined3d_object_destroyed,
3483 HRESULT wined3d_init(struct wined3d *wined3d, uint32_t flags)
3485 wined3d->ref = 1;
3486 wined3d->flags = flags;
3488 TRACE("Initialising adapters.\n");
3490 if (!(wined3d->adapters[0] = wined3d_adapter_create(0, flags)))
3492 WARN("Failed to create adapter.\n");
3493 return E_FAIL;
3495 wined3d->adapter_count = 1;
3497 return WINED3D_OK;