VirtualBox

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

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

wddm: ensure all windows are initially hidden

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