common: Move classes to common namespace

This commit is contained in:
GPUCode 2023-11-05 16:56:28 +02:00
parent 996aa9d17a
commit 303f086b14
21 changed files with 190 additions and 199 deletions

View file

@ -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
#endif

View file

@ -1,35 +1,33 @@
#include "common/disassembler.h"
#include <fmt/format.h>
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

View file

@ -3,15 +3,19 @@
#include <Zydis/Zydis.h>
#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

View file

@ -3,73 +3,95 @@
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/sinks/stdout_color_sinks.h>
#include <spdlog/spdlog.h>
#include <vector>
#include <Util/config.h>
#include "common/log.h"
#ifdef _WIN64
#include <Windows.h>
#include <windows.h>
#endif
#include "log.h"
namespace Common::Log {
namespace logging {
std::vector<spdlog::sink_ptr> 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<spdlog::sinks::stdout_color_sink_mt>());
}
sinks.push_back(std::make_shared<spdlog::sinks::basic_file_sink_mt>(L"shadps4.txt", true));
spdlog::set_default_logger(std::make_shared<spdlog::logger>("shadps4 logger", begin(sinks), end(sinks)));
auto f = std::make_unique<spdlog::pattern_formatter>("%^|%L|: %v%$", spdlog::pattern_time_type::local, std::string("")); // disable eol
spdlog::set_formatter(std::move(f));
spdlog::set_level(static_cast<spdlog::level::level_enum>(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
} // namespace Common::Log

View file

@ -4,7 +4,7 @@
#include <spdlog/spdlog.h>
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 <typename T>
std::string log_hex(T val) {
using unsigned_type = typename std::make_unsigned<T>::type;
std::stringstream ss;
ss << "0x";
ss << std::hex << static_cast<unsigned_type>(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 <typename T>
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

View file

@ -2,10 +2,12 @@
#include <memory>
namespace Common {
template <class T>
class singleton {
class Singleton {
public:
static T* instance() {
static T* Instance() {
if (!m_instance) {
m_instance = std::make_unique<T>();
}
@ -13,9 +15,11 @@ public:
}
protected:
singleton();
~singleton();
Singleton();
~Singleton();
private:
static inline std::unique_ptr<T> m_instance{};
};
} // namespace Common

View file

@ -3,21 +3,18 @@
#include <string>
#include "common/string_util.h"
namespace StringUtil {
namespace Common {
std::vector<std::string> split_string(const std::string &str, char delimiter) {
std::stringstream str_stream(str);
std::string segment;
std::vector<std::string> seglist;
std::vector<std::string> SplitString(const std::string &str, char delimiter) {
std::istringstream iss(str);
std::vector<std::string> 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
} // namespace Common

View file

@ -1,9 +1,10 @@
#pragma once
#include <vector>
#include <string>
namespace StringUtil {
namespace Common {
std::vector<std::string> split_string(const std::string& str, char delimiter);
std::vector<std::string> SplitString(const std::string& str, char delimiter);
}
} // namespace Common

View file

@ -1,4 +1,5 @@
#pragma once
#include <cstdint>
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; }

View file

@ -1,7 +1,10 @@
#pragma once
#include <string>
#include <string_view>
namespace Emulator {
namespace Common {
constexpr char VERSION[] = "0.0.3 WIP";
}
} // namespace Common

View file

@ -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<GPUMemory>::instance();
auto* gpumemory = Common::Singleton<GPUMemory>::Instance();
return gpumemory->memoryCreateObj(submit_id, ctx, nullptr, &virtual_addr, &size, 1, info);
}
void GPU::memorySetAllocArea(u64 virtual_addr, u64 size) {
auto* gpumemory = singleton<GPUMemory>::instance();
auto* gpumemory = Common::Singleton<GPUMemory>::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<GPUMemory>::instance();
auto* gpumemory = Common::Singleton<GPUMemory>::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<GPUMemory>::instance();
auto* gpumemory = Common::Singleton<GPUMemory>::Instance();
std::scoped_lock lock{gpumemory->m_mutex};

View file

@ -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<TileManager>::instance();
auto* g_TileManager = Common::Singleton<TileManager>::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
} // namespace GPU

View file

@ -6,7 +6,7 @@
static thread_local GPU::CommandPool g_command_pool;
void GPU::renderCreateCtx() {
auto* render_ctx = singleton<RenderCtx>::instance();
auto* render_ctx = Common::Singleton<RenderCtx>::Instance();
render_ctx->setGraphicCtx(Emu::getGraphicCtx());
}
@ -37,7 +37,7 @@ void GPU::CommandBuffer::freeBuffer() {
}
void GPU::CommandBuffer::waitForFence() {
auto* render_ctx = singleton<RenderCtx>::instance();
auto* render_ctx = Common::Singleton<RenderCtx>::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<RenderCtx>::instance();
auto* render_ctx = Common::Singleton<RenderCtx>::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<RenderCtx>::instance();
auto* render_ctx = Common::Singleton<RenderCtx>::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<RenderCtx>::instance();
auto* render_ctx = Common::Singleton<RenderCtx>::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<RenderCtx>::instance();
auto* render_ctx = Common::Singleton<RenderCtx>::Instance();
auto* ctx = render_ctx->getGraphicCtx();
for (auto& pool : m_pool) {

View file

@ -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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
videoOut->Init(width, height);
}
bool videoOutFlip(u32 micros) {
auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<Graphics::VideoOutVulkanImage*>(
GPU::memoryCreateObj(0, videoOut->getGraphicCtx(), nullptr, reinterpret_cast<uint64_t>(addresses[i]), buffer_size, buffer_info));
LOG_INFO_IF(log_file_videoout, "buffers[{}] = {}\n", i + startIndex, log_hex_full(reinterpret_cast<uint64_t>(addresses[i])));
LOG_INFO_IF(log_file_videoout, "buffers[{}] = {:#x}\n", i + startIndex, reinterpret_cast<u64>(addresses[i]));
}
return registration_index;
}
s32 PS4_SYSV_ABI sceVideoOutSetFlipRate(s32 handle, s32 rate) {
PRINT_FUNCTION_NAME();
auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::Instance();
videoOut->getCtx(handle)->m_flip_rate = rate;
return SCE_OK;
}
s32 PS4_SYSV_ABI sceVideoOutIsFlipPending(s32 handle) {
PRINT_FUNCTION_NAME();
auto* videoOut = singleton<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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<HLE::Graphics::Objects::VideoOutCtx>::instance();
auto* videoOut = Common::Singleton<HLE::Graphics::Objects::VideoOutCtx>::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
} // namespace HLE::Libs::Graphics::VideoOut

View file

@ -48,20 +48,20 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u
}
auto memtype = magic_enum::enum_cast<MemoryTypes>(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<HLE::Kernel::Objects::PhysicalMemory>::instance();
auto* physical_memory = Common::Singleton<HLE::Kernel::Objects::PhysicalMemory>::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<s64>(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<void*>(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<HLE::Kernel::Objects::PhysicalMemory>::instance();
auto* physical_memory = Common::Singleton<HLE::Kernel::Objects::PhysicalMemory>::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
} // namespace HLE::Libs::LibKernel::MemoryManagement

View file

@ -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));

View file

@ -30,7 +30,7 @@ struct CContext {
};
static PS4_SYSV_ABI int __cxa_atexit(void (*func)(void*), void* arg, void* dso_handle) {
auto* cc = singleton<CContext>::instance();
auto* cc = Common::Singleton<CContext>::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
}; // namespace Core::Libraries::LibC

View file

@ -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<Emulator::Host::Controller::GameController>::instance();
auto* controller = Common::Singleton<Emulator::Host::Controller::GameController>::Instance();
int connectedCount = 0;
bool isConnected = false;

View file

@ -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<Emu::WindowCtx>::instance();
auto window_ctx = Common::Singleton<Emu::WindowCtx>::Instance();
window_ctx->m_graphic_ctx.screen_width = width;
window_ctx->m_graphic_ctx.screen_height = height;
}
void checkAndWaitForGraphicsInit() {
auto* window_ctx = singleton<Emu::WindowCtx>::instance();
auto window_ctx = Common::Singleton<Emu::WindowCtx>::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<uint32_t>(SDL_WINDOW_HIDDEN) | static_cast<uint32_t>(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<Emu::WindowCtx>::instance();
auto window_ctx = Common::Singleton<Emu::WindowCtx>::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<Emu::WindowCtx>::instance();
auto window_ctx = Common::Singleton<Emu::WindowCtx>::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<Emu::WindowCtx>::instance();
sprintf(title, "shadps4 v %s FPS: %f", Common::VERSION, m_current_fps);
auto window_ctx = Common::Singleton<Emu::WindowCtx>::Instance();
SDL_SetWindowTitle(window_ctx->m_window, title);
}
void DrawBuffer(HLE::Libs::Graphics::VideoOutVulkanImage* image) {
auto* window_ctx = singleton<Emu::WindowCtx>::instance();
auto window_ctx = Common::Singleton<Emu::WindowCtx>::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<Emulator::Host::Controller::GameController>::instance();
auto* controller = Common::Singleton<Emulator::Host::Controller::GameController>::Instance();
controller->checKButton(0, button, event->type == SDL_EVENT_KEY_DOWN);
}
}

View file

@ -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<Linker>::instance();
auto linker = Common::Singleton<Linker>::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<Linker>::instance();
[linker](std::stop_token stop_token, void*) {
linker->Execute();
},
nullptr);

View file

@ -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<Emu::WindowCtx>::instance();
auto window_ctx = Common::Singleton<Emu::WindowCtx>::Instance();
const auto& capabilities = window_ctx->m_surface_capabilities.capabilities;
Emu::VulkanSwapchain s{};