diff --git a/GPU/Common/DrawEngineCommon.h b/GPU/Common/DrawEngineCommon.h index 78473c3cf3..d5f8056417 100644 --- a/GPU/Common/DrawEngineCommon.h +++ b/GPU/Common/DrawEngineCommon.h @@ -74,6 +74,8 @@ public: virtual ~DrawEngineCommon(); void Init(); + virtual void DeviceLost() = 0; + virtual void DeviceRestore(Draw::DrawContext *draw) = 0; bool GetCurrentSimpleVertices(int count, std::vector &vertices, std::vector &indices); diff --git a/GPU/D3D11/DrawEngineD3D11.h b/GPU/D3D11/DrawEngineD3D11.h index 2703828516..7c9b46ac5e 100644 --- a/GPU/D3D11/DrawEngineD3D11.h +++ b/GPU/D3D11/DrawEngineD3D11.h @@ -119,6 +119,9 @@ public: DrawEngineD3D11(Draw::DrawContext *draw, ID3D11Device *device, ID3D11DeviceContext *context); ~DrawEngineD3D11(); + void DeviceLost() override { draw_ = nullptr; } + void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; } + void SetShaderManager(ShaderManagerD3D11 *shaderManager) { shaderManager_ = shaderManager; } diff --git a/GPU/D3D11/ShaderManagerD3D11.h b/GPU/D3D11/ShaderManagerD3D11.h index 5dacd408a5..9f8de499a9 100644 --- a/GPU/D3D11/ShaderManagerD3D11.h +++ b/GPU/D3D11/ShaderManagerD3D11.h @@ -89,7 +89,7 @@ public: void ClearShaders() override; void DirtyLastShader() override; - void DeviceLost() override {} + void DeviceLost() override { draw_ = nullptr; } void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; } int GetNumVertexShaders() const { return (int)vsCache_.size(); } int GetNumFragmentShaders() const { return (int)fsCache_.size(); } diff --git a/GPU/D3D11/TextureCacheD3D11.h b/GPU/D3D11/TextureCacheD3D11.h index 35f14d5a6f..53c150a9e4 100644 --- a/GPU/D3D11/TextureCacheD3D11.h +++ b/GPU/D3D11/TextureCacheD3D11.h @@ -52,7 +52,7 @@ public: bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override; - void DeviceLost() override {} + void DeviceLost() override { draw_ = nullptr; } void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; } protected: diff --git a/GPU/Directx9/DrawEngineDX9.h b/GPU/Directx9/DrawEngineDX9.h index e8bb1fbf42..1cea91376b 100644 --- a/GPU/Directx9/DrawEngineDX9.h +++ b/GPU/Directx9/DrawEngineDX9.h @@ -107,6 +107,9 @@ public: DrawEngineDX9(Draw::DrawContext *draw); ~DrawEngineDX9(); + void DeviceLost() override { draw_ = nullptr; } + void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; } + void SetShaderManager(ShaderManagerDX9 *shaderManager) { shaderManager_ = shaderManager; } diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 1c748980c0..cc099aa52a 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -105,6 +105,14 @@ u32 GPU_DX9::CheckGPUFeatures() const { return CheckGPUFeaturesLate(features); } +void GPU_DX9::DeviceLost() { + GPUCommonHW::DeviceLost(); +} + +void GPU_DX9::DeviceRestore(Draw::DrawContext *draw) { + GPUCommonHW::DeviceRestore(draw); +} + void GPU_DX9::ReapplyGfxState() { dxstate.Restore(); GPUCommonHW::ReapplyGfxState(); diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index 1da17b2e3e..f18ffeb77e 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -36,6 +36,9 @@ public: u32 CheckGPUFeatures() const override; + void DeviceLost() override; + void DeviceRestore(Draw::DrawContext *draw) override; + void ReapplyGfxState() override; void GetStats(char *buffer, size_t bufsize) override; diff --git a/GPU/Directx9/ShaderManagerDX9.h b/GPU/Directx9/ShaderManagerDX9.h index a0ccce98ed..99773c69dc 100644 --- a/GPU/Directx9/ShaderManagerDX9.h +++ b/GPU/Directx9/ShaderManagerDX9.h @@ -85,7 +85,7 @@ public: int GetNumVertexShaders() const { return (int)vsCache_.size(); } int GetNumFragmentShaders() const { return (int)fsCache_.size(); } - void DeviceLost() override {} + void DeviceLost() override { draw_ = nullptr; } void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; } std::vector DebugGetShaderIDs(DebugShaderType type); diff --git a/GPU/Directx9/TextureCacheDX9.h b/GPU/Directx9/TextureCacheDX9.h index 8b2a9eaec8..0b41c92a71 100644 --- a/GPU/Directx9/TextureCacheDX9.h +++ b/GPU/Directx9/TextureCacheDX9.h @@ -42,7 +42,7 @@ public: bool GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, bool *isFramebuffer) override; - void DeviceLost() override {} + void DeviceLost() override { draw_ = nullptr; } void DeviceRestore(Draw::DrawContext *draw) override { draw_ = draw; } protected: diff --git a/GPU/GLES/DrawEngineGLES.h b/GPU/GLES/DrawEngineGLES.h index 9352291c29..17f773c0b2 100644 --- a/GPU/GLES/DrawEngineGLES.h +++ b/GPU/GLES/DrawEngineGLES.h @@ -76,8 +76,8 @@ public: fragmentTestCache_ = testCache; } - void DeviceLost(); - void DeviceRestore(Draw::DrawContext *draw); + void DeviceLost() override; + void DeviceRestore(Draw::DrawContext *draw) override; void ClearTrackedVertexArrays() override {} diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 7e362b0697..20ac03129b 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -239,7 +239,6 @@ void GPU_GLES::DeviceLost() { // TransformDraw has registered as a GfxResourceHolder. CancelReady(); fragmentTestCache_.DeviceLost(); - drawEngine_.DeviceLost(); GPUCommonHW::DeviceLost(); } @@ -247,13 +246,8 @@ void GPU_GLES::DeviceLost() { void GPU_GLES::DeviceRestore(Draw::DrawContext *draw) { GPUCommonHW::DeviceRestore(draw); - UpdateCmdInfo(); - UpdateVsyncInterval(true); - - shaderManager_->DeviceRestore(draw_); - textureCache_->DeviceRestore(draw_); - drawEngine_.DeviceRestore(draw_); fragmentTestCache_.DeviceRestore(draw_); + UpdateVsyncInterval(true); } void GPU_GLES::BeginHostFrame() { diff --git a/GPU/GPUCommonHW.cpp b/GPU/GPUCommonHW.cpp index 2278ceadb2..1dbf9c10df 100644 --- a/GPU/GPUCommonHW.cpp +++ b/GPU/GPUCommonHW.cpp @@ -417,13 +417,22 @@ void GPUCommonHW::DeviceLost() { textureCache_->Clear(false); textureCache_->DeviceLost(); shaderManager_->DeviceLost(); + drawEngineCommon_->DeviceLost(); } // Call at the start of the GPU implementation's DeviceRestore void GPUCommonHW::DeviceRestore(Draw::DrawContext *draw) { draw_ = draw; framebufferManager_->DeviceRestore(draw_); + textureCache_->DeviceRestore(draw_); + shaderManager_->DeviceRestore(draw_); + drawEngineCommon_->DeviceRestore(draw_); + PPGeSetDrawContext(draw_); + + gstate_c.SetUseFlags(CheckGPUFeatures()); + BuildReportingInfo(); + UpdateCmdInfo(); } void GPUCommonHW::UpdateCmdInfo() { diff --git a/GPU/Software/TransformUnit.h b/GPU/Software/TransformUnit.h index b1dd318540..895c023a92 100644 --- a/GPU/Software/TransformUnit.h +++ b/GPU/Software/TransformUnit.h @@ -173,6 +173,9 @@ public: SoftwareDrawEngine(); ~SoftwareDrawEngine(); + void DeviceLost() override {} + void DeviceRestore(Draw::DrawContext *draw) override {} + void NotifyConfigChanged() override; void DispatchFlush() override; void DispatchSubmitPrim(const void *verts, const void *inds, GEPrimitiveType prim, int vertexCount, u32 vertType, int cullMode, int *bytesRead) override; diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index 78f561376e..11907c13b7 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -287,7 +287,6 @@ void DrawEngineVulkan::DeviceLost() { void DrawEngineVulkan::DeviceRestore(Draw::DrawContext *draw) { draw_ = draw; - InitDeviceObjects(); } diff --git a/GPU/Vulkan/DrawEngineVulkan.h b/GPU/Vulkan/DrawEngineVulkan.h index 6c21b7609d..b0e99a7c24 100644 --- a/GPU/Vulkan/DrawEngineVulkan.h +++ b/GPU/Vulkan/DrawEngineVulkan.h @@ -158,8 +158,8 @@ public: framebufferManager_ = fbManager; } - void DeviceLost(); - void DeviceRestore(Draw::DrawContext *draw); + void DeviceLost() override; + void DeviceRestore(Draw::DrawContext *draw) override; // So that this can be inlined void Flush() { diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index ee7500ea96..ed9a15c99d 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -454,7 +454,6 @@ void GPU_Vulkan::DeviceLost() { SaveCache(shaderCachePath_); } DestroyDeviceObjects(); - drawEngine_.DeviceLost(); pipelineManager_->DeviceLost(); GPUCommonHW::DeviceLost(); @@ -462,17 +461,11 @@ void GPU_Vulkan::DeviceLost() { void GPU_Vulkan::DeviceRestore(Draw::DrawContext *draw) { GPUCommonHW::DeviceRestore(draw); - InitDeviceObjects(); - - gstate_c.SetUseFlags(CheckGPUFeatures()); - BuildReportingInfo(); - UpdateCmdInfo(); VulkanContext *vulkan = (VulkanContext *)draw_->GetNativeObject(Draw::NativeObject::CONTEXT); - drawEngine_.DeviceRestore(draw_); pipelineManager_->DeviceRestore(vulkan); - textureCacheVulkan_->DeviceRestore(draw_); - shaderManagerVulkan_->DeviceRestore(draw_); + + InitDeviceObjects(); } void GPU_Vulkan::GetStats(char *buffer, size_t bufsize) {