Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Seongjun_Kim
Beginner
535 Views

DirectX 11 CreateSwapChainForHwnd fails with E_ACCESSDENIED

 

Hello.
I am trying to encode YUV media file to H.264 media file using sample_encode sources in MediaSamples_6.0.0.49 on Windows 8.1. 
Command line is below. I used DirectX11.1 (
D3D_FEATURE_LEVEL_11_1) using -d3d11 option.

sample_encode.exe h264 -i C:\Users\test\Downloads\akiyo_qcif\akiyo_qcif.yuv -o C:\Users\test\Downloads\test.264 -w 176 -h 144 -d3d11 -hw

On the first run, encoding succeeds no problem. But on the second run, encoding failed because IDXGIFactory2::CreateSwapChainForHwnd() returned E_ACCESSDENIED.

d3d11_device.cpp

mfxStatus CD3D11Device::Init(
    mfxHDL hWindow,
    mfxU16 nViews,
    mfxU32 nAdapterNum)
{    
    .....
    // create swap chain only for rendering use case (hWindow != 0)
    if (hWindow)
    {
        MSDK_CHECK_POINTER(m_pDXGIFactory.p, MFX_ERR_NULL_PTR);
        DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};

        sts = FillSCD1(swapChainDesc);
        MSDK_CHECK_RESULT(sts, MFX_ERR_NONE, sts);

        hres = m_pDXGIFactory->CreateSwapChainForHwnd(m_pD3D11Device,
            (HWND)hWindow,
            &swapChainDesc,
            NULL,
            NULL,
            reinterpret_cast<IDXGISwapChain1**>(&m_pSwapChain));
        if (FAILED(hres))
            return MFX_ERR_DEVICE_FAILED;
    }

    return sts;
}

I think that some objects was not being freed on destroy. Please check this.
Thank you.

===============================================================
 

Intel Media SDK System Analyzer (64 bit)


The following versions of Media SDK API are supported by platform/driver:

        Version Target  Supported       Dec     Enc
        1.0     HW      Yes             X       X
        1.0     SW      Yes             X       X
        1.1     HW      Yes             X       X
        1.1     SW      Yes             X       X
        1.3     HW      Yes             X       X
        1.3     SW      Yes             X       X
        1.4     HW      Yes             X       X
        1.4     SW      Yes             X       X
        1.5     HW      Yes             X       X
        1.5     SW      Yes             X       X
        1.6     HW      Yes             X       X
        1.6     SW      Yes             X       X
        1.7     HW      Yes             X       X
        1.7     SW      Yes             X       X
        1.8     HW      Yes             X       X
        1.8     SW      Yes             X       X

Graphics Devices:
        Name                                         Version             State
        Intel(R) HD Graphics 4600                    10.18.14.4170       Active

System info:
        CPU:    Intel(R) Core(TM) i7-4770 CPU @ 3.40GHz
        OS:     Microsoft Windows 8.1 K
        Arch:   64
Installed Media SDK packages (be patient...processing takes some time):

Analysis complete... [press ENTER]

0 Kudos
6 Replies
Surbhi_M_Intel
Employee
535 Views

Hi Seongjun, 

We don't expect to see this issue.We need little more information to understand this issue better- 
1. Which product and version are using-  Are you using INDE-Media SDK Client or Media Server Studio? What is the release no. - Media Server Studio 2015 R6 or INDE 2015 Gold U2? 

2. Can you please send us the tracer logs to see whats happening wrong. Tracer logs captures the Media SDK API calls. You can find info about this tool and how to use it in <installed folder>\tools\mediasdk_tracer

3. Can you please update the driver and check, though the one you are using are not too old. But it is of best interest to use the latest one. With every driver release, we fix lot of issues. 

4. Can you test the same scenario with d3d9 option and confirm if you can replicate the issue. This is just to understand if the issue exists only for d3d11 surfaces. 

5. Are you giving any sleep period between two encode sessions or is it back to back? We have tested back to back encode sessions and have not seen this issue. 

Please let us know your findings. 

Thanks,
Surbhi

Seongjun_Kim
Beginner
535 Views

1. Which product and version are using-  Are you using INDE-Media SDK Client or Media Server Studio? What is the release no. - Media Server Studio 2015 R6 or INDE 2015 Gold U2? 

==> I use Intel Media SDK 6.0.0.349 and MediaSamples 6.0.0.49 included in INDE 2015.2.027.

2. Can you please send us the tracer logs to see whats happening wrong. Tracer logs captures the Media SDK API calls. You can find info about this tool and how to use it in <installed folder>\tools\mediasdk_tracer

==> I attached tracer log files. (tracer_first_turn__success.log, tracer_second_turn__accessdenied.log)

3. Can you please update the driver and check, though the one you are using are not too old. But it is of best interest to use the latest one. With every driver release, we fix lot of issues. 

