From 6e28ac711f034a2ecdc8942b064cfcc2c8ad30fc Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 13:22:18 +0200 Subject: [PATCH 1/7] cmake: Refactor library management --- CMakeLists.txt | 31 +++------- src/Util/Disassembler.h | 2 +- src/Util/config.cpp | 2 +- src/core/PS4/GPU/gpu_memory.cpp | 2 +- src/core/PS4/Linker.cpp | 2 +- src/discord.h | 2 +- src/vulkan_util.h | 2 +- third-party/CMakeLists.txt | 105 ++++++++++++++++---------------- 8 files changed, 69 insertions(+), 79 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c27e640..7f812616 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,27 +1,15 @@ cmake_minimum_required(VERSION 3.16.3) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED True) -if(NOT CMAKE_BUILD_TYPE) - set(CMAKE_BUILD_TYPE Release) +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release) endif() project(shadps4) -include_directories(third-party/) -include_directories(third-party/discord-rpc/include) -include_directories(third-party/imgui/) -include_directories(third-party/imgui/backends) -include_directories(third-party/sdl/) -include_directories(third-party/fmt/include) -include_directories(third-party/magic_enum/include) -include_directories(third-party/zydis/include/Zydis) -include_directories(third-party/winpthread/include) -include_directories(third-party/vulkan/include) -include_directories(third-party/xxhash/include) -include_directories(third-party/result/include) -add_subdirectory("third-party") -#=================== EXAMPLE =================== +add_subdirectory(third-party) include_directories(src) set(LIBC_SOURCES src/core/hle/libraries/Libc/Libc.cpp @@ -52,9 +40,7 @@ set(SYSTEMSERVICE_SOURCES src/core/hle/libraries/libsystemservice/system_service ) set(FILESYSTEM_SOURCES src/core/hle/libraries/libkernel/file_system.cpp - src/core/hle/libraries/libkernel/file_system.h - - + src/core/hle/libraries/libkernel/file_system.h ) set(HOST_SOURCES src/Emulator/Host/controller.cpp @@ -110,8 +96,11 @@ add_executable(shadps4 "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/core/PS4/Util/aerolib.h" "src/core/PS4/Loader/SymbolsResolver.h" "src/core/PS4/Loader/SymbolsResolver.cpp" "src/core/PS4/HLE/Libs.cpp" "src/core/PS4/HLE/Libs.h" "src/core/PS4/HLE/LibKernel.cpp" "src/core/PS4/HLE/LibKernel.h" "src/core/PS4/HLE/LibSceGnmDriver.cpp" "src/core/PS4/HLE/LibSceGnmDriver.h" "src/core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/core/PS4/HLE/Kernel/ThreadManagement.h" "src/core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/core/PS4/HLE/Kernel/memory_management.cpp" "src/core/PS4/HLE/Kernel/memory_management.h" "src/core/PS4/GPU/gpu_memory.cpp" "src/core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/core/PS4/HLE/Kernel/Objects/event_queue.h" "src/core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/core/PS4/GPU/video_out_buffer.cpp" "src/core/PS4/GPU/video_out_buffer.h" "src/core/PS4/HLE/Graphics/graphics_render.cpp" "src/core/PS4/HLE/Graphics/graphics_render.h" "src/core/PS4/GPU/tile_manager.cpp" "src/core/PS4/GPU/tile_manager.h" "src/version.h" "src/emuTimer.cpp" "src/emuTimer.h" "src/core/hle/libraries/libkernel/time_management.cpp" "src/core/hle/libraries/libkernel/time_management.h") -find_package(OpenGL REQUIRED) -target_link_libraries(shadps4 PUBLIC fmt mincore spdlog IMGUI SDL3-shared ${OPENGL_LIBRARY} vulkan-1 spirv-tools-opt spirv-tools) +target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt spdlog::spdlog toml11::toml11) +target_link_libraries(shadps4 PRIVATE discord-rpc imgui SDL3-shared vulkan-1 xxhash Zydis) +if (WIN32) + target_link_libraries(shadps4 PRIVATE mincore winpthread) +endif() add_custom_command(TARGET shadps4 POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different diff --git a/src/Util/Disassembler.h b/src/Util/Disassembler.h index 7e444c5a..b962142c 100644 --- a/src/Util/Disassembler.h +++ b/src/Util/Disassembler.h @@ -1,6 +1,6 @@ #pragma once -#include "Zydis.h" +#include #include "../types.h" class Disassembler diff --git a/src/Util/config.cpp b/src/Util/config.cpp index ab4eaf02..7c5a4fa7 100644 --- a/src/Util/config.cpp +++ b/src/Util/config.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include namespace Config { diff --git a/src/core/PS4/GPU/gpu_memory.cpp b/src/core/PS4/GPU/gpu_memory.cpp index e7e2fe81..6d084322 100644 --- a/src/core/PS4/GPU/gpu_memory.cpp +++ b/src/core/PS4/GPU/gpu_memory.cpp @@ -1,6 +1,6 @@ #include "gpu_memory.h" -#include +#include #include "Emulator/Util/singleton.h" diff --git a/src/core/PS4/Linker.cpp b/src/core/PS4/Linker.cpp index 14367dc5..f31087d2 100644 --- a/src/core/PS4/Linker.cpp +++ b/src/core/PS4/Linker.cpp @@ -2,7 +2,7 @@ #include "../virtual_memory.h" #include #include -#include "Zydis.h" +#include #include #include "Util/aerolib.h" #include "Loader/SymbolsResolver.h" diff --git a/src/discord.h b/src/discord.h index ca888018..0be14428 100644 --- a/src/discord.h +++ b/src/discord.h @@ -16,4 +16,4 @@ namespace Discord { void update(RPCStatus status, const std::string& title); void stop(); }; -} // namespace Discord \ No newline at end of file +} // namespace Discord diff --git a/src/vulkan_util.h b/src/vulkan_util.h index e4eda911..550b9b00 100644 --- a/src/vulkan_util.h +++ b/src/vulkan_util.h @@ -1,7 +1,7 @@ #pragma once #include #include -#include +#include #include diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 0b0db59c..8dcf026e 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -1,69 +1,70 @@ -set(CMAKE_CXX_STANDARD 20) -set(CMAKE_CXX_STANDARD_REQUIRED True) +if (MSVC) + # Silence "deprecation" warnings + add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS) +endif() +# Discord-RPC +set(BUILD_EXAMPLES OFF CACHE BOOL "") +add_subdirectory(discord-rpc EXCLUDE_FROM_ALL) +target_include_directories(discord-rpc INTERFACE ./discord-rpc/include) -#====================FMT ==================== -set(fmt_DIR ${CMAKE_CURRENT_SOURCE_DIR}/fmt) -add_subdirectory(${fmt_DIR}) +# fmtlib +add_subdirectory(fmt EXCLUDE_FROM_ALL) -#=================== SPD ==================== +# MagicEnum +add_subdirectory(magic_enum EXCLUDE_FROM_ALL) + +# Spdlog set(SPDLOG_WCHAR_FILENAMES ON CACHE BOOL "") set(SPDLOG_NO_THREAD_ID ON CACHE BOOL "") set(SPDLOG_FMT_EXTERNAL ON CACHE BOOL "") add_subdirectory(spdlog EXCLUDE_FROM_ALL) add_library(stb INTERFACE) -target_include_directories(stb INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/stb") +target_include_directories(stb INTERFACE ./stb) -#=================== SDL3 =================== +# SDL3 +add_subdirectory(SDL EXCLUDE_FROM_ALL) -set(SDL3_DIR ${CMAKE_CURRENT_SOURCE_DIR}/SDL) -add_subdirectory(${SDL3_DIR}) +# Toml11 +add_subdirectory(toml11 EXCLUDE_FROM_ALL) -#================ Zydis ======================== -# Register Zydis dependency. -# Disable build of tools and examples. +# Vulkan +add_subdirectory(vulkan EXCLUDE_FROM_ALL) +target_include_directories(vulkan-1 INTERFACE vulkan/include) + +# Winpthreads +if (WIN32) + add_subdirectory(winpthread EXCLUDE_FROM_ALL) +endif() + +# xxHash +add_library(xxhash INTERFACE) +target_include_directories(xxhash INTERFACE xxhash) + +# Zydis option(ZYDIS_BUILD_TOOLS "" OFF) option(ZYDIS_BUILD_EXAMPLES "" OFF) -set(zydis_DIR ${CMAKE_CURRENT_SOURCE_DIR}/zydis) -add_subdirectory(${zydis_DIR}) +add_subdirectory(zydis EXCLUDE_FROM_ALL) -#========== winpthreads ====================== -add_subdirectory(winpthread) -#=================== discord-rpc =================== -add_subdirectory(discord-rpc) -#=================== toml11 =================== -add_subdirectory(toml11) -#=================== vulkan ================== -add_subdirectory(vulkan) -#=================== IMGUI =================== +# Imgui +add_library(imgui STATIC) -set(IMGUI_DIR ${CMAKE_CURRENT_SOURCE_DIR}/imgui) -add_library(IMGUI STATIC) - - -target_sources( IMGUI - PRIVATE - ${IMGUI_DIR}/imgui_demo.cpp - ${IMGUI_DIR}/imgui_draw.cpp - ${IMGUI_DIR}/imgui_tables.cpp - ${IMGUI_DIR}/imgui_widgets.cpp - ${IMGUI_DIR}/imgui.cpp - - PRIVATE - ${IMGUI_DIR}/backends/imgui_impl_opengl3.cpp - ${IMGUI_DIR}/backends/imgui_impl_sdl3.cpp - ) - -target_include_directories( IMGUI - PUBLIC ${IMGUI_DIR} - PUBLIC ${IMGUI_DIR}/backends - PUBLIC ${SDL3_DIR}/include - ) - -find_package(OpenGL REQUIRED) -target_link_libraries(IMGUI PUBLIC ${OPENGL_LIBRARIES}) - - -target_link_libraries(IMGUI PUBLIC SDL3-shared ${CMAKE_DL_LIBS} Zydis winpthread discord-rpc) +target_sources(imgui PRIVATE + imgui/imgui_demo.cpp + imgui/imgui_draw.cpp + imgui/imgui_tables.cpp + imgui/imgui_widgets.cpp + imgui/imgui.cpp + imgui/backends/imgui_impl_opengl3.cpp + imgui/backends/imgui_impl_sdl3.cpp +) + +target_include_directories(imgui PUBLIC + imgui + imgui/backends + imgui/include +) + +target_link_libraries(imgui PRIVATE SDL3-shared ${CMAKE_DL_LIBS} Zydis winpthread discord-rpc) From 17aefc1aefe8f43468df919a625d781adbb09570 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 13:41:10 +0200 Subject: [PATCH 2/7] src: Move certain headers in common --- src/Emulator/Host/controller.h | 2 +- src/Lib/Timer.h | 2 +- src/Util/config.h | 4 ++-- src/{ => common}/debug.h | 0 src/{Util/Disassembler.cpp => common/disassembler.cpp} | 2 +- src/{Util/Disassembler.h => common/disassembler.h} | 2 +- src/{ => common}/discord.cpp | 0 src/{ => common}/discord.h | 0 src/{core/FsFile.cpp => common/fs_file.cpp} | 2 +- src/{core/FsFile.h => common/fs_file.h} | 2 +- src/{Util => common}/log.cpp | 0 src/{Util => common}/log.h | 0 src/{Emulator/Util => common}/singleton.h | 0 src/{Util => common}/string_util.cpp | 3 +-- src/{Util => common}/string_util.h | 0 src/{ => common}/types.h | 0 src/{ => common}/version.h | 0 src/core/PS4/GPU/gpu_memory.cpp | 2 +- src/core/PS4/GPU/gpu_memory.h | 2 +- src/core/PS4/GPU/tile_manager.cpp | 2 +- src/core/PS4/GPU/tile_manager.h | 2 +- src/core/PS4/GPU/video_out_buffer.cpp | 4 ++-- src/core/PS4/GPU/video_out_buffer.h | 2 +- src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp | 2 +- src/core/PS4/HLE/Graphics/graphics_ctx.h | 2 +- src/core/PS4/HLE/Graphics/graphics_render.cpp | 2 +- src/core/PS4/HLE/Graphics/video_out.cpp | 6 +++--- src/core/PS4/HLE/Graphics/video_out.h | 3 +-- src/core/PS4/HLE/Kernel/Objects/event_queue.cpp | 2 +- src/core/PS4/HLE/Kernel/Objects/event_queue.h | 4 ++-- src/core/PS4/HLE/Kernel/Objects/physical_memory.h | 2 +- src/core/PS4/HLE/Kernel/ThreadManagement.cpp | 2 +- src/core/PS4/HLE/Kernel/ThreadManagement.h | 2 +- src/core/PS4/HLE/Kernel/cpu_management.cpp | 2 +- src/core/PS4/HLE/Kernel/cpu_management.h | 2 +- src/core/PS4/HLE/Kernel/event_queues.cpp | 4 ++-- src/core/PS4/HLE/Kernel/event_queues.h | 4 +--- src/core/PS4/HLE/Kernel/memory_management.cpp | 6 +++--- src/core/PS4/HLE/Kernel/memory_management.h | 2 +- src/core/PS4/HLE/LibKernel.cpp | 6 +++--- src/core/PS4/HLE/LibSceGnmDriver.cpp | 4 ++-- src/core/PS4/Linker.cpp | 4 ++-- src/core/PS4/Loader/Elf.cpp | 4 ++-- src/core/PS4/Loader/Elf.h | 4 ++-- src/core/PS4/Loader/SymbolsResolver.cpp | 4 ++-- src/core/PS4/Loader/SymbolsResolver.h | 5 ++--- src/core/PS4/Stubs.cpp | 2 +- src/core/PS4/Stubs.h | 2 +- src/core/PS4/Util/aerolib.cpp | 4 ++-- src/core/hle/libraries/libc/libc.cpp | 6 +++--- src/core/hle/libraries/libc/libc.h | 2 +- src/core/hle/libraries/libc/libc_cxa.cpp | 4 ++-- src/core/hle/libraries/libc/libc_cxa.h | 2 +- src/core/hle/libraries/libc/libc_math.h | 2 +- src/core/hle/libraries/libc/libc_stdio.cpp | 4 ++-- src/core/hle/libraries/libc/libc_stdio.h | 2 +- src/core/hle/libraries/libc/libc_stdlib.cpp | 4 ++-- src/core/hle/libraries/libc/libc_stdlib.h | 2 +- src/core/hle/libraries/libc/libc_string.h | 2 +- src/core/hle/libraries/libc/va_ctx.h | 2 +- src/core/hle/libraries/libkernel/file_system.cpp | 4 ++-- src/core/hle/libraries/libkernel/file_system.h | 2 +- src/core/hle/libraries/libkernel/time_management.h | 2 +- src/core/hle/libraries/libpad/pad.cpp | 6 +++--- src/core/hle/libraries/libpad/pad.h | 2 +- .../hle/libraries/libsystemservice/system_service.cpp | 2 +- src/core/hle/libraries/libuserservice/user_service.cpp | 2 +- src/core/virtual_memory.cpp | 7 ++----- src/core/virtual_memory.h | 2 +- src/emuTimer.h | 5 +++-- src/emulator.cpp | 4 ++-- src/main.cpp | 9 ++++----- src/vulkan_util.cpp | 6 +++--- 73 files changed, 98 insertions(+), 106 deletions(-) rename src/{ => common}/debug.h (100%) rename src/{Util/Disassembler.cpp => common/disassembler.cpp} (96%) rename src/{Util/Disassembler.h => common/disassembler.h} (92%) rename src/{ => common}/discord.cpp (100%) rename src/{ => common}/discord.h (100%) rename src/{core/FsFile.cpp => common/fs_file.cpp} (98%) rename src/{core/FsFile.h => common/fs_file.h} (98%) rename src/{Util => common}/log.cpp (100%) rename src/{Util => common}/log.h (100%) rename src/{Emulator/Util => common}/singleton.h (100%) rename src/{Util => common}/string_util.cpp (90%) rename src/{Util => common}/string_util.h (100%) rename src/{ => common}/types.h (100%) rename src/{ => common}/version.h (100%) diff --git a/src/Emulator/Host/controller.h b/src/Emulator/Host/controller.h index f534ed7a..33c1550c 100644 --- a/src/Emulator/Host/controller.h +++ b/src/Emulator/Host/controller.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "common/types.h" #include namespace Emulator::Host::Controller { diff --git a/src/Lib/Timer.h b/src/Lib/Timer.h index 8dcc8593..5ba2a09a 100644 --- a/src/Lib/Timer.h +++ b/src/Lib/Timer.h @@ -1,6 +1,6 @@ #pragma once -#include "../types.h" +#include "common/types.h" namespace Lib { class Timer final diff --git a/src/Util/config.h b/src/Util/config.h index c27cc2df..1397a643 100644 --- a/src/Util/config.h +++ b/src/Util/config.h @@ -1,6 +1,6 @@ #pragma once #include -#include +#include "common/types.h" namespace Config { void load(const std::filesystem::path& path); @@ -12,4 +12,4 @@ u32 getLogLevel(); u32 getScreenWidth(); u32 getScreenHeight(); -}; // namespace Config \ No newline at end of file +}; // namespace Config diff --git a/src/debug.h b/src/common/debug.h similarity index 100% rename from src/debug.h rename to src/common/debug.h diff --git a/src/Util/Disassembler.cpp b/src/common/disassembler.cpp similarity index 96% rename from src/Util/Disassembler.cpp rename to src/common/disassembler.cpp index e1af76bb..e930e0c0 100644 --- a/src/Util/Disassembler.cpp +++ b/src/common/disassembler.cpp @@ -1,4 +1,4 @@ -#include "Disassembler.h" +#include "common/disassembler.h" #include Disassembler::Disassembler() diff --git a/src/Util/Disassembler.h b/src/common/disassembler.h similarity index 92% rename from src/Util/Disassembler.h rename to src/common/disassembler.h index b962142c..3737986f 100644 --- a/src/Util/Disassembler.h +++ b/src/common/disassembler.h @@ -1,7 +1,7 @@ #pragma once #include -#include "../types.h" +#include "common/types.h" class Disassembler { diff --git a/src/discord.cpp b/src/common/discord.cpp similarity index 100% rename from src/discord.cpp rename to src/common/discord.cpp diff --git a/src/discord.h b/src/common/discord.h similarity index 100% rename from src/discord.h rename to src/common/discord.h diff --git a/src/core/FsFile.cpp b/src/common/fs_file.cpp similarity index 98% rename from src/core/FsFile.cpp rename to src/common/fs_file.cpp index 3e73c9af..007ec72d 100644 --- a/src/core/FsFile.cpp +++ b/src/common/fs_file.cpp @@ -1,4 +1,4 @@ -#include "FsFile.h" +#include "common/fs_file.h" namespace Common::FS { diff --git a/src/core/FsFile.h b/src/common/fs_file.h similarity index 98% rename from src/core/FsFile.h rename to src/common/fs_file.h index a00d00dc..adc99605 100644 --- a/src/core/FsFile.h +++ b/src/common/fs_file.h @@ -6,7 +6,7 @@ #include #include -#include "../types.h" +#include "common/types.h" namespace Common::FS { diff --git a/src/Util/log.cpp b/src/common/log.cpp similarity index 100% rename from src/Util/log.cpp rename to src/common/log.cpp diff --git a/src/Util/log.h b/src/common/log.h similarity index 100% rename from src/Util/log.h rename to src/common/log.h diff --git a/src/Emulator/Util/singleton.h b/src/common/singleton.h similarity index 100% rename from src/Emulator/Util/singleton.h rename to src/common/singleton.h diff --git a/src/Util/string_util.cpp b/src/common/string_util.cpp similarity index 90% rename from src/Util/string_util.cpp rename to src/common/string_util.cpp index c1b1b6cf..6f1a7403 100644 --- a/src/Util/string_util.cpp +++ b/src/common/string_util.cpp @@ -1,8 +1,7 @@ -#include "string_util.h" - #include #include #include +#include "common/string_util.h" namespace StringUtil { diff --git a/src/Util/string_util.h b/src/common/string_util.h similarity index 100% rename from src/Util/string_util.h rename to src/common/string_util.h diff --git a/src/types.h b/src/common/types.h similarity index 100% rename from src/types.h rename to src/common/types.h diff --git a/src/version.h b/src/common/version.h similarity index 100% rename from src/version.h rename to src/common/version.h diff --git a/src/core/PS4/GPU/gpu_memory.cpp b/src/core/PS4/GPU/gpu_memory.cpp index 6d084322..6ad56cc3 100644 --- a/src/core/PS4/GPU/gpu_memory.cpp +++ b/src/core/PS4/GPU/gpu_memory.cpp @@ -2,7 +2,7 @@ #include -#include "Emulator/Util/singleton.h" +#include "common/singleton.h" void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size, const GPUObject& info) { diff --git a/src/core/PS4/GPU/gpu_memory.h b/src/core/PS4/GPU/gpu_memory.h index f4398085..eb3f1e5b 100644 --- a/src/core/PS4/GPU/gpu_memory.h +++ b/src/core/PS4/GPU/gpu_memory.h @@ -1,7 +1,7 @@ #pragma once #include -#include +#include "common/types.h" #include #include diff --git a/src/core/PS4/GPU/tile_manager.cpp b/src/core/PS4/GPU/tile_manager.cpp index ba072770..01b94f47 100644 --- a/src/core/PS4/GPU/tile_manager.cpp +++ b/src/core/PS4/GPU/tile_manager.cpp @@ -1,5 +1,5 @@ #include "tile_manager.h" -#include "Emulator/Util/singleton.h" +#include "common/singleton.h" #include namespace GPU { diff --git a/src/core/PS4/GPU/tile_manager.h b/src/core/PS4/GPU/tile_manager.h index e6360855..7dba4b3f 100644 --- a/src/core/PS4/GPU/tile_manager.h +++ b/src/core/PS4/GPU/tile_manager.h @@ -1,6 +1,6 @@ #pragma once -#include "types.h" +#include "common/types.h" namespace GPU { diff --git a/src/core/PS4/GPU/video_out_buffer.cpp b/src/core/PS4/GPU/video_out_buffer.cpp index 339b5960..1a9c30a4 100644 --- a/src/core/PS4/GPU/video_out_buffer.cpp +++ b/src/core/PS4/GPU/video_out_buffer.cpp @@ -1,8 +1,8 @@ #include "video_out_buffer.h" -#include +#include "common/log.h" -#include "debug.h" +#include "common/debug.h" #include #include "tile_manager.h" diff --git a/src/core/PS4/GPU/video_out_buffer.h b/src/core/PS4/GPU/video_out_buffer.h index ed459efe..a7876b03 100644 --- a/src/core/PS4/GPU/video_out_buffer.h +++ b/src/core/PS4/GPU/video_out_buffer.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" #include "gpu_memory.h" diff --git a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp index c7586151..b18d3b7c 100644 --- a/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp +++ b/src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp @@ -1,7 +1,7 @@ #include "video_out_ctx.h" #include -#include +#include "common/debug.h" #include namespace HLE::Graphics::Objects { diff --git a/src/core/PS4/HLE/Graphics/graphics_ctx.h b/src/core/PS4/HLE/Graphics/graphics_ctx.h index 1196d0b0..eb355056 100644 --- a/src/core/PS4/HLE/Graphics/graphics_ctx.h +++ b/src/core/PS4/HLE/Graphics/graphics_ctx.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" #include #include #include diff --git a/src/core/PS4/HLE/Graphics/graphics_render.cpp b/src/core/PS4/HLE/Graphics/graphics_render.cpp index 63e68f3a..7af3a257 100644 --- a/src/core/PS4/HLE/Graphics/graphics_render.cpp +++ b/src/core/PS4/HLE/Graphics/graphics_render.cpp @@ -1,6 +1,6 @@ #include "graphics_render.h" #include -#include "Emulator/Util/singleton.h" +#include "common/singleton.h" #include "emulator.h" static thread_local GPU::CommandPool g_command_pool; diff --git a/src/core/PS4/HLE/Graphics/video_out.cpp b/src/core/PS4/HLE/Graphics/video_out.cpp index ac0c67d3..bb71eec3 100644 --- a/src/core/PS4/HLE/Graphics/video_out.cpp +++ b/src/core/PS4/HLE/Graphics/video_out.cpp @@ -7,15 +7,15 @@ #include #include #include -#include -#include +#include "common/log.h" +#include "common/debug.h" #include #include #include #include "Objects/video_out_ctx.h" -#include "Emulator/Util/singleton.h" +#include "common/singleton.h" #include "emulator.h" #include "graphics_render.h" diff --git a/src/core/PS4/HLE/Graphics/video_out.h b/src/core/PS4/HLE/Graphics/video_out.h index be1fd514..65a8fa10 100644 --- a/src/core/PS4/HLE/Graphics/video_out.h +++ b/src/core/PS4/HLE/Graphics/video_out.h @@ -1,7 +1,6 @@ #pragma once #include #include -#include #include @@ -111,4 +110,4 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* sta s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status); s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 index, const void* param); s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle); -} // namespace HLE::Libs::Graphics::VideoOut \ No newline at end of file +} // namespace HLE::Libs::Graphics::VideoOut diff --git a/src/core/PS4/HLE/Kernel/Objects/event_queue.cpp b/src/core/PS4/HLE/Kernel/Objects/event_queue.cpp index 521cd432..4cc99fc8 100644 --- a/src/core/PS4/HLE/Kernel/Objects/event_queue.cpp +++ b/src/core/PS4/HLE/Kernel/Objects/event_queue.cpp @@ -2,7 +2,7 @@ #include -#include "debug.h" +#include "common/debug.h" namespace HLE::Kernel::Objects { EqueueInternal::~EqueueInternal() {} diff --git a/src/core/PS4/HLE/Kernel/Objects/event_queue.h b/src/core/PS4/HLE/Kernel/Objects/event_queue.h index 66ebe33f..ade6fbd2 100644 --- a/src/core/PS4/HLE/Kernel/Objects/event_queue.h +++ b/src/core/PS4/HLE/Kernel/Objects/event_queue.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" #include #include #include @@ -76,4 +76,4 @@ class EqueueInternal { std::vector m_events; std::condition_variable m_cond; }; -}; // namespace HLE::Kernel::Objects \ No newline at end of file +}; // namespace HLE::Kernel::Objects diff --git a/src/core/PS4/HLE/Kernel/Objects/physical_memory.h b/src/core/PS4/HLE/Kernel/Objects/physical_memory.h index e5ea7e5e..3c5038a0 100644 --- a/src/core/PS4/HLE/Kernel/Objects/physical_memory.h +++ b/src/core/PS4/HLE/Kernel/Objects/physical_memory.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "common/types.h" #include #include #include diff --git a/src/core/PS4/HLE/Kernel/ThreadManagement.cpp b/src/core/PS4/HLE/Kernel/ThreadManagement.cpp index c6ea8f8d..2a3ef089 100644 --- a/src/core/PS4/HLE/Kernel/ThreadManagement.cpp +++ b/src/core/PS4/HLE/Kernel/ThreadManagement.cpp @@ -1,6 +1,6 @@ #include "ThreadManagement.h" -#include +#include "common/debug.h" #include "../ErrorCodes.h" diff --git a/src/core/PS4/HLE/Kernel/ThreadManagement.h b/src/core/PS4/HLE/Kernel/ThreadManagement.h index bda43cf3..31e45213 100644 --- a/src/core/PS4/HLE/Kernel/ThreadManagement.h +++ b/src/core/PS4/HLE/Kernel/ThreadManagement.h @@ -3,7 +3,7 @@ #include #include -#include "../../../../types.h" +#include "common/types.h" #include namespace HLE::Libs::LibKernel::ThreadManagement { diff --git a/src/core/PS4/HLE/Kernel/cpu_management.cpp b/src/core/PS4/HLE/Kernel/cpu_management.cpp index 2a605452..6c334024 100644 --- a/src/core/PS4/HLE/Kernel/cpu_management.cpp +++ b/src/core/PS4/HLE/Kernel/cpu_management.cpp @@ -1,6 +1,6 @@ #include "cpu_management.h" #include "Util/config.h" -#include +#include "common/log.h" #include namespace HLE::Libs::LibKernel::CPUManagement { diff --git a/src/core/PS4/HLE/Kernel/cpu_management.h b/src/core/PS4/HLE/Kernel/cpu_management.h index b6147abb..e463d316 100644 --- a/src/core/PS4/HLE/Kernel/cpu_management.h +++ b/src/core/PS4/HLE/Kernel/cpu_management.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "common/types.h" namespace HLE::Libs::LibKernel::CPUManagement { int PS4_SYSV_ABI sceKernelIsNeoMode(); diff --git a/src/core/PS4/HLE/Kernel/event_queues.cpp b/src/core/PS4/HLE/Kernel/event_queues.cpp index c7ea7adc..61b15344 100644 --- a/src/core/PS4/HLE/Kernel/event_queues.cpp +++ b/src/core/PS4/HLE/Kernel/event_queues.cpp @@ -2,8 +2,8 @@ #include #include -#include -#include +#include "common/log.h" +#include "common/debug.h" namespace HLE::Libs::LibKernel::EventQueues { constexpr bool log_file_equeues = true; // disable it to disable logging diff --git a/src/core/PS4/HLE/Kernel/event_queues.h b/src/core/PS4/HLE/Kernel/event_queues.h index 97121540..c59367b2 100644 --- a/src/core/PS4/HLE/Kernel/event_queues.h +++ b/src/core/PS4/HLE/Kernel/event_queues.h @@ -1,7 +1,5 @@ #pragma once -#include - #include "Objects/event_queue.h" namespace HLE::Libs::LibKernel::EventQueues { @@ -11,4 +9,4 @@ using SceKernelEqueue = Kernel::Objects::EqueueInternal*; int PS4_SYSV_ABI sceKernelCreateEqueue(SceKernelEqueue* eq, const char* name); int PS4_SYSV_ABI sceKernelWaitEqueue(SceKernelEqueue eq, HLE::Kernel::Objects::SceKernelEvent* ev, int num, int* out, SceKernelUseconds *timo); -}; // namespace HLE::Libs::LibKernel::EventQueues \ No newline at end of file +}; // namespace HLE::Libs::LibKernel::EventQueues diff --git a/src/core/PS4/HLE/Kernel/memory_management.cpp b/src/core/PS4/HLE/Kernel/memory_management.cpp index d891f6b9..dc39ad9a 100644 --- a/src/core/PS4/HLE/Kernel/memory_management.cpp +++ b/src/core/PS4/HLE/Kernel/memory_management.cpp @@ -2,13 +2,13 @@ #include #include -#include -#include +#include "common/log.h" +#include "common/debug.h" #include #include -#include "Emulator/Util/singleton.h" +#include "common/singleton.h" #include "../ErrorCodes.h" #include "../Libs.h" #include "Objects/physical_memory.h" diff --git a/src/core/PS4/HLE/Kernel/memory_management.h b/src/core/PS4/HLE/Kernel/memory_management.h index 4a872cb5..80ef67fe 100644 --- a/src/core/PS4/HLE/Kernel/memory_management.h +++ b/src/core/PS4/HLE/Kernel/memory_management.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" // constants diff --git a/src/core/PS4/HLE/LibKernel.cpp b/src/core/PS4/HLE/LibKernel.cpp index a7599afa..2a4a4bf6 100644 --- a/src/core/PS4/HLE/LibKernel.cpp +++ b/src/core/PS4/HLE/LibKernel.cpp @@ -1,10 +1,10 @@ #include "LibKernel.h" -#include -#include +#include "common/log.h" +#include "common/debug.h" #include -#include "Emulator/Util/singleton.h" +#include "common/singleton.h" #include "../Loader/Elf.h" #include "Kernel/Objects/physical_memory.h" #include "Kernel/cpu_management.h" diff --git a/src/core/PS4/HLE/LibSceGnmDriver.cpp b/src/core/PS4/HLE/LibSceGnmDriver.cpp index 14d1f43e..be81d557 100644 --- a/src/core/PS4/HLE/LibSceGnmDriver.cpp +++ b/src/core/PS4/HLE/LibSceGnmDriver.cpp @@ -1,8 +1,8 @@ #include "LibSceGnmDriver.h" #include "Libs.h" #include "../Loader/Elf.h" -#include -#include +#include "common/log.h" +#include "common/debug.h" #include #include diff --git a/src/core/PS4/Linker.cpp b/src/core/PS4/Linker.cpp index f31087d2..ac300d39 100644 --- a/src/core/PS4/Linker.cpp +++ b/src/core/PS4/Linker.cpp @@ -1,9 +1,9 @@ #include "Linker.h" #include "../virtual_memory.h" -#include +#include "common/log.h" #include #include -#include +#include "common/string_util.h" #include "Util/aerolib.h" #include "Loader/SymbolsResolver.h" #include "HLE/Kernel/ThreadManagement.h" diff --git a/src/core/PS4/Loader/Elf.cpp b/src/core/PS4/Loader/Elf.cpp index b7f88d85..bfb4008b 100644 --- a/src/core/PS4/Loader/Elf.cpp +++ b/src/core/PS4/Loader/Elf.cpp @@ -1,7 +1,7 @@ #include "Elf.h" -#include -#include +#include "common/log.h" +#include "common/debug.h" #include constexpr bool log_file_loader = true; // disable it to disable logging diff --git a/src/core/PS4/Loader/Elf.h b/src/core/PS4/Loader/Elf.h index 45bf3156..ffc62d27 100644 --- a/src/core/PS4/Loader/Elf.h +++ b/src/core/PS4/Loader/Elf.h @@ -5,8 +5,8 @@ #include #include -#include "../../../types.h" -#include "../../FsFile.h" +#include "common/types.h" +#include "common/fs_file.h" struct self_header { diff --git a/src/core/PS4/Loader/SymbolsResolver.cpp b/src/core/PS4/Loader/SymbolsResolver.cpp index c0e56d53..85a826c5 100644 --- a/src/core/PS4/Loader/SymbolsResolver.cpp +++ b/src/core/PS4/Loader/SymbolsResolver.cpp @@ -1,6 +1,6 @@ -#include "../../../types.h" +#include "common/types.h" #include "SymbolsResolver.h" -#include +#include "common/log.h" void SymbolsResolver::AddSymbol(const SymbolRes& s, u64 virtual_addr) { diff --git a/src/core/PS4/Loader/SymbolsResolver.h b/src/core/PS4/Loader/SymbolsResolver.h index 9932e050..ee227ee9 100644 --- a/src/core/PS4/Loader/SymbolsResolver.h +++ b/src/core/PS4/Loader/SymbolsResolver.h @@ -3,8 +3,7 @@ #include #include #include -#include "../../../types.h" - +#include "common/types.h" struct SymbolRecord { @@ -37,4 +36,4 @@ public: private: std::vector m_symbols; -}; \ No newline at end of file +}; diff --git a/src/core/PS4/Stubs.cpp b/src/core/PS4/Stubs.cpp index 3cba831c..36afc0a0 100644 --- a/src/core/PS4/Stubs.cpp +++ b/src/core/PS4/Stubs.cpp @@ -2,7 +2,7 @@ #include "Util/aerolib.h" -#include "Util/log.h" +#include "common/log.h" // Helper to provide stub implementations for missing functions // diff --git a/src/core/PS4/Stubs.h b/src/core/PS4/Stubs.h index 6c175618..1a7f0081 100644 --- a/src/core/PS4/Stubs.h +++ b/src/core/PS4/Stubs.h @@ -1,4 +1,4 @@ -#include "types.h" +#include "common/types.h" u64 UnresolvedStub(); u64 GetStub(const char *nid); \ No newline at end of file diff --git a/src/core/PS4/Util/aerolib.cpp b/src/core/PS4/Util/aerolib.cpp index 96362d69..b095fa7c 100644 --- a/src/core/PS4/Util/aerolib.cpp +++ b/src/core/PS4/Util/aerolib.cpp @@ -1,10 +1,10 @@ #include "aerolib.h" -#include "types.h" +#include "common/types.h" #include -#include "Util/log.h" +#include "common/log.h" namespace aerolib { diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index ce7d9bc9..765941d4 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -1,10 +1,10 @@ #include "libc.h" -#include +#include "common/debug.h" #include -#include "Emulator/Util/singleton.h" -#include "Util/log.h" +#include "common/singleton.h" +#include "common/log.h" #include "core/PS4/HLE/Libs.h" #include "core/hle/libraries/libc/libc.h" #include "core/hle/libraries/libc/libc_cxa.h" diff --git a/src/core/hle/libraries/libc/libc.h b/src/core/hle/libraries/libc/libc.h index e3824ead..686da34b 100644 --- a/src/core/hle/libraries/libc/libc.h +++ b/src/core/hle/libraries/libc/libc.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" #include "core/PS4/Loader/SymbolsResolver.h" namespace Core::Libraries::LibC { diff --git a/src/core/hle/libraries/libc/libc_cxa.cpp b/src/core/hle/libraries/libc/libc_cxa.cpp index 50ac9add..7fcf3e6c 100644 --- a/src/core/hle/libraries/libc/libc_cxa.cpp +++ b/src/core/hle/libraries/libc/libc_cxa.cpp @@ -1,7 +1,7 @@ #include "libc_cxa.h" -#include "Util/log.h" -#include "debug.h" +#include "common/log.h" +#include "common/debug.h" // adapted from https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx.auto.html diff --git a/src/core/hle/libraries/libc/libc_cxa.h b/src/core/hle/libraries/libc/libc_cxa.h index 170e48f8..617b8f33 100644 --- a/src/core/hle/libraries/libc/libc_cxa.h +++ b/src/core/hle/libraries/libc/libc_cxa.h @@ -2,7 +2,7 @@ #define _TIMESPEC_DEFINED #include -#include +#include "common/types.h" namespace Core::Libraries::LibC { int PS4_SYSV_ABI __cxa_guard_acquire(u64* guard_object); diff --git a/src/core/hle/libraries/libc/libc_math.h b/src/core/hle/libraries/libc/libc_math.h index d4961689..bb95ddaf 100644 --- a/src/core/hle/libraries/libc/libc_math.h +++ b/src/core/hle/libraries/libc/libc_math.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" namespace Core::Libraries::LibC { float PS4_SYSV_ABI atan2f(float y, float x); diff --git a/src/core/hle/libraries/libc/libc_stdio.cpp b/src/core/hle/libraries/libc/libc_stdio.cpp index f82a0ca3..ea84522e 100644 --- a/src/core/hle/libraries/libc/libc_stdio.cpp +++ b/src/core/hle/libraries/libc/libc_stdio.cpp @@ -1,7 +1,7 @@ #include "libc_stdio.h" -#include -#include +#include "common/debug.h" +#include "common/log.h" namespace Core::Libraries::LibC { constexpr bool log_file_libc = true; // disable it to disable logging diff --git a/src/core/hle/libraries/libc/libc_stdio.h b/src/core/hle/libraries/libc/libc_stdio.h index 0546a7bc..0d403387 100644 --- a/src/core/hle/libraries/libc/libc_stdio.h +++ b/src/core/hle/libraries/libc/libc_stdio.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" #include "printf.h" diff --git a/src/core/hle/libraries/libc/libc_stdlib.cpp b/src/core/hle/libraries/libc/libc_stdlib.cpp index 83b4506d..9ff6177b 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.cpp +++ b/src/core/hle/libraries/libc/libc_stdlib.cpp @@ -1,7 +1,7 @@ #include "libc_stdlib.h" -#include -#include +#include "common/log.h" +#include "common/debug.h" #include diff --git a/src/core/hle/libraries/libc/libc_stdlib.h b/src/core/hle/libraries/libc/libc_stdlib.h index d8d465ef..04cb3dd4 100644 --- a/src/core/hle/libraries/libc/libc_stdlib.h +++ b/src/core/hle/libraries/libc/libc_stdlib.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" #include diff --git a/src/core/hle/libraries/libc/libc_string.h b/src/core/hle/libraries/libc/libc_string.h index 0396ddd2..ff7c9e6e 100644 --- a/src/core/hle/libraries/libc/libc_string.h +++ b/src/core/hle/libraries/libc/libc_string.h @@ -1,6 +1,6 @@ #pragma once -#include +#include "common/types.h" #include diff --git a/src/core/hle/libraries/libc/va_ctx.h b/src/core/hle/libraries/libc/va_ctx.h index a8b0c177..12324cfd 100644 --- a/src/core/hle/libraries/libc/va_ctx.h +++ b/src/core/hle/libraries/libc/va_ctx.h @@ -1,4 +1,4 @@ -#include +#include "common/types.h" #include #define VA_ARGS \ diff --git a/src/core/hle/libraries/libkernel/file_system.cpp b/src/core/hle/libraries/libkernel/file_system.cpp index bc3ba4d7..311ff094 100644 --- a/src/core/hle/libraries/libkernel/file_system.cpp +++ b/src/core/hle/libraries/libkernel/file_system.cpp @@ -1,8 +1,8 @@ #include "file_system.h" #include -#include -#include +#include "common/log.h" +#include "common/debug.h" namespace Core::Libraries::LibKernel { constexpr bool log_file_fs = true; // disable it to disable logging diff --git a/src/core/hle/libraries/libkernel/file_system.h b/src/core/hle/libraries/libkernel/file_system.h index 36c973aa..4956a075 100644 --- a/src/core/hle/libraries/libkernel/file_system.h +++ b/src/core/hle/libraries/libkernel/file_system.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "common/types.h" #include "core/PS4/Loader/SymbolsResolver.h" namespace Core::Libraries::LibKernel { diff --git a/src/core/hle/libraries/libkernel/time_management.h b/src/core/hle/libraries/libkernel/time_management.h index 7ea068a9..29660af5 100644 --- a/src/core/hle/libraries/libkernel/time_management.h +++ b/src/core/hle/libraries/libkernel/time_management.h @@ -1,6 +1,6 @@ #pragma once -#include "types.h" +#include "common/types.h" #include "core/PS4/Loader/SymbolsResolver.h" namespace Core::Libraries::LibKernel { diff --git a/src/core/hle/libraries/libpad/pad.cpp b/src/core/hle/libraries/libpad/pad.cpp index fea4992c..4ed9d2b0 100644 --- a/src/core/hle/libraries/libpad/pad.cpp +++ b/src/core/hle/libraries/libpad/pad.cpp @@ -3,10 +3,10 @@ #include #include -#include "Emulator/Util/singleton.h" +#include "common/singleton.h" #include "Emulator/Host/controller.h" -#include -#include +#include "common/debug.h" +#include "common/log.h" namespace Core::Libraries::LibPad { diff --git a/src/core/hle/libraries/libpad/pad.h b/src/core/hle/libraries/libpad/pad.h index af925bdd..ffdfec6a 100644 --- a/src/core/hle/libraries/libpad/pad.h +++ b/src/core/hle/libraries/libpad/pad.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "common/types.h" #include "core/PS4/Loader/SymbolsResolver.h" #include "core/hle/libraries/libuserservice/user_service.h" diff --git a/src/core/hle/libraries/libsystemservice/system_service.cpp b/src/core/hle/libraries/libsystemservice/system_service.cpp index 42b2b5e2..5517bcdb 100644 --- a/src/core/hle/libraries/libsystemservice/system_service.cpp +++ b/src/core/hle/libraries/libsystemservice/system_service.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include "common/log.h" #include "system_service.h" namespace Core::Libraries::LibSystemService { diff --git a/src/core/hle/libraries/libuserservice/user_service.cpp b/src/core/hle/libraries/libuserservice/user_service.cpp index a887f506..314d052f 100644 --- a/src/core/hle/libraries/libuserservice/user_service.cpp +++ b/src/core/hle/libraries/libuserservice/user_service.cpp @@ -3,7 +3,7 @@ #include #include -#include "Util/log.h" +#include "common/log.h" namespace Core::Libraries::LibUserService { diff --git a/src/core/virtual_memory.cpp b/src/core/virtual_memory.cpp index 4f0c3c39..f1248554 100644 --- a/src/core/virtual_memory.cpp +++ b/src/core/virtual_memory.cpp @@ -1,5 +1,6 @@ +#include "common/debug.h" +#include "common/log.h" #include "virtual_memory.h" - #include "core/PS4/Loader/Elf.h" #ifdef _WIN64 @@ -19,10 +20,6 @@ enum PosixPageProtection { }; #endif -#include - -#include "../Util/Log.h" - namespace VirtualMemory { static u32 convertMemoryMode(MemoryMode mode) { switch (mode) { diff --git a/src/core/virtual_memory.h b/src/core/virtual_memory.h index 88582b48..6b255301 100644 --- a/src/core/virtual_memory.h +++ b/src/core/virtual_memory.h @@ -1,5 +1,5 @@ #pragma once -#include +#include "common/types.h" constexpr u64 SYSTEM_RESERVED = 0x800000000u; constexpr u64 CODE_BASE_OFFSET = 0x100000000u; diff --git a/src/emuTimer.h b/src/emuTimer.h index bb53f71b..26c20743 100644 --- a/src/emuTimer.h +++ b/src/emuTimer.h @@ -1,9 +1,10 @@ #pragma once -#include "types.h" + +#include "common/types.h" namespace Emulator::emuTimer { void start(); double getTimeMsec(); u64 getTimeCounter(); u64 getTimeFrequency(); -} // namespace Emulator::emuTimer \ No newline at end of file +} // namespace Emulator::emuTimer diff --git a/src/emulator.cpp b/src/emulator.cpp index 94c6f67f..eb914f5c 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -8,8 +8,8 @@ #include "core/PS4/HLE/Graphics/video_out.h" #include "core/hle/libraries/libpad/pad.h" -#include "Emulator/Util/singleton.h" -#include "version.h" +#include "common/singleton.h" +#include "common/version.h" namespace Emu { diff --git a/src/main.cpp b/src/main.cpp index b3fa7dcc..de0061dd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,8 +1,10 @@ #include #include #include -#include "types.h" -#include "Util/log.h" +#include "common/discord.h" +#include "common/types.h" +#include "common/log.h" +#include "common/singleton.h" #include #include #include @@ -11,11 +13,8 @@ #include #include "core/PS4/HLE/Libs.h" #include "core/PS4/Linker.h" -#include "Emulator/Util\singleton.h" -#include "discord.h" #include "emuTimer.h" -// Main code int main(int argc, char* argv[]) { if (argc == 1) { fmt::print("Usage: {} \n", argv[0]); diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index 2dedcd83..ef3bee54 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -2,9 +2,9 @@ #include #include #include -#include -#include -#include +#include "common/singleton.h" +#include "common/log.h" +#include "common/debug.h" #include #include From a0b80893db6f5ef22b30987144057a6c842cfb69 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 14:21:20 +0200 Subject: [PATCH 3/7] cmake: Update CMakeLists.txt --- CMakeLists.txt | 67 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7f812616..4640a580 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,29 +47,34 @@ set(HOST_SOURCES src/Emulator/Host/controller.cpp src/Emulator/Host/controller.h ) -set(UTIL_SOURCES src/Emulator/Util/singleton.h -) - add_executable(shadps4 + src/common/debug.h + src/common/disassembler.cpp + src/common/disassembler.h + src/common/discord.cpp + src/common/discord.h + src/common/fs_file.cpp + src/common/fs_file.h + src/common/log.cpp + src/common/log.h + src/common/singleton.h + src/common/string_util.cpp + src/common/string_util.h + src/common/types.h + src/common/version.h ${LIBC_SOURCES} ${USERSERVICE_SOURCES} ${PAD_SOURCES} ${SYSTEMSERVICE_SOURCES} ${FILESYSTEM_SOURCES} ${HOST_SOURCES} - ${UTIL_SOURCES} src/Lib/Timer.cpp src/Lib/Timer.h src/main.cpp - src/types.h - src/core/FsFile.cpp - src/core/FsFile.h src/core/PS4/Loader/Elf.cpp src/core/PS4/Loader/Elf.h src/GUI/ElfViewer.cpp src/GUI/ElfViewer.h - src/Util/log.h - src/Util/log.cpp src/Util/config.cpp src/Util/config.h src/core/virtual_memory.cpp @@ -81,20 +86,48 @@ add_executable(shadps4 src/core/PS4/Util/aerolib.cpp src/core/PS4/HLE/Kernel/Objects/physical_memory.h src/core/PS4/HLE/Kernel/Objects/physical_memory.cpp - src/Util/string_util.cpp - src/Util/string_util.cpp src/core/PS4/HLE/Graphics/video_out.cpp src/core/PS4/HLE/Graphics/video_out.h - src/discord.h - src/discord.cpp src/core/PS4/HLE/Kernel/event_queues.cpp src/core/PS4/HLE/Kernel/event_queues.h src/core/PS4/HLE/Kernel/cpu_management.cpp src/core/PS4/HLE/Kernel/cpu_management.h - - - - "src/Util/Disassembler.cpp" "src/Util/Disassembler.h" "src/core/PS4/Util/aerolib.h" "src/core/PS4/Loader/SymbolsResolver.h" "src/core/PS4/Loader/SymbolsResolver.cpp" "src/core/PS4/HLE/Libs.cpp" "src/core/PS4/HLE/Libs.h" "src/core/PS4/HLE/LibKernel.cpp" "src/core/PS4/HLE/LibKernel.h" "src/core/PS4/HLE/LibSceGnmDriver.cpp" "src/core/PS4/HLE/LibSceGnmDriver.h" "src/core/PS4/HLE/Kernel/ThreadManagement.cpp" "src/core/PS4/HLE/Kernel/ThreadManagement.h" "src/core/PS4/HLE/ErrorCodes.h" "src/debug.h" "src/core/PS4/HLE/Kernel/memory_management.cpp" "src/core/PS4/HLE/Kernel/memory_management.h" "src/core/PS4/GPU/gpu_memory.cpp" "src/core/PS4/GPU/gpu_memory.h" "src/emulator.cpp" "src/emulator.h" "src/core/PS4/HLE/Kernel/Objects/event_queue.h" "src/core/PS4/HLE/Kernel/Objects/event_queue.cpp" "src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp" "src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h" "src/core/PS4/HLE/Graphics/graphics_ctx.h" "src/vulkan_util.cpp" "src/vulkan_util.h" "src/core/PS4/GPU/video_out_buffer.cpp" "src/core/PS4/GPU/video_out_buffer.h" "src/core/PS4/HLE/Graphics/graphics_render.cpp" "src/core/PS4/HLE/Graphics/graphics_render.h" "src/core/PS4/GPU/tile_manager.cpp" "src/core/PS4/GPU/tile_manager.h" "src/version.h" "src/emuTimer.cpp" "src/emuTimer.h" "src/core/hle/libraries/libkernel/time_management.cpp" "src/core/hle/libraries/libkernel/time_management.h") + src/core/PS4/Util/aerolib.h + src/core/PS4/Loader/SymbolsResolver.h + src/core/PS4/Loader/SymbolsResolver.cpp + src/core/PS4/HLE/Libs.cpp + src/core/PS4/HLE/Libs.h + src/core/PS4/HLE/LibKernel.cpp + src/core/PS4/HLE/LibKernel.h + src/core/PS4/HLE/LibSceGnmDriver.cpp + src/core/PS4/HLE/LibSceGnmDriver.h + src/core/PS4/HLE/Kernel/ThreadManagement.cpp + src/core/PS4/HLE/Kernel/ThreadManagement.h + src/core/PS4/HLE/ErrorCodes.h + src/core/PS4/HLE/Kernel/memory_management.cpp + src/core/PS4/HLE/Kernel/memory_management.h + src/core/PS4/GPU/gpu_memory.cpp + src/core/PS4/GPU/gpu_memory.h + src/emulator.cpp + src/emulator.h + src/core/PS4/HLE/Kernel/Objects/event_queue.h + src/core/PS4/HLE/Kernel/Objects/event_queue.cpp + src/core/PS4/HLE/Graphics/Objects/video_out_ctx.cpp + src/core/PS4/HLE/Graphics/Objects/video_out_ctx.h + src/core/PS4/HLE/Graphics/graphics_ctx.h + src/vulkan_util.cpp + src/vulkan_util.h + src/core/PS4/GPU/video_out_buffer.cpp + src/core/PS4/GPU/video_out_buffer.h + src/core/PS4/HLE/Graphics/graphics_render.cpp + src/core/PS4/HLE/Graphics/graphics_render.h + src/core/PS4/GPU/tile_manager.cpp + src/core/PS4/GPU/tile_manager.h + src/emuTimer.cpp + src/emuTimer.h + src/core/hle/libraries/libkernel/time_management.cpp + src/core/hle/libraries/libkernel/time_management.h +) target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt spdlog::spdlog toml11::toml11) target_link_libraries(shadps4 PRIVATE discord-rpc imgui SDL3-shared vulkan-1 xxhash Zydis) From 996aa9d17a3ca86d46c37e73bd8a2af630c7d578 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 16:30:11 +0200 Subject: [PATCH 4/7] cmake: Add include directory to winpthread --- third-party/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt index 8dcf026e..0e04aae4 100644 --- a/third-party/CMakeLists.txt +++ b/third-party/CMakeLists.txt @@ -35,6 +35,7 @@ target_include_directories(vulkan-1 INTERFACE vulkan/include) # Winpthreads if (WIN32) add_subdirectory(winpthread EXCLUDE_FROM_ALL) + target_include_directories(winpthread INTERFACE winpthread/include) endif() # xxHash From 303f086b1495d3bb97fd380b7c71fc825ac61d59 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 16:56:28 +0200 Subject: [PATCH 5/7] common: Move classes to common namespace --- src/common/debug.h | 4 +- src/common/disassembler.cpp | 30 +++-- src/common/disassembler.h | 14 ++- src/common/log.cpp | 112 +++++++++++------- src/common/log.h | 48 +------- src/common/singleton.h | 12 +- src/common/string_util.cpp | 23 ++-- src/common/string_util.h | 7 +- src/common/types.h | 2 +- src/common/version.h | 7 +- src/core/PS4/GPU/gpu_memory.cpp | 8 +- src/core/PS4/GPU/tile_manager.cpp | 4 +- src/core/PS4/HLE/Graphics/graphics_render.cpp | 12 +- src/core/PS4/HLE/Graphics/video_out.cpp | 28 ++--- src/core/PS4/HLE/Kernel/memory_management.cpp | 30 ++--- src/core/PS4/Linker.cpp | 7 +- src/core/hle/libraries/libc/libc.cpp | 4 +- src/core/hle/libraries/libpad/pad.cpp | 2 +- src/emulator.cpp | 21 ++-- src/main.cpp | 12 +- src/vulkan_util.cpp | 2 +- 21 files changed, 190 insertions(+), 199 deletions(-) diff --git a/src/common/debug.h b/src/common/debug.h index a8d1cb12..dedd19d9 100644 --- a/src/common/debug.h +++ b/src/common/debug.h @@ -1,7 +1,9 @@ +#pragma once + #ifdef _MSC_VER #define BREAKPOINT __debugbreak #elif defined(__GNUC__) #define BREAKPOINT __builtin_trap #else #error What the fuck is this compiler -#endif \ No newline at end of file +#endif diff --git a/src/common/disassembler.cpp b/src/common/disassembler.cpp index e930e0c0..668a230b 100644 --- a/src/common/disassembler.cpp +++ b/src/common/disassembler.cpp @@ -1,35 +1,33 @@ #include "common/disassembler.h" #include -Disassembler::Disassembler() -{ +namespace Common { + +Disassembler::Disassembler() { ZydisDecoderInit(&m_decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64); ZydisFormatterInit(&m_formatter, ZYDIS_FORMATTER_STYLE_INTEL); } -Disassembler::~Disassembler() -{ -} +Disassembler::~Disassembler() = default; -void Disassembler::printInstruction(void* code,u64 address)//print a single instruction -{ +void Disassembler::printInstruction(void* code, u64 address) { ZydisDecodedInstruction instruction; ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE]; - ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code), &instruction, operands); - if (!ZYAN_SUCCESS(status)) - { + ZyanStatus status = ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code), + &instruction, operands); + if (!ZYAN_SUCCESS(status)) { fmt::print("decode instruction failed at {}\n", fmt::ptr(code)); - } - else - { + } else { printInst(instruction, operands,address); } } -void Disassembler::printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands,u64 address) -{ +void Disassembler::printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands, u64 address) { const int bufLen = 256; char szBuffer[bufLen]; - ZydisFormatterFormatInstruction(&m_formatter, &inst, operands,inst.operand_count_visible, szBuffer, sizeof(szBuffer), address, ZYAN_NULL); + ZydisFormatterFormatInstruction(&m_formatter, &inst, operands,inst.operand_count_visible, + szBuffer, sizeof(szBuffer), address, ZYAN_NULL); fmt::print("instruction: {}\n", szBuffer); } + +} // namespace Common diff --git a/src/common/disassembler.h b/src/common/disassembler.h index 3737986f..9933b6a6 100644 --- a/src/common/disassembler.h +++ b/src/common/disassembler.h @@ -3,15 +3,19 @@ #include #include "common/types.h" -class Disassembler -{ +namespace Common { + +class Disassembler { public: Disassembler(); ~Disassembler(); - void printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands,u64 address); - void printInstruction(void* code,u64 address); + + void printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands, u64 address); + void printInstruction(void* code, u64 address); private: - ZydisDecoder m_decoder; + ZydisDecoder m_decoder; ZydisFormatter m_formatter; }; + +} // namespace Common diff --git a/src/common/log.cpp b/src/common/log.cpp index 4b2b91ed..eba58f6f 100644 --- a/src/common/log.cpp +++ b/src/common/log.cpp @@ -3,73 +3,95 @@ #include #include #include - #include #include - +#include "common/log.h" #ifdef _WIN64 -#include +#include #endif -#include "log.h" +namespace Common::Log { -namespace logging { std::vector sinks; -constexpr bool log_file_exceptions = true; // disable it to disable logging +constexpr bool log_file_exceptions = true; -void flush() { spdlog::details::registry::instance().flush_all(); } +void Flush() { + spdlog::details::registry::instance().flush_all(); +} #ifdef _WIN64 - -static LONG WINAPI exception_handler(PEXCEPTION_POINTERS pExp) noexcept { +static LONG WINAPI ExceptionHandler(PEXCEPTION_POINTERS pExp) noexcept { const u32 ec = pExp->ExceptionRecord->ExceptionCode; switch (ec) { - case EXCEPTION_ACCESS_VIOLATION: - LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_ACCESS_VIOLATION ({}). ", log_hex(ec)); - switch (pExp->ExceptionRecord->ExceptionInformation[0]) { - case 0: LOG_CRITICAL_IF(log_file_exceptions,"Read violation at address {}.", log_hex(pExp->ExceptionRecord->ExceptionInformation[1])); break; - case 1: LOG_CRITICAL_IF(log_file_exceptions,"Write violation at address {}.", log_hex(pExp->ExceptionRecord->ExceptionInformation[1])); break; - case 8:LOG_CRITICAL_IF(log_file_exceptions,"DEP violation at address {}.", log_hex(pExp->ExceptionRecord->ExceptionInformation[1])); break; - default: break; + case EXCEPTION_ACCESS_VIOLATION: { + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_ACCESS_VIOLATION ({:#x}). ", ec); + const auto info = pExp->ExceptionRecord->ExceptionInformation; + switch (info[0]) { + case 0: + LOG_CRITICAL_IF(log_file_exceptions, "Read violation at address {:#x}.", info[1]); + break; + case 1: + LOG_CRITICAL_IF(log_file_exceptions, "Write violation at address {:#x}.", info[1]); + break; + case 8: + LOG_CRITICAL_IF(log_file_exceptions, "DEP violation at address {:#x}.", info[1]); + break; + default: + break; } break; - case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_ARRAY_BOUNDS_EXCEEDED ({:#x}). ", ec); break; - case EXCEPTION_DATATYPE_MISALIGNMENT: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_DATATYPE_MISALIGNMENT ({}). ", log_hex(ec)); break; - case EXCEPTION_FLT_DIVIDE_BY_ZERO: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_FLT_DIVIDE_BY_ZERO ({}). ", log_hex(ec)); break; - case EXCEPTION_ILLEGAL_INSTRUCTION: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_ILLEGAL_INSTRUCTION ({}). ", log_hex(ec)); break; - case EXCEPTION_IN_PAGE_ERROR: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_IN_PAGE_ERROR ({}). ", log_hex(ec)); break; - case EXCEPTION_INT_DIVIDE_BY_ZERO: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_INT_DIVIDE_BY_ZERO ({}). ", log_hex(ec)); break; - case EXCEPTION_PRIV_INSTRUCTION: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_PRIV_INSTRUCTION ({}). ", log_hex(ec)); break; - case EXCEPTION_STACK_OVERFLOW: LOG_CRITICAL_IF(log_file_exceptions,"Exception EXCEPTION_STACK_OVERFLOW ({}). ", log_hex(ec)); break; - default: return EXCEPTION_CONTINUE_SEARCH; + } + case EXCEPTION_ARRAY_BOUNDS_EXCEEDED: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_ARRAY_BOUNDS_EXCEEDED ({:#x}). ", ec); + break; + case EXCEPTION_DATATYPE_MISALIGNMENT: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_DATATYPE_MISALIGNMENT ({:#x}). ", ec); + break; + case EXCEPTION_FLT_DIVIDE_BY_ZERO: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_FLT_DIVIDE_BY_ZERO ({:#x}). ", ec); + break; + case EXCEPTION_ILLEGAL_INSTRUCTION: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_ILLEGAL_INSTRUCTION ({:#x}). ", ec); + break; + case EXCEPTION_IN_PAGE_ERROR: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_IN_PAGE_ERROR ({:#x}). ", ec); + break; + case EXCEPTION_INT_DIVIDE_BY_ZERO: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_INT_DIVIDE_BY_ZERO ({:#x}). ", ec); + break; + case EXCEPTION_PRIV_INSTRUCTION: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_PRIV_INSTRUCTION ({:#x}). ", ec); + break; + case EXCEPTION_STACK_OVERFLOW: + LOG_CRITICAL_IF(log_file_exceptions, "Exception EXCEPTION_STACK_OVERFLOW ({:#x}). ", ec); + break; + default: + return EXCEPTION_CONTINUE_SEARCH; } - flush(); + Flush(); return EXCEPTION_CONTINUE_SEARCH; } - -void register_log_exception_handler() { - if (!AddVectoredExceptionHandler(0, exception_handler)) { - LOG_CRITICAL_IF(log_file_exceptions,"Failed to register an exception handler"); - } -} #endif -int init(bool use_stdout) { - sinks.clear(); // clear existing sinks - if (use_stdout) // if we use stdout window then init it as well +int Init(bool use_stdout) { + sinks.clear(); + if (use_stdout) { sinks.push_back(std::make_shared()); + } sinks.push_back(std::make_shared(L"shadps4.txt", true)); spdlog::set_default_logger(std::make_shared("shadps4 logger", begin(sinks), end(sinks))); auto f = std::make_unique("%^|%L|: %v%$", spdlog::pattern_time_type::local, std::string("")); // disable eol spdlog::set_formatter(std::move(f)); spdlog::set_level(static_cast(Config::getLogLevel())); - spdlog::level::level_enum t = spdlog::get_level(); - #ifdef _WIN64 - register_log_exception_handler(); - #endif - static std::terminate_handler old_terminate = nullptr; +#ifdef _WIN64 + if (!AddVectoredExceptionHandler(0, ExceptionHandler)) { + LOG_CRITICAL_IF(log_file_exceptions, "Failed to register an exception handler"); + } +#endif + + static std::terminate_handler old_terminate = nullptr; old_terminate = std::set_terminate([]() { try { std::rethrow_exception(std::current_exception()); @@ -78,13 +100,15 @@ int init(bool use_stdout) { } catch (...) { LOG_CRITICAL_IF(log_file_exceptions, "Unhandled C++ exception. UNKNOWN"); } - flush(); + Flush(); if (old_terminate) old_terminate(); }); - return 0; // all ok + return 0; } -void set_level(spdlog::level::level_enum log_level) { spdlog::set_level(log_level); } +void SetLevel(spdlog::level::level_enum log_level) { + spdlog::set_level(log_level); +} -} // namespace logging \ No newline at end of file +} // namespace Common::Log diff --git a/src/common/log.h b/src/common/log.h index 350d8dc3..1242c6f3 100644 --- a/src/common/log.h +++ b/src/common/log.h @@ -4,7 +4,7 @@ #include -namespace logging { +namespace Common::Log { #define LOG_TRACE SPDLOG_TRACE #define LOG_DEBUG SPDLOG_DEBUG @@ -26,48 +26,8 @@ namespace logging { #define LOG_CRITICAL_IF(flag, ...) \ if (flag) LOG_CRITICAL(__VA_ARGS__) -int init(bool use_stdout); -void set_level(spdlog::level::level_enum log_level); -} // namespace logging +int Init(bool use_stdout); -// copyright vita3k emu https://github.com/Vita3K/Vita3K/blob/master/vita3k/util/include/util/log.h -/* - returns: A string with the input number formatted in hexadecimal - Examples: - * `12` returns: `"0xC"` - * `1337` returns: `"0x539"` - * `72742069` returns: `"0x455F4B5"` -*/ -template -std::string log_hex(T val) { - using unsigned_type = typename std::make_unsigned::type; - std::stringstream ss; - ss << "0x"; - ss << std::hex << static_cast(val); - return ss.str(); -} +void SetLevel(spdlog::level::level_enum log_level); -/* - returns: A string with the input number formatted in hexadecimal with padding of the inputted type size - Examples: - * `uint8_t 5` returns: `"0x05"` - * `uint8_t 15` returns: `"0x0F"` - * `uint8_t 255` returns: `"0xFF"` - - * `uint16_t 15` returns: `"0x000F"` - * `uint16_t 1337` returns: `"0x0539"` - * `uint16_t 65535` returns: `"0xFFFF"` - - - * `uint32_t 15` returns: `"0x0000000F"` - * `uint32_t 1337` returns: `"0x00000539"` - * `uint32_t 65535` returns: `"0x0000FFFF"` - * `uint32_t 134217728` returns: `"0x08000000"` -*/ -template -std::string log_hex_full(T val) { - std::stringstream ss; - ss << "0x"; - ss << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex << val; - return ss.str(); -} +} // namespace Common::Log diff --git a/src/common/singleton.h b/src/common/singleton.h index 01b3751b..c1099547 100644 --- a/src/common/singleton.h +++ b/src/common/singleton.h @@ -2,10 +2,12 @@ #include +namespace Common { + template -class singleton { +class Singleton { public: - static T* instance() { + static T* Instance() { if (!m_instance) { m_instance = std::make_unique(); } @@ -13,9 +15,11 @@ public: } protected: - singleton(); - ~singleton(); + Singleton(); + ~Singleton(); private: static inline std::unique_ptr m_instance{}; }; + +} // namespace Common diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp index 6f1a7403..19f6020c 100644 --- a/src/common/string_util.cpp +++ b/src/common/string_util.cpp @@ -3,21 +3,18 @@ #include #include "common/string_util.h" -namespace StringUtil { +namespace Common { -std::vector split_string(const std::string &str, char delimiter) { - std::stringstream str_stream(str); - std::string segment; - std::vector seglist; +std::vector SplitString(const std::string &str, char delimiter) { + std::istringstream iss(str); + std::vector output(1); - const size_t num_segments = std::count_if(str.begin(), str.end(), [&](char c) { return c == delimiter; }) + (str.empty() ? 1 : 0); - - seglist.reserve(num_segments); - - while (std::getline(str_stream, segment, delimiter)) { - seglist.push_back(segment); + while (std::getline(iss, *output.rbegin(), delimiter)) { + output.emplace_back(); } - return seglist; + + output.pop_back(); + return output; } -} // namespace StringUtil \ No newline at end of file +} // namespace Common diff --git a/src/common/string_util.h b/src/common/string_util.h index 97d8eb85..a9a8c888 100644 --- a/src/common/string_util.h +++ b/src/common/string_util.h @@ -1,9 +1,10 @@ #pragma once + #include #include -namespace StringUtil { +namespace Common { - std::vector split_string(const std::string& str, char delimiter); +std::vector SplitString(const std::string& str, char delimiter); -} \ No newline at end of file +} // namespace Common diff --git a/src/common/types.h b/src/common/types.h index d74b42b5..9ddfede9 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -1,4 +1,5 @@ #pragma once + #include using s08 = std::int8_t; @@ -16,7 +17,6 @@ using f64 = double; #define PS4_SYSV_ABI __attribute__((sysv_abi)) - // UDLs for memory size values constexpr u64 operator""_KB(u64 x) { return 1024ULL * x; } constexpr u64 operator""_MB(u64 x) { return 1024_KB * x; } diff --git a/src/common/version.h b/src/common/version.h index a64a2fae..e9135885 100644 --- a/src/common/version.h +++ b/src/common/version.h @@ -1,7 +1,10 @@ #pragma once + #include #include -namespace Emulator { +namespace Common { + constexpr char VERSION[] = "0.0.3 WIP"; -} \ No newline at end of file + +} // namespace Common diff --git a/src/core/PS4/GPU/gpu_memory.cpp b/src/core/PS4/GPU/gpu_memory.cpp index 6ad56cc3..c278f37e 100644 --- a/src/core/PS4/GPU/gpu_memory.cpp +++ b/src/core/PS4/GPU/gpu_memory.cpp @@ -6,13 +6,13 @@ void* GPU::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo /*CommandBuffer?*/, u64 virtual_addr, u64 size, const GPUObject& info) { - auto* gpumemory = singleton::instance(); + auto* gpumemory = Common::Singleton::Instance(); return gpumemory->memoryCreateObj(submit_id, ctx, nullptr, &virtual_addr, &size, 1, info); } void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) { - auto* gpumemory = singleton::instance(); + auto* gpumemory = Common::Singleton::Instance(); std::scoped_lock lock{gpumemory->m_mutex}; @@ -59,7 +59,7 @@ bool GPU::vulkanAllocateMemory(HLE::Libs::Graphics::GraphicCtx* ctx, HLE::Libs:: } void GPU::flushGarlic(HLE::Libs::Graphics::GraphicCtx* ctx) { - auto* gpumemory = singleton::instance(); + auto* gpumemory = Common::Singleton::Instance(); gpumemory->flushAllHeaps(ctx); } @@ -78,7 +78,7 @@ int GPU::GPUMemory::getHeapId(u64 virtual_addr, u64 size) { void* GPU::GPUMemory::memoryCreateObj(u64 submit_id, HLE::Libs::Graphics::GraphicCtx* ctx, void* todo, const u64* virtual_addr, const u64* size, int virtual_addr_num, const GPUObject& info) { - auto* gpumemory = singleton::instance(); + auto* gpumemory = Common::Singleton::Instance(); std::scoped_lock lock{gpumemory->m_mutex}; diff --git a/src/core/PS4/GPU/tile_manager.cpp b/src/core/PS4/GPU/tile_manager.cpp index 01b94f47..9a362243 100644 --- a/src/core/PS4/GPU/tile_manager.cpp +++ b/src/core/PS4/GPU/tile_manager.cpp @@ -143,7 +143,7 @@ void convertTileToLinear(void* dst, const void* src,u32 width, u32 height, bool TileManager32 t; t.Init(width, height, is_neo); - auto* g_TileManager = singleton::instance(); + auto* g_TileManager = Common::Singleton::Instance(); std::scoped_lock lock{g_TileManager->m_mutex}; @@ -166,4 +166,4 @@ void convertTileToLinear(void* dst, const void* src,u32 width, u32 height, bool } } } -} // namespace GPU \ No newline at end of file +} // namespace GPU diff --git a/src/core/PS4/HLE/Graphics/graphics_render.cpp b/src/core/PS4/HLE/Graphics/graphics_render.cpp index 7af3a257..84dae4c0 100644 --- a/src/core/PS4/HLE/Graphics/graphics_render.cpp +++ b/src/core/PS4/HLE/Graphics/graphics_render.cpp @@ -6,7 +6,7 @@ static thread_local GPU::CommandPool g_command_pool; void GPU::renderCreateCtx() { - auto* render_ctx = singleton::instance(); + auto* render_ctx = Common::Singleton::Instance(); render_ctx->setGraphicCtx(Emu::getGraphicCtx()); } @@ -37,7 +37,7 @@ void GPU::CommandBuffer::freeBuffer() { } void GPU::CommandBuffer::waitForFence() { - auto* render_ctx = singleton::instance(); + auto* render_ctx = Common::Singleton::Instance(); if (m_execute) { auto* device = render_ctx->getGraphicCtx()->m_device; @@ -89,7 +89,7 @@ void GPU::CommandBuffer::executeWithSemaphore() { submit_info.signalSemaphoreCount = 1; submit_info.pSignalSemaphores = &m_pool->semaphores[m_index]; - auto* render_ctx = singleton::instance(); + auto* render_ctx = Common::Singleton::Instance(); const auto& queue = render_ctx->getGraphicCtx()->queues[m_queue]; auto result = vkQueueSubmit(queue.vk_queue, 1, &submit_info, fence); @@ -115,7 +115,7 @@ void GPU::CommandBuffer::execute() { submit_info.signalSemaphoreCount = 0; submit_info.pSignalSemaphores = nullptr; - auto* render_ctx = singleton::instance(); + auto* render_ctx = Common::Singleton::Instance(); const auto& queue = render_ctx->getGraphicCtx()->queues[m_queue]; auto result = vkQueueSubmit(queue.vk_queue, 1, &submit_info, fence); @@ -127,7 +127,7 @@ void GPU::CommandBuffer::execute() { } } void GPU::CommandPool::createPool(int id) { - auto* render_ctx = singleton::instance(); + auto* render_ctx = Common::Singleton::Instance(); auto* ctx = render_ctx->getGraphicCtx(); VkCommandPoolCreateInfo pool_info{}; @@ -186,7 +186,7 @@ void GPU::CommandPool::createPool(int id) { } void GPU::CommandPool::deleteAllPool() { - auto* render_ctx = singleton::instance(); + auto* render_ctx = Common::Singleton::Instance(); auto* ctx = render_ctx->getGraphicCtx(); for (auto& pool : m_pool) { diff --git a/src/core/PS4/HLE/Graphics/video_out.cpp b/src/core/PS4/HLE/Graphics/video_out.cpp index bb71eec3..cbd08386 100644 --- a/src/core/PS4/HLE/Graphics/video_out.cpp +++ b/src/core/PS4/HLE/Graphics/video_out.cpp @@ -24,12 +24,12 @@ namespace HLE::Libs::Graphics::VideoOut { constexpr bool log_file_videoout = true; // disable it to disable logging void videoOutInit(u32 width, u32 height) { - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); videoOut->Init(width, height); } bool videoOutFlip(u32 micros) { - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); return videoOut->getFlipQueue().flip(micros); } @@ -87,7 +87,7 @@ static void flip_delete_event_func(LibKernel::EventQueues::SceKernelEqueue eq, H s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue eq, s32 handle, void* udata) { PRINT_FUNCTION_NAME(); - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); auto* ctx = videoOut->getCtx(handle); @@ -122,7 +122,7 @@ s32 PS4_SYSV_ABI sceVideoOutAddFlipEvent(LibKernel::EventQueues::SceKernelEqueue s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* const* addresses, s32 bufferNum, const SceVideoOutBufferAttribute* attribute) { PRINT_FUNCTION_NAME(); - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); auto* ctx = videoOut->getCtx(handle); if (handle == 1) { // main port @@ -154,7 +154,7 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co } LOG_INFO_IF(log_file_videoout, "startIndex = {}\n", startIndex); LOG_INFO_IF(log_file_videoout, "bufferNum = {}\n", bufferNum); - LOG_INFO_IF(log_file_videoout, "pixelFormat = {}\n", log_hex_full(attribute->pixelFormat)); + LOG_INFO_IF(log_file_videoout, "pixelFormat = {:#x}\n", attribute->pixelFormat); LOG_INFO_IF(log_file_videoout, "tilingMode = {}\n", attribute->tilingMode); LOG_INFO_IF(log_file_videoout, "aspectRatio = {}\n", attribute->aspectRatio); LOG_INFO_IF(log_file_videoout, "width = {}\n", attribute->width); @@ -208,26 +208,26 @@ s32 PS4_SYSV_ABI sceVideoOutRegisterBuffers(s32 handle, s32 startIndex, void* co ctx->buffers[i + startIndex].buffer_render = static_cast( GPU::memoryCreateObj(0, videoOut->getGraphicCtx(), nullptr, reinterpret_cast(addresses[i]), buffer_size, buffer_info)); - LOG_INFO_IF(log_file_videoout, "buffers[{}] = {}\n", i + startIndex, log_hex_full(reinterpret_cast(addresses[i]))); + LOG_INFO_IF(log_file_videoout, "buffers[{}] = {:#x}\n", i + startIndex, reinterpret_cast(addresses[i])); } return registration_index; } s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate) { PRINT_FUNCTION_NAME(); - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); videoOut->getCtx(handle)->m_flip_rate = rate; return SCE_OK; } s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) { PRINT_FUNCTION_NAME(); - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); s32 pending = videoOut->getCtx(handle)->m_flip_status.flipPendingNum; return pending; } s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode, s64 flipArg) { PRINT_FUNCTION_NAME(); - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); auto* ctx = videoOut->getCtx(handle); if (flipMode != 1) { @@ -254,7 +254,7 @@ s32 PS4_SYSV_ABI sceVideoOutSubmitFlip(s32 handle, s32 bufferIndex, s32 flipMode } s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* status) { PRINT_FUNCTION_NAME(); - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); auto* ctx = videoOut->getCtx(handle); videoOut->getFlipQueue().getFlipStatus(ctx, status); @@ -270,7 +270,7 @@ s32 PS4_SYSV_ABI sceVideoOutGetFlipStatus(s32 handle, SceVideoOutFlipStatus* sta } s32 PS4_SYSV_ABI sceVideoOutGetResolutionStatus(s32 handle, SceVideoOutResolutionStatus* status) { PRINT_FUNCTION_NAME(); - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); *status = videoOut->getCtx(handle)->m_resolution; return SCE_OK; } @@ -289,7 +289,7 @@ s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 i if (param != nullptr) { BREAKPOINT(); } - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); int handle = videoOut->Open(); if (handle < 0) { @@ -300,7 +300,7 @@ s32 PS4_SYSV_ABI sceVideoOutOpen(SceUserServiceUserId userId, s32 busType, s32 i return handle; } s32 PS4_SYSV_ABI sceVideoOutClose(s32 handle) { - auto* videoOut = singleton::instance(); + auto* videoOut = Common::Singleton::Instance(); videoOut->Close(handle); return SCE_OK; } @@ -319,4 +319,4 @@ void videoOutRegisterLib(SymbolsResolver* sym) { LIB_FUNCTION("N5KDtkIjjJ4", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutUnregisterBuffers); LIB_FUNCTION("uquVH4-Du78", "libSceVideoOut", 1, "libSceVideoOut", 0, 0, sceVideoOutClose); } -} // namespace HLE::Libs::Graphics::VideoOut \ No newline at end of file +} // namespace HLE::Libs::Graphics::VideoOut diff --git a/src/core/PS4/HLE/Kernel/memory_management.cpp b/src/core/PS4/HLE/Kernel/memory_management.cpp index dc39ad9a..379e4e23 100644 --- a/src/core/PS4/HLE/Kernel/memory_management.cpp +++ b/src/core/PS4/HLE/Kernel/memory_management.cpp @@ -48,20 +48,20 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u } auto memtype = magic_enum::enum_cast(memoryType); - LOG_INFO_IF(log_file_memory, "search_start = {}\n", log_hex_full(searchStart)); - LOG_INFO_IF(log_file_memory, "search_end = {}\n", log_hex_full(searchEnd)); - LOG_INFO_IF(log_file_memory, "len = {}\n", log_hex_full(len)); - LOG_INFO_IF(log_file_memory, "alignment = {}\n", log_hex_full(alignment)); + LOG_INFO_IF(log_file_memory, "search_start = {:#x}\n", searchStart); + LOG_INFO_IF(log_file_memory, "search_end = {:#x}\n", searchEnd); + LOG_INFO_IF(log_file_memory, "len = {:#x}\n", len); + LOG_INFO_IF(log_file_memory, "alignment = {:#x}\n", alignment); LOG_INFO_IF(log_file_memory, "memory_type = {}\n", magic_enum::enum_name(memtype.value())); u64 physical_addr = 0; - auto* physical_memory = singleton::instance(); + auto* physical_memory = Common::Singleton::Instance(); if (!physical_memory->Alloc(searchStart, searchEnd, len, alignment, &physical_addr, memoryType)) { LOG_TRACE_IF(log_file_memory, "sceKernelAllocateDirectMemory returned SCE_KERNEL_ERROR_EAGAIN can't allocate physical memory\n"); return SCE_KERNEL_ERROR_EAGAIN; } *physAddrOut = static_cast(physical_addr); - LOG_INFO_IF(true, "physAddrOut = {}\n", log_hex_full(physical_addr)); + LOG_INFO_IF(true, "physAddrOut = {:#x}\n", physical_addr); return SCE_OK; } @@ -82,11 +82,11 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl } } - LOG_INFO_IF(log_file_memory, "len = {}\n", log_hex_full(len)); - LOG_INFO_IF(log_file_memory, "prot = {}\n", log_hex_full(prot)); - LOG_INFO_IF(log_file_memory, "flags = {}\n", log_hex_full(flags)); - LOG_INFO_IF(log_file_memory, "directMemoryStart = {}\n", log_hex_full(directMemoryStart)); - LOG_INFO_IF(log_file_memory, "alignment = {}\n", log_hex_full(alignment)); + LOG_INFO_IF(log_file_memory, "len = {:#x}\n", len); + LOG_INFO_IF(log_file_memory, "prot = {:#x}\n", prot); + LOG_INFO_IF(log_file_memory, "flags = {:#x}\n", flags); + LOG_INFO_IF(log_file_memory, "directMemoryStart = {:#x}\n", directMemoryStart); + LOG_INFO_IF(log_file_memory, "alignment = {:#x}\n", alignment); VirtualMemory::MemoryMode cpu_mode = VirtualMemory::MemoryMode::NoAccess; GPU::MemoryMode gpu_mode = GPU::MemoryMode::NoAccess; @@ -106,8 +106,8 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl if (flags == 0) { out_addr = VirtualMemory::memory_alloc_aligned(in_addr, len, cpu_mode, alignment); } - LOG_INFO_IF(log_file_memory, "in_addr = {}\n", log_hex_full(in_addr)); - LOG_INFO_IF(log_file_memory, "out_addr = {}\n", log_hex_full(out_addr)); + LOG_INFO_IF(log_file_memory, "in_addr = {:#x}\n", in_addr); + LOG_INFO_IF(log_file_memory, "out_addr = {:#x}\n", out_addr); *addr = reinterpret_cast(out_addr); // return out_addr to first functions parameter @@ -115,7 +115,7 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl return SCE_KERNEL_ERROR_ENOMEM; } - auto* physical_memory = singleton::instance(); + auto* physical_memory = Common::Singleton::Instance(); if (!physical_memory->Map(out_addr, directMemoryStart, len, prot, cpu_mode, gpu_mode)) { BREAKPOINT(); } @@ -126,4 +126,4 @@ int PS4_SYSV_ABI sceKernelMapDirectMemory(void** addr, u64 len, int prot, int fl return SCE_OK; } -} // namespace HLE::Libs::LibKernel::MemoryManagement \ No newline at end of file +} // namespace HLE::Libs::LibKernel::MemoryManagement diff --git a/src/core/PS4/Linker.cpp b/src/core/PS4/Linker.cpp index ac300d39..d4c48305 100644 --- a/src/core/PS4/Linker.cpp +++ b/src/core/PS4/Linker.cpp @@ -412,7 +412,7 @@ void Linker::LoadSymbols(Module* m) sym++) { std::string id = std::string(m->dynamic_info.str_table + sym->st_name); - auto ids = StringUtil::split_string(id, '#'); + const auto ids = Common::SplitString(id, '#'); if (ids.size() == 3)//symbols are 3 parts name , library , module { const auto* library = FindLibrary(*m, ids.at(1)); @@ -575,9 +575,8 @@ void Linker::Relocate(Module* m) } } -void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info) { - auto ids = StringUtil::split_string(name, '#'); - +void Linker::Resolve(const std::string& name, int Symtype, Module* m, SymbolRecord* return_info) { + const auto ids = Common::SplitString(name, '#'); if (ids.size() == 3) // symbols are 3 parts name , library , module { const auto* library = FindLibrary(*m, ids.at(1)); diff --git a/src/core/hle/libraries/libc/libc.cpp b/src/core/hle/libraries/libc/libc.cpp index 765941d4..44bdde44 100644 --- a/src/core/hle/libraries/libc/libc.cpp +++ b/src/core/hle/libraries/libc/libc.cpp @@ -30,7 +30,7 @@ struct CContext { }; static PS4_SYSV_ABI int __cxa_atexit(void (*func)(void*), void* arg, void* dso_handle) { - auto* cc = singleton::instance(); + auto* cc = Common::Singleton::Instance(); CxaDestructor c{}; c.destructor_func = func; c.destructor_object = arg; @@ -127,4 +127,4 @@ void libcSymbolsRegister(SymbolsResolver* sym) { LIB_FUNCTION("zr094EQ39Ww", "libc", 1, "libc", 1, 1, __cxa_pure_virtual); } -}; // namespace Core::Libraries::LibC \ No newline at end of file +}; // namespace Core::Libraries::LibC diff --git a/src/core/hle/libraries/libpad/pad.cpp b/src/core/hle/libraries/libpad/pad.cpp index 4ed9d2b0..298dd52d 100644 --- a/src/core/hle/libraries/libpad/pad.cpp +++ b/src/core/hle/libraries/libpad/pad.cpp @@ -21,7 +21,7 @@ int PS4_SYSV_ABI scePadOpen(Core::Libraries::LibUserService::SceUserServiceUserI } int PS4_SYSV_ABI scePadReadState(int32_t handle, ScePadData* pData) { - auto* controller = singleton::instance(); + auto* controller = Common::Singleton::Instance(); int connectedCount = 0; bool isConnected = false; diff --git a/src/emulator.cpp b/src/emulator.cpp index eb914f5c..ae92c407 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -27,14 +27,13 @@ int m_fps_frames_num = {0}; double m_fps_start_time = {0}; void emuInit(u32 width, u32 height) { - auto* window_ctx = singleton::instance(); - + auto window_ctx = Common::Singleton::Instance(); window_ctx->m_graphic_ctx.screen_width = width; window_ctx->m_graphic_ctx.screen_height = height; } void checkAndWaitForGraphicsInit() { - auto* window_ctx = singleton::instance(); + auto window_ctx = Common::Singleton::Instance(); std::unique_lock lock{window_ctx->m_mutex}; while (!window_ctx->m_is_graphic_initialized) { @@ -49,7 +48,7 @@ static void CreateSdlWindow(WindowCtx* ctx) { fmt::print("{}\n", SDL_GetError()); std::exit(0); } - std::string title = "shadps4 v" + std::string(Emulator::VERSION); + std::string title = "shadps4 v" + std::string(Common::VERSION); ctx->m_window = SDL_CreateWindowWithPosition(title.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, (static_cast(SDL_WINDOW_HIDDEN) | static_cast(SDL_WINDOW_VULKAN))); @@ -95,7 +94,7 @@ static void calculateFps(double game_time_s) { void emuRun() { Lib::Timer timer; timer.Start(); - auto* window_ctx = singleton::instance(); + auto window_ctx = Common::Singleton::Instance(); { // init window and wait until init finishes std::scoped_lock lock{window_ctx->m_mutex}; @@ -197,19 +196,20 @@ void emuRun() { } HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { - auto* window_ctx = singleton::instance(); + auto window_ctx = Common::Singleton::Instance(); std::scoped_lock lock{window_ctx->m_mutex}; return &window_ctx->m_graphic_ctx; } void updateSDLTitle() { char title[256]; - sprintf(title, "shadps4 v %s FPS: %f", Emulator::VERSION, m_current_fps); - auto* window_ctx = singleton::instance(); + sprintf(title, "shadps4 v %s FPS: %f", Common::VERSION, m_current_fps); + auto window_ctx = Common::Singleton::Instance(); SDL_SetWindowTitle(window_ctx->m_window, title); } + void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) { - auto* window_ctx = singleton::instance(); + auto window_ctx = Common::Singleton::Instance(); if (window_ctx->is_window_hidden) { SDL_ShowWindow(window_ctx->m_window); window_ctx->is_window_hidden = false; @@ -316,11 +316,10 @@ void keyboardEvent(SDL_Event* event) { case SDLK_KP_2: button = ScePadButton ::SCE_PAD_BUTTON_CROSS; break; case SDLK_KP_4: button = ScePadButton ::SCE_PAD_BUTTON_SQUARE; break; case SDLK_RETURN: button = ScePadButton ::SCE_PAD_BUTTON_OPTIONS; break; - default: break; } if (button != 0) { - auto* controller = singleton::instance(); + auto* controller = Common::Singleton::Instance(); controller->checKButton(0, button, event->type == SDL_EVENT_KEY_DOWN); } } diff --git a/src/main.cpp b/src/main.cpp index de0061dd..4f19cd2a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,21 +21,21 @@ int main(int argc, char* argv[]) { return -1; } Config::load("config.toml"); - logging::init(true); // init logging + Common::Log::Init(true); auto width = Config::getScreenWidth(); auto height = Config::getScreenHeight(); Emu::emuInit(width, height); HLE::Libs::Graphics::VideoOut::videoOutInit(width, height); Emulator::emuTimer::start(); - const char* const path = argv[1]; // argument 1 is the path of self file to boot + // Argument 1 is the path of self file to boot + const char* const path = argv[1]; - auto linker = singleton::instance(); + auto linker = Common::Singleton::Instance(); HLE::Libs::Init_HLE_Libs(&linker->getHLESymbols()); - linker->LoadModule(path); // Load main executable + linker->LoadModule(path); std::jthread mainthread( - [](std::stop_token stop_token, void*) { - auto* linker = singleton::instance(); + [linker](std::stop_token stop_token, void*) { linker->Execute(); }, nullptr); diff --git a/src/vulkan_util.cpp b/src/vulkan_util.cpp index ef3bee54..1c2bc5b0 100644 --- a/src/vulkan_util.cpp +++ b/src/vulkan_util.cpp @@ -79,7 +79,7 @@ void Graphics::Vulkan::vulkanCreate(Emu::WindowCtx* ctx) { } Emu::VulkanSwapchain Graphics::Vulkan::vulkanCreateSwapchain(HLE::Libs::Graphics::GraphicCtx* ctx, u32 image_count) { - auto window_ctx = singleton::instance(); + auto window_ctx = Common::Singleton::Instance(); const auto& capabilities = window_ctx->m_surface_capabilities.capabilities; Emu::VulkanSwapchain s{}; From 1cf032eeb163975d8ee1a61aaf9ed1cb71006c4b Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 17:08:47 +0200 Subject: [PATCH 6/7] cmake: Add directory groups --- CMakeLists.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4640a580..4c3a85b1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,24 @@ endif() project(shadps4) +# This function should be passed a list of all files in a target. It will automatically generate +# file groups following the directory hierarchy, so that the layout of the files in IDEs matches the +# one in the filesystem. +function(create_target_directory_groups target_name) + # Place any files that aren't in the source list in a separate group so that they don't get in + # the way. + source_group("Other Files" REGULAR_EXPRESSION ".") + + get_target_property(target_sources "${target_name}" SOURCES) + + foreach(file_name IN LISTS target_sources) + get_filename_component(dir_name "${file_name}" PATH) + # Group names use '\' as a separator even though the entire rest of CMake uses '/'... + string(REPLACE "/" "\\" group_name "${dir_name}") + source_group("${group_name}" FILES "${file_name}") + endforeach() +endfunction() + add_subdirectory(third-party) include_directories(src) @@ -129,6 +147,8 @@ add_executable(shadps4 src/core/hle/libraries/libkernel/time_management.h ) +create_target_directory_groups(shadps4) + target_link_libraries(shadps4 PRIVATE magic_enum::magic_enum fmt::fmt spdlog::spdlog toml11::toml11) target_link_libraries(shadps4 PRIVATE discord-rpc imgui SDL3-shared vulkan-1 xxhash Zydis) if (WIN32) From 7bccfeb8cc9a5d3397d021d82e1a96ec1bedf55f Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 17:14:39 +0200 Subject: [PATCH 7/7] emulator: Use fmt::format instead of snprintf --- src/emulator.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/emulator.cpp b/src/emulator.cpp index ae92c407..2fdd01fb 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -202,10 +202,9 @@ HLE::Libs::Graphics::GraphicCtx* getGraphicCtx() { } void updateSDLTitle() { - char title[256]; - sprintf(title, "shadps4 v %s FPS: %f", Common::VERSION, m_current_fps); + const auto title = fmt::format("shadps4 v {} FPS: {}", Common::VERSION, m_current_fps); auto window_ctx = Common::Singleton::Instance(); - SDL_SetWindowTitle(window_ctx->m_window, title); + SDL_SetWindowTitle(window_ctx->m_window, title.c_str()); } void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {