System: Restore context after pumping messages

This commit is contained in:
Stenzek 2023-09-03 13:13:17 +10:00
parent 25fb69564b
commit 0076ab5cc4
7 changed files with 36 additions and 45 deletions

View File

@ -309,7 +309,7 @@ bool GPU::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_displ
return !sw.HasError();
}
void GPU::RestoreGraphicsAPIState()
void GPU::RestoreDeviceContext()
{
}
@ -1999,11 +1999,11 @@ bool GPU::WriteDisplayTextureToFile(std::string filename, bool full_resolution /
texture_data_stride))
{
Log_ErrorPrintf("Texture download failed");
RestoreGraphicsAPIState();
RestoreDeviceContext();
return false;
}
RestoreGraphicsAPIState();
RestoreDeviceContext();
auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "wb");
if (!fp)
@ -2055,13 +2055,13 @@ bool GPU::RenderScreenshotToBuffer(u32 width, u32 height, const Common::Rectangl
out_pixels->resize(width * height);
if (!g_gpu_device->DownloadTexture(render_texture.get(), 0, 0, width, height, out_pixels->data(), stride))
{
RestoreGraphicsAPIState();
RestoreDeviceContext();
return false;
}
*out_stride = stride;
*out_format = hdformat;
RestoreGraphicsAPIState();
RestoreDeviceContext();
return true;
}

View File

@ -96,7 +96,7 @@ public:
// Graphics API state reset/restore - call when drawing the UI etc.
// TODO: replace with "invalidate cached state"
virtual void RestoreGraphicsAPIState();
virtual void RestoreDeviceContext();
// Render statistics debug window.
void DrawDebugStateWindow();

View File

@ -215,7 +215,7 @@ bool GPU_HW::Initialize()
return false;
}
RestoreGraphicsAPIState();
RestoreDeviceContext();
return true;
}
@ -290,7 +290,7 @@ bool GPU_HW::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di
return true;
}
void GPU_HW::RestoreGraphicsAPIState()
void GPU_HW::RestoreDeviceContext()
{
g_gpu_device->SetTextureSampler(0, m_vram_read_texture.get(), g_gpu_device->GetNearestSampler());
g_gpu_device->SetFramebuffer(m_vram_framebuffer.get());
@ -352,7 +352,7 @@ void GPU_HW::UpdateSettings(const Settings& old_settings)
// Back up VRAM if we're recreating the framebuffer.
if (framebuffer_changed)
{
RestoreGraphicsAPIState();
RestoreDeviceContext();
ReadVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
DestroyBuffers();
}
@ -397,7 +397,7 @@ void GPU_HW::UpdateSettings(const Settings& old_settings)
if (!CreateBuffers())
Panic("Failed to recreate buffers.");
RestoreGraphicsAPIState();
RestoreDeviceContext();
UpdateVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT, m_vram_ptr, false, false);
UpdateDepthBufferFromMaskBit();
UpdateDisplay();
@ -1896,7 +1896,7 @@ bool GPU_HW::BlitVRAMReplacementTexture(const TextureReplacementTexture* tex, u3
g_gpu_device->SetViewportAndScissor(dst_x, dst_y, width, height);
g_gpu_device->Draw(3, 0);
RestoreGraphicsAPIState();
RestoreDeviceContext();
return true;
}
@ -2088,7 +2088,7 @@ void GPU_HW::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color)
g_gpu_device->PushUniformBuffer(&uniforms, sizeof(uniforms));
g_gpu_device->Draw(3, 0);
RestoreGraphicsAPIState();
RestoreDeviceContext();
}
void GPU_HW::ReadVRAM(u32 x, u32 y, u32 width, u32 height)
@ -2119,7 +2119,7 @@ void GPU_HW::ReadVRAM(u32 x, u32 y, u32 width, u32 height)
reinterpret_cast<u32*>(&m_vram_shadow[copy_rect.top * VRAM_WIDTH + copy_rect.left]),
VRAM_WIDTH * sizeof(u16));
RestoreGraphicsAPIState();
RestoreDeviceContext();
}
void GPU_HW::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data, bool set_mask, bool check_mask)
@ -2188,7 +2188,7 @@ void GPU_HW::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data, b
g_gpu_device->SetTextureBuffer(0, m_vram_upload_buffer.get());
g_gpu_device->Draw(3, 0);
RestoreGraphicsAPIState();
RestoreDeviceContext();
}
void GPU_HW::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height)
@ -2254,7 +2254,7 @@ void GPU_HW::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32
m_vram_copy_pipelines[BoolToUInt8(m_GPUSTAT.check_mask_before_draw && !m_pgxp_depth_buffer)].get());
g_gpu_device->PushUniformBuffer(&uniforms, sizeof(uniforms));
g_gpu_device->Draw(3, 0);
RestoreGraphicsAPIState();
RestoreDeviceContext();
if (m_GPUSTAT.check_mask_before_draw && !m_pgxp_depth_buffer)
m_current_depth++;
@ -2532,7 +2532,7 @@ void GPU_HW::UpdateDisplay()
else
SetDisplayTexture(m_display_private_texture.get(), 0, 0, scaled_display_width, scaled_display_height);
RestoreGraphicsAPIState();
RestoreDeviceContext();
}
}
}
@ -2635,7 +2635,7 @@ void GPU_HW::DownsampleFramebufferAdaptive(GPUTexture* source, u32 left, u32 top
GL_POP();
RestoreGraphicsAPIState();
RestoreDeviceContext();
SetDisplayTexture(m_downsample_render_texture.get(), 0, 0, width, height);
}
@ -2656,7 +2656,7 @@ void GPU_HW::DownsampleFramebufferBoxFilter(GPUTexture* source, u32 left, u32 to
g_gpu_device->SetViewportAndScissor(ds_left, ds_top, ds_width, ds_height);
g_gpu_device->Draw(3, 0);
RestoreGraphicsAPIState();
RestoreDeviceContext();
SetDisplayTexture(m_downsample_render_texture.get(), ds_left, ds_top, ds_width, ds_height);
}

