This is a collection of Frequently Asked Questions (FAQ) about Microsoft DirectX.
Should game developers really care about supporting x64 editions?
Absolutely. x64 technology is widely available in the market. The majority of new CPUs sold in the past few years, and
almost all processor lines in development from AMD and Intel, are x64-capable. Windows XP Professional x64 Edition
introduced the OS enabling technology for x64 released in April of 2005. Because x64 editions require a new
generation of 64-bit native drivers, this first release was limited to OEM distribution.
With Windows Vista, customers are free to choose either 32-bit or 64-bit editions when purchasing Windows-based
computers, and licenses for Windows Vista are valid for both 32-bit or 64-bit editions of the OS. In addition, many
64-bit drivers are available in the box, and device manufactures are required to provide both 32-bit and 64-bit
native drivers as part the Windows Logo Program.
All of these factors will greatly increase the deployments of 64-bit editions of Windows. As new computers start
shipping with more than 2 GB of physical RAM, the incentive to use a 32-bit operating system greatly diminishes in
favor of 64-bit editions. Sixty-four-bit technology fully supports 32-bit native code, although 64-bit native
implementations are required to take full advantage of the new 64-bit memory space. Every 32-bit application should
have 64-bit compatibility as a minimum shipping requirement, and meeting that requirement is a baseline requirement
for Windows Vista compatibility. Incompatibilities typically arise from use of 16-bit code designed for the Windows
3.1 operating system or installing drivers that are not provided in both 32-bit and 64-bit native forms.
For more details on 64-bit technology, see
64-bit programming for Game Developers.
Should game developers still be publishing games for Windows 95, Windows 98 or Windows ME?
Not anymore for two reasons: performance and feature set.
If the minimum CPU speed required for your game is 1.2GHz or above (which is more common for high performance titles),
then the vast majority of eligible computers will be running Windows XP. By the time computers with CPU speeds above
1.2GHz were being sold, Windows XP was installed as the default operating system by almost all manufacturers. This
means that there are many features found in Windows XP that today's game developers should be taking advantage of
including:
-
Improved multitasking - which results in a better, smoother experience for video, audio and gaming.
-
More stable video driver model - which allows easier debugging, smoother game play and better performance.
-
Easier configuration for networking - which allows easier access to multi-player games.
-
Support for DMA transfers by default from hard drives - which results in smoother, faster loading applications.
-
Windows error reporting - which results in a more stable OS, drivers and applications.
-
Unicode support - which greatly simplifies localization issues.
-
Better security and stability - which results in better consumer experiences.
-
Better support for modern hardware - most of which no longer uses Windows 98 drivers.
-
Improved memory management - which results in better stability and security.
-
Improved NTFS file system - which is more resistant to failure, and has better performance with security features.
Should game developers still be publishing games for Windows 2000?
Not anymore. In addition to the reasons listed in
Should
game developers still be publishing games for Windows 95, Windows 98 or Windows ME?, Windows 2000 does not have
these features:
-
Windows XP supports advanced processor features such as Hyper-Threading,
Multi-Core
and x64.
-
Windows XP supports side-by-side components which significantly reduces application versioning conflicts.
-
Windows XP supports no-execute memory protection which helps prevent malicious programs and can aid debugging.
-
Windows XP has improved support for advanced AGP and PCI Express
based video cards.
-
Windows XP supports fast user switching, remote desktop and remote assistance which can help lower product support
costs.
-
Performance tools like PIX (in the DirectX Developer SDK) no longer support Windows 2000.
In short, Windows 2000 was never designed or marketed as a consumer operating system.
What are the differences between the various editions of Windows Vista?
How do they impact my DirectX application?
The Windows Vista family includes five editions:
Home Basic and Home Premium are consumer-focused versions, with features like Family Safety (formerly known as Parental
Controls), and Home Premium includes Media Center. Business and Enterprise are corporate-focused editions, with
features like Domain join and Remote Desktop/Terminal Services. The Ultimate edition combines all features of both
the consumer and corporate editions into one version. All editions come in both 32-bit (x86) and 64-bit (x64)
editions, and users are free to use the same product identifier for both platforms.
The technology underlying the various editions is identical, and they all have the same version of the DirectX runtime
and other components. However, the editions do have some minor differences with respect to gaming:
-
Games Explorer exists on all editions, but the Games shortcut on the Start menu is only in Home Basic,
Home Premium, and Ultimate. Games Explorer can still be found on all editions (by clicking Start,
pointing to All Programs, and then clicking Games), and the IGameExplorer interface
functions on all editions.
-
The games that are included with Windows are not available by default on Business and Enterprise, but they can be
enabled by the administrator.
-
Family Safety and game ratings do not display or have any influence on the behavior of Business or Enterprise, and they
are disabled on Ultimate when a domain is joined.
User Account Control settings have the same defaults on all editions, but they can be overridden by Group Policy
settings for the domain on Business, Enterprise, and Ultimate. For example, the policy setting User Account
Control: Behavior of the elevation prompt for standard users may well be set to Automatically deny
elevation requests in many business settings to enhance security, and many users in those environments will
always be running as standard users without the ability to even choose to run as Administrator. Any program (such as
an installer) that requires administrative rights, either due to legacy setup detection or to having a manifest that
specifies the requested execution level as "requireAdministrator", will always fail to start in such situations.
Other policy settings, such as User Account Control: Only elevate executables that are signed and
validated, can also prevent your installer from functioning if you do not sign your executable file using
Authenticode.
These types of policy changes can be applied to any edition of Windows Vista, but are more likely on computers that are
joined to a domain.
What are the differences between the various editions of Windows 7?
How do they impact my DirectX application?
The majority of Windows 7 users will likely have one of two editions: Windows 7 Home Premium, for home users, or Windows
7 Professional, for business users and developers. For large corporations, there is the volume-licensed Windows 7
Enterprise edition, which includes all of Windows 7 features; Windows 7 Ultimate is the retail equivalent of that
edition.
Windows 7 Starter Edition is available world-wide to OEMs, and it is expected to be deployed primarly with
netbooks, ultra-low-power notebook computers. Windows 7 Home Basic is available only in
emerging markets.
Note that all editions of Windows 7 (except Starter Edition) are available for both 32-bit (x86) and 64-bit (x64)
versions, and all retail packages of Windows 7 include media for both versions. As with Windows Vista, users are
free to use the same retail product identifier on either platform.
The underlying technology in the various editions is identical, and all editions have the same version of the DirectX
runtime and other components. They do have some differences with respect to gaming features:
-
Games Explorer exists in all editions, but the Games shortcut on the Start menu is hidden by default in Windows
7 Professional and Enterprise. Games Explorer can still be found on the Start menu (by clicking All
Programs and then double-clicking Games), and the direct Games shortcut can be enabled by
the user.
-
The games that are included with Windows are not available by default on Windows 7 Professional and Enterprise, but they
can be enabled by the administrator.
-
Family Safety and game ratings are available on all editions, but they are disabled on Windows 7 Professional,
Enterprise, and Ultimate when the operating system joins a domain. As with Windows Vista Ultimate, this feature
can be re-enabled on computer that has joined a domain.
User account control (UAC) settings can be affected by Group Policy settings on Windows 7 Professional, Enterprise, and
Ultimate editions, much like Windows Vista. For more information, see
What
are the differences between the various editions of Windows Vista? How do they impact my DirectX application?
Will DirectX 10 be available for Windows XP?
No. Windows Vista, which has DirectX 10, includes an updated DirectX runtime based on the runtime in Windows XP
SP2 (DirectX 9.0c) with changes to work with the new Windows Display Driver Model (WDDM) and the new audio driver
stack, and with other updates in the operating system. In addition to Direct3D 9, Windows Vista supports two new
interfaces when the correct video hardware and drivers are present: Direct3D9Ex and Direct3D10.
Since these new interfaces rely on the WDDM technology, they will never be available on earlier versions of Windows. All
the other changes made to DirectX technologies for Windows Vista are also specific to the new version of Windows.
The name DirectX 10 is misleading in that many technologies shipping in the DirectX SDK (XACT,
XINPUT, D3DX) are not encompassed by this version number. So, referring to the version number of the
DirectX runtime as a whole has lost much of its meaning, even for 9.0c. The DirectX Diagnostic
Tool (DXdiag.exe) on Windows Vista does report DirectX 10, but this really only refers to
Direct3D 10.
Will DirectX 11 be available for Windows Vista or Windows XP?
DirectX 11 is built into Windows 7, and it is available as an update for Windows Vista (see
http://go.microsoft.com/fwlink/?LinkId=160189). This
includes the Direct3D 11 API, DirectX Graphics Infrastructure (DXGI) 1.1, 10Level9 feature levels, Windows Advanced
Rasterization Platform (WARP) 10 software rendering device, Direct2D, DirectWrite, and an update to the Direct3D
10.1 API to support 10Level9 and WARP 10.
For the same reasons noted in the preceding question
(Will
DirectX 10 be available for Windows XP?), Direct3D 11 and related APIs are not available on Windows XP.
What Happened to DirectShow? I can't find it in the DirectX SDK.
DirectShow was removed from the DirectX SDK as of April 2005. You can obtain the headers, libraries, tools, and samples
for DirectShow in the Windows Software Development Kit (formerly known as the Platform SDK).
DirectSetup in the DirectX SDK continues to support the redistribution of DirectShow's system components, and the
latest components are already installed on the following operating systems: Microsoft Windows XP Service Pack
2, Windows XP Professional x64 Edition, Windows Server 2003 Service Pack 1, and Windows
Vista.
What changes were made to the DirectX runtime for Windows Vista?
The primary changes were made to support the new Windows Display Driver Model. For details on the new driver model, on
the impacts on Direct3D 9, and on the two new graphics interfaces, Direct3D 9Ex and Direct3D 10, please review
Graphics APIs in Windows. New graphics APIs for
Windows 7—Direct3D 11, Direct2D, DirectWrite, DXGI 1.1, and an updated Direct3D 10.1—are available as
an update for Windows Vista (see
http://go.microsoft.com/fwlink/?LinkId=160189).
Windows Vista Service Pack 1 includes an updated version of the DirectX runtime. This update extends support of Windows
Vista to include Direct3D 10.1, exposing new optional hardware features. (All hardware that is capable of supporting
Direct3D 10.1 also fully supports all of the features of Direct3D 10.)
DirectSound was updated to expose the capabilities of the new Windows Vista audio driver stack, which supports
multi-channel software buffers. The Direct3D Retained Mode API was completely removed from Windows Vista. DirectPlay
Voice was also removed, as well as DirectPlay's NAT Helper and DirectInput's action-mapper UI. Support for the
DirectX 7 and DirectX 8 interfaces for Visual Basic 6.0 is not available on Windows Vista.
What changes were made to the DirectX runtime for Windows 7?
Windows 7 includes all of the DirectX runtime components found in Windows Vista, and adds Direct3D 11, DXGI 1.1,
10Level9 feature levels, the WARP10 software device, Direct2D, DirectWrite, and an update to Direct3D 10.1 to
support 10Level9 and WARP10. For more information, see
Graphics APIs in Windows.
All other components are identical to Windows Vista, with the addition of 64-bit (x64) native support for the core
DirectMusic API related to timestamped MIDI. The performance layer of DirectMusic remains deprecated, and it is only
available to 32-bit applications on Windows 7 for application compatability. Note that 64-bit native support of
DirectMusic is not available on Windows Vista.
I think I have found a driver bug, what do I do?
First, ensure you have checked the results with the Reference Rasterizer. Then check the results with the latest WHQL
certified version of the IHVs driver. You can programmatically check the WHQL status using the
GetAdapterIdentifier() method on the IDirect3D9 interface passing the D3DENUM_WHQL_LEVEL flag.
Why do I get so many error messages when I try to compile the samples?
You probably don't have your include path set correctly. Many compilers, including Microsoft Visual C++, include an
earlier version of the SDK, so if your include path searches the standard compiler include directories first, you'll
get incorrect versions of the header files. To remedy this issue, make sure the include path and library paths are
set to search the Microsoft DirectX include and library paths first. See also the dxreadme.txt file in the SDK. If
you install the DirectX SDK and you are using Visual C++, the installer can optionally set up the include paths for
you.
I get linker errors about multiple or missing symbols for globally unique identifiers (GUIDs), what do I do?
The various GUIDs you use should be defined once and only once. The definition for the GUID will be inserted if you
#define the INITGUID symbol before including the DirectX header files. Therefore, you should make sure that this
only occurs for one compilation unit. An alternative to this method is to link with the dxguid.lib library, which
contains definitions for all of the DirectX GUIDs. If you use this method (which is recommended), then you should
never #define the INITGUID symbol.
Can I cast a pointer to a DirectX interface to a lower version number?
No. DirectX interfaces are COM interfaces. This means that there is no requirement for higher numbered interfaces to be
derived from corresponding lower numbered ones. Therefore, the only safe way to obtain a different interface to a
DirectX object is to use the QueryInterface method of the interface. This method is part of the standard IUnknown
interface, from which all COM interfaces must derive.
Can I mix the use of DirectX 9 components and DirectX 8 or earlier components within the same application?
You can freely mix different components of differing version; for example, you could use DirectInput 8 with Direct3D 9
in the same application. However, you generally cannot mix different versions of the same component within the same
application; for example, you cannot mix DirectDraw 7 with Direct3D 9 (since these are effectively the same
component as DirectDraw has been subsumed into Direct3D as of DirectX 8). There are exceptions, however, such as the
use of Direct3D 9 and Direct3D 10 together in the same application, which is allowed.
Can I mix the use of Direct3D 9 and Direct3D 10 within the same application?
Yes, you may use these versions of Direct3D together in the same application.
What do the return values from the Release or AddRef methods mean?
The return value will be the current reference count of the object. However, the COM specification states that you
should not rely on this and the value is generally only available for debugging purposes. The values you observe may
be unexpected since various other system objects may be holding references to the DirectX objects you create. For
this reason, you should not write code that repeatedly calls Release until the reference count is zero, as the
object may then be freed even though another component may still be referencing it.
Does it matter in which order I release DirectX interfaces?
It shouldn't matter because COM interfaces are reference counted. However, there are some known bugs with the release
order of interfaces in some versions of DirectX. For safety, you are advised to release interfaces in reverse
creation order when possible.
What is a smart pointer and should I use it?
A smart pointer is a C++ template class designed to encapsulate pointer functionality. In particular, there are standard
smart pointer classes designed to encapsulate COM interface pointers. These pointers automatically perform
QueryInterface instead of a cast and they handle AddRef and Release for you. Whether you should use them is largely
a matter of taste. If your code contains lots of copying of interface pointers, with multiple AddRefs and Releases,
then smart pointers can probably make your code neater and less error prone. Otherwise, you can do without them.
Visual C++ includes a standard Microsoft COM smart pointer, defined in the "comdef.h" header file (look up com_ptr_t
in the help).
I have trouble debugging my DirectX application, any tips?
The most common problem with debugging DirectX applications is attempting to debug while a DirectDraw surface is locked.
This situation can cause a "Win16 Lock" on Microsoft Windows 9x systems, which prevents the debugger window from
painting. Specifying the D3DLOCK_NOSYSLOCK flag when locking the surface can usually eliminate this. Windows 2000
does not suffer from this problem. When developing an application, it is useful to be running with the debugging
version of the DirectX runtime (selected when you install the SDK), which performs some parameter validation and
outputs useful messages to the debugger output.
What's the correct way to check return codes?
Use the SUCCEEDED and FAILED macros. DirectX methods can return multiple success and failure codes, so a simple:
== D3D_OK
or similar test will not always suffice.
How do I disable ALT+TAB and other task switching?
You don't! Games need to be able to handle task switching gracefully, as they many things cause it to happen: ALT+TAB,
remote desktop connections, Fast User Switching, Parental Controls usage limits, and many other events.
At the same time, two common sources of accidental task switching on games with keyboard-centric control schemes are
pressing the Windows logo key and activating the accessibility feature StickyKeys with the SHIFT key. To address
these cases by disabling the functionality, see the techniques described in
Disabling Shortcut Keys in Games.
Is there a recommended book explaining COM?
Inside COM by Dale Rogerson, published by Microsoft Press, is an excellent introduction to COM. For a more detailed look
at COM, the book Essential COM by Don Box, published by Longman, is also highly recommended.
What is managed code?
Managed code is code that has its execution managed by the .NET Framework Common Language Runtime (CLR). It refers to a
contract of cooperation between natively executing code and the runtime. This contract specifies that at any point
of execution, the runtime may stop an executing CPU and retrieve information specific to the current CPU instruction
address. Information that must be query-able generally pertains to runtime state, such as register or stack memory
contents.
Before the code is run, the IL is compiled into native executable code. And, since this compilation happens by the
managed execution environment (or, more correctly, by a runtime-aware compiler that knows how to target the managed
execution environment), the managed execution environment can make guarantees about what the code is going to do. It
can insert traps and appropriate garbage collection hooks, exception handling, type safety, array bounds and index
checking, and so forth. For example, such a compiler makes sure to lay out stack frames and everything just right so
that the garbage collector can run in the background on a separate thread, constantly walking the active call stack,
finding all the roots, chasing down all the live objects. In addition because the IL has a notion of type safety the
execution engine will maintain the guarantee of type safety eliminating a whole class of programming mistakes that
often lead to security holes.
In contrast this to the unmanaged world: Unmanaged executable files are basically a binary image, x86 code, loaded into
memory. The program counter gets put there and that's the last the OS knows. There are protections in place around
memory management and port I/O and so forth, but the system doesn't actually know what the application is doing.
Therefore, it can't make any guarantees about what happens when the application runs.
What books are there about general Windows programming?
Lots. However, the two that are highly recommended are:
How do I debug using the Windows symbol files?
Microsoft publish stripped symbols for all system DLLs (plus a few others). To access them add the following to your
symbol path in the project settings inside Visual Studio:
srv*http://msdl.microsoft.com/download/symbols
for caching symbols locally use the following syntax:
srv*c:\cache*http://msdl.microsoft.com/download/symbols
Where c:\cache is a local directory for caching symbol files.
Why do I get a burst of static when my application starts up? I notice this problem with other applications too.
You probably installed the debug DirectX runtime. The debug version of the runtime fills buffers with static in order to
help developers catch bugs with uninitialized buffers. You cannot guarantee the contents of a DirectSound buffer
after creation; in particular, you cannot assume that a buffer with be zeroed out.
Why I am experiencing a delay in between changing an effects parameters and hearing the results?
Changes in effect parameters do not always take place immediately on DirectX 8. For efficiency, DirectSound processes
100 milliseconds of sound data in a buffer, starting at the play cursor, before the buffer is played. This
preprocessing happens after all of the following calls:
IDirectSoundBuffer8::SetCurrentPosition
IDirectSoundBuffer8::SetFX
IDirectSoundBuffer8::Stop
IDirectSoundBuffer8::Unlock
As of DirectX 9, a new FX processing algorithm that processes effects just-in-time addresses this problem and has
reduced the latency. The algorithm has been added to the IDirectSoundBuffer8::Play() call, along with an additional
thread that processes effects just ahead of the write cursor. So you can set parameters at any time and they'll work
as expected. However, note that on a playing buffer there'll be a small delay (usually 100ms) before you hear the
parameter change, because the audio between the play and write cursors (and a bit more padding) has already been
processed at that time.
How do I detect if DSound is installed?
If you do not need to use DirectSoundEnumerate() to list the available DSound devices, don't link your application with
dsound.lib and instead use it via COMs CoCreateInstance(CLSID_DirectSound...) then initialize the DSound object
using Initialize(NULL). If you need to use DirectSoundEnumerate(), you can dynamically load dsound.dll using
LoadLibrary("dsound.dll"); and access its methods using GetProcAddress("DirectSoundEnumerateA/W") and
GetProcAddress("DirectSoundCreateA/W") and so on.
How do I create multichannel audio with WAVEFORMATEXTENSIBLE?
If you can't find an answer to your question in the DirectSound help files, there is a good article with more
information available at Multiple Channel Audio Data and WAVE Files.
How can I use the DirectSound Voice Manager with property sets like EAX?
In DirectSound 9.0 when you duplicate a buffer it is now possible to get the IDirectSoundBuffer8 interface on the
duplicate buffer, which will give you access to the AcquireResources method. This will allow you to associate a
buffer with the DSBCAPS_LOCDEFER flag with a hardware resource. You can then set your EAX parameters on this buffer
before having to call Play().
I am having problems with unreliable behavior when using cursor position notifications. How can I get more accurate information?
I am suffering from performance degradation when using GetCurrentPosition(). What can I do to improve performance?
My DirectSound application is taking up too much CPU time or is performing slowly. Is there anything I can do to optimize my code?
When I stream a buffer it tends to glitch and perform poorly. What's the best way to stream a buffer?
I am playing the same sounds over and over very often and very quickly and sometimes they don't play properly, or the Play() call takes a long time. What should I do?
Startup latency (which is different from streaming latency mentioned above) can be an issue in the case of some hardware
(the Play() call just takes a long time sometimes on certain sound cards). If you really want to reduce this
latency, for twitch sounds (gun shots, footsteps, and so on.) a handy trick is to keep some buffers always looping
and playing silence. When you need to play a twitch sound, pick a free buffer, see where its write cursor is, and
put the sound into the buffer just beyond the write cursor. Some soundcards fail QuerySupport for deferred
properties that I know they support. Is there a workaround? You could just QuerySupport for the non-deferred
versions of the properties and use deferred settings anyway. The most recent soundcard drivers may also fix this
issue.
How do I encode WAV files into WMA?
Refer to the documentation on the Windows Media Encoder at: Windows Media Encoder 9 Series.
How do I decode MP3 files with DirectSound?
DirectSound does not natively support MP3 decoding. You can decode the files in advance yourself (using an ACM codec of
a DirectShow filter), or else just use DirectShow itself, which can do the decode for you; you can then copy the
resulting PCM audio data into your DirectSound buffers.