Frontend: Reset/restore GPU state before saving screenshot

Fixes driver crashes in Vulkan.
This commit is contained in:
Connor McLaughlin 2020-06-27 02:22:52 +10:00
parent b94de1924d
commit 58b0e6859a
2 changed files with 10 additions and 4 deletions

View file

@ -499,9 +499,11 @@ bool System::SaveState(ByteStream* state)
const u32 screenshot_height = 128; const u32 screenshot_height = 128;
std::vector<u32> screenshot_buffer; std::vector<u32> screenshot_buffer;
if (m_host_interface->GetDisplay()->WriteDisplayTextureToBuffer(&screenshot_buffer, screenshot_width, m_gpu->ResetGraphicsAPIState();
screenshot_height) && const bool screenshot_saved =
!screenshot_buffer.empty()) m_host_interface->GetDisplay()->WriteDisplayTextureToBuffer(&screenshot_buffer, screenshot_width, screenshot_height);
m_gpu->RestoreGraphicsAPIState();
if (screenshot_saved && !screenshot_buffer.empty())
{ {
header.offset_to_screenshot = static_cast<u32>(state->GetPosition()); header.offset_to_screenshot = static_cast<u32>(state->GetPosition());
header.screenshot_width = screenshot_width; header.screenshot_width = screenshot_width;

View file

@ -1947,7 +1947,11 @@ bool CommonHostInterface::SaveScreenshot(const char* filename /* = nullptr */, b
filename = auto_filename.c_str(); filename = auto_filename.c_str();
} }
if (!m_display->WriteDisplayTextureToFile(filename, full_resolution, apply_aspect_ratio)) m_system->GetGPU()->ResetGraphicsAPIState();
const bool screenshot_saved =
m_display->WriteDisplayTextureToFile(filename, full_resolution, apply_aspect_ratio);
m_system->GetGPU()->RestoreGraphicsAPIState();
if (!screenshot_saved)
{ {
AddFormattedOSDMessage(10.0f, "Failed to save screenshot to '%s'", filename); AddFormattedOSDMessage(10.0f, "Failed to save screenshot to '%s'", filename);
return false; return false;