VirtualBox

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

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

wine/new: export

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