# Automatically select back buffer format

In D3D9, you could set BackBufferFormat to D3DFMT_UNKNOWN in the presentation parameters and D3D would select the format for you.

However, in D3D10, if I set the swap chain descriptor's BufferDesc.Format to DXGI_FORMAT_UNKNOWN, I get this error:

D3D11 ERROR: ID3D11Device::CreateTexture2D: A Texture2D does not support the following Format (0, UNKNOWN). [ STATE_CREATION ERROR #92: CREATETEXTURE2D_UNSUPPORTEDFORMAT]


By the way, if I'm calling D3D10CreateDeviceAndSwapChain, why am I getting a D3D11 error? I guess in Windows 8.1 d3d10 is implemented with d3d11 behind the scenes. Strange. Back to the question, I want to have D3D select the back buffer format for me, is it possible?

Edit: If it's not possible to select automatically, where can I find a good rationale to select it myself? The amount of choices is baffling.

• What are you going to use your backbuffer for? The most standard backbuffer format would be "A8R8G8B8" which is a normal 32 bit format where each channel (Alpha, Red, Green, Blue) has 8 bits. – Roy T. Sep 9 '14 at 14:57
• Mostly rendering images, most of them monochrome, some RGB. They can be 8 bit or 16 bit (the monochrome ones). I render them using textured quads. I tried checking what D3D9 selected after initiliazation, and I got 4, which does not correspond to any of the formats listed in MSDN... – dario_ramos Sep 9 '14 at 15:01
• Id say A8R8G8B8 will definitely work for that use case. Some other formats might use less memory but that is usually not relevant for the backbuffer (a single texture will usually take up more) – Roy T. Sep 9 '14 at 15:04
• It's now working with DXGI_FORMAT_R8G8B8A8_UNORM, but it would be nice if I could let D3D decide the best format by himself. – dario_ramos Sep 9 '14 at 18:47
• BTW, there's no reason not to just use Direct3D 11. It's supported on everything Direct3D 10 is supported and includes access to the 10level9 feature levels for broad hardware support. There's also many more options for replacing legacy D3DX content for Direct3D 11. – Chuck Walbourn Sep 9 '14 at 19:57

## 1 Answer

The choice of which backbuffer format to use comes down to four considerations:

1. The target feature level for the hardware you are supporting determines what backbuffer formats are available. See the "Display scan-out" options listed in the DXGI documentation for each feature level. For example, to support all feature levels you have to use DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, or DXGI_FORMAT_B8G8R8A8_UNORM. Note that on older drivers (i.e. first-generation WDDM 1.0 Windows Vista drivers on Feature Level 10.x cards; 9.x feature level devices always support BGRA) DXGI_FORMAT_B8G8R8A8_UNORM may not be supported.

2. If you are going to use Direct2D/DirectWrite interop, then you must use D3D11_CREATE_DEVICE_BGRA_SUPPORT which means you have to be using BGRA-supporting drivers (i.e. WDDM 1.1 or later on Feature Level 10.x+ devices). if you are using Direct2D on the backbuffer, you should use DXGI_FORMAT_B8G8R8A8_UNORM.

3. If you are doing gamma-correct rendering and want to rely on the automatic gamma correction built into Direct3D, then you should use an SRGB format such as DXGI_FORMAT_R8G8B8A8_UNORM_SRGB or DXGI_FORMAT_B8G8R8A8_UNORM_SRGB.

4. If you are wanting to use '10-bit scan out' extended color space (i.e. "High Color" or "Deep Color") in full-screen mode, then you should use DXGI_FORMAT_R10G10B10A2_UNORM which requires feature Level 10.0 or later hardware. You can use DXGI_FORMAT_R16G16B16A16_FLOAT but it tends to take up far too much memory and bandwidth at HD resolutions.

• And what about all the other formats? Are they meant for when you have less resources (i.e. compressed formats, for example), legacy devices and so on? – dario_ramos Sep 10 '14 at 12:35
• There are many more formats you can use for render targets, but they don't necessarily make good choices for the backbuffer. For HDR rendering for example, you typically will use a floating-point render target, and then using a post-process shader to do tone-mapping to a 10:10:10:2 or 8:8:8:8 format buffer which can be a backbuffer format. See HDRToneMappingCS11 sample on MSDN Code Gallery. Remember the backbuffer is the image that goes to the screen, but render targets can be used for all kinds of processing. – Chuck Walbourn Sep 10 '14 at 17:12