From 4a0951733621a89a5048e7ff5d44ea4f4fbc7461 Mon Sep 17 00:00:00 2001
From: Fernando Sahmkow <fsahmkow27@gmail.com>
Date: Thu, 8 Jul 2021 03:05:23 +0200
Subject: [PATCH] Fence Manager: remove reference fencing.

---
 src/video_core/fence_manager.h                | 23 ++-----------------
 .../renderer_opengl/gl_rasterizer.cpp         |  7 ++----
 .../renderer_vulkan/vk_rasterizer.cpp         |  7 ++----
 3 files changed, 6 insertions(+), 31 deletions(-)

diff --git a/src/video_core/fence_manager.h b/src/video_core/fence_manager.h
index b702b2015..34dc6c596 100644
--- a/src/video_core/fence_manager.h
+++ b/src/video_core/fence_manager.h
@@ -60,23 +60,6 @@ public:
         buffer_cache.AccumulateFlushes();
     }
 
-    void SignalReference() {
-        // Only sync references on High
-        if (Settings::values.gpu_accuracy.GetValue() != Settings::GPUAccuracy::High) {
-            return;
-        }
-        TryReleasePendingFences();
-        const bool should_flush = ShouldFlush();
-        CommitAsyncFlushes();
-        TFence new_fence = CreateFence(0, 0, !should_flush);
-        fences.push(new_fence);
-        QueueFence(new_fence);
-        if (should_flush) {
-            rasterizer.FlushCommands();
-        }
-        rasterizer.SyncGuestHost();
-    }
-
     void SignalSemaphore(GPUVAddr addr, u32 value) {
         TryReleasePendingFences();
         const bool should_flush = ShouldFlush();
@@ -111,10 +94,8 @@ public:
             }
             PopAsyncFlushes();
             if (current_fence->IsSemaphore()) {
-                if (current_fence->GetAddress() != 0) {
-                    gpu_memory.template Write<u32>(current_fence->GetAddress(),
-                                                   current_fence->GetPayload());
-                }
+                gpu_memory.template Write<u32>(current_fence->GetAddress(),
+                                               current_fence->GetPayload());
             } else {
                 gpu.IncrementSyncPoint(current_fence->GetPayload());
             }
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 514c2f47d..a4ed8f68f 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -638,7 +638,7 @@ void RasterizerOpenGL::SignalReference() {
     if (!gpu.IsAsync()) {
         return;
     }
-    fence_manager.SignalReference();
+    fence_manager.SignalOrdering();
 }
 
 void RasterizerOpenGL::ReleaseFences() {
@@ -657,10 +657,7 @@ void RasterizerOpenGL::FlushAndInvalidateRegion(VAddr addr, u64 size) {
 
 void RasterizerOpenGL::WaitForIdle() {
     glMemoryBarrier(GL_ALL_BARRIER_BITS);
-    if (!gpu.IsAsync()) {
-        return;
-    }
-    fence_manager.SignalOrdering();
+    SignalReference();
 }
 
 void RasterizerOpenGL::FragmentBarrier() {
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
index 392de47d0..9ea4b6653 100644
--- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp
+++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp
@@ -584,7 +584,7 @@ void RasterizerVulkan::SignalReference() {
     if (!gpu.IsAsync()) {
         return;
     }
-    fence_manager.SignalReference();
+    fence_manager.SignalOrdering();
 }
 
 void RasterizerVulkan::ReleaseFences() {
@@ -619,10 +619,7 @@ void RasterizerVulkan::WaitForIdle() {
         cmdbuf.SetEvent(event, flags);
         cmdbuf.WaitEvents(event, flags, VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT, {}, {}, {});
     });
-    if (!gpu.IsAsync()) {
-        return;
-    }
-    fence_manager.SignalOrdering();
+    SignalReference();
 }
 
 void RasterizerVulkan::FragmentBarrier() {