📄 dxutenum.cpp
字号:
}
else
{
pOptimalDeviceSettings->pp.MultiSampleType = pDeviceSettingsIn->pp.MultiSampleType;
pOptimalDeviceSettings->pp.MultiSampleQuality = pDeviceSettingsIn->pp.MultiSampleQuality;
}
//---------------------
// Swap effect
//---------------------
if( pMatchOptions->eSwapEffect == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
else
pOptimalDeviceSettings->pp.SwapEffect = pDeviceSettingsIn->pp.SwapEffect;
//---------------------
// Depth stencil
//---------------------
if( pMatchOptions->eDepthFormat == DXUTMT_IGNORE_INPUT &&
pMatchOptions->eStencilFormat == DXUTMT_IGNORE_INPUT )
{
UINT nBackBufferBits = DXUTGetD3D9ColorChannelBits( pOptimalDeviceSettings->pp.BackBufferFormat );
if( nBackBufferBits >= 8 )
pOptimalDeviceSettings->pp.AutoDepthStencilFormat = D3DFMT_D32;
else
pOptimalDeviceSettings->pp.AutoDepthStencilFormat = D3DFMT_D16;
}
else
{
pOptimalDeviceSettings->pp.AutoDepthStencilFormat = pDeviceSettingsIn->pp.AutoDepthStencilFormat;
}
//---------------------
// Present flags
//---------------------
if( pMatchOptions->ePresentFlags == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->pp.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
else
pOptimalDeviceSettings->pp.Flags = pDeviceSettingsIn->pp.Flags;
//---------------------
// Refresh rate
//---------------------
if( pMatchOptions->eRefreshRate == DXUTMT_IGNORE_INPUT )
pOptimalDeviceSettings->pp.FullScreen_RefreshRateInHz = 0;
else
pOptimalDeviceSettings->pp.FullScreen_RefreshRateInHz = pDeviceSettingsIn->pp.FullScreen_RefreshRateInHz;
//---------------------
// Present interval
//---------------------
if( pMatchOptions->ePresentInterval == DXUTMT_IGNORE_INPUT )
{
// For windowed and fullscreen, default to D3DPRESENT_INTERVAL_DEFAULT
// which will wait for the vertical retrace period to prevent tearing.
// For benchmarking, use D3DPRESENT_INTERVAL_IMMEDIATE which will
// will wait not for the vertical retrace period but may introduce tearing.
pOptimalDeviceSettings->pp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
}
else
{
pOptimalDeviceSettings->pp.PresentationInterval = pDeviceSettingsIn->pp.PresentationInterval;
}
}
//--------------------------------------------------------------------------------------
// Returns false for any CD3D9EnumDeviceSettingsCombo that doesn't meet the preserve
// match options against the input pDeviceSettingsIn.
//--------------------------------------------------------------------------------------
bool DXUTDoesD3D9DeviceComboMatchPreserveOptions( CD3D9EnumDeviceSettingsCombo* pDeviceSettingsCombo,
DXUTD3D9DeviceSettings* pDeviceSettingsIn,
DXUTMatchOptions* pMatchOptions )
{
//---------------------
// Adapter ordinal
//---------------------
if( pMatchOptions->eAdapterOrdinal == DXUTMT_PRESERVE_INPUT &&
(pDeviceSettingsCombo->AdapterOrdinal != pDeviceSettingsIn->AdapterOrdinal) )
return false;
//---------------------
// Device type
//---------------------
if( pMatchOptions->eDeviceType == DXUTMT_PRESERVE_INPUT &&
(pDeviceSettingsCombo->DeviceType != pDeviceSettingsIn->DeviceType) )
return false;
//---------------------
// Windowed
//---------------------
if( pMatchOptions->eWindowed == DXUTMT_PRESERVE_INPUT &&
(pDeviceSettingsCombo->Windowed != pDeviceSettingsIn->pp.Windowed) )
return false;
//---------------------
// Adapter format
//---------------------
if( pMatchOptions->eAdapterFormat == DXUTMT_PRESERVE_INPUT &&
(pDeviceSettingsCombo->AdapterFormat != pDeviceSettingsIn->AdapterFormat) )
return false;
//---------------------
// Vertex processing
//---------------------
// If keep VP and input has HWVP, then skip if this combo doesn't have HWTL
if( pMatchOptions->eVertexProcessing == DXUTMT_PRESERVE_INPUT &&
((pDeviceSettingsIn->BehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING) != 0) &&
((pDeviceSettingsCombo->pDeviceInfo->Caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0) )
return false;
//---------------------
// Resolution
//---------------------
// If keep resolution then check that width and height supported by this combo
if( pMatchOptions->eResolution == DXUTMT_PRESERVE_INPUT )
{
bool bFound = false;
for( int i=0; i< pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetSize(); i++ )
{
D3DDISPLAYMODE displayMode = pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetAt( i );
if( displayMode.Format != pDeviceSettingsCombo->AdapterFormat )
continue; // Skip this display mode if it doesn't match the combo's adapter format
if( displayMode.Width == pDeviceSettingsIn->pp.BackBufferWidth &&
displayMode.Height == pDeviceSettingsIn->pp.BackBufferHeight )
{
bFound = true;
break;
}
}
// If the width and height are not supported by this combo, return false
if( !bFound )
return false;
}
//---------------------
// Back buffer format
//---------------------
if( pMatchOptions->eBackBufferFormat == DXUTMT_PRESERVE_INPUT &&
pDeviceSettingsCombo->BackBufferFormat != pDeviceSettingsIn->pp.BackBufferFormat )
return false;
//---------------------
// Back buffer count
//---------------------
// No caps for the back buffer count
//---------------------
// Multisample
//---------------------
if( pMatchOptions->eMultiSample == DXUTMT_PRESERVE_INPUT )
{
bool bFound = false;
for( int i=0; i<pDeviceSettingsCombo->multiSampleTypeList.GetSize(); i++ )
{
D3DMULTISAMPLE_TYPE msType = pDeviceSettingsCombo->multiSampleTypeList.GetAt(i);
DWORD msQuality = pDeviceSettingsCombo->multiSampleQualityList.GetAt(i);
if( msType == pDeviceSettingsIn->pp.MultiSampleType &&
msQuality > pDeviceSettingsIn->pp.MultiSampleQuality )
{
bFound = true;
break;
}
}
// If multisample type/quality not supported by this combo, then return false
if( !bFound )
return false;
}
//---------------------
// Swap effect
//---------------------
// No caps for swap effects
//---------------------
// Depth stencil
//---------------------
// If keep depth stencil format then check that the depth stencil format is supported by this combo
if( pMatchOptions->eDepthFormat == DXUTMT_PRESERVE_INPUT &&
pMatchOptions->eStencilFormat == DXUTMT_PRESERVE_INPUT )
{
if( pDeviceSettingsIn->pp.AutoDepthStencilFormat != D3DFMT_UNKNOWN &&
!pDeviceSettingsCombo->depthStencilFormatList.Contains( pDeviceSettingsIn->pp.AutoDepthStencilFormat ) )
return false;
}
// If keep depth format then check that the depth format is supported by this combo
if( pMatchOptions->eDepthFormat == DXUTMT_PRESERVE_INPUT &&
pDeviceSettingsIn->pp.AutoDepthStencilFormat != D3DFMT_UNKNOWN )
{
bool bFound = false;
UINT dwDepthBits = DXUTGetDepthBits( pDeviceSettingsIn->pp.AutoDepthStencilFormat );
for( int i=0; i<pDeviceSettingsCombo->depthStencilFormatList.GetSize(); i++ )
{
D3DFORMAT depthStencilFmt = pDeviceSettingsCombo->depthStencilFormatList.GetAt(i);
UINT dwCurDepthBits = DXUTGetDepthBits( depthStencilFmt );
if( dwCurDepthBits - dwDepthBits == 0)
bFound = true;
}
if( !bFound )
return false;
}
// If keep depth format then check that the depth format is supported by this combo
if( pMatchOptions->eStencilFormat == DXUTMT_PRESERVE_INPUT &&
pDeviceSettingsIn->pp.AutoDepthStencilFormat != D3DFMT_UNKNOWN )
{
bool bFound = false;
UINT dwStencilBits = DXUTGetStencilBits( pDeviceSettingsIn->pp.AutoDepthStencilFormat );
for( int i=0; i<pDeviceSettingsCombo->depthStencilFormatList.GetSize(); i++ )
{
D3DFORMAT depthStencilFmt = pDeviceSettingsCombo->depthStencilFormatList.GetAt(i);
UINT dwCurStencilBits = DXUTGetStencilBits( depthStencilFmt );
if( dwCurStencilBits - dwStencilBits == 0)
bFound = true;
}
if( !bFound )
return false;
}
//---------------------
// Present flags
//---------------------
// No caps for the present flags
//---------------------
// Refresh rate
//---------------------
// If keep refresh rate then check that the resolution is supported by this combo
if( pMatchOptions->eRefreshRate == DXUTMT_PRESERVE_INPUT )
{
bool bFound = false;
for( int i=0; i<pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetSize(); i++ )
{
D3DDISPLAYMODE displayMode = pDeviceSettingsCombo->pAdapterInfo->displayModeList.GetAt( i );
if( displayMode.Format != pDeviceSettingsCombo->AdapterFormat )
continue;
if( displayMode.RefreshRate == pDeviceSettingsIn->pp.FullScreen_RefreshRateInHz )
{
bFound = true;
break;
}
}
// If refresh rate not supported by this combo, then return false
if( !bFound )
return false;
}
//---------------------
// Present interval
//---------------------
// If keep present interval then check that the present interval is supported by this combo
if( pMatchOptions->ePresentInterval == DXUTMT_PRESERVE_INPUT &&
!pDeviceSettingsCombo->presentIntervalList.Contains( pDeviceSettingsIn->pp.PresentationInterval ) )
return false;
return true;
}
//--------------------------------------------------------------------------------------
// Returns a ranking number that describes how closely this device
// combo matches the optimal combo based on the match options and the optimal device settings
//--------------------------------------------------------------------------------------
float DXUTRankD3D9DeviceCombo( CD3D9EnumDeviceSettingsCombo* pDeviceSettingsCombo,
DXUTD3D9DeviceSettings* pOptimalDeviceSettings,
D3DDISPLAYMODE* pAdapterDesktopDisplayMode )
{
float fCurRanking = 0.0f;
// Arbitrary weights. Gives preference to the ordinal, device type, and windowed
const float fAdapterOrdinalWeight = 1000.0f;
const float fDeviceTypeWeight = 100.0f;
const float fWindowWeight = 10.0f;
const float fAdapterFormatWeight = 1.0f;
const float fVertexProcessingWeight = 1.0f;
const float fResolutionWeight = 1.0f;
const float fBackBufferFormatWeight = 1.0f;
const float fMultiSampleWeight = 1.0f;
const float fDepthStencilWeight = 1.0f;
const float fRefreshRateWeight = 1.0f;
const float fPresentIntervalWeight = 1.0f;
//---------------------
// Adapter ordinal
//---------------------
if( pDeviceSettingsCombo->AdapterOrdinal == pOptimalDeviceSettings->AdapterOrdinal )
fCurRanking += fAdapterOrdinalWeight;
//---------------------
// Device type
//---------------------
if( pDeviceSettingsCombo->DeviceType == pOptimalDeviceSettings->DeviceType )
fCurRanking += fDeviceTypeWeight;
// Slightly prefer HAL
if( pDeviceSettingsCombo->DeviceType == D3DDEVTYPE_HAL )
fCurRanking += 0.1f;
//---------------------
// Windowed
//---------------------
if( pDeviceSettingsCombo->Windowed == pOptimalDeviceSettings->pp.Windowed )
fCurRanking += fWindowWeight;
//---------------------
// Adapter format
//---------------------
if( pDeviceSettingsCombo->AdapterFormat == pOptimalDeviceSettings->AdapterFormat )
{
fCurRanking += fAdapterFormatWeight;
}
else
{
int nBitDepthDelta = abs( (long) DXUTGetD3D9ColorChann
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -