Beware of D3D feature level 11 in the Windows Phone emulator

Originally posted to Shawn Hargreaves Blog on MSDN, Tuesday, November 6, 2012

Windows Phone 8 devices support Direct3D 11.1 feature level 9.3, but our emulator uses the WARP rasterizer, which can handle all the way up to feature level 11.  This means that, if you aren't careful, it is possible to accidentally use more advanced D3D features while developing in the emulator, only to get an unpleasant surprise when these things don't work on an actual device.

Q:  how to avoid unpleasant surprises?

A:  make sure you explicitly select feature level 9.3, even when running in the emulator.

Starting with the Windows Phone Direct3D App project template, open up Direct3DBase.cpp, find this code in the CreateDeviceResources method:

    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_11_1,
        D3D_FEATURE_LEVEL_11_0,
        D3D_FEATURE_LEVEL_10_1,
        D3D_FEATURE_LEVEL_10_0,
        D3D_FEATURE_LEVEL_9_3
    };

and change it to:

    D3D_FEATURE_LEVEL featureLevels[] =
    {
        D3D_FEATURE_LEVEL_9_3
    };

Tada!  Now you will be using 9.3 in the emulator, the same as on actual device hardware.

Right above this code, notice how the template turns on D3D11_CREATE_DEVICE_DEBUG only if the _DEBUG define is set?  This enables extra validation to give more useful error messages if you make a mistake in your D3D API usage.  But that validation is not free, so we only enable it in debug builds.

Blog index   -   Back to my homepage