VirtualBox

source: vbox/trunk/src/VBox/Devices/Graphics/shaderlib/directx.c@ 53206

最後變更 在這個檔案從53206是 53201,由 vboxsync 提交於 10 年 前

Devices/Main: vmsvga updates

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 112.0 KB
 
1/*
2 * IWineD3D implementation
3 *
4 * Copyright 2002-2004 Jason Edmeades
5 * Copyright 2003-2004 Raphael Junqueira
6 * Copyright 2004 Christian Costa
7 * Copyright 2005 Oliver Stieber
8 * Copyright 2007-2008 Stefan Dösinger for CodeWeavers
9 * Copyright 2009 Henri Verbeet for CodeWeavers
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
26/*
27 * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
28 * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
29 * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
30 * a choice of LGPL license versions is made available with the language indicating
31 * that LGPLv2 or any later version may be used, or where a choice of which version
32 * of the LGPL is applied is otherwise unspecified.
33 */
34
35#include "config.h"
36#include <stdio.h>
37#include "wined3d_private.h"
38
39#ifdef VBOX_WITH_WDDM
40# include <VBox/VBoxCrHgsmi.h>
41#endif
42
43#ifdef VBOX_WITH_VMSVGA
44# ifndef RT_OS_WINDOWS
45void glFinish(void);
46# endif
47#endif
48
49WINE_DEFAULT_DEBUG_CHANNEL(d3d);
50WINE_DECLARE_DEBUG_CHANNEL(d3d_caps);
51
52#define GLINFO_LOCATION (*gl_info)
53#define WINE_DEFAULT_VIDMEM (64 * 1024 * 1024)
54
55/* The d3d device ID */
56static const GUID IID_D3DDEVICE_D3DUID = { 0xaeb2cdd4, 0x6e41, 0x43ea, { 0x94,0x1c,0x83,0x61,0xcc,0x76,0x07,0x81 } };
57
58
59/* Extension detection */
60static const struct {
61 const char *extension_string;
62 GL_SupportedExt extension;
63 DWORD version;
64} EXTENSION_MAP[] = {
65 /* APPLE */
66 {"GL_APPLE_client_storage", APPLE_CLIENT_STORAGE, 0 },
67 {"GL_APPLE_fence", APPLE_FENCE, 0 },
68 {"GL_APPLE_float_pixels", APPLE_FLOAT_PIXELS, 0 },
69 {"GL_APPLE_flush_buffer_range", APPLE_FLUSH_BUFFER_RANGE, 0 },
70 {"GL_APPLE_flush_render", APPLE_FLUSH_RENDER, 0 },
71 {"GL_APPLE_ycbcr_422", APPLE_YCBCR_422, 0 },
72
73 /* ARB */
74 {"GL_ARB_color_buffer_float", ARB_COLOR_BUFFER_FLOAT, 0 },
75 {"GL_ARB_depth_buffer_float", ARB_DEPTH_BUFFER_FLOAT, 0 },
76 {"GL_ARB_depth_clamp", ARB_DEPTH_CLAMP, 0 },
77 {"GL_ARB_depth_texture", ARB_DEPTH_TEXTURE, 0 },
78 {"GL_ARB_draw_buffers", ARB_DRAW_BUFFERS, 0 },
79 {"GL_ARB_fragment_program", ARB_FRAGMENT_PROGRAM, 0 },
80 {"GL_ARB_fragment_shader", ARB_FRAGMENT_SHADER, 0 },
81 {"GL_ARB_framebuffer_object", ARB_FRAMEBUFFER_OBJECT, 0 },
82 {"GL_ARB_geometry_shader4", ARB_GEOMETRY_SHADER4, 0 },
83 {"GL_ARB_half_float_pixel", ARB_HALF_FLOAT_PIXEL, 0 },
84 {"GL_ARB_half_float_vertex", ARB_HALF_FLOAT_VERTEX, 0 },
85 {"GL_ARB_imaging", ARB_IMAGING, 0 },
86 {"GL_ARB_map_buffer_range", ARB_MAP_BUFFER_RANGE, 0 },
87 {"GL_ARB_multisample", ARB_MULTISAMPLE, 0 }, /* needs GLX_ARB_MULTISAMPLE as well */
88 {"GL_ARB_multitexture", ARB_MULTITEXTURE, 0 },
89 {"GL_ARB_occlusion_query", ARB_OCCLUSION_QUERY, 0 },
90 {"GL_ARB_pixel_buffer_object", ARB_PIXEL_BUFFER_OBJECT, 0 },
91 {"GL_ARB_point_parameters", ARB_POINT_PARAMETERS, 0 },
92 {"GL_ARB_point_sprite", ARB_POINT_SPRITE, 0 },
93 {"GL_ARB_provoking_vertex", ARB_PROVOKING_VERTEX, 0 },
94 {"GL_ARB_shader_objects", ARB_SHADER_OBJECTS, 0 },
95 {"GL_ARB_shader_texture_lod", ARB_SHADER_TEXTURE_LOD, 0 },
96 {"GL_ARB_shading_language_100", ARB_SHADING_LANGUAGE_100, 0 },
97 {"GL_ARB_sync", ARB_SYNC, 0 },
98 {"GL_ARB_texture_border_clamp", ARB_TEXTURE_BORDER_CLAMP, 0 },
99 {"GL_ARB_texture_compression", ARB_TEXTURE_COMPRESSION, 0 },
100 {"GL_ARB_texture_cube_map", ARB_TEXTURE_CUBE_MAP, 0 },
101 {"GL_ARB_texture_env_add", ARB_TEXTURE_ENV_ADD, 0 },
102 {"GL_ARB_texture_env_combine", ARB_TEXTURE_ENV_COMBINE, 0 },
103 {"GL_ARB_texture_env_dot3", ARB_TEXTURE_ENV_DOT3, 0 },
104 {"GL_ARB_texture_float", ARB_TEXTURE_FLOAT, 0 },
105 {"GL_ARB_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
106 {"GL_IBM_texture_mirrored_repeat", ARB_TEXTURE_MIRRORED_REPEAT, 0 },
107 {"GL_ARB_texture_non_power_of_two", ARB_TEXTURE_NON_POWER_OF_TWO, MAKEDWORD_VERSION(2, 0) },
108 {"GL_ARB_texture_rectangle", ARB_TEXTURE_RECTANGLE, 0 },
109 {"GL_ARB_texture_rg", ARB_TEXTURE_RG, 0 },
110 {"GL_ARB_vertex_array_bgra", ARB_VERTEX_ARRAY_BGRA, 0 },
111 {"GL_ARB_vertex_blend", ARB_VERTEX_BLEND, 0 },
112 {"GL_ARB_vertex_buffer_object", ARB_VERTEX_BUFFER_OBJECT, 0 },
113 {"GL_ARB_vertex_program", ARB_VERTEX_PROGRAM, 0 },
114 {"GL_ARB_vertex_shader", ARB_VERTEX_SHADER, 0 },
115
116 /* ATI */
117 {"GL_ATI_fragment_shader", ATI_FRAGMENT_SHADER, 0 },
118 {"GL_ATI_separate_stencil", ATI_SEPARATE_STENCIL, 0 },
119 {"GL_ATI_texture_compression_3dc", ATI_TEXTURE_COMPRESSION_3DC, 0 },
120 {"GL_ATI_texture_env_combine3", ATI_TEXTURE_ENV_COMBINE3, 0 },
121 {"GL_ATI_texture_mirror_once", ATI_TEXTURE_MIRROR_ONCE, 0 },
122
123 /* EXT */
124 {"GL_EXT_blend_color", EXT_BLEND_COLOR, 0 },
125 {"GL_EXT_blend_equation_separate", EXT_BLEND_EQUATION_SEPARATE, 0 },
126 {"GL_EXT_blend_func_separate", EXT_BLEND_FUNC_SEPARATE, 0 },
127 {"GL_EXT_blend_minmax", EXT_BLEND_MINMAX, 0 },
128 {"GL_EXT_draw_buffers2", EXT_DRAW_BUFFERS2, 0 },
129 {"GL_EXT_fog_coord", EXT_FOG_COORD, 0 },
130 {"GL_EXT_framebuffer_blit", EXT_FRAMEBUFFER_BLIT, 0 },
131 {"GL_EXT_framebuffer_multisample", EXT_FRAMEBUFFER_MULTISAMPLE, 0 },
132 {"GL_EXT_framebuffer_object", EXT_FRAMEBUFFER_OBJECT, 0 },
133 {"GL_EXT_gpu_program_parameters", EXT_GPU_PROGRAM_PARAMETERS, 0 },
134 {"GL_EXT_gpu_shader4", EXT_GPU_SHADER4, 0 },
135 {"GL_EXT_packed_depth_stencil", EXT_PACKED_DEPTH_STENCIL, 0 },
136 {"GL_EXT_paletted_texture", EXT_PALETTED_TEXTURE, 0 },
137 {"GL_EXT_point_parameters", EXT_POINT_PARAMETERS, 0 },
138 {"GL_EXT_provoking_vertex", EXT_PROVOKING_VERTEX, 0 },
139 {"GL_EXT_secondary_color", EXT_SECONDARY_COLOR, 0 },
140 {"GL_EXT_stencil_two_side", EXT_STENCIL_TWO_SIDE, 0 },
141 {"GL_EXT_stencil_wrap", EXT_STENCIL_WRAP, 0 },
142 {"GL_EXT_texture3D", EXT_TEXTURE3D, MAKEDWORD_VERSION(1, 2) },
143 {"GL_EXT_texture_compression_rgtc", EXT_TEXTURE_COMPRESSION_RGTC, 0 },
144 {"GL_EXT_texture_compression_s3tc", EXT_TEXTURE_COMPRESSION_S3TC, 0 },
145 {"GL_EXT_texture_env_add", EXT_TEXTURE_ENV_ADD, 0 },
146 {"GL_EXT_texture_env_combine", EXT_TEXTURE_ENV_COMBINE, 0 },
147 {"GL_EXT_texture_env_dot3", EXT_TEXTURE_ENV_DOT3, 0 },
148 {"GL_EXT_texture_filter_anisotropic", EXT_TEXTURE_FILTER_ANISOTROPIC, 0 },
149 {"GL_EXT_texture_lod_bias", EXT_TEXTURE_LOD_BIAS, 0 },
150 {"GL_EXT_texture_sRGB", EXT_TEXTURE_SRGB, 0 },
151 {"GL_EXT_vertex_array_bgra", EXT_VERTEX_ARRAY_BGRA, 0 },
152
153 /* NV */
154 {"GL_NV_depth_clamp", NV_DEPTH_CLAMP, 0 },
155 {"GL_NV_fence", NV_FENCE, 0 },
156 {"GL_NV_fog_distance", NV_FOG_DISTANCE, 0 },
157 {"GL_NV_fragment_program", NV_FRAGMENT_PROGRAM, 0 },
158 {"GL_NV_fragment_program2", NV_FRAGMENT_PROGRAM2, 0 },
159 {"GL_NV_fragment_program_option", NV_FRAGMENT_PROGRAM_OPTION, 0 },
160 {"GL_NV_half_float", NV_HALF_FLOAT, 0 },
161 {"GL_NV_light_max_exponent", NV_LIGHT_MAX_EXPONENT, 0 },
162 {"GL_NV_register_combiners", NV_REGISTER_COMBINERS, 0 },
163 {"GL_NV_register_combiners2", NV_REGISTER_COMBINERS2, 0 },
164 {"GL_NV_texgen_reflection", NV_TEXGEN_REFLECTION, 0 },
165 {"GL_NV_texture_env_combine4", NV_TEXTURE_ENV_COMBINE4, 0 },
166 {"GL_NV_texture_shader", NV_TEXTURE_SHADER, 0 },
167 {"GL_NV_texture_shader2", NV_TEXTURE_SHADER2, 0 },
168 {"GL_NV_vertex_program", NV_VERTEX_PROGRAM, 0 },
169 {"GL_NV_vertex_program1_1", NV_VERTEX_PROGRAM1_1, 0 },
170 {"GL_NV_vertex_program2", NV_VERTEX_PROGRAM2, 0 },
171 {"GL_NV_vertex_program2_option", NV_VERTEX_PROGRAM2_OPTION, 0 },
172 {"GL_NV_vertex_program3", NV_VERTEX_PROGRAM3, 0 },
173
174 /* SGI */
175 {"GL_SGIS_generate_mipmap", SGIS_GENERATE_MIPMAP, 0 },
176};
177
178/**********************************************************
179 * Utility functions follow
180 **********************************************************/
181
182const struct min_lookup minMipLookup[] =
183{
184 /* NONE POINT LINEAR */
185 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
186 {{GL_NEAREST, GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST_MIPMAP_LINEAR}}, /* POINT*/
187 {{GL_LINEAR, GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR_MIPMAP_LINEAR}}, /* LINEAR */
188};
189
190const struct min_lookup minMipLookup_noFilter[] =
191{
192 /* NONE POINT LINEAR */
193 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
194 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
195 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* LINEAR */
196};
197
198const struct min_lookup minMipLookup_noMip[] =
199{
200 /* NONE POINT LINEAR */
201 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* NONE */
202 {{GL_NEAREST, GL_NEAREST, GL_NEAREST}}, /* POINT */
203 {{GL_LINEAR, GL_LINEAR, GL_LINEAR }}, /* LINEAR */
204};
205
206const GLenum magLookup[] =
207{
208 /* NONE POINT LINEAR */
209 GL_NEAREST, GL_NEAREST, GL_LINEAR,
210};
211
212const GLenum magLookup_noFilter[] =
213{
214 /* NONE POINT LINEAR */
215 GL_NEAREST, GL_NEAREST, GL_NEAREST,
216};
217
218/* drawStridedSlow attributes */
219glAttribFunc position_funcs[WINED3D_FFP_EMIT_COUNT];
220glAttribFunc diffuse_funcs[WINED3D_FFP_EMIT_COUNT];
221glAttribFunc specular_func_3ubv;
222glAttribFunc specular_funcs[WINED3D_FFP_EMIT_COUNT];
223glAttribFunc normal_funcs[WINED3D_FFP_EMIT_COUNT];
224glMultiTexCoordFunc multi_texcoord_funcs[WINED3D_FFP_EMIT_COUNT];
225
226
227/**********************************************************
228 * IWineD3D parts follows
229 **********************************************************/
230
231/* GL locking is done by the caller */
232static inline BOOL test_arb_vs_offset_limit(const struct wined3d_gl_info *gl_info)
233{
234 GLuint prog;
235 BOOL ret = FALSE;
236 const char *testcode =
237 "!!ARBvp1.0\n"
238 "PARAM C[66] = { program.env[0..65] };\n"
239 "ADDRESS A0;"
240 "PARAM zero = {0.0, 0.0, 0.0, 0.0};\n"
241 "ARL A0.x, zero.x;\n"
242 "MOV result.position, C[A0.x + 65];\n"
243 "END\n";
244
245 while(glGetError());
246 GL_EXTCALL(glGenProgramsARB(1, &prog));
247 if(!prog) {
248 ERR("Failed to create an ARB offset limit test program\n");
249 }
250 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
251 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
252 strlen(testcode), testcode));
253 if(glGetError() != 0) {
254 TRACE("OpenGL implementation does not allow indirect addressing offsets > 63\n");
255 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
256 ret = TRUE;
257 } else TRACE("OpenGL implementation allows offsets > 63\n");
258
259 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
260 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
261 checkGLcall("ARB vp offset limit test cleanup");
262
263 return ret;
264}
265
266static DWORD ver_for_ext(GL_SupportedExt ext)
267{
268 unsigned int i;
269 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i) {
270 if(EXTENSION_MAP[i].extension == ext) {
271 return EXTENSION_MAP[i].version;
272 }
273 }
274 return 0;
275}
276
277static BOOL match_ati_r300_to_500(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
278 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
279{
280 if (card_vendor != HW_VENDOR_ATI) return FALSE;
281 if (device == CARD_ATI_RADEON_9500) return TRUE;
282 if (device == CARD_ATI_RADEON_X700) return TRUE;
283 if (device == CARD_ATI_RADEON_X1600) return TRUE;
284 return FALSE;
285}
286
287static BOOL match_geforce5(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
288 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
289{
290 if (card_vendor == HW_VENDOR_NVIDIA)
291 {
292 if (device == CARD_NVIDIA_GEFORCEFX_5800 || device == CARD_NVIDIA_GEFORCEFX_5600)
293 {
294 return TRUE;
295 }
296 }
297 return FALSE;
298}
299
300static BOOL match_apple(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
301 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
302{
303 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
304 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
305 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
306 *
307 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
308 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
309 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
310 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
311 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
312 * the chance that other implementations support them is rather small since Win32 QuickTime uses
313 * DirectDraw, not OpenGL.
314 *
315 * This test has been moved into wined3d_guess_gl_vendor()
316 */
317 if (gl_vendor == GL_VENDOR_APPLE)
318 {
319 return TRUE;
320 }
321 return FALSE;
322}
323
324/* Context activation is done by the caller. */
325static void test_pbo_functionality(struct wined3d_gl_info *gl_info)
326{
327 /* Some OpenGL implementations, namely Apple's Geforce 8 driver, advertises PBOs,
328 * but glTexSubImage from a PBO fails miserably, with the first line repeated over
329 * all the texture. This function detects this bug by its symptom and disables PBOs
330 * if the test fails.
331 *
332 * The test uploads a 4x4 texture via the PBO in the "native" format GL_BGRA,
333 * GL_UNSIGNED_INT_8_8_8_8_REV. This format triggers the bug, and it is what we use
334 * for D3DFMT_A8R8G8B8. Then the texture is read back without any PBO and the data
335 * read back is compared to the original. If they are equal PBOs are assumed to work,
336 * otherwise the PBO extension is disabled. */
337 GLuint texture, pbo;
338 static const unsigned int pattern[] =
339 {
340 0x00000000, 0x000000ff, 0x0000ff00, 0x40ff0000,
341 0x80ffffff, 0x40ffff00, 0x00ff00ff, 0x0000ffff,
342 0x00ffff00, 0x00ff00ff, 0x0000ffff, 0x000000ff,
343 0x80ff00ff, 0x0000ffff, 0x00ff00ff, 0x40ff00ff
344 };
345 unsigned int check[sizeof(pattern) / sizeof(pattern[0])];
346
347 /* No PBO -> No point in testing them. */
348 if (!gl_info->supported[ARB_PIXEL_BUFFER_OBJECT]) return;
349
350 ENTER_GL();
351
352 while (glGetError());
353 glGenTextures(1, &texture);
354 glBindTexture(GL_TEXTURE_2D, texture);
355
356 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
357 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, 0);
358 checkGLcall("Specifying the PBO test texture");
359
360 GL_EXTCALL(glGenBuffersARB(1, &pbo));
361 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, pbo));
362 GL_EXTCALL(glBufferDataARB(GL_PIXEL_UNPACK_BUFFER_ARB, sizeof(pattern), pattern, GL_STREAM_DRAW_ARB));
363 checkGLcall("Specifying the PBO test pbo");
364
365 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
366 checkGLcall("Loading the PBO test texture");
367
368 GL_EXTCALL(glBindBufferARB(GL_PIXEL_UNPACK_BUFFER_ARB, 0));
369#ifdef VBOX_WITH_VMSVGA
370 glFinish();
371#else
372 wglFinish(); /* just to be sure */
373#endif
374 memset(check, 0, sizeof(check));
375 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, check);
376 checkGLcall("Reading back the PBO test texture");
377
378 glDeleteTextures(1, &texture);
379 GL_EXTCALL(glDeleteBuffersARB(1, &pbo));
380 checkGLcall("PBO test cleanup");
381
382 LEAVE_GL();
383
384 if (memcmp(check, pattern, sizeof(check)))
385 {
386 WARN_(d3d_caps)("PBO test failed, read back data doesn't match original.\n");
387 WARN_(d3d_caps)("Disabling PBOs. This may result in slower performance.\n");
388 gl_info->supported[ARB_PIXEL_BUFFER_OBJECT] = FALSE;
389 }
390 else
391 {
392 TRACE_(d3d_caps)("PBO test successful.\n");
393 }
394}
395
396static BOOL match_apple_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
397 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
398{
399 return (card_vendor == HW_VENDOR_INTEL) && (gl_vendor == GL_VENDOR_APPLE);
400}
401
402static BOOL match_apple_nonr500ati(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
403 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
404{
405 if (gl_vendor != GL_VENDOR_APPLE) return FALSE;
406 if (card_vendor != HW_VENDOR_ATI) return FALSE;
407 if (device == CARD_ATI_RADEON_X1600) return FALSE;
408 return TRUE;
409}
410
411static BOOL match_fglrx(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
412 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
413{
414 return gl_vendor == GL_VENDOR_FGLRX;
415
416}
417
418static BOOL match_dx10_capable(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
419 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
420{
421 /* DX9 cards support 40 single float varyings in hardware, most drivers report 32. ATI misreports
422 * 44 varyings. So assume that if we have more than 44 varyings we have a dx10 card.
423 * This detection is for the gl_ClipPos varying quirk. If a d3d9 card really supports more than 44
424 * varyings and we subtract one in dx9 shaders its not going to hurt us because the dx9 limit is
425 * hardcoded
426 *
427 * dx10 cards usually have 64 varyings */
428 return gl_info->limits.glsl_varyings > 44;
429}
430
431/* A GL context is provided by the caller */
432static BOOL match_allows_spec_alpha(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
433 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
434{
435 GLenum error;
436 DWORD data[16];
437
438 if (!gl_info->supported[EXT_SECONDARY_COLOR]) return FALSE;
439
440 ENTER_GL();
441 while(glGetError());
442 GL_EXTCALL(glSecondaryColorPointerEXT)(4, GL_UNSIGNED_BYTE, 4, data);
443 error = glGetError();
444 LEAVE_GL();
445
446 if(error == GL_NO_ERROR)
447 {
448 TRACE("GL Implementation accepts 4 component specular color pointers\n");
449 return TRUE;
450 }
451 else
452 {
453 TRACE("GL implementation does not accept 4 component specular colors, error %s\n",
454 debug_glerror(error));
455 return FALSE;
456 }
457}
458
459static BOOL match_apple_nvts(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
460 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
461{
462 if (!match_apple(gl_info, gl_renderer, gl_vendor, card_vendor, device)) return FALSE;
463 return gl_info->supported[NV_TEXTURE_SHADER];
464}
465
466/* A GL context is provided by the caller */
467static BOOL match_broken_nv_clip(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
468 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
469{
470 GLuint prog;
471 BOOL ret = FALSE;
472 GLint pos;
473 const char *testcode =
474 "!!ARBvp1.0\n"
475 "OPTION NV_vertex_program2;\n"
476 "MOV result.clip[0], 0.0;\n"
477 "MOV result.position, 0.0;\n"
478 "END\n";
479
480 if (!gl_info->supported[NV_VERTEX_PROGRAM2_OPTION]) return FALSE;
481
482 ENTER_GL();
483 while(glGetError());
484
485 GL_EXTCALL(glGenProgramsARB(1, &prog));
486 if(!prog)
487 {
488 ERR("Failed to create the NVvp clip test program\n");
489 LEAVE_GL();
490 return FALSE;
491 }
492 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prog));
493 GL_EXTCALL(glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
494 strlen(testcode), testcode));
495 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &pos);
496 if(pos != -1)
497 {
498 WARN("GL_NV_vertex_program2_option result.clip[] test failed\n");
499 TRACE("error: %s\n", debugstr_a((const char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)));
500 ret = TRUE;
501 while(glGetError());
502 }
503 else TRACE("GL_NV_vertex_program2_option result.clip[] test passed\n");
504
505 GL_EXTCALL(glBindProgramARB(GL_VERTEX_PROGRAM_ARB, 0));
506 GL_EXTCALL(glDeleteProgramsARB(1, &prog));
507 checkGLcall("GL_NV_vertex_program2_option result.clip[] test cleanup");
508
509 LEAVE_GL();
510 return ret;
511}
512
513/* Context activation is done by the caller. */
514static BOOL match_fbo_tex_update(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
515 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
516{
517 char data[4 * 4 * 4];
518 GLuint tex, fbo;
519 GLenum status;
520
521#ifndef VBOX_WITH_VMSVGA
522 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO) return FALSE;
523#endif
524 memset(data, 0xcc, sizeof(data));
525
526 ENTER_GL();
527
528 glGenTextures(1, &tex);
529 glBindTexture(GL_TEXTURE_2D, tex);
530 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
531 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
532 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 4, 4, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
533 checkGLcall("glTexImage2D");
534
535 gl_info->fbo_ops.glGenFramebuffers(1, &fbo);
536 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, fbo);
537 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
538 checkGLcall("glFramebufferTexture2D");
539
540 status = gl_info->fbo_ops.glCheckFramebufferStatus(GL_FRAMEBUFFER);
541 if (status != GL_FRAMEBUFFER_COMPLETE) ERR("FBO status %#x\n", status);
542 checkGLcall("glCheckFramebufferStatus");
543
544 memset(data, 0x11, sizeof(data));
545 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
546 checkGLcall("glTexSubImage2D");
547
548 glClearColor(0.996, 0.729, 0.745, 0.792);
549 glClear(GL_COLOR_BUFFER_BIT);
550 checkGLcall("glClear");
551
552 glGetTexImage(GL_TEXTURE_2D, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, data);
553 checkGLcall("glGetTexImage");
554
555 gl_info->fbo_ops.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, 0, 0);
556 gl_info->fbo_ops.glBindFramebuffer(GL_FRAMEBUFFER, 0);
557 glBindTexture(GL_TEXTURE_2D, 0);
558 checkGLcall("glBindTexture");
559
560 gl_info->fbo_ops.glDeleteFramebuffers(1, &fbo);
561 glDeleteTextures(1, &tex);
562 checkGLcall("glDeleteTextures");
563
564 LEAVE_GL();
565
566 return *(DWORD *)data == 0x11111111;
567}
568
569static void quirk_arb_constants(struct wined3d_gl_info *gl_info)
570{
571 TRACE_(d3d_caps)("Using ARB vs constant limit(=%u) for GLSL.\n", gl_info->limits.arb_vs_native_constants);
572 gl_info->limits.glsl_vs_float_constants = gl_info->limits.arb_vs_native_constants;
573 TRACE_(d3d_caps)("Using ARB ps constant limit(=%u) for GLSL.\n", gl_info->limits.arb_ps_native_constants);
574 gl_info->limits.glsl_ps_float_constants = gl_info->limits.arb_ps_native_constants;
575}
576
577static void quirk_apple_glsl_constants(struct wined3d_gl_info *gl_info)
578{
579 quirk_arb_constants(gl_info);
580 /* MacOS needs uniforms for relative addressing offsets. This can accumulate to quite a few uniforms.
581 * Beyond that the general uniform isn't optimal, so reserve a number of uniforms. 12 vec4's should
582 * allow 48 different offsets or other helper immediate values. */
583 TRACE_(d3d_caps)("Reserving 12 GLSL constants for compiler private use.\n");
584 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 12);
585}
586
587/* fglrx crashes with a very bad kernel panic if GL_POINT_SPRITE_ARB is set to GL_COORD_REPLACE_ARB
588 * on more than one texture unit. This means that the d3d9 visual point size test will cause a
589 * kernel panic on any machine running fglrx 9.3(latest that supports r300 to r500 cards). This
590 * quirk only enables point sprites on the first texture unit. This keeps point sprites working in
591 * most games, but avoids the crash
592 *
593 * A more sophisticated way would be to find all units that need texture coordinates and enable
594 * point sprites for one if only one is found, and software emulate point sprites in drawStridedSlow
595 * if more than one unit needs texture coordinates(This requires software ffp and vertex shaders though)
596 *
597 * Note that disabling the extension entirely does not gain predictability because there is no point
598 * sprite capability flag in d3d, so the potential rendering bugs are the same if we disable the extension. */
599static void quirk_one_point_sprite(struct wined3d_gl_info *gl_info)
600{
601 if (gl_info->supported[ARB_POINT_SPRITE])
602 {
603 TRACE("Limiting point sprites to one texture unit.\n");
604 gl_info->limits.point_sprite_units = 1;
605 }
606}
607
608static void quirk_ati_dx9(struct wined3d_gl_info *gl_info)
609{
610 quirk_arb_constants(gl_info);
611
612 /* MacOS advertises GL_ARB_texture_non_power_of_two on ATI r500 and earlier cards, although
613 * these cards only support GL_ARB_texture_rectangle(D3DPTEXTURECAPS_NONPOW2CONDITIONAL).
614 * If real NP2 textures are used, the driver falls back to software. We could just remove the
615 * extension and use GL_ARB_texture_rectangle instead, but texture_rectangle is inconventient
616 * due to the non-normalized texture coordinates. Thus set an internal extension flag,
617 * GL_WINE_normalized_texrect, which signals the code that it can use non power of two textures
618 * as per GL_ARB_texture_non_power_of_two, but has to stick to the texture_rectangle limits.
619 *
620 * fglrx doesn't advertise GL_ARB_texture_non_power_of_two, but it advertises opengl 2.0 which
621 * has this extension promoted to core. The extension loading code sets this extension supported
622 * due to that, so this code works on fglrx as well. */
623 if(gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
624 {
625 TRACE("GL_ARB_texture_non_power_of_two advertised on R500 or earlier card, removing.\n");
626 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
627 gl_info->supported[WINE_NORMALIZED_TEXRECT] = TRUE;
628 }
629
630 /* fglrx has the same structural issues as the one described in quirk_apple_glsl_constants, although
631 * it is generally more efficient. Reserve just 8 constants. */
632 TRACE_(d3d_caps)("Reserving 8 GLSL constants for compiler private use.\n");
633 gl_info->reserved_glsl_constants = max(gl_info->reserved_glsl_constants, 8);
634}
635
636static void quirk_no_np2(struct wined3d_gl_info *gl_info)
637{
638 /* The nVidia GeForceFX series reports OpenGL 2.0 capabilities with the latest drivers versions, but
639 * doesn't explicitly advertise the ARB_tex_npot extension in the GL extension string.
640 * This usually means that ARB_tex_npot is supported in hardware as long as the application is staying
641 * within the limits enforced by the ARB_texture_rectangle extension. This however is not true for the
642 * FX series, which instantly falls back to a slower software path as soon as ARB_tex_npot is used.
643 * We therefore completely remove ARB_tex_npot from the list of supported extensions.
644 *
645 * Note that wine_normalized_texrect can't be used in this case because internally it uses ARB_tex_npot,
646 * triggering the software fallback. There is not much we can do here apart from disabling the
647 * software-emulated extension and reenable ARB_tex_rect (which was previously disabled
648 * in IWineD3DImpl_FillGLCaps).
649 * This fixup removes performance problems on both the FX 5900 and FX 5700 (e.g. for framebuffer
650 * post-processing effects in the game "Max Payne 2").
651 * The behaviour can be verified through a simple test app attached in bugreport #14724. */
652 TRACE("GL_ARB_texture_non_power_of_two advertised through OpenGL 2.0 on NV FX card, removing.\n");
653 gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO] = FALSE;
654 gl_info->supported[ARB_TEXTURE_RECTANGLE] = TRUE;
655}
656
657static void quirk_texcoord_w(struct wined3d_gl_info *gl_info)
658{
659 /* The Intel GPUs on MacOS set the .w register of texcoords to 0.0 by default, which causes problems
660 * with fixed function fragment processing. Ideally this flag should be detected with a test shader
661 * and OpenGL feedback mode, but some GL implementations (MacOS ATI at least, probably all MacOS ones)
662 * do not like vertex shaders in feedback mode and return an error, even though it should be valid
663 * according to the spec.
664 *
665 * We don't want to enable this on all cards, as it adds an extra instruction per texcoord used. This
666 * makes the shader slower and eats instruction slots which should be available to the d3d app.
667 *
668 * ATI Radeon HD 2xxx cards on MacOS have the issue. Instead of checking for the buggy cards, blacklist
669 * all radeon cards on Macs and whitelist the good ones. That way we're prepared for the future. If
670 * this workaround is activated on cards that do not need it, it won't break things, just affect
671 * performance negatively. */
672 TRACE("Enabling vertex texture coord fixes in vertex shaders.\n");
673 gl_info->quirks |= WINED3D_QUIRK_SET_TEXCOORD_W;
674}
675
676static void quirk_clip_varying(struct wined3d_gl_info *gl_info)
677{
678 gl_info->quirks |= WINED3D_QUIRK_GLSL_CLIP_VARYING;
679}
680
681static void quirk_allows_specular_alpha(struct wined3d_gl_info *gl_info)
682{
683 gl_info->quirks |= WINED3D_QUIRK_ALLOWS_SPECULAR_ALPHA;
684}
685
686static void quirk_apple_nvts(struct wined3d_gl_info *gl_info)
687{
688 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
689 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
690}
691
692static void quirk_disable_nvvp_clip(struct wined3d_gl_info *gl_info)
693{
694 gl_info->quirks |= WINED3D_QUIRK_NV_CLIP_BROKEN;
695}
696
697static void quirk_fbo_tex_update(struct wined3d_gl_info *gl_info)
698{
699 gl_info->quirks |= WINED3D_QUIRK_FBO_TEX_UPDATE;
700}
701
702static BOOL match_ati_hd4800(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
703 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
704{
705 if (card_vendor != HW_VENDOR_ATI) return FALSE;
706 if (device == CARD_ATI_RADEON_HD4800) return TRUE;
707 return FALSE;
708}
709
710static void quirk_fullsize_blit(struct wined3d_gl_info *gl_info)
711{
712 gl_info->quirks |= WINED3D_QUIRK_FULLSIZE_BLIT;
713}
714
715#ifdef VBOX_WITH_WDDM
716static BOOL match_mesa_nvidia(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
717 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
718{
719 if (card_vendor != HW_VENDOR_NVIDIA) return FALSE;
720 if (gl_vendor != GL_VENDOR_MESA) return FALSE;
721 return TRUE;
722}
723
724static void quirk_no_shader_3(struct wined3d_gl_info *gl_info)
725{
726 int vs_selected_mode, ps_selected_mode;
727 select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
728 if (vs_selected_mode != SHADER_GLSL && ps_selected_mode != SHADER_GLSL)
729 return;
730
731 gl_info->limits.arb_ps_instructions = 512;
732}
733#endif
734
735static BOOL match_intel(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
736 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
737{
738 if (card_vendor == HW_VENDOR_INTEL) return TRUE;
739 if (gl_vendor == HW_VENDOR_INTEL) return TRUE;
740 return FALSE;
741}
742
743static void quirk_force_blit(struct wined3d_gl_info *gl_info)
744{
745 gl_info->quirks |= WINED3D_QUIRK_FORCE_BLIT;
746}
747
748struct driver_quirk
749{
750 BOOL (*match)(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
751 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device);
752 void (*apply)(struct wined3d_gl_info *gl_info);
753 const char *description;
754};
755
756static const struct driver_quirk quirk_table[] =
757{
758 {
759 match_ati_r300_to_500,
760 quirk_ati_dx9,
761 "ATI GLSL constant and normalized texrect quirk"
762 },
763 /* MacOS advertises more GLSL vertex shader uniforms than supported by the hardware, and if more are
764 * used it falls back to software. While the compiler can detect if the shader uses all declared
765 * uniforms, the optimization fails if the shader uses relative addressing. So any GLSL shader
766 * using relative addressing falls back to software.
767 *
768 * ARB vp gives the correct amount of uniforms, so use it instead of GLSL. */
769 {
770 match_apple,
771 quirk_apple_glsl_constants,
772 "Apple GLSL uniform override"
773 },
774 {
775 match_geforce5,
776 quirk_no_np2,
777 "Geforce 5 NP2 disable"
778 },
779 {
780 match_apple_intel,
781 quirk_texcoord_w,
782 "Init texcoord .w for Apple Intel GPU driver"
783 },
784 {
785 match_apple_nonr500ati,
786 quirk_texcoord_w,
787 "Init texcoord .w for Apple ATI >= r600 GPU driver"
788 },
789 {
790 match_fglrx,
791 quirk_one_point_sprite,
792 "Fglrx point sprite crash workaround"
793 },
794 {
795 match_dx10_capable,
796 quirk_clip_varying,
797 "Reserved varying for gl_ClipPos"
798 },
799 {
800 /* GL_EXT_secondary_color does not allow 4 component secondary colors, but most
801 * GL implementations accept it. The Mac GL is the only implementation known to
802 * reject it.
803 *
804 * If we can pass 4 component specular colors, do it, because (a) we don't have
805 * to screw around with the data, and (b) the D3D fixed function vertex pipeline
806 * passes specular alpha to the pixel shader if any is used. Otherwise the
807 * specular alpha is used to pass the fog coordinate, which we pass to opengl
808 * via GL_EXT_fog_coord.
809 */
810 match_allows_spec_alpha,
811 quirk_allows_specular_alpha,
812 "Allow specular alpha quirk"
813 },
814 {
815 /* The pixel formats provided by GL_NV_texture_shader are broken on OSX
816 * (rdar://5682521).
817 */
818 match_apple_nvts,
819 quirk_apple_nvts,
820 "Apple NV_texture_shader disable"
821 },
822#ifndef VBOX_WITH_VMSVGA
823 {
824 match_broken_nv_clip,
825 quirk_disable_nvvp_clip,
826 "Apple NV_vertex_program clip bug quirk"
827 },
828#endif
829 {
830 match_fbo_tex_update,
831 quirk_fbo_tex_update,
832 "FBO rebind for attachment updates"
833 },
834 {
835 match_ati_hd4800,
836 quirk_fullsize_blit,
837 "Fullsize blit"
838 },
839#ifdef VBOX_WITH_WDDM
840 {
841 match_mesa_nvidia,
842 quirk_no_shader_3,
843 "disable shader 3 support"
844 },
845#endif
846 {
847 match_intel,
848 quirk_force_blit,
849 "force framebuffer blit when possible"
850 }
851};
852
853/* Context activation is done by the caller. */
854static void fixup_extensions(struct wined3d_gl_info *gl_info, const char *gl_renderer,
855 enum wined3d_gl_vendor gl_vendor, enum wined3d_pci_vendor card_vendor, enum wined3d_pci_device device)
856{
857 unsigned int i;
858
859 for (i = 0; i < (sizeof(quirk_table) / sizeof(*quirk_table)); ++i)
860 {
861 if (!quirk_table[i].match(gl_info, gl_renderer, gl_vendor, card_vendor, device)) continue;
862 TRACE_(d3d_caps)("Applying driver quirk \"%s\".\n", quirk_table[i].description);
863 quirk_table[i].apply(gl_info);
864 }
865
866 /* Find out if PBOs work as they are supposed to. */
867 test_pbo_functionality(gl_info);
868}
869
870
871/* Certain applications (Steam) complain if we report an outdated driver version. In general,
872 * reporting a driver version is moot because we are not the Windows driver, and we have different
873 * bugs, features, etc.
874 *
875 * The driver version has the form "x.y.z.w".
876 *
877 * "x" is the Windows version the driver is meant for:
878 * 4 -> 95/98/NT4
879 * 5 -> 2000
880 * 6 -> 2000/XP
881 * 7 -> Vista
882 * 8 -> Win 7
883 *
884 * "y" is the Direct3D level the driver supports:
885 * 11 -> d3d6
886 * 12 -> d3d7
887 * 13 -> d3d8
888 * 14 -> d3d9
889 * 15 -> d3d10
890 *
891 * "z" is unknown, possibly vendor specific.
892 *
893 * "w" is the vendor specific driver version.
894 */
895struct driver_version_information
896{
897 WORD vendor; /* reported PCI card vendor ID */
898 WORD card; /* reported PCI card device ID */
899 const char *description; /* Description of the card e.g. NVIDIA RIVA TNT */
900 WORD d3d_level; /* driver hiword to report */
901 WORD lopart_hi, lopart_lo; /* driver loword to report */
902};
903
904static const struct driver_version_information driver_version_table[] =
905{
906 /* Nvidia drivers. Geforce6 and newer cards are supported by the current driver (180.x)
907 * GeforceFX support is up to 173.x, - driver uses numbering x.y.11.7341 for 173.41 where x is the windows revision (6=2000/xp, 7=vista), y is unknown
908 * Geforce2MX/3/4 up to 96.x - driver uses numbering 9.6.8.9 for 96.89
909 * TNT/Geforce1/2 up to 71.x - driver uses numbering 7.1.8.6 for 71.86
910 *
911 * All version numbers used below are from the Linux nvidia drivers. */
912 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT, "NVIDIA RIVA TNT", 1, 8, 6 },
913 {HW_VENDOR_NVIDIA, CARD_NVIDIA_RIVA_TNT2, "NVIDIA RIVA TNT2/TNT2 Pro", 1, 8, 6 },
914 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE, "NVIDIA GeForce 256", 1, 8, 6 },
915 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2_MX, "NVIDIA GeForce2 MX/MX 400", 6, 4, 3 },
916 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE2, "NVIDIA GeForce2 GTS/GeForce2 Pro", 1, 8, 6 },
917 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE3, "NVIDIA GeForce3", 6, 10, 9371 },
918 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_MX, "NVIDIA GeForce4 MX 460", 6, 10, 9371 },
919 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE4_TI4200, "NVIDIA GeForce4 Ti 4200", 6, 10, 9371 },
920 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5200, "NVIDIA GeForce FX 5200", 15, 11, 7516 },
921 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5600, "NVIDIA GeForce FX 5600", 15, 11, 7516 },
922 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCEFX_5800, "NVIDIA GeForce FX 5800", 15, 11, 7516 },
923 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6200, "NVIDIA GeForce 6200", 15, 11, 8618 },
924 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6600GT, "NVIDIA GeForce 6600 GT", 15, 11, 8618 },
925 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_6800, "NVIDIA GeForce 6800", 15, 11, 8618 },
926 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7300, "NVIDIA GeForce Go 7300", 15, 11, 8585 },
927 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7400, "NVIDIA GeForce Go 7400", 15, 11, 8585 },
928 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7600, "NVIDIA GeForce 7600 GT", 15, 11, 8618 },
929 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_7800GT, "NVIDIA GeForce 7800 GT", 15, 11, 8618 },
930 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8300GS, "NVIDIA GeForce 8300 GS", 15, 11, 8618 },
931 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600GT, "NVIDIA GeForce 8600 GT", 15, 11, 8618 },
932 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8600MGT, "NVIDIA GeForce 8600M GT", 15, 11, 8585 },
933 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_8800GTS, "NVIDIA GeForce 8800 GTS", 15, 11, 8618 },
934 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9200, "NVIDIA GeForce 9200", 15, 11, 8618 },
935 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9400GT, "NVIDIA GeForce 9400 GT", 15, 11, 8618 },
936 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9500GT, "NVIDIA GeForce 9500 GT", 15, 11, 8618 },
937 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9600GT, "NVIDIA GeForce 9600 GT", 15, 11, 8618 },
938 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_9800GT, "NVIDIA GeForce 9800 GT", 15, 11, 8618 },
939 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX260, "NVIDIA GeForce GTX 260", 15, 11, 8618 },
940 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX275, "NVIDIA GeForce GTX 275", 15, 11, 8618 },
941 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GTX280, "NVIDIA GeForce GTX 280", 15, 11, 8618 },
942 {HW_VENDOR_NVIDIA, CARD_NVIDIA_GEFORCE_GT240, "NVIDIA GeForce GT 240", 15, 11, 8618 },
943
944 /* ATI cards. The driver versions are somewhat similar, but not quite the same. Let's hardcode. */
945 {HW_VENDOR_ATI, CARD_ATI_RADEON_9500, "ATI Radeon 9500", 14, 10, 6764 },
946 {HW_VENDOR_ATI, CARD_ATI_RADEON_X700, "ATI Radeon X700 SE", 14, 10, 6764 },
947 {HW_VENDOR_ATI, CARD_ATI_RADEON_X1600, "ATI Radeon X1600 Series", 14, 10, 6764 },
948 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD2350, "ATI Mobility Radeon HD 2350", 14, 10, 6764 },
949 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD2600, "ATI Mobility Radeon HD 2600", 14, 10, 6764 },
950 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD2900, "ATI Radeon HD 2900 XT", 14, 10, 6764 },
951 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD4350, "ATI Radeon HD 4350", 14, 10, 6764 },
952 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD4600, "ATI Radeon HD 4600 Series", 14, 10, 6764 },
953 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD4700, "ATI Radeon HD 4700 Series", 14, 10, 6764 },
954 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD4800, "ATI Radeon HD 4800 Series", 14, 10, 6764 },
955 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD5700, "ATI Radeon HD 5700 Series", 14, 10, 8681 },
956 {HW_VENDOR_ATI, CARD_ATI_RADEON_HD5800, "ATI Radeon HD 5800 Series", 14, 10, 8681 },
957
958 /* TODO: Add information about legacy ATI hardware, Intel and other cards. */
959};
960
961
962static DWORD wined3d_parse_gl_version(const char *gl_version)
963{
964 const char *ptr = gl_version;
965 int major, minor;
966
967 major = atoi(ptr);
968 if (major <= 0) ERR_(d3d_caps)("Invalid opengl major version: %d.\n", major);
969
970 while (isdigit(*ptr)) ++ptr;
971 if (*ptr++ != '.') ERR_(d3d_caps)("Invalid opengl version string: %s.\n", debugstr_a(gl_version));
972
973 minor = atoi(ptr);
974
975 TRACE_(d3d_caps)("Found OpenGL version: %d.%d.\n", major, minor);
976
977 return MAKEDWORD_VERSION(major, minor);
978}
979
980static enum wined3d_gl_vendor wined3d_guess_gl_vendor(struct wined3d_gl_info *gl_info, const char *gl_vendor_string, const char *gl_renderer)
981{
982
983 /* MacOS has various specialities in the extensions it advertises. Some have to be loaded from
984 * the opengl 1.2+ core, while other extensions are advertised, but software emulated. So try to
985 * detect the Apple OpenGL implementation to apply some extension fixups afterwards.
986 *
987 * Detecting this isn't really easy. The vendor string doesn't mention Apple. Compile-time checks
988 * aren't sufficient either because a Linux binary may display on a macos X server via remote X11.
989 * So try to detect the GL implementation by looking at certain Apple extensions. Some extensions
990 * like client storage might be supported on other implementations too, but GL_APPLE_flush_render
991 * is specific to the Mac OS X window management, and GL_APPLE_ycbcr_422 is QuickTime specific. So
992 * the chance that other implementations support them is rather small since Win32 QuickTime uses
993 * DirectDraw, not OpenGL. */
994 if (gl_info->supported[APPLE_FENCE]
995 && gl_info->supported[APPLE_CLIENT_STORAGE]
996 && gl_info->supported[APPLE_FLUSH_RENDER]
997 && gl_info->supported[APPLE_YCBCR_422])
998 return GL_VENDOR_APPLE;
999
1000 if (strstr(gl_vendor_string, "NVIDIA"))
1001 return GL_VENDOR_NVIDIA;
1002
1003 if (strstr(gl_vendor_string, "ATI"))
1004 return GL_VENDOR_FGLRX;
1005
1006 if (strstr(gl_vendor_string, "Intel(R)")
1007 || strstr(gl_renderer, "Intel(R)")
1008 || strstr(gl_vendor_string, "Intel Inc."))
1009 {
1010 if (strstr(gl_renderer, "Mesa"))
1011 return GL_VENDOR_MESA;
1012 return GL_VENDOR_INTEL;
1013 }
1014
1015 if (strstr(gl_vendor_string, "Mesa")
1016 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1017 || strstr(gl_vendor_string, "DRI R300 Project")
1018 || strstr(gl_vendor_string, "X.Org R300 Project")
1019 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1020 || strstr(gl_vendor_string, "VMware, Inc.")
1021 || strstr(gl_renderer, "Mesa")
1022 || strstr(gl_renderer, "Gallium"))
1023 return GL_VENDOR_MESA;
1024
1025 FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Returning GL_VENDOR_UNKNOWN.\n",
1026 debugstr_a(gl_vendor_string));
1027
1028 return GL_VENDOR_UNKNOWN;
1029}
1030
1031static enum wined3d_pci_vendor wined3d_guess_card_vendor(const char *gl_vendor_string, const char *gl_renderer)
1032{
1033 if (strstr(gl_vendor_string, "NVIDIA"))
1034 return HW_VENDOR_NVIDIA;
1035
1036 if (strstr(gl_vendor_string, "ATI")
1037 || strstr(gl_vendor_string, "Advanced Micro Devices, Inc.")
1038 || strstr(gl_vendor_string, "X.Org R300 Project")
1039 || strstr(gl_vendor_string, "DRI R300 Project"))
1040 return HW_VENDOR_ATI;
1041
1042 if (strstr(gl_vendor_string, "Intel(R)")
1043 || strstr(gl_renderer, "Intel(R)")
1044 || strstr(gl_vendor_string, "Intel Inc."))
1045 return HW_VENDOR_INTEL;
1046
1047 if (strstr(gl_vendor_string, "Mesa")
1048 || strstr(gl_vendor_string, "Tungsten Graphics, Inc")
1049 || strstr(gl_vendor_string, "VMware, Inc."))
1050 return HW_VENDOR_SOFTWARE;
1051
1052 FIXME_(d3d_caps)("Received unrecognized GL_VENDOR %s. Returning HW_VENDOR_NVIDIA.\n", debugstr_a(gl_vendor_string));
1053
1054 return HW_VENDOR_NVIDIA;
1055}
1056
1057
1058
1059static enum wined3d_pci_device select_card_nvidia_binary(const struct wined3d_gl_info *gl_info,
1060 const char *gl_renderer, unsigned int *vidmem)
1061{
1062#ifndef VBOX_WITH_WDDM
1063 if (WINE_D3D10_CAPABLE(gl_info))
1064#endif
1065 {
1066 /* Geforce 200 - highend */
1067 if (strstr(gl_renderer, "GTX 280")
1068 || strstr(gl_renderer, "GTX 285")
1069 || strstr(gl_renderer, "GTX 295"))
1070 {
1071 *vidmem = 1024;
1072 return CARD_NVIDIA_GEFORCE_GTX280;
1073 }
1074
1075 /* Geforce 200 - midend high */
1076 if (strstr(gl_renderer, "GTX 275"))
1077 {
1078 *vidmem = 896;
1079 return CARD_NVIDIA_GEFORCE_GTX275;
1080 }
1081
1082 /* Geforce 200 - midend */
1083 if (strstr(gl_renderer, "GTX 260"))
1084 {
1085 *vidmem = 1024;
1086 return CARD_NVIDIA_GEFORCE_GTX260;
1087 }
1088 /* Geforce 200 - midend */
1089 if (strstr(gl_renderer, "GT 240"))
1090 {
1091 *vidmem = 512;
1092 return CARD_NVIDIA_GEFORCE_GT240;
1093 }
1094
1095 /* Geforce9 - highend / Geforce 200 - midend (GTS 150/250 are based on the same core) */
1096 if (strstr(gl_renderer, "9800")
1097 || strstr(gl_renderer, "GTS 150")
1098 || strstr(gl_renderer, "GTS 250"))
1099 {
1100 *vidmem = 512;
1101 return CARD_NVIDIA_GEFORCE_9800GT;
1102 }
1103
1104 /* Geforce9 - midend */
1105 if (strstr(gl_renderer, "9600"))
1106 {
1107 *vidmem = 384; /* The 9600GSO has 384MB, the 9600GT has 512-1024MB */
1108 return CARD_NVIDIA_GEFORCE_9600GT;
1109 }
1110
1111 /* Geforce9 - midend low / Geforce 200 - low */
1112 if (strstr(gl_renderer, "9500")
1113 || strstr(gl_renderer, "GT 120")
1114 || strstr(gl_renderer, "GT 130"))
1115 {
1116 *vidmem = 256; /* The 9500GT has 256-1024MB */
1117 return CARD_NVIDIA_GEFORCE_9500GT;
1118 }
1119
1120 /* Geforce9 - lowend */
1121 if (strstr(gl_renderer, "9400"))
1122 {
1123 *vidmem = 256; /* The 9400GT has 256-1024MB */
1124 return CARD_NVIDIA_GEFORCE_9400GT;
1125 }
1126
1127 /* Geforce9 - lowend low */
1128 if (strstr(gl_renderer, "9100")
1129 || strstr(gl_renderer, "9200")
1130 || strstr(gl_renderer, "9300")
1131 || strstr(gl_renderer, "G 100"))
1132 {
1133 *vidmem = 256; /* The 9100-9300 cards have 256MB */
1134 return CARD_NVIDIA_GEFORCE_9200;
1135 }
1136
1137 /* Geforce8 - highend */
1138 if (strstr(gl_renderer, "8800"))
1139 {
1140 *vidmem = 320; /* The 8800GTS uses 320MB, a 8800GTX can have 768MB */
1141 return CARD_NVIDIA_GEFORCE_8800GTS;
1142 }
1143
1144 /* Geforce8 - midend mobile */
1145 if (strstr(gl_renderer, "8600 M"))
1146 {
1147 *vidmem = 512;
1148 return CARD_NVIDIA_GEFORCE_8600MGT;
1149 }
1150
1151 /* Geforce8 - midend */
1152 if (strstr(gl_renderer, "8600")
1153 || strstr(gl_renderer, "8700"))
1154 {
1155 *vidmem = 256;
1156 return CARD_NVIDIA_GEFORCE_8600GT;
1157 }
1158
1159 /* Geforce8 - lowend */
1160 if (strstr(gl_renderer, "8100")
1161 || strstr(gl_renderer, "8200")
1162 || strstr(gl_renderer, "8300")
1163 || strstr(gl_renderer, "8400")
1164 || strstr(gl_renderer, "8500"))
1165 {
1166 *vidmem = 128; /* 128-256MB for a 8300, 256-512MB for a 8400 */
1167 return CARD_NVIDIA_GEFORCE_8300GS;
1168 }
1169
1170 /* Geforce8-compatible fall back if the GPU is not in the list yet */
1171 *vidmem = 128;
1172 return CARD_NVIDIA_GEFORCE_8300GS;
1173 }
1174
1175 /* Both the GeforceFX, 6xxx and 7xxx series support D3D9. The last two types have more
1176 * shader capabilities, so we use the shader capabilities to distinguish between FX and 6xxx/7xxx.
1177 */
1178 if (WINE_D3D9_CAPABLE(gl_info) && gl_info->supported[NV_VERTEX_PROGRAM3])
1179 {
1180 /* Geforce7 - highend */
1181 if (strstr(gl_renderer, "7800")
1182 || strstr(gl_renderer, "7900")
1183 || strstr(gl_renderer, "7950")
1184 || strstr(gl_renderer, "Quadro FX 4")
1185 || strstr(gl_renderer, "Quadro FX 5"))
1186 {
1187 *vidmem = 256; /* A 7800GT uses 256MB while highend 7900 cards can use 512MB */
1188 return CARD_NVIDIA_GEFORCE_7800GT;
1189 }
1190
1191 /* Geforce7 midend */
1192 if (strstr(gl_renderer, "7600")
1193 || strstr(gl_renderer, "7700"))
1194 {
1195 *vidmem = 256; /* The 7600 uses 256-512MB */
1196 return CARD_NVIDIA_GEFORCE_7600;
1197 }
1198
1199 /* Geforce7 lower medium */
1200 if (strstr(gl_renderer, "7400"))
1201 {
1202 *vidmem = 256; /* The 7400 uses 256-512MB */
1203 return CARD_NVIDIA_GEFORCE_7400;
1204 }
1205
1206 /* Geforce7 lowend */
1207 if (strstr(gl_renderer, "7300"))
1208 {
1209 *vidmem = 256; /* Mac Pros with this card have 256 MB */
1210 return CARD_NVIDIA_GEFORCE_7300;
1211 }
1212
1213 /* Geforce6 highend */
1214 if (strstr(gl_renderer, "6800"))
1215 {
1216 *vidmem = 128; /* The 6800 uses 128-256MB, the 7600 uses 256-512MB */
1217 return CARD_NVIDIA_GEFORCE_6800;
1218 }
1219
1220 /* Geforce6 - midend */
1221 if (strstr(gl_renderer, "6600")
1222 || strstr(gl_renderer, "6610")
1223 || strstr(gl_renderer, "6700"))
1224 {
1225 *vidmem = 128; /* A 6600GT has 128-256MB */
1226 return CARD_NVIDIA_GEFORCE_6600GT;
1227 }
1228
1229 /* Geforce6/7 lowend */
1230 *vidmem = 64; /* */
1231 return CARD_NVIDIA_GEFORCE_6200; /* Geforce 6100/6150/6200/7300/7400/7500 */
1232 }
1233
1234 if (WINE_D3D9_CAPABLE(gl_info))
1235 {
1236 /* GeforceFX - highend */
1237 if (strstr(gl_renderer, "5800")
1238 || strstr(gl_renderer, "5900")
1239 || strstr(gl_renderer, "5950")
1240 || strstr(gl_renderer, "Quadro FX"))
1241 {
1242 *vidmem = 256; /* 5800-5900 cards use 256MB */
1243 return CARD_NVIDIA_GEFORCEFX_5800;
1244 }
1245
1246 /* GeforceFX - midend */
1247 if (strstr(gl_renderer, "5600")
1248 || strstr(gl_renderer, "5650")
1249 || strstr(gl_renderer, "5700")
1250 || strstr(gl_renderer, "5750"))
1251 {
1252 *vidmem = 128; /* A 5600 uses 128-256MB */
1253 return CARD_NVIDIA_GEFORCEFX_5600;
1254 }
1255
1256 /* GeforceFX - lowend */
1257 *vidmem = 64; /* Normal FX5200 cards use 64-256MB; laptop (non-standard) can have less */
1258 return CARD_NVIDIA_GEFORCEFX_5200; /* GeforceFX 5100/5200/5250/5300/5500 */
1259 }
1260
1261 if (WINE_D3D8_CAPABLE(gl_info))
1262 {
1263 if (strstr(gl_renderer, "GeForce4 Ti") || strstr(gl_renderer, "Quadro4"))
1264 {
1265 *vidmem = 64; /* Geforce4 Ti cards have 64-128MB */
1266 return CARD_NVIDIA_GEFORCE4_TI4200; /* Geforce4 Ti4200/Ti4400/Ti4600/Ti4800, Quadro4 */
1267 }
1268
1269 *vidmem = 64; /* Geforce3 cards have 64-128MB */
1270 return CARD_NVIDIA_GEFORCE3; /* Geforce3 standard/Ti200/Ti500, Quadro DCC */
1271 }
1272
1273 if (WINE_D3D7_CAPABLE(gl_info))
1274 {
1275 if (strstr(gl_renderer, "GeForce4 MX"))
1276 {
1277 /* Most Geforce4MX GPUs have at least 64MB of memory, some
1278 * early models had 32MB but most have 64MB or even 128MB. */
1279 *vidmem = 64;
1280 return CARD_NVIDIA_GEFORCE4_MX; /* MX420/MX440/MX460/MX4000 */
1281 }
1282
1283 if (strstr(gl_renderer, "GeForce2 MX") || strstr(gl_renderer, "Quadro2 MXR"))
1284 {
1285 *vidmem = 32; /* Geforce2MX GPUs have 32-64MB of video memory */
1286 return CARD_NVIDIA_GEFORCE2_MX; /* Geforce2 standard/MX100/MX200/MX400, Quadro2 MXR */
1287 }
1288
1289 if (strstr(gl_renderer, "GeForce2") || strstr(gl_renderer, "Quadro2"))
1290 {
1291 *vidmem = 32; /* Geforce2 GPUs have 32-64MB of video memory */
1292 return CARD_NVIDIA_GEFORCE2; /* Geforce2 GTS/Pro/Ti/Ultra, Quadro2 */
1293 }
1294
1295 /* Most Geforce1 cards have 32MB, there are also some rare 16
1296 * and 64MB (Dell) models. */
1297 *vidmem = 32;
1298 return CARD_NVIDIA_GEFORCE; /* Geforce 256/DDR, Quadro */
1299 }
1300
1301 if (strstr(gl_renderer, "TNT2"))
1302 {
1303 *vidmem = 32; /* Most TNT2 boards have 32MB, though there are 16MB boards too */
1304 return CARD_NVIDIA_RIVA_TNT2; /* Riva TNT2 standard/M64/Pro/Ultra */
1305 }
1306
1307 *vidmem = 16; /* Most TNT boards have 16MB, some rare models have 8MB */
1308 return CARD_NVIDIA_RIVA_TNT; /* Riva TNT, Vanta */
1309
1310}
1311
1312static enum wined3d_pci_device select_card_ati_binary(const struct wined3d_gl_info *gl_info,
1313 const char *gl_renderer, unsigned int *vidmem)
1314{
1315 /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1316 *
1317 * Beware: renderer string do not match exact card model,
1318 * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1319#ifndef VBOX_WITH_WDDM
1320 if (WINE_D3D10_CAPABLE(gl_info))
1321#endif
1322 {
1323 /* Radeon EG CYPRESS XT / PRO HD5800 - highend */
1324 if (strstr(gl_renderer, "HD 5800") /* Radeon EG CYPRESS HD58xx generic renderer string */
1325 || strstr(gl_renderer, "HD 5850") /* Radeon EG CYPRESS XT */
1326 || strstr(gl_renderer, "HD 5870")) /* Radeon EG CYPRESS PRO */
1327 {
1328 *vidmem = 1024; /* note: HD58xx cards use 1024MB */
1329 return CARD_ATI_RADEON_HD5800;
1330 }
1331
1332 /* Radeon EG JUNIPER XT / LE HD5700 - midend */
1333 if (strstr(gl_renderer, "HD 5700") /* Radeon EG JUNIPER HD57xx generic renderer string */
1334 || strstr(gl_renderer, "HD 5750") /* Radeon EG JUNIPER LE */
1335 || strstr(gl_renderer, "HD 5770")) /* Radeon EG JUNIPER XT */
1336 {
1337 *vidmem = 512; /* note: HD5770 cards use 1024MB and HD5750 cards use 512MB or 1024MB */
1338 return CARD_ATI_RADEON_HD5700;
1339 }
1340
1341 /* Radeon R7xx HD4800 - highend */
1342 if (strstr(gl_renderer, "HD 4800") /* Radeon RV7xx HD48xx generic renderer string */
1343 || strstr(gl_renderer, "HD 4830") /* Radeon RV770 */
1344 || strstr(gl_renderer, "HD 4850") /* Radeon RV770 */
1345 || strstr(gl_renderer, "HD 4870") /* Radeon RV770 */
1346 || strstr(gl_renderer, "HD 4890")) /* Radeon RV790 */
1347 {
1348 *vidmem = 512; /* note: HD4890 cards use 1024MB */
1349 return CARD_ATI_RADEON_HD4800;
1350 }
1351
1352 /* Radeon R740 HD4700 - midend */
1353 if (strstr(gl_renderer, "HD 4700") /* Radeon RV770 */
1354 || strstr(gl_renderer, "HD 4770")) /* Radeon RV740 */
1355 {
1356 *vidmem = 512;
1357 return CARD_ATI_RADEON_HD4700;
1358 }
1359
1360 /* Radeon R730 HD4600 - midend */
1361 if (strstr(gl_renderer, "HD 4600") /* Radeon RV730 */
1362 || strstr(gl_renderer, "HD 4650") /* Radeon RV730 */
1363 || strstr(gl_renderer, "HD 4670")) /* Radeon RV730 */
1364 {
1365 *vidmem = 512;
1366 return CARD_ATI_RADEON_HD4600;
1367 }
1368
1369 /* Radeon R710 HD4500/HD4350 - lowend */
1370 if (strstr(gl_renderer, "HD 4350") /* Radeon RV710 */
1371 || strstr(gl_renderer, "HD 4550")) /* Radeon RV710 */
1372 {
1373 *vidmem = 256;
1374 return CARD_ATI_RADEON_HD4350;
1375 }
1376
1377 /* Radeon R6xx HD2900/HD3800 - highend */
1378 if (strstr(gl_renderer, "HD 2900")
1379 || strstr(gl_renderer, "HD 3870")
1380 || strstr(gl_renderer, "HD 3850"))
1381 {
1382 *vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
1383 return CARD_ATI_RADEON_HD2900;
1384 }
1385
1386 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
1387 if (strstr(gl_renderer, "HD 2600")
1388 || strstr(gl_renderer, "HD 3830")
1389 || strstr(gl_renderer, "HD 3690")
1390 || strstr(gl_renderer, "HD 3650"))
1391 {
1392 *vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
1393 return CARD_ATI_RADEON_HD2600;
1394 }
1395
1396 /* Radeon R6xx HD2350/HD2400/HD3400 - lowend
1397 * Note HD2300=DX9, HD2350=DX10 */
1398 if (strstr(gl_renderer, "HD 2350")
1399 || strstr(gl_renderer, "HD 2400")
1400 || strstr(gl_renderer, "HD 3470")
1401 || strstr(gl_renderer, "HD 3450")
1402 || strstr(gl_renderer, "HD 3430")
1403 || strstr(gl_renderer, "HD 3400"))
1404 {
1405 *vidmem = 256; /* HD2350/2400 use 256MB, HD34xx use 256-512MB */
1406 return CARD_ATI_RADEON_HD2350;
1407 }
1408
1409 /* Radeon R6xx/R7xx integrated */
1410 if (strstr(gl_renderer, "HD 3100")
1411 || strstr(gl_renderer, "HD 3200")
1412 || strstr(gl_renderer, "HD 3300"))
1413 {
1414 *vidmem = 128; /* 128MB */
1415 return CARD_ATI_RADEON_HD3200;
1416 }
1417
1418 /* Default for when no GPU has been found */
1419 *vidmem = 128; /* 128MB */
1420 return CARD_ATI_RADEON_HD3200;
1421 }
1422
1423 if (WINE_D3D8_CAPABLE(gl_info))
1424 {
1425 /* Radeon R5xx */
1426 if (strstr(gl_renderer, "X1600")
1427 || strstr(gl_renderer, "X1650")
1428 || strstr(gl_renderer, "X1800")
1429 || strstr(gl_renderer, "X1900")
1430 || strstr(gl_renderer, "X1950"))
1431 {
1432 *vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1433 return CARD_ATI_RADEON_X1600;
1434 }
1435
1436 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300/X2500/HD2300 (lowend R5xx)
1437 * Note X2300/X2500/HD2300 are R5xx GPUs with a 2xxx naming but they are still DX9-only */
1438 if (strstr(gl_renderer, "X700")
1439 || strstr(gl_renderer, "X800")
1440 || strstr(gl_renderer, "X850")
1441 || strstr(gl_renderer, "X1300")
1442 || strstr(gl_renderer, "X1400")
1443 || strstr(gl_renderer, "X1450")
1444 || strstr(gl_renderer, "X1550")
1445 || strstr(gl_renderer, "X2300")
1446 || strstr(gl_renderer, "X2500")
1447 || strstr(gl_renderer, "HD 2300")
1448 )
1449 {
1450 *vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1451 return CARD_ATI_RADEON_X700;
1452 }
1453
1454 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
1455 if (strstr(gl_renderer, "Radeon Xpress"))
1456 {
1457 *vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
1458 return CARD_ATI_RADEON_XPRESS_200M;
1459 }
1460
1461 /* Radeon R3xx */
1462 *vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1463 return CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1464 }
1465
1466 if (WINE_D3D8_CAPABLE(gl_info))
1467 {
1468 *vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1469 return CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1470 }
1471
1472 if (WINE_D3D7_CAPABLE(gl_info))
1473 {
1474 *vidmem = 32; /* There are models with up to 64MB */
1475 return CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1476 }
1477
1478 *vidmem = 16; /* There are 16-32MB models */
1479 return CARD_ATI_RAGE_128PRO;
1480
1481}
1482
1483static enum wined3d_pci_device select_card_intel_binary(const struct wined3d_gl_info *gl_info,
1484 const char *gl_renderer, unsigned int *vidmem)
1485{
1486 if (strstr(gl_renderer, "X3100"))
1487 {
1488 /* MacOS calls the card GMA X3100, Google findings also suggest the name GM965 */
1489 *vidmem = 128;
1490 return CARD_INTEL_X3100;
1491 }
1492
1493 if (strstr(gl_renderer, "GMA 950") || strstr(gl_renderer, "945GM"))
1494 {
1495 /* MacOS calls the card GMA 950, but everywhere else the PCI ID is named 945GM */
1496 *vidmem = 64;
1497 return CARD_INTEL_I945GM;
1498 }
1499
1500 if (strstr(gl_renderer, "915GM")) return CARD_INTEL_I915GM;
1501 if (strstr(gl_renderer, "915G")) return CARD_INTEL_I915G;
1502 if (strstr(gl_renderer, "865G")) return CARD_INTEL_I865G;
1503 if (strstr(gl_renderer, "855G")) return CARD_INTEL_I855G;
1504 if (strstr(gl_renderer, "830G")) return CARD_INTEL_I830G;
1505 return CARD_INTEL_I915G;
1506
1507}
1508
1509static enum wined3d_pci_device select_card_ati_mesa(const struct wined3d_gl_info *gl_info,
1510 const char *gl_renderer, unsigned int *vidmem)
1511{
1512 /* See http://developer.amd.com/drivers/pc_vendor_id/Pages/default.aspx
1513 *
1514 * Beware: renderer string do not match exact card model,
1515 * eg HD 4800 is returned for multiple cards, even for RV790 based ones. */
1516 if (strstr(gl_renderer, "Gallium"))
1517 {
1518 /* Radeon R7xx HD4800 - highend */
1519 if (strstr(gl_renderer, "R700") /* Radeon R7xx HD48xx generic renderer string */
1520 || strstr(gl_renderer, "RV770") /* Radeon RV770 */
1521 || strstr(gl_renderer, "RV790")) /* Radeon RV790 */
1522 {
1523 *vidmem = 512; /* note: HD4890 cards use 1024MB */
1524 return CARD_ATI_RADEON_HD4800;
1525 }
1526
1527 /* Radeon R740 HD4700 - midend */
1528 if (strstr(gl_renderer, "RV740")) /* Radeon RV740 */
1529 {
1530 *vidmem = 512;
1531 return CARD_ATI_RADEON_HD4700;
1532 }
1533
1534 /* Radeon R730 HD4600 - midend */
1535 if (strstr(gl_renderer, "RV730")) /* Radeon RV730 */
1536 {
1537 *vidmem = 512;
1538 return CARD_ATI_RADEON_HD4600;
1539 }
1540
1541 /* Radeon R710 HD4500/HD4350 - lowend */
1542 if (strstr(gl_renderer, "RV710")) /* Radeon RV710 */
1543 {
1544 *vidmem = 256;
1545 return CARD_ATI_RADEON_HD4350;
1546 }
1547
1548 /* Radeon R6xx HD2900/HD3800 - highend */
1549 if (strstr(gl_renderer, "R600")
1550 || strstr(gl_renderer, "RV670")
1551 || strstr(gl_renderer, "R680"))
1552 {
1553 *vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
1554 return CARD_ATI_RADEON_HD2900;
1555 }
1556
1557 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
1558 if (strstr(gl_renderer, "RV630")
1559 || strstr(gl_renderer, "RV635"))
1560 {
1561 *vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
1562 return CARD_ATI_RADEON_HD2600;
1563 }
1564
1565 /* Radeon R6xx HD2350/HD2400/HD3400 - lowend */
1566 if (strstr(gl_renderer, "RV610")
1567 || strstr(gl_renderer, "RV620"))
1568 {
1569 *vidmem = 256; /* HD2350/2400 use 256MB, HD34xx use 256-512MB */
1570 return CARD_ATI_RADEON_HD2350;
1571 }
1572
1573 /* Radeon R6xx/R7xx integrated */
1574 if (strstr(gl_renderer, "RS780")
1575 || strstr(gl_renderer, "RS880"))
1576 {
1577 *vidmem = 128; /* 128MB */
1578 return CARD_ATI_RADEON_HD3200;
1579 }
1580
1581 /* Radeon R5xx */
1582 if (strstr(gl_renderer, "RV530")
1583 || strstr(gl_renderer, "RV535")
1584 || strstr(gl_renderer, "RV560")
1585 || strstr(gl_renderer, "R520")
1586 || strstr(gl_renderer, "RV570")
1587 || strstr(gl_renderer, "R580"))
1588 {
1589 *vidmem = 128; /* X1600 uses 128-256MB, >=X1800 uses 256MB */
1590 return CARD_ATI_RADEON_X1600;
1591 }
1592
1593 /* Radeon R4xx + X1300/X1400/X1450/X1550/X2300 (lowend R5xx) */
1594 if (strstr(gl_renderer, "R410")
1595 || strstr(gl_renderer, "R420")
1596 || strstr(gl_renderer, "R423")
1597 || strstr(gl_renderer, "R430")
1598 || strstr(gl_renderer, "R480")
1599 || strstr(gl_renderer, "R481")
1600 || strstr(gl_renderer, "RV410")
1601 || strstr(gl_renderer, "RV515")
1602 || strstr(gl_renderer, "RV516"))
1603 {
1604 *vidmem = 128; /* x700/x8*0 use 128-256MB, >=x1300 128-512MB */
1605 return CARD_ATI_RADEON_X700;
1606 }
1607
1608 /* Radeon Xpress Series - onboard, DX9b, Shader 2.0, 300-400MHz */
1609 if (strstr(gl_renderer, "RS400")
1610 || strstr(gl_renderer, "RS480")
1611 || strstr(gl_renderer, "RS482")
1612 || strstr(gl_renderer, "RS485")
1613 || strstr(gl_renderer, "RS600")
1614 || strstr(gl_renderer, "RS690")
1615 || strstr(gl_renderer, "RS740"))
1616 {
1617 *vidmem = 64; /* Shared RAM, BIOS configurable, 64-256M */
1618 return CARD_ATI_RADEON_XPRESS_200M;
1619 }
1620
1621 /* Radeon R3xx */
1622 if (strstr(gl_renderer, "R300")
1623 || strstr(gl_renderer, "RV350")
1624 || strstr(gl_renderer, "RV351")
1625 || strstr(gl_renderer, "RV360")
1626 || strstr(gl_renderer, "RV370")
1627 || strstr(gl_renderer, "R350")
1628 || strstr(gl_renderer, "R360"))
1629 {
1630 *vidmem = 64; /* Radeon 9500 uses 64MB, higher models use up to 256MB */
1631 return CARD_ATI_RADEON_9500; /* Radeon 9500/9550/9600/9700/9800/X300/X550/X600 */
1632 }
1633 }
1634
1635 if (WINE_D3D9_CAPABLE(gl_info))
1636 {
1637 /* Radeon R7xx HD4800 - highend */
1638 if (strstr(gl_renderer, "(R700") /* Radeon R7xx HD48xx generic renderer string */
1639 || strstr(gl_renderer, "(RV770") /* Radeon RV770 */
1640 || strstr(gl_renderer, "(RV790")) /* Radeon RV790 */
1641 {
1642 *vidmem = 512; /* note: HD4890 cards use 1024MB */
1643 return CARD_ATI_RADEON_HD4800;
1644 }
1645
1646 /* Radeon R740 HD4700 - midend */
1647 if (strstr(gl_renderer, "(RV740")) /* Radeon RV740 */
1648 {
1649 *vidmem = 512;
1650 return CARD_ATI_RADEON_HD4700;
1651 }
1652
1653 /* Radeon R730 HD4600 - midend */
1654 if (strstr(gl_renderer, "(RV730")) /* Radeon RV730 */
1655 {
1656 *vidmem = 512;
1657 return CARD_ATI_RADEON_HD4600;
1658 }
1659
1660 /* Radeon R710 HD4500/HD4350 - lowend */
1661 if (strstr(gl_renderer, "(RV710")) /* Radeon RV710 */
1662 {
1663 *vidmem = 256;
1664 return CARD_ATI_RADEON_HD4350;
1665 }
1666
1667 /* Radeon R6xx HD2900/HD3800 - highend */
1668 if (strstr(gl_renderer, "(R600")
1669 || strstr(gl_renderer, "(RV670")
1670 || strstr(gl_renderer, "(R680"))
1671 {
1672 *vidmem = 512; /* HD2900/HD3800 uses 256-1024MB */
1673 return CARD_ATI_RADEON_HD2900;
1674 }
1675
1676 /* Radeon R6xx HD2600/HD3600 - midend; HD3830 is China-only midend */
1677 if (strstr(gl_renderer, "(RV630")
1678 || strstr(gl_renderer, "(RV635"))
1679 {
1680 *vidmem = 256; /* HD2600/HD3600 uses 256-512MB */
1681 return CARD_ATI_RADEON_HD2600;
1682 }
1683
1684 /* Radeon R6xx HD2300/HD2400/HD3400 - lowend */
1685 if (strstr(gl_renderer, "(RV610")
1686 || strstr(gl_renderer, "(RV620"))
1687 {
1688 *vidmem = 256; /* HD2350/2400 use 256MB, HD34xx use 256-512MB */
1689 return CARD_ATI_RADEON_HD2350;
1690 }
1691
1692 /* Radeon R6xx/R7xx integrated */
1693 if (strstr(gl_renderer, "(RS780")
1694 || strstr(gl_renderer, "(RS880"))
1695 {
1696 *vidmem = 128; /* 128MB */
1697 return CARD_ATI_RADEON_HD3200;
1698 }
1699 }
1700
1701 if (WINE_D3D8_CAPABLE(gl_info))
1702 {
1703 *vidmem = 64; /* 8500/9000 cards use mostly 64MB, though there are 32MB and 128MB models */
1704 return CARD_ATI_RADEON_8500; /* Radeon 8500/9000/9100/9200/9300 */
1705 }
1706
1707 if (WINE_D3D7_CAPABLE(gl_info))
1708 {
1709 *vidmem = 32; /* There are models with up to 64MB */
1710 return CARD_ATI_RADEON_7200; /* Radeon 7000/7100/7200/7500 */
1711 }
1712
1713 *vidmem = 16; /* There are 16-32MB models */
1714 return CARD_ATI_RAGE_128PRO;
1715
1716}
1717
1718static enum wined3d_pci_device select_card_nvidia_mesa(const struct wined3d_gl_info *gl_info,
1719 const char *gl_renderer, unsigned int *vidmem)
1720{
1721 FIXME_(d3d_caps)("Card selection not handled for Mesa Nouveau driver\n");
1722#ifndef VBOX_WITH_WDDM
1723 if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCEFX_5600;
1724#else
1725 /* tmp work around to disable quirk_no_np2 quirk for mesa drivers */
1726 if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE_6200;
1727#endif
1728 if (WINE_D3D8_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE3;
1729 if (WINE_D3D7_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE;
1730 if (WINE_D3D6_CAPABLE(gl_info)) return CARD_NVIDIA_RIVA_TNT;
1731 return CARD_NVIDIA_RIVA_128;
1732}
1733
1734static enum wined3d_pci_device select_card_intel_cmn(const struct wined3d_gl_info *gl_info,
1735 const char *gl_renderer, unsigned int *vidmem)
1736{
1737 if (strstr(gl_renderer, "HD Graphics")
1738 || strstr(gl_renderer, "Sandybridge"))
1739 return CARD_INTEL_SBHD;
1740 FIXME_(d3d_caps)("Card selection not handled for Windows Intel driver\n");
1741 return CARD_INTEL_I915G;
1742}
1743
1744static enum wined3d_pci_device select_card_intel_mesa(const struct wined3d_gl_info *gl_info,
1745 const char *gl_renderer, unsigned int *vidmem)
1746{
1747 return select_card_intel_cmn(gl_info, gl_renderer, vidmem);
1748}
1749
1750struct vendor_card_selection
1751{
1752 enum wined3d_gl_vendor gl_vendor;
1753 enum wined3d_pci_vendor card_vendor;
1754 const char *description; /* Description of the card selector i.e. Apple OS/X Intel */
1755 enum wined3d_pci_device (*select_card)(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1756 unsigned int *vidmem );
1757};
1758
1759static const struct vendor_card_selection vendor_card_select_table[] =
1760{
1761 {GL_VENDOR_NVIDIA, HW_VENDOR_NVIDIA, "Nvidia binary driver", select_card_nvidia_binary},
1762 {GL_VENDOR_APPLE, HW_VENDOR_NVIDIA, "Apple OSX NVidia binary driver", select_card_nvidia_binary},
1763 {GL_VENDOR_APPLE, HW_VENDOR_ATI, "Apple OSX AMD/ATI binary driver", select_card_ati_binary},
1764 {GL_VENDOR_APPLE, HW_VENDOR_INTEL, "Apple OSX Intel binary driver", select_card_intel_binary},
1765 {GL_VENDOR_FGLRX, HW_VENDOR_ATI, "AMD/ATI binary driver", select_card_ati_binary},
1766 {GL_VENDOR_MESA, HW_VENDOR_ATI, "Mesa AMD/ATI driver", select_card_ati_mesa},
1767 {GL_VENDOR_MESA, HW_VENDOR_NVIDIA, "Mesa Nouveau driver", select_card_nvidia_mesa},
1768 {GL_VENDOR_MESA, HW_VENDOR_INTEL, "Mesa Intel driver", select_card_intel_mesa},
1769 {GL_VENDOR_INTEL, HW_VENDOR_INTEL, "Windows Intel binary driver", select_card_intel_cmn}
1770};
1771
1772
1773static enum wined3d_pci_device wined3d_guess_card(const struct wined3d_gl_info *gl_info, const char *gl_renderer,
1774 enum wined3d_gl_vendor *gl_vendor, enum wined3d_pci_vendor *card_vendor, unsigned int *vidmem)
1775{
1776 /* Above is a list of Nvidia and ATI GPUs. Both vendors have dozens of
1777 * different GPUs with roughly the same features. In most cases GPUs from a
1778 * certain family differ in clockspeeds, the amount of video memory and the
1779 * number of shader pipelines.
1780 *
1781 * A Direct3D device object contains the PCI id (vendor + device) of the
1782 * videocard which is used for rendering. Various applications use this
1783 * information to get a rough estimation of the features of the card and
1784 * some might use it for enabling 3d effects only on certain types of
1785 * videocards. In some cases games might even use it to work around bugs
1786 * which happen on certain videocards/driver combinations. The problem is
1787 * that OpenGL only exposes a rendering string containing the name of the
1788 * videocard and not the PCI id.
1789 *
1790 * Various games depend on the PCI id, so somehow we need to provide one.
1791 * A simple option is to parse the renderer string and translate this to
1792 * the right PCI id. This is a lot of work because there are more than 200
1793 * GPUs just for Nvidia. Various cards share the same renderer string, so
1794 * the amount of code might be 'small' but there are quite a number of
1795 * exceptions which would make this a pain to maintain. Another way would
1796 * be to query the PCI id from the operating system (assuming this is the
1797 * videocard which is used for rendering which is not always the case).
1798 * This would work but it is not very portable. Second it would not work
1799 * well in, let's say, a remote X situation in which the amount of 3d
1800 * features which can be used is limited.
1801 *
1802 * As said most games only use the PCI id to get an indication of the
1803 * capabilities of the card. It doesn't really matter if the given id is
1804 * the correct one if we return the id of a card with similar 3d features.
1805 *
1806 * The code below checks the OpenGL capabilities of a videocard and matches
1807 * that to a certain level of Direct3D functionality. Once a card passes
1808 * the Direct3D9 check, we know that the card (in case of Nvidia) is at
1809 * least a GeforceFX. To give a better estimate we do a basic check on the
1810 * renderer string but if that won't pass we return a default card. This
1811 * way is better than maintaining a full card database as even without a
1812 * full database we can return a card with similar features. Second the
1813 * size of the database can be made quite small because when you know what
1814 * type of 3d functionality a card has, you know to which GPU family the
1815 * GPU must belong. Because of this you only have to check a small part of
1816 * the renderer string to distinguishes between different models from that
1817 * family.
1818 *
1819 * The code also selects a default amount of video memory which we will
1820 * use for an estimation of the amount of free texture memory. In case of
1821 * real D3D the amount of texture memory includes video memory and system
1822 * memory (to be specific AGP memory or in case of PCIE TurboCache /
1823 * HyperMemory). We don't know how much system memory can be addressed by
1824 * the system but we can make a reasonable estimation about the amount of
1825 * video memory. If the value is slightly wrong it doesn't matter as we
1826 * didn't include AGP-like memory which makes the amount of addressable
1827 * memory higher and second OpenGL isn't that critical it moves to system
1828 * memory behind our backs if really needed. Note that the amount of video
1829 * memory can be overruled using a registry setting. */
1830
1831 int i;
1832
1833 for (i = 0; i < (sizeof(vendor_card_select_table) / sizeof(*vendor_card_select_table)); ++i)
1834 {
1835 if ((vendor_card_select_table[i].gl_vendor != *gl_vendor)
1836 || (vendor_card_select_table[i].card_vendor != *card_vendor))
1837 continue;
1838 TRACE_(d3d_caps)("Applying card_selector \"%s\".\n", vendor_card_select_table[i].description);
1839 return vendor_card_select_table[i].select_card(gl_info, gl_renderer, vidmem);
1840 }
1841
1842 FIXME_(d3d_caps)("No card selector available for GL vendor %d and card vendor %04x.\n",
1843 *gl_vendor, *card_vendor);
1844
1845 /* Default to generic Nvidia hardware based on the supported OpenGL extensions. The choice
1846 * for Nvidia was because the hardware and drivers they make are of good quality. This makes
1847 * them a good generic choice. */
1848 *card_vendor = HW_VENDOR_NVIDIA;
1849#ifndef VBOX_WITH_WDDM
1850 if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCEFX_5600;
1851#else
1852 /* tmp work around to disable quirk_no_np2 quirk for not-recognized drivers */
1853 if (WINE_D3D9_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE_6200;
1854#endif
1855
1856 if (WINE_D3D8_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE3;
1857 if (WINE_D3D7_CAPABLE(gl_info)) return CARD_NVIDIA_GEFORCE;
1858 if (WINE_D3D6_CAPABLE(gl_info)) return CARD_NVIDIA_RIVA_TNT;
1859 return CARD_NVIDIA_RIVA_128;
1860}
1861
1862#ifndef VBOX_WITH_VMSVGA
1863static const struct fragment_pipeline *select_fragment_implementation(struct wined3d_adapter *adapter)
1864{
1865 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
1866 int vs_selected_mode, ps_selected_mode;
1867
1868 select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
1869 if ((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL)
1870 && gl_info->supported[ARB_FRAGMENT_PROGRAM]) return &arbfp_fragment_pipeline;
1871 else if (ps_selected_mode == SHADER_ATI) return &atifs_fragment_pipeline;
1872 else if (gl_info->supported[NV_REGISTER_COMBINERS]
1873 && gl_info->supported[NV_TEXTURE_SHADER2]) return &nvts_fragment_pipeline;
1874 else if (gl_info->supported[NV_REGISTER_COMBINERS]) return &nvrc_fragment_pipeline;
1875 else return &ffp_fragment_pipeline;
1876}
1877#endif
1878
1879static const shader_backend_t *select_shader_backend(struct wined3d_adapter *adapter)
1880{
1881 int vs_selected_mode, ps_selected_mode;
1882
1883 select_shader_mode(&adapter->gl_info, &ps_selected_mode, &vs_selected_mode);
1884 if (vs_selected_mode == SHADER_GLSL || ps_selected_mode == SHADER_GLSL) return &glsl_shader_backend;
1885#ifndef VBOX_WITH_VMSVGA
1886 if (vs_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_ARB) return &arb_program_shader_backend;
1887#endif
1888 return &none_shader_backend;
1889}
1890
1891#ifndef VBOX_WITH_VMSVGA
1892static const struct blit_shader *select_blit_implementation(struct wined3d_adapter *adapter)
1893{
1894 const struct wined3d_gl_info *gl_info = &adapter->gl_info;
1895 int vs_selected_mode, ps_selected_mode;
1896
1897 select_shader_mode(gl_info, &ps_selected_mode, &vs_selected_mode);
1898 if ((ps_selected_mode == SHADER_ARB || ps_selected_mode == SHADER_GLSL)
1899 && gl_info->supported[ARB_FRAGMENT_PROGRAM]) return &arbfp_blit;
1900 else return &ffp_blit;
1901}
1902#endif
1903
1904/* Context activation is done by the caller. */
1905BOOL IWineD3DImpl_FillGLCaps(struct wined3d_adapter *adapter)
1906{
1907 struct wined3d_driver_info *driver_info = &adapter->driver_info;
1908 struct wined3d_gl_info *gl_info = &adapter->gl_info;
1909 const char *GL_Extensions = NULL;
1910 const char *WGL_Extensions = NULL;
1911 const char *gl_vendor_str, *gl_renderer_str, *gl_version_str;
1912 struct fragment_caps fragment_caps;
1913 enum wined3d_gl_vendor gl_vendor;
1914 enum wined3d_pci_vendor card_vendor;
1915 enum wined3d_pci_device device;
1916 GLint gl_max;
1917 GLfloat gl_floatv[2];
1918 unsigned i;
1919 HDC hdc;
1920 unsigned int vidmem=0;
1921 DWORD gl_version;
1922 size_t len;
1923
1924 TRACE_(d3d_caps)("(%p)\n", gl_info);
1925
1926 ENTER_GL();
1927
1928 gl_renderer_str = (const char *)glGetString(GL_RENDERER);
1929 TRACE_(d3d_caps)("GL_RENDERER: %s.\n", debugstr_a(gl_renderer_str));
1930 if (!gl_renderer_str)
1931 {
1932 LEAVE_GL();
1933 ERR_(d3d_caps)("Received a NULL GL_RENDERER.\n");
1934 return FALSE;
1935 }
1936
1937 gl_vendor_str = (const char *)glGetString(GL_VENDOR);
1938 TRACE_(d3d_caps)("GL_VENDOR: %s.\n", debugstr_a(gl_vendor_str));
1939 if (!gl_vendor_str)
1940 {
1941 LEAVE_GL();
1942 ERR_(d3d_caps)("Received a NULL GL_VENDOR.\n");
1943 return FALSE;
1944 }
1945
1946 /* Parse the GL_VERSION field into major and minor information */
1947 gl_version_str = (const char *)glGetString(GL_VERSION);
1948 TRACE_(d3d_caps)("GL_VERSION: %s.\n", debugstr_a(gl_version_str));
1949 if (!gl_version_str)
1950 {
1951 LEAVE_GL();
1952 ERR_(d3d_caps)("Received a NULL GL_VERSION.\n");
1953 return FALSE;
1954 }
1955 gl_version = wined3d_parse_gl_version(gl_version_str);
1956
1957 /*
1958 * Initialize openGL extension related variables
1959 * with Default values
1960 */
1961 memset(gl_info->supported, 0, sizeof(gl_info->supported));
1962 gl_info->limits.blends = 1;
1963 gl_info->limits.buffers = 1;
1964 gl_info->limits.textures = 1;
1965 gl_info->limits.fragment_samplers = 1;
1966 gl_info->limits.vertex_samplers = 0;
1967 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers + gl_info->limits.vertex_samplers;
1968 gl_info->limits.sampler_stages = 1;
1969 gl_info->limits.glsl_vs_float_constants = 0;
1970 gl_info->limits.glsl_ps_float_constants = 0;
1971 gl_info->limits.arb_vs_float_constants = 0;
1972 gl_info->limits.arb_vs_native_constants = 0;
1973 gl_info->limits.arb_vs_instructions = 0;
1974 gl_info->limits.arb_vs_temps = 0;
1975 gl_info->limits.arb_ps_float_constants = 0;
1976 gl_info->limits.arb_ps_local_constants = 0;
1977 gl_info->limits.arb_ps_instructions = 0;
1978 gl_info->limits.arb_ps_temps = 0;
1979
1980 /* Retrieve opengl defaults */
1981 glGetIntegerv(GL_MAX_CLIP_PLANES, &gl_max);
1982 gl_info->limits.clipplanes = min(WINED3DMAXUSERCLIPPLANES, gl_max);
1983 TRACE_(d3d_caps)("ClipPlanes support - num Planes=%d\n", gl_max);
1984
1985 glGetIntegerv(GL_MAX_LIGHTS, &gl_max);
1986 gl_info->limits.lights = gl_max;
1987 TRACE_(d3d_caps)("Lights support - max lights=%d\n", gl_max);
1988
1989 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_max);
1990 gl_info->limits.texture_size = gl_max;
1991 TRACE_(d3d_caps)("Maximum texture size support - max texture size=%d\n", gl_max);
1992
1993 glGetFloatv(GL_ALIASED_POINT_SIZE_RANGE, gl_floatv);
1994 gl_info->limits.pointsize_min = gl_floatv[0];
1995 gl_info->limits.pointsize_max = gl_floatv[1];
1996 TRACE_(d3d_caps)("Maximum point size support - max point size=%f\n", gl_floatv[1]);
1997
1998 /* Parse the gl supported features, in theory enabling parts of our code appropriately. */
1999 GL_Extensions = (const char *)glGetString(GL_EXTENSIONS);
2000 if (!GL_Extensions)
2001 {
2002 LEAVE_GL();
2003 ERR_(d3d_caps)("Received a NULL GL_EXTENSIONS.\n");
2004 return FALSE;
2005 }
2006
2007 LEAVE_GL();
2008
2009 TRACE_(d3d_caps)("GL_Extensions reported:\n");
2010
2011 gl_info->supported[WINED3D_GL_EXT_NONE] = TRUE;
2012
2013 gl_info->supported[VBOX_SHARED_CONTEXTS] = TRUE;
2014
2015 while (*GL_Extensions)
2016 {
2017 const char *start;
2018 char current_ext[256];
2019
2020 while (isspace(*GL_Extensions)) ++GL_Extensions;
2021 start = GL_Extensions;
2022 while (!isspace(*GL_Extensions) && *GL_Extensions) ++GL_Extensions;
2023
2024 len = GL_Extensions - start;
2025 if (!len || len >= sizeof(current_ext)) continue;
2026
2027 memcpy(current_ext, start, len);
2028 current_ext[len] = '\0';
2029 TRACE_(d3d_caps)("- %s\n", debugstr_a(current_ext));
2030
2031 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
2032 {
2033 if (!strcmp(current_ext, EXTENSION_MAP[i].extension_string))
2034 {
2035 TRACE_(d3d_caps)(" FOUND: %s support.\n", EXTENSION_MAP[i].extension_string);
2036 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
2037 break;
2038 }
2039 }
2040 }
2041
2042#ifdef VBOX_WITH_VMSVGA
2043# ifdef RT_OS_WINDOWS
2044# define OGLGETPROCADDRESS wglGetProcAddress
2045# elif RT_OS_DARWIN
2046extern void (*MyNSGLGetProcAddress(const char *name))(void);
2047# define OGLGETPROCADDRESS MyNSGLGetProcAddress
2048# else
2049extern void (*glXGetProcAddress(const GLubyte *procname))( void );
2050# define OGLGETPROCADDRESS(x) glXGetProcAddress((const GLubyte *)x)
2051# endif
2052#endif
2053
2054 /* Now work out what GL support this card really has */
2055#define USE_GL_FUNC(type, pfn, ext, replace) \
2056{ \
2057 DWORD ver = ver_for_ext(ext); \
2058 if (gl_info->supported[ext]) gl_info->pfn = (type)OGLGETPROCADDRESS(#pfn); \
2059 else if (ver && ver <= gl_version) gl_info->pfn = (type)OGLGETPROCADDRESS(#replace); \
2060 else gl_info->pfn = NULL; \
2061}
2062 GL_EXT_FUNCS_GEN;
2063#undef USE_GL_FUNC
2064
2065#ifndef VBOX_WITH_VMSVGA
2066#define USE_GL_FUNC(type, pfn, ext, replace) gl_info->pfn = (type)OGLGETPROCADDRESS(#pfn);
2067 WGL_EXT_FUNCS_GEN;
2068#undef USE_GL_FUNC
2069#endif
2070
2071 ENTER_GL();
2072
2073 /* Now mark all the extensions supported which are included in the opengl core version. Do this *after*
2074 * loading the functions, otherwise the code above will load the extension entry points instead of the
2075 * core functions, which may not work. */
2076 for (i = 0; i < (sizeof(EXTENSION_MAP) / sizeof(*EXTENSION_MAP)); ++i)
2077 {
2078 if (!gl_info->supported[EXTENSION_MAP[i].extension]
2079 && EXTENSION_MAP[i].version <= gl_version && EXTENSION_MAP[i].version)
2080 {
2081 TRACE_(d3d_caps)(" GL CORE: %s support.\n", EXTENSION_MAP[i].extension_string);
2082 gl_info->supported[EXTENSION_MAP[i].extension] = TRUE;
2083 }
2084 }
2085
2086 if (gl_info->supported[APPLE_FENCE])
2087 {
2088 /* GL_NV_fence and GL_APPLE_fence provide the same functionality basically.
2089 * The apple extension interacts with some other apple exts. Disable the NV
2090 * extension if the apple one is support to prevent confusion in other parts
2091 * of the code. */
2092 gl_info->supported[NV_FENCE] = FALSE;
2093 }
2094 if (gl_info->supported[APPLE_FLOAT_PIXELS])
2095 {
2096 /* GL_APPLE_float_pixels == GL_ARB_texture_float + GL_ARB_half_float_pixel
2097 *
2098 * The enums are the same:
2099 * GL_RGBA16F_ARB = GL_RGBA_FLOAT16_APPLE = 0x881A
2100 * GL_RGB16F_ARB = GL_RGB_FLOAT16_APPLE = 0x881B
2101 * GL_RGBA32F_ARB = GL_RGBA_FLOAT32_APPLE = 0x8814
2102 * GL_RGB32F_ARB = GL_RGB_FLOAT32_APPLE = 0x8815
2103 * GL_HALF_FLOAT_ARB = GL_HALF_APPLE = 0x140B
2104 */
2105 if (!gl_info->supported[ARB_TEXTURE_FLOAT])
2106 {
2107 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_texture_float support(from GL_APPLE_float_pixels.\n");
2108 gl_info->supported[ARB_TEXTURE_FLOAT] = TRUE;
2109 }
2110 if (!gl_info->supported[ARB_HALF_FLOAT_PIXEL])
2111 {
2112 TRACE_(d3d_caps)(" IMPLIED: GL_ARB_half_float_pixel support(from GL_APPLE_float_pixels.\n");
2113 gl_info->supported[ARB_HALF_FLOAT_PIXEL] = TRUE;
2114 }
2115 }
2116 if (gl_info->supported[ARB_MAP_BUFFER_RANGE])
2117 {
2118 /* GL_ARB_map_buffer_range and GL_APPLE_flush_buffer_range provide the same
2119 * functionality. Prefer the ARB extension */
2120 gl_info->supported[APPLE_FLUSH_BUFFER_RANGE] = FALSE;
2121 }
2122 if (gl_info->supported[ARB_TEXTURE_CUBE_MAP])
2123 {
2124 TRACE_(d3d_caps)(" IMPLIED: NVIDIA (NV) Texture Gen Reflection support.\n");
2125 gl_info->supported[NV_TEXGEN_REFLECTION] = TRUE;
2126 }
2127 if (!gl_info->supported[ARB_DEPTH_CLAMP] && gl_info->supported[NV_DEPTH_CLAMP])
2128 {
2129 TRACE_(d3d_caps)(" IMPLIED: ARB_depth_clamp support (by NV_depth_clamp).\n");
2130 gl_info->supported[ARB_DEPTH_CLAMP] = TRUE;
2131 }
2132 if (!gl_info->supported[ARB_VERTEX_ARRAY_BGRA] && gl_info->supported[EXT_VERTEX_ARRAY_BGRA])
2133 {
2134 TRACE_(d3d_caps)(" IMPLIED: ARB_vertex_array_bgra support (by EXT_vertex_array_bgra).\n");
2135 gl_info->supported[ARB_VERTEX_ARRAY_BGRA] = TRUE;
2136 }
2137 if (gl_info->supported[NV_TEXTURE_SHADER2])
2138 {
2139 if (gl_info->supported[NV_REGISTER_COMBINERS])
2140 {
2141 /* Also disable ATI_FRAGMENT_SHADER if register combiners and texture_shader2
2142 * are supported. The nv extensions provide the same functionality as the
2143 * ATI one, and a bit more(signed pixelformats). */
2144 gl_info->supported[ATI_FRAGMENT_SHADER] = FALSE;
2145 }
2146 }
2147
2148 if (gl_info->supported[NV_REGISTER_COMBINERS])
2149 {
2150 glGetIntegerv(GL_MAX_GENERAL_COMBINERS_NV, &gl_max);
2151 gl_info->limits.general_combiners = gl_max;
2152 TRACE_(d3d_caps)("Max general combiners: %d.\n", gl_max);
2153 }
2154 if (gl_info->supported[ARB_DRAW_BUFFERS])
2155 {
2156 glGetIntegerv(GL_MAX_DRAW_BUFFERS_ARB, &gl_max);
2157 gl_info->limits.buffers = gl_max;
2158 TRACE_(d3d_caps)("Max draw buffers: %u.\n", gl_max);
2159 }
2160 if (gl_info->supported[ARB_MULTITEXTURE])
2161 {
2162 glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max);
2163 gl_info->limits.textures = min(MAX_TEXTURES, gl_max);
2164 TRACE_(d3d_caps)("Max textures: %d.\n", gl_info->limits.textures);
2165
2166 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2167 {
2168 GLint tmp;
2169 glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2170 gl_info->limits.fragment_samplers = min(MAX_FRAGMENT_SAMPLERS, tmp);
2171 }
2172 else
2173 {
2174 gl_info->limits.fragment_samplers = max(gl_info->limits.fragment_samplers, gl_max);
2175 }
2176 TRACE_(d3d_caps)("Max fragment samplers: %d.\n", gl_info->limits.fragment_samplers);
2177
2178 if (gl_info->supported[ARB_VERTEX_SHADER])
2179 {
2180 GLint tmp;
2181 glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2182 gl_info->limits.vertex_samplers = tmp;
2183 glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, &tmp);
2184 gl_info->limits.combined_samplers = tmp;
2185
2186 /* Loading GLSL sampler uniforms is much simpler if we can assume that the sampler setup
2187 * is known at shader link time. In a vertex shader + pixel shader combination this isn't
2188 * an issue because then the sampler setup only depends on the two shaders. If a pixel
2189 * shader is used with fixed function vertex processing we're fine too because fixed function
2190 * vertex processing doesn't use any samplers. If fixed function fragment processing is
2191 * used we have to make sure that all vertex sampler setups are valid together with all
2192 * possible fixed function fragment processing setups. This is true if vsamplers + MAX_TEXTURES
2193 * <= max_samplers. This is true on all d3d9 cards that support vtf(gf 6 and gf7 cards).
2194 * dx9 radeon cards do not support vertex texture fetch. DX10 cards have 128 samplers, and
2195 * dx9 is limited to 8 fixed function texture stages and 4 vertex samplers. DX10 does not have
2196 * a fixed function pipeline anymore.
2197 *
2198 * So this is just a check to check that our assumption holds true. If not, write a warning
2199 * and reduce the number of vertex samplers or probably disable vertex texture fetch. */
2200 if (gl_info->limits.vertex_samplers && gl_info->limits.combined_samplers < 12
2201 && MAX_TEXTURES + gl_info->limits.vertex_samplers > gl_info->limits.combined_samplers)
2202 {
2203 FIXME("OpenGL implementation supports %u vertex samplers and %u total samplers.\n",
2204 gl_info->limits.vertex_samplers, gl_info->limits.combined_samplers);
2205 FIXME("Expected vertex samplers + MAX_TEXTURES(=8) > combined_samplers.\n");
2206 if (gl_info->limits.combined_samplers > MAX_TEXTURES)
2207 gl_info->limits.vertex_samplers = gl_info->limits.combined_samplers - MAX_TEXTURES;
2208 else
2209 gl_info->limits.vertex_samplers = 0;
2210 }
2211 }
2212 else
2213 {
2214 gl_info->limits.combined_samplers = gl_info->limits.fragment_samplers;
2215 }
2216 TRACE_(d3d_caps)("Max vertex samplers: %u.\n", gl_info->limits.vertex_samplers);
2217 TRACE_(d3d_caps)("Max combined samplers: %u.\n", gl_info->limits.combined_samplers);
2218 }
2219 if (gl_info->supported[ARB_VERTEX_BLEND])
2220 {
2221 glGetIntegerv(GL_MAX_VERTEX_UNITS_ARB, &gl_max);
2222 gl_info->limits.blends = gl_max;
2223 TRACE_(d3d_caps)("Max blends: %u.\n", gl_info->limits.blends);
2224 }
2225 if (gl_info->supported[EXT_TEXTURE3D])
2226 {
2227 glGetIntegerv(GL_MAX_3D_TEXTURE_SIZE_EXT, &gl_max);
2228 gl_info->limits.texture3d_size = gl_max;
2229 TRACE_(d3d_caps)("Max texture3D size: %d.\n", gl_info->limits.texture3d_size);
2230 }
2231 if (gl_info->supported[EXT_TEXTURE_FILTER_ANISOTROPIC])
2232 {
2233 glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &gl_max);
2234 gl_info->limits.anisotropy = gl_max;
2235 TRACE_(d3d_caps)("Max anisotropy: %d.\n", gl_info->limits.anisotropy);
2236 }
2237 if (gl_info->supported[ARB_FRAGMENT_PROGRAM])
2238 {
2239 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2240 gl_info->limits.arb_ps_float_constants = gl_max;
2241 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM float constants: %d.\n", gl_info->limits.arb_ps_float_constants);
2242 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2243 gl_info->limits.arb_ps_native_constants = gl_max;
2244 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native float constants: %d.\n",
2245 gl_info->limits.arb_ps_native_constants);
2246 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2247 gl_info->limits.arb_ps_temps = gl_max;
2248 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_ps_temps);
2249 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2250 gl_info->limits.arb_ps_instructions = gl_max;
2251 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM native instructions: %d.\n", gl_info->limits.arb_ps_instructions);
2252 GL_EXTCALL(glGetProgramivARB(GL_FRAGMENT_PROGRAM_ARB, GL_MAX_PROGRAM_LOCAL_PARAMETERS_ARB, &gl_max));
2253 gl_info->limits.arb_ps_local_constants = gl_max;
2254 TRACE_(d3d_caps)("Max ARB_FRAGMENT_PROGRAM local parameters: %d.\n", gl_info->limits.arb_ps_instructions);
2255 }
2256 if (gl_info->supported[ARB_VERTEX_PROGRAM])
2257 {
2258 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_ENV_PARAMETERS_ARB, &gl_max));
2259 gl_info->limits.arb_vs_float_constants = gl_max;
2260 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM float constants: %d.\n", gl_info->limits.arb_vs_float_constants);
2261 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_PARAMETERS_ARB, &gl_max));
2262 gl_info->limits.arb_vs_native_constants = gl_max;
2263 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native float constants: %d.\n",
2264 gl_info->limits.arb_vs_native_constants);
2265 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_TEMPORARIES_ARB, &gl_max));
2266 gl_info->limits.arb_vs_temps = gl_max;
2267 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native temporaries: %d.\n", gl_info->limits.arb_vs_temps);
2268 GL_EXTCALL(glGetProgramivARB(GL_VERTEX_PROGRAM_ARB, GL_MAX_PROGRAM_NATIVE_INSTRUCTIONS_ARB, &gl_max));
2269 gl_info->limits.arb_vs_instructions = gl_max;
2270 TRACE_(d3d_caps)("Max ARB_VERTEX_PROGRAM native instructions: %d.\n", gl_info->limits.arb_vs_instructions);
2271#ifndef VBOX_WITH_VMSVGA
2272 if (test_arb_vs_offset_limit(gl_info)) gl_info->quirks |= WINED3D_QUIRK_ARB_VS_OFFSET_LIMIT;
2273#endif
2274 }
2275 if (gl_info->supported[ARB_VERTEX_SHADER])
2276 {
2277 glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, &gl_max);
2278 gl_info->limits.glsl_vs_float_constants = gl_max / 4;
2279#ifdef VBOX_WITH_WDDM
2280 /* AFAICT the " / 4" here comes from that we're going to use the glsl_vs/ps_float_constants to create vec4 arrays,
2281 * thus each array element has 4 components, so the actual number of vec4 arrays is GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2282 * win8 Aero won't properly work with this constant < 256 in any way,
2283 * while Intel drivers I've encountered this problem with supports vec4 arrays of size > GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2284 * so use it here.
2285 * @todo: add logging
2286 * @todo: perhaps should be movet to quirks?
2287 * */
2288 if (gl_info->limits.glsl_vs_float_constants < 256 && gl_max >= 256)
2289 {
2290 DWORD dwVersion = GetVersion();
2291 DWORD dwMajor = (DWORD)(LOBYTE(LOWORD(dwVersion)));
2292 DWORD dwMinor = (DWORD)(HIBYTE(LOWORD(dwVersion)));
2293 /* tmp workaround Win8 Aero requirement for 256 */
2294 if (dwMajor > 6 || dwMinor > 1)
2295 {
2296 gl_info->limits.glsl_vs_float_constants = 256;
2297 }
2298 }
2299#endif
2300 TRACE_(d3d_caps)("Max ARB_VERTEX_SHADER float constants: %u.\n", gl_info->limits.glsl_vs_float_constants);
2301 }
2302 if (gl_info->supported[ARB_FRAGMENT_SHADER])
2303 {
2304 glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, &gl_max);
2305 gl_info->limits.glsl_ps_float_constants = gl_max / 4;
2306#ifdef VBOX_WITH_WDDM
2307 /* AFAICT the " / 4" here comes from that we're going to use the glsl_vs/ps_float_constants to create vec4 arrays,
2308 * thus each array element has 4 components, so the actual number of vec4 arrays is GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2309 * win8 Aero won't properly work with this constant < 256 in any way,
2310 * while Intel drivers I've encountered this problem with supports vec4 arrays of size > GL_MAX_VERTEX/FRAGMENT_UNIFORM_COMPONENTS_ARB / 4
2311 * so use it here.
2312 * @todo: add logging
2313 * @todo: perhaps should be movet to quirks?
2314 * */
2315 if (gl_info->limits.glsl_ps_float_constants < 256 && gl_max >= 256)
2316 {
2317 DWORD dwVersion = GetVersion();
2318 DWORD dwMajor = (DWORD)(LOBYTE(LOWORD(dwVersion)));
2319 DWORD dwMinor = (DWORD)(HIBYTE(LOWORD(dwVersion)));
2320 /* tmp workaround Win8 Aero requirement for 256 */
2321 if (dwMajor > 6 || dwMinor > 1)
2322 {
2323 gl_info->limits.glsl_ps_float_constants = 256;
2324 }
2325 }
2326#endif
2327 TRACE_(d3d_caps)("Max ARB_FRAGMENT_SHADER float constants: %u.\n", gl_info->limits.glsl_ps_float_constants);
2328 glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, &gl_max);
2329 gl_info->limits.glsl_varyings = gl_max;
2330 TRACE_(d3d_caps)("Max GLSL varyings: %u (%u 4 component varyings).\n", gl_max, gl_max / 4);
2331 }
2332 if (gl_info->supported[ARB_SHADING_LANGUAGE_100])
2333 {
2334 const char *str = (const char *)glGetString(GL_SHADING_LANGUAGE_VERSION_ARB);
2335 unsigned int major, minor;
2336
2337 TRACE_(d3d_caps)("GLSL version string: %s.\n", debugstr_a(str));
2338
2339 /* The format of the GLSL version string is "major.minor[.release] [vendor info]". */
2340 sscanf(str, "%u.%u", &major, &minor);
2341 gl_info->glsl_version = MAKEDWORD_VERSION(major, minor);
2342 }
2343 if (gl_info->supported[NV_LIGHT_MAX_EXPONENT])
2344 {
2345 glGetFloatv(GL_MAX_SHININESS_NV, &gl_info->limits.shininess);
2346 }
2347 else
2348 {
2349 gl_info->limits.shininess = 128.0f;
2350 }
2351 if (gl_info->supported[ARB_TEXTURE_NON_POWER_OF_TWO])
2352 {
2353 /* If we have full NP2 texture support, disable
2354 * GL_ARB_texture_rectangle because we will never use it.
2355 * This saves a few redundant glDisable calls. */
2356 gl_info->supported[ARB_TEXTURE_RECTANGLE] = FALSE;
2357 }
2358 if (gl_info->supported[ATI_FRAGMENT_SHADER])
2359 {
2360 /* Disable NV_register_combiners and fragment shader if this is supported.
2361 * generally the NV extensions are preferred over the ATI ones, and this
2362 * extension is disabled if register_combiners and texture_shader2 are both
2363 * supported. So we reach this place only if we have incomplete NV dxlevel 8
2364 * fragment processing support. */
2365 gl_info->supported[NV_REGISTER_COMBINERS] = FALSE;
2366 gl_info->supported[NV_REGISTER_COMBINERS2] = FALSE;
2367 gl_info->supported[NV_TEXTURE_SHADER] = FALSE;
2368 gl_info->supported[NV_TEXTURE_SHADER2] = FALSE;
2369 }
2370 if (gl_info->supported[NV_HALF_FLOAT])
2371 {
2372 /* GL_ARB_half_float_vertex is a subset of GL_NV_half_float. */
2373 gl_info->supported[ARB_HALF_FLOAT_VERTEX] = TRUE;
2374 }
2375 if (gl_info->supported[ARB_POINT_SPRITE])
2376 {
2377 gl_info->limits.point_sprite_units = gl_info->limits.textures;
2378 }
2379 else
2380 {
2381 gl_info->limits.point_sprite_units = 0;
2382 }
2383#ifndef VBOX_WITH_VMSVGA
2384 checkGLcall("extension detection");
2385#endif
2386 LEAVE_GL();
2387
2388#ifndef VBOX_WITH_VMSVGA
2389 adapter->fragment_pipe = select_fragment_implementation(adapter);
2390#endif
2391 adapter->shader_backend = select_shader_backend(adapter);
2392#ifndef VBOX_WITH_VMSVGA
2393 adapter->blitter = select_blit_implementation(adapter);
2394
2395 adapter->fragment_pipe->get_caps(gl_info, &fragment_caps);
2396 gl_info->limits.texture_stages = fragment_caps.MaxTextureBlendStages;
2397 TRACE_(d3d_caps)("Max texture stages: %u.\n", gl_info->limits.texture_stages);
2398
2399 /* In some cases the number of texture stages can be larger than the number
2400 * of samplers. The GF4 for example can use only 2 samplers (no fragment
2401 * shaders), but 8 texture stages (register combiners). */
2402 gl_info->limits.sampler_stages = max(gl_info->limits.fragment_samplers, gl_info->limits.texture_stages);
2403#endif
2404
2405 if (gl_info->supported[ARB_FRAMEBUFFER_OBJECT])
2406 {
2407 gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbuffer;
2408 gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbuffer;
2409 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffers;
2410 gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffers;
2411 gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorage;
2412 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisample;
2413 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameteriv;
2414 gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebuffer;
2415 gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebuffer;
2416 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffers;
2417 gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffers;
2418 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatus;
2419 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1D;
2420 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2D;
2421 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3D;
2422 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbuffer;
2423 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameteriv;
2424 gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebuffer;
2425 gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmap;
2426 }
2427 else
2428 {
2429 if (gl_info->supported[EXT_FRAMEBUFFER_OBJECT])
2430 {
2431 gl_info->fbo_ops.glIsRenderbuffer = gl_info->glIsRenderbufferEXT;
2432 gl_info->fbo_ops.glBindRenderbuffer = gl_info->glBindRenderbufferEXT;
2433 gl_info->fbo_ops.glDeleteRenderbuffers = gl_info->glDeleteRenderbuffersEXT;
2434 gl_info->fbo_ops.glGenRenderbuffers = gl_info->glGenRenderbuffersEXT;
2435 gl_info->fbo_ops.glRenderbufferStorage = gl_info->glRenderbufferStorageEXT;
2436 gl_info->fbo_ops.glGetRenderbufferParameteriv = gl_info->glGetRenderbufferParameterivEXT;
2437 gl_info->fbo_ops.glIsFramebuffer = gl_info->glIsFramebufferEXT;
2438 gl_info->fbo_ops.glBindFramebuffer = gl_info->glBindFramebufferEXT;
2439 gl_info->fbo_ops.glDeleteFramebuffers = gl_info->glDeleteFramebuffersEXT;
2440 gl_info->fbo_ops.glGenFramebuffers = gl_info->glGenFramebuffersEXT;
2441 gl_info->fbo_ops.glCheckFramebufferStatus = gl_info->glCheckFramebufferStatusEXT;
2442 gl_info->fbo_ops.glFramebufferTexture1D = gl_info->glFramebufferTexture1DEXT;
2443 gl_info->fbo_ops.glFramebufferTexture2D = gl_info->glFramebufferTexture2DEXT;
2444 gl_info->fbo_ops.glFramebufferTexture3D = gl_info->glFramebufferTexture3DEXT;
2445 gl_info->fbo_ops.glFramebufferRenderbuffer = gl_info->glFramebufferRenderbufferEXT;
2446 gl_info->fbo_ops.glGetFramebufferAttachmentParameteriv = gl_info->glGetFramebufferAttachmentParameterivEXT;
2447 gl_info->fbo_ops.glGenerateMipmap = gl_info->glGenerateMipmapEXT;
2448 }
2449#ifndef VBOX_WITH_VMSVGA
2450 else if (wined3d_settings.offscreen_rendering_mode == ORM_FBO)
2451 {
2452 WARN_(d3d_caps)("Framebuffer objects not supported, falling back to backbuffer offscreen rendering mode.\n");
2453 wined3d_settings.offscreen_rendering_mode = ORM_BACKBUFFER;
2454 }
2455#endif
2456 if (gl_info->supported[EXT_FRAMEBUFFER_BLIT])
2457 {
2458 gl_info->fbo_ops.glBlitFramebuffer = gl_info->glBlitFramebufferEXT;
2459 }
2460 if (gl_info->supported[EXT_FRAMEBUFFER_MULTISAMPLE])
2461 {
2462 gl_info->fbo_ops.glRenderbufferStorageMultisample = gl_info->glRenderbufferStorageMultisampleEXT;
2463 }
2464 }
2465
2466#ifndef VBOX_WITH_VMSVGA
2467 /* MRTs are currently only supported when FBOs are used. */
2468 if (wined3d_settings.offscreen_rendering_mode != ORM_FBO)
2469 {
2470 gl_info->limits.buffers = 1;
2471 }
2472#endif
2473 gl_vendor = wined3d_guess_gl_vendor(gl_info, gl_vendor_str, gl_renderer_str);
2474 card_vendor = wined3d_guess_card_vendor(gl_vendor_str, gl_renderer_str);
2475 TRACE_(d3d_caps)("found GL_VENDOR (%s)->(0x%04x/0x%04x)\n", debugstr_a(gl_vendor_str), gl_vendor, card_vendor);
2476
2477 device = wined3d_guess_card(gl_info, gl_renderer_str, &gl_vendor, &card_vendor, &vidmem);
2478 TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", card_vendor, device);
2479
2480 /* If we have an estimate use it, else default to 64MB; */
2481 if(vidmem)
2482 gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
2483 else
2484 gl_info->vidmem = WINE_DEFAULT_VIDMEM;
2485
2486 gl_info->wrap_lookup[WINED3DTADDRESS_WRAP - WINED3DTADDRESS_WRAP] = GL_REPEAT;
2487 gl_info->wrap_lookup[WINED3DTADDRESS_MIRROR - WINED3DTADDRESS_WRAP] =
2488 gl_info->supported[ARB_TEXTURE_MIRRORED_REPEAT] ? GL_MIRRORED_REPEAT_ARB : GL_REPEAT;
2489 gl_info->wrap_lookup[WINED3DTADDRESS_CLAMP - WINED3DTADDRESS_WRAP] = GL_CLAMP_TO_EDGE;
2490 gl_info->wrap_lookup[WINED3DTADDRESS_BORDER - WINED3DTADDRESS_WRAP] =
2491 gl_info->supported[ARB_TEXTURE_BORDER_CLAMP] ? GL_CLAMP_TO_BORDER_ARB : GL_REPEAT;
2492 gl_info->wrap_lookup[WINED3DTADDRESS_MIRRORONCE - WINED3DTADDRESS_WRAP] =
2493 gl_info->supported[ATI_TEXTURE_MIRROR_ONCE] ? GL_MIRROR_CLAMP_TO_EDGE_ATI : GL_REPEAT;
2494
2495#ifndef VBOX_WITH_VMSVGA
2496 /* Make sure there's an active HDC else the WGL extensions will fail */
2497 hdc = pwglGetCurrentDC();
2498 if (hdc) {
2499 /* Not all GL drivers might offer WGL extensions e.g. VirtualBox */
2500 if(GL_EXTCALL(wglGetExtensionsStringARB))
2501 WGL_Extensions = GL_EXTCALL(wglGetExtensionsStringARB(hdc));
2502
2503 if (NULL == WGL_Extensions) {
2504 ERR(" WGL_Extensions returns NULL\n");
2505 } else {
2506 TRACE_(d3d_caps)("WGL_Extensions reported:\n");
2507 while (*WGL_Extensions != 0x00) {
2508 const char *Start;
2509 char ThisExtn[256];
2510
2511 while (isspace(*WGL_Extensions)) WGL_Extensions++;
2512 Start = WGL_Extensions;
2513 while (!isspace(*WGL_Extensions) && *WGL_Extensions != 0x00) {
2514 WGL_Extensions++;
2515 }
2516
2517 len = WGL_Extensions - Start;
2518 if (len == 0 || len >= sizeof(ThisExtn))
2519 continue;
2520
2521 memcpy(ThisExtn, Start, len);
2522 ThisExtn[len] = '\0';
2523 TRACE_(d3d_caps)("- %s\n", debugstr_a(ThisExtn));
2524
2525 if (!strcmp(ThisExtn, "WGL_ARB_pixel_format")) {
2526 gl_info->supported[WGL_ARB_PIXEL_FORMAT] = TRUE;
2527 TRACE_(d3d_caps)("FOUND: WGL_ARB_pixel_format support\n");
2528 }
2529 if (!strcmp(ThisExtn, "WGL_WINE_pixel_format_passthrough")) {
2530 gl_info->supported[WGL_WINE_PIXEL_FORMAT_PASSTHROUGH] = TRUE;
2531 TRACE_(d3d_caps)("FOUND: WGL_WINE_pixel_format_passthrough support\n");
2532 }
2533 }
2534 }
2535 }
2536#endif
2537
2538 fixup_extensions(gl_info, gl_renderer_str, gl_vendor, card_vendor, device);
2539#ifndef VBOX_WITH_VMSVGA
2540 init_driver_info(driver_info, card_vendor, device);
2541 add_gl_compat_wrappers(gl_info);
2542#endif
2543
2544 return TRUE;
2545}
2546
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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