Partager via


Map DirectX 9 features to DirectX 11 APIs

[This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation]

Understand how the features your Direct3D 9 game uses will translate to Direct3D 11 and the Windows Store.

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. There are a few minor constraints to the DXGI APIs for Windows Phone. For more info, see Creating a Direct3D device and swap chain for Windows Phone 8.
  • 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.

Note  Direct2D and DirectWrite are not supported on Windows Phone 8.

 

Replace deprecated helper libraries

D3DX and DXUT are deprecated and cannot be used by Windows Store or Windows Phone games. These helper libraries provided resources for tasks such as texture loading and mesh loading.

Move shader programs from FX to HLSL

The D3DX utility library (D3DX 9, D3DX 10, and D3DX 11), including Effects, is deprecated for Windows 8. All DirectX games for the Windows Store and Windows Phone drive the graphics pipeline using HLSL without Effects.

Visual Studio still uses FXC under the hood to compile shader objects. Windows Store 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 Windows Store.

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 Windows Phone or Windows Store apps:

Replace DirectInput with XInput and Windows Store app APIs

DirectInput is not supported for Windows Store apps:

  • Use CoreWindow input event callbacks for mouse, keyboard, and touch input. See Working with event messaging and CoreWindow. These are the only supported input events for pure-native Windows Phone games.
  • Use XInput 1.4 for game controller support (and game controller headset support). If you are using a shared code base for desktop and the Windows Store, see XInput Versions for information on backwards compatibility. XInput is not supported on
  • 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 Windows Store certification requirements. Use the following APIs:

The following articles help you add networking features and declare support for networking in your app's package manifest.

Note that all Windows Store apps (including Windows Store 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 Staying connected in the background. Windows Phone does not support maintaining connections in the background.

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

IDirect3DDevice9

ID3D11Device2

ID3D11DeviceContext2

The graphics pipeline stages are described in Graphics Pipeline.

IDirect3D9

IDXGIFactory2

IDXGIAdapter2

IDXGIDevice3

IDirect3DDevice9::Present

IDXGISwapChain1::Present1

IDirect3DDevice9::TestCooperativeLevel

Call IDXGISwapChain1::Present1 with the DXGI_PRESENT_TEST flag set.

IDirect3DBaseTexture9

IDirect3DTexture9

IDirect3DCubeTexture9

IDirect3DVolumeTexture9

IDirect3DIndexBuffer9

IDirect3DVertexBuffer9

ID3D11Buffer

ID3D11Texture1D

ID3D11Texture2D

ID3D11Texture3D

ID3D11ShaderResourceView

ID3D11RenderTargetView

ID3D11DepthStencilView

IDirect3DVertexShader9

IDirect3DPixelShader9

ID3D11VertexShader

ID3D11PixelShader

IDirect3DVertexDeclaration9

ID3D11InputLayout

IDirect3DDevice9::SetRenderState

IDirect3DDevice9::SetSamplerState

ID3D11BlendState1

ID3D11DepthStencilState

ID3D11RasterizerState1

ID3D11SamplerState

IDirect3DDevice9::DrawIndexedPrimitive

IDirect3DDevice9::DrawPrimitive

ID3D11DeviceContext::Draw

ID3D11DeviceContext::DrawIndexed

ID3D11DeviceContext::DrawIndexedInstanced

ID3D11DeviceContext::DrawInstanced

ID3D11DeviceContext::IASetPrimitiveTopology

ID3D11DeviceContext::DrawAuto

IDirect3DDevice9::BeginScene

IDirect3DDevice9::EndScene

IDirect3DDevice9::DrawPrimitiveUP

IDirect3DDevice9::DrawIndexedPrimitiveUP

No direct equivalent

IDirect3DDevice9::ShowCursor

IDirect3DDevice9::SetCursorPosition

IDirect3DDevice9::SetCursorProperties

Use standard cursor APIs.

IDirect3DDevice9::Reset

LOST device and POOL_MANAGED no longer exist. IDXGISwapChain1::Present1 can fail with a DXGI_ERROR_DEVICE_REMOVED return value.

IDirect3DDevice9:DrawRectPatch

IDirect3DDevice9:DrawTriPatch

IDirect3DDevice9:LightEnable

IDirect3DDevice9:MultiplyTransform

IDirect3DDevice9:SetLight

IDirect3DDevice9:SetMaterial

IDirect3DDevice9:SetNPatchMode

IDirect3DDevice9:SetTransform

IDirect3DDevice9:SetFVF

IDirect3DDevice9:SetTextureStageState

The fixed-function pipeline has been deprecated.

IDirect3DDevice9:CheckDepthStencilMatch

IDirect3DDevice9:CheckDeviceFormat

IDirect3DDevice9:GetDeviceCaps

IDirect3DDevice9:ValidateDevice

Capability bits are replaced with 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