mirror of
https://github.com/RetroDECK/Duckstation.git
synced 2024-11-25 15:15:40 +00:00
System: Restore context after pumping messages
This commit is contained in:
parent
25fb69564b
commit
0076ab5cc4
|
@ -309,7 +309,7 @@ bool GPU::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_displ
|
||||||
return !sw.HasError();
|
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))
|
texture_data_stride))
|
||||||
{
|
{
|
||||||
Log_ErrorPrintf("Texture download failed");
|
Log_ErrorPrintf("Texture download failed");
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
|
|
||||||
auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "wb");
|
auto fp = FileSystem::OpenManagedCFile(filename.c_str(), "wb");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
|
@ -2055,13 +2055,13 @@ bool GPU::RenderScreenshotToBuffer(u32 width, u32 height, const Common::Rectangl
|
||||||
out_pixels->resize(width * height);
|
out_pixels->resize(width * height);
|
||||||
if (!g_gpu_device->DownloadTexture(render_texture.get(), 0, 0, width, height, out_pixels->data(), stride))
|
if (!g_gpu_device->DownloadTexture(render_texture.get(), 0, 0, width, height, out_pixels->data(), stride))
|
||||||
{
|
{
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
*out_stride = stride;
|
*out_stride = stride;
|
||||||
*out_format = hdformat;
|
*out_format = hdformat;
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,7 +96,7 @@ public:
|
||||||
|
|
||||||
// Graphics API state reset/restore - call when drawing the UI etc.
|
// Graphics API state reset/restore - call when drawing the UI etc.
|
||||||
// TODO: replace with "invalidate cached state"
|
// TODO: replace with "invalidate cached state"
|
||||||
virtual void RestoreGraphicsAPIState();
|
virtual void RestoreDeviceContext();
|
||||||
|
|
||||||
// Render statistics debug window.
|
// Render statistics debug window.
|
||||||
void DrawDebugStateWindow();
|
void DrawDebugStateWindow();
|
||||||
|
|
|
@ -215,7 +215,7 @@ bool GPU_HW::Initialize()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +290,7 @@ bool GPU_HW::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di
|
||||||
return true;
|
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->SetTextureSampler(0, m_vram_read_texture.get(), g_gpu_device->GetNearestSampler());
|
||||||
g_gpu_device->SetFramebuffer(m_vram_framebuffer.get());
|
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.
|
// Back up VRAM if we're recreating the framebuffer.
|
||||||
if (framebuffer_changed)
|
if (framebuffer_changed)
|
||||||
{
|
{
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
ReadVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
|
ReadVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT);
|
||||||
DestroyBuffers();
|
DestroyBuffers();
|
||||||
}
|
}
|
||||||
|
@ -397,7 +397,7 @@ void GPU_HW::UpdateSettings(const Settings& old_settings)
|
||||||
if (!CreateBuffers())
|
if (!CreateBuffers())
|
||||||
Panic("Failed to recreate buffers.");
|
Panic("Failed to recreate buffers.");
|
||||||
|
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
UpdateVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT, m_vram_ptr, false, false);
|
UpdateVRAM(0, 0, VRAM_WIDTH, VRAM_HEIGHT, m_vram_ptr, false, false);
|
||||||
UpdateDepthBufferFromMaskBit();
|
UpdateDepthBufferFromMaskBit();
|
||||||
UpdateDisplay();
|
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->SetViewportAndScissor(dst_x, dst_y, width, height);
|
||||||
g_gpu_device->Draw(3, 0);
|
g_gpu_device->Draw(3, 0);
|
||||||
|
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
return true;
|
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->PushUniformBuffer(&uniforms, sizeof(uniforms));
|
||||||
g_gpu_device->Draw(3, 0);
|
g_gpu_device->Draw(3, 0);
|
||||||
|
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GPU_HW::ReadVRAM(u32 x, u32 y, u32 width, u32 height)
|
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]),
|
reinterpret_cast<u32*>(&m_vram_shadow[copy_rect.top * VRAM_WIDTH + copy_rect.left]),
|
||||||
VRAM_WIDTH * sizeof(u16));
|
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)
|
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->SetTextureBuffer(0, m_vram_upload_buffer.get());
|
||||||
g_gpu_device->Draw(3, 0);
|
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)
|
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());
|
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->PushUniformBuffer(&uniforms, sizeof(uniforms));
|
||||||
g_gpu_device->Draw(3, 0);
|
g_gpu_device->Draw(3, 0);
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
|
|
||||||
if (m_GPUSTAT.check_mask_before_draw && !m_pgxp_depth_buffer)
|
if (m_GPUSTAT.check_mask_before_draw && !m_pgxp_depth_buffer)
|
||||||
m_current_depth++;
|
m_current_depth++;
|
||||||
|
@ -2532,7 +2532,7 @@ void GPU_HW::UpdateDisplay()
|
||||||
else
|
else
|
||||||
SetDisplayTexture(m_display_private_texture.get(), 0, 0, scaled_display_width, scaled_display_height);
|
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();
|
GL_POP();
|
||||||
|
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
|
|
||||||
SetDisplayTexture(m_downsample_render_texture.get(), 0, 0, width, height);
|
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->SetViewportAndScissor(ds_left, ds_top, ds_width, ds_height);
|
||||||
g_gpu_device->Draw(3, 0);
|
g_gpu_device->Draw(3, 0);
|
||||||
|
|
||||||
RestoreGraphicsAPIState();
|
RestoreDeviceContext();
|
||||||
|
|
||||||
SetDisplayTexture(m_downsample_render_texture.get(), ds_left, ds_top, ds_width, ds_height);
|
SetDisplayTexture(m_downsample_render_texture.get(), ds_left, ds_top, ds_width, ds_height);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ public:
|
||||||
void Reset(bool clear_vram) override;
|
void Reset(bool clear_vram) override;
|
||||||
bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display) 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 UpdateSettings(const Settings& old_settings) override;
|
||||||
void UpdateResolutionScale() override final;
|
void UpdateResolutionScale() override final;
|
||||||
|
|
|
@ -53,7 +53,7 @@ static void HotkeyModifyResolutionScale(s32 increment)
|
||||||
|
|
||||||
if (System::IsValid())
|
if (System::IsValid())
|
||||||
{
|
{
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
g_gpu->UpdateSettings(old_settings);
|
g_gpu->UpdateSettings(old_settings);
|
||||||
System::ClearMemorySaveStates();
|
System::ClearMemorySaveStates();
|
||||||
}
|
}
|
||||||
|
@ -312,7 +312,7 @@ DEFINE_HOTKEY("TogglePGXP", TRANSLATE_NOOP("Hotkeys", "Graphics"), TRANSLATE_NOO
|
||||||
{
|
{
|
||||||
Settings old_settings = g_settings;
|
Settings old_settings = g_settings;
|
||||||
g_settings.gpu_pgxp_enable = !g_settings.gpu_pgxp_enable;
|
g_settings.gpu_pgxp_enable = !g_settings.gpu_pgxp_enable;
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
g_gpu->UpdateSettings(old_settings);
|
g_gpu->UpdateSettings(old_settings);
|
||||||
System::ClearMemorySaveStates();
|
System::ClearMemorySaveStates();
|
||||||
Host::AddKeyedOSDMessage("TogglePGXP",
|
Host::AddKeyedOSDMessage("TogglePGXP",
|
||||||
|
@ -382,7 +382,7 @@ DEFINE_HOTKEY("TogglePGXPDepth", TRANSLATE_NOOP("Hotkeys", "Graphics"),
|
||||||
const Settings old_settings = g_settings;
|
const Settings old_settings = g_settings;
|
||||||
g_settings.gpu_pgxp_depth_buffer = !g_settings.gpu_pgxp_depth_buffer;
|
g_settings.gpu_pgxp_depth_buffer = !g_settings.gpu_pgxp_depth_buffer;
|
||||||
|
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
g_gpu->UpdateSettings(old_settings);
|
g_gpu->UpdateSettings(old_settings);
|
||||||
System::ClearMemorySaveStates();
|
System::ClearMemorySaveStates();
|
||||||
Host::AddKeyedOSDMessage("TogglePGXPDepth",
|
Host::AddKeyedOSDMessage("TogglePGXPDepth",
|
||||||
|
@ -403,7 +403,7 @@ DEFINE_HOTKEY("TogglePGXPCPU", TRANSLATE_NOOP("Hotkeys", "Graphics"), TRANSLATE_
|
||||||
const Settings old_settings = g_settings;
|
const Settings old_settings = g_settings;
|
||||||
g_settings.gpu_pgxp_cpu = !g_settings.gpu_pgxp_cpu;
|
g_settings.gpu_pgxp_cpu = !g_settings.gpu_pgxp_cpu;
|
||||||
|
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
g_gpu->UpdateSettings(old_settings);
|
g_gpu->UpdateSettings(old_settings);
|
||||||
System::ClearMemorySaveStates();
|
System::ClearMemorySaveStates();
|
||||||
Host::AddKeyedOSDMessage("TogglePGXPCPU",
|
Host::AddKeyedOSDMessage("TogglePGXPCPU",
|
||||||
|
|
|
@ -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*/)
|
bool System::RecreateGPU(GPURenderer renderer, bool force_recreate_device, bool update_display /* = true*/)
|
||||||
{
|
{
|
||||||
ClearMemorySaveStates();
|
ClearMemorySaveStates();
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
|
|
||||||
// save current state
|
// save current state
|
||||||
std::unique_ptr<ByteStream> state_stream = ByteStream::CreateGrowableMemoryStream();
|
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);
|
state_stream->SeekAbsolute(0);
|
||||||
sw.SetMode(StateWrapper::Mode::Read);
|
sw.SetMode(StateWrapper::Mode::Read);
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
g_gpu->DoState(sw, nullptr, update_display);
|
g_gpu->DoState(sw, nullptr, update_display);
|
||||||
TimingEvents::DoState(sw);
|
TimingEvents::DoState(sw);
|
||||||
}
|
}
|
||||||
|
@ -1724,7 +1724,7 @@ void System::Execute()
|
||||||
s_system_executing = true;
|
s_system_executing = true;
|
||||||
|
|
||||||
// TODO: Purge reset/restore
|
// TODO: Purge reset/restore
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
|
|
||||||
if (s_rewind_load_counter >= 0)
|
if (s_rewind_load_counter >= 0)
|
||||||
DoRewind();
|
DoRewind();
|
||||||
|
@ -1800,6 +1800,7 @@ void System::FrameDone()
|
||||||
// counter-acts that.
|
// counter-acts that.
|
||||||
Host::PumpMessagesOnCPUThread();
|
Host::PumpMessagesOnCPUThread();
|
||||||
InputManager::PollSources();
|
InputManager::PollSources();
|
||||||
|
g_gpu->RestoreDeviceContext();
|
||||||
|
|
||||||
if (IsExecutionInterrupted())
|
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
|
// 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
|
// 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).
|
// amounts of computation happening in each frame).
|
||||||
|
@ -1911,7 +1914,7 @@ void System::SingleStepCPU()
|
||||||
s_frame_timer.Reset();
|
s_frame_timer.Reset();
|
||||||
s_system_executing = true;
|
s_system_executing = true;
|
||||||
|
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
|
|
||||||
CPU::SingleStep();
|
CPU::SingleStep();
|
||||||
|
|
||||||
|
@ -2068,7 +2071,7 @@ bool System::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_di
|
||||||
if (!sw.DoMarker("InterruptController") || !InterruptController::DoState(sw))
|
if (!sw.DoMarker("InterruptController") || !InterruptController::DoState(sw))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
if (!sw.DoMarker("GPU") || !g_gpu->DoState(sw, host_texture, update_display))
|
if (!sw.DoMarker("GPU") || !g_gpu->DoState(sw, host_texture, update_display))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -2464,7 +2467,7 @@ bool System::SaveStateToStream(ByteStream* state, u32 screenshot_size /* = 256 *
|
||||||
{
|
{
|
||||||
header.offset_to_data = static_cast<u32>(state->GetPosition());
|
header.offset_to_data = static_cast<u32>(state->GetPosition());
|
||||||
|
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
|
|
||||||
header.data_compression_type = compression_method;
|
header.data_compression_type = compression_method;
|
||||||
|
|
||||||
|
@ -3220,7 +3223,7 @@ bool System::DumpVRAM(const char* filename)
|
||||||
if (!IsValid())
|
if (!IsValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
g_gpu->RestoreDeviceContext();
|
||||||
return g_gpu->DumpVRAMToFile(filename);
|
return g_gpu->DumpVRAMToFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4707,15 +4710,15 @@ bool System::PresentDisplay(bool allow_skip_present)
|
||||||
|
|
||||||
ImGuiManager::NewFrame();
|
ImGuiManager::NewFrame();
|
||||||
|
|
||||||
if (g_gpu)
|
|
||||||
g_gpu->RestoreGraphicsAPIState();
|
|
||||||
|
|
||||||
return do_present;
|
return do_present;
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::InvalidateDisplay()
|
void System::InvalidateDisplay()
|
||||||
{
|
{
|
||||||
PresentDisplay(false);
|
PresentDisplay(false);
|
||||||
|
|
||||||
|
if (g_gpu)
|
||||||
|
g_gpu->RestoreDeviceContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
void System::SetTimerResolutionIncreased(bool enabled)
|
void System::SetTimerResolutionIncreased(bool enabled)
|
||||||
|
|
|
@ -1916,18 +1916,6 @@ bool VulkanDevice::UpdateWindow()
|
||||||
SubmitCommandBuffer(false);
|
SubmitCommandBuffer(false);
|
||||||
WaitForGPUIdle();
|
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);
|
VkSurfaceKHR surface = VulkanSwapChain::CreateVulkanSurface(m_instance, m_physical_device, &m_window_info);
|
||||||
if (surface == VK_NULL_HANDLE)
|
if (surface == VK_NULL_HANDLE)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue