VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/Graphics/Wine_new/wined3d/directx.c@ 51270

Last change on this file since 51270 was 51270, checked in by vboxsync, 11 years ago

wine: update to 1.6.2

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 247.0 KB
Line 
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
8 *
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.
13 *
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.
18 *
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
22 */
23
24/*
25 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
26 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
27 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
28 * a choice of LGPL license versions is made available with the language indicating
29 * that LGPLv2 or any later version may be used, or where a choice of which version
30 * of the LGPL is applied is otherwise unspecified.
31 */
32
33#include "config.h"
34#include "wine/port.h"
35
36#include <stdio.h>
37
38#include "wined3d_private.h"
39#include "winternl.h"
40#ifdef VBOX_WITH_WDDM
41#include <VBox/VBoxCrHgsmi.h>
42#endif
43
44WINE_DEFAULT_DEBUG_CHANNEL(d3d);
45WINE_DECLARE_DEBUG_CHANNEL(d3d_perf);
46
47#define WINE_DEFAULT_VIDMEM (64 * 1024 * 1024)
48
49/* The driver names reflect the lowest GPU supported
50 * by a certain driver, so DRIVER_AMD_R300 supports
51 * R3xx, R4xx and R5xx GPUs. */
52enum wined3d_display_driver
53{
54 DRIVER_AMD_RAGE_128PRO,
55 DRIVER_AMD_R100,
56 DRIVER_AMD_R300,
57 DRIVER_AMD_R600,
58 DRIVER_INTEL_GMA800,
59 DRIVER_INTEL_GMA900,
60 DRIVER_INTEL_GMA950,
61 DRIVER_INTEL_GMA3000,
62 DRIVER_NVIDIA_TNT,
63 DRIVER_NVIDIA_GEFORCE2MX,
64 DRIVER_NVIDIA_GEFORCEFX,
65 DRIVER_NVIDIA_GEFORCE6,
66 DRIVER_UNKNOWN
67};
68
69enum wined3d_driver_model
70{
71 DRIVER_MODEL_WIN9X,
72 DRIVER_MODEL_NT40,
73 DRIVER_MODEL_NT5X,
74 DRIVER_MODEL_NT6X
75};
76
77enum wined3d_gl_vendor
78{
79 GL_VENDOR_UNKNOWN,
80 GL_VENDOR_APPLE,
81 GL_VENDOR_FGLRX,
82 GL_VENDOR_INTEL,
83 GL_VENDOR_MESA,
84 GL_VENDOR_NVIDIA,
85};
86
87/* The d3d device ID */
88static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
89
90/* Extension detection */
91struct wined3d_extension_map
92{
93 const char *extension_string;
94 enum wined3d_gl_extension extension;
95};
96
97static const struct wined3d_extension_map gl_extension_map[] =
98{
99 /* APPLE */
100 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE },
101 {"GL_APPLE_fence", APPLE_FENCE },
102 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS },
103 {"GL_APPLE_flush_buffer_range", APPLE_FLUSH_BUFFER_RANGE },
104 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422 },
105
106 /* ARB */
107 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT },
108 {"GL_ARB_debug_output", ARB_DEBUG_OUTPUT },
109 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT },
110 {"GL_ARB_depth_clamp", ARB_DEPTH_CLAMP },
111 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE },
112 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS },
113 {"GL_ARB_draw_elements_base_vertex", ARB_DRAW_ELEMENTS_BASE_VERTEX },
114 {"GL_ARB_draw_instanced", ARB_DRAW_INSTANCED },
115 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM },
116 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER },
117 {"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT },
118 {"GL_ARB_framebuffer_sRGB", ARB_FRAMEBUFFER_SRGB },
119 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4 },
120 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL },
121 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX },
122 {"GL_ARB_instanced_arrays", ARB_INSTANCED_ARRAYS, },
123 {"GL_ARB_internalformat_query2", ARB_INTERNALFORMAT_QUERY2, },
124 {"GL_ARB_map_buffer_alignment", ARB_MAP_BUFFER_ALIGNMENT },
125 {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE },
126 {"GL_ARB_multisample", ARB_MULTISAMPLE }, /* needs GLX_ARB_MULTISAMPLE as well */
127 {"GL_ARB_multitexture", ARB_MULTITEXTURE },
128 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY },
129 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT },
130 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS },
131 {"GL_ARB_point_sprite", ARB_POINT_SPRITE },
132 {"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX },
133 {"GL_ARB_shader_bit_encoding", ARB_SHADER_BIT_ENCODING },
134 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS },
135 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD },
136 {"GL_ARB_shading_language_100", ARB_SHADING_LANGUAGE_100 },
137 {"GL_ARB_shadow", ARB_SHADOW },
138 {"GL_ARB_sync", ARB_SYNC },
139 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP },
140 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION },
141 {"GL_ARB_texture_compression_rgtc", ARB_TEXTURE_COMPRESSION_RGTC },
142 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP },
143 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD },
144 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE },
145 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3 },
146 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT },
147 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT },
148 {"GL_ARB_texture_mirror_clamp_to_edge", ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE},
149#ifdef VBOX_WITH_WINE_FIX_IBMTMR
150 {"GL_IBM_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT },
151#endif
152 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO },
153 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE },
154 {"GL_ARB_texture_rg", ARB_TEXTURE_RG },
155 {"GL_ARB_vertex_array_bgra", ARB_VERTEX_ARRAY_BGRA },
156 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND },
157 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT },
158 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM },
159 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER },
160
161 /* ATI */
162 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER },
163 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL },
164 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC },
165 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3 },
166 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE },
167
168 /* EXT */
169 {"GL_EXT_blend_color", EXT_BLEND_COLOR },
170 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE },
171 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE },
172 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX },
173 {"GL_EXT_blend_subtract", EXT_BLEND_SUBTRACT },
174 {"GL_EXT_depth_bounds_test", EXT_DEPTH_BOUNDS_TEST },
175 {"GL_EXT_draw_buffers2", EXT_DRAW_BUFFERS2 },
176 {"GL_EXT_fog_coord", EXT_FOG_COORD },
177 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT },
178 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE },
179 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT },
180 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS },
181 {"GL_EXT_gpu_shader4", EXT_GPU_SHADER4 },
182 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL },
183 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE },
184 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS },
185 {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX },
186 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR },
187 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE },
188 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP },
189 {"GL_EXT_texture3D", EXT_TEXTURE3D },
190 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC },
191 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC },
192 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD },
193 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE },
194 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3 },
195 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC},
196 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS },
197 {"GL_EXT_texture_mirror_clamp", EXT_TEXTURE_MIRROR_CLAMP },
198 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB },
199 {"GL_EXT_texture_sRGB_decode", EXT_TEXTURE_SRGB_DECODE },
200 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA },
201
202 /* NV */
203 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP },
204 {"GL_NV_fence", NV_FENCE },
205 {"GL_NV_fog_distance", NV_FOG_DISTANCE },
206 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM },
207 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2 },
208 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION },
209 {"GL_NV_half_float", NV_HALF_FLOAT },
210 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT },
211 {"GL_NV_point_sprite", NV_POINT_SPRITE },
212 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS },
213 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2 },
214 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION },
215 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4 },
216 {"GL_NV_texture_shader", NV_TEXTURE_SHADER },
217 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2 },
218 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM },
219 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1 },
220 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2 },
221 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION },
222 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3 },
223
224 /* SGI */
225 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP },
226};
227
228static const struct wined3d_extension_map wgl_extension_map[] =
229{
230 {"WGL_ARB_pixel_format", WGL_ARB_PIXEL_FORMAT },
231 {"WGL_EXT_swap_control", WGL_EXT_SWAP_CONTROL },
232 {"WGL_WINE_pixel_format_passthrough", WGL_WINE_PIXEL_FORMAT_PASSTHROUGH},
233};
234
235/**********************************************************
236 * Utility functions follow
237 **********************************************************/
238
239const struct min_lookup minMipLookup[] =
240{
241 /* NONE POINT LINEAR */
242 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
243 {{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
244 {{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
245};
246
247const struct min_lookup minMipLookup_noFilter[] =
248{
249 /* NONE POINT LINEAR */
250 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
251 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
252 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* LINEAR */
253};
254
255const struct min_lookup minMipLookup_noMip[] =
256{
257 /* NONE POINT LINEAR */
258 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
259 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
260 {{GL_LINEAR, GL_LINEAR, GL_LINEAR }}, /* LINEAR */
261};
262
263const GLenum magLookup[] =
264{
265 /* NONE POINT LINEAR */
266 GL_NEAREST, GL_NEAREST, GL_LINEAR,
267};
268
269const GLenum magLookup_noFilter[] =
270{
271 /* NONE POINT LINEAR */
272 GL_NEAREST, GL_NEAREST, GL_NEAREST,
273};
274
275/* drawStridedSlow attributes */
276glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
277glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
278glAttribFunc specular_func_3ubv;
279glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
280glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
281glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
282
283/**
284 * Note: GL seems to trap if GetDeviceCaps is called before any HWND's created,
285 * i.e., there is no GL Context - Get a default rendering context to enable the
286 * function query some info from GL.
287 */
288
289struct wined3d_fake_gl_ctx
290{
291 HDC dc;
292 HWND wnd;
293 HGLRC gl_ctx;
294 HDC restore_dc;
295 HGLRC restore_gl_ctx;
296};
297
298static void WineD3D_ReleaseFakeGLContext(const struct wined3d_fake_gl_ctx *ctx)
299{
300 TRACE("Destroying fake GL context.\n");
301
302 if (!wglMakeCurrent(NULL, NULL))
303 ERR("Failed to disable fake GL context.\n");
304
305 if (!wglDeleteContext(ctx->gl_ctx))
306 {
307 DWORD err = GetLastError();
308 ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx->gl_ctx, err);
309 }
310
311 wined3d_release_dc(ctx->wnd, ctx->dc);
312 DestroyWindow(ctx->wnd);
313
314 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
315 ERR("Failed to restore previous GL context.\n");
316}
317
318static void wined3d_create_fake_gl_context_attribs(struct wined3d_fake_gl_ctx *fake_gl_ctx,
319 struct wined3d_gl_info *gl_info, const GLint *ctx_attribs)
320{
321 HGLRC new_ctx;
322
323 if (!(gl_info->p_wglCreateContextAttribsARB = (void *)wglGetProcAddress("wglCreateContextAttribsARB")))
324 return;
325
326 if (!(new_ctx = gl_info->p_wglCreateContextAttribsARB(fake_gl_ctx->dc, NULL, ctx_attribs)))
327 {
328 ERR("Failed to create a context using wglCreateContextAttribsARB(), last error %#x.\n", GetLastError());
329 gl_info->p_wglCreateContextAttribsARB = NULL;
330 return;
331 }
332
333 if (!wglMakeCurrent(fake_gl_ctx->dc, new_ctx))
334 {
335 ERR("Failed to make new context current, last error %#x.\n", GetLastError());
336 if (!wglDeleteContext(new_ctx))
337 ERR("Failed to delete new context, last error %#x.\n", GetLastError());
338 gl_info->p_wglCreateContextAttribsARB = NULL;
339 return;
340 }
341
342 if (!wglDeleteContext(fake_gl_ctx->gl_ctx))
343 ERR("Failed to delete old context, last error %#x.\n", GetLastError());
344 fake_gl_ctx->gl_ctx = new_ctx;
345}
346
347/* Do not call while under the GL lock. */
348#ifdef VBOX
349static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx, struct VBOXUHGSMI *pHgsmi)
350#else
351static BOOL WineD3D_CreateFakeGLContext(struct wined3d_fake_gl_ctx *ctx)
352#endif
353{
354 PIXELFORMATDESCRIPTOR pfd;
355 int iPixelFormat;
356
357 TRACE("getting context...\n");
358
359 ctx->restore_dc = wglGetCurrentDC();
360 ctx->restore_gl_ctx = wglGetCurrentContext();
361
362 /* We need a fake window as a hdc retrieved using GetDC(0) can't be used for much GL purposes. */
363 ctx->wnd = CreateWindowA(WINED3D_OPENGL_WINDOW_CLASS_NAME, "WineD3D fake window",
364 WS_OVERLAPPEDWINDOW, 10, 10, 10, 10, NULL, NULL, NULL, NULL);
365 if (!ctx->wnd)
366 {
367 ERR("Failed to create a window.\n");
368 goto fail;
369 }
370
371 ctx->dc = GetDC(ctx->wnd);
372 if (!ctx->dc)
373 {
374 ERR("Failed to get a DC.\n");
375 goto fail;
376 }
377
378 /* PixelFormat selection */
379 ZeroMemory(&pfd, sizeof(pfd));
380 pfd.nSize = sizeof(pfd);
381 pfd.nVersion = 1;
382 pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER | PFD_DRAW_TO_WINDOW; /* PFD_GENERIC_ACCELERATED */
383 pfd.iPixelType = PFD_TYPE_RGBA;
384 pfd.cColorBits = 32;
385 pfd.iLayerType = PFD_MAIN_PLANE;
386
387 if (!(iPixelFormat = ChoosePixelFormat(ctx->dc, &pfd)))
388 {
389 /* If this happens something is very wrong as ChoosePixelFormat barely fails. */
390 ERR("Failed to find a suitable pixel format.\n");
391 goto fail;
392 }
393 DescribePixelFormat(ctx->dc, iPixelFormat, sizeof(pfd), &pfd);
394 SetPixelFormat(ctx->dc, iPixelFormat, &pfd);
395
396 /* Create a GL context. */
397#ifdef VBOX
398 if (!(ctx->gl_ctx = pVBoxCreateContext(ctx->dc, pHgsmi)))
399#else
400 if (!(ctx->gl_ctx = wglCreateContext(ctx->dc)))
401#endif
402 {
403 WARN("Failed to create default context for capabilities initialization.\n");
404 goto fail;
405 }
406
407#ifdef VBOX_WITH_WDDM
408 pVBoxCtxChromiumParameteriCR(ctx->gl_ctx, GL_HOST_WND_CREATED_HIDDEN_CR, GL_TRUE);
409#endif
410
411 /* Make it the current GL context. */
412 if (!wglMakeCurrent(ctx->dc, ctx->gl_ctx))
413 {
414 ERR("Failed to make fake GL context current.\n");
415 goto fail;
416 }
417
418 return TRUE;
419
420fail:
421 if (ctx->gl_ctx) wglDeleteContext(ctx->gl_ctx);
422 ctx->gl_ctx = NULL;
423 if (ctx->dc) ReleaseDC(ctx->wnd, ctx->dc);
424 ctx->dc = NULL;
425 if (ctx->wnd) DestroyWindow(ctx->wnd);
426 ctx->wnd = NULL;
427 if (ctx->restore_gl_ctx && !wglMakeCurrent(ctx->restore_dc, ctx->restore_gl_ctx))
428 ERR("Failed to restore previous GL context.\n");
429
430 return FALSE;
431}
432
433/* Adjust the amount of used texture memory */
434#ifndef VBOX_WITH_WDDM
435unsigned int adapter_adjust_memory(struct wined3d_adapter *adapter, int amount)
436{
437 adapter->UsedTextureRam += amount;
438 TRACE("Adjusted adapter memory by %d to %d.\n", amount, adapter->UsedTextureRam);
439 return adapter->UsedTextureRam;
440}
441#endif
442
443static void wined3d_adapter_cleanup(struct wined3d_adapter *adapter)
444{
445 HeapFree(GetProcessHeap(), 0, adapter->gl_info.formats);
446 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
447}
448
449ULONG CDECL wined3d_incref(struct wined3d *wined3d)
450{
451 ULONG refcount = InterlockedIncrement(&wined3d->ref);
452
453 TRACE("%p increasing refcount to %u.\n", wined3d, refcount);
454
455 return refcount;
456}
457
458ULONG CDECL wined3d_decref(struct wined3d *wined3d)
459{
460 ULONG refcount = InterlockedDecrement(&wined3d->ref);
461
462 TRACE("%p decreasing refcount to %u.\n", wined3d, refcount);
463
464 if (!refcount)
465 {
466 unsigned int i;
467
468 for (i = 0; i < wined3d->adapter_count; ++i)
469 {
470 wined3d_adapter_cleanup(&wined3d->adapters[i]);
471 }
472 HeapFree(GetProcessHeap(), 0, wined3d);
473
474#ifdef VBOX_WITH_WDDM
475 VBoxExtCheckTerm();
476#endif
477 }
478
479 return refcount;
480}
481
482/* Context activation is done by the caller. */
483static BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
484{
485 GLuint prog;
486 BOOL ret = FALSE;
487 const char *testcode =
488 "!!ARBvp1.0\n"
489 "PARAM C[66] = { program.env[0..65] };\n"
490 "ADDRESS A0;"
491 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
492 "ARL A0.x, zero.x;\n"
493 "MOV result.position, C[A0.x + 65];\n"
494 "END\n";
495
496 while (gl_info->gl_ops.gl.p_glGetError());
497 GL_EXTCALL(glGenProgramsARB(1, &prog));
498 if(!prog) {
499 ERR("Failed to create an ARB offset limit test program\n");
500 }
501 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
502 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
503 strlen(testcode), testcode));
504 if (gl_info->gl_ops.gl.p_glGetError())
505 {
506 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
507 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
508 ret = TRUE;
509 } else TRACE("OpenGL implementation allows offsets > 63\n");
510
511 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
512 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
513 checkGLcall("ARB vp offset limit test cleanup");
514
515 return ret;
516}
517
518static BOOL match_amd_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
519 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
520{
521 if (card_vendor != HW_VENDOR_AMD) return FALSE;
522 if (device == CARD_AMD_RADEON_9500) return TRUE;
523 if (device == CARD_AMD_RADEON_X700) return TRUE;
524 if (device == CARD_AMD_RADEON_X1600) return TRUE;
525 return FALSE;
526}
527
528static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
529 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
530{
531 if (card_vendor == HW_VENDOR_NVIDIA)
532 {
533 if (device == CARD_NVIDIA_GEFORCEFX_5200 ||
534 device == CARD_NVIDIA_GEFORCEFX_5600 ||
535 device == CARD_NVIDIA_GEFORCEFX_5800)
536 {
537 return TRUE;
538 }
539 }
540 return FALSE;
541}
542
543static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
544 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
545{
546 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
547 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
548 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
549 *
550 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
551 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
552 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
553 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
554 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
555 * the chance that other implementations support them is rather small since Win32 QuickTime uses
556 * DirectDraw, not OpenGL.
557 *
558 * This test has been moved into wined3d_guess_gl_vendor()
559 */
560 if (gl_vendor == GL_VENDOR_APPLE)
561 {
562 return TRUE;
563 }
564 return FALSE;
565}
566
567/* Context activation is done by the caller. */
568static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
569{
570 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
571 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
572 * all the texture. This function detects this bug by its symptom and disables PBOs
573 * if the test fails.
574 *
575 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
576 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
577 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
578 * read back is compared to the original. If they are equal PBOs are assumed to work,
579 * otherwise the PBO extension is disabled. */
580 GLuint texture, pbo;
581 static const unsigned int pattern[] =
582 {
583 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
584 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
585 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
586 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
587 };
588 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
589
590 /* No PBO -> No point in testing them. */
591 if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
592
593 while (gl_info->gl_ops.gl.p_glGetError());
594 gl_info->gl_ops.gl.p_glGenTextures(1, &texture);
595 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, texture);
596
597 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
598 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);
599 checkGLcall("Specifying the PBO test texture");
600
601 GL_EXTCALL(glGenBuffersARB(1, &pbo));
602 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
603 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
604 checkGLcall("Specifying the PBO test pbo");
605
606 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);
607 checkGLcall("Loading the PBO test texture");
608
609 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
610
611 gl_info->gl_ops.gl.p_glFinish(); /* just to be sure */
612
613 memset(check, 0, sizeof(check));
614
615 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
616 checkGLcall("Reading back the PBO test texture");
617
618 gl_info->gl_ops.gl.p_glDeleteTextures(1, &texture);
619 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
620 checkGLcall("PBO test cleanup");
621
622 if (memcmp(check, pattern, sizeof(check)))
623 {
624 WARN_(d3d_perf)("PBO test failed, read back data doesn't match original.\n"
625 "Disabling PBOs. This may result in slower performance.\n");
626 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
627 }
628 else
629 {
630 TRACE("PBO test successful.\n");
631 }
632}
633
634static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
635 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
636{
637 return (card_vendor == HW_VENDOR_INTEL) && (gl_vendor == GL_VENDOR_APPLE);
638}
639
640static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
641 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
642{
643 if (gl_vendor != GL_VENDOR_APPLE) return FALSE;
644 if (card_vendor != HW_VENDOR_AMD) return FALSE;
645 if (device == CARD_AMD_RADEON_X1600) return FALSE;
646 return TRUE;
647}
648
649static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
650 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
651{
652 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
653 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
654 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
655 * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
656 * hardcoded
657 *
658 * dx10 cards usually have 64 varyings */
659 return gl_info->limits.glsl_varyings > 44;
660}
661
662static BOOL match_not_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
663 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
664{
665 return !match_dx10_capable(gl_info, gl_renderer, gl_vendor, card_vendor, device);
666}
667
668/* A GL context is provided by the caller */
669static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
670 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
671{
672 GLenum error;
673 DWORD data[16];
674
675 if (!gl_info->supported[EXT_SECONDARY_COLOR])
676 return FALSE;
677
678 while (gl_info->gl_ops.gl.p_glGetError());
679 GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
680 error = gl_info->gl_ops.gl.p_glGetError();
681
682 if (error == GL_NO_ERROR)
683 {
684 TRACE("GL Implementation accepts 4 component specular color pointers\n");
685 return TRUE;
686 }
687 else
688 {
689 TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
690 debug_glerror(error));
691 return FALSE;
692 }
693}
694
695/* A GL context is provided by the caller */
696static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
697 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
698{
699 GLuint prog;
700 BOOL ret = FALSE;
701 GLint pos;
702 const char *testcode =
703 "!!ARBvp1.0\n"
704 "OPTION NV_vertex_program2;\n"
705 "MOV result.clip[0], 0.0;\n"
706 "MOV result.position, 0.0;\n"
707 "END\n";
708
709 if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
710
711 while (gl_info->gl_ops.gl.p_glGetError());
712
713 GL_EXTCALL(glGenProgramsARB(1, &prog));
714 if(!prog)
715 {
716 ERR("Failed to create the NVvp clip test program\n");
717 return FALSE;
718 }
719 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
720 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
721 strlen(testcode), testcode));
722 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
723 if(pos != -1)
724 {
725 WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
726 TRACE("error: %s\n", debugstr_a((const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
727 ret = TRUE;
728 while (gl_info->gl_ops.gl.p_glGetError());
729 }
730 else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
731
732 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
733 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
734 checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
735
736 return ret;
737}
738
739/* Context activation is done by the caller. */
740static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
741 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
742{
743 char data[4 * 4 * 4];
744 GLuint tex, fbo;
745 GLenum status;
746
747 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return FALSE;
748
749 memset(data, 0xcc, sizeof(data));
750
751 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
752 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
753 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
754 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
755 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);
756 checkGLcall("glTexImage2D");
757
758 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
759 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
760 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
761 checkGLcall("glFramebufferTexture2D");
762
763 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
764 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
765 checkGLcall("glCheckFramebufferStatus");
766
767 memset(data, 0x11, sizeof(data));
768 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);
769 checkGLcall("glTexSubImage2D");
770
771 gl_info->gl_ops.gl.p_glClearColor(0.996f, 0.729f, 0.745f, 0.792f);
772 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
773 checkGLcall("glClear");
774
775 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
776 checkGLcall("glGetTexImage");
777
778 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
779 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
780 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
781 checkGLcall("glBindTexture");
782
783 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
784 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
785 checkGLcall("glDeleteTextures");
786
787 return *(DWORD *)data == 0x11111111;
788}
789
790/* Context activation is done by the caller. */
791static BOOL match_broken_rgba16(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
792 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
793{
794 /* GL_RGBA16 uses GL_RGBA8 internally on Geforce 7 and older cards.
795 * This leads to graphical bugs in Half Life 2 and Unreal engine games. */
796 GLuint tex;
797 GLint size;
798
799 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
800 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
801 gl_info->gl_ops.gl.p_glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, 4, 4, 0, GL_RGBA, GL_UNSIGNED_SHORT, NULL);
802 checkGLcall("glTexImage2D");
803
804 gl_info->gl_ops.gl.p_glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_RED_SIZE, &size);
805 checkGLcall("glGetTexLevelParameteriv");
806 TRACE("Real color depth is %d\n", size);
807
808 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
809 checkGLcall("glBindTexture");
810 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
811 checkGLcall("glDeleteTextures");
812
813 return size < 16;
814}
815
816static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
817 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
818{
819 return gl_vendor == GL_VENDOR_FGLRX;
820}
821
822static BOOL match_r200(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
823 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
824{
825 if (card_vendor != HW_VENDOR_AMD) return FALSE;
826 if (device == CARD_AMD_RADEON_8500) return TRUE;
827 return FALSE;
828}
829
830static BOOL match_broken_arb_fog(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
831 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
832{
833 DWORD data[4];
834 GLuint tex, fbo;
835 GLenum status;
836 float color[4] = {0.0f, 1.0f, 0.0f, 0.0f};
837 GLuint prog;
838 GLint err_pos;
839 static const char *program_code =
840 "!!ARBfp1.0\n"
841 "OPTION ARB_fog_linear;\n"
842 "MOV result.color, {1.0, 0.0, 0.0, 0.0};\n"
843 "END\n";
844
845 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
846 return FALSE;
847 if (!gl_info->supported[ARB_FRAGMENT_PROGRAM])
848 return FALSE;
849
850 gl_info->gl_ops.gl.p_glGenTextures(1, &tex);
851 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, tex);
852 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
853 gl_info->gl_ops.gl.p_glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
854 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);
855 checkGLcall("glTexImage2D");
856
857 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
858 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
859 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
860 checkGLcall("glFramebufferTexture2D");
861
862 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
863 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
864 checkGLcall("glCheckFramebufferStatus");
865
866 gl_info->gl_ops.gl.p_glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
867 gl_info->gl_ops.gl.p_glClear(GL_COLOR_BUFFER_BIT);
868 checkGLcall("glClear");
869 gl_info->gl_ops.gl.p_glViewport(0, 0, 4, 1);
870 checkGLcall("glViewport");
871
872 gl_info->gl_ops.gl.p_glEnable(GL_FOG);
873 gl_info->gl_ops.gl.p_glFogf(GL_FOG_START, 0.5f);
874 gl_info->gl_ops.gl.p_glFogf(GL_FOG_END, 0.5f);
875 gl_info->gl_ops.gl.p_glFogi(GL_FOG_MODE, GL_LINEAR);
876 gl_info->gl_ops.gl.p_glHint(GL_FOG_HINT, GL_NICEST);
877 gl_info->gl_ops.gl.p_glFogfv(GL_FOG_COLOR, color);
878 checkGLcall("fog setup");
879
880 GL_EXTCALL(glGenProgramsARB(1, &prog));
881 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog));
882 GL_EXTCALL(glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
883 strlen(program_code), program_code));
884 gl_info->gl_ops.gl.p_glEnable(GL_FRAGMENT_PROGRAM_ARB);
885 checkGLcall("Test fragment program setup");
886
887 gl_info->gl_ops.gl.p_glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &err_pos);
888 if (err_pos != -1)
889 {
890 const char *error_str;
891 error_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_PROGRAM_ERROR_STRING_ARB);
892 FIXME("Fog test program error at position %d: %s\n\n", err_pos, debugstr_a(error_str));
893 }
894
895 gl_info->gl_ops.gl.p_glBegin(GL_TRIANGLE_STRIP);
896 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, -1.0f, 0.0f);
897 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, -1.0f, 1.0f);
898 gl_info->gl_ops.gl.p_glVertex3f(-1.0f, 1.0f, 0.0f);
899 gl_info->gl_ops.gl.p_glVertex3f( 1.0f, 1.0f, 1.0f);
900 gl_info->gl_ops.gl.p_glEnd();
901 checkGLcall("ARBfp fog test draw");
902
903 gl_info->gl_ops.gl.p_glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
904 checkGLcall("glGetTexImage");
905 data[0] &= 0x00ffffff;
906 data[1] &= 0x00ffffff;
907 data[2] &= 0x00ffffff;
908 data[3] &= 0x00ffffff;
909
910 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
911 gl_info->gl_ops.gl.p_glBindTexture(GL_TEXTURE_2D, 0);
912
913 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
914 gl_info->gl_ops.gl.p_glDeleteTextures(1, &tex);
915 gl_info->gl_ops.gl.p_glDisable(GL_FOG);
916 GL_EXTCALL(glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, 0));
917 gl_info->gl_ops.gl.p_glDisable(GL_FRAGMENT_PROGRAM_ARB);
918 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
919 checkGLcall("ARBfp fog test teardown");
920
921 TRACE("Fog test data: %08x %08x %08x %08x\n", data[0], data[1], data[2], data[3]);
922 return data[0] != 0x00ff0000 || data[3] != 0x0000ff00;
923}
924
925static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
926{
927 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
928 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
929 * allow 48 different offsets or other helper immediate values. */
930 TRACE("Reserving 12 GLSL constants for compiler private use.\n");
931 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
932}
933
934static void quirk_amd_dx9(struct wined3d_gl_info *gl_info)
935{
936 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
937 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
938 * If real NP2 textures are used, the driver falls back to software. We could just remove the
939 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconvenient
940 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
941 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
942 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
943 *
944 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
945 * has this extension promoted to core. The extension loading code sets this extension supported
946 * due to that, so this code works on fglrx as well. */
947 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
948 {
949 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
950 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
951 gl_info->supported[WINED3D_GL_NORMALIZED_TEXRECT] = TRUE;
952 }
953}
954
955static void quirk_no_np2(struct wined3d_gl_info *gl_info)
956{
957 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
958 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
959 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
960 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
961 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
962 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
963 *
964 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
965 * triggering the software fallback. There is not much we can do here apart from disabling the
966 * software-emulated extension and re-enable ARB_tex_rect (which was previously disabled
967 * in wined3d_adapter_init_gl_caps).
968 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
969 * post-processing effects in the game "Max Payne 2").
970 * The behaviour can be verified through a simple test app attached in bugreport #14724. */
971 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
972 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
973 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
974}
975
976static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
977{
978 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
979 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
980 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
981 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
982 * according to the spec.
983 *
984 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
985 * makes the shader slower and eats instruction slots which should be available to the d3d app.
986 *
987 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
988 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
989 * this workaround is activated on cards that do not need it, it won't break things, just affect
990 * performance negatively. */
991 TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
992 gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
993}
994
995static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
996{
997 gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
998}
999
1000static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
1001{
1002 gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
1003}
1004
1005static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
1006{
1007 gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
1008}
1009
1010static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info)
1011{
1012 gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE;
1013}
1014
1015static void quirk_broken_rgba16(struct wined3d_gl_info *gl_info)
1016{
1017 gl_info->quirks |= WINED3D_QUIRK_BROKEN_RGBA16;
1018}
1019
1020static void quirk_infolog_spam(struct wined3d_gl_info *gl_info)
1021{
1022 gl_info->quirks |= WINED3D_QUIRK_INFO_LOG_SPAM;
1023}
1024
1025static void quirk_limited_tex_filtering(struct wined3d_gl_info *gl_info)
1026{
1027 /* Nvidia GeForce 6xxx and 7xxx support accelerated VTF only on a few
1028 selected texture formats. They are apparently the only DX9 class GPUs
1029 supporting VTF.
1030 Also, DX9-era GPUs are somewhat limited with float textures
1031 filtering and blending. */
1032 gl_info->quirks |= WINED3D_QUIRK_LIMITED_TEX_FILTERING;
1033}
1034
1035static void quirk_r200_constants(struct wined3d_gl_info *gl_info)
1036{
1037 /* The Mesa r200 driver (and there is no other driver for this GPU Wine would run on)
1038 * loads some fog parameters (start, end, exponent, but not the color) into the
1039 * program.
1040 *
1041 * Apparently the fog hardware is only able to handle linear fog with a range of 0.0;1.0,
1042 * and it is the responsibility of the vertex pipeline to handle non-linear fog and
1043 * linear fog with start and end other than 0.0 and 1.0. */
1044 TRACE("Reserving 1 ARB constant for compiler private use.\n");
1045 gl_info->reserved_arb_constants = max(gl_info->reserved_arb_constants, 1);
1046}
1047
1048static void quirk_broken_arb_fog(struct wined3d_gl_info *gl_info)
1049{
1050 gl_info->quirks |= WINED3D_QUIRK_BROKEN_ARB_FOG;
1051}
1052
1053#ifdef VBOX_WITH_WINE_FIX_QUIRKS
1054static BOOL match_ati_hd4800(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1055 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
1056{
1057 if (card_vendor != HW_VENDOR_AMD) return FALSE;
1058 if (device == CARD_AMD_RADEON_HD4800) return TRUE;
1059 return FALSE;
1060}
1061
1062static void quirk_fullsize_blit(struct wined3d_gl_info *gl_info)
1063{
1064 gl_info->quirks |= WINED3D_QUIRK_FULLSIZE_BLIT;
1065}
1066
1067#ifdef VBOX_WITH_WDDM
1068# if 0
1069static BOOL match_mesa_nvidia(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1070 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
1071{
1072 if (card_vendor != HW_VENDOR_NVIDIA) return FALSE;
1073 if (gl_vendor != GL_VENDOR_MESA) return FALSE;
1074 return TRUE;
1075}
1076
1077static void quirk_no_shader_3(struct wined3d_gl_info *gl_info)
1078{
1079 int vs_selected_mode, ps_selected_mode;
1080 select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
1081 if (vs_selected_mode != SHADER_GLSL && ps_selected_mode != SHADER_GLSL)
1082 return;
1083
1084 gl_info->quirks |= WINED3D_QUIRK_NO_SHADER_V3;
1085}
1086# endif
1087#endif
1088
1089static BOOL match_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1090 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
1091{
1092 if (card_vendor == HW_VENDOR_INTEL) return TRUE;
1093 if (gl_vendor == HW_VENDOR_INTEL) return TRUE;
1094 return FALSE;
1095}
1096
1097static void quirk_force_blit(struct wined3d_gl_info *gl_info)
1098{
1099 gl_info->quirks |= WINED3D_QUIRK_FORCE_BLIT;
1100}
1101#endif
1102
1103struct driver_quirk
1104{
1105 BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1106 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device);
1107 void (*apply)(struct wined3d_gl_info *gl_info);
1108 const char *description;
1109};
1110
1111static const struct driver_quirk quirk_table[] =
1112{
1113 {
1114 match_amd_r300_to_500,
1115 quirk_amd_dx9,
1116 "AMD normalized texrect quirk"
1117 },
1118 {
1119 match_apple,
1120 quirk_apple_glsl_constants,
1121 "Apple GLSL uniform override"
1122 },
1123 {
1124 match_geforce5,
1125 quirk_no_np2,
1126 "Geforce 5 NP2 disable"
1127 },
1128 {
1129 match_apple_intel,
1130 quirk_texcoord_w,
1131 "Init texcoord .w for Apple Intel GPU driver"
1132 },
1133 {
1134 match_apple_nonr500ati,
1135 quirk_texcoord_w,
1136 "Init texcoord .w for Apple ATI >= r600 GPU driver"
1137 },
1138 {
1139 match_dx10_capable,
1140 quirk_clip_varying,
1141 "Reserved varying for gl_ClipPos"
1142 },
1143 {
1144 /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
1145 * GL implementations accept it. The Mac GL is the only implementation known to
1146 * reject it.
1147 *
1148 * If we can pass 4 component specular colors, do it, because (a) we don't have
1149 * to screw around with the data, and (b) the D3D fixed function vertex pipeline
1150 * passes specular alpha to the pixel shader if any is used. Otherwise the
1151 * specular alpha is used to pass the fog coordinate, which we pass to opengl
1152 * via GL_EXT_fog_coord.
1153 */
1154 match_allows_spec_alpha,
1155 quirk_allows_specular_alpha,
1156 "Allow specular alpha quirk"
1157 },
1158 {
1159 match_broken_nv_clip,
1160 quirk_disable_nvvp_clip,
1161 "Apple NV_vertex_program clip bug quirk"
1162 },
1163 {
1164 match_fbo_tex_update,
1165 quirk_fbo_tex_update,
1166 "FBO rebind for attachment updates"
1167 },
1168 {
1169 match_broken_rgba16,
1170 quirk_broken_rgba16,
1171 "True RGBA16 is not available"
1172 },
1173 {
1174 match_fglrx,
1175 quirk_infolog_spam,
1176 "Not printing GLSL infolog"
1177 },
1178 {
1179 match_not_dx10_capable,
1180 quirk_limited_tex_filtering,
1181 "Texture filtering, blending and VTF support is limited"
1182 },
1183 {
1184 match_r200,
1185 quirk_r200_constants,
1186 "r200 vertex shader constants"
1187 },
1188 {
1189 match_broken_arb_fog,
1190 quirk_broken_arb_fog,
1191 "ARBfp fogstart == fogend workaround"
1192 },
1193#ifdef VBOX_WITH_WINE_FIX_QUIRKS
1194 {
1195 match_ati_hd4800,
1196 quirk_fullsize_blit,
1197 "Fullsize blit"
1198 },
1199#if 0 //def VBOX_WITH_WDDM
1200 {
1201 match_mesa_nvidia,
1202 quirk_no_shader_3,
1203 "disable shader 3 support"
1204 },
1205#endif
1206 {
1207 match_intel,
1208 quirk_force_blit,
1209 "force framebuffer blit when possible"
1210 }
1211#endif
1212};
1213
1214/* Certain applications (Steam) complain if we report an outdated driver version. In general,
1215 * reporting a driver version is moot because we are not the Windows driver, and we have different
1216 * bugs, features, etc.
1217 *
1218 * The driver version has the form "x.y.z.w".
1219 *
1220 * "x" is the Windows version the driver is meant for:
1221 * 4 -> 95/98/NT4
1222 * 5 -> 2000
1223 * 6 -> 2000/XP
1224 * 7 -> Vista
1225 * 8 -> Win 7
1226 *
1227 * "y" is the maximum Direct3D version the driver supports.
1228 * y -> d3d version mapping:
1229 * 11 -> d3d6
1230 * 12 -> d3d7
1231 * 13 -> d3d8
1232 * 14 -> d3d9
1233 * 15 -> d3d10
1234 * 16 -> d3d10.1
1235 * 17 -> d3d11
1236 *
1237 * "z" is the subversion number.
1238 *
1239 * "w" is the vendor specific driver build number.
1240 */
1241
1242struct driver_version_information
1243{
1244 enum wined3d_display_driver driver;
1245 enum wined3d_driver_model driver_model;
1246 const char *driver_name; /* name of Windows driver */
1247 WORD version; /* version word ('y'), contained in low word of DriverVersion.HighPart */
1248 WORD subversion; /* subversion word ('z'), contained in high word of DriverVersion.LowPart */
1249 WORD build; /* build number ('w'), contained in low word of DriverVersion.LowPart */
1250};
1251
1252/* The driver version table contains driver information for different devices on several OS versions. */
1253static const struct driver_version_information driver_version_table[] =
1254{
1255 /* AMD
1256 * - Radeon HD2x00 (R600) and up supported by current drivers.
1257 * - Radeon 9500 (R300) - X1*00 (R5xx) supported up to Catalyst 9.3 (Linux) and 10.2 (XP/Vista/Win7)
1258 * - Radeon 7xxx (R100) - 9250 (RV250) supported up to Catalyst 6.11 (XP)
1259 * - Rage 128 supported up to XP, latest official build 6.13.3279 dated October 2001 */
1260 {DRIVER_AMD_RAGE_128PRO, DRIVER_MODEL_NT5X, "ati2dvaa.dll", 13, 3279, 0},
1261 {DRIVER_AMD_R100, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 6614},
1262 {DRIVER_AMD_R300, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 6764},
1263 {DRIVER_AMD_R600, DRIVER_MODEL_NT5X, "ati2dvag.dll", 14, 10, 8681},
1264 {DRIVER_AMD_R300, DRIVER_MODEL_NT6X, "atiumdag.dll", 14, 10, 741 },
1265 {DRIVER_AMD_R600, DRIVER_MODEL_NT6X, "atiumdag.dll", 14, 10, 741 },
1266
1267 /* Intel
1268 * The drivers are unified but not all versions support all GPUs. At some point the 2k/xp
1269 * drivers used ialmrnt5.dll for GMA800/GMA900 but at some point the file was renamed to
1270 * igxprd32.dll but the GMA800 driver was never updated. */
1271 {DRIVER_INTEL_GMA800, DRIVER_MODEL_NT5X, "ialmrnt5.dll", 14, 10, 3889},
1272 {DRIVER_INTEL_GMA900, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 4764},
1273 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 4926},
1274 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT5X, "igxprd32.dll", 14, 10, 5218},
1275 {DRIVER_INTEL_GMA950, DRIVER_MODEL_NT6X, "igdumd32.dll", 14, 10, 1504},
1276 {DRIVER_INTEL_GMA3000, DRIVER_MODEL_NT6X, "igdumd32.dll", 15, 10, 1666},
1277
1278 /* Nvidia
1279 * - Geforce6 and newer cards are supported by the current driver (197.x) on XP-Win7
1280 * - GeforceFX support is up to 173.x on <= XP
1281 * - Geforce2MX/3/4 up to 96.x on <= XP
1282 * - TNT/Geforce1/2 up to 71.x on <= XP
1283 * All version numbers used below are from the Linux nvidia drivers. */
1284 {DRIVER_NVIDIA_TNT, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 10, 7186},
1285 {DRIVER_NVIDIA_GEFORCE2MX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 10, 9371},
1286 {DRIVER_NVIDIA_GEFORCEFX, DRIVER_MODEL_NT5X, "nv4_disp.dll", 14, 11, 7516},
1287 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT5X, "nv4_disp.dll", 15, 12, 6658},
1288 {DRIVER_NVIDIA_GEFORCE6, DRIVER_MODEL_NT6X, "nvd3dum.dll", 15, 12, 6658},
1289};
1290
1291struct gpu_description
1292{
1293 WORD vendor; /* reported PCI card vendor ID */
1294 WORD card; /* reported PCI card device ID */
1295 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
1296 enum wined3d_display_driver driver;
1297 unsigned int vidmem;
1298};
1299
1300/* The amount of video memory stored in the gpu description table is the minimum amount of video memory
1301 * found on a board containing a specific GPU. */
1302static const struct gpu_description gpu_description_table[] =
1303{
1304 /* Nvidia cards */
1305 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", DRIVER_NVIDIA_TNT, 16 },
1306 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", DRIVER_NVIDIA_TNT, 32 },
1307 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", DRIVER_NVIDIA_TNT, 32 },
1308 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", DRIVER_NVIDIA_TNT, 32 },
1309 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", DRIVER_NVIDIA_GEFORCE2MX,32 },
1310 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", DRIVER_NVIDIA_GEFORCE2MX,64 },
1311 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", DRIVER_NVIDIA_GEFORCE2MX,64 },
1312 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", DRIVER_NVIDIA_GEFORCE2MX,64, },
1313 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", DRIVER_NVIDIA_GEFORCEFX, 64 },
1314 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", DRIVER_NVIDIA_GEFORCEFX, 128 },
1315 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", DRIVER_NVIDIA_GEFORCEFX, 256 },
1316 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", DRIVER_NVIDIA_GEFORCE6, 64 },
1317 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", DRIVER_NVIDIA_GEFORCE6, 128 },
1318 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", DRIVER_NVIDIA_GEFORCE6, 128 },
1319 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", DRIVER_NVIDIA_GEFORCE6, 256 },
1320 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", DRIVER_NVIDIA_GEFORCE6, 256 },
1321 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1322 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1323 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", DRIVER_NVIDIA_GEFORCE6, 128 },
1324 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8400GS, "NVIDIA GeForce 8400 GS", DRIVER_NVIDIA_GEFORCE6, 128 },
1325 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1326 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", DRIVER_NVIDIA_GEFORCE6, 512 },
1327 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", DRIVER_NVIDIA_GEFORCE6, 320 },
1328 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTX, "NVIDIA GeForce 8800 GTX", DRIVER_NVIDIA_GEFORCE6, 768 },
1329 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", DRIVER_NVIDIA_GEFORCE6, 256 },
1330 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9300, "NVIDIA GeForce 9300", DRIVER_NVIDIA_GEFORCE6, 256 },
1331 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400M, "NVIDIA GeForce 9400M", DRIVER_NVIDIA_GEFORCE6, 256 },
1332 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1333 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", DRIVER_NVIDIA_GEFORCE6, 256 },
1334 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", DRIVER_NVIDIA_GEFORCE6, 384 },
1335 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", DRIVER_NVIDIA_GEFORCE6, 512 },
1336 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_210, "NVIDIA GeForce 210", DRIVER_NVIDIA_GEFORCE6, 512 },
1337 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT220, "NVIDIA GeForce GT 220", DRIVER_NVIDIA_GEFORCE6, 512 },
1338 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT240, "NVIDIA GeForce GT 240", DRIVER_NVIDIA_GEFORCE6, 512 },
1339 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", DRIVER_NVIDIA_GEFORCE6, 1024},
1340 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", DRIVER_NVIDIA_GEFORCE6, 896 },
1341 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", DRIVER_NVIDIA_GEFORCE6, 1024},
1342 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_315M, "NVIDIA GeForce 315M", DRIVER_NVIDIA_GEFORCE6, 512 },
1343 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_320M, "NVIDIA GeForce 320M", DRIVER_NVIDIA_GEFORCE6, 256},
1344 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_410M, "NVIDIA GeForce 410M", DRIVER_NVIDIA_GEFORCE6, 512},
1345 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT320M, "NVIDIA GeForce GT 320M", DRIVER_NVIDIA_GEFORCE6, 1024},
1346 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT325M, "NVIDIA GeForce GT 325M", DRIVER_NVIDIA_GEFORCE6, 1024},
1347 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT330, "NVIDIA GeForce GT 330", DRIVER_NVIDIA_GEFORCE6, 1024},
1348 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS350M, "NVIDIA GeForce GTS 350M", DRIVER_NVIDIA_GEFORCE6, 1024},
1349 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT420, "NVIDIA GeForce GT 420", DRIVER_NVIDIA_GEFORCE6, 2048},
1350 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT430, "NVIDIA GeForce GT 430", DRIVER_NVIDIA_GEFORCE6, 1024},
1351 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT440, "NVIDIA GeForce GT 440", DRIVER_NVIDIA_GEFORCE6, 1024},
1352 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTS450, "NVIDIA GeForce GTS 450", DRIVER_NVIDIA_GEFORCE6, 1024},
1353 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460, "NVIDIA GeForce GTX 460", DRIVER_NVIDIA_GEFORCE6, 768 },
1354 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX460M, "NVIDIA GeForce GTX 460M", DRIVER_NVIDIA_GEFORCE6, 1536},
1355 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX465, "NVIDIA GeForce GTX 465", DRIVER_NVIDIA_GEFORCE6, 1024},
1356 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX470, "NVIDIA GeForce GTX 470", DRIVER_NVIDIA_GEFORCE6, 1280},
1357 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX480, "NVIDIA GeForce GTX 480", DRIVER_NVIDIA_GEFORCE6, 1536},
1358 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT520, "NVIDIA GeForce GT 520", DRIVER_NVIDIA_GEFORCE6, 1024},
1359 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT540M, "NVIDIA GeForce GT 540M", DRIVER_NVIDIA_GEFORCE6, 1024},
1360 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX550, "NVIDIA GeForce GTX 550 Ti", DRIVER_NVIDIA_GEFORCE6, 1024},
1361 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT555M, "NVIDIA GeForce GT 555M", DRIVER_NVIDIA_GEFORCE6, 1024},
1362 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560TI, "NVIDIA GeForce GTX 560 Ti", DRIVER_NVIDIA_GEFORCE6, 1024},
1363 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX560, "NVIDIA GeForce GTX 560", DRIVER_NVIDIA_GEFORCE6, 1024},
1364 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX570, "NVIDIA GeForce GTX 570", DRIVER_NVIDIA_GEFORCE6, 1280},
1365 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX580, "NVIDIA GeForce GTX 580", DRIVER_NVIDIA_GEFORCE6, 1536},
1366 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT610, "NVIDIA GeForce GT 610", DRIVER_NVIDIA_GEFORCE6, 1024},
1367 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630, "NVIDIA GeForce GT 630", DRIVER_NVIDIA_GEFORCE6, 1024},
1368 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT630M, "NVIDIA GeForce GT 630M", DRIVER_NVIDIA_GEFORCE6, 1024},
1369 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT640M, "NVIDIA GeForce GT 640M", DRIVER_NVIDIA_GEFORCE6, 1024},
1370 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT650M, "NVIDIA GeForce GT 650M", DRIVER_NVIDIA_GEFORCE6, 2048},
1371 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650, "NVIDIA GeForce GTX 650", DRIVER_NVIDIA_GEFORCE6, 1024},
1372 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX650TI, "NVIDIA GeForce GTX 650 Ti", DRIVER_NVIDIA_GEFORCE6, 1024},
1373 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660, "NVIDIA GeForce GTX 660", DRIVER_NVIDIA_GEFORCE6, 2048},
1374 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660M, "NVIDIA GeForce GTX 660M", DRIVER_NVIDIA_GEFORCE6, 2048},
1375 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX660TI, "NVIDIA GeForce GTX 660 Ti", DRIVER_NVIDIA_GEFORCE6, 2048},
1376 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670, "NVIDIA GeForce GTX 670", DRIVER_NVIDIA_GEFORCE6, 2048},
1377 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX670MX, "NVIDIA GeForce GTX 670MX", DRIVER_NVIDIA_GEFORCE6, 3072},
1378 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX680, "NVIDIA GeForce GTX 680", DRIVER_NVIDIA_GEFORCE6, 2048},
1379 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770M, "NVIDIA GeForce GTX 770M", DRIVER_NVIDIA_GEFORCE6, 3072},
1380 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX770, "NVIDIA GeForce GTX 770", DRIVER_NVIDIA_GEFORCE6, 2048},
1381
1382 /* AMD cards */
1383 {HW_VENDOR_AMD, CARD_AMD_RAGE_128PRO, "ATI Rage Fury", DRIVER_AMD_RAGE_128PRO, 16 },
1384 {HW_VENDOR_AMD, CARD_AMD_RADEON_7200, "ATI RADEON 7200 SERIES", DRIVER_AMD_R100, 32 },
1385 {HW_VENDOR_AMD, CARD_AMD_RADEON_8500, "ATI RADEON 8500 SERIES", DRIVER_AMD_R100, 64 },
1386 {HW_VENDOR_AMD, CARD_AMD_RADEON_9500, "ATI Radeon 9500", DRIVER_AMD_R300, 64 },
1387 {HW_VENDOR_AMD, CARD_AMD_RADEON_XPRESS_200M, "ATI RADEON XPRESS 200M Series", DRIVER_AMD_R300, 64 },
1388 {HW_VENDOR_AMD, CARD_AMD_RADEON_X700, "ATI Radeon X700 SE", DRIVER_AMD_R300, 128 },
1389 {HW_VENDOR_AMD, CARD_AMD_RADEON_X1600, "ATI Radeon X1600 Series", DRIVER_AMD_R300, 128 },
1390 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2350, "ATI Mobility Radeon HD 2350", DRIVER_AMD_R600, 256 },
1391 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2600, "ATI Mobility Radeon HD 2600", DRIVER_AMD_R600, 256 },
1392 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD2900, "ATI Radeon HD 2900 XT", DRIVER_AMD_R600, 512 },
1393 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD3200, "ATI Radeon HD 3200 Graphics", DRIVER_AMD_R600, 128 },
1394 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4200M, "ATI Mobility Radeon HD 4200", DRIVER_AMD_R600, 256 },
1395 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4350, "ATI Radeon HD 4350", DRIVER_AMD_R600, 256 },
1396 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4600, "ATI Radeon HD 4600 Series", DRIVER_AMD_R600, 512 },
1397 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4700, "ATI Radeon HD 4700 Series", DRIVER_AMD_R600, 512 },
1398 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD4800, "ATI Radeon HD 4800 Series", DRIVER_AMD_R600, 512 },
1399 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5400, "ATI Radeon HD 5400 Series", DRIVER_AMD_R600, 512 },
1400 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5600, "ATI Radeon HD 5600 Series", DRIVER_AMD_R600, 512 },
1401 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5700, "ATI Radeon HD 5700 Series", DRIVER_AMD_R600, 512 },
1402 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5800, "ATI Radeon HD 5800 Series", DRIVER_AMD_R600, 1024},
1403 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD5900, "ATI Radeon HD 5900 Series", DRIVER_AMD_R600, 1024},
1404 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6300, "AMD Radeon HD 6300 series Graphics", DRIVER_AMD_R600, 1024},
1405 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6400, "AMD Radeon HD 6400 Series", DRIVER_AMD_R600, 1024},
1406 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6410D, "AMD Radeon HD 6410D", DRIVER_AMD_R600, 1024},
1407 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6550D, "AMD Radeon HD 6550D", DRIVER_AMD_R600, 1024},
1408 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600, "AMD Radeon HD 6600 Series", DRIVER_AMD_R600, 1024},
1409 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6600M, "AMD Radeon HD 6600M Series", DRIVER_AMD_R600, 512 },
1410 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6700, "AMD Radeon HD 6700 Series", DRIVER_AMD_R600, 1024},
1411 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6800, "AMD Radeon HD 6800 Series", DRIVER_AMD_R600, 1024},
1412 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD6900, "AMD Radeon HD 6900 Series", DRIVER_AMD_R600, 2048},
1413 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7700, "AMD Radeon HD 7700 Series", DRIVER_AMD_R600, 1024},
1414 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7800, "AMD Radeon HD 7800 Series", DRIVER_AMD_R600, 2048},
1415 {HW_VENDOR_AMD, CARD_AMD_RADEON_HD7900, "AMD Radeon HD 7900 Series", DRIVER_AMD_R600, 2048},
1416 /* Intel cards */
1417 {HW_VENDOR_INTEL, CARD_INTEL_830M, "Intel(R) 82830M Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1418 {HW_VENDOR_INTEL, CARD_INTEL_855GM, "Intel(R) 82852/82855 GM/GME Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1419 {HW_VENDOR_INTEL, CARD_INTEL_845G, "Intel(R) 845G", DRIVER_INTEL_GMA800, 32 },
1420 {HW_VENDOR_INTEL, CARD_INTEL_865G, "Intel(R) 82865G Graphics Controller", DRIVER_INTEL_GMA800, 32 },
1421 {HW_VENDOR_INTEL, CARD_INTEL_915G, "Intel(R) 82915G/GV/910GL Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
1422 {HW_VENDOR_INTEL, CARD_INTEL_E7221G, "Intel(R) E7221G", DRIVER_INTEL_GMA900, 64 },
1423 {HW_VENDOR_INTEL, CARD_INTEL_915GM, "Mobile Intel(R) 915GM/GMS,910GML Express Chipset Family", DRIVER_INTEL_GMA900, 64 },
1424 {HW_VENDOR_INTEL, CARD_INTEL_945G, "Intel(R) 945G", DRIVER_INTEL_GMA950, 64 },
1425 {HW_VENDOR_INTEL, CARD_INTEL_945GM, "Mobile Intel(R) 945GM Express Chipset Family", DRIVER_INTEL_GMA950, 64 },
1426 {HW_VENDOR_INTEL, CARD_INTEL_945GME, "Intel(R) 945GME", DRIVER_INTEL_GMA950, 64 },
1427 {HW_VENDOR_INTEL, CARD_INTEL_Q35, "Intel(R) Q35", DRIVER_INTEL_GMA950, 64 },
1428 {HW_VENDOR_INTEL, CARD_INTEL_G33, "Intel(R) G33", DRIVER_INTEL_GMA950, 64 },
1429 {HW_VENDOR_INTEL, CARD_INTEL_Q33, "Intel(R) Q33", DRIVER_INTEL_GMA950, 64 },
1430 {HW_VENDOR_INTEL, CARD_INTEL_PNVG, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
1431 {HW_VENDOR_INTEL, CARD_INTEL_PNVM, "Intel(R) IGD", DRIVER_INTEL_GMA950, 64 },
1432 {HW_VENDOR_INTEL, CARD_INTEL_965Q, "Intel(R) 965Q", DRIVER_INTEL_GMA3000, 128},
1433 {HW_VENDOR_INTEL, CARD_INTEL_965G, "Intel(R) 965G", DRIVER_INTEL_GMA3000, 128},
1434 {HW_VENDOR_INTEL, CARD_INTEL_946GZ, "Intel(R) 946GZ", DRIVER_INTEL_GMA3000, 128},
1435 {HW_VENDOR_INTEL, CARD_INTEL_965GM, "Mobile Intel(R) 965 Express Chipset Family", DRIVER_INTEL_GMA3000, 128},
1436 {HW_VENDOR_INTEL, CARD_INTEL_965GME, "Intel(R) 965GME", DRIVER_INTEL_GMA3000, 128},
1437 {HW_VENDOR_INTEL, CARD_INTEL_GM45, "Mobile Intel(R) GM45 Express Chipset Family", DRIVER_INTEL_GMA3000, 512},
1438 {HW_VENDOR_INTEL, CARD_INTEL_IGD, "Intel(R) Integrated Graphics Device", DRIVER_INTEL_GMA3000, 512},
1439 {HW_VENDOR_INTEL, CARD_INTEL_G45, "Intel(R) G45/G43", DRIVER_INTEL_GMA3000, 512},
1440 {HW_VENDOR_INTEL, CARD_INTEL_Q45, "Intel(R) Q45/Q43", DRIVER_INTEL_GMA3000, 512},
1441 {HW_VENDOR_INTEL, CARD_INTEL_G41, "Intel(R) G41", DRIVER_INTEL_GMA3000, 512},
1442 {HW_VENDOR_INTEL, CARD_INTEL_B43, "Intel(R) B43", DRIVER_INTEL_GMA3000, 512},
1443 {HW_VENDOR_INTEL, CARD_INTEL_ILKD, "Intel(R) Ironlake Desktop", DRIVER_INTEL_GMA3000, 1024},
1444 {HW_VENDOR_INTEL, CARD_INTEL_ILKM, "Intel(R) Ironlake Mobile", DRIVER_INTEL_GMA3000, 1024},
1445 {HW_VENDOR_INTEL, CARD_INTEL_SNBD, "Intel(R) Sandybridge Desktop", DRIVER_INTEL_GMA3000, 1024},
1446 {HW_VENDOR_INTEL, CARD_INTEL_SNBM, "Intel(R) Sandybridge Mobile", DRIVER_INTEL_GMA3000, 1024},
1447 {HW_VENDOR_INTEL, CARD_INTEL_SNBS, "Intel(R) Sandybridge Server", DRIVER_INTEL_GMA3000, 1024},
1448 {HW_VENDOR_INTEL, CARD_INTEL_IVBD, "Intel(R) Ivybridge Desktop", DRIVER_INTEL_GMA3000, 1024},
1449 {HW_VENDOR_INTEL, CARD_INTEL_IVBM, "Intel(R) Ivybridge Mobile", DRIVER_INTEL_GMA3000, 1024},
1450 {HW_VENDOR_INTEL, CARD_INTEL_IVBS, "Intel(R) Ivybridge Server", DRIVER_INTEL_GMA3000, 1024},
1451};
1452
1453static const struct driver_version_information *get_driver_version_info(enum wined3d_display_driver driver,
1454 enum wined3d_driver_model driver_model)
1455{
1456 unsigned int i;
1457
1458 TRACE("Looking up version info for driver=%d driver_model=%d\n", driver, driver_model);
1459 for (i = 0; i < (sizeof(driver_version_table) / sizeof(driver_version_table[0])); i++)
1460 {
1461 const struct driver_version_information *entry = &driver_version_table[i];
1462
1463 if (entry->driver == driver && entry->driver_model == driver_model)
1464 {
1465 TRACE("Found driver \"%s\", version %u, subversion %u, build %u.\n",
1466 entry->driver_name, entry->version, entry->subversion, entry->build);
1467 return entry;
1468 }
1469 }
1470 return NULL;
1471}
1472
1473static void init_driver_info(struct wined3d_driver_info *driver_info,
1474 enum wined3d_pci_vendor vendor, enum wined3d_pci_device device)
1475{
1476 OSVERSIONINFOW os_version;
1477 WORD driver_os_version;
1478 unsigned int i;
1479 enum wined3d_display_driver driver = DRIVER_UNKNOWN;
1480 enum wined3d_driver_model driver_model;
1481 const struct driver_version_information *version_info;
1482
1483 if (wined3d_settings.pci_vendor_id != PCI_VENDOR_NONE)
1484 {
1485 TRACE("Overriding PCI vendor ID with 0x%04x.\n", wined3d_settings.pci_vendor_id);
1486 vendor = wined3d_settings.pci_vendor_id;
1487 }
1488 driver_info->vendor = vendor;
1489
1490 if (wined3d_settings.pci_device_id != PCI_DEVICE_NONE)
1491 {
1492 TRACE("Overriding PCI device ID with 0x%04x.\n", wined3d_settings.pci_device_id);
1493 device = wined3d_settings.pci_device_id;
1494 }
1495 driver_info->device = device;
1496
1497 /* Set a default amount of video memory (64MB). In general this code isn't used unless the user
1498 * overrides the pci ids to a card which is not in our database. */
1499 driver_info->vidmem = WINE_DEFAULT_VIDMEM;
1500
1501 memset(&os_version, 0, sizeof(os_version));
1502 os_version.dwOSVersionInfoSize = sizeof(os_version);
1503 if (!GetVersionExW(&os_version))
1504 {
1505 ERR("Failed to get OS version, reporting 2000/XP.\n");
1506 driver_os_version = 6;
1507 driver_model = DRIVER_MODEL_NT5X;
1508 }
1509 else
1510 {
1511 TRACE("OS version %u.%u.\n", os_version.dwMajorVersion, os_version.dwMinorVersion);
1512 switch (os_version.dwMajorVersion)
1513 {
1514 case 4:
1515 /* If needed we could distinguish between 9x and NT4, but this code won't make
1516 * sense for NT4 since it had no way to obtain this info through DirectDraw 3.0.
1517 */
1518 driver_os_version = 4;
1519 driver_model = DRIVER_MODEL_WIN9X;
1520 break;
1521
1522 case 5:
1523 driver_os_version = 6;
1524 driver_model = DRIVER_MODEL_NT5X;
1525 break;
1526
1527 case 6:
1528 if (os_version.dwMinorVersion == 0)
1529 {
1530 driver_os_version = 7;
1531 driver_model = DRIVER_MODEL_NT6X;
1532 }
1533 else if (os_version.dwMinorVersion == 1)
1534 {
1535 driver_os_version = 8;
1536 driver_model = DRIVER_MODEL_NT6X;
1537 }
1538 else
1539 {
1540 if (os_version.dwMinorVersion > 2)
1541 {
1542 FIXME("Unhandled OS version %u.%u, reporting Win 8.\n",
1543 os_version.dwMajorVersion, os_version.dwMinorVersion);
1544 }
1545 driver_os_version = 9;
1546 driver_model = DRIVER_MODEL_NT6X;
1547 }
1548 break;
1549
1550 default:
1551 FIXME("Unhandled OS version %u.%u, reporting 2000/XP.\n",
1552 os_version.dwMajorVersion, os_version.dwMinorVersion);
1553 driver_os_version = 6;
1554 driver_model = DRIVER_MODEL_NT5X;
1555 break;
1556 }
1557 }
1558
1559 /* When we reach this stage we always have a vendor or device id (it can be a default one).
1560 * This means that unless the ids are overridden, we will always find a GPU description. */
1561 for (i = 0; i < (sizeof(gpu_description_table) / sizeof(gpu_description_table[0])); i++)
1562 {
1563 if (vendor == gpu_description_table[i].vendor && device == gpu_description_table[i].card)
1564 {
1565 TRACE("Found card %04x:%04x in driver DB.\n", vendor, device);
1566
1567 driver_info->description = gpu_description_table[i].description;
1568 driver_info->vidmem = gpu_description_table[i].vidmem * 1024*1024;
1569 driver = gpu_description_table[i].driver;
1570 break;
1571 }
1572 }
1573
1574 if (wined3d_settings.emulated_textureram)
1575 {
1576 TRACE("Overriding amount of video memory with %u bytes.\n", wined3d_settings.emulated_textureram);
1577 driver_info->vidmem = wined3d_settings.emulated_textureram;
1578 }
1579
1580 /* Try to obtain driver version information for the current Windows version. This fails in
1581 * some cases:
1582 * - the gpu is not available on the currently selected OS version:
1583 * - Geforce GTX480 on Win98. When running applications in compatibility mode on Windows,
1584 * version information for the current Windows version is returned instead of faked info.
1585 * We do the same and assume the default Windows version to emulate is WinXP.
1586 *
1587 * - Videocard is a Riva TNT but winver is set to win7 (there are no drivers for this beast)
1588 * For now return the XP driver info. Perhaps later on we should return VESA.
1589 *
1590 * - the gpu is not in our database (can happen when the user overrides the vendor_id / device_id)
1591 * This could be an indication that our database is not up to date, so this should be fixed.
1592 */
1593 version_info = get_driver_version_info(driver, driver_model);
1594 if (version_info)
1595 {
1596 driver_info->name = version_info->driver_name;
1597 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, version_info->version);
1598 driver_info->version_low = MAKEDWORD_VERSION(version_info->subversion, version_info->build);
1599 }
1600 else
1601 {
1602 version_info = get_driver_version_info(driver, DRIVER_MODEL_NT5X);
1603 if (version_info)
1604 {
1605 driver_info->name = version_info->driver_name;
1606 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, version_info->version);
1607 driver_info->version_low = MAKEDWORD_VERSION(version_info->subversion, version_info->build);
1608 }
1609 else
1610 {
1611 driver_info->description = "Direct3D HAL";
1612 driver_info->name = "Display";
1613 driver_info->version_high = MAKEDWORD_VERSION(driver_os_version, 15);
1614 driver_info->version_low = MAKEDWORD_VERSION(8, 6); /* Nvidia RIVA TNT, arbitrary */
1615
1616 FIXME("Unable to find a driver/device info for vendor_id=%#x device_id=%#x for driver_model=%d\n",
1617 vendor, device, driver_model);
1618 }
1619 }
1620
1621 TRACE("Reporting (fake) driver version 0x%08x-0x%08x.\n",
1622 driver_info->version_high, driver_info->version_low);
1623}
1624
1625/* Context activation is done by the caller. */
1626static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer,
1627 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
1628{
1629 unsigned int i;
1630
1631 for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
1632 {
1633 if (!quirk_table[i].match(gl_info, gl_renderer, gl_vendor, card_vendor, device)) continue;
1634 TRACE("Applying driver quirk \"%s\".\n", quirk_table[i].description);
1635 quirk_table[i].apply(gl_info);
1636 }
1637
1638 /* Find out if PBOs work as they are supposed to. */
1639 test_pbo_functionality(gl_info);
1640}
1641
1642static DWORD wined3d_parse_gl_version(const char *gl_version)
1643{
1644 const char *ptr = gl_version;
1645 int major, minor;
1646
1647 major = atoi(ptr);
1648 if (major <= 0)
1649 ERR("Invalid OpenGL major version %d.\n", major);
1650
1651 while (isdigit(*ptr)) ++ptr;
1652 if (*ptr++ != '.')
1653 ERR("Invalid OpenGL version string %s.\n", debugstr_a(gl_version));
1654
1655 minor = atoi(ptr);
1656
1657 TRACE("Found OpenGL version %d.%d.\n", major, minor);
1658
1659 return MAKEDWORD_VERSION(major, minor);
1660}
1661
1662static enum wined3d_gl_vendor wined3d_guess_gl_vendor(const struct wined3d_gl_info *gl_info,
1663 const char *gl_vendor_string, const char *gl_renderer)
1664{
1665
1666 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
1667 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
1668 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
1669 *
1670 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
1671 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
1672 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
1673 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
1674 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
1675 * the chance that other implementations support them is rather small since Win32 QuickTime uses
1676 * DirectDraw, not OpenGL. */
1677 if (gl_info->supported[APPLE_FENCE]
1678 && gl_info->supported[APPLE_CLIENT_STORAGE]
1679 && gl_info->supported[APPLE_YCBCR_422])
1680 return GL_VENDOR_APPLE;
1681
1682 if (strstr(gl_vendor_string, "NVIDIA"))
1683 return GL_VENDOR_NVIDIA;
1684
1685 if (strstr(gl_vendor_string, "ATI"))
1686 return GL_VENDOR_FGLRX;
1687
1688 if (strstr(gl_vendor_string, "Intel(R)")
1689 /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */
1690 || strstr(gl_renderer, "Intel")
1691 || strstr(gl_vendor_string, "Intel Inc."))
1692 {
1693#if 0//def VBOX_WITH_WINE_FIX_QUIRKS /* check if we still need this: device detection was improved significantly with wine */
1694 if (strstr(gl_renderer, "Mesa"))
1695 return GL_VENDOR_MESA;
1696#endif
1697 return GL_VENDOR_INTEL;
1698 }
1699
1700 if (strstr(gl_vendor_string, "Mesa")
1701 || strstr(gl_vendor_string, "X.Org")
1702 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1703 || strstr(gl_vendor_string, "DRI R300 Project")
1704 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1705 || strstr(gl_vendor_string, "VMware, Inc.")
1706 || strstr(gl_renderer, "Mesa")
1707 || strstr(gl_renderer, "Gallium"))
1708 return GL_VENDOR_MESA;
1709
1710 FIXME("Received unrecognized GL_VENDOR %s. Returning GL_VENDOR_UNKNOWN.\n",
1711 debugstr_a(gl_vendor_string));
1712
1713 return GL_VENDOR_UNKNOWN;
1714}
1715
1716static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_string, const char *gl_renderer)
1717{
1718 if (strstr(gl_vendor_string, "NVIDIA")
1719 || strstr(gl_vendor_string, "Nouveau")
1720 || strstr(gl_vendor_string, "nouveau"))
1721 return HW_VENDOR_NVIDIA;
1722
1723 if (strstr(gl_vendor_string, "ATI")
1724 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1725 || strstr(gl_vendor_string, "X.Org R300 Project")
1726 || strstr(gl_renderer, "AMD")
1727 || strstr(gl_renderer, "R100")
1728 || strstr(gl_renderer, "R200")
1729 || strstr(gl_renderer, "R300")
1730 || strstr(gl_renderer, "R600")
1731 || strstr(gl_renderer, "R700"))
1732 return HW_VENDOR_AMD;
1733
1734 if (strstr(gl_vendor_string, "Intel(R)")
1735 /* Intel switched from Intel(R) to Intel® recently, so just match Intel. */
1736 || strstr(gl_renderer, "Intel")
1737 || strstr(gl_renderer, "i915")
1738 || strstr(gl_vendor_string, "Intel Inc."))
1739 return HW_VENDOR_INTEL;
1740
1741 if (strstr(gl_vendor_string, "Mesa")
1742 || strstr(gl_vendor_string, "Brian Paul")
1743 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1744 || strstr(gl_vendor_string, "VMware, Inc."))
1745 return HW_VENDOR_SOFTWARE;
1746
1747 FIXME("Received unrecognized GL_VENDOR %s. Returning HW_VENDOR_NVIDIA.\n", debugstr_a(gl_vendor_string));
1748
1749 return HW_VENDOR_NVIDIA;
1750}
1751
1752static UINT d3d_level_from_gl_info(const struct wined3d_gl_info *gl_info)
1753{
1754 UINT level = 0;
1755
1756 if (gl_info->supported[ARB_MULTITEXTURE])
1757 level = 6;
1758 if (gl_info->supported[ARB_TEXTURE_COMPRESSION]
1759 && gl_info->supported[ARB_TEXTURE_CUBE_MAP]
1760 && gl_info->supported[ARB_TEXTURE_ENV_DOT3])
1761 level = 7;
1762 if (level == 7 && gl_info->supported[ARB_MULTISAMPLE]
1763 && gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
1764 level = 8;
1765 if (level == 8 && gl_info->supported[ARB_FRAGMENT_PROGRAM]
1766 && gl_info->supported[ARB_VERTEX_SHADER])
1767 level = 9;
1768 if (level == 9 && gl_info->supported[EXT_GPU_SHADER4])
1769 level = 10;
1770
1771 return level;
1772}
1773
1774static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl_info *gl_info,
1775 const char *gl_renderer)
1776{
1777 UINT d3d_level = d3d_level_from_gl_info(gl_info);
1778 unsigned int i;
1779
1780#ifndef VBOX_WITH_WDDM
1781 if (d3d_level >= 10)
1782#endif
1783 {
1784 static const struct
1785 {
1786 const char *renderer;
1787 enum wined3d_pci_device id;
1788 }
1789 cards[] =
1790 {
1791 {"GTX 770M", CARD_NVIDIA_GEFORCE_GTX770M}, /* Geforce 700 - midend high mobile */
1792 {"GTX 770", CARD_NVIDIA_GEFORCE_GTX770}, /* Geforce 700 - highend */
1793 {"GTX 680", CARD_NVIDIA_GEFORCE_GTX680}, /* Geforce 600 - highend */
1794 {"GTX 670MX", CARD_NVIDIA_GEFORCE_GTX670MX}, /* Geforce 600 - highend */
1795 {"GTX 670", CARD_NVIDIA_GEFORCE_GTX670}, /* Geforce 600 - midend high */
1796 {"GTX 660 Ti", CARD_NVIDIA_GEFORCE_GTX660TI}, /* Geforce 600 - midend high */
1797 {"GTX 660M", CARD_NVIDIA_GEFORCE_GTX660M}, /* Geforce 600 - midend high mobile */
1798 {"GTX 660", CARD_NVIDIA_GEFORCE_GTX660}, /* Geforce 600 - midend high */
1799 {"GTX 650 Ti", CARD_NVIDIA_GEFORCE_GTX650TI}, /* Geforce 600 - lowend */
1800 {"GTX 650", CARD_NVIDIA_GEFORCE_GTX650}, /* Geforce 600 - lowend */
1801 {"GT 650M", CARD_NVIDIA_GEFORCE_GT650M}, /* Geforce 600 - midend mobile */
1802 {"GT 640M", CARD_NVIDIA_GEFORCE_GT640M}, /* Geforce 600 - midend mobile */
1803 {"GT 630M", CARD_NVIDIA_GEFORCE_GT630M}, /* Geforce 600 - midend mobile */
1804 {"GT 630", CARD_NVIDIA_GEFORCE_GT630}, /* Geforce 600 - lowend */
1805 {"GT 610", CARD_NVIDIA_GEFORCE_GT610}, /* Geforce 600 - lowend */
1806 {"GTX 580", CARD_NVIDIA_GEFORCE_GTX580}, /* Geforce 500 - highend */
1807 {"GTX 570", CARD_NVIDIA_GEFORCE_GTX570}, /* Geforce 500 - midend high */
1808 {"GTX 560 Ti", CARD_NVIDIA_GEFORCE_GTX560TI}, /* Geforce 500 - midend */
1809 {"GTX 560", CARD_NVIDIA_GEFORCE_GTX560}, /* Geforce 500 - midend */
1810 {"GT 555M", CARD_NVIDIA_GEFORCE_GT555M}, /* Geforce 500 - midend mobile */
1811 {"GTX 550 Ti", CARD_NVIDIA_GEFORCE_GTX550}, /* Geforce 500 - midend */
1812 {"GT 540M", CARD_NVIDIA_GEFORCE_GT540M}, /* Geforce 500 - midend mobile */
1813 {"GT 520", CARD_NVIDIA_GEFORCE_GT520}, /* Geforce 500 - lowend */
1814 {"GTX 480", CARD_NVIDIA_GEFORCE_GTX480}, /* Geforce 400 - highend */
1815 {"GTX 470", CARD_NVIDIA_GEFORCE_GTX470}, /* Geforce 400 - midend high */
1816 {"GTX 465", CARD_NVIDIA_GEFORCE_GTX465}, /* Geforce 400 - midend */
1817 {"GTX 460M", CARD_NVIDIA_GEFORCE_GTX460M}, /* Geforce 400 - highend mobile */
1818 {"GTX 460", CARD_NVIDIA_GEFORCE_GTX460}, /* Geforce 400 - midend */
1819 {"GTS 450", CARD_NVIDIA_GEFORCE_GTS450}, /* Geforce 400 - midend low */
1820 {"GT 440", CARD_NVIDIA_GEFORCE_GT440}, /* Geforce 400 - lowend */
1821 {"GT 430", CARD_NVIDIA_GEFORCE_GT430}, /* Geforce 400 - lowend */
1822 {"GT 420", CARD_NVIDIA_GEFORCE_GT420}, /* Geforce 400 - lowend */
1823 {"410M", CARD_NVIDIA_GEFORCE_410M}, /* Geforce 400 - lowend mobile */
1824 {"GT 330", CARD_NVIDIA_GEFORCE_GT330}, /* Geforce 300 - highend */
1825 {"GTS 360M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1826 {"GTS 350M", CARD_NVIDIA_GEFORCE_GTS350M}, /* Geforce 300 - highend mobile */
1827 {"GT 330M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1828 {"GT 325M", CARD_NVIDIA_GEFORCE_GT325M}, /* Geforce 300 - midend mobile */
1829 {"GT 320M", CARD_NVIDIA_GEFORCE_GT320M}, /* Geforce 300 - midend mobile */
1830 {"320M", CARD_NVIDIA_GEFORCE_320M}, /* Geforce 300 - midend mobile */
1831 {"315M", CARD_NVIDIA_GEFORCE_315M}, /* Geforce 300 - midend mobile */
1832 {"GTX 295", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1833 {"GTX 285", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1834 {"GTX 280", CARD_NVIDIA_GEFORCE_GTX280}, /* Geforce 200 - highend */
1835 {"GTX 275", CARD_NVIDIA_GEFORCE_GTX275}, /* Geforce 200 - midend high */
1836 {"GTX 260", CARD_NVIDIA_GEFORCE_GTX260}, /* Geforce 200 - midend */
1837 {"GT 240", CARD_NVIDIA_GEFORCE_GT240}, /* Geforce 200 - midend */
1838 {"GT 220", CARD_NVIDIA_GEFORCE_GT220}, /* Geforce 200 - lowend */
1839 {"Geforce 310", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1840 {"Geforce 305", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1841 {"Geforce 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1842 {"G 210", CARD_NVIDIA_GEFORCE_210}, /* Geforce 200 - lowend */
1843 {"GTS 250", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1844 {"GTS 150", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1845 {"9800", CARD_NVIDIA_GEFORCE_9800GT}, /* Geforce 9 - highend / Geforce 200 - midend */
1846 {"GT 140", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1847 {"9600", CARD_NVIDIA_GEFORCE_9600GT}, /* Geforce 9 - midend */
1848 {"GT 130", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1849 {"GT 120", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1850 {"9500", CARD_NVIDIA_GEFORCE_9500GT}, /* Geforce 9 - midend low / Geforce 200 - low */
1851 {"9400M", CARD_NVIDIA_GEFORCE_9400M}, /* Geforce 9 - lowend */
1852 {"9400", CARD_NVIDIA_GEFORCE_9400GT}, /* Geforce 9 - lowend */
1853 {"9300", CARD_NVIDIA_GEFORCE_9300}, /* Geforce 9 - lowend low */
1854 {"9200", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1855 {"9100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1856 {"G 100", CARD_NVIDIA_GEFORCE_9200}, /* Geforce 9 - lowend low */
1857 {"8800 GTX", CARD_NVIDIA_GEFORCE_8800GTX}, /* Geforce 8 - highend high */
1858 {"8800", CARD_NVIDIA_GEFORCE_8800GTS}, /* Geforce 8 - highend */
1859 {"8600M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1860 {"8600 M", CARD_NVIDIA_GEFORCE_8600MGT}, /* Geforce 8 - midend mobile */
1861 {"8700", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1862 {"8600", CARD_NVIDIA_GEFORCE_8600GT}, /* Geforce 8 - midend */
1863 {"8500", CARD_NVIDIA_GEFORCE_8400GS}, /* Geforce 8 - mid-lowend */
1864 {"8400", CARD_NVIDIA_GEFORCE_8400GS}, /* Geforce 8 - mid-lowend */
1865 {"8300", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1866 {"8200", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1867 {"8100", CARD_NVIDIA_GEFORCE_8300GS}, /* Geforce 8 - lowend */
1868 };
1869
1870 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1871 {
1872 if (strstr(gl_renderer, cards[i].renderer))
1873 return cards[i].id;
1874 }
1875
1876 return PCI_DEVICE_NONE;
1877 }
1878
1879 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1880 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1881 */
1882 if (d3d_level >= 9 && gl_info->supported[NV_VERTEX_PROGRAM3])
1883 {
1884 static const struct
1885 {
1886 const char *renderer;
1887 enum wined3d_pci_device id;
1888 }
1889 cards[] =
1890 {
1891 {"Quadro FX 5", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1892 {"Quadro FX 4", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1893 {"7950", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1894 {"7900", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1895 {"7800", CARD_NVIDIA_GEFORCE_7800GT}, /* Geforce 7 - highend */
1896 {"7700", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1897 {"7600", CARD_NVIDIA_GEFORCE_7600}, /* Geforce 7 - midend */
1898 {"7400", CARD_NVIDIA_GEFORCE_7400}, /* Geforce 7 - lower medium */
1899 {"7300", CARD_NVIDIA_GEFORCE_7300}, /* Geforce 7 - lowend */
1900 {"6800", CARD_NVIDIA_GEFORCE_6800}, /* Geforce 6 - highend */
1901 {"6700", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1902 {"6610", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1903 {"6600", CARD_NVIDIA_GEFORCE_6600GT}, /* Geforce 6 - midend */
1904 };
1905
1906 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
1907 {
1908 if (strstr(gl_renderer, cards[i].renderer))
1909 return cards[i].id;
1910 }
1911
1912 return PCI_DEVICE_NONE;
1913 }
1914
1915 if (d3d_level >= 9)
1916 {
1917 /* GeforceFX - highend */
1918 if (strstr(gl_renderer, "5800")
1919 || strstr(gl_renderer, "5900")
1920 || strstr(gl_renderer, "5950")
1921 || strstr(gl_renderer, "Quadro FX"))
1922 {
1923 return CARD_NVIDIA_GEFORCEFX_5800;
1924 }
1925
1926 /* GeforceFX - midend */
1927 if (strstr(gl_renderer, "5600")
1928 || strstr(gl_renderer, "5650")
1929 || strstr(gl_renderer, "5700")
1930 || strstr(gl_renderer, "5750"))
1931 {
1932 return CARD_NVIDIA_GEFORCEFX_5600;
1933 }
1934
1935 /* GeforceFX - lowend */
1936 return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1937 }
1938
1939 if (d3d_level >= 8)
1940 {
1941 if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
1942 {
1943 return CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1944 }
1945
1946 return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1947 }
1948
1949 if (d3d_level >= 7)
1950 {
1951 if (strstr(gl_renderer, "GeForce4 MX"))
1952 {
1953 return CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1954 }
1955
1956 if (strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
1957 {
1958 return CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1959 }
1960
1961 if (strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
1962 {
1963 return CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1964 }
1965
1966 return CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1967 }
1968
1969 if (strstr(gl_renderer, "TNT2"))
1970 {
1971 return CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1972 }
1973
1974 return CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1975}
1976
1977static enum wined3d_pci_device select_card_amd_binary(const struct wined3d_gl_info *gl_info,
1978 const char *gl_renderer)
1979{
1980 UINT d3d_level = d3d_level_from_gl_info(gl_info);
1981
1982 /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1983 *
1984 * Beware: renderer string do not match exact card model,
1985 * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1986#ifndef VBOX_WITH_WDDM
1987 if (d3d_level >= 10)
1988#endif
1989 {
1990 unsigned int i;
1991
1992 static const struct
1993 {
1994 const char *renderer;
1995 enum wined3d_pci_device id;
1996 }
1997 cards[] =
1998 {
1999 /* Southern Islands */
2000 {"HD 7900", CARD_AMD_RADEON_HD7900},
2001 {"HD 7800", CARD_AMD_RADEON_HD7800},
2002 {"HD 7700", CARD_AMD_RADEON_HD7700},
2003 /* Northern Islands */
2004 {"HD 6970", CARD_AMD_RADEON_HD6900},
2005 {"HD 6900", CARD_AMD_RADEON_HD6900},
2006 {"HD 6800", CARD_AMD_RADEON_HD6800},
2007 {"HD 6770M",CARD_AMD_RADEON_HD6600M},
2008 {"HD 6750M",CARD_AMD_RADEON_HD6600M},
2009 {"HD 6700", CARD_AMD_RADEON_HD6700},
2010 {"HD 6670", CARD_AMD_RADEON_HD6600},
2011 {"HD 6630M",CARD_AMD_RADEON_HD6600M},
2012 {"HD 6600M",CARD_AMD_RADEON_HD6600M},
2013 {"HD 6600", CARD_AMD_RADEON_HD6600},
2014 {"HD 6570", CARD_AMD_RADEON_HD6600},
2015 {"HD 6500M",CARD_AMD_RADEON_HD6600M},
2016 {"HD 6500", CARD_AMD_RADEON_HD6600},
2017 {"HD 6400", CARD_AMD_RADEON_HD6400},
2018 {"HD 6300", CARD_AMD_RADEON_HD6300},
2019 {"HD 6200", CARD_AMD_RADEON_HD6300},
2020 /* Evergreen */
2021 {"HD 5870", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS PRO */
2022 {"HD 5850", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS XT */
2023 {"HD 5800", CARD_AMD_RADEON_HD5800}, /* Radeon EG CYPRESS HD58xx generic renderer string */
2024 {"HD 5770", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER XT */
2025 {"HD 5750", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER LE */
2026 {"HD 5700", CARD_AMD_RADEON_HD5700}, /* Radeon EG JUNIPER HD57xx generic renderer string */
2027 {"HD 5670", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD XT */
2028 {"HD 5570", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD PRO mapped to HD5600 series */
2029 {"HD 5550", CARD_AMD_RADEON_HD5600}, /* Radeon EG REDWOOD LE mapped to HD5600 series */
2030 {"HD 5450", CARD_AMD_RADEON_HD5400}, /* Radeon EG CEDAR PRO */
2031 {"HD 5000", CARD_AMD_RADEON_HD5600}, /* Defaulting to HD 5600 */
2032 /* R700 */
2033 {"HD 4890", CARD_AMD_RADEON_HD4800}, /* Radeon RV790 */
2034 {"HD 4870", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
2035 {"HD 4850", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
2036 {"HD 4830", CARD_AMD_RADEON_HD4800}, /* Radeon RV770 */
2037 {"HD 4800", CARD_AMD_RADEON_HD4800}, /* Radeon RV7xx HD48xx generic renderer string */
2038 {"HD 4770", CARD_AMD_RADEON_HD4700}, /* Radeon RV740 */
2039 {"HD 4700", CARD_AMD_RADEON_HD4700}, /* Radeon RV7xx HD47xx generic renderer string */
2040 {"HD 4670", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
2041 {"HD 4650", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
2042 {"HD 4600", CARD_AMD_RADEON_HD4600}, /* Radeon RV730 */
2043 {"HD 4550", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
2044 {"HD 4350", CARD_AMD_RADEON_HD4350}, /* Radeon RV710 */
2045 /* R600/R700 integrated */
2046 {"HD 4200M", CARD_AMD_RADEON_HD4200M},
2047 {"HD 3300", CARD_AMD_RADEON_HD3200},
2048 {"HD 3200", CARD_AMD_RADEON_HD3200},
2049 {"HD 3100", CARD_AMD_RADEON_HD3200},
2050 /* R600 */
2051 {"HD 3870", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
2052 {"HD 3850", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
2053 {"HD 2900", CARD_AMD_RADEON_HD2900}, /* HD2900/HD3800 - highend */
2054 {"HD 3830", CARD_AMD_RADEON_HD2600}, /* China-only midend */
2055 {"HD 3690", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
2056 {"HD 3650", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
2057 {"HD 2600", CARD_AMD_RADEON_HD2600}, /* HD2600/HD3600 - midend */
2058 {"HD 3470", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
2059 {"HD 3450", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
2060 {"HD 3430", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
2061 {"HD 3400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
2062 {"HD 2400", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
2063 {"HD 2350", CARD_AMD_RADEON_HD2350}, /* HD2350/HD2400/HD3400 - lowend */
2064 };
2065
2066 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2067 {
2068 if (strstr(gl_renderer, cards[i].renderer))
2069 return cards[i].id;
2070 }
2071
2072 return PCI_DEVICE_NONE;
2073 }
2074
2075 if (d3d_level >= 9)
2076 {
2077 /* Radeon R5xx */
2078 if (strstr(gl_renderer, "X1600")
2079 || strstr(gl_renderer, "X1650")
2080 || strstr(gl_renderer, "X1800")
2081 || strstr(gl_renderer, "X1900")
2082 || strstr(gl_renderer, "X1950"))
2083 {
2084 return CARD_AMD_RADEON_X1600;
2085 }
2086
2087 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300/X2500/HD2300 (lowend R5xx)
2088 * Note X2300/X2500/HD2300 are R5xx GPUs with a 2xxx naming but they are still DX9-only */
2089 if (strstr(gl_renderer, "X700")
2090 || strstr(gl_renderer, "X800")
2091 || strstr(gl_renderer, "X850")
2092 || strstr(gl_renderer, "X1300")
2093 || strstr(gl_renderer, "X1400")
2094 || strstr(gl_renderer, "X1450")
2095 || strstr(gl_renderer, "X1550")
2096 || strstr(gl_renderer, "X2300")
2097 || strstr(gl_renderer, "X2500")
2098 || strstr(gl_renderer, "HD 2300")
2099 )
2100 {
2101 return CARD_AMD_RADEON_X700;
2102 }
2103
2104 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
2105 if (strstr(gl_renderer, "Radeon Xpress"))
2106 {
2107 return CARD_AMD_RADEON_XPRESS_200M;
2108 }
2109 }
2110
2111 return PCI_DEVICE_NONE;
2112}
2113
2114static enum wined3d_pci_device select_card_intel(const struct wined3d_gl_info *gl_info,
2115 const char *gl_renderer)
2116{
2117 unsigned int i;
2118
2119 static const struct
2120 {
2121 const char *renderer;
2122 enum wined3d_pci_device id;
2123 }
2124 cards[] =
2125 {
2126 /* Ivybridge */
2127 {"Ivybridge Server", CARD_INTEL_IVBS},
2128 {"Ivybridge Mobile", CARD_INTEL_IVBM},
2129 {"Ivybridge Desktop", CARD_INTEL_IVBD},
2130 /* Sandybridge */
2131 {"Sandybridge Server", CARD_INTEL_SNBS},
2132 {"Sandybridge Mobile", CARD_INTEL_SNBM},
2133 {"Sandybridge Desktop", CARD_INTEL_SNBD},
2134 /* Ironlake */
2135 {"Ironlake Mobile", CARD_INTEL_ILKM},
2136 {"Ironlake Desktop", CARD_INTEL_ILKD},
2137 /* G4x */
2138 {"B43", CARD_INTEL_B43},
2139 {"G41", CARD_INTEL_G41},
2140 {"G45", CARD_INTEL_G45},
2141 {"Q45", CARD_INTEL_Q45},
2142 {"Integrated Graphics Device", CARD_INTEL_IGD},
2143 {"GM45", CARD_INTEL_GM45},
2144 /* i965 */
2145 {"965GME", CARD_INTEL_965GME},
2146 {"965GM", CARD_INTEL_965GM},
2147 {"X3100", CARD_INTEL_965GM}, /* MacOS */
2148 {"946GZ", CARD_INTEL_946GZ},
2149 {"965G", CARD_INTEL_965G},
2150 {"965Q", CARD_INTEL_965Q},
2151 /* i945 */
2152 {"Pineview M", CARD_INTEL_PNVM},
2153 {"Pineview G", CARD_INTEL_PNVG},
2154 {"IGD", CARD_INTEL_PNVG},
2155 {"Q33", CARD_INTEL_Q33},
2156 {"G33", CARD_INTEL_G33},
2157 {"Q35", CARD_INTEL_Q35},
2158 {"945GME", CARD_INTEL_945GME},
2159 {"945GM", CARD_INTEL_945GM},
2160 {"GMA 950", CARD_INTEL_945GM}, /* MacOS */
2161 {"945G", CARD_INTEL_945G},
2162 /* i915 */
2163 {"915GM", CARD_INTEL_915GM},
2164 {"E7221G", CARD_INTEL_E7221G},
2165 {"915G", CARD_INTEL_915G},
2166 /* i8xx */
2167 {"865G", CARD_INTEL_865G},
2168 {"845G", CARD_INTEL_845G},
2169 {"855GM", CARD_INTEL_855GM},
2170 {"830M", CARD_INTEL_830M},
2171#ifdef VBOX_WITH_WINE_FIX_QUIRKS
2172 {"HD Graphics", CARD_INTEL_SNBM},
2173#endif
2174 };
2175
2176 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2177 {
2178 if (strstr(gl_renderer, cards[i].renderer))
2179 return cards[i].id;
2180 }
2181
2182 return PCI_DEVICE_NONE;
2183}
2184
2185static enum wined3d_pci_device select_card_amd_mesa(const struct wined3d_gl_info *gl_info,
2186 const char *gl_renderer)
2187{
2188 unsigned int i;
2189
2190 /* 20101109 - These are never returned by current Gallium radeon
2191 * drivers: R700, RV790, R680, RV535, RV516, R410, RS485, RV360, RV351.
2192 *
2193 * These are returned but not handled: RC410, RV380. */
2194 static const struct
2195 {
2196 const char *renderer;
2197 enum wined3d_pci_device id;
2198 }
2199 cards[] =
2200 {
2201 /* Southern Islands */
2202 {"TAHITI", CARD_AMD_RADEON_HD7900},
2203 {"PITCAIRN", CARD_AMD_RADEON_HD7800},
2204 {"CAPE VERDE", CARD_AMD_RADEON_HD7700},
2205 /* Northern Islands */
2206 {"CAYMAN", CARD_AMD_RADEON_HD6900},
2207 {"BARTS", CARD_AMD_RADEON_HD6800},
2208 {"TURKS", CARD_AMD_RADEON_HD6600},
2209 {"SUMO2", CARD_AMD_RADEON_HD6410D}, /* SUMO2 first, because we do a strstr(). */
2210 {"SUMO", CARD_AMD_RADEON_HD6550D},
2211 {"CAICOS", CARD_AMD_RADEON_HD6400},
2212 {"PALM", CARD_AMD_RADEON_HD6300},
2213 /* Evergreen */
2214 {"HEMLOCK", CARD_AMD_RADEON_HD5900},
2215 {"CYPRESS", CARD_AMD_RADEON_HD5800},
2216 {"JUNIPER", CARD_AMD_RADEON_HD5700},
2217 {"REDWOOD", CARD_AMD_RADEON_HD5600},
2218 {"CEDAR", CARD_AMD_RADEON_HD5400},
2219 /* R700 */
2220 {"R700", CARD_AMD_RADEON_HD4800},
2221 {"RV790", CARD_AMD_RADEON_HD4800},
2222 {"RV770", CARD_AMD_RADEON_HD4800},
2223 {"RV740", CARD_AMD_RADEON_HD4700},
2224 {"RV730", CARD_AMD_RADEON_HD4600},
2225 {"RV710", CARD_AMD_RADEON_HD4350},
2226 /* R600/R700 integrated */
2227 {"RS880", CARD_AMD_RADEON_HD4200M},
2228 {"RS780", CARD_AMD_RADEON_HD3200},
2229 /* R600 */
2230 {"R680", CARD_AMD_RADEON_HD2900},
2231 {"R600", CARD_AMD_RADEON_HD2900},
2232 {"RV670", CARD_AMD_RADEON_HD2900},
2233 {"RV635", CARD_AMD_RADEON_HD2600},
2234 {"RV630", CARD_AMD_RADEON_HD2600},
2235 {"RV620", CARD_AMD_RADEON_HD2350},
2236 {"RV610", CARD_AMD_RADEON_HD2350},
2237 /* R500 */
2238 {"R580", CARD_AMD_RADEON_X1600},
2239 {"R520", CARD_AMD_RADEON_X1600},
2240 {"RV570", CARD_AMD_RADEON_X1600},
2241 {"RV560", CARD_AMD_RADEON_X1600},
2242 {"RV535", CARD_AMD_RADEON_X1600},
2243 {"RV530", CARD_AMD_RADEON_X1600},
2244 {"RV516", CARD_AMD_RADEON_X700},
2245 {"RV515", CARD_AMD_RADEON_X700},
2246 /* R400 */
2247 {"R481", CARD_AMD_RADEON_X700},
2248 {"R480", CARD_AMD_RADEON_X700},
2249 {"R430", CARD_AMD_RADEON_X700},
2250 {"R423", CARD_AMD_RADEON_X700},
2251 {"R420", CARD_AMD_RADEON_X700},
2252 {"R410", CARD_AMD_RADEON_X700},
2253 {"RV410", CARD_AMD_RADEON_X700},
2254 /* Radeon Xpress - onboard, DX9b, Shader 2.0, 300-400MHz */
2255 {"RS740", CARD_AMD_RADEON_XPRESS_200M},
2256 {"RS690", CARD_AMD_RADEON_XPRESS_200M},
2257 {"RS600", CARD_AMD_RADEON_XPRESS_200M},
2258 {"RS485", CARD_AMD_RADEON_XPRESS_200M},
2259 {"RS482", CARD_AMD_RADEON_XPRESS_200M},
2260 {"RS480", CARD_AMD_RADEON_XPRESS_200M},
2261 {"RS400", CARD_AMD_RADEON_XPRESS_200M},
2262 /* R300 */
2263 {"R360", CARD_AMD_RADEON_9500},
2264 {"R350", CARD_AMD_RADEON_9500},
2265 {"R300", CARD_AMD_RADEON_9500},
2266 {"RV370", CARD_AMD_RADEON_9500},
2267 {"RV360", CARD_AMD_RADEON_9500},
2268 {"RV351", CARD_AMD_RADEON_9500},
2269 {"RV350", CARD_AMD_RADEON_9500},
2270 };
2271
2272 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2273 {
2274 if (strstr(gl_renderer, cards[i].renderer))
2275 return cards[i].id;
2276 }
2277
2278 return PCI_DEVICE_NONE;
2279}
2280
2281static enum wined3d_pci_device select_card_nvidia_mesa(const struct wined3d_gl_info *gl_info,
2282 const char *gl_renderer)
2283{
2284 unsigned int i;
2285
2286 static const struct
2287 {
2288 const char *renderer;
2289 enum wined3d_pci_device id;
2290 }
2291 cards[] =
2292 {
2293 /* Kepler */
2294 {"NVE6", CARD_NVIDIA_GEFORCE_GTX770M},
2295 {"NVE4", CARD_NVIDIA_GEFORCE_GTX680},
2296 /* Fermi */
2297 {"NVD9", CARD_NVIDIA_GEFORCE_GT520},
2298 {"NVCF", CARD_NVIDIA_GEFORCE_GTX550},
2299 {"NVCE", CARD_NVIDIA_GEFORCE_GTX560},
2300 {"NVC8", CARD_NVIDIA_GEFORCE_GTX570},
2301 {"NVC4", CARD_NVIDIA_GEFORCE_GTX460},
2302 {"NVC3", CARD_NVIDIA_GEFORCE_GT440},
2303 {"NVC1", CARD_NVIDIA_GEFORCE_GT420},
2304 {"NVC0", CARD_NVIDIA_GEFORCE_GTX480},
2305 /* Tesla */
2306 {"NVAF", CARD_NVIDIA_GEFORCE_GT320M},
2307 {"NVAC", CARD_NVIDIA_GEFORCE_8200},
2308 {"NVAA", CARD_NVIDIA_GEFORCE_8200},
2309 {"NVA8", CARD_NVIDIA_GEFORCE_210},
2310 {"NVA5", CARD_NVIDIA_GEFORCE_GT220},
2311 {"NVA3", CARD_NVIDIA_GEFORCE_GT240},
2312 {"NVA0", CARD_NVIDIA_GEFORCE_GTX280},
2313 {"NV98", CARD_NVIDIA_GEFORCE_9200},
2314 {"NV96", CARD_NVIDIA_GEFORCE_9400GT},
2315 {"NV94", CARD_NVIDIA_GEFORCE_9600GT},
2316 {"NV92", CARD_NVIDIA_GEFORCE_9800GT},
2317 {"NV86", CARD_NVIDIA_GEFORCE_8500GT},
2318 {"NV84", CARD_NVIDIA_GEFORCE_8600GT},
2319 {"NV50", CARD_NVIDIA_GEFORCE_8800GTX},
2320 /* Curie */
2321 {"NV68", CARD_NVIDIA_GEFORCE_6200}, /* 7050 */
2322 {"NV67", CARD_NVIDIA_GEFORCE_6200}, /* 7000M */
2323 {"NV63", CARD_NVIDIA_GEFORCE_6200}, /* 7100 */
2324 {"NV4E", CARD_NVIDIA_GEFORCE_6200}, /* 6100 Go / 6150 Go */
2325 {"NV4C", CARD_NVIDIA_GEFORCE_6200}, /* 6150SE */
2326 {"NV4B", CARD_NVIDIA_GEFORCE_7600},
2327 {"NV4A", CARD_NVIDIA_GEFORCE_6200},
2328 {"NV49", CARD_NVIDIA_GEFORCE_7800GT}, /* 7900 */
2329 {"NV47", CARD_NVIDIA_GEFORCE_7800GT},
2330 {"NV46", CARD_NVIDIA_GEFORCE_7400},
2331 {"NV45", CARD_NVIDIA_GEFORCE_6800},
2332 {"NV44", CARD_NVIDIA_GEFORCE_6200},
2333 {"NV43", CARD_NVIDIA_GEFORCE_6600GT},
2334 {"NV42", CARD_NVIDIA_GEFORCE_6800},
2335 {"NV41", CARD_NVIDIA_GEFORCE_6800},
2336 {"NV40", CARD_NVIDIA_GEFORCE_6800},
2337 /* Rankine */
2338 {"NV38", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5950 Ultra */
2339 {"NV36", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5700/5750 */
2340 {"NV35", CARD_NVIDIA_GEFORCEFX_5800}, /* FX 5900 */
2341 {"NV34", CARD_NVIDIA_GEFORCEFX_5200},
2342 {"NV31", CARD_NVIDIA_GEFORCEFX_5600},
2343 {"NV30", CARD_NVIDIA_GEFORCEFX_5800},
2344 /* Kelvin */
2345 {"nv28", CARD_NVIDIA_GEFORCE4_TI4200},
2346 {"nv25", CARD_NVIDIA_GEFORCE4_TI4200},
2347 {"nv20", CARD_NVIDIA_GEFORCE3},
2348 /* Celsius */
2349 {"nv1F", CARD_NVIDIA_GEFORCE4_MX}, /* GF4 MX IGP */
2350 {"nv1A", CARD_NVIDIA_GEFORCE2}, /* GF2 IGP */
2351 {"nv18", CARD_NVIDIA_GEFORCE4_MX},
2352 {"nv17", CARD_NVIDIA_GEFORCE4_MX},
2353 {"nv16", CARD_NVIDIA_GEFORCE2},
2354 {"nv15", CARD_NVIDIA_GEFORCE2},
2355 {"nv11", CARD_NVIDIA_GEFORCE2_MX},
2356 {"nv10", CARD_NVIDIA_GEFORCE},
2357 /* Fahrenheit */
2358 {"nv05", CARD_NVIDIA_RIVA_TNT2},
2359 {"nv04", CARD_NVIDIA_RIVA_TNT},
2360 {"nv03", CARD_NVIDIA_RIVA_128},
2361 };
2362
2363 for (i = 0; i < sizeof(cards) / sizeof(*cards); ++i)
2364 {
2365 if (strstr(gl_renderer, cards[i].renderer))
2366 return cards[i].id;
2367 }
2368
2369 return PCI_DEVICE_NONE;
2370}
2371
2372static const struct gl_vendor_selection
2373{
2374 enum wined3d_gl_vendor gl_vendor;
2375 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
2376 enum wined3d_pci_device (*select_card)(const struct wined3d_gl_info *gl_info, const char *gl_renderer);
2377}
2378nvidia_gl_vendor_table[] =
2379{
2380 {GL_VENDOR_NVIDIA, "Nvidia binary driver", select_card_nvidia_binary},
2381 {GL_VENDOR_APPLE, "Apple OSX NVidia binary driver", select_card_nvidia_binary},
2382 {GL_VENDOR_MESA, "Mesa Nouveau driver", select_card_nvidia_mesa},
2383},
2384amd_gl_vendor_table[] =
2385{
2386 {GL_VENDOR_APPLE, "Apple OSX AMD/ATI binary driver", select_card_amd_binary},
2387 {GL_VENDOR_FGLRX, "AMD/ATI binary driver", select_card_amd_binary},
2388 {GL_VENDOR_MESA, "Mesa AMD/ATI driver", select_card_amd_mesa},
2389},
2390intel_gl_vendor_table[] =
2391{
2392 {GL_VENDOR_APPLE, "Apple OSX Intel binary driver", select_card_intel},
2393 {GL_VENDOR_INTEL, "Mesa Intel driver", select_card_intel},
2394 {GL_VENDOR_MESA, "Mesa Intel driver", select_card_intel},
2395};
2396
2397static enum wined3d_pci_device select_card_fallback_nvidia(const struct wined3d_gl_info *gl_info)
2398{
2399 UINT d3d_level = d3d_level_from_gl_info(gl_info);
2400 if (d3d_level >= 10)
2401 return CARD_NVIDIA_GEFORCE_8800GTX;
2402 if (d3d_level >= 9 && gl_info->supported[NV_VERTEX_PROGRAM3])
2403 return CARD_NVIDIA_GEFORCE_6800;
2404 if (d3d_level >= 9)
2405#ifndef VBOX_WITH_WDDM
2406 return CARD_NVIDIA_GEFORCEFX_5800;
2407#else
2408 return CARD_NVIDIA_GEFORCE_6200;
2409#endif
2410 if (d3d_level >= 8)
2411 return CARD_NVIDIA_GEFORCE3;
2412 if (d3d_level >= 7)
2413 return CARD_NVIDIA_GEFORCE;
2414 if (d3d_level >= 6)
2415 return CARD_NVIDIA_RIVA_TNT;
2416 return CARD_NVIDIA_RIVA_128;
2417}
2418
2419static enum wined3d_pci_device select_card_fallback_amd(const struct wined3d_gl_info *gl_info)
2420{
2421 UINT d3d_level = d3d_level_from_gl_info(gl_info);
2422 if (d3d_level >= 10)
2423 return CARD_AMD_RADEON_HD2900;
2424 if (d3d_level >= 9)
2425 return CARD_AMD_RADEON_9500;
2426 if (d3d_level >= 8)
2427 return CARD_AMD_RADEON_8500;
2428 if (d3d_level >= 7)
2429 return CARD_AMD_RADEON_7200;
2430 return CARD_AMD_RAGE_128PRO;
2431}
2432
2433static enum wined3d_pci_device select_card_fallback_intel(const struct wined3d_gl_info *gl_info)
2434{
2435 UINT d3d_level = d3d_level_from_gl_info(gl_info);
2436 if (d3d_level >= 10)
2437 return CARD_INTEL_G45;
2438 return CARD_INTEL_915G;
2439}
2440
2441static enum wined3d_pci_device select_card_handler(const struct gl_vendor_selection *table,
2442 unsigned int table_size, enum wined3d_gl_vendor gl_vendor,
2443 const struct wined3d_gl_info *gl_info, const char *gl_renderer)
2444{
2445 unsigned int i;
2446
2447 for (i = 0; i < table_size; ++i)
2448 {
2449 if (table[i].gl_vendor != gl_vendor)
2450 continue;
2451
2452 TRACE("Applying card selector \"%s\".\n", table[i].description);
2453 return table[i].select_card(gl_info, gl_renderer);
2454 }
2455 FIXME("Couldn't find a suitable card selector for GL vendor %04x (using GL_RENDERER %s)\n",
2456 gl_vendor, debugstr_a(gl_renderer));
2457
2458 return PCI_DEVICE_NONE;
2459}
2460
2461static const struct
2462{
2463 enum wined3d_pci_vendor card_vendor;
2464 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
2465 const struct gl_vendor_selection *gl_vendor_selection;
2466 unsigned int gl_vendor_count;
2467 enum wined3d_pci_device (*select_card_fallback)(const struct wined3d_gl_info *gl_info);
2468}
2469card_vendor_table[] =
2470{
2471 {HW_VENDOR_NVIDIA, "Nvidia", nvidia_gl_vendor_table,
2472 sizeof(nvidia_gl_vendor_table) / sizeof(nvidia_gl_vendor_table[0]),
2473 select_card_fallback_nvidia},
2474 {HW_VENDOR_AMD, "AMD", amd_gl_vendor_table,
2475 sizeof(amd_gl_vendor_table) / sizeof(amd_gl_vendor_table[0]),
2476 select_card_fallback_amd},
2477 {HW_VENDOR_INTEL, "Intel", intel_gl_vendor_table,
2478 sizeof(intel_gl_vendor_table) / sizeof(intel_gl_vendor_table[0]),
2479 select_card_fallback_intel},
2480};
2481
2482
2483static enum wined3d_pci_device wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
2484 enum wined3d_gl_vendor *gl_vendor, enum wined3d_pci_vendor *card_vendor)
2485{
2486 /* A Direct3D device object contains the PCI id (vendor + device) of the
2487 * videocard which is used for rendering. Various applications use this
2488 * information to get a rough estimation of the features of the card and
2489 * some might use it for enabling 3d effects only on certain types of
2490 * videocards. In some cases games might even use it to work around bugs
2491 * which happen on certain videocards/driver combinations. The problem is
2492 * that OpenGL only exposes a rendering string containing the name of the
2493 * videocard and not the PCI id.
2494 *
2495 * Various games depend on the PCI id, so somehow we need to provide one.
2496 * A simple option is to parse the renderer string and translate this to
2497 * the right PCI id. This is a lot of work because there are more than 200
2498 * GPUs just for Nvidia. Various cards share the same renderer string, so
2499 * the amount of code might be 'small' but there are quite a number of
2500 * exceptions which would make this a pain to maintain. Another way would
2501 * be to query the PCI id from the operating system (assuming this is the
2502 * videocard which is used for rendering which is not always the case).
2503 * This would work but it is not very portable. Second it would not work
2504 * well in, let's say, a remote X situation in which the amount of 3d
2505 * features which can be used is limited.
2506 *
2507 * As said most games only use the PCI id to get an indication of the
2508 * capabilities of the card. It doesn't really matter if the given id is
2509 * the correct one if we return the id of a card with similar 3d features.
2510 *
2511 * The code below checks the OpenGL capabilities of a videocard and matches
2512 * that to a certain level of Direct3D functionality. Once a card passes
2513 * the Direct3D9 check, we know that the card (in case of Nvidia) is at
2514 * least a GeforceFX. To give a better estimate we do a basic check on the
2515 * renderer string but if that won't pass we return a default card. This
2516 * way is better than maintaining a full card database as even without a
2517 * full database we can return a card with similar features. Second the
2518 * size of the database can be made quite small because when you know what
2519 * type of 3d functionality a card has, you know to which GPU family the
2520 * GPU must belong. Because of this you only have to check a small part of
2521 * the renderer string to distinguishes between different models from that
2522 * family.
2523 *
2524 * The code also selects a default amount of video memory which we will
2525 * use for an estimation of the amount of free texture memory. In case of
2526 * real D3D the amount of texture memory includes video memory and system
2527 * memory (to be specific AGP memory or in case of PCIE TurboCache /
2528 * HyperMemory). We don't know how much system memory can be addressed by
2529 * the system but we can make a reasonable estimation about the amount of
2530 * video memory. If the value is slightly wrong it doesn't matter as we
2531 * didn't include AGP-like memory which makes the amount of addressable
2532 * memory higher and second OpenGL isn't that critical it moves to system
2533 * memory behind our backs if really needed. Note that the amount of video
2534 * memory can be overruled using a registry setting. */
2535
2536 unsigned int i;
2537 enum wined3d_pci_device device;
2538
2539 for (i = 0; i < (sizeof(card_vendor_table) / sizeof(*card_vendor_table)); ++i)
2540 {
2541 if (card_vendor_table[i].card_vendor != *card_vendor)
2542 continue;
2543
2544 TRACE("Applying card selector \"%s\".\n", card_vendor_table[i].description);
2545 device = select_card_handler(card_vendor_table[i].gl_vendor_selection,
2546 card_vendor_table[i].gl_vendor_count, *gl_vendor, gl_info, gl_renderer);
2547 if (device != PCI_DEVICE_NONE)
2548 return device;
2549
2550 TRACE("Unrecognized renderer %s, falling back to default.\n", debugstr_a(gl_renderer));
2551 return card_vendor_table[i].select_card_fallback(gl_info);
2552 }
2553
2554 FIXME("No card selector available for card vendor %04x (using GL_RENDERER %s).\n",
2555 *card_vendor, debugstr_a(gl_renderer));
2556
2557 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. */
2558 *card_vendor = HW_VENDOR_NVIDIA;
2559 return select_card_fallback_nvidia(gl_info);
2560}
2561
2562static const struct wined3d_vertex_pipe_ops *select_vertex_implementation(const struct wined3d_gl_info *gl_info,
2563 const struct wined3d_shader_backend_ops *shader_backend_ops)
2564{
2565 if (shader_backend_ops == &glsl_shader_backend)
2566 return &glsl_vertex_pipe;
2567 return &ffp_vertex_pipe;
2568}
2569
2570static const struct fragment_pipeline *select_fragment_implementation(const struct wined3d_gl_info *gl_info,
2571 const struct wined3d_shader_backend_ops *shader_backend_ops)
2572{
2573 if (shader_backend_ops == &glsl_shader_backend)
2574 return &glsl_fragment_pipe;
2575 if (shader_backend_ops == &arb_program_shader_backend && gl_info->supported[ARB_FRAGMENT_PROGRAM])
2576 return &arbfp_fragment_pipeline;
2577 if (gl_info->supported[ATI_FRAGMENT_SHADER])
2578 return &atifs_fragment_pipeline;
2579 if (gl_info->supported[NV_REGISTER_COMBINERS] && gl_info->supported[NV_TEXTURE_SHADER2])
2580 return &nvts_fragment_pipeline;
2581 if (gl_info->supported[NV_REGISTER_COMBINERS])
2582 return &nvrc_fragment_pipeline;
2583 return &ffp_fragment_pipeline;
2584}
2585
2586static const struct wined3d_shader_backend_ops *select_shader_backend(const struct wined3d_gl_info *gl_info)
2587{
2588 BOOL glsl = wined3d_settings.glslRequested && gl_info->glsl_version >= MAKEDWORD_VERSION(1, 20);
2589
2590 if (glsl && gl_info->supported[ARB_FRAGMENT_SHADER])
2591 return &glsl_shader_backend;
2592 if (glsl && gl_info->supported[ARB_VERTEX_SHADER])
2593 {
2594 /* Geforce4 cards support GLSL but for vertex shaders only. Further
2595 * its reported GLSL caps are wrong. This combined with the fact that
2596 * GLSL won't offer more features or performance, use ARB shaders only
2597 * on this card. */
2598 if (gl_info->supported[NV_VERTEX_PROGRAM] && !gl_info->supported[NV_VERTEX_PROGRAM2])
2599 return &arb_program_shader_backend;
2600 return &glsl_shader_backend;
2601 }
2602 if (gl_info->supported[ARB_VERTEX_PROGRAM] || gl_info->supported[ARB_FRAGMENT_PROGRAM])
2603 return &arb_program_shader_backend;
2604 return &none_shader_backend;
2605}
2606
2607static const struct blit_shader *select_blit_implementation(const struct wined3d_gl_info *gl_info,
2608 const struct wined3d_shader_backend_ops *shader_backend_ops)
2609{
2610 if ((shader_backend_ops == &glsl_shader_backend
2611 || shader_backend_ops == &arb_program_shader_backend)
2612 && gl_info->supported[ARB_FRAGMENT_PROGRAM])
2613 return &arbfp_blit;
2614 return &ffp_blit;
2615}
2616
2617static void parse_extension_string(struct wined3d_gl_info *gl_info, const char *extensions,
2618 const struct wined3d_extension_map *map, UINT entry_count)
2619{
2620 while (*extensions)
2621 {
2622 const char *start;
2623 size_t len;
2624 UINT i;
2625
2626 while (isspace(*extensions))
2627 ++extensions;
2628 start = extensions;
2629 while (!isspace(*extensions) && *extensions)
2630 ++extensions;
2631
2632 len = extensions - start;
2633 if (!len)
2634 continue;
2635
2636 TRACE("- %s.\n", debugstr_an(start, len));
2637
2638 for (i = 0; i < entry_count; ++i)
2639 {
2640 if (len == strlen(map[i].extension_string)
2641 && !memcmp(start, map[i].extension_string, len))
2642 {
2643 TRACE(" FOUND: %s support.\n", map[i].extension_string);
2644 gl_info->supported[map[i].extension] = TRUE;
2645 break;
2646 }
2647 }
2648 }
2649}
2650
2651static void load_gl_funcs(struct wined3d_gl_info *gl_info)
2652{
2653#define USE_GL_FUNC(pfn) gl_info->gl_ops.ext.p_##pfn = (void *)wglGetProcAddress(#pfn);
2654 GL_EXT_FUNCS_GEN;
2655#undef USE_GL_FUNC
2656
2657#ifndef USE_WIN32_OPENGL
2658 /* hack: use the functions directly from the TEB table to bypass the thunks */
2659 /* note that we still need the above wglGetProcAddress calls to initialize the table */
2660 gl_info->gl_ops.ext = ((struct opengl_funcs *)NtCurrentTeb()->glTable)->ext;
2661#endif
2662}
2663
2664static void wined3d_adapter_init_limits(struct wined3d_gl_info *gl_info)
2665{
2666 GLfloat gl_floatv[2];
2667 GLint gl_max;
2668
2669 gl_info->limits.blends = 1;
2670 gl_info->limits.buffers = 1;
2671 gl_info->limits.textures = 1;
2672 gl_info->limits.texture_coords = 1;
2673 gl_info->limits.fragment_samplers = 1;
2674 gl_info->limits.vertex_samplers = 0;
2675 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers + gl_info->limits.vertex_samplers;
2676 gl_info->limits.vertex_attribs = 16;
2677 gl_info->limits.glsl_vs_float_constants = 0;
2678 gl_info->limits.glsl_ps_float_constants = 0;
2679 gl_info->limits.arb_vs_float_constants = 0;
2680 gl_info->limits.arb_vs_native_constants = 0;
2681 gl_info->limits.arb_vs_instructions = 0;
2682 gl_info->limits.arb_vs_temps = 0;
2683 gl_info->limits.arb_ps_float_constants = 0;
2684 gl_info->limits.arb_ps_local_constants = 0;
2685 gl_info->limits.arb_ps_instructions = 0;
2686 gl_info->limits.arb_ps_temps = 0;
2687
2688 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
2689 gl_info->limits.clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
2690 TRACE("Clip plane support - max planes %d.\n", gl_max);
2691
2692 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
2693 gl_info->limits.lights = gl_max;
2694 TRACE("Light support - max lights %d.\n", gl_max);
2695
2696 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
2697 gl_info->limits.texture_size = gl_max;
2698 TRACE("Maximum texture size support - max texture size %d.\n", gl_max);
2699
2700 gl_info->gl_ops.gl.p_glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
2701 gl_info->limits.pointsize_min = gl_floatv[0];
2702 gl_info->limits.pointsize_max = gl_floatv[1];
2703 TRACE("Maximum point size support - max point size %f.\n", gl_floatv[1]);
2704
2705 if (gl_info->supported[ARB_MAP_BUFFER_ALIGNMENT])
2706 {
2707 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MIN_MAP_BUFFER_ALIGNMENT, &gl_max);
2708 TRACE("Minimum buffer map alignment: %d.\n", gl_max);
2709 }
2710 else
2711 {
2712 WARN_(d3d_perf)("Driver doesn't guarantee a minimum buffer map alignment.\n");
2713 }
2714 if (gl_info->supported[NV_REGISTER_COMBINERS])
2715 {
2716 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &gl_max);
2717 gl_info->limits.general_combiners = gl_max;
2718 TRACE("Max general combiners: %d.\n", gl_max);
2719 }
2720 if (gl_info->supported[ARB_DRAW_BUFFERS] && wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2721 {
2722 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
2723 gl_info->limits.buffers = gl_max;
2724 TRACE("Max draw buffers: %u.\n", gl_max);
2725 }
2726 if (gl_info->supported[ARB_MULTITEXTURE])
2727 {
2728 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
2729 gl_info->limits.textures = min(MAX_TEXTURES, gl_max);
2730 TRACE("Max textures: %d.\n", gl_info->limits.textures);
2731
2732 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2733 {
2734 GLint tmp;
2735 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &gl_max);
2736 gl_info->limits.texture_coords = min(MAX_TEXTURES, gl_max);
2737 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2738 gl_info->limits.fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
2739 }
2740 else
2741 {
2742 gl_info->limits.texture_coords = max(gl_info->limits.texture_coords, gl_max);
2743 gl_info->limits.fragment_samplers = max(gl_info->limits.fragment_samplers, gl_max);
2744 }
2745 TRACE("Max texture coords: %d.\n", gl_info->limits.texture_coords);
2746 TRACE("Max fragment samplers: %d.\n", gl_info->limits.fragment_samplers);
2747
2748 if (gl_info->supported[ARB_VERTEX_SHADER])
2749 {
2750 GLint tmp;
2751 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2752 gl_info->limits.vertex_samplers = tmp;
2753 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2754 gl_info->limits.combined_samplers = tmp;
2755 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_ATTRIBS_ARB, &tmp);
2756 gl_info->limits.vertex_attribs = tmp;
2757
2758 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
2759 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
2760 * an issue because then the sampler setup only depends on the two shaders. If a pixel
2761 * shader is used with fixed function vertex processing we're fine too because fixed function
2762 * vertex processing doesn't use any samplers. If fixed function fragment processing is
2763 * used we have to make sure that all vertex sampler setups are valid together with all
2764 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
2765 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
2766 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
2767 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
2768 * a fixed function pipeline anymore.
2769 *
2770 * So this is just a check to check that our assumption holds true. If not, write a warning
2771 * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
2772 if (gl_info->limits.vertex_samplers && gl_info->limits.combined_samplers < 12
2773 && MAX_TEXTURES + gl_info->limits.vertex_samplers > gl_info->limits.combined_samplers)
2774 {
2775 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
2776 gl_info->limits.vertex_samplers, gl_info->limits.combined_samplers);
2777 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
2778 if (gl_info->limits.combined_samplers > MAX_TEXTURES)
2779 gl_info->limits.vertex_samplers = gl_info->limits.combined_samplers - MAX_TEXTURES;
2780 else
2781 gl_info->limits.vertex_samplers = 0;
2782 }
2783 }
2784 else
2785 {
2786 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers;
2787 }
2788 TRACE("Max vertex samplers: %u.\n", gl_info->limits.vertex_samplers);
2789 TRACE("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
2790 }
2791 if (gl_info->supported[ARB_VERTEX_BLEND])
2792 {
2793 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
2794 gl_info->limits.blends = gl_max;
2795 TRACE("Max blends: %u.\n", gl_info->limits.blends);
2796 }
2797 if (gl_info->supported[EXT_TEXTURE3D])
2798 {
2799 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
2800 gl_info->limits.texture3d_size = gl_max;
2801 TRACE("Max texture3D size: %d.\n", gl_info->limits.texture3d_size);
2802 }
2803 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
2804 {
2805 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
2806 gl_info->limits.anisotropy = gl_max;
2807 TRACE("Max anisotropy: %d.\n", gl_info->limits.anisotropy);
2808 }
2809 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2810 {
2811 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2812 gl_info->limits.arb_ps_float_constants = gl_max;
2813 TRACE("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->limits.arb_ps_float_constants);
2814 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2815 gl_info->limits.arb_ps_native_constants = gl_max;
2816 TRACE("Max ARB_FRAGMENT_PROGRAM native float constants: %d.\n",
2817 gl_info->limits.arb_ps_native_constants);
2818 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2819 gl_info->limits.arb_ps_temps = gl_max;
2820 TRACE("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_ps_temps);
2821 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2822 gl_info->limits.arb_ps_instructions = gl_max;
2823 TRACE("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->limits.arb_ps_instructions);
2824 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
2825 gl_info->limits.arb_ps_local_constants = gl_max;
2826 TRACE("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->limits.arb_ps_instructions);
2827 }
2828 if (gl_info->supported[ARB_VERTEX_PROGRAM])
2829 {
2830 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2831 gl_info->limits.arb_vs_float_constants = gl_max;
2832 TRACE("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->limits.arb_vs_float_constants);
2833 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2834 gl_info->limits.arb_vs_native_constants = gl_max;
2835 TRACE("Max ARB_VERTEX_PROGRAM native float constants: %d.\n",
2836 gl_info->limits.arb_vs_native_constants);
2837 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2838 gl_info->limits.arb_vs_temps = gl_max;
2839 TRACE("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_vs_temps);
2840 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2841 gl_info->limits.arb_vs_instructions = gl_max;
2842 TRACE("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->limits.arb_vs_instructions);
2843 }
2844 if (gl_info->supported[ARB_VERTEX_SHADER])
2845 {
2846 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
2847 gl_info->limits.glsl_vs_float_constants = gl_max / 4;
2848 TRACE("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->limits.glsl_vs_float_constants);
2849#ifdef VBOX_WITH_WDDM
2850 /* AFAICT the " / 4" here comes from that we're going to use the glsl_vs/ps_float_constants to create vec4 arrays,
2851 * thus each array element has 4 components, so the actual number of vec4 arrays is GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2852 * win8 Aero won't properly work with this constant < 256 in any way,
2853 * while Intel drivers I've encountered this problem with supports vec4 arrays of size > GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2854 * so use it here.
2855 * @todo: add logging
2856 * @todo: perhaps should be movet to quirks?
2857 * */
2858 if (gl_info->limits.glsl_vs_float_constants < 256 && gl_max >= 256)
2859 {
2860 DWORD dwVersion = GetVersion();
2861 DWORD dwMajor = (DWORD)(LOBYTE(LOWORD(dwVersion)));
2862 DWORD dwMinor = (DWORD)(HIBYTE(LOWORD(dwVersion)));
2863 /* tmp workaround Win8 Aero requirement for 256 */
2864 if (dwMajor > 6 || dwMinor > 1)
2865 {
2866 gl_info->limits.glsl_vs_float_constants = 256;
2867 }
2868 }
2869#endif
2870 }
2871 if (gl_info->supported[ARB_FRAGMENT_SHADER])
2872 {
2873 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
2874 gl_info->limits.glsl_ps_float_constants = gl_max / 4;
2875 TRACE("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->limits.glsl_ps_float_constants);
2876#ifdef VBOX_WITH_WDDM
2877 /* AFAICT the " / 4" here comes from that we're going to use the glsl_vs/ps_float_constants to create vec4 arrays,
2878 * thus each array element has 4 components, so the actual number of vec4 arrays is GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2879 * win8 Aero won't properly work with this constant < 256 in any way,
2880 * while Intel drivers I've encountered this problem with supports vec4 arrays of size > GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2881 * so use it here.
2882 * @todo: add logging
2883 * @todo: perhaps should be movet to quirks?
2884 * */
2885 if (gl_info->limits.glsl_ps_float_constants < 256 && gl_max >= 256)
2886 {
2887 DWORD dwVersion = GetVersion();
2888 DWORD dwMajor = (DWORD)(LOBYTE(LOWORD(dwVersion)));
2889 DWORD dwMinor = (DWORD)(HIBYTE(LOWORD(dwVersion)));
2890 /* tmp workaround Win8 Aero requirement for 256 */
2891 if (dwMajor > 6 || dwMinor > 1)
2892 {
2893 gl_info->limits.glsl_ps_float_constants = 256;
2894 }
2895 }
2896#endif
2897 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
2898 gl_info->limits.glsl_varyings = gl_max;
2899 TRACE("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
2900 }
2901
2902 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
2903 gl_info->gl_ops.gl.p_glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->limits.shininess);
2904 else
2905 gl_info->limits.shininess = 128.0f;
2906
2907 if ((gl_info->supported[ARB_FRAMEBUFFER_OBJECT] || gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
2908 && wined3d_settings.allow_multisampling)
2909 {
2910 gl_info->gl_ops.gl.p_glGetIntegerv(GL_MAX_SAMPLES, &gl_max);
2911 gl_info->limits.samples = gl_max;
2912 }
2913}
2914
2915/* Context activation is done by the caller. */
2916static BOOL wined3d_adapter_init_gl_caps(struct wined3d_adapter *adapter)
2917{
2918 struct wined3d_driver_info *driver_info = &adapter->driver_info;
2919 const char *gl_vendor_str, *gl_renderer_str, *gl_version_str;
2920 struct wined3d_gl_info *gl_info = &adapter->gl_info;
2921 struct wined3d_vertex_caps vertex_caps;
2922 enum wined3d_pci_vendor card_vendor;
2923 struct fragment_caps fragment_caps;
2924 struct shader_caps shader_caps;
2925 const char *WGL_Extensions = NULL;
2926 const char *GL_Extensions = NULL;
2927 enum wined3d_gl_vendor gl_vendor;
2928 enum wined3d_pci_device device;
2929 DWORD gl_version;
2930 HDC hdc;
2931 unsigned int i;
2932
2933 TRACE("adapter %p.\n", adapter);
2934
2935 gl_renderer_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_RENDERER);
2936 TRACE("GL_RENDERER: %s.\n", debugstr_a(gl_renderer_str));
2937 if (!gl_renderer_str)
2938 {
2939 ERR("Received a NULL GL_RENDERER.\n");
2940 return FALSE;
2941 }
2942
2943 gl_vendor_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VENDOR);
2944 TRACE("GL_VENDOR: %s.\n", debugstr_a(gl_vendor_str));
2945 if (!gl_vendor_str)
2946 {
2947 ERR("Received a NULL GL_VENDOR.\n");
2948 return FALSE;
2949 }
2950
2951 /* Parse the GL_VERSION field into major and minor information */
2952 gl_version_str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_VERSION);
2953 TRACE("GL_VERSION: %s.\n", debugstr_a(gl_version_str));
2954 if (!gl_version_str)
2955 {
2956 ERR("Received a NULL GL_VERSION.\n");
2957 return FALSE;
2958 }
2959 gl_version = wined3d_parse_gl_version(gl_version_str);
2960
2961 /* Parse the gl supported features, in theory enabling parts of our code appropriately. */
2962 GL_Extensions = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_EXTENSIONS);
2963 if (!GL_Extensions)
2964 {
2965 ERR("Received a NULL GL_EXTENSIONS.\n");
2966 return FALSE;
2967 }
2968
2969 memset(gl_info->supported, 0, sizeof(gl_info->supported));
2970 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
2971
2972 TRACE("GL extensions reported:\n");
2973 parse_extension_string(gl_info, GL_Extensions, gl_extension_map,
2974 sizeof(gl_extension_map) / sizeof(*gl_extension_map));
2975
2976 /* Now work out what GL support this card really has. */
2977 load_gl_funcs( gl_info );
2978
2979 hdc = wglGetCurrentDC();
2980 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox. */
2981 if (GL_EXTCALL(wglGetExtensionsStringARB))
2982 WGL_Extensions = (const char *)GL_EXTCALL(wglGetExtensionsStringARB(hdc));
2983 if (!WGL_Extensions)
2984 WARN("WGL extensions not supported.\n");
2985 else
2986 parse_extension_string(gl_info, WGL_Extensions, wgl_extension_map,
2987 sizeof(wgl_extension_map) / sizeof(*wgl_extension_map));
2988
2989 if (!gl_info->supported[EXT_TEXTURE3D] && gl_version >= MAKEDWORD_VERSION(1, 2))
2990 {
2991 TRACE("GL CORE: GL_EXT_texture3D support.\n");
2992 gl_info->gl_ops.ext.p_glTexImage3DEXT = (void *)gl_info->gl_ops.ext.p_glTexImage3D;
2993 gl_info->gl_ops.ext.p_glTexSubImage3DEXT = gl_info->gl_ops.ext.p_glTexSubImage3D;
2994 gl_info->supported[EXT_TEXTURE3D] = TRUE;
2995 }
2996
2997 if (!gl_info->supported[NV_POINT_SPRITE] && gl_version >= MAKEDWORD_VERSION(1, 4))
2998 {
2999 TRACE("GL CORE: GL_NV_point_sprite support.\n");
3000 gl_info->gl_ops.ext.p_glPointParameterivNV = gl_info->gl_ops.ext.p_glPointParameteriv;
3001 gl_info->gl_ops.ext.p_glPointParameteriNV = gl_info->gl_ops.ext.p_glPointParameteri;
3002 gl_info->supported[NV_POINT_SPRITE] = TRUE;
3003 }
3004
3005 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] && gl_version >= MAKEDWORD_VERSION(2, 0))
3006 {
3007 TRACE("GL CORE: GL_ARB_texture_non_power_of_two support.\n");
3008 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = TRUE;
3009 }
3010
3011 if (gl_version >= MAKEDWORD_VERSION(2, 0)) gl_info->supported[WINED3D_GL_VERSION_2_0] = TRUE;
3012
3013 if (gl_info->supported[APPLE_FENCE])
3014 {
3015 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
3016 * The apple extension interacts with some other apple exts. Disable the NV
3017 * extension if the apple one is support to prevent confusion in other parts
3018 * of the code. */
3019 gl_info->supported[NV_FENCE] = FALSE;
3020 }
3021 if (gl_info->supported[APPLE_FLOAT_PIXELS])
3022 {
3023 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
3024 *
3025 * The enums are the same:
3026 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881a
3027 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881b
3028 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
3029 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
3030 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140b
3031 */
3032 if (!gl_info->supported[ARB_TEXTURE_FLOAT])
3033 {
3034 TRACE(" IMPLIED: GL_ARB_texture_float support (by GL_APPLE_float_pixels).\n");
3035 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
3036 }
3037 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
3038 {
3039 TRACE(" IMPLIED: GL_ARB_half_float_pixel support (by GL_APPLE_float_pixels).\n");
3040 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
3041 }
3042 }
3043 if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
3044 {
3045 /* GL_ARB_map_buffer_range and GL_APPLE_flush_buffer_range provide the same
3046 * functionality. Prefer the ARB extension */
3047 gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] = FALSE;
3048 }
3049 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
3050 {
3051 TRACE(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
3052 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
3053 }
3054 if (!gl_info->supported[ARB_DEPTH_CLAMP] && gl_info->supported[NV_DEPTH_CLAMP])
3055 {
3056 TRACE(" IMPLIED: ARB_depth_clamp support (by NV_depth_clamp).\n");
3057 gl_info->supported[ARB_DEPTH_CLAMP] = TRUE;
3058 }
3059 if (!gl_info->supported[ARB_VERTEX_ARRAY_BGRA] && gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
3060 {
3061 TRACE(" IMPLIED: ARB_vertex_array_bgra support (by EXT_vertex_array_bgra).\n");
3062 gl_info->supported[ARB_VERTEX_ARRAY_BGRA] = TRUE;
3063 }
3064 if (!gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] && gl_info->supported[EXT_TEXTURE_COMPRESSION_RGTC])
3065 {
3066 TRACE(" IMPLIED: ARB_texture_compression_rgtc support (by EXT_texture_compression_rgtc).\n");
3067 gl_info->supported[ARB_TEXTURE_COMPRESSION_RGTC] = TRUE;
3068 }
3069 if (gl_info->supported[NV_TEXTURE_SHADER2])
3070 {
3071 if (gl_info->supported[NV_REGISTER_COMBINERS])
3072 {
3073 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
3074 * are supported. The nv extensions provide the same functionality as the
3075 * ATI one, and a bit more(signed pixelformats). */
3076 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
3077 }
3078 }
3079 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
3080 {
3081 /* If we have full NP2 texture support, disable
3082 * GL_ARB_texture_rectangle because we will never use it.
3083 * This saves a few redundant glDisable calls. */
3084 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
3085 }
3086 if (gl_info->supported[ATI_FRAGMENT_SHADER])
3087 {
3088 /* Disable NV_register_combiners and fragment shader if this is supported.
3089 * generally the NV extensions are preferred over the ATI ones, and this
3090 * extension is disabled if register_combiners and texture_shader2 are both
3091 * supported. So we reach this place only if we have incomplete NV dxlevel 8
3092 * fragment processing support. */
3093 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
3094 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
3095 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
3096 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
3097 }
3098 if (gl_info->supported[NV_HALF_FLOAT])
3099 {
3100 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
3101 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
3102 }
3103 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB] && !gl_info->supported[EXT_TEXTURE_SRGB_DECODE])
3104 {
3105 /* Current wined3d sRGB infrastructure requires EXT_texture_sRGB_decode
3106 * for GL_ARB_framebuffer_sRGB support (without EXT_texture_sRGB_decode
3107 * we never render to sRGB surfaces). */
3108 gl_info->supported[ARB_FRAMEBUFFER_SRGB] = FALSE;
3109 }
3110 if (gl_info->supported[ARB_OCCLUSION_QUERY])
3111 {
3112 GLint counter_bits;
3113
3114 GL_EXTCALL(glGetQueryivARB(GL_SAMPLES_PASSED_ARB, GL_QUERY_COUNTER_BITS_ARB, &counter_bits));
3115 TRACE("Occlusion query counter has %d bits.\n", counter_bits);
3116 if (!counter_bits)
3117 gl_info->supported[ARB_OCCLUSION_QUERY] = FALSE;
3118 }
3119 if (!gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] && gl_info->supported[EXT_TEXTURE_MIRROR_CLAMP])
3120 {
3121 TRACE(" IMPLIED: ATI_texture_mirror_once support (by EXT_texture_mirror_clamp).\n");
3122 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] = TRUE;
3123 }
3124 if (!gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] && gl_info->supported[ATI_TEXTURE_MIRROR_ONCE])
3125 {
3126 TRACE(" IMPLIED: ARB_texture_mirror_clamp_to_edge support (by ATI_texture_mirror_once).\n");
3127 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] = TRUE;
3128 }
3129
3130 wined3d_adapter_init_limits(gl_info);
3131
3132 if (gl_info->supported[ARB_VERTEX_PROGRAM] && test_arb_vs_offset_limit(gl_info))
3133 gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
3134
3135 if (gl_info->supported[ARB_SHADING_LANGUAGE_100])
3136 {
3137 const char *str = (const char *)gl_info->gl_ops.gl.p_glGetString(GL_SHADING_LANGUAGE_VERSION_ARB);
3138 unsigned int major, minor;
3139
3140 TRACE("GLSL version string: %s.\n", debugstr_a(str));
3141
3142 /* The format of the GLSL version string is "major.minor[.release] [vendor info]". */
3143 sscanf(str, "%u.%u", &major, &minor);
3144 gl_info->glsl_version = MAKEDWORD_VERSION(major, minor);
3145 }
3146
3147 checkGLcall("extension detection");
3148
3149 adapter->shader_backend = select_shader_backend(gl_info);
3150 adapter->vertex_pipe = select_vertex_implementation(gl_info, adapter->shader_backend);
3151 adapter->fragment_pipe = select_fragment_implementation(gl_info, adapter->shader_backend);
3152 adapter->blitter = select_blit_implementation(gl_info, adapter->shader_backend);
3153
3154 adapter->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
3155 adapter->d3d_info.vs_clipping = shader_caps.wined3d_caps & WINED3D_SHADER_CAP_VS_CLIPPING;
3156 adapter->d3d_info.limits.vs_version = shader_caps.vs_version;
3157 adapter->d3d_info.limits.gs_version = shader_caps.gs_version;
3158 adapter->d3d_info.limits.ps_version = shader_caps.ps_version;
3159 adapter->d3d_info.limits.vs_uniform_count = shader_caps.vs_uniform_count;
3160 adapter->d3d_info.limits.ps_uniform_count = shader_caps.ps_uniform_count;
3161
3162 adapter->vertex_pipe->vp_get_caps(gl_info, &vertex_caps);
3163 adapter->d3d_info.xyzrhw = vertex_caps.xyzrhw;
3164
3165 adapter->fragment_pipe->get_caps(gl_info, &fragment_caps);
3166 adapter->d3d_info.limits.ffp_blend_stages = fragment_caps.MaxTextureBlendStages;
3167 adapter->d3d_info.limits.ffp_textures = fragment_caps.MaxSimultaneousTextures;
3168 TRACE("Max texture stages: %u.\n", adapter->d3d_info.limits.ffp_blend_stages);
3169
3170 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
3171 {
3172 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbuffer;
3173 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbuffer;
3174 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffers;
3175 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffers;
3176 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorage;
3177 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisample;
3178 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameteriv;
3179 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebuffer;
3180 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebuffer;
3181 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffers;
3182 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffers;
3183 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatus;
3184 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1D;
3185 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2D;
3186 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3D;
3187 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbuffer;
3188 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3189 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameteriv;
3190 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebuffer;
3191 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmap;
3192 }
3193 else
3194 {
3195 if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
3196 {
3197 gl_info->fbo_ops.glIsRenderbuffer = gl_info->gl_ops.ext.p_glIsRenderbufferEXT;
3198 gl_info->fbo_ops.glBindRenderbuffer = gl_info->gl_ops.ext.p_glBindRenderbufferEXT;
3199 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->gl_ops.ext.p_glDeleteRenderbuffersEXT;
3200 gl_info->fbo_ops.glGenRenderbuffers = gl_info->gl_ops.ext.p_glGenRenderbuffersEXT;
3201 gl_info->fbo_ops.glRenderbufferStorage = gl_info->gl_ops.ext.p_glRenderbufferStorageEXT;
3202 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->gl_ops.ext.p_glGetRenderbufferParameterivEXT;
3203 gl_info->fbo_ops.glIsFramebuffer = gl_info->gl_ops.ext.p_glIsFramebufferEXT;
3204 gl_info->fbo_ops.glBindFramebuffer = gl_info->gl_ops.ext.p_glBindFramebufferEXT;
3205 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->gl_ops.ext.p_glDeleteFramebuffersEXT;
3206 gl_info->fbo_ops.glGenFramebuffers = gl_info->gl_ops.ext.p_glGenFramebuffersEXT;
3207 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->gl_ops.ext.p_glCheckFramebufferStatusEXT;
3208 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->gl_ops.ext.p_glFramebufferTexture1DEXT;
3209 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->gl_ops.ext.p_glFramebufferTexture2DEXT;
3210 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->gl_ops.ext.p_glFramebufferTexture3DEXT;
3211 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->gl_ops.ext.p_glFramebufferRenderbufferEXT;
3212 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv
3213 = gl_info->gl_ops.ext.p_glGetFramebufferAttachmentParameterivEXT;
3214 gl_info->fbo_ops.glGenerateMipmap = gl_info->gl_ops.ext.p_glGenerateMipmapEXT;
3215 }
3216 else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3217 {
3218 WARN_(d3d_perf)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
3219 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
3220 }
3221 if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
3222 {
3223 gl_info->fbo_ops.glBlitFramebuffer = gl_info->gl_ops.ext.p_glBlitFramebufferEXT;
3224 }
3225 if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
3226 {
3227 gl_info->fbo_ops.glRenderbufferStorageMultisample
3228 = gl_info->gl_ops.ext.p_glRenderbufferStorageMultisampleEXT;
3229 }
3230 }
3231
3232 gl_vendor = wined3d_guess_gl_vendor(gl_info, gl_vendor_str, gl_renderer_str);
3233 card_vendor = wined3d_guess_card_vendor(gl_vendor_str, gl_renderer_str);
3234 TRACE("Found GL_VENDOR (%s)->(0x%04x/0x%04x).\n", debugstr_a(gl_vendor_str), gl_vendor, card_vendor);
3235
3236 device = wined3d_guess_card(gl_info, gl_renderer_str, &gl_vendor, &card_vendor);
3237 TRACE("Found (fake) card: 0x%x (vendor id), 0x%x (device id).\n", card_vendor, device);
3238
3239 gl_info->wrap_lookup[WINED3D_TADDRESS_WRAP - WINED3D_TADDRESS_WRAP] = GL_REPEAT;
3240 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR - WINED3D_TADDRESS_WRAP] =
3241 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
3242 gl_info->wrap_lookup[WINED3D_TADDRESS_CLAMP - WINED3D_TADDRESS_WRAP] = GL_CLAMP_TO_EDGE;
3243 gl_info->wrap_lookup[WINED3D_TADDRESS_BORDER - WINED3D_TADDRESS_WRAP] =
3244 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
3245 gl_info->wrap_lookup[WINED3D_TADDRESS_MIRROR_ONCE - WINED3D_TADDRESS_WRAP] =
3246 gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE] ? GL_MIRROR_CLAMP_TO_EDGE : GL_REPEAT;
3247
3248 adapter->d3d_info.valid_rt_mask = 0;
3249 for (i = 0; i < gl_info->limits.buffers; ++i)
3250 adapter->d3d_info.valid_rt_mask |= (1 << i);
3251
3252 fixup_extensions(gl_info, gl_renderer_str, gl_vendor, card_vendor, device);
3253 init_driver_info(driver_info, card_vendor, device);
3254 add_gl_compat_wrappers(gl_info);
3255
3256 return TRUE;
3257}
3258
3259UINT CDECL wined3d_get_adapter_count(const struct wined3d *wined3d)
3260{
3261 TRACE("wined3d %p, reporting %u adapters.\n",
3262 wined3d, wined3d->adapter_count);
3263
3264 return wined3d->adapter_count;
3265}
3266
3267HRESULT CDECL wined3d_register_software_device(struct wined3d *wined3d, void *init_function)
3268{
3269 FIXME("wined3d %p, init_function %p stub!\n", wined3d, init_function);
3270
3271 return WINED3D_OK;
3272}
3273
3274HMONITOR CDECL wined3d_get_adapter_monitor(const struct wined3d *wined3d, UINT adapter_idx)
3275{
3276 TRACE("wined3d %p, adapter_idx %u.\n", wined3d, adapter_idx);
3277
3278 if (adapter_idx >= wined3d->adapter_count)
3279 return NULL;
3280
3281 return MonitorFromPoint(wined3d->adapters[adapter_idx].monitorPoint, MONITOR_DEFAULTTOPRIMARY);
3282}
3283
3284/* FIXME: GetAdapterModeCount and EnumAdapterModes currently only returns modes
3285 of the same bpp but different resolutions */
3286
3287/* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
3288UINT CDECL wined3d_get_adapter_mode_count(const struct wined3d *wined3d, UINT adapter_idx,
3289 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering)
3290{
3291 const struct wined3d_adapter *adapter;
3292 const struct wined3d_format *format;
3293 unsigned int i = 0;
3294 unsigned int j = 0;
3295 UINT format_bits;
3296 DEVMODEW mode;
3297
3298 TRACE("wined3d %p, adapter_idx %u, format %s, scanline_ordering %#x.\n",
3299 wined3d, adapter_idx, debug_d3dformat(format_id), scanline_ordering);
3300
3301 if (adapter_idx >= wined3d->adapter_count)
3302 return 0;
3303
3304 adapter = &wined3d->adapters[adapter_idx];
3305 format = wined3d_get_format(&adapter->gl_info, format_id);
3306 format_bits = format->byte_count * CHAR_BIT;
3307
3308 memset(&mode, 0, sizeof(mode));
3309 mode.dmSize = sizeof(mode);
3310
3311 while (EnumDisplaySettingsExW(adapter->DeviceName, j++, &mode, 0))
3312 {
3313 if (mode.dmFields & DM_DISPLAYFLAGS)
3314 {
3315 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_PROGRESSIVE
3316#ifndef VBOX_WINE_WITHOUT_LIBWINE
3317 && (mode.u2.dmDisplayFlags & DM_INTERLACED))
3318#else
3319 && (mode.dmDisplayFlags & DM_INTERLACED))
3320#endif
3321 continue;
3322
3323 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED
3324#ifndef VBOX_WINE_WITHOUT_LIBWINE
3325 && !(mode.u2.dmDisplayFlags & DM_INTERLACED))
3326#else
3327 && !(mode.dmDisplayFlags & DM_INTERLACED))
3328#endif
3329 continue;
3330 }
3331
3332 if (format_id == WINED3DFMT_UNKNOWN)
3333 {
3334 /* This is for d3d8, do not enumerate P8 here. */
3335 if (mode.dmBitsPerPel == 32 || mode.dmBitsPerPel == 16) ++i;
3336 }
3337 else if (mode.dmBitsPerPel == format_bits)
3338 {
3339 ++i;
3340 }
3341 }
3342
3343 TRACE("Returning %u matching modes (out of %u total) for adapter %u.\n", i, j, adapter_idx);
3344
3345 return i;
3346}
3347
3348/* Note: dx9 supplies a format. Calls from d3d8 supply WINED3DFMT_UNKNOWN */
3349HRESULT CDECL wined3d_enum_adapter_modes(const struct wined3d *wined3d, UINT adapter_idx,
3350 enum wined3d_format_id format_id, enum wined3d_scanline_ordering scanline_ordering,
3351 UINT mode_idx, struct wined3d_display_mode *mode)
3352{
3353 const struct wined3d_adapter *adapter;
3354 const struct wined3d_format *format;
3355 UINT format_bits;
3356 DEVMODEW m;
3357 UINT i = 0;
3358 int j = 0;
3359
3360 TRACE("wined3d %p, adapter_idx %u, format %s, scanline_ordering %#x, mode_idx %u, mode %p.\n",
3361 wined3d, adapter_idx, debug_d3dformat(format_id), scanline_ordering, mode_idx, mode);
3362
3363 if (!mode || adapter_idx >= wined3d->adapter_count)
3364 return WINED3DERR_INVALIDCALL;
3365
3366 adapter = &wined3d->adapters[adapter_idx];
3367 format = wined3d_get_format(&adapter->gl_info, format_id);
3368 format_bits = format->byte_count * CHAR_BIT;
3369
3370 memset(&m, 0, sizeof(m));
3371 m.dmSize = sizeof(m);
3372
3373 while (i <= mode_idx)
3374 {
3375 if (!EnumDisplaySettingsExW(adapter->DeviceName, j++, &m, 0))
3376 {
3377 WARN("Invalid mode_idx %u.\n", mode_idx);
3378 return WINED3DERR_INVALIDCALL;
3379 }
3380
3381 if (m.dmFields & DM_DISPLAYFLAGS)
3382 {
3383 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_PROGRESSIVE
3384#ifndef VBOX_WINE_WITHOUT_LIBWINE
3385 && (m.u2.dmDisplayFlags & DM_INTERLACED))
3386#else
3387 && (m.dmDisplayFlags & DM_INTERLACED))
3388#endif
3389 continue;
3390
3391 if (scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED
3392#ifndef VBOX_WINE_WITHOUT_LIBWINE
3393 && !(m.u2.dmDisplayFlags & DM_INTERLACED))
3394#else
3395 && !(m.dmDisplayFlags & DM_INTERLACED))
3396#endif
3397 continue;
3398 }
3399
3400 if (format_id == WINED3DFMT_UNKNOWN)
3401 {
3402 /* This is for d3d8, do not enumerate P8 here. */
3403 if (m.dmBitsPerPel == 32 || m.dmBitsPerPel == 16) ++i;
3404 }
3405 else if (m.dmBitsPerPel == format_bits)
3406 {
3407 ++i;
3408 }
3409 }
3410
3411 mode->width = m.dmPelsWidth;
3412 mode->height = m.dmPelsHeight;
3413 mode->refresh_rate = DEFAULT_REFRESH_RATE;
3414 if (m.dmFields & DM_DISPLAYFREQUENCY)
3415 mode->refresh_rate = m.dmDisplayFrequency;
3416
3417 if (format_id == WINED3DFMT_UNKNOWN)
3418 mode->format_id = pixelformat_for_depth(m.dmBitsPerPel);
3419 else
3420 mode->format_id = format_id;
3421
3422 if (!(m.dmFields & DM_DISPLAYFLAGS))
3423 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
3424#ifndef VBOX_WINE_WITHOUT_LIBWINE
3425 else if (m.u2.dmDisplayFlags & DM_INTERLACED)
3426#else
3427 else if (m.dmDisplayFlags & DM_INTERLACED)
3428#endif
3429 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
3430 else
3431 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
3432
3433 TRACE("%ux%u@%u %u bpp, %s %#x.\n", mode->width, mode->height, mode->refresh_rate,
3434 m.dmBitsPerPel, debug_d3dformat(mode->format_id), mode->scanline_ordering);
3435
3436 return WINED3D_OK;
3437}
3438
3439HRESULT CDECL wined3d_get_adapter_display_mode(const struct wined3d *wined3d, UINT adapter_idx,
3440 struct wined3d_display_mode *mode, enum wined3d_display_rotation *rotation)
3441{
3442 const struct wined3d_adapter *adapter;
3443 DEVMODEW m;
3444
3445 TRACE("wined3d %p, adapter_idx %u, display_mode %p, rotation %p.\n",
3446 wined3d, adapter_idx, mode, rotation);
3447
3448 if (!mode || adapter_idx >= wined3d->adapter_count)
3449 return WINED3DERR_INVALIDCALL;
3450
3451 adapter = &wined3d->adapters[adapter_idx];
3452
3453 memset(&m, 0, sizeof(m));
3454 m.dmSize = sizeof(m);
3455
3456 EnumDisplaySettingsExW(adapter->DeviceName, ENUM_CURRENT_SETTINGS, &m, 0);
3457 mode->width = m.dmPelsWidth;
3458 mode->height = m.dmPelsHeight;
3459 mode->refresh_rate = DEFAULT_REFRESH_RATE;
3460 if (m.dmFields & DM_DISPLAYFREQUENCY)
3461 mode->refresh_rate = m.dmDisplayFrequency;
3462 mode->format_id = pixelformat_for_depth(m.dmBitsPerPel);
3463
3464 /* Lie about the format. X11 can't change the color depth, and some apps
3465 * are pretty angry if they SetDisplayMode from 24 to 16 bpp and find out
3466 * that GetDisplayMode still returns 24 bpp. This should probably be
3467 * handled in winex11 instead. */
3468 if (adapter->screen_format && adapter->screen_format != mode->format_id)
3469 {
3470 WARN("Overriding format %s with stored format %s.\n",
3471 debug_d3dformat(mode->format_id),
3472 debug_d3dformat(adapter->screen_format));
3473 mode->format_id = adapter->screen_format;
3474 }
3475
3476 if (!(m.dmFields & DM_DISPLAYFLAGS))
3477 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_UNKNOWN;
3478#ifndef VBOX_WINE_WITHOUT_LIBWINE
3479 else if (m.u2.dmDisplayFlags & DM_INTERLACED)
3480#else
3481 else if (m.dmDisplayFlags & DM_INTERLACED)
3482#endif
3483 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_INTERLACED;
3484 else
3485 mode->scanline_ordering = WINED3D_SCANLINE_ORDERING_PROGRESSIVE;
3486
3487 if (rotation)
3488 {
3489#ifndef VBOX_WINE_WITHOUT_LIBWINE
3490 switch (m.u1.s2.dmDisplayOrientation)
3491#else
3492 switch (m.dmDisplayOrientation)
3493#endif
3494 {
3495 case DMDO_DEFAULT:
3496 *rotation = WINED3D_DISPLAY_ROTATION_0;
3497 break;
3498 case DMDO_90:
3499 *rotation = WINED3D_DISPLAY_ROTATION_90;
3500 break;
3501 case DMDO_180:
3502 *rotation = WINED3D_DISPLAY_ROTATION_180;
3503 break;
3504 case DMDO_270:
3505 *rotation = WINED3D_DISPLAY_ROTATION_270;
3506 break;
3507 default:
3508#ifndef VBOX_WINE_WITHOUT_LIBWINE
3509 FIXME("Unhandled display rotation %#x.\n", m.u1.s2.dmDisplayOrientation);
3510#else
3511 FIXME("Unhandled display rotation %#x.\n", m.dmDisplayOrientation);
3512#endif
3513 *rotation = WINED3D_DISPLAY_ROTATION_UNSPECIFIED;
3514 break;
3515 }
3516 }
3517
3518 TRACE("Returning %ux%u@%u %s %#x.\n", mode->width, mode->height,
3519 mode->refresh_rate, debug_d3dformat(mode->format_id),
3520 mode->scanline_ordering);
3521 return WINED3D_OK;
3522}
3523
3524HRESULT CDECL wined3d_set_adapter_display_mode(struct wined3d *wined3d,
3525 UINT adapter_idx, const struct wined3d_display_mode *mode)
3526{
3527 struct wined3d_display_mode current_mode;
3528 const struct wined3d_format *format;
3529 struct wined3d_adapter *adapter;
3530 DEVMODEW devmode;
3531 RECT clip_rc;
3532 HRESULT hr;
3533 LONG ret;
3534
3535 TRACE("wined3d %p, adapter_idx %u, mode %p (%ux%u@%u %s %#x).\n", wined3d, adapter_idx, mode,
3536 mode->width, mode->height, mode->refresh_rate, debug_d3dformat(mode->format_id),
3537 mode->scanline_ordering);
3538
3539 if (adapter_idx >= wined3d->adapter_count)
3540 return WINED3DERR_INVALIDCALL;
3541
3542 adapter = &wined3d->adapters[adapter_idx];
3543 format = wined3d_get_format(&adapter->gl_info, mode->format_id);
3544
3545 memset(&devmode, 0, sizeof(devmode));
3546 devmode.dmSize = sizeof(devmode);
3547 devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
3548 devmode.dmBitsPerPel = format->byte_count * CHAR_BIT;
3549 devmode.dmPelsWidth = mode->width;
3550 devmode.dmPelsHeight = mode->height;
3551
3552 devmode.dmDisplayFrequency = mode->refresh_rate;
3553 if (mode->refresh_rate)
3554 devmode.dmFields |= DM_DISPLAYFREQUENCY;
3555
3556 if (mode->scanline_ordering != WINED3D_SCANLINE_ORDERING_UNKNOWN)
3557 {
3558 devmode.dmFields |= DM_DISPLAYFLAGS;
3559 if (mode->scanline_ordering == WINED3D_SCANLINE_ORDERING_INTERLACED)
3560#ifndef VBOX_WINE_WITHOUT_LIBWINE
3561 devmode.u2.dmDisplayFlags |= DM_INTERLACED;
3562#else
3563 devmode.dmDisplayFlags |= DM_INTERLACED;
3564#endif
3565 }
3566
3567 /* Only change the mode if necessary. */
3568 if (FAILED(hr = wined3d_get_adapter_display_mode(wined3d, adapter_idx, &current_mode, NULL)))
3569 {
3570 ERR("Failed to get current display mode, hr %#x.\n", hr);
3571 }
3572 else if (current_mode.width == mode->width
3573 && current_mode.height == mode->height
3574 && current_mode.format_id == mode->format_id
3575 && (current_mode.refresh_rate == mode->refresh_rate
3576 || !mode->refresh_rate)
3577 && (current_mode.scanline_ordering == mode->scanline_ordering
3578 || mode->scanline_ordering == WINED3D_SCANLINE_ORDERING_UNKNOWN))
3579 {
3580 TRACE("Skipping redundant mode setting call.\n");
3581 return WINED3D_OK;
3582 }
3583
3584 ret = ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
3585 if (ret != DISP_CHANGE_SUCCESSFUL)
3586 {
3587 if (devmode.dmDisplayFrequency)
3588 {
3589 WARN("ChangeDisplaySettingsExW failed, trying without the refresh rate.\n");
3590 devmode.dmFields &= ~DM_DISPLAYFREQUENCY;
3591 devmode.dmDisplayFrequency = 0;
3592 ret = ChangeDisplaySettingsExW(adapter->DeviceName, &devmode, NULL, CDS_FULLSCREEN, NULL);
3593 }
3594 if (ret != DISP_CHANGE_SUCCESSFUL)
3595 return WINED3DERR_NOTAVAILABLE;
3596 }
3597
3598 /* Store the new values. */
3599 adapter->screen_format = mode->format_id;
3600
3601 /* And finally clip mouse to our screen. */
3602 SetRect(&clip_rc, 0, 0, mode->width, mode->height);
3603 ClipCursor(&clip_rc);
3604
3605 return WINED3D_OK;
3606}
3607
3608/* NOTE: due to structure differences between dx8 and dx9 D3DADAPTER_IDENTIFIER,
3609 and fields being inserted in the middle, a new structure is used in place */
3610HRESULT CDECL wined3d_get_adapter_identifier(const struct wined3d *wined3d,
3611 UINT adapter_idx, DWORD flags, struct wined3d_adapter_identifier *identifier)
3612{
3613#ifndef VBOX_WITH_WDDM
3614 const struct wined3d_adapter *adapter;
3615 size_t len;
3616
3617 TRACE("wined3d %p, adapter_idx %u, flags %#x, identifier %p.\n",
3618 wined3d, adapter_idx, flags, identifier);
3619
3620 if (adapter_idx >= wined3d->adapter_count)
3621 return WINED3DERR_INVALIDCALL;
3622
3623 adapter = &wined3d->adapters[adapter_idx];
3624
3625 if (identifier->driver_size)
3626 {
3627 const char *name = adapter->driver_info.name;
3628 len = min(strlen(name), identifier->driver_size - 1);
3629 memcpy(identifier->driver, name, len);
3630 identifier->driver[len] = '\0';
3631 }
3632
3633 if (identifier->description_size)
3634 {
3635 const char *description = adapter->driver_info.description;
3636 len = min(strlen(description), identifier->description_size - 1);
3637 memcpy(identifier->description, description, len);
3638 identifier->description[len] = '\0';
3639 }
3640
3641 /* Note that d3d8 doesn't supply a device name. */
3642 if (identifier->device_name_size)
3643 {
3644 if (!WideCharToMultiByte(CP_ACP, 0, adapter->DeviceName, -1, identifier->device_name,
3645 identifier->device_name_size, NULL, NULL))
3646 {
3647 ERR("Failed to convert device name, last error %#x.\n", GetLastError());
3648 return WINED3DERR_INVALIDCALL;
3649 }
3650 }
3651
3652 identifier->driver_version.u.HighPart = adapter->driver_info.version_high;
3653 identifier->driver_version.u.LowPart = adapter->driver_info.version_low;
3654 identifier->vendor_id = adapter->driver_info.vendor;
3655 identifier->device_id = adapter->driver_info.device;
3656 identifier->subsystem_id = 0;
3657 identifier->revision = 0;
3658 memcpy(&identifier->device_identifier, &IID_D3DDEVICE_D3DUID, sizeof(identifier->device_identifier));
3659 identifier->whql_level = (flags & WINED3DENUM_NO_WHQL_LEVEL) ? 0 : 1;
3660 memcpy(&identifier->adapter_luid, &adapter->luid, sizeof(identifier->adapter_luid));
3661 identifier->video_memory = adapter->TextureRam;
3662
3663 return WINED3D_OK;
3664#else
3665 ERR("not supported!");
3666 return E_FAIL;
3667#endif
3668}
3669
3670HRESULT CDECL wined3d_get_adapter_raster_status(const struct wined3d *wined3d, UINT adapter_idx,
3671 struct wined3d_raster_status *raster_status)
3672{
3673 LONGLONG freq_per_frame, freq_per_line;
3674 LARGE_INTEGER counter, freq_per_sec;
3675 struct wined3d_display_mode mode;
3676 static UINT once;
3677
3678 if (!once++)
3679 FIXME("wined3d %p, adapter_idx %u, raster_status %p semi-stub!\n",
3680 wined3d, adapter_idx, raster_status);
3681 else
3682 WARN("wined3d %p, adapter_idx %u, raster_status %p semi-stub!\n",
3683 wined3d, adapter_idx, raster_status);
3684
3685 /* Obtaining the raster status is a widely implemented but optional
3686 * feature. When this method returns OK StarCraft 2 expects the
3687 * raster_status->InVBlank value to actually change over time.
3688 * And Endless Alice Crysis doesn't care even if this method fails.
3689 * Thus this method returns OK and fakes raster_status by
3690 * QueryPerformanceCounter. */
3691
3692 if (!QueryPerformanceCounter(&counter) || !QueryPerformanceFrequency(&freq_per_sec))
3693 return WINED3DERR_INVALIDCALL;
3694 if (FAILED(wined3d_get_adapter_display_mode(wined3d, adapter_idx, &mode, NULL)))
3695 return WINED3DERR_INVALIDCALL;
3696 if (mode.refresh_rate == DEFAULT_REFRESH_RATE)
3697 mode.refresh_rate = 60;
3698
3699 freq_per_frame = freq_per_sec.QuadPart / mode.refresh_rate;
3700 /* Assume 20 scan lines in the vertical blank. */
3701 freq_per_line = freq_per_frame / (mode.height + 20);
3702 raster_status->scan_line = (counter.QuadPart % freq_per_frame) / freq_per_line;
3703 if (raster_status->scan_line < mode.height)
3704 raster_status->in_vblank = FALSE;
3705 else
3706 {
3707 raster_status->scan_line = 0;
3708 raster_status->in_vblank = TRUE;
3709 }
3710
3711 TRACE("Returning fake value, in_vblank %u, scan_line %u.\n",
3712 raster_status->in_vblank, raster_status->scan_line);
3713
3714 return WINED3D_OK;
3715}
3716
3717static BOOL wined3d_check_pixel_format_color(const struct wined3d_gl_info *gl_info,
3718 const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
3719{
3720 BYTE redSize, greenSize, blueSize, alphaSize, colorBits;
3721
3722 /* Float formats need FBOs. If FBOs are used this function isn't called */
3723 if (format->flags & WINED3DFMT_FLAG_FLOAT) return FALSE;
3724
3725 if(cfg->iPixelType == WGL_TYPE_RGBA_ARB) { /* Integer RGBA formats */
3726 if (!getColorBits(format, &redSize, &greenSize, &blueSize, &alphaSize, &colorBits))
3727 {
3728 ERR("Unable to check compatibility for format %s.\n", debug_d3dformat(format->id));
3729 return FALSE;
3730 }
3731
3732 if(cfg->redSize < redSize)
3733 return FALSE;
3734
3735 if(cfg->greenSize < greenSize)
3736 return FALSE;
3737
3738 if(cfg->blueSize < blueSize)
3739 return FALSE;
3740
3741 if(cfg->alphaSize < alphaSize)
3742 return FALSE;
3743
3744 return TRUE;
3745 }
3746
3747 /* Probably a RGBA_float or color index mode */
3748 return FALSE;
3749}
3750
3751static BOOL wined3d_check_pixel_format_depth(const struct wined3d_gl_info *gl_info,
3752 const struct wined3d_pixel_format *cfg, const struct wined3d_format *format)
3753{
3754 BYTE depthSize, stencilSize;
3755 BOOL lockable = FALSE;
3756
3757 if (!getDepthStencilBits(format, &depthSize, &stencilSize))
3758 {
3759 ERR("Unable to check compatibility for format %s.\n", debug_d3dformat(format->id));
3760 return FALSE;
3761 }
3762
3763 /* Float formats need FBOs. If FBOs are used this function isn't called */
3764 if (format->flags & WINED3DFMT_FLAG_FLOAT) return FALSE;
3765
3766 if ((format->id == WINED3DFMT_D16_LOCKABLE) || (format->id == WINED3DFMT_D32_FLOAT))
3767 lockable = TRUE;
3768
3769 /* On some modern cards like the Geforce8/9 GLX doesn't offer some dephthstencil formats which D3D9 reports.
3770 * We can safely report 'compatible' formats (e.g. D24 can be used for D16) as long as we aren't dealing with
3771 * a lockable format. This also helps D3D <= 7 as they expect D16 which isn't offered without this on Geforce8 cards. */
3772 if(!(cfg->depthSize == depthSize || (!lockable && cfg->depthSize > depthSize)))
3773 return FALSE;
3774
3775 /* Some cards like Intel i915 ones only offer D24S8 but lots of games also need a format without stencil, so
3776 * allow more stencil bits than requested. */
3777 if(cfg->stencilSize < stencilSize)
3778 return FALSE;
3779
3780 return TRUE;
3781}
3782
3783HRESULT CDECL wined3d_check_depth_stencil_match(const struct wined3d *wined3d,
3784 UINT adapter_idx, enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id,
3785 enum wined3d_format_id render_target_format_id, enum wined3d_format_id depth_stencil_format_id)
3786{
3787 const struct wined3d_format *rt_format;
3788 const struct wined3d_format *ds_format;
3789 const struct wined3d_adapter *adapter;
3790
3791 TRACE("wined3d %p, adapter_idx %u, device_type %s,\n"
3792 "adapter_format %s, render_target_format %s, depth_stencil_format %s.\n",
3793 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
3794 debug_d3dformat(render_target_format_id), debug_d3dformat(depth_stencil_format_id));
3795
3796 if (adapter_idx >= wined3d->adapter_count)
3797 return WINED3DERR_INVALIDCALL;
3798
3799 adapter = &wined3d->adapters[adapter_idx];
3800 rt_format = wined3d_get_format(&adapter->gl_info, render_target_format_id);
3801 ds_format = wined3d_get_format(&adapter->gl_info, depth_stencil_format_id);
3802 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3803 {
3804 if ((rt_format->flags & WINED3DFMT_FLAG_RENDERTARGET)
3805 && (ds_format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)))
3806 {
3807 TRACE("Formats match.\n");
3808 return WINED3D_OK;
3809 }
3810 }
3811 else
3812 {
3813 const struct wined3d_pixel_format *cfgs;
3814 unsigned int cfg_count;
3815 unsigned int i;
3816
3817 cfgs = adapter->cfgs;
3818 cfg_count = adapter->cfg_count;
3819 for (i = 0; i < cfg_count; ++i)
3820 {
3821 if (wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], rt_format)
3822 && wined3d_check_pixel_format_depth(&adapter->gl_info, &cfgs[i], ds_format))
3823 {
3824 TRACE("Formats match.\n");
3825 return WINED3D_OK;
3826 }
3827 }
3828 }
3829
3830 TRACE("Unsupported format pair: %s and %s.\n",
3831 debug_d3dformat(render_target_format_id),
3832 debug_d3dformat(depth_stencil_format_id));
3833
3834 return WINED3DERR_NOTAVAILABLE;
3835}
3836
3837HRESULT CDECL wined3d_check_device_multisample_type(const struct wined3d *wined3d, UINT adapter_idx,
3838 enum wined3d_device_type device_type, enum wined3d_format_id surface_format_id, BOOL windowed,
3839 enum wined3d_multisample_type multisample_type, DWORD *quality_levels)
3840{
3841 const struct wined3d_gl_info *gl_info;
3842
3843 TRACE("wined3d %p, adapter_idx %u, device_type %s, surface_format %s,\n"
3844 "windowed %#x, multisample_type %#x, quality_levels %p.\n",
3845 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(surface_format_id),
3846 windowed, multisample_type, quality_levels);
3847
3848 if (adapter_idx >= wined3d->adapter_count)
3849 return WINED3DERR_INVALIDCALL;
3850
3851 gl_info = &wined3d->adapters[adapter_idx].gl_info;
3852
3853 if (multisample_type > gl_info->limits.samples)
3854 {
3855 TRACE("Returning not supported.\n");
3856 if (quality_levels)
3857 *quality_levels = 0;
3858
3859 return WINED3DERR_NOTAVAILABLE;
3860 }
3861
3862 if (quality_levels)
3863 {
3864 if (multisample_type == WINED3D_MULTISAMPLE_NON_MASKABLE)
3865 /* FIXME: This is probably wrong. */
3866 *quality_levels = gl_info->limits.samples;
3867 else
3868 *quality_levels = 1;
3869 }
3870
3871 return WINED3D_OK;
3872}
3873
3874/* Check if the given DisplayFormat + DepthStencilFormat combination is valid for the Adapter */
3875static BOOL CheckDepthStencilCapability(const struct wined3d_adapter *adapter,
3876 const struct wined3d_format *display_format, const struct wined3d_format *ds_format)
3877{
3878 /* Only allow depth/stencil formats */
3879 if (!(ds_format->depth_size || ds_format->stencil_size)) return FALSE;
3880
3881 /* Blacklist formats not supported on Windows */
3882 switch (ds_format->id)
3883 {
3884 case WINED3DFMT_S1_UINT_D15_UNORM: /* Breaks the shadowvol2 dx7 sdk sample */
3885 case WINED3DFMT_S4X4_UINT_D24_UNORM:
3886 TRACE("[FAILED] - not supported on windows.\n");
3887 return FALSE;
3888
3889 default:
3890 break;
3891 }
3892
3893 if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3894 {
3895 /* With FBOs WGL limitations do not apply, but the format needs to be FBO attachable */
3896 if (ds_format->flags & (WINED3DFMT_FLAG_DEPTH | WINED3DFMT_FLAG_STENCIL)) return TRUE;
3897 }
3898 else
3899 {
3900 unsigned int i;
3901
3902 /* Walk through all WGL pixel formats to find a match */
3903 for (i = 0; i < adapter->cfg_count; ++i)
3904 {
3905 const struct wined3d_pixel_format *cfg = &adapter->cfgs[i];
3906 if (wined3d_check_pixel_format_color(&adapter->gl_info, cfg, display_format)
3907 && wined3d_check_pixel_format_depth(&adapter->gl_info, cfg, ds_format))
3908 return TRUE;
3909 }
3910 }
3911
3912 return FALSE;
3913}
3914
3915/* Check the render target capabilities of a format */
3916static BOOL CheckRenderTargetCapability(const struct wined3d_adapter *adapter,
3917 const struct wined3d_format *adapter_format, const struct wined3d_format *check_format)
3918{
3919 /* Filter out non-RT formats */
3920 if (!(check_format->flags & WINED3DFMT_FLAG_RENDERTARGET)) return FALSE;
3921 if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
3922 {
3923 BYTE AdapterRed, AdapterGreen, AdapterBlue, AdapterAlpha, AdapterTotalSize;
3924 BYTE CheckRed, CheckGreen, CheckBlue, CheckAlpha, CheckTotalSize;
3925 const struct wined3d_pixel_format *cfgs = adapter->cfgs;
3926 unsigned int i;
3927
3928 getColorBits(adapter_format, &AdapterRed, &AdapterGreen, &AdapterBlue, &AdapterAlpha, &AdapterTotalSize);
3929 getColorBits(check_format, &CheckRed, &CheckGreen, &CheckBlue, &CheckAlpha, &CheckTotalSize);
3930
3931 /* In backbuffer mode the front and backbuffer share the same WGL pixelformat.
3932 * The format must match in RGB, alpha is allowed to be different. (Only the backbuffer can have alpha) */
3933 if (!((AdapterRed == CheckRed) && (AdapterGreen == CheckGreen) && (AdapterBlue == CheckBlue)))
3934 {
3935 TRACE("[FAILED]\n");
3936 return FALSE;
3937 }
3938
3939 /* Check if there is a WGL pixel format matching the requirements, the format should also be window
3940 * drawable (not offscreen; e.g. Nvidia offers R5G6B5 for pbuffers even when X is running at 24bit) */
3941 for (i = 0; i < adapter->cfg_count; ++i)
3942 {
3943 if (cfgs[i].windowDrawable
3944 && wined3d_check_pixel_format_color(&adapter->gl_info, &cfgs[i], check_format))
3945 {
3946 TRACE("Pixel format %d is compatible with format %s.\n",
3947 cfgs[i].iPixelFormat, debug_d3dformat(check_format->id));
3948 return TRUE;
3949 }
3950 }
3951 }
3952 else if(wined3d_settings.offscreen_rendering_mode == ORM_FBO)
3953 {
3954 /* For now return TRUE for FBOs until we have some proper checks.
3955 * Note that this function will only be called when the format is around for texturing. */
3956 return TRUE;
3957 }
3958 return FALSE;
3959}
3960
3961static BOOL CheckSurfaceCapability(const struct wined3d_adapter *adapter,
3962 const struct wined3d_format *adapter_format,
3963 const struct wined3d_format *check_format, BOOL no3d)
3964{
3965 if (no3d)
3966 {
3967 switch (check_format->id)
3968 {
3969 case WINED3DFMT_B8G8R8_UNORM:
3970 TRACE("[FAILED] - Not enumerated on Windows.\n");
3971 return FALSE;
3972 case WINED3DFMT_B8G8R8A8_UNORM:
3973 case WINED3DFMT_B8G8R8X8_UNORM:
3974 case WINED3DFMT_B5G6R5_UNORM:
3975 case WINED3DFMT_B5G5R5X1_UNORM:
3976 case WINED3DFMT_B5G5R5A1_UNORM:
3977 case WINED3DFMT_B4G4R4A4_UNORM:
3978 case WINED3DFMT_B2G3R3_UNORM:
3979 case WINED3DFMT_A8_UNORM:
3980 case WINED3DFMT_B2G3R3A8_UNORM:
3981 case WINED3DFMT_B4G4R4X4_UNORM:
3982 case WINED3DFMT_R10G10B10A2_UNORM:
3983 case WINED3DFMT_R8G8B8A8_UNORM:
3984 case WINED3DFMT_R8G8B8X8_UNORM:
3985 case WINED3DFMT_R16G16_UNORM:
3986 case WINED3DFMT_B10G10R10A2_UNORM:
3987 case WINED3DFMT_R16G16B16A16_UNORM:
3988 case WINED3DFMT_P8_UINT:
3989 TRACE("[OK]\n");
3990 return TRUE;
3991 default:
3992 TRACE("[FAILED] - Not available on GDI surfaces.\n");
3993 return FALSE;
3994 }
3995 }
3996
3997 /* All formats that are supported for textures are supported for surfaces
3998 * as well. */
3999 if (check_format->flags & WINED3DFMT_FLAG_TEXTURE)
4000 return TRUE;
4001
4002 /* All depth stencil formats are supported on surfaces */
4003 if (CheckDepthStencilCapability(adapter, adapter_format, check_format)) return TRUE;
4004
4005 /* If opengl can't process the format natively, the blitter may be able to convert it */
4006 if (adapter->blitter->blit_supported(&adapter->gl_info, WINED3D_BLIT_OP_COLOR_BLIT,
4007 NULL, WINED3D_POOL_DEFAULT, 0, check_format,
4008 NULL, WINED3D_POOL_DEFAULT, 0, adapter_format))
4009 {
4010 TRACE("[OK]\n");
4011 return TRUE;
4012 }
4013
4014 /* Reject other formats */
4015 TRACE("[FAILED]\n");
4016 return FALSE;
4017}
4018
4019/* OpenGL supports mipmapping on all formats. Wrapping is unsupported, but we
4020 * have to report mipmapping so we cannot reject WRAPANDMIP. Tests show that
4021 * Windows reports WRAPANDMIP on unfilterable surfaces as well, apparently to
4022 * show that wrapping is supported. The lack of filtering will sort out the
4023 * mipmapping capability anyway.
4024 *
4025 * For now lets report this on all formats, but in the future we may want to
4026 * restrict it to some should applications need that. */
4027HRESULT CDECL wined3d_check_device_format(const struct wined3d *wined3d, UINT adapter_idx,
4028 enum wined3d_device_type device_type, enum wined3d_format_id adapter_format_id, DWORD usage,
4029 enum wined3d_resource_type resource_type, enum wined3d_format_id check_format_id)
4030{
4031 const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
4032 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4033 const struct wined3d_format *adapter_format = wined3d_get_format(gl_info, adapter_format_id);
4034 const struct wined3d_format *format = wined3d_get_format(gl_info, check_format_id);
4035 DWORD format_flags = 0;
4036 DWORD allowed_usage;
4037
4038 TRACE("wined3d %p, adapter_idx %u, device_type %s, adapter_format %s, usage %s, %s,\n"
4039 "resource_type %s, check_format %s.\n",
4040 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(adapter_format_id),
4041 debug_d3dusage(usage), debug_d3dusagequery(usage), debug_d3dresourcetype(resource_type),
4042 debug_d3dformat(check_format_id));
4043
4044 if (adapter_idx >= wined3d->adapter_count)
4045 return WINED3DERR_INVALIDCALL;
4046
4047 switch (resource_type)
4048 {
4049 case WINED3D_RTYPE_CUBE_TEXTURE:
4050 if (!gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4051 {
4052 TRACE("[FAILED] - No cube texture support.\n");
4053 return WINED3DERR_NOTAVAILABLE;
4054 }
4055
4056 format_flags |= WINED3DFMT_FLAG_TEXTURE;
4057 allowed_usage = WINED3DUSAGE_AUTOGENMIPMAP
4058 | WINED3DUSAGE_DYNAMIC
4059 | WINED3DUSAGE_RENDERTARGET
4060 | WINED3DUSAGE_SOFTWAREPROCESSING
4061 | WINED3DUSAGE_QUERY_FILTER
4062 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
4063 | WINED3DUSAGE_QUERY_SRGBREAD
4064 | WINED3DUSAGE_QUERY_SRGBWRITE
4065 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
4066 | WINED3DUSAGE_QUERY_WRAPANDMIP;
4067 break;
4068
4069 case WINED3D_RTYPE_SURFACE:
4070 if (!CheckSurfaceCapability(adapter, adapter_format, format, wined3d->flags & WINED3D_NO3D))
4071 {
4072 TRACE("[FAILED] - Not supported for plain surfaces.\n");
4073 return WINED3DERR_NOTAVAILABLE;
4074 }
4075
4076 allowed_usage = WINED3DUSAGE_DEPTHSTENCIL
4077 | WINED3DUSAGE_RENDERTARGET
4078 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING;
4079 break;
4080
4081 case WINED3D_RTYPE_TEXTURE:
4082 if ((usage & WINED3DUSAGE_DEPTHSTENCIL) && (format->flags & WINED3DFMT_FLAG_SHADOW)
4083 && !gl_info->supported[ARB_SHADOW])
4084 {
4085 TRACE("[FAILED] - No shadow sampler support.\n");
4086 return WINED3DERR_NOTAVAILABLE;
4087 }
4088
4089 format_flags |= WINED3DFMT_FLAG_TEXTURE;
4090 allowed_usage = WINED3DUSAGE_AUTOGENMIPMAP
4091 | WINED3DUSAGE_DEPTHSTENCIL
4092 | WINED3DUSAGE_DYNAMIC
4093 | WINED3DUSAGE_RENDERTARGET
4094 | WINED3DUSAGE_SOFTWAREPROCESSING
4095 | WINED3DUSAGE_QUERY_FILTER
4096 | WINED3DUSAGE_QUERY_LEGACYBUMPMAP
4097 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
4098 | WINED3DUSAGE_QUERY_SRGBREAD
4099 | WINED3DUSAGE_QUERY_SRGBWRITE
4100 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
4101 | WINED3DUSAGE_QUERY_WRAPANDMIP;
4102 break;
4103
4104 case WINED3D_RTYPE_VOLUME_TEXTURE:
4105 case WINED3D_RTYPE_VOLUME:
4106 /* Volume is to VolumeTexture what Surface is to Texture, but its
4107 * usage caps are not documented. Most driver seem to offer
4108 * (nearly) the same on Volume and VolumeTexture, so do that too. */
4109 if (!gl_info->supported[EXT_TEXTURE3D])
4110 {
4111 TRACE("[FAILED] - No volume texture support.\n");
4112 return WINED3DERR_NOTAVAILABLE;
4113 }
4114
4115 /* Filter formats that need conversion; For one part, this
4116 * conversion is unimplemented, and volume textures are huge, so
4117 * it would be a big performance hit. Unless we hit an application
4118 * needing one of those formats, don't advertize them to avoid
4119 * leading applications into temptation. The windows drivers don't
4120 * support most of those formats on volumes anyway. */
4121 if (format->convert)
4122 {
4123 TRACE("[FAILED] - No converted formats on volumes.\n");
4124 return WINED3DERR_NOTAVAILABLE;
4125 }
4126
4127 /* The GL_EXT_texture_compression_s3tc spec requires that loading
4128 * an s3tc compressed texture results in an error. While the D3D
4129 * refrast does support s3tc volumes, at least the nvidia Windows
4130 * driver does not, so we're free not to support this format. */
4131 switch (check_format_id)
4132 {
4133 case WINED3DFMT_DXT1:
4134 case WINED3DFMT_DXT2:
4135 case WINED3DFMT_DXT3:
4136 case WINED3DFMT_DXT4:
4137 case WINED3DFMT_DXT5:
4138 TRACE("[FAILED] - DXTn does not support 3D textures.\n");
4139 return WINED3DERR_NOTAVAILABLE;
4140
4141 default:
4142 /* Do nothing, continue with checking the format below */
4143 break;
4144 }
4145
4146 format_flags |= WINED3DFMT_FLAG_TEXTURE;
4147 allowed_usage = WINED3DUSAGE_DYNAMIC
4148 | WINED3DUSAGE_SOFTWAREPROCESSING
4149 | WINED3DUSAGE_QUERY_FILTER
4150 | WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING
4151 | WINED3DUSAGE_QUERY_SRGBREAD
4152 | WINED3DUSAGE_QUERY_SRGBWRITE
4153 | WINED3DUSAGE_QUERY_VERTEXTEXTURE
4154 | WINED3DUSAGE_QUERY_WRAPANDMIP;
4155 break;
4156
4157 default:
4158 FIXME("Unhandled resource type %s.\n", debug_d3dresourcetype(resource_type));
4159 return WINED3DERR_NOTAVAILABLE;
4160 }
4161
4162 if ((usage & allowed_usage) != usage)
4163 {
4164 TRACE("Requested usage %#x, but resource type %s only allows %#x.\n",
4165 usage, debug_d3dresourcetype(resource_type), allowed_usage);
4166 return WINED3DERR_NOTAVAILABLE;
4167 }
4168
4169 if (usage & WINED3DUSAGE_QUERY_FILTER)
4170 format_flags |= WINED3DFMT_FLAG_FILTERING;
4171 if (usage & WINED3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING)
4172 format_flags |= WINED3DFMT_FLAG_POSTPIXELSHADER_BLENDING;
4173 if (usage & WINED3DUSAGE_QUERY_SRGBREAD)
4174 format_flags |= WINED3DFMT_FLAG_SRGB_READ;
4175 if (usage & WINED3DUSAGE_QUERY_SRGBWRITE)
4176 format_flags |= WINED3DFMT_FLAG_SRGB_WRITE;
4177 if (usage & WINED3DUSAGE_QUERY_VERTEXTEXTURE)
4178 format_flags |= WINED3DFMT_FLAG_VTF;
4179 if (usage & WINED3DUSAGE_QUERY_LEGACYBUMPMAP)
4180 format_flags |= WINED3DFMT_FLAG_BUMPMAP;
4181
4182 if ((format->flags & format_flags) != format_flags)
4183 {
4184 TRACE("Requested format flags %#x, but format %s only has %#x.\n",
4185 format_flags, debug_d3dformat(check_format_id), format->flags);
4186 return WINED3DERR_NOTAVAILABLE;
4187 }
4188
4189 if ((format_flags & WINED3DFMT_FLAG_TEXTURE) && (wined3d->flags & WINED3D_NO3D))
4190 {
4191 TRACE("Requested texturing support, but wined3d was created with WINED3D_NO3D.\n");
4192 return WINED3DERR_NOTAVAILABLE;
4193 }
4194
4195 if ((usage & WINED3DUSAGE_DEPTHSTENCIL)
4196 && !CheckDepthStencilCapability(adapter, adapter_format, format))
4197 {
4198 TRACE("Requested WINED3DUSAGE_DEPTHSTENCIL, but format %s is not supported for depth / stencil buffers.\n",
4199 debug_d3dformat(check_format_id));
4200 return WINED3DERR_NOTAVAILABLE;
4201 }
4202
4203 if ((usage & WINED3DUSAGE_RENDERTARGET)
4204 && !CheckRenderTargetCapability(adapter, adapter_format, format))
4205 {
4206 TRACE("Requested WINED3DUSAGE_RENDERTARGET, but format %s is not supported for render targets.\n",
4207 debug_d3dformat(check_format_id));
4208 return WINED3DERR_NOTAVAILABLE;
4209 }
4210
4211 if ((usage & WINED3DUSAGE_AUTOGENMIPMAP) && !gl_info->supported[SGIS_GENERATE_MIPMAP])
4212 {
4213 TRACE("No WINED3DUSAGE_AUTOGENMIPMAP support, returning WINED3DOK_NOAUTOGEN.\n");
4214 return WINED3DOK_NOAUTOGEN;
4215 }
4216
4217 return WINED3D_OK;
4218}
4219
4220HRESULT CDECL wined3d_check_device_format_conversion(const struct wined3d *wined3d, UINT adapter_idx,
4221 enum wined3d_device_type device_type, enum wined3d_format_id src_format, enum wined3d_format_id dst_format)
4222{
4223 FIXME("wined3d %p, adapter_idx %u, device_type %s, src_format %s, dst_format %s stub!\n",
4224 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(src_format),
4225 debug_d3dformat(dst_format));
4226
4227 return WINED3D_OK;
4228}
4229
4230HRESULT CDECL wined3d_check_device_type(const struct wined3d *wined3d, UINT adapter_idx,
4231 enum wined3d_device_type device_type, enum wined3d_format_id display_format,
4232 enum wined3d_format_id backbuffer_format, BOOL windowed)
4233{
4234 UINT mode_count;
4235 HRESULT hr;
4236
4237 TRACE("wined3d %p, adapter_idx %u, device_type %s, display_format %s, backbuffer_format %s, windowed %#x.\n",
4238 wined3d, adapter_idx, debug_d3ddevicetype(device_type), debug_d3dformat(display_format),
4239 debug_d3dformat(backbuffer_format), windowed);
4240
4241 if (adapter_idx >= wined3d->adapter_count)
4242 return WINED3DERR_INVALIDCALL;
4243
4244 /* The task of this function is to check whether a certain display / backbuffer format
4245 * combination is available on the given adapter. In fullscreen mode microsoft specified
4246 * that the display format shouldn't provide alpha and that ignoring alpha the backbuffer
4247 * and display format should match exactly.
4248 * In windowed mode format conversion can occur and this depends on the driver. When format
4249 * conversion is done, this function should nevertheless fail and applications need to use
4250 * CheckDeviceFormatConversion.
4251 * At the moment we assume that fullscreen and windowed have the same capabilities. */
4252
4253 /* There are only 4 display formats. */
4254 if (!(display_format == WINED3DFMT_B5G6R5_UNORM
4255 || display_format == WINED3DFMT_B5G5R5X1_UNORM
4256 || display_format == WINED3DFMT_B8G8R8X8_UNORM
4257 || display_format == WINED3DFMT_B10G10R10A2_UNORM))
4258 {
4259 TRACE("Format %s is not supported as display format.\n", debug_d3dformat(display_format));
4260 return WINED3DERR_NOTAVAILABLE;
4261 }
4262
4263 /* If the requested display format is not available, don't continue. */
4264 mode_count = wined3d_get_adapter_mode_count(wined3d, adapter_idx,
4265 display_format, WINED3D_SCANLINE_ORDERING_UNKNOWN);
4266 if (!mode_count)
4267 {
4268 TRACE("No available modes for display format %s.\n", debug_d3dformat(display_format));
4269 return WINED3DERR_NOTAVAILABLE;
4270 }
4271
4272 /* Windowed mode allows you to specify WINED3DFMT_UNKNOWN for the backbuffer format,
4273 * it means 'reuse' the display format for the backbuffer. */
4274 if (!windowed && backbuffer_format == WINED3DFMT_UNKNOWN)
4275 {
4276 TRACE("backbuffer_format WINED3FMT_UNKNOWN only available in windowed mode.\n");
4277 return WINED3DERR_NOTAVAILABLE;
4278 }
4279
4280 /* In FULLSCREEN mode WINED3DFMT_B5G6R5_UNORM can only be mixed with
4281 * backbuffer format WINED3DFMT_B5G6R5_UNORM. */
4282 if (display_format == WINED3DFMT_B5G6R5_UNORM && backbuffer_format != WINED3DFMT_B5G6R5_UNORM)
4283 {
4284 TRACE("Unsupported display/backbuffer format combination %s / %s.\n",
4285 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4286 return WINED3DERR_NOTAVAILABLE;
4287 }
4288
4289 /* In FULLSCREEN mode WINED3DFMT_B5G5R5X1_UNORM can only be mixed with
4290 * backbuffer formats WINED3DFMT_B5G5R5X1_UNORM and
4291 * WINED3DFMT_B5G5R5A1_UNORM. */
4292 if (display_format == WINED3DFMT_B5G5R5X1_UNORM
4293 && !(backbuffer_format == WINED3DFMT_B5G5R5X1_UNORM || backbuffer_format == WINED3DFMT_B5G5R5A1_UNORM))
4294 {
4295 TRACE("Unsupported display/backbuffer format combination %s / %s.\n",
4296 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4297 return WINED3DERR_NOTAVAILABLE;
4298 }
4299
4300 /* In FULLSCREEN mode WINED3DFMT_B8G8R8X8_UNORM can only be mixed with
4301 * backbuffer formats WINED3DFMT_B8G8R8X8_UNORM and
4302 * WINED3DFMT_B8G8R8A8_UNORM. */
4303 if (display_format == WINED3DFMT_B8G8R8X8_UNORM
4304 && !(backbuffer_format == WINED3DFMT_B8G8R8X8_UNORM || backbuffer_format == WINED3DFMT_B8G8R8A8_UNORM))
4305 {
4306 TRACE("Unsupported display/backbuffer format combination %s / %s.\n",
4307 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4308 return WINED3DERR_NOTAVAILABLE;
4309 }
4310
4311 /* WINED3DFMT_B10G10R10A2_UNORM is only allowed in fullscreen mode and it
4312 * can only be mixed with backbuffer format WINED3DFMT_B10G10R10A2_UNORM. */
4313 if (display_format == WINED3DFMT_B10G10R10A2_UNORM
4314 && (backbuffer_format != WINED3DFMT_B10G10R10A2_UNORM || windowed))
4315 {
4316 TRACE("Unsupported display/backbuffer format combination %s / %s.\n",
4317 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4318 return WINED3DERR_NOTAVAILABLE;
4319 }
4320
4321 /* Use CheckDeviceFormat to see if the backbuffer_format is usable with the given display_format */
4322 hr = wined3d_check_device_format(wined3d, adapter_idx, device_type, display_format,
4323 WINED3DUSAGE_RENDERTARGET, WINED3D_RTYPE_SURFACE, backbuffer_format);
4324 if (FAILED(hr))
4325 TRACE("Unsupported display/backbuffer format combination %s / %s.\n",
4326 debug_d3dformat(display_format), debug_d3dformat(backbuffer_format));
4327
4328 return hr;
4329}
4330
4331HRESULT CDECL wined3d_get_device_caps(const struct wined3d *wined3d, UINT adapter_idx,
4332 enum wined3d_device_type device_type, WINED3DCAPS *caps)
4333{
4334 const struct wined3d_adapter *adapter = &wined3d->adapters[adapter_idx];
4335 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
4336 struct shader_caps shader_caps;
4337 struct fragment_caps fragment_caps;
4338 struct wined3d_vertex_caps vertex_caps;
4339 DWORD ckey_caps, blit_caps, fx_caps, pal_caps;
4340
4341 TRACE("wined3d %p, adapter_idx %u, device_type %s, caps %p.\n",
4342 wined3d, adapter_idx, debug_d3ddevicetype(device_type), caps);
4343
4344 if (adapter_idx >= wined3d->adapter_count)
4345 return WINED3DERR_INVALIDCALL;
4346
4347 caps->DeviceType = (device_type == WINED3D_DEVICE_TYPE_HAL) ? WINED3D_DEVICE_TYPE_HAL : WINED3D_DEVICE_TYPE_REF;
4348 caps->AdapterOrdinal = adapter_idx;
4349
4350 caps->Caps = 0;
4351 caps->Caps2 = WINED3DCAPS2_CANRENDERWINDOWED |
4352 WINED3DCAPS2_FULLSCREENGAMMA |
4353 WINED3DCAPS2_DYNAMICTEXTURES;
4354 if (gl_info->supported[SGIS_GENERATE_MIPMAP])
4355 caps->Caps2 |= WINED3DCAPS2_CANAUTOGENMIPMAP;
4356
4357 caps->Caps3 = WINED3DCAPS3_ALPHA_FULLSCREEN_FLIP_OR_DISCARD |
4358 WINED3DCAPS3_COPY_TO_VIDMEM |
4359 WINED3DCAPS3_COPY_TO_SYSTEMMEM;
4360
4361 caps->PresentationIntervals = WINED3DPRESENT_INTERVAL_IMMEDIATE |
4362 WINED3DPRESENT_INTERVAL_ONE;
4363
4364 caps->CursorCaps = WINED3DCURSORCAPS_COLOR |
4365 WINED3DCURSORCAPS_LOWRES;
4366
4367 caps->DevCaps = WINED3DDEVCAPS_FLOATTLVERTEX |
4368 WINED3DDEVCAPS_EXECUTESYSTEMMEMORY |
4369 WINED3DDEVCAPS_TLVERTEXSYSTEMMEMORY|
4370 WINED3DDEVCAPS_TLVERTEXVIDEOMEMORY |
4371 WINED3DDEVCAPS_DRAWPRIMTLVERTEX |
4372 WINED3DDEVCAPS_HWTRANSFORMANDLIGHT |
4373 WINED3DDEVCAPS_EXECUTEVIDEOMEMORY |
4374 WINED3DDEVCAPS_PUREDEVICE |
4375 WINED3DDEVCAPS_HWRASTERIZATION |
4376 WINED3DDEVCAPS_TEXTUREVIDEOMEMORY |
4377 WINED3DDEVCAPS_TEXTURESYSTEMMEMORY |
4378 WINED3DDEVCAPS_CANRENDERAFTERFLIP |
4379 WINED3DDEVCAPS_DRAWPRIMITIVES2 |
4380 WINED3DDEVCAPS_DRAWPRIMITIVES2EX;
4381
4382 caps->PrimitiveMiscCaps = WINED3DPMISCCAPS_CULLNONE |
4383 WINED3DPMISCCAPS_CULLCCW |
4384 WINED3DPMISCCAPS_CULLCW |
4385 WINED3DPMISCCAPS_COLORWRITEENABLE |
4386 WINED3DPMISCCAPS_CLIPTLVERTS |
4387 WINED3DPMISCCAPS_CLIPPLANESCALEDPOINTS |
4388 WINED3DPMISCCAPS_MASKZ |
4389 WINED3DPMISCCAPS_BLENDOP |
4390 WINED3DPMISCCAPS_MRTPOSTPIXELSHADERBLENDING;
4391 /* TODO:
4392 WINED3DPMISCCAPS_NULLREFERENCE
4393 WINED3DPMISCCAPS_FOGANDSPECULARALPHA
4394 WINED3DPMISCCAPS_MRTINDEPENDENTBITDEPTHS
4395 WINED3DPMISCCAPS_FOGVERTEXCLAMPED */
4396
4397 if (gl_info->supported[EXT_BLEND_EQUATION_SEPARATE] && gl_info->supported[EXT_BLEND_FUNC_SEPARATE])
4398 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_SEPARATEALPHABLEND;
4399 if (gl_info->supported[EXT_DRAW_BUFFERS2])
4400 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_INDEPENDENTWRITEMASKS;
4401 if (gl_info->supported[ARB_FRAMEBUFFER_SRGB])
4402 caps->PrimitiveMiscCaps |= WINED3DPMISCCAPS_POSTBLENDSRGBCONVERT;
4403
4404 caps->RasterCaps = WINED3DPRASTERCAPS_DITHER |
4405 WINED3DPRASTERCAPS_PAT |
4406 WINED3DPRASTERCAPS_WFOG |
4407 WINED3DPRASTERCAPS_ZFOG |
4408 WINED3DPRASTERCAPS_FOGVERTEX |
4409 WINED3DPRASTERCAPS_FOGTABLE |
4410 WINED3DPRASTERCAPS_STIPPLE |
4411 WINED3DPRASTERCAPS_SUBPIXEL |
4412 WINED3DPRASTERCAPS_ZTEST |
4413 WINED3DPRASTERCAPS_SCISSORTEST |
4414 WINED3DPRASTERCAPS_SLOPESCALEDEPTHBIAS |
4415 WINED3DPRASTERCAPS_DEPTHBIAS;
4416
4417 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4418 {
4419 caps->RasterCaps |= WINED3DPRASTERCAPS_ANISOTROPY |
4420 WINED3DPRASTERCAPS_ZBIAS |
4421 WINED3DPRASTERCAPS_MIPMAPLODBIAS;
4422 }
4423
4424 caps->ZCmpCaps = WINED3DPCMPCAPS_ALWAYS |
4425 WINED3DPCMPCAPS_EQUAL |
4426 WINED3DPCMPCAPS_GREATER |
4427 WINED3DPCMPCAPS_GREATEREQUAL |
4428 WINED3DPCMPCAPS_LESS |
4429 WINED3DPCMPCAPS_LESSEQUAL |
4430 WINED3DPCMPCAPS_NEVER |
4431 WINED3DPCMPCAPS_NOTEQUAL;
4432
4433 caps->SrcBlendCaps = WINED3DPBLENDCAPS_BOTHINVSRCALPHA |
4434 WINED3DPBLENDCAPS_BOTHSRCALPHA |
4435 WINED3DPBLENDCAPS_DESTALPHA |
4436 WINED3DPBLENDCAPS_DESTCOLOR |
4437 WINED3DPBLENDCAPS_INVDESTALPHA |
4438 WINED3DPBLENDCAPS_INVDESTCOLOR |
4439 WINED3DPBLENDCAPS_INVSRCALPHA |
4440 WINED3DPBLENDCAPS_INVSRCCOLOR |
4441 WINED3DPBLENDCAPS_ONE |
4442 WINED3DPBLENDCAPS_SRCALPHA |
4443 WINED3DPBLENDCAPS_SRCALPHASAT |
4444 WINED3DPBLENDCAPS_SRCCOLOR |
4445 WINED3DPBLENDCAPS_ZERO;
4446
4447 caps->DestBlendCaps = WINED3DPBLENDCAPS_DESTALPHA |
4448 WINED3DPBLENDCAPS_DESTCOLOR |
4449 WINED3DPBLENDCAPS_INVDESTALPHA |
4450 WINED3DPBLENDCAPS_INVDESTCOLOR |
4451 WINED3DPBLENDCAPS_INVSRCALPHA |
4452 WINED3DPBLENDCAPS_INVSRCCOLOR |
4453 WINED3DPBLENDCAPS_ONE |
4454 WINED3DPBLENDCAPS_SRCALPHA |
4455 WINED3DPBLENDCAPS_SRCCOLOR |
4456 WINED3DPBLENDCAPS_ZERO;
4457 /* NOTE: WINED3DPBLENDCAPS_SRCALPHASAT is not supported as dest blend factor,
4458 * according to the glBlendFunc manpage
4459 *
4460 * WINED3DPBLENDCAPS_BOTHINVSRCALPHA and WINED3DPBLENDCAPS_BOTHSRCALPHA are
4461 * legacy settings for srcblend only
4462 */
4463
4464 if (gl_info->supported[EXT_BLEND_COLOR])
4465 {
4466 caps->SrcBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4467 caps->DestBlendCaps |= WINED3DPBLENDCAPS_BLENDFACTOR;
4468 }
4469
4470
4471 caps->AlphaCmpCaps = WINED3DPCMPCAPS_ALWAYS |
4472 WINED3DPCMPCAPS_EQUAL |
4473 WINED3DPCMPCAPS_GREATER |
4474 WINED3DPCMPCAPS_GREATEREQUAL |
4475 WINED3DPCMPCAPS_LESS |
4476 WINED3DPCMPCAPS_LESSEQUAL |
4477 WINED3DPCMPCAPS_NEVER |
4478 WINED3DPCMPCAPS_NOTEQUAL;
4479
4480 caps->ShadeCaps = WINED3DPSHADECAPS_SPECULARGOURAUDRGB |
4481 WINED3DPSHADECAPS_COLORGOURAUDRGB |
4482 WINED3DPSHADECAPS_ALPHAFLATBLEND |
4483 WINED3DPSHADECAPS_ALPHAGOURAUDBLEND |
4484 WINED3DPSHADECAPS_COLORFLATRGB |
4485 WINED3DPSHADECAPS_FOGFLAT |
4486 WINED3DPSHADECAPS_FOGGOURAUD |
4487 WINED3DPSHADECAPS_SPECULARFLATRGB;
4488
4489 caps->TextureCaps = WINED3DPTEXTURECAPS_ALPHA |
4490 WINED3DPTEXTURECAPS_ALPHAPALETTE |
4491 WINED3DPTEXTURECAPS_TRANSPARENCY |
4492 WINED3DPTEXTURECAPS_BORDER |
4493 WINED3DPTEXTURECAPS_MIPMAP |
4494 WINED3DPTEXTURECAPS_PROJECTED |
4495 WINED3DPTEXTURECAPS_PERSPECTIVE;
4496
4497 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4498 {
4499 caps->TextureCaps |= WINED3DPTEXTURECAPS_POW2 |
4500 WINED3DPTEXTURECAPS_NONPOW2CONDITIONAL;
4501 }
4502
4503 if (gl_info->supported[EXT_TEXTURE3D])
4504 {
4505 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP |
4506 WINED3DPTEXTURECAPS_MIPVOLUMEMAP;
4507 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4508 {
4509 caps->TextureCaps |= WINED3DPTEXTURECAPS_VOLUMEMAP_POW2;
4510 }
4511 }
4512
4513 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4514 {
4515 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP |
4516 WINED3DPTEXTURECAPS_MIPCUBEMAP;
4517 if (!gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
4518 {
4519 caps->TextureCaps |= WINED3DPTEXTURECAPS_CUBEMAP_POW2;
4520 }
4521 }
4522
4523 caps->TextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
4524 WINED3DPTFILTERCAPS_MAGFPOINT |
4525 WINED3DPTFILTERCAPS_MINFLINEAR |
4526 WINED3DPTFILTERCAPS_MINFPOINT |
4527 WINED3DPTFILTERCAPS_MIPFLINEAR |
4528 WINED3DPTFILTERCAPS_MIPFPOINT |
4529 WINED3DPTFILTERCAPS_LINEAR |
4530 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
4531 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4532 WINED3DPTFILTERCAPS_MIPLINEAR |
4533 WINED3DPTFILTERCAPS_MIPNEAREST |
4534 WINED3DPTFILTERCAPS_NEAREST;
4535
4536 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4537 {
4538 caps->TextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
4539 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4540 }
4541
4542 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
4543 {
4544 caps->CubeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
4545 WINED3DPTFILTERCAPS_MAGFPOINT |
4546 WINED3DPTFILTERCAPS_MINFLINEAR |
4547 WINED3DPTFILTERCAPS_MINFPOINT |
4548 WINED3DPTFILTERCAPS_MIPFLINEAR |
4549 WINED3DPTFILTERCAPS_MIPFPOINT |
4550 WINED3DPTFILTERCAPS_LINEAR |
4551 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
4552 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4553 WINED3DPTFILTERCAPS_MIPLINEAR |
4554 WINED3DPTFILTERCAPS_MIPNEAREST |
4555 WINED3DPTFILTERCAPS_NEAREST;
4556
4557 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
4558 {
4559 caps->CubeTextureFilterCaps |= WINED3DPTFILTERCAPS_MAGFANISOTROPIC |
4560 WINED3DPTFILTERCAPS_MINFANISOTROPIC;
4561 }
4562 }
4563 else
4564 {
4565 caps->CubeTextureFilterCaps = 0;
4566 }
4567
4568 if (gl_info->supported[EXT_TEXTURE3D])
4569 {
4570 caps->VolumeTextureFilterCaps = WINED3DPTFILTERCAPS_MAGFLINEAR |
4571 WINED3DPTFILTERCAPS_MAGFPOINT |
4572 WINED3DPTFILTERCAPS_MINFLINEAR |
4573 WINED3DPTFILTERCAPS_MINFPOINT |
4574 WINED3DPTFILTERCAPS_MIPFLINEAR |
4575 WINED3DPTFILTERCAPS_MIPFPOINT |
4576 WINED3DPTFILTERCAPS_LINEAR |
4577 WINED3DPTFILTERCAPS_LINEARMIPLINEAR |
4578 WINED3DPTFILTERCAPS_LINEARMIPNEAREST |
4579 WINED3DPTFILTERCAPS_MIPLINEAR |
4580 WINED3DPTFILTERCAPS_MIPNEAREST |
4581 WINED3DPTFILTERCAPS_NEAREST;
4582 }
4583 else
4584 {
4585 caps->VolumeTextureFilterCaps = 0;
4586 }
4587
4588 caps->TextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
4589 WINED3DPTADDRESSCAPS_CLAMP |
4590 WINED3DPTADDRESSCAPS_WRAP;
4591
4592 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4593 {
4594 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4595 }
4596 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4597 {
4598 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4599 }
4600 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
4601 {
4602 caps->TextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4603 }
4604
4605 if (gl_info->supported[EXT_TEXTURE3D])
4606 {
4607 caps->VolumeTextureAddressCaps = WINED3DPTADDRESSCAPS_INDEPENDENTUV |
4608 WINED3DPTADDRESSCAPS_CLAMP |
4609 WINED3DPTADDRESSCAPS_WRAP;
4610 if (gl_info->supported[ARB_TEXTURE_BORDER_CLAMP])
4611 {
4612 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_BORDER;
4613 }
4614 if (gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT])
4615 {
4616 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRROR;
4617 }
4618 if (gl_info->supported[ARB_TEXTURE_MIRROR_CLAMP_TO_EDGE])
4619 {
4620 caps->VolumeTextureAddressCaps |= WINED3DPTADDRESSCAPS_MIRRORONCE;
4621 }
4622 }
4623 else
4624 {
4625 caps->VolumeTextureAddressCaps = 0;
4626 }
4627
4628 caps->LineCaps = WINED3DLINECAPS_TEXTURE |
4629 WINED3DLINECAPS_ZTEST |
4630 WINED3DLINECAPS_BLEND |
4631 WINED3DLINECAPS_ALPHACMP |
4632 WINED3DLINECAPS_FOG;
4633 /* WINED3DLINECAPS_ANTIALIAS is not supported on Windows, and dx and gl seem to have a different
4634 * idea how generating the smoothing alpha values works; the result is different
4635 */
4636
4637 caps->MaxTextureWidth = gl_info->limits.texture_size;
4638 caps->MaxTextureHeight = gl_info->limits.texture_size;
4639
4640 if (gl_info->supported[EXT_TEXTURE3D])
4641 caps->MaxVolumeExtent = gl_info->limits.texture3d_size;
4642 else
4643 caps->MaxVolumeExtent = 0;
4644
4645 caps->MaxTextureRepeat = 32768;
4646 caps->MaxTextureAspectRatio = gl_info->limits.texture_size;
4647 caps->MaxVertexW = 1.0f;
4648
4649 caps->GuardBandLeft = 0.0f;
4650 caps->GuardBandTop = 0.0f;
4651 caps->GuardBandRight = 0.0f;
4652 caps->GuardBandBottom = 0.0f;
4653
4654 caps->ExtentsAdjust = 0.0f;
4655
4656 caps->StencilCaps = WINED3DSTENCILCAPS_DECRSAT |
4657 WINED3DSTENCILCAPS_INCRSAT |
4658 WINED3DSTENCILCAPS_INVERT |
4659 WINED3DSTENCILCAPS_KEEP |
4660 WINED3DSTENCILCAPS_REPLACE |
4661 WINED3DSTENCILCAPS_ZERO;
4662 if (gl_info->supported[EXT_STENCIL_WRAP])
4663 {
4664 caps->StencilCaps |= WINED3DSTENCILCAPS_DECR |
4665 WINED3DSTENCILCAPS_INCR;
4666 }
4667 if (gl_info->supported[EXT_STENCIL_TWO_SIDE] || gl_info->supported[ATI_SEPARATE_STENCIL])
4668 {
4669 caps->StencilCaps |= WINED3DSTENCILCAPS_TWOSIDED;
4670 }
4671
4672 caps->MaxAnisotropy = gl_info->limits.anisotropy;
4673 caps->MaxPointSize = gl_info->limits.pointsize_max;
4674
4675 caps->MaxPrimitiveCount = 0xfffff; /* For now set 2^20-1 which is used by most >=Geforce3/Radeon8500 cards */
4676 caps->MaxVertexIndex = 0xfffff;
4677 caps->MaxStreams = MAX_STREAMS;
4678 caps->MaxStreamStride = 1024;
4679
4680 /* d3d9.dll sets D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES here because StretchRects is implemented in d3d9 */
4681 caps->DevCaps2 = WINED3DDEVCAPS2_STREAMOFFSET |
4682 WINED3DDEVCAPS2_VERTEXELEMENTSCANSHARESTREAMOFFSET;
4683 caps->MaxNpatchTessellationLevel = 0;
4684 caps->MasterAdapterOrdinal = 0;
4685 caps->AdapterOrdinalInGroup = 0;
4686 caps->NumberOfAdaptersInGroup = 1;
4687
4688 caps->NumSimultaneousRTs = gl_info->limits.buffers;
4689
4690 caps->StretchRectFilterCaps = WINED3DPTFILTERCAPS_MINFPOINT |
4691 WINED3DPTFILTERCAPS_MAGFPOINT |
4692 WINED3DPTFILTERCAPS_MINFLINEAR |
4693 WINED3DPTFILTERCAPS_MAGFLINEAR;
4694 caps->VertexTextureFilterCaps = 0;
4695
4696 adapter->shader_backend->shader_get_caps(&adapter->gl_info, &shader_caps);
4697 adapter->fragment_pipe->get_caps(&adapter->gl_info, &fragment_caps);
4698 adapter->vertex_pipe->vp_get_caps(&adapter->gl_info, &vertex_caps);
4699
4700 /* Add shader misc caps. Only some of them belong to the shader parts of the pipeline */
4701 caps->PrimitiveMiscCaps |= fragment_caps.PrimitiveMiscCaps;
4702
4703 caps->VertexShaderVersion = shader_caps.vs_version;
4704 caps->MaxVertexShaderConst = shader_caps.vs_uniform_count;
4705
4706 caps->PixelShaderVersion = shader_caps.ps_version;
4707 caps->PixelShader1xMaxValue = shader_caps.ps_1x_max_value;
4708
4709 caps->TextureOpCaps = fragment_caps.TextureOpCaps;
4710 caps->MaxTextureBlendStages = fragment_caps.MaxTextureBlendStages;
4711 caps->MaxSimultaneousTextures = fragment_caps.MaxSimultaneousTextures;
4712
4713 caps->MaxUserClipPlanes = vertex_caps.max_user_clip_planes;
4714 caps->MaxActiveLights = vertex_caps.max_active_lights;
4715 caps->MaxVertexBlendMatrices = vertex_caps.max_vertex_blend_matrices;
4716 caps->MaxVertexBlendMatrixIndex = vertex_caps.max_vertex_blend_matrix_index;
4717 caps->VertexProcessingCaps = vertex_caps.vertex_processing_caps;
4718 caps->FVFCaps = vertex_caps.fvf_caps;
4719 caps->RasterCaps |= vertex_caps.raster_caps;
4720
4721 /* The following caps are shader specific, but they are things we cannot detect, or which
4722 * are the same among all shader models. So to avoid code duplication set the shader version
4723 * specific, but otherwise constant caps here
4724 */
4725 if (caps->VertexShaderVersion >= 3)
4726 {
4727 /* Where possible set the caps based on OpenGL extensions and if they
4728 * aren't set (in case of software rendering) use the VS 3.0 from
4729 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
4730 * VS3.0 value. */
4731 caps->VS20Caps.caps = WINED3DVS20CAPS_PREDICATION;
4732 /* VS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4733 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MAX_DYNAMICFLOWCONTROLDEPTH;
4734 caps->VS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_vs_temps);
4735 /* level of nesting in loops / if-statements; VS 3.0 requires MAX (4) */
4736 caps->VS20Caps.static_flow_control_depth = WINED3DVS20_MAX_STATICFLOWCONTROLDEPTH;
4737
4738 caps->MaxVShaderInstructionsExecuted = 65535; /* VS 3.0 needs at least 65535, some cards even use 2^32-1 */
4739 caps->MaxVertexShader30InstructionSlots = max(512, adapter->gl_info.limits.arb_vs_instructions);
4740 }
4741 else if (caps->VertexShaderVersion == 2)
4742 {
4743 caps->VS20Caps.caps = 0;
4744 caps->VS20Caps.dynamic_flow_control_depth = WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH;
4745 caps->VS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_vs_temps);
4746 caps->VS20Caps.static_flow_control_depth = 1;
4747
4748 caps->MaxVShaderInstructionsExecuted = 65535;
4749 caps->MaxVertexShader30InstructionSlots = 0;
4750 }
4751 else
4752 { /* VS 1.x */
4753 caps->VS20Caps.caps = 0;
4754 caps->VS20Caps.dynamic_flow_control_depth = 0;
4755 caps->VS20Caps.temp_count = 0;
4756 caps->VS20Caps.static_flow_control_depth = 0;
4757
4758 caps->MaxVShaderInstructionsExecuted = 0;
4759 caps->MaxVertexShader30InstructionSlots = 0;
4760 }
4761
4762 if (caps->PixelShaderVersion >= 3)
4763 {
4764 /* Where possible set the caps based on OpenGL extensions and if they
4765 * aren't set (in case of software rendering) use the PS 3.0 from
4766 * MSDN or else if there's OpenGL spec use a hardcoded value minimum
4767 * PS 3.0 value. */
4768
4769 /* Caps is more or less undocumented on MSDN but it appears to be
4770 * used for PS20Caps based on results from R9600/FX5900/Geforce6800
4771 * cards from Windows */
4772 caps->PS20Caps.caps = WINED3DPS20CAPS_ARBITRARYSWIZZLE |
4773 WINED3DPS20CAPS_GRADIENTINSTRUCTIONS |
4774 WINED3DPS20CAPS_PREDICATION |
4775 WINED3DPS20CAPS_NODEPENDENTREADLIMIT |
4776 WINED3DPS20CAPS_NOTEXINSTRUCTIONLIMIT;
4777 /* PS 3.0 requires MAX_DYNAMICFLOWCONTROLDEPTH (24) */
4778 caps->PS20Caps.dynamic_flow_control_depth = WINED3DPS20_MAX_DYNAMICFLOWCONTROLDEPTH;
4779 caps->PS20Caps.temp_count = max(32, adapter->gl_info.limits.arb_ps_temps);
4780 /* PS 3.0 requires MAX_STATICFLOWCONTROLDEPTH (4) */
4781 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MAX_STATICFLOWCONTROLDEPTH;
4782 /* PS 3.0 requires MAX_NUMINSTRUCTIONSLOTS (512) */
4783 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MAX_NUMINSTRUCTIONSLOTS;
4784
4785 caps->MaxPShaderInstructionsExecuted = 65535;
4786 caps->MaxPixelShader30InstructionSlots = max(WINED3DMIN30SHADERINSTRUCTIONS,
4787 adapter->gl_info.limits.arb_ps_instructions);
4788 }
4789 else if(caps->PixelShaderVersion == 2)
4790 {
4791 /* Below we assume PS2.0 specs, not extended 2.0a(GeforceFX)/2.0b(Radeon R3xx) ones */
4792 caps->PS20Caps.caps = 0;
4793 caps->PS20Caps.dynamic_flow_control_depth = 0; /* WINED3DVS20_MIN_DYNAMICFLOWCONTROLDEPTH = 0 */
4794 caps->PS20Caps.temp_count = max(12, adapter->gl_info.limits.arb_ps_temps);
4795 caps->PS20Caps.static_flow_control_depth = WINED3DPS20_MIN_STATICFLOWCONTROLDEPTH; /* Minimum: 1 */
4796 /* Minimum number (64 ALU + 32 Texture), a GeforceFX uses 512 */
4797 caps->PS20Caps.instruction_slot_count = WINED3DPS20_MIN_NUMINSTRUCTIONSLOTS;
4798
4799 caps->MaxPShaderInstructionsExecuted = 512; /* Minimum value, a GeforceFX uses 1024 */
4800 caps->MaxPixelShader30InstructionSlots = 0;
4801 }
4802 else /* PS 1.x */
4803 {
4804 caps->PS20Caps.caps = 0;
4805 caps->PS20Caps.dynamic_flow_control_depth = 0;
4806 caps->PS20Caps.temp_count = 0;
4807 caps->PS20Caps.static_flow_control_depth = 0;
4808 caps->PS20Caps.instruction_slot_count = 0;
4809
4810 caps->MaxPShaderInstructionsExecuted = 0;
4811 caps->MaxPixelShader30InstructionSlots = 0;
4812 }
4813
4814 if (caps->VertexShaderVersion >= 2)
4815 {
4816 /* OpenGL supports all the formats below, perhaps not always
4817 * without conversion, but it supports them.
4818 * Further GLSL doesn't seem to have an official unsigned type so
4819 * don't advertise it yet as I'm not sure how we handle it.
4820 * We might need to add some clamping in the shader engine to
4821 * support it.
4822 * TODO: WINED3DDTCAPS_USHORT2N, WINED3DDTCAPS_USHORT4N, WINED3DDTCAPS_UDEC3, WINED3DDTCAPS_DEC3N */
4823 caps->DeclTypes = WINED3DDTCAPS_UBYTE4 |
4824 WINED3DDTCAPS_UBYTE4N |
4825 WINED3DDTCAPS_SHORT2N |
4826 WINED3DDTCAPS_SHORT4N;
4827 if (gl_info->supported[ARB_HALF_FLOAT_VERTEX])
4828 {
4829 caps->DeclTypes |= WINED3DDTCAPS_FLOAT16_2 |
4830 WINED3DDTCAPS_FLOAT16_4;
4831 }
4832 }
4833 else
4834 {
4835 caps->DeclTypes = 0;
4836 }
4837
4838 /* Set DirectDraw helper Caps */
4839 ckey_caps = WINEDDCKEYCAPS_DESTBLT |
4840 WINEDDCKEYCAPS_SRCBLT;
4841 fx_caps = WINEDDFXCAPS_BLTALPHA |
4842 WINEDDFXCAPS_BLTMIRRORLEFTRIGHT |
4843 WINEDDFXCAPS_BLTMIRRORUPDOWN |
4844 WINEDDFXCAPS_BLTROTATION90 |
4845 WINEDDFXCAPS_BLTSHRINKX |
4846 WINEDDFXCAPS_BLTSHRINKXN |
4847 WINEDDFXCAPS_BLTSHRINKY |
4848 WINEDDFXCAPS_BLTSHRINKXN |
4849 WINEDDFXCAPS_BLTSTRETCHX |
4850 WINEDDFXCAPS_BLTSTRETCHXN |
4851 WINEDDFXCAPS_BLTSTRETCHY |
4852 WINEDDFXCAPS_BLTSTRETCHYN;
4853 blit_caps = WINEDDCAPS_BLT |
4854 WINEDDCAPS_BLTCOLORFILL |
4855 WINEDDCAPS_BLTDEPTHFILL |
4856 WINEDDCAPS_BLTSTRETCH |
4857 WINEDDCAPS_CANBLTSYSMEM |
4858 WINEDDCAPS_CANCLIP |
4859 WINEDDCAPS_CANCLIPSTRETCHED |
4860 WINEDDCAPS_COLORKEY |
4861 WINEDDCAPS_COLORKEYHWASSIST |
4862 WINEDDCAPS_ALIGNBOUNDARYSRC;
4863 pal_caps = WINEDDPCAPS_8BIT |
4864 WINEDDPCAPS_PRIMARYSURFACE;
4865
4866 /* Fill the ddraw caps structure */
4867 caps->ddraw_caps.caps = WINEDDCAPS_GDI |
4868 WINEDDCAPS_PALETTE |
4869 blit_caps;
4870 caps->ddraw_caps.caps2 = WINEDDCAPS2_CERTIFIED |
4871 WINEDDCAPS2_NOPAGELOCKREQUIRED |
4872 WINEDDCAPS2_PRIMARYGAMMA |
4873 WINEDDCAPS2_WIDESURFACES |
4874 WINEDDCAPS2_CANRENDERWINDOWED;
4875 caps->ddraw_caps.color_key_caps = ckey_caps;
4876 caps->ddraw_caps.fx_caps = fx_caps;
4877 caps->ddraw_caps.pal_caps = pal_caps;
4878 caps->ddraw_caps.svb_caps = blit_caps;
4879 caps->ddraw_caps.svb_color_key_caps = ckey_caps;
4880 caps->ddraw_caps.svb_fx_caps = fx_caps;
4881 caps->ddraw_caps.vsb_caps = blit_caps;
4882 caps->ddraw_caps.vsb_color_key_caps = ckey_caps;
4883 caps->ddraw_caps.vsb_fx_caps = fx_caps;
4884 caps->ddraw_caps.ssb_caps = blit_caps;
4885 caps->ddraw_caps.ssb_color_key_caps = ckey_caps;
4886 caps->ddraw_caps.ssb_fx_caps = fx_caps;
4887
4888 caps->ddraw_caps.dds_caps = WINEDDSCAPS_ALPHA |
4889 WINEDDSCAPS_BACKBUFFER |
4890 WINEDDSCAPS_FLIP |
4891 WINEDDSCAPS_FRONTBUFFER |
4892 WINEDDSCAPS_OFFSCREENPLAIN |
4893 WINEDDSCAPS_PALETTE |
4894 WINEDDSCAPS_PRIMARYSURFACE |
4895 WINEDDSCAPS_SYSTEMMEMORY |
4896 WINEDDSCAPS_VIDEOMEMORY |
4897 WINEDDSCAPS_VISIBLE;
4898 caps->ddraw_caps.stride_align = DDRAW_PITCH_ALIGNMENT;
4899
4900 if (!(wined3d->flags & WINED3D_NO3D))
4901 {
4902 caps->ddraw_caps.dds_caps |= WINEDDSCAPS_3DDEVICE |
4903 WINEDDSCAPS_MIPMAP |
4904 WINEDDSCAPS_TEXTURE |
4905 WINEDDSCAPS_ZBUFFER;
4906 caps->ddraw_caps.caps |= WINEDDCAPS_3D;
4907 }
4908
4909 return WINED3D_OK;
4910}
4911
4912HRESULT CDECL wined3d_device_create(struct wined3d *wined3d, UINT adapter_idx, enum wined3d_device_type device_type,
4913 HWND focus_window, DWORD flags, BYTE surface_alignment, struct wined3d_device_parent *device_parent,
4914 struct wined3d_device **device)
4915{
4916 struct wined3d_device *object;
4917 HRESULT hr;
4918
4919 TRACE("wined3d %p, adapter_idx %u, device_type %#x, focus_window %p, flags %#x, device_parent %p, device %p.\n",
4920 wined3d, adapter_idx, device_type, focus_window, flags, device_parent, device);
4921
4922 /* Validate the adapter number. If no adapters are available(no GL), ignore the adapter
4923 * number and create a device without a 3D adapter for 2D only operation. */
4924 if (wined3d->adapter_count && adapter_idx >= wined3d->adapter_count)
4925 return WINED3DERR_INVALIDCALL;
4926
4927 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
4928 if (!object)
4929 return E_OUTOFMEMORY;
4930
4931 hr = device_init(object, wined3d, adapter_idx, device_type,
4932 focus_window, flags, surface_alignment, device_parent);
4933 if (FAILED(hr))
4934 {
4935 WARN("Failed to initialize device, hr %#x.\n", hr);
4936 HeapFree(GetProcessHeap(), 0, object);
4937 return hr;
4938 }
4939
4940 TRACE("Created device %p.\n", object);
4941 *device = object;
4942
4943 device_parent->ops->wined3d_device_created(device_parent, *device);
4944
4945 return WINED3D_OK;
4946}
4947
4948static void WINE_GLAPI invalid_func(const void *data)
4949{
4950 ERR("Invalid vertex attribute function called\n");
4951 DebugBreak();
4952}
4953
4954static void WINE_GLAPI invalid_texcoord_func(GLenum unit, const void *data)
4955{
4956 ERR("Invalid texcoord function called\n");
4957 DebugBreak();
4958}
4959
4960/* Helper functions for providing vertex data to opengl. The arrays are initialized based on
4961 * the extension detection and are used in drawStridedSlow
4962 */
4963static void WINE_GLAPI position_d3dcolor(const void *data)
4964{
4965 DWORD pos = *((const DWORD *)data);
4966
4967 FIXME("Add a test for fixed function position from d3dcolor type\n");
4968 context_get_current()->gl_info->gl_ops.gl.p_glVertex4s(D3DCOLOR_B_R(pos),
4969 D3DCOLOR_B_G(pos),
4970 D3DCOLOR_B_B(pos),
4971 D3DCOLOR_B_A(pos));
4972}
4973
4974static void WINE_GLAPI position_float4(const void *data)
4975{
4976 const GLfloat *pos = data;
4977
4978 if (pos[3] != 0.0f && pos[3] != 1.0f)
4979 {
4980 float w = 1.0f / pos[3];
4981
4982 context_get_current()->gl_info->gl_ops.gl.p_glVertex4f(pos[0] * w, pos[1] * w, pos[2] * w, w);
4983 }
4984 else
4985 {
4986 context_get_current()->gl_info->gl_ops.gl.p_glVertex3fv(pos);
4987 }
4988}
4989
4990static void WINE_GLAPI diffuse_d3dcolor(const void *data)
4991{
4992 DWORD diffuseColor = *((const DWORD *)data);
4993
4994 context_get_current()->gl_info->gl_ops.gl.p_glColor4ub(D3DCOLOR_B_R(diffuseColor),
4995 D3DCOLOR_B_G(diffuseColor),
4996 D3DCOLOR_B_B(diffuseColor),
4997 D3DCOLOR_B_A(diffuseColor));
4998}
4999
5000static void WINE_GLAPI specular_d3dcolor(const void *data)
5001{
5002 DWORD specularColor = *((const DWORD *)data);
5003 GLbyte d[] = {D3DCOLOR_B_R(specularColor),
5004 D3DCOLOR_B_G(specularColor),
5005 D3DCOLOR_B_B(specularColor)};
5006
5007 specular_func_3ubv(d);
5008}
5009
5010static void WINE_GLAPI warn_no_specular_func(const void *data)
5011{
5012 WARN("GL_EXT_secondary_color not supported\n");
5013}
5014
5015static void wined3d_adapter_init_ffp_attrib_ops(const struct wined3d_adapter *adapter)
5016{
5017 const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
5018 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
5019
5020 position_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5021 position_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5022 position_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)gl_info->gl_ops.gl.p_glVertex3fv;
5023 if (!d3d_info->xyzrhw)
5024 position_funcs[WINED3D_FFP_EMIT_FLOAT4] = position_float4;
5025 else
5026 position_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)gl_info->gl_ops.gl.p_glVertex4fv;
5027 position_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = position_d3dcolor;
5028 position_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5029 position_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5030 position_funcs[WINED3D_FFP_EMIT_SHORT4] = (glAttribFunc)gl_info->gl_ops.gl.p_glVertex2sv;
5031 position_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
5032 position_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5033 position_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
5034 position_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5035 position_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
5036 position_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5037 position_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5038 position_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5039 position_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5040 position_funcs[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5041
5042 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5043 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5044 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)gl_info->gl_ops.gl.p_glColor3fv;
5045 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)gl_info->gl_ops.gl.p_glColor4fv;
5046 diffuse_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = diffuse_d3dcolor;
5047 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5048 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5049 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
5050 diffuse_funcs[WINED3D_FFP_EMIT_UBYTE4N] = (glAttribFunc)gl_info->gl_ops.gl.p_glColor4ubv;
5051 diffuse_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5052 diffuse_funcs[WINED3D_FFP_EMIT_SHORT4N] = (glAttribFunc)gl_info->gl_ops.gl.p_glColor4sv;
5053 diffuse_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5054 diffuse_funcs[WINED3D_FFP_EMIT_USHORT4N] = (glAttribFunc)gl_info->gl_ops.gl.p_glColor4usv;
5055 diffuse_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5056 diffuse_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5057 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5058 diffuse_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5059 diffuse_funcs[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5060
5061 /* No 4 component entry points here */
5062 specular_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5063 specular_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5064 if (gl_info->supported[EXT_SECONDARY_COLOR])
5065 {
5066 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)GL_EXTCALL(glSecondaryColor3fvEXT);
5067 }
5068 else
5069 {
5070 specular_funcs[WINED3D_FFP_EMIT_FLOAT3] = warn_no_specular_func;
5071 }
5072 specular_funcs[WINED3D_FFP_EMIT_FLOAT4] = invalid_func;
5073 if (gl_info->supported[EXT_SECONDARY_COLOR])
5074 {
5075 specular_func_3ubv = (glAttribFunc)GL_EXTCALL(glSecondaryColor3ubvEXT);
5076 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = specular_d3dcolor;
5077 }
5078 else
5079 {
5080 specular_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = warn_no_specular_func;
5081 }
5082 specular_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5083 specular_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5084 specular_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
5085 specular_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
5086 specular_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5087 specular_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
5088 specular_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5089 specular_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
5090 specular_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5091 specular_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5092 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5093 specular_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5094 specular_funcs[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5095
5096 /* Only 3 component entry points here. Test how others behave. Float4 normals are used
5097 * by one of our tests, trying to pass it to the pixel shader, which fails on Windows.
5098 */
5099 normal_funcs[WINED3D_FFP_EMIT_FLOAT1] = invalid_func;
5100 normal_funcs[WINED3D_FFP_EMIT_FLOAT2] = invalid_func;
5101 normal_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glAttribFunc)gl_info->gl_ops.gl.p_glNormal3fv;
5102 normal_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glAttribFunc)gl_info->gl_ops.gl.p_glNormal3fv; /* Just ignore the 4th value */
5103 normal_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_func;
5104 normal_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_func;
5105 normal_funcs[WINED3D_FFP_EMIT_SHORT2] = invalid_func;
5106 normal_funcs[WINED3D_FFP_EMIT_SHORT4] = invalid_func;
5107 normal_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_func;
5108 normal_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_func;
5109 normal_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_func;
5110 normal_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_func;
5111 normal_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_func;
5112 normal_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_func;
5113 normal_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_func;
5114 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_func;
5115 normal_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_func;
5116 normal_funcs[WINED3D_FFP_EMIT_INVALID] = invalid_func;
5117
5118 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT1] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord1fvARB);
5119 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2fvARB);
5120 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT3] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord3fvARB);
5121 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4fvARB);
5122 multi_texcoord_funcs[WINED3D_FFP_EMIT_D3DCOLOR] = invalid_texcoord_func;
5123 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4] = invalid_texcoord_func;
5124 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2svARB);
5125 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4svARB);
5126 multi_texcoord_funcs[WINED3D_FFP_EMIT_UBYTE4N] = invalid_texcoord_func;
5127 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT2N] = invalid_texcoord_func;
5128 multi_texcoord_funcs[WINED3D_FFP_EMIT_SHORT4N] = invalid_texcoord_func;
5129 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT2N] = invalid_texcoord_func;
5130 multi_texcoord_funcs[WINED3D_FFP_EMIT_USHORT4N] = invalid_texcoord_func;
5131 multi_texcoord_funcs[WINED3D_FFP_EMIT_UDEC3] = invalid_texcoord_func;
5132 multi_texcoord_funcs[WINED3D_FFP_EMIT_DEC3N] = invalid_texcoord_func;
5133 if (gl_info->supported[NV_HALF_FLOAT])
5134 {
5135 /* Not supported by ARB_HALF_FLOAT_VERTEX, so check for NV_HALF_FLOAT */
5136 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord2hvNV);
5137 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = (glMultiTexCoordFunc)GL_EXTCALL(glMultiTexCoord4hvNV);
5138 } else {
5139 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_2] = invalid_texcoord_func;
5140 multi_texcoord_funcs[WINED3D_FFP_EMIT_FLOAT16_4] = invalid_texcoord_func;
5141 }
5142 multi_texcoord_funcs[WINED3D_FFP_EMIT_INVALID] = invalid_texcoord_func;
5143}
5144
5145static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter *adapter, HDC dc)
5146{
5147 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
5148 int i;
5149
5150 if (gl_info->supported[WGL_ARB_PIXEL_FORMAT])
5151 {
5152 UINT attrib_count = 0;
5153 GLint cfg_count;
5154 int attribs[11];
5155 int values[11];
5156 int attribute;
5157
5158 attribute = WGL_NUMBER_PIXEL_FORMATS_ARB;
5159 GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, 0, 0, 1, &attribute, &cfg_count));
5160
5161 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cfg_count * sizeof(*adapter->cfgs));
5162 attribs[attrib_count++] = WGL_RED_BITS_ARB;
5163 attribs[attrib_count++] = WGL_GREEN_BITS_ARB;
5164 attribs[attrib_count++] = WGL_BLUE_BITS_ARB;
5165 attribs[attrib_count++] = WGL_ALPHA_BITS_ARB;
5166 attribs[attrib_count++] = WGL_COLOR_BITS_ARB;
5167 attribs[attrib_count++] = WGL_DEPTH_BITS_ARB;
5168 attribs[attrib_count++] = WGL_STENCIL_BITS_ARB;
5169 attribs[attrib_count++] = WGL_DRAW_TO_WINDOW_ARB;
5170 attribs[attrib_count++] = WGL_PIXEL_TYPE_ARB;
5171 attribs[attrib_count++] = WGL_DOUBLE_BUFFER_ARB;
5172 attribs[attrib_count++] = WGL_AUX_BUFFERS_ARB;
5173
5174 for (i = 0, adapter->cfg_count = 0; i < cfg_count; ++i)
5175 {
5176 struct wined3d_pixel_format *cfg = &adapter->cfgs[adapter->cfg_count];
5177 int format_id = i + 1;
5178
5179 if (!GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, attrib_count, attribs, values)))
5180 continue;
5181
5182 cfg->iPixelFormat = format_id;
5183 cfg->redSize = values[0];
5184 cfg->greenSize = values[1];
5185 cfg->blueSize = values[2];
5186 cfg->alphaSize = values[3];
5187 cfg->colorSize = values[4];
5188 cfg->depthSize = values[5];
5189 cfg->stencilSize = values[6];
5190 cfg->windowDrawable = values[7];
5191 cfg->iPixelType = values[8];
5192 cfg->doubleBuffer = values[9];
5193 cfg->auxBuffers = values[10];
5194
5195 cfg->numSamples = 0;
5196 /* Check multisample support. */
5197 if (gl_info->supported[ARB_MULTISAMPLE])
5198 {
5199 int attribs[2] = {WGL_SAMPLE_BUFFERS_ARB, WGL_SAMPLES_ARB};
5200 int values[2];
5201
5202 if (GL_EXTCALL(wglGetPixelFormatAttribivARB(dc, format_id, 0, 2, attribs, values)))
5203 {
5204 /* values[0] = WGL_SAMPLE_BUFFERS_ARB which tells whether
5205 * multisampling is supported. values[1] = number of
5206 * multisample buffers. */
5207 if (values[0])
5208 cfg->numSamples = values[1];
5209 }
5210 }
5211
5212 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5213 "depth=%d, stencil=%d, samples=%d, windowDrawable=%d\n",
5214 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
5215 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
5216 cfg->depthSize, cfg->stencilSize, cfg->numSamples, cfg->windowDrawable);
5217
5218 ++adapter->cfg_count;
5219 }
5220 }
5221 else
5222 {
5223 int cfg_count;
5224
5225 cfg_count = DescribePixelFormat(dc, 0, 0, 0);
5226 adapter->cfgs = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cfg_count * sizeof(*adapter->cfgs));
5227
5228 for (i = 0, adapter->cfg_count = 0; i < cfg_count; ++i)
5229 {
5230 struct wined3d_pixel_format *cfg = &adapter->cfgs[adapter->cfg_count];
5231 PIXELFORMATDESCRIPTOR pfd;
5232 int format_id = i + 1;
5233
5234 if (!DescribePixelFormat(dc, format_id, sizeof(pfd), &pfd))
5235 continue;
5236
5237 /* We only want HW acceleration using an OpenGL ICD driver.
5238 * PFD_GENERIC_FORMAT = slow opengl 1.1 gdi software rendering.
5239 * PFD_GENERIC_ACCELERATED = partial hw acceleration using a MCD
5240 * driver (e.g. 3dfx minigl). */
5241 if (pfd.dwFlags & (PFD_GENERIC_FORMAT | PFD_GENERIC_ACCELERATED))
5242 {
5243 TRACE("Skipping format %d because it isn't ICD accelerated.\n", format_id);
5244 continue;
5245 }
5246
5247 cfg->iPixelFormat = format_id;
5248 cfg->redSize = pfd.cRedBits;
5249 cfg->greenSize = pfd.cGreenBits;
5250 cfg->blueSize = pfd.cBlueBits;
5251 cfg->alphaSize = pfd.cAlphaBits;
5252 cfg->colorSize = pfd.cColorBits;
5253 cfg->depthSize = pfd.cDepthBits;
5254 cfg->stencilSize = pfd.cStencilBits;
5255 cfg->windowDrawable = (pfd.dwFlags & PFD_DRAW_TO_WINDOW) ? 1 : 0;
5256 cfg->iPixelType = (pfd.iPixelType == PFD_TYPE_RGBA) ? WGL_TYPE_RGBA_ARB : WGL_TYPE_COLORINDEX_ARB;
5257 cfg->doubleBuffer = (pfd.dwFlags & PFD_DOUBLEBUFFER) ? 1 : 0;
5258 cfg->auxBuffers = pfd.cAuxBuffers;
5259 cfg->numSamples = 0;
5260
5261 TRACE("iPixelFormat=%d, iPixelType=%#x, doubleBuffer=%d, RGBA=%d/%d/%d/%d, "
5262 "depth=%d, stencil=%d, windowDrawable=%d\n",
5263 cfg->iPixelFormat, cfg->iPixelType, cfg->doubleBuffer,
5264 cfg->redSize, cfg->greenSize, cfg->blueSize, cfg->alphaSize,
5265 cfg->depthSize, cfg->stencilSize, cfg->windowDrawable);
5266
5267 ++adapter->cfg_count;
5268 }
5269 }
5270}
5271
5272/**
5273 * Loads a system DLL.
5274 *
5275 * @returns Module handle or NULL
5276 * @param pszName The DLL name.
5277 */
5278static HMODULE loadSystemDll(const char *pszName)
5279{
5280 char szPath[MAX_PATH];
5281 UINT cchPath = GetSystemDirectoryA(szPath, sizeof(szPath));
5282 size_t cbName = strlen(pszName) + 1;
5283 if (cchPath + 1 + cbName > sizeof(szPath))
5284 return NULL;
5285 szPath[cchPath] = '\\';
5286 memcpy(&szPath[cchPath + 1], pszName, cbName);
5287 return LoadLibraryA(szPath);
5288}
5289
5290/* Do not call while under the GL lock. */
5291static BOOL wined3d_adapter_init(struct wined3d_adapter *adapter, UINT ordinal)
5292{
5293 struct wined3d_gl_info *gl_info = &adapter->gl_info;
5294 struct wined3d_fake_gl_ctx fake_gl_ctx = {0};
5295 unsigned int ctx_attrib_idx = 0;
5296 DISPLAY_DEVICEW display_device;
5297 GLint ctx_attribs[3];
5298#ifdef VBOX
5299 struct VBOXUHGSMI *pHgsmi = NULL;
5300#endif
5301
5302 TRACE("adapter %p, ordinal %u.\n", adapter, ordinal);
5303
5304 adapter->ordinal = ordinal;
5305 adapter->monitorPoint.x = -1;
5306 adapter->monitorPoint.y = -1;
5307
5308/* Dynamically load all GL core functions */
5309#ifdef USE_WIN32_OPENGL
5310 {
5311# ifndef VBOX
5312 HMODULE mod_gl = GetModuleHandleA("opengl32.dll");
5313# else
5314 BOOL (APIENTRY *pDrvValidateVersion)(DWORD) DECLSPEC_HIDDEN;
5315# ifdef VBOX_WDDM_WOW64
5316 HMODULE mod_gl = loadSystemDll("VBoxOGL-x86.dll");
5317# else
5318 HMODULE mod_gl = loadSystemDll("VBoxOGL.dll");
5319# endif
5320 if (!mod_gl)
5321 {
5322 ERR("Can't load VBoxOGL.dll!\n");
5323 return FALSE;
5324 }
5325
5326 pDrvValidateVersion = (void*)GetProcAddress(mod_gl, "DrvValidateVersion");
5327 if(!pDrvValidateVersion) {
5328 ERR("Can't get DrvValidateVersion\n");
5329 FreeLibrary(mod_gl);
5330 return FALSE;
5331 }
5332 if(!pDrvValidateVersion(1)) {
5333 ERR("DrvValidateVersion FAILED\n");
5334 FreeLibrary(mod_gl);
5335 return FALSE;
5336 }
5337
5338# define VBOX_USE_FUNC(f) p##f = (void *)GetProcAddress(mod_gl, #f);
5339 VBOX_GL_FUNCS_GEN
5340# undef VBOX_USE_FUNC
5341# endif
5342# define USE_GL_FUNC(f) gl_info->gl_ops.gl.p_##f = (void *)GetProcAddress(mod_gl, #f);
5343 ALL_WGL_FUNCS
5344# undef USE_GL_FUNC
5345 gl_info->gl_ops.wgl.p_wglSwapBuffers = (void *)GetProcAddress(mod_gl, "wglSwapBuffers");
5346 }
5347#else
5348 /* To bypass the opengl32 thunks retrieve functions from the WGL driver instead of opengl32 */
5349 {
5350 HDC hdc = GetDC( 0 );
5351 const struct opengl_funcs *wgl_driver = __wine_get_wgl_driver( hdc, WINE_WGL_DRIVER_VERSION );
5352 ReleaseDC( 0, hdc );
5353 if (!wgl_driver || wgl_driver == (void *)-1) return FALSE;
5354 gl_info->gl_ops.wgl = wgl_driver->wgl;
5355 gl_info->gl_ops.gl = wgl_driver->gl;
5356 }
5357#endif
5358
5359 glEnableWINE = gl_info->gl_ops.gl.p_glEnable;
5360 glDisableWINE = gl_info->gl_ops.gl.p_glDisable;
5361
5362#ifdef VBOX_WITH_WDDM
5363 pHgsmi = VBoxCrHgsmiCreate();
5364 if (!pHgsmi)
5365 {
5366 ERR("VBoxCrHgsmiCreate failed");
5367 return FALSE;
5368 }
5369#endif
5370
5371 if (!AllocateLocallyUniqueId(&adapter->luid))
5372 {
5373 ERR("Failed to set adapter LUID (%#x).\n", GetLastError());
5374 return FALSE;
5375 }
5376 TRACE("Allocated LUID %08x:%08x for adapter %p.\n",
5377 adapter->luid.HighPart, adapter->luid.LowPart, adapter);
5378
5379 if (!WineD3D_CreateFakeGLContext(&fake_gl_ctx
5380#ifdef VBOX
5381 , pHgsmi
5382#endif
5383 ))
5384 {
5385 ERR("Failed to get a GL context for adapter %p.\n", adapter);
5386#ifdef VBOX_WITH_WDDM
5387 VBoxCrHgsmiDestroy(pHgsmi);
5388#endif
5389 return FALSE;
5390 }
5391
5392 if (context_debug_output_enabled(gl_info))
5393 {
5394 ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_FLAGS_ARB;
5395 ctx_attribs[ctx_attrib_idx++] = WGL_CONTEXT_DEBUG_BIT_ARB;
5396 }
5397 ctx_attribs[ctx_attrib_idx] = 0;
5398 wined3d_create_fake_gl_context_attribs(&fake_gl_ctx, gl_info, ctx_attribs);
5399
5400 if (!wined3d_adapter_init_gl_caps(adapter))
5401 {
5402 ERR("Failed to initialize GL caps for adapter %p.\n", adapter);
5403 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5404#ifdef VBOX_WITH_WDDM
5405 VBoxCrHgsmiDestroy(pHgsmi);
5406#endif
5407 return FALSE;
5408 }
5409
5410 wined3d_adapter_init_fb_cfgs(adapter, fake_gl_ctx.dc);
5411 /* We haven't found any suitable formats. This should only happen in
5412 * case of GDI software rendering, which is pretty useless anyway. */
5413 if (!adapter->cfg_count)
5414 {
5415 WARN("No suitable pixel formats found.\n");
5416 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5417 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
5418#ifdef VBOX_WITH_WDDM
5419 VBoxCrHgsmiDestroy(pHgsmi);
5420#endif
5421 return FALSE;
5422 }
5423
5424 if (!wined3d_adapter_init_format_info(adapter))
5425 {
5426 ERR("Failed to initialize GL format info.\n");
5427 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5428 HeapFree(GetProcessHeap(), 0, adapter->cfgs);
5429#ifdef VBOX_WITH_WDDM
5430 VBoxCrHgsmiDestroy(pHgsmi);
5431#endif
5432 return FALSE;
5433 }
5434
5435#ifndef VBOX_WITH_WDDM
5436 adapter->TextureRam = adapter->driver_info.vidmem;
5437 adapter->UsedTextureRam = 0;
5438 TRACE("Emulating %u MB of texture ram.\n", adapter->TextureRam / (1024 * 1024));
5439#endif
5440
5441 display_device.cb = sizeof(display_device);
5442 EnumDisplayDevicesW(NULL, ordinal, &display_device, 0);
5443 TRACE("DeviceName: %s\n", debugstr_w(display_device.DeviceName));
5444 strcpyW(adapter->DeviceName, display_device.DeviceName);
5445
5446 WineD3D_ReleaseFakeGLContext(&fake_gl_ctx);
5447
5448 wined3d_adapter_init_ffp_attrib_ops(adapter);
5449
5450#ifdef VBOX_WITH_WDDM
5451 VBoxCrHgsmiDestroy(pHgsmi);
5452#endif
5453
5454 return TRUE;
5455}
5456
5457static void wined3d_adapter_init_nogl(struct wined3d_adapter *adapter, UINT ordinal)
5458{
5459 DISPLAY_DEVICEW display_device;
5460
5461 memset(adapter, 0, sizeof(*adapter));
5462 adapter->ordinal = ordinal;
5463 adapter->monitorPoint.x = -1;
5464 adapter->monitorPoint.y = -1;
5465
5466 adapter->driver_info.name = "Display";
5467 adapter->driver_info.description = "WineD3D DirectDraw Emulation";
5468#ifndef VBOX_WITH_WDDM
5469 if (wined3d_settings.emulated_textureram)
5470 adapter->TextureRam = wined3d_settings.emulated_textureram;
5471 else
5472 adapter->TextureRam = 128 * 1024 * 1024;
5473#endif
5474
5475 initPixelFormatsNoGL(&adapter->gl_info);
5476
5477 adapter->vertex_pipe = &none_vertex_pipe;
5478 adapter->fragment_pipe = &none_fragment_pipe;
5479 adapter->shader_backend = &none_shader_backend;
5480 adapter->blitter = &cpu_blit;
5481
5482 display_device.cb = sizeof(display_device);
5483 EnumDisplayDevicesW(NULL, ordinal, &display_device, 0);
5484 TRACE("DeviceName: %s\n", debugstr_w(display_device.DeviceName));
5485 strcpyW(adapter->DeviceName, display_device.DeviceName);
5486}
5487
5488static void STDMETHODCALLTYPE wined3d_null_wined3d_object_destroyed(void *parent) {}
5489
5490const struct wined3d_parent_ops wined3d_null_parent_ops =
5491{
5492 wined3d_null_wined3d_object_destroyed,
5493};
5494
5495/* Do not call while under the GL lock. */
5496HRESULT wined3d_init(struct wined3d *wined3d, UINT version, DWORD flags)
5497{
5498 wined3d->dxVersion = version;
5499 wined3d->ref = 1;
5500 wined3d->flags = flags;
5501
5502 TRACE("Initializing adapters.\n");
5503
5504 if (flags & WINED3D_NO3D)
5505 {
5506 wined3d_adapter_init_nogl(&wined3d->adapters[0], 0);
5507 wined3d->adapter_count = 1;
5508 return WINED3D_OK;
5509 }
5510
5511 if (!wined3d_adapter_init(&wined3d->adapters[0], 0))
5512 {
5513 WARN("Failed to initialize adapter.\n");
5514 return E_FAIL;
5515 }
5516 wined3d->adapter_count = 1;
5517
5518 return WINED3D_OK;
5519}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette