Search code examples
c#directxdirect3dhardware-acceleration

How to check in code if CPU supports hardware acceleration on C#?


I am building a program which uses a Direct3D object, using Direct3D = Microsoft.DirectX.Direct3D, to render a live stream. I tested it on a Windows 7 machine and the issue is that the CPU does not support Hardware Acceleration. To run the program, I changed the flag when I create the Direct3D object to Direct3D.CreateFlags.SoftwareVertexProcessing, which is fine. I would like to know if there is any way to check if the CPU supports Hardware Acceleration. If so, use Direct3D.CreateFlags.HardwareVertexProcessing and if not, use software. My program will run a different machines, so it would be better this way than to build two programs. The program is written in C# but if you know how to do it in other languages I would appreciate it and I will try to translate in C#.


Solution

  • I don't know if there is a more direct route in C# but in [C++][1] you can check with:

    HRESULT GetDeviceCaps(
      UINT       Adapter,
      D3DDEVTYPE DeviceType,
      D3DCAPS9   *pCaps
    );
    

    [1] https://learn.microsoft.com/en-us/windows/win32/direct3d9/selecting-a-device