From 9b8d2a88de60b1e4ce658e06caa44efaceac54b3 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 19 Jan 2025 15:31:56 +1000 Subject: [PATCH] System: Required changes for Android --- src/core/gpu_thread.cpp | 3 +++ src/core/system.cpp | 19 ++++++++++--------- src/core/system_private.h | 3 +++ 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/core/gpu_thread.cpp b/src/core/gpu_thread.cpp index f40d15cac..8a9e78494 100644 --- a/src/core/gpu_thread.cpp +++ b/src/core/gpu_thread.cpp @@ -433,6 +433,7 @@ bool GPUThread::SleepGPUThread(bool allow_sleep) void GPUThread::Internal::GPUThreadEntryPoint() { s_state.gpu_thread = Threading::ThreadHandle::GetForCallingThread(); + std::atomic_thread_fence(std::memory_order_release); // Take a local copy of the FIFO, that way it's not ping-ponging between the threads. u8* const command_fifo_data = s_state.command_fifo_data.get(); @@ -521,6 +522,8 @@ void GPUThread::Internal::GPUThreadEntryPoint() s_state.command_fifo_read_ptr.store(read_ptr, std::memory_order_release); } + + s_state.gpu_thread = {}; } void GPUThread::Internal::DoRunIdle() diff --git a/src/core/system.cpp b/src/core/system.cpp index 105bfb1ec..b487af99c 100644 --- a/src/core/system.cpp +++ b/src/core/system.cpp @@ -514,13 +514,14 @@ bool System::CPUThreadInitialize(Error* error, u32 async_worker_thread_count) } #endif + s_state.cpu_thread_handle = Threading::ThreadHandle::GetForCallingThread(); + s_state.async_task_queue.SetWorkerCount(async_worker_thread_count); + // This will call back to Host::LoadSettings() -> ReloadSources(). LoadSettings(false); LogStartupInformation(); - s_state.async_task_queue.SetWorkerCount(async_worker_thread_count); - GPUThread::Internal::ProcessStartup(); if (g_settings.achievements_enabled) @@ -545,6 +546,7 @@ void System::CPUThreadShutdown() InputManager::CloseSources(); s_state.async_task_queue.SetWorkerCount(0); + s_state.cpu_thread_handle = {}; #ifdef _WIN32 CoUninitialize(); @@ -556,6 +558,11 @@ const Threading::ThreadHandle& System::GetCPUThreadHandle() return s_state.cpu_thread_handle; } +void System::SetCPUThreadHandle(Threading::ThreadHandle handle) +{ + s_state.cpu_thread_handle = std::move(handle); +} + void System::IdlePollUpdate() { InputManager::PollSources(); @@ -1930,8 +1937,6 @@ bool System::Initialize(std::unique_ptr disc, DiscRegion disc_region, b SIO::Initialize(); PCDrv::Initialize(); - s_state.cpu_thread_handle = Threading::ThreadHandle::GetForCallingThread(); - UpdateGTEAspectRatio(); UpdateThrottlePeriod(); UpdateMemorySaveStateSettings(); @@ -4230,17 +4235,13 @@ bool System::CheckForRequiredSubQ(Error* error) return true; } } -#ifndef __ANDROID__ + Error::SetStringFmt( error, TRANSLATE_FS("System", "You are attempting to run a libcrypt protected game without an SBI file:\n\n{0}: " "{1}\n\nYour dump is incomplete, you must add the SBI file to run this game. \n\nThe " "name of the SBI file must match the name of the disc image."), s_state.running_game_serial, s_state.running_game_title); -#else - // Shorter because no confirm messages. - Error::SetStringView(error, "The selected game requires a SBI file to run properly."); -#endif return false; } diff --git a/src/core/system_private.h b/src/core/system_private.h index 770300f84..1ada8ce48 100644 --- a/src/core/system_private.h +++ b/src/core/system_private.h @@ -71,6 +71,9 @@ void CPUThreadShutdown(); /// Returns a handle to the CPU thread. const Threading::ThreadHandle& GetCPUThreadHandle(); +/// Changes the CPU thread handle, use with care. +void SetCPUThreadHandle(Threading::ThreadHandle handle); + /// Polls input, updates subsystems which are present while paused/inactive. void IdlePollUpdate();