summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/core.cpp2
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp3
-rw-r--r--src/video_core/gpu.cpp29
-rw-r--r--src/video_core/gpu.h6
4 files changed, 30 insertions, 10 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index aa96f709b..3f9a7f44b 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -317,6 +317,8 @@ struct System::Impl {
317 is_powered_on = false; 317 is_powered_on = false;
318 exit_lock = false; 318 exit_lock = false;
319 319
320 gpu_core->NotifyShutdown();
321
320 services.reset(); 322 services.reset();
321 service_manager.reset(); 323 service_manager.reset();
322 cheat_engine.reset(); 324 cheat_engine.reset();
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index 396cc5afa..a22811ec1 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -266,11 +266,10 @@ void NVFlinger::Compose() {
266 266
267 auto& gpu = system.GPU(); 267 auto& gpu = system.GPU();
268 const auto& multi_fence = buffer->get().multi_fence; 268 const auto& multi_fence = buffer->get().multi_fence;
269 const auto stop_token = vsync_thread.get_stop_token();
270 guard->unlock(); 269 guard->unlock();
271 for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) { 270 for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) {
272 const auto& fence = multi_fence.fences[fence_id]; 271 const auto& fence = multi_fence.fences[fence_id];
273 gpu.WaitFence(fence.id, fence.value, stop_token); 272 gpu.WaitFence(fence.id, fence.value);
274 } 273 }
275 guard->lock(); 274 guard->lock();
276 275
diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp
index d98874150..44fda27ef 100644
--- a/src/video_core/gpu.cpp
+++ b/src/video_core/gpu.cpp
@@ -206,7 +206,7 @@ struct GPU::Impl {
206 } 206 }
207 207
208 /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame. 208 /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame.
209 void WaitFence(u32 syncpoint_id, u32 value, std::stop_token stop_token = {}) { 209 void WaitFence(u32 syncpoint_id, u32 value) {
210 // Synced GPU, is always in sync 210 // Synced GPU, is always in sync
211 if (!is_async) { 211 if (!is_async) {
212 return; 212 return;
@@ -218,8 +218,13 @@ struct GPU::Impl {
218 } 218 }
219 MICROPROFILE_SCOPE(GPU_wait); 219 MICROPROFILE_SCOPE(GPU_wait);
220 std::unique_lock lock{sync_mutex}; 220 std::unique_lock lock{sync_mutex};
221 sync_cv.wait(lock, stop_token, 221 sync_cv.wait(lock, [=, this] {
222 [=, this] { return syncpoints.at(syncpoint_id).load() >= value; }); 222 if (shutting_down.load(std::memory_order_relaxed)) {
223 // We're shutting down, ensure no threads continue to wait for the next syncpoint
224 return true;
225 }
226 return syncpoints.at(syncpoint_id).load() >= value;
227 });
223 } 228 }
224 229
225 void IncrementSyncPoint(u32 syncpoint_id) { 230 void IncrementSyncPoint(u32 syncpoint_id) {
@@ -307,6 +312,12 @@ struct GPU::Impl {
307 cpu_context->MakeCurrent(); 312 cpu_context->MakeCurrent();
308 } 313 }
309 314
315 void NotifyShutdown() {
316 std::unique_lock lk{sync_mutex};
317 shutting_down.store(true, std::memory_order::relaxed);
318 sync_cv.notify_all();
319 }
320
310 /// Obtain the CPU Context 321 /// Obtain the CPU Context
311 void ObtainContext() { 322 void ObtainContext() {
312 cpu_context->MakeCurrent(); 323 cpu_context->MakeCurrent();
@@ -665,6 +676,8 @@ struct GPU::Impl {
665 std::unique_ptr<Engines::KeplerMemory> kepler_memory; 676 std::unique_ptr<Engines::KeplerMemory> kepler_memory;
666 /// Shader build notifier 677 /// Shader build notifier
667 std::unique_ptr<VideoCore::ShaderNotify> shader_notify; 678 std::unique_ptr<VideoCore::ShaderNotify> shader_notify;
679 /// When true, we are about to shut down emulation session, so terminate outstanding tasks
680 std::atomic_bool shutting_down{};
668 681
669 std::array<std::atomic<u32>, Service::Nvidia::MaxSyncPoints> syncpoints{}; 682 std::array<std::atomic<u32>, Service::Nvidia::MaxSyncPoints> syncpoints{};
670 683
@@ -673,7 +686,7 @@ struct GPU::Impl {
673 std::mutex sync_mutex; 686 std::mutex sync_mutex;
674 std::mutex device_mutex; 687 std::mutex device_mutex;
675 688
676 std::condition_variable_any sync_cv; 689 std::condition_variable sync_cv;
677 690
678 struct FlushRequest { 691 struct FlushRequest {
679 explicit FlushRequest(u64 fence_, VAddr addr_, std::size_t size_) 692 explicit FlushRequest(u64 fence_, VAddr addr_, std::size_t size_)
@@ -812,8 +825,8 @@ const VideoCore::ShaderNotify& GPU::ShaderNotify() const {
812 return impl->ShaderNotify(); 825 return impl->ShaderNotify();
813} 826}
814 827
815void GPU::WaitFence(u32 syncpoint_id, u32 value, std::stop_token stop_token) { 828void GPU::WaitFence(u32 syncpoint_id, u32 value) {
816 impl->WaitFence(syncpoint_id, value, stop_token); 829 impl->WaitFence(syncpoint_id, value);
817} 830}
818 831
819void GPU::IncrementSyncPoint(u32 syncpoint_id) { 832void GPU::IncrementSyncPoint(u32 syncpoint_id) {
@@ -852,6 +865,10 @@ void GPU::Start() {
852 impl->Start(); 865 impl->Start();
853} 866}
854 867
868void GPU::NotifyShutdown() {
869 impl->NotifyShutdown();
870}
871
855void GPU::ObtainContext() { 872void GPU::ObtainContext() {
856 impl->ObtainContext(); 873 impl->ObtainContext();
857} 874}
diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h
index cc65a7870..3188b83ed 100644
--- a/src/video_core/gpu.h
+++ b/src/video_core/gpu.h
@@ -5,7 +5,6 @@
5#pragma once 5#pragma once
6 6
7#include <memory> 7#include <memory>
8#include <stop_token>
9 8
10#include "common/bit_field.h" 9#include "common/bit_field.h"
11#include "common/common_types.h" 10#include "common/common_types.h"
@@ -210,7 +209,7 @@ public:
210 [[nodiscard]] const VideoCore::ShaderNotify& ShaderNotify() const; 209 [[nodiscard]] const VideoCore::ShaderNotify& ShaderNotify() const;
211 210
212 /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame. 211 /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame.
213 void WaitFence(u32 syncpoint_id, u32 value, std::stop_token stop_token = {}); 212 void WaitFence(u32 syncpoint_id, u32 value);
214 213
215 void IncrementSyncPoint(u32 syncpoint_id); 214 void IncrementSyncPoint(u32 syncpoint_id);
216 215
@@ -233,6 +232,9 @@ public:
233 /// core timing events. 232 /// core timing events.
234 void Start(); 233 void Start();
235 234
235 /// Performs any additional necessary steps to shutdown GPU emulation.
236 void NotifyShutdown();
237
236 /// Obtain the CPU Context 238 /// Obtain the CPU Context
237 void ObtainContext(); 239 void ObtainContext();
238 240