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)
-
2\$\begingroup\$ 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? \$\endgroup\$– Laurent CouvidouCommented Mar 22, 2013 at 8:40
-
1\$\begingroup\$ 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... \$\endgroup\$– GPUquantCommented Mar 22, 2013 at 10:04
-
1\$\begingroup\$ Right now I am trying to use 1x1px window which is hidden. But it's not nice solution I'd say. \$\endgroup\$– GPUquantCommented Mar 22, 2013 at 10:05
1 Answer
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.)
-
\$\begingroup\$ +1 Calling
Flush
instead of presenting the swap chain, this is neat! \$\endgroup\$ Commented Mar 22, 2013 at 22:10 -
\$\begingroup\$ Is this somehow possible with D3D9 via the
IDirect3D9::CreateDevice
method? I couldn't find aD3D9CreateDevice
method sadly. \$\endgroup\$– VinzCommented Jun 22, 2017 at 3:15 -
\$\begingroup\$ @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. \$\endgroup\$ Commented Jun 23, 2017 at 0:42