From 8562b516c0e3fa25a65e440db29cd474c0cbb896 Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sun, 28 Jun 2020 21:42:57 -0300 Subject: [PATCH 01/55] core_timing,scheduler: Use std::scoped_lock when possible Simplifies the cognitive load of procedures using locks and makes locks safe against exceptions. --- src/core/core_timing.cpp | 6 ++---- src/core/hle/kernel/scheduler.cpp | 21 ++++++++++----------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/core/core_timing.cpp b/src/core/core_timing.cpp index 5c83c41a4..a63e60461 100644 --- a/src/core/core_timing.cpp +++ b/src/core/core_timing.cpp @@ -172,7 +172,7 @@ void CoreTiming::ClearPendingEvents() { } void CoreTiming::RemoveEvent(const std::shared_ptr& event_type) { - basic_lock.lock(); + std::scoped_lock lock{basic_lock}; const auto itr = std::remove_if(event_queue.begin(), event_queue.end(), [&](const Event& e) { return e.type.lock().get() == event_type.get(); @@ -183,12 +183,10 @@ void CoreTiming::RemoveEvent(const std::shared_ptr& event_type) { event_queue.erase(itr, event_queue.end()); std::make_heap(event_queue.begin(), event_queue.end(), std::greater<>()); } - basic_lock.unlock(); } std::optional CoreTiming::Advance() { - std::scoped_lock advance_scope{advance_lock}; - std::scoped_lock basic_scope{basic_lock}; + std::scoped_lock lock{advance_lock, basic_lock}; global_timer = GetGlobalTimeNs().count(); while (!event_queue.empty() && event_queue.front().time <= global_timer) { diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index 2b12c0dbf..7b929781c 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp @@ -6,6 +6,7 @@ // licensed under GPLv2 or later under exception provided by the author. #include +#include #include #include #include @@ -31,22 +32,20 @@ GlobalScheduler::GlobalScheduler(KernelCore& kernel) : kernel{kernel} {} GlobalScheduler::~GlobalScheduler() = default; void GlobalScheduler::AddThread(std::shared_ptr thread) { - global_list_guard.lock(); + std::scoped_lock lock{global_list_guard}; thread_list.push_back(std::move(thread)); - global_list_guard.unlock(); } void GlobalScheduler::RemoveThread(std::shared_ptr thread) { - global_list_guard.lock(); + std::scoped_lock lock{global_list_guard}; thread_list.erase(std::remove(thread_list.begin(), thread_list.end(), thread), thread_list.end()); - global_list_guard.unlock(); } u32 GlobalScheduler::SelectThreads() { ASSERT(is_locked); const auto update_thread = [](Thread* thread, Scheduler& sched) { - sched.guard.lock(); + std::scoped_lock lock{sched.guard}; if (thread != sched.selected_thread_set.get()) { if (thread == nullptr) { ++sched.idle_selection_count; @@ -57,7 +56,6 @@ u32 GlobalScheduler::SelectThreads() { sched.is_context_switch_pending || (sched.selected_thread_set != sched.current_thread); sched.is_context_switch_pending = reschedule_pending; std::atomic_thread_fence(std::memory_order_seq_cst); - sched.guard.unlock(); return reschedule_pending; }; if (!is_reselection_pending.load()) { @@ -757,11 +755,12 @@ void Scheduler::OnSwitch(void* this_scheduler) { void Scheduler::SwitchToCurrent() { while (true) { - guard.lock(); - selected_thread = selected_thread_set; - current_thread = selected_thread; - is_context_switch_pending = false; - guard.unlock(); + { + std::scoped_lock lock{guard}; + selected_thread = selected_thread_set; + current_thread = selected_thread; + is_context_switch_pending = false; + } while (!is_context_switch_pending) { if (current_thread != nullptr && !current_thread->IsHLEThread()) { current_thread->context_guard.lock(); From 6a0010d0c64ff3e023d8f16e543dfaf73c531179 Mon Sep 17 00:00:00 2001 From: VolcaEM <63682805+VolcaEM@users.noreply.github.com> Date: Mon, 29 Jun 2020 04:01:34 +0200 Subject: [PATCH 02/55] service: Update function tables --- src/core/hle/service/nfp/nfp.cpp | 4 +- src/core/hle/service/nim/nim.cpp | 88 +++++++++++++++++-- src/core/hle/service/npns/npns.cpp | 1 + src/core/hle/service/ns/ns.cpp | 26 +++--- src/core/hle/service/ns/ns.h | 6 +- src/core/hle/service/ns/pl_u.cpp | 2 +- src/core/hle/service/nvdrv/interface.cpp | 11 +-- src/core/hle/service/nvdrv/interface.h | 4 +- src/core/hle/service/nvdrv/nvmemp.cpp | 8 +- src/core/hle/service/nvdrv/nvmemp.h | 4 +- src/core/hle/service/pcie/pcie.cpp | 3 + src/core/hle/service/pcv/pcv.cpp | 3 + src/core/hle/service/pm/pm.cpp | 34 ++++---- src/core/hle/service/prepo/prepo.cpp | 5 ++ src/core/hle/service/psc/psc.cpp | 2 + src/core/hle/service/ptm/psm.cpp | 1 + src/core/hle/service/sm/controller.cpp | 19 ++-- src/core/hle/service/sm/controller.h | 6 +- src/core/hle/service/sockets/nsd.cpp | 6 ++ src/core/hle/service/sockets/sfdnsres.cpp | 25 +++--- src/core/hle/service/sockets/sfdnsres.h | 2 +- src/core/hle/service/spl/spl.cpp | 39 +++++---- src/core/hle/service/time/time.cpp | 7 ++ src/core/hle/service/usb/usb.cpp | 31 +++---- src/core/hle/service/vi/vi.cpp | 2 + src/core/hle/service/vi/vi_u.cpp | 1 + src/core/hle/service/wlan/wlan.cpp | 102 ++++++++++++---------- 27 files changed, 285 insertions(+), 157 deletions(-) diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 4b79eb81d..386ecd4a9 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -55,7 +55,7 @@ public: {19, &IUser::GetState, "GetState"}, {20, &IUser::GetDeviceState, "GetDeviceState"}, {21, &IUser::GetNpadId, "GetNpadId"}, - {22, &IUser::GetApplicationAreaSize, "GetApplicationAreaSize"}, + {22, &IUser::GetApplicationArea2, "GetApplicationArea2"}, {23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, {24, nullptr, "RecreateApplicationArea"}, }; @@ -295,7 +295,7 @@ private: rb.Push(ErrCodes::ERR_NO_APPLICATION_AREA); } - void GetApplicationAreaSize(Kernel::HLERequestContext& ctx) { + void GetApplicationArea2(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_NFP, "(STUBBED) called"); // We don't need to worry about this since we can just open the file IPC::ResponseBuilder rb{ctx, 3}; diff --git a/src/core/hle/service/nim/nim.cpp b/src/core/hle/service/nim/nim.cpp index f19affce7..16d304874 100644 --- a/src/core/hle/service/nim/nim.cpp +++ b/src/core/hle/service/nim/nim.cpp @@ -121,11 +121,83 @@ public: {39, nullptr, "PrepareShutdown"}, {40, nullptr, "ListApplyDeltaTask"}, {41, nullptr, "ClearNotEnoughSpaceStateOfApplyDeltaTask"}, - {42, nullptr, "Unknown1"}, - {43, nullptr, "Unknown2"}, - {44, nullptr, "Unknown3"}, - {45, nullptr, "Unknown4"}, - {46, nullptr, "Unknown5"}, + {42, nullptr, "Unknown42"}, + {43, nullptr, "Unknown42"}, + {44, nullptr, "Unknown44"}, + {45, nullptr, "Unknown45"}, + {46, nullptr, "Unknown46"}, + {47, nullptr, "Unknown47"}, + {48, nullptr, "Unknown48"}, + {49, nullptr, "Unknown49"}, + {50, nullptr, "Unknown50"}, + {51, nullptr, "Unknown51"}, + {52, nullptr, "Unknown52"}, + {53, nullptr, "Unknown53"}, + {54, nullptr, "Unknown54"}, + {55, nullptr, "Unknown55"}, + {56, nullptr, "Unknown56"}, + {57, nullptr, "Unknown57"}, + {58, nullptr, "Unknown58"}, + {59, nullptr, "Unknown59"}, + {60, nullptr, "Unknown60"}, + {61, nullptr, "Unknown61"}, + {62, nullptr, "Unknown62"}, + {63, nullptr, "Unknown63"}, + {64, nullptr, "Unknown64"}, + {65, nullptr, "Unknown65"}, + {66, nullptr, "Unknown66"}, + {67, nullptr, "Unknown67"}, + {68, nullptr, "Unknown68"}, + {69, nullptr, "Unknown69"}, + {70, nullptr, "Unknown70"}, + {71, nullptr, "Unknown71"}, + {72, nullptr, "Unknown72"}, + {73, nullptr, "Unknown73"}, + {74, nullptr, "Unknown74"}, + {75, nullptr, "Unknown75"}, + {76, nullptr, "Unknown76"}, + {77, nullptr, "Unknown77"}, + {78, nullptr, "Unknown78"}, + {79, nullptr, "Unknown79"}, + {80, nullptr, "Unknown80"}, + {81, nullptr, "Unknown81"}, + {82, nullptr, "Unknown82"}, + {83, nullptr, "Unknown83"}, + {84, nullptr, "Unknown84"}, + {85, nullptr, "Unknown85"}, + {86, nullptr, "Unknown86"}, + {87, nullptr, "Unknown87"}, + {88, nullptr, "Unknown88"}, + {89, nullptr, "Unknown89"}, + {90, nullptr, "Unknown90"}, + {91, nullptr, "Unknown91"}, + {92, nullptr, "Unknown92"}, + {93, nullptr, "Unknown93"}, + {94, nullptr, "Unknown94"}, + {95, nullptr, "Unknown95"}, + {96, nullptr, "Unknown96"}, + {97, nullptr, "Unknown97"}, + {98, nullptr, "Unknown98"}, + {99, nullptr, "Unknown99"}, + {100, nullptr, "Unknown100"}, + {101, nullptr, "Unknown101"}, + {102, nullptr, "Unknown102"}, + {103, nullptr, "Unknown103"}, + {104, nullptr, "Unknown104"}, + {105, nullptr, "Unknown105"}, + {106, nullptr, "Unknown106"}, + {107, nullptr, "Unknown107"}, + {108, nullptr, "Unknown108"}, + {109, nullptr, "Unknown109"}, + {110, nullptr, "Unknown110"}, + {111, nullptr, "Unknown111"}, + {112, nullptr, "Unknown112"}, + {113, nullptr, "Unknown113"}, + {114, nullptr, "Unknown114"}, + {115, nullptr, "Unknown115"}, + {116, nullptr, "Unknown116"}, + {117, nullptr, "Unknown117"}, + {118, nullptr, "Unknown118"}, }; // clang-format on @@ -142,6 +214,7 @@ public: {1, nullptr, "RefreshDebugAvailability"}, {2, nullptr, "ClearDebugResponse"}, {3, nullptr, "RegisterDebugResponse"}, + {4, nullptr, "IsLargeResourceAvailable"}, }; // clang-format on @@ -164,6 +237,8 @@ public: static const FunctionInfo functions[] = { {0, nullptr, "RequestDeviceAuthenticationToken"}, {1, nullptr, "RequestCachedDeviceAuthenticationToken"}, + {2, nullptr, "RequestEdgeToken"}, + {3, nullptr, "RequestCachedEdgeToken"}, {100, nullptr, "RequestRegisterDeviceAccount"}, {101, nullptr, "RequestUnregisterDeviceAccount"}, {102, nullptr, "RequestDeviceAccountStatus"}, @@ -181,7 +256,8 @@ public: {305, nullptr, "RequestCreateVirtualAccount"}, {306, nullptr, "RequestDeviceLinkStatus"}, {400, nullptr, "GetAccountByVirtualAccount"}, - {500, nullptr, "RequestSyncTicket"}, + {401, nullptr, "GetVirtualAccount"}, + {500, nullptr, "RequestSyncTicketLegacy"}, {501, nullptr, "RequestDownloadTicket"}, {502, nullptr, "RequestDownloadTicketForPrepurchasedContents"}, {503, nullptr, "RequestSyncTicket"}, diff --git a/src/core/hle/service/npns/npns.cpp b/src/core/hle/service/npns/npns.cpp index f38d01084..8fa16fb08 100644 --- a/src/core/hle/service/npns/npns.cpp +++ b/src/core/hle/service/npns/npns.cpp @@ -30,6 +30,7 @@ public: {23, nullptr, "DestroyToken"}, {24, nullptr, "DestroyTokenWithApplicationId"}, {25, nullptr, "QueryIsTokenValid"}, + {26, nullptr, "ListenToMyApplicationId"}, {31, nullptr, "UploadTokenToBaaS"}, {32, nullptr, "DestroyTokenForBaaS"}, {33, nullptr, "CreateTokenForBaaS"}, diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 7e5ceccdb..80b7062d5 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -104,7 +104,7 @@ IApplicationManagerInterface::IApplicationManagerInterface() {94, nullptr, "LaunchApplication"}, {95, nullptr, "GetApplicationLaunchInfo"}, {96, nullptr, "AcquireApplicationLaunchInfo"}, - {97, nullptr, "GetMainApplicationProgramIndex2"}, + {97, nullptr, "GetMainApplicationProgramIndexByApplicationLaunchInfo"}, {98, nullptr, "EnableApplicationAllThreadDumpOnCrash"}, {99, nullptr, "LaunchDevMenu"}, {100, nullptr, "ResetToFactorySettings"}, @@ -254,7 +254,7 @@ IApplicationManagerInterface::IApplicationManagerInterface() {2170, nullptr, "GetRightsEnvironmentStatus"}, {2171, nullptr, "GetRightsEnvironmentStatusChangedEvent"}, {2180, nullptr, "RequestExtendRightsInRightsEnvironment"}, - {2181, nullptr, "GetLastResultOfExtendRightsInRightsEnvironment"}, + {2181, nullptr, "GetResultOfExtendRightsInRightsEnvironment"}, {2182, nullptr, "SetActiveRightsContextUsingStateToRightsEnvironment"}, {2190, nullptr, "GetRightsEnvironmentHandleForApplication"}, {2199, nullptr, "GetRightsEnvironmentCountForDebug"}, @@ -445,8 +445,8 @@ IApplicationVersionInterface::IApplicationVersionInterface() IApplicationVersionInterface::~IApplicationVersionInterface() = default; -IContentManagerInterface::IContentManagerInterface() - : ServiceFramework{"IContentManagerInterface"} { +IContentManagementInterface::IContentManagementInterface() + : ServiceFramework{"IContentManagementInterface"} { // clang-format off static const FunctionInfo functions[] = { {11, nullptr, "CalculateApplicationOccupiedSize"}, @@ -463,7 +463,7 @@ IContentManagerInterface::IContentManagerInterface() RegisterHandlers(functions); } -IContentManagerInterface::~IContentManagerInterface() = default; +IContentManagementInterface::~IContentManagementInterface() = default; IDocumentInterface::IDocumentInterface() : ServiceFramework{"IDocumentInterface"} { // clang-format off @@ -545,7 +545,7 @@ NS::NS(const char* name) : ServiceFramework{name} { {7995, &NS::PushInterface, "GetAccountProxyInterface"}, {7996, &NS::PushInterface, "GetApplicationManagerInterface"}, {7997, &NS::PushInterface, "GetDownloadTaskInterface"}, - {7998, &NS::PushInterface, "GetContentManagementInterface"}, + {7998, &NS::PushInterface, "GetContentManagementInterface"}, {7999, &NS::PushInterface, "GetDocumentInterface"}, }; // clang-format on @@ -567,14 +567,14 @@ public: {0, nullptr, "LaunchProgram"}, {1, nullptr, "TerminateProcess"}, {2, nullptr, "TerminateProgram"}, - {4, nullptr, "GetShellEventHandle"}, + {4, nullptr, "GetShellEvent"}, {5, nullptr, "GetShellEventInfo"}, {6, nullptr, "TerminateApplication"}, {7, nullptr, "PrepareLaunchProgramFromHost"}, - {8, nullptr, "LaunchApplication"}, - {9, nullptr, "LaunchApplicationWithStorageId"}, - {10, nullptr, "TerminateApplication2"}, - {11, nullptr, "GetRunningApplicationProcessId"}, + {8, nullptr, "LaunchApplicationFromHost"}, + {9, nullptr, "LaunchApplicationWithStorageIdForDevelop"}, + {10, nullptr, "IsSystemMemoryResourceLimitBoosted"}, + {11, nullptr, "GetRunningApplicationProcessIdForDevelop"}, {12, nullptr, "SetCurrentApplicationRightsEnvironmentCanBeActive"}, {13, nullptr, "CreateApplicationResourceForDevelop"}, {14, nullptr, "IsPreomiaForDevelop"}, @@ -636,6 +636,10 @@ public: {9, nullptr, "GetSystemUpdateNotificationEventForContentDelivery"}, {10, nullptr, "NotifySystemUpdateForContentDelivery"}, {11, nullptr, "PrepareShutdown"}, + {12, nullptr, "Unknown12"}, + {13, nullptr, "Unknown13"}, + {14, nullptr, "Unknown14"}, + {15, nullptr, "Unknown15"}, {16, nullptr, "DestroySystemUpdateTask"}, {17, nullptr, "RequestSendSystemUpdate"}, {18, nullptr, "GetSendSystemUpdateProgress"}, diff --git a/src/core/hle/service/ns/ns.h b/src/core/hle/service/ns/ns.h index 13a64ad88..c2554b878 100644 --- a/src/core/hle/service/ns/ns.h +++ b/src/core/hle/service/ns/ns.h @@ -40,10 +40,10 @@ public: ~IApplicationVersionInterface() override; }; -class IContentManagerInterface final : public ServiceFramework { +class IContentManagementInterface final : public ServiceFramework { public: - explicit IContentManagerInterface(); - ~IContentManagerInterface() override; + explicit IContentManagementInterface(); + ~IContentManagementInterface() override; }; class IDocumentInterface final : public ServiceFramework { diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp index 6efdf1606..40838a225 100644 --- a/src/core/hle/service/ns/pl_u.cpp +++ b/src/core/hle/service/ns/pl_u.cpp @@ -163,7 +163,7 @@ PL_U::PL_U(Core::System& system) {5, &PL_U::GetSharedFontInOrderOfPriority, "GetSharedFontInOrderOfPriority"}, {6, nullptr, "GetSharedFontInOrderOfPriorityForSystem"}, {100, nullptr, "RequestApplicationFunctionAuthorization"}, - {101, nullptr, "RequestApplicationFunctionAuthorizationForSystem"}, + {101, nullptr, "RequestApplicationFunctionAuthorizationByProcessId"}, {102, nullptr, "RequestApplicationFunctionAuthorizationByApplicationId"}, {1000, nullptr, "LoadNgWordDataForPlatformRegionChina"}, {1001, nullptr, "GetNgWordDataSizeForPlatformRegionChina"}, diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp index c8ea6c661..deaf0808b 100644 --- a/src/core/hle/service/nvdrv/interface.cpp +++ b/src/core/hle/service/nvdrv/interface.cpp @@ -144,7 +144,7 @@ void NVDRV::QueryEvent(Kernel::HLERequestContext& ctx) { } } -void NVDRV::SetClientPID(Kernel::HLERequestContext& ctx) { +void NVDRV::SetAruid(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; pid = rp.Pop(); LOG_WARNING(Service_NVDRV, "(STUBBED) called, pid=0x{:X}", pid); @@ -154,7 +154,7 @@ void NVDRV::SetClientPID(Kernel::HLERequestContext& ctx) { rb.Push(0); } -void NVDRV::FinishInitialize(Kernel::HLERequestContext& ctx) { +void NVDRV::SetGraphicsFirmwareMemoryMarginEnabled(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_NVDRV, "(STUBBED) called"); IPC::ResponseBuilder rb{ctx, 2}; @@ -187,13 +187,14 @@ NVDRV::NVDRV(std::shared_ptr nvdrv, const char* name) {4, &NVDRV::QueryEvent, "QueryEvent"}, {5, nullptr, "MapSharedMem"}, {6, &NVDRV::GetStatus, "GetStatus"}, - {7, nullptr, "ForceSetClientPID"}, - {8, &NVDRV::SetClientPID, "SetClientPID"}, + {7, nullptr, "SetAruidForTest"}, + {8, &NVDRV::SetAruid, "SetAruid"}, {9, &NVDRV::DumpGraphicsMemoryInfo, "DumpGraphicsMemoryInfo"}, {10, nullptr, "InitializeDevtools"}, {11, &NVDRV::Ioctl2, "Ioctl2"}, {12, &NVDRV::Ioctl3, "Ioctl3"}, - {13, &NVDRV::FinishInitialize, "FinishInitialize"}, + {13, &NVDRV::SetGraphicsFirmwareMemoryMarginEnabled, + "SetGraphicsFirmwareMemoryMarginEnabled"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/nvdrv/interface.h b/src/core/hle/service/nvdrv/interface.h index 9269ce00c..72e17a728 100644 --- a/src/core/hle/service/nvdrv/interface.h +++ b/src/core/hle/service/nvdrv/interface.h @@ -29,8 +29,8 @@ private: void Close(Kernel::HLERequestContext& ctx); void Initialize(Kernel::HLERequestContext& ctx); void QueryEvent(Kernel::HLERequestContext& ctx); - void SetClientPID(Kernel::HLERequestContext& ctx); - void FinishInitialize(Kernel::HLERequestContext& ctx); + void SetAruid(Kernel::HLERequestContext& ctx); + void SetGraphicsFirmwareMemoryMarginEnabled(Kernel::HLERequestContext& ctx); void GetStatus(Kernel::HLERequestContext& ctx); void DumpGraphicsMemoryInfo(Kernel::HLERequestContext& ctx); void IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version); diff --git a/src/core/hle/service/nvdrv/nvmemp.cpp b/src/core/hle/service/nvdrv/nvmemp.cpp index b7b8b7a1b..73b37e805 100644 --- a/src/core/hle/service/nvdrv/nvmemp.cpp +++ b/src/core/hle/service/nvdrv/nvmemp.cpp @@ -10,19 +10,19 @@ namespace Service::Nvidia { NVMEMP::NVMEMP() : ServiceFramework("nvmemp") { static const FunctionInfo functions[] = { - {0, &NVMEMP::Cmd0, "Cmd0"}, - {1, &NVMEMP::Cmd1, "Cmd1"}, + {0, &NVMEMP::Open, "Open"}, + {1, &NVMEMP::GetAruid, "GetAruid"}, }; RegisterHandlers(functions); } NVMEMP::~NVMEMP() = default; -void NVMEMP::Cmd0(Kernel::HLERequestContext& ctx) { +void NVMEMP::Open(Kernel::HLERequestContext& ctx) { UNIMPLEMENTED(); } -void NVMEMP::Cmd1(Kernel::HLERequestContext& ctx) { +void NVMEMP::GetAruid(Kernel::HLERequestContext& ctx) { UNIMPLEMENTED(); } diff --git a/src/core/hle/service/nvdrv/nvmemp.h b/src/core/hle/service/nvdrv/nvmemp.h index 6eafb1346..c453ee4db 100644 --- a/src/core/hle/service/nvdrv/nvmemp.h +++ b/src/core/hle/service/nvdrv/nvmemp.h @@ -14,8 +14,8 @@ public: ~NVMEMP() override; private: - void Cmd0(Kernel::HLERequestContext& ctx); - void Cmd1(Kernel::HLERequestContext& ctx); + void Open(Kernel::HLERequestContext& ctx); + void GetAruid(Kernel::HLERequestContext& ctx); }; } // namespace Service::Nvidia diff --git a/src/core/hle/service/pcie/pcie.cpp b/src/core/hle/service/pcie/pcie.cpp index 39cf05eba..c568a0adc 100644 --- a/src/core/hle/service/pcie/pcie.cpp +++ b/src/core/hle/service/pcie/pcie.cpp @@ -36,6 +36,9 @@ public: {18, nullptr, "ReleaseIrq"}, {19, nullptr, "SetIrqEnable"}, {20, nullptr, "SetAspmEnable"}, + {21, nullptr, "SetResetUponResumeEnable"}, + {22, nullptr, "Unknown22"}, + {23, nullptr, "Unknown23"}, }; // clang-format on diff --git a/src/core/hle/service/pcv/pcv.cpp b/src/core/hle/service/pcv/pcv.cpp index d6891a659..8bfc0276e 100644 --- a/src/core/hle/service/pcv/pcv.cpp +++ b/src/core/hle/service/pcv/pcv.cpp @@ -42,6 +42,9 @@ public: {24, nullptr, "GetModuleStateTable"}, {25, nullptr, "GetPowerDomainStateTable"}, {26, nullptr, "GetFuseInfo"}, + {27, nullptr, "GetDramId"}, + {28, nullptr, "IsPoweredOn"}, + {29, nullptr, "GetVoltage"}, }; // clang-format on diff --git a/src/core/hle/service/pm/pm.cpp b/src/core/hle/service/pm/pm.cpp index 809eca0ab..f43122ad2 100644 --- a/src/core/hle/service/pm/pm.cpp +++ b/src/core/hle/service/pm/pm.cpp @@ -78,13 +78,13 @@ public: : ServiceFramework{"pm:dmnt"}, kernel(kernel) { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "GetDebugProcesses"}, - {1, nullptr, "StartDebugProcess"}, - {2, &DebugMonitor::GetTitlePid, "GetTitlePid"}, - {3, nullptr, "EnableDebugForTitleId"}, - {4, &DebugMonitor::GetApplicationPid, "GetApplicationPid"}, - {5, nullptr, "EnableDebugForApplication"}, - {6, nullptr, "DisableDebug"}, + {0, nullptr, "GetJitDebugProcessIdList"}, + {1, nullptr, "StartProcess"}, + {2, &DebugMonitor::GetProcessId, "GetProcessId"}, + {3, nullptr, "HookToCreateProcess"}, + {4, &DebugMonitor::GetApplicationProcessId, "GetApplicationProcessId"}, + {5, nullptr, "HookToCreateApplicationProgress"}, + {6, nullptr, "ClearHook"}, }; // clang-format on @@ -92,7 +92,7 @@ public: } private: - void GetTitlePid(Kernel::HLERequestContext& ctx) { + void GetProcessId(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; const auto title_id = rp.PopRaw(); @@ -114,7 +114,7 @@ private: rb.Push((*process)->GetProcessID()); } - void GetApplicationPid(Kernel::HLERequestContext& ctx) { + void GetApplicationProcessId(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_PM, "called"); GetApplicationPidGeneric(ctx, kernel.GetProcessList()); } @@ -163,15 +163,15 @@ public: : ServiceFramework{"pm:shell"}, kernel(kernel) { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "LaunchProcess"}, - {1, nullptr, "TerminateProcessByPid"}, - {2, nullptr, "TerminateProcessByTitleId"}, - {3, nullptr, "GetProcessEventWaiter"}, - {4, nullptr, "GetProcessEventType"}, + {0, nullptr, "LaunchProgram"}, + {1, nullptr, "TerminateProcess"}, + {2, nullptr, "TerminateProgram"}, + {3, nullptr, "GetProcessEventHandle"}, + {4, nullptr, "GetProcessEventInfo"}, {5, nullptr, "NotifyBootFinished"}, - {6, &Shell::GetApplicationPid, "GetApplicationPid"}, + {6, &Shell::GetApplicationProcessIdForShell, "GetApplicationProcessIdForShell"}, {7, nullptr, "BoostSystemMemoryResourceLimit"}, - {8, nullptr, "EnableAdditionalSystemThreads"}, + {8, nullptr, "BoostApplicationThreadResourceLimit"}, {9, nullptr, "GetBootFinishedEventHandle"}, }; // clang-format on @@ -180,7 +180,7 @@ public: } private: - void GetApplicationPid(Kernel::HLERequestContext& ctx) { + void GetApplicationProcessIdForShell(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_PM, "called"); GetApplicationPidGeneric(ctx, kernel.GetProcessList()); } diff --git a/src/core/hle/service/prepo/prepo.cpp b/src/core/hle/service/prepo/prepo.cpp index 14309c679..9d36ea0d0 100644 --- a/src/core/hle/service/prepo/prepo.cpp +++ b/src/core/hle/service/prepo/prepo.cpp @@ -42,6 +42,11 @@ public: {40101, nullptr, "SetUserAgreementCheckEnabled"}, {50100, nullptr, "ReadAllApplicationReportFiles"}, {90100, nullptr, "ReadAllReportFiles"}, + {90101, nullptr, "Unknown90101"}, + {90102, nullptr, "Unknown90102"}, + {90200, nullptr, "GetStatistics"}, + {90201, nullptr, "GetThroughputHistory"}, + {90300, nullptr, "GetLastUploadError"}, }; // clang-format on diff --git a/src/core/hle/service/psc/psc.cpp b/src/core/hle/service/psc/psc.cpp index 53ec6b031..99e1c9042 100644 --- a/src/core/hle/service/psc/psc.cpp +++ b/src/core/hle/service/psc/psc.cpp @@ -24,6 +24,8 @@ public: {4, nullptr, "Cancel"}, {5, nullptr, "PrintModuleInformation"}, {6, nullptr, "GetModuleInformation"}, + {10, nullptr, "Unknown10"}, + {11, nullptr, "Unknown11"}, }; // clang-format on diff --git a/src/core/hle/service/ptm/psm.cpp b/src/core/hle/service/ptm/psm.cpp index 12d154ecf..6d9e6bd09 100644 --- a/src/core/hle/service/ptm/psm.cpp +++ b/src/core/hle/service/ptm/psm.cpp @@ -35,6 +35,7 @@ public: {15, nullptr, "GetBatteryAgePercentage"}, {16, nullptr, "GetBatteryChargeInfoEvent"}, {17, nullptr, "GetBatteryChargeInfoFields"}, + {18, nullptr, "GetBatteryChargeCalibratedEvent"}, }; // clang-format on diff --git a/src/core/hle/service/sm/controller.cpp b/src/core/hle/service/sm/controller.cpp index 9cca84b31..25ab667f3 100644 --- a/src/core/hle/service/sm/controller.cpp +++ b/src/core/hle/service/sm/controller.cpp @@ -12,7 +12,7 @@ namespace Service::SM { -void Controller::ConvertSessionToDomain(Kernel::HLERequestContext& ctx) { +void Controller::ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx) { ASSERT_MSG(ctx.Session()->IsSession(), "Session is already a domain"); LOG_DEBUG(Service, "called, server_session={}", ctx.Session()->GetObjectId()); ctx.Session()->ConvertToDomain(); @@ -22,7 +22,7 @@ void Controller::ConvertSessionToDomain(Kernel::HLERequestContext& ctx) { rb.Push(1); // Converted sessions start with 1 request handler } -void Controller::DuplicateSession(Kernel::HLERequestContext& ctx) { +void Controller::CloneCurrentObject(Kernel::HLERequestContext& ctx) { // TODO(bunnei): This is just creating a new handle to the same Session. I assume this is wrong // and that we probably want to actually make an entirely new Session, but we still need to // verify this on hardware. @@ -33,10 +33,10 @@ void Controller::DuplicateSession(Kernel::HLERequestContext& ctx) { rb.PushMoveObjects(ctx.Session()->GetParent()->Client()); } -void Controller::DuplicateSessionEx(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service, "(STUBBED) called, using DuplicateSession"); +void Controller::CloneCurrentObjectEx(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service, "(STUBBED) called, using CloneCurrentObject"); - DuplicateSession(ctx); + CloneCurrentObject(ctx); } void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) { @@ -47,13 +47,14 @@ void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) { rb.Push(0x1000); } +// https://switchbrew.org/wiki/IPC_Marshalling Controller::Controller() : ServiceFramework("IpcController") { static const FunctionInfo functions[] = { - {0x00000000, &Controller::ConvertSessionToDomain, "ConvertSessionToDomain"}, - {0x00000001, nullptr, "ConvertDomainToSession"}, - {0x00000002, &Controller::DuplicateSession, "DuplicateSession"}, + {0x00000000, &Controller::ConvertCurrentObjectToDomain, "ConvertCurrentObjectToDomain"}, + {0x00000001, nullptr, "CopyFromCurrentDomain"}, + {0x00000002, &Controller::CloneCurrentObject, "CloneCurrentObject"}, {0x00000003, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"}, - {0x00000004, &Controller::DuplicateSessionEx, "DuplicateSessionEx"}, + {0x00000004, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/sm/controller.h b/src/core/hle/service/sm/controller.h index dc66c9e37..180c6da50 100644 --- a/src/core/hle/service/sm/controller.h +++ b/src/core/hle/service/sm/controller.h @@ -14,9 +14,9 @@ public: ~Controller() override; private: - void ConvertSessionToDomain(Kernel::HLERequestContext& ctx); - void DuplicateSession(Kernel::HLERequestContext& ctx); - void DuplicateSessionEx(Kernel::HLERequestContext& ctx); + void ConvertCurrentObjectToDomain(Kernel::HLERequestContext& ctx); + void CloneCurrentObject(Kernel::HLERequestContext& ctx); + void CloneCurrentObjectEx(Kernel::HLERequestContext& ctx); void QueryPointerBufferSize(Kernel::HLERequestContext& ctx); }; diff --git a/src/core/hle/service/sockets/nsd.cpp b/src/core/hle/service/sockets/nsd.cpp index dc70fd6fe..40d781124 100644 --- a/src/core/hle/service/sockets/nsd.cpp +++ b/src/core/hle/service/sockets/nsd.cpp @@ -14,6 +14,7 @@ NSD::NSD(const char* name) : ServiceFramework(name) { {12, nullptr, "GetDeviceId"}, {13, nullptr, "DeleteSettings"}, {14, nullptr, "ImportSettings"}, + {15, nullptr, "SetChangeEnvironmentIdentifierDisabled"}, {20, nullptr, "Resolve"}, {21, nullptr, "ResolveEx"}, {30, nullptr, "GetNasServiceSetting"}, @@ -28,6 +29,11 @@ NSD::NSD(const char* name) : ServiceFramework(name) { {60, nullptr, "ReadSaveDataFromFsForTest"}, {61, nullptr, "WriteSaveDataToFsForTest"}, {62, nullptr, "DeleteSaveDataOfFsForTest"}, + {63, nullptr, "IsChangeEnvironmentIdentifierDisabled"}, + {64, nullptr, "SetWithoutDomainExchangeFqdns"}, + {100, nullptr, "GetApplicationServerEnvironmentType"}, + {101, nullptr, "SetApplicationServerEnvironmentType"}, + {102, nullptr, "DeleteApplicationServerEnvironmentType"}, }; // clang-format on diff --git a/src/core/hle/service/sockets/sfdnsres.cpp b/src/core/hle/service/sockets/sfdnsres.cpp index 852e71e4b..e3017451f 100644 --- a/src/core/hle/service/sockets/sfdnsres.cpp +++ b/src/core/hle/service/sockets/sfdnsres.cpp @@ -7,7 +7,7 @@ namespace Service::Sockets { -void SFDNSRES::GetAddrInfo(Kernel::HLERequestContext& ctx) { +void SFDNSRES::GetAddrInfoRequest(Kernel::HLERequestContext& ctx) { struct Parameters { u8 use_nsd_resolve; u32 unknown; @@ -29,15 +29,20 @@ SFDNSRES::SFDNSRES() : ServiceFramework("sfdnsres") { static const FunctionInfo functions[] = { {0, nullptr, "SetDnsAddressesPrivate"}, {1, nullptr, "GetDnsAddressPrivate"}, - {2, nullptr, "GetHostByName"}, - {3, nullptr, "GetHostByAddr"}, - {4, nullptr, "GetHostStringError"}, - {5, nullptr, "GetGaiStringError"}, - {6, &SFDNSRES::GetAddrInfo, "GetAddrInfo"}, - {7, nullptr, "GetNameInfo"}, - {8, nullptr, "RequestCancelHandle"}, - {9, nullptr, "CancelSocketCall"}, - {11, nullptr, "ClearDnsIpServerAddressArray"}, + {2, nullptr, "GetHostByNameRequest"}, + {3, nullptr, "GetHostByAddrRequest"}, + {4, nullptr, "GetHostStringErrorRequest"}, + {5, nullptr, "GetGaiStringErrorRequest"}, + {6, &SFDNSRES::GetAddrInfoRequest, "GetAddrInfoRequest"}, + {7, nullptr, "GetNameInfoRequest"}, + {8, nullptr, "RequestCancelHandleRequest"}, + {9, nullptr, "CancelRequest"}, + {10, nullptr, "GetHostByNameRequestWithOptions"}, + {11, nullptr, "GetHostByAddrRequestWithOptions"}, + {12, nullptr, "GetAddrInfoRequestWithOptions"}, + {13, nullptr, "GetNameInfoRequestWithOptions"}, + {14, nullptr, "ResolverSetOptionRequest"}, + {15, nullptr, "ResolverGetOptionRequest"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/sockets/sfdnsres.h b/src/core/hle/service/sockets/sfdnsres.h index eda432903..acd3647bb 100644 --- a/src/core/hle/service/sockets/sfdnsres.h +++ b/src/core/hle/service/sockets/sfdnsres.h @@ -15,7 +15,7 @@ public: ~SFDNSRES() override; private: - void GetAddrInfo(Kernel::HLERequestContext& ctx); + void GetAddrInfoRequest(Kernel::HLERequestContext& ctx); }; } // namespace Service::Sockets diff --git a/src/core/hle/service/spl/spl.cpp b/src/core/hle/service/spl/spl.cpp index 70cb41905..6caab8929 100644 --- a/src/core/hle/service/spl/spl.cpp +++ b/src/core/hle/service/spl/spl.cpp @@ -9,35 +9,36 @@ namespace Service::SPL { SPL::SPL(std::shared_ptr module) : Module::Interface(std::move(module), "spl:") { static const FunctionInfo functions[] = { {0, nullptr, "GetConfig"}, - {1, nullptr, "UserExpMod"}, + {1, nullptr, "ModularExponentiate"}, {2, nullptr, "GenerateAesKek"}, {3, nullptr, "LoadAesKey"}, {4, nullptr, "GenerateAesKey"}, {5, nullptr, "SetConfig"}, {7, &SPL::GetRandomBytes, "GetRandomBytes"}, - {9, nullptr, "LoadSecureExpModKey"}, - {10, nullptr, "SecureExpMod"}, + {9, nullptr, "ImportLotusKey"}, + {10, nullptr, "DecryptLotusMessage"}, {11, nullptr, "IsDevelopment"}, {12, nullptr, "GenerateSpecificAesKey"}, - {13, nullptr, "DecryptPrivk"}, + {13, nullptr, "DecryptDeviceUniqueData"}, {14, nullptr, "DecryptAesKey"}, - {15, nullptr, "DecryptAesCtr"}, + {15, nullptr, "CryptAesCtr"}, {16, nullptr, "ComputeCmac"}, - {17, nullptr, "LoadRsaOaepKey"}, - {18, nullptr, "UnwrapRsaOaepWrappedTitleKey"}, + {17, nullptr, "ImportEsKey"}, + {18, nullptr, "UnwrapTitleKey"}, {19, nullptr, "LoadTitleKey"}, - {20, nullptr, "UnwrapAesWrappedTitleKey"}, - {21, nullptr, "LockAesEngine"}, - {22, nullptr, "UnlockAesEngine"}, - {23, nullptr, "GetSplWaitEvent"}, - {24, nullptr, "SetSharedData"}, - {25, nullptr, "GetSharedData"}, - {26, nullptr, "ImportSslRsaKey"}, - {27, nullptr, "SecureExpModWithSslKey"}, - {28, nullptr, "ImportEsRsaKey"}, - {29, nullptr, "SecureExpModWithEsKey"}, - {30, nullptr, "EncryptManuRsaKeyForImport"}, - {31, nullptr, "GetPackage2Hash"}, + {20, nullptr, "PrepareEsCommonKey"}, + {21, nullptr, "AllocateAesKeyslot"}, + {22, nullptr, "DeallocateAesKeySlot"}, + {23, nullptr, "GetAesKeyslotAvailableEvent"}, + {24, nullptr, "SetBootReason"}, + {25, nullptr, "GetBootReason"}, + {26, nullptr, "DecryptAndStoreSslClientCertKey"}, + {27, nullptr, "ModularExponentiateWithSslClientCertKey"}, + {28, nullptr, "DecryptAndStoreDrmDeviceCertKey"}, + {29, nullptr, "ModularExponentiateWithDrmDeviceCertKey"}, + {30, nullptr, "ReencryptDeviceUniqueData "}, + {31, nullptr, "PrepareEsArchiveKey"}, // This is also GetPackage2Hash? + {32, nullptr, "LoadPreparedAesKey"} }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index 67f1bbcf3..cc1dbd575 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp @@ -90,6 +90,13 @@ public: : ServiceFramework("ISteadyClock"), clock_core{clock_core}, system{system} { static const FunctionInfo functions[] = { {0, &ISteadyClock::GetCurrentTimePoint, "GetCurrentTimePoint"}, + {2, nullptr, "GetTestOffset"}, + {3, nullptr, "SetTestOffset"}, + {100, nullptr, "GetRtcValue"}, + {101, nullptr, "IsRtcResetDetected"}, + {102, nullptr, "GetSetupResultValue"}, + {200, nullptr, "GetInternalOffset"}, + {201, nullptr, "SetInternalOffset"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/usb/usb.cpp b/src/core/hle/service/usb/usb.cpp index 58a9845fc..d033f8603 100644 --- a/src/core/hle/service/usb/usb.cpp +++ b/src/core/hle/service/usb/usb.cpp @@ -20,7 +20,7 @@ public: static const FunctionInfo functions[] = { {0, nullptr, "GetDsEndpoint"}, {1, nullptr, "GetSetupEvent"}, - {2, nullptr, "Unknown"}, + {2, nullptr, "Unknown2"}, {3, nullptr, "EnableInterface"}, {4, nullptr, "DisableInterface"}, {5, nullptr, "CtrlInPostBufferAsync"}, @@ -55,6 +55,7 @@ public: {9, nullptr, "SetBinaryObjectStore"}, {10, nullptr, "Enable"}, {11, nullptr, "Disable"}, + {12, nullptr, "Unknown12"}, }; // clang-format on @@ -69,13 +70,13 @@ public: static const FunctionInfo functions[] = { {0, nullptr, "Open"}, {1, nullptr, "Close"}, - {2, nullptr, "Unknown1"}, + {2, nullptr, "Unknown2"}, {3, nullptr, "Populate"}, {4, nullptr, "PostBufferAsync"}, {5, nullptr, "GetXferReport"}, {6, nullptr, "PostBufferMultiAsync"}, - {7, nullptr, "Unknown3"}, - {8, nullptr, "Unknown4"}, + {7, nullptr, "Unknown7"}, + {8, nullptr, "Unknown8"}, }; // clang-format on @@ -88,13 +89,13 @@ public: explicit IClientIfSession() : ServiceFramework{"IClientIfSession"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "Unknown1"}, + {0, nullptr, "Unknown0"}, {1, nullptr, "SetInterface"}, {2, nullptr, "GetInterface"}, {3, nullptr, "GetAlternateInterface"}, {4, nullptr, "GetCurrentFrame"}, {5, nullptr, "CtrlXferAsync"}, - {6, nullptr, "Unknown2"}, + {6, nullptr, "Unknown6"}, {7, nullptr, "GetCtrlXferReport"}, {8, nullptr, "ResetDevice"}, {9, nullptr, "OpenUsbEp"}, @@ -118,7 +119,7 @@ public: {5, nullptr, "DestroyInterfaceAvailableEvent"}, {6, nullptr, "GetInterfaceStateChangeEvent"}, {7, nullptr, "AcquireUsbIf"}, - {8, nullptr, "Unknown1"}, + {8, nullptr, "Unknown8"}, }; // clang-format on @@ -179,8 +180,8 @@ public: {4, nullptr, "GetFwRevision"}, {5, nullptr, "GetManufacturerId"}, {6, nullptr, "GetDeviceId"}, - {7, nullptr, "Unknown1"}, - {8, nullptr, "Unknown2"}, + {7, nullptr, "Unknown7"}, + {8, nullptr, "Unknown8"}, }; // clang-format on @@ -215,12 +216,12 @@ public: explicit USB_PM() : ServiceFramework{"usb:pm"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "Unknown1"}, - {1, nullptr, "Unknown2"}, - {2, nullptr, "Unknown3"}, - {3, nullptr, "Unknown4"}, - {4, nullptr, "Unknown5"}, - {5, nullptr, "Unknown6"}, + {0, nullptr, "Unknown0"}, + {1, nullptr, "Unknown1"}, + {2, nullptr, "Unknown2"}, + {3, nullptr, "Unknown3"}, + {4, nullptr, "Unknown4"}, + {5, nullptr, "Unknown5"}, }; // clang-format on diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 46e14c2a3..67b45e7c0 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -698,6 +698,7 @@ public: {3215, nullptr, "SetDisplayGamma"}, {3216, nullptr, "GetDisplayCmuLuma"}, {3217, nullptr, "SetDisplayCmuLuma"}, + {6013, nullptr, "GetLayerPresentationSubmissionTimestamps"}, {8225, nullptr, "GetSharedBufferMemoryHandleId"}, {8250, nullptr, "OpenSharedLayer"}, {8251, nullptr, "CloseSharedLayer"}, @@ -783,6 +784,7 @@ public: {2300, nullptr, "AcquireLayerTexturePresentingEvent"}, {2301, nullptr, "ReleaseLayerTexturePresentingEvent"}, {2302, nullptr, "GetDisplayHotplugEvent"}, + {2303, nullptr, "GetDisplayModeChangedEvent"}, {2402, nullptr, "GetDisplayHotplugState"}, {2501, nullptr, "GetCompositorErrorInfo"}, {2601, nullptr, "GetDisplayErrorEvent"}, diff --git a/src/core/hle/service/vi/vi_u.cpp b/src/core/hle/service/vi/vi_u.cpp index 9d5ceb608..6b7329345 100644 --- a/src/core/hle/service/vi/vi_u.cpp +++ b/src/core/hle/service/vi/vi_u.cpp @@ -12,6 +12,7 @@ VI_U::VI_U(std::shared_ptr nv_flinger) : ServiceFramework{"vi:u"}, nv_flinger{std::move(nv_flinger)} { static const FunctionInfo functions[] = { {0, &VI_U::GetDisplayService, "GetDisplayService"}, + {1, nullptr, "GetDisplayServiceWithProxyNameExchange"}, }; RegisterHandlers(functions); } diff --git a/src/core/hle/service/wlan/wlan.cpp b/src/core/hle/service/wlan/wlan.cpp index 2654594c1..0260d7dcf 100644 --- a/src/core/hle/service/wlan/wlan.cpp +++ b/src/core/hle/service/wlan/wlan.cpp @@ -15,34 +15,37 @@ public: explicit WLANInfra() : ServiceFramework{"wlan:inf"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "Unknown1"}, - {1, nullptr, "Unknown2"}, + {0, nullptr, "OpenMode"}, + {1, nullptr, "CloseMode"}, {2, nullptr, "GetMacAddress"}, {3, nullptr, "StartScan"}, {4, nullptr, "StopScan"}, {5, nullptr, "Connect"}, {6, nullptr, "CancelConnect"}, {7, nullptr, "Disconnect"}, - {8, nullptr, "Unknown3"}, - {9, nullptr, "Unknown4"}, + {8, nullptr, "GetConnectionEvent"}, + {9, nullptr, "GetConnectionStatus"}, {10, nullptr, "GetState"}, {11, nullptr, "GetScanResult"}, {12, nullptr, "GetRssi"}, {13, nullptr, "ChangeRxAntenna"}, - {14, nullptr, "Unknown5"}, - {15, nullptr, "Unknown6"}, + {14, nullptr, "GetFwVersion"}, + {15, nullptr, "RequestSleep"}, {16, nullptr, "RequestWakeUp"}, {17, nullptr, "RequestIfUpDown"}, - {18, nullptr, "Unknown7"}, - {19, nullptr, "Unknown8"}, - {20, nullptr, "Unknown9"}, - {21, nullptr, "Unknown10"}, - {22, nullptr, "Unknown11"}, - {23, nullptr, "Unknown12"}, - {24, nullptr, "Unknown13"}, - {25, nullptr, "Unknown14"}, - {26, nullptr, "Unknown15"}, - {27, nullptr, "Unknown16"}, + {18, nullptr, "Unknown18"}, + {19, nullptr, "Unknown19"}, + {20, nullptr, "Unknown20"}, + {21, nullptr, "Unknown21"}, + {22, nullptr, "Unknown22"}, + {23, nullptr, "Unknown23"}, + {24, nullptr, "Unknown24"}, + {25, nullptr, "Unknown25"}, + {26, nullptr, "Unknown26"}, + {27, nullptr, "Unknown27"}, + {28, nullptr, "Unknown28"}, + {29, nullptr, "Unknown29"}, + {30, nullptr, "Unknown30"}, }; // clang-format on @@ -55,12 +58,12 @@ public: explicit WLANLocal() : ServiceFramework{"wlan:lcl"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "Unknown1"}, - {1, nullptr, "Unknown2"}, - {2, nullptr, "Unknown3"}, - {3, nullptr, "Unknown4"}, - {4, nullptr, "Unknown5"}, - {5, nullptr, "Unknown6"}, + {0, nullptr, "Unknown0"}, + {1, nullptr, "Unknown1"}, + {2, nullptr, "Unknown2"}, + {3, nullptr, "Unknown3"}, + {4, nullptr, "Unknown4"}, + {5, nullptr, "Unknown5"}, {6, nullptr, "GetMacAddress"}, {7, nullptr, "CreateBss"}, {8, nullptr, "DestroyBss"}, @@ -72,38 +75,42 @@ public: {14, nullptr, "CancelJoin"}, {15, nullptr, "Disconnect"}, {16, nullptr, "SetBeaconLostCount"}, - {17, nullptr, "Unknown7"}, - {18, nullptr, "Unknown8"}, - {19, nullptr, "Unknown9"}, + {17, nullptr, "Unknown17"}, + {18, nullptr, "Unknown18"}, + {19, nullptr, "Unknown19"}, {20, nullptr, "GetBssIndicationEvent"}, {21, nullptr, "GetBssIndicationInfo"}, {22, nullptr, "GetState"}, {23, nullptr, "GetAllowedChannels"}, {24, nullptr, "AddIe"}, {25, nullptr, "DeleteIe"}, - {26, nullptr, "Unknown10"}, - {27, nullptr, "Unknown11"}, + {26, nullptr, "Unknown26"}, + {27, nullptr, "Unknown27"}, {28, nullptr, "CreateRxEntry"}, {29, nullptr, "DeleteRxEntry"}, - {30, nullptr, "Unknown12"}, - {31, nullptr, "Unknown13"}, + {30, nullptr, "Unknown30"}, + {31, nullptr, "Unknown31"}, {32, nullptr, "AddMatchingDataToRxEntry"}, {33, nullptr, "RemoveMatchingDataFromRxEntry"}, {34, nullptr, "GetScanResult"}, - {35, nullptr, "Unknown14"}, + {35, nullptr, "Unknown35"}, {36, nullptr, "SetActionFrameWithBeacon"}, {37, nullptr, "CancelActionFrameWithBeacon"}, {38, nullptr, "CreateRxEntryForActionFrame"}, {39, nullptr, "DeleteRxEntryForActionFrame"}, - {40, nullptr, "Unknown15"}, - {41, nullptr, "Unknown16"}, + {40, nullptr, "Unknown40"}, + {41, nullptr, "Unknown41"}, {42, nullptr, "CancelGetActionFrame"}, {43, nullptr, "GetRssi"}, - {44, nullptr, "Unknown17"}, - {45, nullptr, "Unknown18"}, - {46, nullptr, "Unknown19"}, - {47, nullptr, "Unknown20"}, - {48, nullptr, "Unknown21"}, + {44, nullptr, "Unknown44"}, + {45, nullptr, "Unknown45"}, + {46, nullptr, "Unknown46"}, + {47, nullptr, "Unknown47"}, + {48, nullptr, "Unknown48"}, + {49, nullptr, "Unknown49"}, + {50, nullptr, "Unknown50"}, + {51, nullptr, "Unknown51"}, + {52, nullptr, "Unknown52"}, }; // clang-format on @@ -142,18 +149,19 @@ public: explicit WLANSocketManager() : ServiceFramework{"wlan:soc"} { // clang-format off static const FunctionInfo functions[] = { - {0, nullptr, "Unknown1"}, - {1, nullptr, "Unknown2"}, - {2, nullptr, "Unknown3"}, - {3, nullptr, "Unknown4"}, - {4, nullptr, "Unknown5"}, - {5, nullptr, "Unknown6"}, + {0, nullptr, "Unknown0"}, + {1, nullptr, "Unknown1"}, + {2, nullptr, "Unknown2"}, + {3, nullptr, "Unknown3"}, + {4, nullptr, "Unknown4"}, + {5, nullptr, "Unknown5"}, {6, nullptr, "GetMacAddress"}, {7, nullptr, "SwitchTsfTimerFunction"}, - {8, nullptr, "Unknown7"}, - {9, nullptr, "Unknown8"}, - {10, nullptr, "Unknown9"}, - {11, nullptr, "Unknown10"}, + {8, nullptr, "Unknown8"}, + {9, nullptr, "Unknown9"}, + {10, nullptr, "Unknown10"}, + {11, nullptr, "Unknown11"}, + {12, nullptr, "Unknown12"}, }; // clang-format on From f2eead3b5b6a91a153af126874435ca0e791ef08 Mon Sep 17 00:00:00 2001 From: VolcaEM <63682805+VolcaEM@users.noreply.github.com> Date: Mon, 29 Jun 2020 04:09:38 +0200 Subject: [PATCH 03/55] Clang-format --- src/core/hle/service/spl/spl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/spl/spl.cpp b/src/core/hle/service/spl/spl.cpp index 6caab8929..773551464 100644 --- a/src/core/hle/service/spl/spl.cpp +++ b/src/core/hle/service/spl/spl.cpp @@ -38,7 +38,7 @@ SPL::SPL(std::shared_ptr module) : Module::Interface(std::move(module), {29, nullptr, "ModularExponentiateWithDrmDeviceCertKey"}, {30, nullptr, "ReencryptDeviceUniqueData "}, {31, nullptr, "PrepareEsArchiveKey"}, // This is also GetPackage2Hash? - {32, nullptr, "LoadPreparedAesKey"} + {32, nullptr, "LoadPreparedAesKey"}, }; RegisterHandlers(functions); } From a0c499aef7d2739e179ae9a03c53c3f07898d38f Mon Sep 17 00:00:00 2001 From: VolcaEM <63682805+VolcaEM@users.noreply.github.com> Date: Mon, 29 Jun 2020 04:12:36 +0200 Subject: [PATCH 04/55] Fix typo --- src/core/hle/service/nim/nim.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/hle/service/nim/nim.cpp b/src/core/hle/service/nim/nim.cpp index 16d304874..11aa74828 100644 --- a/src/core/hle/service/nim/nim.cpp +++ b/src/core/hle/service/nim/nim.cpp @@ -122,7 +122,7 @@ public: {40, nullptr, "ListApplyDeltaTask"}, {41, nullptr, "ClearNotEnoughSpaceStateOfApplyDeltaTask"}, {42, nullptr, "Unknown42"}, - {43, nullptr, "Unknown42"}, + {43, nullptr, "Unknown43"}, {44, nullptr, "Unknown44"}, {45, nullptr, "Unknown45"}, {46, nullptr, "Unknown46"}, From f3630a07133d9f40860da0c54b664759f83d14ac Mon Sep 17 00:00:00 2001 From: VolcaEM <63682805+VolcaEM@users.noreply.github.com> Date: Mon, 29 Jun 2020 04:21:10 +0200 Subject: [PATCH 05/55] Use decimal instead of hexadecimal Co-authored-by: David <25727384+ogniK5377@users.noreply.github.com> --- src/core/hle/service/sm/controller.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/hle/service/sm/controller.cpp b/src/core/hle/service/sm/controller.cpp index 25ab667f3..cccccc30a 100644 --- a/src/core/hle/service/sm/controller.cpp +++ b/src/core/hle/service/sm/controller.cpp @@ -50,9 +50,11 @@ void Controller::QueryPointerBufferSize(Kernel::HLERequestContext& ctx) { // https://switchbrew.org/wiki/IPC_Marshalling Controller::Controller() : ServiceFramework("IpcController") { static const FunctionInfo functions[] = { - {0x00000000, &Controller::ConvertCurrentObjectToDomain, "ConvertCurrentObjectToDomain"}, - {0x00000001, nullptr, "CopyFromCurrentDomain"}, - {0x00000002, &Controller::CloneCurrentObject, "CloneCurrentObject"}, + {0, &Controller::ConvertCurrentObjectToDomain, "ConvertCurrentObjectToDomain"}, + {1, nullptr, "CopyFromCurrentDomain"}, + {2, &Controller::CloneCurrentObject, "CloneCurrentObject"}, + {3, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"}, + {4, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"}, {0x00000003, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"}, {0x00000004, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"}, }; From 86946ea13c4883672cf62f13c6d2a43ff5c2f352 Mon Sep 17 00:00:00 2001 From: VolcaEM <63682805+VolcaEM@users.noreply.github.com> Date: Mon, 29 Jun 2020 04:22:38 +0200 Subject: [PATCH 06/55] Remove duplicate functions --- src/core/hle/service/sm/controller.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/core/hle/service/sm/controller.cpp b/src/core/hle/service/sm/controller.cpp index cccccc30a..972aaa6d9 100644 --- a/src/core/hle/service/sm/controller.cpp +++ b/src/core/hle/service/sm/controller.cpp @@ -55,8 +55,6 @@ Controller::Controller() : ServiceFramework("IpcController") { {2, &Controller::CloneCurrentObject, "CloneCurrentObject"}, {3, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"}, {4, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"}, - {0x00000003, &Controller::QueryPointerBufferSize, "QueryPointerBufferSize"}, - {0x00000004, &Controller::CloneCurrentObjectEx, "CloneCurrentObjectEx"}, }; RegisterHandlers(functions); } From 24c2930012baa60379da6f8c23f2cf35e38ef2d2 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Wed, 1 Jul 2020 16:52:02 +1000 Subject: [PATCH 07/55] audio: Improving audio timing for multicore/single core Fixes the issue with needing the timestretcher for multicore. --- src/audio_core/stream.cpp | 23 +++++------------------ src/audio_core/stream.h | 4 ++-- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index dfc4805d9..307d78ecd 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -38,7 +38,7 @@ Stream::Stream(Core::Timing::CoreTiming& core_timing, u32 sample_rate, Format fo sink_stream{sink_stream}, core_timing{core_timing}, name{std::move(name_)} { release_event = Core::Timing::CreateEvent( - name, [this](u64 userdata, s64 cycles_late) { ReleaseActiveBuffer(); }); + name, [this](u64 userdata, s64 cycles_late) { ReleaseActiveBuffer(cycles_late); }); } void Stream::Play() { @@ -66,15 +66,6 @@ s64 Stream::GetBufferReleaseNS(const Buffer& buffer) const { return ns.count(); } -s64 Stream::GetBufferReleaseNSHostTiming(const Buffer& buffer) const { - const std::size_t num_samples{buffer.GetSamples().size() / GetNumChannels()}; - /// DSP signals before playing the last sample, in HLE we emulate this in this way - s64 base_samples = std::max(static_cast(num_samples) - 1, 0); - const auto ns = - std::chrono::nanoseconds((static_cast(base_samples) * 1000000000ULL) / sample_rate); - return ns.count(); -} - static void VolumeAdjustSamples(std::vector& samples, float game_volume) { const float volume{std::clamp(Settings::Volume() - (1.0f - game_volume), 0.0f, 1.0f)}; @@ -89,7 +80,7 @@ static void VolumeAdjustSamples(std::vector& samples, float game_volume) { } } -void Stream::PlayNextBuffer() { +void Stream::PlayNextBuffer(s64 cycles_late) { if (!IsPlaying()) { // Ensure we are in playing state before playing the next buffer sink_stream.Flush(); @@ -114,18 +105,14 @@ void Stream::PlayNextBuffer() { sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); - if (core_timing.IsHostTiming()) { - core_timing.ScheduleEvent(GetBufferReleaseNSHostTiming(*active_buffer), release_event, {}); - } else { - core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer), release_event, {}); - } + core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer) - cycles_late, release_event, {}); } -void Stream::ReleaseActiveBuffer() { +void Stream::ReleaseActiveBuffer(s64 cycles_late) { ASSERT(active_buffer); released_buffers.push(std::move(active_buffer)); release_callback(); - PlayNextBuffer(); + PlayNextBuffer(cycles_late); } bool Stream::QueueBuffer(BufferPtr&& buffer) { diff --git a/src/audio_core/stream.h b/src/audio_core/stream.h index e309d60fe..524376257 100644 --- a/src/audio_core/stream.h +++ b/src/audio_core/stream.h @@ -90,10 +90,10 @@ public: private: /// Plays the next queued buffer in the audio stream, starting playback if necessary - void PlayNextBuffer(); + void PlayNextBuffer(s64 cycles_late = 0); /// Releases the actively playing buffer, signalling that it has been completed - void ReleaseActiveBuffer(); + void ReleaseActiveBuffer(s64 cycles_late = 0); /// Gets the number of core cycles when the specified buffer will be released s64 GetBufferReleaseNS(const Buffer& buffer) const; From 28aa6975284bcedff49988346d2c71629a001628 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Wed, 1 Jul 2020 16:59:42 +1000 Subject: [PATCH 08/55] Don't handle cycles late if stretcher is active Timestretcher seems to be broken --- src/audio_core/stream.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 307d78ecd..22e8df373 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -105,7 +105,9 @@ void Stream::PlayNextBuffer(s64 cycles_late) { sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); - core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer) - cycles_late, release_event, {}); + core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer) - + (Settings::values.enable_audio_stretching ? 0 : cycles_late), + release_event, {}); } void Stream::ReleaseActiveBuffer(s64 cycles_late) { From b1b1ed7597cbe329e26db8240b9e05d3fc360b6f Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Wed, 1 Jul 2020 22:00:47 +0000 Subject: [PATCH 09/55] cmake: stop linking against QGL after c6a0ab979239 --- CMakeLists.txt | 4 ++-- CMakeModules/CopyYuzuQt5Deps.cmake | 1 - src/yuzu/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 73405ce4b..2f1bc81ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,7 @@ if(ENABLE_QT) set(QT_PREFIX_HINT HINTS "${QT_PREFIX}") endif() - find_package(Qt5 5.9 COMPONENTS Widgets OpenGL ${QT_PREFIX_HINT}) + find_package(Qt5 5.9 COMPONENTS Widgets ${QT_PREFIX_HINT}) if (YUZU_USE_QT_WEB_ENGINE) find_package(Qt5 COMPONENTS WebEngineCore WebEngineWidgets) endif() @@ -289,7 +289,7 @@ if (CONAN_REQUIRED_LIBS) if(ENABLE_QT) list(APPEND CMAKE_MODULE_PATH "${CONAN_QT_ROOT_RELEASE}") list(APPEND CMAKE_PREFIX_PATH "${CONAN_QT_ROOT_RELEASE}") - find_package(Qt5 5.9 REQUIRED COMPONENTS Widgets OpenGL) + find_package(Qt5 5.9 REQUIRED COMPONENTS Widgets) if (YUZU_USE_QT_WEB_ENGINE) find_package(Qt5 REQUIRED COMPONENTS WebEngineCore WebEngineWidgets) endif() diff --git a/CMakeModules/CopyYuzuQt5Deps.cmake b/CMakeModules/CopyYuzuQt5Deps.cmake index 2598b9b60..59343b1ca 100644 --- a/CMakeModules/CopyYuzuQt5Deps.cmake +++ b/CMakeModules/CopyYuzuQt5Deps.cmake @@ -15,7 +15,6 @@ function(copy_yuzu_Qt5_deps target_dir) icuuc*.dll Qt5Core$<$:d>.* Qt5Gui$<$:d>.* - Qt5OpenGL$<$:d>.* Qt5Widgets$<$:d>.* ) diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 75c27e39e..c08a10f29 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -147,7 +147,7 @@ endif() create_target_directory_groups(yuzu) target_link_libraries(yuzu PRIVATE common core input_common video_core) -target_link_libraries(yuzu PRIVATE Boost::boost glad Qt5::OpenGL Qt5::Widgets) +target_link_libraries(yuzu PRIVATE Boost::boost glad Qt5::Widgets) target_link_libraries(yuzu PRIVATE ${PLATFORM_LIBRARIES} Threads::Threads) if (ENABLE_VULKAN AND NOT WIN32) From 38b585a309b4c5fd330491e0fb36ac47d04b66db Mon Sep 17 00:00:00 2001 From: VolcaEM <63682805+VolcaEM@users.noreply.github.com> Date: Thu, 2 Jul 2020 08:58:51 +0200 Subject: [PATCH 10/55] Rename GetApplicationArea2 to GetApplicationAreaSize --- src/core/hle/service/nfp/nfp.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp index 386ecd4a9..4b79eb81d 100644 --- a/src/core/hle/service/nfp/nfp.cpp +++ b/src/core/hle/service/nfp/nfp.cpp @@ -55,7 +55,7 @@ public: {19, &IUser::GetState, "GetState"}, {20, &IUser::GetDeviceState, "GetDeviceState"}, {21, &IUser::GetNpadId, "GetNpadId"}, - {22, &IUser::GetApplicationArea2, "GetApplicationArea2"}, + {22, &IUser::GetApplicationAreaSize, "GetApplicationAreaSize"}, {23, &IUser::AttachAvailabilityChangeEvent, "AttachAvailabilityChangeEvent"}, {24, nullptr, "RecreateApplicationArea"}, }; @@ -295,7 +295,7 @@ private: rb.Push(ErrCodes::ERR_NO_APPLICATION_AREA); } - void GetApplicationArea2(Kernel::HLERequestContext& ctx) { + void GetApplicationAreaSize(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_NFP, "(STUBBED) called"); // We don't need to worry about this since we can just open the file IPC::ResponseBuilder rb{ctx, 3}; From 3f910efb409db461a5a16926e7ba55a7bf724abd Mon Sep 17 00:00:00 2001 From: VolcaEM <63682805+VolcaEM@users.noreply.github.com> Date: Thu, 2 Jul 2020 09:02:55 +0200 Subject: [PATCH 11/55] Rename two functions in NS - Rename "GetShellEvent" to "GetShellEventHandle" - Rename "LaunchApplicationFromHost" to "LaunchApplication" --- src/core/hle/service/ns/ns.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 80b7062d5..3e4dd2f7a 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -567,11 +567,11 @@ public: {0, nullptr, "LaunchProgram"}, {1, nullptr, "TerminateProcess"}, {2, nullptr, "TerminateProgram"}, - {4, nullptr, "GetShellEvent"}, + {4, nullptr, "GetShellEventHandle"}, {5, nullptr, "GetShellEventInfo"}, {6, nullptr, "TerminateApplication"}, {7, nullptr, "PrepareLaunchProgramFromHost"}, - {8, nullptr, "LaunchApplicationFromHost"}, + {8, nullptr, "LaunchApplication"}, {9, nullptr, "LaunchApplicationWithStorageIdForDevelop"}, {10, nullptr, "IsSystemMemoryResourceLimitBoosted"}, {11, nullptr, "GetRunningApplicationProcessIdForDevelop"}, From c0dc8f9d2567bd2a7f0bbd0bf4a5f42194bbb102 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 5 Jul 2020 06:26:07 -0400 Subject: [PATCH 12/55] AM/ISelfController: Stub CreateManagedDisplaySeparableLayer Stub this by sending 1 layer id instead of 2 as yuzu does not support multiple layers per display. No adverse side effects have been observed. - Used by Animal Crossing: New Horizons Update 1.3.0 --- src/core/hle/service/am/am.cpp | 20 +++++++++++++++++++- src/core/hle/service/am/am.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 1bb544dd8..2642c24cc 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -271,7 +271,7 @@ ISelfController::ISelfController(Core::System& system, {41, nullptr, "IsSystemBufferSharingEnabled"}, {42, nullptr, "GetSystemSharedLayerHandle"}, {43, nullptr, "GetSystemSharedBufferHandle"}, - {44, nullptr, "CreateManagedDisplaySeparableLayer"}, + {44, &ISelfController::CreateManagedDisplaySeparableLayer, "CreateManagedDisplaySeparableLayer"}, {45, nullptr, "SetManagedDisplayLayerSeparationMode"}, {50, &ISelfController::SetHandlesRequestToDisplay, "SetHandlesRequestToDisplay"}, {51, nullptr, "ApproveToDisplay"}, @@ -461,6 +461,24 @@ void ISelfController::CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx) rb.Push(*layer_id); } +void ISelfController::CreateManagedDisplaySeparableLayer(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_AM, "(STUBBED) called"); + + // TODO(Subv): Find out how AM determines the display to use, for now just + // create the layer in the Default display. + // This calls nn::vi::CreateRecordingLayer() which creates another layer. + // Currently we do not support more than 1 layer per display, output 1 layer id for now. + // Outputting 1 layer id instead of the expected 2 has not been observed to cause any adverse + // side effects. + // TODO: Support multiple layers + const auto display_id = nvflinger->OpenDisplay("Default"); + const auto layer_id = nvflinger->CreateLayer(*display_id); + + IPC::ResponseBuilder rb{ctx, 4}; + rb.Push(RESULT_SUCCESS); + rb.Push(*layer_id); +} + void ISelfController::SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_AM, "(STUBBED) called"); diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h index 2f69466ec..6cfb11b48 100644 --- a/src/core/hle/service/am/am.h +++ b/src/core/hle/service/am/am.h @@ -140,6 +140,7 @@ private: void SetOutOfFocusSuspendingEnabled(Kernel::HLERequestContext& ctx); void SetAlbumImageOrientation(Kernel::HLERequestContext& ctx); void CreateManagedDisplayLayer(Kernel::HLERequestContext& ctx); + void CreateManagedDisplaySeparableLayer(Kernel::HLERequestContext& ctx); void SetHandlesRequestToDisplay(Kernel::HLERequestContext& ctx); void SetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx); void GetIdleTimeDetectionExtension(Kernel::HLERequestContext& ctx); From cf76769026ae417fa3822d499f6a55ef084ec2da Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Wed, 8 Jul 2020 19:45:06 +0300 Subject: [PATCH 13/55] AM: fix GetDesiredLanguage: try to get a control metadata from application update when is failed to get from the basic version. Tested on Kirby Star Allies --- src/core/hle/service/am/am.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index 24cfb370b..32fad35f3 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -1389,7 +1389,19 @@ void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) { u32 supported_languages = 0; FileSys::PatchManager pm{system.CurrentProcess()->GetTitleID()}; - const auto res = pm.GetControlMetadata(); + const auto res = [this] { + const auto title_id = system.CurrentProcess()->GetTitleID(); + + FileSys::PatchManager pm{title_id}; + auto res = pm.GetControlMetadata(); + if (res.first != nullptr) { + return res; + } + + FileSys::PatchManager pm_update{FileSys::GetUpdateTitleID(title_id)}; + return pm_update.GetControlMetadata(); + }(); + if (res.first != nullptr) { supported_languages = res.first->GetSupportedLanguages(); } From 48ff15602e89ee2b7946310dd343859d56795a67 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Thu, 9 Jul 2020 14:56:56 +0000 Subject: [PATCH 14/55] cmake: pass libusb include directory as well In file included from src/input_common/gcadapter/gc_adapter.cpp:8: src/./input_common/gcadapter/gc_adapter.h:11:10: fatal error: 'libusb.h' file not found #include ^~~~~~~~~~ --- CMakeLists.txt | 1 + src/input_common/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd40e5cfe..eb51d09dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -333,6 +333,7 @@ endif() find_package(LibUSB) if (NOT LIBUSB_FOUND) add_subdirectory(externals/libusb) + set(LIBUSB_INCLUDE_DIR "") set(LIBUSB_LIBRARIES usb) endif() diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 3bd76dd23..1d7e19a66 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -30,6 +30,7 @@ if(SDL2_FOUND) target_compile_definitions(input_common PRIVATE HAVE_SDL2) endif() +target_include_directories(input_common SYSTEM PUBLIC ${LIBUSB_INCLUDE_DIR}) target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) create_target_directory_groups(input_common) From 95cd2e17ab346b9aec0e40383b4effde23652c47 Mon Sep 17 00:00:00 2001 From: John Galt Date: Thu, 9 Jul 2020 11:25:10 -0400 Subject: [PATCH 15/55] cmake: fix fmt linking when found This is a new attempt at #4206 that shouldn't break windows builds. If someone else could test on windows, it would be much appreciated. Previously, the build bot passed but the actual builds failed. --- src/common/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index d120c8d3d..423bef0f5 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -191,5 +191,9 @@ endif() create_target_directory_groups(common) find_package(Boost 1.71 COMPONENTS context headers REQUIRED) -target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) +if (fmt_FOUND) + target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt microprofile) +else() + target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) +endif() target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd xbyak) From 1c7d106aacccbabd6551ce3882ac1acfa1b14fca Mon Sep 17 00:00:00 2001 From: lat9nq Date: Thu, 9 Jul 2020 21:28:32 -0400 Subject: [PATCH 16/55] vk_stream_buffer: set allocable_size to 9 MiB This solves the crash on Linux systems running the current Linux Long Lived branch nVidia driver. --- src/video_core/renderer_vulkan/vk_stream_buffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/renderer_vulkan/vk_stream_buffer.cpp b/src/video_core/renderer_vulkan/vk_stream_buffer.cpp index 868447af2..2d28a6c47 100644 --- a/src/video_core/renderer_vulkan/vk_stream_buffer.cpp +++ b/src/video_core/renderer_vulkan/vk_stream_buffer.cpp @@ -121,7 +121,7 @@ void VKStreamBuffer::CreateBuffers(VkBufferUsageFlags usage) { // Substract from the preferred heap size some bytes to avoid getting out of memory. const VkDeviceSize heap_size = memory_properties.memoryHeaps[preferred_heap].size; - const VkDeviceSize allocable_size = heap_size - 4 * 1024 * 1024; + const VkDeviceSize allocable_size = heap_size - 9 * 1024 * 1024; VkBufferCreateInfo buffer_ci; buffer_ci.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; From 63d23835ef4445b3a010cc0e8b1e73ebe012ac08 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Thu, 9 Jul 2020 22:42:09 -0400 Subject: [PATCH 17/55] configuration: implement per-game configurations (#4098) * Switch game settings to use a pointer In order to add full per-game settings, we need to be able to tell yuzu to switch to using either the global or game configuration. Using a pointer makes it easier to switch. * configuration: add new UI without changing existing funcitonality The new UI also adds General, System, Graphics, Advanced Graphics, and Audio tabs, but as yet they do nothing. This commit keeps yuzu to the same functionality as originally branched. * configuration: Rename files These weren't included in the last commit. Now they are. * configuration: setup global configuration checkbox Global config checkbox now enables/disables the appropriate tabs in the game properties dialog. The use global configuration setting is now saved to the config, defaulting to true. This also addresses some changes requested in the PR. * configuration: swap to per-game config memory for properties dialog Does not set memory going in-game. Swaps to game values when opening the properties dialog, then swaps back when closing it. Uses a `memcpy` to swap. Also implements saving config files, limited to certain groups of configurations so as to not risk setting unsafe configurations. * configuration: change config interfaces to use config-specific pointers When a game is booted, we need to be able to open the configuration dialogs without changing the settings pointer in the game's emualtion. A new pointer specific to just the configuration dialogs can be used to separate changes to just those config dialogs without affecting the emulation. * configuration: boot a game using per-game settings Swaps values where needed to boot a game. * configuration: user correct config during emulation Creates a new pointer specifically for modifying the configuration while emulation is in progress. Both the regular configuration dialog and the game properties dialog now use the pointer Settings::config_values to focus edits to the correct struct. * settings: split Settings::values into two different structs By splitting the settings into two mutually exclusive structs, it becomes easier, as a developer, to determine how to use the Settings structs after per-game configurations is merged. Other benefits include only duplicating the required settings in memory. * settings: move use_docked_mode to Controls group `use_docked_mode` is set in the input settings and cannot be accessed from the system settings. Grouping it with system settings causes it to be saved with per-game settings, which may make transferring configs more difficult later on, especially since docked mode cannot be set from within the game properties dialog. * configuration: Fix the other yuzu executables and a regression In main.cpp, we have to get the title ID before the ROM is loaded, else the renderer will reflect only the global settings and now the user's game specific settings. * settings: use a template to duplicate memory for each setting Replaces the type of each variable in the Settings::Values struct with a new class that allows basic data reading and writing. The new struct Settings::Setting duplicates the data in memory and can manage global overrides per each setting. * configuration: correct add-ons config and swap settings when apropriate Any add-ons interaction happens directly through the global values struct. Swapping bewteen structs now also includes copying the necessary global configs that cannot be changed nor saved in per-game settings. General and System config menus now update based on whether it is viewing the global or per-game settings. * settings: restore old values struct No longer needed with the Settings::Setting class template. * configuration: implement hierarchical game properties dialog This sets the apropriate global or local data in each setting. * clang format * clang format take 2 can the docker container save this? * address comments and style issues * config: read and write settings with global awareness Adds new functions to read and write settings while keeping the global state in focus. Files now generated per-game are much smaller since often they only need address the global state. * settings: restore global state when necessary Upon closing a game or the game properties dialog, we need to restore all global settings to the original global state so that we can properly open the configuration dialog or boot a different game. * configuration: guard setting values incorrectly This disables setting values while a game is running if the setting is overwritten by a per game setting. * config: don't write local settings in the global config Simple guards to prevent writing the wrong settings in the wrong files. * configuration: add comments, assume less, and clang format No longer assumes that a disabled UI element means the global state is turned off, instead opting to directly answer that question. Still however assumes a game is running if it is in that state. * configuration: fix a logic error Should not be negated * restore settings' global state regardless of accept/cancel Fixes loading a properties dialog and causing the global config dialog to show local settings. * fix more logic errors Fixed the frame limit would set the global setting from the game properties dialog. Also strengthened the Settings::Setting member variables and simplified the logic in config reading (ReadSettingGlobal). * fix another logic error In my efforts to guard RestoreGlobalState, I accidentally negated the IsPowered condition. * configure_audio: set toggle_stretched_audio to tristate * fixed custom rtc and rng seed overwriting the global value * clang format * rebased * clang format take 4 * address my own review Basically revert unintended changes * settings: literal instead of casting "No need to cast, use 1U instead" Thanks, Morph! Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com> * Revert "settings: literal instead of casting " This reverts commit 95e992a87c898f3e882ffdb415bb0ef9f80f613f. * main: fix status buttons reporting wrong settings after stop emulation * settings: Log UseDockedMode in the Controls group This should have happened when use_docked_mode was moved over to the controls group internally. This just reflects this in the log. * main: load settings if the file has a title id In other words, don't exit if the loader has trouble getting a title id. * use a zero * settings: initalize resolution factor with constructor instead of casting * Revert "settings: initalize resolution factor with constructor instead of casting" This reverts commit 54c35ecb46a29953842614620f9b7de1aa9d5dc8. * configure_graphics: guard device selector when Vulkan is global Prevents the user from editing the device selector if Vulkan is the global renderer backend. Also resets the vulkan_device variable when the users switches back-and-forth between global and Vulkan. * address reviewer concerns Changes function variables to const wherever they don't need to be changed. Sets Settings::Setting to final as it should not be inherited from. Sets ConfigurationShared::use_global_text to static. Co-Authored-By: VolcaEM * main: load per-game settings after LoadROM This prevents `Restart Emulation` from restoring the global settings *after* the per-game settings were applied. Thanks to BSoDGamingYT for finding this bug. * Revert "main: load per-game settings after LoadROM" This reverts commit 9d0d48c52d2dcf3bfb1806cc8fa7d5a271a8a804. * main: only restore global settings when necessary Loading the per-game settings cannot happen after the ROM is loaded, so we have to specify when to restore the global state. Again thanks to BSoD for finding the bug. * configuration_shared: address reviewer concerns except operator overrides Dropping operator override usage in next commit. Co-Authored-By: LC * settings: Drop operator overrides from Setting template Requires using GetValue and SetValue explicitly. Also reverts a change that broke title ID formatting in the game properties dialog. * complete rebase * configuration_shared: translate "Use global configuration" Uses ConfigurePerGame to do so, since its usage, at least as of now, corresponds with ConfigurationShared. * configure_per_game: address reviewer concern As far as I understand, it prevents the program from unnecessarily copying strings. Co-Authored-By: LC Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com> Co-authored-by: VolcaEM Co-authored-by: LC --- src/audio_core/cubeb_sink.cpp | 2 +- src/audio_core/stream.cpp | 7 +- src/core/core.cpp | 6 +- src/core/frontend/framebuffer_layout.cpp | 2 +- src/core/hle/kernel/process.cpp | 2 +- src/core/hle/service/am/am.cpp | 8 +- src/core/hle/service/ns/ns.cpp | 3 +- src/core/hle/service/set/set.cpp | 10 +- src/core/hle/service/spl/module.cpp | 2 +- src/core/hle/service/vi/vi.cpp | 20 +- src/core/perf_stats.cpp | 5 +- src/core/settings.cpp | 84 +++-- src/core/settings.h | 124 ++++--- src/core/telemetry_session.cpp | 27 +- src/video_core/buffer_cache/buffer_cache.h | 6 +- src/video_core/gpu.cpp | 2 +- src/video_core/query_cache.h | 2 +- src/video_core/renderer_base.cpp | 2 +- src/video_core/renderer_opengl/gl_device.cpp | 8 +- .../renderer_opengl/gl_shader_disk_cache.cpp | 2 +- .../renderer_opengl/renderer_opengl.cpp | 8 +- .../renderer_vulkan/renderer_vulkan.cpp | 2 +- src/video_core/texture_cache/texture_cache.h | 2 +- src/video_core/textures/texture.cpp | 2 +- src/video_core/video_core.cpp | 8 +- src/yuzu/CMakeLists.txt | 11 +- src/yuzu/bootmanager.cpp | 8 +- src/yuzu/configuration/config.cpp | 328 ++++++++++------ src/yuzu/configuration/config.h | 27 +- .../configuration/configuration_shared.cpp | 76 ++++ src/yuzu/configuration/configuration_shared.h | 36 ++ src/yuzu/configuration/configure_audio.cpp | 82 +++- src/yuzu/configuration/configure_audio.h | 2 + src/yuzu/configuration/configure_audio.ui | 50 ++- src/yuzu/configuration/configure_dialog.cpp | 2 + src/yuzu/configuration/configure_general.cpp | 76 +++- src/yuzu/configuration/configure_general.h | 2 + src/yuzu/configuration/configure_graphics.cpp | 150 +++++++- src/yuzu/configuration/configure_graphics.h | 2 + src/yuzu/configuration/configure_graphics.ui | 36 ++ .../configure_graphics_advanced.cpp | 106 +++++- .../configure_graphics_advanced.h | 2 + src/yuzu/configuration/configure_per_game.cpp | 140 +++++++ src/yuzu/configuration/configure_per_game.h | 51 +++ src/yuzu/configuration/configure_per_game.ui | 350 ++++++++++++++++++ ...eral.cpp => configure_per_game_addons.cpp} | 105 ++---- ..._general.h => configure_per_game_addons.h} | 16 +- .../configure_per_game_addons.ui | 38 ++ .../configuration/configure_per_general.ui | 276 -------------- src/yuzu/configuration/configure_system.cpp | 192 ++++++++-- src/yuzu/configuration/configure_system.h | 2 + src/yuzu/main.cpp | 116 +++--- src/yuzu/main.h | 1 + src/yuzu_cmd/config.cpp | 79 ++-- .../emu_window/emu_window_sdl2_gl.cpp | 2 +- src/yuzu_cmd/yuzu.cpp | 2 +- src/yuzu_tester/config.cpp | 61 +-- 57 files changed, 1940 insertions(+), 833 deletions(-) create mode 100644 src/yuzu/configuration/configuration_shared.cpp create mode 100644 src/yuzu/configuration/configuration_shared.h create mode 100644 src/yuzu/configuration/configure_per_game.cpp create mode 100644 src/yuzu/configuration/configure_per_game.h create mode 100644 src/yuzu/configuration/configure_per_game.ui rename src/yuzu/configuration/{configure_per_general.cpp => configure_per_game_addons.cpp} (57%) rename src/yuzu/configuration/{configure_per_general.h => configure_per_game_addons.h} (70%) create mode 100644 src/yuzu/configuration/configure_per_game_addons.ui delete mode 100644 src/yuzu/configuration/configure_per_general.ui diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index c4e0e30fe..41bf5cd4d 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -193,7 +193,7 @@ long CubebSinkStream::DataCallback(cubeb_stream* stream, void* user_data, const const std::size_t samples_to_write = num_channels * num_frames; std::size_t samples_written; - if (Settings::values.enable_audio_stretching) { + if (Settings::values.enable_audio_stretching.GetValue()) { const std::vector in{impl->queue.Pop()}; const std::size_t num_in{in.size() / num_channels}; s16* const out{reinterpret_cast(buffer)}; diff --git a/src/audio_core/stream.cpp b/src/audio_core/stream.cpp index 22e8df373..aab3e979a 100644 --- a/src/audio_core/stream.cpp +++ b/src/audio_core/stream.cpp @@ -105,9 +105,10 @@ void Stream::PlayNextBuffer(s64 cycles_late) { sink_stream.EnqueueSamples(GetNumChannels(), active_buffer->GetSamples()); - core_timing.ScheduleEvent(GetBufferReleaseNS(*active_buffer) - - (Settings::values.enable_audio_stretching ? 0 : cycles_late), - release_event, {}); + core_timing.ScheduleEvent( + GetBufferReleaseNS(*active_buffer) - + (Settings::values.enable_audio_stretching.GetValue() ? 0 : cycles_late), + release_event, {}); } void Stream::ReleaseActiveBuffer(s64 cycles_late) { diff --git a/src/core/core.cpp b/src/core/core.cpp index 1a243c515..69a1aa0a5 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -147,8 +147,8 @@ struct System::Impl { device_memory = std::make_unique(system); - is_multicore = Settings::values.use_multi_core; - is_async_gpu = is_multicore || Settings::values.use_asynchronous_gpu_emulation; + is_multicore = Settings::values.use_multi_core.GetValue(); + is_async_gpu = is_multicore || Settings::values.use_asynchronous_gpu_emulation.GetValue(); kernel.SetMulticore(is_multicore); cpu_manager.SetMulticore(is_multicore); @@ -162,7 +162,7 @@ struct System::Impl { const auto current_time = std::chrono::duration_cast( std::chrono::system_clock::now().time_since_epoch()); Settings::values.custom_rtc_differential = - Settings::values.custom_rtc.value_or(current_time) - current_time; + Settings::values.custom_rtc.GetValue().value_or(current_time) - current_time; // Create a default fs if one doesn't already exist. if (virtual_filesystem == nullptr) diff --git a/src/core/frontend/framebuffer_layout.cpp b/src/core/frontend/framebuffer_layout.cpp index d0c43447c..c1fbc235b 100644 --- a/src/core/frontend/framebuffer_layout.cpp +++ b/src/core/frontend/framebuffer_layout.cpp @@ -29,7 +29,7 @@ FramebufferLayout DefaultFrameLayout(u32 width, u32 height) { const float window_aspect_ratio = static_cast(height) / width; const float emulation_aspect_ratio = EmulationAspectRatio( - static_cast(Settings::values.aspect_ratio), window_aspect_ratio); + static_cast(Settings::values.aspect_ratio.GetValue()), window_aspect_ratio); const Common::Rectangle screen_window_area{0, 0, width, height}; Common::Rectangle screen = MaxRectangle(screen_window_area, emulation_aspect_ratio); diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index f9d7c024d..c6fcb56ad 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp @@ -123,7 +123,7 @@ std::shared_ptr Process::Create(Core::System& system, std::string name, : kernel.CreateNewUserProcessID(); process->capabilities.InitializeForMetadatalessProcess(); - std::mt19937 rng(Settings::values.rng_seed.value_or(0)); + std::mt19937 rng(Settings::values.rng_seed.GetValue().value_or(0)); std::uniform_int_distribution distribution; std::generate(process->random_entropy.begin(), process->random_entropy.end(), [&] { return distribution(rng); }); diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index c688d6d98..256449aa7 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -749,14 +749,14 @@ void ICommonStateGetter::GetDefaultDisplayResolution(Kernel::HLERequestContext& if (Settings::values.use_docked_mode) { rb.Push(static_cast(Service::VI::DisplayResolution::DockedWidth) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); rb.Push(static_cast(Service::VI::DisplayResolution::DockedHeight) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); } else { rb.Push(static_cast(Service::VI::DisplayResolution::UndockedWidth) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); rb.Push(static_cast(Service::VI::DisplayResolution::UndockedHeight) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); } } diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp index 7e5ceccdb..6cfa9666d 100644 --- a/src/core/hle/service/ns/ns.cpp +++ b/src/core/hle/service/ns/ns.cpp @@ -366,7 +366,8 @@ ResultVal IApplicationManagerInterface::GetApplicationDesiredLanguage( LOG_DEBUG(Service_NS, "called with supported_languages={:08X}", supported_languages); // Get language code from settings - const auto language_code = Set::GetLanguageCodeFromIndex(Settings::values.language_index); + const auto language_code = + Set::GetLanguageCodeFromIndex(Settings::values.language_index.GetValue()); // Convert to application language, get priority list const auto application_language = ConvertToApplicationLanguage(language_code); diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp index e5cfd2101..34fe2fd82 100644 --- a/src/core/hle/service/set/set.cpp +++ b/src/core/hle/service/set/set.cpp @@ -91,7 +91,7 @@ void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t m } void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { - const auto language_code = available_language_codes[Settings::values.language_index]; + const auto language_code = available_language_codes[Settings::values.language_index.GetValue()]; const auto key_code = std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), [=](const auto& element) { return element.first == language_code; }); @@ -99,7 +99,7 @@ void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { if (key_code == language_to_layout.cend()) { LOG_ERROR(Service_SET, "Could not find keyboard layout for language index {}, defaulting to English us", - Settings::values.language_index); + Settings::values.language_index.GetValue()); } else { layout = key_code->second; } @@ -163,11 +163,11 @@ void SET::GetQuestFlag(Kernel::HLERequestContext& ctx) { } void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_SET, "called {}", Settings::values.language_index); + LOG_DEBUG(Service_SET, "called {}", Settings::values.language_index.GetValue()); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(RESULT_SUCCESS); - rb.PushEnum(available_language_codes[Settings::values.language_index]); + rb.PushEnum(available_language_codes[Settings::values.language_index.GetValue()]); } void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { @@ -175,7 +175,7 @@ void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); - rb.Push(Settings::values.region_index); + rb.Push(Settings::values.region_index.GetValue()); } void SET::GetKeyCodeMap(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/spl/module.cpp b/src/core/hle/service/spl/module.cpp index e724d4ab8..865ed3b91 100644 --- a/src/core/hle/service/spl/module.cpp +++ b/src/core/hle/service/spl/module.cpp @@ -19,7 +19,7 @@ namespace Service::SPL { Module::Interface::Interface(std::shared_ptr module, const char* name) : ServiceFramework(name), module(std::move(module)), - rng(Settings::values.rng_seed.value_or(std::time(nullptr))) {} + rng(Settings::values.rng_seed.GetValue().value_or(std::time(nullptr))) {} Module::Interface::~Interface() = default; diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp index 157092074..552a5e4ef 100644 --- a/src/core/hle/service/vi/vi.cpp +++ b/src/core/hle/service/vi/vi.cpp @@ -519,9 +519,9 @@ private: IGBPConnectRequestParcel request{ctx.ReadBuffer()}; IGBPConnectResponseParcel response{ static_cast(static_cast(DisplayResolution::UndockedWidth) * - Settings::values.resolution_factor), + Settings::values.resolution_factor.GetValue()), static_cast(static_cast(DisplayResolution::UndockedHeight) * - Settings::values.resolution_factor)}; + Settings::values.resolution_factor.GetValue())}; ctx.WriteBuffer(response.Serialize()); break; } @@ -748,14 +748,14 @@ private: if (Settings::values.use_docked_mode) { rb.Push(static_cast(Service::VI::DisplayResolution::DockedWidth) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); rb.Push(static_cast(Service::VI::DisplayResolution::DockedHeight) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); } else { rb.Push(static_cast(Service::VI::DisplayResolution::UndockedWidth) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); rb.Push(static_cast(Service::VI::DisplayResolution::UndockedHeight) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); } rb.PushRaw(60.0f); // This wouldn't seem to be correct for 30 fps games. @@ -1029,9 +1029,9 @@ private: // between docked and undocked dimensions. We take the liberty of applying // the resolution scaling factor here. rb.Push(static_cast(DisplayResolution::UndockedWidth) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); rb.Push(static_cast(DisplayResolution::UndockedHeight) * - static_cast(Settings::values.resolution_factor)); + static_cast(Settings::values.resolution_factor.GetValue())); } void SetLayerScalingMode(Kernel::HLERequestContext& ctx) { @@ -1064,8 +1064,8 @@ private: LOG_WARNING(Service_VI, "(STUBBED) called"); DisplayInfo display_info; - display_info.width *= static_cast(Settings::values.resolution_factor); - display_info.height *= static_cast(Settings::values.resolution_factor); + display_info.width *= static_cast(Settings::values.resolution_factor.GetValue()); + display_info.height *= static_cast(Settings::values.resolution_factor.GetValue()); ctx.WriteBuffer(&display_info, sizeof(DisplayInfo)); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(RESULT_SUCCESS); diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp index 9f3a6b811..29339ead7 100644 --- a/src/core/perf_stats.cpp +++ b/src/core/perf_stats.cpp @@ -119,13 +119,14 @@ double PerfStats::GetLastFrameTimeScale() { } void FrameLimiter::DoFrameLimiting(microseconds current_system_time_us) { - if (!Settings::values.use_frame_limit || Settings::values.use_multi_core) { + if (!Settings::values.use_frame_limit.GetValue() || + Settings::values.use_multi_core.GetValue()) { return; } auto now = Clock::now(); - const double sleep_scale = Settings::values.frame_limit / 100.0; + const double sleep_scale = Settings::values.frame_limit.GetValue() / 100.0; // Max lag caused by slow frames. Shouldn't be more than the length of a frame at the current // speed percent or it will clamp too much and prevent this from properly limiting to that diff --git a/src/core/settings.cpp b/src/core/settings.cpp index 56df5e925..d3886c4ec 100644 --- a/src/core/settings.cpp +++ b/src/core/settings.cpp @@ -62,6 +62,7 @@ const std::array mapping = {{ } Values values = {}; +bool configuring_global = true; std::string GetTimeZoneString() { static constexpr std::array timezones{{ @@ -73,9 +74,9 @@ std::string GetTimeZoneString() { "UCT", "Universal", "UTC", "W-SU", "WET", "Zulu", }}; - ASSERT(Settings::values.time_zone_index < timezones.size()); + ASSERT(Settings::values.time_zone_index.GetValue() < timezones.size()); - return timezones[Settings::values.time_zone_index]; + return timezones[Settings::values.time_zone_index.GetValue()]; } void Apply() { @@ -97,25 +98,25 @@ void LogSetting(const std::string& name, const T& value) { void LogSettings() { LOG_INFO(Config, "yuzu Configuration:"); - LogSetting("System_UseDockedMode", Settings::values.use_docked_mode); - LogSetting("System_RngSeed", Settings::values.rng_seed.value_or(0)); + LogSetting("Controls_UseDockedMode", Settings::values.use_docked_mode); + LogSetting("System_RngSeed", Settings::values.rng_seed.GetValue().value_or(0)); LogSetting("System_CurrentUser", Settings::values.current_user); - LogSetting("System_LanguageIndex", Settings::values.language_index); - LogSetting("System_RegionIndex", Settings::values.region_index); - LogSetting("System_TimeZoneIndex", Settings::values.time_zone_index); - LogSetting("Core_UseMultiCore", Settings::values.use_multi_core); - LogSetting("Renderer_UseResolutionFactor", Settings::values.resolution_factor); - LogSetting("Renderer_UseFrameLimit", Settings::values.use_frame_limit); - LogSetting("Renderer_FrameLimit", Settings::values.frame_limit); - LogSetting("Renderer_UseDiskShaderCache", Settings::values.use_disk_shader_cache); - LogSetting("Renderer_GPUAccuracyLevel", Settings::values.gpu_accuracy); + LogSetting("System_LanguageIndex", Settings::values.language_index.GetValue()); + LogSetting("System_RegionIndex", Settings::values.region_index.GetValue()); + LogSetting("System_TimeZoneIndex", Settings::values.time_zone_index.GetValue()); + LogSetting("Core_UseMultiCore", Settings::values.use_multi_core.GetValue()); + LogSetting("Renderer_UseResolutionFactor", Settings::values.resolution_factor.GetValue()); + LogSetting("Renderer_UseFrameLimit", Settings::values.use_frame_limit.GetValue()); + LogSetting("Renderer_FrameLimit", Settings::values.frame_limit.GetValue()); + LogSetting("Renderer_UseDiskShaderCache", Settings::values.use_disk_shader_cache.GetValue()); + LogSetting("Renderer_GPUAccuracyLevel", Settings::values.gpu_accuracy.GetValue()); LogSetting("Renderer_UseAsynchronousGpuEmulation", - Settings::values.use_asynchronous_gpu_emulation); - LogSetting("Renderer_UseVsync", Settings::values.use_vsync); - LogSetting("Renderer_UseAssemblyShaders", Settings::values.use_assembly_shaders); - LogSetting("Renderer_AnisotropicFilteringLevel", Settings::values.max_anisotropy); + Settings::values.use_asynchronous_gpu_emulation.GetValue()); + LogSetting("Renderer_UseVsync", Settings::values.use_vsync.GetValue()); + LogSetting("Renderer_UseAssemblyShaders", Settings::values.use_assembly_shaders.GetValue()); + LogSetting("Renderer_AnisotropicFilteringLevel", Settings::values.max_anisotropy.GetValue()); LogSetting("Audio_OutputEngine", Settings::values.sink_id); - LogSetting("Audio_EnableAudioStretching", Settings::values.enable_audio_stretching); + LogSetting("Audio_EnableAudioStretching", Settings::values.enable_audio_stretching.GetValue()); LogSetting("Audio_OutputDevice", Settings::values.audio_device_id); LogSetting("DataStorage_UseVirtualSd", Settings::values.use_virtual_sd); LogSetting("DataStorage_NandDir", FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)); @@ -131,15 +132,56 @@ float Volume() { if (values.audio_muted) { return 0.0f; } - return values.volume; + return values.volume.GetValue(); } bool IsGPULevelExtreme() { - return values.gpu_accuracy == GPUAccuracy::Extreme; + return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme; } bool IsGPULevelHigh() { - return values.gpu_accuracy == GPUAccuracy::Extreme || values.gpu_accuracy == GPUAccuracy::High; + return values.gpu_accuracy.GetValue() == GPUAccuracy::Extreme || + values.gpu_accuracy.GetValue() == GPUAccuracy::High; +} + +void RestoreGlobalState() { + // If a game is running, DO NOT restore the global settings state + if (Core::System::GetInstance().IsPoweredOn()) { + return; + } + + // Audio + values.enable_audio_stretching.SetGlobal(true); + values.volume.SetGlobal(true); + + // Core + values.use_multi_core.SetGlobal(true); + + // Renderer + values.renderer_backend.SetGlobal(true); + values.vulkan_device.SetGlobal(true); + values.aspect_ratio.SetGlobal(true); + values.max_anisotropy.SetGlobal(true); + values.use_frame_limit.SetGlobal(true); + values.frame_limit.SetGlobal(true); + values.use_disk_shader_cache.SetGlobal(true); + values.gpu_accuracy.SetGlobal(true); + values.use_asynchronous_gpu_emulation.SetGlobal(true); + values.use_vsync.SetGlobal(true); + values.use_assembly_shaders.SetGlobal(true); + values.use_fast_gpu_time.SetGlobal(true); + values.force_30fps_mode.SetGlobal(true); + values.bg_red.SetGlobal(true); + values.bg_green.SetGlobal(true); + values.bg_blue.SetGlobal(true); + + // System + values.language_index.SetGlobal(true); + values.region_index.SetGlobal(true); + values.time_zone_index.SetGlobal(true); + values.rng_seed.SetGlobal(true); + values.custom_rtc.SetGlobal(true); + values.sound_index.SetGlobal(true); } } // namespace Settings diff --git a/src/core/settings.h b/src/core/settings.h index a598ccbc1..850ca4072 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -382,20 +382,85 @@ enum class GPUAccuracy : u32 { Extreme = 2, }; +extern bool configuring_global; + +template +class Setting final { +public: + Setting() = default; + explicit Setting(Type val) : global{val} {} + ~Setting() = default; + void SetGlobal(bool to_global) { + use_global = to_global; + } + bool UsingGlobal() const { + return use_global; + } + Type GetValue(bool need_global = false) const { + if (use_global || need_global) { + return global; + } + return local; + } + void SetValue(const Type& value) { + if (use_global) { + global = value; + } else { + local = value; + } + } + +private: + bool use_global = true; + Type global{}; + Type local{}; +}; + struct Values { + // Audio + std::string audio_device_id; + std::string sink_id; + bool audio_muted; + Setting enable_audio_stretching; + Setting volume; + + // Core + Setting use_multi_core; + + // Renderer + Setting renderer_backend; + bool renderer_debug; + Setting vulkan_device; + + Setting resolution_factor = Setting(static_cast(1)); + Setting aspect_ratio; + Setting max_anisotropy; + Setting use_frame_limit; + Setting frame_limit; + Setting use_disk_shader_cache; + Setting gpu_accuracy; + Setting use_asynchronous_gpu_emulation; + Setting use_vsync; + Setting use_assembly_shaders; + Setting force_30fps_mode; + Setting use_fast_gpu_time; + + Setting bg_red; + Setting bg_green; + Setting bg_blue; + // System - bool use_docked_mode; - std::optional rng_seed; + Setting> rng_seed; // Measured in seconds since epoch - std::optional custom_rtc; + Setting> custom_rtc; // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` std::chrono::seconds custom_rtc_differential; s32 current_user; - s32 language_index; - s32 region_index; - s32 time_zone_index; - s32 sound_index; + Setting language_index; + Setting region_index; + Setting time_zone_index; + Setting sound_index; // Controls std::array players; @@ -419,8 +484,7 @@ struct Values { u16 udp_input_port; u8 udp_pad_index; - // Core - bool use_multi_core; + bool use_docked_mode; // Data Storage bool use_virtual_sd; @@ -432,39 +496,6 @@ struct Values { NANDUserSize nand_user_size; SDMCSize sdmc_size; - // Renderer - RendererBackend renderer_backend; - bool renderer_debug; - int vulkan_device; - - u16 resolution_factor{1}; - int aspect_ratio; - int max_anisotropy; - bool use_frame_limit; - u16 frame_limit; - bool use_disk_shader_cache; - GPUAccuracy gpu_accuracy; - bool use_asynchronous_gpu_emulation; - bool use_vsync; - bool use_assembly_shaders; - bool force_30fps_mode; - bool use_fast_gpu_time; - - float bg_red; - float bg_green; - float bg_blue; - - std::string log_filter; - - bool use_dev_keys; - - // Audio - bool audio_muted; - std::string sink_id; - bool enable_audio_stretching; - std::string audio_device_id; - float volume; - // Debugging bool record_frame_times; bool use_gdbstub; @@ -477,7 +508,11 @@ struct Values { bool disable_cpu_opt; bool disable_macro_jit; - // BCAT + // Misceallaneous + std::string log_filter; + bool use_dev_keys; + + // Services std::string bcat_backend; bool bcat_boxcat_local; @@ -501,4 +536,7 @@ std::string GetTimeZoneString(); void Apply(); void LogSettings(); +// Restore the global state of all applicable settings in the Values struct +void RestoreGlobalState(); + } // namespace Settings diff --git a/src/core/telemetry_session.cpp b/src/core/telemetry_session.cpp index c781b3cfc..78915e6db 100644 --- a/src/core/telemetry_session.cpp +++ b/src/core/telemetry_session.cpp @@ -189,19 +189,24 @@ void TelemetrySession::AddInitialInfo(Loader::AppLoader& app_loader) { // Log user configuration information constexpr auto field_type = Telemetry::FieldType::UserConfig; AddField(field_type, "Audio_SinkId", Settings::values.sink_id); - AddField(field_type, "Audio_EnableAudioStretching", Settings::values.enable_audio_stretching); - AddField(field_type, "Core_UseMultiCore", Settings::values.use_multi_core); - AddField(field_type, "Renderer_Backend", TranslateRenderer(Settings::values.renderer_backend)); - AddField(field_type, "Renderer_ResolutionFactor", Settings::values.resolution_factor); - AddField(field_type, "Renderer_UseFrameLimit", Settings::values.use_frame_limit); - AddField(field_type, "Renderer_FrameLimit", Settings::values.frame_limit); - AddField(field_type, "Renderer_UseDiskShaderCache", Settings::values.use_disk_shader_cache); + AddField(field_type, "Audio_EnableAudioStretching", + Settings::values.enable_audio_stretching.GetValue()); + AddField(field_type, "Core_UseMultiCore", Settings::values.use_multi_core.GetValue()); + AddField(field_type, "Renderer_Backend", + TranslateRenderer(Settings::values.renderer_backend.GetValue())); + AddField(field_type, "Renderer_ResolutionFactor", + Settings::values.resolution_factor.GetValue()); + AddField(field_type, "Renderer_UseFrameLimit", Settings::values.use_frame_limit.GetValue()); + AddField(field_type, "Renderer_FrameLimit", Settings::values.frame_limit.GetValue()); + AddField(field_type, "Renderer_UseDiskShaderCache", + Settings::values.use_disk_shader_cache.GetValue()); AddField(field_type, "Renderer_GPUAccuracyLevel", - TranslateGPUAccuracyLevel(Settings::values.gpu_accuracy)); + TranslateGPUAccuracyLevel(Settings::values.gpu_accuracy.GetValue())); AddField(field_type, "Renderer_UseAsynchronousGpuEmulation", - Settings::values.use_asynchronous_gpu_emulation); - AddField(field_type, "Renderer_UseVsync", Settings::values.use_vsync); - AddField(field_type, "Renderer_UseAssemblyShaders", Settings::values.use_assembly_shaders); + Settings::values.use_asynchronous_gpu_emulation.GetValue()); + AddField(field_type, "Renderer_UseVsync", Settings::values.use_vsync.GetValue()); + AddField(field_type, "Renderer_UseAssemblyShaders", + Settings::values.use_assembly_shaders.GetValue()); AddField(field_type, "System_UseDockedMode", Settings::values.use_docked_mode); } diff --git a/src/video_core/buffer_cache/buffer_cache.h b/src/video_core/buffer_cache/buffer_cache.h index c6479af9f..dd7ce8c99 100644 --- a/src/video_core/buffer_cache/buffer_cache.h +++ b/src/video_core/buffer_cache/buffer_cache.h @@ -96,7 +96,8 @@ public: } if (is_written) { map->MarkAsModified(true, GetModifiedTicks()); - if (Settings::IsGPULevelHigh() && Settings::values.use_asynchronous_gpu_emulation) { + if (Settings::IsGPULevelHigh() && + Settings::values.use_asynchronous_gpu_emulation.GetValue()) { MarkForAsyncFlush(map); } if (!map->is_written) { @@ -369,7 +370,8 @@ private: } if (modified_inheritance) { map->MarkAsModified(true, GetModifiedTicks()); - if (Settings::IsGPULevelHigh() && Settings::values.use_asynchronous_gpu_emulation) { + if (Settings::IsGPULevelHigh() && + Settings::values.use_asynchronous_gpu_emulation.GetValue()) { MarkForAsyncFlush(map); } } diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 482e49711..758bfe148 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -157,7 +157,7 @@ u64 GPU::GetTicks() const { constexpr u64 gpu_ticks_den = 625; u64 nanoseconds = system.CoreTiming().GetGlobalTimeNs().count(); - if (Settings::values.use_fast_gpu_time) { + if (Settings::values.use_fast_gpu_time.GetValue()) { nanoseconds /= 256; } const u64 nanoseconds_num = nanoseconds / gpu_ticks_den; diff --git a/src/video_core/query_cache.h b/src/video_core/query_cache.h index e12dab899..0d3a88765 100644 --- a/src/video_core/query_cache.h +++ b/src/video_core/query_cache.h @@ -132,7 +132,7 @@ public: } query->BindCounter(Stream(type).Current(), timestamp); - if (Settings::values.use_asynchronous_gpu_emulation) { + if (Settings::values.use_asynchronous_gpu_emulation.GetValue()) { AsyncFlushQuery(cpu_addr); } } diff --git a/src/video_core/renderer_base.cpp b/src/video_core/renderer_base.cpp index 919d1f2d4..dfb06e87e 100644 --- a/src/video_core/renderer_base.cpp +++ b/src/video_core/renderer_base.cpp @@ -18,7 +18,7 @@ RendererBase::~RendererBase() = default; void RendererBase::RefreshBaseSettings() { UpdateCurrentFramebufferLayout(); - renderer_settings.use_framelimiter = Settings::values.use_frame_limit; + renderer_settings.use_framelimiter = Settings::values.use_frame_limit.GetValue(); renderer_settings.set_background_color = true; } diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp index 208fc6167..c1f20f0ab 100644 --- a/src/video_core/renderer_opengl/gl_device.cpp +++ b/src/video_core/renderer_opengl/gl_device.cpp @@ -229,15 +229,15 @@ Device::Device() // uniform buffers as "push constants" has_fast_buffer_sub_data = is_nvidia && !disable_fast_buffer_sub_data; - use_assembly_shaders = Settings::values.use_assembly_shaders && GLAD_GL_NV_gpu_program5 && - GLAD_GL_NV_compute_program5 && GLAD_GL_NV_transform_feedback && - GLAD_GL_NV_transform_feedback2; + use_assembly_shaders = Settings::values.use_assembly_shaders.GetValue() && + GLAD_GL_NV_gpu_program5 && GLAD_GL_NV_compute_program5 && + GLAD_GL_NV_transform_feedback && GLAD_GL_NV_transform_feedback2; LOG_INFO(Render_OpenGL, "Renderer_VariableAOFFI: {}", has_variable_aoffi); LOG_INFO(Render_OpenGL, "Renderer_ComponentIndexingBug: {}", has_component_indexing_bug); LOG_INFO(Render_OpenGL, "Renderer_PreciseBug: {}", has_precise_bug); - if (Settings::values.use_assembly_shaders && !use_assembly_shaders) { + if (Settings::values.use_assembly_shaders.GetValue() && !use_assembly_shaders) { LOG_ERROR(Render_OpenGL, "Assembly shaders enabled but not supported"); } } diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 653c3f2f9..2dcc2b0eb 100644 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -213,7 +213,7 @@ ShaderDiskCacheOpenGL::~ShaderDiskCacheOpenGL() = default; std::optional> ShaderDiskCacheOpenGL::LoadTransferable() { // Skip games without title id const bool has_title_id = system.CurrentProcess()->GetTitleID() != 0; - if (!Settings::values.use_disk_shader_cache || !has_title_id) { + if (!Settings::values.use_disk_shader_cache.GetValue() || !has_title_id) { return {}; } diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index c40adb6e7..e66cdc083 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -455,8 +455,8 @@ void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color void RendererOpenGL::InitOpenGLObjects() { frame_mailbox = std::make_unique(); - glClearColor(Settings::values.bg_red, Settings::values.bg_green, Settings::values.bg_blue, - 0.0f); + glClearColor(Settings::values.bg_red.GetValue(), Settings::values.bg_green.GetValue(), + Settings::values.bg_blue.GetValue(), 0.0f); // Create shader programs OGLShader vertex_shader; @@ -561,8 +561,8 @@ void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture, void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) { if (renderer_settings.set_background_color) { // Update background color before drawing - glClearColor(Settings::values.bg_red, Settings::values.bg_green, Settings::values.bg_blue, - 0.0f); + glClearColor(Settings::values.bg_red.GetValue(), Settings::values.bg_green.GetValue(), + Settings::values.bg_blue.GetValue(), 0.0f); } // Set projection matrix diff --git a/src/video_core/renderer_vulkan/renderer_vulkan.cpp b/src/video_core/renderer_vulkan/renderer_vulkan.cpp index 2d9b18ed9..2258479f5 100644 --- a/src/video_core/renderer_vulkan/renderer_vulkan.cpp +++ b/src/video_core/renderer_vulkan/renderer_vulkan.cpp @@ -409,7 +409,7 @@ bool RendererVulkan::PickDevices() { return false; } - const s32 device_index = Settings::values.vulkan_device; + const s32 device_index = Settings::values.vulkan_device.GetValue(); if (device_index < 0 || device_index >= static_cast(devices->size())) { LOG_ERROR(Render_Vulkan, "Invalid device index {}!", device_index); return false; diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 6207d8dfe..cdcddb225 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h @@ -249,7 +249,7 @@ public: auto& surface = render_targets[index].target; surface->MarkAsRenderTarget(false, NO_RT); const auto& cr_params = surface->GetSurfaceParams(); - if (!cr_params.is_tiled && Settings::values.use_asynchronous_gpu_emulation) { + if (!cr_params.is_tiled && Settings::values.use_asynchronous_gpu_emulation.GetValue()) { AsyncFlushSurface(surface); } } diff --git a/src/video_core/textures/texture.cpp b/src/video_core/textures/texture.cpp index d1939d744..4171e3ef2 100644 --- a/src/video_core/textures/texture.cpp +++ b/src/video_core/textures/texture.cpp @@ -48,7 +48,7 @@ constexpr std::array SRGB_CONVERSION_LUT = { }; unsigned SettingsMinimumAnisotropy() noexcept { - switch (static_cast(Settings::values.max_anisotropy)) { + switch (static_cast(Settings::values.max_anisotropy.GetValue())) { default: case Anisotropy::Default: return 1U; diff --git a/src/video_core/video_core.cpp b/src/video_core/video_core.cpp index f60bdc60a..45f360bdd 100644 --- a/src/video_core/video_core.cpp +++ b/src/video_core/video_core.cpp @@ -19,7 +19,7 @@ namespace { std::unique_ptr CreateRenderer(Core::Frontend::EmuWindow& emu_window, Core::System& system, Core::Frontend::GraphicsContext& context) { - switch (Settings::values.renderer_backend) { + switch (Settings::values.renderer_backend.GetValue()) { case Settings::RendererBackend::OpenGL: return std::make_unique(emu_window, system, context); #ifdef HAS_VULKAN @@ -42,7 +42,7 @@ std::unique_ptr CreateGPU(Core::Frontend::EmuWindow& emu_window, Cor return nullptr; } - if (Settings::values.use_asynchronous_gpu_emulation) { + if (Settings::values.use_asynchronous_gpu_emulation.GetValue()) { return std::make_unique(system, std::move(renderer), std::move(context)); } @@ -51,8 +51,8 @@ std::unique_ptr CreateGPU(Core::Frontend::EmuWindow& emu_window, Cor u16 GetResolutionScaleFactor(const RendererBase& renderer) { return static_cast( - Settings::values.resolution_factor != 0 - ? Settings::values.resolution_factor + Settings::values.resolution_factor.GetValue() != 0 + ? Settings::values.resolution_factor.GetValue() : renderer.GetRenderWindow().GetFramebufferLayout().GetScalingRatio()); } diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 75c27e39e..742b72856 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -24,6 +24,8 @@ add_executable(yuzu compatibility_list.h configuration/config.cpp configuration/config.h + configuration/configuration_shared.cpp + configuration/configuration_shared.h configuration/configure.ui configuration/configure_audio.cpp configuration/configure_audio.h @@ -60,9 +62,12 @@ add_executable(yuzu configuration/configure_mouse_advanced.cpp configuration/configure_mouse_advanced.h configuration/configure_mouse_advanced.ui - configuration/configure_per_general.cpp - configuration/configure_per_general.h - configuration/configure_per_general.ui + configuration/configure_per_game.cpp + configuration/configure_per_game.h + configuration/configure_per_game.ui + configuration/configure_per_game_addons.cpp + configuration/configure_per_game_addons.h + configuration/configure_per_game_addons.ui configuration/configure_profile_manager.cpp configuration/configure_profile_manager.h configuration/configure_profile_manager.ui diff --git a/src/yuzu/bootmanager.cpp b/src/yuzu/bootmanager.cpp index 4bfce48a4..5738787ac 100644 --- a/src/yuzu/bootmanager.cpp +++ b/src/yuzu/bootmanager.cpp @@ -145,7 +145,7 @@ public: // disable vsync for any shared contexts auto format = share_context->format(); - format.setSwapInterval(main_surface ? Settings::values.use_vsync : 0); + format.setSwapInterval(main_surface ? Settings::values.use_vsync.GetValue() : 0); context = std::make_unique(); context->setShareContext(share_context); @@ -495,7 +495,7 @@ void GRenderWindow::resizeEvent(QResizeEvent* event) { std::unique_ptr GRenderWindow::CreateSharedContext() const { #ifdef HAS_OPENGL - if (Settings::values.renderer_backend == Settings::RendererBackend::OpenGL) { + if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL) { auto c = static_cast(main_context.get()); // Bind the shared contexts to the main surface in case the backend wants to take over // presentation @@ -511,7 +511,7 @@ bool GRenderWindow::InitRenderTarget() { first_frame = false; - switch (Settings::values.renderer_backend) { + switch (Settings::values.renderer_backend.GetValue()) { case Settings::RendererBackend::OpenGL: if (!InitializeOpenGL()) { return false; @@ -538,7 +538,7 @@ bool GRenderWindow::InitRenderTarget() { OnFramebufferSizeChanged(); BackupGeometry(); - if (Settings::values.renderer_backend == Settings::RendererBackend::OpenGL) { + if (Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::OpenGL) { if (!LoadOpenGL()) { return false; } diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 5e0d0e7af..1b2b1b2bb 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -13,17 +13,20 @@ #include "input_common/udp/client.h" #include "yuzu/configuration/config.h" -Config::Config() { +Config::Config(const std::string& config_file, bool is_global) { // TODO: Don't hardcode the path; let the frontend decide where to put the config files. - qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + "qt-config.ini"; + qt_config_loc = FileUtil::GetUserPath(FileUtil::UserPath::ConfigDir) + config_file; FileUtil::CreateFullPath(qt_config_loc); qt_config = std::make_unique(QString::fromStdString(qt_config_loc), QSettings::IniFormat); + global = is_global; Reload(); } Config::~Config() { - Save(); + if (global) { + Save(); + } } const std::array Config::default_buttons = { @@ -402,16 +405,19 @@ void Config::ApplyDefaultProfileIfInputInvalid() { void Config::ReadAudioValues() { qt_config->beginGroup(QStringLiteral("Audio")); - Settings::values.sink_id = ReadSetting(QStringLiteral("output_engine"), QStringLiteral("auto")) - .toString() - .toStdString(); - Settings::values.enable_audio_stretching = - ReadSetting(QStringLiteral("enable_audio_stretching"), true).toBool(); - Settings::values.audio_device_id = - ReadSetting(QStringLiteral("output_device"), QStringLiteral("auto")) - .toString() - .toStdString(); - Settings::values.volume = ReadSetting(QStringLiteral("volume"), 1).toFloat(); + if (global) { + Settings::values.sink_id = + ReadSetting(QStringLiteral("output_engine"), QStringLiteral("auto")) + .toString() + .toStdString(); + Settings::values.audio_device_id = + ReadSetting(QStringLiteral("output_device"), QStringLiteral("auto")) + .toString() + .toStdString(); + } + ReadSettingGlobal(Settings::values.enable_audio_stretching, + QStringLiteral("enable_audio_stretching"), true); + ReadSettingGlobal(Settings::values.volume, QStringLiteral("volume"), 1); qt_config->endGroup(); } @@ -440,6 +446,8 @@ void Config::ReadControlValues() { .toInt()); Settings::values.udp_pad_index = static_cast(ReadSetting(QStringLiteral("udp_pad_index"), 0).toUInt()); + Settings::values.use_docked_mode = + ReadSetting(QStringLiteral("use_docked_mode"), false).toBool(); qt_config->endGroup(); } @@ -447,7 +455,7 @@ void Config::ReadControlValues() { void Config::ReadCoreValues() { qt_config->beginGroup(QStringLiteral("Core")); - Settings::values.use_multi_core = ReadSetting(QStringLiteral("use_multi_core"), false).toBool(); + ReadSettingGlobal(Settings::values.use_multi_core, QStringLiteral("use_multi_core"), false); qt_config->endGroup(); } @@ -628,32 +636,28 @@ void Config::ReadPathValues() { void Config::ReadRendererValues() { qt_config->beginGroup(QStringLiteral("Renderer")); - Settings::values.renderer_backend = - static_cast(ReadSetting(QStringLiteral("backend"), 0).toInt()); - Settings::values.renderer_debug = ReadSetting(QStringLiteral("debug"), false).toBool(); - Settings::values.vulkan_device = ReadSetting(QStringLiteral("vulkan_device"), 0).toInt(); - Settings::values.aspect_ratio = ReadSetting(QStringLiteral("aspect_ratio"), 0).toInt(); - Settings::values.max_anisotropy = ReadSetting(QStringLiteral("max_anisotropy"), 0).toInt(); - Settings::values.use_frame_limit = - ReadSetting(QStringLiteral("use_frame_limit"), true).toBool(); - Settings::values.frame_limit = ReadSetting(QStringLiteral("frame_limit"), 100).toUInt(); - Settings::values.use_disk_shader_cache = - ReadSetting(QStringLiteral("use_disk_shader_cache"), true).toBool(); - const int gpu_accuracy_level = ReadSetting(QStringLiteral("gpu_accuracy"), 0).toInt(); - Settings::values.gpu_accuracy = static_cast(gpu_accuracy_level); - Settings::values.use_asynchronous_gpu_emulation = - ReadSetting(QStringLiteral("use_asynchronous_gpu_emulation"), false).toBool(); - Settings::values.use_vsync = ReadSetting(QStringLiteral("use_vsync"), true).toBool(); - Settings::values.use_assembly_shaders = - ReadSetting(QStringLiteral("use_assembly_shaders"), false).toBool(); - Settings::values.use_fast_gpu_time = - ReadSetting(QStringLiteral("use_fast_gpu_time"), true).toBool(); - Settings::values.force_30fps_mode = - ReadSetting(QStringLiteral("force_30fps_mode"), false).toBool(); + ReadSettingGlobal(Settings::values.renderer_backend, QStringLiteral("backend"), 0); + ReadSettingGlobal(Settings::values.renderer_debug, QStringLiteral("debug"), false); + ReadSettingGlobal(Settings::values.vulkan_device, QStringLiteral("vulkan_device"), 0); + ReadSettingGlobal(Settings::values.aspect_ratio, QStringLiteral("aspect_ratio"), 0); + ReadSettingGlobal(Settings::values.max_anisotropy, QStringLiteral("max_anisotropy"), 0); + ReadSettingGlobal(Settings::values.use_frame_limit, QStringLiteral("use_frame_limit"), true); + ReadSettingGlobal(Settings::values.frame_limit, QStringLiteral("frame_limit"), 100); + ReadSettingGlobal(Settings::values.use_disk_shader_cache, + QStringLiteral("use_disk_shader_cache"), true); + ReadSettingGlobal(Settings::values.gpu_accuracy, QStringLiteral("gpu_accuracy"), 0); + ReadSettingGlobal(Settings::values.use_asynchronous_gpu_emulation, + QStringLiteral("use_asynchronous_gpu_emulation"), false); + ReadSettingGlobal(Settings::values.use_vsync, QStringLiteral("use_vsync"), true); + ReadSettingGlobal(Settings::values.use_assembly_shaders, QStringLiteral("use_assembly_shaders"), + false); + ReadSettingGlobal(Settings::values.use_fast_gpu_time, QStringLiteral("use_fast_gpu_time"), + true); + ReadSettingGlobal(Settings::values.force_30fps_mode, QStringLiteral("force_30fps_mode"), false); - Settings::values.bg_red = ReadSetting(QStringLiteral("bg_red"), 0.0).toFloat(); - Settings::values.bg_green = ReadSetting(QStringLiteral("bg_green"), 0.0).toFloat(); - Settings::values.bg_blue = ReadSetting(QStringLiteral("bg_blue"), 0.0).toFloat(); + ReadSettingGlobal(Settings::values.bg_red, QStringLiteral("bg_red"), 0.0); + ReadSettingGlobal(Settings::values.bg_green, QStringLiteral("bg_green"), 0.0); + ReadSettingGlobal(Settings::values.bg_blue, QStringLiteral("bg_blue"), 0.0); qt_config->endGroup(); } @@ -682,35 +686,45 @@ void Config::ReadShortcutValues() { void Config::ReadSystemValues() { qt_config->beginGroup(QStringLiteral("System")); - Settings::values.use_docked_mode = - ReadSetting(QStringLiteral("use_docked_mode"), false).toBool(); + ReadSettingGlobal(Settings::values.current_user, QStringLiteral("current_user"), 0); + Settings::values.current_user = + std::clamp(Settings::values.current_user, 0, Service::Account::MAX_USERS - 1); - Settings::values.current_user = std::clamp( - ReadSetting(QStringLiteral("current_user"), 0).toInt(), 0, Service::Account::MAX_USERS - 1); + ReadSettingGlobal(Settings::values.language_index, QStringLiteral("language_index"), 1); - Settings::values.language_index = ReadSetting(QStringLiteral("language_index"), 1).toInt(); + ReadSettingGlobal(Settings::values.region_index, QStringLiteral("region_index"), 1); - Settings::values.region_index = ReadSetting(QStringLiteral("region_index"), 1).toInt(); + ReadSettingGlobal(Settings::values.time_zone_index, QStringLiteral("time_zone_index"), 0); - Settings::values.time_zone_index = ReadSetting(QStringLiteral("time_zone_index"), 0).toInt(); - - const auto rng_seed_enabled = ReadSetting(QStringLiteral("rng_seed_enabled"), false).toBool(); - if (rng_seed_enabled) { - Settings::values.rng_seed = ReadSetting(QStringLiteral("rng_seed"), 0).toULongLong(); - } else { - Settings::values.rng_seed = std::nullopt; + bool rng_seed_enabled; + ReadSettingGlobal(rng_seed_enabled, QStringLiteral("rng_seed_enabled"), false); + bool rng_seed_global = + global || qt_config->value(QStringLiteral("rng_seed/use_global"), true).toBool(); + Settings::values.rng_seed.SetGlobal(rng_seed_global); + if (global || !rng_seed_global) { + if (rng_seed_enabled) { + Settings::values.rng_seed.SetValue( + ReadSetting(QStringLiteral("rng_seed"), 0).toULongLong()); + } else { + Settings::values.rng_seed.SetValue(std::nullopt); + } } - const auto custom_rtc_enabled = - ReadSetting(QStringLiteral("custom_rtc_enabled"), false).toBool(); - if (custom_rtc_enabled) { - Settings::values.custom_rtc = - std::chrono::seconds(ReadSetting(QStringLiteral("custom_rtc"), 0).toULongLong()); - } else { - Settings::values.custom_rtc = std::nullopt; + bool custom_rtc_enabled; + ReadSettingGlobal(custom_rtc_enabled, QStringLiteral("custom_rtc_enabled"), false); + bool custom_rtc_global = + global || qt_config->value(QStringLiteral("custom_rtc/use_global"), true).toBool(); + Settings::values.custom_rtc.SetGlobal(custom_rtc_global); + if (global || !custom_rtc_global) { + if (custom_rtc_enabled) { + Settings::values.custom_rtc.SetValue( + std::chrono::seconds(ReadSetting(QStringLiteral("custom_rtc"), 0).toULongLong())); + } else { + Settings::values.custom_rtc.SetValue(std::nullopt); + } } - Settings::values.sound_index = ReadSetting(QStringLiteral("sound_index"), 1).toInt(); + ReadSettingGlobal(Settings::values.sound_index, QStringLiteral("sound_index"), 1); qt_config->endGroup(); } @@ -804,18 +818,20 @@ void Config::ReadWebServiceValues() { } void Config::ReadValues() { - ReadControlValues(); + if (global) { + ReadControlValues(); + ReadDataStorageValues(); + ReadDebuggingValues(); + ReadDisabledAddOnValues(); + ReadServiceValues(); + ReadUIValues(); + ReadWebServiceValues(); + ReadMiscellaneousValues(); + } ReadCoreValues(); ReadRendererValues(); ReadAudioValues(); - ReadDataStorageValues(); ReadSystemValues(); - ReadMiscellaneousValues(); - ReadDebuggingValues(); - ReadWebServiceValues(); - ReadServiceValues(); - ReadDisabledAddOnValues(); - ReadUIValues(); } void Config::SavePlayerValues() { @@ -902,30 +918,35 @@ void Config::SaveTouchscreenValues() { } void Config::SaveValues() { - SaveControlValues(); + if (global) { + SaveControlValues(); + SaveDataStorageValues(); + SaveDebuggingValues(); + SaveDisabledAddOnValues(); + SaveServiceValues(); + SaveUIValues(); + SaveWebServiceValues(); + SaveMiscellaneousValues(); + } SaveCoreValues(); SaveRendererValues(); SaveAudioValues(); - SaveDataStorageValues(); SaveSystemValues(); - SaveMiscellaneousValues(); - SaveDebuggingValues(); - SaveWebServiceValues(); - SaveServiceValues(); - SaveDisabledAddOnValues(); - SaveUIValues(); } void Config::SaveAudioValues() { qt_config->beginGroup(QStringLiteral("Audio")); - WriteSetting(QStringLiteral("output_engine"), QString::fromStdString(Settings::values.sink_id), - QStringLiteral("auto")); - WriteSetting(QStringLiteral("enable_audio_stretching"), - Settings::values.enable_audio_stretching, true); - WriteSetting(QStringLiteral("output_device"), - QString::fromStdString(Settings::values.audio_device_id), QStringLiteral("auto")); - WriteSetting(QStringLiteral("volume"), Settings::values.volume, 1.0f); + if (global) { + WriteSetting(QStringLiteral("output_engine"), + QString::fromStdString(Settings::values.sink_id), QStringLiteral("auto")); + WriteSetting(QStringLiteral("output_device"), + QString::fromStdString(Settings::values.audio_device_id), + QStringLiteral("auto")); + } + WriteSettingGlobal(QStringLiteral("enable_audio_stretching"), + Settings::values.enable_audio_stretching, true); + WriteSettingGlobal(QStringLiteral("volume"), Settings::values.volume, 1.0f); qt_config->endGroup(); } @@ -948,6 +969,7 @@ void Config::SaveControlValues() { WriteSetting(QStringLiteral("udp_input_port"), Settings::values.udp_input_port, InputCommon::CemuhookUDP::DEFAULT_PORT); WriteSetting(QStringLiteral("udp_pad_index"), Settings::values.udp_pad_index, 0); + WriteSetting(QStringLiteral("use_docked_mode"), Settings::values.use_docked_mode, false); qt_config->endGroup(); } @@ -955,7 +977,7 @@ void Config::SaveControlValues() { void Config::SaveCoreValues() { qt_config->beginGroup(QStringLiteral("Core")); - WriteSetting(QStringLiteral("use_multi_core"), Settings::values.use_multi_core, false); + WriteSettingGlobal(QStringLiteral("use_multi_core"), Settings::values.use_multi_core, false); qt_config->endGroup(); } @@ -1078,29 +1100,34 @@ void Config::SavePathValues() { void Config::SaveRendererValues() { qt_config->beginGroup(QStringLiteral("Renderer")); - WriteSetting(QStringLiteral("backend"), static_cast(Settings::values.renderer_backend), 0); + WriteSettingGlobal(QStringLiteral("backend"), + static_cast(Settings::values.renderer_backend.GetValue(global)), + Settings::values.renderer_backend.UsingGlobal(), 0); WriteSetting(QStringLiteral("debug"), Settings::values.renderer_debug, false); - WriteSetting(QStringLiteral("vulkan_device"), Settings::values.vulkan_device, 0); - WriteSetting(QStringLiteral("aspect_ratio"), Settings::values.aspect_ratio, 0); - WriteSetting(QStringLiteral("max_anisotropy"), Settings::values.max_anisotropy, 0); - WriteSetting(QStringLiteral("use_frame_limit"), Settings::values.use_frame_limit, true); - WriteSetting(QStringLiteral("frame_limit"), Settings::values.frame_limit, 100); - WriteSetting(QStringLiteral("use_disk_shader_cache"), Settings::values.use_disk_shader_cache, - true); - WriteSetting(QStringLiteral("gpu_accuracy"), static_cast(Settings::values.gpu_accuracy), - 0); - WriteSetting(QStringLiteral("use_asynchronous_gpu_emulation"), - Settings::values.use_asynchronous_gpu_emulation, false); - WriteSetting(QStringLiteral("use_vsync"), Settings::values.use_vsync, true); - WriteSetting(QStringLiteral("use_assembly_shaders"), Settings::values.use_assembly_shaders, - false); - WriteSetting(QStringLiteral("use_fast_gpu_time"), Settings::values.use_fast_gpu_time, true); - WriteSetting(QStringLiteral("force_30fps_mode"), Settings::values.force_30fps_mode, false); + WriteSettingGlobal(QStringLiteral("vulkan_device"), Settings::values.vulkan_device, 0); + WriteSettingGlobal(QStringLiteral("aspect_ratio"), Settings::values.aspect_ratio, 0); + WriteSettingGlobal(QStringLiteral("max_anisotropy"), Settings::values.max_anisotropy, 0); + WriteSettingGlobal(QStringLiteral("use_frame_limit"), Settings::values.use_frame_limit, true); + WriteSettingGlobal(QStringLiteral("frame_limit"), Settings::values.frame_limit, 100); + WriteSettingGlobal(QStringLiteral("use_disk_shader_cache"), + Settings::values.use_disk_shader_cache, true); + WriteSettingGlobal(QStringLiteral("gpu_accuracy"), + static_cast(Settings::values.gpu_accuracy.GetValue(global)), + Settings::values.gpu_accuracy.UsingGlobal(), 0); + WriteSettingGlobal(QStringLiteral("use_asynchronous_gpu_emulation"), + Settings::values.use_asynchronous_gpu_emulation, false); + WriteSettingGlobal(QStringLiteral("use_vsync"), Settings::values.use_vsync, true); + WriteSettingGlobal(QStringLiteral("use_assembly_shaders"), + Settings::values.use_assembly_shaders, false); + WriteSettingGlobal(QStringLiteral("use_fast_gpu_time"), Settings::values.use_fast_gpu_time, + true); + WriteSettingGlobal(QStringLiteral("force_30fps_mode"), Settings::values.force_30fps_mode, + false); // Cast to double because Qt's written float values are not human-readable - WriteSetting(QStringLiteral("bg_red"), static_cast(Settings::values.bg_red), 0.0); - WriteSetting(QStringLiteral("bg_green"), static_cast(Settings::values.bg_green), 0.0); - WriteSetting(QStringLiteral("bg_blue"), static_cast(Settings::values.bg_blue), 0.0); + WriteSettingGlobal(QStringLiteral("bg_red"), Settings::values.bg_red, 0.0); + WriteSettingGlobal(QStringLiteral("bg_green"), Settings::values.bg_green, 0.0); + WriteSettingGlobal(QStringLiteral("bg_blue"), Settings::values.bg_blue, 0.0); qt_config->endGroup(); } @@ -1128,23 +1155,28 @@ void Config::SaveShortcutValues() { void Config::SaveSystemValues() { qt_config->beginGroup(QStringLiteral("System")); - WriteSetting(QStringLiteral("use_docked_mode"), Settings::values.use_docked_mode, false); WriteSetting(QStringLiteral("current_user"), Settings::values.current_user, 0); - WriteSetting(QStringLiteral("language_index"), Settings::values.language_index, 1); - WriteSetting(QStringLiteral("region_index"), Settings::values.region_index, 1); - WriteSetting(QStringLiteral("time_zone_index"), Settings::values.time_zone_index, 0); + WriteSettingGlobal(QStringLiteral("language_index"), Settings::values.language_index, 1); + WriteSettingGlobal(QStringLiteral("region_index"), Settings::values.region_index, 1); + WriteSettingGlobal(QStringLiteral("time_zone_index"), Settings::values.time_zone_index, 0); - WriteSetting(QStringLiteral("rng_seed_enabled"), Settings::values.rng_seed.has_value(), false); - WriteSetting(QStringLiteral("rng_seed"), Settings::values.rng_seed.value_or(0), 0); + WriteSettingGlobal(QStringLiteral("rng_seed_enabled"), + Settings::values.rng_seed.GetValue(global).has_value(), + Settings::values.rng_seed.UsingGlobal(), false); + WriteSettingGlobal(QStringLiteral("rng_seed"), + Settings::values.rng_seed.GetValue(global).value_or(0), + Settings::values.rng_seed.UsingGlobal(), 0); - WriteSetting(QStringLiteral("custom_rtc_enabled"), Settings::values.custom_rtc.has_value(), - false); - WriteSetting(QStringLiteral("custom_rtc"), - QVariant::fromValue( - Settings::values.custom_rtc.value_or(std::chrono::seconds{}).count()), - 0); + WriteSettingGlobal(QStringLiteral("custom_rtc_enabled"), + Settings::values.custom_rtc.GetValue(global).has_value(), + Settings::values.custom_rtc.UsingGlobal(), false); + WriteSettingGlobal( + QStringLiteral("custom_rtc"), + QVariant::fromValue( + Settings::values.custom_rtc.GetValue(global).value_or(std::chrono::seconds{}).count()), + Settings::values.custom_rtc.UsingGlobal(), 0); - WriteSetting(QStringLiteral("sound_index"), Settings::values.sound_index, 1); + WriteSettingGlobal(QStringLiteral("sound_index"), Settings::values.sound_index, 1); qt_config->endGroup(); } @@ -1236,6 +1268,34 @@ QVariant Config::ReadSetting(const QString& name, const QVariant& default_value) return result; } +template +void Config::ReadSettingGlobal(Settings::Setting& setting, const QString& name) { + const bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool(); + setting.SetGlobal(use_global); + if (global || !use_global) { + setting.SetValue(ReadSetting(name).value()); + } +} + +template +void Config::ReadSettingGlobal(Settings::Setting& setting, const QString& name, + const QVariant& default_value) { + const bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool(); + setting.SetGlobal(use_global); + if (global || !use_global) { + setting.SetValue(ReadSetting(name, default_value).value()); + } +} + +template +void Config::ReadSettingGlobal(Type& setting, const QString& name, + const QVariant& default_value) const { + const bool use_global = qt_config->value(name + QStringLiteral("/use_global"), true).toBool(); + if (global || !use_global) { + setting = ReadSetting(name, default_value).value(); + } +} + void Config::WriteSetting(const QString& name, const QVariant& value) { qt_config->setValue(name, value); } @@ -1246,6 +1306,40 @@ void Config::WriteSetting(const QString& name, const QVariant& value, qt_config->setValue(name, value); } +template +void Config::WriteSettingGlobal(const QString& name, const Settings::Setting& setting) { + if (!global) { + qt_config->setValue(name + QStringLiteral("/use_global"), setting.UsingGlobal()); + } + if (global || !setting.UsingGlobal()) { + qt_config->setValue(name, setting.GetValue(global)); + } +} + +template +void Config::WriteSettingGlobal(const QString& name, const Settings::Setting& setting, + const QVariant& default_value) { + if (!global) { + qt_config->setValue(name + QStringLiteral("/use_global"), setting.UsingGlobal()); + } + if (global || !setting.UsingGlobal()) { + qt_config->setValue(name + QStringLiteral("/default"), + setting.GetValue(global) == default_value.value()); + qt_config->setValue(name, setting.GetValue(global)); + } +} + +void Config::WriteSettingGlobal(const QString& name, const QVariant& value, bool use_global, + const QVariant& default_value) { + if (!global) { + qt_config->setValue(name + QStringLiteral("/use_global"), use_global); + } + if (global || !use_global) { + qt_config->setValue(name + QStringLiteral("/default"), value == default_value); + qt_config->setValue(name, value); + } +} + void Config::Reload() { ReadValues(); // To apply default value changes diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 09316382c..681f0bca5 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "core/settings.h" #include "yuzu/uisettings.h" @@ -15,7 +16,7 @@ class QSettings; class Config { public: - Config(); + explicit Config(const std::string& config_loc = "qt-config.ini", bool is_global = true); ~Config(); void Reload(); @@ -82,9 +83,33 @@ private: QVariant ReadSetting(const QString& name) const; QVariant ReadSetting(const QString& name, const QVariant& default_value) const; + // Templated ReadSettingGlobal functions will also look for the use_global setting and set + // both the value and the global state properly + template + void ReadSettingGlobal(Settings::Setting& setting, const QString& name); + template + void ReadSettingGlobal(Settings::Setting& setting, const QString& name, + const QVariant& default_value); + template + void ReadSettingGlobal(Type& setting, const QString& name, const QVariant& default_value) const; + // Templated WriteSettingGlobal functions will also write the global state if needed and will + // skip writing the actual setting if it defers to the global value void WriteSetting(const QString& name, const QVariant& value); void WriteSetting(const QString& name, const QVariant& value, const QVariant& default_value); + template + void WriteSettingGlobal(const QString& name, const Settings::Setting& setting); + template + void WriteSettingGlobal(const QString& name, const Settings::Setting& setting, + const QVariant& default_value); + void WriteSettingGlobal(const QString& name, const QVariant& value, bool use_global, + const QVariant& default_value); std::unique_ptr qt_config; std::string qt_config_loc; + + bool global; }; + +// These metatype declarations cannot be in core/settings.h because core is devoid of QT +Q_DECLARE_METATYPE(Settings::RendererBackend); +Q_DECLARE_METATYPE(Settings::GPUAccuracy); diff --git a/src/yuzu/configuration/configuration_shared.cpp b/src/yuzu/configuration/configuration_shared.cpp new file mode 100644 index 000000000..bb47c3933 --- /dev/null +++ b/src/yuzu/configuration/configuration_shared.cpp @@ -0,0 +1,76 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "core/settings.h" +#include "yuzu/configuration/configuration_shared.h" +#include "yuzu/configuration/configure_per_game.h" + +void ConfigurationShared::ApplyPerGameSetting(Settings::Setting* setting, + const QCheckBox* checkbox) { + if (checkbox->checkState() == Qt::PartiallyChecked) { + setting->SetGlobal(true); + } else { + setting->SetGlobal(false); + setting->SetValue(checkbox->checkState() == Qt::Checked); + } +} + +void ConfigurationShared::ApplyPerGameSetting(Settings::Setting* setting, + const QComboBox* combobox) { + if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + setting->SetGlobal(true); + } else { + setting->SetGlobal(false); + setting->SetValue(combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET); + } +} + +void ConfigurationShared::ApplyPerGameSetting(Settings::Setting* setting, + const QComboBox* combobox) { + if (combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + setting->SetGlobal(true); + } else { + setting->SetGlobal(false); + setting->SetValue(static_cast( + combobox->currentIndex() - ConfigurationShared::USE_GLOBAL_OFFSET)); + } +} + +void ConfigurationShared::SetPerGameSetting(QCheckBox* checkbox, + const Settings::Setting* setting) { + if (setting->UsingGlobal()) { + checkbox->setCheckState(Qt::PartiallyChecked); + } else { + checkbox->setCheckState(setting->GetValue() ? Qt::Checked : Qt::Unchecked); + } +} + +void ConfigurationShared::SetPerGameSetting(QComboBox* combobox, + const Settings::Setting* setting) { + combobox->setCurrentIndex(setting->UsingGlobal() + ? ConfigurationShared::USE_GLOBAL_INDEX + : setting->GetValue() + ConfigurationShared::USE_GLOBAL_OFFSET); +} + +void ConfigurationShared::SetPerGameSetting( + QComboBox* combobox, const Settings::Setting* setting) { + combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX + : static_cast(setting->GetValue()) + + ConfigurationShared::USE_GLOBAL_OFFSET); +} + +void ConfigurationShared::SetPerGameSetting( + QComboBox* combobox, const Settings::Setting* setting) { + combobox->setCurrentIndex(setting->UsingGlobal() ? ConfigurationShared::USE_GLOBAL_INDEX + : static_cast(setting->GetValue()) + + ConfigurationShared::USE_GLOBAL_OFFSET); +} + +void ConfigurationShared::InsertGlobalItem(QComboBox* combobox) { + const QString use_global_text = ConfigurePerGame::tr("Use global configuration"); + combobox->insertItem(ConfigurationShared::USE_GLOBAL_INDEX, use_global_text); + combobox->insertSeparator(ConfigurationShared::USE_GLOBAL_SEPARATOR_INDEX); +} diff --git a/src/yuzu/configuration/configuration_shared.h b/src/yuzu/configuration/configuration_shared.h new file mode 100644 index 000000000..b11b1b950 --- /dev/null +++ b/src/yuzu/configuration/configuration_shared.h @@ -0,0 +1,36 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include "core/settings.h" + +namespace ConfigurationShared { + +constexpr int USE_GLOBAL_INDEX = 0; +constexpr int USE_GLOBAL_SEPARATOR_INDEX = 1; +constexpr int USE_GLOBAL_OFFSET = 2; + +// Global-aware apply and set functions + +void ApplyPerGameSetting(Settings::Setting* setting, const QCheckBox* checkbox); +void ApplyPerGameSetting(Settings::Setting* setting, const QComboBox* combobox); +void ApplyPerGameSetting(Settings::Setting* setting, + const QComboBox* combobox); +void ApplyPerGameSetting(Settings::Setting* setting, + const QComboBox* combobox); + +void SetPerGameSetting(QCheckBox* checkbox, const Settings::Setting* setting); +void SetPerGameSetting(QComboBox* combobox, const Settings::Setting* setting); +void SetPerGameSetting(QComboBox* combobox, + const Settings::Setting* setting); +void SetPerGameSetting(QComboBox* combobox, + const Settings::Setting* setting); + +void InsertGlobalItem(QComboBox* combobox); + +} // namespace ConfigurationShared diff --git a/src/yuzu/configuration/configure_audio.cpp b/src/yuzu/configuration/configure_audio.cpp index f370c690f..cc021beec 100644 --- a/src/yuzu/configuration/configure_audio.cpp +++ b/src/yuzu/configuration/configure_audio.cpp @@ -11,6 +11,7 @@ #include "core/core.h" #include "core/settings.h" #include "ui_configure_audio.h" +#include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_audio.h" ConfigureAudio::ConfigureAudio(QWidget* parent) @@ -24,6 +25,11 @@ ConfigureAudio::ConfigureAudio(QWidget* parent) connect(ui->output_sink_combo_box, qOverload(&QComboBox::currentIndexChanged), this, &ConfigureAudio::UpdateAudioDevices); + ui->volume_label->setVisible(Settings::configuring_global); + ui->volume_combo_box->setVisible(!Settings::configuring_global); + + SetupPerGameUI(); + SetConfiguration(); const bool is_powered_on = Core::System::GetInstance().IsPoweredOn(); @@ -41,8 +47,22 @@ void ConfigureAudio::SetConfiguration() { SetAudioDeviceFromDeviceID(); - ui->toggle_audio_stretching->setChecked(Settings::values.enable_audio_stretching); - ui->volume_slider->setValue(Settings::values.volume * ui->volume_slider->maximum()); + ui->volume_slider->setValue(Settings::values.volume.GetValue() * ui->volume_slider->maximum()); + + if (Settings::configuring_global) { + ui->toggle_audio_stretching->setChecked( + Settings::values.enable_audio_stretching.GetValue()); + } else { + ConfigurationShared::SetPerGameSetting(ui->toggle_audio_stretching, + &Settings::values.enable_audio_stretching); + if (Settings::values.volume.UsingGlobal()) { + ui->volume_combo_box->setCurrentIndex(0); + ui->volume_slider->setEnabled(false); + } else { + ui->volume_combo_box->setCurrentIndex(1); + ui->volume_slider->setEnabled(true); + } + } SetVolumeIndicatorText(ui->volume_slider->sliderPosition()); } @@ -80,15 +100,36 @@ void ConfigureAudio::SetVolumeIndicatorText(int percentage) { } void ConfigureAudio::ApplyConfiguration() { - Settings::values.sink_id = - ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex()) - .toStdString(); - Settings::values.enable_audio_stretching = ui->toggle_audio_stretching->isChecked(); - Settings::values.audio_device_id = - ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()) - .toStdString(); - Settings::values.volume = - static_cast(ui->volume_slider->sliderPosition()) / ui->volume_slider->maximum(); + if (Settings::configuring_global) { + Settings::values.sink_id = + ui->output_sink_combo_box->itemText(ui->output_sink_combo_box->currentIndex()) + .toStdString(); + Settings::values.audio_device_id = + ui->audio_device_combo_box->itemText(ui->audio_device_combo_box->currentIndex()) + .toStdString(); + + // Guard if during game and set to game-specific value + if (Settings::values.enable_audio_stretching.UsingGlobal()) { + Settings::values.enable_audio_stretching.SetValue( + ui->toggle_audio_stretching->isChecked()); + } + if (Settings::values.volume.UsingGlobal()) { + Settings::values.volume.SetValue( + static_cast(ui->volume_slider->sliderPosition()) / + ui->volume_slider->maximum()); + } + } else { + ConfigurationShared::ApplyPerGameSetting(&Settings::values.enable_audio_stretching, + ui->toggle_audio_stretching); + if (ui->volume_combo_box->currentIndex() == 0) { + Settings::values.volume.SetGlobal(true); + } else { + Settings::values.volume.SetGlobal(false); + Settings::values.volume.SetValue( + static_cast(ui->volume_slider->sliderPosition()) / + ui->volume_slider->maximum()); + } + } } void ConfigureAudio::changeEvent(QEvent* event) { @@ -122,3 +163,22 @@ void ConfigureAudio::RetranslateUI() { ui->retranslateUi(this); SetVolumeIndicatorText(ui->volume_slider->sliderPosition()); } + +void ConfigureAudio::SetupPerGameUI() { + if (Settings::configuring_global) { + ui->volume_slider->setEnabled(Settings::values.volume.UsingGlobal()); + ui->toggle_audio_stretching->setEnabled( + Settings::values.enable_audio_stretching.UsingGlobal()); + + return; + } + + ui->toggle_audio_stretching->setTristate(true); + connect(ui->volume_combo_box, static_cast(&QComboBox::activated), + this, [this](int index) { ui->volume_slider->setEnabled(index == 1); }); + + ui->output_sink_combo_box->setVisible(false); + ui->output_sink_label->setVisible(false); + ui->audio_device_combo_box->setVisible(false); + ui->audio_device_label->setVisible(false); +} diff --git a/src/yuzu/configuration/configure_audio.h b/src/yuzu/configuration/configure_audio.h index ea83bd72d..d84f4a682 100644 --- a/src/yuzu/configuration/configure_audio.h +++ b/src/yuzu/configuration/configure_audio.h @@ -34,5 +34,7 @@ private: void SetAudioDeviceFromDeviceID(); void SetVolumeIndicatorText(int percentage); + void SetupPerGameUI(); + std::unique_ptr ui; }; diff --git a/src/yuzu/configuration/configure_audio.ui b/src/yuzu/configuration/configure_audio.ui index a098b9acc..862ccb988 100644 --- a/src/yuzu/configuration/configure_audio.ui +++ b/src/yuzu/configuration/configure_audio.ui @@ -6,8 +6,8 @@ 0 0 - 188 - 246 + 367 + 368 @@ -18,9 +18,9 @@ - + - + Output Engine: @@ -31,20 +31,20 @@ - - - - This post-processing effect adjusts audio speed to match emulation speed and helps prevent audio stutter. This however increases audio latency. - - - Enable audio stretching - - - - + + + This post-processing effect adjusts audio speed to match emulation speed and helps prevent audio stutter. This however increases audio latency. + + + Enable audio stretching + + + + + - + Audio Device: @@ -61,7 +61,21 @@ 0 - + + + + Use global volume + + + + + Set volume: + + + + + + Volume: @@ -74,7 +88,7 @@ - 40 + 30 20 diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index df4473b46..5918e9972 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -14,6 +14,8 @@ ConfigureDialog::ConfigureDialog(QWidget* parent, HotkeyRegistry& registry) : QDialog(parent), ui(new Ui::ConfigureDialog), registry(registry) { + Settings::configuring_global = true; + ui->setupUi(this); ui->hotkeysTab->Populate(registry); setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 74b2ad537..1fb62d1cf 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp @@ -7,17 +7,21 @@ #include "core/core.h" #include "core/settings.h" #include "ui_configure_general.h" +#include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_general.h" #include "yuzu/uisettings.h" ConfigureGeneral::ConfigureGeneral(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureGeneral) { - ui->setupUi(this); + SetupPerGameUI(); + SetConfiguration(); - connect(ui->toggle_frame_limit, &QCheckBox::toggled, ui->frame_limit, &QSpinBox::setEnabled); + connect(ui->toggle_frame_limit, &QCheckBox::stateChanged, ui->frame_limit, [this]() { + ui->frame_limit->setEnabled(ui->toggle_frame_limit->checkState() == Qt::Checked); + }); } ConfigureGeneral::~ConfigureGeneral() = default; @@ -26,27 +30,56 @@ void ConfigureGeneral::SetConfiguration() { const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); ui->use_multi_core->setEnabled(runtime_lock); - ui->use_multi_core->setChecked(Settings::values.use_multi_core); + ui->use_multi_core->setChecked(Settings::values.use_multi_core.GetValue()); ui->toggle_check_exit->setChecked(UISettings::values.confirm_before_closing); ui->toggle_user_on_boot->setChecked(UISettings::values.select_user_on_boot); ui->toggle_background_pause->setChecked(UISettings::values.pause_when_in_background); ui->toggle_hide_mouse->setChecked(UISettings::values.hide_mouse); - ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit); - ui->frame_limit->setEnabled(ui->toggle_frame_limit->isChecked()); - ui->frame_limit->setValue(Settings::values.frame_limit); + ui->toggle_frame_limit->setChecked(Settings::values.use_frame_limit.GetValue()); + ui->frame_limit->setValue(Settings::values.frame_limit.GetValue()); + + if (!Settings::configuring_global) { + if (Settings::values.use_multi_core.UsingGlobal()) { + ui->use_multi_core->setCheckState(Qt::PartiallyChecked); + } + if (Settings::values.use_frame_limit.UsingGlobal()) { + ui->toggle_frame_limit->setCheckState(Qt::PartiallyChecked); + } + } + + ui->frame_limit->setEnabled(ui->toggle_frame_limit->checkState() == Qt::Checked && + ui->toggle_frame_limit->isEnabled()); } void ConfigureGeneral::ApplyConfiguration() { - UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); - UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked(); - UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked(); - UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked(); + if (Settings::configuring_global) { + UISettings::values.confirm_before_closing = ui->toggle_check_exit->isChecked(); + UISettings::values.select_user_on_boot = ui->toggle_user_on_boot->isChecked(); + UISettings::values.pause_when_in_background = ui->toggle_background_pause->isChecked(); + UISettings::values.hide_mouse = ui->toggle_hide_mouse->isChecked(); - Settings::values.use_frame_limit = ui->toggle_frame_limit->isChecked(); - Settings::values.frame_limit = ui->frame_limit->value(); - Settings::values.use_multi_core = ui->use_multi_core->isChecked(); + // Guard if during game and set to game-specific value + if (Settings::values.use_frame_limit.UsingGlobal()) { + Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() == + Qt::Checked); + Settings::values.frame_limit.SetValue(ui->frame_limit->value()); + Settings::values.use_multi_core.SetValue(ui->use_multi_core->isChecked()); + } + } else { + ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_multi_core, + ui->use_multi_core); + + bool global_frame_limit = ui->toggle_frame_limit->checkState() == Qt::PartiallyChecked; + Settings::values.use_frame_limit.SetGlobal(global_frame_limit); + Settings::values.frame_limit.SetGlobal(global_frame_limit); + if (!global_frame_limit) { + Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() == + Qt::Checked); + Settings::values.frame_limit.SetValue(ui->frame_limit->value()); + } + } } void ConfigureGeneral::changeEvent(QEvent* event) { @@ -60,3 +93,20 @@ void ConfigureGeneral::changeEvent(QEvent* event) { void ConfigureGeneral::RetranslateUI() { ui->retranslateUi(this); } + +void ConfigureGeneral::SetupPerGameUI() { + if (Settings::configuring_global) { + ui->toggle_frame_limit->setEnabled(Settings::values.use_frame_limit.UsingGlobal()); + ui->frame_limit->setEnabled(Settings::values.frame_limit.UsingGlobal()); + + return; + } + + ui->toggle_check_exit->setVisible(false); + ui->toggle_user_on_boot->setVisible(false); + ui->toggle_background_pause->setVisible(false); + ui->toggle_hide_mouse->setVisible(false); + + ui->toggle_frame_limit->setTristate(true); + ui->use_multi_core->setTristate(true); +} diff --git a/src/yuzu/configuration/configure_general.h b/src/yuzu/configuration/configure_general.h index ef05ce065..9c785c22e 100644 --- a/src/yuzu/configuration/configure_general.h +++ b/src/yuzu/configuration/configure_general.h @@ -28,5 +28,7 @@ private: void SetConfiguration(); + void SetupPerGameUI(); + std::unique_ptr ui; }; diff --git a/src/yuzu/configuration/configure_graphics.cpp b/src/yuzu/configuration/configure_graphics.cpp index 431f51d73..cb4706bd6 100644 --- a/src/yuzu/configuration/configure_graphics.cpp +++ b/src/yuzu/configuration/configure_graphics.cpp @@ -13,6 +13,7 @@ #include "core/core.h" #include "core/settings.h" #include "ui_configure_graphics.h" +#include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_graphics.h" #ifdef HAS_VULKAN @@ -21,11 +22,13 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureGraphics) { - vulkan_device = Settings::values.vulkan_device; + vulkan_device = Settings::values.vulkan_device.GetValue(); RetrieveVulkanDevices(); ui->setupUi(this); + SetupPerGameUI(); + SetConfiguration(); connect(ui->api, qOverload(&QComboBox::currentIndexChanged), this, @@ -40,6 +43,9 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent) } UpdateBackgroundColorButton(new_bg_color); }); + + ui->bg_label->setVisible(Settings::configuring_global); + ui->bg_combobox->setVisible(!Settings::configuring_global); } void ConfigureGraphics::UpdateDeviceSelection(int device) { @@ -57,27 +63,95 @@ void ConfigureGraphics::SetConfiguration() { const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); ui->api->setEnabled(runtime_lock); - ui->api->setCurrentIndex(static_cast(Settings::values.renderer_backend)); - ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio); - ui->use_disk_shader_cache->setEnabled(runtime_lock); - ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache); ui->use_asynchronous_gpu_emulation->setEnabled(runtime_lock); - ui->use_asynchronous_gpu_emulation->setChecked(Settings::values.use_asynchronous_gpu_emulation); - UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red, Settings::values.bg_green, - Settings::values.bg_blue)); + ui->use_disk_shader_cache->setEnabled(runtime_lock); + + if (Settings::configuring_global) { + ui->api->setCurrentIndex(static_cast(Settings::values.renderer_backend.GetValue())); + ui->aspect_ratio_combobox->setCurrentIndex(Settings::values.aspect_ratio.GetValue()); + ui->use_disk_shader_cache->setChecked(Settings::values.use_disk_shader_cache.GetValue()); + ui->use_asynchronous_gpu_emulation->setChecked( + Settings::values.use_asynchronous_gpu_emulation.GetValue()); + } else { + ConfigurationShared::SetPerGameSetting(ui->use_disk_shader_cache, + &Settings::values.use_disk_shader_cache); + ConfigurationShared::SetPerGameSetting(ui->use_asynchronous_gpu_emulation, + &Settings::values.use_asynchronous_gpu_emulation); + + ConfigurationShared::SetPerGameSetting(ui->api, &Settings::values.renderer_backend); + ConfigurationShared::SetPerGameSetting(ui->aspect_ratio_combobox, + &Settings::values.aspect_ratio); + + ui->bg_combobox->setCurrentIndex(Settings::values.bg_red.UsingGlobal() ? 0 : 1); + ui->bg_button->setEnabled(!Settings::values.bg_red.UsingGlobal()); + } + + UpdateBackgroundColorButton(QColor::fromRgbF(Settings::values.bg_red.GetValue(), + Settings::values.bg_green.GetValue(), + Settings::values.bg_blue.GetValue())); UpdateDeviceComboBox(); } void ConfigureGraphics::ApplyConfiguration() { - Settings::values.renderer_backend = GetCurrentGraphicsBackend(); - Settings::values.vulkan_device = vulkan_device; - Settings::values.aspect_ratio = ui->aspect_ratio_combobox->currentIndex(); - Settings::values.use_disk_shader_cache = ui->use_disk_shader_cache->isChecked(); - Settings::values.use_asynchronous_gpu_emulation = - ui->use_asynchronous_gpu_emulation->isChecked(); - Settings::values.bg_red = static_cast(bg_color.redF()); - Settings::values.bg_green = static_cast(bg_color.greenF()); - Settings::values.bg_blue = static_cast(bg_color.blueF()); + if (Settings::configuring_global) { + // Guard if during game and set to game-specific value + if (Settings::values.renderer_backend.UsingGlobal()) { + Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); + } + if (Settings::values.vulkan_device.UsingGlobal()) { + Settings::values.vulkan_device.SetValue(vulkan_device); + } + if (Settings::values.aspect_ratio.UsingGlobal()) { + Settings::values.aspect_ratio.SetValue(ui->aspect_ratio_combobox->currentIndex()); + } + if (Settings::values.use_disk_shader_cache.UsingGlobal()) { + Settings::values.use_disk_shader_cache.SetValue(ui->use_disk_shader_cache->isChecked()); + } + if (Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()) { + Settings::values.use_asynchronous_gpu_emulation.SetValue( + ui->use_asynchronous_gpu_emulation->isChecked()); + } + if (Settings::values.bg_red.UsingGlobal()) { + Settings::values.bg_red.SetValue(static_cast(bg_color.redF())); + Settings::values.bg_green.SetValue(static_cast(bg_color.greenF())); + Settings::values.bg_blue.SetValue(static_cast(bg_color.blueF())); + } + } else { + if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + Settings::values.renderer_backend.SetGlobal(true); + Settings::values.vulkan_device.SetGlobal(true); + } else { + Settings::values.renderer_backend.SetGlobal(false); + Settings::values.renderer_backend.SetValue(GetCurrentGraphicsBackend()); + if (GetCurrentGraphicsBackend() == Settings::RendererBackend::Vulkan) { + Settings::values.vulkan_device.SetGlobal(false); + Settings::values.vulkan_device.SetValue(vulkan_device); + } else { + Settings::values.vulkan_device.SetGlobal(true); + } + } + + ConfigurationShared::ApplyPerGameSetting(&Settings::values.aspect_ratio, + ui->aspect_ratio_combobox); + + ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_disk_shader_cache, + ui->use_disk_shader_cache); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_asynchronous_gpu_emulation, + ui->use_asynchronous_gpu_emulation); + + if (ui->bg_combobox->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + Settings::values.bg_red.SetGlobal(true); + Settings::values.bg_green.SetGlobal(true); + Settings::values.bg_blue.SetGlobal(true); + } else { + Settings::values.bg_red.SetGlobal(false); + Settings::values.bg_green.SetGlobal(false); + Settings::values.bg_blue.SetGlobal(false); + Settings::values.bg_red.SetValue(static_cast(bg_color.redF())); + Settings::values.bg_green.SetValue(static_cast(bg_color.greenF())); + Settings::values.bg_blue.SetValue(static_cast(bg_color.blueF())); + } + } } void ConfigureGraphics::changeEvent(QEvent* event) { @@ -106,6 +180,11 @@ void ConfigureGraphics::UpdateDeviceComboBox() { ui->device->clear(); bool enabled = false; + + if (!Settings::configuring_global && + ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + vulkan_device = Settings::values.vulkan_device.GetValue(); + } switch (GetCurrentGraphicsBackend()) { case Settings::RendererBackend::OpenGL: ui->device->addItem(tr("OpenGL Graphics Device")); @@ -119,6 +198,9 @@ void ConfigureGraphics::UpdateDeviceComboBox() { enabled = !vulkan_devices.empty(); break; } + // If in per-game config and use global is selected, don't enable. + enabled &= !(!Settings::configuring_global && + ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX); ui->device->setEnabled(enabled && !Core::System::GetInstance().IsPoweredOn()); } @@ -132,5 +214,37 @@ void ConfigureGraphics::RetrieveVulkanDevices() { } Settings::RendererBackend ConfigureGraphics::GetCurrentGraphicsBackend() const { - return static_cast(ui->api->currentIndex()); + if (Settings::configuring_global) { + return static_cast(ui->api->currentIndex()); + } + + if (ui->api->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + Settings::values.renderer_backend.SetGlobal(true); + return Settings::values.renderer_backend.GetValue(); + } + Settings::values.renderer_backend.SetGlobal(false); + return static_cast(ui->api->currentIndex() - + ConfigurationShared::USE_GLOBAL_OFFSET); +} + +void ConfigureGraphics::SetupPerGameUI() { + if (Settings::configuring_global) { + ui->api->setEnabled(Settings::values.renderer_backend.UsingGlobal()); + ui->device->setEnabled(Settings::values.renderer_backend.UsingGlobal()); + ui->aspect_ratio_combobox->setEnabled(Settings::values.aspect_ratio.UsingGlobal()); + ui->use_asynchronous_gpu_emulation->setEnabled( + Settings::values.use_asynchronous_gpu_emulation.UsingGlobal()); + ui->use_disk_shader_cache->setEnabled(Settings::values.use_disk_shader_cache.UsingGlobal()); + ui->bg_button->setEnabled(Settings::values.bg_red.UsingGlobal()); + + return; + } + + connect(ui->bg_combobox, static_cast(&QComboBox::activated), this, + [this](int index) { ui->bg_button->setEnabled(index == 1); }); + + ui->use_disk_shader_cache->setTristate(true); + ui->use_asynchronous_gpu_emulation->setTristate(true); + ConfigurationShared::InsertGlobalItem(ui->aspect_ratio_combobox); + ConfigurationShared::InsertGlobalItem(ui->api); } diff --git a/src/yuzu/configuration/configure_graphics.h b/src/yuzu/configuration/configure_graphics.h index 7e0596d9c..24f01c739 100644 --- a/src/yuzu/configuration/configure_graphics.h +++ b/src/yuzu/configuration/configure_graphics.h @@ -35,6 +35,8 @@ private: void RetrieveVulkanDevices(); + void SetupPerGameUI(); + Settings::RendererBackend GetCurrentGraphicsBackend() const; std::unique_ptr ui; diff --git a/src/yuzu/configuration/configure_graphics.ui b/src/yuzu/configuration/configure_graphics.ui index 6e75447a5..62418fc14 100644 --- a/src/yuzu/configuration/configure_graphics.ui +++ b/src/yuzu/configuration/configure_graphics.ui @@ -121,6 +121,29 @@ + + + + Use global background color + + + 0 + + + 10 + + + + Use global background color + + + + + Set background color: + + + + @@ -128,6 +151,19 @@ + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/src/yuzu/configuration/configure_graphics_advanced.cpp b/src/yuzu/configuration/configure_graphics_advanced.cpp index be5006ad3..7c0fa7ec5 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.cpp +++ b/src/yuzu/configuration/configure_graphics_advanced.cpp @@ -5,6 +5,7 @@ #include "core/core.h" #include "core/settings.h" #include "ui_configure_graphics_advanced.h" +#include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_graphics_advanced.h" ConfigureGraphicsAdvanced::ConfigureGraphicsAdvanced(QWidget* parent) @@ -12,6 +13,8 @@ ConfigureGraphicsAdvanced::ConfigureGraphicsAdvanced(QWidget* parent) ui->setupUi(this); + SetupPerGameUI(); + SetConfiguration(); } @@ -19,26 +22,81 @@ ConfigureGraphicsAdvanced::~ConfigureGraphicsAdvanced() = default; void ConfigureGraphicsAdvanced::SetConfiguration() { const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); - ui->gpu_accuracy->setCurrentIndex(static_cast(Settings::values.gpu_accuracy)); ui->use_vsync->setEnabled(runtime_lock); - ui->use_vsync->setChecked(Settings::values.use_vsync); ui->use_assembly_shaders->setEnabled(runtime_lock); - ui->use_assembly_shaders->setChecked(Settings::values.use_assembly_shaders); - ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time); ui->force_30fps_mode->setEnabled(runtime_lock); - ui->force_30fps_mode->setChecked(Settings::values.force_30fps_mode); ui->anisotropic_filtering_combobox->setEnabled(runtime_lock); - ui->anisotropic_filtering_combobox->setCurrentIndex(Settings::values.max_anisotropy); + + if (Settings::configuring_global) { + ui->gpu_accuracy->setCurrentIndex( + static_cast(Settings::values.gpu_accuracy.GetValue())); + ui->use_vsync->setChecked(Settings::values.use_vsync.GetValue()); + ui->use_assembly_shaders->setChecked(Settings::values.use_assembly_shaders.GetValue()); + ui->use_fast_gpu_time->setChecked(Settings::values.use_fast_gpu_time.GetValue()); + ui->force_30fps_mode->setChecked(Settings::values.force_30fps_mode.GetValue()); + ui->anisotropic_filtering_combobox->setCurrentIndex( + Settings::values.max_anisotropy.GetValue()); + } else { + ConfigurationShared::SetPerGameSetting(ui->gpu_accuracy, &Settings::values.gpu_accuracy); + ConfigurationShared::SetPerGameSetting(ui->use_vsync, &Settings::values.use_vsync); + ConfigurationShared::SetPerGameSetting(ui->use_assembly_shaders, + &Settings::values.use_assembly_shaders); + ConfigurationShared::SetPerGameSetting(ui->use_fast_gpu_time, + &Settings::values.use_fast_gpu_time); + ConfigurationShared::SetPerGameSetting(ui->force_30fps_mode, + &Settings::values.force_30fps_mode); + ConfigurationShared::SetPerGameSetting(ui->anisotropic_filtering_combobox, + &Settings::values.max_anisotropy); + } } void ConfigureGraphicsAdvanced::ApplyConfiguration() { - auto gpu_accuracy = static_cast(ui->gpu_accuracy->currentIndex()); - Settings::values.gpu_accuracy = gpu_accuracy; - Settings::values.use_vsync = ui->use_vsync->isChecked(); - Settings::values.use_assembly_shaders = ui->use_assembly_shaders->isChecked(); - Settings::values.use_fast_gpu_time = ui->use_fast_gpu_time->isChecked(); - Settings::values.force_30fps_mode = ui->force_30fps_mode->isChecked(); - Settings::values.max_anisotropy = ui->anisotropic_filtering_combobox->currentIndex(); + // Subtract 2 if configuring per-game (separator and "use global configuration" take 2 slots) + const auto gpu_accuracy = static_cast( + ui->gpu_accuracy->currentIndex() - + ((Settings::configuring_global) ? 0 : ConfigurationShared::USE_GLOBAL_OFFSET)); + + if (Settings::configuring_global) { + // Must guard in case of a during-game configuration when set to be game-specific. + if (Settings::values.gpu_accuracy.UsingGlobal()) { + Settings::values.gpu_accuracy.SetValue(gpu_accuracy); + } + if (Settings::values.use_vsync.UsingGlobal()) { + Settings::values.use_vsync.SetValue(ui->use_vsync->isChecked()); + } + if (Settings::values.use_assembly_shaders.UsingGlobal()) { + Settings::values.use_assembly_shaders.SetValue(ui->use_assembly_shaders->isChecked()); + } + if (Settings::values.use_fast_gpu_time.UsingGlobal()) { + Settings::values.use_fast_gpu_time.SetValue(ui->use_fast_gpu_time->isChecked()); + } + if (Settings::values.force_30fps_mode.UsingGlobal()) { + Settings::values.force_30fps_mode.SetValue(ui->force_30fps_mode->isChecked()); + } + if (Settings::values.max_anisotropy.UsingGlobal()) { + Settings::values.max_anisotropy.SetValue( + ui->anisotropic_filtering_combobox->currentIndex()); + } + } else { + ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, + ui->anisotropic_filtering_combobox); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_vsync, ui->use_vsync); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_assembly_shaders, + ui->use_assembly_shaders); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.use_fast_gpu_time, + ui->use_fast_gpu_time); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.force_30fps_mode, + ui->force_30fps_mode); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.max_anisotropy, + ui->anisotropic_filtering_combobox); + + if (ui->gpu_accuracy->currentIndex() == ConfigurationShared::USE_GLOBAL_INDEX) { + Settings::values.gpu_accuracy.SetGlobal(true); + } else { + Settings::values.gpu_accuracy.SetGlobal(false); + Settings::values.gpu_accuracy.SetValue(gpu_accuracy); + } + } } void ConfigureGraphicsAdvanced::changeEvent(QEvent* event) { @@ -52,3 +110,25 @@ void ConfigureGraphicsAdvanced::changeEvent(QEvent* event) { void ConfigureGraphicsAdvanced::RetranslateUI() { ui->retranslateUi(this); } + +void ConfigureGraphicsAdvanced::SetupPerGameUI() { + // Disable if not global (only happens during game) + if (Settings::configuring_global) { + ui->gpu_accuracy->setEnabled(Settings::values.gpu_accuracy.UsingGlobal()); + ui->use_vsync->setEnabled(Settings::values.use_vsync.UsingGlobal()); + ui->use_assembly_shaders->setEnabled(Settings::values.use_assembly_shaders.UsingGlobal()); + ui->use_fast_gpu_time->setEnabled(Settings::values.use_fast_gpu_time.UsingGlobal()); + ui->force_30fps_mode->setEnabled(Settings::values.force_30fps_mode.UsingGlobal()); + ui->anisotropic_filtering_combobox->setEnabled( + Settings::values.max_anisotropy.UsingGlobal()); + + return; + } + + ConfigurationShared::InsertGlobalItem(ui->gpu_accuracy); + ui->use_vsync->setTristate(true); + ui->use_assembly_shaders->setTristate(true); + ui->use_fast_gpu_time->setTristate(true); + ui->force_30fps_mode->setTristate(true); + ConfigurationShared::InsertGlobalItem(ui->anisotropic_filtering_combobox); +} diff --git a/src/yuzu/configuration/configure_graphics_advanced.h b/src/yuzu/configuration/configure_graphics_advanced.h index bbc9d4355..c043588ff 100644 --- a/src/yuzu/configuration/configure_graphics_advanced.h +++ b/src/yuzu/configuration/configure_graphics_advanced.h @@ -26,5 +26,7 @@ private: void SetConfiguration(); + void SetupPerGameUI(); + std::unique_ptr ui; }; diff --git a/src/yuzu/configuration/configure_per_game.cpp b/src/yuzu/configuration/configure_per_game.cpp new file mode 100644 index 000000000..1e49f0787 --- /dev/null +++ b/src/yuzu/configuration/configure_per_game.cpp @@ -0,0 +1,140 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "common/common_paths.h" +#include "common/file_util.h" +#include "core/file_sys/control_metadata.h" +#include "core/file_sys/patch_manager.h" +#include "core/file_sys/xts_archive.h" +#include "core/loader/loader.h" +#include "ui_configure_per_game.h" +#include "yuzu/configuration/config.h" +#include "yuzu/configuration/configure_input.h" +#include "yuzu/configuration/configure_per_game.h" +#include "yuzu/uisettings.h" +#include "yuzu/util/util.h" + +ConfigurePerGame::ConfigurePerGame(QWidget* parent, u64 title_id) + : QDialog(parent), ui(std::make_unique()), title_id(title_id) { + game_config = std::make_unique(fmt::format("{:016X}.ini", title_id), false); + + Settings::configuring_global = false; + + ui->setupUi(this); + setFocusPolicy(Qt::ClickFocus); + setWindowTitle(tr("Properties")); + + ui->addonsTab->SetTitleId(title_id); + + scene = new QGraphicsScene; + ui->icon_view->setScene(scene); + + LoadConfiguration(); +} + +ConfigurePerGame::~ConfigurePerGame() = default; + +void ConfigurePerGame::ApplyConfiguration() { + ui->addonsTab->ApplyConfiguration(); + ui->generalTab->ApplyConfiguration(); + ui->systemTab->ApplyConfiguration(); + ui->graphicsTab->ApplyConfiguration(); + ui->graphicsAdvancedTab->ApplyConfiguration(); + ui->audioTab->ApplyConfiguration(); + + Settings::Apply(); + Settings::LogSettings(); + + game_config->Save(); +} + +void ConfigurePerGame::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + } + + QDialog::changeEvent(event); +} + +void ConfigurePerGame::RetranslateUI() { + ui->retranslateUi(this); +} + +void ConfigurePerGame::LoadFromFile(FileSys::VirtualFile file) { + this->file = std::move(file); + LoadConfiguration(); +} + +void ConfigurePerGame::LoadConfiguration() { + if (file == nullptr) { + return; + } + + ui->addonsTab->LoadFromFile(file); + + ui->display_title_id->setText( + QStringLiteral("%1").arg(title_id, 16, 16, QLatin1Char{'0'}).toUpper()); + + FileSys::PatchManager pm{title_id}; + const auto control = pm.GetControlMetadata(); + const auto loader = Loader::GetLoader(file); + + if (control.first != nullptr) { + ui->display_version->setText(QString::fromStdString(control.first->GetVersionString())); + ui->display_name->setText(QString::fromStdString(control.first->GetApplicationName())); + ui->display_developer->setText(QString::fromStdString(control.first->GetDeveloperName())); + } else { + std::string title; + if (loader->ReadTitle(title) == Loader::ResultStatus::Success) + ui->display_name->setText(QString::fromStdString(title)); + + FileSys::NACP nacp; + if (loader->ReadControlData(nacp) == Loader::ResultStatus::Success) + ui->display_developer->setText(QString::fromStdString(nacp.GetDeveloperName())); + + ui->display_version->setText(QStringLiteral("1.0.0")); + } + + if (control.second != nullptr) { + scene->clear(); + + QPixmap map; + const auto bytes = control.second->ReadAllBytes(); + map.loadFromData(bytes.data(), static_cast(bytes.size())); + + scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(), + Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + } else { + std::vector bytes; + if (loader->ReadIcon(bytes) == Loader::ResultStatus::Success) { + scene->clear(); + + QPixmap map; + map.loadFromData(bytes.data(), static_cast(bytes.size())); + + scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(), + Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + } + } + + ui->display_filename->setText(QString::fromStdString(file->GetName())); + + ui->display_format->setText( + QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))); + + const auto valueText = ReadableByteSize(file->GetSize()); + ui->display_size->setText(valueText); +} diff --git a/src/yuzu/configuration/configure_per_game.h b/src/yuzu/configuration/configure_per_game.h new file mode 100644 index 000000000..5f9a08cef --- /dev/null +++ b/src/yuzu/configuration/configure_per_game.h @@ -0,0 +1,51 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include + +#include +#include + +#include "core/file_sys/vfs_types.h" +#include "yuzu/configuration/config.h" + +class QGraphicsScene; +class QStandardItem; +class QStandardItemModel; +class QTreeView; +class QVBoxLayout; + +namespace Ui { +class ConfigurePerGame; +} + +class ConfigurePerGame : public QDialog { + Q_OBJECT + +public: + explicit ConfigurePerGame(QWidget* parent, u64 title_id); + ~ConfigurePerGame() override; + + /// Save all button configurations to settings file + void ApplyConfiguration(); + + void LoadFromFile(FileSys::VirtualFile file); + +private: + void changeEvent(QEvent* event) override; + void RetranslateUI(); + + void LoadConfiguration(); + + std::unique_ptr ui; + FileSys::VirtualFile file; + u64 title_id; + + QGraphicsScene* scene; + + std::unique_ptr game_config; +}; diff --git a/src/yuzu/configuration/configure_per_game.ui b/src/yuzu/configuration/configure_per_game.ui new file mode 100644 index 000000000..d2057c4ab --- /dev/null +++ b/src/yuzu/configuration/configure_per_game.ui @@ -0,0 +1,350 @@ + + + ConfigurePerGame + + + + 0 + 0 + 800 + 600 + + + + Dialog + + + + + + + + + 0 + 0 + + + + Info + + + + + + + 0 + 0 + + + + + 256 + 256 + + + + + 256 + 256 + + + + Qt::ScrollBarAlwaysOff + + + Qt::ScrollBarAlwaysOff + + + false + + + + + + + + + true + + + true + + + + + + + true + + + true + + + + + + + Name + + + + + + + Title ID + + + + + + + true + + + true + + + + + + + true + + + true + + + + + + + true + + + true + + + + + + + Filename + + + + + + + true + + + true + + + + + + + true + + + true + + + + + + + Format + + + + + + + Version + + + + + + + Size + + + + + + + Developer + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + + + + + + + true + + + 0 + + + true + + + false + + + false + + + + Add-Ons + + + + + General + + + + + System + + + + + Graphics + + + + + Adv. Graphics + + + + + Audio + + + + + + + + + + + + + 0 + 0 + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + ConfigureGeneral + QWidget +
configuration/configure_general.h
+ 1 +
+ + ConfigureSystem + QWidget +
configuration/configure_system.h
+ 1 +
+ + ConfigureAudio + QWidget +
configuration/configure_audio.h
+ 1 +
+ + ConfigureGraphics + QWidget +
configuration/configure_graphics.h
+ 1 +
+ + ConfigureGraphicsAdvanced + QWidget +
configuration/configure_graphics_advanced.h
+ 1 +
+ + ConfigurePerGameAddons + QWidget +
configuration/configure_per_game_addons.h
+ 1 +
+
+ + + + buttonBox + accepted() + ConfigurePerGame + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + ConfigurePerGame + reject() + + + 316 + 260 + + + 286 + 274 + + + + +
diff --git a/src/yuzu/configuration/configure_per_general.cpp b/src/yuzu/configuration/configure_per_game_addons.cpp similarity index 57% rename from src/yuzu/configuration/configure_per_general.cpp rename to src/yuzu/configuration/configure_per_game_addons.cpp index d7f259f12..478d5d3a1 100644 --- a/src/yuzu/configuration/configure_per_general.cpp +++ b/src/yuzu/configuration/configure_per_game_addons.cpp @@ -15,23 +15,20 @@ #include "common/common_paths.h" #include "common/file_util.h" -#include "core/file_sys/control_metadata.h" +#include "core/core.h" #include "core/file_sys/patch_manager.h" #include "core/file_sys/xts_archive.h" #include "core/loader/loader.h" -#include "ui_configure_per_general.h" +#include "ui_configure_per_game_addons.h" #include "yuzu/configuration/config.h" #include "yuzu/configuration/configure_input.h" -#include "yuzu/configuration/configure_per_general.h" +#include "yuzu/configuration/configure_per_game_addons.h" #include "yuzu/uisettings.h" #include "yuzu/util/util.h" -ConfigurePerGameGeneral::ConfigurePerGameGeneral(QWidget* parent, u64 title_id) - : QDialog(parent), ui(std::make_unique()), title_id(title_id) { - +ConfigurePerGameAddons::ConfigurePerGameAddons(QWidget* parent) + : QWidget(parent), ui(new Ui::ConfigurePerGameAddons) { ui->setupUi(this); - setFocusPolicy(Qt::ClickFocus); - setWindowTitle(tr("Properties")); layout = new QVBoxLayout; tree_view = new QTreeView; @@ -52,7 +49,7 @@ ConfigurePerGameGeneral::ConfigurePerGameGeneral(QWidget* parent, u64 title_id) item_model->setHeaderData(1, Qt::Horizontal, tr("Version")); // We must register all custom types with the Qt Automoc system so that we are able to use it - // with signals/slots. In this case, QList falls under the umbrells of custom types. + // with signals/slots. In this case, QList falls under the umbrella of custom types. qRegisterMetaType>("QList"); layout->setContentsMargins(0, 0, 0, 0); @@ -61,18 +58,15 @@ ConfigurePerGameGeneral::ConfigurePerGameGeneral(QWidget* parent, u64 title_id) ui->scrollArea->setLayout(layout); - scene = new QGraphicsScene; - ui->icon_view->setScene(scene); + ui->scrollArea->setEnabled(!Core::System::GetInstance().IsPoweredOn()); connect(item_model, &QStandardItemModel::itemChanged, [] { UISettings::values.is_game_list_reload_pending.exchange(true); }); - - LoadConfiguration(); } -ConfigurePerGameGeneral::~ConfigurePerGameGeneral() = default; +ConfigurePerGameAddons::~ConfigurePerGameAddons() = default; -void ConfigurePerGameGeneral::ApplyConfiguration() { +void ConfigurePerGameAddons::ApplyConfiguration() { std::vector disabled_addons; for (const auto& item : list_items) { @@ -92,72 +86,35 @@ void ConfigurePerGameGeneral::ApplyConfiguration() { Settings::values.disabled_addons[title_id] = disabled_addons; } -void ConfigurePerGameGeneral::changeEvent(QEvent* event) { - if (event->type() == QEvent::LanguageChange) { - RetranslateUI(); - } - - QDialog::changeEvent(event); -} - -void ConfigurePerGameGeneral::RetranslateUI() { - ui->retranslateUi(this); -} - -void ConfigurePerGameGeneral::LoadFromFile(FileSys::VirtualFile file) { +void ConfigurePerGameAddons::LoadFromFile(FileSys::VirtualFile file) { this->file = std::move(file); LoadConfiguration(); } -void ConfigurePerGameGeneral::LoadConfiguration() { +void ConfigurePerGameAddons::SetTitleId(u64 id) { + this->title_id = id; +} + +void ConfigurePerGameAddons::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + } + + QWidget::changeEvent(event); +} + +void ConfigurePerGameAddons::RetranslateUI() { + ui->retranslateUi(this); +} + +void ConfigurePerGameAddons::LoadConfiguration() { if (file == nullptr) { return; } - ui->display_title_id->setText(QString::fromStdString(fmt::format("{:016X}", title_id))); - FileSys::PatchManager pm{title_id}; - const auto control = pm.GetControlMetadata(); const auto loader = Loader::GetLoader(file); - if (control.first != nullptr) { - ui->display_version->setText(QString::fromStdString(control.first->GetVersionString())); - ui->display_name->setText(QString::fromStdString(control.first->GetApplicationName())); - ui->display_developer->setText(QString::fromStdString(control.first->GetDeveloperName())); - } else { - std::string title; - if (loader->ReadTitle(title) == Loader::ResultStatus::Success) - ui->display_name->setText(QString::fromStdString(title)); - - FileSys::NACP nacp; - if (loader->ReadControlData(nacp) == Loader::ResultStatus::Success) - ui->display_developer->setText(QString::fromStdString(nacp.GetDeveloperName())); - - ui->display_version->setText(QStringLiteral("1.0.0")); - } - - if (control.second != nullptr) { - scene->clear(); - - QPixmap map; - const auto bytes = control.second->ReadAllBytes(); - map.loadFromData(bytes.data(), static_cast(bytes.size())); - - scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(), - Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - } else { - std::vector bytes; - if (loader->ReadIcon(bytes) == Loader::ResultStatus::Success) { - scene->clear(); - - QPixmap map; - map.loadFromData(bytes.data(), static_cast(bytes.size())); - - scene->addPixmap(map.scaled(ui->icon_view->width(), ui->icon_view->height(), - Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); - } - } - FileSys::VirtualFile update_raw; loader->ReadUpdateRaw(update_raw); @@ -182,12 +139,4 @@ void ConfigurePerGameGeneral::LoadConfiguration() { } tree_view->setColumnWidth(0, 5 * tree_view->width() / 16); - - ui->display_filename->setText(QString::fromStdString(file->GetName())); - - ui->display_format->setText( - QString::fromStdString(Loader::GetFileTypeString(loader->GetFileType()))); - - const auto valueText = ReadableByteSize(file->GetSize()); - ui->display_size->setText(valueText); } diff --git a/src/yuzu/configuration/configure_per_general.h b/src/yuzu/configuration/configure_per_game_addons.h similarity index 70% rename from src/yuzu/configuration/configure_per_general.h rename to src/yuzu/configuration/configure_per_game_addons.h index a3b2cdeff..a00ec3539 100644 --- a/src/yuzu/configuration/configure_per_general.h +++ b/src/yuzu/configuration/configure_per_game_addons.h @@ -1,4 +1,4 @@ -// Copyright 2016 Citra Emulator Project +// Copyright 2016 Citra Emulator Project // Licensed under GPLv2 or any later version // Refer to the license.txt file included. @@ -7,7 +7,6 @@ #include #include -#include #include #include "core/file_sys/vfs_types.h" @@ -19,35 +18,36 @@ class QTreeView; class QVBoxLayout; namespace Ui { -class ConfigurePerGameGeneral; +class ConfigurePerGameAddons; } -class ConfigurePerGameGeneral : public QDialog { +class ConfigurePerGameAddons : public QWidget { Q_OBJECT public: - explicit ConfigurePerGameGeneral(QWidget* parent, u64 title_id); - ~ConfigurePerGameGeneral() override; + explicit ConfigurePerGameAddons(QWidget* parent = nullptr); + ~ConfigurePerGameAddons() override; /// Save all button configurations to settings file void ApplyConfiguration(); void LoadFromFile(FileSys::VirtualFile file); + void SetTitleId(u64 id); + private: void changeEvent(QEvent* event) override; void RetranslateUI(); void LoadConfiguration(); - std::unique_ptr ui; + std::unique_ptr ui; FileSys::VirtualFile file; u64 title_id; QVBoxLayout* layout; QTreeView* tree_view; QStandardItemModel* item_model; - QGraphicsScene* scene; std::vector> list_items; }; diff --git a/src/yuzu/configuration/configure_per_game_addons.ui b/src/yuzu/configuration/configure_per_game_addons.ui new file mode 100644 index 000000000..aefdebfcd --- /dev/null +++ b/src/yuzu/configuration/configure_per_game_addons.ui @@ -0,0 +1,38 @@ + + + ConfigurePerGameAddons + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + true + + + + + 0 + 0 + 380 + 280 + + + + + + + + + + diff --git a/src/yuzu/configuration/configure_per_general.ui b/src/yuzu/configuration/configure_per_general.ui deleted file mode 100644 index 8fdd96fa4..000000000 --- a/src/yuzu/configuration/configure_per_general.ui +++ /dev/null @@ -1,276 +0,0 @@ - - - ConfigurePerGameGeneral - - - - 0 - 0 - 400 - 520 - - - - ConfigurePerGameGeneral - - - - - - - - Info - - - - - - - - true - - - true - - - - - - - true - - - true - - - - - - - Developer - - - - - - - true - - - true - - - - - - - Name - - - - - - - Filename - - - - - - - Version - - - - - - - Format - - - - - - - true - - - true - - - - - - - true - - - true - - - - - - - Size - - - - - - - true - - - true - - - - - - - Title ID - - - - - - - true - - - true - - - - - - - - 0 - 0 - - - - - 128 - 128 - - - - - 128 - 128 - - - - Qt::ScrollBarAlwaysOff - - - Qt::ScrollBarAlwaysOff - - - QAbstractScrollArea::AdjustToContents - - - false - - - - - - - - - - - - Add-Ons - - - - - - true - - - - - 0 - 0 - 350 - 169 - - - - - - - - - - - - - - - Qt::Vertical - - - QSizePolicy::Fixed - - - - 20 - 40 - - - - - - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - - - - - - - - buttonBox - accepted() - ConfigurePerGameGeneral - accept() - - - 269 - 567 - - - 269 - 294 - - - - - buttonBox - rejected() - ConfigurePerGameGeneral - reject() - - - 269 - 567 - - - 269 - 294 - - - - - diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 10315e7a6..68e02738b 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -14,6 +14,7 @@ #include "core/core.h" #include "core/settings.h" #include "ui_configure_system.h" +#include "yuzu/configuration/configuration_shared.h" #include "yuzu/configuration/configure_system.h" ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureSystem) { @@ -21,20 +22,25 @@ ConfigureSystem::ConfigureSystem(QWidget* parent) : QWidget(parent), ui(new Ui:: connect(ui->button_regenerate_console_id, &QPushButton::clicked, this, &ConfigureSystem::RefreshConsoleID); - connect(ui->rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](bool checked) { - ui->rng_seed_edit->setEnabled(checked); - if (!checked) { + connect(ui->rng_seed_checkbox, &QCheckBox::stateChanged, this, [this](int state) { + ui->rng_seed_edit->setEnabled(state == Qt::Checked); + if (state != Qt::Checked) { ui->rng_seed_edit->setText(QStringLiteral("00000000")); } }); - connect(ui->custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](bool checked) { - ui->custom_rtc_edit->setEnabled(checked); - if (!checked) { + connect(ui->custom_rtc_checkbox, &QCheckBox::stateChanged, this, [this](int state) { + ui->custom_rtc_edit->setEnabled(state == Qt::Checked); + if (state != Qt::Checked) { ui->custom_rtc_edit->setDateTime(QDateTime::currentDateTime()); } }); + ui->label_console_id->setVisible(Settings::configuring_global); + ui->button_regenerate_console_id->setVisible(Settings::configuring_global); + + SetupPerGameUI(); + SetConfiguration(); } @@ -54,26 +60,58 @@ void ConfigureSystem::RetranslateUI() { void ConfigureSystem::SetConfiguration() { enabled = !Core::System::GetInstance().IsPoweredOn(); - - ui->combo_language->setCurrentIndex(Settings::values.language_index); - ui->combo_region->setCurrentIndex(Settings::values.region_index); - ui->combo_time_zone->setCurrentIndex(Settings::values.time_zone_index); - ui->combo_sound->setCurrentIndex(Settings::values.sound_index); - - ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.has_value()); - ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.has_value()); - - const auto rng_seed = QStringLiteral("%1") - .arg(Settings::values.rng_seed.value_or(0), 8, 16, QLatin1Char{'0'}) - .toUpper(); - ui->rng_seed_edit->setText(rng_seed); - - ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value()); - ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value()); - - const auto rtc_time = Settings::values.custom_rtc.value_or( + const auto rng_seed = + QStringLiteral("%1") + .arg(Settings::values.rng_seed.GetValue().value_or(0), 8, 16, QLatin1Char{'0'}) + .toUpper(); + const auto rtc_time = Settings::values.custom_rtc.GetValue().value_or( std::chrono::seconds(QDateTime::currentSecsSinceEpoch())); - ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count())); + + if (Settings::configuring_global) { + ui->combo_language->setCurrentIndex(Settings::values.language_index.GetValue()); + ui->combo_region->setCurrentIndex(Settings::values.region_index.GetValue()); + ui->combo_time_zone->setCurrentIndex(Settings::values.time_zone_index.GetValue()); + ui->combo_sound->setCurrentIndex(Settings::values.sound_index.GetValue()); + + ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value()); + ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() && + Settings::values.rng_seed.UsingGlobal()); + ui->rng_seed_edit->setText(rng_seed); + + ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.GetValue().has_value()); + ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value() && + Settings::values.rng_seed.UsingGlobal()); + ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count())); + } else { + ConfigurationShared::SetPerGameSetting(ui->combo_language, + &Settings::values.language_index); + ConfigurationShared::SetPerGameSetting(ui->combo_region, &Settings::values.region_index); + ConfigurationShared::SetPerGameSetting(ui->combo_time_zone, + &Settings::values.time_zone_index); + ConfigurationShared::SetPerGameSetting(ui->combo_sound, &Settings::values.sound_index); + + if (Settings::values.rng_seed.UsingGlobal()) { + ui->rng_seed_checkbox->setCheckState(Qt::PartiallyChecked); + } else { + ui->rng_seed_checkbox->setCheckState( + Settings::values.rng_seed.GetValue().has_value() ? Qt::Checked : Qt::Unchecked); + ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value()); + if (Settings::values.rng_seed.GetValue().has_value()) { + ui->rng_seed_edit->setText(rng_seed); + } + } + + if (Settings::values.custom_rtc.UsingGlobal()) { + ui->custom_rtc_checkbox->setCheckState(Qt::PartiallyChecked); + } else { + ui->custom_rtc_checkbox->setCheckState( + Settings::values.custom_rtc.GetValue().has_value() ? Qt::Checked : Qt::Unchecked); + ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value()); + if (Settings::values.custom_rtc.GetValue().has_value()) { + ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count())); + } + } + } } void ConfigureSystem::ReadSystemSettings() {} @@ -83,22 +121,78 @@ void ConfigureSystem::ApplyConfiguration() { return; } - Settings::values.language_index = ui->combo_language->currentIndex(); - Settings::values.region_index = ui->combo_region->currentIndex(); - Settings::values.time_zone_index = ui->combo_time_zone->currentIndex(); - Settings::values.sound_index = ui->combo_sound->currentIndex(); + if (Settings::configuring_global) { + // Guard if during game and set to game-specific value + if (Settings::values.language_index.UsingGlobal()) { + Settings::values.language_index.SetValue(ui->combo_language->currentIndex()); + } + if (Settings::values.region_index.UsingGlobal()) { + Settings::values.region_index.SetValue(ui->combo_region->currentIndex()); + } + if (Settings::values.time_zone_index.UsingGlobal()) { + Settings::values.time_zone_index.SetValue(ui->combo_time_zone->currentIndex()); + } + if (Settings::values.sound_index.UsingGlobal()) { + Settings::values.sound_index.SetValue(ui->combo_sound->currentIndex()); + } - if (ui->rng_seed_checkbox->isChecked()) { - Settings::values.rng_seed = ui->rng_seed_edit->text().toULongLong(nullptr, 16); - } else { - Settings::values.rng_seed = std::nullopt; - } + if (Settings::values.rng_seed.UsingGlobal()) { + if (ui->rng_seed_checkbox->isChecked()) { + Settings::values.rng_seed.SetValue( + ui->rng_seed_edit->text().toULongLong(nullptr, 16)); + } else { + Settings::values.rng_seed.SetValue(std::nullopt); + } + } - if (ui->custom_rtc_checkbox->isChecked()) { - Settings::values.custom_rtc = - std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch()); + if (Settings::values.custom_rtc.UsingGlobal()) { + if (ui->custom_rtc_checkbox->isChecked()) { + Settings::values.custom_rtc.SetValue( + std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch())); + } else { + Settings::values.custom_rtc.SetValue(std::nullopt); + } + } } else { - Settings::values.custom_rtc = std::nullopt; + ConfigurationShared::ApplyPerGameSetting(&Settings::values.language_index, + ui->combo_language); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.region_index, ui->combo_region); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.time_zone_index, + ui->combo_time_zone); + ConfigurationShared::ApplyPerGameSetting(&Settings::values.sound_index, ui->combo_sound); + + switch (ui->rng_seed_checkbox->checkState()) { + case Qt::Checked: + Settings::values.rng_seed.SetGlobal(false); + Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toULongLong(nullptr, 16)); + break; + case Qt::Unchecked: + Settings::values.rng_seed.SetGlobal(false); + Settings::values.rng_seed.SetValue(std::nullopt); + break; + case Qt::PartiallyChecked: + Settings::values.rng_seed.SetGlobal(false); + Settings::values.rng_seed.SetValue(std::nullopt); + Settings::values.rng_seed.SetGlobal(true); + break; + } + + switch (ui->custom_rtc_checkbox->checkState()) { + case Qt::Checked: + Settings::values.custom_rtc.SetGlobal(false); + Settings::values.custom_rtc.SetValue( + std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch())); + break; + case Qt::Unchecked: + Settings::values.custom_rtc.SetGlobal(false); + Settings::values.custom_rtc.SetValue(std::nullopt); + break; + case Qt::PartiallyChecked: + Settings::values.custom_rtc.SetGlobal(false); + Settings::values.custom_rtc.SetValue(std::nullopt); + Settings::values.custom_rtc.SetGlobal(true); + break; + } } Settings::Apply(); @@ -120,3 +214,25 @@ void ConfigureSystem::RefreshConsoleID() { ui->label_console_id->setText( tr("Console ID: 0x%1").arg(QString::number(console_id, 16).toUpper())); } + +void ConfigureSystem::SetupPerGameUI() { + if (Settings::configuring_global) { + ui->combo_language->setEnabled(Settings::values.language_index.UsingGlobal()); + ui->combo_region->setEnabled(Settings::values.region_index.UsingGlobal()); + ui->combo_time_zone->setEnabled(Settings::values.time_zone_index.UsingGlobal()); + ui->combo_sound->setEnabled(Settings::values.sound_index.UsingGlobal()); + ui->rng_seed_checkbox->setEnabled(Settings::values.rng_seed.UsingGlobal()); + ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.UsingGlobal()); + ui->custom_rtc_checkbox->setEnabled(Settings::values.custom_rtc.UsingGlobal()); + ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.UsingGlobal()); + + return; + } + + ConfigurationShared::InsertGlobalItem(ui->combo_language); + ConfigurationShared::InsertGlobalItem(ui->combo_region); + ConfigurationShared::InsertGlobalItem(ui->combo_time_zone); + ConfigurationShared::InsertGlobalItem(ui->combo_sound); + ui->rng_seed_checkbox->setTristate(true); + ui->custom_rtc_checkbox->setTristate(true); +} diff --git a/src/yuzu/configuration/configure_system.h b/src/yuzu/configuration/configure_system.h index 26d42d5c5..f317ef8b5 100644 --- a/src/yuzu/configuration/configure_system.h +++ b/src/yuzu/configuration/configure_system.h @@ -32,6 +32,8 @@ private: void RefreshConsoleID(); + void SetupPerGameUI(); + std::unique_ptr ui; bool enabled = false; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 9844e4764..4d501a8f9 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -16,7 +16,7 @@ #include "applets/software_keyboard.h" #include "applets/web_browser.h" #include "configuration/configure_input.h" -#include "configuration/configure_per_general.h" +#include "configuration/configure_per_game.h" #include "core/file_sys/vfs.h" #include "core/file_sys/vfs_real.h" #include "core/frontend/applets/general_frontend.h" @@ -534,15 +534,15 @@ void GMainWindow::InitializeWidgets() { if (emulation_running) { return; } - bool is_async = - !Settings::values.use_asynchronous_gpu_emulation || Settings::values.use_multi_core; - Settings::values.use_asynchronous_gpu_emulation = is_async; - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); + bool is_async = !Settings::values.use_asynchronous_gpu_emulation.GetValue() || + Settings::values.use_multi_core.GetValue(); + Settings::values.use_asynchronous_gpu_emulation.SetValue(is_async); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); Settings::Apply(); }); async_status_button->setText(tr("ASYNC")); async_status_button->setCheckable(true); - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); // Setup Multicore button multicore_status_button = new QPushButton(); @@ -552,17 +552,17 @@ void GMainWindow::InitializeWidgets() { if (emulation_running) { return; } - Settings::values.use_multi_core = !Settings::values.use_multi_core; - bool is_async = - Settings::values.use_asynchronous_gpu_emulation || Settings::values.use_multi_core; - Settings::values.use_asynchronous_gpu_emulation = is_async; - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); - multicore_status_button->setChecked(Settings::values.use_multi_core); + Settings::values.use_multi_core.SetValue(!Settings::values.use_multi_core.GetValue()); + bool is_async = Settings::values.use_asynchronous_gpu_emulation.GetValue() || + Settings::values.use_multi_core.GetValue(); + Settings::values.use_asynchronous_gpu_emulation.SetValue(is_async); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); + multicore_status_button->setChecked(Settings::values.use_multi_core.GetValue()); Settings::Apply(); }); multicore_status_button->setText(tr("MULTICORE")); multicore_status_button->setCheckable(true); - multicore_status_button->setChecked(Settings::values.use_multi_core); + multicore_status_button->setChecked(Settings::values.use_multi_core.GetValue()); statusBar()->insertPermanentWidget(0, multicore_status_button); statusBar()->insertPermanentWidget(0, async_status_button); @@ -581,16 +581,16 @@ void GMainWindow::InitializeWidgets() { renderer_status_button->setCheckable(false); renderer_status_button->setDisabled(true); #else - renderer_status_button->setChecked(Settings::values.renderer_backend == + renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == Settings::RendererBackend::Vulkan); connect(renderer_status_button, &QPushButton::clicked, [=] { if (emulation_running) { return; } if (renderer_status_button->isChecked()) { - Settings::values.renderer_backend = Settings::RendererBackend::Vulkan; + Settings::values.renderer_backend.SetValue(Settings::RendererBackend::Vulkan); } else { - Settings::values.renderer_backend = Settings::RendererBackend::OpenGL; + Settings::values.renderer_backend.SetValue(Settings::RendererBackend::OpenGL); } Settings::Apply(); @@ -727,21 +727,24 @@ void GMainWindow::InitializeHotkeys() { }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Toggle Speed Limit"), this), &QShortcut::activated, this, [&] { - Settings::values.use_frame_limit = !Settings::values.use_frame_limit; + Settings::values.use_frame_limit.SetValue( + !Settings::values.use_frame_limit.GetValue()); UpdateStatusBar(); }); constexpr u16 SPEED_LIMIT_STEP = 5; connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Increase Speed Limit"), this), &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit < 9999 - SPEED_LIMIT_STEP) { - Settings::values.frame_limit += SPEED_LIMIT_STEP; + if (Settings::values.frame_limit.GetValue() < 9999 - SPEED_LIMIT_STEP) { + Settings::values.frame_limit.SetValue(SPEED_LIMIT_STEP + + Settings::values.frame_limit.GetValue()); UpdateStatusBar(); } }); connect(hotkey_registry.GetHotkey(main_window, QStringLiteral("Decrease Speed Limit"), this), &QShortcut::activated, this, [&] { - if (Settings::values.frame_limit > SPEED_LIMIT_STEP) { - Settings::values.frame_limit -= SPEED_LIMIT_STEP; + if (Settings::values.frame_limit.GetValue() > SPEED_LIMIT_STEP) { + Settings::values.frame_limit.SetValue(Settings::values.frame_limit.GetValue() - + SPEED_LIMIT_STEP); UpdateStatusBar(); } }); @@ -1039,6 +1042,17 @@ void GMainWindow::BootGame(const QString& filename) { LOG_INFO(Frontend, "yuzu starting..."); StoreRecentFile(filename); // Put the filename on top of the list + u64 title_id{0}; + + const auto v_file = Core::GetGameFileFromPath(vfs, filename.toUtf8().constData()); + const auto loader = Loader::GetLoader(v_file); + if (!(loader == nullptr || loader->ReadProgramId(title_id) != Loader::ResultStatus::Success)) { + // Load per game settings + Config per_game_config(fmt::format("{:016X}.ini", title_id), false); + } + + Settings::LogSettings(); + if (UISettings::values.select_user_on_boot) { SelectAndSetCurrentUser(); } @@ -1063,6 +1077,7 @@ void GMainWindow::BootGame(const QString& filename) { &LoadingScreen::OnLoadProgress, Qt::QueuedConnection); // Update the GUI + UpdateStatusButtons(); if (ui.action_Single_Window_Mode->isChecked()) { game_list->hide(); game_list_placeholder->hide(); @@ -1078,8 +1093,6 @@ void GMainWindow::BootGame(const QString& filename) { ui.centralwidget->setMouseTracking(true); } - const u64 title_id = Core::System::GetInstance().CurrentProcess()->GetTitleID(); - std::string title_name; std::string title_version; const auto res = Core::System::GetInstance().GetGameName(title_name); @@ -1521,7 +1534,7 @@ void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) { return; } - ConfigurePerGameGeneral dialog(this, title_id); + ConfigurePerGame dialog(this, title_id); dialog.LoadFromFile(v_file); auto result = dialog.exec(); if (result == QDialog::Accepted) { @@ -1532,7 +1545,14 @@ void GMainWindow::OnGameListOpenPerGameProperties(const std::string& file) { game_list->PopulateAsync(UISettings::values.game_dirs); } - config->Save(); + // Do not cause the global config to write local settings into the config file + Settings::RestoreGlobalState(); + + if (!Core::System::GetInstance().IsPoweredOn()) { + config->Save(); + } + } else { + Settings::RestoreGlobalState(); } } @@ -1819,6 +1839,9 @@ void GMainWindow::OnStopGame() { } ShutdownGame(); + + Settings::RestoreGlobalState(); + UpdateStatusButtons(); } void GMainWindow::OnLoadComplete() { @@ -1926,7 +1949,7 @@ void GMainWindow::ToggleWindowMode() { void GMainWindow::ResetWindowSize() { const auto aspect_ratio = Layout::EmulationAspectRatio( - static_cast(Settings::values.aspect_ratio), + static_cast(Settings::values.aspect_ratio.GetValue()), static_cast(Layout::ScreenUndocked::Height) / Layout::ScreenUndocked::Width); if (!ui.action_Single_Window_Mode->isChecked()) { render_window->resize(Layout::ScreenUndocked::Height / aspect_ratio, @@ -1974,16 +1997,7 @@ void GMainWindow::OnConfigure() { ui.centralwidget->setMouseTracking(false); } - dock_status_button->setChecked(Settings::values.use_docked_mode); - multicore_status_button->setChecked(Settings::values.use_multi_core); - Settings::values.use_asynchronous_gpu_emulation = - Settings::values.use_asynchronous_gpu_emulation || Settings::values.use_multi_core; - async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation); - -#ifdef HAS_VULKAN - renderer_status_button->setChecked(Settings::values.renderer_backend == - Settings::RendererBackend::Vulkan); -#endif + UpdateStatusButtons(); } void GMainWindow::OnLoadAmiibo() { @@ -2097,21 +2111,34 @@ void GMainWindow::UpdateStatusBar() { auto results = Core::System::GetInstance().GetAndResetPerfStats(); - if (Settings::values.use_frame_limit) { + if (Settings::values.use_frame_limit.GetValue()) { emu_speed_label->setText(tr("Speed: %1% / %2%") .arg(results.emulation_speed * 100.0, 0, 'f', 0) - .arg(Settings::values.frame_limit)); + .arg(Settings::values.frame_limit.GetValue())); } else { emu_speed_label->setText(tr("Speed: %1%").arg(results.emulation_speed * 100.0, 0, 'f', 0)); } game_fps_label->setText(tr("Game: %1 FPS").arg(results.game_fps, 0, 'f', 0)); emu_frametime_label->setText(tr("Frame: %1 ms").arg(results.frametime * 1000.0, 0, 'f', 2)); - emu_speed_label->setVisible(!Settings::values.use_multi_core); + emu_speed_label->setVisible(!Settings::values.use_multi_core.GetValue()); game_fps_label->setVisible(true); emu_frametime_label->setVisible(true); } +void GMainWindow::UpdateStatusButtons() { + dock_status_button->setChecked(Settings::values.use_docked_mode); + multicore_status_button->setChecked(Settings::values.use_multi_core.GetValue()); + Settings::values.use_asynchronous_gpu_emulation.SetValue( + Settings::values.use_asynchronous_gpu_emulation.GetValue() || + Settings::values.use_multi_core.GetValue()); + async_status_button->setChecked(Settings::values.use_asynchronous_gpu_emulation.GetValue()); +#ifdef HAS_VULKAN + renderer_status_button->setChecked(Settings::values.renderer_backend.GetValue() == + Settings::RendererBackend::Vulkan); +#endif +} + void GMainWindow::HideMouseCursor() { if (emu_thread == nullptr || UISettings::values.hide_mouse == false) { mouse_hide_timer.stop(); @@ -2195,6 +2222,9 @@ void GMainWindow::OnCoreError(Core::System::ResultStatus result, std::string det if (answer == QMessageBox::Yes) { if (emu_thread) { ShutdownGame(); + + Settings::RestoreGlobalState(); + UpdateStatusButtons(); } } else { // Only show the message if the game is still running. @@ -2357,9 +2387,13 @@ void GMainWindow::closeEvent(QCloseEvent* event) { hotkey_registry.SaveHotkeys(); // Shutdown session if the emu thread is active... - if (emu_thread != nullptr) + if (emu_thread != nullptr) { ShutdownGame(); + Settings::RestoreGlobalState(); + UpdateStatusButtons(); + } + render_window->close(); QWidget::closeEvent(event); @@ -2539,8 +2573,6 @@ int main(int argc, char* argv[]) { QObject::connect(&app, &QGuiApplication::applicationStateChanged, &main_window, &GMainWindow::OnAppFocusStateChanged); - Settings::LogSettings(); - int result = app.exec(); detached_tasks.WaitForAllTasks(); return result; diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 66c84e5c0..8e3d39c38 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -221,6 +221,7 @@ private: void UpdateWindowTitle(const std::string& title_name = {}, const std::string& title_version = {}); void UpdateStatusBar(); + void UpdateStatusButtons(); void HideMouseCursor(); void ShowMouseCursor(); void OpenURL(const QUrl& url); diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 659b9f701..23763144f 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -354,63 +354,72 @@ void Config::ReadValues() { const auto rng_seed_enabled = sdl2_config->GetBoolean("System", "rng_seed_enabled", false); if (rng_seed_enabled) { - Settings::values.rng_seed = sdl2_config->GetInteger("System", "rng_seed", 0); + Settings::values.rng_seed.SetValue(sdl2_config->GetInteger("System", "rng_seed", 0)); } else { - Settings::values.rng_seed = std::nullopt; + Settings::values.rng_seed.SetValue(std::nullopt); } const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false); if (custom_rtc_enabled) { - Settings::values.custom_rtc = - std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0)); + Settings::values.custom_rtc.SetValue( + std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0))); } else { - Settings::values.custom_rtc = std::nullopt; + Settings::values.custom_rtc.SetValue(std::nullopt); } - Settings::values.language_index = sdl2_config->GetInteger("System", "language_index", 1); - Settings::values.time_zone_index = sdl2_config->GetInteger("System", "time_zone_index", 0); + Settings::values.language_index.SetValue( + sdl2_config->GetInteger("System", "language_index", 1)); + Settings::values.time_zone_index.SetValue( + sdl2_config->GetInteger("System", "time_zone_index", 0)); // Core - Settings::values.use_multi_core = sdl2_config->GetBoolean("Core", "use_multi_core", false); + Settings::values.use_multi_core.SetValue( + sdl2_config->GetBoolean("Core", "use_multi_core", false)); // Renderer const int renderer_backend = sdl2_config->GetInteger( "Renderer", "backend", static_cast(Settings::RendererBackend::OpenGL)); - Settings::values.renderer_backend = static_cast(renderer_backend); + Settings::values.renderer_backend.SetValue( + static_cast(renderer_backend)); Settings::values.renderer_debug = sdl2_config->GetBoolean("Renderer", "debug", false); - Settings::values.vulkan_device = sdl2_config->GetInteger("Renderer", "vulkan_device", 0); + Settings::values.vulkan_device.SetValue( + sdl2_config->GetInteger("Renderer", "vulkan_device", 0)); - Settings::values.aspect_ratio = - static_cast(sdl2_config->GetInteger("Renderer", "aspect_ratio", 0)); - Settings::values.max_anisotropy = - static_cast(sdl2_config->GetInteger("Renderer", "max_anisotropy", 0)); - Settings::values.use_frame_limit = sdl2_config->GetBoolean("Renderer", "use_frame_limit", true); - Settings::values.frame_limit = - static_cast(sdl2_config->GetInteger("Renderer", "frame_limit", 100)); - Settings::values.use_disk_shader_cache = - sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", false); + Settings::values.aspect_ratio.SetValue( + static_cast(sdl2_config->GetInteger("Renderer", "aspect_ratio", 0))); + Settings::values.max_anisotropy.SetValue( + static_cast(sdl2_config->GetInteger("Renderer", "max_anisotropy", 0))); + Settings::values.use_frame_limit.SetValue( + sdl2_config->GetBoolean("Renderer", "use_frame_limit", true)); + Settings::values.frame_limit.SetValue( + static_cast(sdl2_config->GetInteger("Renderer", "frame_limit", 100))); + Settings::values.use_disk_shader_cache.SetValue( + sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", false)); const int gpu_accuracy_level = sdl2_config->GetInteger("Renderer", "gpu_accuracy", 0); - Settings::values.gpu_accuracy = static_cast(gpu_accuracy_level); - Settings::values.use_asynchronous_gpu_emulation = - sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false); - Settings::values.use_vsync = - static_cast(sdl2_config->GetInteger("Renderer", "use_vsync", 1)); - Settings::values.use_assembly_shaders = - sdl2_config->GetBoolean("Renderer", "use_assembly_shaders", false); - Settings::values.use_fast_gpu_time = - sdl2_config->GetBoolean("Renderer", "use_fast_gpu_time", true); + Settings::values.gpu_accuracy.SetValue(static_cast(gpu_accuracy_level)); + Settings::values.use_asynchronous_gpu_emulation.SetValue( + sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false)); + Settings::values.use_vsync.SetValue( + static_cast(sdl2_config->GetInteger("Renderer", "use_vsync", 1))); + Settings::values.use_assembly_shaders.SetValue( + sdl2_config->GetBoolean("Renderer", "use_assembly_shaders", false)); + Settings::values.use_fast_gpu_time.SetValue( + sdl2_config->GetBoolean("Renderer", "use_fast_gpu_time", true)); - Settings::values.bg_red = static_cast(sdl2_config->GetReal("Renderer", "bg_red", 0.0)); - Settings::values.bg_green = - static_cast(sdl2_config->GetReal("Renderer", "bg_green", 0.0)); - Settings::values.bg_blue = static_cast(sdl2_config->GetReal("Renderer", "bg_blue", 0.0)); + Settings::values.bg_red.SetValue( + static_cast(sdl2_config->GetReal("Renderer", "bg_red", 0.0))); + Settings::values.bg_green.SetValue( + static_cast(sdl2_config->GetReal("Renderer", "bg_green", 0.0))); + Settings::values.bg_blue.SetValue( + static_cast(sdl2_config->GetReal("Renderer", "bg_blue", 0.0))); // Audio Settings::values.sink_id = sdl2_config->Get("Audio", "output_engine", "auto"); - Settings::values.enable_audio_stretching = - sdl2_config->GetBoolean("Audio", "enable_audio_stretching", true); + Settings::values.enable_audio_stretching.SetValue( + sdl2_config->GetBoolean("Audio", "enable_audio_stretching", true)); Settings::values.audio_device_id = sdl2_config->Get("Audio", "output_device", "auto"); - Settings::values.volume = static_cast(sdl2_config->GetReal("Audio", "volume", 1)); + Settings::values.volume.SetValue( + static_cast(sdl2_config->GetReal("Audio", "volume", 1))); // Miscellaneous Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Trace"); diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp index 09cc0a3b5..e78025737 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2_gl.cpp @@ -165,7 +165,7 @@ std::unique_ptr EmuWindow_SDL2_GL::CreateShared void EmuWindow_SDL2_GL::Present() { SDL_GL_MakeCurrent(render_window, window_context); - SDL_GL_SetSwapInterval(Settings::values.use_vsync ? 1 : 0); + SDL_GL_SetSwapInterval(Settings::values.use_vsync.GetValue() ? 1 : 0); while (IsOpen()) { system.Renderer().TryPresent(100); SDL_GL_SwapWindow(render_window); diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index e6c6a839d..512b060a7 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -181,7 +181,7 @@ int main(int argc, char** argv) { Core::System& system{Core::System::GetInstance()}; std::unique_ptr emu_window; - switch (Settings::values.renderer_backend) { + switch (Settings::values.renderer_backend.GetValue()) { case Settings::RendererBackend::OpenGL: emu_window = std::make_unique(system, fullscreen); break; diff --git a/src/yuzu_tester/config.cpp b/src/yuzu_tester/config.cpp index 1566c2e3f..acb22885e 100644 --- a/src/yuzu_tester/config.cpp +++ b/src/yuzu_tester/config.cpp @@ -81,6 +81,9 @@ void Config::ReadValues() { Settings::values.touchscreen.diameter_x = 15; Settings::values.touchscreen.diameter_y = 15; + Settings::values.use_docked_mode = + sdl2_config->GetBoolean("Controls", "use_docked_mode", false); + // Data Storage Settings::values.use_virtual_sd = sdl2_config->GetBoolean("Data Storage", "use_virtual_sd", true); @@ -92,57 +95,59 @@ void Config::ReadValues() { FileUtil::GetUserPath(FileUtil::UserPath::SDMCDir))); // System - Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false); - Settings::values.current_user = std::clamp( sdl2_config->GetInteger("System", "current_user", 0), 0, Service::Account::MAX_USERS - 1); const auto rng_seed_enabled = sdl2_config->GetBoolean("System", "rng_seed_enabled", false); if (rng_seed_enabled) { - Settings::values.rng_seed = sdl2_config->GetInteger("System", "rng_seed", 0); + Settings::values.rng_seed.SetValue(sdl2_config->GetInteger("System", "rng_seed", 0)); } else { - Settings::values.rng_seed = std::nullopt; + Settings::values.rng_seed.SetValue(std::nullopt); } const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false); if (custom_rtc_enabled) { - Settings::values.custom_rtc = - std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0)); + Settings::values.custom_rtc.SetValue( + std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0))); } else { - Settings::values.custom_rtc = std::nullopt; + Settings::values.custom_rtc.SetValue(std::nullopt); } // Core - Settings::values.use_multi_core = sdl2_config->GetBoolean("Core", "use_multi_core", false); + Settings::values.use_multi_core.SetValue( + sdl2_config->GetBoolean("Core", "use_multi_core", false)); // Renderer - Settings::values.aspect_ratio = - static_cast(sdl2_config->GetInteger("Renderer", "aspect_ratio", 0)); - Settings::values.max_anisotropy = - static_cast(sdl2_config->GetInteger("Renderer", "max_anisotropy", 0)); - Settings::values.use_frame_limit = false; - Settings::values.frame_limit = 100; - Settings::values.use_disk_shader_cache = - sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", false); + Settings::values.aspect_ratio.SetValue( + static_cast(sdl2_config->GetInteger("Renderer", "aspect_ratio", 0))); + Settings::values.max_anisotropy.SetValue( + static_cast(sdl2_config->GetInteger("Renderer", "max_anisotropy", 0))); + Settings::values.use_frame_limit.SetValue(false); + Settings::values.frame_limit.SetValue(100); + Settings::values.use_disk_shader_cache.SetValue( + sdl2_config->GetBoolean("Renderer", "use_disk_shader_cache", false)); const int gpu_accuracy_level = sdl2_config->GetInteger("Renderer", "gpu_accuracy", 0); - Settings::values.gpu_accuracy = static_cast(gpu_accuracy_level); - Settings::values.use_asynchronous_gpu_emulation = - sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false); - Settings::values.use_fast_gpu_time = - sdl2_config->GetBoolean("Renderer", "use_fast_gpu_time", true); + Settings::values.gpu_accuracy.SetValue(static_cast(gpu_accuracy_level)); + Settings::values.use_asynchronous_gpu_emulation.SetValue( + sdl2_config->GetBoolean("Renderer", "use_asynchronous_gpu_emulation", false)); + Settings::values.use_fast_gpu_time.SetValue( + sdl2_config->GetBoolean("Renderer", "use_fast_gpu_time", true)); - Settings::values.bg_red = static_cast(sdl2_config->GetReal("Renderer", "bg_red", 0.0)); - Settings::values.bg_green = - static_cast(sdl2_config->GetReal("Renderer", "bg_green", 0.0)); - Settings::values.bg_blue = static_cast(sdl2_config->GetReal("Renderer", "bg_blue", 0.0)); + Settings::values.bg_red.SetValue( + static_cast(sdl2_config->GetReal("Renderer", "bg_red", 0.0))); + Settings::values.bg_green.SetValue( + static_cast(sdl2_config->GetReal("Renderer", "bg_green", 0.0))); + Settings::values.bg_blue.SetValue( + static_cast(sdl2_config->GetReal("Renderer", "bg_blue", 0.0))); // Audio Settings::values.sink_id = "null"; - Settings::values.enable_audio_stretching = false; + Settings::values.enable_audio_stretching.SetValue(false); Settings::values.audio_device_id = "auto"; - Settings::values.volume = 0; + Settings::values.volume.SetValue(0); - Settings::values.language_index = sdl2_config->GetInteger("System", "language_index", 1); + Settings::values.language_index.SetValue( + sdl2_config->GetInteger("System", "language_index", 1)); // Miscellaneous Settings::values.log_filter = sdl2_config->Get("Miscellaneous", "log_filter", "*:Trace"); From 48aa076049f9c3ac05b32682027d48639cd72528 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Fri, 10 Jul 2020 14:02:44 +1000 Subject: [PATCH 18/55] cmake: Fix libusb builds breaking --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index cd40e5cfe..4619f33f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,6 +330,7 @@ elseif(SDL2_FOUND) endif() # Ensure libusb is properly configured (based on dolphin libusb include) +INCLUDE(FindPkgConfig) find_package(LibUSB) if (NOT LIBUSB_FOUND) add_subdirectory(externals/libusb) From bd2feb68739b47bab7af929f9e9dd1d5ebcaec37 Mon Sep 17 00:00:00 2001 From: David Marcec Date: Fri, 10 Jul 2020 14:04:06 +1000 Subject: [PATCH 19/55] cmake: Fix libfmt linking errors --- src/common/CMakeLists.txt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 423bef0f5..d120c8d3d 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -191,9 +191,5 @@ endif() create_target_directory_groups(common) find_package(Boost 1.71 COMPONENTS context headers REQUIRED) -if (fmt_FOUND) - target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt microprofile) -else() - target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) -endif() +target_link_libraries(common PUBLIC ${Boost_LIBRARIES} fmt::fmt microprofile) target_link_libraries(common PRIVATE lz4::lz4 zstd::zstd xbyak) From 47e26d7bc78d5ee73776def99a92d3519e6c9d0f Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 9 Jul 2020 12:19:06 -0400 Subject: [PATCH 20/55] settings: Remove storage size options --- src/core/settings.h | 29 ----- src/yuzu/configuration/config.cpp | 29 +---- .../configuration/configure_filesystem.cpp | 27 ---- .../configuration/configure_filesystem.ui | 121 ------------------ src/yuzu_cmd/config.cpp | 9 -- 5 files changed, 1 insertion(+), 214 deletions(-) diff --git a/src/core/settings.h b/src/core/settings.h index 850ca4072..29dc57c16 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -346,31 +346,6 @@ struct TouchscreenInput { u32 rotation_angle; }; -enum class NANDTotalSize : u64 { - S29_1GB = 0x747C00000ULL, -}; - -enum class NANDUserSize : u64 { - S26GB = 0x680000000ULL, -}; - -enum class NANDSystemSize : u64 { - S2_5GB = 0xA0000000, -}; - -enum class SDMCSize : u64 { - S1GB = 0x40000000, - S2GB = 0x80000000, - S4GB = 0x100000000ULL, - S8GB = 0x200000000ULL, - S16GB = 0x400000000ULL, - S32GB = 0x800000000ULL, - S64GB = 0x1000000000ULL, - S128GB = 0x2000000000ULL, - S256GB = 0x4000000000ULL, - S1TB = 0x10000000000ULL, -}; - enum class RendererBackend { OpenGL = 0, Vulkan = 1, @@ -491,10 +466,6 @@ struct Values { bool gamecard_inserted; bool gamecard_current_game; std::string gamecard_path; - NANDTotalSize nand_total_size; - NANDSystemSize nand_system_size; - NANDUserSize nand_user_size; - SDMCSize sdmc_size; // Debugging bool record_frame_times; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 1b2b1b2bb..f48785697 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -505,22 +505,6 @@ void Config::ReadDataStorageValues() { ReadSetting(QStringLiteral("gamecard_current_game"), false).toBool(); Settings::values.gamecard_path = ReadSetting(QStringLiteral("gamecard_path"), QStringLiteral("")).toString().toStdString(); - Settings::values.nand_total_size = static_cast( - ReadSetting(QStringLiteral("nand_total_size"), - QVariant::fromValue(static_cast(Settings::NANDTotalSize::S29_1GB))) - .toULongLong()); - Settings::values.nand_user_size = static_cast( - ReadSetting(QStringLiteral("nand_user_size"), - QVariant::fromValue(static_cast(Settings::NANDUserSize::S26GB))) - .toULongLong()); - Settings::values.nand_system_size = static_cast( - ReadSetting(QStringLiteral("nand_system_size"), - QVariant::fromValue(static_cast(Settings::NANDSystemSize::S2_5GB))) - .toULongLong()); - Settings::values.sdmc_size = static_cast( - ReadSetting(QStringLiteral("sdmc_size"), - QVariant::fromValue(static_cast(Settings::SDMCSize::S16GB))) - .toULongLong()); qt_config->endGroup(); } @@ -1006,18 +990,7 @@ void Config::SaveDataStorageValues() { false); WriteSetting(QStringLiteral("gamecard_path"), QString::fromStdString(Settings::values.gamecard_path), QStringLiteral("")); - WriteSetting(QStringLiteral("nand_total_size"), - QVariant::fromValue(static_cast(Settings::values.nand_total_size)), - QVariant::fromValue(static_cast(Settings::NANDTotalSize::S29_1GB))); - WriteSetting(QStringLiteral("nand_user_size"), - QVariant::fromValue(static_cast(Settings::values.nand_user_size)), - QVariant::fromValue(static_cast(Settings::NANDUserSize::S26GB))); - WriteSetting(QStringLiteral("nand_system_size"), - QVariant::fromValue(static_cast(Settings::values.nand_system_size)), - QVariant::fromValue(static_cast(Settings::NANDSystemSize::S2_5GB))); - WriteSetting(QStringLiteral("sdmc_size"), - QVariant::fromValue(static_cast(Settings::values.sdmc_size)), - QVariant::fromValue(static_cast(Settings::SDMCSize::S16GB))); + qt_config->endGroup(); } diff --git a/src/yuzu/configuration/configure_filesystem.cpp b/src/yuzu/configuration/configure_filesystem.cpp index 835ee821c..a089f5733 100644 --- a/src/yuzu/configuration/configure_filesystem.cpp +++ b/src/yuzu/configuration/configure_filesystem.cpp @@ -11,19 +11,6 @@ #include "yuzu/configuration/configure_filesystem.h" #include "yuzu/uisettings.h" -namespace { - -template -void SetComboBoxFromData(QComboBox* combo_box, T data) { - const auto index = combo_box->findData(QVariant::fromValue(static_cast(data))); - if (index >= combo_box->count() || index < 0) - return; - - combo_box->setCurrentIndex(index); -} - -} // Anonymous namespace - ConfigureFilesystem::ConfigureFilesystem(QWidget* parent) : QWidget(parent), ui(std::make_unique()) { ui->setupUi(this); @@ -73,11 +60,6 @@ void ConfigureFilesystem::setConfiguration() { ui->cache_game_list->setChecked(UISettings::values.cache_game_list); - SetComboBoxFromData(ui->nand_size, Settings::values.nand_total_size); - SetComboBoxFromData(ui->usrnand_size, Settings::values.nand_user_size); - SetComboBoxFromData(ui->sysnand_size, Settings::values.nand_system_size); - SetComboBoxFromData(ui->sdmc_size, Settings::values.sdmc_size); - UpdateEnabledControls(); } @@ -98,15 +80,6 @@ void ConfigureFilesystem::applyConfiguration() { Settings::values.dump_nso = ui->dump_nso->isChecked(); UISettings::values.cache_game_list = ui->cache_game_list->isChecked(); - - Settings::values.nand_total_size = static_cast( - ui->nand_size->itemData(ui->nand_size->currentIndex()).toULongLong()); - Settings::values.nand_system_size = static_cast( - ui->nand_size->itemData(ui->sysnand_size->currentIndex()).toULongLong()); - Settings::values.nand_user_size = static_cast( - ui->nand_size->itemData(ui->usrnand_size->currentIndex()).toULongLong()); - Settings::values.sdmc_size = static_cast( - ui->nand_size->itemData(ui->sdmc_size->currentIndex()).toULongLong()); } void ConfigureFilesystem::SetDirectory(DirectoryTarget target, QLineEdit* edit) { diff --git a/src/yuzu/configuration/configure_filesystem.ui b/src/yuzu/configuration/configure_filesystem.ui index 58cd07f52..84bea0600 100644 --- a/src/yuzu/configuration/configure_filesystem.ui +++ b/src/yuzu/configuration/configure_filesystem.ui @@ -115,127 +115,6 @@
- - - - Storage Sizes - - - - - - SD Card - - - - - - - System NAND - - - - - - - - 2.5 GB - - - - - - - - 32 GB - - - - 1 GB - - - - - 2 GB - - - - - 4 GB - - - - - 8 GB - - - - - 16 GB - - - - - 32 GB - - - - - 64 GB - - - - - 128 GB - - - - - 256 GB - - - - - 1 TB - - - - - - - - - 26 GB - - - - - - - - User NAND - - - - - - - NAND - - - - - - - - 29.1 GB - - - - - - - diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 23763144f..dce70a1e0 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -335,15 +335,6 @@ void Config::ReadValues() { Settings::values.gamecard_current_game = sdl2_config->GetBoolean("Data Storage", "gamecard_current_game", false); Settings::values.gamecard_path = sdl2_config->Get("Data Storage", "gamecard_path", ""); - Settings::values.nand_total_size = static_cast(sdl2_config->GetInteger( - "Data Storage", "nand_total_size", static_cast(Settings::NANDTotalSize::S29_1GB))); - Settings::values.nand_user_size = static_cast(sdl2_config->GetInteger( - "Data Storage", "nand_user_size", static_cast(Settings::NANDUserSize::S26GB))); - Settings::values.nand_system_size = static_cast( - sdl2_config->GetInteger("Data Storage", "nand_system_size", - static_cast(Settings::NANDSystemSize::S2_5GB))); - Settings::values.sdmc_size = static_cast(sdl2_config->GetInteger( - "Data Storage", "sdmc_size", static_cast(Settings::SDMCSize::S16GB))); // System Settings::values.use_docked_mode = sdl2_config->GetBoolean("System", "use_docked_mode", false); From 0373ead96e45a590ded0949a801a2783ef1097bf Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 9 Jul 2020 12:29:12 -0400 Subject: [PATCH 21/55] bis_factory: Use hardware default NAND partition sizes Sets the total space of user and system partitions to their hardware defaults. Furthermore, return the total space as free space for the user partition to prevent it from reaching zero. Some games like Bioshock 2 check for the available free space prior to save creation, and we should not be limited by arbitrary limits. --- src/core/file_sys/bis_factory.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/core/file_sys/bis_factory.cpp b/src/core/file_sys/bis_factory.cpp index 8935a62c3..a412dbd9c 100644 --- a/src/core/file_sys/bis_factory.cpp +++ b/src/core/file_sys/bis_factory.cpp @@ -12,6 +12,10 @@ namespace FileSys { +constexpr u64 NAND_USER_SIZE = 0x680000000; // 26624 MiB +constexpr u64 NAND_SYSTEM_SIZE = 0xA0000000; // 2560 MiB +constexpr u64 NAND_TOTAL_SIZE = 0x747C00000; // 29820 MiB + BISFactory::BISFactory(VirtualDir nand_root_, VirtualDir load_root_, VirtualDir dump_root_) : nand_root(std::move(nand_root_)), load_root(std::move(load_root_)), dump_root(std::move(dump_root_)), @@ -110,30 +114,27 @@ VirtualDir BISFactory::GetImageDirectory() const { u64 BISFactory::GetSystemNANDFreeSpace() const { const auto sys_dir = GetOrCreateDirectoryRelative(nand_root, "/system"); - if (sys_dir == nullptr) - return 0; + if (sys_dir == nullptr) { + return GetSystemNANDTotalSpace(); + } return GetSystemNANDTotalSpace() - sys_dir->GetSize(); } u64 BISFactory::GetSystemNANDTotalSpace() const { - return static_cast(Settings::values.nand_system_size); + return NAND_SYSTEM_SIZE; } u64 BISFactory::GetUserNANDFreeSpace() const { - const auto usr_dir = GetOrCreateDirectoryRelative(nand_root, "/user"); - if (usr_dir == nullptr) - return 0; - - return GetUserNANDTotalSpace() - usr_dir->GetSize(); + return GetUserNANDTotalSpace(); } u64 BISFactory::GetUserNANDTotalSpace() const { - return static_cast(Settings::values.nand_user_size); + return NAND_USER_SIZE; } u64 BISFactory::GetFullNANDTotalSpace() const { - return static_cast(Settings::values.nand_total_size); + return NAND_TOTAL_SIZE; } VirtualDir BISFactory::GetBCATDirectory(u64 title_id) const { From 17242a886590ec06dfb56d2e50679485dfb64905 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 9 Jul 2020 12:32:07 -0400 Subject: [PATCH 22/55] sdmc_factory: Set the SDMC total size to 1 TiB We should not be limited by the SDMC's partition size, set this to 1 TiB. Hardware is limited to the max allowed by the MBR partition table which is 2 TiB. --- src/core/file_sys/sdmc_factory.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/file_sys/sdmc_factory.cpp b/src/core/file_sys/sdmc_factory.cpp index 5113a1ca6..6f732e4d8 100644 --- a/src/core/file_sys/sdmc_factory.cpp +++ b/src/core/file_sys/sdmc_factory.cpp @@ -10,6 +10,8 @@ namespace FileSys { +constexpr u64 SDMC_TOTAL_SIZE = 0x10000000000; // 1 TiB + SDMCFactory::SDMCFactory(VirtualDir dir_) : dir(std::move(dir_)), contents(std::make_unique( GetOrCreateDirectoryRelative(dir, "/Nintendo/Contents/registered"), @@ -46,7 +48,7 @@ u64 SDMCFactory::GetSDMCFreeSpace() const { } u64 SDMCFactory::GetSDMCTotalSpace() const { - return static_cast(Settings::values.sdmc_size); + return SDMC_TOTAL_SIZE; } } // namespace FileSys From b24b463c874b5c71c906e05f42d44912e071fa06 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 9 Jul 2020 14:38:28 -0400 Subject: [PATCH 23/55] bis_factory: Set User NAND free space to be 1 MiB less than total. --- src/core/file_sys/bis_factory.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/file_sys/bis_factory.cpp b/src/core/file_sys/bis_factory.cpp index a412dbd9c..285277ef8 100644 --- a/src/core/file_sys/bis_factory.cpp +++ b/src/core/file_sys/bis_factory.cpp @@ -126,7 +126,9 @@ u64 BISFactory::GetSystemNANDTotalSpace() const { } u64 BISFactory::GetUserNANDFreeSpace() const { - return GetUserNANDTotalSpace(); + // For some reason games such as BioShock 1 checks whether this is exactly 0x680000000 bytes. + // Set the free space to be 1 MiB less than the total as a workaround to this issue. + return GetUserNANDTotalSpace() - 0x100000; } u64 BISFactory::GetUserNANDTotalSpace() const { From 4c269e5ced47765f35dbb58afa9fcac8138a1f7c Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 16 Apr 2020 23:27:38 -0400 Subject: [PATCH 24/55] Add support for batch install to NAND This adds support to batch install files to NAND --- src/yuzu/CMakeLists.txt | 6 +- src/yuzu/install_dialog.cpp | 72 +++++++++ src/yuzu/install_dialog.h | 35 +++++ src/yuzu/main.cpp | 299 +++++++++++++++++++++--------------- src/yuzu/main.h | 4 + src/yuzu/main.ui | 2 +- 6 files changed, 292 insertions(+), 126 deletions(-) create mode 100644 src/yuzu/install_dialog.cpp create mode 100644 src/yuzu/install_dialog.h diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 742b72856..f430525f8 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -98,11 +98,13 @@ add_executable(yuzu game_list_p.h game_list_worker.cpp game_list_worker.h + hotkeys.cpp + hotkeys.h + install_dialog.cpp + install_dialog.h loading_screen.cpp loading_screen.h loading_screen.ui - hotkeys.cpp - hotkeys.h main.cpp main.h main.ui diff --git a/src/yuzu/install_dialog.cpp b/src/yuzu/install_dialog.cpp new file mode 100644 index 000000000..fac158c25 --- /dev/null +++ b/src/yuzu/install_dialog.cpp @@ -0,0 +1,72 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include +#include +#include +#include +#include +#include "yuzu/install_dialog.h" +#include "yuzu/uisettings.h" + +InstallDialog::InstallDialog(QWidget* parent, const QStringList& files) : QDialog(parent) { + file_list = new QListWidget(this); + + for (const QString& file : files) { + QListWidgetItem* item = new QListWidgetItem(QFileInfo(file).fileName(), file_list); + item->setData(Qt::UserRole, file); + item->setFlags(item->flags() | Qt::ItemIsUserCheckable); + item->setCheckState(Qt::Checked); + } + + file_list->setMinimumWidth((file_list->sizeHintForColumn(0) * 6) / 5); + + vbox_layout = new QVBoxLayout; + + hbox_layout = new QHBoxLayout; + + description = new QLabel(tr("Please confirm these are the files you wish to install.")); + + overwrite_files = new QCheckBox(tr("Overwrite Existing Files")); + overwrite_files->setCheckState(Qt::Unchecked); + + buttons = new QDialogButtonBox; + buttons->addButton(QDialogButtonBox::Cancel); + buttons->addButton(tr("Install"), QDialogButtonBox::AcceptRole); + + connect(buttons, &QDialogButtonBox::accepted, this, &InstallDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, this, &InstallDialog::reject); + + hbox_layout->addWidget(overwrite_files); + hbox_layout->addWidget(buttons); + + vbox_layout->addWidget(description); + vbox_layout->addWidget(file_list); + vbox_layout->addLayout(hbox_layout); + + setLayout(vbox_layout); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + setWindowTitle(tr("Install Files to NAND")); +} + +InstallDialog::~InstallDialog() = default; + +QStringList InstallDialog::GetFilenames() const { + QStringList filenames; + + for (int i = 0; i < file_list->count(); ++i) { + const QListWidgetItem* item = file_list->item(i); + if (item->checkState() == Qt::Checked) { + filenames.append(item->data(Qt::UserRole).toString()); + } + } + + return filenames; +} + +bool InstallDialog::ShouldOverwriteFiles() const { + return overwrite_files->isChecked(); +} \ No newline at end of file diff --git a/src/yuzu/install_dialog.h b/src/yuzu/install_dialog.h new file mode 100644 index 000000000..3eaa9e60a --- /dev/null +++ b/src/yuzu/install_dialog.h @@ -0,0 +1,35 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include + +class QCheckBox; +class QDialogButtonBox; +class QHBoxLayout; +class QLabel; +class QListWidget; +class QVBoxLayout; + +class InstallDialog : public QDialog { + Q_OBJECT + +public: + explicit InstallDialog(QWidget* parent, const QStringList& files); + ~InstallDialog() override; + + QStringList GetFilenames() const; + bool ShouldOverwriteFiles() const; + +private: + QListWidget* file_list; + + QVBoxLayout* vbox_layout; + QHBoxLayout* hbox_layout; + + QLabel* description; + QCheckBox* overwrite_files; + QDialogButtonBox* buttons; +}; \ No newline at end of file diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4d501a8f9..45ddc3baf 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -107,6 +107,7 @@ static FileSys::VirtualFile VfsDirectoryCreateFileWrapper(const FileSys::Virtual #include "yuzu/game_list.h" #include "yuzu/game_list_p.h" #include "yuzu/hotkeys.h" +#include "yuzu/install_dialog.h" #include "yuzu/loading_screen.h" #include "yuzu/main.h" #include "yuzu/uisettings.h" @@ -1596,38 +1597,67 @@ void GMainWindow::OnMenuLoadFolder() { void GMainWindow::OnMenuInstallToNAND() { const QString file_filter = tr("Installable Switch File (*.nca *.nsp *.xci);;Nintendo Content Archive " - "(*.nca);;Nintendo Submissions Package (*.nsp);;NX Cartridge " + "(*.nca);;Nintendo Submission Package (*.nsp);;NX Cartridge " "Image (*.xci)"); - QString filename = QFileDialog::getOpenFileName(this, tr("Install File"), - UISettings::values.roms_path, file_filter); + QStringList files = QFileDialog::getOpenFileNames(this, tr("Install Files"), + UISettings::values.roms_path, file_filter); - if (filename.isEmpty()) { + if (files.isEmpty()) { return; } - const auto qt_raw_copy = [this](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, std::size_t block_size) { - if (src == nullptr || dest == nullptr) + InstallDialog installDialog(this, files); + if (installDialog.exec() == QDialog::Rejected) { + return; + } + + const QStringList filenames = installDialog.GetFilenames(); + const bool overwrite_files = installDialog.ShouldOverwriteFiles(); + + int count = 0; + int total_count = filenames.size(); + bool is_progressdialog_created = false; + + const auto qt_raw_copy = [this, &count, &total_count, &is_progressdialog_created]( + const FileSys::VirtualFile& src, const FileSys::VirtualFile& dest, + std::size_t block_size) { + if (src == nullptr || dest == nullptr) { return false; - if (!dest->Resize(src->GetSize())) + } + if (!dest->Resize(src->GetSize())) { return false; + } std::array buffer{}; const int progress_maximum = static_cast(src->GetSize() / buffer.size()); - QProgressDialog progress( - tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())), - tr("Cancel"), 0, progress_maximum, this); - progress.setWindowModality(Qt::WindowModal); + if (!is_progressdialog_created) { + ui.action_Install_File_NAND->setEnabled(false); + install_progress = new QProgressDialog( + tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())), + tr("Cancel"), 0, progress_maximum, this); + install_progress->setWindowTitle( + tr("%n file(s) remaining", "", total_count - count - 1)); + install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & + ~Qt::WindowMaximizeButtonHint); + install_progress->setAutoClose(false); + is_progressdialog_created = true; + } else { + install_progress->setWindowTitle( + tr("%n file(s) remaining", "", total_count - count - 1)); + install_progress->setLabelText( + tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName()))); + install_progress->setMaximum(progress_maximum); + } for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (progress.wasCanceled()) { + if (install_progress->wasCanceled()) { dest->Resize(0); return false; } const int progress_value = static_cast(i / buffer.size()); - progress.setValue(progress_value); + install_progress->setValue(progress_value); const auto read = src->Read(buffer.data(), buffer.size(), i); dest->Write(buffer.data(), read, i); @@ -1636,143 +1666,166 @@ void GMainWindow::OnMenuInstallToNAND() { return true; }; - const auto success = [this]() { + const auto success = [this, &count, &is_progressdialog_created]() { + if (is_progressdialog_created) { + install_progress->close(); + } QMessageBox::information(this, tr("Successfully Installed"), - tr("The file was successfully installed.")); + tr("%n file(s) successfully installed", "", count)); game_list->PopulateAsync(UISettings::values.game_dirs); FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + "game_list"); + ui.action_Install_File_NAND->setEnabled(true); }; - const auto failed = [this]() { + const auto failed = [this, &is_progressdialog_created](const QString& file) { + if (is_progressdialog_created) { + install_progress->close(); + } QMessageBox::warning( - this, tr("Failed to Install"), + this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), tr("There was an error while attempting to install the provided file. It " "could have an incorrect format or be missing metadata. Please " "double-check your file and try again.")); + game_list->PopulateAsync(UISettings::values.game_dirs); + ui.action_Install_File_NAND->setEnabled(true); }; - const auto overwrite = [this]() { - return QMessageBox::question(this, tr("Failed to Install"), - tr("The file you are attempting to install already exists " - "in the cache. Would you like to overwrite it?")) == - QMessageBox::Yes; + const auto overwrite = [this](const QString& file) { + return QMessageBox::question( + this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), + tr("The file you are attempting to install already exists " + "in the cache. Would you like to overwrite it?")) == QMessageBox::Yes; }; - if (filename.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || - filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - std::shared_ptr nsp; - if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - nsp = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - if (nsp->IsExtractedType()) - failed(); - } else { - const auto xci = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - nsp = xci->GetSecurePartitionNSP(); - } + for (const QString& filename : filenames) { + if (filename.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || + filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + std::shared_ptr nsp; + if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + nsp = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + if (nsp->IsExtractedType()) { + failed(filename); + break; + } + } else { + const auto xci = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + nsp = xci->GetSecurePartitionNSP(); + } - if (nsp->GetStatus() != Loader::ResultStatus::Success) { - failed(); - return; - } - const auto res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, false, qt_raw_copy); - if (res == FileSys::InstallResult::Success) { - success(); - } else { - if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite()) { + if (nsp->GetStatus() != Loader::ResultStatus::Success) { + failed(filename); + break; + } + const auto res = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nsp, false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + ++count; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files && overwrite(filename)) { const auto res2 = Core::System::GetInstance() .GetFileSystemController() .GetUserNANDContents() ->InstallEntry(*nsp, true, qt_raw_copy); - if (res2 == FileSys::InstallResult::Success) { - success(); - } else { - failed(); + if (res2 != FileSys::InstallResult::Success) { + failed(filename); + break; } + ++count; + } else { + --total_count; } } else { - failed(); + failed(filename); + break; } - } - } else { - const auto nca = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - const auto id = nca->GetStatus(); - - // Game updates necessary are missing base RomFS - if (id != Loader::ResultStatus::Success && - id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) { - failed(); - return; - } - - const QStringList tt_options{tr("System Application"), - tr("System Archive"), - tr("System Application Update"), - tr("Firmware Package (Type A)"), - tr("Firmware Package (Type B)"), - tr("Game"), - tr("Game Update"), - tr("Game DLC"), - tr("Delta Title")}; - bool ok; - const auto item = QInputDialog::getItem( - this, tr("Select NCA Install Type..."), - tr("Please select the type of title you would like to install this NCA as:\n(In " - "most instances, the default 'Game' is fine.)"), - tt_options, 5, false, &ok); - - auto index = tt_options.indexOf(item); - if (!ok || index == -1) { - QMessageBox::warning(this, tr("Failed to Install"), - tr("The title type you selected for the NCA is invalid.")); - return; - } - - // If index is equal to or past Game, add the jump in TitleType. - if (index >= 5) { - index += static_cast(FileSys::TitleType::Application) - - static_cast(FileSys::TitleType::FirmwarePackageB); - } - - FileSys::InstallResult res; - if (index >= static_cast(FileSys::TitleType::Application)) { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); } else { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetSystemNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); - } + const auto nca = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + const auto id = nca->GetStatus(); - if (res == FileSys::InstallResult::Success) { - success(); - } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite()) { - const auto res2 = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), - true, qt_raw_copy); - if (res2 == FileSys::InstallResult::Success) { - success(); + // Game updates necessary are missing base RomFS + if (id != Loader::ResultStatus::Success && + id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) { + failed(filename); + break; + } + + const QStringList tt_options{tr("System Application"), + tr("System Archive"), + tr("System Application Update"), + tr("Firmware Package (Type A)"), + tr("Firmware Package (Type B)"), + tr("Game"), + tr("Game Update"), + tr("Game DLC"), + tr("Delta Title")}; + bool ok; + const auto item = QInputDialog::getItem( + this, tr("Select NCA Install Type..."), + tr("Please select the type of title you would like to install this NCA as:\n(In " + "most instances, the default 'Game' is fine.)"), + tt_options, 5, false, &ok); + + auto index = tt_options.indexOf(item); + if (!ok || index == -1) { + QMessageBox::warning(this, tr("Failed to Install"), + tr("The title type you selected for the NCA is invalid.")); + break; + } + + // If index is equal to or past Game, add the jump in TitleType. + if (index >= 5) { + index += static_cast(FileSys::TitleType::Application) - + static_cast(FileSys::TitleType::FirmwarePackageB); + } + + FileSys::InstallResult res; + if (index >= static_cast(FileSys::TitleType::Application)) { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), false, + qt_raw_copy); + } else { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetSystemNANDContents() + ->InstallEntry(*nca, static_cast(index), false, + qt_raw_copy); + } + + if (res == FileSys::InstallResult::Success) { + ++count; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files && overwrite(filename)) { + const auto res2 = + Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), true, + qt_raw_copy); + if (res2 != FileSys::InstallResult::Success) { + failed(filename); + break; + } + ++count; } else { - failed(); + --total_count; } + } else { + failed(filename); + break; } - } else { - failed(); + } + + // Return success only on the last file + if (filename == filenames.last()) { + success(); } } } diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 8e3d39c38..55d072e96 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -28,6 +28,7 @@ class MicroProfileDialog; class ProfilerWidget; class QLabel; class QPushButton; +class QProgressDialog; class WaitTreeWidget; enum class GameListOpenTarget; class GameListPlaceholder; @@ -272,6 +273,9 @@ private: HotkeyRegistry hotkey_registry; + // Install to NAND progress dialog + QProgressDialog* install_progress; + protected: void dropEvent(QDropEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; diff --git a/src/yuzu/main.ui b/src/yuzu/main.ui index bee6e107e..c3a1d715e 100644 --- a/src/yuzu/main.ui +++ b/src/yuzu/main.ui @@ -130,7 +130,7 @@ true - Install File to NAND... + Install Files to NAND... From 7f4d96d87332824643d7a8d3ff0fab7ea771b798 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 1 Jul 2020 16:15:57 -0400 Subject: [PATCH 25/55] Refactor batch installing files Key issues fixed: - Progress dialog showing up as white/hanging/getting stuck/unresponsive. Key changes: - Progress dialog now shows progress as a function of all files instead of per nca within a file. - Overwrite existing files will overwrite all files in the selection. --- src/yuzu/install_dialog.cpp | 16 +- src/yuzu/install_dialog.h | 5 +- src/yuzu/main.cpp | 407 +++++++++++++++++++----------------- src/yuzu/main.h | 14 +- 4 files changed, 242 insertions(+), 200 deletions(-) diff --git a/src/yuzu/install_dialog.cpp b/src/yuzu/install_dialog.cpp index fac158c25..5f3b4c963 100644 --- a/src/yuzu/install_dialog.cpp +++ b/src/yuzu/install_dialog.cpp @@ -22,7 +22,7 @@ InstallDialog::InstallDialog(QWidget* parent, const QStringList& files) : QDialo item->setCheckState(Qt::Checked); } - file_list->setMinimumWidth((file_list->sizeHintForColumn(0) * 6) / 5); + file_list->setMinimumWidth((file_list->sizeHintForColumn(0) * 10) / 9); vbox_layout = new QVBoxLayout; @@ -54,19 +54,23 @@ InstallDialog::InstallDialog(QWidget* parent, const QStringList& files) : QDialo InstallDialog::~InstallDialog() = default; -QStringList InstallDialog::GetFilenames() const { - QStringList filenames; +QStringList InstallDialog::GetFiles() const { + QStringList files; for (int i = 0; i < file_list->count(); ++i) { const QListWidgetItem* item = file_list->item(i); if (item->checkState() == Qt::Checked) { - filenames.append(item->data(Qt::UserRole).toString()); + files.append(item->data(Qt::UserRole).toString()); } } - return filenames; + return files; } bool InstallDialog::ShouldOverwriteFiles() const { return overwrite_files->isChecked(); -} \ No newline at end of file +} + +int InstallDialog::GetMinimumWidth() const { + return file_list->width(); +} diff --git a/src/yuzu/install_dialog.h b/src/yuzu/install_dialog.h index 3eaa9e60a..55a458ba8 100644 --- a/src/yuzu/install_dialog.h +++ b/src/yuzu/install_dialog.h @@ -20,8 +20,9 @@ public: explicit InstallDialog(QWidget* parent, const QStringList& files); ~InstallDialog() override; - QStringList GetFilenames() const; + QStringList GetFiles() const; bool ShouldOverwriteFiles() const; + int GetMinimumWidth() const; private: QListWidget* file_list; @@ -32,4 +33,4 @@ private: QLabel* description; QCheckBox* overwrite_files; QDialogButtonBox* buttons; -}; \ No newline at end of file +}; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 45ddc3baf..4539cbe0d 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1599,28 +1599,107 @@ void GMainWindow::OnMenuInstallToNAND() { tr("Installable Switch File (*.nca *.nsp *.xci);;Nintendo Content Archive " "(*.nca);;Nintendo Submission Package (*.nsp);;NX Cartridge " "Image (*.xci)"); - QStringList files = QFileDialog::getOpenFileNames(this, tr("Install Files"), - UISettings::values.roms_path, file_filter); - if (files.isEmpty()) { + QStringList filenames = QFileDialog::getOpenFileNames( + this, tr("Install Files"), UISettings::values.roms_path, file_filter); + + if (filenames.isEmpty()) { return; } - InstallDialog installDialog(this, files); + InstallDialog installDialog(this, filenames); if (installDialog.exec() == QDialog::Rejected) { return; } - const QStringList filenames = installDialog.GetFilenames(); + const QStringList files = installDialog.GetFiles(); const bool overwrite_files = installDialog.ShouldOverwriteFiles(); int count = 0; - int total_count = filenames.size(); - bool is_progressdialog_created = false; + const int total_count = filenames.size(); - const auto qt_raw_copy = [this, &count, &total_count, &is_progressdialog_created]( - const FileSys::VirtualFile& src, const FileSys::VirtualFile& dest, - std::size_t block_size) { + QStringList new_files{}; // Newly installed files that do not yet exist in the NAND + QStringList overwritten_files{}; // Files that overwrote those existing in the NAND + QStringList existing_files{}; // Files that were not installed as they already exist in the NAND + QStringList failed_files{}; // Files that failed to install due to errors + + ui.action_Install_File_NAND->setEnabled(false); + + QProgressDialog install_progress(QStringLiteral(""), tr("Cancel"), 0, total_count, this); + install_progress.setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & + ~Qt::WindowMaximizeButtonHint); + install_progress.setAutoClose(false); + install_progress.setFixedWidth(installDialog.GetMinimumWidth()); + install_progress.show(); + + for (const QString& file : files) { + install_progress.setWindowTitle(tr("%n file(s) remaining", "", total_count - count)); + install_progress.setLabelText( + tr("Installing file \"%1\"...").arg(QFileInfo(file).fileName())); + + QFuture future; + InstallResult result; + + if (file.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || + file.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + future = QtConcurrent::run([this, &file, &overwrite_files, &install_progress] { + return InstallNSPXCI(file, overwrite_files, install_progress); + }); + + while (!future.isFinished()) { + QCoreApplication::processEvents(); + } + + result = future.result(); + } else { + result = InstallNCA(file, overwrite_files, install_progress); + } + + switch (result) { + case InstallResult::Success: + new_files.append(QFileInfo(file).fileName()); + break; + case InstallResult::Overwrite: + overwritten_files.append(QFileInfo(file).fileName()); + break; + case InstallResult::AlreadyExists: + existing_files.append(QFileInfo(file).fileName()); + break; + case InstallResult::Failure: + failed_files.append(QFileInfo(file).fileName()); + break; + } + + install_progress.setValue(++count); + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + + install_progress.close(); + + const QString install_results = + (new_files.isEmpty() ? QStringLiteral("") + : tr("%n file(s) were newly installed\n", "", new_files.size())) + + (overwritten_files.isEmpty() + ? QStringLiteral("") + : tr("%n file(s) were overwritten\n", "", overwritten_files.size())) + + (existing_files.isEmpty() + ? QStringLiteral("") + : tr("%n file(s) already exist in NAND\n", "", existing_files.size())) + + (failed_files.isEmpty() ? QStringLiteral("") + : tr("%n file(s) failed to install\n", "", failed_files.size())); + + QMessageBox::information(this, tr("Install Results"), install_results); + game_list->PopulateAsync(UISettings::values.game_dirs); + FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + DIR_SEP + + "game_list"); + ui.action_Install_File_NAND->setEnabled(true); +} + +InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite_files, + QProgressDialog& install_progress) { + const auto qt_raw_copy = [this, &install_progress](const FileSys::VirtualFile& src, + const FileSys::VirtualFile& dest, + std::size_t block_size) { if (src == nullptr || dest == nullptr) { return false; } @@ -1629,204 +1708,154 @@ void GMainWindow::OnMenuInstallToNAND() { } std::array buffer{}; - const int progress_maximum = static_cast(src->GetSize() / buffer.size()); - - if (!is_progressdialog_created) { - ui.action_Install_File_NAND->setEnabled(false); - install_progress = new QProgressDialog( - tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName())), - tr("Cancel"), 0, progress_maximum, this); - install_progress->setWindowTitle( - tr("%n file(s) remaining", "", total_count - count - 1)); - install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & - ~Qt::WindowMaximizeButtonHint); - install_progress->setAutoClose(false); - is_progressdialog_created = true; - } else { - install_progress->setWindowTitle( - tr("%n file(s) remaining", "", total_count - count - 1)); - install_progress->setLabelText( - tr("Installing file \"%1\"...").arg(QString::fromStdString(src->GetName()))); - install_progress->setMaximum(progress_maximum); - } for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress->wasCanceled()) { + if (install_progress.wasCanceled()) { dest->Resize(0); return false; } - const int progress_value = static_cast(i / buffer.size()); - install_progress->setValue(progress_value); + const auto read = src->Read(buffer.data(), buffer.size(), i); + dest->Write(buffer.data(), read, i); + } + return true; + }; + + std::shared_ptr nsp; + if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { + nsp = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + if (nsp->IsExtractedType()) { + return InstallResult::Failure; + } + } else { + const auto xci = std::make_shared( + vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + nsp = xci->GetSecurePartitionNSP(); + } + + if (nsp->GetStatus() != Loader::ResultStatus::Success) { + return InstallResult::Failure; + } + const auto res = + Core::System::GetInstance().GetFileSystemController().GetUserNANDContents()->InstallEntry( + *nsp, false, qt_raw_copy); + if (res == FileSys::InstallResult::Success) { + return InstallResult::Success; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files) { + const auto res2 = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nsp, true, qt_raw_copy); + if (res2 != FileSys::InstallResult::Success) { + return InstallResult::Failure; + } + return InstallResult::Overwrite; + } else { + return InstallResult::AlreadyExists; + } + } else { + return InstallResult::Failure; + } +} + +InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_files, + QProgressDialog& install_progress) { + const auto qt_raw_copy = [this, &install_progress](const FileSys::VirtualFile& src, + const FileSys::VirtualFile& dest, + std::size_t block_size) { + if (src == nullptr || dest == nullptr) { + return false; + } + if (!dest->Resize(src->GetSize())) { + return false; + } + + std::array buffer{}; + + for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { + if (install_progress.wasCanceled()) { + dest->Resize(0); + return false; + } const auto read = src->Read(buffer.data(), buffer.size(), i); dest->Write(buffer.data(), read, i); } - return true; }; - const auto success = [this, &count, &is_progressdialog_created]() { - if (is_progressdialog_created) { - install_progress->close(); - } - QMessageBox::information(this, tr("Successfully Installed"), - tr("%n file(s) successfully installed", "", count)); - game_list->PopulateAsync(UISettings::values.game_dirs); - FileUtil::DeleteDirRecursively(FileUtil::GetUserPath(FileUtil::UserPath::CacheDir) + - DIR_SEP + "game_list"); - ui.action_Install_File_NAND->setEnabled(true); - }; + const auto nca = + std::make_shared(vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); + const auto id = nca->GetStatus(); - const auto failed = [this, &is_progressdialog_created](const QString& file) { - if (is_progressdialog_created) { - install_progress->close(); - } - QMessageBox::warning( - this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), - tr("There was an error while attempting to install the provided file. It " - "could have an incorrect format or be missing metadata. Please " - "double-check your file and try again.")); - game_list->PopulateAsync(UISettings::values.game_dirs); - ui.action_Install_File_NAND->setEnabled(true); - }; + // Game updates necessary are missing base RomFS + if (id != Loader::ResultStatus::Success && + id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) { + return InstallResult::Failure; + } - const auto overwrite = [this](const QString& file) { - return QMessageBox::question( - this, tr("Failed to Install %1").arg(QFileInfo(file).fileName()), - tr("The file you are attempting to install already exists " - "in the cache. Would you like to overwrite it?")) == QMessageBox::Yes; - }; + const QStringList tt_options{tr("System Application"), + tr("System Archive"), + tr("System Application Update"), + tr("Firmware Package (Type A)"), + tr("Firmware Package (Type B)"), + tr("Game"), + tr("Game Update"), + tr("Game DLC"), + tr("Delta Title")}; + bool ok; + const auto item = QInputDialog::getItem( + this, tr("Select NCA Install Type..."), + tr("Please select the type of title you would like to install this NCA as:\n(In " + "most instances, the default 'Game' is fine.)"), + tt_options, 5, false, &ok); - for (const QString& filename : filenames) { - if (filename.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || - filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - std::shared_ptr nsp; - if (filename.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - nsp = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - if (nsp->IsExtractedType()) { - failed(filename); - break; - } - } else { - const auto xci = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - nsp = xci->GetSecurePartitionNSP(); - } - - if (nsp->GetStatus() != Loader::ResultStatus::Success) { - failed(filename); - break; - } - const auto res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, false, qt_raw_copy); - if (res == FileSys::InstallResult::Success) { - ++count; - } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files && overwrite(filename)) { - const auto res2 = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, true, qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - failed(filename); - break; - } - ++count; - } else { - --total_count; - } - } else { - failed(filename); - break; + auto index = tt_options.indexOf(item); + if (!ok || index == -1) { + QMessageBox::warning(this, tr("Failed to Install"), + tr("The title type you selected for the NCA is invalid.")); + return InstallResult::Failure; + } + + // If index is equal to or past Game, add the jump in TitleType. + if (index >= 5) { + index += static_cast(FileSys::TitleType::Application) - + static_cast(FileSys::TitleType::FirmwarePackageB); + } + + FileSys::InstallResult res; + if (index >= static_cast(FileSys::TitleType::Application)) { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + } else { + res = Core::System::GetInstance() + .GetFileSystemController() + .GetSystemNANDContents() + ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + } + + if (res == FileSys::InstallResult::Success) { + return InstallResult::Success; + } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { + if (overwrite_files) { + const auto res2 = + Core::System::GetInstance() + .GetFileSystemController() + .GetUserNANDContents() + ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); + if (res2 != FileSys::InstallResult::Success) { + return InstallResult::Failure; } + return InstallResult::Overwrite; } else { - const auto nca = std::make_shared( - vfs->OpenFile(filename.toStdString(), FileSys::Mode::Read)); - const auto id = nca->GetStatus(); - - // Game updates necessary are missing base RomFS - if (id != Loader::ResultStatus::Success && - id != Loader::ResultStatus::ErrorMissingBKTRBaseRomFS) { - failed(filename); - break; - } - - const QStringList tt_options{tr("System Application"), - tr("System Archive"), - tr("System Application Update"), - tr("Firmware Package (Type A)"), - tr("Firmware Package (Type B)"), - tr("Game"), - tr("Game Update"), - tr("Game DLC"), - tr("Delta Title")}; - bool ok; - const auto item = QInputDialog::getItem( - this, tr("Select NCA Install Type..."), - tr("Please select the type of title you would like to install this NCA as:\n(In " - "most instances, the default 'Game' is fine.)"), - tt_options, 5, false, &ok); - - auto index = tt_options.indexOf(item); - if (!ok || index == -1) { - QMessageBox::warning(this, tr("Failed to Install"), - tr("The title type you selected for the NCA is invalid.")); - break; - } - - // If index is equal to or past Game, add the jump in TitleType. - if (index >= 5) { - index += static_cast(FileSys::TitleType::Application) - - static_cast(FileSys::TitleType::FirmwarePackageB); - } - - FileSys::InstallResult res; - if (index >= static_cast(FileSys::TitleType::Application)) { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); - } else { - res = Core::System::GetInstance() - .GetFileSystemController() - .GetSystemNANDContents() - ->InstallEntry(*nca, static_cast(index), false, - qt_raw_copy); - } - - if (res == FileSys::InstallResult::Success) { - ++count; - } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files && overwrite(filename)) { - const auto res2 = - Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), true, - qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - failed(filename); - break; - } - ++count; - } else { - --total_count; - } - } else { - failed(filename); - break; - } - } - - // Return success only on the last file - if (filename == filenames.last()) { - success(); + return InstallResult::AlreadyExists; } + } else { + return InstallResult::Failure; } } diff --git a/src/yuzu/main.h b/src/yuzu/main.h index 55d072e96..deea8170d 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -48,6 +48,13 @@ enum class EmulatedDirectoryTarget { SDMC, }; +enum class InstallResult { + Success, + Overwrite, + AlreadyExists, + Failure, +}; + enum class ReinitializeKeyBehavior { NoWarning, Warning, @@ -219,6 +226,10 @@ private slots: private: std::optional SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); + InstallResult InstallNSPXCI(const QString& filename, bool overwrite_files, + QProgressDialog& install_progress); + InstallResult InstallNCA(const QString& filename, bool overwrite_files, + QProgressDialog& install_progress); void UpdateWindowTitle(const std::string& title_name = {}, const std::string& title_version = {}); void UpdateStatusBar(); @@ -273,9 +284,6 @@ private: HotkeyRegistry hotkey_registry; - // Install to NAND progress dialog - QProgressDialog* install_progress; - protected: void dropEvent(QDropEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; From 6d8d7ebc66d9deb5adb4edb246590481b1236bbc Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 5 Jul 2020 09:29:39 -0400 Subject: [PATCH 26/55] Update the install and progress dialogs - Remove the overwrite files checkbox, it will always overwrite - The progressbar now reflects the progress in terms of data transferred. --- src/yuzu/install_dialog.cpp | 12 ++-- src/yuzu/install_dialog.h | 2 +- src/yuzu/main.cpp | 118 ++++++++++++++++-------------------- src/yuzu/main.h | 13 ++-- 4 files changed, 65 insertions(+), 80 deletions(-) diff --git a/src/yuzu/install_dialog.cpp b/src/yuzu/install_dialog.cpp index 5f3b4c963..06b0b1874 100644 --- a/src/yuzu/install_dialog.cpp +++ b/src/yuzu/install_dialog.cpp @@ -22,7 +22,7 @@ InstallDialog::InstallDialog(QWidget* parent, const QStringList& files) : QDialo item->setCheckState(Qt::Checked); } - file_list->setMinimumWidth((file_list->sizeHintForColumn(0) * 10) / 9); + file_list->setMinimumWidth((file_list->sizeHintForColumn(0) * 11) / 10); vbox_layout = new QVBoxLayout; @@ -30,8 +30,8 @@ InstallDialog::InstallDialog(QWidget* parent, const QStringList& files) : QDialo description = new QLabel(tr("Please confirm these are the files you wish to install.")); - overwrite_files = new QCheckBox(tr("Overwrite Existing Files")); - overwrite_files->setCheckState(Qt::Unchecked); + update_description = + new QLabel(tr("Installing an Update or DLC will overwrite the previously installed one.")); buttons = new QDialogButtonBox; buttons->addButton(QDialogButtonBox::Cancel); @@ -40,10 +40,10 @@ InstallDialog::InstallDialog(QWidget* parent, const QStringList& files) : QDialo connect(buttons, &QDialogButtonBox::accepted, this, &InstallDialog::accept); connect(buttons, &QDialogButtonBox::rejected, this, &InstallDialog::reject); - hbox_layout->addWidget(overwrite_files); hbox_layout->addWidget(buttons); vbox_layout->addWidget(description); + vbox_layout->addWidget(update_description); vbox_layout->addWidget(file_list); vbox_layout->addLayout(hbox_layout); @@ -67,10 +67,6 @@ QStringList InstallDialog::GetFiles() const { return files; } -bool InstallDialog::ShouldOverwriteFiles() const { - return overwrite_files->isChecked(); -} - int InstallDialog::GetMinimumWidth() const { return file_list->width(); } diff --git a/src/yuzu/install_dialog.h b/src/yuzu/install_dialog.h index 55a458ba8..e4aba1b06 100644 --- a/src/yuzu/install_dialog.h +++ b/src/yuzu/install_dialog.h @@ -31,6 +31,6 @@ private: QHBoxLayout* hbox_layout; QLabel* description; - QCheckBox* overwrite_files; + QLabel* update_description; QDialogButtonBox* buttons; }; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 4539cbe0d..8a57e34c7 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -848,6 +848,9 @@ void GMainWindow::ConnectWidgetEvents() { connect(game_list, &GameList::OpenPerGameGeneralRequested, this, &GMainWindow::OnGameListOpenPerGameProperties); + connect(this, &GMainWindow::UpdateInstallProgress, this, + &GMainWindow::IncrementInstallProgress); + connect(this, &GMainWindow::EmulationStarting, render_window, &GRenderWindow::OnEmulationStarting); connect(this, &GMainWindow::EmulationStopping, render_window, @@ -1594,6 +1597,10 @@ void GMainWindow::OnMenuLoadFolder() { } } +void GMainWindow::IncrementInstallProgress() { + install_progress->setValue(install_progress->value() + 1); +} + void GMainWindow::OnMenuInstallToNAND() { const QString file_filter = tr("Installable Switch File (*.nca *.nsp *.xci);;Nintendo Content Archive " @@ -1613,28 +1620,35 @@ void GMainWindow::OnMenuInstallToNAND() { } const QStringList files = installDialog.GetFiles(); - const bool overwrite_files = installDialog.ShouldOverwriteFiles(); - int count = 0; - const int total_count = filenames.size(); + int remaining = filenames.size(); + + // This would only overflow above 2^43 bytes (8.796 TB) + int total_size = 0; + for (const QString& file : files) { + total_size += static_cast(QFile(file).size() / 0x1000); + } + if (total_size < 0) { + LOG_CRITICAL(Frontend, "Attempting to install too many files, aborting."); + return; + } QStringList new_files{}; // Newly installed files that do not yet exist in the NAND QStringList overwritten_files{}; // Files that overwrote those existing in the NAND - QStringList existing_files{}; // Files that were not installed as they already exist in the NAND - QStringList failed_files{}; // Files that failed to install due to errors + QStringList failed_files{}; // Files that failed to install due to errors ui.action_Install_File_NAND->setEnabled(false); - QProgressDialog install_progress(QStringLiteral(""), tr("Cancel"), 0, total_count, this); - install_progress.setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & - ~Qt::WindowMaximizeButtonHint); - install_progress.setAutoClose(false); - install_progress.setFixedWidth(installDialog.GetMinimumWidth()); - install_progress.show(); + install_progress = new QProgressDialog(QStringLiteral(""), tr("Cancel"), 0, total_size, this); + install_progress->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint & + ~Qt::WindowMaximizeButtonHint); + install_progress->setAttribute(Qt::WA_DeleteOnClose, true); + install_progress->setFixedWidth(installDialog.GetMinimumWidth() + 40); + install_progress->show(); for (const QString& file : files) { - install_progress.setWindowTitle(tr("%n file(s) remaining", "", total_count - count)); - install_progress.setLabelText( + install_progress->setWindowTitle(tr("%n file(s) remaining", "", remaining)); + install_progress->setLabelText( tr("Installing file \"%1\"...").arg(QFileInfo(file).fileName())); QFuture future; @@ -1642,19 +1656,21 @@ void GMainWindow::OnMenuInstallToNAND() { if (file.endsWith(QStringLiteral("xci"), Qt::CaseInsensitive) || file.endsWith(QStringLiteral("nsp"), Qt::CaseInsensitive)) { - future = QtConcurrent::run([this, &file, &overwrite_files, &install_progress] { - return InstallNSPXCI(file, overwrite_files, install_progress); - }); + + future = QtConcurrent::run([this, &file] { return InstallNSPXCI(file); }); while (!future.isFinished()) { QCoreApplication::processEvents(); } result = future.result(); + } else { - result = InstallNCA(file, overwrite_files, install_progress); + result = InstallNCA(file); } + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + switch (result) { case InstallResult::Success: new_files.append(QFileInfo(file).fileName()); @@ -1662,19 +1678,15 @@ void GMainWindow::OnMenuInstallToNAND() { case InstallResult::Overwrite: overwritten_files.append(QFileInfo(file).fileName()); break; - case InstallResult::AlreadyExists: - existing_files.append(QFileInfo(file).fileName()); - break; case InstallResult::Failure: failed_files.append(QFileInfo(file).fileName()); break; } - install_progress.setValue(++count); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + --remaining; } - install_progress.close(); + install_progress->close(); const QString install_results = (new_files.isEmpty() ? QStringLiteral("") @@ -1682,9 +1694,6 @@ void GMainWindow::OnMenuInstallToNAND() { (overwritten_files.isEmpty() ? QStringLiteral("") : tr("%n file(s) were overwritten\n", "", overwritten_files.size())) + - (existing_files.isEmpty() - ? QStringLiteral("") - : tr("%n file(s) already exist in NAND\n", "", existing_files.size())) + (failed_files.isEmpty() ? QStringLiteral("") : tr("%n file(s) failed to install\n", "", failed_files.size())); @@ -1695,11 +1704,9 @@ void GMainWindow::OnMenuInstallToNAND() { ui.action_Install_File_NAND->setEnabled(true); } -InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite_files, - QProgressDialog& install_progress) { - const auto qt_raw_copy = [this, &install_progress](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, - std::size_t block_size) { +InstallResult GMainWindow::InstallNSPXCI(const QString& filename) { + const auto qt_raw_copy = [this](const FileSys::VirtualFile& src, + const FileSys::VirtualFile& dest, std::size_t block_size) { if (src == nullptr || dest == nullptr) { return false; } @@ -1710,11 +1717,13 @@ InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite std::array buffer{}; for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress.wasCanceled()) { + if (install_progress->wasCanceled()) { dest->Resize(0); return false; } + emit UpdateInstallProgress(); + const auto read = src->Read(buffer.data(), buffer.size(), i); dest->Write(buffer.data(), read, i); } @@ -1739,32 +1748,19 @@ InstallResult GMainWindow::InstallNSPXCI(const QString& filename, bool overwrite } const auto res = Core::System::GetInstance().GetFileSystemController().GetUserNANDContents()->InstallEntry( - *nsp, false, qt_raw_copy); + *nsp, true, qt_raw_copy); if (res == FileSys::InstallResult::Success) { return InstallResult::Success; } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files) { - const auto res2 = Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nsp, true, qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - return InstallResult::Failure; - } - return InstallResult::Overwrite; - } else { - return InstallResult::AlreadyExists; - } + return InstallResult::Overwrite; } else { return InstallResult::Failure; } } -InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_files, - QProgressDialog& install_progress) { - const auto qt_raw_copy = [this, &install_progress](const FileSys::VirtualFile& src, - const FileSys::VirtualFile& dest, - std::size_t block_size) { +InstallResult GMainWindow::InstallNCA(const QString& filename) { + const auto qt_raw_copy = [this](const FileSys::VirtualFile& src, + const FileSys::VirtualFile& dest, std::size_t block_size) { if (src == nullptr || dest == nullptr) { return false; } @@ -1775,11 +1771,13 @@ InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_fi std::array buffer{}; for (std::size_t i = 0; i < src->GetSize(); i += buffer.size()) { - if (install_progress.wasCanceled()) { + if (install_progress->wasCanceled()) { dest->Resize(0); return false; } + emit UpdateInstallProgress(); + const auto read = src->Read(buffer.data(), buffer.size(), i); dest->Write(buffer.data(), read, i); } @@ -1830,30 +1828,18 @@ InstallResult GMainWindow::InstallNCA(const QString& filename, bool overwrite_fi res = Core::System::GetInstance() .GetFileSystemController() .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); } else { res = Core::System::GetInstance() .GetFileSystemController() .GetSystemNANDContents() - ->InstallEntry(*nca, static_cast(index), false, qt_raw_copy); + ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); } if (res == FileSys::InstallResult::Success) { return InstallResult::Success; } else if (res == FileSys::InstallResult::ErrorAlreadyExists) { - if (overwrite_files) { - const auto res2 = - Core::System::GetInstance() - .GetFileSystemController() - .GetUserNANDContents() - ->InstallEntry(*nca, static_cast(index), true, qt_raw_copy); - if (res2 != FileSys::InstallResult::Success) { - return InstallResult::Failure; - } - return InstallResult::Overwrite; - } else { - return InstallResult::AlreadyExists; - } + return InstallResult::Overwrite; } else { return InstallResult::Failure; } diff --git a/src/yuzu/main.h b/src/yuzu/main.h index deea8170d..adff65fb5 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -51,7 +51,6 @@ enum class EmulatedDirectoryTarget { enum class InstallResult { Success, Overwrite, - AlreadyExists, Failure, }; @@ -110,6 +109,8 @@ signals: // Signal that tells widgets to update icons to use the current theme void UpdateThemedIcons(); + void UpdateInstallProgress(); + void ErrorDisplayFinished(); void ProfileSelectorFinishedSelection(std::optional uuid); @@ -206,6 +207,7 @@ private slots: void OnGameListOpenPerGameProperties(const std::string& file); void OnMenuLoadFile(); void OnMenuLoadFolder(); + void IncrementInstallProgress(); void OnMenuInstallToNAND(); void OnMenuRecentFile(); void OnConfigure(); @@ -226,10 +228,8 @@ private slots: private: std::optional SelectRomFSDumpTarget(const FileSys::ContentProvider&, u64 program_id); - InstallResult InstallNSPXCI(const QString& filename, bool overwrite_files, - QProgressDialog& install_progress); - InstallResult InstallNCA(const QString& filename, bool overwrite_files, - QProgressDialog& install_progress); + InstallResult InstallNSPXCI(const QString& filename); + InstallResult InstallNCA(const QString& filename); void UpdateWindowTitle(const std::string& title_name = {}, const std::string& title_version = {}); void UpdateStatusBar(); @@ -284,6 +284,9 @@ private: HotkeyRegistry hotkey_registry; + // Install progress dialog + QProgressDialog* install_progress; + protected: void dropEvent(QDropEvent* event) override; void dragEnterEvent(QDragEnterEvent* event) override; From 75a01475d174a8dbea7dcf41002cb53abce1d8bb Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Wed, 8 Jul 2020 13:01:25 -0400 Subject: [PATCH 27/55] Add additional empty check for the QStringList returned by the InstallDialog --- src/yuzu/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 8a57e34c7..432379705 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -1621,6 +1621,10 @@ void GMainWindow::OnMenuInstallToNAND() { const QStringList files = installDialog.GetFiles(); + if (files.isEmpty()) { + return; + } + int remaining = filenames.size(); // This would only overflow above 2^43 bytes (8.796 TB) From 7351ca8c75b7c4d3a7101f0e2f8659b73c4a64c6 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 5 Jul 2020 16:10:51 -0400 Subject: [PATCH 28/55] KeyManager: Prevent writing of invalid keys If the keys are zero, don't write them to the autogenerated file. --- src/core/crypto/key_manager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp index 8997c7082..f87fe0abc 100644 --- a/src/core/crypto/key_manager.cpp +++ b/src/core/crypto/key_manager.cpp @@ -695,8 +695,9 @@ void KeyManager::WriteKeyToFile(KeyCategory category, std::string_view keyname, } void KeyManager::SetKey(S128KeyType id, Key128 key, u64 field1, u64 field2) { - if (s128_keys.find({id, field1, field2}) != s128_keys.end()) + if (s128_keys.find({id, field1, field2}) != s128_keys.end() || key == Key128{}) { return; + } if (id == S128KeyType::Titlekey) { Key128 rights_id; std::memcpy(rights_id.data(), &field2, sizeof(u64)); @@ -716,8 +717,9 @@ void KeyManager::SetKey(S128KeyType id, Key128 key, u64 field1, u64 field2) { return std::tie(elem.second.type, elem.second.field1, elem.second.field2) == std::tie(id, field1, field2); }); - if (iter2 != s128_file_id.end()) + if (iter2 != s128_file_id.end()) { WriteKeyToFile(category, iter2->first, key); + } // Variable cases if (id == S128KeyType::KeyArea) { @@ -745,16 +747,18 @@ void KeyManager::SetKey(S128KeyType id, Key128 key, u64 field1, u64 field2) { } void KeyManager::SetKey(S256KeyType id, Key256 key, u64 field1, u64 field2) { - if (s256_keys.find({id, field1, field2}) != s256_keys.end()) + if (s256_keys.find({id, field1, field2}) != s256_keys.end() || key == Key256{}) { return; + } const auto iter = std::find_if( s256_file_id.begin(), s256_file_id.end(), [&id, &field1, &field2](const std::pair> elem) { return std::tie(elem.second.type, elem.second.field1, elem.second.field2) == std::tie(id, field1, field2); }); - if (iter != s256_file_id.end()) + if (iter != s256_file_id.end()) { WriteKeyToFile(KeyCategory::Standard, iter->first, key); + } s256_keys[{id, field1, field2}] = key; } From 755506d4047af89aaa4cb90720ef721582431784 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Tue, 7 Jul 2020 06:57:20 -0400 Subject: [PATCH 29/55] vfs_real: Fix MoveFile The file wasn't closed prior to being renamed / moved, throwing an error that states "The process cannot access the file because it is being used by another process." Fix this by closing the file prior to a rename / move operation. Fixes saving in Luigi's Mansion 3 and KATANA KAMI: A Way of the Samurai Story. --- src/core/file_sys/vfs_real.cpp | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp index e21300a7c..96ce5957c 100644 --- a/src/core/file_sys/vfs_real.cpp +++ b/src/core/file_sys/vfs_real.cpp @@ -112,19 +112,26 @@ VirtualFile RealVfsFilesystem::MoveFile(std::string_view old_path_, std::string_ const auto new_path = FileUtil::SanitizePath(new_path_, FileUtil::DirectorySeparator::PlatformDefault); - if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || - FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) - return nullptr; - if (cache.find(old_path) != cache.end()) { - auto cached = cache[old_path]; - if (!cached.expired()) { - auto file = cached.lock(); - file->Open(new_path, "r+b"); - cache.erase(old_path); - cache[new_path] = file; + auto file = cache[old_path].lock(); + + if (!cache[old_path].expired()) { + file->Close(); } + + if (!FileUtil::Exists(old_path) || FileUtil::Exists(new_path) || + FileUtil::IsDirectory(old_path) || !FileUtil::Rename(old_path, new_path)) { + return nullptr; + } + + cache.erase(old_path); + file->Open(new_path, "r+b"); + cache[new_path] = file; + } else { + UNREACHABLE(); + return nullptr; } + return OpenFile(new_path, Mode::ReadWrite); } From d39b4575665386c6889787edc985f85295dfe29d Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 10 Jul 2020 01:18:37 -0400 Subject: [PATCH 30/55] CMakeLists: Use lower-case command names Our convention uses lower-case command names, so this is just a consistency change. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4619f33f4..a99d34e5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,7 +330,7 @@ elseif(SDL2_FOUND) endif() # Ensure libusb is properly configured (based on dolphin libusb include) -INCLUDE(FindPkgConfig) +include(FindPkgConfig) find_package(LibUSB) if (NOT LIBUSB_FOUND) add_subdirectory(externals/libusb) From 798c1b457d721962799f4e6f042ad4fe91b72386 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 10 Jul 2020 04:47:31 -0400 Subject: [PATCH 31/55] CMakeLists: Update fmt to 7.0.1 Keeps the package up to date with the latest major release of fmt. This version brings in quite a bit of improvements, such as code size reduction, etc. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4619f33f4..26299d103 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,7 +151,7 @@ macro(yuzu_find_packages) # Cmake Pkg Prefix Version Conan Pkg "Boost 1.71 boost/1.72.0" "Catch2 2.11 catch2/2.11.0" - "fmt 6.2 fmt/6.2.0" + "fmt 7.0 fmt/7.0.1" # can't use until https://github.com/bincrafters/community/issues/1173 #"libzip 1.5 libzip/1.5.2@bincrafters/stable" "lz4 1.8 lz4/1.9.2" From fca26980a2bcf13ebac1249a9478201e2a74128e Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Fri, 10 Jul 2020 18:15:32 -0300 Subject: [PATCH 32/55] vk_rasterizer: Pass to CmdBindVertexBuffers2EXT This has been fixed in Nvidia's public beta driver 451.74. The previous beta driver will be broken, people using these will have to update. --- src/video_core/renderer_vulkan/vk_rasterizer.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 380ed532b..7625871c2 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -332,23 +332,23 @@ private: if constexpr (has_extended_dynamic_state) { // With extended dynamic states we can specify the length and stride of a vertex buffer - // std::array sizes; + std::array sizes; std::array strides; - // std::copy(vertex.sizes.begin(), vertex.sizes.begin() + N, sizes.begin()); + std::copy(vertex.sizes.begin(), vertex.sizes.begin() + N, sizes.begin()); std::copy(vertex.strides.begin(), vertex.strides.begin() + N, strides.begin()); if constexpr (is_indexed) { scheduler.Record( - [buffers, offsets, strides, index = index](vk::CommandBuffer cmdbuf) { + [buffers, offsets, sizes, strides, index = index](vk::CommandBuffer cmdbuf) { cmdbuf.BindIndexBuffer(index.buffer, index.offset, index.type); cmdbuf.BindVertexBuffers2EXT(0, static_cast(N), buffers.data(), - offsets.data(), nullptr, + offsets.data(), sizes.data(), ExpandStrides(strides).data()); }); } else { - scheduler.Record([buffers, offsets, strides](vk::CommandBuffer cmdbuf) { + scheduler.Record([buffers, offsets, sizes, strides](vk::CommandBuffer cmdbuf) { cmdbuf.BindVertexBuffers2EXT(0, static_cast(N), buffers.data(), - offsets.data(), nullptr, + offsets.data(), sizes.data(), ExpandStrides(strides).data()); }); } From fb0fefc75c3cb9e060d59f3b10fe3ae66626aeb8 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Fri, 10 Jul 2020 19:24:23 -0400 Subject: [PATCH 33/55] CMakeLists: Make use of /std:c++latest on MSVC Provides the buildbot with one builder that is always tracking the latest version of the C++ standard, allowing us to progressively rectify our code and amend any differences between standards over time instead of waiting for a complete standard change, potentially breaking a lot of code all at once. --- CMakeLists.txt | 11 +++++++++-- src/yuzu/game_list.cpp | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c0e49c03..c8e86959b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,8 +118,15 @@ message(STATUS "Target architecture: ${ARCHITECTURE}") # Configure C++ standard # =========================== -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) +if (MSVC) + add_compile_options(/std:c++latest) + + # cubeb and boost still make use of deprecated result_of. + add_definitions(-D_HAS_DEPRECATED_RESULT_OF) +else() + set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD_REQUIRED ON) +endif() # Output binaries to bin/ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin) diff --git a/src/yuzu/game_list.cpp b/src/yuzu/game_list.cpp index bfb600df0..ab7fc7a24 100644 --- a/src/yuzu/game_list.cpp +++ b/src/yuzu/game_list.cpp @@ -531,8 +531,8 @@ void GameList::AddPermDirPopup(QMenu& context_menu, QModelIndex selected) { UISettings::GameDir& game_dir = *selected.data(GameListDir::GameDirRole).value(); - QAction* move_up = context_menu.addAction(tr(u8"\U000025b2 Move Up")); - QAction* move_down = context_menu.addAction(tr(u8"\U000025bc Move Down ")); + QAction* move_up = context_menu.addAction(tr("\u25B2 Move Up")); + QAction* move_down = context_menu.addAction(tr("\u25bc Move Down")); QAction* open_directory_location = context_menu.addAction(tr("Open Directory Location")); const int row = selected.row(); From 0193202964449ba7a6ae46d614a63bf5caa589a7 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 11 Jul 2020 14:26:36 +0100 Subject: [PATCH 34/55] configuration: Add settings to enable/disable specific CPU optimizations --- externals/dynarmic | 2 +- src/core/arm/dynarmic/arm_dynarmic_32.cpp | 28 ++++- src/core/arm/dynarmic/arm_dynarmic_64.cpp | 32 ++++-- src/core/settings.h | 11 +- src/yuzu/CMakeLists.txt | 3 + src/yuzu/configuration/config.cpp | 53 ++++++++- src/yuzu/configuration/config.h | 2 + src/yuzu/configuration/configure.ui | 11 ++ src/yuzu/configuration/configure_cpu.cpp | 64 +++++++++++ src/yuzu/configuration/configure_cpu.h | 31 ++++++ src/yuzu/configuration/configure_cpu.ui | 113 ++++++++++++++++++++ src/yuzu/configuration/configure_debug.cpp | 2 - src/yuzu/configuration/configure_debug.ui | 7 -- src/yuzu/configuration/configure_dialog.cpp | 5 +- src/yuzu_cmd/config.cpp | 2 - src/yuzu_cmd/default_ini.h | 36 ++++++- src/yuzu_tester/default_ini.h | 33 ++++++ 17 files changed, 405 insertions(+), 30 deletions(-) create mode 100644 src/yuzu/configuration/configure_cpu.cpp create mode 100644 src/yuzu/configuration/configure_cpu.h create mode 100644 src/yuzu/configuration/configure_cpu.ui diff --git a/externals/dynarmic b/externals/dynarmic index 4f967387c..82417da78 160000 --- a/externals/dynarmic +++ b/externals/dynarmic @@ -1 +1 @@ -Subproject commit 4f967387c07365b7ea35d2fa3e19b7df8872a09b +Subproject commit 82417da7803e2cf18efc28a1cd3f3d0a4b6045ae diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index 0d4ab95b7..369a081cd 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp @@ -142,10 +142,30 @@ std::shared_ptr ARM_Dynarmic_32::MakeJit(Common::PageTable& // Timing config.wall_clock_cntpct = uses_wall_clock; - // Optimizations - if (Settings::values.disable_cpu_opt) { - config.enable_optimizations = false; - config.enable_fast_dispatch = false; + // Safe optimizations + if (!Settings::values.cpuopt_page_tables) { + config.page_table = nullptr; + } + if (!Settings::values.cpuopt_block_linking) { + config.optimizations &= ~Dynarmic::OptimizationFlag::BlockLinking; + } + if (!Settings::values.cpuopt_return_stack_buffer) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ReturnStackBuffer; + } + if (!Settings::values.cpuopt_fast_dispatcher) { + config.optimizations &= ~Dynarmic::OptimizationFlag::FastDispatch; + } + if (!Settings::values.cpuopt_context_elimination) { + config.optimizations &= ~Dynarmic::OptimizationFlag::GetSetElimination; + } + if (!Settings::values.cpuopt_const_prop) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ConstProp; + } + if (!Settings::values.cpuopt_misc_ir) { + config.optimizations &= ~Dynarmic::OptimizationFlag::MiscIROpt; + } + if (!Settings::values.cpuopt_reduce_misalign_checks) { + config.only_detect_misalignment_via_page_table_on_page_boundary = false; } return std::make_unique(config); diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index 790981034..e208a4aa7 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp @@ -191,15 +191,35 @@ std::shared_ptr ARM_Dynarmic_64::MakeJit(Common::PageTable& // Unpredictable instructions config.define_unpredictable_behaviour = true; - // Optimizations - if (Settings::values.disable_cpu_opt) { - config.enable_optimizations = false; - config.enable_fast_dispatch = false; - } - // Timing config.wall_clock_cntpct = uses_wall_clock; + // Safe optimizations + if (!Settings::values.cpuopt_page_tables) { + config.page_table = nullptr; + } + if (!Settings::values.cpuopt_block_linking) { + config.optimizations &= ~Dynarmic::OptimizationFlag::BlockLinking; + } + if (!Settings::values.cpuopt_return_stack_buffer) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ReturnStackBuffer; + } + if (!Settings::values.cpuopt_fast_dispatcher) { + config.optimizations &= ~Dynarmic::OptimizationFlag::FastDispatch; + } + if (!Settings::values.cpuopt_context_elimination) { + config.optimizations &= ~Dynarmic::OptimizationFlag::GetSetElimination; + } + if (!Settings::values.cpuopt_const_prop) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ConstProp; + } + if (!Settings::values.cpuopt_misc_ir) { + config.optimizations &= ~Dynarmic::OptimizationFlag::MiscIROpt; + } + if (!Settings::values.cpuopt_reduce_misalign_checks) { + config.only_detect_misalignment_via_page_table_on_page_boundary = false; + } + return std::make_shared(config); } diff --git a/src/core/settings.h b/src/core/settings.h index 850ca4072..c081c083f 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -427,6 +427,16 @@ struct Values { // Core Setting use_multi_core; + // Cpu + bool cpuopt_page_tables; + bool cpuopt_block_linking; + bool cpuopt_return_stack_buffer; + bool cpuopt_fast_dispatcher; + bool cpuopt_context_elimination; + bool cpuopt_const_prop; + bool cpuopt_misc_ir; + bool cpuopt_reduce_misalign_checks; + // Renderer Setting renderer_backend; bool renderer_debug; @@ -505,7 +515,6 @@ struct Values { bool dump_nso; bool reporting_services; bool quest_flag; - bool disable_cpu_opt; bool disable_macro_jit; // Misceallaneous diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 6b25a7fa0..39efa962b 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -30,6 +30,9 @@ add_executable(yuzu configuration/configure_audio.cpp configuration/configure_audio.h configuration/configure_audio.ui + configuration/configure_cpu.cpp + configuration/configure_cpu.h + configuration/configure_cpu.ui configuration/configure_debug.cpp configuration/configure_debug.h configuration/configure_debug.ui diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 1b2b1b2bb..f28e345a5 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -540,8 +540,6 @@ void Config::ReadDebuggingValues() { Settings::values.reporting_services = ReadSetting(QStringLiteral("reporting_services"), false).toBool(); Settings::values.quest_flag = ReadSetting(QStringLiteral("quest_flag"), false).toBool(); - Settings::values.disable_cpu_opt = - ReadSetting(QStringLiteral("disable_cpu_opt"), false).toBool(); Settings::values.disable_macro_jit = ReadSetting(QStringLiteral("disable_macro_jit"), false).toBool(); @@ -633,6 +631,31 @@ void Config::ReadPathValues() { qt_config->endGroup(); } +void Config::ReadCpuValues() { + qt_config->beginGroup(QStringLiteral("Cpu")); + + if (global) { + Settings::values.cpuopt_page_tables = + ReadSetting(QStringLiteral("cpuopt_page_tables"), true).toBool(); + Settings::values.cpuopt_block_linking = + ReadSetting(QStringLiteral("cpuopt_block_linking"), true).toBool(); + Settings::values.cpuopt_return_stack_buffer = + ReadSetting(QStringLiteral("cpuopt_return_stack_buffer"), true).toBool(); + Settings::values.cpuopt_fast_dispatcher = + ReadSetting(QStringLiteral("cpuopt_fast_dispatcher"), true).toBool(); + Settings::values.cpuopt_context_elimination = + ReadSetting(QStringLiteral("cpuopt_context_elimination"), true).toBool(); + Settings::values.cpuopt_const_prop = + ReadSetting(QStringLiteral("cpuopt_const_prop"), true).toBool(); + Settings::values.cpuopt_misc_ir = + ReadSetting(QStringLiteral("cpuopt_misc_ir"), true).toBool(); + Settings::values.cpuopt_reduce_misalign_checks = + ReadSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), true).toBool(); + } + + qt_config->endGroup(); +} + void Config::ReadRendererValues() { qt_config->beginGroup(QStringLiteral("Renderer")); @@ -829,6 +852,7 @@ void Config::ReadValues() { ReadMiscellaneousValues(); } ReadCoreValues(); + ReadCpuValues(); ReadRendererValues(); ReadAudioValues(); ReadSystemValues(); @@ -929,6 +953,7 @@ void Config::SaveValues() { SaveMiscellaneousValues(); } SaveCoreValues(); + SaveCpuValues(); SaveRendererValues(); SaveAudioValues(); SaveSystemValues(); @@ -1033,7 +1058,6 @@ void Config::SaveDebuggingValues() { WriteSetting(QStringLiteral("dump_exefs"), Settings::values.dump_exefs, false); WriteSetting(QStringLiteral("dump_nso"), Settings::values.dump_nso, false); WriteSetting(QStringLiteral("quest_flag"), Settings::values.quest_flag, false); - WriteSetting(QStringLiteral("disable_cpu_opt"), Settings::values.disable_cpu_opt, false); WriteSetting(QStringLiteral("disable_macro_jit"), Settings::values.disable_macro_jit, false); qt_config->endGroup(); @@ -1097,6 +1121,29 @@ void Config::SavePathValues() { qt_config->endGroup(); } +void Config::SaveCpuValues() { + qt_config->beginGroup(QStringLiteral("Cpu")); + + if (global) { + WriteSetting(QStringLiteral("cpuopt_page_tables"), Settings::values.cpuopt_page_tables, + true); + WriteSetting(QStringLiteral("cpuopt_block_linking"), Settings::values.cpuopt_block_linking, + true); + WriteSetting(QStringLiteral("cpuopt_return_stack_buffer"), + Settings::values.cpuopt_return_stack_buffer, true); + WriteSetting(QStringLiteral("cpuopt_fast_dispatcher"), + Settings::values.cpuopt_fast_dispatcher, true); + WriteSetting(QStringLiteral("cpuopt_context_elimination"), + Settings::values.cpuopt_context_elimination, true); + WriteSetting(QStringLiteral("cpuopt_const_prop"), Settings::values.cpuopt_const_prop, true); + WriteSetting(QStringLiteral("cpuopt_misc_ir"), Settings::values.cpuopt_misc_ir, true); + WriteSetting(QStringLiteral("cpuopt_reduce_misalign_checks"), + Settings::values.cpuopt_reduce_misalign_checks, true); + } + + qt_config->endGroup(); +} + void Config::SaveRendererValues() { qt_config->beginGroup(QStringLiteral("Renderer")); diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index 681f0bca5..8e815f829 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h @@ -49,6 +49,7 @@ private: void ReadDisabledAddOnValues(); void ReadMiscellaneousValues(); void ReadPathValues(); + void ReadCpuValues(); void ReadRendererValues(); void ReadShortcutValues(); void ReadSystemValues(); @@ -73,6 +74,7 @@ private: void SaveDisabledAddOnValues(); void SaveMiscellaneousValues(); void SavePathValues(); + void SaveCpuValues(); void SaveRendererValues(); void SaveShortcutValues(); void SaveSystemValues(); diff --git a/src/yuzu/configuration/configure.ui b/src/yuzu/configuration/configure.ui index 9aec1bd09..a23fd9435 100644 --- a/src/yuzu/configuration/configure.ui +++ b/src/yuzu/configuration/configure.ui @@ -78,6 +78,11 @@ Hotkeys + + + CPU + + Graphics @@ -158,6 +163,12 @@
configuration/configure_debug.h
1 + + ConfigureCpu + QWidget +
configuration/configure_cpu.h
+ 1 +
ConfigureGraphics QWidget diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp new file mode 100644 index 000000000..28e010b6b --- /dev/null +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -0,0 +1,64 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "common/common_types.h" +#include "common/logging/log.h" +#include "core/core.h" +#include "core/settings.h" +#include "ui_configure_cpu.h" +#include "yuzu/configuration/configure_cpu.h" + +ConfigureCpu::ConfigureCpu(QWidget* parent) : QWidget(parent), ui(new Ui::ConfigureCpu) { + ui->setupUi(this); + + SetConfiguration(); +} + +ConfigureCpu::~ConfigureCpu() = default; + +void ConfigureCpu::SetConfiguration() { + const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); + + ui->cpuopt_page_tables->setEnabled(runtime_lock); + ui->cpuopt_page_tables->setChecked(Settings::values.cpuopt_page_tables); + ui->cpuopt_block_linking->setEnabled(runtime_lock); + ui->cpuopt_block_linking->setChecked(Settings::values.cpuopt_block_linking); + ui->cpuopt_return_stack_buffer->setEnabled(runtime_lock); + ui->cpuopt_return_stack_buffer->setChecked(Settings::values.cpuopt_return_stack_buffer); + ui->cpuopt_fast_dispatcher->setEnabled(runtime_lock); + ui->cpuopt_fast_dispatcher->setChecked(Settings::values.cpuopt_fast_dispatcher); + ui->cpuopt_context_elimination->setEnabled(runtime_lock); + ui->cpuopt_context_elimination->setChecked(Settings::values.cpuopt_context_elimination); + ui->cpuopt_const_prop->setEnabled(runtime_lock); + ui->cpuopt_const_prop->setChecked(Settings::values.cpuopt_const_prop); + ui->cpuopt_misc_ir->setEnabled(runtime_lock); + ui->cpuopt_misc_ir->setChecked(Settings::values.cpuopt_misc_ir); + ui->cpuopt_reduce_misalign_checks->setEnabled(runtime_lock); + ui->cpuopt_reduce_misalign_checks->setChecked(Settings::values.cpuopt_reduce_misalign_checks); +} + +void ConfigureCpu::ApplyConfiguration() { + Settings::values.cpuopt_page_tables = ui->cpuopt_page_tables->isChecked(); + Settings::values.cpuopt_block_linking = ui->cpuopt_block_linking->isChecked(); + Settings::values.cpuopt_return_stack_buffer = ui->cpuopt_return_stack_buffer->isChecked(); + Settings::values.cpuopt_fast_dispatcher = ui->cpuopt_fast_dispatcher->isChecked(); + Settings::values.cpuopt_context_elimination = ui->cpuopt_context_elimination->isChecked(); + Settings::values.cpuopt_const_prop = ui->cpuopt_const_prop->isChecked(); + Settings::values.cpuopt_misc_ir = ui->cpuopt_misc_ir->isChecked(); + Settings::values.cpuopt_reduce_misalign_checks = ui->cpuopt_reduce_misalign_checks->isChecked(); +} + +void ConfigureCpu::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + } + + QWidget::changeEvent(event); +} + +void ConfigureCpu::RetranslateUI() { + ui->retranslateUi(this); +} diff --git a/src/yuzu/configuration/configure_cpu.h b/src/yuzu/configuration/configure_cpu.h new file mode 100644 index 000000000..a4c6e5f20 --- /dev/null +++ b/src/yuzu/configuration/configure_cpu.h @@ -0,0 +1,31 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "core/settings.h" + +namespace Ui { +class ConfigureCpu; +} + +class ConfigureCpu : public QWidget { + Q_OBJECT + +public: + explicit ConfigureCpu(QWidget* parent = nullptr); + ~ConfigureCpu() override; + + void ApplyConfiguration(); + +private: + void changeEvent(QEvent* event) override; + void RetranslateUI(); + + void SetConfiguration(); + + std::unique_ptr ui; +}; diff --git a/src/yuzu/configuration/configure_cpu.ui b/src/yuzu/configuration/configure_cpu.ui new file mode 100644 index 000000000..d04cfb2d5 --- /dev/null +++ b/src/yuzu/configuration/configure_cpu.ui @@ -0,0 +1,113 @@ + + + ConfigureCpu + + + + 0 + 0 + 400 + 321 + + + + Form + + + + + + + + Safe CPU Optimizations + + + + + + 1 + + + Keep these enabled. For debugging only. + + + + + + + Enable inline page tables + + + + + + + Enable block linking + + + + + + + Enable return stack buffer + + + + + + + Enable fast dispatcher + + + + + + + Enable context elimination + + + + + + + Enable constant propagation + + + + + + + Enable miscellaneous optimizations + + + + + + + Enable misalignment check reduction + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + diff --git a/src/yuzu/configuration/configure_debug.cpp b/src/yuzu/configuration/configure_debug.cpp index 2c77441fd..d0e71dd60 100644 --- a/src/yuzu/configuration/configure_debug.cpp +++ b/src/yuzu/configuration/configure_debug.cpp @@ -36,7 +36,6 @@ void ConfigureDebug::SetConfiguration() { ui->homebrew_args_edit->setText(QString::fromStdString(Settings::values.program_args)); ui->reporting_services->setChecked(Settings::values.reporting_services); ui->quest_flag->setChecked(Settings::values.quest_flag); - ui->disable_cpu_opt->setChecked(Settings::values.disable_cpu_opt); ui->enable_graphics_debugging->setEnabled(!Core::System::GetInstance().IsPoweredOn()); ui->enable_graphics_debugging->setChecked(Settings::values.renderer_debug); ui->disable_macro_jit->setEnabled(!Core::System::GetInstance().IsPoweredOn()); @@ -51,7 +50,6 @@ void ConfigureDebug::ApplyConfiguration() { Settings::values.program_args = ui->homebrew_args_edit->text().toStdString(); Settings::values.reporting_services = ui->reporting_services->isChecked(); Settings::values.quest_flag = ui->quest_flag->isChecked(); - Settings::values.disable_cpu_opt = ui->disable_cpu_opt->isChecked(); Settings::values.renderer_debug = ui->enable_graphics_debugging->isChecked(); Settings::values.disable_macro_jit = ui->disable_macro_jit->isChecked(); Debugger::ToggleConsole(); diff --git a/src/yuzu/configuration/configure_debug.ui b/src/yuzu/configuration/configure_debug.ui index 46f0208c6..272bdd6b8 100644 --- a/src/yuzu/configuration/configure_debug.ui +++ b/src/yuzu/configuration/configure_debug.ui @@ -228,13 +228,6 @@
- - - - Disable CPU JIT optimizations - - -
diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index 5918e9972..a0f49c282 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -42,6 +42,7 @@ void ConfigureDialog::ApplyConfiguration() { ui->filesystemTab->applyConfiguration(); ui->inputTab->ApplyConfiguration(); ui->hotkeysTab->ApplyConfiguration(registry); + ui->cpuTab->ApplyConfiguration(); ui->graphicsTab->ApplyConfiguration(); ui->graphicsAdvancedTab->ApplyConfiguration(); ui->audioTab->ApplyConfiguration(); @@ -76,9 +77,10 @@ void ConfigureDialog::RetranslateUI() { Q_DECLARE_METATYPE(QList); void ConfigureDialog::PopulateSelectionList() { - const std::array>, 5> items{ + const std::array>, 6> items{ {{tr("General"), {ui->generalTab, ui->webTab, ui->debugTab, ui->uiTab}}, {tr("System"), {ui->systemTab, ui->profileManagerTab, ui->serviceTab, ui->filesystemTab}}, + {tr("CPU"), {ui->cpuTab}}, {tr("Graphics"), {ui->graphicsTab, ui->graphicsAdvancedTab}}, {tr("Audio"), {ui->audioTab}}, {tr("Controls"), {ui->inputTab, ui->hotkeysTab}}}, @@ -107,6 +109,7 @@ void ConfigureDialog::UpdateVisibleTabs() { {ui->profileManagerTab, tr("Profiles")}, {ui->inputTab, tr("Input")}, {ui->hotkeysTab, tr("Hotkeys")}, + {ui->cpuTab, tr("CPU")}, {ui->graphicsTab, tr("Graphics")}, {ui->graphicsAdvancedTab, tr("Advanced")}, {ui->audioTab, tr("Audio")}, diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 23763144f..441d8e8f7 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -437,8 +437,6 @@ void Config::ReadValues() { Settings::values.reporting_services = sdl2_config->GetBoolean("Debugging", "reporting_services", false); Settings::values.quest_flag = sdl2_config->GetBoolean("Debugging", "quest_flag", false); - Settings::values.disable_cpu_opt = - sdl2_config->GetBoolean("Debugging", "disable_cpu_opt", false); Settings::values.disable_macro_jit = sdl2_config->GetBoolean("Debugging", "disable_macro_jit", false); diff --git a/src/yuzu_cmd/default_ini.h b/src/yuzu_cmd/default_ini.h index 45c07ed5d..5bed47fd7 100644 --- a/src/yuzu_cmd/default_ini.h +++ b/src/yuzu_cmd/default_ini.h @@ -97,6 +97,39 @@ udp_pad_index= # 0 (default): Disabled, 1: Enabled use_multi_core= +[Cpu] +# Enable inline page tables optimization (faster guest memory access) +# 0: Disabled, 1 (default): Enabled +cpuopt_page_tables = + +# Enable block linking CPU optimization (reduce block dispatcher use during predictable jumps) +# 0: Disabled, 1 (default): Enabled +cpuopt_block_linking = + +# Enable return stack buffer CPU optimization (reduce block dispatcher use during predictable returns) +# 0: Disabled, 1 (default): Enabled +cpuopt_return_stack_buffer = + +# Enable fast dispatcher CPU optimization (use a two-tiered dispatcher architecture) +# 0: Disabled, 1 (default): Enabled +cpuopt_fast_dispatcher = + +# Enable context elimination CPU Optimization (reduce host memory use for guest context) +# 0: Disabled, 1 (default): Enabled +cpuopt_context_elimination = + +# Enable constant propagation CPU optimization (basic IR optimization) +# 0: Disabled, 1 (default): Enabled +cpuopt_const_prop = + +# Enable miscellaneous CPU optimizations (basic IR optimization) +# 0: Disabled, 1 (default): Enabled +cpuopt_misc_ir = + +# Enable reduction of memory misalignment checks (reduce memory fallbacks for misaligned access) +# 0: Disabled, 1 (default): Enabled +cpuopt_reduce_misalign_checks = + [Renderer] # Which backend API to use. # 0 (default): OpenGL, 1: Vulkan @@ -283,9 +316,6 @@ dump_nso=false # Determines whether or not yuzu will report to the game that the emulated console is in Kiosk Mode # false: Retail/Normal Mode (default), true: Kiosk Mode quest_flag = -# Determines whether or not JIT CPU optimizations are enabled -# false: Optimizations Enabled, true: Optimizations Disabled -disable_cpu_opt = # Enables/Disables the macro JIT compiler disable_macro_jit=false diff --git a/src/yuzu_tester/default_ini.h b/src/yuzu_tester/default_ini.h index 41bbbbf60..3eb64e9d7 100644 --- a/src/yuzu_tester/default_ini.h +++ b/src/yuzu_tester/default_ini.h @@ -12,6 +12,39 @@ const char* sdl2_config_file = R"( # 0 (default): Disabled, 1: Enabled use_multi_core= +[Cpu] +# Enable inline page tables optimization (faster guest memory access) +# 0: Disabled, 1 (default): Enabled +cpuopt_page_tables = + +# Enable block linking CPU optimization (reduce block dispatcher use during predictable jumps) +# 0: Disabled, 1 (default): Enabled +cpuopt_block_linking = + +# Enable return stack buffer CPU optimization (reduce block dispatcher use during predictable returns) +# 0: Disabled, 1 (default): Enabled +cpuopt_return_stack_buffer = + +# Enable fast dispatcher CPU optimization (use a two-tiered dispatcher architecture) +# 0: Disabled, 1 (default): Enabled +cpuopt_fast_dispatcher = + +# Enable context elimination CPU Optimization (reduce host memory use for guest context) +# 0: Disabled, 1 (default): Enabled +cpuopt_context_elimination = + +# Enable constant propagation CPU optimization (basic IR optimization) +# 0: Disabled, 1 (default): Enabled +cpuopt_const_prop = + +# Enable miscellaneous CPU optimizations (basic IR optimization) +# 0: Disabled, 1 (default): Enabled +cpuopt_misc_ir = + +# Enable reduction of memory misalignment checks (reduce memory fallbacks for misaligned access) +# 0: Disabled, 1 (default): Enabled +cpuopt_reduce_misalign_checks = + [Renderer] # Whether to use software or hardware rendering. # 0: Software, 1 (default): Hardware From 6744e7ea4a2e00ac2a481045f036a282b85fc0b1 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 11 Jul 2020 14:37:34 +0100 Subject: [PATCH 35/55] CMakeLists: Do not search for system libusb on macOS --- CMakeLists.txt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c0e49c03..88ea04c08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -330,14 +330,15 @@ elseif(SDL2_FOUND) endif() # Ensure libusb is properly configured (based on dolphin libusb include) -include(FindPkgConfig) -find_package(LibUSB) +if(NOT APPLE) + include(FindPkgConfig) + find_package(LibUSB) +endif() if (NOT LIBUSB_FOUND) add_subdirectory(externals/libusb) set(LIBUSB_LIBRARIES usb) endif() - # Prefer the -pthread flag on Linux. set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads REQUIRED) From 505aa3a4c1eb2384ab5a46aecf6431db239b74e3 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 11 Jul 2020 16:25:49 +0100 Subject: [PATCH 36/55] configure_cpu: Show/Hide debugging options --- src/core/arm/dynarmic/arm_dynarmic_32.cpp | 48 ++++++++++++----------- src/core/arm/dynarmic/arm_dynarmic_64.cpp | 48 ++++++++++++----------- src/core/settings.h | 7 ++++ src/yuzu/configuration/config.cpp | 6 +++ src/yuzu/configuration/configure_cpu.cpp | 22 +++++++++++ src/yuzu/configuration/configure_cpu.h | 2 + src/yuzu/configuration/configure_cpu.ui | 48 +++++++++++++++++++++++ 7 files changed, 135 insertions(+), 46 deletions(-) diff --git a/src/core/arm/dynarmic/arm_dynarmic_32.cpp b/src/core/arm/dynarmic/arm_dynarmic_32.cpp index 369a081cd..443ca72eb 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_32.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_32.cpp @@ -143,29 +143,31 @@ std::shared_ptr ARM_Dynarmic_32::MakeJit(Common::PageTable& config.wall_clock_cntpct = uses_wall_clock; // Safe optimizations - if (!Settings::values.cpuopt_page_tables) { - config.page_table = nullptr; - } - if (!Settings::values.cpuopt_block_linking) { - config.optimizations &= ~Dynarmic::OptimizationFlag::BlockLinking; - } - if (!Settings::values.cpuopt_return_stack_buffer) { - config.optimizations &= ~Dynarmic::OptimizationFlag::ReturnStackBuffer; - } - if (!Settings::values.cpuopt_fast_dispatcher) { - config.optimizations &= ~Dynarmic::OptimizationFlag::FastDispatch; - } - if (!Settings::values.cpuopt_context_elimination) { - config.optimizations &= ~Dynarmic::OptimizationFlag::GetSetElimination; - } - if (!Settings::values.cpuopt_const_prop) { - config.optimizations &= ~Dynarmic::OptimizationFlag::ConstProp; - } - if (!Settings::values.cpuopt_misc_ir) { - config.optimizations &= ~Dynarmic::OptimizationFlag::MiscIROpt; - } - if (!Settings::values.cpuopt_reduce_misalign_checks) { - config.only_detect_misalignment_via_page_table_on_page_boundary = false; + if (Settings::values.cpu_accuracy != Settings::CPUAccuracy::Accurate) { + if (!Settings::values.cpuopt_page_tables) { + config.page_table = nullptr; + } + if (!Settings::values.cpuopt_block_linking) { + config.optimizations &= ~Dynarmic::OptimizationFlag::BlockLinking; + } + if (!Settings::values.cpuopt_return_stack_buffer) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ReturnStackBuffer; + } + if (!Settings::values.cpuopt_fast_dispatcher) { + config.optimizations &= ~Dynarmic::OptimizationFlag::FastDispatch; + } + if (!Settings::values.cpuopt_context_elimination) { + config.optimizations &= ~Dynarmic::OptimizationFlag::GetSetElimination; + } + if (!Settings::values.cpuopt_const_prop) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ConstProp; + } + if (!Settings::values.cpuopt_misc_ir) { + config.optimizations &= ~Dynarmic::OptimizationFlag::MiscIROpt; + } + if (!Settings::values.cpuopt_reduce_misalign_checks) { + config.only_detect_misalignment_via_page_table_on_page_boundary = false; + } } return std::make_unique(config); diff --git a/src/core/arm/dynarmic/arm_dynarmic_64.cpp b/src/core/arm/dynarmic/arm_dynarmic_64.cpp index e208a4aa7..a63a04a25 100644 --- a/src/core/arm/dynarmic/arm_dynarmic_64.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic_64.cpp @@ -195,29 +195,31 @@ std::shared_ptr ARM_Dynarmic_64::MakeJit(Common::PageTable& config.wall_clock_cntpct = uses_wall_clock; // Safe optimizations - if (!Settings::values.cpuopt_page_tables) { - config.page_table = nullptr; - } - if (!Settings::values.cpuopt_block_linking) { - config.optimizations &= ~Dynarmic::OptimizationFlag::BlockLinking; - } - if (!Settings::values.cpuopt_return_stack_buffer) { - config.optimizations &= ~Dynarmic::OptimizationFlag::ReturnStackBuffer; - } - if (!Settings::values.cpuopt_fast_dispatcher) { - config.optimizations &= ~Dynarmic::OptimizationFlag::FastDispatch; - } - if (!Settings::values.cpuopt_context_elimination) { - config.optimizations &= ~Dynarmic::OptimizationFlag::GetSetElimination; - } - if (!Settings::values.cpuopt_const_prop) { - config.optimizations &= ~Dynarmic::OptimizationFlag::ConstProp; - } - if (!Settings::values.cpuopt_misc_ir) { - config.optimizations &= ~Dynarmic::OptimizationFlag::MiscIROpt; - } - if (!Settings::values.cpuopt_reduce_misalign_checks) { - config.only_detect_misalignment_via_page_table_on_page_boundary = false; + if (Settings::values.cpu_accuracy != Settings::CPUAccuracy::Accurate) { + if (!Settings::values.cpuopt_page_tables) { + config.page_table = nullptr; + } + if (!Settings::values.cpuopt_block_linking) { + config.optimizations &= ~Dynarmic::OptimizationFlag::BlockLinking; + } + if (!Settings::values.cpuopt_return_stack_buffer) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ReturnStackBuffer; + } + if (!Settings::values.cpuopt_fast_dispatcher) { + config.optimizations &= ~Dynarmic::OptimizationFlag::FastDispatch; + } + if (!Settings::values.cpuopt_context_elimination) { + config.optimizations &= ~Dynarmic::OptimizationFlag::GetSetElimination; + } + if (!Settings::values.cpuopt_const_prop) { + config.optimizations &= ~Dynarmic::OptimizationFlag::ConstProp; + } + if (!Settings::values.cpuopt_misc_ir) { + config.optimizations &= ~Dynarmic::OptimizationFlag::MiscIROpt; + } + if (!Settings::values.cpuopt_reduce_misalign_checks) { + config.only_detect_misalignment_via_page_table_on_page_boundary = false; + } } return std::make_shared(config); diff --git a/src/core/settings.h b/src/core/settings.h index c081c083f..b3451a704 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -382,6 +382,11 @@ enum class GPUAccuracy : u32 { Extreme = 2, }; +enum class CPUAccuracy { + Accurate = 0, + DebugMode = 1, +}; + extern bool configuring_global; template @@ -428,6 +433,8 @@ struct Values { Setting use_multi_core; // Cpu + CPUAccuracy cpu_accuracy; + bool cpuopt_page_tables; bool cpuopt_block_linking; bool cpuopt_return_stack_buffer; diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index f28e345a5..430e78e5f 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -635,6 +635,9 @@ void Config::ReadCpuValues() { qt_config->beginGroup(QStringLiteral("Cpu")); if (global) { + Settings::values.cpu_accuracy = static_cast( + ReadSetting(QStringLiteral("cpu_accuracy"), 0).toInt()); + Settings::values.cpuopt_page_tables = ReadSetting(QStringLiteral("cpuopt_page_tables"), true).toBool(); Settings::values.cpuopt_block_linking = @@ -1125,6 +1128,9 @@ void Config::SaveCpuValues() { qt_config->beginGroup(QStringLiteral("Cpu")); if (global) { + WriteSetting(QStringLiteral("cpu_accuracy"), + static_cast(Settings::values.cpu_accuracy), 0); + WriteSetting(QStringLiteral("cpuopt_page_tables"), Settings::values.cpuopt_page_tables, true); WriteSetting(QStringLiteral("cpuopt_block_linking"), Settings::values.cpuopt_block_linking, diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index 28e010b6b..4fc392a7e 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -15,6 +15,9 @@ ConfigureCpu::ConfigureCpu(QWidget* parent) : QWidget(parent), ui(new Ui::Config ui->setupUi(this); SetConfiguration(); + + connect(ui->accuracy, qOverload(&QComboBox::currentIndexChanged), this, + &ConfigureCpu::UpdateGroups); } ConfigureCpu::~ConfigureCpu() = default; @@ -22,6 +25,10 @@ ConfigureCpu::~ConfigureCpu() = default; void ConfigureCpu::SetConfiguration() { const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); + ui->accuracy->setEnabled(runtime_lock); + ui->accuracy->setCurrentIndex(static_cast(Settings::values.cpu_accuracy)); + UpdateGroups(static_cast(Settings::values.cpu_accuracy)); + ui->cpuopt_page_tables->setEnabled(runtime_lock); ui->cpuopt_page_tables->setChecked(Settings::values.cpuopt_page_tables); ui->cpuopt_block_linking->setEnabled(runtime_lock); @@ -40,7 +47,22 @@ void ConfigureCpu::SetConfiguration() { ui->cpuopt_reduce_misalign_checks->setChecked(Settings::values.cpuopt_reduce_misalign_checks); } +void ConfigureCpu::UpdateGroups(int index) { + switch (index) { + case 0: + default: + ui->group_safe->setVisible(false); + break; + case 1: + ui->group_safe->setVisible(true); + break; + } +} + void ConfigureCpu::ApplyConfiguration() { + Settings::values.cpu_accuracy = + static_cast(ui->accuracy->currentIndex()); + Settings::values.cpuopt_page_tables = ui->cpuopt_page_tables->isChecked(); Settings::values.cpuopt_block_linking = ui->cpuopt_block_linking->isChecked(); Settings::values.cpuopt_return_stack_buffer = ui->cpuopt_return_stack_buffer->isChecked(); diff --git a/src/yuzu/configuration/configure_cpu.h b/src/yuzu/configuration/configure_cpu.h index a4c6e5f20..cf55980b0 100644 --- a/src/yuzu/configuration/configure_cpu.h +++ b/src/yuzu/configuration/configure_cpu.h @@ -25,6 +25,8 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); + void UpdateGroups(int index); + void SetConfiguration(); std::unique_ptr ui; diff --git a/src/yuzu/configuration/configure_cpu.ui b/src/yuzu/configuration/configure_cpu.ui index d04cfb2d5..27bd4aa42 100644 --- a/src/yuzu/configuration/configure_cpu.ui +++ b/src/yuzu/configuration/configure_cpu.ui @@ -18,6 +18,54 @@ + + General + + + + + + + + Accuracy: + + + + + + + + Accurate + + + + + Debugging Mode (Debugging ONLY) + + + + + + + + + + 1 + + + We recommend setting accuracy to "Accurate". + + + + + + + + + + + + Safe CPU Optimizations From da11a27f42f25a7f24c0b7cece8e499f34880fc8 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sat, 11 Jul 2020 16:26:06 +0100 Subject: [PATCH 37/55] configure_cpu: Add tooltips --- src/yuzu/configuration/configure_cpu.ui | 55 ++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/src/yuzu/configuration/configure_cpu.ui b/src/yuzu/configuration/configure_cpu.ui index 27bd4aa42..308e70356 100644 --- a/src/yuzu/configuration/configure_cpu.ui +++ b/src/yuzu/configuration/configure_cpu.ui @@ -76,7 +76,7 @@ 1 - Keep these enabled. For debugging only. + Keep all of these enabled. For debugging only. @@ -85,6 +85,13 @@ Enable inline page tables + + + <div style="white-space: nowrap">This optimization speeds up memory accesses by the guest program.</div> + <div style="white-space: nowrap">Enabling it inlines accesses to PageTable::pointers into emitted code.</div> + <div style="white-space: nowrap">Disabling this forces all memory accesses to go through the Memory::Read/Memory::Write functions.</div> + + @@ -92,6 +99,11 @@ Enable block linking + + + <div>This optimization avoids dispatcher lookups by allowing emitted basic blocks to jump directly to other basic blocks if the destination PC is static.</div> + + @@ -99,6 +111,11 @@ Enable return stack buffer + + + <div>This optimization avoids dispatcher lookups by keeping track potential return addresses of BL instructions. This approximates what happens with a return stack buffer on a real CPU.</div> + + @@ -106,6 +123,11 @@ Enable fast dispatcher + + + <div>Enable a two-tiered dispatch system. A faster dispatcher written in assembly has a small MRU cache of jump destinations is used first. If that fails, dispatch falls back to the slower C++ dispatcher.</div> + + @@ -113,6 +135,11 @@ Enable context elimination + + + <div>Enables an IR optimization that reduces unnecessary accesses to the CPU context structure.</div> + + @@ -120,6 +147,11 @@ Enable constant propagation + + + <div>Enables IR optimizations that involve constant propagation.</div> + + @@ -127,6 +159,11 @@ Enable miscellaneous optimizations + + + <div>Enables miscellaneous IR optimizations.</div> + + @@ -134,6 +171,12 @@ Enable misalignment check reduction + + + <div style="white-space: nowrap">When enabled, a misalignment is only triggered when an access crosses a page boundary.</div> + <div style="white-space: nowrap">When disabled, a misalignment is triggered on all misaligned accesses.</div> + +
@@ -154,6 +197,16 @@ + + + + CPU settings are available only when game is not running. + + + true + + +
From a4306b9e5662fca74f65f0b657e7002fda7f1829 Mon Sep 17 00:00:00 2001 From: Marshall Mohror Date: Tue, 7 Jul 2020 16:39:23 -0500 Subject: [PATCH 38/55] Common: remove a mod from AlignUp (#5441) In cases where the size is not a known constant when inlining, AlignUp currently generates two 64-bit div instructions. This generates one div and a cmov which is significantly cheaper. --- src/common/alignment.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/alignment.h b/src/common/alignment.h index f8c49e079..516bb26c1 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -11,7 +11,9 @@ namespace Common { template constexpr T AlignUp(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); - return static_cast(value + (size - value % size) % size); + auto mod{value % size}; + value -= mod; + return static_cast(mod == T{0} ? value : value + size); } template From 1074c87f18881ba8e6c20c1cee10ec3cbba71adb Mon Sep 17 00:00:00 2001 From: bunnei Date: Sat, 11 Jul 2020 19:28:09 -0400 Subject: [PATCH 39/55] Revert "Port citra-emu/citra#5441: "Common: remove a mod from AlignUp"" --- src/common/alignment.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/common/alignment.h b/src/common/alignment.h index 516bb26c1..f8c49e079 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -11,9 +11,7 @@ namespace Common { template constexpr T AlignUp(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); - auto mod{value % size}; - value -= mod; - return static_cast(mod == T{0} ? value : value + size); + return static_cast(value + (size - value % size) % size); } template From 63cc4e417f803118d10cfb0b45ad7b5490748c85 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sun, 12 Jul 2020 10:16:07 -0400 Subject: [PATCH 40/55] Fix Discord invite link --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1e9f67e08..e4ecb531d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ yuzu emulator ============= [![Travis CI Build Status](https://travis-ci.com/yuzu-emu/yuzu.svg?branch=master)](https://travis-ci.com/yuzu-emu/yuzu) [![Azure Mainline CI Build Status](https://dev.azure.com/yuzu-emu/yuzu/_apis/build/status/yuzu%20mainline?branchName=master)](https://dev.azure.com/yuzu-emu/yuzu/) -[![Discord](https://img.shields.io/discord/398318088170242053?color=%237289DA&label=yuzu&logo=discord&logoColor=white)](https://discord.gg/XQV6dn9) +[![Discord](https://img.shields.io/discord/398318088170242053?color=%237289DA&label=yuzu&logo=discord&logoColor=white)](https://discord.com/invite/u77vRWY) yuzu is an experimental open-source emulator for the Nintendo Switch from the creators of [Citra](https://citra-emu.org/). @@ -16,7 +16,7 @@ yuzu is licensed under the GPLv2 (or any later version). Refer to the license.tx Check out our [website](https://yuzu-emu.org/)! -For development discussion, please join us on [Discord](https://discord.gg/XQV6dn9). +For development discussion, please join us on [Discord](https://discord.com/invite/u77vRWY). ### Development From 80a0f2a118b858b3ceb4ae0ae09d72353d58c928 Mon Sep 17 00:00:00 2001 From: Tobias Date: Sun, 12 Jul 2020 16:45:49 +0200 Subject: [PATCH 41/55] common/alignment: Fix compilation errors (#4303) --- src/common/alignment.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/alignment.h b/src/common/alignment.h index f8c49e079..b37044bb6 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h @@ -11,7 +11,9 @@ namespace Common { template constexpr T AlignUp(T value, std::size_t size) { static_assert(std::is_unsigned_v, "T must be an unsigned value."); - return static_cast(value + (size - value % size) % size); + auto mod{static_cast(value % size)}; + value -= mod; + return static_cast(mod == T{0} ? value : value + size); } template From a67d00ef31aba1c45dde956b48844f91427963a1 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Sun, 12 Jul 2020 12:06:04 +0100 Subject: [PATCH 42/55] configure_cpu: Split optimization settings off into Debug tab --- src/yuzu/CMakeLists.txt | 3 + src/yuzu/configuration/configure.ui | 11 ++ src/yuzu/configuration/configure_cpu.cpp | 51 ++--- src/yuzu/configuration/configure_cpu.h | 2 +- src/yuzu/configuration/configure_cpu.ui | 124 +------------ .../configuration/configure_cpu_debug.cpp | 65 +++++++ src/yuzu/configuration/configure_cpu_debug.h | 31 ++++ src/yuzu/configuration/configure_cpu_debug.ui | 174 ++++++++++++++++++ src/yuzu/configuration/configure_dialog.cpp | 4 +- 9 files changed, 302 insertions(+), 163 deletions(-) create mode 100644 src/yuzu/configuration/configure_cpu_debug.cpp create mode 100644 src/yuzu/configuration/configure_cpu_debug.h create mode 100644 src/yuzu/configuration/configure_cpu_debug.ui diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 39efa962b..5f175b989 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -33,6 +33,9 @@ add_executable(yuzu configuration/configure_cpu.cpp configuration/configure_cpu.h configuration/configure_cpu.ui + configuration/configure_cpu_debug.cpp + configuration/configure_cpu_debug.h + configuration/configure_cpu_debug.ui configuration/configure_debug.cpp configuration/configure_debug.h configuration/configure_debug.ui diff --git a/src/yuzu/configuration/configure.ui b/src/yuzu/configuration/configure.ui index a23fd9435..5f5d8e571 100644 --- a/src/yuzu/configuration/configure.ui +++ b/src/yuzu/configuration/configure.ui @@ -83,6 +83,11 @@ CPU + + + Debug + + Graphics @@ -169,6 +174,12 @@
configuration/configure_cpu.h
1 + + ConfigureCpuDebug + QWidget +
configuration/configure_cpu_debug.h
+ 1 +
ConfigureGraphics QWidget diff --git a/src/yuzu/configuration/configure_cpu.cpp b/src/yuzu/configuration/configure_cpu.cpp index 4fc392a7e..7493e5ffb 100644 --- a/src/yuzu/configuration/configure_cpu.cpp +++ b/src/yuzu/configuration/configure_cpu.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "common/common_types.h" #include "common/logging/log.h" @@ -16,8 +17,8 @@ ConfigureCpu::ConfigureCpu(QWidget* parent) : QWidget(parent), ui(new Ui::Config SetConfiguration(); - connect(ui->accuracy, qOverload(&QComboBox::currentIndexChanged), this, - &ConfigureCpu::UpdateGroups); + connect(ui->accuracy, qOverload(&QComboBox::activated), this, + &ConfigureCpu::AccuracyUpdated); } ConfigureCpu::~ConfigureCpu() = default; @@ -27,50 +28,24 @@ void ConfigureCpu::SetConfiguration() { ui->accuracy->setEnabled(runtime_lock); ui->accuracy->setCurrentIndex(static_cast(Settings::values.cpu_accuracy)); - UpdateGroups(static_cast(Settings::values.cpu_accuracy)); - - ui->cpuopt_page_tables->setEnabled(runtime_lock); - ui->cpuopt_page_tables->setChecked(Settings::values.cpuopt_page_tables); - ui->cpuopt_block_linking->setEnabled(runtime_lock); - ui->cpuopt_block_linking->setChecked(Settings::values.cpuopt_block_linking); - ui->cpuopt_return_stack_buffer->setEnabled(runtime_lock); - ui->cpuopt_return_stack_buffer->setChecked(Settings::values.cpuopt_return_stack_buffer); - ui->cpuopt_fast_dispatcher->setEnabled(runtime_lock); - ui->cpuopt_fast_dispatcher->setChecked(Settings::values.cpuopt_fast_dispatcher); - ui->cpuopt_context_elimination->setEnabled(runtime_lock); - ui->cpuopt_context_elimination->setChecked(Settings::values.cpuopt_context_elimination); - ui->cpuopt_const_prop->setEnabled(runtime_lock); - ui->cpuopt_const_prop->setChecked(Settings::values.cpuopt_const_prop); - ui->cpuopt_misc_ir->setEnabled(runtime_lock); - ui->cpuopt_misc_ir->setChecked(Settings::values.cpuopt_misc_ir); - ui->cpuopt_reduce_misalign_checks->setEnabled(runtime_lock); - ui->cpuopt_reduce_misalign_checks->setChecked(Settings::values.cpuopt_reduce_misalign_checks); } -void ConfigureCpu::UpdateGroups(int index) { - switch (index) { - case 0: - default: - ui->group_safe->setVisible(false); - break; - case 1: - ui->group_safe->setVisible(true); - break; +void ConfigureCpu::AccuracyUpdated(int index) { + if (static_cast(index) == Settings::CPUAccuracy::DebugMode) { + const auto result = QMessageBox::warning(this, tr("Setting CPU to Debug Mode"), + tr("CPU Debug Mode is only intended for developer " + "use. Are you sure you want to enable this?"), + QMessageBox::Yes | QMessageBox::No); + if (result == QMessageBox::No) { + ui->accuracy->setCurrentIndex(static_cast(Settings::CPUAccuracy::Accurate)); + return; + } } } void ConfigureCpu::ApplyConfiguration() { Settings::values.cpu_accuracy = static_cast(ui->accuracy->currentIndex()); - - Settings::values.cpuopt_page_tables = ui->cpuopt_page_tables->isChecked(); - Settings::values.cpuopt_block_linking = ui->cpuopt_block_linking->isChecked(); - Settings::values.cpuopt_return_stack_buffer = ui->cpuopt_return_stack_buffer->isChecked(); - Settings::values.cpuopt_fast_dispatcher = ui->cpuopt_fast_dispatcher->isChecked(); - Settings::values.cpuopt_context_elimination = ui->cpuopt_context_elimination->isChecked(); - Settings::values.cpuopt_const_prop = ui->cpuopt_const_prop->isChecked(); - Settings::values.cpuopt_misc_ir = ui->cpuopt_misc_ir->isChecked(); - Settings::values.cpuopt_reduce_misalign_checks = ui->cpuopt_reduce_misalign_checks->isChecked(); } void ConfigureCpu::changeEvent(QEvent* event) { diff --git a/src/yuzu/configuration/configure_cpu.h b/src/yuzu/configuration/configure_cpu.h index cf55980b0..e4741d3a4 100644 --- a/src/yuzu/configuration/configure_cpu.h +++ b/src/yuzu/configuration/configure_cpu.h @@ -25,7 +25,7 @@ private: void changeEvent(QEvent* event) override; void RetranslateUI(); - void UpdateGroups(int index); + void AccuracyUpdated(int index); void SetConfiguration(); diff --git a/src/yuzu/configuration/configure_cpu.ui b/src/yuzu/configuration/configure_cpu.ui index 308e70356..bf6ea79bb 100644 --- a/src/yuzu/configuration/configure_cpu.ui +++ b/src/yuzu/configuration/configure_cpu.ui @@ -40,7 +40,7 @@ - Debugging Mode (Debugging ONLY) + Enable Debug Mode
@@ -62,128 +62,6 @@ - - - - - - Safe CPU Optimizations - - - - - - 1 - - - Keep all of these enabled. For debugging only. - - - - - - - Enable inline page tables - - - - <div style="white-space: nowrap">This optimization speeds up memory accesses by the guest program.</div> - <div style="white-space: nowrap">Enabling it inlines accesses to PageTable::pointers into emitted code.</div> - <div style="white-space: nowrap">Disabling this forces all memory accesses to go through the Memory::Read/Memory::Write functions.</div> - - - - - - - - Enable block linking - - - - <div>This optimization avoids dispatcher lookups by allowing emitted basic blocks to jump directly to other basic blocks if the destination PC is static.</div> - - - - - - - - Enable return stack buffer - - - - <div>This optimization avoids dispatcher lookups by keeping track potential return addresses of BL instructions. This approximates what happens with a return stack buffer on a real CPU.</div> - - - - - - - - Enable fast dispatcher - - - - <div>Enable a two-tiered dispatch system. A faster dispatcher written in assembly has a small MRU cache of jump destinations is used first. If that fails, dispatch falls back to the slower C++ dispatcher.</div> - - - - - - - - Enable context elimination - - - - <div>Enables an IR optimization that reduces unnecessary accesses to the CPU context structure.</div> - - - - - - - - Enable constant propagation - - - - <div>Enables IR optimizations that involve constant propagation.</div> - - - - - - - - Enable miscellaneous optimizations - - - - <div>Enables miscellaneous IR optimizations.</div> - - - - - - - - Enable misalignment check reduction - - - - <div style="white-space: nowrap">When enabled, a misalignment is only triggered when an access crosses a page boundary.</div> - <div style="white-space: nowrap">When disabled, a misalignment is triggered on all misaligned accesses.</div> - - - - - - - - - diff --git a/src/yuzu/configuration/configure_cpu_debug.cpp b/src/yuzu/configuration/configure_cpu_debug.cpp new file mode 100644 index 000000000..3385b2cf6 --- /dev/null +++ b/src/yuzu/configuration/configure_cpu_debug.cpp @@ -0,0 +1,65 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "common/common_types.h" +#include "common/logging/log.h" +#include "core/core.h" +#include "core/settings.h" +#include "ui_configure_cpu_debug.h" +#include "yuzu/configuration/configure_cpu_debug.h" + +ConfigureCpuDebug::ConfigureCpuDebug(QWidget* parent) + : QWidget(parent), ui(new Ui::ConfigureCpuDebug) { + ui->setupUi(this); + + SetConfiguration(); +} + +ConfigureCpuDebug::~ConfigureCpuDebug() = default; + +void ConfigureCpuDebug::SetConfiguration() { + const bool runtime_lock = !Core::System::GetInstance().IsPoweredOn(); + + ui->cpuopt_page_tables->setEnabled(runtime_lock); + ui->cpuopt_page_tables->setChecked(Settings::values.cpuopt_page_tables); + ui->cpuopt_block_linking->setEnabled(runtime_lock); + ui->cpuopt_block_linking->setChecked(Settings::values.cpuopt_block_linking); + ui->cpuopt_return_stack_buffer->setEnabled(runtime_lock); + ui->cpuopt_return_stack_buffer->setChecked(Settings::values.cpuopt_return_stack_buffer); + ui->cpuopt_fast_dispatcher->setEnabled(runtime_lock); + ui->cpuopt_fast_dispatcher->setChecked(Settings::values.cpuopt_fast_dispatcher); + ui->cpuopt_context_elimination->setEnabled(runtime_lock); + ui->cpuopt_context_elimination->setChecked(Settings::values.cpuopt_context_elimination); + ui->cpuopt_const_prop->setEnabled(runtime_lock); + ui->cpuopt_const_prop->setChecked(Settings::values.cpuopt_const_prop); + ui->cpuopt_misc_ir->setEnabled(runtime_lock); + ui->cpuopt_misc_ir->setChecked(Settings::values.cpuopt_misc_ir); + ui->cpuopt_reduce_misalign_checks->setEnabled(runtime_lock); + ui->cpuopt_reduce_misalign_checks->setChecked(Settings::values.cpuopt_reduce_misalign_checks); +} + +void ConfigureCpuDebug::ApplyConfiguration() { + Settings::values.cpuopt_page_tables = ui->cpuopt_page_tables->isChecked(); + Settings::values.cpuopt_block_linking = ui->cpuopt_block_linking->isChecked(); + Settings::values.cpuopt_return_stack_buffer = ui->cpuopt_return_stack_buffer->isChecked(); + Settings::values.cpuopt_fast_dispatcher = ui->cpuopt_fast_dispatcher->isChecked(); + Settings::values.cpuopt_context_elimination = ui->cpuopt_context_elimination->isChecked(); + Settings::values.cpuopt_const_prop = ui->cpuopt_const_prop->isChecked(); + Settings::values.cpuopt_misc_ir = ui->cpuopt_misc_ir->isChecked(); + Settings::values.cpuopt_reduce_misalign_checks = ui->cpuopt_reduce_misalign_checks->isChecked(); +} + +void ConfigureCpuDebug::changeEvent(QEvent* event) { + if (event->type() == QEvent::LanguageChange) { + RetranslateUI(); + } + + QWidget::changeEvent(event); +} + +void ConfigureCpuDebug::RetranslateUI() { + ui->retranslateUi(this); +} diff --git a/src/yuzu/configuration/configure_cpu_debug.h b/src/yuzu/configuration/configure_cpu_debug.h new file mode 100644 index 000000000..c9941ef3b --- /dev/null +++ b/src/yuzu/configuration/configure_cpu_debug.h @@ -0,0 +1,31 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include "core/settings.h" + +namespace Ui { +class ConfigureCpuDebug; +} + +class ConfigureCpuDebug : public QWidget { + Q_OBJECT + +public: + explicit ConfigureCpuDebug(QWidget* parent = nullptr); + ~ConfigureCpuDebug() override; + + void ApplyConfiguration(); + +private: + void changeEvent(QEvent* event) override; + void RetranslateUI(); + + void SetConfiguration(); + + std::unique_ptr ui; +}; diff --git a/src/yuzu/configuration/configure_cpu_debug.ui b/src/yuzu/configuration/configure_cpu_debug.ui new file mode 100644 index 000000000..a90dc64fe --- /dev/null +++ b/src/yuzu/configuration/configure_cpu_debug.ui @@ -0,0 +1,174 @@ + + + ConfigureCpuDebug + + + + 0 + 0 + 400 + 321 + + + + Form + + + + + + + + Toggle CPU Optimizations + + + + + + 1 + + + + <div> + <b>For debugging only.</b> + <br> + If you're not sure what these do, keep all of these enabled. + <br> + These settings only take effect when CPU Accuracy is "Debug Mode". + </div> + + + + + + + + Enable inline page tables + + + + <div style="white-space: nowrap">This optimization speeds up memory accesses by the guest program.</div> + <div style="white-space: nowrap">Enabling it inlines accesses to PageTable::pointers into emitted code.</div> + <div style="white-space: nowrap">Disabling this forces all memory accesses to go through the Memory::Read/Memory::Write functions.</div> + + + + + + + + Enable block linking + + + + <div>This optimization avoids dispatcher lookups by allowing emitted basic blocks to jump directly to other basic blocks if the destination PC is static.</div> + + + + + + + + Enable return stack buffer + + + + <div>This optimization avoids dispatcher lookups by keeping track potential return addresses of BL instructions. This approximates what happens with a return stack buffer on a real CPU.</div> + + + + + + + + Enable fast dispatcher + + + + <div>Enable a two-tiered dispatch system. A faster dispatcher written in assembly has a small MRU cache of jump destinations is used first. If that fails, dispatch falls back to the slower C++ dispatcher.</div> + + + + + + + + Enable context elimination + + + + <div>Enables an IR optimization that reduces unnecessary accesses to the CPU context structure.</div> + + + + + + + + Enable constant propagation + + + + <div>Enables IR optimizations that involve constant propagation.</div> + + + + + + + + Enable miscellaneous optimizations + + + + <div>Enables miscellaneous IR optimizations.</div> + + + + + + + + Enable misalignment check reduction + + + + <div style="white-space: nowrap">When enabled, a misalignment is only triggered when an access crosses a page boundary.</div> + <div style="white-space: nowrap">When disabled, a misalignment is triggered on all misaligned accesses.</div> + + + + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + CPU settings are available only when game is not running. + + + true + + + + + + + + diff --git a/src/yuzu/configuration/configure_dialog.cpp b/src/yuzu/configuration/configure_dialog.cpp index a0f49c282..a5afb354f 100644 --- a/src/yuzu/configuration/configure_dialog.cpp +++ b/src/yuzu/configuration/configure_dialog.cpp @@ -43,6 +43,7 @@ void ConfigureDialog::ApplyConfiguration() { ui->inputTab->ApplyConfiguration(); ui->hotkeysTab->ApplyConfiguration(registry); ui->cpuTab->ApplyConfiguration(); + ui->cpuDebugTab->ApplyConfiguration(); ui->graphicsTab->ApplyConfiguration(); ui->graphicsAdvancedTab->ApplyConfiguration(); ui->audioTab->ApplyConfiguration(); @@ -80,7 +81,7 @@ void ConfigureDialog::PopulateSelectionList() { const std::array>, 6> items{ {{tr("General"), {ui->generalTab, ui->webTab, ui->debugTab, ui->uiTab}}, {tr("System"), {ui->systemTab, ui->profileManagerTab, ui->serviceTab, ui->filesystemTab}}, - {tr("CPU"), {ui->cpuTab}}, + {tr("CPU"), {ui->cpuTab, ui->cpuDebugTab}}, {tr("Graphics"), {ui->graphicsTab, ui->graphicsAdvancedTab}}, {tr("Audio"), {ui->audioTab}}, {tr("Controls"), {ui->inputTab, ui->hotkeysTab}}}, @@ -110,6 +111,7 @@ void ConfigureDialog::UpdateVisibleTabs() { {ui->inputTab, tr("Input")}, {ui->hotkeysTab, tr("Hotkeys")}, {ui->cpuTab, tr("CPU")}, + {ui->cpuDebugTab, tr("Debug")}, {ui->graphicsTab, tr("Graphics")}, {ui->graphicsAdvancedTab, tr("Advanced")}, {ui->audioTab, tr("Audio")}, From 9ce6ea648f7cb51f5411d3e0753ef9a3439381c5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:36:27 -0400 Subject: [PATCH 43/55] gc_adapter: Silence sign conversion warnings --- src/input_common/gcadapter/gc_adapter.cpp | 8 ++++---- src/input_common/gcadapter/gc_adapter.h | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 6d9f4d9eb..9fa170711 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -33,7 +33,7 @@ Adapter::Adapter() { } } -GCPadStatus Adapter::GetPadStatus(int port, const std::array& adapter_payload) { +GCPadStatus Adapter::GetPadStatus(std::size_t port, const std::array& adapter_payload) { GCPadStatus pad = {}; bool get_origin = false; @@ -227,7 +227,7 @@ void Adapter::Setup() { } if (devices != nullptr) { - for (std::size_t index = 0; index < device_count; ++index) { + for (std::size_t index = 0; index < static_cast(device_count); ++index) { if (CheckDeviceAccess(devices[index])) { // GC Adapter found and accessible, registering it GetGCEndpoint(devices[index]); @@ -357,11 +357,11 @@ void Adapter::Reset() { } } -bool Adapter::DeviceConnected(int port) { +bool Adapter::DeviceConnected(std::size_t port) { return adapter_controllers_status[port] != ControllerTypes::None; } -void Adapter::ResetDeviceType(int port) { +void Adapter::ResetDeviceType(std::size_t port) { adapter_controllers_status[port] = ControllerTypes::None; } diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index b1c2a1958..250c2275a 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -104,7 +104,7 @@ public: const std::array& GetPadState() const; private: - GCPadStatus GetPadStatus(int port, const std::array& adapter_payload); + GCPadStatus GetPadStatus(std::size_t port, const std::array& adapter_payload); void PadToState(const GCPadStatus& pad, GCState& state); @@ -117,10 +117,10 @@ private: void StopScanThread(); /// Returns true if there is a device connected to port - bool DeviceConnected(int port); + bool DeviceConnected(std::size_t port); /// Resets status of device connected to port - void ResetDeviceType(int port); + void ResetDeviceType(std::size_t port); /// Returns true if we successfully gain access to GC Adapter bool CheckDeviceAccess(libusb_device* device); From 32b6fc40622a838d4785d5e2dbea4ee17447c362 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:38:16 -0400 Subject: [PATCH 44/55] gc_adapter: Remove deprecated usage of = in lambda captures It's deprecated in C++20 to use = to capture the this pointer. Instead, we can simply pass this as an argument to the thread constructor. --- src/input_common/gcadapter/gc_adapter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 9fa170711..70d382bcf 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -198,7 +198,7 @@ void Adapter::StartScanThread() { } detect_thread_running = true; - detect_thread = std::thread([=] { ScanThreadFunc(); }); + detect_thread = std::thread(&Adapter::ScanThreadFunc, this); } void Adapter::StopScanThread() { From a8ba6dc3c9f876835d706d90b27249e2984d526e Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:40:22 -0400 Subject: [PATCH 45/55] gc_poller: Silence sign conversion warnings --- src/input_common/gcadapter/gc_poller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index 385ce8430..ead1a1b0e 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -249,7 +249,7 @@ Common::ParamPackage GCAnalogFactory::GetNextInput() { const u8 axis = static_cast(pad.axis); if (analog_x_axis == -1) { analog_x_axis = axis; - controller_number = port; + controller_number = static_cast(port); } else if (analog_y_axis == -1 && analog_x_axis != axis && controller_number == port) { analog_y_axis = axis; } From 839c91cd14d65d0d62a946078aa62657530fd55a Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:41:32 -0400 Subject: [PATCH 46/55] gc_poller: Get rid of undefined behavior in Create() Ensures that the function always has returns in all control paths. --- src/input_common/gcadapter/gc_poller.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index ead1a1b0e..d9296c496 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "common/assert.h" #include "common/threadsafe_queue.h" #include "input_common/gcadapter/gc_adapter.h" #include "input_common/gcadapter/gc_poller.h" @@ -94,6 +95,9 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param return std::make_unique(port, axis, threshold, trigger_if_greater, adapter.get()); } + + UNREACHABLE(); + return nullptr; } Common::ParamPackage GCButtonFactory::GetNextInput() { From a1dddca4ab83cb63463134db11ed3585d8bd91f1 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:43:05 -0400 Subject: [PATCH 47/55] gc_poller: Mark GCButtonFactory::GetNextInput() as const This doesn't modify class instance state. --- src/input_common/gcadapter/gc_poller.cpp | 2 +- src/input_common/gcadapter/gc_poller.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index d9296c496..bddfa102f 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -100,7 +100,7 @@ std::unique_ptr GCButtonFactory::Create(const Common::Param return nullptr; } -Common::ParamPackage GCButtonFactory::GetNextInput() { +Common::ParamPackage GCButtonFactory::GetNextInput() const { Common::ParamPackage params; GCAdapter::GCPadStatus pad; auto& queue = adapter->GetPadQueue(); diff --git a/src/input_common/gcadapter/gc_poller.h b/src/input_common/gcadapter/gc_poller.h index e96af7d51..0527f328f 100644 --- a/src/input_common/gcadapter/gc_poller.h +++ b/src/input_common/gcadapter/gc_poller.h @@ -25,7 +25,7 @@ public: */ std::unique_ptr Create(const Common::ParamPackage& params) override; - Common::ParamPackage GetNextInput(); + Common::ParamPackage GetNextInput() const; /// For device input configuration/polling void BeginConfiguration(); From 8df93132cd0d0c3129e27a0e86edbfba7caa7196 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:49:40 -0400 Subject: [PATCH 48/55] udp: Silence a C++20 deprecation warning C++20 deprecates using the = lambda capture to implicitly capture the this pointer. Instead, we must specify it explicitly. --- src/input_common/udp/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input_common/udp/client.cpp b/src/input_common/udp/client.cpp index da5227058..e63c73c4f 100644 --- a/src/input_common/udp/client.cpp +++ b/src/input_common/udp/client.cpp @@ -234,7 +234,7 @@ CalibrationConfigurationJob::CalibrationConfigurationJob( std::function status_callback, std::function data_callback) { - std::thread([=] { + std::thread([=, this] { constexpr u16 CALIBRATION_THRESHOLD = 100; u16 min_x{UINT16_MAX}; From 539675b21a4e132a3826d5ee7385c8a980d558e5 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 15:53:29 -0400 Subject: [PATCH 49/55] CMakeLists: Disable concepts in boost asio --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 12c0a4284..174ed1c58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,8 @@ if (MSVC) # cubeb and boost still make use of deprecated result_of. add_definitions(-D_HAS_DEPRECATED_RESULT_OF) + # boost asio's concept usage doesn't play nicely with MSVC yet. + add_definitions(-DASIO_DISABLE_CONCEPTS) else() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) From b971b822756f14560d585bb7160ef864974783eb Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 17:17:48 -0400 Subject: [PATCH 50/55] CMakeLists: Correct boost asio disabling define name Previously the name of the define was missing the BOOST_ prefix. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 174ed1c58..99476c55f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -124,7 +124,7 @@ if (MSVC) # cubeb and boost still make use of deprecated result_of. add_definitions(-D_HAS_DEPRECATED_RESULT_OF) # boost asio's concept usage doesn't play nicely with MSVC yet. - add_definitions(-DASIO_DISABLE_CONCEPTS) + add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS) else() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) From 07632ad825086a3910ed1690dad30c602d67c213 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Sun, 12 Jul 2020 18:15:27 -0400 Subject: [PATCH 51/55] CMakeLists: Enable usage of C++20 on Linux This also fixes building on Linux with C++20, so we can enable it across the board for all OSes that we officially support. --- CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99476c55f..a5357335f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -118,15 +118,15 @@ message(STATUS "Target architecture: ${ARCHITECTURE}") # Configure C++ standard # =========================== +# boost asio's concept usage doesn't play nicely with some compilers yet. +add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS) if (MSVC) add_compile_options(/std:c++latest) # cubeb and boost still make use of deprecated result_of. add_definitions(-D_HAS_DEPRECATED_RESULT_OF) - # boost asio's concept usage doesn't play nicely with MSVC yet. - add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS) else() - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) endif() From 883fab2fff5ff9bdad38eee4e55bacc520ce0cc9 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 13 Jul 2020 18:48:19 +0000 Subject: [PATCH 52/55] input_common: make libusb private to gc_adapter --- src/input_common/CMakeLists.txt | 4 ++-- src/input_common/gcadapter/gc_adapter.cpp | 1 + src/input_common/gcadapter/gc_adapter.h | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/input_common/CMakeLists.txt b/src/input_common/CMakeLists.txt index 1d7e19a66..317c25bad 100644 --- a/src/input_common/CMakeLists.txt +++ b/src/input_common/CMakeLists.txt @@ -30,8 +30,8 @@ if(SDL2_FOUND) target_compile_definitions(input_common PRIVATE HAVE_SDL2) endif() -target_include_directories(input_common SYSTEM PUBLIC ${LIBUSB_INCLUDE_DIR}) -target_link_libraries(input_common PUBLIC ${LIBUSB_LIBRARIES}) +target_include_directories(input_common SYSTEM PRIVATE ${LIBUSB_INCLUDE_DIR}) +target_link_libraries(input_common PRIVATE ${LIBUSB_LIBRARIES}) create_target_directory_groups(input_common) target_link_libraries(input_common PUBLIC core PRIVATE common Boost::boost) diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index 6d9f4d9eb..c031fc22a 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "common/logging/log.h" #include "input_common/gcadapter/gc_adapter.h" diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index b1c2a1958..1337c260e 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -8,10 +8,13 @@ #include #include #include -#include #include "common/common_types.h" #include "common/threadsafe_queue.h" +struct libusb_context; +struct libusb_device; +struct libusb_device_handle; + namespace GCAdapter { enum { From b284c433850053dca46d2e2381b16b17d38cd048 Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 14 Jul 2020 01:46:54 +0000 Subject: [PATCH 53/55] input_common: drop unused libusb.h include Remnant of an early implementation. --- src/input_common/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index fd0af1019..b9d5d0ec3 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -4,7 +4,6 @@ #include #include -#include #include "common/param_package.h" #include "input_common/analog_from_button.h" #include "input_common/gcadapter/gc_adapter.h" From e02687ff47a7004aeb87bae8bf6ee2438dbd9455 Mon Sep 17 00:00:00 2001 From: lat9nq Date: Tue, 14 Jul 2020 00:49:17 -0400 Subject: [PATCH 54/55] configure_general: Explicitly guard use_multi_core when applying settings This is likely an oversight during a rebase. Guards use_multi_core to be only set when the global value is in use. It should not make a difference given the current code base, but makes the code sensible. --- src/yuzu/configuration/configure_general.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/yuzu/configuration/configure_general.cpp b/src/yuzu/configuration/configure_general.cpp index 1fb62d1cf..20316c9cc 100644 --- a/src/yuzu/configuration/configure_general.cpp +++ b/src/yuzu/configuration/configure_general.cpp @@ -65,6 +65,8 @@ void ConfigureGeneral::ApplyConfiguration() { Settings::values.use_frame_limit.SetValue(ui->toggle_frame_limit->checkState() == Qt::Checked); Settings::values.frame_limit.SetValue(ui->frame_limit->value()); + } + if (Settings::values.use_multi_core.UsingGlobal()) { Settings::values.use_multi_core.SetValue(ui->use_multi_core->isChecked()); } } else { From ab65de2f96984415cbeb3fee392b930c61f0d8b4 Mon Sep 17 00:00:00 2001 From: Ameer Date: Tue, 14 Jul 2020 11:23:10 -0400 Subject: [PATCH 55/55] Fix crash if gc configured but adapter not connected --- src/input_common/gcadapter/gc_adapter.h | 6 ++--- src/input_common/gcadapter/gc_poller.cpp | 34 +++++++++++++++--------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/input_common/gcadapter/gc_adapter.h b/src/input_common/gcadapter/gc_adapter.h index 120ce4c02..e2cdd6255 100644 --- a/src/input_common/gcadapter/gc_adapter.h +++ b/src/input_common/gcadapter/gc_adapter.h @@ -100,6 +100,9 @@ public: void BeginConfiguration(); void EndConfiguration(); + /// Returns true if there is a device connected to port + bool DeviceConnected(std::size_t port); + std::array, 4>& GetPadQueue(); const std::array, 4>& GetPadQueue() const; @@ -119,9 +122,6 @@ private: /// Stop scanning for the adapter void StopScanThread(); - /// Returns true if there is a device connected to port - bool DeviceConnected(std::size_t port); - /// Resets status of device connected to port void ResetDeviceType(std::size_t port); diff --git a/src/input_common/gcadapter/gc_poller.cpp b/src/input_common/gcadapter/gc_poller.cpp index bddfa102f..b20419ec3 100644 --- a/src/input_common/gcadapter/gc_poller.cpp +++ b/src/input_common/gcadapter/gc_poller.cpp @@ -21,7 +21,10 @@ public: ~GCButton() override; bool GetStatus() const override { - return gcadapter->GetPadState()[port].buttons.at(button); + if (gcadapter->DeviceConnected(port)) { + return gcadapter->GetPadState()[port].buttons.at(button); + } + return false; } private: @@ -44,13 +47,17 @@ public: } bool GetStatus() const override { - const float axis_value = (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; - if (trigger_if_greater) { - // TODO: Might be worthwile to set a slider for the trigger threshold. It is currently - // always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick - return axis_value > threshold; + if (gcadapter->DeviceConnected(port)) { + const float axis_value = + (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 128.0f; + if (trigger_if_greater) { + // TODO: Might be worthwile to set a slider for the trigger threshold. It is + // currently always set to 0.5 in configure_input_player.cpp ZL/ZR HandleClick + return axis_value > threshold; + } + return axis_value < -threshold; } - return axis_value < -threshold; + return false; } private: @@ -151,11 +158,14 @@ public: : port(port_), axis_x(axis_x_), axis_y(axis_y_), deadzone(deadzone_), gcadapter(adapter) {} float GetAxis(int axis) const { - std::lock_guard lock{mutex}; - // division is not by a perfect 128 to account for some variance in center location - // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range - // [20-230] - return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; + if (gcadapter->DeviceConnected(port)) { + std::lock_guard lock{mutex}; + // division is not by a perfect 128 to account for some variance in center location + // e.g. my device idled at 131 in X, 120 in Y, and full range of motion was in range + // [20-230] + return (gcadapter->GetPadState()[port].axes.at(axis) - 128.0f) / 95.0f; + } + return 0.0f; } std::pair GetAnalog(int axis_x, int axis_y) const {