View File

@ -49,7 +49,7 @@ public:
void Reset(bool clear_vram) override;
bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display) override;
void RestoreGraphicsAPIState() override;
void RestoreDeviceContext() override;
void UpdateSettings(const Settings& old_settings) override;
void UpdateResolutionScale() override final;

View File

@ -53,7 +53,7 @@ static void HotkeyModifyResolutionScale(s32 increment)
if (System::IsValid())
{
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
g_gpu->UpdateSettings(old_settings);
System::ClearMemorySaveStates();
}
@ -312,7 +312,7 @@ DEFINE_HOTKEY("TogglePGXP", TRANSLATE_NOOP("Hotkeys", "Graphics"), TRANSLATE_NOO
{
Settings old_settings = g_settings;
g_settings.gpu_pgxp_enable = !g_settings.gpu_pgxp_enable;
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
g_gpu->UpdateSettings(old_settings);
System::ClearMemorySaveStates();
Host::AddKeyedOSDMessage("TogglePGXP",
@ -382,7 +382,7 @@ DEFINE_HOTKEY("TogglePGXPDepth", TRANSLATE_NOOP("Hotkeys", "Graphics"),
const Settings old_settings = g_settings;
g_settings.gpu_pgxp_depth_buffer = !g_settings.gpu_pgxp_depth_buffer;
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
g_gpu->UpdateSettings(old_settings);
System::ClearMemorySaveStates();
Host::AddKeyedOSDMessage("TogglePGXPDepth",
@ -403,7 +403,7 @@ DEFINE_HOTKEY("TogglePGXPCPU", TRANSLATE_NOOP("Hotkeys", "Graphics"), TRANSLATE_
const Settings old_settings = g_settings;
g_settings.gpu_pgxp_cpu = !g_settings.gpu_pgxp_cpu;
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
g_gpu->UpdateSettings(old_settings);
System::ClearMemorySaveStates();
Host::AddKeyedOSDMessage("TogglePGXPCPU",

View File

@ -876,7 +876,7 @@ std::string System::GetInputProfilePath(const std::string_view& name)
bool System::RecreateGPU(GPURenderer renderer, bool force_recreate_device, bool update_display /* = true*/)
{
ClearMemorySaveStates();
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
// save current state
std::unique_ptr<ByteStream> state_stream = ByteStream::CreateGrowableMemoryStream();
@ -903,7 +903,7 @@ bool System::RecreateGPU(GPURenderer renderer, bool force_recreate_device, bool
{
state_stream->SeekAbsolute(0);
sw.SetMode(StateWrapper::Mode::Read);
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
g_gpu->DoState(sw, nullptr, update_display);
TimingEvents::DoState(sw);
}
@ -1724,7 +1724,7 @@ void System::Execute()
s_system_executing = true;
// TODO: Purge reset/restore
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
if (s_rewind_load_counter >= 0)
DoRewind();
@ -1800,6 +1800,7 @@ void System::FrameDone()
// counter-acts that.
Host::PumpMessagesOnCPUThread();
InputManager::PollSources();
g_gpu->RestoreDeviceContext();
if (IsExecutionInterrupted())
{
@ -1846,6 +1847,8 @@ void System::FrameDone()
}
}
g_gpu->RestoreDeviceContext();
// Update perf counters *after* throttling, we want to measure from start-of-frame
// to start-of-frame, not end-of-frame to end-of-frame (will be noisy due to different
// amounts of computation happening in each frame).
@ -1911,7 +1914,7 @@ void System::SingleStepCPU()
s_frame_timer.Reset();
s_system_executing = true;
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
CPU::SingleStep();
@ -2068,7 +2071,7 @@ bool System::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di
if (!sw.DoMarker("InterruptController") || !InterruptController::DoState(sw))
return false;
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
if (!sw.DoMarker("GPU") || !g_gpu->DoState(sw, host_texture, update_display))
return false;
@ -2464,7 +2467,7 @@ bool System::SaveStateToStream(ByteStream* state, u32 screenshot_size /* = 256 *
{
header.offset_to_data = static_cast<u32>(state->GetPosition());
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
header.data_compression_type = compression_method;
@ -3220,7 +3223,7 @@ bool System::DumpVRAM(const char* filename)
if (!IsValid())
return false;
g_gpu->RestoreGraphicsAPIState();
g_gpu->RestoreDeviceContext();
return g_gpu->DumpVRAMToFile(filename);
}
@ -4707,15 +4710,15 @@ bool System::PresentDisplay(bool allow_skip_present)
ImGuiManager::NewFrame();
if (g_gpu)
g_gpu->RestoreGraphicsAPIState();
return do_present;
}
void System::InvalidateDisplay()
{
PresentDisplay(false);
if (g_gpu)
g_gpu->RestoreDeviceContext();
}
void System::SetTimerResolutionIncreased(bool enabled)

View File

@ -1916,18 +1916,6 @@ bool VulkanDevice::UpdateWindow()
SubmitCommandBuffer(false);
WaitForGPUIdle();
// recreate surface in existing swap chain if it already exists
if (m_swap_chain)
{
if (m_swap_chain->RecreateSurface(m_window_info))
{
m_window_info = m_swap_chain->GetWindowInfo();
return true;
}
m_swap_chain.reset();
}
VkSurfaceKHR surface = VulkanSwapChain::CreateVulkanSurface(m_instance, m_physical_device, &m_window_info);
if (surface == VK_NULL_HANDLE)
{