==> I use win64_153621 version for Windows8.1. (https://downloadcenter.intel.com/download/24964)

4. Can you test the same scenario with d3d9 option and confirm if you can replicate the issue. This is just to understand if the issue exists only for d3d11 surfaces. 

==> I tried encoding test two times using same command line replaced d3d11 option of d3d9 option. All the test result in SUCCESS.
samle_encode.exe h264 -i C:\Users\withsmilo\Downloads\akiyo_qcif\akiyo_qcif.yuv -o C:\Users\withsmilo\Downloads\smilo.264 -w 176 -h 144 -d3d9 -hw

5. Are you giving any sleep period between two encode sessions or is it back to back? We have tested back to back encode sessions and have not seen this issue. 

==> I gave 1min, 10min, 30min sleep period between continuous tests, first test results in success ONLY. Other tests result in FAILED.

 

I built sample_encode sources on x64 debug mode using Visual Studio 2013.
After debugging it, I found that IDXGIFactory2::CreateSwapChainForHwnd() returned E_ACCESSDENIED,
I think that error point is not Media SDK API but d3d11_device.cpp source in which some objects was not being freed on destroy.

I tried to encode it with D3D11 option on "CLEAN" Windows8.1+INDE+Driver, but still first run success and second run failed. :(

Thank you! :)

Surbhi_M_Intel
Employee
535 Views

Hi Seongjun, 

So far we are not able to reproduce this issue, so I am discussing this issue with experts and we are suspecting this to be sample issue. Thanks for reporting the behavior. Can you please confirm are you using any discrete graphics card present in addition to Intel Integrated graphics card.

Thanks,
Surbhi 

Seongjun_Kim
Beginner
535 Views

Hello SURBHI,

Thank you for your reply! I think that sample codes have a bug, too.
I use Intel(R) HD Graphics 4600 ONLY as display adapter, and do not use any other graphics cards in my computer.

Thanks.

Seongjun_Kim
Beginner
535 Views

I found why sample codes generate E_ACCESSDENIED error.

* Test scenario

  1. I built sample_encode sources on x64 debug mode using Visual Studio 2013.
  2. Encoding test using sample_encode.exe binary file succeeds ALWAYS no problem.
  3. Next, I will stop sample_encode's operation during its initialization step.
  4. I add a breakpoint to the line below CreateSwapChainForHwnd() on d3d11_device.cpp (148 line) file.
    hres = m_pDXGIFactory->CreateSwapChainForHwnd(m_pD3D11Device,
                (HWND)hWindow,
                &swapChainDesc,
                NULL,
                NULL,
                reinterpret_cast<IDXGISwapChain1**>(&m_pSwapChain));
    if (FAILED(hres))  // <====================== Add a breakpoint HERE!
                return MFX_ERR_DEVICE_FAILED;
  5. Run on debug mode and check to hang in upper breakpoint. You can see S_OK as hres value, and then STOP to debug.

  6. Retry to run debug mode, you will find E_ACCESSDENIED error returned by CreateSwapChainForHwnd().

*  Problem solution

  • I think that the window handle(hWindow) taken by WindowFromPoint() was NOT freed on the step 5, So on the second run, CreateSwapChainForHwnd() returned E_ACCESSDENIED error. This is maybe a bug of sample codes.
  • My workaround code is below. Whenever encoder runs, I will take the window handle of an window created NEWLY.
    MediaSamples_6.0.0.49/sample_encode/src/pipeline_encode.cpp
    @@ -474,13 +474,45 @@ mfxStatus CEncodingPipeline::InitMfxVppParams(sInputParams *pInParams)
         return MFX_ERR_NONE;
     }
    
    +LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
    +{
    +    switch (message)
    +    {
    +    case WM_CLOSE:
    +    {
    +        DestroyWindow(hWnd);
    +        break;
    +    }
    +    case WM_DESTROY:
    +    {
    +        PostQuitMessage(0);
    +        break;
    +    }
    +    default:
    +        return DefWindowProc(hWnd, message, wParam, lParam);
    +        DestroyWindow(hWnd);
    +        break;
    +    }
    +    case WM_DESTROY:
    +    {
    +        PostQuitMessage(0);
    +        break;
    +    }
    +    default:
    +        return DefWindowProc(hWnd, message, wParam, lParam);
    +    }
    +
    +    return 0;
    +}
    +
     mfxStatus CEncodingPipeline::CreateHWDevice()
     {
         mfxStatus sts = MFX_ERR_NONE;
     #if D3D_SURFACES_SUPPORT
    -    POINT point = {0, 0};
    -    HWND window = WindowFromPoint(point);
    -
    +    HWND window;
    +    if (D3D11_MEMORY == m_memType)
    +    {
    +        WNDCLASS wc = { 0 };
    +        wc.lpfnWndProc = WndProc;
    +        wc.lpszClassName = _T("SampleWnd");
    +        RegisterClass(&wc);
    +        window = CreateWindow(_T("SampleWnd"), _T(""), 0, 0, 0, 0, 0, NULL, NULL, NULL, 0);
    +    }
    +    else
    +    {
    +        POINT point = { 0, 0 };
    +        window = WindowFromPoint(point);
    +    }
     #if MFX_D3D11_SUPPORT
         if (D3D11_MEMORY == m_memType)
             m_hwdev = new CD3D11Device();

     

Surbhi_M_Intel
Employee
535 Views

We did replicate this issue after multiple trials and as we discussed the problem is in the logic of sample. We suspect this to because of window handle being corrupted somewhere in between which is resulting the access denied or trying to access wrong window which might not exist. 
I think your work around defies both of the possibilities, so this can be definitely used. I have also reported this to be a bug and should be solved in our future releases. Thank your for identifying it. 

-Surbhi

P.S. Since we have identified the problem and solution here, so I am closing this thread, if you do see any issues with Media SDK or samples, feel free start a new thread. 

Reply