From 7da57c478c3c3c392e072f03ab52ad3fae0db91d Mon Sep 17 00:00:00 2001 From: Stenzek Date: Tue, 26 Dec 2023 21:25:10 +1000 Subject: [PATCH] Common: Rename General to HostSys Actually fits what it's doing. --- common/Assertions.cpp | 4 +-- common/BitUtils.h | 14 ++++++++ common/CMakeLists.txt | 5 ++- common/Darwin/DarwinMisc.cpp | 2 +- common/General.cpp | 26 -------------- common/{Misc.cpp => HostSys.cpp} | 2 +- common/{General.h => HostSys.h} | 43 +++++++---------------- common/Linux/LnxHostSys.cpp | 2 +- common/Linux/LnxMisc.cpp | 2 +- common/Semaphore.cpp | 1 + common/Threading.h | 1 - common/Windows/WinHostSys.cpp | 2 +- common/Windows/WinMisc.cpp | 3 +- common/common.vcxproj | 5 ++- common/common.vcxproj.filters | 7 ++-- pcsx2/Achievements.cpp | 1 - pcsx2/CDVD/CDVD.cpp | 1 + pcsx2/Config.h | 2 +- pcsx2/GS/GSJobQueue.h | 1 - pcsx2/GS/GSPerfMon.cpp | 2 ++ pcsx2/GS/Renderers/Common/GSFunctionMap.h | 2 ++ pcsx2/GS/Renderers/DX12/GSDevice12.cpp | 1 + pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm | 1 + pcsx2/GS/Renderers/SW/GSRasterizer.cpp | 1 - pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp | 1 + pcsx2/GameDatabase.h | 1 + pcsx2/IPU/IPU_MultiISA.cpp | 2 -- pcsx2/Input/InputManager.cpp | 1 + pcsx2/SIO/Memcard/MemoryCardProtocol.cpp | 2 ++ pcsx2/SIO/Sio.cpp | 2 ++ pcsx2/SPU2/spu2freeze.cpp | 2 ++ pcsx2/vtlb.cpp | 2 +- pcsx2/vtlb.h | 4 +-- 33 files changed, 61 insertions(+), 87 deletions(-) delete mode 100644 common/General.cpp rename common/{Misc.cpp => HostSys.cpp} (99%) rename common/{General.h => HostSys.h} (78%) diff --git a/common/Assertions.cpp b/common/Assertions.cpp index 7799f0ad5c3a9..b6115ca9c9efe 100644 --- a/common/Assertions.cpp +++ b/common/Assertions.cpp @@ -1,10 +1,10 @@ // SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team // SPDX-License-Identifier: LGPL-3.0+ -#include "Threading.h" -#include "General.h" #include "Assertions.h" #include "CrashHandler.h" +#include "HostSys.h" +#include "Threading.h" #include #include "fmt/core.h" diff --git a/common/BitUtils.h b/common/BitUtils.h index 129d5a2ba1149..74265477d33f6 100644 --- a/common/BitUtils.h +++ b/common/BitUtils.h @@ -6,6 +6,7 @@ #include "common/Pcsx2Defs.h" #include +#include #ifdef _MSC_VER @@ -84,3 +85,16 @@ namespace Common return std::countl_zero(static_cast(n)); } } // namespace Common + +template +[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset) +{ + T value; + std::memcpy(&value, buffer + offset, sizeof(value)); + return value; +} + +[[maybe_unused]] __fi static u8 GetBufferU8(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } +[[maybe_unused]] __fi static u16 GetBufferU16(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } +[[maybe_unused]] __fi static u32 GetBufferU32(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } +[[maybe_unused]] __fi static u64 GetBufferU64(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 7928cc22fa04f..a096a8d1c82ea 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -17,11 +17,10 @@ target_sources(common PRIVATE Error.cpp FastJmp.cpp FileSystem.cpp - General.cpp + HostSys.cpp Image.cpp HTTPDownloader.cpp MemorySettingsInterface.cpp - Misc.cpp MD5Digest.cpp PrecompiledHeader.cpp Perf.cpp @@ -72,8 +71,8 @@ target_sources(common PRIVATE FPControl.h FastJmp.h FileSystem.h - General.h HashCombine.h + HostSys.h HeterogeneousContainers.h Image.h LRUCache.h diff --git a/common/Darwin/DarwinMisc.cpp b/common/Darwin/DarwinMisc.cpp index df596f57f5fd2..8663ee4f1e80d 100644 --- a/common/Darwin/DarwinMisc.cpp +++ b/common/Darwin/DarwinMisc.cpp @@ -16,7 +16,7 @@ #include "common/Pcsx2Types.h" #include "common/Console.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/Threading.h" #include "common/WindowInfo.h" diff --git a/common/General.cpp b/common/General.cpp deleted file mode 100644 index bd1f006a9cdad..0000000000000 --- a/common/General.cpp +++ /dev/null @@ -1,26 +0,0 @@ -// SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team -// SPDX-License-Identifier: LGPL-3.0+ - -#include "General.h" - -// -------------------------------------------------------------------------------------- -// PageProtectionMode (implementations) -// -------------------------------------------------------------------------------------- -std::string PageProtectionMode::ToString() const -{ - std::string modeStr; - - if (m_read) - modeStr += "Read"; - if (m_write) - modeStr += "Write"; - if (m_exec) - modeStr += "Exec"; - - if (modeStr.empty()) - return "NoAccess"; - if (modeStr.length() <= 5) - modeStr += "Only"; - - return modeStr; -} diff --git a/common/Misc.cpp b/common/HostSys.cpp similarity index 99% rename from common/Misc.cpp rename to common/HostSys.cpp index ae8c3f9baf412..ee043949a4023 100644 --- a/common/Misc.cpp +++ b/common/HostSys.cpp @@ -1,7 +1,7 @@ // SPDX-FileCopyrightText: 2002-2023 PCSX2 Dev Team // SPDX-License-Identifier: LGPL-3.0+ -#include "General.h" +#include "HostSys.h" #include "Console.h" #include "VectorIntrin.h" diff --git a/common/General.h b/common/HostSys.h similarity index 78% rename from common/General.h rename to common/HostSys.h index 1a282a9697db0..5ee267df4210f 100644 --- a/common/General.h +++ b/common/HostSys.h @@ -9,20 +9,6 @@ #include #include #include -#include - -template -[[maybe_unused]] __fi static T GetBufferT(u8* buffer, u32 offset) -{ - T value; - std::memcpy(&value, buffer + offset, sizeof(value)); - return value; -} - -[[maybe_unused]] __fi static u8 GetBufferU8(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } -[[maybe_unused]] __fi static u16 GetBufferU16(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } -[[maybe_unused]] __fi static u32 GetBufferU32(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } -[[maybe_unused]] __fi static u64 GetBufferU64(u8* buffer, u32 offset) { return GetBufferT(buffer, offset); } // -------------------------------------------------------------------------------------- // PageProtectionMode @@ -30,46 +16,41 @@ template class PageProtectionMode { protected: - bool m_read; - bool m_write; - bool m_exec; + bool m_read = false; + bool m_write = false; + bool m_exec = false; public: - PageProtectionMode() - { - All(false); - } + __fi constexpr PageProtectionMode() = default; - PageProtectionMode& Read(bool allow = true) + __fi constexpr PageProtectionMode& Read(bool allow = true) { m_read = allow; return *this; } - PageProtectionMode& Write(bool allow = true) + __fi constexpr PageProtectionMode& Write(bool allow = true) { m_write = allow; return *this; } - PageProtectionMode& Execute(bool allow = true) + __fi constexpr PageProtectionMode& Execute(bool allow = true) { m_exec = allow; return *this; } - PageProtectionMode& All(bool allow = true) + __fi constexpr PageProtectionMode& All(bool allow = true) { m_read = m_write = m_exec = allow; return *this; } - bool CanRead() const { return m_read; } - bool CanWrite() const { return m_write; } - bool CanExecute() const { return m_exec && m_read; } - bool IsNone() const { return !m_read && !m_write; } - - std::string ToString() const; + __fi constexpr bool CanRead() const { return m_read; } + __fi constexpr bool CanWrite() const { return m_write; } + __fi constexpr bool CanExecute() const { return m_exec && m_read; } + __fi constexpr bool IsNone() const { return !m_read && !m_write; } }; static __fi PageProtectionMode PageAccess_None() diff --git a/common/Linux/LnxHostSys.cpp b/common/Linux/LnxHostSys.cpp index d3ad89c0b3345..d8f012a4e3f26 100644 --- a/common/Linux/LnxHostSys.cpp +++ b/common/Linux/LnxHostSys.cpp @@ -16,7 +16,7 @@ #include "common/BitUtils.h" #include "common/Assertions.h" #include "common/Console.h" -#include "common/General.h" +#include "common/HostSys.h" // Apple uses the MAP_ANON define instead of MAP_ANONYMOUS, but they mean // the same thing. diff --git a/common/Linux/LnxMisc.cpp b/common/Linux/LnxMisc.cpp index 6ffd0785668e1..2919e0edfd498 100644 --- a/common/Linux/LnxMisc.cpp +++ b/common/Linux/LnxMisc.cpp @@ -4,7 +4,7 @@ #if !defined(_WIN32) && !defined(__APPLE__) #include "common/Pcsx2Types.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/ScopedGuard.h" #include "common/StringUtil.h" #include "common/Threading.h" diff --git a/common/Semaphore.cpp b/common/Semaphore.cpp index e44c17ed40b0b..63f53dc25f785 100644 --- a/common/Semaphore.cpp +++ b/common/Semaphore.cpp @@ -3,6 +3,7 @@ #include "common/Threading.h" #include "common/Assertions.h" +#include "common/HostSys.h" #ifdef _WIN32 #include "common/RedtapeWindows.h" diff --git a/common/Threading.h b/common/Threading.h index 3a4f42ad23297..4e46f9ba2bcbd 100644 --- a/common/Threading.h +++ b/common/Threading.h @@ -4,7 +4,6 @@ #pragma once #include "common/Pcsx2Defs.h" -#include "common/General.h" #if defined(__APPLE__) #include diff --git a/common/Windows/WinHostSys.cpp b/common/Windows/WinHostSys.cpp index 59d2d9b091bac..ff7b462f002b6 100644 --- a/common/Windows/WinHostSys.cpp +++ b/common/Windows/WinHostSys.cpp @@ -6,7 +6,7 @@ #include "common/BitUtils.h" #include "common/RedtapeWindows.h" #include "common/Console.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/StringUtil.h" #include "common/AlignedMalloc.h" #include "common/Assertions.h" diff --git a/common/Windows/WinMisc.cpp b/common/Windows/WinMisc.cpp index e328db0dc8062..3e34a8760c54a 100644 --- a/common/Windows/WinMisc.cpp +++ b/common/Windows/WinMisc.cpp @@ -3,11 +3,10 @@ #if defined(_WIN32) -#include "common/Pcsx2Defs.h" +#include "common/HostSys.h" #include "common/RedtapeWindows.h" #include "common/StringUtil.h" #include "common/Threading.h" -#include "common/General.h" #include "common/WindowInfo.h" #include "fmt/core.h" diff --git a/common/common.vcxproj b/common/common.vcxproj index 1353ed22ccd9d..30a2aca5a8158 100644 --- a/common/common.vcxproj +++ b/common/common.vcxproj @@ -55,7 +55,6 @@ true - @@ -84,7 +83,7 @@ - + @@ -135,7 +134,7 @@ - + diff --git a/common/common.vcxproj.filters b/common/common.vcxproj.filters index 416e15b660ac0..42869b1c19128 100644 --- a/common/common.vcxproj.filters +++ b/common/common.vcxproj.filters @@ -40,7 +40,7 @@ Source Files - + Source Files @@ -124,9 +124,6 @@ Source Files - - Source Files - Source Files @@ -159,7 +156,7 @@ Header Files - + Header Files diff --git a/pcsx2/Achievements.cpp b/pcsx2/Achievements.cpp index 38c8feb2deccd..e2c2bbda6f95a 100644 --- a/pcsx2/Achievements.cpp +++ b/pcsx2/Achievements.cpp @@ -22,7 +22,6 @@ #include "common/Console.h" #include "common/Error.h" #include "common/FileSystem.h" -#include "common/General.h" #include "common/HTTPDownloader.h" #include "common/MD5Digest.h" #include "common/Path.h" diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index e76b70607bc6d..f60e6693fff93 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -17,6 +17,7 @@ #include "IopDma.h" #include "VMManager.h" +#include "common/BitUtils.h" #include "common/Error.h" #include "common/FileSystem.h" #include "common/Path.h" diff --git a/pcsx2/Config.h b/pcsx2/Config.h index 602cc5537cb9f..b84fdb1c4d17f 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -3,7 +3,7 @@ #pragma once -#include "common/General.h" +#include "common/Pcsx2Defs.h" #include "common/FPControl.h" #include #include diff --git a/pcsx2/GS/GSJobQueue.h b/pcsx2/GS/GSJobQueue.h index 87940ac2dd272..d5984e8517ab8 100644 --- a/pcsx2/GS/GSJobQueue.h +++ b/pcsx2/GS/GSJobQueue.h @@ -6,7 +6,6 @@ #include "GS.h" #include "common/boost_spsc_queue.hpp" #include "common/Assertions.h" -#include "common/General.h" #include "common/Threading.h" #include #include diff --git a/pcsx2/GS/GSPerfMon.cpp b/pcsx2/GS/GSPerfMon.cpp index 0e0cbde1f8555..d5af3f9fb16de 100644 --- a/pcsx2/GS/GSPerfMon.cpp +++ b/pcsx2/GS/GSPerfMon.cpp @@ -4,6 +4,8 @@ #include "GSPerfMon.h" #include "GS.h" +#include + GSPerfMon g_perfmon; GSPerfMon::GSPerfMon() = default; diff --git a/pcsx2/GS/Renderers/Common/GSFunctionMap.h b/pcsx2/GS/Renderers/Common/GSFunctionMap.h index 54b87436499b9..a5fccce22ef0c 100644 --- a/pcsx2/GS/Renderers/Common/GSFunctionMap.h +++ b/pcsx2/GS/Renderers/Common/GSFunctionMap.h @@ -6,6 +6,8 @@ #include "GS/GSExtra.h" #include "GS/Renderers/SW/GSScanlineEnvironment.h" +#include "common/HostSys.h" + template class GSFunctionMap { diff --git a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp index 2b5bdc11a8ac6..012e95378b873 100644 --- a/pcsx2/GS/Renderers/DX12/GSDevice12.cpp +++ b/pcsx2/GS/Renderers/DX12/GSDevice12.cpp @@ -14,6 +14,7 @@ #include "common/Console.h" #include "common/BitUtils.h" +#include "common/HostSys.h" #include "common/ScopedGuard.h" #include "common/StringUtil.h" diff --git a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm index 5a120a971ad09..15c5211a966fc 100644 --- a/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm +++ b/pcsx2/GS/Renderers/Metal/GSDeviceMTL.mm @@ -8,6 +8,7 @@ #include "GS/GSPerfMon.h" #include "common/Console.h" +#include "common/HostSys.h" #include "imgui.h" diff --git a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp index 61b9c56d20b2e..61ab3e9af9c1d 100644 --- a/pcsx2/GS/Renderers/SW/GSRasterizer.cpp +++ b/pcsx2/GS/Renderers/SW/GSRasterizer.cpp @@ -11,7 +11,6 @@ #include "common/AlignedMalloc.h" #include "common/Console.h" -#include "common/General.h" #include "common/StringUtil.h" #define ENABLE_DRAW_STATS 0 diff --git a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp index 47912c388b444..7a70971b7627a 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSDeviceVK.cpp @@ -14,6 +14,7 @@ #include "common/Console.h" #include "common/BitUtils.h" +#include "common/HostSys.h" #include "common/Path.h" #include "common/ScopedGuard.h" diff --git a/pcsx2/GameDatabase.h b/pcsx2/GameDatabase.h index f2f4f9af42f08..8b24b20587b7a 100644 --- a/pcsx2/GameDatabase.h +++ b/pcsx2/GameDatabase.h @@ -8,6 +8,7 @@ #include "common/FPControl.h" +#include #include #include #include diff --git a/pcsx2/IPU/IPU_MultiISA.cpp b/pcsx2/IPU/IPU_MultiISA.cpp index 26d762256d5af..194a2b0172c25 100644 --- a/pcsx2/IPU/IPU_MultiISA.cpp +++ b/pcsx2/IPU/IPU_MultiISA.cpp @@ -14,8 +14,6 @@ #include "IPU/yuv2rgb.h" #include "IPU/IPU_MultiISA.h" -#include "common/General.h" - // the IPU is fixed to 16 byte strides (128-bit / QWC resolution): static const uint decoder_stride = 16; diff --git a/pcsx2/Input/InputManager.cpp b/pcsx2/Input/InputManager.cpp index 2b4e0409f0a36..7c925017e1e7a 100644 --- a/pcsx2/Input/InputManager.cpp +++ b/pcsx2/Input/InputManager.cpp @@ -19,6 +19,7 @@ #include "fmt/core.h" #include +#include #include #include #include diff --git a/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp b/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp index 2a6310064256a..e9c4ea42eb15b 100644 --- a/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp +++ b/pcsx2/SIO/Memcard/MemoryCardProtocol.cpp @@ -10,6 +10,8 @@ #include "common/Assertions.h" #include "common/Console.h" +#include + #define MC_LOG_ENABLE 0 #define MC_LOG if (MC_LOG_ENABLE) DevCon diff --git a/pcsx2/SIO/Sio.cpp b/pcsx2/SIO/Sio.cpp index 02412971ec44b..c1bfc3f32fb4a 100644 --- a/pcsx2/SIO/Sio.cpp +++ b/pcsx2/SIO/Sio.cpp @@ -9,6 +9,8 @@ #include "Host.h" #include "IconsFontAwesome5.h" +#include + _mcd mcds[2][4]; _mcd *mcd; diff --git a/pcsx2/SPU2/spu2freeze.cpp b/pcsx2/SPU2/spu2freeze.cpp index 9eec55297c570..6587f0eccf9dc 100644 --- a/pcsx2/SPU2/spu2freeze.cpp +++ b/pcsx2/SPU2/spu2freeze.cpp @@ -5,6 +5,8 @@ #include "SPU2/spu2.h" // hopefully temporary, until I resolve lClocks depdendency #include "IopMem.h" +#include + namespace SPU2Savestate { // Arbitrary ID to identify SPU2 saves. diff --git a/pcsx2/vtlb.cpp b/pcsx2/vtlb.cpp index 0fe5ccbe87b94..e5c5b4aad0537 100644 --- a/pcsx2/vtlb.cpp +++ b/pcsx2/vtlb.cpp @@ -1023,7 +1023,7 @@ bool vtlb_GetGuestAddress(uptr host_addr, u32* guest_addr) return true; } -void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, const PageProtectionMode& prot) +void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, PageProtectionMode prot) { if (!CHECK_FASTMEM) return; diff --git a/pcsx2/vtlb.h b/pcsx2/vtlb.h index 66a5bfdd4974b..12384e2a19d07 100644 --- a/pcsx2/vtlb.h +++ b/pcsx2/vtlb.h @@ -5,7 +5,7 @@ #include "MemoryTypes.h" -#include "common/General.h" +#include "common/HostSys.h" #include "common/SingleRegisterTypes.h" static const uptr VTLB_AllocUpperBounds = _1gb * 2; @@ -73,7 +73,7 @@ extern void vtlb_VMapBuffer(u32 vaddr,void* buffer,u32 sz); extern void vtlb_VMapUnmap(u32 vaddr,u32 sz); extern bool vtlb_ResolveFastmemMapping(uptr* addr); extern bool vtlb_GetGuestAddress(uptr host_addr, u32* guest_addr); -extern void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, const PageProtectionMode& prot); +extern void vtlb_UpdateFastmemProtection(u32 paddr, u32 size, PageProtectionMode prot); extern bool vtlb_BackpatchLoadStore(uptr code_address, uptr fault_address); extern void vtlb_ClearLoadStoreInfo();