# DirectX11 without window attached?

I just wonder, if it's possible to initialize and use DX11 or DX9 for offscreen rendering only - meaning with no attached window. My intention is to do some GPU benchmarking before opening actual window. In this benchmarking some test scene is rendered, but should not be visible. (Actually depending on the benchmark score different windows are opened)

• With D3D11 you need to provide a window handle when creating the swap chain, see here. But maybe there's a way to hide this window? – Laurent Couvidou Mar 22 '13 at 8:40
• yeah, I know, that DX11 requires window handle for swapchain - but if you render offscreen only do you really need any swapchain? Is there some way to initialize and render without swapchain - I thought swapchain is just for screen rendering... – GPUquant Mar 22 '13 at 10:04
• Right now I am trying to use 1x1px window which is hidden. But it's not nice solution I'd say. – GPUquant Mar 22 '13 at 10:05

Yes. You can initialize the Direct3D device using D3D11CreateDevice, which requires no window. You simply do not create a swap chain at all. You can still create offscreen render targets and draw to them in the usual way. Instead of calling Present on the swap chain, you can call ID3D11DeviceContext::Flush to kick the GPU with the work you've queued up.
If you later want to create a window, you can destroy the device and recreate it with D3D11CreateDeviceAndSwapChain, or you can create a swap chain and attach it to the existing device with IDXGIFactory::CreateSwapChain. (The IDXGIFactory is a separate COM object that needs to be created with CreateDXGIFactory first.)
• +1 Calling Flush instead of presenting the swap chain, this is neat! – Laurent Couvidou Mar 22 '13 at 22:10
• Is this somehow possible with D3D9 via the IDirect3D9::CreateDevice method? I couldn't find a D3D9CreateDevice method sadly. – Vinz Jun 22 '17 at 3:15
• @Vinzenz I don't think so. D3D9 doesn't separate the concepts of "device" and "swap chain", as D3D10 and up do. They're both rolled into the D3D9 device object, which requires a HWND to create. – Nathan Reed Jun 23 '17 at 0:42