locked
CreateRasterizerState triggers exception when feature level 9.x is enforced

    Question

  • My application fails to pass Windows App Cert Kit with failure on Direct3d feature level test. When I debug my app, I find the function call to CreateRasterizerState results in exception if Direct3D feature level is enforced to be 9.1/9.2/9.3.

       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,
           D3D_FEATURE_LEVEL_9_2,
           D3D_FEATURE_LEVEL_9_1
       };
    
       // Create the DX11 API device object, and get a corresponding context.
       ComPtr<ID3D11Device> device;
       ComPtr<ID3D11DeviceContext> context;
       DX::ThrowIfFailed(
          D3D11CreateDevice(
             nullptr,                    // specify null to use the default adapter
             D3D_DRIVER_TYPE_HARDWARE,
             0,                          // leave as 0 unless software device
             creationFlags,              // optionally set debug and Direct2D compatibility flags
             featureLevels,              // list of feature levels this app can support
             ARRAYSIZE(featureLevels),   // number of entries in above list
             D3D11_SDK_VERSION,          // always set this to D3D11_SDK_VERSION for Metro style apps
             &device,                    // returns the Direct3D device created
             &m_featureLevel,            // returns feature level of device created
             &context                    // returns the device immediate context
          )
       );

    CreateRasterizerState succeeds otherwise.

    // in header file
       Microsoft::WRL::ComPtr<ID3D11RasterizerState> m_rasterizerState;
    
    // in implementation file
       // Create rasterizer state
       D3D11_RASTERIZER_DESC rd;
       ZeroMemory(&rd, sizeof(D3D11_RASTERIZER_DESC));
       rd.FillMode = D3D11_FILL_SOLID;
       rd.CullMode = D3D11_CULL_BACK;
       rd.FrontCounterClockwise = TRUE;
       if ( m_featureLevel>=D3D_FEATURE_LEVEL_10_0 )
          DX::ThrowIfFailed(m_d3dDevice->CreateRasterizerState(&rd, m_rasterizerState.GetAddressOf()));
    As a temperary solution, I add a conditional statement for CreateRasterizerState. But what's the best solution?


    • Edited by Leonard Monday, August 27, 2012 12:34 PM
    Monday, August 27, 2012 12:32 PM

Answers

  • You should always check your error codes: it is much easier to provide help if you can provide what error you received as well as where it came from. That said, I expect the problem is that you are setting D3D11_RASTERIZER_DESC.DepthClipEnable to false. This must be TRUE for 9_1 as documented in the list of differences in feature level support for the various methods at 10Level9 ID3D11Device Methods.

    --Rob

    • Marked as answer by Leonard Monday, August 27, 2012 4:22 PM
    Monday, August 27, 2012 3:55 PM
    Moderator

All replies

  • You should always check your error codes: it is much easier to provide help if you can provide what error you received as well as where it came from. That said, I expect the problem is that you are setting D3D11_RASTERIZER_DESC.DepthClipEnable to false. This must be TRUE for 9_1 as documented in the list of differences in feature level support for the various methods at 10Level9 ID3D11Device Methods.

    --Rob

    • Marked as answer by Leonard Monday, August 27, 2012 4:22 PM
    Monday, August 27, 2012 3:55 PM
    Moderator
  • It works. Thanks a lot.
    Monday, August 27, 2012 4:22 PM