From 303f086b1495d3bb97fd380b7c71fc825ac61d59 Mon Sep 17 00:00:00 2001 From: GPUCode Date: Sun, 5 Nov 2023 16:56:28 +0200 Subject: [PATCH] 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{};