0

I have a DX11 application to which I would like to add support for software rendering. This is because in some circumstances it will be run on machines without GPUs. From the research I have done, it seems like my best bet is WARP.

It was surprisingly simple to change the app to use WARP:

hr = D3D11CreateDevice(
    NULL, 
    D3D_DRIVER_TYPE_WARP, // was D3D_DRIVER_TYPE_HARDWARE
    NULL,
    creationFlag,
    featureLevels,
    ARRAYSIZE(featureLevels),
    D3D11_SDK_VERSION,
    &mDevice,
    &mFeatureLevel,
    &mDeviceContext
    );

It runs nicely. Where I'm struggling is determining when to set the DriverType to WARP instead of hardware. Is there a function I can call that will tell me if hardware support is available on the system?

I'm using DX 11 feature level 9_1.

Justin R.
  • 23,435
  • 23
  • 108
  • 157

2 Answers2

2

This is how it's done usually: Just try to D3D11CreateDevice() with all parameters you expect as to be fine, including D3D_DRIVER_TYPE_HARDWARE (try different feature levels in the loop, to find out best). If this will fail, roll back to WARP. If WARP will fail, roll back to software, D3D9, GL, etc. If all possible variants will fail, notify user that he needs to upgrade his machine and/or OS =)

Each try you check return code, and device and context pointers. When you found (HRESULT == S_OK) && (device != 0) && (context != 0) - Bingo!

Hope it helps.

Ivan Aksamentov - Drop
  • 12,860
  • 3
  • 34
  • 61
  • Can I ask why I have to check context and the hresult too? – Justin R. Feb 11 '14 at 01:00
  • I don't know if there is any possibility when only one or only two of `HRESULT`, `device` and `context` fail, but I think that it is always a good idea to check *All* of postconditions in the end. Also, it is not specified in docs if failed `device` is always null or not. Also, check all three each iteration, is just simpler to write ([KISS principle](http://en.wikipedia.org/wiki/KISS_principle)). On initialization time additional comparison operations won't do any performance loss (compared to performance of `D3D11CreateDevice()` itself), so "better safe than sorry". – Ivan Aksamentov - Drop Feb 11 '14 at 07:30
0

I think that hardware will drop to software if hardware is not available:

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476328(v=vs.85).aspx

Specifically:

http://msdn.microsoft.com/en-us/library/windows/desktop/ff476082(v=vs.85).aspx

Where it says:

If DriverType == D3D_DRIVER_TYPE_HARDWARE, the adapter used will be the default adapter, which is the first adapter that is enumerated by IDXGIFactory1::EnumAdapters.

Alternatively, if you want to control between WARP or hardware and nothing else, use EnumAdapters to get available adapters:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb174538(v=vs.85).aspx

This gives you more control in case some 3rd party software adapter's installed.

thang
  • 3,466
  • 1
  • 19
  • 31
  • The problem with this is that if Hardware fails, the next driver type is Software, which is way slower than WARP. I like your idea of using EnumAdapters; maybe I can make something work with that. Thank you! – Justin R. Feb 10 '14 at 23:06