From 561ce29c98bf822941061023e1f71a62175318ae Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Mon, 10 Jun 2019 10:39:59 -0400
Subject: [PATCH] texture_cache: correct mutex locks

---
 src/video_core/texture_cache/texture_cache.h | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index d2c27bceff..503bd2b430 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -90,6 +90,7 @@ public:
 
     TView GetTextureSurface(const Tegra::Texture::FullTextureInfo& config,
                             const VideoCommon::Shader::Sampler& entry) {
+        std::lock_guard lock{mutex};
         const auto gpu_addr{config.tic.Address()};
         if (!gpu_addr) {
             return {};
@@ -99,6 +100,7 @@ public:
     }
 
     TView GetDepthBufferSurface(bool preserve_contents) {
+        std::lock_guard lock{mutex};
         auto& maxwell3d = system.GPU().Maxwell3D();
 
         if (!maxwell3d.dirty_flags.zeta_buffer) {
@@ -127,6 +129,7 @@ public:
     }
 
     TView GetColorBufferSurface(std::size_t index, bool preserve_contents) {
+        std::lock_guard lock{mutex};
         ASSERT(index < Tegra::Engines::Maxwell3D::Regs::NumRenderTargets);
         auto& maxwell3d = system.GPU().Maxwell3D();
         if (!maxwell3d.dirty_flags.color_buffer[index]) {
@@ -188,6 +191,7 @@ public:
     void DoFermiCopy(const Tegra::Engines::Fermi2D::Regs::Surface& src_config,
                      const Tegra::Engines::Fermi2D::Regs::Surface& dst_config,
                      const Tegra::Engines::Fermi2D::Config& copy_config) {
+        std::lock_guard lock{mutex};
         std::pair<TSurface, TView> dst_surface = GetFermiSurface(dst_config);
         std::pair<TSurface, TView> src_surface = GetFermiSurface(src_config);
         ImageBlit(src_surface.second, dst_surface.second, copy_config);
@@ -245,8 +249,6 @@ protected:
     virtual void BufferCopy(TSurface& src_surface, TSurface& dst_surface) = 0;
 
     void Register(TSurface surface) {
-        std::lock_guard lock{mutex};
-
         const GPUVAddr gpu_addr = surface->GetGpuAddr();
         const CacheAddr cache_ptr = ToCacheAddr(memory_manager->GetPointer(gpu_addr));
         const std::size_t size = surface->GetSizeInBytes();
@@ -266,8 +268,6 @@ protected:
     }
 
     void Unregister(TSurface surface) {
-        std::lock_guard lock{mutex};
-
         if (guard_cache && surface->IsProtected()) {
             return;
         }