4

I have a task to collect information about GPU in Windows with C++ and I don't know where to start! Any idea?

Update: I want name, vram, dac, manufacturer, version, clock.

update2: If I use win32_videocontroller class, I just got the currently used video card's properties, but I need all video card's properties if there are more.

user3540983
  • 141
  • 1
  • 4
  • 11
  • What sort of information do you need? `GetDeviceCaps` is a really trivial way to get some basic information (e.g., current vertical/horizontal resolution) but it's hard to guess whether that's the sort of information you want or not. – Jerry Coffin Mar 29 '15 at 15:56
  • Name,Vram,DAC,version,manufacturer,clock – user3540983 Mar 29 '15 at 16:00
  • and also how can I determine how many display device in gpu? – user3540983 Mar 29 '15 at 16:03
  • Unfortunately, Windows doesn't provide much support for retrieving all that information. You can get quite a bit of information about an nVidia GPU with [NVML](http://developer.download.nvidia.com/assets/cuda/files/CUDADownloads/NVML/nvml.pdf). Offhand I don't know of a direct analog to that for Intel, AMD, etc., GPUs though. – Jerry Coffin Mar 29 '15 at 16:06
  • Use DirectX caps queries –  Mar 29 '15 at 16:22
  • Can you give directx caps documentation link or some information about it ? :) – user3540983 Mar 29 '15 at 16:26
  • https://msdn.microsoft.com/en-us/library/windows/desktop/bb152827%28v=vs.85%29.aspx – szulak Mar 29 '15 at 16:31
  • 1
    Some of the things you want don't exist, at least not universally. Some GPUs have multiple different clocks. Others don't have fixed-size VRAM. Laptop configurations may conceivably have absolutely no DAC at all, if the display accepts digital data. – Ben Voigt Mar 29 '15 at 18:20
  • 1
    You might consider [OpenCL](https://en.wikipedia.org/wiki/OpenCL) (which might work also outside of Windows; e.g. on Linux) – Basile Starynkevitch Mar 30 '15 at 05:26
  • @BasileStarynkevitch I had a similar problem to solve and I used OpenCL to get the job done. One issue I had though was that in order for the hardware to get detected correctly, I needed my end-user to install OpenCL runtime drivers on their computer, otherwise, on some computers, the detection wouldn't work. I was wondering if there is a better solution that doesn't require a whole library/ecosystem to be installed to just detect the GPUs, CPUs etc. Just fishing for some thoughts or ideas! – Sanket_Diwale Jun 16 '22 at 23:09

2 Answers2

4

You might want to use WMI and Win32_VideoController class.

Win32_VideoController class

szulak
  • 703
  • 7
  • 16
  • I tried it before but it didn't work with AdapterRam and etc. it didnt return the value and it was the same with some others – user3540983 Mar 29 '15 at 16:30
  • [link](https://msdn.microsoft.com/en-us/library/aa390423%28v=vs.85%29.aspx) I use this code and If I request AdapterRam it wont give anything back (ofc I wrote the wql querry to win32_displaycontroller...... – user3540983 Mar 29 '15 at 16:46
  • Are you running your application with admin privileges? It might be required. – szulak Mar 29 '15 at 16:50
  • The link above is actually to the [Win32_VideoController](https://msdn.microsoft.com/en-us/library/aa394512%28v=vs.85%29.aspx) class, not to the obsolete `Win32_DisplayControllerConfiguration` class. – Eryk Sun Mar 29 '15 at 17:59
  • well I got some information from the Win32_VideoController , I only have problems with few which i needed, so you mean when I run my application in VS with admin priv. or should I start the VS as admin? – user3540983 Mar 29 '15 at 20:12
  • @user3540983 if you're running a debug version from the VS, you must restart VS with admin rights. – szulak Mar 29 '15 at 20:15
  • hr = pclsObj->Get(searchParameter, 0, &vtProp, 0, 0); (hr Hresult) and hr is false after it and the searchParameter was AdapterRam and my wql is Select * from Win32_VideoController... I really don't get it why I have problems with specific members of this videocontroller – user3540983 Mar 29 '15 at 20:29
  • What does GetLastError() return after the Get() call? – szulak Mar 29 '15 at 20:30
  • btw how can I get other video card's data, i mean it gives back the currently used video card's properties – user3540983 Mar 29 '15 at 21:22
1

Start with: IDirect3D9::GetAdapterIdentifier

The perhaps: IDXGIAdapter::GetDesc

And if you are on Windows 8: IDXGIAdapter2::GetDesc2 returns some more information

This should at least get you some rudimentary information like name, vendor, and features of the graphics card. Not sure about vram/dac/clock.

selbie
  • 100,020
  • 15
  • 103
  • 173