Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Game startup and shutdown fixes #849

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions neo/renderer/NVRHI/RenderBackend_NVRHI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ static NvrhiContext prevContext;

/*
==================
R_InitOpenGL
idRenderBackend::Init

This function is responsible for initializing a valid OpenGL subsystem
for rendering. This is done by calling the system specific GLimp_Init,
which gives us a working OGL subsystem, then setting all necessary openGL
This function is responsible for initializing a valid DX12/Vulkan subsystem
for rendering. This is done by calling the system specific GLimp_Init/VKimp_Init,
which gives us a working subsystem, then setting all necessary renderer
state, including images, vertex programs, and display lists.

Changes to the vertex cache size or smp state require a vid_restart.
Expand All @@ -154,11 +154,11 @@ and model information functions.
*/
void idRenderBackend::Init()
{
common->Printf( "----- R_InitOpenGL -----\n" );
common->Printf( "----- idRenderBackend::Init -----\n" );

if( tr.IsInitialized() )
{
common->FatalError( "R_InitOpenGL called while active" );
common->FatalError( "idRenderBackend::Init called while active" );
}

// SRS - create deviceManager here to prevent allocation loop via R_SetNewMode( true )
Expand Down
36 changes: 23 additions & 13 deletions neo/renderer/RenderSystem_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,8 @@ void R_SetNewMode( const bool fullInit )
idList<vidMode_t> modeList;
if( !R_GetModeListForDisplay( r_fullscreen.GetInteger() - 1, modeList ) )
{
idLib::Printf( "r_fullscreen reset from %i to 1 because mode list failed.\n", r_fullscreen.GetInteger() );
r_fullscreen.SetInteger( 1 );
R_GetModeListForDisplay( r_fullscreen.GetInteger() - 1, modeList );
idLib::Printf( "Going to safe mode because display not found.\n" );
goto safeMode;
}

if( modeList.Num() < 1 )
Expand Down Expand Up @@ -510,7 +509,7 @@ void R_SetNewMode( const bool fullInit )

if( i == 2 )
{
common->FatalError( "Unable to initialize OpenGL" );
common->FatalError( "Unable to initialize renderer" );
}

if( i == 0 )
Expand All @@ -522,8 +521,25 @@ void R_SetNewMode( const bool fullInit )
safeMode:
// if we failed, set everything back to "safe mode"
// and try again

// SRS - get the first display with a non-zero mode list, or fail if not found
int safeDisplay = 0;
idList<vidMode_t> safeList;
for( ; ; safeDisplay++ )
{
if( !R_GetModeListForDisplay( safeDisplay, safeList ) )
{
common->FatalError( "Unable to find a valid display for renderer" );
}
else if( safeList.Num() > 0 )
{
break;
}
}
// SRS end

r_vidMode.SetInteger( 0 );
r_fullscreen.SetInteger( 1 );
r_fullscreen.SetInteger( safeDisplay + 1 );
r_displayRefresh.SetInteger( 0 );
r_antiAliasing.SetInteger( 0 );
}
Expand Down Expand Up @@ -2209,14 +2225,8 @@ void idRenderSystemLocal::Shutdown()

UnbindBufferObjects();

// SRS - wait for fence to hit before freeing any resources the GPU may be using, otherwise get Vulkan validation layer errors on shutdown
// SRS - skip this step if we are in a Doom Classic game
#if defined(USE_DOOMCLASSIC)
if( common->GetCurrentGame() == DOOM3_BFG )
{
backend.GL_BlockingSwapBuffers();
}
#endif
// SRS - wait for device idle before freeing any resources the GPU may be using, otherwise get errors on shutdown
deviceManager->GetDevice()->waitForIdle();

// free the vertex cache, which should have nothing allocated now
vertexCache.Shutdown();
Expand Down
15 changes: 5 additions & 10 deletions neo/sys/DeviceManager_DX12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ static RefCountPtr<IDXGIAdapter> FindAdapter( const std::wstring& targetName )

return targetAdapter;
}

/* SRS - No longer needed, window centering now done in CreateWindowDeviceAndSwapChain() within win_glimp.cpp
// Adjust window rect so that it is centred on the given adapter. Clamps to fit if it's too big.
static bool MoveWindowOntoAdapter( IDXGIAdapter* targetAdapter, RECT& rect )
{
Expand Down Expand Up @@ -204,7 +204,7 @@ static bool MoveWindowOntoAdapter( IDXGIAdapter* targetAdapter, RECT& rect )

return false;
}

*/
void DeviceManager_DX12::ReportLiveObjects()
{
nvrhi::RefCountPtr<IDXGIDebug> pDebug;
Expand Down Expand Up @@ -298,16 +298,11 @@ bool DeviceManager_DX12::CreateDeviceAndSwapChain()
*/
HRESULT hr = E_FAIL;

RECT clientRect;
GetClientRect( ( HWND )windowHandle, &clientRect );
UINT width = clientRect.right - clientRect.left;
UINT height = clientRect.bottom - clientRect.top;

ZeroMemory( &m_SwapChainDesc, sizeof( m_SwapChainDesc ) );
m_SwapChainDesc.Width = width;
m_SwapChainDesc.Height = height;
m_SwapChainDesc.Width = m_DeviceParams.backBufferWidth;
m_SwapChainDesc.Height = m_DeviceParams.backBufferHeight;
m_SwapChainDesc.SampleDesc.Count = m_DeviceParams.swapChainSampleCount;
m_SwapChainDesc.SampleDesc.Quality = 0;
m_SwapChainDesc.SampleDesc.Quality = m_DeviceParams.swapChainSampleQuality;
m_SwapChainDesc.BufferUsage = m_DeviceParams.swapChainUsage;
m_SwapChainDesc.BufferCount = m_DeviceParams.swapChainBufferCount;
m_SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
Expand Down
Loading