summaryrefslogtreecommitdiff
path: root/src/video_core/gpu_thread.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2019-03-30 20:08:09 -0400
committerGravatar bunnei2019-04-01 21:32:39 -0400
commit4555b637500daeb26f556113656fc3d242e60872 (patch)
tree3b79747fa480de5bcfb7e836d75f9a414599246d /src/video_core/gpu_thread.cpp
parentMerge pull request #2301 from FearlessTobi/remove-amiibo-setting (diff)
downloadyuzu-4555b637500daeb26f556113656fc3d242e60872.tar.gz
yuzu-4555b637500daeb26f556113656fc3d242e60872.tar.xz
yuzu-4555b637500daeb26f556113656fc3d242e60872.zip
gpu_thread: Improve synchronization by using CoreTiming.
Diffstat (limited to 'src/video_core/gpu_thread.cpp')
-rw-r--r--src/video_core/gpu_thread.cpp43
1 files changed, 33 insertions, 10 deletions
diff --git a/src/video_core/gpu_thread.cpp b/src/video_core/gpu_thread.cpp
index c5dc199c5..23f9bd422 100644
--- a/src/video_core/gpu_thread.cpp
+++ b/src/video_core/gpu_thread.cpp
@@ -4,6 +4,9 @@
4 4
5#include "common/assert.h" 5#include "common/assert.h"
6#include "common/microprofile.h" 6#include "common/microprofile.h"
7#include "core/core.h"
8#include "core/core_timing.h"
9#include "core/core_timing_util.h"
7#include "core/frontend/scope_acquire_window_context.h" 10#include "core/frontend/scope_acquire_window_context.h"
8#include "video_core/dma_pusher.h" 11#include "video_core/dma_pusher.h"
9#include "video_core/gpu.h" 12#include "video_core/gpu.h"
@@ -36,7 +39,6 @@ static void RunThread(VideoCore::RendererBase& renderer, Tegra::DmaPusher& dma_p
36 dma_pusher.Push(std::move(submit_list->entries)); 39 dma_pusher.Push(std::move(submit_list->entries));
37 dma_pusher.DispatchCalls(); 40 dma_pusher.DispatchCalls();
38 } else if (const auto data = std::get_if<SwapBuffersCommand>(&next.data)) { 41 } else if (const auto data = std::get_if<SwapBuffersCommand>(&next.data)) {
39 state.DecrementFramesCounter();
40 renderer.SwapBuffers(std::move(data->framebuffer)); 42 renderer.SwapBuffers(std::move(data->framebuffer));
41 } else if (const auto data = std::get_if<FlushRegionCommand>(&next.data)) { 43 } else if (const auto data = std::get_if<FlushRegionCommand>(&next.data)) {
42 renderer.Rasterizer().FlushRegion(data->addr, data->size); 44 renderer.Rasterizer().FlushRegion(data->addr, data->size);
@@ -47,13 +49,18 @@ static void RunThread(VideoCore::RendererBase& renderer, Tegra::DmaPusher& dma_p
47 } else { 49 } else {
48 UNREACHABLE(); 50 UNREACHABLE();
49 } 51 }
52 state.signaled_fence = next.fence;
53 state.TrySynchronize();
50 } 54 }
51 } 55 }
52} 56}
53 57
54ThreadManager::ThreadManager(VideoCore::RendererBase& renderer, Tegra::DmaPusher& dma_pusher) 58ThreadManager::ThreadManager(Core::System& system, VideoCore::RendererBase& renderer,
55 : renderer{renderer}, thread{RunThread, std::ref(renderer), std::ref(dma_pusher), 59 Tegra::DmaPusher& dma_pusher)
56 std::ref(state)} {} 60 : system{system}, thread{RunThread, std::ref(renderer), std::ref(dma_pusher), std::ref(state)} {
61 synchronization_event = system.CoreTiming().RegisterEvent(
62 "GPUThreadSynch", [this](u64 fence, int) { state.WaitForSynchronization(fence); });
63}
57 64
58ThreadManager::~ThreadManager() { 65ThreadManager::~ThreadManager() {
59 // Notify GPU thread that a shutdown is pending 66 // Notify GPU thread that a shutdown is pending
@@ -62,14 +69,14 @@ ThreadManager::~ThreadManager() {
62} 69}
63 70
64void ThreadManager::SubmitList(Tegra::CommandList&& entries) { 71void ThreadManager::SubmitList(Tegra::CommandList&& entries) {
65 PushCommand(SubmitListCommand(std::move(entries))); 72 const u64 fence{PushCommand(SubmitListCommand(std::move(entries)))};
73 const s64 synchronization_ticks{Core::Timing::usToCycles(9000)};
74 system.CoreTiming().ScheduleEvent(synchronization_ticks, synchronization_event, fence);
66} 75}
67 76
68void ThreadManager::SwapBuffers( 77void ThreadManager::SwapBuffers(
69 std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) { 78 std::optional<std::reference_wrapper<const Tegra::FramebufferConfig>> framebuffer) {
70 state.IncrementFramesCounter();
71 PushCommand(SwapBuffersCommand(std::move(framebuffer))); 79 PushCommand(SwapBuffersCommand(std::move(framebuffer)));
72 state.WaitForFrames();
73} 80}
74 81
75void ThreadManager::FlushRegion(CacheAddr addr, u64 size) { 82void ThreadManager::FlushRegion(CacheAddr addr, u64 size) {
@@ -79,7 +86,7 @@ void ThreadManager::FlushRegion(CacheAddr addr, u64 size) {
79void ThreadManager::InvalidateRegion(CacheAddr addr, u64 size) { 86void ThreadManager::InvalidateRegion(CacheAddr addr, u64 size) {
80 if (state.queue.Empty()) { 87 if (state.queue.Empty()) {
81 // It's quicker to invalidate a single region on the CPU if the queue is already empty 88 // It's quicker to invalidate a single region on the CPU if the queue is already empty
82 renderer.Rasterizer().InvalidateRegion(addr, size); 89 system.Renderer().Rasterizer().InvalidateRegion(addr, size);
83 } else { 90 } else {
84 PushCommand(InvalidateRegionCommand(addr, size)); 91 PushCommand(InvalidateRegionCommand(addr, size));
85 } 92 }
@@ -90,9 +97,25 @@ void ThreadManager::FlushAndInvalidateRegion(CacheAddr addr, u64 size) {
90 InvalidateRegion(addr, size); 97 InvalidateRegion(addr, size);
91} 98}
92 99
93void ThreadManager::PushCommand(CommandData&& command_data) { 100u64 ThreadManager::PushCommand(CommandData&& command_data) {
94 state.queue.Push(CommandDataContainer(std::move(command_data))); 101 const u64 fence{++state.last_fence};
102 state.queue.Push(CommandDataContainer(std::move(command_data), fence));
95 state.SignalCommands(); 103 state.SignalCommands();
104 return fence;
105}
106
107MICROPROFILE_DEFINE(GPU_wait, "GPU", "Wait for the GPU", MP_RGB(128, 128, 192));
108void SynchState::WaitForSynchronization(u64 fence) {
109 if (signaled_fence >= fence) {
110 return;
111 }
112
113 // Wait for the GPU to be idle (all commands to be executed)
114 {
115 MICROPROFILE_SCOPE(GPU_wait);
116 std::unique_lock<std::mutex> lock{synchronization_mutex};
117 synchronization_condition.wait(lock, [this, fence] { return signaled_fence >= fence; });
118 }
96} 119}
97 120
98} // namespace VideoCommon::GPUThread 121} // namespace VideoCommon::GPUThread