Change r_maxFrameLatency cvar name and set to default value of 2 frames

This commit is contained in:
Stephen Saunders 2023-05-27 01:40:40 -04:00
parent 34332dbeeb
commit 85e980421a

View file

@ -47,7 +47,7 @@ using nvrhi::RefCountPtr;
#define HR_RETURN(hr) if(FAILED(hr)) return false
idCVar r_graphicsAdapter( "r_graphicsAdapter", "", CVAR_RENDERER | CVAR_INIT | CVAR_ARCHIVE, "Substring in the name the DXGI graphics adapter to select a certain GPU" );
idCVar r_dx12FrameLatency( "r_dx12FrameLatency", "0", CVAR_INTEGER | CVAR_RENDERER | CVAR_INIT, "DX12 maximum frame latency using DXGI swap chain waitable object" );
idCVar r_maxFrameLatency( "r_maxFrameLatency", "2", CVAR_RENDERER | CVAR_INIT | CVAR_ARCHIVE | CVAR_INTEGER, "Maximum frame latency for DXGI swap chains (DX12 only)", 0, 3 );
class DeviceManager_DX12 : public DeviceManager
{
@ -59,7 +59,7 @@ class DeviceManager_DX12 : public DeviceManager
DXGI_SWAP_CHAIN_DESC1 m_SwapChainDesc{};
DXGI_SWAP_CHAIN_FULLSCREEN_DESC m_FullScreenDesc{};
RefCountPtr<IDXGIAdapter> m_DxgiAdapter;
HANDLE m_frameLatencyWaitableObject = nullptr;
HANDLE m_frameLatencyWaitableObject = NULL;
bool m_TearingSupported = false;
std::vector<RefCountPtr<ID3D12Resource>> m_SwapChainBuffers;
@ -313,7 +313,7 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
m_SwapChainDesc.BufferCount = m_DeviceParams.swapChainBufferCount;
m_SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
m_SwapChainDesc.Flags = ( m_DeviceParams.allowModeSwitch ? DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH : 0 ) |
( r_dx12FrameLatency.GetInteger() > 0 ? DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT : 0 );
( r_maxFrameLatency.GetInteger() > 0 ? DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT : 0 );
// Special processing for sRGB swap chain formats.
// DXGI will not create a swap chain with an sRGB format, but its contents will be interpreted as sRGB.
@ -432,9 +432,9 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
hr = pSwapChain1->QueryInterface( IID_PPV_ARGS( &m_SwapChain ) );
HR_RETURN( hr );
if( r_dx12FrameLatency.GetInteger() > 0 )
if( r_maxFrameLatency.GetInteger() > 0 )
{
hr = m_SwapChain->SetMaximumFrameLatency( r_dx12FrameLatency.GetInteger() );
hr = m_SwapChain->SetMaximumFrameLatency( r_maxFrameLatency.GetInteger() );
HR_RETURN( hr );
m_frameLatencyWaitableObject = m_SwapChain->GetFrameLatencyWaitableObject();
@ -479,6 +479,12 @@ void DeviceManager_DX12::DestroyDeviceAndSwapChain()
m_FrameWaitQuery = nullptr;
if( m_frameLatencyWaitableObject )
{
CloseHandle( m_frameLatencyWaitableObject );
m_frameLatencyWaitableObject = NULL;
}
if( m_SwapChain )
{
m_SwapChain->SetFullscreenState( false, nullptr );
@ -629,10 +635,11 @@ void DeviceManager_DX12::Present()
if( m_frameLatencyWaitableObject )
{
OPTICK_CATEGORY("DX12_Sync1", Optick::Category::Wait);
OPTICK_CATEGORY( "DX12_Sync1", Optick::Category::Wait );
// SRS - When m_frameLatencyWaitableObject active, sync first on earlier present
DWORD result = WaitForSingleObjectEx( m_frameLatencyWaitableObject, INFINITE, true );
assert( result == WAIT_OBJECT_0 );
}
if constexpr( NUM_FRAME_DATA > 2 )