wininet: Added support for INTERNET_COOKIE_HTTPONLY flag to InternetSetCookieEx.
[wine/multimedia.git] / dlls / wined3d / directx.c
blobd6bb38364d0b6fe09319fd80366701ed34e3124c
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 "config.h"
25 #include "wine/port.h"
27 #include <stdio.h>
29 #include "wined3d_private.h"
30 #include "winternl.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(d3d);
33 WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
34 WINE_DECLARE_DEBUG_CHANNEL(winediag);
36 #define WINE_DEFAULT_VIDMEM (64 * 1024 * 1024)
37 #define DEFAULT_REFRESH_RATE 0
39 /* The driver names reflect the lowest GPU supported
40 * by a certain driver, so DRIVER_AMD_R300 supports
41 * R3xx, R4xx and R5xx GPUs. */
42 enum wined3d_display_driver
44 DRIVER_AMD_RAGE_128PRO,
45 DRIVER_AMD_R100,
46 DRIVER_AMD_R300,
47 DRIVER_AMD_R600,
48 DRIVER_INTEL_GMA800,
49 DRIVER_INTEL_GMA900,
50 DRIVER_INTEL_GMA950,
51 DRIVER_INTEL_GMA3000,
52 DRIVER_NVIDIA_TNT,
53 DRIVER_NVIDIA_GEFORCE2MX,
54 DRIVER_NVIDIA_GEFORCEFX,
55 DRIVER_NVIDIA_GEFORCE6,
56 DRIVER_VMWARE,
57 DRIVER_UNKNOWN
60 enum wined3d_driver_model
62 DRIVER_MODEL_WIN9X,
63 DRIVER_MODEL_NT40,
64 DRIVER_MODEL_NT5X,
65 DRIVER_MODEL_NT6X
68 enum wined3d_gl_vendor
70 GL_VENDOR_UNKNOWN,
71 GL_VENDOR_APPLE,
72 GL_VENDOR_FGLRX,
73 GL_VENDOR_MESA,
74 GL_VENDOR_NVIDIA,
77 /* The d3d device ID */
78 static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
80 /* Extension detection */
81 struct wined3d_extension_map
83 const char *extension_string;
84 enum wined3d_gl_extension extension;
87 static const struct wined3d_extension_map gl_extension_map[] =
89 /* APPLE */
90 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE },
91 {"GL_APPLE_fence", APPLE_FENCE },
92 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS },
93 {"GL_APPLE_flush_buffer_range", APPLE_FLUSH_BUFFER_RANGE },
94 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422 },
96 /* ARB */
97 {"GL_ARB_blend_func_extended", ARB_BLEND_FUNC_EXTENDED },
98 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT },
99 {"GL_ARB_debug_output", ARB_DEBUG_OUTPUT },
100 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT },
101 {"GL_ARB_depth_clamp", ARB_DEPTH_CLAMP },
102 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE },
103 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS },
104 {"GL_ARB_draw_elements_base_vertex", ARB_DRAW_ELEMENTS_BASE_VERTEX },
105 {"GL_ARB_draw_instanced", ARB_DRAW_INSTANCED },
106 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM },
107 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER },
108 {"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT },
109 {"GL_ARB_framebuffer_sRGB", ARB_FRAMEBUFFER_SRGB },
110 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4 },
111 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL },
112 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX },
113 {"GL_ARB_instanced_arrays", ARB_INSTANCED_ARRAYS, },
114 {"GL_ARB_internalformat_query2", ARB_INTERNALFORMAT_QUERY2, },
115 {"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT },
116 {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE },
117 {"GL_ARB_multisample", ARB_MULTISAMPLE }, /* needs GLX_ARB_MULTISAMPLE as well */
118 {"GL_ARB_multitexture", ARB_MULTITEXTURE },
119 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY },
120 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT },
121 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS },
122 {"GL_ARB_point_sprite", ARB_POINT_SPRITE },
123 {"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX },
124 {"GL_ARB_shader_bit_encoding", ARB_SHADER_BIT_ENCODING },
125 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS },
126 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD },
127 {"GL_ARB_shading_language_100", ARB_SHADING_LANGUAGE_100 },
128 {"GL_ARB_shadow", ARB_SHADOW },
129 {"GL_ARB_sync", ARB_SYNC },
130 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP },
131 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION },
132 {"GL_ARB_texture_compression_rgtc", ARB_TEXTURE_COMPRESSION_RGTC },
133 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP },
134 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD },
135 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE },
136 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3 },
137 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT },
138 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT },
139 {"GL_ARB_texture_mirror_clamp_to_edge", ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE},
140 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO },
141 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE },
142 {"GL_ARB_texture_rg", ARB_TEXTURE_RG },
143 {"GL_ARB_timer_query", ARB_TIMER_QUERY },
144 {"GL_ARB_vertex_array_bgra", ARB_VERTEX_ARRAY_BGRA },
145 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND },
146 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT },
147 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM },
148 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER },
150 /* ATI */
151 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER },
152 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL },
153 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC },
154 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3 },
155 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE },
157 /* EXT */
158 {"GL_EXT_blend_color", EXT_BLEND_COLOR },
159 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE },
160 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE },
161 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX },
162 {"GL_EXT_blend_subtract", EXT_BLEND_SUBTRACT },
163 {"GL_EXT_depth_bounds_test", EXT_DEPTH_BOUNDS_TEST },
164 {"GL_EXT_draw_buffers2", EXT_DRAW_BUFFERS2 },
165 {"GL_EXT_fog_coord", EXT_FOG_COORD },
166 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT },
167 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE },
168 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT },
169 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS },
170 {"GL_EXT_gpu_shader4", EXT_GPU_SHADER4 },
171 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL },
172 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS },
173 {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX },
174 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR },
175 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE },
176 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP },
177 {"GL_EXT_texture3D", EXT_TEXTURE3D },
178 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC },
179 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC },
180 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD },
181 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE },
182 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3 },
183 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC},
184 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS },
185 {"GL_EXT_texture_mirror_clamp", EXT_TEXTURE_MIRROR_CLAMP },
186 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB },
187 {"GL_EXT_texture_sRGB_decode", EXT_TEXTURE_SRGB_DECODE },
188 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA },
190 /* NV */
191 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP },
192 {"GL_NV_fence", NV_FENCE },
193 {"GL_NV_fog_distance", NV_FOG_DISTANCE },
194 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM },
195 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2 },
196 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION },
197 {"GL_NV_half_float", NV_HALF_FLOAT },
198 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT },
199 {"GL_NV_point_sprite", NV_POINT_SPRITE },
200 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS },
201 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2 },
202 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION },
203 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4 },
204 {"GL_NV_texture_shader", NV_TEXTURE_SHADER },
205 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2 },
206 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM },
207 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1 },
208 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2 },
209 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION },
210 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3 },
212 /* SGI */
213 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP },
216 static const struct wined3d_extension_map wgl_extension_map[] =
218 {"WGL_ARB_pixel_format", WGL_ARB_PIXEL_FORMAT },
219 {"WGL_EXT_swap_control", WGL_EXT_SWAP_CONTROL },
220 {"WGL_WINE_pixel_format_passthrough", WGL_WINE_PIXEL_FORMAT_PASSTHROUGH},
223 /**********************************************************
224 * Utility functions follow
225 **********************************************************/
227 const struct min_lookup minMipLookup[] =
229 /* NONE POINT LINEAR */
230 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
231 {{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
232 {{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
235 const struct min_lookup minMipLookup_noFilter[] =
237 /* NONE POINT LINEAR */
238 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
239 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
240 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* LINEAR */
243 const struct min_lookup minMipLookup_noMip[] =
245 /* NONE POINT LINEAR */
246 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
247 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
248 {{GL_LINEAR, GL_LINEAR, GL_LINEAR }}, /* LINEAR */
251 const GLenum magLookup[] =
253 /* NONE POINT LINEAR */
254 GL_NEAREST, GL_NEAREST, GL_LINEAR,
257 const GLenum magLookup_noFilter[] =
259 /* NONE POINT LINEAR */
260 GL_NEAREST, GL_NEAREST, GL_NEAREST,
263 struct wined3d_caps_gl_ctx
265 HDC dc;
266 HWND wnd;
267 HGLRC gl_ctx;
268 HDC restore_dc;
269 HGLRC restore_gl_ctx;
272 static void wined3d_caps_gl_ctx_destroy(const struct wined3d_caps_gl_ctx *ctx)
274 TRACE("Destroying caps GL context.\n");
276 if (!wglMakeCurrent(NULL, NULL))
277 ERR("Failed to disable caps GL context.\n");
279 if (!wglDeleteContext(ctx->gl_ctx))
281 DWORD err = GetLastError();
282 ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
285 wined3d_release_dc(ctx->wnd, ctx->dc);
286 DestroyWindow(ctx->wnd);
288 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
289 ERR("Failed to restore previous GL context.\n");
292 static void wined3d_caps_gl_ctx_create_attribs(struct wined3d_caps_gl_ctx *caps_gl_ctx,
293 struct wined3d_gl_info *gl_info, const GLint *ctx_attribs)
295 HGLRC new_ctx;
297 if (!(gl_info->p_wglCreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB")))
298 return;
300 if (!(new_ctx = gl_info->p_wglCreateContextAttribsARB(caps_gl_ctx->dc, NULL, ctx_attribs)))
302 ERR("Failed to create a context using wglCreateContextAttribsARB(), last error %#x.\n", GetLastError());
303 gl_info->p_wglCreateContextAttribsARB = NULL;
304 return;
307 if (!wglMakeCurrent(caps_gl_ctx->dc, new_ctx))
309 ERR("Failed to make new context current, last error %#x.\n", GetLastError());
310 if (!wglDeleteContext(new_ctx))
311 ERR("Failed to delete new context, last error %#x.\n", GetLastError());
312 gl_info->p_wglCreateContextAttribsARB = NULL;
313 return;
316 if (!wglDeleteContext(caps_gl_ctx->gl_ctx))
317 ERR("Failed to delete old context, last error %#x.\n", GetLastError());
318 caps_gl_ctx->gl_ctx = new_ctx;
321 static BOOL wined3d_caps_gl_ctx_create(struct wined3d_caps_gl_ctx *ctx)
323 PIXELFORMATDESCRIPTOR pfd;
324 int iPixelFormat;
326 TRACE("getting context...\n");
328 ctx->restore_dc = wglGetCurrentDC();
329 ctx->restore_gl_ctx = wglGetCurrentContext();
331 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
332 ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
333 WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
334 if (!ctx->wnd)
336 ERR("Failed to create a window.\n");
337 goto fail;
340 ctx->dc = GetDC(ctx->wnd);
341 if (!ctx->dc)
343 ERR("Failed to get a DC.\n");
344 goto fail;
347 /* PixelFormat selection */
348 ZeroMemory(&pfd, sizeof(pfd));
349 pfd.nSize = sizeof(pfd);
350 pfd.nVersion = 1;
351 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
352 pfd.iPixelType = PFD_TYPE_RGBA;
353 pfd.cColorBits = 32;
354 pfd.iLayerType = PFD_MAIN_PLANE;
356 if (!(iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd)))
358 /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
359 ERR("Failed to find a suitable pixel format.\n");
360 goto fail;
362 DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
363 SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
365 /* Create a GL context. */
366 if (!(ctx->gl_ctx = wglCreateContext(ctx->dc)))
368 WARN("Failed to create default context for capabilities initialization.\n");
369 goto fail;
372 /* Make it the current GL context. */
373 if (!wglMakeCurrent(ctx->dc, ctx->gl_ctx))
375 ERR("Failed to make caps GL context current.\n");
376 goto fail;
379 return TRUE;
381 fail:
382 if (ctx->gl_ctx) wglDeleteContext(ctx->gl_ctx);
383 ctx->gl_ctx = NULL;
384 if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
385 ctx->dc = NULL;
386 if (ctx->wnd) DestroyWindow(ctx->wnd);
387 ctx->wnd = NULL;
388 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
389 ERR("Failed to restore previous GL context.\n");
391 return FALSE;
394 /* Adjust the amount of used texture memory */
395 unsigned int adapter_adjust_memory(struct wined3d_adapter *adapter, int amount)
397 adapter->UsedTextureRam += amount;
398 TRACE("Adjusted adapter memory by %d to %d.\n", amount, adapter->UsedTextureRam);
399 return adapter->UsedTextureRam;
402 static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
404 HeapFree(GetProcessHeap(), 0, adapter->gl_info.formats);
405 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
408 ULONG CDECL wined3d_incref(struct wined3d *wined3d)
410 ULONG refcount = InterlockedIncrement(&wined3d->ref);
412 TRACE("%p increasing refcount to %u.\n", wined3d, refcount);
414 return refcount;
417 ULONG CDECL wined3d_decref(struct wined3d *wined3d)
419 ULONG refcount = InterlockedDecrement(&wined3d->ref);
421 TRACE("%p decreasing refcount to %u.\n", wined3d, refcount);
423 if (!refcount)
425 unsigned int i;
427 for (i = 0; i < wined3d->adapter_count; ++i)
429 wined3d_adapter_cleanup(&wined3d->adapters[i]);
431 HeapFree(GetProcessHeap(), 0, wined3d);
434 return refcount;
437 /* Context activation is done by the caller. */
438 static BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
440 GLuint prog;
441 BOOL ret = FALSE;
442 static const char testcode[] =
443 "!!ARBvp1.0\n"
444 "PARAM C[66] = { program.env[0..65] };\n"
445 "ADDRESS A0;"
446 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
447 "ARL A0.x, zero.x;\n"
448 "MOV result.position, C[A0.x + 65];\n"
449 "END\n";
451 while (gl_info->gl_ops.gl.p_glGetError());
452 GL_EXTCALL(glGenProgramsARB(1, &prog));
453 if(!prog) {
454 ERR("Failed to create an ARB offset limit test program\n");
456 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
457 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
458 strlen(testcode), testcode));
459 if (gl_info->gl_ops.gl.p_glGetError())
461 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
462 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
463 ret = TRUE;
464 } else TRACE("OpenGL implementation allows offsets > 63\n");
466 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
467 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
468 checkGLcall("ARB vp offset limit test cleanup");
470 return ret;
473 static BOOL match_amd_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
474 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
476 if (card_vendor != HW_VENDOR_AMD) return FALSE;
477 if (device == CARD_AMD_RADEON_9500) return TRUE;
478 if (device == CARD_AMD_RADEON_X700) return TRUE;
479 if (device == CARD_AMD_RADEON_X1600) return TRUE;
480 return FALSE;
483 static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
484 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
486 if (card_vendor == HW_VENDOR_NVIDIA)
488 if (device == CARD_NVIDIA_GEFORCEFX_5200 ||
489 device == CARD_NVIDIA_GEFORCEFX_5600 ||
490 device == CARD_NVIDIA_GEFORCEFX_5800)
492 return TRUE;
495 return FALSE;
498 static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
499 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
501 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
502 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
503 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
505 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
506 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
507 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
508 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
509 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
510 * the chance that other implementations support them is rather small since Win32 QuickTime uses
511 * DirectDraw, not OpenGL.
513 * This test has been moved into wined3d_guess_gl_vendor()
515 if (gl_vendor == GL_VENDOR_APPLE)
517 return TRUE;
519 return FALSE;
522 /* Context activation is done by the caller. */
523 static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
525 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
526 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
527 * all the texture. This function detects this bug by its symptom and disables PBOs
528 * if the test fails.
530 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
531 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
532 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
533 * read back is compared to the original. If they are equal PBOs are assumed to work,
534 * otherwise the PBO extension is disabled. */
535 GLuint texture, pbo;
536 static const unsigned int pattern[] =
538 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
539 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
540 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
541 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
543 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
545 /* No PBO -> No point in testing them. */
546 if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
548 while (gl_info->gl_ops.gl.p_glGetError());
549 gl_info->gl_ops.gl.p_glGenTextures(1, &texture);
550 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
552 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
553 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
554 checkGLcall("Specifying the PBO test texture");
556 GL_EXTCALL(glGenBuffersARB(1, &pbo));
557 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
558 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
559 checkGLcall("Specifying the PBO test pbo");
561 gl_info->gl_ops.gl.p_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
562 checkGLcall("Loading the PBO test texture");
564 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
566 gl_info->gl_ops.gl.p_glFinish(); /* just to be sure */
568 memset(check, 0, sizeof(check));
569 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
570 checkGLcall("Reading back the PBO test texture");
572 gl_info->gl_ops.gl.p_glDeleteTextures(1, &texture);
573 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
574 checkGLcall("PBO test cleanup");
576 if (memcmp(check, pattern, sizeof(check)))
578 WARN_(d3d_perf)("PBO test failed, read back data doesn't match original.\n"
579 "Disabling PBOs. This may result in slower performance.\n");
580 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
582 else
584 TRACE("PBO test successful.\n");
588 static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
589 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
591 return (card_vendor == HW_VENDOR_INTEL) && (gl_vendor == GL_VENDOR_APPLE);
594 static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
595 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
597 if (gl_vendor != GL_VENDOR_APPLE) return FALSE;
598 if (card_vendor != HW_VENDOR_AMD) return FALSE;
599 if (device == CARD_AMD_RADEON_X1600) return FALSE;
600 return TRUE;
603 static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
604 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
606 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
607 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
608 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
609 * varyings and we subtract one in dx9 shaders it's not going to hurt us because the dx9 limit is
610 * hardcoded
612 * dx10 cards usually have 64 varyings */
613 return gl_info->limits.glsl_varyings > 44;
616 static BOOL match_not_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
617 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
619 return !match_dx10_capable(gl_info, gl_renderer, gl_vendor, card_vendor, device);
622 /* A GL context is provided by the caller */
623 static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
624 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
626 GLenum error;
627 DWORD data[16];
629 if (!gl_info->supported[EXT_SECONDARY_COLOR])
630 return FALSE;
632 while (gl_info->gl_ops.gl.p_glGetError());
633 GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
634 error = gl_info->gl_ops.gl.p_glGetError();
636 if (error == GL_NO_ERROR)
638 TRACE("GL Implementation accepts 4 component specular color pointers\n");
639 return TRUE;
641 else
643 TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
644 debug_glerror(error));
645 return FALSE;
649 /* A GL context is provided by the caller */
650 static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
651 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
653 GLuint prog;
654 BOOL ret = FALSE;
655 GLint pos;
656 static const char testcode[] =
657 "!!ARBvp1.0\n"
658 "OPTION NV_vertex_program2;\n"
659 "MOV result.clip[0], 0.0;\n"
660 "MOV result.position, 0.0;\n"
661 "END\n";
663 if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
665 while (gl_info->gl_ops.gl.p_glGetError());
667 GL_EXTCALL(glGenProgramsARB(1, &prog));
668 if(!prog)
670 ERR("Failed to create the NVvp clip test program\n");
671 return FALSE;
673 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
674 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
675 strlen(testcode), testcode));
676 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
677 if(pos != -1)
679 WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
680 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
681 ret = TRUE;
682 while (gl_info->gl_ops.gl.p_glGetError());
684 else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
686 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
687 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
688 checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
690 return ret;
693 /* Context activation is done by the caller. */
694 static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
695 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
697 char data[4 * 4 * 4];
698 GLuint tex, fbo;
699 GLenum status;
701 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return FALSE;
703 memset(data, 0xcc, sizeof(data));
705 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
706 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
707 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
708 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
709 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
710 checkGLcall("glTexImage2D");
712 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
713 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
714 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
715 checkGLcall("glFramebufferTexture2D");
717 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
718 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
719 checkGLcall("glCheckFramebufferStatus");
721 memset(data, 0x11, sizeof(data));
722 gl_info->gl_ops.gl.p_glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
723 checkGLcall("glTexSubImage2D");
725 gl_info->gl_ops.gl.p_glClearColor(0.996f, 0.729f, 0.745f, 0.792f);
726 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
727 checkGLcall("glClear");
729 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
730 checkGLcall("glGetTexImage");
732 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
733 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
734 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
735 checkGLcall("glBindTexture");
737 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
738 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
739 checkGLcall("glDeleteTextures");
741 return *(DWORD *)data == 0x11111111;
744 /* Context activation is done by the caller. */
745 static BOOL match_broken_rgba16(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
746 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
748 /* GL_RGBA16 uses GL_RGBA8 internally on Geforce 7 and older cards.
749 * This leads to graphical bugs in Half Life 2 and Unreal engine games. */
750 GLuint tex;
751 GLint size;
753 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
754 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
755 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL);
756 checkGLcall("glTexImage2D");
758 gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &size);
759 checkGLcall("glGetTexLevelParameteriv");
760 TRACE("Real color depth is %d\n", size);
762 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
763 checkGLcall("glBindTexture");
764 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
765 checkGLcall("glDeleteTextures");
767 return size < 16;
770 static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
771 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
773 return gl_vendor == GL_VENDOR_FGLRX;
776 static BOOL match_r200(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
777 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
779 if (card_vendor != HW_VENDOR_AMD) return FALSE;
780 if (device == CARD_AMD_RADEON_8500) return TRUE;
781 return FALSE;
784 static BOOL match_broken_arb_fog(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
785 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
787 DWORD data[4];
788 GLuint tex, fbo;
789 GLenum status;
790 float color[4] = {0.0f, 1.0f, 0.0f, 0.0f};
791 GLuint prog;
792 GLint err_pos;
793 static const char program_code[] =
794 "!!ARBfp1.0\n"
795 "OPTION ARB_fog_linear;\n"
796 "MOV result.color, {1.0, 0.0, 0.0, 0.0};\n"
797 "END\n";
799 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
800 return FALSE;
801 if (!gl_info->supported[ARB_FRAGMENT_PROGRAM])
802 return FALSE;
804 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
805 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
806 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
807 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
808 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 4, 1, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
809 checkGLcall("glTexImage2D");
811 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
812 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
813 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
814 checkGLcall("glFramebufferTexture2D");
816 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
817 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
818 checkGLcall("glCheckFramebufferStatus");
820 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
821 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
822 checkGLcall("glClear");
823 gl_info->gl_ops.gl.p_glViewport(0, 0, 4, 1);
824 checkGLcall("glViewport");
826 gl_info->gl_ops.gl.p_glEnable(GL_FOG);
827 gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, 0.5f);
828 gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, 0.5f);
829 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
830 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
831 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, color);
832 checkGLcall("fog setup");
834 GL_EXTCALL(glGenProgramsARB(1, &prog));
835 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog));
836 GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
837 strlen(program_code), program_code));
838 gl_info->gl_ops.gl.p_glEnable(GL_FRAGMENT_PROGRAM_ARB);
839 checkGLcall("Test fragment program setup");
841 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err_pos);
842 if (err_pos != -1)
844 const char *error_str;
845 error_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB);
846 FIXME("Fog test program error at position %d: %s\n\n", err_pos, debugstr_a(error_str));
849 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
850 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, -1.0f, 0.0f);
851 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, -1.0f, 1.0f);
852 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, 1.0f, 0.0f);
853 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, 1.0f, 1.0f);
854 gl_info->gl_ops.gl.p_glEnd();
855 checkGLcall("ARBfp fog test draw");
857 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
858 checkGLcall("glGetTexImage");
859 data[0] &= 0x00ffffff;
860 data[1] &= 0x00ffffff;
861 data[2] &= 0x00ffffff;
862 data[3] &= 0x00ffffff;
864 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
865 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
867 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
868 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
869 gl_info->gl_ops.gl.p_glDisable(GL_FOG);
870 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0));
871 gl_info->gl_ops.gl.p_glDisable(GL_FRAGMENT_PROGRAM_ARB);
872 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
873 checkGLcall("ARBfp fog test teardown");
875 TRACE("Fog test data: %08x %08x %08x %08x\n", data[0], data[1], data[2], data[3]);
876 return data[0] != 0x00ff0000 || data[3] != 0x0000ff00;
879 static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
881 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
882 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
883 * allow 48 different offsets or other helper immediate values. */
884 TRACE("Reserving 12 GLSL constants for compiler private use.\n");
885 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
888 static void quirk_amd_dx9(struct wined3d_gl_info *gl_info)
890 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
891 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
892 * If real NP2 textures are used, the driver falls back to software. We could just remove the
893 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconvenient
894 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
895 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
896 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
898 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
899 * has this extension promoted to core. The extension loading code sets this extension supported
900 * due to that, so this code works on fglrx as well. */
901 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
903 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
904 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
905 gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] = TRUE;
909 static void quirk_no_np2(struct wined3d_gl_info *gl_info)
911 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
912 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
913 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
914 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
915 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
916 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
918 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
919 * triggering the software fallback. There is not much we can do here apart from disabling the
920 * software-emulated extension and re-enable ARB_tex_rect (which was previously disabled
921 * in wined3d_adapter_init_gl_caps).
922 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
923 * post-processing effects in the game "Max Payne 2").
924 * The behaviour can be verified through a simple test app attached in bugreport #14724. */
925 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
926 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
927 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
930 static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
932 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
933 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
934 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
935 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
936 * according to the spec.
938 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
939 * makes the shader slower and eats instruction slots which should be available to the d3d app.
941 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
942 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
943 * this workaround is activated on cards that do not need it, it won't break things, just affect
944 * performance negatively. */
945 TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
946 gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
949 static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
951 gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
954 static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
956 gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
959 static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
961 gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
964 static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info)
966 gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE;
969 static void quirk_broken_rgba16(struct wined3d_gl_info *gl_info)
971 gl_info->quirks |= WINED3D_QUIRK_BROKEN_RGBA16;
974 static void quirk_infolog_spam(struct wined3d_gl_info *gl_info)
976 gl_info->quirks |= WINED3D_QUIRK_INFO_LOG_SPAM;
979 static void quirk_limited_tex_filtering(struct wined3d_gl_info *gl_info)
981 /* Nvidia GeForce 6xxx and 7xxx support accelerated VTF only on a few
982 selected texture formats. They are apparently the only DX9 class GPUs
983 supporting VTF.
984 Also, DX9-era GPUs are somewhat limited with float textures
985 filtering and blending. */
986 gl_info->quirks |= WINED3D_QUIRK_LIMITED_TEX_FILTERING;
989 static void quirk_r200_constants(struct wined3d_gl_info *gl_info)
991 /* The Mesa r200 driver (and there is no other driver for this GPU Wine would run on)
992 * loads some fog parameters (start, end, exponent, but not the color) into the
993 * program.
995 * Apparently the fog hardware is only able to handle linear fog with a range of 0.0;1.0,
996 * and it is the responsibility of the vertex pipeline to handle non-linear fog and
997 * linear fog with start and end other than 0.0 and 1.0. */
998 TRACE("Reserving 1 ARB constant for compiler private use.\n");
999 gl_info->reserved_arb_constants = max(gl_info->reserved_arb_constants, 1);
1002 static void quirk_broken_arb_fog(struct wined3d_gl_info *gl_info)
1004 gl_info->quirks |= WINED3D_QUIRK_BROKEN_ARB_FOG;
1007 struct driver_quirk
1009 BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1010 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device);
1011 void (*apply)(struct wined3d_gl_info *gl_info);
1012 const char *description;
1015 static const struct driver_quirk quirk_table[] =
1018 match_amd_r300_to_500,
1019 quirk_amd_dx9,
1020 "AMD normalized texrect quirk"
1023 match_apple,
1024 quirk_apple_glsl_constants,
1025 "Apple GLSL uniform override"
1028 match_geforce5,
1029 quirk_no_np2,
1030 "Geforce 5 NP2 disable"
1033 match_apple_intel,
1034 quirk_texcoord_w,
1035 "Init texcoord .w for Apple Intel GPU driver"
1038 match_apple_nonr500ati,
1039 quirk_texcoord_w,
1040 "Init texcoord .w for Apple ATI >= r600 GPU driver"
1043 match_dx10_capable,
1044 quirk_clip_varying,
1045 "Reserved varying for gl_ClipPos"
1048 /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
1049 * GL implementations accept it. The Mac GL is the only implementation known to
1050 * reject it.
1052 * If we can pass 4 component specular colors, do it, because (a) we don't have
1053 * to screw around with the data, and (b) the D3D fixed function vertex pipeline
1054 * passes specular alpha to the pixel shader if any is used. Otherwise the
1055 * specular alpha is used to pass the fog coordinate, which we pass to opengl
1056 * via GL_EXT_fog_coord.
1058 match_allows_spec_alpha,
1059 quirk_allows_specular_alpha,
1060 "Allow specular alpha quirk"
1063 match_broken_nv_clip,
1064 quirk_disable_nvvp_clip,
1065 "Apple NV_vertex_program clip bug quirk"
1068 match_fbo_tex_update,
1069 quirk_fbo_tex_update,
1070 "FBO rebind for attachment updates"
1073 match_broken_rgba16,
1074 quirk_broken_rgba16,
1075 "True RGBA16 is not available"
1078 match_fglrx,
1079 quirk_infolog_spam,
1080 "Not printing GLSL infolog"
1083 match_not_dx10_capable,
1084 quirk_limited_tex_filtering,
1085 "Texture filtering, blending and VTF support is limited"
1088 match_r200,
1089 quirk_r200_constants,
1090 "r200 vertex shader constants"
1093 match_broken_arb_fog,
1094 quirk_broken_arb_fog,
1095 "ARBfp fogstart == fogend workaround"
1099 /* Certain applications (Steam) complain if we report an outdated driver version. In general,
1100 * reporting a driver version is moot because we are not the Windows driver, and we have different
1101 * bugs, features, etc.
1103 * The driver version has the form "x.y.z.w".
1105 * "x" is the Windows version the driver is meant for:
1106 * 4 -> 95/98/NT4
1107 * 5 -> 2000
1108 * 6 -> 2000/XP
1109 * 7 -> Vista
1110 * 8 -> Win 7
1112 * "y" is the maximum Direct3D version the driver supports.
1113 * y -> d3d version mapping:
1114 * 11 -> d3d6
1115 * 12 -> d3d7
1116 * 13 -> d3d8
1117 * 14 -> d3d9
1118 * 15 -> d3d10
1119 * 16 -> d3d10.1
1120 * 17 -> d3d11
1122 * "z" is the subversion number.
1124 * "w" is the vendor specific driver build number.
1127 struct driver_version_information
1129 enum wined3d_display_driver driver;
1130 enum wined3d_driver_model driver_model;
1131 const char *driver_name; /* name of Windows driver */
1132 WORD version; /* version word ('y'), contained in low word of DriverVersion.HighPart */
1133 WORD subversion; /* subversion word ('z'), contained in high word of DriverVersion.LowPart */
1134 WORD build; /* build number ('w'), contained in low word of DriverVersion.LowPart */
1137 /* The driver version table contains driver information for different devices on several OS versions. */
1138 static const struct driver_version_information driver_version_table[] =
1140 /* AMD
1141 * - Radeon HD2x00 (R600) and up supported by current drivers.
1142 * - Radeon 9500 (R300) - X1*00 (R5xx) supported up to Catalyst 9.3 (Linux) and 10.2 (XP/Vista/Win7)
1143 * - Radeon 7xxx (R100) - 9250 (RV250) supported up to Catalyst 6.11 (XP)
1144 * - Rage 128 supported up to XP, latest official build 6.13.3279 dated October 2001 */
1145 {DRIVER_AMD_RAGE_128PRO, DRIVER_MODEL_NT5X, "ati2dvaa.dll", 13, 3279, 0},
1146 {DRIVER_AMD_R100, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 6614},
1147 {DRIVER_AMD_R300, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 6764},
1148 {DRIVER_AMD_R600, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 8681},
1149 {DRIVER_AMD_R300, DRIVER_MODEL_NT6X, "atiumdag.dll", 14, 10, 741 },
1150 {DRIVER_AMD_R600, DRIVER_MODEL_NT6X, "atiumdag.dll", 14, 10, 741 },
1152 /* Intel
1153 * The drivers are unified but not all versions support all GPUs. At some point the 2k/xp
1154 * drivers used ialmrnt5.dll for GMA800/GMA900 but at some point the file was renamed to
1155 * igxprd32.dll but the GMA800 driver was never updated. */
1156 {DRIVER_INTEL_GMA800, DRIVER_MODEL_NT5X, "ialmrnt5.dll", 14, 10, 3889},
1157 {DRIVER_INTEL_GMA900, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 4764},
1158 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 4926},
1159 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 5218},
1160 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT6X, "igdumd32.dll", 14, 10, 1504},
1161 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT6X, "igdumd32.dll", 15, 10, 1666},
1163 /* Nvidia
1164 * - Geforce6 and newer cards are supported by the current driver (197.x) on XP-Win7
1165 * - GeforceFX support is up to 173.x on <= XP
1166 * - Geforce2MX/3/4 up to 96.x on <= XP
1167 * - TNT/Geforce1/2 up to 71.x on <= XP
1168 * All version numbers used below are from the Linux nvidia drivers. */
1169 {DRIVER_NVIDIA_TNT, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 10, 7186},
1170 {DRIVER_NVIDIA_GEFORCE2MX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 10, 9371},
1171 {DRIVER_NVIDIA_GEFORCEFX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 11, 7516},
1172 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT5X, "nv4_disp.dll", 15, 12, 6658},
1173 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT6X, "nvd3dum.dll", 15, 12, 6658},
1175 /* VMware */
1176 {DRIVER_VMWARE, DRIVER_MODEL_NT5X, "vm3dum.dll", 14, 1, 1134},
1179 struct gpu_description
1181 WORD vendor; /* reported PCI card vendor ID */
1182 WORD card; /* reported PCI card device ID */
1183 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
1184 enum wined3d_display_driver driver;
1185 unsigned int vidmem;
1188 /* The amount of video memory stored in the gpu description table is the minimum amount of video memory
1189 * found on a board containing a specific GPU. */
1190 static const struct gpu_description gpu_description_table[] =
1192 /* Nvidia cards */
1193 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", DRIVER_NVIDIA_TNT, 16 },
1194 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", DRIVER_NVIDIA_TNT, 32 },
1195 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", DRIVER_NVIDIA_TNT, 32 },
1196 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", DRIVER_NVIDIA_TNT, 32 },
1197 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", DRIVER_NVIDIA_GEFORCE2MX,32 },
1198 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", DRIVER_NVIDIA_GEFORCE2MX,64 },
1199 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", DRIVER_NVIDIA_GEFORCE2MX,64 },
1200 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", DRIVER_NVIDIA_GEFORCE2MX,64, },
1201 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", DRIVER_NVIDIA_GEFORCEFX, 64 },
1202 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", DRIVER_NVIDIA_GEFORCEFX, 128 },
1203 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", DRIVER_NVIDIA_GEFORCEFX, 256 },
1204 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", DRIVER_NVIDIA_GEFORCE6, 64 },
1205 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", DRIVER_NVIDIA_GEFORCE6, 128 },
1206 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", DRIVER_NVIDIA_GEFORCE6, 128 },
1207 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", DRIVER_NVIDIA_GEFORCE6, 256 },
1208 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", DRIVER_NVIDIA_GEFORCE6, 256 },
1209 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1210 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1211 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", DRIVER_NVIDIA_GEFORCE6, 128 },
1212 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8400GS, "NVIDIA GeForce 8400 GS", DRIVER_NVIDIA_GEFORCE6, 128 },
1213 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1214 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", DRIVER_NVIDIA_GEFORCE6, 512 },
1215 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", DRIVER_NVIDIA_GEFORCE6, 320 },
1216 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTX, "NVIDIA GeForce 8800 GTX", DRIVER_NVIDIA_GEFORCE6, 768 },
1217 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", DRIVER_NVIDIA_GEFORCE6, 256 },
1218 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9300, "NVIDIA GeForce 9300", DRIVER_NVIDIA_GEFORCE6, 256 },
1219 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400M, "NVIDIA GeForce 9400M", DRIVER_NVIDIA_GEFORCE6, 256 },
1220 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1221 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1222 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", DRIVER_NVIDIA_GEFORCE6, 384 },
1223 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", DRIVER_NVIDIA_GEFORCE6, 512 },
1224 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_210, "NVIDIA GeForce 210", DRIVER_NVIDIA_GEFORCE6, 512 },
1225 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT220, "NVIDIA GeForce GT 220", DRIVER_NVIDIA_GEFORCE6, 512 },
1226 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT240, "NVIDIA GeForce GT 240", DRIVER_NVIDIA_GEFORCE6, 512 },
1227 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", DRIVER_NVIDIA_GEFORCE6, 1024},
1228 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", DRIVER_NVIDIA_GEFORCE6, 896 },
1229 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", DRIVER_NVIDIA_GEFORCE6, 1024},
1230 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_315M, "NVIDIA GeForce 315M", DRIVER_NVIDIA_GEFORCE6, 512 },
1231 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_320M, "NVIDIA GeForce 320M", DRIVER_NVIDIA_GEFORCE6, 256},
1232 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_410M, "NVIDIA GeForce 410M", DRIVER_NVIDIA_GEFORCE6, 512},
1233 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT320M, "NVIDIA GeForce GT 320M", DRIVER_NVIDIA_GEFORCE6, 1024},
1234 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT325M, "NVIDIA GeForce GT 325M", DRIVER_NVIDIA_GEFORCE6, 1024},
1235 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT330, "NVIDIA GeForce GT 330", DRIVER_NVIDIA_GEFORCE6, 1024},
1236 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS350M, "NVIDIA GeForce GTS 350M", DRIVER_NVIDIA_GEFORCE6, 1024},
1237 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT420, "NVIDIA GeForce GT 420", DRIVER_NVIDIA_GEFORCE6, 2048},
1238 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT430, "NVIDIA GeForce GT 430", DRIVER_NVIDIA_GEFORCE6, 1024},
1239 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT440, "NVIDIA GeForce GT 440", DRIVER_NVIDIA_GEFORCE6, 1024},
1240 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS450, "NVIDIA GeForce GTS 450", DRIVER_NVIDIA_GEFORCE6, 1024},
1241 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460, "NVIDIA GeForce GTX 460", DRIVER_NVIDIA_GEFORCE6, 768 },
1242 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460M, "NVIDIA GeForce GTX 460M", DRIVER_NVIDIA_GEFORCE6, 1536},
1243 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX465, "NVIDIA GeForce GTX 465", DRIVER_NVIDIA_GEFORCE6, 1024},
1244 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX470, "NVIDIA GeForce GTX 470", DRIVER_NVIDIA_GEFORCE6, 1280},
1245 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX480, "NVIDIA GeForce GTX 480", DRIVER_NVIDIA_GEFORCE6, 1536},
1246 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT520, "NVIDIA GeForce GT 520", DRIVER_NVIDIA_GEFORCE6, 1024},
1247 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT540M, "NVIDIA GeForce GT 540M", DRIVER_NVIDIA_GEFORCE6, 1024},
1248 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX550, "NVIDIA GeForce GTX 550 Ti", DRIVER_NVIDIA_GEFORCE6, 1024},
1249 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT555M, "NVIDIA GeForce GT 555M", DRIVER_NVIDIA_GEFORCE6, 1024},
1250 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560TI, "NVIDIA GeForce GTX 560 Ti", DRIVER_NVIDIA_GEFORCE6, 1024},
1251 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560, "NVIDIA GeForce GTX 560", DRIVER_NVIDIA_GEFORCE6, 1024},
1252 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX570, "NVIDIA GeForce GTX 570", DRIVER_NVIDIA_GEFORCE6, 1280},
1253 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX580, "NVIDIA GeForce GTX 580", DRIVER_NVIDIA_GEFORCE6, 1536},
1254 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT610, "NVIDIA GeForce GT 610", DRIVER_NVIDIA_GEFORCE6, 1024},
1255 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630, "NVIDIA GeForce GT 630", DRIVER_NVIDIA_GEFORCE6, 1024},
1256 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630M, "NVIDIA GeForce GT 630M", DRIVER_NVIDIA_GEFORCE6, 1024},
1257 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT640M, "NVIDIA GeForce GT 640M", DRIVER_NVIDIA_GEFORCE6, 1024},
1258 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT650M, "NVIDIA GeForce GT 650M", DRIVER_NVIDIA_GEFORCE6, 2048},
1259 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650, "NVIDIA GeForce GTX 650", DRIVER_NVIDIA_GEFORCE6, 1024},
1260 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650TI, "NVIDIA GeForce GTX 650 Ti", DRIVER_NVIDIA_GEFORCE6, 1024},
1261 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660, "NVIDIA GeForce GTX 660", DRIVER_NVIDIA_GEFORCE6, 2048},
1262 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660M, "NVIDIA GeForce GTX 660M", DRIVER_NVIDIA_GEFORCE6, 2048},
1263 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660TI, "NVIDIA GeForce GTX 660 Ti", DRIVER_NVIDIA_GEFORCE6, 2048},
1264 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670, "NVIDIA GeForce GTX 670", DRIVER_NVIDIA_GEFORCE6, 2048},
1265 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670MX, "NVIDIA GeForce GTX 670MX", DRIVER_NVIDIA_GEFORCE6, 3072},
1266 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX680, "NVIDIA GeForce GTX 680", DRIVER_NVIDIA_GEFORCE6, 2048},
1267 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX750, "NVIDIA GeForce GTX 750", DRIVER_NVIDIA_GEFORCE6, 1024},
1268 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX750TI, "NVIDIA GeForce GTX 750 Ti", DRIVER_NVIDIA_GEFORCE6, 2048},
1269 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX760, "NVIDIA Geforce GTX 760", DRIVER_NVIDIA_GEFORCE6, 2048},
1270 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX765M, "NVIDIA GeForce GTX 765M", DRIVER_NVIDIA_GEFORCE6, 2048},
1271 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770M, "NVIDIA GeForce GTX 770M", DRIVER_NVIDIA_GEFORCE6, 3072},
1272 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770, "NVIDIA GeForce GTX 770", DRIVER_NVIDIA_GEFORCE6, 2048},
1273 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX780, "NVIDIA GeForce GTX 780", DRIVER_NVIDIA_GEFORCE6, 3072},
1274 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX780TI, "NVIDIA GeForce GTX 780 Ti", DRIVER_NVIDIA_GEFORCE6, 3072},
1276 /* AMD cards */
1277 {HW_VENDOR_AMD, CARD_AMD_RAGE_128PRO, "ATI Rage Fury", DRIVER_AMD_RAGE_128PRO, 16 },
1278 {HW_VENDOR_AMD, CARD_AMD_RADEON_7200, "ATI RADEON 7200 SERIES", DRIVER_AMD_R100, 32 },
1279 {HW_VENDOR_AMD, CARD_AMD_RADEON_8500, "ATI RADEON 8500 SERIES", DRIVER_AMD_R100, 64 },
1280 {HW_VENDOR_AMD, CARD_AMD_RADEON_9500, "ATI Radeon 9500", DRIVER_AMD_R300, 64 },
1281 {HW_VENDOR_AMD, CARD_AMD_RADEON_XPRESS_200M, "ATI RADEON XPRESS 200M Series", DRIVER_AMD_R300, 64 },
1282 {HW_VENDOR_AMD, CARD_AMD_RADEON_X700, "ATI Radeon X700 SE", DRIVER_AMD_R300, 128 },
1283 {HW_VENDOR_AMD, CARD_AMD_RADEON_X1600, "ATI Radeon X1600 Series", DRIVER_AMD_R300, 128 },
1284 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2350, "ATI Mobility Radeon HD 2350", DRIVER_AMD_R600, 256 },
1285 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2600, "ATI Mobility Radeon HD 2600", DRIVER_AMD_R600, 256 },
1286 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2900, "ATI Radeon HD 2900 XT", DRIVER_AMD_R600, 512 },
1287 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD3200, "ATI Radeon HD 3200 Graphics", DRIVER_AMD_R600, 128 },
1288 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4200M, "ATI Mobility Radeon HD 4200", DRIVER_AMD_R600, 256 },
1289 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4350, "ATI Radeon HD 4350", DRIVER_AMD_R600, 256 },
1290 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4600, "ATI Radeon HD 4600 Series", DRIVER_AMD_R600, 512 },
1291 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4700, "ATI Radeon HD 4700 Series", DRIVER_AMD_R600, 512 },
1292 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4800, "ATI Radeon HD 4800 Series", DRIVER_AMD_R600, 512 },
1293 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5400, "ATI Radeon HD 5400 Series", DRIVER_AMD_R600, 512 },
1294 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5600, "ATI Radeon HD 5600 Series", DRIVER_AMD_R600, 512 },
1295 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5700, "ATI Radeon HD 5700 Series", DRIVER_AMD_R600, 512 },
1296 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5800, "ATI Radeon HD 5800 Series", DRIVER_AMD_R600, 1024},
1297 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5900, "ATI Radeon HD 5900 Series", DRIVER_AMD_R600, 1024},
1298 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6300, "AMD Radeon HD 6300 series Graphics", DRIVER_AMD_R600, 1024},
1299 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6400, "AMD Radeon HD 6400 Series", DRIVER_AMD_R600, 1024},
1300 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6410D, "AMD Radeon HD 6410D", DRIVER_AMD_R600, 1024},
1301 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6550D, "AMD Radeon HD 6550D", DRIVER_AMD_R600, 1024},
1302 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600, "AMD Radeon HD 6600 Series", DRIVER_AMD_R600, 1024},
1303 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600M, "AMD Radeon HD 6600M Series", DRIVER_AMD_R600, 512 },
1304 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6700, "AMD Radeon HD 6700 Series", DRIVER_AMD_R600, 1024},
1305 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6800, "AMD Radeon HD 6800 Series", DRIVER_AMD_R600, 1024},
1306 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6900, "AMD Radeon HD 6900 Series", DRIVER_AMD_R600, 2048},
1307 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7700, "AMD Radeon HD 7700 Series", DRIVER_AMD_R600, 1024},
1308 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7800, "AMD Radeon HD 7800 Series", DRIVER_AMD_R600, 2048},
1309 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7900, "AMD Radeon HD 7900 Series", DRIVER_AMD_R600, 2048},
1311 /* VMware */
1312 {HW_VENDOR_VMWARE, CARD_VMWARE_SVGA3D, "VMware SVGA 3D (Microsoft Corporation - WDDM)", DRIVER_VMWARE, 1024},
1314 /* Intel cards */
1315 {HW_VENDOR_INTEL, CARD_INTEL_830M, "Intel(R) 82830M Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1316 {HW_VENDOR_INTEL, CARD_INTEL_855GM, "Intel(R) 82852/82855 GM/GME Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1317 {HW_VENDOR_INTEL, CARD_INTEL_845G, "Intel(R) 845G", DRIVER_INTEL_GMA800, 32 },
1318 {HW_VENDOR_INTEL, CARD_INTEL_865G, "Intel(R) 82865G Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1319 {HW_VENDOR_INTEL, CARD_INTEL_915G, "Intel(R) 82915G/GV/910GL Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
1320 {HW_VENDOR_INTEL, CARD_INTEL_E7221G, "Intel(R) E7221G", DRIVER_INTEL_GMA900, 64 },
1321 {HW_VENDOR_INTEL, CARD_INTEL_915GM, "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
1322 {HW_VENDOR_INTEL, CARD_INTEL_945G, "Intel(R) 945G", DRIVER_INTEL_GMA950, 64 },
1323 {HW_VENDOR_INTEL, CARD_INTEL_945GM, "Mobile Intel(R) 945GM Express Chipset Family", DRIVER_INTEL_GMA950, 64 },
1324 {HW_VENDOR_INTEL, CARD_INTEL_945GME, "Intel(R) 945GME", DRIVER_INTEL_GMA950, 64 },
1325 {HW_VENDOR_INTEL, CARD_INTEL_Q35, "Intel(R) Q35", DRIVER_INTEL_GMA950, 64 },
1326 {HW_VENDOR_INTEL, CARD_INTEL_G33, "Intel(R) G33", DRIVER_INTEL_GMA950, 64 },
1327 {HW_VENDOR_INTEL, CARD_INTEL_Q33, "Intel(R) Q33", DRIVER_INTEL_GMA950, 64 },
1328 {HW_VENDOR_INTEL, CARD_INTEL_PNVG, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
1329 {HW_VENDOR_INTEL, CARD_INTEL_PNVM, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
1330 {HW_VENDOR_INTEL, CARD_INTEL_965Q, "Intel(R) 965Q", DRIVER_INTEL_GMA3000, 128},
1331 {HW_VENDOR_INTEL, CARD_INTEL_965G, "Intel(R) 965G", DRIVER_INTEL_GMA3000, 128},
1332 {HW_VENDOR_INTEL, CARD_INTEL_946GZ, "Intel(R) 946GZ", DRIVER_INTEL_GMA3000, 128},
1333 {HW_VENDOR_INTEL, CARD_INTEL_965GM, "Mobile Intel(R) 965 Express Chipset Family", DRIVER_INTEL_GMA3000, 128},
1334 {HW_VENDOR_INTEL, CARD_INTEL_965GME, "Intel(R) 965GME", DRIVER_INTEL_GMA3000, 128},
1335 {HW_VENDOR_INTEL, CARD_INTEL_GM45, "Mobile Intel(R) GM45 Express Chipset Family", DRIVER_INTEL_GMA3000, 512},
1336 {HW_VENDOR_INTEL, CARD_INTEL_IGD, "Intel(R) Integrated Graphics Device", DRIVER_INTEL_GMA3000, 512},
1337 {HW_VENDOR_INTEL, CARD_INTEL_G45, "Intel(R) G45/G43", DRIVER_INTEL_GMA3000, 512},
1338 {HW_VENDOR_INTEL, CARD_INTEL_Q45, "Intel(R) Q45/Q43", DRIVER_INTEL_GMA3000, 512},
1339 {HW_VENDOR_INTEL, CARD_INTEL_G41, "Intel(R) G41", DRIVER_INTEL_GMA3000, 512},
1340 {HW_VENDOR_INTEL, CARD_INTEL_B43, "Intel(R) B43", DRIVER_INTEL_GMA3000, 512},
1341 {HW_VENDOR_INTEL, CARD_INTEL_ILKD, "Intel(R) Ironlake Desktop", DRIVER_INTEL_GMA3000, 1024},
1342 {HW_VENDOR_INTEL, CARD_INTEL_ILKM, "Intel(R) Ironlake Mobile", DRIVER_INTEL_GMA3000, 1024},
1343 {HW_VENDOR_INTEL, CARD_INTEL_SNBD, "Intel(R) Sandybridge Desktop", DRIVER_INTEL_GMA3000, 1024},
1344 {HW_VENDOR_INTEL, CARD_INTEL_SNBM, "Intel(R) Sandybridge Mobile", DRIVER_INTEL_GMA3000, 1024},
1345 {HW_VENDOR_INTEL, CARD_INTEL_SNBS, "Intel(R) Sandybridge Server", DRIVER_INTEL_GMA3000, 1024},
1346 {HW_VENDOR_INTEL, CARD_INTEL_IVBD, "Intel(R) Ivybridge Desktop", DRIVER_INTEL_GMA3000, 1024},
1347 {HW_VENDOR_INTEL, CARD_INTEL_IVBM, "Intel(R) Ivybridge Mobile", DRIVER_INTEL_GMA3000, 1024},
1348 {HW_VENDOR_INTEL, CARD_INTEL_IVBS, "Intel(R) Ivybridge Server", DRIVER_INTEL_GMA3000, 1024},
1349 {HW_VENDOR_INTEL, CARD_INTEL_HWM, "Intel(R) Haswell Mobile", DRIVER_INTEL_GMA3000, 1024},
1352 static const struct driver_version_information *get_driver_version_info(enum wined3d_display_driver driver,
1353 enum wined3d_driver_model driver_model)
1355 unsigned int i;
1357 TRACE("Looking up version info for driver=%d driver_model=%d\n", driver, driver_model);
1358 for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++)
1360 const struct driver_version_information *entry = &driver_version_table[i];
1362 if (entry->driver == driver && entry->driver_model == driver_model)
1364 TRACE("Found driver \"%s\", version %u, subversion %u, build %u.\n",
1365 entry->driver_name, entry->version, entry->subversion, entry->build);
1366 return entry;
1369 return NULL;
1372 static const struct gpu_description *get_gpu_description(enum wined3d_pci_vendor vendor,
1373 enum wined3d_pci_device device)
1375 unsigned int i;
1377 for (i = 0; i < (sizeof(gpu_description_table) / sizeof(*gpu_description_table)); ++i)
1379 if (vendor == gpu_description_table[i].vendor && device == gpu_description_table[i].card)
1380 return &gpu_description_table[i];
1383 return NULL;
1386 static void init_driver_info(struct wined3d_driver_info *driver_info,
1387 enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
1389 OSVERSIONINFOW os_version;
1390 WORD driver_os_version;
1391 enum wined3d_display_driver driver;
1392 enum wined3d_driver_model driver_model;
1393 const struct driver_version_information *version_info;
1394 const struct gpu_description *gpu_desc;
1396 if (driver_info->vendor != PCI_VENDOR_NONE || driver_info->device != PCI_DEVICE_NONE)
1398 static unsigned int once;
1400 TRACE("GPU override %04x:%04x.\n", wined3d_settings.pci_vendor_id, wined3d_settings.pci_device_id);
1402 driver_info->vendor = wined3d_settings.pci_vendor_id;
1403 if (driver_info->vendor == PCI_VENDOR_NONE)
1404 driver_info->vendor = vendor;
1406 driver_info->device = wined3d_settings.pci_device_id;
1407 if (driver_info->device == PCI_DEVICE_NONE)
1408 driver_info->device = device;
1410 if (get_gpu_description(driver_info->vendor, driver_info->device))
1412 vendor = driver_info->vendor;
1413 device = driver_info->device;
1415 else if (!once++)
1416 ERR_(winediag)("Invalid GPU override %04x:%04x specified, ignoring.\n",
1417 driver_info->vendor, driver_info->device);
1420 driver_info->vendor = vendor;
1421 driver_info->device = device;
1423 memset(&os_version, 0, sizeof(os_version));
1424 os_version.dwOSVersionInfoSize = sizeof(os_version);
1425 if (!GetVersionExW(&os_version))
1427 ERR("Failed to get OS version, reporting 2000/XP.\n");
1428 driver_os_version = 6;
1429 driver_model = DRIVER_MODEL_NT5X;
1431 else
1433 TRACE("OS version %u.%u.\n", os_version.dwMajorVersion, os_version.dwMinorVersion);
1434 switch (os_version.dwMajorVersion)
1436 case 4:
1437 /* If needed we could distinguish between 9x and NT4, but this code won't make
1438 * sense for NT4 since it had no way to obtain this info through DirectDraw 3.0.
1440 driver_os_version = 4;
1441 driver_model = DRIVER_MODEL_WIN9X;
1442 break;
1444 case 5:
1445 driver_os_version = 6;
1446 driver_model = DRIVER_MODEL_NT5X;
1447 break;
1449 case 6:
1450 if (os_version.dwMinorVersion == 0)
1452 driver_os_version = 7;
1453 driver_model = DRIVER_MODEL_NT6X;
1455 else if (os_version.dwMinorVersion == 1)
1457 driver_os_version = 8;
1458 driver_model = DRIVER_MODEL_NT6X;
1460 else
1462 if (os_version.dwMinorVersion > 2)
1464 FIXME("Unhandled OS version %u.%u, reporting Win 8.\n",
1465 os_version.dwMajorVersion, os_version.dwMinorVersion);
1467 driver_os_version = 9;
1468 driver_model = DRIVER_MODEL_NT6X;
1470 break;
1472 default:
1473 FIXME("Unhandled OS version %u.%u, reporting 2000/XP.\n",
1474 os_version.dwMajorVersion, os_version.dwMinorVersion);
1475 driver_os_version = 6;
1476 driver_model = DRIVER_MODEL_NT5X;
1477 break;
1481 if ((gpu_desc = get_gpu_description(driver_info->vendor, driver_info->device)))
1483 driver_info->description = gpu_desc->description;
1484 driver_info->vidmem = gpu_desc->vidmem * 1024 * 1024;
1485 driver = gpu_desc->driver;
1487 else
1489 ERR("Card %04x:%04x not found in driver DB.\n", vendor, device);
1490 driver_info->description = "Direct3D HAL";
1491 driver_info->vidmem = WINE_DEFAULT_VIDMEM;
1492 driver = DRIVER_UNKNOWN;
1495 if (wined3d_settings.emulated_textureram)
1497 TRACE("Overriding amount of video memory with %u bytes.\n", wined3d_settings.emulated_textureram);
1498 driver_info->vidmem = wined3d_settings.emulated_textureram;
1501 /* Try to obtain driver version information for the current Windows version. This fails in
1502 * some cases:
1503 * - the gpu is not available on the currently selected OS version:
1504 * - Geforce GTX480 on Win98. When running applications in compatibility mode on Windows,
1505 * version information for the current Windows version is returned instead of faked info.
1506 * We do the same and assume the default Windows version to emulate is WinXP.
1508 * - Videocard is a Riva TNT but winver is set to win7 (there are no drivers for this beast)
1509 * For now return the XP driver info. Perhaps later on we should return VESA.
1511 * - the gpu is not in our database (can happen when the user overrides the vendor_id / device_id)
1512 * This could be an indication that our database is not up to date, so this should be fixed.
1514 if ((version_info = get_driver_version_info(driver, driver_model))
1515 || (version_info = get_driver_version_info(driver, DRIVER_MODEL_NT5X)))
1517 driver_info->name = version_info->driver_name;
1518 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, version_info->version);
1519 driver_info->version_low = MAKEDWORD_VERSION(version_info->subversion, version_info->build);
1521 else
1523 ERR("No driver version info found for device %04x:%04x, driver model %#x.\n",
1524 vendor, device, driver_model);
1525 driver_info->name = "Display";
1526 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, 15);
1527 driver_info->version_low = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
1530 TRACE("Reporting (fake) driver version 0x%08x-0x%08x.\n",
1531 driver_info->version_high, driver_info->version_low);
1534 /* Context activation is done by the caller. */
1535 static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer,
1536 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
1538 unsigned int i;
1540 for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
1542 if (!quirk_table[i].match(gl_info, gl_renderer, gl_vendor, card_vendor, device)) continue;
1543 TRACE("Applying driver quirk \"%s\".\n", quirk_table[i].description);
1544 quirk_table[i].apply(gl_info);
1547 /* Find out if PBOs work as they are supposed to. */
1548 test_pbo_functionality(gl_info);
1551 static DWORD wined3d_parse_gl_version(const char *gl_version)
1553 const char *ptr = gl_version;
1554 int major, minor;
1556 major = atoi(ptr);
1557 if (major <= 0)
1558 ERR("Invalid OpenGL major version %d.\n", major);
1560 while (isdigit(*ptr)) ++ptr;
1561 if (*ptr++ != '.')
1562 ERR("Invalid OpenGL version string %s.\n", debugstr_a(gl_version));
1564 minor = atoi(ptr);
1566 TRACE("Found OpenGL version %d.%d.\n", major, minor);
1568 return MAKEDWORD_VERSION(major, minor);
1571 static enum wined3d_gl_vendor wined3d_guess_gl_vendor(const struct wined3d_gl_info *gl_info,
1572 const char *gl_vendor_string, const char *gl_renderer)
1575 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
1576 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
1577 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
1579 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
1580 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
1581 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
1582 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
1583 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
1584 * the chance that other implementations support them is rather small since Win32 QuickTime uses
1585 * DirectDraw, not OpenGL. */
1586 if (gl_info->supported[APPLE_FENCE]
1587 && gl_info->supported[APPLE_CLIENT_STORAGE]
1588 && gl_info->supported[APPLE_YCBCR_422])
1589 return GL_VENDOR_APPLE;
1591 if (strstr(gl_vendor_string, "NVIDIA"))
1592 return GL_VENDOR_NVIDIA;
1594 if (strstr(gl_vendor_string, "ATI"))
1595 return GL_VENDOR_FGLRX;
1597 if (strstr(gl_vendor_string, "Mesa")
1598 || strstr(gl_vendor_string, "X.Org")
1599 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1600 || strstr(gl_vendor_string, "DRI R300 Project")
1601 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1602 || strstr(gl_vendor_string, "VMware, Inc.")
1603 || strstr(gl_vendor_string, "Intel")
1604 || strstr(gl_renderer, "Mesa")
1605 || strstr(gl_renderer, "Gallium")
1606 || strstr(gl_renderer, "Intel"))
1607 return GL_VENDOR_MESA;
1609 FIXME("Received unrecognized GL_VENDOR %s. Returning GL_VENDOR_UNKNOWN.\n",
1610 debugstr_a(gl_vendor_string));
1612 return GL_VENDOR_UNKNOWN;
1615 static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_string, const char *gl_renderer)
1617 if (strstr(gl_vendor_string, "NVIDIA")
1618 || strstr(gl_vendor_string, "Nouveau")
1619 || strstr(gl_vendor_string, "nouveau"))
1620 return HW_VENDOR_NVIDIA;
1622 if (strstr(gl_vendor_string, "ATI")
1623 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1624 || strstr(gl_vendor_string, "X.Org R300 Project")
1625 || strstr(gl_renderer, "AMD")
1626 || strstr(gl_renderer, "R100")
1627 || strstr(gl_renderer, "R200")
1628 || strstr(gl_renderer, "R300")
1629 || strstr(gl_renderer, "R600")
1630 || strstr(gl_renderer, "R700"))
1631 return HW_VENDOR_AMD;
1633 if (strstr(gl_vendor_string, "Intel(R)")
1634 /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */
1635 || strstr(gl_renderer, "Intel")
1636 || strstr(gl_renderer, "i915")
1637 || strstr(gl_vendor_string, "Intel Inc."))
1638 return HW_VENDOR_INTEL;
1640 if (strstr(gl_renderer, "SVGA3D"))
1641 return HW_VENDOR_VMWARE;
1643 if (strstr(gl_vendor_string, "Mesa")
1644 || strstr(gl_vendor_string, "Brian Paul")
1645 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1646 || strstr(gl_vendor_string, "VMware, Inc."))
1647 return HW_VENDOR_SOFTWARE;
1649 FIXME("Received unrecognized GL_VENDOR %s. Returning HW_VENDOR_NVIDIA.\n", debugstr_a(gl_vendor_string));
1651 return HW_VENDOR_NVIDIA;
1654 static UINT d3d_level_from_gl_info(const struct wined3d_gl_info *gl_info)
1656 UINT level = 0;
1658 if (gl_info->supported[ARB_MULTITEXTURE])
1659 level = 6;
1660 if (gl_info->supported[ARB_TEXTURE_COMPRESSION]
1661 && gl_info->supported[ARB_TEXTURE_CUBE_MAP]
1662 && gl_info->supported[ARB_TEXTURE_ENV_DOT3])
1663 level = 7;
1664 if (level == 7 && gl_info->supported[ARB_MULTISAMPLE]
1665 && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
1666 level = 8;
1667 if (level == 8 && gl_info->supported[ARB_FRAGMENT_PROGRAM]
1668 && gl_info->supported[ARB_VERTEX_SHADER])
1669 level = 9;
1670 if (level == 9 && (gl_info->supported[EXT_GPU_SHADER4]
1671 || gl_info->glsl_version >= MAKEDWORD_VERSION(1, 30)))
1672 level = 10;
1674 return level;
1677 static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl_info *gl_info,
1678 const char *gl_renderer)
1680 UINT d3d_level = d3d_level_from_gl_info(gl_info);
1681 unsigned int i;
1683 if (d3d_level >= 10)
1685 static const struct
1687 const char *renderer;
1688 enum wined3d_pci_device id;
1690 cards[] =
1692 {"GTX 780 Ti", CARD_NVIDIA_GEFORCE_GTX780TI}, /* Geforce 700 - highend */
1693 {"GTX 780", CARD_NVIDIA_GEFORCE_GTX780}, /* Geforce 700 - highend */
1694 {"GTX 770M", CARD_NVIDIA_GEFORCE_GTX770M}, /* Geforce 700 - midend high mobile */
1695 {"GTX 770", CARD_NVIDIA_GEFORCE_GTX770}, /* Geforce 700 - highend */
1696 {"GTX 765M", CARD_NVIDIA_GEFORCE_GTX765M}, /* Geforce 700 - midend high mobile */
1697 {"GTX 760", CARD_NVIDIA_GEFORCE_GTX760}, /* Geforce 700 - midend high */
1698 {"GTX 750 Ti", CARD_NVIDIA_GEFORCE_GTX750TI}, /* Geforce 700 - midend */
1699 {"GTX 750", CARD_NVIDIA_GEFORCE_GTX750}, /* Geforce 700 - midend */
1700 {"GTX 680", CARD_NVIDIA_GEFORCE_GTX680}, /* Geforce 600 - highend */
1701 {"GTX 670MX", CARD_NVIDIA_GEFORCE_GTX670MX}, /* Geforce 600 - highend */
1702 {"GTX 670", CARD_NVIDIA_GEFORCE_GTX670}, /* Geforce 600 - midend high */
1703 {"GTX 660 Ti", CARD_NVIDIA_GEFORCE_GTX660TI}, /* Geforce 600 - midend high */
1704 {"GTX 660M", CARD_NVIDIA_GEFORCE_GTX660M}, /* Geforce 600 - midend high mobile */
1705 {"GTX 660", CARD_NVIDIA_GEFORCE_GTX660}, /* Geforce 600 - midend high */
1706 {"GTX 650 Ti", CARD_NVIDIA_GEFORCE_GTX650TI}, /* Geforce 600 - lowend */
1707 {"GTX 650", CARD_NVIDIA_GEFORCE_GTX650}, /* Geforce 600 - lowend */
1708 {"GT 650M", CARD_NVIDIA_GEFORCE_GT650M}, /* Geforce 600 - midend mobile */
1709 {"GT 640M", CARD_NVIDIA_GEFORCE_GT640M}, /* Geforce 600 - midend mobile */
1710 {"GT 630M", CARD_NVIDIA_GEFORCE_GT630M}, /* Geforce 600 - midend mobile */
1711 {"GT 630", CARD_NVIDIA_GEFORCE_GT630}, /* Geforce 600 - lowend */
1712 {"GT 610", CARD_NVIDIA_GEFORCE_GT610}, /* Geforce 600 - lowend */
1713 {"GTX 580", CARD_NVIDIA_GEFORCE_GTX580}, /* Geforce 500 - highend */
1714 {"GTX 570", CARD_NVIDIA_GEFORCE_GTX570}, /* Geforce 500 - midend high */
1715 {"GTX 560 Ti", CARD_NVIDIA_GEFORCE_GTX560TI}, /* Geforce 500 - midend */
1716 {"GTX 560", CARD_NVIDIA_GEFORCE_GTX560}, /* Geforce 500 - midend */
1717 {"GT 555M", CARD_NVIDIA_GEFORCE_GT555M}, /* Geforce 500 - midend mobile */
1718 {"GTX 550 Ti", CARD_NVIDIA_GEFORCE_GTX550}, /* Geforce 500 - midend */
1719 {"GT 540M", CARD_NVIDIA_GEFORCE_GT540M}, /* Geforce 500 - midend mobile */
1720 {"GT 520", CARD_NVIDIA_GEFORCE_GT520}, /* Geforce 500 - lowend */
1721 {"GTX 480", CARD_NVIDIA_GEFORCE_GTX480}, /* Geforce 400 - highend */
1722 {"GTX 470", CARD_NVIDIA_GEFORCE_GTX470}, /* Geforce 400 - midend high */
1723 {"GTX 465", CARD_NVIDIA_GEFORCE_GTX465}, /* Geforce 400 - midend */
1724 {"GTX 460M", CARD_NVIDIA_GEFORCE_GTX460M}, /* Geforce 400 - highend mobile */
1725 {"GTX 460", CARD_NVIDIA_GEFORCE_GTX460}, /* Geforce 400 - midend */
1726 {"GTS 450", CARD_NVIDIA_GEFORCE_GTS450}, /* Geforce 400 - midend low */
1727 {"GT 440", CARD_NVIDIA_GEFORCE_GT440}, /* Geforce 400 - lowend */
1728 {"GT 430", CARD_NVIDIA_GEFORCE_GT430}, /* Geforce 400 - lowend */
1729 {"GT 420", CARD_NVIDIA_GEFORCE_GT420}, /* Geforce 400 - lowend */
1730 {"410M", CARD_NVIDIA_GEFORCE_410M}, /* Geforce 400 - lowend mobile */
1731 {"GT 330", CARD_NVIDIA_GEFORCE_GT330}, /* Geforce 300 - highend */
1732 {"GTS 360M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1733 {"GTS 350M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1734 {"GT 330M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1735 {"GT 325M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1736 {"GT 320M", CARD_NVIDIA_GEFORCE_GT320M}, /* Geforce 300 - midend mobile */
1737 {"320M", CARD_NVIDIA_GEFORCE_320M}, /* Geforce 300 - midend mobile */
1738 {"315M", CARD_NVIDIA_GEFORCE_315M}, /* Geforce 300 - midend mobile */
1739 {"GTX 295", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1740 {"GTX 285", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1741 {"GTX 280", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1742 {"GTX 275", CARD_NVIDIA_GEFORCE_GTX275}, /* Geforce 200 - midend high */
1743 {"GTX 260", CARD_NVIDIA_GEFORCE_GTX260}, /* Geforce 200 - midend */
1744 {"GT 240", CARD_NVIDIA_GEFORCE_GT240}, /* Geforce 200 - midend */
1745 {"GT 220", CARD_NVIDIA_GEFORCE_GT220}, /* Geforce 200 - lowend */
1746 {"Geforce 310", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1747 {"Geforce 305", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1748 {"Geforce 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1749 {"G 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1750 {"GTS 250", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1751 {"GTS 150", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1752 {"9800", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1753 {"GT 140", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1754 {"9600", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1755 {"GT 130", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1756 {"GT 120", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1757 {"9500", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1758 {"9400M", CARD_NVIDIA_GEFORCE_9400M}, /* Geforce 9 - lowend */
1759 {"9400", CARD_NVIDIA_GEFORCE_9400GT}, /* Geforce 9 - lowend */
1760 {"9300", CARD_NVIDIA_GEFORCE_9300}, /* Geforce 9 - lowend low */
1761 {"9200", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1762 {"9100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1763 {"G 100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1764 {"8800 GTX", CARD_NVIDIA_GEFORCE_8800GTX}, /* Geforce 8 - highend high */
1765 {"8800", CARD_NVIDIA_GEFORCE_8800GTS}, /* Geforce 8 - highend */
1766 {"8600M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1767 {"8600 M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1768 {"8700", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1769 {"8600", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1770 {"8500", CARD_NVIDIA_GEFORCE_8400GS}, /* Geforce 8 - mid-lowend */
1771 {"8400", CARD_NVIDIA_GEFORCE_8400GS}, /* Geforce 8 - mid-lowend */
1772 {"8300", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1773 {"8200", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1774 {"8100", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1777 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1779 if (strstr(gl_renderer, cards[i].renderer))
1780 return cards[i].id;
1782 return PCI_DEVICE_NONE;
1785 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1786 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1788 if (d3d_level >= 9 && gl_info->supported[NV_VERTEX_PROGRAM3])
1790 static const struct
1792 const char *renderer;
1793 enum wined3d_pci_device id;
1795 cards[] =
1797 {"Quadro FX 5", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1798 {"Quadro FX 4", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1799 {"7950", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1800 {"7900", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1801 {"7800", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1802 {"7700", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1803 {"7600", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1804 {"7400", CARD_NVIDIA_GEFORCE_7400}, /* Geforce 7 - lower medium */
1805 {"7300", CARD_NVIDIA_GEFORCE_7300}, /* Geforce 7 - lowend */
1806 {"6800", CARD_NVIDIA_GEFORCE_6800}, /* Geforce 6 - highend */
1807 {"6700", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1808 {"6610", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1809 {"6600", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1812 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1814 if (strstr(gl_renderer, cards[i].renderer))
1815 return cards[i].id;
1817 return PCI_DEVICE_NONE;
1820 if (d3d_level >= 9)
1822 /* GeforceFX - highend */
1823 if (strstr(gl_renderer, "5800")
1824 || strstr(gl_renderer, "5900")
1825 || strstr(gl_renderer, "5950")
1826 || strstr(gl_renderer, "Quadro FX"))
1828 return CARD_NVIDIA_GEFORCEFX_5800;
1831 /* GeforceFX - midend */
1832 if (strstr(gl_renderer, "5600")
1833 || strstr(gl_renderer, "5650")
1834 || strstr(gl_renderer, "5700")
1835 || strstr(gl_renderer, "5750"))
1837 return CARD_NVIDIA_GEFORCEFX_5600;
1840 /* GeforceFX - lowend */
1841 return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1844 if (d3d_level >= 8)
1846 if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
1848 return CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1851 return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1854 if (d3d_level >= 7)
1856 if (strstr(gl_renderer, "GeForce4 MX"))
1858 return CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1861 if (strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
1863 return CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1866 if (strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
1868 return CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1871 return CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1874 if (strstr(gl_renderer, "TNT2"))
1876 return CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1879 return CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1882 static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_info *gl_info,
1883 const char *gl_renderer)
1885 UINT d3d_level = d3d_level_from_gl_info(gl_info);
1887 /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1889 * Beware: renderer string do not match exact card model,
1890 * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1891 if (d3d_level >= 10)
1893 unsigned int i;
1895 static const struct
1897 const char *renderer;
1898 enum wined3d_pci_device id;
1900 cards[] =
1902 /* Southern Islands */
1903 {"HD 7900", CARD_AMD_RADEON_HD7900},
1904 {"HD 7800", CARD_AMD_RADEON_HD7800},
1905 {"HD 7700", CARD_AMD_RADEON_HD7700},
1906 /* Northern Islands */
1907 {"HD 6970", CARD_AMD_RADEON_HD6900},
1908 {"HD 6900", CARD_AMD_RADEON_HD6900},
1909 {"HD 6800", CARD_AMD_RADEON_HD6800},
1910 {"HD 6770M",CARD_AMD_RADEON_HD6600M},
1911 {"HD 6750M",CARD_AMD_RADEON_HD6600M},
1912 {"HD 6700", CARD_AMD_RADEON_HD6700},
1913 {"HD 6670", CARD_AMD_RADEON_HD6600},
1914 {"HD 6630M",CARD_AMD_RADEON_HD6600M},
1915 {"HD 6600M",CARD_AMD_RADEON_HD6600M},
1916 {"HD 6600", CARD_AMD_RADEON_HD6600},
1917 {"HD 6570", CARD_AMD_RADEON_HD6600},
1918 {"HD 6500M",CARD_AMD_RADEON_HD6600M},
1919 {"HD 6500", CARD_AMD_RADEON_HD6600},
1920 {"HD 6400", CARD_AMD_RADEON_HD6400},
1921 {"HD 6300", CARD_AMD_RADEON_HD6300},
1922 {"HD 6200", CARD_AMD_RADEON_HD6300},
1923 /* Evergreen */
1924 {"HD 5870", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS PRO */
1925 {"HD 5850", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS XT */
1926 {"HD 5800", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS HD58xx generic renderer string */
1927 {"HD 5770", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER XT */
1928 {"HD 5750", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER LE */
1929 {"HD 5700", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER HD57xx generic renderer string */
1930 {"HD 5670", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD XT */
1931 {"HD 5570", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD PRO mapped to HD5600 series */
1932 {"HD 5550", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD LE mapped to HD5600 series */
1933 {"HD 5450", CARD_AMD_RADEON_HD5400}, /* Radeon EG CEDAR PRO */
1934 {"HD 5000", CARD_AMD_RADEON_HD5600}, /* Defaulting to HD 5600 */
1935 /* R700 */
1936 {"HD 4890", CARD_AMD_RADEON_HD4800}, /* Radeon RV790 */
1937 {"HD 4870", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1938 {"HD 4850", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1939 {"HD 4830", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
1940 {"HD 4800", CARD_AMD_RADEON_HD4800}, /* Radeon RV7xx HD48xx generic renderer string */
1941 {"HD 4770", CARD_AMD_RADEON_HD4700}, /* Radeon RV740 */
1942 {"HD 4700", CARD_AMD_RADEON_HD4700}, /* Radeon RV7xx HD47xx generic renderer string */
1943 {"HD 4670", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1944 {"HD 4650", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1945 {"HD 4600", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
1946 {"HD 4550", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
1947 {"HD 4350", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
1948 /* R600/R700 integrated */
1949 {"HD 4200M", CARD_AMD_RADEON_HD4200M},
1950 {"HD 3300", CARD_AMD_RADEON_HD3200},
1951 {"HD 3200", CARD_AMD_RADEON_HD3200},
1952 {"HD 3100", CARD_AMD_RADEON_HD3200},
1953 /* R600 */
1954 {"HD 3870", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1955 {"HD 3850", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1956 {"HD 2900", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
1957 {"HD 3830", CARD_AMD_RADEON_HD2600}, /* China-only midend */
1958 {"HD 3690", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1959 {"HD 3650", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1960 {"HD 2600", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
1961 {"HD 3470", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1962 {"HD 3450", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1963 {"HD 3430", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1964 {"HD 3400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1965 {"HD 2400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1966 {"HD 2350", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
1969 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1971 if (strstr(gl_renderer, cards[i].renderer))
1972 return cards[i].id;
1974 return PCI_DEVICE_NONE;
1977 if (d3d_level >= 9)
1979 /* Radeon R5xx */
1980 if (strstr(gl_renderer, "X1600")
1981 || strstr(gl_renderer, "X1650")
1982 || strstr(gl_renderer, "X1800")
1983 || strstr(gl_renderer, "X1900")
1984 || strstr(gl_renderer, "X1950"))
1986 return CARD_AMD_RADEON_X1600;
1989 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300/X2500/HD2300 (lowend R5xx)
1990 * Note X2300/X2500/HD2300 are R5xx GPUs with a 2xxx naming but they are still DX9-only */
1991 if (strstr(gl_renderer, "X700")
1992 || strstr(gl_renderer, "X800")
1993 || strstr(gl_renderer, "X850")
1994 || strstr(gl_renderer, "X1300")
1995 || strstr(gl_renderer, "X1400")
1996 || strstr(gl_renderer, "X1450")
1997 || strstr(gl_renderer, "X1550")
1998 || strstr(gl_renderer, "X2300")
1999 || strstr(gl_renderer, "X2500")
2000 || strstr(gl_renderer, "HD 2300")
2003 return CARD_AMD_RADEON_X700;
2006 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400 MHz */
2007 if (strstr(gl_renderer, "Radeon Xpress"))
2009 return CARD_AMD_RADEON_XPRESS_200M;
2012 return PCI_DEVICE_NONE;
2015 static enum wined3d_pci_device select_card_intel(const struct wined3d_gl_info *gl_info,
2016 const char *gl_renderer)
2018 unsigned int i;
2020 static const struct
2022 const char *renderer;
2023 enum wined3d_pci_device id;
2025 cards[] =
2027 /* Haswell */
2028 {"Haswell Mobile", CARD_INTEL_HWM},
2029 /* Ivybridge */
2030 {"Ivybridge Server", CARD_INTEL_IVBS},
2031 {"Ivybridge Mobile", CARD_INTEL_IVBM},
2032 {"Ivybridge Desktop", CARD_INTEL_IVBD},
2033 /* Sandybridge */
2034 {"Sandybridge Server", CARD_INTEL_SNBS},
2035 {"Sandybridge Mobile", CARD_INTEL_SNBM},
2036 {"Sandybridge Desktop", CARD_INTEL_SNBD},
2037 /* Ironlake */
2038 {"Ironlake Mobile", CARD_INTEL_ILKM},
2039 {"Ironlake Desktop", CARD_INTEL_ILKD},
2040 /* G4x */
2041 {"B43", CARD_INTEL_B43},
2042 {"G41", CARD_INTEL_G41},
2043 {"G45", CARD_INTEL_G45},
2044 {"Q45", CARD_INTEL_Q45},
2045 {"Integrated Graphics Device", CARD_INTEL_IGD},
2046 {"GM45", CARD_INTEL_GM45},
2047 /* i965 */
2048 {"965GME", CARD_INTEL_965GME},
2049 {"965GM", CARD_INTEL_965GM},
2050 {"X3100", CARD_INTEL_965GM}, /* MacOS */
2051 {"946GZ", CARD_INTEL_946GZ},
2052 {"965G", CARD_INTEL_965G},
2053 {"965Q", CARD_INTEL_965Q},
2054 /* i945 */
2055 {"Pineview M", CARD_INTEL_PNVM},
2056 {"Pineview G", CARD_INTEL_PNVG},
2057 {"IGD", CARD_INTEL_PNVG},
2058 {"Q33", CARD_INTEL_Q33},
2059 {"G33", CARD_INTEL_G33},
2060 {"Q35", CARD_INTEL_Q35},
2061 {"945GME", CARD_INTEL_945GME},
2062 {"945GM", CARD_INTEL_945GM},
2063 {"GMA 950", CARD_INTEL_945GM}, /* MacOS */
2064 {"945G", CARD_INTEL_945G},
2065 /* i915 */
2066 {"915GM", CARD_INTEL_915GM},
2067 {"E7221G", CARD_INTEL_E7221G},
2068 {"915G", CARD_INTEL_915G},
2069 /* i8xx */
2070 {"865G", CARD_INTEL_865G},
2071 {"845G", CARD_INTEL_845G},
2072 {"855GM", CARD_INTEL_855GM},
2073 {"830M", CARD_INTEL_830M},
2076 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2078 if (strstr(gl_renderer, cards[i].renderer))
2079 return cards[i].id;
2082 return PCI_DEVICE_NONE;
2085 static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info *gl_info,
2086 const char *gl_renderer)
2088 unsigned int i;
2090 /* 20101109 - These are never returned by current Gallium radeon
2091 * drivers: R700, RV790, R680, RV535, RV516, R410, RS485, RV360, RV351.
2093 * These are returned but not handled: RC410, RV380. */
2094 static const struct
2096 const char *renderer;
2097 enum wined3d_pci_device id;
2099 cards[] =
2101 /* Southern Islands */
2102 {"TAHITI", CARD_AMD_RADEON_HD7900},
2103 {"PITCAIRN", CARD_AMD_RADEON_HD7800},
2104 {"CAPE VERDE", CARD_AMD_RADEON_HD7700},
2105 /* Northern Islands */
2106 {"CAYMAN", CARD_AMD_RADEON_HD6900},
2107 {"BARTS", CARD_AMD_RADEON_HD6800},
2108 {"TURKS", CARD_AMD_RADEON_HD6600},
2109 {"SUMO2", CARD_AMD_RADEON_HD6410D}, /* SUMO2 first, because we do a strstr(). */
2110 {"SUMO", CARD_AMD_RADEON_HD6550D},
2111 {"CAICOS", CARD_AMD_RADEON_HD6400},
2112 {"PALM", CARD_AMD_RADEON_HD6300},
2113 /* Evergreen */
2114 {"HEMLOCK", CARD_AMD_RADEON_HD5900},
2115 {"CYPRESS", CARD_AMD_RADEON_HD5800},
2116 {"JUNIPER", CARD_AMD_RADEON_HD5700},
2117 {"REDWOOD", CARD_AMD_RADEON_HD5600},
2118 {"CEDAR", CARD_AMD_RADEON_HD5400},
2119 /* R700 */
2120 {"R700", CARD_AMD_RADEON_HD4800},
2121 {"RV790", CARD_AMD_RADEON_HD4800},
2122 {"RV770", CARD_AMD_RADEON_HD4800},
2123 {"RV740", CARD_AMD_RADEON_HD4700},
2124 {"RV730", CARD_AMD_RADEON_HD4600},
2125 {"RV710", CARD_AMD_RADEON_HD4350},
2126 /* R600/R700 integrated */
2127 {"RS880", CARD_AMD_RADEON_HD4200M},
2128 {"RS780", CARD_AMD_RADEON_HD3200},
2129 /* R600 */
2130 {"R680", CARD_AMD_RADEON_HD2900},
2131 {"R600", CARD_AMD_RADEON_HD2900},
2132 {"RV670", CARD_AMD_RADEON_HD2900},
2133 {"RV635", CARD_AMD_RADEON_HD2600},
2134 {"RV630", CARD_AMD_RADEON_HD2600},
2135 {"RV620", CARD_AMD_RADEON_HD2350},
2136 {"RV610", CARD_AMD_RADEON_HD2350},
2137 /* R500 */
2138 {"R580", CARD_AMD_RADEON_X1600},
2139 {"R520", CARD_AMD_RADEON_X1600},
2140 {"RV570", CARD_AMD_RADEON_X1600},
2141 {"RV560", CARD_AMD_RADEON_X1600},
2142 {"RV535", CARD_AMD_RADEON_X1600},
2143 {"RV530", CARD_AMD_RADEON_X1600},
2144 {"RV516", CARD_AMD_RADEON_X700},
2145 {"RV515", CARD_AMD_RADEON_X700},
2146 /* R400 */
2147 {"R481", CARD_AMD_RADEON_X700},
2148 {"R480", CARD_AMD_RADEON_X700},
2149 {"R430", CARD_AMD_RADEON_X700},
2150 {"R423", CARD_AMD_RADEON_X700},
2151 {"R420", CARD_AMD_RADEON_X700},
2152 {"R410", CARD_AMD_RADEON_X700},
2153 {"RV410", CARD_AMD_RADEON_X700},
2154 /* Radeon Xpress - onboard, DX9b, Shader 2.0, 300-400 MHz */
2155 {"RS740", CARD_AMD_RADEON_XPRESS_200M},
2156 {"RS690", CARD_AMD_RADEON_XPRESS_200M},
2157 {"RS600", CARD_AMD_RADEON_XPRESS_200M},
2158 {"RS485", CARD_AMD_RADEON_XPRESS_200M},
2159 {"RS482", CARD_AMD_RADEON_XPRESS_200M},
2160 {"RS480", CARD_AMD_RADEON_XPRESS_200M},
2161 {"RS400", CARD_AMD_RADEON_XPRESS_200M},
2162 /* R300 */
2163 {"R360", CARD_AMD_RADEON_9500},
2164 {"R350", CARD_AMD_RADEON_9500},
2165 {"R300", CARD_AMD_RADEON_9500},
2166 {"RV370", CARD_AMD_RADEON_9500},
2167 {"RV360", CARD_AMD_RADEON_9500},
2168 {"RV351", CARD_AMD_RADEON_9500},
2169 {"RV350", CARD_AMD_RADEON_9500},
2172 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2174 if (strstr(gl_renderer, cards[i].renderer))
2175 return cards[i].id;
2178 return PCI_DEVICE_NONE;
2181 static enum wined3d_pci_device select_card_nvidia_mesa(const struct wined3d_gl_info *gl_info,
2182 const char *gl_renderer)
2184 unsigned int i;
2186 static const struct
2188 const char *renderer;
2189 enum wined3d_pci_device id;
2191 cards[] =
2193 /* Maxwell */
2194 {"NV117", CARD_NVIDIA_GEFORCE_GTX750},
2195 /* Kepler */
2196 {"NVF1", CARD_NVIDIA_GEFORCE_GTX780TI},
2197 {"NVF0", CARD_NVIDIA_GEFORCE_GTX780},
2198 {"NVE6", CARD_NVIDIA_GEFORCE_GTX770M},
2199 {"NVE4", CARD_NVIDIA_GEFORCE_GTX680},
2200 /* Fermi */
2201 {"NVD9", CARD_NVIDIA_GEFORCE_GT520},
2202 {"NVCF", CARD_NVIDIA_GEFORCE_GTX550},
2203 {"NVCE", CARD_NVIDIA_GEFORCE_GTX560},
2204 {"NVC8", CARD_NVIDIA_GEFORCE_GTX570},
2205 {"NVC4", CARD_NVIDIA_GEFORCE_GTX460},
2206 {"NVC3", CARD_NVIDIA_GEFORCE_GT440},
2207 {"NVC1", CARD_NVIDIA_GEFORCE_GT420},
2208 {"NVC0", CARD_NVIDIA_GEFORCE_GTX480},
2209 /* Tesla */
2210 {"NVAF", CARD_NVIDIA_GEFORCE_GT320M},
2211 {"NVAC", CARD_NVIDIA_GEFORCE_8200},
2212 {"NVAA", CARD_NVIDIA_GEFORCE_8200},
2213 {"NVA8", CARD_NVIDIA_GEFORCE_210},
2214 {"NVA5", CARD_NVIDIA_GEFORCE_GT220},
2215 {"NVA3", CARD_NVIDIA_GEFORCE_GT240},
2216 {"NVA0", CARD_NVIDIA_GEFORCE_GTX280},
2217 {"NV98", CARD_NVIDIA_GEFORCE_9200},
2218 {"NV96", CARD_NVIDIA_GEFORCE_9400GT},
2219 {"NV94", CARD_NVIDIA_GEFORCE_9600GT},
2220 {"NV92", CARD_NVIDIA_GEFORCE_9800GT},
2221 {"NV86", CARD_NVIDIA_GEFORCE_8500GT},
2222 {"NV84", CARD_NVIDIA_GEFORCE_8600GT},
2223 {"NV50", CARD_NVIDIA_GEFORCE_8800GTX},
2224 /* Curie */
2225 {"NV68", CARD_NVIDIA_GEFORCE_6200}, /* 7050 */
2226 {"NV67", CARD_NVIDIA_GEFORCE_6200}, /* 7000M */
2227 {"NV63", CARD_NVIDIA_GEFORCE_6200}, /* 7100 */
2228 {"NV4E", CARD_NVIDIA_GEFORCE_6200}, /* 6100 Go / 6150 Go */
2229 {"NV4C", CARD_NVIDIA_GEFORCE_6200}, /* 6150SE */
2230 {"NV4B", CARD_NVIDIA_GEFORCE_7600},
2231 {"NV4A", CARD_NVIDIA_GEFORCE_6200},
2232 {"NV49", CARD_NVIDIA_GEFORCE_7800GT}, /* 7900 */
2233 {"NV47", CARD_NVIDIA_GEFORCE_7800GT},
2234 {"NV46", CARD_NVIDIA_GEFORCE_7400},
2235 {"NV45", CARD_NVIDIA_GEFORCE_6800},
2236 {"NV44", CARD_NVIDIA_GEFORCE_6200},
2237 {"NV43", CARD_NVIDIA_GEFORCE_6600GT},
2238 {"NV42", CARD_NVIDIA_GEFORCE_6800},
2239 {"NV41", CARD_NVIDIA_GEFORCE_6800},
2240 {"NV40", CARD_NVIDIA_GEFORCE_6800},
2241 /* Rankine */
2242 {"NV38", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5950 Ultra */
2243 {"NV36", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5700/5750 */
2244 {"NV35", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5900 */
2245 {"NV34", CARD_NVIDIA_GEFORCEFX_5200},
2246 {"NV31", CARD_NVIDIA_GEFORCEFX_5600},
2247 {"NV30", CARD_NVIDIA_GEFORCEFX_5800},
2248 /* Kelvin */
2249 {"nv28", CARD_NVIDIA_GEFORCE4_TI4200},
2250 {"nv25", CARD_NVIDIA_GEFORCE4_TI4200},
2251 {"nv20", CARD_NVIDIA_GEFORCE3},
2252 /* Celsius */
2253 {"nv1F", CARD_NVIDIA_GEFORCE4_MX}, /* GF4 MX IGP */
2254 {"nv1A", CARD_NVIDIA_GEFORCE2}, /* GF2 IGP */
2255 {"nv18", CARD_NVIDIA_GEFORCE4_MX},
2256 {"nv17", CARD_NVIDIA_GEFORCE4_MX},
2257 {"nv16", CARD_NVIDIA_GEFORCE2},
2258 {"nv15", CARD_NVIDIA_GEFORCE2},
2259 {"nv11", CARD_NVIDIA_GEFORCE2_MX},
2260 {"nv10", CARD_NVIDIA_GEFORCE},
2261 /* Fahrenheit */
2262 {"nv05", CARD_NVIDIA_RIVA_TNT2},
2263 {"nv04", CARD_NVIDIA_RIVA_TNT},
2264 {"nv03", CARD_NVIDIA_RIVA_128},
2267 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2269 if (strstr(gl_renderer, cards[i].renderer))
2270 return cards[i].id;
2272 return PCI_DEVICE_NONE;
2275 static enum wined3d_pci_device select_card_vmware(const struct wined3d_gl_info *gl_info, const char *gl_renderer)
2277 if (strstr(gl_renderer, "SVGA3D"))
2278 return CARD_VMWARE_SVGA3D;
2280 return PCI_DEVICE_NONE;
2283 static const struct gl_vendor_selection
2285 enum wined3d_gl_vendor gl_vendor;
2286 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
2287 enum wined3d_pci_device (*select_card)(const struct wined3d_gl_info *gl_info, const char *gl_renderer);
2289 amd_gl_vendor_table[] =
2291 {GL_VENDOR_APPLE, "Apple OSX AMD/ATI binary driver", select_card_amd_binary},
2292 {GL_VENDOR_FGLRX, "AMD/ATI binary driver", select_card_amd_binary},
2293 {GL_VENDOR_MESA, "Mesa AMD/ATI driver", select_card_amd_mesa},
2295 nvidia_gl_vendor_table[] =
2297 {GL_VENDOR_APPLE, "Apple OSX NVidia binary driver", select_card_nvidia_binary},
2298 {GL_VENDOR_MESA, "Mesa Nouveau driver", select_card_nvidia_mesa},
2299 {GL_VENDOR_NVIDIA, "Nvidia binary driver", select_card_nvidia_binary},
2301 vmware_gl_vendor_table[] =
2303 {GL_VENDOR_MESA, "VMware driver", select_card_vmware},
2305 intel_gl_vendor_table[] =
2307 {GL_VENDOR_APPLE, "Apple OSX Intel binary driver", select_card_intel},
2308 {GL_VENDOR_MESA, "Mesa Intel driver", select_card_intel},
2311 static enum wined3d_pci_device select_card_fallback_nvidia(const struct wined3d_gl_info *gl_info)
2313 UINT d3d_level = d3d_level_from_gl_info(gl_info);
2314 if (d3d_level >= 10)
2315 return CARD_NVIDIA_GEFORCE_8800GTX;
2316 if (d3d_level >= 9 && gl_info->supported[NV_VERTEX_PROGRAM3])
2317 return CARD_NVIDIA_GEFORCE_6800;
2318 if (d3d_level >= 9)
2319 return CARD_NVIDIA_GEFORCEFX_5800;
2320 if (d3d_level >= 8)
2321 return CARD_NVIDIA_GEFORCE3;
2322 if (d3d_level >= 7)
2323 return CARD_NVIDIA_GEFORCE;
2324 if (d3d_level >= 6)
2325 return CARD_NVIDIA_RIVA_TNT;
2326 return CARD_NVIDIA_RIVA_128;
2329 static enum wined3d_pci_device select_card_fallback_amd(const struct wined3d_gl_info *gl_info)
2331 UINT d3d_level = d3d_level_from_gl_info(gl_info);
2332 if (d3d_level >= 10)
2333 return CARD_AMD_RADEON_HD2900;
2334 if (d3d_level >= 9)
2335 return CARD_AMD_RADEON_9500;
2336 if (d3d_level >= 8)
2337 return CARD_AMD_RADEON_8500;
2338 if (d3d_level >= 7)
2339 return CARD_AMD_RADEON_7200;
2340 return CARD_AMD_RAGE_128PRO;
2343 static enum wined3d_pci_device select_card_fallback_intel(const struct wined3d_gl_info *gl_info)
2345 UINT d3d_level = d3d_level_from_gl_info(gl_info);
2346 if (d3d_level >= 10)
2347 return CARD_INTEL_G45;
2348 return CARD_INTEL_915G;
2351 static enum wined3d_pci_device select_card_handler(const struct gl_vendor_selection *table,
2352 unsigned int table_size, enum wined3d_gl_vendor gl_vendor,
2353 const struct wined3d_gl_info *gl_info, const char *gl_renderer)
2355 unsigned int i;
2357 for (i = 0; i < table_size; ++i)
2359 if (table[i].gl_vendor != gl_vendor)
2360 continue;
2362 TRACE("Applying card selector \"%s\".\n", table[i].description);
2363 return table[i].select_card(gl_info, gl_renderer);
2365 FIXME("Couldn't find a suitable card selector for GL vendor %04x (using GL_RENDERER %s)\n",
2366 gl_vendor, debugstr_a(gl_renderer));
2368 return PCI_DEVICE_NONE;
2371 static const struct
2373 enum wined3d_pci_vendor card_vendor;
2374 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
2375 const struct gl_vendor_selection *gl_vendor_selection;
2376 unsigned int gl_vendor_count;
2377 enum wined3d_pci_device (*select_card_fallback)(const struct wined3d_gl_info *gl_info);
2379 card_vendor_table[] =
2381 {HW_VENDOR_AMD, "AMD", amd_gl_vendor_table,
2382 sizeof(amd_gl_vendor_table) / sizeof(*amd_gl_vendor_table),
2383 select_card_fallback_amd},
2384 {HW_VENDOR_NVIDIA, "Nvidia", nvidia_gl_vendor_table,
2385 sizeof(nvidia_gl_vendor_table) / sizeof(*nvidia_gl_vendor_table),
2386 select_card_fallback_nvidia},
2387 {HW_VENDOR_VMWARE, "VMware", vmware_gl_vendor_table,
2388 sizeof(vmware_gl_vendor_table) / sizeof(*vmware_gl_vendor_table),
2389 select_card_fallback_amd},
2390 {HW_VENDOR_INTEL, "Intel", intel_gl_vendor_table,
2391 sizeof(intel_gl_vendor_table) / sizeof(*intel_gl_vendor_table),
2392 select_card_fallback_intel},
2396 static enum wined3d_pci_device wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
2397 enum wined3d_gl_vendor *gl_vendor, enum wined3d_pci_vendor *card_vendor)
2399 /* A Direct3D device object contains the PCI id (vendor + device) of the
2400 * videocard which is used for rendering. Various applications use this
2401 * information to get a rough estimation of the features of the card and
2402 * some might use it for enabling 3d effects only on certain types of
2403 * videocards. In some cases games might even use it to work around bugs
2404 * which happen on certain videocards/driver combinations. The problem is
2405 * that OpenGL only exposes a rendering string containing the name of the
2406 * videocard and not the PCI id.
2408 * Various games depend on the PCI id, so somehow we need to provide one.
2409 * A simple option is to parse the renderer string and translate this to
2410 * the right PCI id. This is a lot of work because there are more than 200
2411 * GPUs just for Nvidia. Various cards share the same renderer string, so
2412 * the amount of code might be 'small' but there are quite a number of
2413 * exceptions which would make this a pain to maintain. Another way would
2414 * be to query the PCI id from the operating system (assuming this is the
2415 * videocard which is used for rendering which is not always the case).
2416 * This would work but it is not very portable. Second it would not work
2417 * well in, let's say, a remote X situation in which the amount of 3d
2418 * features which can be used is limited.
2420 * As said most games only use the PCI id to get an indication of the
2421 * capabilities of the card. It doesn't really matter if the given id is
2422 * the correct one if we return the id of a card with similar 3d features.
2424 * The code below checks the OpenGL capabilities of a videocard and matches
2425 * that to a certain level of Direct3D functionality. Once a card passes
2426 * the Direct3D9 check, we know that the card (in case of Nvidia) is at
2427 * least a GeforceFX. To give a better estimate we do a basic check on the
2428 * renderer string but if that won't pass we return a default card. This
2429 * way is better than maintaining a full card database as even without a
2430 * full database we can return a card with similar features. Second the
2431 * size of the database can be made quite small because when you know what
2432 * type of 3d functionality a card has, you know to which GPU family the
2433 * GPU must belong. Because of this you only have to check a small part of
2434 * the renderer string to distinguish between different models from that
2435 * family.
2437 * The code also selects a default amount of video memory which we will
2438 * use for an estimation of the amount of free texture memory. In case of
2439 * real D3D the amount of texture memory includes video memory and system
2440 * memory (to be specific AGP memory or in case of PCIE TurboCache /
2441 * HyperMemory). We don't know how much system memory can be addressed by
2442 * the system but we can make a reasonable estimation about the amount of
2443 * video memory. If the value is slightly wrong it doesn't matter as we
2444 * didn't include AGP-like memory which makes the amount of addressable
2445 * memory higher and second OpenGL isn't that critical it moves to system
2446 * memory behind our backs if really needed. Note that the amount of video
2447 * memory can be overruled using a registry setting. */
2449 unsigned int i;
2450 enum wined3d_pci_device device;
2452 for (i = 0; i < (sizeof(card_vendor_table) / sizeof(*card_vendor_table)); ++i)
2454 if (card_vendor_table[i].card_vendor != *card_vendor)
2455 continue;
2457 TRACE("Applying card selector \"%s\".\n", card_vendor_table[i].description);
2458 device = select_card_handler(card_vendor_table[i].gl_vendor_selection,
2459 card_vendor_table[i].gl_vendor_count, *gl_vendor, gl_info, gl_renderer);
2460 if (device != PCI_DEVICE_NONE)
2461 return device;
2463 TRACE("Unrecognized renderer %s, falling back to default.\n", debugstr_a(gl_renderer));
2464 return card_vendor_table[i].select_card_fallback(gl_info);
2467 FIXME("No card selector available for card vendor %04x (using GL_RENDERER %s).\n",
2468 *card_vendor, debugstr_a(gl_renderer));
2470 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. */
2471 *card_vendor = HW_VENDOR_NVIDIA;
2472 return select_card_fallback_nvidia(gl_info);
2475 static const struct wined3d_vertex_pipe_ops *select_vertex_implementation(const struct wined3d_gl_info *gl_info,
2476 const struct wined3d_shader_backend_ops *shader_backend_ops)
2478 if (shader_backend_ops == &glsl_shader_backend)
2479 return &glsl_vertex_pipe;
2480 return &ffp_vertex_pipe;
2483 static const struct fragment_pipeline *select_fragment_implementation(const struct wined3d_gl_info *gl_info,
2484 const struct wined3d_shader_backend_ops *shader_backend_ops)
2486 if (shader_backend_ops == &glsl_shader_backend)
2487 return &glsl_fragment_pipe;
2488 if (shader_backend_ops == &arb_program_shader_backend && gl_info->supported[ARB_FRAGMENT_PROGRAM])
2489 return &arbfp_fragment_pipeline;
2490 if (gl_info->supported[ATI_FRAGMENT_SHADER])
2491 return &atifs_fragment_pipeline;
2492 if (gl_info->supported[NV_REGISTER_COMBINERS] && gl_info->supported[NV_TEXTURE_SHADER2])
2493 return &nvts_fragment_pipeline;
2494 if (gl_info->supported[NV_REGISTER_COMBINERS])
2495 return &nvrc_fragment_pipeline;
2496 return &ffp_fragment_pipeline;
2499 static const struct wined3d_shader_backend_ops *select_shader_backend(const struct wined3d_gl_info *gl_info)
2501 BOOL glsl = wined3d_settings.glslRequested && gl_info->glsl_version >= MAKEDWORD_VERSION(1, 20);
2503 if (glsl && gl_info->supported[ARB_FRAGMENT_SHADER])
2504 return &glsl_shader_backend;
2505 if (glsl && gl_info->supported[ARB_VERTEX_SHADER])
2507 /* Geforce4 cards support GLSL but for vertex shaders only. Further
2508 * its reported GLSL caps are wrong. This combined with the fact that
2509 * GLSL won't offer more features or performance, use ARB shaders only
2510 * on this card. */
2511 if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2])
2512 return &arb_program_shader_backend;
2513 return &glsl_shader_backend;
2515 if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_FRAGMENT_PROGRAM])
2516 return &arb_program_shader_backend;
2517 return &none_shader_backend;
2520 static const struct blit_shader *select_blit_implementation(const struct wined3d_gl_info *gl_info,
2521 const struct wined3d_shader_backend_ops *shader_backend_ops)
2523 if ((shader_backend_ops == &glsl_shader_backend
2524 || shader_backend_ops == &arb_program_shader_backend)
2525 && gl_info->supported[ARB_FRAGMENT_PROGRAM])
2526 return &arbfp_blit;
2527 return &ffp_blit;
2530 static void parse_extension_string(struct wined3d_gl_info *gl_info, const char *extensions,
2531 const struct wined3d_extension_map *map, UINT entry_count)
2533 while (*extensions)
2535 const char *start;
2536 size_t len;
2537 UINT i;
2539 while (isspace(*extensions))
2540 ++extensions;
2541 start = extensions;
2542 while (!isspace(*extensions) && *extensions)
2543 ++extensions;
2545 len = extensions - start;
2546 if (!len)
2547 continue;
2549 TRACE("- %s.\n", debugstr_an(start, len));
2551 for (i = 0; i < entry_count; ++i)
2553 if (len == strlen(map[i].extension_string)
2554 && !memcmp(start, map[i].extension_string, len))
2556 TRACE(" FOUND: %s support.\n", map[i].extension_string);
2557 gl_info->supported[map[i].extension] = TRUE;
2558 break;
2564 static void load_gl_funcs(struct wined3d_gl_info *gl_info)
2566 #define USE_GL_FUNC(pfn) gl_info->gl_ops.ext.p_##pfn = (void *)wglGetProcAddress(#pfn);
2567 GL_EXT_FUNCS_GEN;
2568 #undef USE_GL_FUNC
2570 #ifndef USE_WIN32_OPENGL
2571 /* hack: use the functions directly from the TEB table to bypass the thunks */
2572 /* note that we still need the above wglGetProcAddress calls to initialize the table */
2573 gl_info->gl_ops.ext = ((struct opengl_funcs *)NtCurrentTeb()->glTable)->ext;
2574 #endif
2577 static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
2579 GLfloat gl_floatv[2];
2580 GLint gl_max;
2582 gl_info->limits.blends = 1;
2583 gl_info->limits.buffers = 1;
2584 gl_info->limits.textures = 1;
2585 gl_info->limits.texture_coords = 1;
2586 gl_info->limits.fragment_samplers = 1;
2587 gl_info->limits.vertex_samplers = 0;
2588 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers + gl_info->limits.vertex_samplers;
2589 gl_info->limits.vertex_attribs = 16;
2590 gl_info->limits.glsl_vs_float_constants = 0;
2591 gl_info->limits.glsl_ps_float_constants = 0;
2592 gl_info->limits.arb_vs_float_constants = 0;
2593 gl_info->limits.arb_vs_native_constants = 0;
2594 gl_info->limits.arb_vs_instructions = 0;
2595 gl_info->limits.arb_vs_temps = 0;
2596 gl_info->limits.arb_ps_float_constants = 0;
2597 gl_info->limits.arb_ps_local_constants = 0;
2598 gl_info->limits.arb_ps_instructions = 0;
2599 gl_info->limits.arb_ps_temps = 0;
2601 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
2602 gl_info->limits.clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
2603 TRACE("Clip plane support - max planes %d.\n", gl_max);
2605 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
2606 gl_info->limits.lights = gl_max;
2607 TRACE("Light support - max lights %d.\n", gl_max);
2609 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
2610 gl_info->limits.texture_size = gl_max;
2611 TRACE("Maximum texture size support - max texture size %d.\n", gl_max);
2613 gl_info->gl_ops.gl.p_glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
2614 gl_info->limits.pointsize_min = gl_floatv[0];
2615 gl_info->limits.pointsize_max = gl_floatv[1];
2616 TRACE("Maximum point size support - max point size %f.\n", gl_floatv[1]);
2618 if (gl_info->supported[ARB_MAP_BUFFER_ALIGNMENT])
2620 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &gl_max);
2621 TRACE("Minimum buffer map alignment: %d.\n", gl_max);
2623 else
2625 WARN_(d3d_perf)("Driver doesn't guarantee a minimum buffer map alignment.\n");
2627 if (gl_info->supported[NV_REGISTER_COMBINERS])
2629 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &gl_max);
2630 gl_info->limits.general_combiners = gl_max;
2631 TRACE("Max general combiners: %d.\n", gl_max);
2633 if (gl_info->supported[ARB_DRAW_BUFFERS] && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2635 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
2636 gl_info->limits.buffers = gl_max;
2637 TRACE("Max draw buffers: %u.\n", gl_max);
2639 if (gl_info->supported[ARB_MULTITEXTURE])
2641 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
2642 gl_info->limits.textures = min(MAX_TEXTURES, gl_max);
2643 TRACE("Max textures: %d.\n", gl_info->limits.textures);
2645 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2647 GLint tmp;
2648 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &gl_max);
2649 gl_info->limits.texture_coords = min(MAX_TEXTURES, gl_max);
2650 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2651 gl_info->limits.fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
2653 else
2655 gl_info->limits.texture_coords = max(gl_info->limits.texture_coords, gl_max);
2656 gl_info->limits.fragment_samplers = max(gl_info->limits.fragment_samplers, gl_max);
2658 TRACE("Max texture coords: %d.\n", gl_info->limits.texture_coords);
2659 TRACE("Max fragment samplers: %d.\n", gl_info->limits.fragment_samplers);
2661 if (gl_info->supported[ARB_VERTEX_SHADER])
2663 GLint tmp;
2664 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2665 gl_info->limits.vertex_samplers = tmp;
2666 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2667 gl_info->limits.combined_samplers = tmp;
2668 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &tmp);
2669 gl_info->limits.vertex_attribs = tmp;
2671 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
2672 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
2673 * an issue because then the sampler setup only depends on the two shaders. If a pixel
2674 * shader is used with fixed function vertex processing we're fine too because fixed function
2675 * vertex processing doesn't use any samplers. If fixed function fragment processing is
2676 * used we have to make sure that all vertex sampler setups are valid together with all
2677 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
2678 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
2679 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
2680 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
2681 * a fixed function pipeline anymore.
2683 * So this is just a check to check that our assumption holds true. If not, write a warning
2684 * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
2685 if (gl_info->limits.vertex_samplers && gl_info->limits.combined_samplers < 12
2686 && MAX_TEXTURES + gl_info->limits.vertex_samplers > gl_info->limits.combined_samplers)
2688 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
2689 gl_info->limits.vertex_samplers, gl_info->limits.combined_samplers);
2690 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
2691 if (gl_info->limits.combined_samplers > MAX_TEXTURES)
2692 gl_info->limits.vertex_samplers = gl_info->limits.combined_samplers - MAX_TEXTURES;
2693 else
2694 gl_info->limits.vertex_samplers = 0;
2697 else
2699 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers;
2701 TRACE("Max vertex samplers: %u.\n", gl_info->limits.vertex_samplers);
2702 TRACE("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
2704 if (gl_info->supported[ARB_VERTEX_BLEND])
2706 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
2707 gl_info->limits.blends = gl_max;
2708 TRACE("Max blends: %u.\n", gl_info->limits.blends);
2710 if (gl_info->supported[EXT_TEXTURE3D])
2712 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
2713 gl_info->limits.texture3d_size = gl_max;
2714 TRACE("Max texture3D size: %d.\n", gl_info->limits.texture3d_size);
2716 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
2718 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
2719 gl_info->limits.anisotropy = gl_max;
2720 TRACE("Max anisotropy: %d.\n", gl_info->limits.anisotropy);
2722 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2724 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2725 gl_info->limits.arb_ps_float_constants = gl_max;
2726 TRACE("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->limits.arb_ps_float_constants);
2727 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2728 gl_info->limits.arb_ps_native_constants = gl_max;
2729 TRACE("Max ARB_FRAGMENT_PROGRAM native float constants: %d.\n",
2730 gl_info->limits.arb_ps_native_constants);
2731 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2732 gl_info->limits.arb_ps_temps = gl_max;
2733 TRACE("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_ps_temps);
2734 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2735 gl_info->limits.arb_ps_instructions = gl_max;
2736 TRACE("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->limits.arb_ps_instructions);
2737 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
2738 gl_info->limits.arb_ps_local_constants = gl_max;
2739 TRACE("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->limits.arb_ps_instructions);
2741 if (gl_info->supported[ARB_VERTEX_PROGRAM])
2743 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2744 gl_info->limits.arb_vs_float_constants = gl_max;
2745 TRACE("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->limits.arb_vs_float_constants);
2746 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2747 gl_info->limits.arb_vs_native_constants = gl_max;
2748 TRACE("Max ARB_VERTEX_PROGRAM native float constants: %d.\n",
2749 gl_info->limits.arb_vs_native_constants);
2750 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2751 gl_info->limits.arb_vs_temps = gl_max;
2752 TRACE("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_vs_temps);
2753 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2754 gl_info->limits.arb_vs_instructions = gl_max;
2755 TRACE("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->limits.arb_vs_instructions);
2757 if (gl_info->supported[ARB_VERTEX_SHADER])
2759 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
2760 gl_info->limits.glsl_vs_float_constants = gl_max / 4;
2761 TRACE("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->limits.glsl_vs_float_constants);
2763 if (gl_info->supported[ARB_FRAGMENT_SHADER])
2765 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
2766 gl_info->limits.glsl_ps_float_constants = gl_max / 4;
2767 TRACE("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->limits.glsl_ps_float_constants);
2768 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
2769 gl_info->limits.glsl_varyings = gl_max;
2770 TRACE("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
2773 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
2774 gl_info->gl_ops.gl.p_glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->limits.shininess);
2775 else
2776 gl_info->limits.shininess = 128.0f;
2778 if ((gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
2779 && wined3d_settings.allow_multisampling)
2781 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_SAMPLES, &gl_max);
2782 gl_info->limits.samples = gl_max;
2786 /* Context activation is done by the caller. */
2787 static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter)
2789 struct wined3d_driver_info *driver_info = &adapter->driver_info;
2790 const char *gl_vendor_str, *gl_renderer_str, *gl_version_str;
2791 struct wined3d_gl_info *gl_info = &adapter->gl_info;
2792 struct wined3d_vertex_caps vertex_caps;
2793 enum wined3d_pci_vendor card_vendor;
2794 struct fragment_caps fragment_caps;
2795 struct shader_caps shader_caps;
2796 const char *WGL_Extensions = NULL;
2797 const char *GL_Extensions = NULL;
2798 enum wined3d_gl_vendor gl_vendor;
2799 enum wined3d_pci_device device;
2800 DWORD gl_version;
2801 HDC hdc;
2802 unsigned int i;
2804 TRACE("adapter %p.\n", adapter);
2806 gl_renderer_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_RENDERER);
2807 TRACE("GL_RENDERER: %s.\n", debugstr_a(gl_renderer_str));
2808 if (!gl_renderer_str)
2810 ERR("Received a NULL GL_RENDERER.\n");
2811 return FALSE;
2814 gl_vendor_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VENDOR);
2815 TRACE("GL_VENDOR: %s.\n", debugstr_a(gl_vendor_str));
2816 if (!gl_vendor_str)
2818 ERR("Received a NULL GL_VENDOR.\n");
2819 return FALSE;
2822 /* Parse the GL_VERSION field into major and minor information */
2823 gl_version_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VERSION);
2824 TRACE("GL_VERSION: %s.\n", debugstr_a(gl_version_str));
2825 if (!gl_version_str)
2827 ERR("Received a NULL GL_VERSION.\n");
2828 return FALSE;
2830 gl_version = wined3d_parse_gl_version(gl_version_str);
2832 /* Parse the gl supported features, in theory enabling parts of our code appropriately. */
2833 GL_Extensions = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_EXTENSIONS);
2834 if (!GL_Extensions)
2836 ERR("Received a NULL GL_EXTENSIONS.\n");
2837 return FALSE;
2840 memset(gl_info->supported, 0, sizeof(gl_info->supported));
2841 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
2843 TRACE("GL extensions reported:\n");
2844 parse_extension_string(gl_info, GL_Extensions, gl_extension_map,
2845 sizeof(gl_extension_map) / sizeof(*gl_extension_map));
2847 /* Now work out what GL support this card really has. */
2848 load_gl_funcs( gl_info );
2850 hdc = wglGetCurrentDC();
2851 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox. */
2852 if (GL_EXTCALL(wglGetExtensionsStringARB))
2853 WGL_Extensions = (const char *)GL_EXTCALL(wglGetExtensionsStringARB(hdc));
2854 if (!WGL_Extensions)
2855 WARN("WGL extensions not supported.\n");
2856 else
2857 parse_extension_string(gl_info, WGL_Extensions, wgl_extension_map,
2858 sizeof(wgl_extension_map) / sizeof(*wgl_extension_map));
2860 if (!gl_info->supported[EXT_TEXTURE3D] && gl_version >= MAKEDWORD_VERSION(1, 2))
2862 TRACE("GL CORE: GL_EXT_texture3D support.\n");
2863 gl_info->gl_ops.ext.p_glTexImage3DEXT = (void *)gl_info->gl_ops.ext.p_glTexImage3D;
2864 gl_info->gl_ops.ext.p_glTexSubImage3DEXT = gl_info->gl_ops.ext.p_glTexSubImage3D;
2865 gl_info->supported[EXT_TEXTURE3D] = TRUE;
2868 if (!gl_info->supported[NV_POINT_SPRITE] && gl_version >= MAKEDWORD_VERSION(1, 4))
2870 TRACE("GL CORE: GL_NV_point_sprite support.\n");
2871 gl_info->gl_ops.ext.p_glPointParameterivNV = gl_info->gl_ops.ext.p_glPointParameteriv;
2872 gl_info->gl_ops.ext.p_glPointParameteriNV = gl_info->gl_ops.ext.p_glPointParameteri;
2873 gl_info->supported[NV_POINT_SPRITE] = TRUE;
2876 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && gl_version >= MAKEDWORD_VERSION(2, 0))
2878 TRACE("GL CORE: GL_ARB_texture_non_power_of_two support.\n");
2879 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = TRUE;
2882 if (gl_version >= MAKEDWORD_VERSION(2, 0)) gl_info->supported[WINED3D_GL_VERSION_2_0] = TRUE;
2884 if (gl_info->supported[APPLE_FENCE])
2886 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
2887 * The apple extension interacts with some other apple exts. Disable the NV
2888 * extension if the apple one is support to prevent confusion in other parts
2889 * of the code. */
2890 gl_info->supported[NV_FENCE] = FALSE;
2892 if (gl_info->supported[APPLE_FLOAT_PIXELS])
2894 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
2896 * The enums are the same:
2897 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881a
2898 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881b
2899 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
2900 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
2901 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140b
2903 if (!gl_info->supported[ARB_TEXTURE_FLOAT])
2905 TRACE(" IMPLIED: GL_ARB_texture_float support (by GL_APPLE_float_pixels).\n");
2906 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
2908 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
2910 TRACE(" IMPLIED: GL_ARB_half_float_pixel support (by GL_APPLE_float_pixels).\n");
2911 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
2914 if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
2916 /* GL_ARB_map_buffer_range and GL_APPLE_flush_buffer_range provide the same
2917 * functionality. Prefer the ARB extension */
2918 gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] = FALSE;
2920 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
2922 TRACE(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
2923 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
2925 if (!gl_info->supported[ARB_DEPTH_CLAMP] && gl_info->supported[NV_DEPTH_CLAMP])
2927 TRACE(" IMPLIED: ARB_depth_clamp support (by NV_depth_clamp).\n");
2928 gl_info->supported[ARB_DEPTH_CLAMP] = TRUE;
2930 if (!gl_info->supported[ARB_VERTEX_ARRAY_BGRA] && gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
2932 TRACE(" IMPLIED: ARB_vertex_array_bgra support (by EXT_vertex_array_bgra).\n");
2933 gl_info->supported[ARB_VERTEX_ARRAY_BGRA] = TRUE;
2935 if (!gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] && gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
2937 TRACE(" IMPLIED: ARB_texture_compression_rgtc support (by EXT_texture_compression_rgtc).\n");
2938 gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] = TRUE;
2940 if (gl_info->supported[NV_TEXTURE_SHADER2])
2942 if (gl_info->supported[NV_REGISTER_COMBINERS])
2944 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
2945 * are supported. The nv extensions provide the same functionality as the
2946 * ATI one, and a bit more(signed pixelformats). */
2947 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
2950 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
2952 /* If we have full NP2 texture support, disable
2953 * GL_ARB_texture_rectangle because we will never use it.
2954 * This saves a few redundant glDisable calls. */
2955 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
2957 if (gl_info->supported[ATI_FRAGMENT_SHADER])
2959 /* Disable NV_register_combiners and fragment shader if this is supported.
2960 * generally the NV extensions are preferred over the ATI ones, and this
2961 * extension is disabled if register_combiners and texture_shader2 are both
2962 * supported. So we reach this place only if we have incomplete NV dxlevel 8
2963 * fragment processing support. */
2964 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
2965 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
2966 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
2967 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
2969 if (gl_info->supported[NV_HALF_FLOAT])
2971 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
2972 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
2974 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB] && !gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
2976 /* Current wined3d sRGB infrastructure requires EXT_texture_sRGB_decode
2977 * for GL_ARB_framebuffer_sRGB support (without EXT_texture_sRGB_decode
2978 * we never render to sRGB surfaces). */
2979 gl_info->supported[ARB_FRAMEBUFFER_SRGB] = FALSE;
2981 if (gl_info->supported[ARB_OCCLUSION_QUERY])
2983 GLint counter_bits;
2985 GL_EXTCALL(glGetQueryivARB(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &counter_bits));
2986 TRACE("Occlusion query counter has %d bits.\n", counter_bits);
2987 if (!counter_bits)
2988 gl_info->supported[ARB_OCCLUSION_QUERY] = FALSE;
2990 if (gl_info->supported[ARB_TIMER_QUERY])
2992 GLint counter_bits;
2994 GL_EXTCALL(glGetQueryivARB(GL_TIMESTAMP, GL_QUERY_COUNTER_BITS_ARB, &counter_bits));
2995 TRACE("Timestamp query counter has %d bits.\n", counter_bits);
2996 if (!counter_bits)
2997 gl_info->supported[ARB_TIMER_QUERY] = FALSE;
2999 if (!gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] && gl_info->supported[EXT_TEXTURE_MIRROR_CLAMP])
3001 TRACE(" IMPLIED: ATI_texture_mirror_once support (by EXT_texture_mirror_clamp).\n");
3002 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
3004 if (!gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] && gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
3006 TRACE(" IMPLIED: ARB_texture_mirror_clamp_to_edge support (by ATI_texture_mirror_once).\n");
3007 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] = TRUE;
3010 wined3d_adapter_init_limits(gl_info);
3012 if (gl_info->supported[ARB_VERTEX_PROGRAM] && test_arb_vs_offset_limit(gl_info))
3013 gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
3015 if (gl_info->supported[ARB_SHADING_LANGUAGE_100])
3017 const char *str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_SHADING_LANGUAGE_VERSION_ARB);
3018 unsigned int major, minor;
3020 TRACE("GLSL version string: %s.\n", debugstr_a(str));
3022 /* The format of the GLSL version string is "major.minor[.release] [vendor info]". */
3023 sscanf(str, "%u.%u", &major, &minor);
3024 gl_info->glsl_version = MAKEDWORD_VERSION(major, minor);
3027 checkGLcall("extension detection");
3029 adapter->shader_backend = select_shader_backend(gl_info);
3030 adapter->vertex_pipe = select_vertex_implementation(gl_info, adapter->shader_backend);
3031 adapter->fragment_pipe = select_fragment_implementation(gl_info, adapter->shader_backend);
3032 adapter->blitter = select_blit_implementation(gl_info, adapter->shader_backend);
3034 adapter->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
3035 adapter->d3d_info.vs_clipping = shader_caps.wined3d_caps & WINED3D_SHADER_CAP_VS_CLIPPING;
3036 adapter->d3d_info.limits.vs_version = shader_caps.vs_version;
3037 adapter->d3d_info.limits.gs_version = shader_caps.gs_version;
3038 adapter->d3d_info.limits.ps_version = shader_caps.ps_version;
3039 adapter->d3d_info.limits.vs_uniform_count = shader_caps.vs_uniform_count;
3040 adapter->d3d_info.limits.ps_uniform_count = shader_caps.ps_uniform_count;
3042 adapter->vertex_pipe->vp_get_caps(gl_info, &vertex_caps);
3043 adapter->d3d_info.xyzrhw = vertex_caps.xyzrhw;
3045 adapter->fragment_pipe->get_caps(gl_info, &fragment_caps);
3046 adapter->d3d_info.limits.ffp_blend_stages = fragment_caps.MaxTextureBlendStages;
3047 adapter->d3d_info.limits.ffp_textures = fragment_caps.MaxSimultaneousTextures;
3048 TRACE("Max texture stages: %u.\n", adapter->d3d_info.limits.ffp_blend_stages);
3050 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3052 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbuffer;
3053 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbuffer;
3054 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffers;
3055 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffers;
3056 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorage;
3057 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisample;
3058 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameteriv;
3059 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebuffer;
3060 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebuffer;
3061 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffers;
3062 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffers;
3063 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatus;
3064 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1D;
3065 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2D;
3066 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3D;
3067 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbuffer;
3068 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3069 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameteriv;
3070 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebuffer;
3071 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmap;
3073 else
3075 if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
3077 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbufferEXT;
3078 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbufferEXT;
3079 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffersEXT;
3080 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffersEXT;
3081 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorageEXT;
3082 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameterivEXT;
3083 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebufferEXT;
3084 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebufferEXT;
3085 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffersEXT;
3086 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffersEXT;
3087 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatusEXT;
3088 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1DEXT;
3089 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2DEXT;
3090 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3DEXT;
3091 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbufferEXT;
3092 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3093 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameterivEXT;
3094 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmapEXT;
3096 else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3098 WARN_(d3d_perf)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
3099 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
3101 if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
3103 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebufferEXT;
3105 if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
3107 gl_info->fbo_ops.glRenderbufferStorageMultisample
3108 = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisampleEXT;
3112 gl_vendor = wined3d_guess_gl_vendor(gl_info, gl_vendor_str, gl_renderer_str);
3113 card_vendor = wined3d_guess_card_vendor(gl_vendor_str, gl_renderer_str);
3114 TRACE("Found GL_VENDOR (%s)->(0x%04x/0x%04x).\n", debugstr_a(gl_vendor_str), gl_vendor, card_vendor);
3116 device = wined3d_guess_card(gl_info, gl_renderer_str, &gl_vendor, &card_vendor);
3117 TRACE("Found (fake) card: 0x%x (vendor id), 0x%x (device id).\n", card_vendor, device);
3119 gl_info->wrap_lookup[WINED3D_TADDRESS_WRAP - WINED3D_TADDRESS_WRAP] = GL_REPEAT;
3120 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR - WINED3D_TADDRESS_WRAP] =
3121 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
3122 gl_info->wrap_lookup[WINED3D_TADDRESS_CLAMP - WINED3D_TADDRESS_WRAP] = GL_CLAMP_TO_EDGE;
3123 gl_info->wrap_lookup[WINED3D_TADDRESS_BORDER - WINED3D_TADDRESS_WRAP] =
3124 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
3125 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP] =
3126 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] ? GL_MIRROR_CLAMP_TO_EDGE : GL_REPEAT;
3128 adapter->d3d_info.valid_rt_mask = 0;
3129 for (i = 0; i < gl_info->limits.buffers; ++i)
3130 adapter->d3d_info.valid_rt_mask |= (1 << i);
3132 fixup_extensions(gl_info, gl_renderer_str, gl_vendor, card_vendor, device);
3133 init_driver_info(driver_info, card_vendor, device);
3134 add_gl_compat_wrappers(gl_info);
3136 return TRUE;
3139 UINT CDECL wined3d_get_adapter_count(const struct wined3d *wined3d)
3141 TRACE("wined3d %p, reporting %u adapters.\n",
3142 wined3d, wined3d->adapter_count);
3144 return wined3d->adapter_count;
3147 HRESULT CDECL wined3d_register_software_device(struct wined3d *wined3d, void *init_function)
3149 FIXME("wined3d %p, init_function %p stub!\n", wined3d, init_function);
3151 return WINED3D_OK;
3154 HMONITOR CDECL wined3d_get_adapter_monitor(const struct wined3d *wined3d, UINT adapter_idx)
3156 TRACE("wined3d %p, adapter_idx %u.\n", wined3d, adapter_idx);
3158 if (adapter_idx >= wined3d->adapter_count)
3159 return NULL;
3161 return MonitorFromPoint(wined3d->adapters[adapter_idx].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
3164 /* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
3165 of the same bpp but different resolutions */
3167 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
3168 UINT CDECL wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT adapter_idx,
3169 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering)
3171 const struct wined3d_adapter *adapter;
3172 const struct wined3d_format *format;
3173 unsigned int i = 0;
3174 unsigned int j = 0;
3175 UINT format_bits;
3176 DEVMODEW mode;
3178 TRACE("wined3d %p, adapter_idx %u, format %s, scanline_ordering %#x.\n",
3179 wined3d, adapter_idx, debug_d3dformat(format_id), scanline_ordering);
3181 if (adapter_idx >= wined3d->adapter_count)
3182 return 0;
3184 adapter = &wined3d->adapters[adapter_idx];
3185 format = wined3d_get_format(&adapter->gl_info, format_id);
3186 format_bits = format->byte_count * CHAR_BIT;
3188 memset(&mode, 0, sizeof(mode));
3189 mode.dmSize = sizeof(mode);
3191 while (EnumDisplaySettingsExW(adapter->DeviceName, j++, &mode, 0))
3193 if (mode.dmFields & DM_DISPLAYFLAGS)
3195 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_PROGRESSIVE
3196 && (mode.u2.dmDisplayFlags & DM_INTERLACED))
3197 continue;
3199 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED
3200 && !(mode.u2.dmDisplayFlags & DM_INTERLACED))
3201 continue;
3204 if (format_id == WINED3DFMT_UNKNOWN)
3206 /* This is for d3d8, do not enumerate P8 here. */
3207 if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
3209 else if (mode.dmBitsPerPel == format_bits)
3211 ++i;
3215 TRACE("Returning %u matching modes (out of %u total) for adapter %u.\n", i, j, adapter_idx);
3217 return i;
3220 /* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
3221 HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx,
3222 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering,
3223 UINT mode_idx, struct wined3d_display_mode *mode)
3225 const struct wined3d_adapter *adapter;
3226 const struct wined3d_format *format;
3227 UINT format_bits;
3228 DEVMODEW m;
3229 UINT i = 0;
3230 int j = 0;
3232 TRACE("wined3d %p, adapter_idx %u, format %s, scanline_ordering %#x, mode_idx %u, mode %p.\n",
3233 wined3d, adapter_idx, debug_d3dformat(format_id), scanline_ordering, mode_idx, mode);
3235 if (!mode || adapter_idx >= wined3d->adapter_count)
3236 return WINED3DERR_INVALIDCALL;
3238 adapter = &wined3d->adapters[adapter_idx];
3239 format = wined3d_get_format(&adapter->gl_info, format_id);
3240 format_bits = format->byte_count * CHAR_BIT;
3242 memset(&m, 0, sizeof(m));
3243 m.dmSize = sizeof(m);
3245 while (i <= mode_idx)
3247 if (!EnumDisplaySettingsExW(adapter->DeviceName, j++, &m, 0))
3249 WARN("Invalid mode_idx %u.\n", mode_idx);
3250 return WINED3DERR_INVALIDCALL;
3253 if (m.dmFields & DM_DISPLAYFLAGS)
3255 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_PROGRESSIVE
3256 && (m.u2.dmDisplayFlags & DM_INTERLACED))
3257 continue;
3259 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED
3260 && !(m.u2.dmDisplayFlags & DM_INTERLACED))
3261 continue;
3264 if (format_id == WINED3DFMT_UNKNOWN)
3266 /* This is for d3d8, do not enumerate P8 here. */
3267 if (m.dmBitsPerPel == 32 || m.dmBitsPerPel == 16) ++i;
3269 else if (m.dmBitsPerPel == format_bits)
3271 ++i;
3275 mode->width = m.dmPelsWidth;
3276 mode->height = m.dmPelsHeight;
3277 mode->refresh_rate = DEFAULT_REFRESH_RATE;
3278 if (m.dmFields & DM_DISPLAYFREQUENCY)
3279 mode->refresh_rate = m.dmDisplayFrequency;
3281 if (format_id == WINED3DFMT_UNKNOWN)
3282 mode->format_id = pixelformat_for_depth(m.dmBitsPerPel);
3283 else
3284 mode->format_id = format_id;
3286 if (!(m.dmFields & DM_DISPLAYFLAGS))
3287 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
3288 else if (m.u2.dmDisplayFlags & DM_INTERLACED)
3289 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
3290 else
3291 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
3293 TRACE("%ux%u@%u %u bpp, %s %#x.\n", mode->width, mode->height, mode->refresh_rate,
3294 m.dmBitsPerPel, debug_d3dformat(mode->format_id), mode->scanline_ordering);
3296 return WINED3D_OK;
3299 HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx,
3300 struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
3302 const struct wined3d_adapter *adapter;
3303 DEVMODEW m;
3305 TRACE("wined3d %p, adapter_idx %u, display_mode %p, rotation %p.\n",
3306 wined3d, adapter_idx, mode, rotation);
3308 if (!mode || adapter_idx >= wined3d->adapter_count)
3309 return WINED3DERR_INVALIDCALL;
3311 adapter = &wined3d->adapters[adapter_idx];
3313 memset(&m, 0, sizeof(m));
3314 m.dmSize = sizeof(m);
3316 EnumDisplaySettingsExW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &m, 0);
3317 mode->width = m.dmPelsWidth;
3318 mode->height = m.dmPelsHeight;
3319 mode->refresh_rate = DEFAULT_REFRESH_RATE;
3320 if (m.dmFields & DM_DISPLAYFREQUENCY)
3321 mode->refresh_rate = m.dmDisplayFrequency;
3322 mode->format_id = pixelformat_for_depth(m.dmBitsPerPel);
3324 /* Lie about the format. X11 can't change the color depth, and some apps
3325 * are pretty angry if they SetDisplayMode from 24 to 16 bpp and find out
3326 * that GetDisplayMode still returns 24 bpp. This should probably be
3327 * handled in winex11 instead. */
3328 if (adapter->screen_format && adapter->screen_format != mode->format_id)
3330 WARN("Overriding format %s with stored format %s.\n",
3331 debug_d3dformat(mode->format_id),
3332 debug_d3dformat(adapter->screen_format));
3333 mode->format_id = adapter->screen_format;
3336 if (!(m.dmFields & DM_DISPLAYFLAGS))
3337 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
3338 else if (m.u2.dmDisplayFlags & DM_INTERLACED)
3339 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
3340 else
3341 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
3343 if (rotation)
3345 switch (m.u1.s2.dmDisplayOrientation)
3347 case DMDO_DEFAULT:
3348 *rotation = WINED3D_DISPLAY_ROTATION_0;
3349 break;
3350 case DMDO_90:
3351 *rotation = WINED3D_DISPLAY_ROTATION_90;
3352 break;
3353 case DMDO_180:
3354 *rotation = WINED3D_DISPLAY_ROTATION_180;
3355 break;
3356 case DMDO_270:
3357 *rotation = WINED3D_DISPLAY_ROTATION_270;
3358 break;
3359 default:
3360 FIXME("Unhandled display rotation %#x.\n", m.u1.s2.dmDisplayOrientation);
3361 *rotation = WINED3D_DISPLAY_ROTATION_UNSPECIFIED;
3362 break;
3366 TRACE("Returning %ux%u@%u %s %#x.\n", mode->width, mode->height,
3367 mode->refresh_rate, debug_d3dformat(mode->format_id),
3368 mode->scanline_ordering);
3369 return WINED3D_OK;
3372 HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
3373 UINT adapter_idx, const struct wined3d_display_mode *mode)
3375 struct wined3d_display_mode current_mode;
3376 const struct wined3d_format *format;
3377 struct wined3d_adapter *adapter;
3378 DEVMODEW devmode;
3379 RECT clip_rc;
3380 HRESULT hr;
3381 LONG ret;
3383 TRACE("wined3d %p, adapter_idx %u, mode %p (%ux%u@%u %s %#x).\n", wined3d, adapter_idx, mode,
3384 mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id),
3385 mode->scanline_ordering);
3387 if (adapter_idx >= wined3d->adapter_count)
3388 return WINED3DERR_INVALIDCALL;
3390 adapter = &wined3d->adapters[adapter_idx];
3391 format = wined3d_get_format(&adapter->gl_info, mode->format_id);
3393 memset(&devmode, 0, sizeof(devmode));
3394 devmode.dmSize = sizeof(devmode);
3395 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
3396 devmode.dmBitsPerPel = format->byte_count * CHAR_BIT;
3397 devmode.dmPelsWidth = mode->width;
3398 devmode.dmPelsHeight = mode->height;
3400 devmode.dmDisplayFrequency = mode->refresh_rate;
3401 if (mode->refresh_rate)
3402 devmode.dmFields |= DM_DISPLAYFREQUENCY;
3404 if (mode->scanline_ordering != WINED3D_SCANLINE_ORDERING_UNKNOWN)
3406 devmode.dmFields |= DM_DISPLAYFLAGS;
3407 if (mode->scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED)
3408 devmode.u2.dmDisplayFlags |= DM_INTERLACED;
3411 /* Only change the mode if necessary. */
3412 if (FAILED(hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &current_mode, NULL)))
3414 ERR("Failed to get current display mode, hr %#x.\n", hr);
3416 else if (current_mode.width == mode->width
3417 && current_mode.height == mode->height
3418 && current_mode.format_id == mode->format_id
3419 && (current_mode.refresh_rate == mode->refresh_rate
3420 || !mode->refresh_rate)
3421 && (current_mode.scanline_ordering == mode->scanline_ordering
3422 || mode->scanline_ordering == WINED3D_SCANLINE_ORDERING_UNKNOWN))
3424 TRACE("Skipping redundant mode setting call.\n");
3425 return WINED3D_OK;
3428 ret = ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
3429 if (ret != DISP_CHANGE_SUCCESSFUL)
3431 if (devmode.dmDisplayFrequency)
3433 WARN("ChangeDisplaySettingsExW failed, trying without the refresh rate.\n");
3434 devmode.dmFields &= ~DM_DISPLAYFREQUENCY;
3435 devmode.dmDisplayFrequency = 0;
3436 ret = ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
3438 if (ret != DISP_CHANGE_SUCCESSFUL)
3439 return WINED3DERR_NOTAVAILABLE;
3442 /* Store the new values. */
3443 adapter->screen_format = mode->format_id;
3445 /* And finally clip mouse to our screen. */
3446 SetRect(&clip_rc, 0, 0, mode->width, mode->height);
3447 ClipCursor(&clip_rc);
3449 return WINED3D_OK;
3452 /* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
3453 and fields being inserted in the middle, a new structure is used in place */
3454 HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d,
3455 UINT adapter_idx, DWORD flags, struct wined3d_adapter_identifier *identifier)
3457 const struct wined3d_adapter *adapter;
3458 size_t len;
3460 TRACE("wined3d %p, adapter_idx %u, flags %#x, identifier %p.\n",
3461 wined3d, adapter_idx, flags, identifier);
3463 if (adapter_idx >= wined3d->adapter_count)
3464 return WINED3DERR_INVALIDCALL;
3466 adapter = &wined3d->adapters[adapter_idx];
3468 if (identifier->driver_size)
3470 const char *name = adapter->driver_info.name;
3471 len = min(strlen(name), identifier->driver_size - 1);
3472 memcpy(identifier->driver, name, len);
3473 memset(&identifier->driver[len], 0, identifier->driver_size - len);
3476 if (identifier->description_size)
3478 const char *description = adapter->driver_info.description;
3479 len = min(strlen(description), identifier->description_size - 1);
3480 memcpy(identifier->description, description, len);
3481 memset(&identifier->description[len], 0, identifier->description_size - len);
3484 /* Note that d3d8 doesn't supply a device name. */
3485 if (identifier->device_name_size)
3487 if (!WideCharToMultiByte(CP_ACP, 0, adapter->DeviceName, -1, identifier->device_name,
3488 identifier->device_name_size, NULL, NULL))
3490 ERR("Failed to convert device name, last error %#x.\n", GetLastError());
3491 return WINED3DERR_INVALIDCALL;
3495 identifier->driver_version.u.HighPart = adapter->driver_info.version_high;
3496 identifier->driver_version.u.LowPart = adapter->driver_info.version_low;
3497 identifier->vendor_id = adapter->driver_info.vendor;
3498 identifier->device_id = adapter->driver_info.device;
3499 identifier->subsystem_id = 0;
3500 identifier->revision = 0;
3501 memcpy(&identifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(identifier->device_identifier));
3502 identifier->whql_level = (flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
3503 memcpy(&identifier->adapter_luid, &adapter->luid, sizeof(identifier->adapter_luid));
3504 identifier->video_memory = adapter->TextureRam;
3506 return WINED3D_OK;
3509 HRESULT CDECL wined3d_get_adapter_raster_status(const struct wined3d *wined3d, UINT adapter_idx,
3510 struct wined3d_raster_status *raster_status)
3512 LONGLONG freq_per_frame, freq_per_line;
3513 LARGE_INTEGER counter, freq_per_sec;
3514 struct wined3d_display_mode mode;
3515 static UINT once;
3517 if (!once++)
3518 FIXME("wined3d %p, adapter_idx %u, raster_status %p semi-stub!\n",
3519 wined3d, adapter_idx, raster_status);
3520 else
3521 WARN("wined3d %p, adapter_idx %u, raster_status %p semi-stub!\n",
3522 wined3d, adapter_idx, raster_status);
3524 /* Obtaining the raster status is a widely implemented but optional
3525 * feature. When this method returns OK StarCraft 2 expects the
3526 * raster_status->InVBlank value to actually change over time.
3527 * And Endless Alice Crysis doesn't care even if this method fails.
3528 * Thus this method returns OK and fakes raster_status by
3529 * QueryPerformanceCounter. */
3531 if (!QueryPerformanceCounter(&counter) || !QueryPerformanceFrequency(&freq_per_sec))
3532 return WINED3DERR_INVALIDCALL;
3533 if (FAILED(wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode, NULL)))
3534 return WINED3DERR_INVALIDCALL;
3535 if (mode.refresh_rate == DEFAULT_REFRESH_RATE)
3536 mode.refresh_rate = 60;
3538 freq_per_frame = freq_per_sec.QuadPart / mode.refresh_rate;
3539 /* Assume 20 scan lines in the vertical blank. */
3540 freq_per_line = freq_per_frame / (mode.height + 20);
3541 raster_status->scan_line = (counter.QuadPart % freq_per_frame) / freq_per_line;
3542 if (raster_status->scan_line < mode.height)
3543 raster_status->in_vblank = FALSE;
3544 else
3546 raster_status->scan_line = 0;
3547 raster_status->in_vblank = TRUE;
3550 TRACE("Returning fake value, in_vblank %u, scan_line %u.\n",
3551 raster_status->in_vblank, raster_status->scan_line);
3553 return WINED3D_OK;
3556 static BOOL wined3d_check_pixel_format_color(const struct wined3d_gl_info *gl_info,
3557 const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
3559 BYTE redSize, greenSize, blueSize, alphaSize, colorBits;
3561 /* Float formats need FBOs. If FBOs are used this function isn't called */
3562 if (format->flags & WINED3DFMT_FLAG_FLOAT) return FALSE;
3564 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
3565 if (!getColorBits(format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
3567 ERR("Unable to check compatibility for format %s.\n", debug_d3dformat(format->id));
3568 return FALSE;
3571 if(cfg->redSize < redSize)
3572 return FALSE;
3574 if(cfg->greenSize < greenSize)
3575 return FALSE;
3577 if(cfg->blueSize < blueSize)
3578 return FALSE;
3580 if(cfg->alphaSize < alphaSize)
3581 return FALSE;
3583 return TRUE;
3586 /* Probably a RGBA_float or color index mode */
3587 return FALSE;
3590 static BOOL wined3d_check_pixel_format_depth(const struct wined3d_gl_info *gl_info,
3591 const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
3593 BYTE depthSize, stencilSize;
3594 BOOL lockable = FALSE;
3596 if (!getDepthStencilBits(format, &depthSize, &stencilSize))
3598 ERR("Unable to check compatibility for format %s.\n", debug_d3dformat(format->id));
3599 return FALSE;
3602 /* Float formats need FBOs. If FBOs are used this function isn't called */
3603 if (format->flags & WINED3DFMT_FLAG_FLOAT) return FALSE;
3605 if ((format->id == WINED3DFMT_D16_LOCKABLE) || (format->id == WINED3DFMT_D32_FLOAT))
3606 lockable = TRUE;
3608 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
3609 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
3610 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
3611 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
3612 return FALSE;
3614 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
3615 * allow more stencil bits than requested. */
3616 if(cfg->stencilSize < stencilSize)
3617 return FALSE;
3619 return TRUE;
3622 HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d,
3623 UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id,
3624 enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id)
3626 const struct wined3d_format *rt_format;
3627 const struct wined3d_format *ds_format;
3628 const struct wined3d_adapter *adapter;
3630 TRACE("wined3d %p, adapter_idx %u, device_type %s,\n"
3631 "adapter_format %s, render_target_format %s, depth_stencil_format %s.\n",
3632 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
3633 debug_d3dformat(render_target_format_id), debug_d3dformat(depth_stencil_format_id));
3635 if (adapter_idx >= wined3d->adapter_count)
3636 return WINED3DERR_INVALIDCALL;
3638 adapter = &wined3d->adapters[adapter_idx];
3639 rt_format = wined3d_get_format(&adapter->gl_info, render_target_format_id);
3640 ds_format = wined3d_get_format(&adapter->gl_info, depth_stencil_format_id);
3641 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3643 if ((rt_format->flags & WINED3DFMT_FLAG_RENDERTARGET)
3644 && (ds_format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
3646 TRACE("Formats match.\n");
3647 return WINED3D_OK;
3650 else
3652 const struct wined3d_pixel_format *cfgs;
3653 unsigned int cfg_count;
3654 unsigned int i;
3656 cfgs = adapter->cfgs;
3657 cfg_count = adapter->cfg_count;
3658 for (i = 0; i < cfg_count; ++i)
3660 if (wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], rt_format)
3661 && wined3d_check_pixel_format_depth(&adapter->gl_info, &cfgs[i], ds_format))
3663 TRACE("Formats match.\n");
3664 return WINED3D_OK;
3669 TRACE("Unsupported format pair: %s and %s.\n",
3670 debug_d3dformat(render_target_format_id),
3671 debug_d3dformat(depth_stencil_format_id));
3673 return WINED3DERR_NOTAVAILABLE;
3676 HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx,
3677 enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed,
3678 enum wined3d_multisample_type multisample_type, DWORD *quality_levels)
3680 const struct wined3d_gl_info *gl_info;
3682 TRACE("wined3d %p, adapter_idx %u, device_type %s, surface_format %s,\n"
3683 "windowed %#x, multisample_type %#x, quality_levels %p.\n",
3684 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(surface_format_id),
3685 windowed, multisample_type, quality_levels);
3687 if (adapter_idx >= wined3d->adapter_count)
3688 return WINED3DERR_INVALIDCALL;
3690 gl_info = &wined3d->adapters[adapter_idx].gl_info;
3692 if (multisample_type > gl_info->limits.samples)
3694 TRACE("Returning not supported.\n");
3695 if (quality_levels)
3696 *quality_levels = 0;
3698 return WINED3DERR_NOTAVAILABLE;
3701 if (quality_levels)
3703 if (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
3704 /* FIXME: This is probably wrong. */
3705 *quality_levels = gl_info->limits.samples;
3706 else
3707 *quality_levels = 1;
3710 return WINED3D_OK;
3713 /* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
3714 static BOOL CheckDepthStencilCapability(const struct wined3d_adapter *adapter,
3715 const struct wined3d_format *display_format, const struct wined3d_format *ds_format)
3717 /* Only allow depth/stencil formats */
3718 if (!(ds_format->depth_size || ds_format->stencil_size)) return FALSE;
3720 /* Blacklist formats not supported on Windows */
3721 switch (ds_format->id)
3723 case WINED3DFMT_S1_UINT_D15_UNORM: /* Breaks the shadowvol2 dx7 sdk sample */
3724 case WINED3DFMT_S4X4_UINT_D24_UNORM:
3725 TRACE("[FAILED] - not supported on windows.\n");
3726 return FALSE;
3728 default:
3729 break;
3732 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3734 /* With FBOs WGL limitations do not apply, but the format needs to be FBO attachable */
3735 if (ds_format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) return TRUE;
3737 else
3739 unsigned int i;
3741 /* Walk through all WGL pixel formats to find a match */
3742 for (i = 0; i < adapter->cfg_count; ++i)
3744 const struct wined3d_pixel_format *cfg = &adapter->cfgs[i];
3745 if (wined3d_check_pixel_format_color(&adapter->gl_info, cfg, display_format)
3746 && wined3d_check_pixel_format_depth(&adapter->gl_info, cfg, ds_format))
3747 return TRUE;
3751 return FALSE;
3754 /* Check the render target capabilities of a format */
3755 static BOOL CheckRenderTargetCapability(const struct wined3d_adapter *adapter,
3756 const struct wined3d_format *adapter_format, const struct wined3d_format *check_format)
3758 /* Filter out non-RT formats */
3759 if (!(check_format->flags & WINED3DFMT_FLAG_RENDERTARGET)) return FALSE;
3760 if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
3762 BYTE AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
3763 BYTE CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
3764 const struct wined3d_pixel_format *cfgs = adapter->cfgs;
3765 unsigned int i;
3767 getColorBits(adapter_format, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
3768 getColorBits(check_format, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
3770 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
3771 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
3772 if (!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue)))
3774 TRACE("[FAILED]\n");
3775 return FALSE;
3778 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
3779 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
3780 for (i = 0; i < adapter->cfg_count; ++i)
3782 if (cfgs[i].windowDrawable
3783 && wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], check_format))
3785 TRACE("Pixel format %d is compatible with format %s.\n",
3786 cfgs[i].iPixelFormat, debug_d3dformat(check_format->id));
3787 return TRUE;
3791 else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3793 /* For now return TRUE for FBOs until we have some proper checks.
3794 * Note that this function will only be called when the format is around for texturing. */
3795 return TRUE;
3797 return FALSE;
3800 static BOOL CheckSurfaceCapability(const struct wined3d_adapter *adapter,
3801 const struct wined3d_format *adapter_format,
3802 const struct wined3d_format *check_format, BOOL no3d)
3804 if (no3d)
3806 switch (check_format->id)
3808 case WINED3DFMT_B8G8R8_UNORM:
3809 TRACE("[FAILED] - Not enumerated on Windows.\n");
3810 return FALSE;
3811 case WINED3DFMT_B8G8R8A8_UNORM:
3812 case WINED3DFMT_B8G8R8X8_UNORM:
3813 case WINED3DFMT_B5G6R5_UNORM:
3814 case WINED3DFMT_B5G5R5X1_UNORM:
3815 case WINED3DFMT_B5G5R5A1_UNORM:
3816 case WINED3DFMT_B4G4R4A4_UNORM:
3817 case WINED3DFMT_B2G3R3_UNORM:
3818 case WINED3DFMT_A8_UNORM:
3819 case WINED3DFMT_B2G3R3A8_UNORM:
3820 case WINED3DFMT_B4G4R4X4_UNORM:
3821 case WINED3DFMT_R10G10B10A2_UNORM:
3822 case WINED3DFMT_R8G8B8A8_UNORM:
3823 case WINED3DFMT_R8G8B8X8_UNORM:
3824 case WINED3DFMT_R16G16_UNORM:
3825 case WINED3DFMT_B10G10R10A2_UNORM:
3826 case WINED3DFMT_R16G16B16A16_UNORM:
3827 case WINED3DFMT_P8_UINT:
3828 TRACE("[OK]\n");
3829 return TRUE;
3830 default:
3831 TRACE("[FAILED] - Not available on GDI surfaces.\n");
3832 return FALSE;
3836 /* All formats that are supported for textures are supported for surfaces
3837 * as well. */
3838 if (check_format->flags & WINED3DFMT_FLAG_TEXTURE)
3839 return TRUE;
3840 /* All depth stencil formats are supported on surfaces */
3841 if (CheckDepthStencilCapability(adapter, adapter_format, check_format)) return TRUE;
3843 /* If opengl can't process the format natively, the blitter may be able to convert it */
3844 if (adapter->blitter->blit_supported(&adapter->gl_info, WINED3D_BLIT_OP_COLOR_BLIT,
3845 NULL, WINED3D_POOL_DEFAULT, 0, check_format,
3846 NULL, WINED3D_POOL_DEFAULT, 0, adapter_format))
3848 TRACE("[OK]\n");
3849 return TRUE;
3852 /* Reject other formats */
3853 TRACE("[FAILED]\n");
3854 return FALSE;
3857 /* OpenGL supports mipmapping on all formats. Wrapping is unsupported, but we
3858 * have to report mipmapping so we cannot reject WRAPANDMIP. Tests show that
3859 * Windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to
3860 * show that wrapping is supported. The lack of filtering will sort out the
3861 * mipmapping capability anyway.
3863 * For now lets report this on all formats, but in the future we may want to
3864 * restrict it to some should applications need that. */
3865 HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT adapter_idx,
3866 enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, DWORD usage,
3867 enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id)
3869 const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
3870 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
3871 const struct wined3d_format *adapter_format = wined3d_get_format(gl_info, adapter_format_id);
3872 const struct wined3d_format *format = wined3d_get_format(gl_info, check_format_id);
3873 DWORD format_flags = 0;
3874 DWORD allowed_usage;
3876 TRACE("wined3d %p, adapter_idx %u, device_type %s, adapter_format %s, usage %s, %s,\n"
3877 "resource_type %s, check_format %s.\n",
3878 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
3879 debug_d3dusage(usage), debug_d3dusagequery(usage), debug_d3dresourcetype(resource_type),
3880 debug_d3dformat(check_format_id));
3882 if (adapter_idx >= wined3d->adapter_count)
3883 return WINED3DERR_INVALIDCALL;
3885 switch (resource_type)
3887 case WINED3D_RTYPE_CUBE_TEXTURE:
3888 if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3890 TRACE("[FAILED] - No cube texture support.\n");
3891 return WINED3DERR_NOTAVAILABLE;
3894 format_flags |= WINED3DFMT_FLAG_TEXTURE;
3895 allowed_usage = WINED3DUSAGE_AUTOGENMIPMAP
3896 | WINED3DUSAGE_DYNAMIC
3897 | WINED3DUSAGE_RENDERTARGET
3898 | WINED3DUSAGE_SOFTWAREPROCESSING
3899 | WINED3DUSAGE_QUERY_FILTER
3900 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
3901 | WINED3DUSAGE_QUERY_SRGBREAD
3902 | WINED3DUSAGE_QUERY_SRGBWRITE
3903 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
3904 | WINED3DUSAGE_QUERY_WRAPANDMIP;
3905 break;
3907 case WINED3D_RTYPE_SURFACE:
3908 if (!CheckSurfaceCapability(adapter, adapter_format, format, wined3d->flags & WINED3D_NO3D))
3910 TRACE("[FAILED] - Not supported for plain surfaces.\n");
3911 return WINED3DERR_NOTAVAILABLE;
3914 allowed_usage = WINED3DUSAGE_DEPTHSTENCIL
3915 | WINED3DUSAGE_RENDERTARGET
3916 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
3917 break;
3919 case WINED3D_RTYPE_TEXTURE:
3920 if ((usage & WINED3DUSAGE_DEPTHSTENCIL) && (format->flags & WINED3DFMT_FLAG_SHADOW)
3921 && !gl_info->supported[ARB_SHADOW])
3923 TRACE("[FAILED] - No shadow sampler support.\n");
3924 return WINED3DERR_NOTAVAILABLE;
3927 format_flags |= WINED3DFMT_FLAG_TEXTURE;
3928 allowed_usage = WINED3DUSAGE_AUTOGENMIPMAP
3929 | WINED3DUSAGE_DEPTHSTENCIL
3930 | WINED3DUSAGE_DYNAMIC
3931 | WINED3DUSAGE_RENDERTARGET
3932 | WINED3DUSAGE_SOFTWAREPROCESSING
3933 | WINED3DUSAGE_QUERY_FILTER
3934 | WINED3DUSAGE_QUERY_LEGACYBUMPMAP
3935 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
3936 | WINED3DUSAGE_QUERY_SRGBREAD
3937 | WINED3DUSAGE_QUERY_SRGBWRITE
3938 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
3939 | WINED3DUSAGE_QUERY_WRAPANDMIP;
3940 break;
3942 case WINED3D_RTYPE_VOLUME_TEXTURE:
3943 case WINED3D_RTYPE_VOLUME:
3944 /* Volume is to VolumeTexture what Surface is to Texture, but its
3945 * usage caps are not documented. Most driver seem to offer
3946 * (nearly) the same on Volume and VolumeTexture, so do that too. */
3947 if (!gl_info->supported[EXT_TEXTURE3D])
3949 TRACE("[FAILED] - No volume texture support.\n");
3950 return WINED3DERR_NOTAVAILABLE;
3953 /* The GL_EXT_texture_compression_s3tc spec requires that loading
3954 * an s3tc compressed texture results in an error. While the D3D
3955 * refrast does support s3tc volumes, at least the nvidia Windows
3956 * driver does not, so we're free not to support this format. */
3957 switch (check_format_id)
3959 case WINED3DFMT_DXT1:
3960 case WINED3DFMT_DXT2:
3961 case WINED3DFMT_DXT3:
3962 case WINED3DFMT_DXT4:
3963 case WINED3DFMT_DXT5:
3964 TRACE("[FAILED] - DXTn does not support 3D textures.\n");
3965 return WINED3DERR_NOTAVAILABLE;
3967 default:
3968 /* Do nothing, continue with checking the format below */
3969 break;
3972 format_flags |= WINED3DFMT_FLAG_TEXTURE;
3973 allowed_usage = WINED3DUSAGE_DYNAMIC
3974 | WINED3DUSAGE_SOFTWAREPROCESSING
3975 | WINED3DUSAGE_QUERY_FILTER
3976 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
3977 | WINED3DUSAGE_QUERY_SRGBREAD
3978 | WINED3DUSAGE_QUERY_SRGBWRITE
3979 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
3980 | WINED3DUSAGE_QUERY_WRAPANDMIP;
3981 break;
3983 default:
3984 FIXME("Unhandled resource type %s.\n", debug_d3dresourcetype(resource_type));
3985 return WINED3DERR_NOTAVAILABLE;
3988 if ((usage & allowed_usage) != usage)
3990 TRACE("Requested usage %#x, but resource type %s only allows %#x.\n",
3991 usage, debug_d3dresourcetype(resource_type), allowed_usage);
3992 return WINED3DERR_NOTAVAILABLE;
3995 if (usage & WINED3DUSAGE_QUERY_FILTER)
3996 format_flags |= WINED3DFMT_FLAG_FILTERING;
3997 if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
3998 format_flags |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
3999 if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
4000 format_flags |= WINED3DFMT_FLAG_SRGB_READ;
4001 if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
4002 format_flags |= WINED3DFMT_FLAG_SRGB_WRITE;
4003 if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
4004 format_flags |= WINED3DFMT_FLAG_VTF;
4005 if (usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
4006 format_flags |= WINED3DFMT_FLAG_BUMPMAP;
4008 if ((format->flags & format_flags) != format_flags)
4010 TRACE("Requested format flags %#x, but format %s only has %#x.\n",
4011 format_flags, debug_d3dformat(check_format_id), format->flags);
4012 return WINED3DERR_NOTAVAILABLE;
4015 if ((format_flags & WINED3DFMT_FLAG_TEXTURE) && (wined3d->flags & WINED3D_NO3D))
4017 TRACE("Requested texturing support, but wined3d was created with WINED3D_NO3D.\n");
4018 return WINED3DERR_NOTAVAILABLE;
4021 if ((usage & WINED3DUSAGE_DEPTHSTENCIL)
4022 && !CheckDepthStencilCapability(adapter, adapter_format, format))
4024 TRACE("Requested WINED3DUSAGE_DEPTHSTENCIL, but format %s is not supported for depth / stencil buffers.\n",
4025 debug_d3dformat(check_format_id));
4026 return WINED3DERR_NOTAVAILABLE;
4029 if ((usage & WINED3DUSAGE_RENDERTARGET)
4030 && !CheckRenderTargetCapability(adapter, adapter_format, format))
4032 TRACE("Requested WINED3DUSAGE_RENDERTARGET, but format %s is not supported for render targets.\n",
4033 debug_d3dformat(check_format_id));
4034 return WINED3DERR_NOTAVAILABLE;
4037 if ((usage & WINED3DUSAGE_AUTOGENMIPMAP) && !gl_info->supported[SGIS_GENERATE_MIPMAP])
4039 TRACE("No WINED3DUSAGE_AUTOGENMIPMAP support, returning WINED3DOK_NOAUTOGEN.\n");
4040 return WINED3DOK_NOAUTOGEN;
4043 return WINED3D_OK;
4046 UINT CDECL wined3d_calculate_format_pitch(const struct wined3d *wined3d, UINT adapter_idx,
4047 enum wined3d_format_id format_id, UINT width)
4049 const struct wined3d_gl_info *gl_info;
4051 TRACE("wined3d %p, adapter_idx %u, format_id %s, width %u.\n",
4052 wined3d, adapter_idx, debug_d3dformat(format_id), width);
4054 if (adapter_idx >= wined3d->adapter_count)
4055 return ~0u;
4057 gl_info = &wined3d->adapters[adapter_idx].gl_info;
4058 return wined3d_format_calculate_pitch(wined3d_get_format(gl_info, format_id), width);
4061 HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx,
4062 enum wined3d_device_type device_type, enum wined3d_format_id src_format, enum wined3d_format_id dst_format)
4064 FIXME("wined3d %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n",
4065 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
4066 debug_d3dformat(dst_format));
4068 return WINED3D_OK;
4071 HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx,
4072 enum wined3d_device_type device_type, enum wined3d_format_id display_format,
4073 enum wined3d_format_id backbuffer_format, BOOL windowed)
4075 BOOL present_conversion = wined3d->flags & WINED3D_PRESENT_CONVERSION;
4077 TRACE("wined3d %p, adapter_idx %u, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
4078 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(display_format),
4079 debug_d3dformat(backbuffer_format), windowed);
4081 if (adapter_idx >= wined3d->adapter_count)
4082 return WINED3DERR_INVALIDCALL;
4084 /* The task of this function is to check whether a certain display / backbuffer format
4085 * combination is available on the given adapter. In fullscreen mode microsoft specified
4086 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
4087 * and display format should match exactly.
4088 * In windowed mode format conversion can occur and this depends on the driver. */
4090 /* There are only 4 display formats. */
4091 if (!(display_format == WINED3DFMT_B5G6R5_UNORM
4092 || display_format == WINED3DFMT_B5G5R5X1_UNORM
4093 || display_format == WINED3DFMT_B8G8R8X8_UNORM
4094 || display_format == WINED3DFMT_B10G10R10A2_UNORM))
4096 TRACE("Format %s is not supported as display format.\n", debug_d3dformat(display_format));
4097 return WINED3DERR_NOTAVAILABLE;
4100 if (!windowed)
4102 /* If the requested display format is not available, don't continue. */
4103 if (!wined3d_get_adapter_mode_count(wined3d, adapter_idx,
4104 display_format, WINED3D_SCANLINE_ORDERING_UNKNOWN))
4106 TRACE("No available modes for display format %s.\n", debug_d3dformat(display_format));
4107 return WINED3DERR_NOTAVAILABLE;
4110 present_conversion = FALSE;
4112 else if (display_format == WINED3DFMT_B10G10R10A2_UNORM)
4114 /* WINED3DFMT_B10G10R10A2_UNORM is only allowed in fullscreen mode. */
4115 TRACE("Unsupported format combination %s / %s in windowed mode.\n",
4116 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4117 return WINED3DERR_NOTAVAILABLE;
4120 if (present_conversion)
4122 /* Use the display format as back buffer format if the latter is
4123 * WINED3DFMT_UNKNOWN. */
4124 if (backbuffer_format == WINED3DFMT_UNKNOWN)
4125 backbuffer_format = display_format;
4127 if (FAILED(wined3d_check_device_format_conversion(wined3d, adapter_idx,
4128 device_type, backbuffer_format, display_format)))
4130 TRACE("Format conversion from %s to %s not supported.\n",
4131 debug_d3dformat(backbuffer_format), debug_d3dformat(display_format));
4132 return WINED3DERR_NOTAVAILABLE;
4135 else
4137 /* When format conversion from the back buffer format to the display
4138 * format is not allowed, only a limited number of combinations are
4139 * valid. */
4141 if (display_format == WINED3DFMT_B5G6R5_UNORM && backbuffer_format != WINED3DFMT_B5G6R5_UNORM)
4143 TRACE("Unsupported format combination %s / %s.\n",
4144 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4145 return WINED3DERR_NOTAVAILABLE;
4148 if (display_format == WINED3DFMT_B5G5R5X1_UNORM
4149 && !(backbuffer_format == WINED3DFMT_B5G5R5X1_UNORM || backbuffer_format == WINED3DFMT_B5G5R5A1_UNORM))
4151 TRACE("Unsupported format combination %s / %s.\n",
4152 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4153 return WINED3DERR_NOTAVAILABLE;
4156 if (display_format == WINED3DFMT_B8G8R8X8_UNORM
4157 && !(backbuffer_format == WINED3DFMT_B8G8R8X8_UNORM || backbuffer_format == WINED3DFMT_B8G8R8A8_UNORM))
4159 TRACE("Unsupported format combination %s / %s.\n",
4160 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4161 return WINED3DERR_NOTAVAILABLE;
4164 if (display_format == WINED3DFMT_B10G10R10A2_UNORM
4165 && backbuffer_format != WINED3DFMT_B10G10R10A2_UNORM)
4167 TRACE("Unsupported format combination %s / %s.\n",
4168 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4169 return WINED3DERR_NOTAVAILABLE;
4173 /* Validate that the back buffer format is usable for render targets. */
4174 if (FAILED(wined3d_check_device_format(wined3d, adapter_idx, device_type, display_format,
4175 WINED3DUSAGE_RENDERTARGET, WINED3D_RTYPE_SURFACE, backbuffer_format)))
4177 TRACE("Format %s not allowed for render targets.\n", debug_d3dformat(backbuffer_format));
4178 return WINED3DERR_NOTAVAILABLE;
4181 return WINED3D_OK;
4184 HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx,
4185 enum wined3d_device_type device_type, WINED3DCAPS *caps)
4187 const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
4188 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4189 struct shader_caps shader_caps;
4190 struct fragment_caps fragment_caps;
4191 struct wined3d_vertex_caps vertex_caps;
4192 DWORD ckey_caps, blit_caps, fx_caps;
4194 TRACE("wined3d %p, adapter_idx %u, device_type %s, caps %p.\n",
4195 wined3d, adapter_idx, debug_d3ddevicetype(device_type), caps);
4197 if (adapter_idx >= wined3d->adapter_count)
4198 return WINED3DERR_INVALIDCALL;
4200 caps->DeviceType = (device_type == WINED3D_DEVICE_TYPE_HAL) ? WINED3D_DEVICE_TYPE_HAL : WINED3D_DEVICE_TYPE_REF;
4201 caps->AdapterOrdinal = adapter_idx;
4203 caps->Caps = 0;
4204 caps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
4205 WINED3DCAPS2_FULLSCREENGAMMA |
4206 WINED3DCAPS2_DYNAMICTEXTURES;
4207 if (gl_info->supported[SGIS_GENERATE_MIPMAP])
4208 caps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
4210 caps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
4211 WINED3DCAPS3_COPY_TO_VIDMEM |
4212 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
4214 caps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
4215 WINED3DPRESENT_INTERVAL_ONE;
4217 caps->CursorCaps = WINED3DCURSORCAPS_COLOR |
4218 WINED3DCURSORCAPS_LOWRES;
4220 caps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
4221 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
4222 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
4223 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
4224 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
4225 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
4226 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
4227 WINED3DDEVCAPS_PUREDEVICE |
4228 WINED3DDEVCAPS_HWRASTERIZATION |
4229 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
4230 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
4231 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
4232 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
4233 WINED3DDEVCAPS_DRAWPRIMITIVES2EX;
4235 caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
4236 WINED3DPMISCCAPS_CULLCCW |
4237 WINED3DPMISCCAPS_CULLCW |
4238 WINED3DPMISCCAPS_COLORWRITEENABLE |
4239 WINED3DPMISCCAPS_CLIPTLVERTS |
4240 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
4241 WINED3DPMISCCAPS_MASKZ |
4242 WINED3DPMISCCAPS_BLENDOP |
4243 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
4244 /* TODO:
4245 WINED3DPMISCCAPS_NULLREFERENCE
4246 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
4247 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
4248 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
4250 if (gl_info->supported[EXT_BLEND_EQUATION_SEPARATE] && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
4251 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
4252 if (gl_info->supported[EXT_DRAW_BUFFERS2])
4253 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS;
4254 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB])
4255 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_POSTBLENDSRGBCONVERT;
4257 caps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
4258 WINED3DPRASTERCAPS_PAT |
4259 WINED3DPRASTERCAPS_WFOG |
4260 WINED3DPRASTERCAPS_ZFOG |
4261 WINED3DPRASTERCAPS_FOGVERTEX |
4262 WINED3DPRASTERCAPS_FOGTABLE |
4263 WINED3DPRASTERCAPS_STIPPLE |
4264 WINED3DPRASTERCAPS_SUBPIXEL |
4265 WINED3DPRASTERCAPS_ZTEST |
4266 WINED3DPRASTERCAPS_SCISSORTEST |
4267 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
4268 WINED3DPRASTERCAPS_DEPTHBIAS;
4270 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4272 caps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
4273 WINED3DPRASTERCAPS_ZBIAS |
4274 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
4277 caps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
4278 WINED3DPCMPCAPS_EQUAL |
4279 WINED3DPCMPCAPS_GREATER |
4280 WINED3DPCMPCAPS_GREATEREQUAL |
4281 WINED3DPCMPCAPS_LESS |
4282 WINED3DPCMPCAPS_LESSEQUAL |
4283 WINED3DPCMPCAPS_NEVER |
4284 WINED3DPCMPCAPS_NOTEQUAL;
4286 /* WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA
4287 * are legacy settings for srcblend only. */
4288 caps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
4289 WINED3DPBLENDCAPS_BOTHSRCALPHA |
4290 WINED3DPBLENDCAPS_DESTALPHA |
4291 WINED3DPBLENDCAPS_DESTCOLOR |
4292 WINED3DPBLENDCAPS_INVDESTALPHA |
4293 WINED3DPBLENDCAPS_INVDESTCOLOR |
4294 WINED3DPBLENDCAPS_INVSRCALPHA |
4295 WINED3DPBLENDCAPS_INVSRCCOLOR |
4296 WINED3DPBLENDCAPS_ONE |
4297 WINED3DPBLENDCAPS_SRCALPHA |
4298 WINED3DPBLENDCAPS_SRCALPHASAT |
4299 WINED3DPBLENDCAPS_SRCCOLOR |
4300 WINED3DPBLENDCAPS_ZERO;
4302 caps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
4303 WINED3DPBLENDCAPS_DESTCOLOR |
4304 WINED3DPBLENDCAPS_INVDESTALPHA |
4305 WINED3DPBLENDCAPS_INVDESTCOLOR |
4306 WINED3DPBLENDCAPS_INVSRCALPHA |
4307 WINED3DPBLENDCAPS_INVSRCCOLOR |
4308 WINED3DPBLENDCAPS_ONE |
4309 WINED3DPBLENDCAPS_SRCALPHA |
4310 WINED3DPBLENDCAPS_SRCCOLOR |
4311 WINED3DPBLENDCAPS_ZERO;
4313 if (gl_info->supported[ARB_BLEND_FUNC_EXTENDED])
4314 caps->DestBlendCaps |= WINED3DPBLENDCAPS_SRCALPHASAT;
4316 if (gl_info->supported[EXT_BLEND_COLOR])
4318 caps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4319 caps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4323 caps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
4324 WINED3DPCMPCAPS_EQUAL |
4325 WINED3DPCMPCAPS_GREATER |
4326 WINED3DPCMPCAPS_GREATEREQUAL |
4327 WINED3DPCMPCAPS_LESS |
4328 WINED3DPCMPCAPS_LESSEQUAL |
4329 WINED3DPCMPCAPS_NEVER |
4330 WINED3DPCMPCAPS_NOTEQUAL;
4332 caps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
4333 WINED3DPSHADECAPS_COLORGOURAUDRGB |
4334 WINED3DPSHADECAPS_ALPHAFLATBLEND |
4335 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
4336 WINED3DPSHADECAPS_COLORFLATRGB |
4337 WINED3DPSHADECAPS_FOGFLAT |
4338 WINED3DPSHADECAPS_FOGGOURAUD |
4339 WINED3DPSHADECAPS_SPECULARFLATRGB;
4341 caps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
4342 WINED3DPTEXTURECAPS_ALPHAPALETTE |
4343 WINED3DPTEXTURECAPS_TRANSPARENCY |
4344 WINED3DPTEXTURECAPS_BORDER |
4345 WINED3DPTEXTURECAPS_MIPMAP |
4346 WINED3DPTEXTURECAPS_PROJECTED |
4347 WINED3DPTEXTURECAPS_PERSPECTIVE;
4349 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4351 caps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
4352 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
4355 if (gl_info->supported[EXT_TEXTURE3D])
4357 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
4358 WINED3DPTEXTURECAPS_MIPVOLUMEMAP;
4359 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4361 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
4365 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4367 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
4368 WINED3DPTEXTURECAPS_MIPCUBEMAP;
4369 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4371 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP_POW2;
4375 caps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
4376 WINED3DPTFILTERCAPS_MAGFPOINT |
4377 WINED3DPTFILTERCAPS_MINFLINEAR |
4378 WINED3DPTFILTERCAPS_MINFPOINT |
4379 WINED3DPTFILTERCAPS_MIPFLINEAR |
4380 WINED3DPTFILTERCAPS_MIPFPOINT |
4381 WINED3DPTFILTERCAPS_LINEAR |
4382 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
4383 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4384 WINED3DPTFILTERCAPS_MIPLINEAR |
4385 WINED3DPTFILTERCAPS_MIPNEAREST |
4386 WINED3DPTFILTERCAPS_NEAREST;
4388 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4390 caps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
4391 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4394 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4396 caps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
4397 WINED3DPTFILTERCAPS_MAGFPOINT |
4398 WINED3DPTFILTERCAPS_MINFLINEAR |
4399 WINED3DPTFILTERCAPS_MINFPOINT |
4400 WINED3DPTFILTERCAPS_MIPFLINEAR |
4401 WINED3DPTFILTERCAPS_MIPFPOINT |
4402 WINED3DPTFILTERCAPS_LINEAR |
4403 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
4404 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4405 WINED3DPTFILTERCAPS_MIPLINEAR |
4406 WINED3DPTFILTERCAPS_MIPNEAREST |
4407 WINED3DPTFILTERCAPS_NEAREST;
4409 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4411 caps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
4412 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4415 else
4417 caps->CubeTextureFilterCaps = 0;
4420 if (gl_info->supported[EXT_TEXTURE3D])
4422 caps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
4423 WINED3DPTFILTERCAPS_MAGFPOINT |
4424 WINED3DPTFILTERCAPS_MINFLINEAR |
4425 WINED3DPTFILTERCAPS_MINFPOINT |
4426 WINED3DPTFILTERCAPS_MIPFLINEAR |
4427 WINED3DPTFILTERCAPS_MIPFPOINT |
4428 WINED3DPTFILTERCAPS_LINEAR |
4429 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
4430 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4431 WINED3DPTFILTERCAPS_MIPLINEAR |
4432 WINED3DPTFILTERCAPS_MIPNEAREST |
4433 WINED3DPTFILTERCAPS_NEAREST;
4435 else
4437 caps->VolumeTextureFilterCaps = 0;
4440 caps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
4441 WINED3DPTADDRESSCAPS_CLAMP |
4442 WINED3DPTADDRESSCAPS_WRAP;
4444 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4446 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4448 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4450 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4452 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
4454 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4457 if (gl_info->supported[EXT_TEXTURE3D])
4459 caps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
4460 WINED3DPTADDRESSCAPS_CLAMP |
4461 WINED3DPTADDRESSCAPS_WRAP;
4462 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4464 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4466 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4468 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4470 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
4472 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4475 else
4477 caps->VolumeTextureAddressCaps = 0;
4480 caps->LineCaps = WINED3DLINECAPS_TEXTURE |
4481 WINED3DLINECAPS_ZTEST |
4482 WINED3DLINECAPS_BLEND |
4483 WINED3DLINECAPS_ALPHACMP |
4484 WINED3DLINECAPS_FOG;
4485 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
4486 * idea how generating the smoothing alpha values works; the result is different
4489 caps->MaxTextureWidth = gl_info->limits.texture_size;
4490 caps->MaxTextureHeight = gl_info->limits.texture_size;
4492 if (gl_info->supported[EXT_TEXTURE3D])
4493 caps->MaxVolumeExtent = gl_info->limits.texture3d_size;
4494 else
4495 caps->MaxVolumeExtent = 0;
4497 caps->MaxTextureRepeat = 32768;
4498 caps->MaxTextureAspectRatio = gl_info->limits.texture_size;
4499 caps->MaxVertexW = 1.0f;
4501 caps->GuardBandLeft = 0.0f;
4502 caps->GuardBandTop = 0.0f;
4503 caps->GuardBandRight = 0.0f;
4504 caps->GuardBandBottom = 0.0f;
4506 caps->ExtentsAdjust = 0.0f;
4508 caps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
4509 WINED3DSTENCILCAPS_INCRSAT |
4510 WINED3DSTENCILCAPS_INVERT |
4511 WINED3DSTENCILCAPS_KEEP |
4512 WINED3DSTENCILCAPS_REPLACE |
4513 WINED3DSTENCILCAPS_ZERO;
4514 if (gl_info->supported[EXT_STENCIL_WRAP])
4516 caps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
4517 WINED3DSTENCILCAPS_INCR;
4519 if (gl_info->supported[EXT_STENCIL_TWO_SIDE] || gl_info->supported[ATI_SEPARATE_STENCIL])
4521 caps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
4524 caps->MaxAnisotropy = gl_info->limits.anisotropy;
4525 caps->MaxPointSize = gl_info->limits.pointsize_max;
4527 caps->MaxPrimitiveCount = 0x555555; /* Taken from an AMD Radeon HD 5700 (Evergreen) GPU. */
4528 caps->MaxVertexIndex = 0xffffff; /* Taken from an AMD Radeon HD 5700 (Evergreen) GPU. */
4529 caps->MaxStreams = MAX_STREAMS;
4530 caps->MaxStreamStride = 1024;
4532 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
4533 caps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
4534 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
4535 caps->MaxNpatchTessellationLevel = 0;
4536 caps->MasterAdapterOrdinal = 0;
4537 caps->AdapterOrdinalInGroup = 0;
4538 caps->NumberOfAdaptersInGroup = 1;
4540 caps->NumSimultaneousRTs = gl_info->limits.buffers;
4542 caps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
4543 WINED3DPTFILTERCAPS_MAGFPOINT |
4544 WINED3DPTFILTERCAPS_MINFLINEAR |
4545 WINED3DPTFILTERCAPS_MAGFLINEAR;
4546 caps->VertexTextureFilterCaps = 0;
4548 adapter->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
4549 adapter->fragment_pipe->get_caps(&adapter->gl_info, &fragment_caps);
4550 adapter->vertex_pipe->vp_get_caps(&adapter->gl_info, &vertex_caps);
4552 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
4553 caps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
4555 caps->VertexShaderVersion = shader_caps.vs_version;
4556 caps->MaxVertexShaderConst = shader_caps.vs_uniform_count;
4558 caps->PixelShaderVersion = shader_caps.ps_version;
4559 caps->PixelShader1xMaxValue = shader_caps.ps_1x_max_value;
4561 caps->TextureOpCaps = fragment_caps.TextureOpCaps;
4562 caps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
4563 caps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
4565 caps->MaxUserClipPlanes = vertex_caps.max_user_clip_planes;
4566 caps->MaxActiveLights = vertex_caps.max_active_lights;
4567 caps->MaxVertexBlendMatrices = vertex_caps.max_vertex_blend_matrices;
4568 caps->MaxVertexBlendMatrixIndex = vertex_caps.max_vertex_blend_matrix_index;
4569 caps->VertexProcessingCaps = vertex_caps.vertex_processing_caps;
4570 caps->FVFCaps = vertex_caps.fvf_caps;
4571 caps->RasterCaps |= vertex_caps.raster_caps;
4573 /* The following caps are shader specific, but they are things we cannot detect, or which
4574 * are the same among all shader models. So to avoid code duplication set the shader version
4575 * specific, but otherwise constant caps here
4577 if (caps->VertexShaderVersion >= 3)
4579 /* Where possible set the caps based on OpenGL extensions and if they
4580 * aren't set (in case of software rendering) use the VS 3.0 from
4581 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
4582 * VS3.0 value. */
4583 caps->VS20Caps.caps = WINED3DVS20CAPS_PREDICATION;
4584 /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4585 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH;
4586 caps->VS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_vs_temps);
4587 /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
4588 caps->VS20Caps.static_flow_control_depth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH;
4590 caps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
4591 caps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions);
4592 caps->VertexTextureFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT | WINED3DPTFILTERCAPS_MAGFPOINT;
4594 else if (caps->VertexShaderVersion == 2)
4596 caps->VS20Caps.caps = 0;
4597 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
4598 caps->VS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_vs_temps);
4599 caps->VS20Caps.static_flow_control_depth = 1;
4601 caps->MaxVShaderInstructionsExecuted = 65535;
4602 caps->MaxVertexShader30InstructionSlots = 0;
4604 else
4605 { /* VS 1.x */
4606 caps->VS20Caps.caps = 0;
4607 caps->VS20Caps.dynamic_flow_control_depth = 0;
4608 caps->VS20Caps.temp_count = 0;
4609 caps->VS20Caps.static_flow_control_depth = 0;
4611 caps->MaxVShaderInstructionsExecuted = 0;
4612 caps->MaxVertexShader30InstructionSlots = 0;
4615 if (caps->PixelShaderVersion >= 3)
4617 /* Where possible set the caps based on OpenGL extensions and if they
4618 * aren't set (in case of software rendering) use the PS 3.0 from
4619 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
4620 * PS 3.0 value. */
4622 /* Caps is more or less undocumented on MSDN but it appears to be
4623 * used for PS20Caps based on results from R9600/FX5900/Geforce6800
4624 * cards from Windows */
4625 caps->PS20Caps.caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
4626 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
4627 WINED3DPS20CAPS_PREDICATION |
4628 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
4629 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
4630 /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4631 caps->PS20Caps.dynamic_flow_control_depth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH;
4632 caps->PS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_ps_temps);
4633 /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
4634 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH;
4635 /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
4636 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS;
4638 caps->MaxPShaderInstructionsExecuted = 65535;
4639 caps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS,
4640 adapter->gl_info.limits.arb_ps_instructions);
4642 else if(caps->PixelShaderVersion == 2)
4644 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
4645 caps->PS20Caps.caps = 0;
4646 caps->PS20Caps.dynamic_flow_control_depth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
4647 caps->PS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_ps_temps);
4648 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
4649 /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
4650 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS;
4652 caps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
4653 caps->MaxPixelShader30InstructionSlots = 0;
4655 else /* PS 1.x */
4657 caps->PS20Caps.caps = 0;
4658 caps->PS20Caps.dynamic_flow_control_depth = 0;
4659 caps->PS20Caps.temp_count = 0;
4660 caps->PS20Caps.static_flow_control_depth = 0;
4661 caps->PS20Caps.instruction_slot_count = 0;
4663 caps->MaxPShaderInstructionsExecuted = 0;
4664 caps->MaxPixelShader30InstructionSlots = 0;
4667 if (caps->VertexShaderVersion >= 2)
4669 /* OpenGL supports all the formats below, perhaps not always
4670 * without conversion, but it supports them.
4671 * Further GLSL doesn't seem to have an official unsigned type so
4672 * don't advertise it yet as I'm not sure how we handle it.
4673 * We might need to add some clamping in the shader engine to
4674 * support it.
4675 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
4676 caps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
4677 WINED3DDTCAPS_UBYTE4N |
4678 WINED3DDTCAPS_SHORT2N |
4679 WINED3DDTCAPS_SHORT4N;
4680 if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
4682 caps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
4683 WINED3DDTCAPS_FLOAT16_4;
4686 else
4688 caps->DeclTypes = 0;
4691 /* Set DirectDraw helper Caps */
4692 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
4693 WINEDDCKEYCAPS_SRCBLT;
4694 fx_caps = WINEDDFXCAPS_BLTALPHA |
4695 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
4696 WINEDDFXCAPS_BLTMIRRORUPDOWN |
4697 WINEDDFXCAPS_BLTROTATION90 |
4698 WINEDDFXCAPS_BLTSHRINKX |
4699 WINEDDFXCAPS_BLTSHRINKXN |
4700 WINEDDFXCAPS_BLTSHRINKY |
4701 WINEDDFXCAPS_BLTSHRINKXN |
4702 WINEDDFXCAPS_BLTSTRETCHX |
4703 WINEDDFXCAPS_BLTSTRETCHXN |
4704 WINEDDFXCAPS_BLTSTRETCHY |
4705 WINEDDFXCAPS_BLTSTRETCHYN;
4706 blit_caps = WINEDDCAPS_BLT |
4707 WINEDDCAPS_BLTCOLORFILL |
4708 WINEDDCAPS_BLTDEPTHFILL |
4709 WINEDDCAPS_BLTSTRETCH |
4710 WINEDDCAPS_CANBLTSYSMEM |
4711 WINEDDCAPS_CANCLIP |
4712 WINEDDCAPS_CANCLIPSTRETCHED |
4713 WINEDDCAPS_COLORKEY |
4714 WINEDDCAPS_COLORKEYHWASSIST |
4715 WINEDDCAPS_ALIGNBOUNDARYSRC;
4717 /* Fill the ddraw caps structure */
4718 caps->ddraw_caps.caps = WINEDDCAPS_GDI |
4719 WINEDDCAPS_PALETTE |
4720 blit_caps;
4721 caps->ddraw_caps.caps2 = WINEDDCAPS2_CERTIFIED |
4722 WINEDDCAPS2_NOPAGELOCKREQUIRED |
4723 WINEDDCAPS2_PRIMARYGAMMA |
4724 WINEDDCAPS2_WIDESURFACES |
4725 WINEDDCAPS2_CANRENDERWINDOWED;
4726 caps->ddraw_caps.color_key_caps = ckey_caps;
4727 caps->ddraw_caps.fx_caps = fx_caps;
4728 caps->ddraw_caps.svb_caps = blit_caps;
4729 caps->ddraw_caps.svb_color_key_caps = ckey_caps;
4730 caps->ddraw_caps.svb_fx_caps = fx_caps;
4731 caps->ddraw_caps.vsb_caps = blit_caps;
4732 caps->ddraw_caps.vsb_color_key_caps = ckey_caps;
4733 caps->ddraw_caps.vsb_fx_caps = fx_caps;
4734 caps->ddraw_caps.ssb_caps = blit_caps;
4735 caps->ddraw_caps.ssb_color_key_caps = ckey_caps;
4736 caps->ddraw_caps.ssb_fx_caps = fx_caps;
4738 caps->ddraw_caps.dds_caps = WINEDDSCAPS_ALPHA |
4739 WINEDDSCAPS_BACKBUFFER |
4740 WINEDDSCAPS_FLIP |
4741 WINEDDSCAPS_FRONTBUFFER |
4742 WINEDDSCAPS_OFFSCREENPLAIN |
4743 WINEDDSCAPS_PALETTE |
4744 WINEDDSCAPS_PRIMARYSURFACE |
4745 WINEDDSCAPS_SYSTEMMEMORY |
4746 WINEDDSCAPS_VIDEOMEMORY |
4747 WINEDDSCAPS_VISIBLE;
4749 if (!(wined3d->flags & WINED3D_NO3D))
4751 caps->ddraw_caps.dds_caps |= WINEDDSCAPS_3DDEVICE |
4752 WINEDDSCAPS_MIPMAP |
4753 WINEDDSCAPS_TEXTURE |
4754 WINEDDSCAPS_ZBUFFER;
4755 caps->ddraw_caps.caps |= WINEDDCAPS_3D;
4758 return WINED3D_OK;
4761 HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type,
4762 HWND focus_window, DWORD flags, BYTE surface_alignment, struct wined3d_device_parent *device_parent,
4763 struct wined3d_device **device)
4765 struct wined3d_device *object;
4766 HRESULT hr;
4768 TRACE("wined3d %p, adapter_idx %u, device_type %#x, focus_window %p, flags %#x, device_parent %p, device %p.\n",
4769 wined3d, adapter_idx, device_type, focus_window, flags, device_parent, device);
4771 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
4772 * number and create a device without a 3D adapter for 2D only operation. */
4773 if (wined3d->adapter_count && adapter_idx >= wined3d->adapter_count)
4774 return WINED3DERR_INVALIDCALL;
4776 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
4777 if (!object)
4778 return E_OUTOFMEMORY;
4780 hr = device_init(object, wined3d, adapter_idx, device_type,
4781 focus_window, flags, surface_alignment, device_parent);
4782 if (FAILED(hr))
4784 WARN("Failed to initialize device, hr %#x.\n", hr);
4785 HeapFree(GetProcessHeap(), 0, object);
4786 return hr;
4789 TRACE("Created device %p.\n", object);
4790 *device = object;
4792 device_parent->ops->wined3d_device_created(device_parent, *device);
4794 return WINED3D_OK;
4797 static void WINE_GLAPI invalid_func(const void *data)
4799 ERR("Invalid vertex attribute function called\n");
4800 DebugBreak();
4803 static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
4805 ERR("Invalid texcoord function called\n");
4806 DebugBreak();
4809 /* Helper functions for providing vertex data to opengl. The arrays are initialized based on
4810 * the extension detection and are used in drawStridedSlow
4812 static void WINE_GLAPI position_d3dcolor(const void *data)
4814 DWORD pos = *((const DWORD *)data);
4816 FIXME("Add a test for fixed function position from d3dcolor type\n");
4817 context_get_current()->gl_info->gl_ops.gl.p_glVertex4s(D3DCOLOR_B_R(pos),
4818 D3DCOLOR_B_G(pos),
4819 D3DCOLOR_B_B(pos),
4820 D3DCOLOR_B_A(pos));
4823 static void WINE_GLAPI position_float4(const void *data)
4825 const GLfloat *pos = data;
4827 if (pos[3] != 0.0f && pos[3] != 1.0f)
4829 float w = 1.0f / pos[3];
4831 context_get_current()->gl_info->gl_ops.gl.p_glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
4833 else
4835 context_get_current()->gl_info->gl_ops.gl.p_glVertex3fv(pos);
4839 static void WINE_GLAPI diffuse_d3dcolor(const void *data)
4841 DWORD diffuseColor = *((const DWORD *)data);
4843 context_get_current()->gl_info->gl_ops.gl.p_glColor4ub(D3DCOLOR_B_R(diffuseColor),
4844 D3DCOLOR_B_G(diffuseColor),
4845 D3DCOLOR_B_B(diffuseColor),
4846 D3DCOLOR_B_A(diffuseColor));
4849 static void WINE_GLAPI specular_d3dcolor(const void *data)
4851 DWORD specularColor = *((const DWORD *)data);
4852 GLubyte d[] =
4854 D3DCOLOR_B_R(specularColor),
4855 D3DCOLOR_B_G(specularColor),
4856 D3DCOLOR_B_B(specularColor)
4859 context_get_current()->gl_info->gl_ops.ext.p_glSecondaryColor3ubvEXT(d);
4862 static void WINE_GLAPI warn_no_specular_func(const void *data)
4864 WARN("GL_EXT_secondary_color not supported\n");
4867 static void wined3d_adapter_init_ffp_attrib_ops(struct wined3d_adapter *adapter)
4869 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4870 struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
4871 struct wined3d_ffp_attrib_ops *ops = &d3d_info->ffp_attrib_ops;
4873 ops->position[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4874 ops->position[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4875 ops->position[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex3fv;
4876 if (!d3d_info->xyzrhw)
4877 ops->position[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
4878 else
4879 ops->position[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex4fv;
4880 ops->position[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
4881 ops->position[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4882 ops->position[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4883 ops->position[WINED3D_FFP_EMIT_SHORT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glVertex2sv;
4884 ops->position[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4885 ops->position[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4886 ops->position[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4887 ops->position[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4888 ops->position[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4889 ops->position[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4890 ops->position[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4891 ops->position[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4892 ops->position[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4893 ops->position[WINED3D_FFP_EMIT_INVALID] = invalid_func;
4895 ops->diffuse[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4896 ops->diffuse[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4897 ops->diffuse[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor3fv;
4898 ops->diffuse[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4fv;
4899 ops->diffuse[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
4900 ops->diffuse[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4901 ops->diffuse[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4902 ops->diffuse[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4903 ops->diffuse[WINED3D_FFP_EMIT_UBYTE4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4ubv;
4904 ops->diffuse[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4905 ops->diffuse[WINED3D_FFP_EMIT_SHORT4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4sv;
4906 ops->diffuse[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4907 ops->diffuse[WINED3D_FFP_EMIT_USHORT4N] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glColor4usv;
4908 ops->diffuse[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4909 ops->diffuse[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4910 ops->diffuse[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4911 ops->diffuse[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4912 ops->diffuse[WINED3D_FFP_EMIT_INVALID] = invalid_func;
4914 /* No 4 component entry points here. */
4915 ops->specular[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4916 ops->specular[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4917 if (gl_info->supported[EXT_SECONDARY_COLOR])
4918 ops->specular[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)GL_EXTCALL(glSecondaryColor3fvEXT);
4919 else
4920 ops->specular[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
4921 ops->specular[WINED3D_FFP_EMIT_FLOAT4] = invalid_func;
4922 if (gl_info->supported[EXT_SECONDARY_COLOR])
4923 ops->specular[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
4924 else
4925 ops->specular[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
4926 ops->specular[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4927 ops->specular[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4928 ops->specular[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4929 ops->specular[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4930 ops->specular[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4931 ops->specular[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4932 ops->specular[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4933 ops->specular[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4934 ops->specular[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4935 ops->specular[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4936 ops->specular[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4937 ops->specular[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4938 ops->specular[WINED3D_FFP_EMIT_INVALID] = invalid_func;
4940 /* Only 3 component entry points here. Test how others behave. Float4
4941 * normals are used by one of our tests, trying to pass it to the pixel
4942 * shader, which fails on Windows. */
4943 ops->normal[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
4944 ops->normal[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
4945 ops->normal[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glNormal3fv;
4946 /* Just ignore the 4th value. */
4947 ops->normal[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_attrib_func)gl_info->gl_ops.gl.p_glNormal3fv;
4948 ops->normal[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_func;
4949 ops->normal[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
4950 ops->normal[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
4951 ops->normal[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
4952 ops->normal[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
4953 ops->normal[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
4954 ops->normal[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
4955 ops->normal[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
4956 ops->normal[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
4957 ops->normal[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
4958 ops->normal[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
4959 ops->normal[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
4960 ops->normal[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
4961 ops->normal[WINED3D_FFP_EMIT_INVALID] = invalid_func;
4963 ops->texcoord[WINED3D_FFP_EMIT_FLOAT1] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord1fvARB;
4964 ops->texcoord[WINED3D_FFP_EMIT_FLOAT2] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2fvARB;
4965 ops->texcoord[WINED3D_FFP_EMIT_FLOAT3] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord3fvARB;
4966 ops->texcoord[WINED3D_FFP_EMIT_FLOAT4] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4fvARB;
4967 ops->texcoord[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_texcoord_func;
4968 ops->texcoord[WINED3D_FFP_EMIT_UBYTE4] = invalid_texcoord_func;
4969 ops->texcoord[WINED3D_FFP_EMIT_SHORT2] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2svARB;
4970 ops->texcoord[WINED3D_FFP_EMIT_SHORT4] = (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4svARB;
4971 ops->texcoord[WINED3D_FFP_EMIT_UBYTE4N] = invalid_texcoord_func;
4972 ops->texcoord[WINED3D_FFP_EMIT_SHORT2N] = invalid_texcoord_func;
4973 ops->texcoord[WINED3D_FFP_EMIT_SHORT4N] = invalid_texcoord_func;
4974 ops->texcoord[WINED3D_FFP_EMIT_USHORT2N] = invalid_texcoord_func;
4975 ops->texcoord[WINED3D_FFP_EMIT_USHORT4N] = invalid_texcoord_func;
4976 ops->texcoord[WINED3D_FFP_EMIT_UDEC3] = invalid_texcoord_func;
4977 ops->texcoord[WINED3D_FFP_EMIT_DEC3N] = invalid_texcoord_func;
4978 if (gl_info->supported[NV_HALF_FLOAT])
4980 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT. */
4981 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_2] =
4982 (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord2hvNV;
4983 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_4] =
4984 (wined3d_ffp_texcoord_func)gl_info->gl_ops.ext.p_glMultiTexCoord4hvNV;
4986 else
4988 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
4989 ops->texcoord[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
4991 ops->texcoord[WINED3D_FFP_EMIT_INVALID] = invalid_texcoord_func;
4994 static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter *adapter, HDC dc)
4996 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4997 int i;
4999 if (gl_info->supported[WGL_ARB_PIXEL_FORMAT])
5001 UINT attrib_count = 0;
5002 GLint cfg_count;
5003 int attribs[11];
5004 int values[11];
5005 int attribute;
5007 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
5008 GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, 0, 0, 1, &attribute, &cfg_count));
5010 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cfg_count * sizeof(*adapter->cfgs));
5011 attribs[attrib_count++] = WGL_RED_BITS_ARB;
5012 attribs[attrib_count++] = WGL_GREEN_BITS_ARB;
5013 attribs[attrib_count++] = WGL_BLUE_BITS_ARB;
5014 attribs[attrib_count++] = WGL_ALPHA_BITS_ARB;
5015 attribs[attrib_count++] = WGL_COLOR_BITS_ARB;
5016 attribs[attrib_count++] = WGL_DEPTH_BITS_ARB;
5017 attribs[attrib_count++] = WGL_STENCIL_BITS_ARB;
5018 attribs[attrib_count++] = WGL_DRAW_TO_WINDOW_ARB;
5019 attribs[attrib_count++] = WGL_PIXEL_TYPE_ARB;
5020 attribs[attrib_count++] = WGL_DOUBLE_BUFFER_ARB;
5021 attribs[attrib_count++] = WGL_AUX_BUFFERS_ARB;
5023 for (i = 0, adapter->cfg_count = 0; i < cfg_count; ++i)
5025 struct wined3d_pixel_format *cfg = &adapter->cfgs[adapter->cfg_count];
5026 int format_id = i + 1;
5028 if (!GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, attrib_count, attribs, values)))
5029 continue;
5031 cfg->iPixelFormat = format_id;
5032 cfg->redSize = values[0];
5033 cfg->greenSize = values[1];
5034 cfg->blueSize = values[2];
5035 cfg->alphaSize = values[3];
5036 cfg->colorSize = values[4];
5037 cfg->depthSize = values[5];
5038 cfg->stencilSize = values[6];
5039 cfg->windowDrawable = values[7];
5040 cfg->iPixelType = values[8];
5041 cfg->doubleBuffer = values[9];
5042 cfg->auxBuffers = values[10];
5044 cfg->numSamples = 0;
5045 /* Check multisample support. */
5046 if (gl_info->supported[ARB_MULTISAMPLE])
5048 int attribs[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
5049 int values[2];
5051 if (GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, 2, attribs, values)))
5053 /* values[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether
5054 * multisampling is supported. values[1] = number of
5055 * multisample buffers. */
5056 if (values[0])
5057 cfg->numSamples = values[1];
5061 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5062 "depth=%d, stencil=%d, samples=%d, windowDrawable=%d\n",
5063 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
5064 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
5065 cfg->depthSize, cfg->stencilSize, cfg->numSamples, cfg->windowDrawable);
5067 ++adapter->cfg_count;
5070 else
5072 int cfg_count;
5074 cfg_count = DescribePixelFormat(dc, 0, 0, 0);
5075 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cfg_count * sizeof(*adapter->cfgs));
5077 for (i = 0, adapter->cfg_count = 0; i < cfg_count; ++i)
5079 struct wined3d_pixel_format *cfg = &adapter->cfgs[adapter->cfg_count];
5080 PIXELFORMATDESCRIPTOR pfd;
5081 int format_id = i + 1;
5083 if (!DescribePixelFormat(dc, format_id, sizeof(pfd), &pfd))
5084 continue;
5086 /* We only want HW acceleration using an OpenGL ICD driver.
5087 * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering.
5088 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD
5089 * driver (e.g. 3dfx minigl). */
5090 if (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
5092 TRACE("Skipping format %d because it isn't ICD accelerated.\n", format_id);
5093 continue;
5096 cfg->iPixelFormat = format_id;
5097 cfg->redSize = pfd.cRedBits;
5098 cfg->greenSize = pfd.cGreenBits;
5099 cfg->blueSize = pfd.cBlueBits;
5100 cfg->alphaSize = pfd.cAlphaBits;
5101 cfg->colorSize = pfd.cColorBits;
5102 cfg->depthSize = pfd.cDepthBits;
5103 cfg->stencilSize = pfd.cStencilBits;
5104 cfg->windowDrawable = (pfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
5105 cfg->iPixelType = (pfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
5106 cfg->doubleBuffer = (pfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
5107 cfg->auxBuffers = pfd.cAuxBuffers;
5108 cfg->numSamples = 0;
5110 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5111 "depth=%d, stencil=%d, windowDrawable=%d\n",
5112 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
5113 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
5114 cfg->depthSize, cfg->stencilSize, cfg->windowDrawable);
5116 ++adapter->cfg_count;
5121 static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal)
5123 struct wined3d_gl_info *gl_info = &adapter->gl_info;
5124 struct wined3d_caps_gl_ctx caps_gl_ctx = {0};
5125 unsigned int ctx_attrib_idx = 0;
5126 DISPLAY_DEVICEW display_device;
5127 GLint ctx_attribs[3];
5129 TRACE("adapter %p, ordinal %u.\n", adapter, ordinal);
5131 adapter->ordinal = ordinal;
5132 adapter->monitorPoint.x = -1;
5133 adapter->monitorPoint.y = -1;
5135 /* Dynamically load all GL core functions */
5136 #ifdef USE_WIN32_OPENGL
5138 HMODULE mod_gl = GetModuleHandleA("opengl32.dll");
5139 #define USE_GL_FUNC(f) gl_info->gl_ops.gl.p_##f = (void *)GetProcAddress(mod_gl, #f);
5140 ALL_WGL_FUNCS
5141 #undef USE_GL_FUNC
5142 gl_info->gl_ops.wgl.p_wglSwapBuffers = (void *)GetProcAddress(mod_gl, "wglSwapBuffers");
5144 #else
5145 /* To bypass the opengl32 thunks retrieve functions from the WGL driver instead of opengl32 */
5147 HDC hdc = GetDC( 0 );
5148 const struct opengl_funcs *wgl_driver = __wine_get_wgl_driver( hdc, WINE_WGL_DRIVER_VERSION );
5149 ReleaseDC( 0, hdc );
5150 if (!wgl_driver || wgl_driver == (void *)-1) return FALSE;
5151 gl_info->gl_ops.wgl = wgl_driver->wgl;
5152 gl_info->gl_ops.gl = wgl_driver->gl;
5154 #endif
5156 glEnableWINE = gl_info->gl_ops.gl.p_glEnable;
5157 glDisableWINE = gl_info->gl_ops.gl.p_glDisable;
5159 if (!AllocateLocallyUniqueId(&adapter->luid))
5161 ERR("Failed to set adapter LUID (%#x).\n", GetLastError());
5162 return FALSE;
5164 TRACE("Allocated LUID %08x:%08x for adapter %p.\n",
5165 adapter->luid.HighPart, adapter->luid.LowPart, adapter);
5167 if (!wined3d_caps_gl_ctx_create(&caps_gl_ctx))
5169 ERR("Failed to get a GL context for adapter %p.\n", adapter);
5170 return FALSE;
5173 if (context_debug_output_enabled(gl_info))
5175 ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_FLAGS_ARB;
5176 ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_DEBUG_BIT_ARB;
5178 ctx_attribs[ctx_attrib_idx] = 0;
5179 wined3d_caps_gl_ctx_create_attribs(&caps_gl_ctx, gl_info, ctx_attribs);
5181 if (!wined3d_adapter_init_gl_caps(adapter))
5183 ERR("Failed to initialize GL caps for adapter %p.\n", adapter);
5184 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5185 return FALSE;
5188 wined3d_adapter_init_fb_cfgs(adapter, caps_gl_ctx.dc);
5189 /* We haven't found any suitable formats. This should only happen in
5190 * case of GDI software rendering, which is pretty useless anyway. */
5191 if (!adapter->cfg_count)
5193 WARN("No suitable pixel formats found.\n");
5194 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5195 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
5196 return FALSE;
5199 if (!wined3d_adapter_init_format_info(adapter))
5201 ERR("Failed to initialize GL format info.\n");
5202 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5203 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
5204 return FALSE;
5207 adapter->TextureRam = adapter->driver_info.vidmem;
5208 adapter->UsedTextureRam = 0;
5209 TRACE("Emulating %u MB of texture ram.\n", adapter->TextureRam / (1024 * 1024));
5211 display_device.cb = sizeof(display_device);
5212 EnumDisplayDevicesW(NULL, ordinal, &display_device, 0);
5213 TRACE("DeviceName: %s\n", debugstr_w(display_device.DeviceName));
5214 strcpyW(adapter->DeviceName, display_device.DeviceName);
5216 wined3d_caps_gl_ctx_destroy(&caps_gl_ctx);
5218 wined3d_adapter_init_ffp_attrib_ops(adapter);
5220 return TRUE;
5223 static void wined3d_adapter_init_nogl(struct wined3d_adapter *adapter, UINT ordinal)
5225 DISPLAY_DEVICEW display_device;
5227 memset(adapter, 0, sizeof(*adapter));
5228 adapter->ordinal = ordinal;
5229 adapter->monitorPoint.x = -1;
5230 adapter->monitorPoint.y = -1;
5232 adapter->driver_info.name = "Display";
5233 adapter->driver_info.description = "WineD3D DirectDraw Emulation";
5234 if (wined3d_settings.emulated_textureram)
5235 adapter->TextureRam = wined3d_settings.emulated_textureram;
5236 else
5237 adapter->TextureRam = 128 * 1024 * 1024;
5239 initPixelFormatsNoGL(&adapter->gl_info);
5241 adapter->vertex_pipe = &none_vertex_pipe;
5242 adapter->fragment_pipe = &none_fragment_pipe;
5243 adapter->shader_backend = &none_shader_backend;
5244 adapter->blitter = &cpu_blit;
5246 display_device.cb = sizeof(display_device);
5247 EnumDisplayDevicesW(NULL, ordinal, &display_device, 0);
5248 TRACE("DeviceName: %s\n", debugstr_w(display_device.DeviceName));
5249 strcpyW(adapter->DeviceName, display_device.DeviceName);
5252 static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
5254 const struct wined3d_parent_ops wined3d_null_parent_ops =
5256 wined3d_null_wined3d_object_destroyed,
5259 HRESULT wined3d_init(struct wined3d *wined3d, DWORD flags)
5261 wined3d->ref = 1;
5262 wined3d->flags = flags;
5264 TRACE("Initializing adapters.\n");
5266 if (flags & WINED3D_NO3D)
5268 wined3d_adapter_init_nogl(&wined3d->adapters[0], 0);
5269 wined3d->adapter_count = 1;
5270 return WINED3D_OK;
5273 if (!wined3d_adapter_init(&wined3d->adapters[0], 0))
5275 WARN("Failed to initialize adapter.\n");
5276 return E_FAIL;
5278 wined3d->adapter_count = 1;
5280 return WINED3D_OK;