microsoft / DirectX-Graphics-Samples

This repo contains the DirectX Graphics samples that demonstrate how to build graphics intensive applications on Windows.
MIT License
5.88k stars 2k forks source link

How to use DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE in D3D12 #846

Closed LastSunlight closed 4 months ago

LastSunlight commented 7 months ago
 I want to use DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE create SwapChain, but it look like not support with D3D12.
walbourn commented 4 months ago

I believe that flag is only intended for use with Direct2D.

That said, what are all the options you are providing to DXGI when creating the swapchain? Perhaps more details would help.

Also, have you tried enabling DXGI debugging?

LastSunlight commented 4 months ago

ok,I use this flag with D3D11 to create swapchain in unrealengine5, it works。

this is create details: `DXGI_SWAP_CHAIN_DESC1 SwapChainDesc = {};

BackBufferCount = 2; SwapChainDesc.BufferCount = BackBufferCount; SwapChainDesc.Width = SizeX; SwapChainDesc.Height = SizeY; SwapChainDesc.SampleDesc.Count = 1; SwapChainDesc.SampleDesc.Quality = 0; SwapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE; SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT; DXGI_SWAP_CHAIN_FULLSCREEN_DESC FSSwapChainDesc = {}; FSSwapChainDesc.Windowed = !bIsFullscreen;`

image

but it look like not support with D3D12. This is details: https://learn.microsoft.com/en-us/windows/win32/api/dxgi/ne-dxgi-dxgi_swap_chain_flag image

LastSunlight commented 4 months ago

ok,I use this flag with D3D11 to create swapchain in unrealengine5, it works。

this is create details: `// Create the swapchain. DXGI_SWAP_CHAIN_DESC1 SwapChainDesc = {}; BackBufferCount = 2; SwapChainDesc.BufferCount = BackBufferCount; SwapChainDesc.Width = SizeX; SwapChainDesc.Height = SizeY; SwapChainDesc.SampleDesc.Count = 1; SwapChainDesc.SampleDesc.Quality = 0; SwapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; SwapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE; SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT; DXGI_SWAP_CHAIN_FULLSCREEN_DESC FSSwapChainDesc = {}; FSSwapChainDesc.Windowed = !bIsFullscreen;

        IDXGISwapChain1* SwapChain1 = nullptr;
        HRESULT CreateSwapChainForHwndResult = DXGISwapchainProvider ?
            DXGISwapchainProvider->CreateSwapChainForHwnd(Factory2, D3DRHI->GetDevice(), WindowHandle, &SwapChainDesc, &FSSwapChainDesc, nullptr, &SwapChain1) :
            Factory2->CreateSwapChainForHwnd(D3DRHI->GetDevice(), WindowHandle, &SwapChainDesc, &FSSwapChainDesc, nullptr, &SwapChain1);`

image

but it look like not support with D3D12. This is details: https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgisurface1-getdc

jenatali commented 4 months ago

Correct, D3D12 does not provide any native GDI interop support.