Advanced Device Selection with DXUT

This topic covers advanced scenarios for controlling Direct3D device creation using DXUT.

Selecting the Best Available Device

DXUT uses a highly flexible method for selecting the best device from the enumerated set. This device enumeration and ranking system can be used independently from the rest of the framework by calling the DXUTFindValidDeviceSettings function:

HRESULT DXUTFindValidDeviceSettings( 
    DXUTDeviceSettings* pOut,
    DXUTDeviceSettings* pIn,
    DXUTMatchOptions*   pMatchOptions )

The pIn parameter accepts a pointer to an existing DXUTDeviceSettings structure. The pMatchOptions parameter is used to specify which of the input device settings must be preserved, which settings should be matched to the closest valid settings, and which settings can be ignored when selecting the best device.

For example, suppose the calling function wants a hal device with a back buffer format of D3DFMT_A2B10G10R10. If the hal device on the system does not support this back buffer format, but a reference device is installed that does, then the function has a choice to either use the reference device or to change to a back buffer format compatible with the hal device. The match options in the DXUT_MATCH_TYPE enumeration let the caller control how these choices are made.

Each match option (see DXUTMatchOptions) must be one of the following types:

DXUT_MATCH_TYPE Value Description
DXUTMT_IGNORE_INPUT Use the closest valid value to a default device setting.
DXUTMT_PRESERVE_INPUT Use the input parameters without change; however, it is possible that no valid device will be found.
DXUTMT_CLOSEST_TO_INPUT Use the closest valid value to the input.

If pMatchOptions is NULL, then all of the match options are assumed to be DXUTMT_IGNORE_INPUT. DXUTFindValidDeviceSettings returns a failure code if no valid device settings can be found; otherwise, the function returns a success code and the valid device settings are written to pOut.

Controlling the Device Selection Dialog

You may wish to control exactly what choices appear in the list of options in DXUT's device selection dialog. For example, it is possible to notify the device selection dialog that an application requires a stencil buffer.

To control the list of options that appear in the framework's device selection dialog, you can use the LPDXUTCALLBACKISDEVICEACCEPTABLE callback function. This will allow you to control which combinations of device settings are allowed (adapter ordinal, device type, adapter format, back buffer format, and windowed). To control the other settings in the device selection dialog, you can use CD3DEnumeration member functions, which are defined in DXUTenum.cpp and declared in the following header file:

(SDK root)\Samples\C++\Common\DXUTenum.h

For example, to control which depth stencil formats are allowed in the dialog, you can use the following code:

CGrowableArray<D3DFORMAT>* pDSList;
pDSList = DXUTGetEnumeration()->GetPossibleDepthStencilFormatList();

nIndex = pDSList->IndexOf( D3DFMT_D16 );
if( nIndex >= 0 ) pDSList->Remove( nIndex );

nIndex = pDSList->IndexOf( D3DFMT_D24X8 );
if( nIndex >= 0 ) pDSList->Remove( nIndex );

nIndex = pDSList->IndexOf( D3DFMT_D24S8 );
if( nIndex >= 0 ) pDSList->Remove( nIndex );

Calls to CD3DEnumeration functions, such as in this example code, must be made before the device is created.