├── core ├── libraries │ ├── network │ │ ├── net_obj.h │ │ ├── net_obj.cpp │ │ ├── ssl2.h │ │ ├── net_ctl_obj.h │ │ └── net_ctl_codes.h │ ├── error_codes.h │ ├── np_manager │ │ └── np_manager_error.h │ ├── random │ │ ├── random_error.h │ │ ├── random.h │ │ └── random.cpp │ ├── system │ │ ├── system_error.h │ │ ├── posix.cpp │ │ ├── posix.h │ │ ├── systemservice_error.h │ │ ├── userservice_error.h │ │ └── msgdialog.h │ ├── np_common │ │ └── np_common_error.h │ ├── audio3d │ │ ├── audio3d_impl.h │ │ ├── audio3d_impl.cpp │ │ └── audio3d_error.h │ ├── jpeg │ │ └── jpeg_error.h │ ├── ajm │ │ ├── ajm_instance_statistics.h │ │ ├── ajm_instance_statistics.cpp │ │ ├── ajm_error.h │ │ └── ajm_context.h │ ├── app_content │ │ └── app_content_error.h │ ├── razor_cpu │ │ └── razor_cpu.h │ ├── disc_map │ │ ├── disc_map_codes.h │ │ ├── disc_map.h │ │ └── disc_map.cpp │ ├── kernel │ │ ├── process.h │ │ ├── threads.cpp │ │ ├── aio.h │ │ ├── sync │ │ │ └── mutex.cpp │ │ ├── threads │ │ │ ├── sleepq.h │ │ │ ├── exception.h │ │ │ └── pthread_clean.cpp │ │ ├── kernel.h │ │ └── threads.h │ ├── fiber │ │ └── fiber_error.h │ ├── avplayer │ │ ├── avplayer_data_streamer.h │ │ ├── avplayer_error.h │ │ ├── avplayer_file_streamer.h │ │ ├── avplayer_common.cpp │ │ └── avplayer_common.h │ ├── move │ │ ├── move.h │ │ └── move.cpp │ ├── zlib │ │ ├── zlib_sce.h │ │ └── zlib_error.h │ ├── libpng │ │ └── pngdec_error.h │ ├── libc_internal │ │ └── libc_internal.h │ ├── audio │ │ ├── audioout_backend.h │ │ └── audioout_error.h │ ├── ngs2 │ │ ├── ngs2_impl.h │ │ └── ngs2.h │ ├── mouse │ │ └── mouse.h │ ├── ime │ │ └── error_dialog.h │ ├── pad │ │ └── pad_errors.h │ ├── screenshot │ │ └── screenshot.h │ ├── np_trophy │ │ └── trophy_ui.h │ ├── videodec │ │ ├── videodec_impl.h │ │ ├── videodec2_impl.h │ │ └── videodec2_avc.h │ ├── web_browser_dialog │ │ └── webbrowserdialog.h │ ├── playgo │ │ └── playgo_dialog.h │ ├── save_data │ │ ├── save_memory.h │ │ ├── dialog │ │ │ └── savedatadialog.h │ │ └── save_backup.h │ ├── np_party │ │ └── np_party.h │ ├── rtc │ │ └── rtc_error.h │ └── videoout │ │ ├── buffer.h │ │ └── videoout_error.h ├── file_format │ ├── entry_name.cpp │ ├── pkg_type.h │ ├── splash.h │ ├── splash.cpp │ ├── trp.h │ └── rif_generator.h ├── devices │ ├── logger_stub.cpp │ ├── logger_stub.h │ ├── base_device.cpp │ ├── logger.h │ ├── console_device.h │ ├── random_device.h │ ├── srandom_device.h │ ├── urandom_device.h │ ├── deci_tty6_device.h │ ├── nop_device.h │ ├── logger.cpp │ └── base_device.h ├── aerolib │ ├── stubs.h │ ├── aerolib.h │ └── aerolib.cpp ├── loader.h ├── devtools │ ├── layer.h │ ├── options.h │ ├── help.txt │ ├── widget │ │ ├── memory_map.h │ │ ├── frame_graph.h │ │ ├── frame_dump.h │ │ ├── shader_list.h │ │ ├── reg_popup.h │ │ └── reg_view.h │ └── options.cpp ├── loader.cpp ├── cpu_patches.h ├── file_sys │ ├── file.h │ └── fs.h ├── thread.h ├── loader │ ├── dwarf.h │ ├── symbols_resolver.cpp │ └── symbols_resolver.h ├── tls.h └── signals.h ├── common ├── config_stub.cpp ├── stb.h ├── stb.cpp ├── io_file_stub.cpp ├── ntapi_stub.cpp ├── arch.h ├── log_stub.cpp ├── version.h ├── signal_context.h ├── scm_rev.h ├── hash.h ├── support │ └── avdec.h ├── singleton.h ├── logging │ ├── text_formatter.h │ ├── log_entry.h │ ├── backend.h │ └── formatter.h ├── adaptive_mutex.h ├── error.h ├── discord_rpc_handler.h ├── native_clock.h ├── number_utils.h ├── string_util.h ├── scm_rev.cpp.in ├── spin_lock.h ├── div_ceil.h ├── concepts.h ├── assert.cpp ├── decoder.h ├── func_traits.h ├── spin_lock.cpp ├── types.h ├── fixed_value.h ├── ntapi.cpp ├── native_clock.cpp ├── thread.h ├── rdtsc.h ├── memory_patcher.h ├── alignment.h ├── discord_rpc_handler.cpp ├── error.cpp ├── unique_function.h ├── decoder.cpp ├── slot_array.h └── rdtsc.cpp ├── imgui ├── renderer │ ├── fonts │ │ ├── NotoSansJP-Regular.ttf │ │ └── ProggyVector-Regular.ttf │ ├── texture_manager.h │ ├── imgui_core.h │ ├── imgui_impl_sdl3.h │ └── CMakeLists.txt ├── imgui_layer.h ├── imgui_texture.h └── imgui_config.h ├── .gitignore ├── video_core ├── host_shaders │ ├── source_shader.h.in │ ├── fs_tri.vert │ ├── post_process.frag │ ├── StringShaderHeader.cmake │ ├── CMakeLists.txt │ └── detilers │ │ ├── micro_8bpp.comp │ │ ├── micro_32bpp.comp │ │ ├── micro_64bpp.comp │ │ ├── display_micro_64bpp.comp │ │ └── micro_16bpp.comp ├── renderer_vulkan │ ├── vk_common.cpp │ ├── vk_shader_hle.h │ ├── vk_common.h │ ├── vk_shader_util.h │ ├── vk_compute_pipeline.h │ └── vk_master_semaphore.h ├── renderdoc.h ├── texture_cache │ ├── sampler.h │ ├── tile_manager.h │ └── image_view.h ├── page_manager.h └── amdgpu │ └── pixel_format.h ├── simple_log.h └── CMakeLists.txt /core/libraries/network/net_obj.h: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /core/libraries/network/net_obj.cpp: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /common/config_stub.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Config { 4 | std::string getTrophyKey() { 5 | return ""; 6 | } 7 | } -------------------------------------------------------------------------------- /imgui/renderer/fonts/NotoSansJP-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seregonwar/ShadPKG/HEAD/imgui/renderer/fonts/NotoSansJP-Regular.ttf -------------------------------------------------------------------------------- /core/file_format/entry_name.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::string_view GetEntryNameByType(unsigned int) { 4 | return "unknown"; 5 | } -------------------------------------------------------------------------------- /imgui/renderer/fonts/ProggyVector-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/seregonwar/ShadPKG/HEAD/imgui/renderer/fonts/ProggyVector-Regular.ttf -------------------------------------------------------------------------------- /common/stb.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | -------------------------------------------------------------------------------- /core/devices/logger_stub.cpp: -------------------------------------------------------------------------------- 1 | #include "core/devices/logger_stub.h" 2 | 3 | namespace Core { 4 | namespace Devices { 5 | Logger::Logger(std::basic_string, std::allocator>, bool) {} 6 | } 7 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | /build 3 | /build 4 | *.vcxproj 5 | /build 6 | /build 7 | /gift 8 | RIF_Documentation.md 9 | /rifs 10 | /ShadPKG-ps4 11 | /test_output 12 | /toml11 13 | /user 14 | debug_log.txt 15 | *.txt 16 | example_content_ids.txt 17 | -------------------------------------------------------------------------------- /common/stb.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #define STB_IMAGE_IMPLEMENTATION 5 | #define STBI_ONLY_PNG 6 | #define STBI_NO_STDIO 7 | #include "common/stb.h" 8 | -------------------------------------------------------------------------------- /core/devices/logger_stub.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core { 5 | namespace Devices { 6 | class Logger { 7 | public: 8 | Logger(std::basic_string, std::allocator>, bool); 9 | }; 10 | } 11 | } -------------------------------------------------------------------------------- /common/io_file_stub.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Common { namespace FS { 5 | class IOFile { 6 | public: 7 | uint64_t GetFileMapping() { return 0; } 8 | }; 9 | }} 10 | 11 | extern "C" void* __imp_CreateFileMapping2 = nullptr; -------------------------------------------------------------------------------- /core/libraries/error_codes.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | // Generic 7 | constexpr int ORBIS_OK = 0x00000000; 8 | constexpr int ORBIS_FAIL = 0xFFFFFFFF; 9 | -------------------------------------------------------------------------------- /common/ntapi_stub.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "common/ntapi.h" 3 | 4 | static u64 NtSetInformationFile_stub(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, FILE_INFORMATION_CLASS) { 5 | return 0; 6 | } 7 | 8 | NtSetInformationFile_t NtSetInformationFile = NtSetInformationFile_stub; -------------------------------------------------------------------------------- /common/arch.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #if defined(__x86_64__) || defined(_M_X64) 7 | #define ARCH_X86_64 1 8 | #elif defined(__aarch64__) || defined(_M_ARM64) 9 | #define ARCH_ARM64 1 10 | #endif 11 | -------------------------------------------------------------------------------- /common/log_stub.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | namespace Common { 3 | namespace Log { 4 | enum class Class {}; 5 | enum class Level {}; 6 | void FmtLogMessageImpl(Class, Level, const char*, unsigned, const char*, const char*, const fmt::v11::basic_format_args&) {} 7 | void Stop() {} 8 | } 9 | } -------------------------------------------------------------------------------- /core/devices/base_device.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "base_device.h" 5 | 6 | namespace Core::Devices { 7 | 8 | BaseDevice::BaseDevice() = default; 9 | 10 | BaseDevice::~BaseDevice() = default; 11 | 12 | } // namespace Core::Devices -------------------------------------------------------------------------------- /core/aerolib/stubs.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::AeroLib { 9 | 10 | u64 UnresolvedStub(); 11 | 12 | u64 GetStub(const char* nid); 13 | 14 | } // namespace Core::AeroLib 15 | -------------------------------------------------------------------------------- /core/libraries/np_manager/np_manager_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | constexpr int ORBIS_NP_ERROR_INVALID_ARGUMENT = 0x80550003; 9 | constexpr int ORBIS_NP_ERROR_SIGNED_OUT = 0x80550006; -------------------------------------------------------------------------------- /core/libraries/random/random_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | constexpr int SCE_RANDOM_ERROR_INVALID = 0x817C0016; 7 | constexpr int SCE_RANDOM_ERROR_OUT_OF_RESOURCES = 0x817C001C; 8 | constexpr int SCE_RANDOM_ERROR_FATAL = 0x817C00FF; -------------------------------------------------------------------------------- /core/libraries/system/system_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | constexpr int ORBIS_SYSMODULE_INVALID_ID = 0x805A1000; 7 | constexpr int ORBIS_SYSMODULE_NOT_LOADED = 0x805A1001; 8 | constexpr int ORBIS_SYSMODULE_LOCK_FAILED = 0x805A10FF; -------------------------------------------------------------------------------- /core/file_format/pkg_type.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/types.h" 8 | 9 | /// Retrieves the PKG entry name from its type identifier. 10 | std::string_view GetEntryNameByType(u32 type); 11 | -------------------------------------------------------------------------------- /core/libraries/np_common/np_common_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | constexpr int ORBIS_NP_ERROR_INVALID_ARGUMENT = 0x80550003; 9 | constexpr int ORBIS_NP_UTIL_ERROR_NOT_MATCH = 0x80550609; -------------------------------------------------------------------------------- /common/version.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace Common { 10 | 11 | constexpr char VERSION[] = "0.6.0"; 12 | constexpr bool isRelease = true; 13 | 14 | } // namespace Common 15 | -------------------------------------------------------------------------------- /core/libraries/system/posix.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "core/libraries/system/posix.h" 5 | 6 | namespace Libraries::Posix { 7 | 8 | void Registerlibsceposix(Core::Loader::SymbolsResolver* sym) {} 9 | 10 | } // namespace Libraries::Posix 11 | -------------------------------------------------------------------------------- /video_core/host_shaders/source_shader.h.in: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2022 Citra Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace HostShaders { 9 | 10 | constexpr std::string_view @CONTENTS_NAME@ = { 11 | @CONTENTS@ 12 | }; 13 | 14 | } // namespace HostShaders 15 | -------------------------------------------------------------------------------- /core/libraries/system/posix.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | namespace Core::Loader { 7 | class SymbolsResolver; 8 | } 9 | 10 | namespace Libraries::Posix { 11 | void Registerlibsceposix(Core::Loader::SymbolsResolver* sym); 12 | } // namespace Libraries::Posix 13 | -------------------------------------------------------------------------------- /core/libraries/audio3d/audio3d_impl.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "audio3d.h" 7 | 8 | namespace Libraries::Audio3d { 9 | 10 | class Audio3d { 11 | public: 12 | private: 13 | using OrbisAudio3dPluginId = u32; 14 | }; 15 | 16 | } // namespace Libraries::Audio3d 17 | -------------------------------------------------------------------------------- /core/libraries/system/systemservice_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // SystemService library 9 | constexpr int ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER = 0x80A10003; 10 | constexpr int ORBIS_SYSTEM_SERVICE_ERROR_NO_EVENT = 0x80A10004; 11 | -------------------------------------------------------------------------------- /core/aerolib/aerolib.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace Core::AeroLib { 9 | 10 | struct NidEntry { 11 | const char* nid; 12 | const char* name; 13 | }; 14 | 15 | const NidEntry* FindByNid(const char* nid); 16 | 17 | } // namespace Core::AeroLib 18 | -------------------------------------------------------------------------------- /core/libraries/network/ssl2.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::Ssl2 { 13 | void RegisterlibSceSsl2(Core::Loader::SymbolsResolver* sym); 14 | } // namespace Libraries::Ssl2 -------------------------------------------------------------------------------- /imgui/imgui_layer.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | namespace ImGui { 7 | 8 | class Layer { 9 | public: 10 | virtual ~Layer() = default; 11 | static void AddLayer(Layer* layer); 12 | static void RemoveLayer(Layer* layer); 13 | 14 | virtual void Draw() = 0; 15 | }; 16 | 17 | } // namespace ImGui -------------------------------------------------------------------------------- /common/signal_context.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Common { 9 | 10 | void* GetXmmPointer(void* ctx, u8 index); 11 | 12 | void* GetRip(void* ctx); 13 | 14 | void IncrementRip(void* ctx, u64 length); 15 | 16 | bool IsWriteError(void* ctx); 17 | 18 | } // namespace Common -------------------------------------------------------------------------------- /core/loader.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace Loader { 9 | 10 | constexpr static u32 PkgMagic = 0x544e437f; 11 | 12 | enum class FileTypes { 13 | Unknown, 14 | Pkg, 15 | }; 16 | 17 | FileTypes DetectFileType(const std::filesystem::path& filepath); 18 | } // namespace Loader 19 | -------------------------------------------------------------------------------- /core/libraries/jpeg/jpeg_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_ADDR = 0x80650101; 7 | constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_SIZE = 0x80650102; 8 | constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_PARAM = 0x80650103; 9 | constexpr int ORBIS_JPEG_ENC_ERROR_INVALID_HANDLE = 0x80650104; 10 | -------------------------------------------------------------------------------- /common/scm_rev.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | namespace Common { 7 | 8 | extern const char g_scm_rev[]; 9 | extern const char g_scm_branch[]; 10 | extern const char g_scm_desc[]; 11 | extern const char g_scm_remote_name[]; 12 | extern const char g_scm_remote_url[]; 13 | extern const char g_scm_date[]; 14 | 15 | } // namespace Common 16 | -------------------------------------------------------------------------------- /video_core/host_shaders/fs_tri.vert: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #version 450 5 | 6 | layout(location = 0) out vec2 uv; 7 | 8 | void main() { 9 | vec2 pos = vec2( 10 | float((gl_VertexIndex & 1u) << 2u), 11 | float((gl_VertexIndex & 2u) << 1u) 12 | ); 13 | gl_Position = vec4(pos - vec2(1.0, 1.0), 0.0, 1.0); 14 | uv = pos * 0.5; 15 | } 16 | -------------------------------------------------------------------------------- /core/libraries/ajm/ajm_instance_statistics.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/ajm/ajm_batch.h" 7 | 8 | namespace Libraries::Ajm { 9 | 10 | class AjmInstanceStatistics { 11 | public: 12 | void ExecuteJob(AjmJob& job); 13 | 14 | static AjmInstanceStatistics& Getinstance(); 15 | }; 16 | 17 | } // namespace Libraries::Ajm 18 | -------------------------------------------------------------------------------- /core/libraries/app_content/app_content_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // AppContent library 9 | constexpr int ORBIS_APP_CONTENT_ERROR_PARAMETER = 0x80D90002; 10 | constexpr int ORBIS_APP_CONTENT_ERROR_DRM_NO_ENTITLEMENT = 0x80D90007; 11 | constexpr int ORBIS_APP_CONTENT_ERROR_NOT_FOUND = 0x80D90005; 12 | -------------------------------------------------------------------------------- /core/libraries/audio3d/audio3d_impl.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "audio3d_error.h" 5 | #include "audio3d_impl.h" 6 | 7 | #include "common/logging/log.h" 8 | #include "core/libraries/error_codes.h" 9 | #include "core/libraries/kernel/kernel.h" 10 | 11 | using namespace Libraries::Kernel; 12 | 13 | namespace Libraries::Audio3d {} // namespace Libraries::Audio3d 14 | -------------------------------------------------------------------------------- /core/libraries/razor_cpu/razor_cpu.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | #include 9 | #include 10 | 11 | namespace Core::Loader { 12 | class SymbolsResolver; 13 | } 14 | 15 | namespace Libraries::RazorCpu { 16 | void RegisterlibSceRazorCpu(Core::Loader::SymbolsResolver* sym); 17 | } // namespace Libraries::RazorCpu -------------------------------------------------------------------------------- /common/hash.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | [[nodiscard]] inline u64 HashCombine(const u64 seed, const u64 hash) { 9 | return seed ^ (hash + 0x9e3779b9 + (seed << 12) + (seed >> 4)); 10 | } 11 | 12 | [[nodiscard]] inline u32 HashCombine(const u32 seed, const u32 hash) { 13 | return seed ^ (hash + 0x9e3779b9 + (seed << 6) + (seed >> 2)); 14 | } -------------------------------------------------------------------------------- /core/libraries/disc_map/disc_map_codes.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | constexpr int ORBIS_DISC_MAP_ERROR_INVALID_ARGUMENT = 0x81100001; 7 | constexpr int ORBIS_DISC_MAP_ERROR_LOCATION_NOT_MAPPED = 0x81100002; 8 | constexpr int ORBIS_DISC_MAP_ERROR_FILE_NOT_FOUND = 0x81100003; 9 | constexpr int ORBIS_DISC_MAP_ERROR_NO_BITMAP_INFO = 0x81100004; 10 | constexpr int ORBIS_DISC_MAP_ERROR_FATAL = 0x811000FF; 11 | -------------------------------------------------------------------------------- /core/libraries/kernel/process.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::Kernel { 13 | 14 | int PS4_SYSV_ABI sceKernelIsNeoMode(); 15 | 16 | int PS4_SYSV_ABI sceKernelGetCompiledSdkVersion(int* ver); 17 | 18 | void RegisterProcess(Core::Loader::SymbolsResolver* sym); 19 | 20 | } // namespace Libraries::Kernel 21 | -------------------------------------------------------------------------------- /video_core/renderer_vulkan/vk_common.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "video_core/renderer_vulkan/vk_common.h" 5 | 6 | // Implement vma functions 7 | #define VMA_IMPLEMENTATION 8 | #pragma clang diagnostic push 9 | #pragma clang diagnostic ignored "-Wnullability-completeness" 10 | #include 11 | #pragma clang diagnostic pop 12 | 13 | // Store the dispatch loader here 14 | VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE 15 | -------------------------------------------------------------------------------- /core/devtools/layer.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "imgui/imgui_layer.h" 7 | 8 | namespace Core::Devtools { 9 | 10 | class Layer final : public ImGui::Layer { 11 | 12 | static void DrawMenuBar(); 13 | 14 | static void DrawAdvanced(); 15 | 16 | static void DrawSimple(); 17 | 18 | public: 19 | static void SetupSettings(); 20 | 21 | void Draw() override; 22 | }; 23 | 24 | } // namespace Core::Devtools 25 | -------------------------------------------------------------------------------- /core/libraries/random/random.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::Random { 13 | 14 | constexpr s32 SCE_RANDOM_MAX_SIZE = 64; 15 | 16 | s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, std::size_t size); 17 | 18 | void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym); 19 | 20 | } // namespace Libraries::Random 21 | -------------------------------------------------------------------------------- /core/libraries/fiber/fiber_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // Fiber library 9 | constexpr int ORBIS_FIBER_ERROR_NULL = 0x80590001; 10 | constexpr int ORBIS_FIBER_ERROR_ALIGNMENT = 0x80590002; 11 | constexpr int ORBIS_FIBER_ERROR_RANGE = 0x80590003; 12 | constexpr int ORBIS_FIBER_ERROR_INVALID = 0x80590004; 13 | constexpr int ORBIS_FIBER_ERROR_PERMISSION = 0x80590005; 14 | constexpr int ORBIS_FIBER_ERROR_STATE = 0x80590006; 15 | -------------------------------------------------------------------------------- /core/libraries/avplayer/avplayer_data_streamer.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "avplayer.h" 7 | 8 | #include "common/types.h" 9 | 10 | #include 11 | 12 | struct AVIOContext; 13 | 14 | namespace Libraries::AvPlayer { 15 | 16 | class IDataStreamer { 17 | public: 18 | virtual ~IDataStreamer() = default; 19 | virtual bool Init(std::string_view path) = 0; 20 | virtual AVIOContext* GetContext() = 0; 21 | }; 22 | 23 | } // namespace Libraries::AvPlayer 24 | -------------------------------------------------------------------------------- /core/libraries/move/move.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::Move { 13 | 14 | int PS4_SYSV_ABI sceMoveOpen(); 15 | int PS4_SYSV_ABI sceMoveGetDeviceInfo(); 16 | int PS4_SYSV_ABI sceMoveReadStateRecent(); 17 | int PS4_SYSV_ABI sceMoveTerm(); 18 | int PS4_SYSV_ABI sceMoveInit(); 19 | 20 | void RegisterlibSceMove(Core::Loader::SymbolsResolver* sym); 21 | } // namespace Libraries::Move -------------------------------------------------------------------------------- /common/support/avdec.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | // support header file for libav 7 | 8 | // The av_err2str macro in libavutil/error.h does not play nice with C++ 9 | #ifdef av_err2str 10 | #undef av_err2str 11 | #include 12 | av_always_inline std::string av_err2string(int errnum) { 13 | char errbuf[AV_ERROR_MAX_STRING_SIZE]; 14 | return av_make_error_string(errbuf, AV_ERROR_MAX_STRING_SIZE, errnum); 15 | } 16 | #define av_err2str(err) av_err2string(err).c_str() 17 | #endif // av_err2str 18 | -------------------------------------------------------------------------------- /video_core/renderer_vulkan/vk_shader_hle.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "video_core/amdgpu/liverpool.h" 7 | 8 | namespace Shader { 9 | struct Info; 10 | } 11 | 12 | namespace Vulkan { 13 | 14 | class Rasterizer; 15 | 16 | /// Attempts to execute a shader using HLE if possible. 17 | bool ExecuteShaderHLE(const Shader::Info& info, const AmdGpu::Liverpool::Regs& regs, 18 | const AmdGpu::Liverpool::ComputeProgram& cs_program, Rasterizer& rasterizer); 19 | 20 | } // namespace Vulkan 21 | -------------------------------------------------------------------------------- /common/singleton.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace Common { 9 | 10 | template 11 | class Singleton { 12 | public: 13 | static T* Instance() { 14 | if (!m_instance) { 15 | m_instance = std::make_unique(); 16 | } 17 | return m_instance.get(); 18 | } 19 | 20 | protected: 21 | Singleton(); 22 | ~Singleton(); 23 | 24 | private: 25 | static inline std::unique_ptr m_instance{}; 26 | }; 27 | 28 | } // namespace Common 29 | -------------------------------------------------------------------------------- /common/logging/text_formatter.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2014 Citra Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace Common::Log { 9 | 10 | struct Entry; 11 | 12 | /// Formats a log entry into the provided text buffer. 13 | std::string FormatLogMessage(const Entry& entry); 14 | 15 | /// Formats and prints a log entry to stderr. 16 | void PrintMessage(const Entry& entry); 17 | 18 | /// Prints the same message as `PrintMessage`, but colored according to the severity level. 19 | void PrintColoredMessage(const Entry& entry); 20 | 21 | } // namespace Common::Log 22 | -------------------------------------------------------------------------------- /core/libraries/disc_map/disc_map.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | namespace Libraries::DiscMap { 12 | 13 | int PS4_SYSV_ABI sceDiscMapGetPackageSize(); 14 | int PS4_SYSV_ABI sceDiscMapIsRequestOnHDD(); 15 | int PS4_SYSV_ABI Func_7C980FFB0AA27E7A(); 16 | int PS4_SYSV_ABI Func_8A828CAEE7EDD5E9(); 17 | int PS4_SYSV_ABI Func_E7EBCE96E92F91F8(); 18 | 19 | void RegisterlibSceDiscMap(Core::Loader::SymbolsResolver* sym); 20 | } // namespace Libraries::DiscMap -------------------------------------------------------------------------------- /core/devtools/options.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | struct ImGuiTextBuffer; 9 | 10 | namespace Core::Devtools { 11 | 12 | struct TOptions { 13 | std::string disassembler_cli_isa{"clrxdisasm --raw {src}"}; 14 | std::string disassembler_cli_spv{"spirv-cross -V {src}"}; 15 | bool frame_dump_render_on_collapse{false}; 16 | }; 17 | 18 | extern TOptions Options; 19 | 20 | void LoadOptionsConfig(const char* line); 21 | void SerializeOptionsConfig(ImGuiTextBuffer* buf); 22 | 23 | } // namespace Core::Devtools 24 | -------------------------------------------------------------------------------- /simple_log.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | inline void simple_log(const std::string& msg) { 9 | static std::mutex mtx; 10 | static std::ofstream log_file("debug_log.txt", std::ios::app); 11 | std::lock_guard lock(mtx); 12 | 13 | // Timestamp 14 | std::time_t now = std::time(nullptr); 15 | char buf[32]; 16 | std::strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", std::localtime(&now)); 17 | 18 | log_file << "[" << buf << "] " << msg << std::endl; 19 | log_file.flush(); 20 | std::cout << "[LOG] " << msg << std::endl; 21 | } -------------------------------------------------------------------------------- /common/adaptive_mutex.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #ifdef __linux__ 7 | #include 8 | #endif 9 | 10 | namespace Common { 11 | 12 | #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 13 | class AdaptiveMutex { 14 | public: 15 | void lock() { 16 | pthread_mutex_lock(&mutex); 17 | } 18 | void unlock() { 19 | pthread_mutex_unlock(&mutex); 20 | } 21 | 22 | private: 23 | pthread_mutex_t mutex = PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP; 24 | }; 25 | #endif // PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 26 | 27 | } // namespace Common 28 | -------------------------------------------------------------------------------- /core/devtools/help.txt: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | R"( 4 | * If you hold shift, you can move the window without docking it. 5 | * You don't need to close every window you open. When a parent window is closed, all its children will be closed too. 6 | * If you want to inspect or compare more than 1 frame dump without undocking, there's a option to keep showing opened popups even when in hide/minimize the frame dump window. 7 | * To use the disassembly viewer, you need to set up a cli to use a external disassembler and use "{src}" as a placeholder for the source code file, e.g. dis.exe --some-opt "{src}" 8 | )" -------------------------------------------------------------------------------- /common/error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project 2 | // SPDX-FileCopyrightText: 2014 Citra Emulator Project 3 | // SPDX-License-Identifier: GPL-2.0-or-later 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | namespace Common { 10 | 11 | // Generic function to get last error message. 12 | // Call directly after the command or use the error num. 13 | // This function might change the error code. 14 | // Defined in error.cpp. 15 | [[nodiscard]] std::string GetLastErrorMsg(); 16 | 17 | // Like GetLastErrorMsg(), but passing an explicit error code. 18 | // Defined in error.cpp. 19 | [[nodiscard]] std::string NativeErrorToString(int e); 20 | 21 | } // namespace Common 22 | -------------------------------------------------------------------------------- /imgui/renderer/texture_manager.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include "common/types.h" 10 | #include "imgui/imgui_texture.h" 11 | 12 | namespace vk { 13 | class CommandBuffer; 14 | } 15 | 16 | namespace ImGui::Core::TextureManager { 17 | 18 | struct Inner; 19 | 20 | void StartWorker(); 21 | 22 | void StopWorker(); 23 | 24 | void DecodePngTexture(std::vector data, Inner* core); 25 | 26 | void DecodePngFile(std::filesystem::path path, Inner* core); 27 | 28 | void Submit(); 29 | 30 | }; // namespace ImGui::Core::TextureManager -------------------------------------------------------------------------------- /video_core/renderdoc.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace VideoCore { 9 | 10 | /// Loads renderdoc dynamic library module. 11 | void LoadRenderDoc(); 12 | 13 | /// Begins a capture if a renderdoc instance is attached. 14 | void StartCapture(); 15 | 16 | /// Ends current renderdoc capture. 17 | void EndCapture(); 18 | 19 | /// Triggers capturing process. 20 | void TriggerCapture(); 21 | 22 | /// Sets output directory for captures 23 | void SetOutputDir(const std::filesystem::path& path, const std::string& prefix); 24 | 25 | } // namespace VideoCore 26 | -------------------------------------------------------------------------------- /core/libraries/kernel/threads.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "core/libraries/kernel/kernel.h" 5 | #include "core/libraries/kernel/threads.h" 6 | #include "core/libraries/kernel/threads/pthread.h" 7 | 8 | namespace Libraries::Kernel { 9 | 10 | void RegisterThreads(Core::Loader::SymbolsResolver* sym) { 11 | RegisterMutex(sym); 12 | RegisterCond(sym); 13 | RegisterRwlock(sym); 14 | RegisterSemaphore(sym); 15 | RegisterSpec(sym); 16 | RegisterThreadAttr(sym); 17 | RegisterThread(sym); 18 | RegisterRtld(sym); 19 | RegisterPthreadClean(sym); 20 | } 21 | 22 | } // namespace Libraries::Kernel 23 | -------------------------------------------------------------------------------- /common/discord_rpc_handler.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace DiscordRPCHandler { 11 | 12 | enum class RPCStatus { 13 | Idling, 14 | Playing, 15 | }; 16 | 17 | class RPC { 18 | std::uint64_t startTimestamp; 19 | bool rpcEnabled = false; 20 | RPCStatus status; 21 | 22 | public: 23 | void init(); 24 | void setStatusIdling(); 25 | void setStatusPlaying(const std::string& game_name, const std::string& game_id); 26 | void shutdown(); 27 | bool getRPCEnabled(); 28 | }; 29 | 30 | } // namespace DiscordRPCHandler 31 | -------------------------------------------------------------------------------- /core/libraries/audio3d/audio3d_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | constexpr int ORBIS_AUDIO3D_ERROR_UNKNOWN = 0x80EA0001; 9 | constexpr int ORBIS_AUDIO3D_ERROR_INVALID_PORT = 0x80EA0002; 10 | constexpr int ORBIS_AUDIO3D_ERROR_INVALID_OBJECT = 0x80EA0003; 11 | constexpr int ORBIS_AUDIO3D_ERROR_INVALID_PARAMETER = 0x80EA0004; 12 | constexpr int ORBIS_AUDIO3D_ERROR_OUT_OF_MEMORY = 0x80EA0005; 13 | constexpr int ORBIS_AUDIO3D_ERROR_OUT_OF_RESOURCES = 0x80EA0006; 14 | constexpr int ORBIS_AUDIO3D_ERROR_NOT_READY = 0x80EA0007; 15 | constexpr int ORBIS_AUDIO3D_ERROR_NOT_SUPPORTED = 0x80EA0008; 16 | -------------------------------------------------------------------------------- /common/logging/log_entry.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2014 Citra Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "common/logging/types.h" 9 | 10 | namespace Common::Log { 11 | 12 | /** 13 | * A log entry. Log entries are store in a structured format to permit more varied output 14 | * formatting on different frontends, as well as facilitating filtering and aggregation. 15 | */ 16 | struct Entry { 17 | std::chrono::microseconds timestamp; 18 | Class log_class{}; 19 | Level log_level{}; 20 | const char* filename = nullptr; 21 | u32 line_num = 0; 22 | std::string function; 23 | std::string message; 24 | }; 25 | 26 | } // namespace Common::Log 27 | -------------------------------------------------------------------------------- /common/native_clock.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/types.h" 8 | 9 | namespace Common { 10 | 11 | class NativeClock final { 12 | public: 13 | explicit NativeClock(); 14 | 15 | u64 GetTscFrequency() const { 16 | return rdtsc_frequency; 17 | } 18 | 19 | u64 GetTimeNS(u64 base_ptc = 0) const; 20 | u64 GetTimeUS(u64 base_ptc = 0) const; 21 | u64 GetTimeMS(u64 base_ptc = 0) const; 22 | u64 GetUptime() const; 23 | 24 | private: 25 | u64 rdtsc_frequency; 26 | u64 ns_rdtsc_factor; 27 | u64 us_rdtsc_factor; 28 | u64 ms_rdtsc_factor; 29 | }; 30 | 31 | } // namespace Common 32 | -------------------------------------------------------------------------------- /common/number_utils.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace NumberUtils { 9 | 10 | float Uf11ToF32(u16 val); 11 | float Uf10ToF32(u16 val); 12 | float Uf16ToF32(u16 val); 13 | float U2ToUnorm(u8 val); 14 | float S2ToSnorm(s8 val); 15 | float U4ToUnorm(u8 val); 16 | float S4ToSnorm(s8 val); 17 | float U5ToUnorm(u8 val); 18 | float S5ToSnorm(s8 val); 19 | float U6ToUnorm(u8 val); 20 | float S6ToSnorm(s8 val); 21 | float U8ToUnorm(u8 val); 22 | float S8ToSnorm(s8 val); 23 | float U10ToUnorm(u16 val); 24 | float S10ToSnorm(s16 val); 25 | float U16ToUnorm(u16 val); 26 | float S16ToSnorm(s16 val); 27 | 28 | } // namespace NumberUtils 29 | -------------------------------------------------------------------------------- /common/string_util.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project 2 | // SPDX-FileCopyrightText: 2014 Citra Emulator Project 3 | // SPDX-License-Identifier: GPL-2.0-or-later 4 | 5 | #pragma once 6 | 7 | #include 8 | #include 9 | 10 | namespace Common { 11 | 12 | /// Make a string lowercase 13 | [[nodiscard]] std::string ToLower(std::string_view str); 14 | 15 | void ToLowerInPlace(std::string& str); 16 | 17 | std::vector SplitString(const std::string& str, char delimiter); 18 | 19 | std::string_view U8stringToString(std::u8string_view u8str); 20 | 21 | #ifdef _WIN32 22 | [[nodiscard]] std::string UTF16ToUTF8(std::wstring_view input); 23 | [[nodiscard]] std::wstring UTF8ToUTF16W(std::string_view str); 24 | #endif 25 | 26 | } // namespace Common 27 | -------------------------------------------------------------------------------- /core/loader.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/io_file.h" 5 | #include "common/types.h" 6 | #include "loader.h" 7 | 8 | namespace Loader { 9 | 10 | FileTypes DetectFileType(const std::filesystem::path& filepath) { 11 | // No file loaded 12 | if (filepath.empty()) { 13 | return FileTypes::Unknown; 14 | } 15 | Common::FS::IOFile file; 16 | file.Open(filepath, Common::FS::FileAccessMode::Read); 17 | file.Seek(0); 18 | u32 magic; 19 | file.Read(magic); 20 | file.Close(); 21 | switch (magic) { 22 | case PkgMagic: 23 | return FileTypes::Pkg; 24 | } 25 | return FileTypes::Unknown; 26 | } 27 | 28 | } // namespace Loader 29 | -------------------------------------------------------------------------------- /video_core/host_shaders/post_process.frag: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #version 450 5 | 6 | layout (location = 0) in vec2 uv; 7 | layout (location = 0) out vec4 color; 8 | 9 | layout (binding = 0) uniform sampler2D texSampler; 10 | 11 | layout(push_constant) uniform settings { 12 | float gamma; 13 | } pp; 14 | 15 | const float cutoff = 0.0031308, a = 1.055, b = 0.055, d = 12.92; 16 | vec3 gamma(vec3 rgb) 17 | { 18 | return mix(a * pow(rgb, vec3(1.0 / (2.4 + 1.0 - pp.gamma))) - b, d * rgb / pp.gamma, lessThan(rgb, vec3(cutoff))); 19 | } 20 | 21 | void main() 22 | { 23 | vec4 color_linear = texture(texSampler, uv); 24 | color = vec4(gamma(color_linear.rgb), color_linear.a); 25 | } 26 | -------------------------------------------------------------------------------- /common/scm_rev.cpp.in: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/scm_rev.h" 5 | 6 | #define GIT_REV "@GIT_REV@" 7 | #define GIT_BRANCH "@GIT_BRANCH@" 8 | #define GIT_DESC "@GIT_DESC@" 9 | #define GIT_REMOTE_NAME "@GIT_REMOTE_NAME@" 10 | #define GIT_REMOTE_URL "@GIT_REMOTE_URL@" 11 | #define BUILD_DATE "@BUILD_DATE@" 12 | 13 | namespace Common { 14 | 15 | const char g_scm_rev[] = GIT_REV; 16 | const char g_scm_branch[] = GIT_BRANCH; 17 | const char g_scm_desc[] = GIT_DESC; 18 | const char g_scm_remote_name[] = GIT_REMOTE_NAME; 19 | const char g_scm_remote_url[] = GIT_REMOTE_URL; 20 | const char g_scm_date[] = BUILD_DATE; 21 | 22 | } // namespace 23 | 24 | -------------------------------------------------------------------------------- /core/libraries/zlib/zlib_sce.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | namespace Libraries::Zlib { 12 | 13 | s32 PS4_SYSV_ABI sceZlibInitialize(const void* buffer, u32 length); 14 | s32 PS4_SYSV_ABI sceZlibInflate(const void* src, u32 src_len, void* dst, u32 dst_len, 15 | u64* request_id); 16 | s32 PS4_SYSV_ABI sceZlibWaitForDone(u64* request_id, const u32* timeout); 17 | s32 PS4_SYSV_ABI sceZlibGetResult(u64 request_id, u32* dst_length, s32* status); 18 | s32 PS4_SYSV_ABI sceZlibFinalize(); 19 | 20 | void RegisterlibSceZlib(Core::Loader::SymbolsResolver* sym); 21 | } // namespace Libraries::Zlib -------------------------------------------------------------------------------- /core/libraries/libpng/pngdec_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // PngDec library 9 | constexpr int ORBIS_PNG_DEC_ERROR_INVALID_ADDR = 0x80690001; 10 | constexpr int ORBIS_PNG_DEC_ERROR_INVALID_SIZE = 0x80690002; 11 | constexpr int ORBIS_PNG_DEC_ERROR_INVALID_PARAM = 0x80690003; 12 | constexpr int ORBIS_PNG_DEC_ERROR_INVALID_HANDLE = 0x80690004; 13 | constexpr int ORBIS_PNG_DEC_ERROR_INVALID_WORK_MEMORY = 0x80690005; 14 | constexpr int ORBIS_PNG_DEC_ERROR_INVALID_DATA = 0x80690010; 15 | constexpr int ORBIS_PNG_DEC_ERROR_UNSUPPORT_DATA = 0x80690011; 16 | constexpr int ORBIS_PNG_DEC_ERROR_DECODE_ERROR = 0x80690012; 17 | constexpr int ORBIS_PNG_DEC_ERROR_FATAL = 0x80690020; 18 | -------------------------------------------------------------------------------- /core/libraries/zlib/zlib_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // Zlib library 9 | constexpr int ORBIS_ZLIB_ERROR_NOT_FOUND = 0x81120002; 10 | constexpr int ORBIS_ZLIB_ERROR_BUSY = 0x8112000B; 11 | constexpr int ORBIS_ZLIB_ERROR_FAULT = 0x8112000E; 12 | constexpr int ORBIS_ZLIB_ERROR_INVALID = 0x81120016; 13 | constexpr int ORBIS_ZLIB_ERROR_NOSPACE = 0x8112001C; 14 | constexpr int ORBIS_ZLIB_ERROR_NOT_SUPPORTED = 0x81120025; 15 | constexpr int ORBIS_ZLIB_ERROR_TIMEDOUT = 0x81120027; 16 | constexpr int ORBIS_ZLIB_ERROR_NOT_INITIALIZED = 0x81120032; 17 | constexpr int ORBIS_ZLIB_ERROR_ALREADY_INITIALIZED = 0x81120033; 18 | constexpr int ORBIS_ZLIB_ERROR_FATAL = 0x811200FF; 19 | -------------------------------------------------------------------------------- /core/devtools/widget/memory_map.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/memory.h" 7 | 8 | namespace Core::Devtools::Widget { 9 | 10 | class MemoryMapViewer { 11 | struct Iterator { 12 | bool is_vma; 13 | struct { 14 | MemoryManager::DMemMap::iterator it; 15 | MemoryManager::DMemMap::iterator end; 16 | } dmem; 17 | struct { 18 | MemoryManager::VMAMap::iterator it; 19 | MemoryManager::VMAMap::iterator end; 20 | } vma; 21 | 22 | bool DrawLine(); 23 | }; 24 | 25 | bool showing_vma = true; 26 | 27 | public: 28 | bool open = false; 29 | 30 | void Draw(); 31 | }; 32 | 33 | } // namespace Core::Devtools::Widget 34 | -------------------------------------------------------------------------------- /core/devtools/widget/frame_graph.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Devtools::Widget { 9 | 10 | class FrameGraph { 11 | static constexpr u32 FRAME_BUFFER_SIZE = 1024; 12 | struct FrameInfo { 13 | u32 num; 14 | float delta; 15 | }; 16 | 17 | std::array frame_list{}; 18 | 19 | float deltaTime{}; 20 | float frameRate{}; 21 | 22 | void DrawFrameGraph(); 23 | 24 | public: 25 | bool is_open = true; 26 | 27 | void Draw(); 28 | 29 | void AddFrame(u32 num, float delta) { 30 | frame_list[num % FRAME_BUFFER_SIZE] = FrameInfo{num, delta}; 31 | } 32 | }; 33 | 34 | } // namespace Core::Devtools::Widget -------------------------------------------------------------------------------- /common/logging/backend.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2014 Citra Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/logging/filter.h" 8 | 9 | namespace Common::Log { 10 | 11 | class Filter; 12 | 13 | /// Initializes the logging system. This should be the first thing called in main. 14 | void Initialize(std::string_view log_file = ""); 15 | 16 | bool IsActive(); 17 | 18 | /// Starts the logging threads. 19 | void Start(); 20 | 21 | /// Explictily stops the logger thread and flushes the buffers 22 | void Stop(); 23 | 24 | /// The global filter will prevent any messages from even being processed if they are filtered. 25 | void SetGlobalFilter(const Filter& filter); 26 | 27 | void SetColorConsoleBackendEnabled(bool enabled); 28 | 29 | } // namespace Common::Log 30 | -------------------------------------------------------------------------------- /common/spin_lock.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace Common { 9 | 10 | /** 11 | * SpinLock class 12 | * a lock similar to mutex that forces a thread to spin wait instead calling the 13 | * supervisor. Should be used on short sequences of code. 14 | */ 15 | class SpinLock { 16 | public: 17 | SpinLock() = default; 18 | 19 | SpinLock(const SpinLock&) = delete; 20 | SpinLock& operator=(const SpinLock&) = delete; 21 | 22 | SpinLock(SpinLock&&) = delete; 23 | SpinLock& operator=(SpinLock&&) = delete; 24 | 25 | void lock(); 26 | void unlock(); 27 | [[nodiscard]] bool try_lock(); 28 | 29 | private: 30 | std::atomic_flag lck = ATOMIC_FLAG_INIT; 31 | }; 32 | 33 | } // namespace Common 34 | -------------------------------------------------------------------------------- /core/cpu_patches.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core { 9 | 10 | /// Initializes a stack for the current thread for use by patch implementations. 11 | void InitializeThreadPatchStack(); 12 | 13 | /// Cleans up the patch stack for the current thread. 14 | void CleanupThreadPatchStack(); 15 | 16 | /// Registers a module for patching, providing an area to generate trampoline code. 17 | void RegisterPatchModule(void* module_ptr, u64 module_size, void* trampoline_area_ptr, 18 | u64 trampoline_area_size); 19 | 20 | /// Applies CPU patches that need to be done before beginning executions. 21 | void PrePatchInstructions(u64 segment_addr, u64 segment_size); 22 | 23 | } // namespace Core 24 | -------------------------------------------------------------------------------- /video_core/renderer_vulkan/vk_common.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | // Include vulkan-hpp header 7 | #define VK_ENABLE_BETA_EXTENSIONS 8 | #define VK_NO_PROTOTYPES 9 | #define VULKAN_HPP_DISPATCH_LOADER_DYNAMIC 1 10 | #define VULKAN_HPP_NO_CONSTRUCTORS 11 | #define VULKAN_HPP_NO_STRUCT_SETTERS 12 | #define VULKAN_HPP_HAS_SPACESHIP_OPERATOR 13 | #define VULKAN_HPP_NO_EXCEPTIONS 14 | // Define assert-on-result to nothing to instead return the result for our handling. 15 | #define VULKAN_HPP_ASSERT_ON_RESULT 16 | 17 | #pragma clang diagnostic push 18 | #pragma clang diagnostic ignored "-Wunused-value" 19 | #include 20 | #pragma clang diagnostic pop 21 | 22 | #define VMA_STATIC_VULKAN_FUNCTIONS 0 23 | #define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 24 | -------------------------------------------------------------------------------- /video_core/texture_cache/sampler.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "video_core/amdgpu/resource.h" 7 | #include "video_core/renderer_vulkan/vk_common.h" 8 | 9 | namespace Vulkan { 10 | class Instance; 11 | } 12 | 13 | namespace VideoCore { 14 | 15 | class Sampler { 16 | public: 17 | explicit Sampler(const Vulkan::Instance& instance, const AmdGpu::Sampler& sampler); 18 | ~Sampler(); 19 | 20 | Sampler(const Sampler&) = delete; 21 | Sampler& operator=(const Sampler&) = delete; 22 | 23 | Sampler(Sampler&&) = default; 24 | Sampler& operator=(Sampler&&) = default; 25 | 26 | vk::Sampler Handle() const noexcept { 27 | return *handle; 28 | } 29 | 30 | private: 31 | vk::UniqueSampler handle; 32 | }; 33 | 34 | } // namespace VideoCore 35 | -------------------------------------------------------------------------------- /core/libraries/libc_internal/libc_internal.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::LibcInternal { 13 | void* PS4_SYSV_ABI internal_memset(void* s, int c, size_t n); 14 | void* PS4_SYSV_ABI internal_memcpy(void* dest, const void* src, size_t n); 15 | int PS4_SYSV_ABI internal_memcpy_s(void* dest, size_t destsz, const void* src, size_t count); 16 | int PS4_SYSV_ABI internal_strcpy_s(char* dest, size_t dest_size, const char* src); 17 | int PS4_SYSV_ABI internal_memcmp(const void* s1, const void* s2, size_t n); 18 | float PS4_SYSV_ABI internal_expf(float x); 19 | 20 | void RegisterlibSceLibcInternal(Core::Loader::SymbolsResolver* sym); 21 | } // namespace Libraries::LibcInternal -------------------------------------------------------------------------------- /core/libraries/system/userservice_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // UserService library 9 | constexpr int ORBIS_USER_SERVICE_ERROR_INTERNAL = 0x80960001; 10 | constexpr int ORBIS_USER_SERVICE_ERROR_NOT_INITIALIZED = 0x80960002; 11 | constexpr int ORBIS_USER_SERVICE_ERROR_ALREADY_INITIALIZED = 0x80960003; 12 | constexpr int ORBIS_USER_SERVICE_ERROR_NO_MEMORY = 0x80960004; 13 | constexpr int ORBIS_USER_SERVICE_ERROR_INVALID_ARGUMENT = 0x80960005; 14 | constexpr int ORBIS_USER_SERVICE_ERROR_OPERATION_NOT_SUPPORTED = 0x80960006; 15 | constexpr int ORBIS_USER_SERVICE_ERROR_NO_EVENT = 0x80960007; 16 | constexpr int ORBIS_USER_SERVICE_ERROR_NOT_LOGGED_IN = 0x80960009; 17 | constexpr int ORBIS_USER_SERVICE_ERROR_BUFFER_TOO_SHORT = 0x8096000A; 18 | -------------------------------------------------------------------------------- /common/div_ceil.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace Common { 10 | 11 | /// Ceiled integer division. 12 | template 13 | requires std::is_integral_v && std::is_unsigned_v 14 | [[nodiscard]] constexpr N DivCeil(N number, D divisor) { 15 | return static_cast((static_cast(number) + divisor - 1) / divisor); 16 | } 17 | 18 | /// Ceiled integer division with logarithmic divisor in base 2 19 | template 20 | requires std::is_integral_v && std::is_unsigned_v 21 | [[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) { 22 | return static_cast((static_cast(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); 23 | } 24 | 25 | } // namespace Common 26 | -------------------------------------------------------------------------------- /core/file_sys/file.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include 6 | #include 7 | #include "common/types.h" 8 | #include "common/io_file.h" // Per Common::FS::FileAccessMode 9 | 10 | namespace Core::FileSys { 11 | 12 | class File { 13 | public: 14 | int Open(const std::filesystem::path& path, Common::FS::FileAccessMode f_access); 15 | s64 Read(void* buf, size_t nbytes); 16 | s64 Pread(void* buf, size_t nbytes, s64 offset); 17 | s64 Write(const void* buf, size_t nbytes); 18 | s64 Pwrite(const void* buf, size_t nbytes, s64 offset); 19 | void SetSize(s64 size); 20 | void Flush(); 21 | s64 Lseek(s64 offset, int whence); 22 | void Unlink(); 23 | 24 | private: 25 | #ifdef _WIN64 26 | void* handle = nullptr; // HANDLE su Windows 27 | #endif 28 | }; 29 | 30 | } // namespace Core::FileSys -------------------------------------------------------------------------------- /core/libraries/random/random.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "random.h" 5 | #include "random_error.h" 6 | 7 | #include "common/logging/log.h" 8 | #include "core/libraries/error_codes.h" 9 | #include "core/libraries/libs.h" 10 | 11 | namespace Libraries::Random { 12 | 13 | s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, std::size_t size) { 14 | LOG_TRACE(Lib_Random, "called"); 15 | if (size > SCE_RANDOM_MAX_SIZE) { 16 | return SCE_RANDOM_ERROR_INVALID; 17 | } 18 | 19 | for (auto i = 0; i < size; ++i) { 20 | buf[i] = std::rand() & 0xFF; 21 | } 22 | return ORBIS_OK; 23 | } 24 | 25 | void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym) { 26 | LIB_FUNCTION("PI7jIZj4pcE", "libSceRandom", 1, "libSceRandom", 1, 1, sceRandomGetRandomNumber); 27 | }; 28 | 29 | } // namespace Libraries::Random 30 | -------------------------------------------------------------------------------- /common/concepts.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Common { 11 | 12 | // Check if type satisfies the ContiguousContainer named requirement. 13 | template 14 | concept IsContiguousContainer = std::contiguous_iterator; 15 | 16 | template 17 | concept DerivedFrom = std::derived_from; 18 | 19 | // TODO: Replace with std::convertible_to when libc++ implements it. 20 | template 21 | concept ConvertibleTo = std::is_convertible_v; 22 | 23 | // No equivalents in the stdlib 24 | 25 | template 26 | concept IsArithmetic = std::is_arithmetic_v; 27 | 28 | template 29 | concept IsIntegral = std::is_integral_v; 30 | 31 | } // namespace Common 32 | -------------------------------------------------------------------------------- /core/devices/logger.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "base_device.h" 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | namespace Core::Devices { 13 | 14 | class Logger final : BaseDevice { 15 | std::string prefix; 16 | bool is_err; 17 | 18 | std::recursive_mutex mtx; 19 | std::vector buffer; 20 | 21 | public: 22 | explicit Logger(std::string prefix, bool is_err); 23 | 24 | ~Logger() override; 25 | 26 | s64 write(const void* buf, size_t nbytes) override; 27 | size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 28 | s64 pwrite(const void* buf, size_t nbytes, u64 offset) override; 29 | 30 | s32 fsync() override; 31 | 32 | private: 33 | void log(const char* buf, size_t nbytes); 34 | void log_flush(); 35 | }; 36 | 37 | } // namespace Core::Devices 38 | -------------------------------------------------------------------------------- /core/libraries/audio/audioout_backend.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | namespace Libraries::AudioOut { 7 | 8 | struct PortOut; 9 | 10 | class PortBackend { 11 | public: 12 | virtual ~PortBackend() = default; 13 | 14 | /// Guaranteed to be called in intervals of at least port buffer time, 15 | /// with size equal to port buffer size. 16 | virtual void Output(void* ptr) = 0; 17 | 18 | virtual void SetVolume(const std::array& ch_volumes) = 0; 19 | }; 20 | 21 | class AudioOutBackend { 22 | public: 23 | AudioOutBackend() = default; 24 | virtual ~AudioOutBackend() = default; 25 | 26 | virtual std::unique_ptr Open(PortOut& port) = 0; 27 | }; 28 | 29 | class SDLAudioOut final : public AudioOutBackend { 30 | public: 31 | std::unique_ptr Open(PortOut& port) override; 32 | }; 33 | 34 | } // namespace Libraries::AudioOut 35 | -------------------------------------------------------------------------------- /core/libraries/ngs2/ngs2_impl.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "ngs2.h" 7 | 8 | namespace Libraries::Ngs2 { 9 | 10 | class Ngs2 { 11 | public: 12 | s32 ReportInvalid(Ngs2Handle* handle, u32 handle_type) const; 13 | s32 HandleSetup(Ngs2Handle* handle, void* data, std::atomic* atomic, u32 type, u32 flags); 14 | s32 HandleCleanup(Ngs2Handle* handle, u32 hType, void* dataOut); 15 | s32 HandleEnter(Ngs2Handle* handle, u32 hType, Ngs2Handle* handleOut); 16 | s32 HandleLeave(Ngs2Handle* handle); 17 | s32 StackBufferOpen(StackBuffer* buf, void* base_addr, size_t size, void** stackTop, 18 | bool verify); 19 | s32 StackBufferClose(StackBuffer* buf, size_t* usedSize); 20 | s32 SystemSetupCore(StackBuffer* buf, SystemOptions* options, Ngs2Handle** sysOut); 21 | 22 | private: 23 | }; 24 | 25 | } // namespace Libraries::Ngs2 26 | -------------------------------------------------------------------------------- /video_core/renderer_vulkan/vk_shader_util.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "common/types.h" 9 | #include "video_core/renderer_vulkan/vk_common.h" 10 | 11 | namespace Vulkan { 12 | 13 | /** 14 | * @brief Creates a vulkan shader module from GLSL by converting it to SPIR-V using glslang. 15 | * @param code The string containing GLSL code. 16 | * @param stage The pipeline stage the shader will be used in. 17 | * @param device The vulkan device handle. 18 | */ 19 | vk::ShaderModule Compile(std::string_view code, vk::ShaderStageFlagBits stage, vk::Device device); 20 | 21 | /** 22 | * @brief Creates a vulkan shader module from SPIR-V bytecode. 23 | * @param code The SPIR-V bytecode data. 24 | * @param device The vulkan device handle 25 | */ 26 | vk::ShaderModule CompileSPV(std::span code, vk::Device device); 27 | 28 | } // namespace Vulkan 29 | -------------------------------------------------------------------------------- /common/assert.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/arch.h" 5 | #include "common/assert.h" 6 | #include "common/logging/backend.h" 7 | 8 | #if defined(_MSC_VER) 9 | #define Crash() __debugbreak() 10 | #elif defined(ARCH_X86_64) 11 | #define Crash() __asm__ __volatile__("int $3") 12 | #elif defined(ARCH_ARM64) 13 | #define Crash() __asm__ __volatile__("brk 0") 14 | #else 15 | #error "Missing Crash() implementation for target CPU architecture." 16 | #endif 17 | 18 | void assert_fail_impl() { 19 | Common::Log::Stop(); 20 | std::fflush(stdout); 21 | Crash(); 22 | } 23 | 24 | [[noreturn]] void unreachable_impl() { 25 | Common::Log::Stop(); 26 | std::fflush(stdout); 27 | Crash(); 28 | throw std::runtime_error("Unreachable code"); 29 | } 30 | 31 | void assert_fail_debug_msg(const char* msg) { 32 | LOG_CRITICAL(Debug, "Assertion Failed!\n{}", msg); 33 | assert_fail_impl(); 34 | } 35 | -------------------------------------------------------------------------------- /core/aerolib/aerolib.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | #include "common/types.h" 6 | #include "core/aerolib/aerolib.h" 7 | 8 | namespace Core::AeroLib { 9 | 10 | // Use a direct table here + binary search as contents are static 11 | static constexpr NidEntry NIDS[] = { 12 | #define STUB(nid, name) {nid, #name}, 13 | #include "aerolib.inl" 14 | #undef STUB 15 | }; 16 | 17 | const NidEntry* FindByNid(const char* nid) { 18 | s64 l = 0; 19 | s64 r = sizeof(NIDS) / sizeof(NIDS[0]) - 1; 20 | 21 | while (l <= r) { 22 | const size_t m = l + (r - l) / 2; 23 | const int cmp = std::strcmp(NIDS[m].nid, nid); 24 | if (cmp == 0) { 25 | return &NIDS[m]; 26 | } else if (cmp < 0) { 27 | l = m + 1; 28 | } else { 29 | r = m - 1; 30 | } 31 | } 32 | return nullptr; 33 | } 34 | 35 | } // namespace Core::AeroLib 36 | -------------------------------------------------------------------------------- /core/libraries/avplayer/avplayer_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // AvPlayer library 9 | constexpr int ORBIS_AVPLAYER_ERROR_INVALID_PARAMS = 0x806A0001; 10 | constexpr int ORBIS_AVPLAYER_ERROR_OPERATION_FAILED = 0x806A0002; 11 | constexpr int ORBIS_AVPLAYER_ERROR_NO_MEMORY = 0x806A0003; 12 | constexpr int ORBIS_AVPLAYER_ERROR_NOT_SUPPORTED = 0x806A0004; 13 | constexpr int ORBIS_AVPLAYER_ERROR_WAR_FILE_NONINTERLEAVED = 0x806A00A0; 14 | constexpr int ORBIS_AVPLAYER_ERROR_WAR_LOOPING_BACK = 0x806A00A1; 15 | constexpr int ORBIS_AVPLAYER_ERROR_WAR_JUMP_COMPLETE = 0x806A00A3; 16 | constexpr int ORBIS_AVPLAYER_ERROR_INFO_MARLIN_ENCRY = 0x806A00B0; 17 | constexpr int ORBIS_AVPLAYER_ERROR_INFO_PLAYREADY_ENCRY = 0x806A00B4; 18 | constexpr int ORBIS_AVPLAYER_ERROR_INFO_AES_ENCRY = 0x806A00B5; 19 | constexpr int ORBIS_AVPLAYER_ERROR_INFO_OTHER_ENCRY = 0x806A00BF; 20 | -------------------------------------------------------------------------------- /core/libraries/mouse/mouse.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include "common/types.h" 6 | 7 | namespace Core::Loader { 8 | class SymbolsResolver; 9 | } 10 | 11 | namespace Libraries::Mouse { 12 | 13 | int PS4_SYSV_ABI sceMouseClose(); 14 | int PS4_SYSV_ABI sceMouseConnectPort(); 15 | int PS4_SYSV_ABI sceMouseDebugGetDeviceId(); 16 | int PS4_SYSV_ABI sceMouseDeviceOpen(); 17 | int PS4_SYSV_ABI sceMouseDisconnectDevice(); 18 | int PS4_SYSV_ABI sceMouseDisconnectPort(); 19 | int PS4_SYSV_ABI sceMouseGetDeviceInfo(); 20 | int PS4_SYSV_ABI sceMouseInit(); 21 | int PS4_SYSV_ABI sceMouseMbusInit(); 22 | int PS4_SYSV_ABI sceMouseOpen(); 23 | int PS4_SYSV_ABI sceMouseRead(); 24 | int PS4_SYSV_ABI sceMouseSetHandType(); 25 | int PS4_SYSV_ABI sceMouseSetPointerSpeed(); 26 | int PS4_SYSV_ABI sceMouseSetProcessPrivilege(); 27 | 28 | void RegisterlibSceMouse(Core::Loader::SymbolsResolver* sym); 29 | } // namespace Libraries::Mouse -------------------------------------------------------------------------------- /common/decoder.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/singleton.h" 8 | #include "common/types.h" 9 | 10 | namespace Common { 11 | 12 | class DecoderImpl { 13 | public: 14 | DecoderImpl(); 15 | ~DecoderImpl(); 16 | 17 | std::string disassembleInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands, 18 | u64 address); 19 | void printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands, u64 address); 20 | void printInstruction(void* code, u64 address); 21 | ZyanStatus decodeInstruction(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands, 22 | void* data, u64 size = 15); 23 | 24 | private: 25 | ZydisDecoder m_decoder; 26 | ZydisFormatter m_formatter; 27 | }; 28 | 29 | using Decoder = Common::Singleton; 30 | 31 | } // namespace Common 32 | -------------------------------------------------------------------------------- /core/thread.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Libraries::Kernel { 9 | struct PthreadAttr; 10 | } // namespace Libraries::Kernel 11 | 12 | namespace Core { 13 | 14 | using ThreadFunc = void (*)(void*); 15 | using PthreadFunc = void* (*)(void*); 16 | 17 | class NativeThread { 18 | public: 19 | NativeThread(); 20 | ~NativeThread(); 21 | 22 | int Create(ThreadFunc func, void* arg, const ::Libraries::Kernel::PthreadAttr* attr); 23 | void Exit(); 24 | 25 | void Initialize(); 26 | 27 | uintptr_t GetHandle() { 28 | return reinterpret_cast(native_handle); 29 | } 30 | 31 | u64 GetTid() { 32 | return tid; 33 | } 34 | 35 | private: 36 | #ifdef _WIN64 37 | void* native_handle; 38 | #else 39 | uintptr_t native_handle; 40 | void* sig_stack_ptr; 41 | #endif 42 | u64 tid; 43 | }; 44 | 45 | } // namespace Core -------------------------------------------------------------------------------- /core/libraries/ime/error_dialog.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | #include "core/libraries/system/commondialog.h" 8 | 9 | namespace Core::Loader { 10 | class SymbolsResolver; 11 | } 12 | namespace Libraries::ErrorDialog { 13 | 14 | using OrbisUserServiceUserId = s32; 15 | 16 | struct Param; 17 | 18 | CommonDialog::Error PS4_SYSV_ABI sceErrorDialogClose(); 19 | CommonDialog::Status PS4_SYSV_ABI sceErrorDialogGetStatus(); 20 | CommonDialog::Error PS4_SYSV_ABI sceErrorDialogInitialize(); 21 | CommonDialog::Error PS4_SYSV_ABI sceErrorDialogOpen(const Param* param); 22 | int PS4_SYSV_ABI sceErrorDialogOpenDetail(); 23 | int PS4_SYSV_ABI sceErrorDialogOpenWithReport(); 24 | CommonDialog::Error PS4_SYSV_ABI sceErrorDialogTerminate(); 25 | CommonDialog::Status PS4_SYSV_ABI sceErrorDialogUpdateStatus(); 26 | 27 | void RegisterlibSceErrorDialog(Core::Loader::SymbolsResolver* sym); 28 | } // namespace Libraries::ErrorDialog -------------------------------------------------------------------------------- /imgui/renderer/imgui_core.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "video_core/renderer_vulkan/vk_instance.h" 9 | #include "vulkan/vulkan_handles.hpp" 10 | 11 | union SDL_Event; 12 | 13 | namespace Vulkan { 14 | struct Frame; 15 | } 16 | 17 | namespace ImGui::Core { 18 | 19 | void Initialize(const Vulkan::Instance& instance, const Frontend::WindowSDL& window, 20 | u32 image_count, vk::Format surface_format, 21 | const vk::AllocationCallbacks* allocator = nullptr); 22 | 23 | void OnResize(); 24 | 25 | void Shutdown(const vk::Device& device); 26 | 27 | bool ProcessEvent(SDL_Event* event); 28 | 29 | ImGuiID NewFrame(bool is_reusing_frame = false); 30 | 31 | void Render(const vk::CommandBuffer& cmdbuf, const vk::ImageView& image_view, 32 | const vk::Extent2D& extent); 33 | 34 | bool MustKeepDrawing(); // Force the emulator redraw 35 | 36 | } // namespace ImGui::Core 37 | -------------------------------------------------------------------------------- /core/devtools/widget/frame_dump.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include "cmd_list.h" 10 | #include "core/debug_state.h" 11 | 12 | namespace Core::Devtools::Widget { 13 | 14 | class CmdListViewer; 15 | 16 | class FrameDumpViewer { 17 | friend class CmdListViewer; 18 | 19 | std::shared_ptr frame_dump; 20 | int id; 21 | 22 | std::vector cmd_list_viewer; 23 | std::array has_queue_type; 24 | 25 | DebugStateType::QueueType selected_queue_type; 26 | s32 selected_submit_num; 27 | s32 selected_queue_num2; 28 | s32 selected_cmd = -1; 29 | 30 | CmdListFilter filter; 31 | 32 | public: 33 | bool is_open = true; 34 | 35 | explicit FrameDumpViewer(const DebugStateType::FrameDump& frame_dump); 36 | 37 | ~FrameDumpViewer(); 38 | 39 | void Draw(); 40 | }; 41 | 42 | } // namespace Core::Devtools::Widget -------------------------------------------------------------------------------- /core/file_format/splash.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include "common/types.h" 10 | 11 | class Splash { 12 | public: 13 | struct ImageInfo { 14 | u32 width; 15 | u32 height; 16 | u32 num_channels; 17 | 18 | u32 GetSizeBytes() const { 19 | return width * height * 4; // we always forcing rgba8 for simplicity 20 | } 21 | }; 22 | 23 | Splash() = default; 24 | ~Splash() = default; 25 | 26 | bool Open(const std::filesystem::path& filepath); 27 | [[nodiscard]] bool IsLoaded() const { 28 | return img_data.size(); 29 | } 30 | 31 | const auto& GetImageData() const { 32 | return img_data; 33 | } 34 | 35 | ImageInfo GetImageInfo() const { 36 | return img_info; 37 | } 38 | 39 | private: 40 | ImageInfo img_info{}; 41 | std::vector img_data{}; 42 | }; 43 | -------------------------------------------------------------------------------- /common/func_traits.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | namespace Common { 9 | 10 | template 11 | struct FuncTraits {}; 12 | 13 | template 14 | struct FuncTraits { 15 | using ReturnType = ReturnType_; 16 | 17 | static constexpr size_t NUM_ARGS = sizeof...(Args); 18 | 19 | template 20 | using ArgType = std::tuple_element_t>; 21 | }; 22 | 23 | template 24 | struct LambdaTraits : LambdaTraits::operator())> {}; 25 | 26 | template 27 | struct LambdaTraits { 28 | template 29 | using ArgType = std::tuple_element_t>; 30 | 31 | static constexpr size_t NUM_ARGS{sizeof...(Args)}; 32 | }; 33 | 34 | } // namespace Common 35 | -------------------------------------------------------------------------------- /core/libraries/kernel/aio.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "common/types.h" 13 | 14 | namespace Core::Loader { 15 | class SymbolsResolver; 16 | } 17 | 18 | namespace Libraries::Kernel { 19 | 20 | enum AioState { 21 | ORBIS_KERNEL_AIO_STATE_SUBMITTED = 1, 22 | ORBIS_KERNEL_AIO_STATE_PROCESSING = 2, 23 | ORBIS_KERNEL_AIO_STATE_COMPLETED = 3, 24 | ORBIS_KERNEL_AIO_STATE_ABORTED = 4 25 | }; 26 | 27 | struct OrbisKernelAioResult { 28 | s64 returnValue; 29 | u32 state; 30 | }; 31 | 32 | typedef s32 OrbisKernelAioSubmitId; 33 | 34 | struct OrbisKernelAioRWRequest { 35 | s64 offset; 36 | s64 nbyte; 37 | void* buf; 38 | OrbisKernelAioResult* result; 39 | s32 fd; 40 | }; 41 | 42 | void RegisterAio(Core::Loader::SymbolsResolver* sym); 43 | } // namespace Libraries::Kernel -------------------------------------------------------------------------------- /imgui/renderer/imgui_impl_sdl3.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | // Based on imgui_impl_sdl3.h from Dear ImGui repository 5 | 6 | #pragma once 7 | 8 | struct SDL_Window; 9 | struct SDL_Renderer; 10 | struct SDL_Gamepad; 11 | typedef union SDL_Event SDL_Event; 12 | 13 | namespace ImGui::Sdl { 14 | 15 | bool Init(SDL_Window* window); 16 | void Shutdown(); 17 | void NewFrame(bool is_reusing); 18 | bool ProcessEvent(const SDL_Event* event); 19 | void OnResize(); 20 | 21 | // Gamepad selection automatically starts in AutoFirst mode, picking first available SDL_Gamepad. 22 | // You may override this. When using manual mode, caller is responsible for opening/closing gamepad. 23 | enum GamepadMode { 24 | ImGui_ImplSDL3_GamepadMode_AutoFirst, 25 | ImGui_ImplSDL3_GamepadMode_AutoAll, 26 | ImGui_ImplSDL3_GamepadMode_Manual 27 | }; 28 | void SetGamepadMode(GamepadMode mode, SDL_Gamepad** manual_gamepads_array = NULL, 29 | int manual_gamepads_count = -1); 30 | 31 | }; // namespace ImGui::Sdl 32 | -------------------------------------------------------------------------------- /common/spin_lock.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/spin_lock.h" 5 | 6 | #if _MSC_VER 7 | #include 8 | #if _M_AMD64 9 | #define __x86_64__ 1 10 | #endif 11 | #if _M_ARM64 12 | #define __aarch64__ 1 13 | #endif 14 | #else 15 | #if __x86_64__ 16 | #include 17 | #endif 18 | #endif 19 | 20 | namespace { 21 | 22 | void ThreadPause() { 23 | #if __x86_64__ 24 | _mm_pause(); 25 | #elif __aarch64__ && _MSC_VER 26 | __yield(); 27 | #elif __aarch64__ 28 | asm("yield"); 29 | #endif 30 | } 31 | 32 | } // Anonymous namespace 33 | 34 | namespace Common { 35 | 36 | void SpinLock::lock() { 37 | while (lck.test_and_set(std::memory_order_acquire)) { 38 | ThreadPause(); 39 | } 40 | } 41 | 42 | void SpinLock::unlock() { 43 | lck.clear(std::memory_order_release); 44 | } 45 | 46 | bool SpinLock::try_lock() { 47 | if (lck.test_and_set(std::memory_order_acquire)) { 48 | return false; 49 | } 50 | return true; 51 | } 52 | 53 | } // namespace Common 54 | -------------------------------------------------------------------------------- /common/types.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | using s8 = std::int8_t; 10 | using s16 = std::int16_t; 11 | using s32 = std::int32_t; 12 | using s64 = std::int64_t; 13 | 14 | using u8 = std::uint8_t; 15 | using u16 = std::uint16_t; 16 | using u32 = std::uint32_t; 17 | using u64 = std::uint64_t; 18 | 19 | using f32 = float; 20 | using f64 = double; 21 | 22 | using u128 = std::array; 23 | static_assert(sizeof(u128) == 16, "u128 must be 128 bits wide"); 24 | 25 | using VAddr = uintptr_t; 26 | using PAddr = uintptr_t; 27 | 28 | #define PS4_SYSV_ABI __attribute__((sysv_abi)) 29 | 30 | // UDLs for memory size values 31 | constexpr unsigned long long operator""_KB(unsigned long long x) { 32 | return 1024ULL * x; 33 | } 34 | constexpr unsigned long long operator""_MB(unsigned long long x) { 35 | return 1024_KB * x; 36 | } 37 | constexpr unsigned long long operator""_GB(unsigned long long x) { 38 | return 1024_MB * x; 39 | } 40 | -------------------------------------------------------------------------------- /common/fixed_value.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | /** 7 | * @brief A template class that encapsulates a fixed, compile-time constant value. 8 | * 9 | * @tparam T The type of the value. 10 | * @tparam Value The fixed value of type T. 11 | * 12 | * This class provides a way to encapsulate a value that is constant and known at compile-time. 13 | * The value is stored as a private member and cannot be changed. Any attempt to assign a new 14 | * value to an object of this class will reset it to the fixed value. 15 | */ 16 | template 17 | class FixedValue { 18 | T m_value{Value}; 19 | 20 | public: 21 | constexpr FixedValue() = default; 22 | 23 | constexpr explicit(false) operator T() const { 24 | return m_value; 25 | } 26 | 27 | FixedValue& operator=(const T&) { 28 | m_value = Value; 29 | return *this; 30 | } 31 | FixedValue& operator=(T&&) noexcept { 32 | m_value = {Value}; 33 | return *this; 34 | } 35 | }; 36 | -------------------------------------------------------------------------------- /core/libraries/avplayer/avplayer_file_streamer.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "core/libraries/avplayer/avplayer.h" 8 | #include "core/libraries/avplayer/avplayer_data_streamer.h" 9 | 10 | struct AVIOContext; 11 | 12 | namespace Libraries::AvPlayer { 13 | 14 | class AvPlayerFileStreamer : public IDataStreamer { 15 | public: 16 | AvPlayerFileStreamer(const SceAvPlayerFileReplacement& file_replacement); 17 | ~AvPlayerFileStreamer(); 18 | 19 | bool Init(std::string_view path) override; 20 | 21 | AVIOContext* GetContext() override { 22 | return m_avio_context; 23 | } 24 | 25 | private: 26 | static s32 ReadPacket(void* opaque, u8* buffer, s32 size); 27 | static s64 Seek(void* opaque, s64 buffer, int whence); 28 | 29 | SceAvPlayerFileReplacement m_file_replacement; 30 | 31 | int m_fd = -1; 32 | u64 m_position{}; 33 | u64 m_file_size{}; 34 | AVIOContext* m_avio_context{}; 35 | }; 36 | 37 | } // namespace Libraries::AvPlayer 38 | -------------------------------------------------------------------------------- /core/libraries/pad/pad_errors.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // Pad library 9 | constexpr int ORBIS_PAD_ERROR_INVALID_ARG = 0x80920001; 10 | constexpr int ORBIS_PAD_ERROR_INVALID_PORT = 0x80920002; 11 | constexpr int ORBIS_PAD_ERROR_INVALID_HANDLE = 0x80920003; 12 | constexpr int ORBIS_PAD_ERROR_ALREADY_OPENED = 0x80920004; 13 | constexpr int ORBIS_PAD_ERROR_NOT_INITIALIZED = 0x80920005; 14 | constexpr int ORBIS_PAD_ERROR_INVALID_LIGHTBAR_SETTING = 0x80920006; 15 | constexpr int ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED = 0x80920007; 16 | constexpr int ORBIS_PAD_ERROR_DEVICE_NO_HANDLE = 0x80920008; 17 | constexpr int ORBIS_PAD_ERROR_FATAL = 0x809200FF; 18 | constexpr int ORBIS_PAD_ERROR_NOT_PERMITTED = 0x80920101; 19 | constexpr int ORBIS_PAD_ERROR_INVALID_BUFFER_LENGTH = 0x80920102; 20 | constexpr int ORBIS_PAD_ERROR_INVALID_REPORT_LENGTH = 0x80920103; 21 | constexpr int ORBIS_PAD_ERROR_INVALID_REPORT_ID = 0x80920104; 22 | constexpr int ORBIS_PAD_ERROR_SEND_AGAIN = 0x80920105; 23 | -------------------------------------------------------------------------------- /core/libraries/screenshot/screenshot.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::ScreenShot { 13 | 14 | int PS4_SYSV_ABI _Z5dummyv(); 15 | int PS4_SYSV_ABI sceScreenShotCapture(); 16 | int PS4_SYSV_ABI sceScreenShotDisable(); 17 | int PS4_SYSV_ABI sceScreenShotDisableNotification(); 18 | int PS4_SYSV_ABI sceScreenShotEnable(); 19 | int PS4_SYSV_ABI sceScreenShotEnableNotification(); 20 | int PS4_SYSV_ABI sceScreenShotGetAppInfo(); 21 | int PS4_SYSV_ABI sceScreenShotGetDrcParam(); 22 | int PS4_SYSV_ABI sceScreenShotIsDisabled(); 23 | int PS4_SYSV_ABI sceScreenShotIsVshScreenCaptureDisabled(); 24 | int PS4_SYSV_ABI sceScreenShotSetOverlayImage(); 25 | int PS4_SYSV_ABI sceScreenShotSetOverlayImageWithOrigin(); 26 | int PS4_SYSV_ABI sceScreenShotSetParam(); 27 | int PS4_SYSV_ABI sceScreenShotSetDrcParam(); 28 | 29 | void RegisterlibSceScreenShot(Core::Loader::SymbolsResolver* sym); 30 | } // namespace Libraries::ScreenShot -------------------------------------------------------------------------------- /core/libraries/kernel/sync/mutex.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "mutex.h" 5 | 6 | #include "common/assert.h" 7 | 8 | namespace Libraries::Kernel { 9 | 10 | TimedMutex::TimedMutex() { 11 | #ifdef _WIN64 12 | mtx = CreateMutex(nullptr, false, nullptr); 13 | ASSERT(mtx); 14 | #endif 15 | } 16 | 17 | TimedMutex::~TimedMutex() { 18 | #ifdef _WIN64 19 | CloseHandle(mtx); 20 | #endif 21 | } 22 | 23 | void TimedMutex::lock() { 24 | #ifdef _WIN64 25 | for (;;) { 26 | u64 res = WaitForSingleObjectEx(mtx, INFINITE, true); 27 | if (res == WAIT_OBJECT_0) { 28 | return; 29 | } 30 | } 31 | #else 32 | mtx.lock(); 33 | #endif 34 | } 35 | 36 | bool TimedMutex::try_lock() { 37 | #ifdef _WIN64 38 | return WaitForSingleObjectEx(mtx, 0, true) == WAIT_OBJECT_0; 39 | #else 40 | return mtx.try_lock(); 41 | #endif 42 | } 43 | 44 | void TimedMutex::unlock() { 45 | #ifdef _WIN64 46 | ReleaseMutex(mtx); 47 | #else 48 | mtx.unlock(); 49 | #endif 50 | } 51 | 52 | } // namespace Libraries::Kernel -------------------------------------------------------------------------------- /common/ntapi.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #ifdef _WIN32 5 | 6 | #include "ntapi.h" 7 | 8 | NtClose_t NtClose = nullptr; 9 | NtSetInformationFile_t NtSetInformationFile = nullptr; 10 | NtCreateThread_t NtCreateThread = nullptr; 11 | NtTerminateThread_t NtTerminateThread = nullptr; 12 | NtQueueApcThreadEx_t NtQueueApcThreadEx = nullptr; 13 | 14 | namespace Common::NtApi { 15 | 16 | void Initialize() { 17 | HMODULE nt_handle = GetModuleHandleA("ntdll.dll"); 18 | 19 | // http://stackoverflow.com/a/31411628/4725495 20 | NtClose = (NtClose_t)GetProcAddress(nt_handle, "NtClose"); 21 | NtSetInformationFile = 22 | (NtSetInformationFile_t)GetProcAddress(nt_handle, "NtSetInformationFile"); 23 | NtCreateThread = (NtCreateThread_t)GetProcAddress(nt_handle, "NtCreateThread"); 24 | NtTerminateThread = (NtTerminateThread_t)GetProcAddress(nt_handle, "NtTerminateThread"); 25 | NtQueueApcThreadEx = (NtQueueApcThreadEx_t)GetProcAddress(nt_handle, "NtQueueApcThreadEx"); 26 | } 27 | 28 | } // namespace Common::NtApi 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /core/libraries/np_trophy/trophy_ui.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "common/fixed_value.h" 11 | #include "common/types.h" 12 | #include "core/libraries/np_trophy/np_trophy.h" 13 | #include "imgui/imgui_layer.h" 14 | #include "imgui/imgui_texture.h" 15 | 16 | namespace Libraries::NpTrophy { 17 | 18 | class TrophyUI final : public ImGui::Layer { 19 | public: 20 | TrophyUI(const std::filesystem::path& trophyIconPath, const std::string& trophyName); 21 | ~TrophyUI() override; 22 | 23 | void Finish(); 24 | 25 | void Draw() override; 26 | 27 | private: 28 | std::string trophy_name; 29 | float trophy_timer = 5.0f; 30 | ImGui::RefCountedTexture trophy_icon; 31 | }; 32 | 33 | struct TrophyInfo { 34 | std::filesystem::path trophy_icon_path; 35 | std::string trophy_name; 36 | }; 37 | 38 | void AddTrophyToQueue(const std::filesystem::path& trophyIconPath, const std::string& trophyName); 39 | 40 | }; // namespace Libraries::NpTrophy -------------------------------------------------------------------------------- /common/native_clock.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/native_clock.h" 5 | #include "common/rdtsc.h" 6 | #include "common/uint128.h" 7 | 8 | namespace Common { 9 | 10 | NativeClock::NativeClock() 11 | : rdtsc_frequency{EstimateRDTSCFrequency()}, 12 | ns_rdtsc_factor{GetFixedPoint64Factor(std::nano::den, rdtsc_frequency)}, 13 | us_rdtsc_factor{GetFixedPoint64Factor(std::micro::den, rdtsc_frequency)}, 14 | ms_rdtsc_factor{GetFixedPoint64Factor(std::milli::den, rdtsc_frequency)} {} 15 | 16 | u64 NativeClock::GetTimeNS(u64 base_ptc /*= 0*/) const { 17 | return MultiplyHigh(GetUptime() - base_ptc, ns_rdtsc_factor); 18 | } 19 | 20 | u64 NativeClock::GetTimeUS(u64 base_ptc /*= 0*/) const { 21 | return MultiplyHigh(GetUptime() - base_ptc, us_rdtsc_factor); 22 | } 23 | 24 | u64 NativeClock::GetTimeMS(u64 base_ptc /*= 0*/) const { 25 | return MultiplyHigh(GetUptime() - base_ptc, ms_rdtsc_factor); 26 | } 27 | 28 | u64 NativeClock::GetUptime() const { 29 | return FencedRDTSC(); 30 | } 31 | 32 | } // namespace Common 33 | -------------------------------------------------------------------------------- /core/libraries/kernel/threads/sleepq.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Libraries::Kernel { 9 | 10 | struct Pthread; 11 | struct SleepQueue; 12 | 13 | using ListBaseHook = 14 | boost::intrusive::list_base_hook>; 15 | 16 | using SleepqList = boost::intrusive::list>; 17 | 18 | struct SleepQueue : public ListBaseHook { 19 | std::forward_list sq_blocked; 20 | SleepqList sq_freeq; 21 | void* sq_wchan; 22 | int sq_type; 23 | }; 24 | 25 | void SleepqLock(void* wchan); 26 | 27 | void SleepqUnlock(void* wchan); 28 | 29 | SleepQueue* SleepqLookup(void* wchan); 30 | 31 | void SleepqAdd(void* wchan, Pthread* td); 32 | 33 | int SleepqRemove(SleepQueue* sq, Pthread* td); 34 | 35 | void SleepqDrop(SleepQueue* sq, void (*callback)(Pthread*, void*), void* arg); 36 | 37 | } // namespace Libraries::Kernel 38 | -------------------------------------------------------------------------------- /core/loader/dwarf.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright (C) 2001-2024 Free Software Foundation, Inc. 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Dwarf { 9 | 10 | enum { 11 | DW_EH_PE_ptr = 0x00, 12 | DW_EH_PE_uleb128 = 0x01, 13 | DW_EH_PE_udata2 = 0x02, 14 | DW_EH_PE_udata4 = 0x03, 15 | DW_EH_PE_udata8 = 0x04, 16 | DW_EH_PE_signed = 0x08, 17 | DW_EH_PE_sleb128 = 0x09, 18 | DW_EH_PE_sdata2 = 0x0A, 19 | DW_EH_PE_sdata4 = 0x0B, 20 | DW_EH_PE_sdata8 = 0x0C, 21 | DW_EH_PE_absptr = 0x00, 22 | DW_EH_PE_pcrel = 0x10, 23 | DW_EH_PE_textrel = 0x20, 24 | DW_EH_PE_datarel = 0x30, 25 | DW_EH_PE_funcrel = 0x40, 26 | DW_EH_PE_aligned = 0x50, 27 | DW_EH_PE_indirect = 0x80, 28 | DW_EH_PE_omit = 0xFF 29 | }; 30 | 31 | /// Information encoded in the EH frame header. 32 | struct EHHeaderInfo { 33 | uintptr_t eh_frame_ptr; 34 | size_t fde_count; 35 | uintptr_t table; 36 | u8 table_enc; 37 | }; 38 | 39 | bool DecodeEHHdr(uintptr_t ehHdrStart, uintptr_t ehHdrEnd, EHHeaderInfo& ehHdrInfo); 40 | 41 | } // namespace Dwarf 42 | -------------------------------------------------------------------------------- /core/libraries/videodec/videodec_impl.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "videodec.h" 9 | 10 | extern "C" { 11 | #include 12 | #include 13 | #include 14 | } 15 | 16 | namespace Libraries::Videodec { 17 | 18 | class VdecDecoder { 19 | public: 20 | VdecDecoder(const OrbisVideodecConfigInfo& pCfgInfoIn, 21 | const OrbisVideodecResourceInfo& pRsrcInfoIn); 22 | ~VdecDecoder(); 23 | s32 Decode(const OrbisVideodecInputData& pInputDataIn, 24 | OrbisVideodecFrameBuffer& pFrameBufferInOut, 25 | OrbisVideodecPictureInfo& pPictureInfoOut); 26 | s32 Flush(OrbisVideodecFrameBuffer& pFrameBufferInOut, 27 | OrbisVideodecPictureInfo& pPictureInfoOut); 28 | s32 Reset(); 29 | 30 | private: 31 | AVFrame* ConvertNV12Frame(AVFrame& frame); 32 | 33 | private: 34 | AVCodecContext* mCodecContext = nullptr; 35 | SwsContext* mSwsContext = nullptr; 36 | }; 37 | 38 | } // namespace Libraries::Videodec -------------------------------------------------------------------------------- /common/thread.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project 2 | // SPDX-FileCopyrightText: 2014 Citra Emulator Project 3 | // SPDX-License-Identifier: GPL-2.0-or-later 4 | 5 | #pragma once 6 | 7 | #include 8 | #include "common/types.h" 9 | 10 | namespace Common { 11 | 12 | enum class ThreadPriority : u32 { 13 | Low = 0, 14 | Normal = 1, 15 | High = 2, 16 | VeryHigh = 3, 17 | Critical = 4, 18 | }; 19 | 20 | void SetCurrentThreadRealtime(std::chrono::nanoseconds period_ns); 21 | 22 | void SetCurrentThreadPriority(ThreadPriority new_priority); 23 | 24 | void SetCurrentThreadName(const char* name); 25 | 26 | void SetThreadName(void* thread, const char* name); 27 | 28 | class AccurateTimer { 29 | std::chrono::nanoseconds target_interval{}; 30 | std::chrono::nanoseconds total_wait{}; 31 | 32 | std::chrono::high_resolution_clock::time_point start_time; 33 | 34 | public: 35 | explicit AccurateTimer(std::chrono::nanoseconds target_interval); 36 | 37 | void Start(); 38 | 39 | void End(); 40 | 41 | std::chrono::nanoseconds GetTotalWait() const { 42 | return total_wait; 43 | } 44 | }; 45 | 46 | } // namespace Common 47 | -------------------------------------------------------------------------------- /core/libraries/videodec/videodec2_impl.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "videodec2.h" 9 | 10 | extern "C" { 11 | #include 12 | #include 13 | #include 14 | } 15 | 16 | namespace Libraries::Vdec2 { 17 | 18 | extern std::vector gPictureInfos; 19 | 20 | class VdecDecoder { 21 | public: 22 | VdecDecoder(const OrbisVideodec2DecoderConfigInfo& configInfo, 23 | const OrbisVideodec2DecoderMemoryInfo& memoryInfo); 24 | ~VdecDecoder(); 25 | 26 | s32 Decode(const OrbisVideodec2InputData& inputData, OrbisVideodec2FrameBuffer& frameBuffer, 27 | OrbisVideodec2OutputInfo& outputInfo); 28 | s32 Flush(OrbisVideodec2FrameBuffer& frameBuffer, OrbisVideodec2OutputInfo& outputInfo); 29 | s32 Reset(); 30 | 31 | private: 32 | AVFrame* ConvertNV12Frame(AVFrame& frame); 33 | 34 | private: 35 | AVCodecContext* mCodecContext = nullptr; 36 | SwsContext* mSwsContext = nullptr; 37 | }; 38 | 39 | } // namespace Libraries::Vdec2 -------------------------------------------------------------------------------- /core/devtools/options.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | 6 | #include "options.h" 7 | 8 | namespace Core::Devtools { 9 | 10 | TOptions Options; 11 | 12 | void LoadOptionsConfig(const char* line) { 13 | char str[512]; 14 | int i; 15 | if (sscanf(line, "disassembler_cli_isa=%511[^\n]", str) == 1) { 16 | Options.disassembler_cli_isa = str; 17 | return; 18 | } 19 | if (sscanf(line, "disassembler_cli_spv=%511[^\n]", str) == 1) { 20 | Options.disassembler_cli_spv = str; 21 | return; 22 | } 23 | if (sscanf(line, "frame_dump_render_on_collapse=%d", &i) == 1) { 24 | Options.frame_dump_render_on_collapse = i != 0; 25 | return; 26 | } 27 | } 28 | 29 | void SerializeOptionsConfig(ImGuiTextBuffer* buf) { 30 | buf->appendf("disassembler_cli_isa=%s\n", Options.disassembler_cli_isa.c_str()); 31 | buf->appendf("disassembler_cli_spv=%s\n", Options.disassembler_cli_spv.c_str()); 32 | buf->appendf("frame_dump_render_on_collapse=%d\n", Options.frame_dump_render_on_collapse); 33 | } 34 | 35 | } // namespace Core::Devtools 36 | -------------------------------------------------------------------------------- /core/libraries/network/net_ctl_obj.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/types.h" 8 | 9 | namespace Libraries::NetCtl { 10 | 11 | using OrbisNetCtlCallback = PS4_SYSV_ABI void (*)(int eventType, void* arg); 12 | using OrbisNetCtlCallbackForNpToolkit = PS4_SYSV_ABI void (*)(int eventType, void* arg); 13 | 14 | struct NetCtlCallback { 15 | OrbisNetCtlCallback func; 16 | void* arg; 17 | }; 18 | 19 | struct NetCtlCallbackForNpToolkit { 20 | OrbisNetCtlCallbackForNpToolkit func; 21 | void* arg; 22 | }; 23 | 24 | class NetCtlInternal { 25 | public: 26 | explicit NetCtlInternal(); 27 | ~NetCtlInternal(); 28 | 29 | s32 RegisterCallback(OrbisNetCtlCallback func, void* arg); 30 | s32 RegisterNpToolkitCallback(OrbisNetCtlCallbackForNpToolkit func, void* arg); 31 | void CheckCallback(); 32 | void CheckNpToolkitCallback(); 33 | 34 | public: 35 | std::array nptool_callbacks{}; 36 | std::array callbacks{}; 37 | std::mutex m_mutex; 38 | }; 39 | } // namespace Libraries::NetCtl 40 | -------------------------------------------------------------------------------- /core/libraries/web_browser_dialog/webbrowserdialog.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::WebBrowserDialog { 13 | 14 | s32 PS4_SYSV_ABI sceWebBrowserDialogClose(); 15 | s32 PS4_SYSV_ABI sceWebBrowserDialogGetEvent(); 16 | s32 PS4_SYSV_ABI sceWebBrowserDialogGetResult(); 17 | s32 PS4_SYSV_ABI sceWebBrowserDialogGetStatus(); 18 | s32 PS4_SYSV_ABI sceWebBrowserDialogInitialize(); 19 | s32 PS4_SYSV_ABI sceWebBrowserDialogNavigate(); 20 | s32 PS4_SYSV_ABI sceWebBrowserDialogOpen(); 21 | s32 PS4_SYSV_ABI sceWebBrowserDialogOpenForPredeterminedContent(); 22 | s32 PS4_SYSV_ABI sceWebBrowserDialogResetCookie(); 23 | s32 PS4_SYSV_ABI sceWebBrowserDialogSetCookie(); 24 | s32 PS4_SYSV_ABI sceWebBrowserDialogSetZoom(); 25 | s32 PS4_SYSV_ABI sceWebBrowserDialogTerminate(); 26 | s32 PS4_SYSV_ABI sceWebBrowserDialogUpdateStatus(); 27 | s32 PS4_SYSV_ABI Func_F2BE042771625F8C(); 28 | 29 | void RegisterlibSceWebBrowserDialog(Core::Loader::SymbolsResolver* sym); 30 | } // namespace Libraries::WebBrowserDialog -------------------------------------------------------------------------------- /core/devtools/widget/shader_list.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/debug_state.h" 7 | #include "text_editor.h" 8 | 9 | #include 10 | 11 | namespace Core::Devtools::Widget { 12 | 13 | class ShaderList { 14 | struct Selection { 15 | explicit Selection(int index); 16 | ~Selection(); 17 | Selection(const Selection& other) = delete; 18 | Selection(Selection&& other) noexcept; 19 | Selection& operator=(Selection other); 20 | 21 | void ReloadShader(DebugStateType::ShaderDump& value); 22 | 23 | bool DrawShader(DebugStateType::ShaderDump& value); 24 | 25 | int index{-1}; 26 | std::unique_ptr isa_editor{}; 27 | std::unique_ptr glsl_editor{}; 28 | bool open = true; 29 | bool showing_bin = false; 30 | 31 | std::filesystem::path patch_path; 32 | std::filesystem::path patch_bin_path; 33 | }; 34 | 35 | std::vector open_shaders{}; 36 | 37 | char search_box[128]{}; 38 | 39 | public: 40 | bool open = false; 41 | 42 | void Draw(); 43 | }; 44 | 45 | } // namespace Core::Devtools::Widget -------------------------------------------------------------------------------- /imgui/imgui_texture.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace ImGui { 10 | 11 | namespace Core::TextureManager { 12 | struct Inner; 13 | } // namespace Core::TextureManager 14 | 15 | class RefCountedTexture { 16 | Core::TextureManager::Inner* inner; 17 | 18 | explicit RefCountedTexture(Core::TextureManager::Inner* inner); 19 | 20 | public: 21 | struct Image { 22 | ImTextureID im_id; 23 | u32 width; 24 | u32 height; 25 | }; 26 | 27 | static RefCountedTexture DecodePngTexture(std::vector data); 28 | 29 | static RefCountedTexture DecodePngFile(std::filesystem::path path); 30 | 31 | RefCountedTexture(); 32 | 33 | RefCountedTexture(const RefCountedTexture& other); 34 | RefCountedTexture(RefCountedTexture&& other) noexcept; 35 | RefCountedTexture& operator=(const RefCountedTexture& other); 36 | RefCountedTexture& operator=(RefCountedTexture&& other) noexcept; 37 | 38 | virtual ~RefCountedTexture(); 39 | 40 | [[nodiscard]] Image GetTexture() const; 41 | 42 | explicit(false) operator bool() const; 43 | }; 44 | 45 | }; // namespace ImGui -------------------------------------------------------------------------------- /core/tls.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Xbyak { 9 | class CodeGenerator; 10 | } 11 | 12 | namespace Libraries::Fiber { 13 | struct OrbisFiberContext; 14 | } 15 | 16 | namespace Core { 17 | 18 | union DtvEntry { 19 | std::size_t counter; 20 | u8* pointer; 21 | }; 22 | 23 | struct Tcb { 24 | Tcb* tcb_self; 25 | DtvEntry* tcb_dtv; 26 | void* tcb_thread; 27 | ::Libraries::Fiber::OrbisFiberContext* tcb_fiber; 28 | }; 29 | 30 | #ifdef _WIN32 31 | /// Gets the thread local storage key for the TCB block. 32 | u32 GetTcbKey(); 33 | #endif 34 | 35 | /// Sets the data pointer to the TCB block. 36 | void SetTcbBase(void* image_address); 37 | 38 | /// Retrieves Tcb structure for the calling thread. 39 | Tcb* GetTcbBase(); 40 | 41 | /// Makes sure TLS is initialized for the thread before entering guest. 42 | void EnsureThreadInitialized(); 43 | 44 | template 45 | ReturnType ExecuteGuest(PS4_SYSV_ABI ReturnType (*func)(FuncArgs...), CallArgs&&... args) { 46 | EnsureThreadInitialized(); 47 | return func(std::forward(args)...); 48 | } 49 | 50 | } // namespace Core 51 | -------------------------------------------------------------------------------- /core/devices/console_device.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include 6 | #include "base_device.h" 7 | 8 | namespace Core::Devices { 9 | 10 | class ConsoleDevice final : BaseDevice { 11 | u32 handle; 12 | 13 | public: 14 | static std::shared_ptr Create(u32 handle, const char*, int, u16); 15 | explicit ConsoleDevice(u32 handle) : handle(handle) {} 16 | 17 | ~ConsoleDevice() override = default; 18 | 19 | int ioctl(u64 cmd, Common::VaCtx* args) override; 20 | s64 write(const void* buf, size_t nbytes) override; 21 | size_t readv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 22 | size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 23 | s64 preadv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt, u64 offset) override; 24 | s64 lseek(s64 offset, int whence) override; 25 | s64 read(void* buf, size_t nbytes) override; 26 | int fstat(Libraries::Kernel::OrbisKernelStat* sb) override; 27 | s32 fsync() override; 28 | int ftruncate(s64 length) override; 29 | int getdents(void* buf, u32 nbytes, s64* basep) override; 30 | s64 pwrite(const void* buf, size_t nbytes, u64 offset) override; 31 | }; 32 | 33 | } // namespace Core::Devices -------------------------------------------------------------------------------- /core/devices/random_device.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include 6 | #include "base_device.h" 7 | 8 | namespace Core::Devices { 9 | 10 | class RandomDevice final : BaseDevice { 11 | u32 handle; 12 | 13 | public: 14 | static std::shared_ptr Create(u32 handle, const char*, int, u16); 15 | explicit RandomDevice(u32 handle) : handle(handle) {} 16 | 17 | ~RandomDevice() override = default; 18 | 19 | int ioctl(u64 cmd, Common::VaCtx* args) override; 20 | s64 write(const void* buf, size_t nbytes) override; 21 | size_t readv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 22 | size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 23 | s64 preadv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt, u64 offset) override; 24 | s64 lseek(s64 offset, int whence) override; 25 | s64 read(void* buf, size_t nbytes) override; 26 | int fstat(Libraries::Kernel::OrbisKernelStat* sb) override; 27 | s32 fsync() override; 28 | int ftruncate(s64 length) override; 29 | int getdents(void* buf, u32 nbytes, s64* basep) override; 30 | s64 pwrite(const void* buf, size_t nbytes, u64 offset) override; 31 | }; 32 | 33 | } // namespace Core::Devices -------------------------------------------------------------------------------- /core/devices/srandom_device.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include 6 | #include "base_device.h" 7 | 8 | namespace Core::Devices { 9 | 10 | class SRandomDevice final : BaseDevice { 11 | u32 handle; 12 | 13 | public: 14 | static std::shared_ptr Create(u32 handle, const char*, int, u16); 15 | explicit SRandomDevice(u32 handle) : handle(handle) {} 16 | 17 | ~SRandomDevice() override = default; 18 | 19 | int ioctl(u64 cmd, Common::VaCtx* args) override; 20 | s64 write(const void* buf, size_t nbytes) override; 21 | size_t readv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 22 | size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 23 | s64 preadv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt, u64 offset) override; 24 | s64 lseek(s64 offset, int whence) override; 25 | s64 read(void* buf, size_t nbytes) override; 26 | int fstat(Libraries::Kernel::OrbisKernelStat* sb) override; 27 | s32 fsync() override; 28 | int ftruncate(s64 length) override; 29 | int getdents(void* buf, u32 nbytes, s64* basep) override; 30 | s64 pwrite(const void* buf, size_t nbytes, u64 offset) override; 31 | }; 32 | 33 | } // namespace Core::Devices -------------------------------------------------------------------------------- /core/devices/urandom_device.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include 6 | #include "base_device.h" 7 | 8 | namespace Core::Devices { 9 | 10 | class URandomDevice final : BaseDevice { 11 | u32 handle; 12 | 13 | public: 14 | static std::shared_ptr Create(u32 handle, const char*, int, u16); 15 | explicit URandomDevice(u32 handle) : handle(handle) {} 16 | 17 | ~URandomDevice() override = default; 18 | 19 | int ioctl(u64 cmd, Common::VaCtx* args) override; 20 | s64 write(const void* buf, size_t nbytes) override; 21 | size_t readv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 22 | size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 23 | s64 preadv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt, u64 offset) override; 24 | s64 lseek(s64 offset, int whence) override; 25 | s64 read(void* buf, size_t nbytes) override; 26 | int fstat(Libraries::Kernel::OrbisKernelStat* sb) override; 27 | s32 fsync() override; 28 | int ftruncate(s64 length) override; 29 | int getdents(void* buf, u32 nbytes, s64* basep) override; 30 | s64 pwrite(const void* buf, size_t nbytes, u64 offset) override; 31 | }; 32 | 33 | } // namespace Core::Devices -------------------------------------------------------------------------------- /core/devices/deci_tty6_device.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include 6 | #include "base_device.h" 7 | 8 | namespace Core::Devices { 9 | 10 | class DeciTty6Device final : BaseDevice { 11 | u32 handle; 12 | 13 | public: 14 | static std::shared_ptr Create(u32 handle, const char*, int, u16); 15 | explicit DeciTty6Device(u32 handle) : handle(handle) {} 16 | 17 | ~DeciTty6Device() override = default; 18 | 19 | int ioctl(u64 cmd, Common::VaCtx* args) override; 20 | s64 write(const void* buf, size_t nbytes) override; 21 | size_t readv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 22 | size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override; 23 | s64 preadv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt, u64 offset) override; 24 | s64 lseek(s64 offset, int whence) override; 25 | s64 read(void* buf, size_t nbytes) override; 26 | int fstat(Libraries::Kernel::OrbisKernelStat* sb) override; 27 | s32 fsync() override; 28 | int ftruncate(s64 length) override; 29 | int getdents(void* buf, u32 nbytes, s64* basep) override; 30 | s64 pwrite(const void* buf, size_t nbytes, u64 offset) override; 31 | }; 32 | 33 | } // namespace Core::Devices -------------------------------------------------------------------------------- /common/rdtsc.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/arch.h" 7 | 8 | #ifdef _MSC_VER 9 | #include 10 | #endif 11 | 12 | #include "common/types.h" 13 | 14 | namespace Common { 15 | 16 | #ifdef _MSC_VER 17 | __forceinline static u64 FencedRDTSC() { 18 | #ifdef ARCH_X86_64 19 | _mm_lfence(); 20 | _ReadWriteBarrier(); 21 | const u64 result = __rdtsc(); 22 | _mm_lfence(); 23 | _ReadWriteBarrier(); 24 | return result; 25 | #else 26 | #error "Missing FencedRDTSC() implementation for target CPU architecture." 27 | #endif 28 | } 29 | #else 30 | static inline u64 FencedRDTSC() { 31 | #ifdef ARCH_X86_64 32 | u64 eax; 33 | u64 edx; 34 | asm volatile("lfence\n\t" 35 | "rdtsc\n\t" 36 | "lfence\n\t" 37 | : "=a"(eax), "=d"(edx)); 38 | return (edx << 32) | eax; 39 | #elif defined(ARCH_ARM64) 40 | u64 ret; 41 | asm volatile("isb\n\t" 42 | "mrs %0, cntvct_el0\n\t" 43 | "isb\n\t" 44 | : "=r"(ret)::"memory"); 45 | return ret; 46 | #else 47 | #error "Missing FencedRDTSC() implementation for target CPU architecture." 48 | #endif 49 | } 50 | #endif 51 | 52 | u64 EstimateRDTSCFrequency(); 53 | 54 | } // namespace Common 55 | -------------------------------------------------------------------------------- /core/file_format/splash.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | 6 | #include "common/assert.h" 7 | #include "common/io_file.h" 8 | #include "common/stb.h" 9 | #include "splash.h" 10 | 11 | bool Splash::Open(const std::filesystem::path& filepath) { 12 | ASSERT_MSG(filepath.extension().string() == ".png", "Unexpected file format passed"); 13 | 14 | Common::FS::IOFile file(filepath, Common::FS::FileAccessMode::Read); 15 | if (!file.IsOpen()) { 16 | return false; 17 | } 18 | 19 | std::vector png_file{}; 20 | const auto png_size = file.GetSize(); 21 | png_file.resize(png_size); 22 | file.Seek(0); 23 | file.Read(png_file); 24 | 25 | auto* img_mem = stbi_load_from_memory(png_file.data(), png_file.size(), 26 | reinterpret_cast(&img_info.width), 27 | reinterpret_cast(&img_info.height), 28 | reinterpret_cast(&img_info.num_channels), 4); 29 | if (!img_mem) { 30 | return false; 31 | } 32 | 33 | const auto img_size = img_info.GetSizeBytes(); 34 | img_data.resize(img_size); 35 | std::memcpy(img_data.data(), img_mem, img_size); 36 | stbi_image_free(img_mem); 37 | return true; 38 | } 39 | -------------------------------------------------------------------------------- /core/libraries/playgo/playgo_dialog.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | #include "core/libraries/system/commondialog.h" 8 | 9 | namespace Core::Loader { 10 | class SymbolsResolver; 11 | } 12 | 13 | namespace Libraries::PlayGo::Dialog { 14 | 15 | struct OrbisPlayGoDialogParam { 16 | CommonDialog::BaseParam baseParam; 17 | s32 size; 18 | u8 unk[0x30]; 19 | }; 20 | static_assert(sizeof(OrbisPlayGoDialogParam) == 0x68); 21 | 22 | struct OrbisPlayGoDialogResult { 23 | u8 unk1[0x4]; 24 | CommonDialog::Result result; 25 | u8 unk2[0x20]; 26 | }; 27 | static_assert(sizeof(OrbisPlayGoDialogResult) == 0x28); 28 | 29 | CommonDialog::Error PS4_SYSV_ABI scePlayGoDialogClose(); 30 | CommonDialog::Error PS4_SYSV_ABI scePlayGoDialogGetResult(OrbisPlayGoDialogResult* result); 31 | CommonDialog::Status PS4_SYSV_ABI scePlayGoDialogGetStatus(); 32 | CommonDialog::Error PS4_SYSV_ABI scePlayGoDialogInitialize(); 33 | CommonDialog::Error PS4_SYSV_ABI scePlayGoDialogOpen(const OrbisPlayGoDialogParam* param); 34 | CommonDialog::Error PS4_SYSV_ABI scePlayGoDialogTerminate(); 35 | CommonDialog::Status PS4_SYSV_ABI scePlayGoDialogUpdateStatus(); 36 | 37 | void RegisterlibScePlayGoDialog(Core::Loader::SymbolsResolver* sym); 38 | } // namespace Libraries::PlayGo::Dialog 39 | -------------------------------------------------------------------------------- /common/memory_patcher.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include 6 | #include 7 | #include 8 | 9 | namespace MemoryPatcher { 10 | 11 | extern uintptr_t g_eboot_address; 12 | extern uint64_t g_eboot_image_size; 13 | extern std::string g_game_serial; 14 | extern std::string patchFile; 15 | 16 | enum PatchMask : uint8_t { 17 | None, 18 | Mask, 19 | Mask_Jump32, 20 | }; 21 | 22 | struct patchInfo { 23 | std::string gameSerial; 24 | std::string modNameStr; 25 | std::string offsetStr; 26 | std::string valueStr; 27 | bool isOffset; 28 | bool littleEndian; 29 | PatchMask patchMask; 30 | int maskOffset; 31 | }; 32 | 33 | extern std::vector pending_patches; 34 | 35 | std::string convertValueToHex(const std::string type, const std::string valueStr); 36 | 37 | void OnGameLoaded(); 38 | void AddPatchToQueue(patchInfo patchToAdd); 39 | void ApplyPendingPatches(); 40 | 41 | void PatchMemory(std::string modNameStr, std::string offsetStr, std::string valueStr, bool isOffset, 42 | bool littleEndian, PatchMask patchMask = PatchMask::None, int maskOffset = 0); 43 | 44 | static std::vector PatternToByte(const std::string& pattern); 45 | uintptr_t PatternScan(const std::string& signature); 46 | 47 | } // namespace MemoryPatcher -------------------------------------------------------------------------------- /imgui/renderer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | # SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | project(ImGui_Resources) 5 | 6 | add_executable(Dear_ImGui_FontEmbed ${CMAKE_SOURCE_DIR}/externals/dear_imgui/misc/fonts/binary_to_compressed_c.cpp) 7 | 8 | set(FONT_LIST 9 | NotoSansJP-Regular.ttf 10 | ProggyVector-Regular.ttf 11 | ) 12 | 13 | set(OutputList "") 14 | FOREACH (FONT_FILE ${FONT_LIST}) 15 | string(REGEX REPLACE "-" "_" fontname ${FONT_FILE}) 16 | string(TOLOWER ${fontname} fontname) 17 | string(REGEX REPLACE ".ttf" "" fontname_cpp ${fontname}) 18 | set(fontname_cpp "imgui_font_${fontname_cpp}") 19 | 20 | MESSAGE(STATUS "Embedding font ${FONT_FILE}") 21 | set(OUTPUT "generated_fonts/imgui_fonts/${fontname}") 22 | add_custom_command( 23 | OUTPUT "${OUTPUT}.g.cpp" 24 | COMMAND ${CMAKE_COMMAND} -E make_directory "generated_fonts/imgui_fonts" 25 | COMMAND $ -nostatic "${CMAKE_CURRENT_SOURCE_DIR}/fonts/${FONT_FILE}" ${fontname_cpp} > "${OUTPUT}.g.cpp" 26 | DEPENDS Dear_ImGui_FontEmbed "fonts/${FONT_FILE}" 27 | USES_TERMINAL 28 | ) 29 | list(APPEND OutputList "${OUTPUT}.g.cpp") 30 | ENDFOREACH () 31 | 32 | add_library(ImGui_Resources STATIC ${OutputList}) 33 | set(IMGUI_RESOURCES_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/generated_fonts PARENT_SCOPE) 34 | -------------------------------------------------------------------------------- /core/devtools/widget/reg_popup.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include 9 | 10 | #include "common/types.h" 11 | #include "video_core/renderer_vulkan/liverpool_to_vk.h" 12 | 13 | namespace Core::Devtools::Widget { 14 | 15 | class RegPopup { 16 | int id; 17 | ImGuiWindowFlags flags{ImGuiWindowFlags_NoSavedSettings}; 18 | 19 | using DepthBuffer = std::tuple; 20 | 21 | ImVec2 last_pos; 22 | std::variant data; 23 | std::string title{}; 24 | 25 | static void DrawColorBuffer(const AmdGpu::Liverpool::ColorBuffer& buffer); 26 | 27 | static void DrawDepthBuffer(const DepthBuffer& depth_data); 28 | 29 | public: 30 | bool open = false; 31 | bool moved = false; 32 | 33 | RegPopup(); 34 | 35 | void SetData(const std::string& base_title, AmdGpu::Liverpool::ColorBuffer color_buffer, 36 | u32 cb_id); 37 | 38 | void SetData(const std::string& base_title, AmdGpu::Liverpool::DepthBuffer depth_buffer, 39 | AmdGpu::Liverpool::DepthControl depth_control); 40 | 41 | void SetPos(ImVec2 pos, bool auto_resize = false); 42 | 43 | void Draw(); 44 | }; 45 | 46 | } // namespace Core::Devtools::Widget 47 | -------------------------------------------------------------------------------- /video_core/page_manager.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #ifdef __linux__ 9 | #include "common/adaptive_mutex.h" 10 | #endif 11 | #include "common/spin_lock.h" 12 | #include "common/types.h" 13 | 14 | namespace Vulkan { 15 | class Rasterizer; 16 | } 17 | 18 | namespace VideoCore { 19 | 20 | class PageManager { 21 | public: 22 | explicit PageManager(Vulkan::Rasterizer* rasterizer); 23 | ~PageManager(); 24 | 25 | /// Register a range of mapped gpu memory. 26 | void OnGpuMap(VAddr address, size_t size); 27 | 28 | /// Unregister a range of gpu memory that was unmapped. 29 | void OnGpuUnmap(VAddr address, size_t size); 30 | 31 | /// Increase/decrease the number of surface in pages touching the specified region 32 | void UpdatePagesCachedCount(VAddr addr, u64 size, s32 delta); 33 | 34 | static VAddr GetPageAddr(VAddr addr); 35 | static VAddr GetNextPageAddr(VAddr addr); 36 | 37 | private: 38 | struct Impl; 39 | std::unique_ptr impl; 40 | Vulkan::Rasterizer* rasterizer; 41 | boost::icl::interval_map cached_pages; 42 | #ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP 43 | Common::AdaptiveMutex lock; 44 | #else 45 | Common::SpinLock lock; 46 | #endif 47 | }; 48 | 49 | } // namespace VideoCore 50 | -------------------------------------------------------------------------------- /core/file_format/trp.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/endian.h" 8 | #include "common/io_file.h" 9 | #include "common/types.h" 10 | #include "core/crypto/crypto.h" 11 | 12 | struct TrpHeader { 13 | u32_be magic; // (0xDCA24D00) 14 | u32_be version; 15 | u64_be file_size; // size of full trp file 16 | u32_be entry_num; // num entries 17 | u32_be entry_size; // size of entry 18 | u32_be dev_flag; // 1: dev 19 | unsigned char digest[20]; // sha1 hash 20 | u32_be key_index; // 3031300? 21 | unsigned char padding[44]; 22 | }; 23 | 24 | struct TrpEntry { 25 | char entry_name[32]; 26 | u64_be entry_pos; 27 | u64_be entry_len; 28 | u32_be flag; // 3 = CONFIG/ESFM , 0 = PNG 29 | unsigned char padding[12]; 30 | }; 31 | 32 | class TRP { 33 | public: 34 | TRP(); 35 | ~TRP(); 36 | bool Extract(const std::filesystem::path& trophyPath, const std::string titleId); 37 | void GetNPcommID(const std::filesystem::path& trophyPath, int index); 38 | 39 | private: 40 | Crypto crypto; 41 | std::vector NPcommID = std::vector(12); 42 | std::array np_comm_id{}; 43 | std::array esfmIv{}; 44 | std::filesystem::path trpFilesPath; 45 | static constexpr int iv_len = 16; 46 | }; -------------------------------------------------------------------------------- /core/devtools/widget/reg_view.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include "core/debug_state.h" 6 | #include "imgui_memory_editor.h" 7 | #include "reg_popup.h" 8 | #include "text_editor.h" 9 | 10 | namespace Core::Devtools::Widget { 11 | 12 | struct ShaderCache { 13 | MemoryEditor hex_view; 14 | TextEditor dis_view; 15 | Vulkan::Liverpool::UserData user_data; 16 | }; 17 | 18 | class RegView { 19 | int id; 20 | 21 | std::string title; 22 | DebugStateType::RegDump data; 23 | u32 batch_id{~0u}; 24 | ImVec2 last_pos; 25 | 26 | std::unordered_map shader_decomp; 27 | int selected_shader{-1}; 28 | RegPopup default_reg_popup; 29 | int last_selected_cb{-1}; 30 | std::vector extra_reg_popup; 31 | 32 | bool show_registers{true}; 33 | bool show_user_data{true}; 34 | bool show_disassembly{true}; 35 | 36 | void ProcessShader(int shader_id); 37 | 38 | void SelectShader(int shader_id); 39 | 40 | void DrawComputeRegs(); 41 | 42 | void DrawGraphicsRegs(); 43 | 44 | public: 45 | bool open = false; 46 | bool moved = false; 47 | 48 | RegView(); 49 | 50 | void SetData(DebugStateType::RegDump data, const std::string& base_title, u32 batch_id); 51 | 52 | void SetPos(ImVec2 pos); 53 | 54 | void Draw(); 55 | }; 56 | 57 | } // namespace Core::Devtools::Widget -------------------------------------------------------------------------------- /core/libraries/save_data/save_memory.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "save_backup.h" 8 | 9 | class PSF; 10 | 11 | namespace Libraries::SaveData { 12 | using OrbisUserServiceUserId = s32; 13 | } 14 | 15 | namespace Libraries::SaveData::SaveMemory { 16 | 17 | void PersistMemory(u32 slot_id, bool lock = true); 18 | 19 | [[nodiscard]] std::string GetSaveDir(u32 slot_id); 20 | 21 | [[nodiscard]] std::filesystem::path GetSavePath(OrbisUserServiceUserId user_id, u32 slot_id, 22 | std::string_view game_serial); 23 | 24 | // returns the size of the save memory if exists 25 | size_t SetupSaveMemory(OrbisUserServiceUserId user_id, u32 slot_id, std::string_view game_serial); 26 | 27 | // Write the icon. Set buf to null to read the standard icon. 28 | void SetIcon(u32 slot_id, void* buf = nullptr, size_t buf_size = 0); 29 | 30 | [[nodiscard]] bool IsSaveMemoryInitialized(u32 slot_id); 31 | 32 | [[nodiscard]] PSF& GetParamSFO(u32 slot_id); 33 | 34 | [[nodiscard]] std::vector GetIcon(u32 slot_id); 35 | 36 | // Save now or wait for the background thread to save 37 | void SaveSFO(u32 slot_id); 38 | 39 | void ReadMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset); 40 | 41 | void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset); 42 | 43 | } // namespace Libraries::SaveData::SaveMemory -------------------------------------------------------------------------------- /core/libraries/save_data/dialog/savedatadialog.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | #include "core/libraries/system/commondialog.h" 8 | 9 | namespace Core::Loader { 10 | class SymbolsResolver; 11 | } 12 | 13 | namespace Libraries::SaveData::Dialog { 14 | 15 | struct OrbisSaveDataDialogParam; 16 | struct OrbisSaveDataDialogResult; 17 | enum class OrbisSaveDataDialogProgressBarTarget : u32; 18 | 19 | CommonDialog::Error PS4_SYSV_ABI sceSaveDataDialogClose(); 20 | CommonDialog::Error PS4_SYSV_ABI sceSaveDataDialogGetResult(OrbisSaveDataDialogResult* result); 21 | CommonDialog::Status PS4_SYSV_ABI sceSaveDataDialogGetStatus(); 22 | CommonDialog::Error PS4_SYSV_ABI sceSaveDataDialogInitialize(); 23 | s32 PS4_SYSV_ABI sceSaveDataDialogIsReadyToDisplay(); 24 | CommonDialog::Error PS4_SYSV_ABI sceSaveDataDialogOpen(const OrbisSaveDataDialogParam* param); 25 | CommonDialog::Error PS4_SYSV_ABI 26 | sceSaveDataDialogProgressBarInc(OrbisSaveDataDialogProgressBarTarget target, u32 delta); 27 | CommonDialog::Error PS4_SYSV_ABI 28 | sceSaveDataDialogProgressBarSetValue(OrbisSaveDataDialogProgressBarTarget target, u32 rate); 29 | CommonDialog::Error PS4_SYSV_ABI sceSaveDataDialogTerminate(); 30 | CommonDialog::Status PS4_SYSV_ABI sceSaveDataDialogUpdateStatus(); 31 | 32 | void RegisterlibSceSaveDataDialog(Core::Loader::SymbolsResolver* sym); 33 | } // namespace Libraries::SaveData::Dialog 34 | -------------------------------------------------------------------------------- /common/logging/formatter.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2014 Citra Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | // Adapted from https://github.com/fmtlib/fmt/issues/2704 10 | // a generic formatter for enum classes 11 | #if FMT_VERSION >= 80100 12 | template 13 | struct fmt::formatter, char>> 14 | : formatter> { 15 | template 16 | auto format(const T& value, FormatContext& ctx) -> decltype(ctx.out()) { 17 | return fmt::formatter>::format( 18 | static_cast>(value), ctx); 19 | } 20 | }; 21 | #endif 22 | 23 | namespace fmt { 24 | template 25 | struct UTF { 26 | T data; 27 | 28 | explicit UTF(const std::u8string_view view) { 29 | data = view.empty() ? T{} : T{(const char*)&view.front(), (const char*)&view.back() + 1}; 30 | } 31 | 32 | explicit UTF(const std::u8string& str) : UTF(std::u8string_view{str}) {} 33 | }; 34 | } // namespace fmt 35 | 36 | template <> 37 | struct fmt::formatter, char> : formatter { 38 | template 39 | auto format(const UTF& wrapper, FormatContext& ctx) const { 40 | return formatter::format(wrapper.data, ctx); 41 | } 42 | }; -------------------------------------------------------------------------------- /core/file_sys/fs.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "common/io_file.h" 12 | #include "common/logging/formatter.h" 13 | #include "core/devices/base_device.h" 14 | 15 | namespace Core::FileSys { 16 | 17 | struct DirEntry { 18 | std::string name; 19 | bool isFile; 20 | }; 21 | 22 | enum class FileType { 23 | Regular, // standard file 24 | Directory, 25 | Device, 26 | }; 27 | 28 | struct File { 29 | std::atomic_bool is_opened{}; 30 | std::atomic type{FileType::Regular}; 31 | std::filesystem::path m_host_name; 32 | std::string m_guest_name; 33 | Common::FS::IOFile f; 34 | std::vector dirents; 35 | u32 dirents_index; 36 | std::mutex m_mutex; 37 | std::shared_ptr device; // only valid for type == Device 38 | }; 39 | 40 | class HandleTable { 41 | public: 42 | HandleTable() = default; 43 | virtual ~HandleTable() = default; 44 | 45 | int CreateHandle(); 46 | void DeleteHandle(int d); 47 | File* GetFile(int d); 48 | File* GetFile(const std::filesystem::path& host_name); 49 | int GetFileDescriptor(File* file); 50 | 51 | void CreateStdHandles(); 52 | 53 | private: 54 | std::vector m_files; 55 | std::mutex m_mutex; 56 | }; 57 | 58 | } // namespace Core::FileSys 59 | -------------------------------------------------------------------------------- /core/libraries/ajm/ajm_instance_statistics.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "core/libraries/ajm/ajm.h" 5 | #include "core/libraries/ajm/ajm_instance_statistics.h" 6 | 7 | namespace Libraries::Ajm { 8 | 9 | void AjmInstanceStatistics::ExecuteJob(AjmJob& job) { 10 | if (job.output.p_engine) { 11 | job.output.p_engine->usage_batch = 0.01; 12 | const auto ic = job.input.statistics_engine_parameters->interval_count; 13 | for (u32 idx = 0; idx < ic; ++idx) { 14 | job.output.p_engine->usage_interval[idx] = 0.01; 15 | } 16 | } 17 | if (job.output.p_engine_per_codec) { 18 | job.output.p_engine_per_codec->codec_count = 1; 19 | job.output.p_engine_per_codec->codec_id[0] = static_cast(AjmCodecType::At9Dec); 20 | job.output.p_engine_per_codec->codec_percentage[0] = 0.01; 21 | } 22 | if (job.output.p_memory) { 23 | job.output.p_memory->instance_free = 0x400000; 24 | job.output.p_memory->buffer_free = 0x400000; 25 | job.output.p_memory->batch_size = 0x4200; 26 | job.output.p_memory->input_size = 0x2000; 27 | job.output.p_memory->output_size = 0x2000; 28 | job.output.p_memory->small_size = 0x200; 29 | } 30 | } 31 | 32 | AjmInstanceStatistics& AjmInstanceStatistics::Getinstance() { 33 | static AjmInstanceStatistics instance; 34 | return instance; 35 | } 36 | 37 | } // namespace Libraries::Ajm 38 | -------------------------------------------------------------------------------- /core/libraries/move/move.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/logging/log.h" 5 | #include "core/libraries/error_codes.h" 6 | #include "core/libraries/libs.h" 7 | #include "move.h" 8 | 9 | namespace Libraries::Move { 10 | 11 | int PS4_SYSV_ABI sceMoveOpen() { 12 | LOG_ERROR(Lib_Move, "(STUBBED) called"); 13 | return ORBIS_FAIL; 14 | } 15 | 16 | int PS4_SYSV_ABI sceMoveGetDeviceInfo() { 17 | LOG_ERROR(Lib_Move, "(STUBBED) called"); 18 | return ORBIS_OK; 19 | } 20 | 21 | int PS4_SYSV_ABI sceMoveReadStateRecent() { 22 | LOG_TRACE(Lib_Move, "(STUBBED) called"); 23 | return ORBIS_OK; 24 | } 25 | 26 | int PS4_SYSV_ABI sceMoveTerm() { 27 | LOG_ERROR(Lib_Move, "(STUBBED) called"); 28 | return ORBIS_OK; 29 | } 30 | 31 | int PS4_SYSV_ABI sceMoveInit() { 32 | LOG_ERROR(Lib_Move, "(STUBBED) called"); 33 | return ORBIS_OK; 34 | } 35 | 36 | void RegisterlibSceMove(Core::Loader::SymbolsResolver* sym) { 37 | LIB_FUNCTION("HzC60MfjJxU", "libSceMove", 1, "libSceMove", 1, 1, sceMoveOpen); 38 | LIB_FUNCTION("GWXTyxs4QbE", "libSceMove", 1, "libSceMove", 1, 1, sceMoveGetDeviceInfo); 39 | LIB_FUNCTION("f2bcpK6kJfg", "libSceMove", 1, "libSceMove", 1, 1, sceMoveReadStateRecent); 40 | LIB_FUNCTION("tsZi60H4ypY", "libSceMove", 1, "libSceMove", 1, 1, sceMoveTerm); 41 | LIB_FUNCTION("j1ITE-EoJmE", "libSceMove", 1, "libSceMove", 1, 1, sceMoveInit); 42 | }; 43 | 44 | } // namespace Libraries::Move -------------------------------------------------------------------------------- /video_core/host_shaders/StringShaderHeader.cmake: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: 2020 yuzu Emulator Project 2 | # SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | set(SOURCE_FILE ${CMAKE_ARGV3}) 5 | set(HEADER_FILE ${CMAKE_ARGV4}) 6 | set(INPUT_FILE ${CMAKE_ARGV5}) 7 | 8 | get_filename_component(CONTENTS_NAME ${SOURCE_FILE} NAME) 9 | string(REPLACE "." "_" CONTENTS_NAME ${CONTENTS_NAME}) 10 | string(TOUPPER ${CONTENTS_NAME} CONTENTS_NAME) 11 | 12 | FILE(READ ${SOURCE_FILE} line_contents) 13 | 14 | # Replace double quotes with single quotes, 15 | # as double quotes will be used to wrap the lines 16 | STRING(REGEX REPLACE "\"" "'" line_contents "${line_contents}") 17 | 18 | # CMake separates list elements with semicolons, but semicolons 19 | # are used extensively in the shader code. 20 | # Replace with a temporary marker, to be reverted later. 21 | STRING(REGEX REPLACE ";" "{{SEMICOLON}}" line_contents "${line_contents}") 22 | 23 | # Make every line an individual element in the CMake list. 24 | STRING(REGEX REPLACE "\n" ";" line_contents "${line_contents}") 25 | 26 | # Build the shader string, wrapping each line in double quotes. 27 | foreach(line IN LISTS line_contents) 28 | string(CONCAT CONTENTS "${CONTENTS}" \"${line}\\n\"\n) 29 | endforeach() 30 | 31 | # Revert the original semicolons in the source. 32 | STRING(REGEX REPLACE "{{SEMICOLON}}" ";" CONTENTS "${CONTENTS}") 33 | 34 | get_filename_component(OUTPUT_DIR ${HEADER_FILE} DIRECTORY) 35 | make_directory(${OUTPUT_DIR}) 36 | configure_file(${INPUT_FILE} ${HEADER_FILE} @ONLY) 37 | -------------------------------------------------------------------------------- /common/alignment.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2014 Jannik Vogel 2 | // SPDX-License-Identifier: CC0-1.0 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace Common { 10 | 11 | template 12 | [[nodiscard]] constexpr T AlignUp(T value, std::size_t size) { 13 | static_assert(std::is_unsigned_v, "T must be an unsigned value."); 14 | auto mod{static_cast(value % size)}; 15 | value -= mod; 16 | return static_cast(mod == T{0} ? value : value + size); 17 | } 18 | 19 | template 20 | [[nodiscard]] constexpr T AlignDown(T value, std::size_t size) { 21 | static_assert(std::is_unsigned_v, "T must be an unsigned value."); 22 | return static_cast(value - value % size); 23 | } 24 | 25 | template 26 | requires std::is_integral_v 27 | [[nodiscard]] constexpr bool IsAligned(T value, std::size_t alignment) { 28 | return (value & (alignment - 1)) == 0; 29 | } 30 | 31 | template 32 | requires std::is_integral_v 33 | [[nodiscard]] constexpr bool Is16KBAligned(T value) { 34 | return (value & 0x3FFF) == 0; 35 | } 36 | 37 | template 38 | requires std::is_integral_v 39 | [[nodiscard]] constexpr bool Is64KBAligned(T value) { 40 | return (value & 0xFFFF) == 0; 41 | } 42 | 43 | template 44 | requires std::is_integral_v 45 | [[nodiscard]] constexpr bool Is2MBAligned(T value) { 46 | return (value & 0x1FFFFF) == 0; 47 | } 48 | 49 | } // namespace Common 50 | -------------------------------------------------------------------------------- /core/libraries/videodec/videodec2_avc.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Libraries::Vdec2 { 9 | 10 | struct OrbisVideodec2AvcPictureInfo { 11 | u64 thisSize; 12 | 13 | bool isValid; 14 | 15 | u64 ptsData; 16 | u64 dtsData; 17 | u64 attachedData; 18 | 19 | u8 idrPictureflag; 20 | 21 | u8 profile_idc; 22 | u8 level_idc; 23 | u32 pic_width_in_mbs_minus1; 24 | u32 pic_height_in_map_units_minus1; 25 | u8 frame_mbs_only_flag; 26 | 27 | u8 frame_cropping_flag; 28 | u32 frameCropLeftOffset; 29 | u32 frameCropRightOffset; 30 | u32 frameCropTopOffset; 31 | u32 frameCropBottomOffset; 32 | 33 | u8 aspect_ratio_info_present_flag; 34 | u8 aspect_ratio_idc; 35 | u16 sar_width; 36 | u16 sar_height; 37 | 38 | u8 video_signal_type_present_flag; 39 | u8 video_format; 40 | u8 video_full_range_flag; 41 | u8 colour_description_present_flag; 42 | u8 colour_primaries; 43 | u8 transfer_characteristics; 44 | u8 matrix_coefficients; 45 | 46 | u8 timing_info_present_flag; 47 | u32 num_units_in_tick; 48 | u32 time_scale; 49 | u8 fixed_frame_rate_flag; 50 | 51 | u8 bitstream_restriction_flag; 52 | u8 max_dec_frame_buffering; 53 | 54 | u8 pic_struct_present_flag; 55 | u8 pic_struct; 56 | u8 field_pic_flag; 57 | u8 bottom_field_flag; 58 | }; 59 | 60 | } // namespace Libraries::Vdec2 -------------------------------------------------------------------------------- /video_core/renderer_vulkan/vk_compute_pipeline.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "video_core/renderer_vulkan/vk_common.h" 7 | #include "video_core/renderer_vulkan/vk_pipeline_common.h" 8 | 9 | namespace VideoCore { 10 | class BufferCache; 11 | class TextureCache; 12 | } // namespace VideoCore 13 | 14 | namespace Vulkan { 15 | 16 | class Instance; 17 | class Scheduler; 18 | class DescriptorHeap; 19 | 20 | struct ComputePipelineKey { 21 | size_t value; 22 | 23 | friend bool operator==(const ComputePipelineKey& lhs, const ComputePipelineKey& rhs) { 24 | return lhs.value == rhs.value; 25 | } 26 | friend bool operator!=(const ComputePipelineKey& lhs, const ComputePipelineKey& rhs) { 27 | return !(lhs == rhs); 28 | } 29 | }; 30 | 31 | class ComputePipeline : public Pipeline { 32 | public: 33 | ComputePipeline(const Instance& instance, Scheduler& scheduler, DescriptorHeap& desc_heap, 34 | vk::PipelineCache pipeline_cache, ComputePipelineKey compute_key, 35 | const Shader::Info& info, vk::ShaderModule module); 36 | ~ComputePipeline(); 37 | 38 | private: 39 | ComputePipelineKey compute_key; 40 | }; 41 | 42 | } // namespace Vulkan 43 | 44 | template <> 45 | struct std::hash { 46 | std::size_t operator()(const Vulkan::ComputePipelineKey& key) const noexcept { 47 | return std::hash{}(key.value); 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /core/libraries/system/msgdialog.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/system/commondialog.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::MsgDialog { 13 | 14 | struct DialogResult; 15 | struct OrbisParam; 16 | enum class OrbisMsgDialogProgressBarTarget : u32; 17 | 18 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogClose(); 19 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogGetResult(DialogResult* result); 20 | CommonDialog::Status PS4_SYSV_ABI sceMsgDialogGetStatus(); 21 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogInitialize(); 22 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogOpen(const OrbisParam* param); 23 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogProgressBarInc(OrbisMsgDialogProgressBarTarget, 24 | u32 delta); 25 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogProgressBarSetMsg(OrbisMsgDialogProgressBarTarget, 26 | const char* msg); 27 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogProgressBarSetValue(OrbisMsgDialogProgressBarTarget, 28 | u32 value); 29 | CommonDialog::Error PS4_SYSV_ABI sceMsgDialogTerminate(); 30 | CommonDialog::Status PS4_SYSV_ABI sceMsgDialogUpdateStatus(); 31 | 32 | void RegisterlibSceMsgDialog(Core::Loader::SymbolsResolver* sym); 33 | } // namespace Libraries::MsgDialog 34 | -------------------------------------------------------------------------------- /core/libraries/ajm/ajm_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | constexpr int ORBIS_AJM_ERROR_UNKNOWN = 0x80930001; 7 | constexpr int ORBIS_AJM_ERROR_INVALID_CONTEXT = 0x80930002; 8 | constexpr int ORBIS_AJM_ERROR_INVALID_INSTANCE = 0x80930003; 9 | constexpr int ORBIS_AJM_ERROR_INVALID_BATCH = 0x80930004; 10 | constexpr int ORBIS_AJM_ERROR_INVALID_PARAMETER = 0x80930005; 11 | constexpr int ORBIS_AJM_ERROR_OUT_OF_MEMORY = 0x80930006; 12 | constexpr int ORBIS_AJM_ERROR_OUT_OF_RESOURCES = 0x80930007; 13 | constexpr int ORBIS_AJM_ERROR_CODEC_NOT_SUPPORTED = 0x80930008; 14 | constexpr int ORBIS_AJM_ERROR_CODEC_ALREADY_REGISTERED = 0x80930009; 15 | constexpr int ORBIS_AJM_ERROR_CODEC_NOT_REGISTERED = 0x8093000A; 16 | constexpr int ORBIS_AJM_ERROR_WRONG_REVISION_FLAG = 0x8093000B; 17 | constexpr int ORBIS_AJM_ERROR_FLAG_NOT_SUPPORTED = 0x8093000C; 18 | constexpr int ORBIS_AJM_ERROR_BUSY = 0x8093000D; 19 | constexpr int ORBIS_AJM_ERROR_BAD_PRIORITY = 0x8093000E; 20 | constexpr int ORBIS_AJM_ERROR_IN_PROGRESS = 0x8093000F; 21 | constexpr int ORBIS_AJM_ERROR_RETRY = 0x80930010; 22 | constexpr int ORBIS_AJM_ERROR_MALFORMED_BATCH = 0x80930011; 23 | constexpr int ORBIS_AJM_ERROR_JOB_CREATION = 0x80930012; 24 | constexpr int ORBIS_AJM_ERROR_INVALID_OPCODE = 0x80930013; 25 | constexpr int ORBIS_AJM_ERROR_PRIORITY_VIOLATION = 0x80930014; 26 | constexpr int ORBIS_AJM_ERROR_BUFFER_TOO_BIG = 0x80930015; 27 | constexpr int ORBIS_AJM_ERROR_INVALID_ADDRESS = 0x80930016; 28 | constexpr int ORBIS_AJM_ERROR_CANCELLED = 0x80930017; 29 | -------------------------------------------------------------------------------- /video_core/texture_cache/tile_manager.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | #include "video_core/buffer_cache/buffer.h" 8 | 9 | namespace VideoCore { 10 | 11 | class TextureCache; 12 | struct ImageInfo; 13 | 14 | enum DetilerType : u32 { 15 | Micro8, 16 | Micro16, 17 | Micro32, 18 | Micro64, 19 | Micro128, 20 | 21 | Macro8, 22 | Macro32, 23 | Macro64, 24 | 25 | Display_Micro64, 26 | 27 | Max 28 | }; 29 | 30 | struct DetilerContext { 31 | vk::UniquePipeline pl; 32 | vk::UniquePipelineLayout pl_layout; 33 | }; 34 | 35 | class TileManager { 36 | public: 37 | using ScratchBuffer = std::pair; 38 | 39 | TileManager(const Vulkan::Instance& instance, Vulkan::Scheduler& scheduler); 40 | ~TileManager(); 41 | 42 | std::pair TryDetile(vk::Buffer in_buffer, u32 in_offset, 43 | const ImageInfo& info); 44 | 45 | ScratchBuffer AllocBuffer(u32 size, bool is_storage = false); 46 | void Upload(ScratchBuffer buffer, const void* data, size_t size); 47 | void FreeBuffer(ScratchBuffer buffer); 48 | 49 | private: 50 | const DetilerContext* GetDetiler(const ImageInfo& info) const; 51 | 52 | private: 53 | const Vulkan::Instance& instance; 54 | Vulkan::Scheduler& scheduler; 55 | vk::UniqueDescriptorSetLayout desc_layout; 56 | std::array detilers; 57 | }; 58 | 59 | } // namespace VideoCore 60 | -------------------------------------------------------------------------------- /core/libraries/network/net_ctl_codes.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | // error codes 7 | constexpr int ORBIS_NET_CTL_ERROR_CALLBACK_MAX = 0x80412103; 8 | constexpr int ORBIS_NET_CTL_ERROR_ID_NOT_FOUND = 0x80412104; 9 | constexpr int ORBIS_NET_CTL_ERROR_INVALID_ID = 0x80412105; 10 | constexpr int ORBIS_NET_CTL_ERROR_INVALID_ADDR = 0x80412107; 11 | constexpr int ORBIS_NET_CTL_ERROR_NOT_CONNECTED = 0x80412108; 12 | constexpr int ORBIS_NET_CTL_ERROR_NOT_AVAIL = 0x80412109; 13 | constexpr int ORBIS_NET_CTL_ERROR_NETWORK_DISABLED = 0x8041210D; 14 | constexpr int ORBIS_NET_CTL_ERROR_DISCONNECT_REQ = 0x8041210E; 15 | constexpr int ORBIS_NET_CTL_ERROR_ETHERNET_PLUGOUT = 0x80412115; 16 | constexpr int ORBIS_NET_CTL_ERROR_WIFI_DEAUTHED = 0x80412116; 17 | constexpr int ORBIS_NET_CTL_ERROR_WIFI_BEACON_LOST = 0x80412117; 18 | 19 | // state codes 20 | constexpr int ORBIS_NET_CTL_STATE_DISCONNECTED = 0; 21 | constexpr int ORBIS_NET_CTL_STATE_CONNECTING = 1; 22 | constexpr int ORBIS_NET_CTL_STATE_IPOBTAINING = 2; 23 | constexpr int ORBIS_NET_CTL_STATE_IPOBTAINED = 3; 24 | 25 | // event type 26 | constexpr int ORBIS_NET_CTL_EVENT_TYPE_DISCONNECTED = 1; 27 | constexpr int ORBIS_SCE_NET_CTL_EVENT_TYPE_DISCONNECT_REQ_FINISHED = 2; 28 | constexpr int ORBIS_NET_CTL_EVENT_TYPE_IPOBTAINED = 3; 29 | 30 | // get info codes 31 | // device 32 | constexpr int ORBIS_NET_CTL_DEVICE_WIRED = 0; 33 | constexpr int ORBIS_NET_CTL_DEVICE_WIRELESS = 1; 34 | // link 35 | constexpr int ORBIS_NET_CTL_LINK_DISCONNECTED = 0; 36 | constexpr int ORBIS_NET_CTL_LINK_CONNECTED = 1; 37 | -------------------------------------------------------------------------------- /core/libraries/ngs2/ngs2.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/types.h" 8 | 9 | namespace Core::Loader { 10 | class SymbolsResolver; 11 | } 12 | 13 | namespace Libraries::Ngs2 { 14 | 15 | class Ngs2; 16 | 17 | using SceNgs2Handle = Ngs2*; 18 | 19 | enum class SceNgs2HandleType : u32 { 20 | System = 0, 21 | }; 22 | 23 | struct Ngs2Handle { 24 | void* selfPointer; 25 | void* dataPointer; 26 | std::atomic* atomicPtr; 27 | u32 handleType; 28 | u32 flags_unk; 29 | 30 | u32 uid; 31 | u16 maxGrainSamples; 32 | u16 minGrainSamples; 33 | u16 currentGrainSamples; 34 | u16 numGrainSamples; 35 | u16 unknown2; 36 | u32 sampleRate; 37 | u32 unknown3; 38 | 39 | void* flushMutex; 40 | u32 flushMutexInitialized; 41 | void* processMutex; 42 | u32 processMutexInitialized; 43 | 44 | // Linked list pointers for system list 45 | Ngs2Handle* prev; 46 | Ngs2Handle* next; 47 | }; 48 | 49 | struct SystemOptions { 50 | char padding[6]; 51 | s32 maxGrainSamples; 52 | s32 numGrainSamples; 53 | s32 sampleRate; 54 | }; 55 | 56 | struct SystemState { 57 | // TODO 58 | }; 59 | 60 | struct StackBuffer { 61 | void** top; 62 | void* base; 63 | void* curr; 64 | size_t usedSize; 65 | size_t totalSize; 66 | size_t alignment; 67 | char isVerifyEnabled; 68 | char padding[7]; 69 | }; 70 | 71 | void RegisterlibSceNgs2(Core::Loader::SymbolsResolver* sym); 72 | 73 | } // namespace Libraries::Ngs2 74 | -------------------------------------------------------------------------------- /core/libraries/kernel/kernel.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include "common/types.h" 9 | #include "core/libraries/kernel/orbis_error.h" 10 | 11 | namespace Core::Loader { 12 | class SymbolsResolver; 13 | } 14 | 15 | namespace Libraries::Kernel { 16 | 17 | void ErrSceToPosix(int result); 18 | int ErrnoToSceKernelError(int e); 19 | void SetPosixErrno(int e); 20 | 21 | template 22 | struct StringLiteral { 23 | constexpr StringLiteral(const char (&str)[N]) { 24 | std::copy_n(str, N, value); 25 | } 26 | 27 | char value[N]; 28 | }; 29 | 30 | template 31 | struct WrapperImpl; 32 | 33 | template 34 | struct WrapperImpl { 35 | static constexpr StringLiteral Name{name}; 36 | static R PS4_SYSV_ABI wrap(Args... args) { 37 | u32 ret = f(args...); 38 | if (ret != 0) { 39 | // LOG_ERROR(Lib_Kernel, "Function {} returned {}", std::string_view{name.value}, ret); 40 | ret += ORBIS_KERNEL_ERROR_UNKNOWN; 41 | } 42 | return ret; 43 | } 44 | }; 45 | 46 | template 47 | constexpr auto OrbisWrapper = WrapperImpl::wrap; 48 | 49 | #define ORBIS(func) WrapperImpl<#func, decltype(&func), func>::wrap 50 | 51 | int* PS4_SYSV_ABI __Error(); 52 | 53 | void RegisterKernel(Core::Loader::SymbolsResolver* sym); 54 | 55 | } // namespace Libraries::Kernel 56 | -------------------------------------------------------------------------------- /video_core/renderer_vulkan/vk_master_semaphore.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "common/types.h" 11 | #include "video_core/renderer_vulkan/vk_common.h" 12 | 13 | namespace Vulkan { 14 | 15 | class Instance; 16 | class Scheduler; 17 | 18 | class MasterSemaphore { 19 | public: 20 | explicit MasterSemaphore(const Instance& instance_); 21 | ~MasterSemaphore(); 22 | 23 | [[nodiscard]] u64 CurrentTick() const noexcept { 24 | return current_tick.load(std::memory_order_acquire); 25 | } 26 | 27 | [[nodiscard]] u64 KnownGpuTick() const noexcept { 28 | return gpu_tick.load(std::memory_order_acquire); 29 | } 30 | 31 | [[nodiscard]] bool IsFree(u64 tick) const noexcept { 32 | return KnownGpuTick() >= tick; 33 | } 34 | 35 | [[nodiscard]] u64 NextTick() noexcept { 36 | return current_tick.fetch_add(1, std::memory_order_release); 37 | } 38 | 39 | [[nodiscard]] vk::Semaphore Handle() const noexcept { 40 | return semaphore.get(); 41 | } 42 | 43 | /// Refresh the known GPU tick 44 | void Refresh(); 45 | 46 | /// Waits for a tick to be hit on the GPU 47 | void Wait(u64 tick); 48 | 49 | protected: 50 | const Instance& instance; 51 | vk::UniqueSemaphore semaphore; ///< Timeline semaphore. 52 | std::atomic gpu_tick{0}; ///< Current known GPU tick. 53 | std::atomic current_tick{1}; ///< Current logical tick. 54 | }; 55 | 56 | } // namespace Vulkan 57 | -------------------------------------------------------------------------------- /core/devices/nop_device.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | #include "base_device.h" 6 | 7 | namespace Core::Devices { 8 | 9 | class NopDevice final : BaseDevice { 10 | u32 handle; 11 | 12 | public: 13 | explicit NopDevice(u32 handle) : handle(handle) {} 14 | 15 | ~NopDevice() override = default; 16 | 17 | int ioctl(u64 cmd, Common::VaCtx* args) override { 18 | return 0; 19 | } 20 | 21 | s64 write(const void* buf, size_t nbytes) override { 22 | return 0; 23 | } 24 | 25 | size_t readv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override { 26 | return 0; 27 | } 28 | 29 | size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) override { 30 | return 0; 31 | } 32 | 33 | s64 preadv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt, u64 offset) override { 34 | return 0; 35 | } 36 | 37 | s64 lseek(s64 offset, int whence) override { 38 | return 0; 39 | } 40 | 41 | s64 read(void* buf, size_t nbytes) override { 42 | return 0; 43 | } 44 | 45 | int fstat(Libraries::Kernel::OrbisKernelStat* sb) override { 46 | return 0; 47 | } 48 | 49 | s32 fsync() override { 50 | return 0; 51 | } 52 | 53 | int ftruncate(s64 length) override { 54 | return 0; 55 | } 56 | 57 | int getdents(void* buf, u32 nbytes, s64* basep) override { 58 | return 0; 59 | } 60 | 61 | s64 pwrite(const void* buf, size_t nbytes, u64 offset) override { 62 | return 0; 63 | } 64 | }; 65 | 66 | } // namespace Core::Devices 67 | -------------------------------------------------------------------------------- /imgui/imgui_config.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | // WARNING: All includes from this file must be relative to allow Dear_ImGui project to compile 7 | // without having this project include paths. 8 | 9 | #include 10 | 11 | extern void assert_fail_debug_msg(const char* msg); 12 | 13 | #define ImDrawIdx std::uint32_t 14 | 15 | #define IM_STRINGIZE(x) IM_STRINGIZE2(x) 16 | #define IM_STRINGIZE2(x) #x 17 | #define IM_ASSERT(_EXPR) \ 18 | ([&]() { \ 19 | if (!(_EXPR)) [[unlikely]] { \ 20 | assert_fail_debug_msg(#_EXPR " at " __FILE__ ":" IM_STRINGIZE(__LINE__)); \ 21 | } \ 22 | }()) 23 | 24 | #define IMGUI_ENABLE_STB_TRUETYPE 25 | #define IMGUI_DEFINE_MATH_OPERATORS 26 | 27 | #define IM_VEC2_CLASS_EXTRA \ 28 | constexpr ImVec2(float _v) : x(_v), y(_v) {} 29 | 30 | #define IM_VEC4_CLASS_EXTRA \ 31 | constexpr ImVec4(float _v) : x(_v), y(_v), z(_v), w(_v) {} 32 | 33 | namespace ImGui { 34 | struct Texture; 35 | } 36 | #define ImTextureID ImTextureID 37 | using ImTextureID = ::ImGui::Texture*; 38 | 39 | #ifdef IMGUI_USE_WCHAR32 40 | #error "This project uses 16 bits wchar standard like Orbis" 41 | #endif -------------------------------------------------------------------------------- /core/libraries/np_party/np_party.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::NpParty { 13 | 14 | s32 PS4_SYSV_ABI sceNpPartyCheckCallback(); 15 | s32 PS4_SYSV_ABI sceNpPartyCreate(); 16 | s32 PS4_SYSV_ABI sceNpPartyCreateA(); 17 | s32 PS4_SYSV_ABI sceNpPartyGetId(); 18 | s32 PS4_SYSV_ABI sceNpPartyGetMemberInfo(); 19 | s32 PS4_SYSV_ABI sceNpPartyGetMemberInfoA(); 20 | s32 PS4_SYSV_ABI sceNpPartyGetMembers(); 21 | s32 PS4_SYSV_ABI sceNpPartyGetMembersA(); 22 | s32 PS4_SYSV_ABI sceNpPartyGetMemberSessionInfo(); 23 | s32 PS4_SYSV_ABI sceNpPartyGetMemberVoiceInfo(); 24 | s32 PS4_SYSV_ABI sceNpPartyGetState(); 25 | s32 PS4_SYSV_ABI sceNpPartyGetStateAsUser(); 26 | s32 PS4_SYSV_ABI sceNpPartyGetStateAsUserA(); 27 | s32 PS4_SYSV_ABI sceNpPartyGetVoiceChatPriority(); 28 | s32 PS4_SYSV_ABI sceNpPartyInitialize(); 29 | s32 PS4_SYSV_ABI sceNpPartyJoin(); 30 | s32 PS4_SYSV_ABI sceNpPartyLeave(); 31 | s32 PS4_SYSV_ABI sceNpPartyRegisterHandler(); 32 | s32 PS4_SYSV_ABI sceNpPartyRegisterHandlerA(); 33 | s32 PS4_SYSV_ABI sceNpPartyRegisterPrivateHandler(); 34 | s32 PS4_SYSV_ABI sceNpPartySendBinaryMessage(); 35 | s32 PS4_SYSV_ABI sceNpPartySetVoiceChatPriority(); 36 | s32 PS4_SYSV_ABI sceNpPartyShowInvitationList(); 37 | s32 PS4_SYSV_ABI sceNpPartyShowInvitationListA(); 38 | s32 PS4_SYSV_ABI sceNpPartyTerminate(); 39 | s32 PS4_SYSV_ABI sceNpPartyUnregisterPrivateHandler(); 40 | s32 PS4_SYSV_ABI module_start(); 41 | s32 PS4_SYSV_ABI module_stop(); 42 | 43 | void RegisterlibSceNpParty(Core::Loader::SymbolsResolver* sym); 44 | } // namespace Libraries::NpParty -------------------------------------------------------------------------------- /core/file_format/rif_generator.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "common/types.h" 11 | 12 | class RIFGenerator { 13 | public: 14 | RIFGenerator(); 15 | ~RIFGenerator(); 16 | 17 | // Valida il formato del Content ID 18 | static bool ValidateContentID(const std::string& content_id); 19 | 20 | // Genera un file RIF per un Content ID specifico 21 | bool GenerateRIF(const std::string& content_id, const std::filesystem::path& output_path); 22 | 23 | // Genera un timestamp deterministico basato sul Content ID 24 | static u32 GenerateTimestamp(const std::string& content_id); 25 | 26 | // Genera il contenuto del file RIF 27 | static std::vector GenerateRIFContent(const std::string& content_id); 28 | 29 | // Verifica se un file RIF è valido 30 | static bool ValidateRIF(const std::filesystem::path& rif_path); 31 | 32 | private: 33 | // Costanti per la struttura RIF 34 | static constexpr u32 RIF_SIZE = 1024; 35 | static constexpr std::array RIF_MAGIC = {0x52, 0x49, 0x46, 0x00}; // "RIF\0" 36 | static constexpr std::array RIF_VERSION = {0x00, 0x01}; 37 | static constexpr std::array RIF_UNKNOWN = {0xFF, 0xFF}; 38 | 39 | // Offset per i vari campi nel file RIF 40 | static constexpr u32 MAGIC_OFFSET = 0x00; 41 | static constexpr u32 VERSION_OFFSET = 0x04; 42 | static constexpr u32 UNKNOWN_OFFSET = 0x06; 43 | static constexpr u32 PADDING_OFFSET = 0x08; 44 | static constexpr u32 TIMESTAMP_OFFSET = 0x10; 45 | static constexpr u32 CONTENT_ID_OFFSET = 0x40; 46 | }; -------------------------------------------------------------------------------- /common/discord_rpc_handler.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | #include 6 | #include "discord_rpc_handler.h" 7 | 8 | namespace DiscordRPCHandler { 9 | 10 | void RPC::init() { 11 | DiscordEventHandlers handlers{}; 12 | 13 | Discord_Initialize("1139939140494971051", &handlers, 1, nullptr); 14 | startTimestamp = time(nullptr); 15 | rpcEnabled = true; 16 | } 17 | 18 | void RPC::setStatusIdling() { 19 | DiscordRichPresence rpc{}; 20 | rpc.largeImageKey = "https://cdn.jsdelivr.net/gh/shadps4-emu/shadPS4@main/.github/shadps4.png"; 21 | rpc.largeImageText = "shadPS4 is a PS4 emulator"; 22 | rpc.startTimestamp = startTimestamp; 23 | rpc.details = "Idle"; 24 | 25 | status = RPCStatus::Idling; 26 | Discord_UpdatePresence(&rpc); 27 | } 28 | 29 | void RPC::setStatusPlaying(const std::string& game_name, const std::string& game_id) { 30 | DiscordRichPresence rpc{}; 31 | 32 | rpc.details = "Playing"; 33 | rpc.state = game_name.c_str(); 34 | std::string largeImageUrl = 35 | "https://store.playstation.com/store/api/chihiro/00_09_000/titlecontainer/US/en/999/" + 36 | game_id + "_00/image"; 37 | rpc.largeImageKey = largeImageUrl.c_str(); 38 | rpc.largeImageText = game_name.c_str(); 39 | rpc.startTimestamp = startTimestamp; 40 | 41 | status = RPCStatus::Playing; 42 | Discord_UpdatePresence(&rpc); 43 | } 44 | 45 | void RPC::shutdown() { 46 | if (rpcEnabled) { 47 | rpcEnabled = false; 48 | Discord_ClearPresence(); 49 | Discord_Shutdown(); 50 | } 51 | } 52 | 53 | bool RPC::getRPCEnabled() { 54 | return rpcEnabled; 55 | } 56 | 57 | } // namespace DiscordRPCHandler 58 | -------------------------------------------------------------------------------- /core/libraries/disc_map/disc_map.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/logging/log.h" 5 | #include "core/libraries/error_codes.h" 6 | #include "core/libraries/libs.h" 7 | #include "disc_map.h" 8 | #include "disc_map_codes.h" 9 | 10 | namespace Libraries::DiscMap { 11 | 12 | int PS4_SYSV_ABI sceDiscMapGetPackageSize() { 13 | LOG_WARNING(Lib_DiscMap, "(DUMMY) called"); 14 | return ORBIS_DISC_MAP_ERROR_NO_BITMAP_INFO; 15 | } 16 | 17 | int PS4_SYSV_ABI sceDiscMapIsRequestOnHDD() { 18 | LOG_WARNING(Lib_DiscMap, "(DUMMY) called"); 19 | return ORBIS_DISC_MAP_ERROR_NO_BITMAP_INFO; 20 | } 21 | 22 | int PS4_SYSV_ABI Func_7C980FFB0AA27E7A() { 23 | LOG_ERROR(Lib_DiscMap, "(STUBBED) called"); 24 | return ORBIS_OK; 25 | } 26 | 27 | int PS4_SYSV_ABI Func_8A828CAEE7EDD5E9() { 28 | LOG_ERROR(Lib_DiscMap, "(STUBBED) called"); 29 | return ORBIS_OK; 30 | } 31 | 32 | int PS4_SYSV_ABI Func_E7EBCE96E92F91F8() { 33 | LOG_ERROR(Lib_DiscMap, "(STUBBED) called"); 34 | return ORBIS_OK; 35 | } 36 | 37 | void RegisterlibSceDiscMap(Core::Loader::SymbolsResolver* sym) { 38 | LIB_FUNCTION("fl1eoDnwQ4s", "libSceDiscMap", 1, "libSceDiscMap", 1, 1, 39 | sceDiscMapGetPackageSize); 40 | LIB_FUNCTION("lbQKqsERhtE", "libSceDiscMap", 1, "libSceDiscMap", 1, 1, 41 | sceDiscMapIsRequestOnHDD); 42 | LIB_FUNCTION("fJgP+wqifno", "libSceDiscMap", 1, "libSceDiscMap", 1, 1, Func_7C980FFB0AA27E7A); 43 | LIB_FUNCTION("ioKMruft1ek", "libSceDiscMap", 1, "libSceDiscMap", 1, 1, Func_8A828CAEE7EDD5E9); 44 | LIB_FUNCTION("5+vOlukvkfg", "libSceDiscMap", 1, "libSceDiscMap", 1, 1, Func_E7EBCE96E92F91F8); 45 | }; 46 | 47 | } // namespace Libraries::DiscMap 48 | -------------------------------------------------------------------------------- /core/libraries/save_data/save_backup.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | #include "common/types.h" 10 | 11 | namespace Libraries::SaveData { 12 | 13 | using OrbisUserServiceUserId = s32; 14 | 15 | namespace Backup { 16 | 17 | enum class WorkerStatus { 18 | NotStarted, 19 | Waiting, 20 | Running, 21 | Stopping, 22 | }; 23 | 24 | enum class OrbisSaveDataEventType : u32 { 25 | UMOUNT_BACKUP = 1, 26 | BACKUP = 2, 27 | SAVE_DATA_MEMORY_SYNC = 3, 28 | 29 | __DO_NOT_SAVE = 1000000, // This value is only for the backup thread 30 | }; 31 | 32 | struct BackupRequest { 33 | bool done{}; 34 | 35 | OrbisUserServiceUserId user_id{}; 36 | std::string title_id{}; 37 | std::string dir_name{}; 38 | OrbisSaveDataEventType origin{}; 39 | 40 | std::filesystem::path save_path{}; 41 | }; 42 | 43 | // No problem calling this function if the backup thread is already running 44 | void StartThread(); 45 | 46 | void StopThread(); 47 | 48 | bool NewRequest(OrbisUserServiceUserId user_id, std::string_view title_id, 49 | std::string_view dir_name, OrbisSaveDataEventType origin); 50 | 51 | bool Restore(const std::filesystem::path& save_path); 52 | 53 | WorkerStatus GetWorkerStatus(); 54 | 55 | bool IsBackupExecutingFor(const std::filesystem::path& save_path); 56 | 57 | std::filesystem::path MakeBackupPath(const std::filesystem::path& save_path); 58 | 59 | std::optional PopLastEvent(); 60 | 61 | void PushBackupEvent(BackupRequest&& req); 62 | 63 | float GetProgress(); 64 | 65 | void ClearProgress(); 66 | 67 | } // namespace Backup 68 | 69 | } // namespace Libraries::SaveData 70 | -------------------------------------------------------------------------------- /common/error.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: 2013 Dolphin Emulator Project 2 | // SPDX-FileCopyrightText: 2014 Citra Emulator Project 3 | // SPDX-License-Identifier: GPL-2.0-or-later 4 | 5 | #include 6 | #ifdef _WIN32 7 | #include 8 | #else 9 | #include 10 | #include 11 | #endif 12 | 13 | #include "common/error.h" 14 | 15 | namespace Common { 16 | 17 | std::string NativeErrorToString(int e) { 18 | #ifdef _WIN32 19 | LPSTR err_str; 20 | 21 | DWORD res = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_ALLOCATE_BUFFER | 22 | FORMAT_MESSAGE_IGNORE_INSERTS, 23 | nullptr, e, MAKELANGID(LANG_ENGLISH, SUBLANG_ENGLISH_US), 24 | reinterpret_cast(&err_str), 1, nullptr); 25 | if (!res) { 26 | return "(FormatMessageA failed to format error)"; 27 | } 28 | std::string ret(err_str); 29 | LocalFree(err_str); 30 | return ret; 31 | #else 32 | char err_str[255]; 33 | #if defined(__GLIBC__) && (_GNU_SOURCE || (_POSIX_C_SOURCE < 200112L && _XOPEN_SOURCE < 600)) || \ 34 | defined(ANDROID) 35 | // Thread safe (GNU-specific) 36 | const char* str = strerror_r(e, err_str, sizeof(err_str)); 37 | return std::string(str); 38 | #else 39 | // Thread safe (XSI-compliant) 40 | int second_err = strerror_r(e, err_str, sizeof(err_str)); 41 | if (second_err != 0) { 42 | return "(strerror_r failed to format error)"; 43 | } 44 | return std::string(err_str); 45 | #endif // GLIBC etc. 46 | #endif // _WIN32 47 | } 48 | 49 | std::string GetLastErrorMsg() { 50 | #ifdef _WIN32 51 | return NativeErrorToString(GetLastError()); 52 | #else 53 | return NativeErrorToString(errno); 54 | #endif 55 | } 56 | 57 | } // namespace Common 58 | -------------------------------------------------------------------------------- /video_core/host_shaders/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-FileCopyrightText: Copyright 2023 Citra Emulator Project 2 | # SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | set(SHADER_FILES 5 | detilers/display_micro_64bpp.comp 6 | detilers/macro_32bpp.comp 7 | detilers/macro_64bpp.comp 8 | detilers/macro_8bpp.comp 9 | detilers/micro_128bpp.comp 10 | detilers/micro_16bpp.comp 11 | detilers/micro_32bpp.comp 12 | detilers/micro_64bpp.comp 13 | detilers/micro_8bpp.comp 14 | fs_tri.vert 15 | post_process.frag 16 | ) 17 | 18 | set(SHADER_INCLUDE ${CMAKE_CURRENT_BINARY_DIR}/include) 19 | set(SHADER_DIR ${SHADER_INCLUDE}/video_core/host_shaders) 20 | set(HOST_SHADERS_INCLUDE ${SHADER_INCLUDE} PARENT_SCOPE) 21 | 22 | set(INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/source_shader.h.in) 23 | set(HEADER_GENERATOR ${CMAKE_CURRENT_SOURCE_DIR}/StringShaderHeader.cmake) 24 | 25 | foreach(FILENAME IN ITEMS ${SHADER_FILES}) 26 | string(REPLACE "." "_" SHADER_NAME ${FILENAME}) 27 | set(SOURCE_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${FILENAME}) 28 | set(SOURCE_HEADER_FILE ${SHADER_DIR}/${SHADER_NAME}.h) 29 | add_custom_command( 30 | OUTPUT 31 | ${SOURCE_HEADER_FILE} 32 | COMMAND 33 | ${CMAKE_COMMAND} -P ${HEADER_GENERATOR} ${SOURCE_FILE} ${SOURCE_HEADER_FILE} ${INPUT_FILE} 34 | MAIN_DEPENDENCY 35 | ${SOURCE_FILE} 36 | DEPENDS 37 | ${INPUT_FILE} 38 | # HEADER_GENERATOR should be included here but msbuild seems to assume it's always modified 39 | ) 40 | set(SHADER_HEADERS ${SHADER_HEADERS} ${SOURCE_HEADER_FILE}) 41 | endforeach() 42 | 43 | set(SHADER_SOURCES ${SHADER_FILES}) 44 | list(APPEND SHADER_SOURCES ${GLSL_INCLUDES}) 45 | 46 | add_custom_target(host_shaders 47 | DEPENDS 48 | ${SHADER_HEADERS} 49 | SOURCES 50 | ${SHADER_SOURCES} 51 | ) 52 | -------------------------------------------------------------------------------- /video_core/amdgpu/pixel_format.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include "common/types.h" 9 | #include "video_core/amdgpu/types.h" 10 | 11 | namespace AmdGpu { 12 | 13 | enum NumberClass { 14 | Float, 15 | Sint, 16 | Uint, 17 | }; 18 | 19 | [[nodiscard]] constexpr NumberClass GetNumberClass(const NumberFormat nfmt) { 20 | switch (nfmt) { 21 | case NumberFormat::Sint: 22 | return Sint; 23 | case NumberFormat::Uint: 24 | return Uint; 25 | default: 26 | return Float; 27 | } 28 | } 29 | 30 | [[nodiscard]] constexpr bool IsInteger(const NumberFormat nfmt) { 31 | return nfmt == AmdGpu::NumberFormat::Sint || nfmt == AmdGpu::NumberFormat::Uint; 32 | } 33 | 34 | [[nodiscard]] std::string_view NameOf(DataFormat fmt); 35 | [[nodiscard]] std::string_view NameOf(NumberFormat fmt); 36 | 37 | int NumComponents(DataFormat format); 38 | int NumBits(DataFormat format); 39 | u32 ComponentBits(DataFormat format, u32 comp); 40 | s32 ComponentOffset(DataFormat format, u32 comp); 41 | 42 | } // namespace AmdGpu 43 | 44 | template <> 45 | struct fmt::formatter { 46 | constexpr auto parse(format_parse_context& ctx) { 47 | return ctx.begin(); 48 | } 49 | auto format(AmdGpu::DataFormat fmt, format_context& ctx) const { 50 | return fmt::format_to(ctx.out(), "{}", AmdGpu::NameOf(fmt)); 51 | } 52 | }; 53 | 54 | template <> 55 | struct fmt::formatter { 56 | constexpr auto parse(format_parse_context& ctx) { 57 | return ctx.begin(); 58 | } 59 | auto format(AmdGpu::NumberFormat fmt, format_context& ctx) const { 60 | return fmt::format_to(ctx.out(), "{}", AmdGpu::NameOf(fmt)); 61 | } 62 | }; 63 | -------------------------------------------------------------------------------- /video_core/texture_cache/image_view.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "shader_recompiler/info.h" 7 | #include "video_core/amdgpu/liverpool.h" 8 | #include "video_core/amdgpu/resource.h" 9 | #include "video_core/renderer_vulkan/vk_common.h" 10 | #include "video_core/texture_cache/types.h" 11 | 12 | namespace Vulkan { 13 | class Instance; 14 | class Scheduler; 15 | } // namespace Vulkan 16 | 17 | namespace VideoCore { 18 | 19 | struct ImageViewInfo { 20 | ImageViewInfo() = default; 21 | ImageViewInfo(const AmdGpu::Image& image, const Shader::ImageResource& desc) noexcept; 22 | ImageViewInfo(const AmdGpu::Liverpool::ColorBuffer& col_buffer) noexcept; 23 | ImageViewInfo(const AmdGpu::Liverpool::DepthBuffer& depth_buffer, 24 | AmdGpu::Liverpool::DepthView view, AmdGpu::Liverpool::DepthControl ctl); 25 | 26 | vk::ImageViewType type = vk::ImageViewType::e2D; 27 | vk::Format format = vk::Format::eR8G8B8A8Unorm; 28 | SubresourceRange range; 29 | vk::ComponentMapping mapping{}; 30 | bool is_storage = false; 31 | 32 | auto operator<=>(const ImageViewInfo&) const = default; 33 | }; 34 | 35 | struct Image; 36 | 37 | constexpr Common::SlotId NULL_IMAGE_VIEW_ID{0}; 38 | 39 | struct ImageView { 40 | ImageView(const Vulkan::Instance& instance, const ImageViewInfo& info, Image& image, 41 | ImageId image_id); 42 | ~ImageView(); 43 | 44 | ImageView(const ImageView&) = delete; 45 | ImageView& operator=(const ImageView&) = delete; 46 | 47 | ImageView(ImageView&&) = default; 48 | ImageView& operator=(ImageView&&) = default; 49 | 50 | ImageId image_id{}; 51 | Extent3D size{0, 0, 0}; 52 | ImageViewInfo info{}; 53 | vk::UniqueImageView image_view; 54 | }; 55 | 56 | } // namespace VideoCore 57 | -------------------------------------------------------------------------------- /video_core/host_shaders/detilers/micro_8bpp.comp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #version 450 5 | #extension GL_KHR_shader_subgroup_shuffle : require 6 | 7 | // NOTE: Current subgroup utilization is suboptimal on most GPUs, so 8 | // it will be nice to process two tiles at once here. 9 | layout (local_size_x = 16, local_size_y = 1, local_size_z = 1) in; 10 | 11 | layout(std430, binding = 0) buffer input_buf { 12 | uint in_data[]; 13 | }; 14 | layout(std430, binding = 1) buffer output_buf { 15 | uint out_data[]; 16 | }; 17 | 18 | layout(push_constant) uniform image_info { 19 | uint num_levels; 20 | uint pitch; 21 | uint height; 22 | uint sizes[14]; 23 | } info; 24 | 25 | #define MICRO_TILE_DIM 8 26 | #define TEXELS_PER_ELEMENT 4 27 | 28 | void main() { 29 | uint p0 = in_data[gl_GlobalInvocationID.x]; 30 | uint p1 = subgroupShuffleXor(p0, 1); 31 | uint hword = gl_LocalInvocationID.x & 1; 32 | uint dst_tx = (hword == 1) 33 | ? (p0 & 0xffff0000) | (p1 >> 16) 34 | : (p0 & 0x0000ffff) | (p1 << 16); 35 | 36 | uint col = (gl_LocalInvocationID.x >> 2) & 1; 37 | uint row = (gl_LocalInvocationID.x % TEXELS_PER_ELEMENT) 38 | + TEXELS_PER_ELEMENT * (gl_LocalInvocationID.x >> 3); 39 | 40 | uint mip = 0; 41 | for (int m = 0; m < info.num_levels; ++m) { 42 | mip += (gl_GlobalInvocationID.x * 4) >= info.sizes[m] ? 1 : 0; 43 | } 44 | 45 | uint tiles_per_pitch = max((info.pitch >> mip) / 8, 1); 46 | uint target_tile_x = gl_WorkGroupID.x % tiles_per_pitch; 47 | uint target_tile_y = gl_WorkGroupID.x / tiles_per_pitch; 48 | uint dw_ofs_x = target_tile_x * 2 + col; // 2 = uints 49 | uint dw_ofs_y = (target_tile_y * MICRO_TILE_DIM + row) * tiles_per_pitch * 2; // 2 = uints 50 | out_data[dw_ofs_x + dw_ofs_y] = dst_tx; 51 | } 52 | -------------------------------------------------------------------------------- /core/libraries/kernel/threads/exception.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/types.h" 7 | 8 | namespace Core::Loader { 9 | class SymbolsResolver; 10 | } 11 | 12 | namespace Libraries::Kernel { 13 | 14 | using SceKernelExceptionHandler = PS4_SYSV_ABI void (*)(int, void*); 15 | 16 | constexpr int POSIX_SIGSEGV = 11; 17 | constexpr int POSIX_SIGUSR1 = 30; 18 | 19 | struct Mcontext { 20 | u64 mc_onstack; 21 | u64 mc_rdi; 22 | u64 mc_rsi; 23 | u64 mc_rdx; 24 | u64 mc_rcx; 25 | u64 mc_r8; 26 | u64 mc_r9; 27 | u64 mc_rax; 28 | u64 mc_rbx; 29 | u64 mc_rbp; 30 | u64 mc_r10; 31 | u64 mc_r11; 32 | u64 mc_r12; 33 | u64 mc_r13; 34 | u64 mc_r14; 35 | u64 mc_r15; 36 | int mc_trapno; 37 | u16 mc_fs; 38 | u16 mc_gs; 39 | u64 mc_addr; 40 | int mc_flags; 41 | u16 mc_es; 42 | u16 mc_ds; 43 | u64 mc_err; 44 | u64 mc_rip; 45 | u64 mc_cs; 46 | u64 mc_rflags; 47 | u64 mc_rsp; 48 | u64 mc_ss; 49 | u64 mc_len; 50 | u64 mc_fpformat; 51 | u64 mc_ownedfp; 52 | u64 mc_lbrfrom; 53 | u64 mc_lbrto; 54 | u64 mc_aux1; 55 | u64 mc_aux2; 56 | u64 mc_fpstate[104]; 57 | u64 mc_fsbase; 58 | u64 mc_gsbase; 59 | u64 mc_spare[6]; 60 | }; 61 | 62 | struct Stack { 63 | void* ss_sp; 64 | std::size_t ss_size; 65 | int ss_flags; 66 | int _align; 67 | }; 68 | 69 | struct Sigset { 70 | u64 bits[2]; 71 | }; 72 | 73 | struct Ucontext { 74 | struct Sigset uc_sigmask; 75 | int field1_0x10[12]; 76 | struct Mcontext uc_mcontext; 77 | struct Ucontext* uc_link; 78 | struct Stack uc_stack; 79 | int uc_flags; 80 | int __spare[4]; 81 | int field7_0x4f4[3]; 82 | }; 83 | 84 | void RegisterException(Core::Loader::SymbolsResolver* sym); 85 | 86 | } // namespace Libraries::Kernel 87 | -------------------------------------------------------------------------------- /common/unique_function.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | 9 | namespace Common { 10 | 11 | /// General purpose function wrapper similar to std::function. 12 | /// Unlike std::function, the captured values don't have to be copyable. 13 | /// This class can be moved but not copied. 14 | template 15 | class UniqueFunction { 16 | class CallableBase { 17 | public: 18 | virtual ~CallableBase() = default; 19 | virtual ResultType operator()(Args&&...) = 0; 20 | }; 21 | 22 | template 23 | class Callable final : public CallableBase { 24 | public: 25 | Callable(Functor&& functor_) : functor{std::move(functor_)} {} 26 | ~Callable() override = default; 27 | 28 | ResultType operator()(Args&&... args) override { 29 | return functor(std::forward(args)...); 30 | } 31 | 32 | private: 33 | Functor functor; 34 | }; 35 | 36 | public: 37 | UniqueFunction() = default; 38 | 39 | template 40 | UniqueFunction(Functor&& functor) 41 | : callable{std::make_unique>(std::move(functor))} {} 42 | 43 | UniqueFunction& operator=(UniqueFunction&& rhs) noexcept = default; 44 | UniqueFunction(UniqueFunction&& rhs) noexcept = default; 45 | 46 | UniqueFunction& operator=(const UniqueFunction&) = delete; 47 | UniqueFunction(const UniqueFunction&) = delete; 48 | 49 | ResultType operator()(Args&&... args) const { 50 | return (*callable)(std::forward(args)...); 51 | } 52 | 53 | explicit operator bool() const noexcept { 54 | return static_cast(callable); 55 | } 56 | 57 | private: 58 | std::unique_ptr callable; 59 | }; 60 | 61 | } // namespace Common 62 | -------------------------------------------------------------------------------- /core/libraries/avplayer/avplayer_common.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include // std::equal 5 | #include // std::tolower 6 | 7 | #include "core/libraries/avplayer/avplayer.h" 8 | #include "core/libraries/avplayer/avplayer_common.h" 9 | 10 | namespace Libraries::AvPlayer { 11 | 12 | static bool iequals(std::string_view l, std::string_view r) { 13 | return std::ranges::equal(l, r, [](u8 a, u8 b) { return std::tolower(a) == std::tolower(b); }); 14 | } 15 | 16 | SceAvPlayerSourceType GetSourceType(std::string_view path) { 17 | if (path.empty()) { 18 | return SceAvPlayerSourceType::Unknown; 19 | } 20 | 21 | std::string_view name = path; 22 | if (path.find("://") != std::string_view::npos) { 23 | // This path is a URI. Strip HTTP parameters from it. 24 | // schema://server.domain/path/file.ext/and/beyond?param=value#paragraph -> 25 | // -> schema://server.domain/path/to/file.ext/and/beyond 26 | name = path.substr(0, path.find_first_of("?#")); 27 | if (name.empty()) { 28 | return SceAvPlayerSourceType::Unknown; 29 | } 30 | } 31 | 32 | // schema://server.domain/path/to/file.ext/and/beyond -> .ext/and/beyond 33 | auto ext = name.substr(name.rfind('.')); 34 | if (ext.empty()) { 35 | return SceAvPlayerSourceType::Unknown; 36 | } 37 | 38 | // .ext/and/beyond -> .ext 39 | ext = ext.substr(0, ext.find('/')); 40 | 41 | if (iequals(ext, ".mp4") || iequals(ext, ".m4v") || iequals(ext, ".m3d") || 42 | iequals(ext, ".m4a") || iequals(ext, ".mov")) { 43 | return SceAvPlayerSourceType::FileMp4; 44 | } 45 | 46 | if (iequals(ext, ".m3u8")) { 47 | return SceAvPlayerSourceType::Hls; 48 | } 49 | 50 | return SceAvPlayerSourceType::Unknown; 51 | } 52 | 53 | } // namespace Libraries::AvPlayer 54 | -------------------------------------------------------------------------------- /core/devices/logger.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "common/logging/log.h" 5 | #include "core/libraries/kernel/file_system.h" 6 | #include "logger.h" 7 | 8 | namespace Core::Devices { 9 | 10 | Logger::Logger(std::string prefix, bool is_err) : prefix(std::move(prefix)), is_err(is_err) {} 11 | 12 | Logger::~Logger() = default; 13 | 14 | s64 Logger::write(const void* buf, size_t nbytes) { 15 | log(static_cast(buf), nbytes); 16 | return nbytes; 17 | } 18 | 19 | size_t Logger::writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) { 20 | size_t total_written = 0; 21 | for (int i = 0; i < iovcnt; i++) { 22 | log(static_cast(iov[i].iov_base), iov[i].iov_len); 23 | total_written += iov[i].iov_len; 24 | } 25 | return total_written; 26 | } 27 | 28 | s64 Logger::pwrite(const void* buf, size_t nbytes, u64 offset) { 29 | log(static_cast(buf), nbytes); 30 | return nbytes; 31 | } 32 | 33 | s32 Logger::fsync() { 34 | log_flush(); 35 | return 0; 36 | } 37 | 38 | void Logger::log(const char* buf, size_t nbytes) { 39 | std::scoped_lock lock{mtx}; 40 | const char* end = buf + nbytes; 41 | for (const char* it = buf; it < end; ++it) { 42 | char c = *it; 43 | if (c == '\r') { 44 | continue; 45 | } 46 | if (c == '\n') { 47 | log_flush(); 48 | continue; 49 | } 50 | buffer.push_back(c); 51 | } 52 | } 53 | 54 | void Logger::log_flush() { 55 | std::scoped_lock lock{mtx}; 56 | if (buffer.empty()) { 57 | return; 58 | } 59 | if (is_err) { 60 | LOG_ERROR(Tty, "[{}] {}", prefix, std::string_view{buffer}); 61 | } else { 62 | LOG_INFO(Tty, "[{}] {}", prefix, std::string_view{buffer}); 63 | } 64 | buffer.clear(); 65 | } 66 | 67 | } // namespace Core::Devices -------------------------------------------------------------------------------- /common/decoder.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | #include "common/decoder.h" 6 | 7 | namespace Common { 8 | 9 | DecoderImpl::DecoderImpl() { 10 | ZydisDecoderInit(&m_decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64); 11 | ZydisFormatterInit(&m_formatter, ZYDIS_FORMATTER_STYLE_INTEL); 12 | } 13 | 14 | DecoderImpl::~DecoderImpl() = default; 15 | 16 | std::string DecoderImpl::disassembleInst(ZydisDecodedInstruction& inst, 17 | ZydisDecodedOperand* operands, u64 address) { 18 | const int bufLen = 256; 19 | char szBuffer[bufLen]; 20 | ZydisFormatterFormatInstruction(&m_formatter, &inst, operands, inst.operand_count_visible, 21 | szBuffer, sizeof(szBuffer), address, ZYAN_NULL); 22 | return szBuffer; 23 | } 24 | 25 | void DecoderImpl::printInstruction(void* code, u64 address) { 26 | ZydisDecodedInstruction instruction; 27 | ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT_VISIBLE]; 28 | ZyanStatus status = 29 | ZydisDecoderDecodeFull(&m_decoder, code, sizeof(code), &instruction, operands); 30 | if (!ZYAN_SUCCESS(status)) { 31 | fmt::print("decode instruction failed at {}\n", fmt::ptr(code)); 32 | } else { 33 | printInst(instruction, operands, address); 34 | } 35 | } 36 | 37 | void DecoderImpl::printInst(ZydisDecodedInstruction& inst, ZydisDecodedOperand* operands, 38 | u64 address) { 39 | std::string s = disassembleInst(inst, operands, address); 40 | fmt::print("instruction: {}\n", s); 41 | } 42 | 43 | ZyanStatus DecoderImpl::decodeInstruction(ZydisDecodedInstruction& inst, 44 | ZydisDecodedOperand* operands, void* data, u64 size) { 45 | return ZydisDecoderDecodeFull(&m_decoder, data, size, &inst, operands); 46 | } 47 | 48 | } // namespace Common 49 | -------------------------------------------------------------------------------- /common/slot_array.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | // #include 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | namespace Common { 15 | 16 | template ::max(), IndexType MinIndex = 0> 18 | class SlotArray { 19 | public: 20 | SlotArray() { 21 | std::iota(m_free_indices.begin(), m_free_indices.end(), MinIndex); 22 | } 23 | 24 | template 25 | std::optional Create(Types&&... args) { 26 | if (!HasFreeSlots()) { 27 | return std::nullopt; 28 | } 29 | const auto index = m_free_indices[m_curr_cursor]; 30 | m_resources[index - MinIndex] = ResourceType(std::forward(args)...); 31 | m_curr_cursor += 1; 32 | return index; 33 | } 34 | 35 | bool Destroy(IndexType index) { 36 | if (!m_resources[index - MinIndex].has_value()) { 37 | return false; 38 | } 39 | m_curr_cursor -= 1; 40 | m_free_indices[m_curr_cursor] = index; 41 | m_resources[index - MinIndex] = std::nullopt; 42 | return true; 43 | } 44 | 45 | ResourceType* Get(IndexType index) { 46 | auto& resource = m_resources[index - MinIndex]; 47 | if (!resource.has_value()) { 48 | return nullptr; 49 | } 50 | return &resource.value(); 51 | } 52 | 53 | bool HasFreeSlots() { 54 | return m_curr_cursor < m_free_indices.size(); 55 | } 56 | 57 | private: 58 | size_t m_curr_cursor = 0; 59 | std::array m_free_indices; 60 | std::array, MaxIndex - MinIndex> m_resources; 61 | }; 62 | 63 | } // namespace Common 64 | -------------------------------------------------------------------------------- /core/libraries/rtc/rtc_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | constexpr int ORBIS_RTC_ERROR_DATETIME_UNINITIALIZED = 0x7FFEF9FE; 9 | constexpr int ORBIS_RTC_ERROR_INVALID_PARAMETER = 0x80010602; 10 | constexpr int ORBIS_RTC_ERROR_INVALID_TICK_PARAMETER = 0x80010603; 11 | constexpr int ORBIS_RTC_ERROR_INVALID_DATE_PARAMETER = 0x80010604; 12 | constexpr int ORBIS_RTC_ERROR_NOT_IMPLEMENTED = 0x80010605; 13 | constexpr int ORBIS_RTC_ERROR_INVALID_TIMEZONE_FORMAT = 0x80010607; 14 | constexpr int ORBIS_RTC_ERROR_INVALID_YEARS_PARAMETER = 0x80010621; 15 | constexpr int ORBIS_RTC_ERROR_INVALID_MONTHS_PARAMETER = 0x80010622; 16 | constexpr int ORBIS_RTC_ERROR_INVALID_DAYS_PARAMETER = 0x80010623; 17 | constexpr int ORBIS_RTC_ERROR_INVALID_HOURS_PARAMETER = 0x80010624; 18 | constexpr int ORBIS_RTC_ERROR_INVALID_MINUTES_PARAMETER = 0x80010625; 19 | constexpr int ORBIS_RTC_ERROR_INVALID_SECONDS_PARAMETER = 0x80010626; 20 | constexpr int ORBIS_RTC_ERROR_INVALID_MILLISECONDS_PARAMETER = 0x80010627; 21 | constexpr int ORBIS_RTC_ERROR_NOT_INITIALIZED = 0x80B50001; 22 | constexpr int ORBIS_RTC_ERROR_INVALID_POINTER = 0x80B50002; 23 | constexpr int ORBIS_RTC_ERROR_INVALID_VALUE = 0x80B50003; 24 | constexpr int ORBIS_RTC_ERROR_INVALID_ARG = 0x80B50004; 25 | constexpr int ORBIS_RTC_ERROR_NOT_SUPPORTED = 0x80B50005; 26 | constexpr int ORBIS_RTC_ERROR_NO_CLOCK = 0x80B50006; 27 | constexpr int ORBIS_RTC_ERROR_BAD_PARSE = 0x80B50007; 28 | constexpr int ORBIS_RTC_ERROR_INVALID_YEAR = 0x80B50008; 29 | constexpr int ORBIS_RTC_ERROR_INVALID_MONTH = 0x80B50009; 30 | constexpr int ORBIS_RTC_ERROR_INVALID_DAY = 0x80B5000A; 31 | constexpr int ORBIS_RTC_ERROR_INVALID_HOUR = 0x80B5000B; 32 | constexpr int ORBIS_RTC_ERROR_INVALID_MINUTE = 0x80B5000C; 33 | constexpr int ORBIS_RTC_ERROR_INVALID_SECOND = 0x80B5000D; 34 | constexpr int ORBIS_RTC_ERROR_INVALID_MICROSECOND = 0x80B5000E; 35 | -------------------------------------------------------------------------------- /core/signals.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/singleton.h" 8 | 9 | namespace Core { 10 | 11 | using AccessViolationHandler = bool (*)(void* context, void* fault_address); 12 | using IllegalInstructionHandler = bool (*)(void* context); 13 | 14 | /// Receives OS signals and dispatches to the appropriate handlers. 15 | class SignalDispatch { 16 | public: 17 | SignalDispatch(); 18 | ~SignalDispatch(); 19 | 20 | /// Registers a handler for memory access violation signals. 21 | void RegisterAccessViolationHandler(const AccessViolationHandler& handler, u32 priority) { 22 | access_violation_handlers.emplace(handler, priority); 23 | } 24 | 25 | /// Registers a handler for illegal instruction signals. 26 | void RegisterIllegalInstructionHandler(const IllegalInstructionHandler& handler, u32 priority) { 27 | illegal_instruction_handlers.emplace(handler, priority); 28 | } 29 | 30 | /// Dispatches an access violation signal, returning whether it was successfully handled. 31 | bool DispatchAccessViolation(void* context, void* fault_address) const; 32 | 33 | /// Dispatches an illegal instruction signal, returning whether it was successfully handled. 34 | bool DispatchIllegalInstruction(void* context) const; 35 | 36 | private: 37 | template 38 | struct HandlerEntry { 39 | T handler; 40 | u32 priority; 41 | 42 | std::strong_ordering operator<=>(const HandlerEntry& right) const { 43 | return priority <=> right.priority; 44 | } 45 | }; 46 | std::set> access_violation_handlers; 47 | std::set> illegal_instruction_handlers; 48 | 49 | #ifdef _WIN32 50 | void* handle{}; 51 | #endif 52 | }; 53 | 54 | using Signals = Common::Singleton; 55 | 56 | } // namespace Core -------------------------------------------------------------------------------- /video_core/host_shaders/detilers/micro_32bpp.comp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #version 450 5 | 6 | layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in; 7 | 8 | layout(std430, binding = 0) buffer input_buf { 9 | uint in_data[]; 10 | }; 11 | layout(std430, binding = 1) buffer output_buf { 12 | uint out_data[]; 13 | }; 14 | 15 | layout(push_constant) uniform image_info { 16 | uint num_levels; 17 | uint pitch; 18 | uint height; 19 | uint sizes[14]; 20 | } info; 21 | 22 | // Inverse morton LUT, small enough to fit into K$ 23 | const uint rmort[16] = { 24 | 0x11011000, 0x31213020, 25 | 0x13031202, 0x33233222, 26 | 0x51415040, 0x71617060, 27 | 0x53435242, 0x73637262, 28 | 29 | 0x15051404, 0x35253424, 30 | 0x17071606, 0x37273626, 31 | 0x55455444, 0x75657464, 32 | 0x57475646, 0x77677666, 33 | }; 34 | 35 | #define MICRO_TILE_DIM (8) 36 | #define TEXELS_PER_ELEMENT (1) 37 | 38 | void main() { 39 | uint tile_base = gl_GlobalInvocationID.x - gl_LocalInvocationID.x; // WG*16 40 | uint p0 = in_data[gl_GlobalInvocationID.x]; 41 | uint bit_ofs = 8 * (gl_LocalInvocationID.x % 4); 42 | uint packed_pos = rmort[gl_LocalInvocationID.x >> 2] >> bit_ofs; 43 | uint col = bitfieldExtract(packed_pos, 4, 4); 44 | uint row = bitfieldExtract(packed_pos, 0, 4); 45 | 46 | uint mip = 0; 47 | for (int m = 0; m < info.num_levels; ++m) { 48 | mip += (gl_GlobalInvocationID.x * 4) >= info.sizes[m] ? 1 : 0; 49 | } 50 | 51 | uint tiles_per_pitch = max((info.pitch >> mip) / MICRO_TILE_DIM, 1); 52 | uint target_tile_x = gl_WorkGroupID.x % tiles_per_pitch; 53 | uint target_tile_y = gl_WorkGroupID.x / tiles_per_pitch; 54 | uint dw_ofs_x = target_tile_x * MICRO_TILE_DIM + col; 55 | uint dw_ofs_y = (target_tile_y * tiles_per_pitch * 64) + row * tiles_per_pitch * MICRO_TILE_DIM; 56 | out_data[dw_ofs_x + dw_ofs_y] = p0; 57 | } 58 | -------------------------------------------------------------------------------- /core/libraries/ajm/ajm_context.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "common/bounded_threadsafe_queue.h" 7 | #include "common/slot_array.h" 8 | #include "common/types.h" 9 | #include "core/libraries/ajm/ajm.h" 10 | #include "core/libraries/ajm/ajm_batch.h" 11 | #include "core/libraries/ajm/ajm_instance.h" 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | 20 | namespace Libraries::Ajm { 21 | 22 | class AjmContext { 23 | public: 24 | AjmContext(); 25 | 26 | s32 InstanceCreate(AjmCodecType codec_type, AjmInstanceFlags flags, u32* out_instance_id); 27 | s32 InstanceDestroy(u32 instance_id); 28 | 29 | s32 BatchCancel(const u32 batch_id); 30 | s32 ModuleRegister(AjmCodecType type); 31 | s32 BatchWait(const u32 batch_id, const u32 timeout, AjmBatchError* const p_batch_error); 32 | s32 BatchStartBuffer(u8* p_batch, u32 batch_size, const int priority, 33 | AjmBatchError* p_batch_error, u32* p_batch_id); 34 | 35 | void WorkerThread(std::stop_token stop); 36 | void ProcessBatch(u32 id, std::span jobs); 37 | 38 | private: 39 | static constexpr u32 MaxInstances = 0x2fff; 40 | static constexpr u32 MaxBatches = 0x0400; 41 | static constexpr u32 NumAjmCodecs = std::to_underlying(AjmCodecType::Max); 42 | 43 | [[nodiscard]] bool IsRegistered(AjmCodecType type) const; 44 | 45 | std::array registered_codecs{}; 46 | 47 | std::shared_mutex instances_mutex; 48 | Common::SlotArray, MaxInstances, 1> instances; 49 | 50 | std::shared_mutex batches_mutex; 51 | Common::SlotArray, MaxBatches, 1> batches; 52 | 53 | std::jthread worker_thread{}; 54 | Common::MPSCQueue> batch_queue; 55 | }; 56 | 57 | } // namespace Libraries::Ajm 58 | -------------------------------------------------------------------------------- /core/libraries/kernel/threads/pthread_clean.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include "core/libraries/kernel/threads/pthread.h" 5 | #include "core/libraries/libs.h" 6 | 7 | namespace Libraries::Kernel { 8 | 9 | void PS4_SYSV_ABI __pthread_cleanup_push_imp(PthreadCleanupFunc routine, void* arg, 10 | PthreadCleanup* newbuf) { 11 | newbuf->routine = routine; 12 | newbuf->routine_arg = arg; 13 | newbuf->onheap = 0; 14 | g_curthread->cleanup.push_front(newbuf); 15 | } 16 | 17 | void PS4_SYSV_ABI posix_pthread_cleanup_push(PthreadCleanupFunc routine, void* arg) { 18 | Pthread* curthread = g_curthread; 19 | PthreadCleanup* newbuf = new PthreadCleanup{}; 20 | if (newbuf == nullptr) { 21 | return; 22 | } 23 | 24 | newbuf->routine = routine; 25 | newbuf->routine_arg = arg; 26 | newbuf->onheap = 1; 27 | curthread->cleanup.push_front(newbuf); 28 | } 29 | 30 | void PS4_SYSV_ABI posix_pthread_cleanup_pop(int execute) { 31 | Pthread* curthread = g_curthread; 32 | if (!curthread->cleanup.empty()) { 33 | PthreadCleanup* old = curthread->cleanup.front(); 34 | curthread->cleanup.pop_front(); 35 | if (execute) { 36 | old->routine(old->routine_arg); 37 | } 38 | if (old->onheap) { 39 | delete old; 40 | } 41 | } 42 | } 43 | 44 | void RegisterPthreadClean(Core::Loader::SymbolsResolver* sym) { 45 | // Posix 46 | LIB_FUNCTION("4ZeZWcMsAV0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cleanup_push); 47 | LIB_FUNCTION("RVxb0Ssa5t0", "libScePosix", 1, "libkernel", 1, 1, posix_pthread_cleanup_pop); 48 | 49 | // Posix-Kernel 50 | LIB_FUNCTION("1xvtUVx1-Sg", "libkernel", 1, "libkernel", 1, 1, __pthread_cleanup_push_imp); 51 | LIB_FUNCTION("iWsFlYMf3Kw", "libkernel", 1, "libkernel", 1, 1, posix_pthread_cleanup_pop); 52 | } 53 | 54 | } // namespace Libraries::Kernel 55 | -------------------------------------------------------------------------------- /core/libraries/audio/audioout_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // AudioOut library 9 | constexpr int ORBIS_AUDIO_OUT_ERROR_NOT_OPENED = 0x80260001; 10 | constexpr int ORBIS_AUDIO_OUT_ERROR_BUSY = 0x80260002; 11 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PORT = 0x80260003; 12 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_POINTER = 0x80260004; 13 | constexpr int ORBIS_AUDIO_OUT_ERROR_PORT_FULL = 0x80260005; 14 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_SIZE = 0x80260006; 15 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_FORMAT = 0x80260007; 16 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_SAMPLE_FREQ = 0x80260008; 17 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_VOLUME = 0x80260009; 18 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PORT_TYPE = 0x8026000A; 19 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_CONF_TYPE = 0x8026000C; 20 | constexpr int ORBIS_AUDIO_OUT_ERROR_OUT_OF_MEMORY = 0x8026000D; 21 | constexpr int ORBIS_AUDIO_OUT_ERROR_ALREADY_INIT = 0x8026000E; 22 | constexpr int ORBIS_AUDIO_OUT_ERROR_NOT_INIT = 0x8026000F; 23 | constexpr int ORBIS_AUDIO_OUT_ERROR_MEMORY = 0x80260010; 24 | constexpr int ORBIS_AUDIO_OUT_ERROR_SYSTEM_RESOURCE = 0x80260011; 25 | constexpr int ORBIS_AUDIO_OUT_ERROR_TRANS_EVENT = 0x80260012; 26 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_FLAG = 0x80260013; 27 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_MIXLEVEL = 0x80260014; 28 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_ARG = 0x80260015; 29 | constexpr int ORBIS_AUDIO_OUT_ERROR_INVALID_PARAM = 0x80260016; 30 | constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_FATAL = 0x80260200; 31 | constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_API_PARAM = 0x80260201; 32 | constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_CONFIG = 0x80260202; 33 | constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_NOT_INITIALIZED = 0x80260203; 34 | constexpr int ORBIS_AUDIO_OUT_ERROR_MASTERING_INVALID_STATES_ID = 0x80260204; 35 | -------------------------------------------------------------------------------- /core/loader/symbols_resolver.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | #include "common/io_file.h" 6 | #include "common/string_util.h" 7 | #include "common/types.h" 8 | #include "core/aerolib/aerolib.h" 9 | #include "core/loader/symbols_resolver.h" 10 | 11 | namespace Core::Loader { 12 | 13 | void SymbolsResolver::AddSymbol(const SymbolResolver& s, u64 virtual_addr) { 14 | m_symbols.emplace_back(GenerateName(s), s.nidName, virtual_addr); 15 | } 16 | 17 | std::string SymbolsResolver::GenerateName(const SymbolResolver& s) { 18 | return fmt::format("{}#{}#{}#{}#{}#{}#{}", s.name, s.library, s.library_version, s.module, 19 | s.module_version_major, s.module_version_minor, SymbolTypeToS(s.type)); 20 | } 21 | 22 | const SymbolRecord* SymbolsResolver::FindSymbol(const SymbolResolver& s) const { 23 | const std::string name = GenerateName(s); 24 | for (u32 i = 0; i < m_symbols.size(); i++) { 25 | if (m_symbols[i].name == name) { 26 | return &m_symbols[i]; 27 | } 28 | } 29 | 30 | // LOG_INFO(Core_Linker, "Unresolved! {}", name); 31 | return nullptr; 32 | } 33 | 34 | void SymbolsResolver::DebugDump(const std::filesystem::path& file_name) { 35 | Common::FS::IOFile f{file_name, Common::FS::FileAccessMode::Write, 36 | Common::FS::FileType::TextFile}; 37 | for (const auto& symbol : m_symbols) { 38 | const auto ids = Common::SplitString(symbol.name, '#'); 39 | const auto aeronid = AeroLib::FindByNid(ids.at(0).c_str()); 40 | const auto nid_name = aeronid ? aeronid->name : "UNK"; 41 | f.WriteString( 42 | fmt::format("0x{:<20x} {:<16} {:<60} {:<30} {:<2} {:<30} {:<2} {:<2} {:<10}\n", 43 | symbol.virtual_address, ids.at(0), nid_name, ids.at(1), ids.at(2), 44 | ids.at(3), ids.at(4), ids.at(5), ids.at(6))); 45 | } 46 | } 47 | 48 | } // namespace Core::Loader 49 | -------------------------------------------------------------------------------- /video_core/host_shaders/detilers/micro_64bpp.comp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #version 450 5 | 6 | layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in; 7 | 8 | layout(std430, binding = 0) buffer input_buf { 9 | uint in_data[]; 10 | }; 11 | layout(std430, binding = 1) buffer output_buf { 12 | uint out_data[]; 13 | }; 14 | 15 | layout(push_constant) uniform image_info { 16 | uint num_levels; 17 | uint pitch; 18 | uint height; 19 | uint sizes[14]; 20 | } info; 21 | 22 | // Inverse morton LUT, small enough to fit into K$ 23 | const uint rmort[16] = { 24 | 0x11011000, 0x31213020, 25 | 0x13031202, 0x33233222, 26 | 0x51415040, 0x71617060, 27 | 0x53435242, 0x73637262, 28 | 29 | 0x15051404, 0x35253424, 30 | 0x17071606, 0x37273626, 31 | 0x55455444, 0x75657464, 32 | 0x57475646, 0x77677666, 33 | }; 34 | 35 | #define MICRO_TILE_DIM (8) 36 | 37 | void main() { 38 | uint block_ofs = 2 * gl_GlobalInvocationID.x; 39 | uint p0 = in_data[block_ofs + 0]; 40 | uint p1 = in_data[block_ofs + 1]; 41 | 42 | uint bit_ofs = 8 * (gl_LocalInvocationID.x % 4); 43 | uint packed_pos = rmort[gl_LocalInvocationID.x >> 2] >> bit_ofs; 44 | uint col = bitfieldExtract(packed_pos, 4, 4); 45 | uint row = bitfieldExtract(packed_pos, 0, 4); 46 | 47 | uint mip = 0; 48 | for (int m = 0; m < info.num_levels; ++m) { 49 | mip += (gl_GlobalInvocationID.x * 8) >= info.sizes[m] ? 1 : 0; 50 | } 51 | 52 | uint tiles_per_pitch = max((info.pitch >> mip) / MICRO_TILE_DIM, 1) * 2; 53 | uint target_tile_x = 2 * gl_WorkGroupID.x % tiles_per_pitch; 54 | uint target_tile_y = 2 * gl_WorkGroupID.x / tiles_per_pitch; 55 | uint dw_ofs_x = target_tile_x * MICRO_TILE_DIM + col * 2; 56 | uint dw_ofs_y = (target_tile_y * tiles_per_pitch * 64) + row * tiles_per_pitch * MICRO_TILE_DIM; 57 | out_data[dw_ofs_x + dw_ofs_y] = p0; 58 | out_data[dw_ofs_x + dw_ofs_y + 1] = p1; 59 | } 60 | -------------------------------------------------------------------------------- /core/loader/symbols_resolver.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "common/types.h" 11 | 12 | namespace Core::Loader { 13 | 14 | enum class SymbolType { 15 | Unknown, 16 | Function, 17 | Object, 18 | Tls, 19 | NoType, 20 | }; 21 | 22 | struct SymbolRecord { 23 | std::string name; 24 | std::string nid_name; 25 | u64 virtual_address; 26 | }; 27 | 28 | struct SymbolResolver { 29 | std::string name; 30 | std::string nidName; 31 | std::string library; 32 | u16 library_version; 33 | std::string module; 34 | u8 module_version_major; 35 | u8 module_version_minor; 36 | SymbolType type; 37 | }; 38 | 39 | class SymbolsResolver { 40 | public: 41 | SymbolsResolver() = default; 42 | virtual ~SymbolsResolver() = default; 43 | 44 | void AddSymbol(const SymbolResolver& s, u64 virtual_addr); 45 | const SymbolRecord* FindSymbol(const SymbolResolver& s) const; 46 | 47 | void DebugDump(const std::filesystem::path& file_name); 48 | 49 | std::span GetSymbols() const { 50 | return m_symbols; 51 | } 52 | 53 | size_t GetSize() const noexcept { 54 | return m_symbols.size(); 55 | } 56 | 57 | static std::string GenerateName(const SymbolResolver& s); 58 | 59 | static std::string_view SymbolTypeToS(SymbolType sym_type) { 60 | switch (sym_type) { 61 | case SymbolType::Unknown: 62 | return "Unknown"; 63 | case SymbolType::Function: 64 | return "Function"; 65 | case SymbolType::Object: 66 | return "Object"; 67 | case SymbolType::Tls: 68 | return "Tls"; 69 | case SymbolType::NoType: 70 | return "NoType"; 71 | } 72 | } 73 | 74 | private: 75 | std::vector m_symbols; 76 | }; 77 | 78 | } // namespace Core::Loader 79 | -------------------------------------------------------------------------------- /core/libraries/videoout/buffer.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | 8 | #include "common/assert.h" 9 | #include "common/types.h" 10 | 11 | namespace Libraries::VideoOut { 12 | 13 | constexpr std::size_t MaxDisplayBuffers = 16; 14 | constexpr std::size_t MaxDisplayBufferGroups = 4; 15 | 16 | enum class PixelFormat : u32 { 17 | Unknown, 18 | A8R8G8B8Srgb = 0x80000000, 19 | A8B8G8R8Srgb = 0x80002200, 20 | A2R10G10B10 = 0x88060000, 21 | A2R10G10B10Srgb = 0x88000000, 22 | A2R10G10B10Bt2020Pq = 0x88740000, 23 | A16R16G16B16Float = 0xC1060000, 24 | }; 25 | 26 | enum class TilingMode : s32 { 27 | Tile = 0, 28 | Linear = 1, 29 | }; 30 | 31 | constexpr std::string_view GetPixelFormatString(PixelFormat format) { 32 | switch (format) { 33 | case PixelFormat::A8R8G8B8Srgb: 34 | return "A8R8G8B8Srgb"; 35 | case PixelFormat::A8B8G8R8Srgb: 36 | return "A8B8G8R8Srgb"; 37 | case PixelFormat::A2R10G10B10: 38 | return "A2R10G10B10"; 39 | case PixelFormat::A2R10G10B10Srgb: 40 | return "A2R10G10B10Srgb"; 41 | case PixelFormat::A2R10G10B10Bt2020Pq: 42 | return "A2R10G10B10Bt2020Pq"; 43 | case PixelFormat::A16R16G16B16Float: 44 | return "A16R16G16B16Float"; 45 | default: 46 | UNREACHABLE_MSG("Unknown pixel format {}", static_cast(format)); 47 | return ""; 48 | } 49 | } 50 | 51 | struct BufferAttribute { 52 | PixelFormat pixel_format; 53 | TilingMode tiling_mode; 54 | s32 aspect_ratio; 55 | u32 width; 56 | u32 height; 57 | u32 pitch_in_pixel; 58 | u32 option; 59 | u32 reserved0; 60 | u64 reserved1; 61 | }; 62 | 63 | struct BufferAttributeGroup { 64 | bool is_occupied; 65 | BufferAttribute attrib; 66 | }; 67 | 68 | struct VideoOutBuffer { 69 | s32 group_index{-1}; 70 | uintptr_t address_left; 71 | uintptr_t address_right; 72 | }; 73 | 74 | } // namespace Libraries::VideoOut 75 | -------------------------------------------------------------------------------- /video_core/host_shaders/detilers/display_micro_64bpp.comp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #version 450 5 | 6 | layout (local_size_x = 64, local_size_y = 1, local_size_z = 1) in; 7 | 8 | layout(std430, binding = 0) buffer input_buf { 9 | uint in_data[]; 10 | }; 11 | layout(std430, binding = 1) buffer output_buf { 12 | uint out_data[]; 13 | }; 14 | 15 | layout(push_constant) uniform image_info { 16 | uint num_levels; 17 | uint pitch; 18 | uint height; 19 | uint c0; 20 | uint c1; 21 | } info; 22 | 23 | const uint lut_64bpp[16] = { 24 | 0x05040100, 0x0d0c0908, 25 | 0x07060302, 0x0f0e0b0a, 26 | 0x15141110, 0x1d1c1918, 27 | 0x17161312, 0x1f1e1b1a, 28 | 0x25242120, 0x2d2c2928, 29 | 0x27262322, 0x2f2e2b2a, 30 | 0x35343130, 0x3d3c3938, 31 | 0x37363332, 0x3f3e3b3a, 32 | }; 33 | 34 | #define MICRO_TILE_DIM (8) 35 | #define MICRO_TILE_SZ (512) 36 | #define TEXELS_PER_ELEMENT (1) 37 | #define BPP (64) 38 | 39 | void main() { 40 | uint x = gl_GlobalInvocationID.x % info.pitch; 41 | uint y = (gl_GlobalInvocationID.x / info.pitch) % info.height; 42 | uint z = gl_GlobalInvocationID.x / (info.pitch * info.height); 43 | 44 | uint col = bitfieldExtract(x, 0, 3); 45 | uint row = bitfieldExtract(y, 0, 3); 46 | uint idx_dw = lut_64bpp[(col + row * MICRO_TILE_DIM) >> 2u]; 47 | uint byte_ofs = gl_LocalInvocationID.x & 3u; 48 | uint idx = bitfieldExtract(idx_dw >> (8 * byte_ofs), 0, 8); 49 | 50 | uint slice_offs = z * info.c1 * MICRO_TILE_SZ; 51 | uint tile_row = y / MICRO_TILE_DIM; 52 | uint tile_column = x / MICRO_TILE_DIM; 53 | uint tile_offs = ((tile_row * info.c0) + tile_column) * MICRO_TILE_SZ; 54 | uint offs = slice_offs + tile_offs + ((idx * BPP) / 8u); 55 | 56 | uint p0 = in_data[(offs >> 2) + 0]; 57 | uint p1 = in_data[(offs >> 2) + 1]; 58 | out_data[2 * gl_GlobalInvocationID.x + 0] = p0; 59 | out_data[2 * gl_GlobalInvocationID.x + 1] = p1; 60 | } 61 | -------------------------------------------------------------------------------- /core/libraries/avplayer/avplayer_common.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "core/libraries/avplayer/avplayer.h" 13 | 14 | #define AVPLAYER_IS_ERROR(x) ((x) < 0) 15 | 16 | namespace Libraries::AvPlayer { 17 | 18 | enum class AvState { 19 | Initial, 20 | AddingSource, 21 | Ready, 22 | Play, 23 | Stop, 24 | EndOfFile, 25 | Pause, 26 | C0x08, 27 | Jump, 28 | TrickMode, 29 | C0x0B, 30 | Buffering, 31 | Starting, 32 | Error, 33 | }; 34 | 35 | enum class AvEventType { 36 | ChangeFlowState = 21, 37 | WarningId = 22, 38 | RevertState = 30, 39 | AddSource = 40, 40 | Error = 255, 41 | }; 42 | 43 | union AvPlayerEventData { 44 | u32 num_frames; // 20 45 | AvState state; // AvEventType::ChangeFlowState 46 | s32 error; // AvEventType::WarningId 47 | u32 attempt; // AvEventType::AddSource 48 | }; 49 | 50 | struct AvPlayerEvent { 51 | AvEventType event; 52 | AvPlayerEventData payload; 53 | }; 54 | 55 | template 56 | class AvPlayerQueue { 57 | public: 58 | size_t Size() { 59 | return m_queue.size(); 60 | } 61 | 62 | void Push(T&& value) { 63 | std::lock_guard guard(m_mutex); 64 | m_queue.emplace(std::forward(value)); 65 | } 66 | 67 | std::optional Pop() { 68 | if (Size() == 0) { 69 | return std::nullopt; 70 | } 71 | std::lock_guard guard(m_mutex); 72 | auto result = std::move(m_queue.front()); 73 | m_queue.pop(); 74 | return result; 75 | } 76 | 77 | void Clear() { 78 | std::lock_guard guard(m_mutex); 79 | m_queue = {}; 80 | } 81 | 82 | private: 83 | std::mutex m_mutex{}; 84 | std::queue m_queue{}; 85 | }; 86 | 87 | SceAvPlayerSourceType GetSourceType(std::string_view path); 88 | 89 | } // namespace Libraries::AvPlayer 90 | -------------------------------------------------------------------------------- /core/devices/base_device.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/types.h" 8 | #include "common/va_ctx.h" 9 | 10 | namespace Libraries::Kernel { 11 | struct OrbisKernelStat; 12 | struct SceKernelIovec; 13 | } // namespace Libraries::Kernel 14 | 15 | namespace Core::Devices { 16 | 17 | class BaseDevice { 18 | public: 19 | explicit BaseDevice(); 20 | 21 | virtual ~BaseDevice() = 0; 22 | 23 | virtual int ioctl(u64 cmd, Common::VaCtx* args) { 24 | return ORBIS_KERNEL_ERROR_ENOTTY; 25 | } 26 | 27 | virtual s64 write(const void* buf, size_t nbytes) { 28 | return ORBIS_KERNEL_ERROR_EBADF; 29 | } 30 | 31 | virtual size_t readv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) { 32 | return ORBIS_KERNEL_ERROR_EBADF; 33 | } 34 | 35 | virtual size_t writev(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt) { 36 | return ORBIS_KERNEL_ERROR_EBADF; 37 | } 38 | 39 | virtual s64 preadv(const Libraries::Kernel::SceKernelIovec* iov, int iovcnt, u64 offset) { 40 | return ORBIS_KERNEL_ERROR_EBADF; 41 | } 42 | 43 | virtual s64 lseek(s64 offset, int whence) { 44 | return ORBIS_KERNEL_ERROR_EBADF; 45 | } 46 | 47 | virtual s64 read(void* buf, size_t nbytes) { 48 | return ORBIS_KERNEL_ERROR_EBADF; 49 | } 50 | 51 | virtual int fstat(Libraries::Kernel::OrbisKernelStat* sb) { 52 | return ORBIS_KERNEL_ERROR_EBADF; 53 | } 54 | 55 | virtual s32 fsync() { 56 | return ORBIS_KERNEL_ERROR_EBADF; 57 | } 58 | 59 | virtual int ftruncate(s64 length) { 60 | return ORBIS_KERNEL_ERROR_EBADF; 61 | } 62 | 63 | virtual int getdents(void* buf, u32 nbytes, s64* basep) { 64 | return ORBIS_KERNEL_ERROR_EBADF; 65 | } 66 | 67 | virtual s64 pwrite(const void* buf, size_t nbytes, u64 offset) { 68 | return ORBIS_KERNEL_ERROR_EBADF; 69 | } 70 | }; 71 | 72 | } // namespace Core::Devices 73 | -------------------------------------------------------------------------------- /core/libraries/videoout/videoout_error.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include "core/libraries/error_codes.h" 7 | 8 | // VideoOut library 9 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; 10 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; 11 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PIXEL_FORMAT = 0x80290003; 12 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_PITCH = 0x80290004; 13 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_RESOLUTION = 0x80290005; 14 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_FLIP_MODE = 0x80290006; 15 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_TILING_MODE = 0x80290007; 16 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_ASPECT_RATIO = 0x80290008; 17 | constexpr int ORBIS_VIDEO_OUT_ERROR_RESOURCE_BUSY = 0x80290009; 18 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_INDEX = 0x8029000A; 19 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_HANDLE = 0x8029000B; 20 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT_QUEUE = 0x8029000C; 21 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_EVENT = 0x8029000D; 22 | constexpr int ORBIS_VIDEO_OUT_ERROR_NO_EMPTY_SLOT = 0x8029000F; 23 | constexpr int ORBIS_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; 24 | constexpr int ORBIS_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; 25 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_MEMORY = 0x80290013; 26 | constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_NOT_PHYSICALLY_CONTIGUOUS = 0x80290014; 27 | constexpr int ORBIS_VIDEO_OUT_ERROR_MEMORY_INVALID_ALIGNMENT = 0x80290015; 28 | constexpr int ORBIS_VIDEO_OUT_ERROR_UNSUPPORTED_OUTPUT_MODE = 0x80290016; 29 | constexpr int ORBIS_VIDEO_OUT_ERROR_OVERFLOW = 0x80290017; 30 | constexpr int ORBIS_VIDEO_OUT_ERROR_NO_DEVICE = 0x80290018; 31 | constexpr int ORBIS_VIDEO_OUT_ERROR_UNAVAILABLE_OUTPUT_MODE = 0x80290019; 32 | constexpr int ORBIS_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; 33 | constexpr int ORBIS_VIDEO_OUT_ERROR_UNKNOWN = 0x802900FE; 34 | constexpr int ORBIS_VIDEO_OUT_ERROR_FATAL = 0x802900FF; 35 | constexpr int ORBIS_VIDEO_OUT_ERROR_ENOMEM = 0x8029100C; 36 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | project(pkgtool_minimal) 3 | 4 | # Usa C++23 per abilitare std::byteswap e altre feature moderne 5 | set(CMAKE_CXX_STANDARD 23) 6 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 7 | 8 | # Percorsi vcpkg (modifica se necessario) 9 | set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/vcpkg/scripts/buildsystems/vcpkg.cmake") 10 | set(VCPKG_TARGET_TRIPLET "x64-windows") 11 | set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/vcpkg/installed/x64-windows/share") 12 | set(ZLIB_DIR "${CMAKE_SOURCE_DIR}/vcpkg/installed/x64-windows/share/zlib") 13 | set(fmt_DIR "${CMAKE_SOURCE_DIR}/vcpkg/installed/x64-windows/share/fmt") 14 | set(cryptopp_DIR "${CMAKE_SOURCE_DIR}/vcpkg/installed/x64-windows/share/cryptopp") 15 | 16 | # Trova i pacchetti richiesti tramite vcpkg 17 | find_package(ZLIB REQUIRED) 18 | find_package(CryptoPP REQUIRED) 19 | find_package(fmt REQUIRED) 20 | 21 | add_executable(pkgtool 22 | main.cpp 23 | core/file_format/pkg.cpp 24 | core/file_format/trp.cpp 25 | core/file_format/psf.cpp 26 | core/file_format/rif_generator.cpp 27 | core/crypto/crypto.cpp 28 | core/file_sys/file.cpp 29 | core/file_sys/fs.cpp 30 | common/io_file.cpp 31 | common/path_util.cpp 32 | common/error.cpp 33 | common/assert.cpp 34 | common/string_util.cpp 35 | core/file_format/entry_name.cpp 36 | common/ntapi_stub.cpp 37 | common/io_file_stub.cpp 38 | common/config.cpp 39 | common/logging/backend.cpp 40 | common/logging/filter.cpp 41 | common/logging/text_formatter.cpp 42 | common/thread.cpp 43 | core/devices/logger.cpp 44 | core/devices/base_device.cpp 45 | ) 46 | 47 | # Includi tutte le directory necessarie 48 | # (aggiungi altre se servono per gli header) 49 | target_include_directories(pkgtool PRIVATE 50 | ${CMAKE_SOURCE_DIR} 51 | ${CMAKE_SOURCE_DIR}/core 52 | ${CMAKE_SOURCE_DIR}/core/file_format 53 | ${CMAKE_SOURCE_DIR}/core/crypto 54 | ${CMAKE_SOURCE_DIR}/core/file_sys 55 | ${CMAKE_SOURCE_DIR}/common 56 | ) 57 | 58 | # Link alle librerie tramite vcpkg 59 | # (usa i target moderni) 60 | target_link_libraries(pkgtool PRIVATE ZLIB::ZLIB fmt::fmt cryptopp::cryptopp) -------------------------------------------------------------------------------- /common/rdtsc.cpp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #include 5 | #include "common/rdtsc.h" 6 | #include "common/uint128.h" 7 | 8 | #ifdef _WIN64 9 | #include 10 | #endif 11 | 12 | namespace Common { 13 | 14 | static constexpr size_t SecondToNanoseconds = 1000000000ULL; 15 | 16 | template 17 | static u64 RoundToNearest(u64 value) { 18 | const auto mod = value % Nearest; 19 | return mod >= (Nearest / 2) ? (value - mod + Nearest) : (value - mod); 20 | } 21 | 22 | static u64 GetTimeNs() { 23 | #ifdef _WIN64 24 | // GetSystemTimePreciseAsFileTime returns the file time in 100ns units. 25 | static constexpr u64 Multiplier = 100; 26 | // Convert Windows epoch to Unix epoch. 27 | static constexpr u64 WindowsEpochToUnixEpoch = 0x19DB1DED53E8000LL; 28 | FILETIME filetime; 29 | GetSystemTimePreciseAsFileTime(&filetime); 30 | return Multiplier * ((static_cast(filetime.dwHighDateTime) << 32) + 31 | static_cast(filetime.dwLowDateTime) - WindowsEpochToUnixEpoch); 32 | #elif defined(__APPLE__) 33 | return clock_gettime_nsec_np(CLOCK_REALTIME); 34 | #else 35 | timespec ts; 36 | clock_gettime(CLOCK_REALTIME, &ts); 37 | return ts.tv_sec * SecondToNanoseconds + ts.tv_nsec; 38 | #endif 39 | } 40 | 41 | u64 EstimateRDTSCFrequency() { 42 | // Discard the first result measuring the rdtsc. 43 | FencedRDTSC(); 44 | std::this_thread::sleep_for(std::chrono::milliseconds{1}); 45 | FencedRDTSC(); 46 | 47 | // Get the current time. 48 | const auto start_time = GetTimeNs(); 49 | const u64 tsc_start = FencedRDTSC(); 50 | // Wait for 100 milliseconds. 51 | std::this_thread::sleep_for(std::chrono::milliseconds{100}); 52 | const auto end_time = GetTimeNs(); 53 | const u64 tsc_end = FencedRDTSC(); 54 | // Calculate differences. 55 | const u64 tsc_diff = tsc_end - tsc_start; 56 | const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, end_time - start_time); 57 | return RoundToNearest<100'000>(tsc_freq); 58 | } 59 | 60 | } // namespace Common 61 | -------------------------------------------------------------------------------- /core/libraries/kernel/threads.h: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #pragma once 5 | 6 | #include 7 | #include "common/polyfill_thread.h" 8 | #include "core/libraries/kernel/threads/pthread.h" 9 | 10 | namespace Core::Loader { 11 | class SymbolsResolver; 12 | } 13 | 14 | namespace Libraries::Kernel { 15 | 16 | int PS4_SYSV_ABI posix_pthread_attr_init(PthreadAttrT* attr); 17 | 18 | int PS4_SYSV_ABI posix_pthread_attr_destroy(PthreadAttrT* attr); 19 | 20 | int PS4_SYSV_ABI posix_pthread_create(PthreadT* thread, const PthreadAttrT* attr, 21 | PthreadEntryFunc start_routine, void* arg); 22 | 23 | int PS4_SYSV_ABI posix_pthread_join(PthreadT pthread, void** thread_return); 24 | 25 | void RegisterThreads(Core::Loader::SymbolsResolver* sym); 26 | 27 | class Thread { 28 | public: 29 | explicit Thread() = default; 30 | ~Thread() { 31 | Stop(); 32 | } 33 | 34 | void Run(std::function&& func) { 35 | this->func = std::move(func); 36 | PthreadAttrT attr{}; 37 | posix_pthread_attr_init(&attr); 38 | posix_pthread_create(&thread, &attr, RunWrapper, this); 39 | posix_pthread_attr_destroy(&attr); 40 | } 41 | 42 | void Join() { 43 | if (thread) { 44 | posix_pthread_join(thread, nullptr); 45 | thread = nullptr; 46 | } 47 | } 48 | 49 | bool Joinable() const { 50 | return thread != nullptr; 51 | } 52 | 53 | void Stop() { 54 | if (Joinable()) { 55 | stop.request_stop(); 56 | Join(); 57 | } 58 | thread = nullptr; 59 | func = nullptr; 60 | stop = std::stop_source{}; 61 | } 62 | 63 | static void* PS4_SYSV_ABI RunWrapper(void* arg) { 64 | Thread* thr = (Thread*)arg; 65 | thr->func(thr->stop.get_token()); 66 | return nullptr; 67 | } 68 | 69 | private: 70 | PthreadT thread{}; 71 | std::function func; 72 | std::stop_source stop; 73 | }; 74 | 75 | } // namespace Libraries::Kernel 76 | -------------------------------------------------------------------------------- /video_core/host_shaders/detilers/micro_16bpp.comp: -------------------------------------------------------------------------------- 1 | // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project 2 | // SPDX-License-Identifier: GPL-2.0-or-later 3 | 4 | #version 450 5 | 6 | // NOTE: Current subgroup utilization is suboptimal on most GPUs, so 7 | // it will be nice to process two tiles at once here. 8 | layout (local_size_x = 32, local_size_y = 1, local_size_z = 1) in; 9 | 10 | layout(std430, binding = 0) buffer input_buf { 11 | uint in_data[]; 12 | }; 13 | layout(std430, binding = 1) buffer output_buf { 14 | uint out_data[]; 15 | }; 16 | 17 | layout(push_constant) uniform image_info { 18 | uint num_levels; 19 | uint pitch; 20 | uint height; 21 | uint sizes[14]; 22 | } info; 23 | 24 | #define MICRO_TILE_DIM 8 25 | #define TEXELS_PER_ELEMENT 2 26 | 27 | // Inverse morton LUT, small enough to fit into K$ 28 | const uint rmort[16] = { 29 | 0x11011000, 0x31213020, 30 | 0x13031202, 0x33233222, 31 | 0x51415040, 0x71617060, 32 | 0x53435242, 0x73637262, 33 | 34 | 0x15051404, 0x35253424, 35 | 0x17071606, 0x37273626, 36 | 0x55455444, 0x75657464, 37 | 0x57475646, 0x77677666, 38 | }; 39 | 40 | void main() { 41 | uint src_tx = in_data[gl_GlobalInvocationID.x]; 42 | uint p[TEXELS_PER_ELEMENT] = { 43 | (src_tx >> 16) & 0xffff, 44 | src_tx & 0xffff 45 | }; 46 | 47 | uint bit_ofs = 8 * TEXELS_PER_ELEMENT * (gl_LocalInvocationID.x % 4); 48 | uint packed_pos = rmort[gl_LocalInvocationID.x >> 1] >> bit_ofs; 49 | uint col = bitfieldExtract(packed_pos, 4, 4); 50 | uint row = bitfieldExtract(packed_pos, 0, 4); 51 | 52 | uint mip = 0u; 53 | for (int m = 0; m < info.num_levels; ++m) { 54 | mip += (gl_GlobalInvocationID.x * 4) >= info.sizes[m] ? 1 : 0; 55 | } 56 | uint tiles_per_pitch = max(((info.pitch >> mip) / 8u), 1u); 57 | uint target_tile_x = gl_WorkGroupID.x % tiles_per_pitch; 58 | uint target_tile_y = gl_WorkGroupID.x / tiles_per_pitch; 59 | uint dw_ofs_x = target_tile_x * 8 + col; 60 | uint dw_ofs_y = (target_tile_y * tiles_per_pitch * 64) + row * tiles_per_pitch * 8; 61 | out_data[(dw_ofs_x + dw_ofs_y) / 2] = src_tx; 62 | } 63 | --------------------------------------------------------------------------------