首页 > 解决方案 > Visual Basic 查找 GPU 专用内存 NVIDIA 或 AMD

问题描述

我试图在他们的 GPU 上找到用户专用的 RAM。我在网上找到了非常适合使用 WMI 查找不同 GPU 属性的代码,但是没有一个属性会返回诸如“4 GB”之类的专用内存。最接近的是 AdapterRAM,但它返回的数字与我的目的无关。

        Dim arr() As String = Nothing
        Dim int As Integer
        Dim objWMIService As Object
        Dim colDevices As Object
        Dim objDevice As Object
        objWMIService = GetObject("winmgmts:\\.\root\cimv2")
        colDevices = objWMIService.ExecQuery("Select AdapterRAM From Win32_VideoController")

        For Each objDevice In colDevices
            ReDim Preserve arr(int)
            arr(int) = objDevice.AdapterRAM
            int += 1
        Next objDevice

        colDevices = Nothing
        objWMIService = Nothing
        Return arr

是否有任何其他方法、接口等来找到这个用户专用的 GPU 内存。它应该返回类似“4 GB”的东西

标签: vb.netmemorywindows-10gpuwmi

解决方案


其中一种方法是使用 DXGI。例如 :

使用 DXGI 声明:(我无法粘贴它们,太大了...)VB_DXGI.vb =>

Dim hr As HRESULT = HRESULT.E_FAIL
Dim pFactory1 As IDXGIFactory1 = Nothing
Dim IID_IDXGIFactory1 As Guid = New Guid("770AAE78-F26F-4DBA-A829-253C83D1B387")
hr = CreateDXGIFactory1(IID_IDXGIFactory1, pFactory1)
If ((hr = HRESULT.S_OK) And (pFactory1 IsNot Nothing)) Then
    Dim i As Integer = 0
    Dim pAdapter1 As IDXGIAdapter1 = Nothing
    While (pFactory1.EnumAdapters1(CUInt(i), pAdapter1) <> DXGI_ERROR_NOT_FOUND)
        Dim dxAdapterDesc As DXGI_ADAPTER_DESC = New DXGI_ADAPTER_DESC()
        hr = pAdapter1.GetDesc(dxAdapterDesc)
        Console.WriteLine("Adapter Name: {0}", dxAdapterDesc.Description)
        Console.WriteLine("Dedicated Video Memory : {0}", dxAdapterDesc.DedicatedVideoMemory.ToString())
        Console.WriteLine("Shared System Memory : {0}", dxAdapterDesc.SharedSystemMemory.ToString())
        Console.WriteLine("Dedicated System Memory : {0}", dxAdapterDesc.DedicatedSystemMemory.ToString())
        Console.WriteLine("Total Memory : {0}", (dxAdapterDesc.DedicatedVideoMemory + dxAdapterDesc.SharedSystemMemory + dxAdapterDesc.DedicatedSystemMemory).ToString())
        Dim pOutput As IDXGIOutput = Nothing
        Dim j As Integer = 0
        While (pAdapter1.EnumOutputs(CUInt(j), pOutput) <> DXGI_ERROR_NOT_FOUND)
            Dim outputDesc As DXGI_OUTPUT_DESC = New DXGI_OUTPUT_DESC()
            hr = pOutput.GetDesc(outputDesc)
            Console.WriteLine(vbTab + "Device : {0} ({1}, {2}, {3}, {4})", outputDesc.DeviceName, outputDesc.DesktopCoordinates.left, outputDesc.DesktopCoordinates.top, outputDesc.DesktopCoordinates.right, outputDesc.DesktopCoordinates.bottom)
            j += 1
            Marshal.ReleaseComObject(pOutput)
            pOutput = Nothing
        End While
        i += 1
        Marshal.ReleaseComObject(pAdapter1)
        pAdapter1 = Nothing
    End While
    Marshal.ReleaseComObject(pFactory1)
End If  

推荐阅读