How to install the latest version of DirectX
What is DirectX?
DirectX is a set of components in Windows that allows software, primarily and especially games, to work directly with your video and audio hardware. Games that use DirectX can use multimedia accelerator features built-in to your hardware more efficiently which improves your overall multimedia experience.
Check which version of DirectX is installed
The DxDiag tool reports detailed information about the DirectX components and drivers installed on your system and can be used.
From Start, type dxdiag in the Search box, and then press enter.
Tap or click on dxdiag from the results.
Check DirectX Version on the first page of the report in the System Information section.
Swipe in from the right edge of the screen, and then tap Search. Type dxdiag in the search box. Or, just type dxdiag from Start.
Tap or click on dxdiag from the results.
Check DirectX Version on the first page of the report in the System Information section.
Click Start, type dxdiag in the search box.
Tap or click on dxdiag from the results.
Check DirectX Version on the first page of the report in the System Information section.
DirectX versions and updates by Operating System
DirectX 11.3 and 12 are included with these Windows versions.
Updates will be available through Windows Update. There is no stand-alone package for these versions of DirectX.
DirectX 11.1 is included in Windows 8, Windows RT, and Windows Server 2012. There is no stand-alone update package for DirectX 11.1. You can only install this DirectX version through Windows Update in Windows 8, Windows RT and Windows Server 2012.
DirectX 11.2 is included in Windows 8.1, Windows RT 8.1 and Windows Server 2012 R2. There is no stand-alone update package for DirectX 11.2. You can only install this DirectX version through Windows Update in Windows 8.1, Windows RT 8.1 and Windows Server 2012 R2.
Note To upgrade DirectX further, you will need to upgrade your operating system.
DirectX 11.0 is included in Windows 7 and Server 2008 R2. There is no stand-alone update package for this version. You can update DirectX by installing the service pack and update listed below.
DirectX 11.1 is available for Windows 7 SP1 and Windows Server 2008 RS SP1, with Platform Update for Windows 7 and Windows Server 2008 (KB2670838).
Note To upgrade DirectX further, you will need to upgrade your operating system.
DirectX 10 is included in Windows Vista. There is no stand-alone update package for this version. You can update DirectX by installing the service pack and update listed below.
DirectX 10.1 is included in Windows Vista SP1 or later, and Windows Server SP1 or later. There is no stand-alone update package for this version. You can update DirectX by installing the service pack and update listed below.
DirectX 11.0 is available for Windows Vista SP2 and Windows Server 2008 SP2, with KB971512 installed.
Note To upgrade DirectX further, you will need to upgrade your operating system.
DirectX 9.0c is available for Windows XP and Windows Server 2003 by installing the DirectX 9.0c End-User Runtime.
Some applications and games require DirectX 9. However, your computer includes a more recent version of DirectX. If you install and then run an application or game that requires DirectX 9, you might receive an error message such as «The program can’t start because d3dx9_35.dll is missing from your computer. Try reinstalling the program to fix this problem.»
To resolve this issue, install DirectX End-User Runtime.
When you run this package, no change is made to your version of DirectX, Direct3D 9, Direct3D 10.x, Direct3D 11.x, DirectInput, DirectSound, DirectPlay, DirectShow, or DirectMusic.
To upgrade DirectX further, you will need to upgrade your operating system.
Work with DirectX device resources
Understand the role of the Microsoft DirectX Graphics Infrastructure (DXGI) in your Windows Store DirectX game. DXGI is a set of APIs used to configure and manage low-level graphics and graphics adapter resources. Without it, you’d have no way to draw your game’s graphics to a window.
Think of DXGI this way: to directly access the GPU and manage its resources, you must have a way to describe it to your app. The most important piece of info you need about the GPU is the place to draw pixels so it can send those pixels to the screen. Typically this is called the «back buffer»вЂ”a location in GPU memory where you can draw the pixels and then have it «flipped» or «swapped» and sent to the screen on a refresh signal. DXGI lets you acquire that location and the means to use that buffer (called a swap chain because it is a chain of swappable buffers, allowing for multiple buffering strategies).
To do this, you need access to write to the swap chain, and a handle to the window that will display the current back buffer for the swap chain. You also need to connect the two to ensure that the operating system will refresh the window with the contents of the back buffer when you request it to do so.
The overall process for drawing to the screen is as follows:
- Get a CoreWindow for your app.
- Get an interface for the Direct3D device and context.
- Create the swap chain to display your rendered image in the CoreWindow.
- Create a render target for drawing and populate it with pixels.
- Present the swap chain!
Create a window for your app
The first thing we need to do is create a window. First, create a window class by populating an instance of WNDCLASS, then register it using RegisterClass. The window class contains essential properties of the window, including the icon it uses, the static message processing function (more on this later), and a unique name for the window class.
Next, you create the window. We also need to provide size information for the window and the name of the window class we just created. When you call CreateWindow, you get back an opaque pointer to the window called an HWND; you’ll need to keep the HWND pointer and use it any time you need to reference the window, including destroying or recreating it, and (especially important) when creating the DXGI swap chain you use to draw in the window.
The Windows desktop app model includes a hook into the Windows message loop. You’ll need to base your main program loop off of this hook by writing a «StaticWindowProc» function to process windowing events. This must be a static function because Windows will call it outside of the context of any class instance. Here’s a very simple example of a static message processing function.
This simple example only checks for program exit conditions: WM_CLOSE, sent when the window is requested to be closed, and WM_DESTROY, which is sent after the window is actually removed from the screen. A full, production app needs to handle other windowing events too—for the complete list of windowing events, see Window Notifications.
The main program loop itself needs to acknowledge Windows messages by allowing Windows the opportunity to run the static message proc. Help the program run efficiently by forking the behavior: each iteration should choose to process new Windows messages if they are available, and if no messages are in the queue it should render a new frame. Here’s a very simple example:
Get an interface for the Direct3D device and context
The first step to using Direct3D is to acquire an interface for the Direct3D hardware (the GPU), represented as instances of ID3D11Device and ID3D11DeviceContext. The former is a virtual representation of the GPU resources, and the latter is a device-agnostic abstraction of the rendering pipeline and process. Here’s an easy way to think of it: ID3D11Device contains the graphics methods you call infrequently, usually before any rendering occurs, to acquire and configure the set of resources you need to start drawing pixels. ID3D11DeviceContext, on the other hand, contains the methods you call every frame: loading in buffers and views and other resources, changing output-merger and rasterizer state, managing shaders, and drawing the results of passing those resources through the states and shaders.
There’s one very important part of this process: setting the feature level. The feature level tells DirectX the minimum level of hardware your app supports, with D3D_FEATURE_LEVEL_9_1 as the lowest feature set and D3D_FEATURE_LEVEL_11_1 as the current highest. You should support 9_1 as the minimum if you want to reach the widest possible audience. Take some time to read up on Direct3D feature levels and assess for yourself the minimum and maximum feature levels you want your game to support and to understand the implications of your choice.
Obtain references (pointers) to both the Direct3D device and device context and store them as class-level variables on the DeviceResources instance (as ComPtr smart pointers). Use these references whenever you need to access the Direct3D device or device context.
Create the swap chain
Okay: You have a window to draw in, and you have an interface to send data and give commands to the GPU. Now let’s see how to bring them together.
First, you tell DXGI what values to use for the properties of the swap chain. Do this using a DXGI_SWAP_CHAIN_DESC structure. Six fields are particularly important for desktop apps:
- Windowed: Indicates whether the swap chain is full-screen or clipped to the window. Set this to TRUE to put the swap chain in the window you created earlier.
- BufferUsage: Set this to DXGI_USAGE_RENDER_TARGET_OUTPUT. This indicates that the swap chain will be a drawing surface, allowing you to use it as a Direct3D render-target.
- SwapEffect: Set this to DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL.
- Format: The DXGI_FORMAT_B8G8R8A8_UNORM format specifies 32-bit color: 8 bits for each of the three RGB color channels, and 8 bits for the alpha channel.
- BufferCount: Set this to 2 for a traditional double-buffered behavior to avoid tearing. Set the buffer count to 3 if your graphics content takes more than one monitor refresh cycle to render a single frame (at 60 Hz for example, the threshold is more than 16 ms).
- SampleDesc: This field controls multisampling. Set Count to 1 and Quality to 0 for flip-model swap chains. (To use multisampling with flip-model swap chains, draw on a separate multisampled render target and then resolve that target to the swap chain just before presenting it. Example code is provided in Multisampling in Windows Store apps.)
After you have specified a configuration for the swap chain, you must use the same DXGI factory that created the Direct3D device (and device context) in order to create the swap chain.
Get the ID3D11Device reference you created previously. Upcast it to IDXGIDevice3 (if you haven’t already) and then call IDXGIDevice::GetAdapter to acquire the DXGI adapter. Get the parent factory for that adapter by calling IDXGIFactory2::GetParent (IDXGIFactory2 inherits from IDXGIObject)—now you can use that factory to create the swap chain by calling CreateSwapChainForHwnd, as seen in the following code sample.
If you’re just starting out, it’s probably best to use the configuration shown here. Now at this point, if you are already familiar with previous versions of DirectX you might be asking: «Why didn’t we create the device and swap chain at the same time, instead of walking back through all of those classes?» The answer is efficiency: swap chains are Direct3D device resources, and device resources are tied to the particular Direct3D device that created them. If you create a new device with a new swap chain, you have to recreate all your device resources using the new Direct3D device. So by creating the swap chain with the same factory (as shown above), you are able to recreate the swap chain and continue using the Direct3D device resources you already have loaded!
Now you’ve got a window from the operating system, a way to access the GPU and its resources, and a swap chain to display the rendering results. All that’s left is to wire the whole thing together!
Create a render target for drawing
The shader pipeline needs a resource to draw pixels into. The simplest way to create this resource is to define a ID3D11Texture2D resource as a back buffer for the pixel shader to draw into, and then read that texture into the swap chain.
To do this, you create a render-target view. In Direct3D, a view is a way to access a specific resource. In this case, the view enables the pixel shader to write into the texture as it completes its per-pixel operations.
Let’s look at the code for this. When you set DXGI_USAGE_RENDER_TARGET_OUTPUT on the swap chain, that enabled the underlying Direct3D resource to be used as a drawing surface. So to get our render target view, we just need to get the back buffer from the swap chain and create a render target view bound to the back buffer resource.
Also create a depth-stencil buffer. A depth-stencil buffer is just a particular form of ID3D11Texture2D resource, which is typically used to determine which pixels have draw priority during rasterization based on the distance of the objects in the scene from the camera. A depth-stencil buffer can also be used for stencil effects, where specific pixels are discarded or ignored during rasterization. This buffer must be the same size as the render target. Note that you cannot read from or render to the frame buffer depth-stencil texture because it is used exclusively by the shader pipeline before and during final rasterization.
Also create a view for the depth-stencil buffer as an ID3D11DepthStencilView. The view tells the shader pipeline how to interpret the underlying ID3D11Texture2D resource — so if you don’t supply this view no per-pixel depth testing is performed, and the objects in your scene may seem a bit inside-out at the very least!
The last step is to create a viewport. This defines the visible rectangle of the back buffer displayed on the screen; you can change the part of the buffer that is displayed on the screen by changing the parameters of the viewport. This code targets the whole window size—or the screen resolution, in the case of full-screen swap chains. For fun, change the supplied coordinate values and observe the results.
And that’s how you go from nothing to drawing pixels in a window! As you start out, it’s a good idea to become familiar with how DirectX, through DXGI, manages the core resources you need to start drawing pixels.
Next you’ll look at the structure of the graphics pipeline; see Understand the DirectX app template’s rendering pipeline.