diff --git a/GPU/Common/PresentationCommon.cpp b/GPU/Common/PresentationCommon.cpp index 6bc3179b85..392ea6d045 100644 --- a/GPU/Common/PresentationCommon.cpp +++ b/GPU/Common/PresentationCommon.cpp @@ -599,8 +599,7 @@ void PresentationCommon::CreateDeviceObjects() { texColorRBSwizzle_ = CreatePipeline({ draw_->GetVshaderPreset(VS_TEXTURE_COLOR_2D), draw_->GetFshaderPreset(FS_TEXTURE_COLOR_2D_RB_SWIZZLE) }, false, &vsTexColBufDesc); texColorBlend_ = CreatePipeline({ draw_->GetVshaderPreset(VS_TEXTURE_COLOR_2D), draw_->GetFshaderPreset(FS_TEXTURE_COLOR_2D) }, false, &vsTexColBufDesc, true); overlayVdata_ = draw_->CreateBuffer(sizeof(Vertex) * 4, BufferUsageFlag::DYNAMIC | BufferUsageFlag::VERTEXDATA); - - restorePostShader_ = false; + // Not resetting restorePostShader_: after a device loss, BeginFrame uses it to bring the post-shader back. } template diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index ea3439b176..17cd36cb05 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -612,6 +612,7 @@ void ShaderManagerGLES::Clear() { linkedShaderCache_.clear(); fsCache_.Clear(); vsCache_.Clear(); + lastShader_ = nullptr; lastFSID_.set_invalid(); lastVSID_.set_invalid(); diff --git a/GPU/GLES/TextureCacheGLES.cpp b/GPU/GLES/TextureCacheGLES.cpp index 3050cf55dd..5f5e81883e 100644 --- a/GPU/GLES/TextureCacheGLES.cpp +++ b/GPU/GLES/TextureCacheGLES.cpp @@ -407,6 +407,7 @@ bool TextureCacheGLES::GetCurrentTextureDebug(GPUDebugBuffer &buffer, int level, void TextureCacheGLES::DeviceLost() { TextureCacheCommon::DeviceLost(); + lastBoundTexture_ = nullptr; draw_ = nullptr; render_ = nullptr; } diff --git a/GPU/Metal/DrawEngineMetal.mm b/GPU/Metal/DrawEngineMetal.mm index 905a1b8e4d..1dbd5276d7 100644 --- a/GPU/Metal/DrawEngineMetal.mm +++ b/GPU/Metal/DrawEngineMetal.mm @@ -178,6 +178,10 @@ void DrawEngineMetal::DeviceLost() { } boundSecondary_ = nil; boundDepal_ = nil; + // Allocated from the old render manager's push buffer. + baseUBO_ = MetalPushAlloc{}; + lightUBO_ = MetalPushAlloc{}; + uboFrame_ = (uint64_t)-1; draw_ = nullptr; rm_ = nullptr; } diff --git a/GPU/Metal/GPU_Metal.mm b/GPU/Metal/GPU_Metal.mm index 43e07d0971..0deea8a6eb 100644 --- a/GPU/Metal/GPU_Metal.mm +++ b/GPU/Metal/GPU_Metal.mm @@ -214,6 +214,12 @@ void GPU_Metal::DeviceLost() { void GPU_Metal::DeviceRestore(Draw::DrawContext *draw) { GPUCommonHW::DeviceRestore(draw); + + // DeviceLost saved the cache and then threw everything away. Load it again, or the next save would + // overwrite the file with only what gets drawn from now on. + if (shaderCachePath_.Valid()) { + LoadCache(shaderCachePath_); + } } void GPU_Metal::GetStats(StringWriter &w) { diff --git a/GPU/Vulkan/DrawEngineVulkan.cpp b/GPU/Vulkan/DrawEngineVulkan.cpp index aadc9edee9..163420f617 100644 --- a/GPU/Vulkan/DrawEngineVulkan.cpp +++ b/GPU/Vulkan/DrawEngineVulkan.cpp @@ -133,6 +133,10 @@ void DrawEngineVulkan::DestroyDeviceObjects() { void DrawEngineVulkan::DeviceLost() { DestroyDeviceObjects(); DirtyAllUBOs(); + // The pipelines and views these point to are gone (BeginFrame resets them too, but a flush could come first). + lastPipeline_ = nullptr; + boundDepal_ = VK_NULL_HANDLE; + boundSecondary_ = VK_NULL_HANDLE; draw_ = nullptr; }