Map DirectX 9 features to DirectX 11 APIs
Understand how the features your Direct3D 9 game uses will translate to Direct3D 11 and the Universal Windows Platform (UWP).
Also see Plan your DirectX port, and Important changes from Direct3D 9 to Direct3D 11.
Mapping Direct3D 9 to DirectX 11 APIs
Direct3D is still the foundation of DirectX graphics, but the API has changed since DirectX 9:
- Microsoft DirectX Graphics Infrastructure (DXGI) is used to set up graphics adapters. Use DXGI to select buffer formats, create swap chains, present frames, and create shared resources. See DXGI Overview.
- A Direct3D device context is used to set pipeline state and generate rendering commands. Most of our samples use an immediate context to render directly to the device; Direct3D 11 also supports multithreaded rendering, in which case deferred contexts are used. See Introduction to a Device in Direct3D 11.
- Some features have been deprecated, most notably the fixed function pipeline. See Deprecated Features.
For a full list of Direct3D 11 features, see Direct3D 11 Features and Direct3D 11 Features.
Moving from Direct2D 9 to Direct2D 11
Direct2D (Windows) is still an important part of DirectX graphics and Windows. You can still use Direct2D to draw 2D games, and to draw overlays (HUDs) on top of Direct3D.
Direct2D runs on top of Direct3D; 2D games can be implemented using either API. For example, a 2D game implemented using Direct3D can use orthographic projection, set Z-values to control the drawing order of primitives, and use pixel shaders to add special effects.
Since Direct2D is based on Direct3D it also uses DXGI and device contexts. See Direct2D API Overview.
The DirectWrite API adds support for formatted text using Direct2D. See Introducing DirectWrite.
Replace deprecated helper libraries
D3DX and DXUT are deprecated and cannot be used by UWP games. These helper libraries provided resources for tasks such as texture loading and mesh loading.
- The Simple port from Direct3D 9 to UWP walkthrough demonstrates how to set up a window, initialize Direct3D, and do basic 3D rendering.
- The Simple UWP game with DirectX walkthrough demonstrates common game programming tasks including graphics, loading files, UI, controls, and sound.
- The DirectX Tool Kit community project offers helper classes for use with Direct3D 11 and UWP apps.
Move shader programs from FX to HLSL
The D3DX utility library (D3DX 9, D3DX 10, and D3DX 11), including Effects, is deprecated for UWP. All DirectX games for UWP drive the graphics pipeline using HLSL without Effects.
Visual Studio still uses FXC under the hood to compile shader objects. UWP game shaders are compiled ahead of time. The bytecode is loaded at runtime, then each shader resource is bound to the graphics pipeline during the appropriate rendering pass. Shaders should be moved to their own separate .HLSL files and rendering techniques should be implemented in your C++ code.
For a quick look at loading shader resources see Simple port from Direct3D 9 to UWP.
Direct3D 11 introduced Shader Model 5, which requires Direct3D feature level 11_0 (or above). See HLSL Shader Model 5 Features for Direct3D 11.
Replace XNAMath and D3DXMath
Code using XNAMath (or D3DXMath) should be migrated to DirectXMath. DirectXMath includes types that are portable across x86, x64, and Arm. See Code Migration from the XNA Math Library.
Note that DirectXMath float types are convenient for use with shaders. For example XMFLOAT4 and XMFLOAT4X4 conveniently align data for constant buffers.
Replace DirectSound with XAudio2 (and background audio)
DirectSound is not supported for UWP:
- Use XAudio2 to add sound effects to your game.
Replace DirectInput with XInput and Windows Runtime APIs
DirectInput is not supported for UWP:
- Use CoreWindow input event callbacks for mouse, keyboard, and touch input.
- Use XInput 1.4 for game controller support (and game controller headset support). If you are using a shared code base for desktop and UWP, see XInput Versions for information on backwards compatibility.
- Register for EdgeGesture events if your game needs to use the app bar.
Use Microsoft Media Foundation instead of DirectShow
DirectShow is no longer part of the DirectX API (or the Windows API). Microsoft Media Foundation provides video content to Direct3D using shared surfaces. See Direct3D 11 Video APIs.
Replace DirectPlay with networking code
Microsoft DirectPlay has been deprecated. If your game uses network services, you need to provide networking code that complies with UWP requirements. Use the following APIs:
- Win32 and COM for UWP apps (networking) (Windows)
- Windows.Networking namespace (Windows)
- Windows.Networking.Sockets namespace (Windows)
- Windows.Networking.Connectivity namespace (Windows)
- Windows.ApplicationModel.Background namespace (Windows)
The following articles help you add networking features and declare support for networking in your app's package manifest.
- Connecting with sockets (UWP apps using C#/VB/C++ and XAML) (Windows)
- Connecting with WebSockets (UWP apps using C#/VB/C++ and XAML) (Windows)
- Connecting to web services (UWP apps using C#/VB/C++ and XAML) (Windows)
- Networking basics
Note that all UWP apps (including games) use specific types of background tasks to maintain connectivity while the app is suspended. If your game needs to maintain connection state while suspended see Networking basics.
Function mapping
Use the following table to help convert code from Direct3D 9 to Direct3D 11. This can also help distinguish between the device and device context.
Direct3D9 | Direct3D 11 Equivalent |
---|---|
The graphics pipeline stages are described in Graphics Pipeline. |
|
Call IDXGISwapChain1::Present1 with the DXGI_PRESENT_TEST flag set. |
|
ID3D11DeviceContext::DrawIndexed ID3D11DeviceContext::DrawIndexedInstanced ID3D11DeviceContext::DrawInstanced |
|
No direct equivalent |
|
Use standard cursor APIs. |
|
LOST device and POOL_MANAGED no longer exist. IDXGISwapChain1::Present1 can fail with a DXGI_ERROR_DEVICE_REMOVED return value. |
|
IDirect3DDevice9:DrawRectPatch IDirect3DDevice9:MultiplyTransform |
The fixed-function pipeline has been deprecated. |
IDirect3DDevice9:CheckDepthStencilMatch IDirect3DDevice9:CheckDeviceFormat |
Capability bits are replaced by feature levels. Only a few format and feature usage cases are optional for any given feature level. These can be checked with ID3D11Device::CheckFeatureSupport and ID3D11Device::CheckFormatSupport. |
Surface format mapping
Use the following table to convert Direct3D 9 formats into DXGI formats.
Direct3D 9 Format | Direct3D 11 Format |
---|---|
D3DFMT_UNKNOWN |
DXGI_FORMAT_UNKNOWN |
D3DFMT_R8G8B8 |
Not available |
D3DFMT_A8R8G8B8 |
DXGI_FORMAT_B8G8R8A8_UNORM DXGI_FORMAT_B8G8R8A8_UNORM_SRGB |
D3DFMT_X8R8G8B8 |
DXGI_FORMAT_B8G8R8X8_UNORM DXGI_FORMAT_B8G8R8X8_UNORM_SRGB |
D3DFMT_R5G6B5 |
DXGI_FORMAT_B5G6R5_UNORM |
D3DFMT_X1R5G5B5 |
Not available |
D3DFMT_A1R5G5B5 |
DXGI_FORMAT_B5G5R5A1_UNORM |
D3DFMT_A4R4G4B4 |
DXGI_FORMAT_B4G4R4A4_UNORM |
D3DFMT_R3G3B2 |
Not available |
D3DFMT_A8 |
DXGI_FORMAT_A8_UNORM |
D3DFMT_A8R3G3B2 |
Not available |
D3DFMT_X4R4G4B4 |
Not available |
D3DFMT_A2B10G10R10 |
DXGI_FORMAT_R10G10B10A2 |
D3DFMT_A8B8G8R8 |
DXGI_FORMAT_R8G8B8A8_UNORM DXGI_FORMAT_R8G8B8A8_UNORM_SRGB |
D3DFMT_X8B8G8R8 |
Not available |
D3DFMT_G16R16 |
DXGI_FORMAT_R16G16_UNORM |
D3DFMT_A2R10G10B10 |
Not available |
D3DFMT_A16B16G16R16 |
DXGI_FORMAT_R16G16B16A16_UNORM |
D3DFMT_A8P8 |
Not available |
D3DFMT_P8 |
Not available |
D3DFMT_L8 |
DXGI_FORMAT_R8_UNORM
Note Use .r swizzle in shader to duplicate red to other components to get Direct3D 9 behavior.
|
D3DFMT_A8L8 |
DXGI_FORMAT_R8G8_UNORM
Note Use swizzle .rrrg in shader to duplicate red and move green to the alpha components to get Direct3D 9 behavior.
|
D3DFMT_A4L4 |
Not available |
D3DFMT_V8U8 |
DXGI_FORMAT_R8G8_SNORM |
D3DFMT_L6V5U5 |
Not available |
D3DFMT_X8L8V8U8 |
Not available |
D3DFMT_Q8W8V8U8 |
DXGI_FORMAT_R8G8B8A8_SNORM |
D3DFMT_V16U16 |
DXGI_FORMAT_R16G16_SNORM |
D3DFMT_W11V11U10 |
Not available |
D3DFMT_A2W10V10U10 |
Not available |
D3DFMT_UYVY |
Not available |
D3DFMT_R8G8_B8G8 |
DXGI_FORMAT_G8R8_G8B8_UNORM
Note In Direct3D 9 the data was scaled up by 255.0f, but this can be handled in the shader.
|
D3DFMT_YUY2 |
Not available |
D3DFMT_G8R8_G8B8 |
DXGI_FORMAT_R8G8_B8G8_UNORM
Note In Direct3D 9 the data was scaled up by 255.0f, but this can be handled in the shader.
|
D3DFMT_DXT1 |
DXGI_FORMAT_BC1_UNORM & DXGI_FORMAT_BC1_UNORM_SRGB |
D3DFMT_DXT2 |
DXGI_FORMAT_BC1_UNORM & DXGI_FORMAT_BC1_UNORM_SRGB
Note DXT1 and DXT2 are the same from an API/hardware perspective. The only difference is whether premultiplied alpha is used, which can be tracked by an application and doesn't need a separate format.
|
D3DFMT_DXT3 |
DXGI_FORMAT_BC2_UNORM & DXGI_FORMAT_BC2_UNORM_SRGB |
D3DFMT_DXT4 |
DXGI_FORMAT_BC2_UNORM & DXGI_FORMAT_BC2_UNORM_SRGB
Note DXT3 and DXT4 are the same from an API/hardware perspective. The only difference is whether premultiplied alpha is used, which can be tracked by an application and doesn't need a separate format.
|
D3DFMT_DXT5 |
DXGI_FORMAT_BC3_UNORM & DXGI_FORMAT_BC3_UNORM_SRGB |
D3DFMT_D16 & D3DFMT_D16_LOCKABLE |
DXGI_FORMAT_D16_UNORM |
D3DFMT_D32 |
Not available |
D3DFMT_D15S1 |
Not available |
D3DFMT_D24S8 |
Not available |
D3DFMT_D24X8 |
Not available |
D3DFMT_D24X4S4 |
Not available |
D3DFMT_D16 |
DXGI_FORMAT_D16_UNORM |
D3DFMT_D32F_LOCKABLE |
DXGI_FORMAT_D32_FLOAT |
D3DFMT_D24FS8 |
Not available |
D3DFMT_S1D15 |
Not available |
D3DFMT_S8D24 |
DXGI_FORMAT_D24_UNORM_S8_UINT |
D3DFMT_X8D24 |
Not available |
D3DFMT_X4S4D24 |
Not available |
D3DFMT_L16 |
DXGI_FORMAT_R16_UNORM
Note Use .r swizzle in shader to duplicate red to other components to get D3D9 behavior.
|
D3DFMT_INDEX16 |
DXGI_FORMAT_R16_UINT |
D3DFMT_INDEX32 |
DXGI_FORMAT_R32_UINT |
D3DFMT_Q16W16V16U16 |
DXGI_FORMAT_R16G16B16A16_SNORM |
D3DFMT_MULTI2_ARGB8 |
Not available |
D3DFMT_R16F |
DXGI_FORMAT_R16_FLOAT |
D3DFMT_G16R16F |
DXGI_FORMAT_R16G16_FLOAT |
D3DFMT_A16B16G16R16F |
DXGI_FORMAT_R16G16B16A16_FLOAT |
D3DFMT_R32F |
DXGI_FORMAT_R32_FLOAT |
D3DFMT_G32R32F |
DXGI_FORMAT_R32G32_FLOAT |
D3DFMT_A32B32G32R32F |
DXGI_FORMAT_R32G32B32A32_FLOAT |
D3DFMT_CxV8U8 |
Not available |
D3DDECLTYPE_FLOAT1 |
DXGI_FORMAT_R32_FLOAT |
D3DDECLTYPE_FLOAT2 |
DXGI_FORMAT_R32G32_FLOAT |
D3DDECLTYPE_FLOAT3 |
DXGI_FORMAT_R32G32B32_FLOAT |
D3DDECLTYPE_FLOAT4 |
DXGI_FORMAT_R32G32B32A32_FLOAT |
D3DDECLTYPED3DCOLOR |
Not available |
D3DDECLTYPE_UBYTE4 |
DXGI_FORMAT_R8G8B8A8_UINT
Note The shader gets UINT values, but if Direct3D 9 style integral floats are needed (0.0f, 1.0f... 255.f), UINT can just be converted to float32 in the shader.
|
D3DDECLTYPE_SHORT2 |
DXGI_FORMAT_R16G16_SINT
Note The shader gets SINT values, but if Direct3D 9 style integral floats are needed, SINT can just be converted to float32 in the shader.
|
D3DDECLTYPE_SHORT4 |
DXGI_FORMAT_R16G16B16A16_SINT
Note The shader gets SINT values, but if Direct3D 9 style integral floats are needed, SINT can just be converted to float32 in the shader.
|
D3DDECLTYPE_UBYTE4N |
DXGI_FORMAT_R8G8B8A8_UNORM |
D3DDECLTYPE_SHORT2N |
DXGI_FORMAT_R16G16_SNORM |
D3DDECLTYPE_SHORT4N |
DXGI_FORMAT_R16G16B16A16_SNORM |
D3DDECLTYPE_USHORT2N |
DXGI_FORMAT_R16G16_UNORM |
D3DDECLTYPE_USHORT4N |
DXGI_FORMAT_R16G16B16A16_UNORM |
D3DDECLTYPE_UDEC3 |
Not available |
D3DDECLTYPE_DEC3N |
Not available |
D3DDECLTYPE_FLOAT16_2 |
DXGI_FORMAT_R16G16_FLOAT |
D3DDECLTYPE_FLOAT16_4 |
DXGI_FORMAT_R16G16B16A16_FLOAT |
FourCC 'ATI1' |
DXGI_FORMAT_BC4_UNORM
Note Requires Feature Level 10.0 or later
|
FourCC 'ATI2' |
DXGI_FORMAT_BC5_UNORM
Note Requires Feature Level 10.0 or later
|
Additional mapping info
- IDirect3DDevice9::SetCursorPosition is replaced by SetCursorPos.
- IDirect3DDevice9::SetCursorProperties is replaced by SetCursor.
- IDirect3DDevice9::SetIndices is replaced by ID3D11DeviceContext::IASetIndexBuffer.
- IDirect3DDevice9::SetRenderTarget is replaced by ID3D11DeviceContext::OMSetRenderTargets.
- IDirect3DDevice9::SetScissorRect is replaced by ID3D11DeviceContext::RSSetScissorRects.
- IDirect3DDevice9::SetStreamSource is replaced by ID3D11DeviceContext::IASetVertexBuffers.
- IDirect3DDevice9::SetVertexDeclaration is replaced by ID3D11DeviceContext::IASetInputLayout.
- IDirect3DDevice9::SetViewport is replaced by ID3D11DeviceContext::RSSetViewports.
- IDirect3DDevice9::ShowCursor is replaced by ShowCursor.
Control of the video card's hardware gamma ramp through IDirect3DDevice9::SetGammaRamp is replaced by IDXGIOutput::SetGammaControl. See Using gamma correction.
IDirect3DDevice9::ProcessVertices is replaced by the Stream-Output functionality of Geometry Shaders. See Getting started with the Stream-Output Stage.
The method IDirect3DDevice9::SetClipPlane to set user clip-planes was replaced by either the HLSL SV_ClipDistance vertex shader output semantic (see Semantics), available in VS_4_0 and up, or the new HLSL clipplanes function attribute (see User clip planes on feature level 9 hardware).
IDirect3DDevice9::SetPaletteEntries and IDirect3DDevice9::SetCurrentTexturePalette are deprecated. Replace these with a pixel shader that looks up colors in a 256x1 R8G8B8A8 texture instead.
Fixed-function tessellation functions like DrawRectPatch, DrawTriPatch, SetNPatchMode, and DeletePatch are deprecated. Replace these with programmable-pipeline SM5.0 Tessellation shaders (if hardware supports tessellation shaders).
IDirect3DDevice9::SetFVF, and FVF codes, are no longer supported. You should port from D3D8/D3D9 FVF codes to D3D9 Vertex Declarations before porting to D3D11 Input Layouts.
All of the D3DDECLTYPE types that are not directly supported can be emulated fairly efficiently with a small number of bitwise operations at the beginning of a vertex shader in VS_4_0 and up.