mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-27 11:14:22 +01:00
bootmanager: Use std::stop_source for stopping emulation
Use its std::stop_token to abort shader cache loading. Using std::stop_token instead of std::atomic_bool allows the usage of other utilities like std::stop_callback.
This commit is contained in:
parent
0485b8e84b
commit
4009ae1da2
@ -4,10 +4,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
#include <stop_token>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "video_core/engines/fermi_2d.h"
|
#include "video_core/engines/fermi_2d.h"
|
||||||
#include "video_core/gpu.h"
|
#include "video_core/gpu.h"
|
||||||
@ -123,7 +123,7 @@ public:
|
|||||||
virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
|
virtual void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) {}
|
||||||
|
|
||||||
/// Initialize disk cached resources for the game being emulated
|
/// Initialize disk cached resources for the game being emulated
|
||||||
virtual void LoadDiskResources(u64 title_id, const std::atomic_bool& stop_loading,
|
virtual void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||||
const DiskResourceLoadCallback& callback) {}
|
const DiskResourceLoadCallback& callback) {}
|
||||||
|
|
||||||
/// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
|
/// Grant access to the Guest Driver Profile for recording/obtaining info on the guest driver.
|
||||||
|
@ -351,7 +351,7 @@ void RasterizerOpenGL::SetupShaders(bool is_indexed) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerOpenGL::LoadDiskResources(u64 title_id, const std::atomic_bool& stop_loading,
|
void RasterizerOpenGL::LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||||
const VideoCore::DiskResourceLoadCallback& callback) {
|
const VideoCore::DiskResourceLoadCallback& callback) {
|
||||||
shader_cache.LoadDiskCache(title_id, stop_loading, callback);
|
shader_cache.LoadDiskCache(title_id, stop_loading, callback);
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ public:
|
|||||||
const Tegra::Engines::Fermi2D::Config& copy_config) override;
|
const Tegra::Engines::Fermi2D::Config& copy_config) override;
|
||||||
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
||||||
u32 pixel_stride) override;
|
u32 pixel_stride) override;
|
||||||
void LoadDiskResources(u64 title_id, const std::atomic_bool& stop_loading,
|
void LoadDiskResources(u64 title_id, std::stop_token stop_loading,
|
||||||
const VideoCore::DiskResourceLoadCallback& callback) override;
|
const VideoCore::DiskResourceLoadCallback& callback) override;
|
||||||
|
|
||||||
/// Returns true when there are commands queued to the OpenGL server.
|
/// Returns true when there are commands queued to the OpenGL server.
|
||||||
|
@ -331,7 +331,7 @@ ShaderCacheOpenGL::ShaderCacheOpenGL(RasterizerOpenGL& rasterizer_,
|
|||||||
|
|
||||||
ShaderCacheOpenGL::~ShaderCacheOpenGL() = default;
|
ShaderCacheOpenGL::~ShaderCacheOpenGL() = default;
|
||||||
|
|
||||||
void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop_loading,
|
void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, std::stop_token stop_loading,
|
||||||
const VideoCore::DiskResourceLoadCallback& callback) {
|
const VideoCore::DiskResourceLoadCallback& callback) {
|
||||||
disk_cache.BindTitleID(title_id);
|
disk_cache.BindTitleID(title_id);
|
||||||
const std::optional transferable = disk_cache.LoadTransferable();
|
const std::optional transferable = disk_cache.LoadTransferable();
|
||||||
@ -372,7 +372,7 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop
|
|||||||
const auto scope = context->Acquire();
|
const auto scope = context->Acquire();
|
||||||
|
|
||||||
for (std::size_t i = begin; i < end; ++i) {
|
for (std::size_t i = begin; i < end; ++i) {
|
||||||
if (stop_loading) {
|
if (stop_loading.stop_requested()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const auto& entry = (*transferable)[i];
|
const auto& entry = (*transferable)[i];
|
||||||
@ -435,7 +435,7 @@ void ShaderCacheOpenGL::LoadDiskCache(u64 title_id, const std::atomic_bool& stop
|
|||||||
precompiled_cache_altered = true;
|
precompiled_cache_altered = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (stop_loading) {
|
if (stop_loading.stop_requested()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +127,7 @@ public:
|
|||||||
~ShaderCacheOpenGL() override;
|
~ShaderCacheOpenGL() override;
|
||||||
|
|
||||||
/// Loads disk cache for the current game
|
/// Loads disk cache for the current game
|
||||||
void LoadDiskCache(u64 title_id, const std::atomic_bool& stop_loading,
|
void LoadDiskCache(u64 title_id, std::stop_token stop_loading,
|
||||||
const VideoCore::DiskResourceLoadCallback& callback);
|
const VideoCore::DiskResourceLoadCallback& callback);
|
||||||
|
|
||||||
/// Gets the current specified shader stage program
|
/// Gets the current specified shader stage program
|
||||||
|
@ -51,11 +51,11 @@ void EmuThread::run() {
|
|||||||
Common::SetCurrentThreadName(name.c_str());
|
Common::SetCurrentThreadName(name.c_str());
|
||||||
|
|
||||||
auto& system = Core::System::GetInstance();
|
auto& system = Core::System::GetInstance();
|
||||||
|
auto& gpu = system.GPU();
|
||||||
|
auto stop_token = stop_source.get_token();
|
||||||
|
|
||||||
system.RegisterHostThread();
|
system.RegisterHostThread();
|
||||||
|
|
||||||
auto& gpu = system.GPU();
|
|
||||||
|
|
||||||
// Main process has been loaded. Make the context current to this thread and begin GPU and CPU
|
// Main process has been loaded. Make the context current to this thread and begin GPU and CPU
|
||||||
// execution.
|
// execution.
|
||||||
gpu.Start();
|
gpu.Start();
|
||||||
@ -65,7 +65,7 @@ void EmuThread::run() {
|
|||||||
emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
|
emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
|
||||||
|
|
||||||
system.Renderer().ReadRasterizer()->LoadDiskResources(
|
system.Renderer().ReadRasterizer()->LoadDiskResources(
|
||||||
system.CurrentProcess()->GetTitleID(), stop_run,
|
system.CurrentProcess()->GetTitleID(), stop_token,
|
||||||
[this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
|
[this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
|
||||||
emit LoadProgress(stage, value, total);
|
emit LoadProgress(stage, value, total);
|
||||||
});
|
});
|
||||||
@ -78,7 +78,7 @@ void EmuThread::run() {
|
|||||||
// so that the DebugModeLeft signal can be emitted before the
|
// so that the DebugModeLeft signal can be emitted before the
|
||||||
// next execution step
|
// next execution step
|
||||||
bool was_active = false;
|
bool was_active = false;
|
||||||
while (!stop_run) {
|
while (!stop_token.stop_requested()) {
|
||||||
if (running) {
|
if (running) {
|
||||||
if (was_active) {
|
if (was_active) {
|
||||||
emit DebugModeLeft();
|
emit DebugModeLeft();
|
||||||
@ -100,7 +100,7 @@ void EmuThread::run() {
|
|||||||
}
|
}
|
||||||
running_guard = false;
|
running_guard = false;
|
||||||
|
|
||||||
if (!stop_run) {
|
if (!stop_token.stop_requested()) {
|
||||||
was_active = true;
|
was_active = true;
|
||||||
emit DebugModeEntered();
|
emit DebugModeEntered();
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ void EmuThread::run() {
|
|||||||
UNIMPLEMENTED();
|
UNIMPLEMENTED();
|
||||||
} else {
|
} else {
|
||||||
std::unique_lock lock{running_mutex};
|
std::unique_lock lock{running_mutex};
|
||||||
running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; });
|
running_cv.wait(lock, stop_token, [this] { return IsRunning() || exec_step; });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,16 +89,16 @@ public:
|
|||||||
* Requests for the emulation thread to stop running
|
* Requests for the emulation thread to stop running
|
||||||
*/
|
*/
|
||||||
void RequestStop() {
|
void RequestStop() {
|
||||||
stop_run = true;
|
stop_source.request_stop();
|
||||||
SetRunning(false);
|
SetRunning(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool exec_step = false;
|
bool exec_step = false;
|
||||||
bool running = false;
|
bool running = false;
|
||||||
std::atomic_bool stop_run{false};
|
std::stop_source stop_source;
|
||||||
std::mutex running_mutex;
|
std::mutex running_mutex;
|
||||||
std::condition_variable running_cv;
|
std::condition_variable_any running_cv;
|
||||||
Common::Event running_wait{};
|
Common::Event running_wait{};
|
||||||
std::atomic_bool running_guard{false};
|
std::atomic_bool running_guard{false};
|
||||||
|
|
||||||
|
@ -219,7 +219,7 @@ int main(int argc, char** argv) {
|
|||||||
system.GPU().Start();
|
system.GPU().Start();
|
||||||
|
|
||||||
system.Renderer().ReadRasterizer()->LoadDiskResources(
|
system.Renderer().ReadRasterizer()->LoadDiskResources(
|
||||||
system.CurrentProcess()->GetTitleID(), false,
|
system.CurrentProcess()->GetTitleID(), std::stop_token{},
|
||||||
[](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
|
[](VideoCore::LoadCallbackStage, size_t value, size_t total) {});
|
||||||
|
|
||||||
void(system.Run());
|
void(system.Run());
|
||||||
|
Loading…
Reference in New Issue
Block a user