diff options
| -rw-r--r-- | src/video_core/renderer_opengl/renderer_opengl.cpp | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index 12333e8c9..c91658cd1 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp | |||
| @@ -56,7 +56,7 @@ public: | |||
| 56 | std::deque<Frame*> present_queue; | 56 | std::deque<Frame*> present_queue; |
| 57 | Frame* previous_frame{}; | 57 | Frame* previous_frame{}; |
| 58 | 58 | ||
| 59 | FrameMailbox() { | 59 | FrameMailbox() : has_debug_tool{Device().HasDebugTool()} { |
| 60 | for (auto& frame : swap_chain) { | 60 | for (auto& frame : swap_chain) { |
| 61 | free_queue.push(&frame); | 61 | free_queue.push(&frame); |
| 62 | } | 62 | } |
| @@ -127,9 +127,13 @@ public: | |||
| 127 | std::unique_lock lock{swap_chain_lock}; | 127 | std::unique_lock lock{swap_chain_lock}; |
| 128 | present_queue.push_front(frame); | 128 | present_queue.push_front(frame); |
| 129 | present_cv.notify_one(); | 129 | present_cv.notify_one(); |
| 130 | |||
| 131 | DebugNotifyNextFrame(); | ||
| 130 | } | 132 | } |
| 131 | 133 | ||
| 132 | Frame* TryGetPresentFrame(int timeout_ms) { | 134 | Frame* TryGetPresentFrame(int timeout_ms) { |
| 135 | DebugWaitForNextFrame(); | ||
| 136 | |||
| 133 | std::unique_lock lock{swap_chain_lock}; | 137 | std::unique_lock lock{swap_chain_lock}; |
| 134 | // wait for new entries in the present_queue | 138 | // wait for new entries in the present_queue |
| 135 | present_cv.wait_for(lock, std::chrono::milliseconds(timeout_ms), | 139 | present_cv.wait_for(lock, std::chrono::milliseconds(timeout_ms), |
| @@ -155,6 +159,33 @@ public: | |||
| 155 | previous_frame = frame; | 159 | previous_frame = frame; |
| 156 | return frame; | 160 | return frame; |
| 157 | } | 161 | } |
| 162 | |||
| 163 | private: | ||
| 164 | std::mutex debug_synch_mutex; | ||
| 165 | std::condition_variable debug_synch_condition; | ||
| 166 | std::atomic_int frame_for_debug{}; | ||
| 167 | const bool has_debug_tool; // When true, using a GPU debugger, so keep frames in lock-step | ||
| 168 | |||
| 169 | /// Signal that a new frame is available (called from GPU thread) | ||
| 170 | void DebugNotifyNextFrame() { | ||
| 171 | if (!has_debug_tool) { | ||
| 172 | return; | ||
| 173 | } | ||
| 174 | frame_for_debug++; | ||
| 175 | std::lock_guard lock{debug_synch_mutex}; | ||
| 176 | debug_synch_condition.notify_one(); | ||
| 177 | } | ||
| 178 | |||
| 179 | /// Wait for a new frame to be available (called from presentation thread) | ||
| 180 | void DebugWaitForNextFrame() { | ||
| 181 | if (!has_debug_tool) { | ||
| 182 | return; | ||
| 183 | } | ||
| 184 | const int last_frame = frame_for_debug; | ||
| 185 | std::unique_lock lock{debug_synch_mutex}; | ||
| 186 | debug_synch_condition.wait(lock, | ||
| 187 | [this, last_frame] { return frame_for_debug > last_frame; }); | ||
| 188 | } | ||
| 158 | }; | 189 | }; |
| 159 | 190 | ||
| 160 | namespace { | 191 | namespace { |