GPU: Allow closing window/app to interrupt shader compilation

This commit is contained in:
Connor McLaughlin
2021-02-19 01:48:44 +10:00
parent 413e52b38d
commit 24c2165bb3
8 changed files with 88 additions and 16 deletions

View File

@ -509,6 +509,10 @@ bool GPU_HW_D3D11::CompileShaders()
do \
{ \
progress_value++; \
if (System::IsStartupCancelled()) \
{ \
return false; \
} \
if (compile_time.GetTimeSeconds() >= 1.0f) \
{ \
compile_time.Reset(); \

View File

@ -519,6 +519,10 @@ bool GPU_HW_OpenGL::CompilePrograms()
do \
{ \
progress_value++; \
if (System::IsStartupCancelled()) \
{ \
return false; \
} \
if (compile_time.GetTimeSeconds() >= 1.0f) \
{ \
compile_time.Reset(); \

View File

@ -829,6 +829,10 @@ bool GPU_HW_Vulkan::CompilePipelines()
do \
{ \
progress_value++; \
if (System::IsStartupCancelled()) \
{ \
return false; \
} \
if (compile_time.GetTimeSeconds() >= 1.0f) \
{ \
compile_time.Reset(); \

View File

@ -115,8 +115,12 @@ bool HostInterface::BootSystem(const SystemBootParameters& parameters)
if (!System::Boot(parameters))
{
ReportFormattedError(
g_host_interface->TranslateString("System", "System failed to boot. The log may contain more information."));
if (!System::IsStartupCancelled())
{
ReportFormattedError(
g_host_interface->TranslateString("System", "System failed to boot. The log may contain more information."));
}
OnSystemDestroyed();
m_audio_stream.reset();
ReleaseHostDisplay();

View File

@ -85,6 +85,7 @@ static void UpdateRunningGame(const char* path, CDImage* image);
static bool CheckForSBIFile(CDImage* image);
static State s_state = State::Shutdown;
static std::atomic_bool s_startup_cancelled{false};
static ConsoleRegion s_region = ConsoleRegion::NTSC_U;
TickCount g_ticks_per_second = MASTER_CLOCK;
@ -173,6 +174,17 @@ bool IsValid()
return s_state != State::Shutdown && s_state != State::Starting;
}
bool IsStartupCancelled()
{
return s_startup_cancelled.load();
}
void CancelPendingStartup()
{
if (s_state == State::Starting)
s_startup_cancelled.store(true);
}
ConsoleRegion GetRegion()
{
return s_region;
@ -584,7 +596,10 @@ bool RecreateGPU(GPURenderer renderer, bool update_display /* = true*/)
g_gpu.reset();
if (!CreateGPU(renderer))
{
Panic("Failed to recreate GPU");
if (!IsStartupCancelled())
g_host_interface->ReportError("Failed to recreate GPU.");
System::Shutdown();
return false;
}
@ -628,6 +643,7 @@ bool Boot(const SystemBootParameters& params)
Assert(s_state == State::Shutdown);
Assert(s_media_playlist.empty());
s_state = State::Starting;
s_startup_cancelled.store(false);
s_region = g_settings.region;
if (params.state_stream)
@ -833,6 +849,13 @@ bool Initialize(bool force_software_renderer)
if (!CreateGPU(force_software_renderer ? GPURenderer::Software : g_settings.gpu_renderer))
return false;
// Was startup cancelled? (e.g. shading compilers took too long and the user closed the application)
if (IsStartupCancelled())
{
Shutdown();
return false;
}
// CPU code cache must happen after GPU, because it might steal our address space.
CPU::CodeCache::Initialize();

View File

@ -92,6 +92,9 @@ bool IsPaused();
bool IsShutdown();
bool IsValid();
bool IsStartupCancelled();
void CancelPendingStartup();
ConsoleRegion GetRegion();
bool IsPALRegion();

View File

@ -825,6 +825,7 @@ void QtHostInterface::powerOffSystem()
{
if (!isOnWorkerThread())
{
System::CancelPendingStartup();
QMetaObject::invokeMethod(this, "powerOffSystem", Qt::QueuedConnection);
return;
}
@ -839,6 +840,7 @@ void QtHostInterface::powerOffSystemWithoutSaving()
{
if (!isOnWorkerThread())
{
System::CancelPendingStartup();
QMetaObject::invokeMethod(this, "powerOffSystemWithoutSaving", Qt::QueuedConnection);
return;
}
@ -849,9 +851,14 @@ void QtHostInterface::powerOffSystemWithoutSaving()
void QtHostInterface::synchronousPowerOffSystem()
{
if (!isOnWorkerThread())
{
System::CancelPendingStartup();
QMetaObject::invokeMethod(this, "powerOffSystem", Qt::BlockingQueuedConnection);
}
else
{
powerOffSystem();
}
}
void QtHostInterface::resetSystem()