DirectX Installation for Game Developers
This article is intended to address some of the common questions about the DirectX runtime, and using DirectSetup to install DirectX.
- DirectX Runtime
- DirectX Version Number
- DirectX Libraries
- Installation of DirectX by the Game's Installer
- Small Installation Packages
- DirectX Web Installer
- Internal Deployment of the Debug DirectX Runtime
- Driver for the Xbox 360 Controller for Windows
The DirectX runtime consists of core components and optional components.
The core components, such as Direct3D and DirectInput, are considered part of the operating system. The core components for DirectX 9.0c have not changed since the DirectX SDK Summer 2004 Update, and they match what was released with Microsoft Windows XP SP2, Windows XP Pro x64 Edition, and Windows Server 2003 SP1. Windows Vista includes DirectX 10, which supports the Windows Display Driver Model (WDDM) and Direct3D 10.x. Windows 7 and Windows Vista (see KB971644) support DirectX 11, which supports Direct3D 11, Direct2D, DirectWrite, the WARP10 software rendering device, and the 10level9 feature levels. See Graphics APIs in Windows for more details.
The optional components are released in updates of DirectX SDK, and they include D3DX, XACT, XAudio2, XINPUT, Managed DirectX, and other such components. Many of the optional components are regularly updated to integrate customer feedback and expose new features.
The DirectX version number, such as 9.0c, refers only to the version of the core components, such as Direct3D, DirectInput, or DirectSound. This number does not cover the versions of the various optional components that are released in the DirectX SDK, such as D3DX, XACT, XINPUT, and so on.
Generally speaking, the DirectX version number is not meaningful except as a quick reference to the core run-time bits. This number should not be used to check if the correct DirectX runtime is already installed, because it doesn't take into account the optional DirectX components.
In the past, the optional components of the DirectX SDK, including D3DX, were released as static libraries. However, these are now released as dynamic-like libraries (DLL) because of the increased demand for better security practices. DLLs allow servicing of previously released code. If these components were deployed as static libraries, there would be no way for Microsoft to address security issues found after release.
As features are added or changed to the optional components, the names of the corresponding DLLs are also changed to ensure that no regressions are caused to existing games that are using released components. The DLLs for each component live side by side, and game developers can choose exactly which DLL version that the game uses by linking to the corresponding import library.
While ensuring that DLLs are installed on a system isn't as easy as simply linking to static libraries, some changes have been made to the DirectX SDK to address the pain of the DLL model:
- The DirectX redistributable can be configured to contain only those components that your application requires to minimize distribution and media sizes.
- The redistributable folder, Program Files\DirectX SDK\Redist\, now contains a cabinet (.cab) file for every possible optional component, so you don't have to dig up an older SDK to find them.
- Installing the SDK itself installs every possible optional component.
- A DirectX redistributable that contains all the optional components is available as both a Web-based installer and as a downloadable package; see the DirectX Developer Center (DirectX) for more information.
The following are the best practices for adding installation of DirectX to a game's installer:
A game's installation process should install the DirectX redistributable components during every single installation without allowing users to opt-out of it. If you allow opting-out, then some users will guess that they don't need it, and if they actually do, the game will not run.
Do not assume that the latest optional components are already installed on a system, because Windows Update and Service Packs do not provide any of DirectX's optional components. You must install the DirectX runtime either by running dxsetup.exe directly or calling DirectSetup.
Launch setup in silent mode so that users do not accidentally skip updating the DirectX runtime. You can do this by launching dxsetup.exe with the following command:
or by calling DirectSetup and not showing any UI.
If you prompt the user to accept a EULA, then combine that with prompting for acceptance of the DirectX EULA when installing in silent mode so that prompting for acceptance of EULAs happens just once. Prompting should happen before you install anything so that if user doesn't accept, you don't end up with a failed and partial installation.
Because the DirectX version number doesn't refer to anything except the core DirectX components, do not check an installed version before running dxsetup.exe or calling DirectSetup. Also, do not check for a file's existence to test if an optional component is already installed, since this usually will not correctly determine when a component exists but needs updating. However, the DirectX setup package will quickly determine this, and perform the right action.
You can create smaller installation packages for DirectX by stripping the contents of the DirectX redistributable folder down to the minimal set of files required to make the installer work, and retaining any additional components that your game uses.
Depending on your minimum specifications, you might not even need to include the core DirectX 9.0c cabinet files in the redistributable folder of your installation media. A large majority of Windows XP installations have Service Pack 2, which includes the core DirectX 9.0c components, so the DirectX setup operation will be very fast, and will not require a reboot. The smallest package that can be created is about 3 MB, and it can be compressed to about half that size. A package like this contains one version of the D3DX DLL, and it requires that DirectX 9.0c be already present.
The minimal set of files that are required to build a redistributable package are the following files, located in the DirectX SDK Redist folder (Program Files\DirectX SDK\Redist\):
Add to these the cabinet files for the components that you want to install. If you require the users of your application to already have DirectX 9.0c, then you do not need to include DirectX.cab or dxnt.cab, which make up most of the space requirement. DirectX.cab is only needed for Windows 98 and Windows ME; dxnt.cab is only needed for Windows 2000, Windows XP, and Windows XP SP1; and dxdllreg_x86.cab is only required for Windows 2000, Windows XP RTM, Windows XP SP1, and Windows Server 2003 RTM. Also, if you do not make use of DirectShow, or you assume that it is already installed, you can omit BDA.cab, BDANT.cab, and BDAXP.cab.
Continuing with this example, if you are using only the 32-bit version of D3DX for April 2006, you can add Apr2006_d3dx9_30_x86.cab. If you are using the 32-bit August 2006 32-bit version of XINPUT, you add Aug2006_xinput_x86.cab.
If you have a native 64-bit application, you'll need to add the _x64 versions. However, if you have a 32-bit application running on a 64-bit OS, the 32-bit versions of the DLLs will work.
You can then distribute this package of files and launch DirectSetup in silent mode or run dxsetup.exe in the command shell in silent mode. Remember not to guard this package by any version checking of files, and make sure that your users cannot opt out of running the DirectX setup. Either of these events creates a fallible installation process.
The DirectX Web Installer is a downloaded executable file that checks the user's computer for DirectX components, both optional and core. It downloads and installs components as needed after examining the currently-installed components. It is available by clicking Download on the following Web page: http://www.microsoft.com/directx/. Do not redistribute the DirectX Web Installer, simply point users to the Microsoft Web site.
The DirectX Web Installer is updated on a regular basis, and is intended mostly for use by those who play small downloadable games, for which even a few additional megabytes to download is considered too much.
Another way to do this is to point users to the latest DirectX End-User Runtime that includes all components. However, it is a large package. This is mostly useful for scenarios in which having the SDK is not necessary, such as setting up an artist's computer or download-only games for which users are accustomed to fetching additional components.
The debug runtimes of the DirectX components are installed when the DirectX SDK is installed, but installing the SDK on every test computer can be painful. You need to design your setup process to copy the debug runtime DLLs from Program Files\Microsoft DirectX SDK\Developer Runtime\architecture\ to Windows\system32\ or to the game's folder.
However, we strongly recommend that you do not simply copy the released run-time DLLs because it is easy to forget to remove them for the final product. Instead, put the DirectX setup files in a shared folder and run the setup silently from the shared folder.
The user is expected to obtain the XInput driver for Xbox 360 controller from Windows Update or from the controller packaging. The XInput driver is included with Windows Vista.