From e380ad0353570768e15f10a6729d6bf74a7ba510 Mon Sep 17 00:00:00 2001 From: FileEX Date: Wed, 12 Mar 2025 19:10:15 +0100 Subject: [PATCH 1/3] CPU affinity --- Client/core/CClientVariables.cpp | 1 + Client/core/CCore.cpp | 11 +++++++++ Client/core/CSettings.cpp | 38 ++++++++++++++++++++++++++++++++ Client/core/CSettings.h | 1 + 4 files changed, 51 insertions(+) diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index 85dee800fa4..f3478cfb944 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -357,6 +357,7 @@ void CClientVariables::LoadDefaults() DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function) + DEFAULT("process_cpu_affinity", true); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games if (!Exists("locale")) { diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index bafebb15253..72bf0d2e992 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -1795,6 +1795,17 @@ void CCore::ApplyCoreInitSettings() SetApplicationSettingInt("reset-settings-revision", 21486); } + + // Set process settings + HANDLE currProc = GetCurrentProcess(); + + // Process priority + int PriorityClassList[] = {NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS}; + SetPriorityClass(currProc, PriorityClassList[CVARS_GET_VALUE("process_priority") % 3]); + + // Process CPU affinity + if (CVARS_GET_VALUE("process_cpu_affinity")) + SetProcessAffinityMask(currProc, 1 << 0); } // diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index d9d7713e3c6..b4a33ef7d4e 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -1207,6 +1207,12 @@ void CSettings::CreateGUI() m_pPhotoSavingCheckbox->AutoSize(NULL, 20.0f); vecTemp.fY += fLineHeight; + // Process affinity + m_pProcessAffinityCheckbox = reinterpret_cast(pManager->CreateCheckBox(pTabAdvanced, _("Set CPU 0 affinity to improve game performance"), true)); + m_pProcessAffinityCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY)); + m_pProcessAffinityCheckbox->AutoSize(nullptr, 20.0f); + vecTemp.fY += fLineHeight; + // Auto updater section label m_pAdvancedUpdaterLabel = reinterpret_cast(pManager->CreateLabel(pTabAdvanced, _("Auto updater"))); m_pAdvancedUpdaterLabel->SetPosition(CVector2D(vecTemp.fX - 10.0f, vecTemp.fY)); @@ -3228,6 +3234,22 @@ void CSettings::LoadData() CVARS_GET("photosaving", bVar); m_pPhotoSavingCheckbox->SetSelected(bVar); + // Process CPU Affinity + CVARS_GET("process_cpu_affinity", bVar); + m_pProcessAffinityCheckbox->SetSelected(bVar); + + DWORD_PTR affinityMask = 0; + if (bVar) + affinityMask = 1 << 0; // CPU 0 only + else + { + SYSTEM_INFO sysInfo; + GetSystemInfo(&sysInfo); + + affinityMask = (1 << sysInfo.dwNumberOfProcessors) - 1; // All cores (default) + } + SetProcessAffinityMask(GetCurrentProcess(), affinityMask); + // Update build type CVARS_GET("update_build_type", iVar); if (iVar == 0 || iVar == 1) @@ -3624,6 +3646,22 @@ void CSettings::SaveData() CVARS_SET("photosaving", photoSaving); CScreenShot::SetPhotoSavingInsideDocuments(photoSaving); + // Process CPU Affinity + bool cpuAffinity = m_pProcessAffinityCheckbox->GetSelected(); + CVARS_SET("process_cpu_affinity", cpuAffinity); + + DWORD_PTR affinityMask = 0; + if (cpuAffinity) + affinityMask = 1 << 0; // CPU 0 only + else + { + SYSTEM_INFO sysInfo; + GetSystemInfo(&sysInfo); + + affinityMask = (1 << sysInfo.dwNumberOfProcessors) - 1; // All cores (default) + } + SetProcessAffinityMask(GetCurrentProcess(), affinityMask); + // Debug setting if (CGUIListItem* pSelected = m_pDebugSettingCombo->GetSelectedItem()) { diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index 91a14ca40eb..26b5b6342e7 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -216,6 +216,7 @@ class CSettings CGUICheckBox* m_pWin8ColorCheckBox; CGUICheckBox* m_pWin8MouseCheckBox; CGUICheckBox* m_pPhotoSavingCheckbox; + CGUICheckBox* m_pProcessAffinityCheckbox; CGUILabel* m_pUpdateBuildTypeLabel; CGUIComboBox* m_pUpdateBuildTypeCombo; CGUILabel* m_pUpdateAutoInstallLabel; From da607edeadb3895d0fdb597375ab9421813ad6cf Mon Sep 17 00:00:00 2001 From: FileEX Date: Sun, 16 Mar 2025 14:35:00 +0100 Subject: [PATCH 2/3] Disable by default --- Client/core/CClientVariables.cpp | 2 +- Client/core/CSettings.cpp | 56 ++++++++++++++++++++++++++++---- Client/core/CSettings.h | 1 + 3 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index f3478cfb944..0b77fbdaf5b 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -357,7 +357,7 @@ void CClientVariables::LoadDefaults() DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function) - DEFAULT("process_cpu_affinity", true); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games + DEFAULT("process_cpu_affinity", false); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games if (!Exists("locale")) { diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index b4a33ef7d4e..c1d988d4152 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -405,6 +405,12 @@ void CSettings::CreateGUI() m_pCheckBoxAllowDiscordRPC->GetPosition(vecTemp, false); m_pCheckBoxAllowDiscordRPC->AutoSize(NULL, 20.0f); + // Enable camera photos getting saved to documents folder + m_pPhotoSavingCheckbox = reinterpret_cast(pManager->CreateCheckBox(pTabMultiplayer, _("Save photos taken by camera weapon to GTA San Andreas User Files folder"), true)); + m_pPhotoSavingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f)); + m_pPhotoSavingCheckbox->GetPosition(vecTemp, false); + m_pPhotoSavingCheckbox->AutoSize(NULL, 20.0f); + m_pCheckBoxCustomizedSAFiles = reinterpret_cast(pManager->CreateCheckBox(pTabMultiplayer, _("Use customized GTA:SA files"), true)); m_pCheckBoxCustomizedSAFiles->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY + 20.0f)); m_pCheckBoxCustomizedSAFiles->GetPosition(vecTemp, false); @@ -1201,12 +1207,6 @@ void CSettings::CreateGUI() m_pCachePathValue->AutoSize(); vecTemp.fY += fLineHeight; - // Enable camera photos getting saved to documents folder - m_pPhotoSavingCheckbox = reinterpret_cast(pManager->CreateCheckBox(pTabAdvanced, _("Save photos taken by camera weapon to GTA San Andreas User Files folder"), true)); - m_pPhotoSavingCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY)); - m_pPhotoSavingCheckbox->AutoSize(NULL, 20.0f); - vecTemp.fY += fLineHeight; - // Process affinity m_pProcessAffinityCheckbox = reinterpret_cast(pManager->CreateCheckBox(pTabAdvanced, _("Set CPU 0 affinity to improve game performance"), true)); m_pProcessAffinityCheckbox->SetPosition(CVector2D(vecTemp.fX, vecTemp.fY)); @@ -1312,6 +1312,7 @@ void CSettings::CreateGUI() m_pButtonBrowserWhitelistRemove->SetClickHandler(GUI_CALLBACK(&CSettings::OnBrowserWhitelistRemove, this)); m_pEditBrowserWhitelistAdd->SetActivateHandler(GUI_CALLBACK(&CSettings::OnBrowserWhitelistDomainAddFocused, this)); m_pEditBrowserWhitelistAdd->SetDeactivateHandler(GUI_CALLBACK(&CSettings::OnBrowserWhitelistDomainAddDefocused, this)); + m_pProcessAffinityCheckbox->SetClickHandler(GUI_CALLBACK(&CSettings::OnAffinityClick, this)); // Set up the events for advanced description m_pPriorityLabel->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this)); @@ -1380,6 +1381,9 @@ void CSettings::CreateGUI() m_pUpdateAutoInstallCombo->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this)); m_pUpdateAutoInstallCombo->SetMouseLeaveHandler(GUI_CALLBACK(&CSettings::OnHideAdvancedSettingDescription, this)); + m_pProcessAffinityCheckbox->SetMouseEnterHandler(GUI_CALLBACK(&CSettings::OnShowAdvancedSettingDescription, this)); + m_pProcessAffinityCheckbox->SetMouseLeaveHandler(GUI_CALLBACK(&CSettings::OnHideAdvancedSettingDescription, this)); + // Load Chat presets LoadChatPresets(); @@ -4749,6 +4753,44 @@ static void DPIAwareQuestionCallBack(void* userdata, unsigned int uiButton) } } +static void CPUAffinityQuestionCallBack(void* userdata, unsigned int button) +{ + CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow()->Reset(); + + if (button == 0) + { + auto const checkBox = reinterpret_cast(userdata); + checkBox->SetSelected(false); + } +} + +bool CSettings::OnAffinityClick(CGUIElement* pElement) +{ + static bool shownWarning = false; + + if (m_pProcessAffinityCheckbox->GetSelected() && !shownWarning) + { + shownWarning = true; + + std::string message = std::string( + _("Enabling this setting may improve game performance, but on some processors, it may worsen it.\n" + "We have observed issues with AMD Ryzen processors featuring 3D V-Cache.\n" + "The exact list of affected processors is unknown.\n" + "\nAre you sure you want to enable this option?")); + + CQuestionBox* pQuestionBox = CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow(); + pQuestionBox->Reset(); + pQuestionBox->SetTitle(_("EXPERIMENTAL FEATURE")); + pQuestionBox->SetMessage(message); + pQuestionBox->SetButton(0, _("No")); + pQuestionBox->SetButton(1, _("Yes")); + pQuestionBox->SetCallback(CPUAffinityQuestionCallBack, m_pProcessAffinityCheckbox); + pQuestionBox->Show(); + } + + return true; +} + bool CSettings::OnBrowserBlacklistAdd(CGUIElement* pElement) { SString strDomain = m_pEditBrowserBlacklistAdd->GetText(); @@ -4912,6 +4954,8 @@ bool CSettings::OnShowAdvancedSettingDescription(CGUIElement* pElement) strText = std::string(_("16-bit color:")) + " " + std::string(_("Enable 16 bit color modes - Requires MTA restart")); else if (pCheckBox && pCheckBox == m_pWin8MouseCheckBox) strText = std::string(_("Mouse fix:")) + " " + std::string(_("Mouse movement fix - May need PC restart")); + else if (pCheckBox && pCheckBox == m_pProcessAffinityCheckbox) + strText = std::string(_("CPU affinity:")) + " " + std::string(_("Experimental feature - It may improve performance or worsen it.")); if (strText != "") m_pAdvancedSettingDescriptionLabel->SetText(strText.c_str()); diff --git a/Client/core/CSettings.h b/Client/core/CSettings.h index 26b5b6342e7..f0731a18fe2 100644 --- a/Client/core/CSettings.h +++ b/Client/core/CSettings.h @@ -407,6 +407,7 @@ class CSettings bool OnShowAdvancedSettingDescription(CGUIElement* pElement); bool OnHideAdvancedSettingDescription(CGUIElement* pElement); bool OnTabChanged(CGUIElement* pElement); + bool OnAffinityClick(CGUIElement* pElement); void ReloadBrowserLists(); private: From 2d1f8229de5778011fc22e98d057f3a20db10bcd Mon Sep 17 00:00:00 2001 From: FileEX Date: Fri, 4 Apr 2025 20:38:16 +0200 Subject: [PATCH 3/3] Small changes --- Client/core/CClientVariables.cpp | 2 +- Client/core/CCore.cpp | 24 ++++++++++-------------- Client/core/CSettings.cpp | 20 +++++++------------- 3 files changed, 18 insertions(+), 28 deletions(-) diff --git a/Client/core/CClientVariables.cpp b/Client/core/CClientVariables.cpp index 0b77fbdaf5b..f3478cfb944 100644 --- a/Client/core/CClientVariables.cpp +++ b/Client/core/CClientVariables.cpp @@ -357,7 +357,7 @@ void CClientVariables::LoadDefaults() DEFAULT("discord_rpc_share_data", false); // Consistent Rich Presence data sharing DEFAULT("discord_rpc_share_data_firsttime", false); // Display the user data sharing consent dialog box - for the first time DEFAULT("browser_enable_gpu", true); // Enable GPU in CEF? (allows stuff like WebGL to function) - DEFAULT("process_cpu_affinity", false); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games + DEFAULT("process_cpu_affinity", true); // Set CPU 0 affinity to improve game performance and fix the known issue in single-threaded games if (!Exists("locale")) { diff --git a/Client/core/CCore.cpp b/Client/core/CCore.cpp index 920c44d9cac..5e4b17c07a9 100644 --- a/Client/core/CCore.cpp +++ b/Client/core/CCore.cpp @@ -1770,7 +1770,7 @@ void CCore::OnPostColorFilterRender() void CCore::ApplyCoreInitSettings() { #if (_WIN32_WINNT >= _WIN32_WINNT_LONGHORN) - const auto aware = CVARS_GET_VALUE("process_dpi_aware"); + bool aware = CVARS_GET_VALUE("process_dpi_aware"); // The minimum supported client for the function below is Windows Vista (Longhorn). // For more information, refer to the Microsoft Learn article: @@ -1779,13 +1779,13 @@ void CCore::ApplyCoreInitSettings() SetProcessDPIAware(); #endif - const auto revision = GetApplicationSettingInt("reset-settings-revision"); + int revision = GetApplicationSettingInt("reset-settings-revision"); // Users with the default skin will be switched to the 2023 version by replacing "Default" with "Default 2023". // The "Default 2023" GUI skin was introduced in commit 2d9e03324b07e355031ecb3263477477f1a91399. if (revision < 21486) { - const auto skin = CVARS_GET_VALUE("current_skin"); + auto skin = CVARS_GET_VALUE("current_skin"); if (skin == "Default") CVARS_SET("current_skin", "Default 2023"); @@ -1793,25 +1793,21 @@ void CCore::ApplyCoreInitSettings() SetApplicationSettingInt("reset-settings-revision", 21486); } - const auto process = GetCurrentProcess(); - const int priorities[] = {NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS}; - const auto priority = CVARS_GET_VALUE("process_priority") % 3; + HANDLE process = GetCurrentProcess(); + const int priorities[] = {NORMAL_PRIORITY_CLASS, ABOVE_NORMAL_PRIORITY_CLASS, HIGH_PRIORITY_CLASS}; + int priority = CVARS_GET_VALUE("process_priority") % 3; SetPriorityClass(process, priorities[priority]); - const auto affinity = CVARS_GET_VALUE("process_cpu_affinity"); - + bool affinity = CVARS_GET_VALUE("process_cpu_affinity"); if (!affinity) return; DWORD_PTR mask; DWORD_PTR sys; - const auto result = GetProcessAffinityMask(process, &mask, &sys); - - if (!result) - return; - - SetProcessAffinityMask(process, mask & ~1); + BOOL result = GetProcessAffinityMask(process, &mask, &sys); + if (result) + SetProcessAffinityMask(process, mask & ~1); } // diff --git a/Client/core/CSettings.cpp b/Client/core/CSettings.cpp index bab74ba4312..e2351fdaa70 100644 --- a/Client/core/CSettings.cpp +++ b/Client/core/CSettings.cpp @@ -3245,13 +3245,11 @@ void CSettings::LoadData() DWORD_PTR mask; DWORD_PTR sys; - const auto process = GetCurrentProcess(); - const auto result = GetProcessAffinityMask(process, &mask, &sys); + HANDLE process = GetCurrentProcess(); + BOOL result = GetProcessAffinityMask(process, &mask, &sys); if (bVar && result) - { SetProcessAffinityMask(process, mask & ~1); - } else { SYSTEM_INFO info; @@ -3657,19 +3655,17 @@ void CSettings::SaveData() CScreenShot::SetPhotoSavingInsideDocuments(photoSaving); // Process CPU Affinity - const auto affinity = m_pProcessAffinityCheckbox->GetSelected(); + bool affinity = m_pProcessAffinityCheckbox->GetSelected(); CVARS_SET("process_cpu_affinity", affinity); DWORD_PTR mask; DWORD_PTR sys; - const auto process = GetCurrentProcess(); - const auto result = GetProcessAffinityMask(process, &mask, &sys); + HANDLE process = GetCurrentProcess(); + BOOL result = GetProcessAffinityMask(process, &mask, &sys); if (affinity && result) - { SetProcessAffinityMask(process, mask & ~1); - } else { SYSTEM_INFO info; @@ -4785,9 +4781,7 @@ bool CSettings::OnAffinityClick(CGUIElement* pElement) shownWarning = true; std::string message = std::string( - _("Enabling this setting may improve game performance, but on some processors, it may worsen it.\n" - "We have observed issues with AMD Ryzen processors featuring 3D V-Cache.\n" - "The exact list of affected processors is unknown.\n" + _("This option should only be changed if you experience performance issues.\n" "\nAre you sure you want to enable this option?")); CQuestionBox* pQuestionBox = CCore::GetSingleton().GetLocalGUI()->GetMainMenu()->GetQuestionWindow(); @@ -4967,7 +4961,7 @@ bool CSettings::OnShowAdvancedSettingDescription(CGUIElement* pElement) else if (pCheckBox && pCheckBox == m_pWin8MouseCheckBox) strText = std::string(_("Mouse fix:")) + " " + std::string(_("Mouse movement fix - May need PC restart")); else if (pCheckBox && pCheckBox == m_pProcessAffinityCheckbox) - strText = std::string(_("CPU affinity:")) + " " + std::string(_("Experimental feature - It may improve performance or worsen it.")); + strText = std::string(_("CPU affinity:")) + " " + std::string(_("Experimental feature - Change only if you experience performance issues")); if (strText != "") m_pAdvancedSettingDescriptionLabel->SetText(strText.c_str());