0028466: Visualization, OpenGl_Context - read GPU memory using WGL_AMD_gpu_associatio...
authorkgv <kgv@opencascade.com>
Thu, 16 Feb 2017 21:24:17 +0000 (00:24 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 2 Mar 2017 09:31:57 +0000 (12:31 +0300)
src/OpenGl/OpenGl_Context.cxx
src/OpenGl/OpenGl_GlFunctions.hxx

index 3ca3907..b377c5e 100644 (file)
@@ -1350,6 +1350,12 @@ void OpenGl_Context::init (const Standard_Boolean theIsCoreProfile)
       FindProcShort (wglDXLockObjectsNV);
       FindProcShort (wglDXUnlockObjectsNV);
     }
+    if (CheckExtension (aWglExts, "WGL_AMD_gpu_association"))
+    {
+      FindProcShort (wglGetGPUIDsAMD);
+      FindProcShort (wglGetGPUInfoAMD);
+      FindProcShort (wglGetContextGPUIDAMD);
+    }
   }
 #elif defined(__APPLE__)
     //
@@ -2560,6 +2566,21 @@ void OpenGl_Context::MemoryInfo (TColStd_IndexedDataMapOfStringString& theDict)
       addInfo (theDict, "Total memory", TCollection_AsciiString() + (aValue / 1024) + " MiB");
     }
   }
+#if defined(_WIN32)
+  else if (myFuncs->wglGetGPUInfoAMD != NULL
+        && myFuncs->wglGetContextGPUIDAMD != NULL)
+  {
+    GLuint aTotalMemMiB = 0;
+    UINT anAmdId = myFuncs->wglGetContextGPUIDAMD ((HGLRC )myGContext);
+    if (anAmdId != 0)
+    {
+      if (myFuncs->wglGetGPUInfoAMD (anAmdId, WGL_GPU_RAM_AMD, GL_UNSIGNED_INT, sizeof(aTotalMemMiB), &aTotalMemMiB) > 0)
+      {
+        addInfo (theDict, "GPU memory", TCollection_AsciiString() + (int )aTotalMemMiB + " MiB");
+      }
+    }
+  }
+#endif
 #endif
 
 #if !defined(GL_ES_VERSION_2_0) && !defined(__APPLE__) && !defined(_WIN32)
index 37af470..cfb31ce 100644 (file)
@@ -1641,6 +1641,28 @@ public: //! @name wgl extensions
   #define WGL_ACCESS_WRITE_DISCARD_NV 0x0002
 #endif
 
+  // WGL_AMD_gpu_association
+
+#ifndef WGL_GPU_VENDOR_AMD
+  #define WGL_GPU_VENDOR_AMD                 0x1F00
+  #define WGL_GPU_RENDERER_STRING_AMD        0x1F01
+  #define WGL_GPU_OPENGL_VERSION_STRING_AMD  0x1F02
+  #define WGL_GPU_FASTEST_TARGET_GPUS_AMD    0x21A2
+  #define WGL_GPU_RAM_AMD                    0x21A3
+  #define WGL_GPU_CLOCK_AMD                  0x21A4
+  #define WGL_GPU_NUM_PIPES_AMD              0x21A5
+  #define WGL_GPU_NUM_SIMD_AMD               0x21A6
+  #define WGL_GPU_NUM_RB_AMD                 0x21A7
+  #define WGL_GPU_NUM_SPI_AMD                0x21A8
+#endif
+
+  typedef UINT (WINAPI *wglGetGPUIDsAMD_t       )(UINT theMaxCount, UINT* theIds);
+  typedef INT  (WINAPI *wglGetGPUInfoAMD_t      )(UINT theId, INT theProperty, GLenum theDataType, UINT theSize, void* theData);
+  typedef UINT (WINAPI *wglGetContextGPUIDAMD_t )(HGLRC theHglrc);
+  wglGetGPUIDsAMD_t       wglGetGPUIDsAMD;
+  wglGetGPUInfoAMD_t      wglGetGPUInfoAMD;
+  wglGetContextGPUIDAMD_t wglGetContextGPUIDAMD;
+
 #elif defined(__APPLE__)
 public: //! @name CGL extensions