Selecting a Device
Applications can query hardware to detect the supported Microsoft Direct3D device types. This section contains information on the primary tasks involved in enumerating display adapters and selecting Direct3D devices.
An application must perform a series of tasks to select an appropriate Direct3D device. Note that the following steps are intended for a full-screen application. In most cases, a windowed application can skip most of these steps.
- Initially, the application must enumerate the display adapters on the system. An adapter is a physical piece of hardware. Note that the graphics card might contain more than a single adapter, as is the case with a dual-head display. For a detailed example of enumerating adapters, see (SDK root)\Samples\Managed\Common\dxmutenum.cs. Applications that are not concerned with multiple-monitor support can disregard this step and use the default adapter enumeration.
- For each adapter, the application enumerates the supported display modes with the Adapters property of the Manager object. The collection of adapters can be queried with the AdapterListCollection object.
- If required, the application checks for the presence of hardware acceleration in each enumerated display mode by checking the return value of the checkType parameter of Manager.CheckDeviceType. Other parameters of CheckDeviceType can provide additional information on the current display and back buffer formats of the device.
- The application checks for the desired level of functionality for the device on this adapter using the Device.DeviceCaps property. This property returns a Caps structure that describes the capabilities of the device. Those devices that do not support the required functionality will not contain a valid structure. The device capability returned by DeviceCaps is guaranteed to be constant for a device across all display modes verified by CheckDeviceType.
- Devices can always render to surfaces of the format of an enumerated display mode that is supported by the device. If the application is required to render to a surface of a different format, it can call CheckDeviceType. If the device can render to the format, then it is guaranteed that all capabilities returned by DeviceCaps are applicable.
- Lastly, the application can determine if multisampling techniques, such as full-scene antialiasing, are supported for a render format by using the CheckDeviceMultiSampleType method.
After completing the above steps, the application should have a list of display modes in which it can operate. The final step is to verify that enough device-accessible memory is available to accommodate the required number of buffers and antialiasing. This test is necessary because the memory consumption for the mode and multisample combination is impossible to predict without verifying it. Moreover, some display adapter architectures might not have a constant amount of device-accessible memory. This means that an application should be able to report out-of-video-memory failures when going into full-screen mode. Typically, an application should remove full-screen mode from the list of modes it offers to a user, or it should attempt to consume less memory by reducing the number of back buffers or using a simpler multisampling technique.
A windowed application performs a similar set of tasks, as follows.
- It determines the desktop rectangle covered by the client area of the window.
- It enumerates adapters, looking for the adapter for which the monitor covers the client area. If the client area is owned by more than one adapter, then the application can choose to drive each adapter independently, or to drive a single adapter and have Direct3D transfer pixels from one device to another at presentation. The application can also disregard the above two steps and use the default adapter, although this might result in slower operation when the window is placed on a secondary monitor. The default adapter is the first ordinal identified by the DeviceCreationParameters.AdapterOrdinal. The adapter ordinal value can be queried with the GetDeviceCaps method or returned by the AdapterInformation.Adapter property.
- The application should call CheckDeviceType to determine if the device can support rendering to a back buffer of the specified format while in desktop mode. The AdapterInformation.CurrentDisplayMode property can be used to determine the desktop display format.