question

yoestar avatar image
0 Votes"
yoestar asked FeiXue-MSFT answered

How to switch Dx11 flip model to BitBlt model on same HWND

I used flip model to display video (Dx11) on an hWnd. Now I want to use BitBlt model of Direct3D9 to display video on the same hWnd. How can I turn off flip model of Dx11?
For special reasons, I need to turn off Dx11 after using Dx11 display, and then use DX9 to display video.
The actual test result is: even after I release both swapchain and d3ddevice, I still can't use the BitBlt model of Direct3D9 to display video. Is there something wrong with the release code?


reference MSDN:
Use flip model in an HWND that is not also targeted by other APIs, including DXGI bitblt presentation model, other versions of Direct3D, or GDI. Because bitblt model maintains an additional copy of the surface, you can add GDI and other Direct3D contents to the same HWND through piecemeal updates from Direct3D and GDI. When you use the flip model, only Direct3D content in flip model swap chains that the runtime passes to DWM are visible. The runtime ignores all other bitblt model Direct3D or GDI content updates.

windows-api
· 15
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Is that some ideas to help me, thank you very much.

0 Votes 0 ·

Hello, engineer. I'm in a hurry to solve this problem. Thank you.

0 Votes 0 ·

up it, please help me, thank you very much.

0 Votes 0 ·

Hi,thank you for asking questions on Q&A. Could you please show a minimal, reproducible sample without private information? This can help us solve this problem.

0 Votes 0 ·

Baidu disk link:
url:https://pan.baidu.com/s/1H0dAAbflVyv_BD8p7KI2vw
access code:98xy


After compiling, put the "surface.rgb" file in the generated debug directory (EXE directory) to run.
The UI is as follows: click "RGB" first_ When the video is half played, click "switch DX9". At this time, the video will stop on the last screen of Dx11, but in fact DX9 is still playing the video.
If create swapchain of dx11 use DXGI_SWAP_EFFECT_FLIP_DISCARD, that is occur this problem. but if i use DXGI_SWAP_EFFECT_DISCARD that is no problem, but i must use DXGI_SWAP_EFFECT_FLIP_DISCARD now, Besides the destory window, is there any other feasible way to switch from Dx11 flip model to DX9
91584-sampleui.jpg


0 Votes 0 ·
sampleui.jpg (40.1 KiB)

Have you received my sample?

0 Votes 0 ·

Yes, I will confirm it with Internal engineer, and response here if there is any update. Thanks for your understanding.

0 Votes 0 ·

Hi, due to my environment problem, I cannot use the network disk function, so I cannot download the Surface.rgb file. Could you try to share it to github so that I can get it.

0 Votes 0 ·
Show more comments
0 Votes 0 ·
Show more comments

@SongZhu-MSFT @FeiXue-MSFT
Have you received the code and data I uploaded?

0 Votes 0 ·

1 Answer

FeiXue-MSFT avatar image
0 Votes"
FeiXue-MSFT answered

@yoestar, After investigate the code further, there are two problems in the code.

1.There is a problem with the way about using smart pointers. The original code in RenderFrameRGB is:

 else {
 …
         hres = m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&m_pDXGIBackBuffer.p);
         if (FAILED(hres)) {
             return false;
         }
         m_pD3D11Ctx->UpdateSubresource(m_pDXGIBackBuffer, 0, NULL, m_pOneFrame, m_iWidth * 4, 0);
     }

&m_pDXGIBackBuffer.p is wrong. This will overwrite the previous pointer value stored in m_pDXGIBackBuffer, causing the object to leak. The correct code is:

         CComQIPtr<ID3D11Texture2D> pDXGIBackBuffer;
    
         hres = m_pSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (void**)&pDXGIBackBuffer);
    
         if (FAILED(hres)) {
             return false;
         }
         m_pD3D11Ctx->UpdateSubresource(pDXGIBackBuffer, 0, NULL, m_pOneFrame, m_iWidth * 4, 0);

There are other places do the same thing. Though they are not leaking any objects, I suggest fix all of them.

The following is fine, though, because the function takes an array of pointers and it does not modify the array:

 (ID3D11RenderTargetView * const *ppRenderTargetViews):
     m_pD3D11Ctx->OMSetRenderTargets(1, &m_pRenderView.p, NULL);

2 . DWM appears to be still in the flip mode for the window.

If you restart DWM.exe, Dx9 Blt (or Dx11 Blt or GDI) starts working. Since the DWM issue is complex and requires more time to investigate, please create a support case so that our engineers can work with you closely and help fix the issue as soon as possible. Please refer to the link below and click the Contact US to open a support case:

https://developer.microsoft.com/en-us/windows/support/




5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.