From 0844cdc2be0fb4bf1769e97a05a6d6b4ac624ef2 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Stefan=20D=C3=B6singer?= <stefan@codeweavers.com>
Date: Fri, 14 Aug 2009 13:09:26 +0200
Subject: [PATCH 4/4] WineD3D: Use GL_ATI_meminfo if available

---
 dlls/wined3d/directx.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 82e476c..723eb78 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -1957,11 +1957,29 @@ static BOOL IWineD3DImpl_FillGLCaps(struct wined3d_gl_info *gl_info)
     }
     TRACE_(d3d_caps)("FOUND (fake) card: 0x%x (vendor id), 0x%x (device id)\n", gl_info->gl_vendor, gl_info->gl_card);
 
-    /* If we have an estimate use it, else default to 64MB;  */
-    if(vidmem)
-        gl_info->vidmem = vidmem*1024*1024; /* convert from MBs to bytes */
+    /* Use video memory info from GL if available */
+    if(GL_SUPPORT(ATI_MEMINFO))
+    {
+        /* All GL_ATI_meminfo enums return 4 ints, even the (undocumented)
+         * GL_TOTAL_PHYSICAL_MEMORY_ATI one, which returns {mem, 0, 0, 0} */
+        GLint mem[4];
+        /* Returns the vidmem in KB */
+        glGetIntegerv(GL_TOTAL_PHYSICAL_MEMORY_ATI, mem);
+        TRACE("Video memory from OpenGL: %d MB\n", mem[0] / 1024);
+        gl_info->vidmem = mem[0] * 1024; /* convert from KBs to bytes */
+    }
+    else if(vidmem)
+    {
+        /* If we have an estimate use it */
+        gl_info->vidmem = vidmem * 1024 * 1024; /* convert from MBs to bytes */
+        TRACE("Video memory estimate: %d MB\n", vidmem);
+    }
     else
+    {
+        /* Otherwise default to 64MB */
+        TRACE("Default video memory: %d MB\n", WINE_DEFAULT_VIDMEM / (1024 * 1024));
         gl_info->vidmem = WINE_DEFAULT_VIDMEM;
+    }
 
     /* Load all the lookup tables */
     for (i = 0; i < MAX_LOOKUPS; i++) {
-- 
1.6.3.3

