From 039c69f0318dcbe10a94933d70c397cb612265f8 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 11 Nov 2017 08:08:59 -0800 Subject: [PATCH 1/4] SaveState: Fix use-after-resize iterator. Only on older save states. --- Core/HLE/sceKernelModule.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 2630cde19f..3c8170b829 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -301,7 +301,9 @@ public: } else { // Older save state. Let's still reload, but this may not pick up new flags, etc. bool foundBroken = false; - for (auto func : importedFuncs) { + auto importedFuncsState = importedFuncs; + importedFuncs.clear(); + for (auto func : importedFuncsState) { if (func.moduleName[KERNELOBJECT_MAX_NAME_LENGTH] != '\0' || !Memory::IsValidAddress(func.stubAddr)) { foundBroken = true; } else { From f93ef929606ae5d051eeb4f394f86c434b8f4251 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 11 Nov 2017 08:09:56 -0800 Subject: [PATCH 2/4] D3D11: Avoid clearing shaders on load state. They don't need to be cleared (unlike FBOs), and clearing them requires clearing even more things. Fixes #9637. --- GPU/D3D11/GPU_D3D11.cpp | 3 +-- GPU/Directx9/GPU_DX9.cpp | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 057716bf00..24cbde0ca4 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -749,13 +749,12 @@ void GPU_D3D11::DoState(PointerWrap &p) { // TODO: Some of these things may not be necessary. // None of these are necessary when saving. - if (p.mode == p.MODE_READ) { + if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) { textureCacheD3D11_->Clear(true); drawEngine_.ClearTrackedVertexArrays(); gstate_c.Dirty(DIRTY_TEXTURE_IMAGE); framebufferManagerD3D11_->DestroyAllFBOs(); - shaderManagerD3D11_->ClearShaders(); } } diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 7459d45df6..1946916e36 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -681,7 +681,7 @@ void GPU_DX9::DoState(PointerWrap &p) { // TODO: Some of these things may not be necessary. // None of these are necessary when saving. - if (p.mode == p.MODE_READ) { + if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) { textureCacheDX9_->Clear(true); drawEngine_.ClearTrackedVertexArrays(); From 9cf17d92880bc81fc5b1b3b8939e537c8f98d64a Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 11 Nov 2017 08:11:10 -0800 Subject: [PATCH 3/4] D3D11: Clear input layouts on shader clear. When we do clear shaders, make sure to also clear input layouts so we don't have corrupt keys. --- GPU/D3D11/DrawEngineD3D11.h | 4 ++-- GPU/D3D11/GPU_D3D11.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/GPU/D3D11/DrawEngineD3D11.h b/GPU/D3D11/DrawEngineD3D11.h index 48b52063bf..7838c79cea 100644 --- a/GPU/D3D11/DrawEngineD3D11.h +++ b/GPU/D3D11/DrawEngineD3D11.h @@ -146,6 +146,8 @@ public: void Resized() override; + void ClearInputLayoutMap(); + private: void DecodeVerts(); void DoFlush(); @@ -154,8 +156,6 @@ private: void ApplyDrawStateLate(bool applyStencilRef, uint8_t stencilRef); void ResetShaderBlending(); - void ClearInputLayoutMap(); - ID3D11InputLayout *SetupDecFmtForDraw(D3D11VertexShader *vshader, const DecVtxFormat &decFmt, u32 pspFmt); void MarkUnreliable(VertexArrayInfoD3D11 *vai); diff --git a/GPU/D3D11/GPU_D3D11.cpp b/GPU/D3D11/GPU_D3D11.cpp index 24cbde0ca4..3c402a2025 100644 --- a/GPU/D3D11/GPU_D3D11.cpp +++ b/GPU/D3D11/GPU_D3D11.cpp @@ -278,6 +278,7 @@ void GPU_D3D11::DeviceLost() { // Simply drop all caches and textures. // FBOs appear to survive? Or no? shaderManagerD3D11_->ClearShaders(); + drawEngine_.ClearInputLayoutMap(); textureCacheD3D11_->Clear(false); framebufferManagerD3D11_->DeviceLost(); } @@ -742,6 +743,7 @@ void GPU_D3D11::ClearCacheNextFrame() { void GPU_D3D11::ClearShaderCache() { shaderManagerD3D11_->ClearShaders(); + drawEngine_.ClearInputLayoutMap(); } void GPU_D3D11::DoState(PointerWrap &p) { From 7041341d1ac9a78de0ca65bc7ea7ff9b27171b19 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 11 Nov 2017 08:17:04 -0800 Subject: [PATCH 4/4] SaveState: Avoid clearing shaders in all backends. --- GPU/Directx9/GPU_DX9.cpp | 1 - GPU/GLES/GPU_GLES.cpp | 2 -- GPU/Vulkan/GPU_Vulkan.cpp | 2 -- 3 files changed, 5 deletions(-) diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 1946916e36..bc85e33e0f 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -687,7 +687,6 @@ void GPU_DX9::DoState(PointerWrap &p) { gstate_c.Dirty(DIRTY_TEXTURE_IMAGE); framebufferManagerDX9_->DestroyAllFBOs(); - shaderManagerDX9_->ClearCache(true); } } diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index b8e7adbd06..781f4c5cd7 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -930,12 +930,10 @@ void GPU_GLES::DoState(PointerWrap &p) { // In Freeze-Frame mode, we don't want to do any of this. if (p.mode == p.MODE_READ && !PSP_CoreParameter().frozen) { textureCacheGL_->Clear(true); - depalShaderCache_.Clear(); drawEngine_.ClearTrackedVertexArrays(); gstate_c.Dirty(DIRTY_TEXTURE_IMAGE); framebufferManagerGL_->DestroyAllFBOs(); - shaderManagerGL_->ClearCache(true); } } diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 66a0e76f56..5a60a9bcbd 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -897,8 +897,6 @@ void GPU_Vulkan::DoState(PointerWrap &p) { gstate_c.Dirty(DIRTY_TEXTURE_IMAGE); framebufferManagerVulkan_->DestroyAllFBOs(); - shaderManagerVulkan_->ClearShaders(); - pipelineManager_->Clear(); } }