From d2127b38deace732f0c41b6cc1881e21f4ed268b Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Tue, 28 Jan 2025 00:12:48 -0800 Subject: [PATCH 01/15] vk_rasterizer: Keep viewport depth offset even without native depth clip control. (#2257) --- src/video_core/renderer_vulkan/vk_rasterizer.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index 7a0652ed7..7c77f2519 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp @@ -1155,10 +1155,7 @@ void Rasterizer::UpdateViewportScissorState(const GraphicsPipeline& pipeline) { const auto& vp_ctl = regs.viewport_control; const float reduce_z = - instance.IsDepthClipControlSupported() && - regs.clipper_control.clip_space == AmdGpu::Liverpool::ClipSpace::MinusWToW - ? 1.0f - : 0.0f; + regs.clipper_control.clip_space == AmdGpu::Liverpool::ClipSpace::MinusWToW ? 1.0f : 0.0f; if (regs.polygon_control.enable_window_offset) { LOG_ERROR(Render_Vulkan, From 8379922f8ab1209d25b4cbec14303401aa75eec9 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Tue, 28 Jan 2025 02:31:26 -0800 Subject: [PATCH 02/15] hotfix: Reduce requested videodec memory block sizes. This really needs a more accurate implementation, but for the stub lowering the value helps games that run out of memory space if it is too large. --- src/core/libraries/videodec/videodec.cpp | 2 +- src/core/libraries/videodec/videodec2.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/videodec/videodec.cpp b/src/core/libraries/videodec/videodec.cpp index 6c9a9b8c0..79001e76f 100644 --- a/src/core/libraries/videodec/videodec.cpp +++ b/src/core/libraries/videodec/videodec.cpp @@ -9,7 +9,7 @@ namespace Libraries::Videodec { -static constexpr u64 kMinimumMemorySize = 32_MB; ///> Fake minimum memory size for querying +static constexpr u64 kMinimumMemorySize = 8_MB; ///> Fake minimum memory size for querying int PS4_SYSV_ABI sceVideodecCreateDecoder(const OrbisVideodecConfigInfo* pCfgInfoIn, const OrbisVideodecResourceInfo* pRsrcInfoIn, diff --git a/src/core/libraries/videodec/videodec2.cpp b/src/core/libraries/videodec/videodec2.cpp index 07f7a274b..be0db4ea3 100644 --- a/src/core/libraries/videodec/videodec2.cpp +++ b/src/core/libraries/videodec/videodec2.cpp @@ -10,7 +10,7 @@ namespace Libraries::Vdec2 { -static constexpr u64 kMinimumMemorySize = 32_MB; ///> Fake minimum memory size for querying +static constexpr u64 kMinimumMemorySize = 8_MB; ///> Fake minimum memory size for querying s32 PS4_SYSV_ABI sceVideodec2QueryComputeMemoryInfo(OrbisVideodec2ComputeMemoryInfo* computeMemInfo) { From 4b93b8b57460c83421d0d859e243dd05a864bdc1 Mon Sep 17 00:00:00 2001 From: Martin <67326368+Martini-141@users.noreply.github.com> Date: Tue, 28 Jan 2025 17:47:00 +0100 Subject: [PATCH 03/15] add missing translations and other corrections nb (#2253) --- src/qt_gui/translations/nb.ts | 42 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/qt_gui/translations/nb.ts b/src/qt_gui/translations/nb.ts index d6d4090df..0b7d2699a 100644 --- a/src/qt_gui/translations/nb.ts +++ b/src/qt_gui/translations/nb.ts @@ -98,7 +98,7 @@ Open Folder... - Åpne mappen... + Åpne mappe... Open Game Folder @@ -126,7 +126,7 @@ Copy All - Kopier alle + Kopier alt Delete... @@ -146,19 +146,19 @@ Compatibility... - Compatibility... + Kompatibilitet... Update database - Update database + Oppdater database View report - View report + Vis rapport Submit a report - Submit a report + Send inn en rapport Shortcut creation @@ -574,11 +574,11 @@ Trophy Key - Trophy Key + Trofénøkkel Trophy - Trophy + Trofé Logger @@ -658,7 +658,7 @@ Enable Shaders Dumping - Aktiver dumping av skyggelegger + Aktiver skyggeleggerdumping Enable NULL GPU @@ -666,7 +666,7 @@ Paths - Stier + Mapper Game Folders @@ -686,7 +686,7 @@ Enable Debug Dumping - Aktiver dumping av feilretting + Aktiver feilrettingsdumping Enable Vulkan Validation Layers @@ -718,7 +718,7 @@ GUI Settings - GUI-innstillinger + Grensesnitt-innstillinger Disable Trophy Pop-ups @@ -730,7 +730,7 @@ Update Compatibility Database On Startup - Oppdater kompatibilitets-database ved oppstart + Oppdater database ved oppstart Game Compatibility @@ -750,7 +750,7 @@ Audio Backend - Audio Backend + Lydsystem Save @@ -806,7 +806,7 @@ TrophyKey - Trophy Key:\nKey used to decrypt trophies. Must be obtained from your jailbroken console.\nMust contain only hex characters. + Trofénøkkel:\nNøkkel brukes til å dekryptere trofeer. Må hentes fra din konsoll (jailbroken).\nMå bare inneholde sekskantede tegn. logTypeGroupBox @@ -846,7 +846,7 @@ checkCompatibilityOnStartupCheckBox - Oppdater kompatibilitets-data ved oppstart:\nOppdaterer kompatibilitets-databasen automatisk når shadPS4 starter. + Oppdater database ved oppstart:\nOppdaterer kompatibilitets-databasen automatisk når shadPS4 starter. updateCompatibilityButton @@ -894,7 +894,7 @@ dumpShadersCheckBox - Aktiver dumping av skyggelegger:\nFor teknisk feilsøking lagrer skyggeleggerne fra spillet i en mappe mens de gjengis. + Aktiver skyggeleggerdumping:\nFor teknisk feilsøking lagrer skyggeleggerne fra spillet i en mappe mens de gjengis. nullGpuCheckBox @@ -914,7 +914,7 @@ debugDump - Aktiver dumping av feilsøking:\nLagrer import- og eksport-symbolene og filoverskriftsinformasjonen til det nåværende kjørende PS4-programmet i en katalog. + Aktiver feilrettingsdumping:\nLagrer import- og eksport-symbolene og filoverskriftsinformasjonen til det nåværende kjørende PS4-programmet i en katalog. vkValidationCheckBox @@ -1188,7 +1188,7 @@ Path - Sti + Adresse Play Time @@ -1232,7 +1232,7 @@ Game can be completed with playable performance and no major glitches - Spillet kan fullføres med spillbar ytelse og ingen store feil + Spillet kan fullføres med spillbar ytelse og uten store feil @@ -1361,4 +1361,4 @@ TB - \ No newline at end of file + From 2cdd873681dd3b03d0752bda5c84412f06f4f0b8 Mon Sep 17 00:00:00 2001 From: slick-daddy <129640104+slick-daddy@users.noreply.github.com> Date: Tue, 28 Jan 2025 19:47:12 +0300 Subject: [PATCH 04/15] Update tr_TR.ts (#2255) --- src/qt_gui/translations/tr_TR.ts | 54 ++++++++++++++++---------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/src/qt_gui/translations/tr_TR.ts b/src/qt_gui/translations/tr_TR.ts index 6436278de..a2368bfee 100644 --- a/src/qt_gui/translations/tr_TR.ts +++ b/src/qt_gui/translations/tr_TR.ts @@ -546,7 +546,7 @@ Enable Separate Update Folder - Enable Separate Update Folder + Ayrı Güncelleme Klasörünü Etkinleştir Default tab when opening settings @@ -554,7 +554,7 @@ Show Game Size In List - Göster oyun boyutunu listede + Oyun Boyutunu Listede Göster Show Splash @@ -574,11 +574,11 @@ Trophy Key - Trophy Key + Kupa Anahtarı Trophy - Trophy + Kupa Logger @@ -722,7 +722,7 @@ Disable Trophy Pop-ups - Disable Trophy Pop-ups + Kupa Açılır Pencerelerini Devre Dışı Bırak Play title music @@ -730,23 +730,23 @@ Update Compatibility Database On Startup - Update Compatibility Database On Startup + Başlangıçta Uyumluluk Veritabanını Güncelle Game Compatibility - Game Compatibility + Oyun Uyumluluğu Display Compatibility Data - Display Compatibility Data + Uyumluluk Verilerini Göster Update Compatibility Database - Update Compatibility Database + Uyumluluk Veritabanını Güncelle Volume - Ses seviyesi + Ses Seviyesi Audio Backend @@ -1105,11 +1105,11 @@ The game is in version: %1 - Oyun sürümde: %1 + Oyun sürümü: %1 The downloaded patch only works on version: %1 - İndirilen yamanın sadece sürümde çalışıyor: %1 + İndirilen yama sadece şu sürümde çalışıyor: %1 You may need to update your game. @@ -1168,7 +1168,7 @@ Compatibility - Compatibility + Uyumluluk Region @@ -1196,35 +1196,35 @@ Never Played - Never Played + Hiç Oynanmadı h - h + sa m - m + dk s - s + sn Compatibility is untested - Compatibility is untested + Uyumluluk test edilmemiş Game does not initialize properly / crashes the emulator - Game does not initialize properly / crashes the emulator + Oyun düzgün bir şekilde başlatılamıyor / emülatörü çökertiyor Game boots, but only displays a blank screen - Game boots, but only displays a blank screen + Oyun başlatılabiliyor ancak yalnızca boş bir ekran gösteriyor Game displays an image but does not go past the menu - Game displays an image but does not go past the menu + Oyun bir resim gösteriyor ancak menüleri geçemiyor Game has game-breaking glitches or unplayable performance @@ -1232,7 +1232,7 @@ Game can be completed with playable performance and no major glitches - Game can be completed with playable performance and no major glitches + Oyun, oynanabilir performansla tamamlanabilir ve büyük aksaklık yok @@ -1267,7 +1267,7 @@ Your version is already up to date! - Versiyonunuz zaten güncel! + Sürümünüz zaten güncel! Update Available @@ -1279,11 +1279,11 @@ Current Version - Mevcut Versiyon + Mevcut Sürüm Latest Version - Son Versiyon + Son Sürüm Do you want to update? @@ -1335,7 +1335,7 @@ Failed to create the update script file - Güncelleme betiği dosyası oluşturulamadı + Güncelleme komut dosyası oluşturulamadı @@ -1361,4 +1361,4 @@ TB - \ No newline at end of file + From a78f8afe58a995cecdb4eb1f1e6d6e58320444f6 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Tue, 28 Jan 2025 08:48:19 -0800 Subject: [PATCH 05/15] libraries: Implement libSceZlib. (#2256) * libraries: add zlib hle skeleton/stub * libraries: Implement libSceZlib. * zlib: Make variables static. --------- Co-authored-by: Nenkai --- CMakeLists.txt | 6 + src/common/logging/filter.cpp | 1 + src/common/logging/types.h | 1 + src/core/libraries/libs.cpp | 2 + src/core/libraries/zlib/zlib.cpp | 183 +++++++++++++++++++++++++++ src/core/libraries/zlib/zlib_error.h | 18 +++ src/core/libraries/zlib/zlib_sce.h | 21 +++ 7 files changed, 232 insertions(+) create mode 100644 src/core/libraries/zlib/zlib.cpp create mode 100644 src/core/libraries/zlib/zlib_error.h create mode 100644 src/core/libraries/zlib/zlib_sce.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c9dad307..78e3c7997 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -440,6 +440,11 @@ set(NP_LIBS src/core/libraries/np_common/np_common.cpp src/core/libraries/np_party/np_party.h ) +set(ZLIB_LIB src/core/libraries/zlib/zlib.cpp + src/core/libraries/zlib/zlib_sce.h + src/core/libraries/zlib/zlib_error.h +) + set(MISC_LIBS src/core/libraries/screenshot/screenshot.cpp src/core/libraries/screenshot/screenshot.h src/core/libraries/move/move.cpp @@ -612,6 +617,7 @@ set(CORE src/core/aerolib/stubs.cpp ${PLAYGO_LIB} ${RANDOM_LIB} ${USBD_LIB} + ${ZLIB_LIB} ${MISC_LIBS} ${IME_LIB} ${FIBER_LIB} diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index f1d3a9499..dd708c528 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp @@ -133,6 +133,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { SUB(Lib, Mouse) \ SUB(Lib, WebBrowserDialog) \ SUB(Lib, NpParty) \ + SUB(Lib, Zlib) \ CLS(Frontend) \ CLS(Render) \ SUB(Render, Vulkan) \ diff --git a/src/common/logging/types.h b/src/common/logging/types.h index d5530312c..54f8cdd0b 100644 --- a/src/common/logging/types.h +++ b/src/common/logging/types.h @@ -100,6 +100,7 @@ enum class Class : u8 { Lib_Mouse, ///< The LibSceMouse implementation Lib_WebBrowserDialog, ///< The LibSceWebBrowserDialog implementation Lib_NpParty, ///< The LibSceNpParty implementation + Lib_Zlib, ///< The LibSceZlib implementation. Frontend, ///< Emulator UI Render, ///< Video Core Render_Vulkan, ///< Vulkan backend diff --git a/src/core/libraries/libs.cpp b/src/core/libraries/libs.cpp index e09de1cee..8cf286d13 100644 --- a/src/core/libraries/libs.cpp +++ b/src/core/libraries/libs.cpp @@ -54,6 +54,7 @@ #include "core/libraries/videodec/videodec2.h" #include "core/libraries/videoout/video_out.h" #include "core/libraries/web_browser_dialog/webbrowserdialog.h" +#include "core/libraries/zlib/zlib_sce.h" #include "fiber/fiber.h" #include "jpeg/jpegenc.h" @@ -111,6 +112,7 @@ void InitHLELibs(Core::Loader::SymbolsResolver* sym) { Libraries::Mouse::RegisterlibSceMouse(sym); Libraries::WebBrowserDialog::RegisterlibSceWebBrowserDialog(sym); Libraries::NpParty::RegisterlibSceNpParty(sym); + Libraries::Zlib::RegisterlibSceZlib(sym); } } // namespace Libraries diff --git a/src/core/libraries/zlib/zlib.cpp b/src/core/libraries/zlib/zlib.cpp new file mode 100644 index 000000000..899cb5bf6 --- /dev/null +++ b/src/core/libraries/zlib/zlib.cpp @@ -0,0 +1,183 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include +#include +#include +#include +#include +#include + +#include "common/logging/log.h" +#include "common/thread.h" +#include "core/libraries/kernel/threads.h" +#include "core/libraries/libs.h" +#include "core/libraries/zlib/zlib_error.h" +#include "core/libraries/zlib/zlib_sce.h" + +namespace Libraries::Zlib { + +struct InflateTask { + u64 request_id; + const void* src; + u32 src_length; + void* dst; + u32 dst_length; +}; + +struct InflateResult { + u32 length; + s32 status; +}; + +static Kernel::Thread task_thread; + +static std::mutex mutex; +static std::queue task_queue; +static std::condition_variable_any task_queue_cv; +static std::queue done_queue; +static std::condition_variable_any done_queue_cv; +static std::unordered_map results; +static u64 next_request_id; + +void ZlibTaskThread(const std::stop_token& stop) { + Common::SetCurrentThreadName("shadPS4:ZlibTaskThread"); + + while (!stop.stop_requested()) { + InflateTask task; + { + // Lock and pop from the task queue, unless stop has been requested. + std::unique_lock lock(mutex); + if (!task_queue_cv.wait(lock, stop, [&] { return !task_queue.empty(); })) { + break; + } + task = task_queue.back(); + task_queue.pop(); + } + + uLongf decompressed_length = task.dst_length; + const auto ret = uncompress(static_cast(task.dst), &decompressed_length, + static_cast(task.src), task.src_length); + + { + // Lock, insert the new result, and push the finished request ID to the done queue. + std::unique_lock lock(mutex); + results[task.request_id] = InflateResult{ + .length = static_cast(decompressed_length), + .status = ret == Z_BUF_ERROR ? ORBIS_ZLIB_ERROR_NOSPACE + : ret == Z_OK ? ORBIS_OK + : ORBIS_ZLIB_ERROR_FATAL, + }; + done_queue.push(task.request_id); + } + done_queue_cv.notify_one(); + } +} + +s32 PS4_SYSV_ABI sceZlibInitialize(const void* buffer, u32 length) { + LOG_INFO(Lib_Zlib, "called"); + if (task_thread.Joinable()) { + return ORBIS_ZLIB_ERROR_ALREADY_INITIALIZED; + } + + // Initialize with empty task data + task_queue = std::queue(); + done_queue = std::queue(); + results.clear(); + next_request_id = 1; + + task_thread.Run([](const std::stop_token& stop) { ZlibTaskThread(stop); }); + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceZlibInflate(const void* src, u32 src_len, void* dst, u32 dst_len, + u64* request_id) { + LOG_DEBUG(Lib_Zlib, "(STUBBED) called"); + if (!task_thread.Joinable()) { + return ORBIS_ZLIB_ERROR_NOT_INITIALIZED; + } + if (!src || !src_len || !dst || !dst_len || !request_id || dst_len > 64_KB || + dst_len % 2_KB != 0) { + return ORBIS_ZLIB_ERROR_INVALID; + } + + { + std::unique_lock lock(mutex); + *request_id = next_request_id++; + task_queue.emplace(InflateTask{ + .request_id = *request_id, + .src = src, + .src_length = src_len, + .dst = dst, + .dst_length = dst_len, + }); + task_queue_cv.notify_one(); + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceZlibWaitForDone(u64* request_id, const u32* timeout) { + LOG_DEBUG(Lib_Zlib, "(STUBBED) called"); + if (!task_thread.Joinable()) { + return ORBIS_ZLIB_ERROR_NOT_INITIALIZED; + } + if (!request_id) { + return ORBIS_ZLIB_ERROR_INVALID; + } + + { + // Pop from the done queue, unless the timeout is reached. + std::unique_lock lock(mutex); + const auto pred = [] { return !done_queue.empty(); }; + if (timeout) { + if (!done_queue_cv.wait_for(lock, std::chrono::milliseconds(*timeout), pred)) { + return ORBIS_ZLIB_ERROR_TIMEDOUT; + } + } else { + done_queue_cv.wait(lock, pred); + } + *request_id = done_queue.back(); + done_queue.pop(); + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceZlibGetResult(const u64 request_id, u32* dst_length, s32* status) { + LOG_DEBUG(Lib_Zlib, "(STUBBED) called"); + if (!task_thread.Joinable()) { + return ORBIS_ZLIB_ERROR_NOT_INITIALIZED; + } + if (!dst_length || !status) { + return ORBIS_ZLIB_ERROR_INVALID; + } + + { + std::unique_lock lock(mutex); + if (!results.contains(request_id)) { + return ORBIS_ZLIB_ERROR_NOT_FOUND; + } + const auto result = results[request_id]; + *dst_length = result.length; + *status = result.status; + } + return ORBIS_OK; +} + +s32 PS4_SYSV_ABI sceZlibFinalize() { + LOG_INFO(Lib_Zlib, "called"); + if (!task_thread.Joinable()) { + return ORBIS_ZLIB_ERROR_NOT_INITIALIZED; + } + task_thread.Stop(); + return ORBIS_OK; +} + +void RegisterlibSceZlib(Core::Loader::SymbolsResolver* sym) { + LIB_FUNCTION("m1YErdIXCp4", "libSceZlib", 1, "libSceZlib", 1, 1, sceZlibInitialize); + LIB_FUNCTION("6na+Sa-B83w", "libSceZlib", 1, "libSceZlib", 1, 1, sceZlibFinalize); + LIB_FUNCTION("TLar1HULv1Q", "libSceZlib", 1, "libSceZlib", 1, 1, sceZlibInflate); + LIB_FUNCTION("uB8VlDD4e0s", "libSceZlib", 1, "libSceZlib", 1, 1, sceZlibWaitForDone); + LIB_FUNCTION("2eDcGHC0YaM", "libSceZlib", 1, "libSceZlib", 1, 1, sceZlibGetResult); +}; + +} // namespace Libraries::Zlib diff --git a/src/core/libraries/zlib/zlib_error.h b/src/core/libraries/zlib/zlib_error.h new file mode 100644 index 000000000..59574f0b2 --- /dev/null +++ b/src/core/libraries/zlib/zlib_error.h @@ -0,0 +1,18 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/libraries/error_codes.h" + +// Zlib library +constexpr int ORBIS_ZLIB_ERROR_NOT_FOUND = 0x81120002; +constexpr int ORBIS_ZLIB_ERROR_BUSY = 0x8112000B; +constexpr int ORBIS_ZLIB_ERROR_FAULT = 0x8112000E; +constexpr int ORBIS_ZLIB_ERROR_INVALID = 0x81120016; +constexpr int ORBIS_ZLIB_ERROR_NOSPACE = 0x8112001C; +constexpr int ORBIS_ZLIB_ERROR_NOT_SUPPORTED = 0x81120025; +constexpr int ORBIS_ZLIB_ERROR_TIMEDOUT = 0x81120027; +constexpr int ORBIS_ZLIB_ERROR_NOT_INITIALIZED = 0x81120032; +constexpr int ORBIS_ZLIB_ERROR_ALREADY_INITIALIZED = 0x81120033; +constexpr int ORBIS_ZLIB_ERROR_FATAL = 0x811200FF; diff --git a/src/core/libraries/zlib/zlib_sce.h b/src/core/libraries/zlib/zlib_sce.h new file mode 100644 index 000000000..6f8cf9468 --- /dev/null +++ b/src/core/libraries/zlib/zlib_sce.h @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/types.h" + +namespace Core::Loader { +class SymbolsResolver; +} +namespace Libraries::Zlib { + +s32 PS4_SYSV_ABI sceZlibInitialize(const void* buffer, u32 length); +s32 PS4_SYSV_ABI sceZlibInflate(const void* src, u32 src_len, void* dst, u32 dst_len, + u64* request_id); +s32 PS4_SYSV_ABI sceZlibWaitForDone(u64* request_id, const u32* timeout); +s32 PS4_SYSV_ABI sceZlibGetResult(u64 request_id, u32* dst_length, s32* status); +s32 PS4_SYSV_ABI sceZlibFinalize(); + +void RegisterlibSceZlib(Core::Loader::SymbolsResolver* sym); +} // namespace Libraries::Zlib \ No newline at end of file From 0575853be18d8f0504482b4a5a407fb14a23d492 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Tue, 28 Jan 2025 17:56:05 -0800 Subject: [PATCH 06/15] externals: Update MoltenVK. (#2264) Adds support for VK_EXT_depth_clip_control --- externals/MoltenVK/MoltenVK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/MoltenVK/MoltenVK b/externals/MoltenVK/MoltenVK index 6fa077fb8..aba997657 160000 --- a/externals/MoltenVK/MoltenVK +++ b/externals/MoltenVK/MoltenVK @@ -1 +1 @@ -Subproject commit 6fa077fb8ed8dac4e4cd66b6b1ebd7b4d955a754 +Subproject commit aba997657b94d6de1794ebad36ce5634341252c7 From 78a0a755c5f2ff06c340ec0dc3431fc247aaa3e4 Mon Sep 17 00:00:00 2001 From: ElBread3 <92335081+ElBread3@users.noreply.github.com> Date: Tue, 28 Jan 2025 21:14:47 -0600 Subject: [PATCH 07/15] qt_gui: Some game install features and fixes (#2261) * open update folder + delete save folder + bulk install checkbox * delete pkg on install checkbox + use game icon for finish window --- src/qt_gui/gui_context_menus.h | 45 ++++++++++++++++++++++++++++--- src/qt_gui/install_dir_select.cpp | 24 ++++++++++++++--- src/qt_gui/install_dir_select.h | 12 +++++++++ src/qt_gui/main_window.cpp | 26 +++++++++++++++--- src/qt_gui/main_window.h | 4 +++ 5 files changed, 101 insertions(+), 10 deletions(-) diff --git a/src/qt_gui/gui_context_menus.h b/src/qt_gui/gui_context_menus.h index 72affeca7..bdc2aec0c 100644 --- a/src/qt_gui/gui_context_menus.h +++ b/src/qt_gui/gui_context_menus.h @@ -52,10 +52,12 @@ public: // "Open Folder..." submenu QMenu* openFolderMenu = new QMenu(tr("Open Folder..."), widget); QAction* openGameFolder = new QAction(tr("Open Game Folder"), widget); + QAction* openUpdateFolder = new QAction(tr("Open Update Folder"), widget); QAction* openSaveDataFolder = new QAction(tr("Open Save Data Folder"), widget); QAction* openLogFolder = new QAction(tr("Open Log Folder"), widget); openFolderMenu->addAction(openGameFolder); + openFolderMenu->addAction(openUpdateFolder); openFolderMenu->addAction(openSaveDataFolder); openFolderMenu->addAction(openLogFolder); @@ -87,10 +89,12 @@ public: QMenu* deleteMenu = new QMenu(tr("Delete..."), widget); QAction* deleteGame = new QAction(tr("Delete Game"), widget); QAction* deleteUpdate = new QAction(tr("Delete Update"), widget); + QAction* deleteSaveData = new QAction(tr("Delete Save Data"), widget); QAction* deleteDLC = new QAction(tr("Delete DLC"), widget); deleteMenu->addAction(deleteGame); deleteMenu->addAction(deleteUpdate); + deleteMenu->addAction(deleteSaveData); deleteMenu->addAction(deleteDLC); menu.addMenu(deleteMenu); @@ -122,6 +126,18 @@ public: QDesktopServices::openUrl(QUrl::fromLocalFile(folderPath)); } + if (selected == openUpdateFolder) { + QString open_update_path; + Common::FS::PathToQString(open_update_path, m_games[itemID].path); + open_update_path += "-UPDATE"; + if (!std::filesystem::exists(Common::FS::PathFromQString(open_update_path))) { + QMessageBox::critical(nullptr, tr("Error"), + QString(tr("This game has no update folder to open!"))); + } else { + QDesktopServices::openUrl(QUrl::fromLocalFile(open_update_path)); + } + } + if (selected == openSaveDataFolder) { QString userPath; Common::FS::PathToQString(userPath, @@ -143,7 +159,7 @@ public: PSF psf; std::filesystem::path game_folder_path = m_games[itemID].path; std::filesystem::path game_update_path = game_folder_path; - game_update_path += "UPDATE"; + game_update_path += "-UPDATE"; if (std::filesystem::exists(game_update_path)) { game_folder_path = game_update_path; } @@ -238,6 +254,11 @@ public: QString trophyPath, gameTrpPath; Common::FS::PathToQString(trophyPath, m_games[itemID].serial); Common::FS::PathToQString(gameTrpPath, m_games[itemID].path); + auto game_update_path = Common::FS::PathFromQString(gameTrpPath); + game_update_path += "-UPDATE"; + if (std::filesystem::exists(game_update_path)) { + Common::FS::PathToQString(gameTrpPath, game_update_path); + } TrophyViewer* trophyViewer = new TrophyViewer(trophyPath, gameTrpPath); trophyViewer->show(); connect(widget->parent(), &QWidget::destroyed, trophyViewer, @@ -335,14 +356,18 @@ public: clipboard->setText(combinedText); } - if (selected == deleteGame || selected == deleteUpdate || selected == deleteDLC) { + if (selected == deleteGame || selected == deleteUpdate || selected == deleteDLC || + selected == deleteSaveData) { bool error = false; - QString folder_path, game_update_path, dlc_path; + QString folder_path, game_update_path, dlc_path, save_data_path; Common::FS::PathToQString(folder_path, m_games[itemID].path); game_update_path = folder_path + "-UPDATE"; Common::FS::PathToQString( dlc_path, Config::getAddonInstallDir() / Common::FS::PathFromQString(folder_path).parent_path().filename()); + Common::FS::PathToQString(save_data_path, + Common::FS::GetUserPath(Common::FS::PathType::UserDir) / + "savedata/1" / m_games[itemID].serial); QString message_type = tr("Game"); if (selected == deleteUpdate) { @@ -363,6 +388,15 @@ public: folder_path = dlc_path; message_type = tr("DLC"); } + } else if (selected == deleteSaveData) { + if (!std::filesystem::exists(Common::FS::PathFromQString(save_data_path))) { + QMessageBox::critical(nullptr, tr("Error"), + QString(tr("This game has no save data to delete!"))); + error = true; + } else { + folder_path = save_data_path; + message_type = tr("Save Data"); + } } if (!error) { QString gameName = QString::fromStdString(m_games[itemID].name); @@ -374,7 +408,10 @@ public: QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { dir.removeRecursively(); - widget->removeRow(itemID); + if (selected == deleteGame) { + widget->removeRow(itemID); + m_games.removeAt(itemID); + } } } } diff --git a/src/qt_gui/install_dir_select.cpp b/src/qt_gui/install_dir_select.cpp index e0951b123..e90a10ee6 100644 --- a/src/qt_gui/install_dir_select.cpp +++ b/src/qt_gui/install_dir_select.cpp @@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include #include #include #include @@ -15,10 +16,11 @@ #include "install_dir_select.h" InstallDirSelect::InstallDirSelect() : selected_dir() { - selected_dir = Config::getGameInstallDirs().empty() ? "" : Config::getGameInstallDirs().front(); + auto install_dirs = Config::getGameInstallDirs(); + selected_dir = install_dirs.empty() ? "" : install_dirs.front(); - if (!Config::getGameInstallDirs().empty() && Config::getGameInstallDirs().size() == 1) { - reject(); + if (!install_dirs.empty() && install_dirs.size() == 1) { + accept(); } auto layout = new QVBoxLayout(this); @@ -53,6 +55,14 @@ QWidget* InstallDirSelect::SetupInstallDirList() { vlayout->addWidget(m_path_list); + auto checkbox = new QCheckBox(tr("Install All Queued to Selected Folder")); + connect(checkbox, &QCheckBox::toggled, this, &InstallDirSelect::setUseForAllQueued); + vlayout->addWidget(checkbox); + + auto checkbox2 = new QCheckBox(tr("Delete PKG File on Install")); + connect(checkbox2, &QCheckBox::toggled, this, &InstallDirSelect::setDeleteFileOnInstall); + vlayout->addWidget(checkbox2); + group->setLayout(vlayout); return group; } @@ -66,6 +76,14 @@ void InstallDirSelect::setSelectedDirectory(QListWidgetItem* item) { } } +void InstallDirSelect::setUseForAllQueued(bool enabled) { + use_for_all_queued = enabled; +} + +void InstallDirSelect::setDeleteFileOnInstall(bool enabled) { + delete_file_on_install = enabled; +} + QWidget* InstallDirSelect::SetupDialogActions() { auto actions = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); diff --git a/src/qt_gui/install_dir_select.h b/src/qt_gui/install_dir_select.h index e3e81575a..e11cbf381 100644 --- a/src/qt_gui/install_dir_select.h +++ b/src/qt_gui/install_dir_select.h @@ -22,9 +22,21 @@ public: return selected_dir; } + bool useForAllQueued() { + return use_for_all_queued; + } + + bool deleteFileOnInstall() { + return delete_file_on_install; + } + private: QWidget* SetupInstallDirList(); QWidget* SetupDialogActions(); void setSelectedDirectory(QListWidgetItem* item); + void setDeleteFileOnInstall(bool enabled); + void setUseForAllQueued(bool enabled); std::filesystem::path selected_dir; + bool delete_file_on_install = false; + bool use_for_all_queued = false; }; diff --git a/src/qt_gui/main_window.cpp b/src/qt_gui/main_window.cpp index 3ee392613..3678b3a82 100644 --- a/src/qt_gui/main_window.cpp +++ b/src/qt_gui/main_window.cpp @@ -725,9 +725,20 @@ void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int return; } auto category = psf.GetString("CATEGORY"); - InstallDirSelect ids; - ids.exec(); - auto game_install_dir = ids.getSelectedDirectory(); + + if (!use_for_all_queued || pkgNum == 1) { + InstallDirSelect ids; + const auto selected = ids.exec(); + if (selected == QDialog::Rejected) { + return; + } + + last_install_dir = ids.getSelectedDirectory(); + delete_file_on_install = ids.deleteFileOnInstall(); + use_for_all_queued = ids.useForAllQueued(); + } + std::filesystem::path game_install_dir = last_install_dir; + auto game_folder_path = game_install_dir / pkg.GetTitleID(); QString pkgType = QString::fromStdString(pkg.GetPkgFlags()); bool use_game_update = pkgType.contains("PATCH") && Config::getSeparateUpdateEnabled(); @@ -879,8 +890,14 @@ void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int if (pkgNum == nPkg) { QString path; Common::FS::PathToQString(path, game_install_dir); + QIcon windowIcon( + Common::FS::PathToUTF8String(game_folder_path / "sce_sys/icon0.png") + .c_str()); QMessageBox extractMsgBox(this); extractMsgBox.setWindowTitle(tr("Extraction Finished")); + if (!windowIcon.isNull()) { + extractMsgBox.setWindowIcon(windowIcon); + } extractMsgBox.setText( QString(tr("Game successfully installed at %1")).arg(path)); extractMsgBox.addButton(QMessageBox::Ok); @@ -894,6 +911,9 @@ void MainWindow::InstallDragDropPkg(std::filesystem::path file, int pkgNum, int }); extractMsgBox.exec(); } + if (delete_file_on_install) { + std::filesystem::remove(file); + } }); connect(&dialog, &QProgressDialog::canceled, [&]() { futureWatcher.cancel(); }); connect(&futureWatcher, &QFutureWatcher::progressValueChanged, &dialog, diff --git a/src/qt_gui/main_window.h b/src/qt_gui/main_window.h index f4163defa..5ac56e44c 100644 --- a/src/qt_gui/main_window.h +++ b/src/qt_gui/main_window.h @@ -123,4 +123,8 @@ protected: } void resizeEvent(QResizeEvent* event) override; + + std::filesystem::path last_install_dir = ""; + bool delete_file_on_install = false; + bool use_for_all_queued = false; }; From 9bad66b24d4082240d00849a3d342d4d4a7c52d3 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Wed, 29 Jan 2025 01:29:52 -0800 Subject: [PATCH 08/15] hotfix: Raise videodec memory back up to 16MB. Found a game that needs more, still should be low enough compared to before to fix some games. --- src/core/libraries/videodec/videodec.cpp | 2 +- src/core/libraries/videodec/videodec2.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/videodec/videodec.cpp b/src/core/libraries/videodec/videodec.cpp index 79001e76f..02ea61509 100644 --- a/src/core/libraries/videodec/videodec.cpp +++ b/src/core/libraries/videodec/videodec.cpp @@ -9,7 +9,7 @@ namespace Libraries::Videodec { -static constexpr u64 kMinimumMemorySize = 8_MB; ///> Fake minimum memory size for querying +static constexpr u64 kMinimumMemorySize = 16_MB; ///> Fake minimum memory size for querying int PS4_SYSV_ABI sceVideodecCreateDecoder(const OrbisVideodecConfigInfo* pCfgInfoIn, const OrbisVideodecResourceInfo* pRsrcInfoIn, diff --git a/src/core/libraries/videodec/videodec2.cpp b/src/core/libraries/videodec/videodec2.cpp index be0db4ea3..a7e520b41 100644 --- a/src/core/libraries/videodec/videodec2.cpp +++ b/src/core/libraries/videodec/videodec2.cpp @@ -10,7 +10,7 @@ namespace Libraries::Vdec2 { -static constexpr u64 kMinimumMemorySize = 8_MB; ///> Fake minimum memory size for querying +static constexpr u64 kMinimumMemorySize = 16_MB; ///> Fake minimum memory size for querying s32 PS4_SYSV_ABI sceVideodec2QueryComputeMemoryInfo(OrbisVideodec2ComputeMemoryInfo* computeMemInfo) { From aa847de043e2e04512d5d01b4d9e40adc4706b0a Mon Sep 17 00:00:00 2001 From: isshininu Date: Wed, 29 Jan 2025 13:54:08 +0400 Subject: [PATCH 09/15] Update ru_RU translation (#2267) Several changes in ru_RU translation file. --- src/qt_gui/translations/ru_RU.ts | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/qt_gui/translations/ru_RU.ts b/src/qt_gui/translations/ru_RU.ts index 6423f5ba4..0fddb1e7f 100644 --- a/src/qt_gui/translations/ru_RU.ts +++ b/src/qt_gui/translations/ru_RU.ts @@ -126,11 +126,11 @@ Copy All - Копировать все + Копировать всё Delete... - Удаление... + Удалить... Delete Game @@ -158,7 +158,7 @@ Submit a report - Отправить отчет + Отправить отчёт Shortcut creation @@ -297,7 +297,7 @@ Elf Viewer - Elf + Исполняемый файл Game Install Directory @@ -542,7 +542,7 @@ Fullscreen Mode - Режим Полного Экран + Тип полноэкранного режима Enable Separate Update Folder @@ -574,11 +574,11 @@ Trophy Key - Trophy Key + Ключ трофеев Trophy - Trophy + Трофеи Logger @@ -750,7 +750,7 @@ Audio Backend - Звуковая Подсистема + Звуковая подсистема Save @@ -826,7 +826,7 @@ disableTrophycheckBox - Отключить уведомления о трофеях:\nОтключает внутриигровые уведомления о трофеях. Прогресс трофеев по прежнему можно отслеживать в меню Просмотр трофеев (правая кнопка мыши по игре в главном окне). + Отключить уведомления о трофеях:\nОтключает внутриигровые уведомления о трофеях. Прогресс трофеев по прежнему можно отслеживать в меню просмотра трофеев (правая кнопка мыши по игре в главном окне). hideCursorGroupBox @@ -1192,11 +1192,11 @@ Play Time - Времени в игре + Время в игре Never Played - Вы не играли + Нет h @@ -1361,4 +1361,4 @@ ТБ - \ No newline at end of file + From 4bb578f9fb73ce77680e26621717db460a93b0e8 Mon Sep 17 00:00:00 2001 From: Missake212 Date: Wed, 29 Jan 2025 11:45:44 +0100 Subject: [PATCH 10/15] updates french translation (#2262) * updates the french translation * fix space at the end * forgot to translate a line * final changes * final changes 2 --- src/qt_gui/translations/fr.ts | 66 +++++++++++++++++------------------ 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/src/qt_gui/translations/fr.ts b/src/qt_gui/translations/fr.ts index 601ece8b4..0f87b087b 100644 --- a/src/qt_gui/translations/fr.ts +++ b/src/qt_gui/translations/fr.ts @@ -146,19 +146,19 @@ Compatibility... - Compatibility... + Compatibilité... Update database - Update database + Mettre à jour la base de données View report - View report + Voir rapport Submit a report - Submit a report + Soumettre un rapport Shortcut creation @@ -186,7 +186,7 @@ requiresEnableSeparateUpdateFolder_MSG - This feature requires the 'Enable Separate Update Folder' config option to work. If you want to use this feature, please enable it. + Cette fonctionnalité nécessite l'option 'Dossier séparé pour les mises à jour' pour fonctionner. Si vous voulez utiliser cette fonctionnalité, veuillez l'activer. This game has no update to delete! @@ -546,7 +546,7 @@ Enable Separate Update Folder - Dossier séparé pour les mises à jours + Dossier séparé pour les mises à jour Default tab when opening settings @@ -574,11 +574,11 @@ Trophy Key - Trophy Key + Clé de trophée Trophy - Trophy + Trophée Logger @@ -586,11 +586,11 @@ Log Type - Type + Type de journal Log Filter - Filtre + Filtre du journal Open Log Location @@ -722,7 +722,7 @@ Disable Trophy Pop-ups - Disable Trophy Pop-ups + Désactiver les notifications de trophées Play title music @@ -730,19 +730,19 @@ Update Compatibility Database On Startup - Update Compatibility Database On Startup + Mettre à jour la base de données de compatibilité au lancement Game Compatibility - Game Compatibility + Compatibilité du jeu Display Compatibility Data - Display Compatibility Data + Afficher les données de compatibilité Update Compatibility Database - Update Compatibility Database + Mettre à jour la base de données de compatibilité Volume @@ -750,7 +750,7 @@ Audio Backend - Audio Backend + Back-end audio Save @@ -786,7 +786,7 @@ separateUpdatesCheckBox - Dossier séparé pour les mises à jours:\nInstalle les mises à jours des jeux dans un dossier séparé pour une gestion plus facile. + Dossier séparé pour les mises à jour:\nInstalle les mises à jours des jeux dans un dossier séparé pour une gestion plus facile. showSplashCheckBox @@ -806,7 +806,7 @@ TrophyKey - Trophy Key:\nKey used to decrypt trophies. Must be obtained from your jailbroken console.\nMust contain only hex characters. + Clé de trophées:\nClé utilisée pour décrypter les trophées. Doit être obtenu à partir de votre console jailbreakée.\nDoit contenir des caractères hexadécimaux uniquement. logTypeGroupBox @@ -826,7 +826,7 @@ disableTrophycheckBox - Disable Trophy Pop-ups:\nDisable in-game trophy notifications. Trophy progress can still be tracked using the Trophy Viewer (right-click the game in the main window). + Désactiver les notifications de trophées:\nDésactive les notifications de trophées en jeu. La progression des trophées peut toujours être suivie à l'aide de la Visionneuse de trophées (clique droit sur le jeu sur la fenêtre principale). hideCursorGroupBox @@ -842,15 +842,15 @@ enableCompatibilityCheckBox - Display Compatibility Data:\nDisplays game compatibility information in table view. Enable "Update Compatibility On Startup" to get up-to-date information. + Afficher les données de compatibilité:\nAffiche les informations de compatibilité des jeux dans une colonne dédiée. Activez "Mettre à jour la compatibilité au démarrage" pour avoir des informations à jour. checkCompatibilityOnStartupCheckBox - Update Compatibility On Startup:\nAutomatically update the compatibility database when shadPS4 starts. + Mettre à jour la compatibilité au démarrage:\nMettre à jour automatiquement la base de données de compatibilité au démarrage de shadPS4. updateCompatibilityButton - Update Compatibility Database:\nImmediately update the compatibility database. + Mettre à jour la compatibilité au démarrage:\nMet à jour immédiatement la base de données de compatibilité. Never @@ -1093,7 +1093,7 @@ DownloadComplete_MSG - Patchs téléchargés avec succès ! Tous les patches disponibles pour tous les jeux ont été téléchargés, il n'est pas nécessaire de les télécharger individuellement pour chaque jeu comme c'est le cas pour les Cheats. Si le correctif n'apparaît pas, il se peut qu'il n'existe pas pour le numéro de série et la version spécifiques du jeu. + Patchs téléchargés avec succès ! Tous les patches disponibles pour tous les jeux ont été téléchargés, il n'est pas nécessaire de les télécharger individuellement pour chaque jeu comme c'est le cas pour les Cheats. Si le correctif n'apparaît pas, il se peut qu'il n'existe pas pour la série et la version spécifiques du jeu. Failed to parse JSON data from HTML. @@ -1113,7 +1113,7 @@ You may need to update your game. - Vous devrez peut-être mettre à jour votre jeu. + Vous devriez peut-être mettre à jour votre jeu. Incompatibility Notice @@ -1137,7 +1137,7 @@ Directory does not exist: - Répertoire n'existe pas: + Le répertoire n'existe pas: Failed to open files.json for reading. @@ -1149,7 +1149,7 @@ Can't apply cheats before the game is started - Impossible d'appliquer les Cheats avant que le jeu ne commence. + Impossible d'appliquer les cheats avant que le jeu ne soit lancé @@ -1168,7 +1168,7 @@ Compatibility - Compatibility + Compatibilité Region @@ -1212,27 +1212,27 @@ Compatibility is untested - Compatibility is untested + La compatibilité n'a pas été testé Game does not initialize properly / crashes the emulator - Game does not initialize properly / crashes the emulator + Le jeu ne se lance pas correctement / crash l'émulateur Game boots, but only displays a blank screen - Game boots, but only displays a blank screen + Le jeu démarre, mais n'affiche qu'un écran noir Game displays an image but does not go past the menu - Game displays an image but does not go past the menu + Le jeu affiche une image mais ne dépasse pas le menu Game has game-breaking glitches or unplayable performance - Game has game-breaking glitches or unplayable performance + Le jeu a des problèmes majeurs ou des performances qui le rendent injouable Game can be completed with playable performance and no major glitches - Game can be completed with playable performance and no major glitches + Le jeu peut être terminé avec des performances acceptables et sans problèmes majeurs From 929e15260d8d7a618c10a5f396b1f9e872970425 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Wed, 29 Jan 2025 18:14:36 -0800 Subject: [PATCH 11/15] shader_recompiler: Fix cube sampling coordinates. (#2266) --- .../ir/passes/resource_tracking_pass.cpp | 25 ++++++++++++++----- src/shader_recompiler/specialization.h | 2 ++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp index 43d125bf0..c5f98e5b9 100644 --- a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp +++ b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp @@ -583,6 +583,18 @@ void PatchTextureBufferArgs(IR::Block& block, IR::Inst& inst, Info& info) { } } +IR::Value FixCubeCoords(IR::IREmitter& ir, const AmdGpu::Image& image, const IR::Value& x, + const IR::Value& y, const IR::Value& face) { + if (!image.IsCube()) { + return ir.CompositeConstruct(x, y, face); + } + // AMD cube math results in coordinates in the range [1.0, 2.0]. We need + // to convert this to the range [0.0, 1.0] to get correct results. + const auto fixed_x = ir.FPSub(IR::F32{x}, ir.Imm32(1.f)); + const auto fixed_y = ir.FPSub(IR::F32{y}, ir.Imm32(1.f)); + return ir.CompositeConstruct(fixed_x, fixed_y, face); +} + void PatchImageSampleArgs(IR::Block& block, IR::Inst& inst, Info& info, const ImageResource& image_res, const AmdGpu::Image& image) { const auto handle = inst.Arg(0); @@ -643,8 +655,8 @@ void PatchImageSampleArgs(IR::Block& block, IR::Inst& inst, Info& info, case AmdGpu::ImageType::Color1DArray: return read(0); case AmdGpu::ImageType::Color2D: - case AmdGpu::ImageType::Color2DArray: case AmdGpu::ImageType::Color2DMsaa: + case AmdGpu::ImageType::Color2DArray: return ir.CompositeConstruct(read(0), read(8)); case AmdGpu::ImageType::Color3D: return ir.CompositeConstruct(read(0), read(8), read(16)); @@ -665,8 +677,8 @@ void PatchImageSampleArgs(IR::Block& block, IR::Inst& inst, Info& info, addr_reg = addr_reg + 2; return {get_addr_reg(addr_reg - 2), get_addr_reg(addr_reg - 1)}; case AmdGpu::ImageType::Color2D: - case AmdGpu::ImageType::Color2DArray: case AmdGpu::ImageType::Color2DMsaa: + case AmdGpu::ImageType::Color2DArray: // (du/dx, dv/dx), (du/dy, dv/dy) addr_reg = addr_reg + 4; return {ir.CompositeConstruct(get_addr_reg(addr_reg - 4), get_addr_reg(addr_reg - 3)), @@ -711,12 +723,13 @@ void PatchImageSampleArgs(IR::Block& block, IR::Inst& inst, Info& info, case AmdGpu::ImageType::Color2D: // x, y addr_reg = addr_reg + 2; return ir.CompositeConstruct(get_coord(addr_reg - 2, 0), get_coord(addr_reg - 1, 1)); - case AmdGpu::ImageType::Color2DArray: // x, y, slice - [[fallthrough]]; case AmdGpu::ImageType::Color2DMsaa: // x, y, frag + [[fallthrough]]; + case AmdGpu::ImageType::Color2DArray: // x, y, slice addr_reg = addr_reg + 3; - return ir.CompositeConstruct(get_coord(addr_reg - 3, 0), get_coord(addr_reg - 2, 1), - get_addr_reg(addr_reg - 1)); + // Note we can use FixCubeCoords with fallthrough cases since it checks for image type. + return FixCubeCoords(ir, image, get_coord(addr_reg - 3, 0), get_coord(addr_reg - 2, 1), + get_addr_reg(addr_reg - 1)); case AmdGpu::ImageType::Color3D: // x, y, z addr_reg = addr_reg + 3; return ir.CompositeConstruct(get_coord(addr_reg - 3, 0), get_coord(addr_reg - 2, 1), diff --git a/src/shader_recompiler/specialization.h b/src/shader_recompiler/specialization.h index 523e63497..eb0085965 100644 --- a/src/shader_recompiler/specialization.h +++ b/src/shader_recompiler/specialization.h @@ -47,6 +47,7 @@ struct ImageSpecialization { AmdGpu::ImageType type = AmdGpu::ImageType::Color2D; bool is_integer = false; bool is_storage = false; + bool is_cube = false; AmdGpu::CompMapping dst_select{}; AmdGpu::NumberConversion num_conversion{}; @@ -127,6 +128,7 @@ struct StageSpecialization { spec.type = sharp.GetViewType(desc.is_array); spec.is_integer = AmdGpu::IsInteger(sharp.GetNumberFmt()); spec.is_storage = desc.is_written; + spec.is_cube = sharp.IsCube(); if (spec.is_storage) { spec.dst_select = sharp.DstSelect(); } From 0358271b93160a97079376c408b5c270e807826c Mon Sep 17 00:00:00 2001 From: Vinicius Rangel Date: Thu, 30 Jan 2025 04:45:48 -0300 Subject: [PATCH 12/15] Savefixes vii (#2279) * savedata: rewrite save memory functions to handle slot id & better backup management * savedata: auto-restore backup if needed * safe save backup shutdown replaced exit by quick_exit --- src/common/elf_info.h | 1 + src/core/libraries/save_data/save_backup.cpp | 21 +- src/core/libraries/save_data/save_backup.h | 2 + .../libraries/save_data/save_instance.cpp | 53 +-- src/core/libraries/save_data/save_instance.h | 5 +- src/core/libraries/save_data/save_memory.cpp | 365 ++++++++---------- src/core/libraries/save_data/save_memory.h | 36 +- src/core/libraries/save_data/savedata.cpp | 108 ++++-- src/emulator.cpp | 3 +- 9 files changed, 285 insertions(+), 309 deletions(-) diff --git a/src/common/elf_info.h b/src/common/elf_info.h index cb32679bb..d885709cd 100644 --- a/src/common/elf_info.h +++ b/src/common/elf_info.h @@ -80,6 +80,7 @@ public: static constexpr u32 FW_40 = 0x4000000; static constexpr u32 FW_45 = 0x4500000; static constexpr u32 FW_50 = 0x5000000; + static constexpr u32 FW_55 = 0x5500000; static constexpr u32 FW_80 = 0x8000000; static ElfInfo& Instance() { diff --git a/src/core/libraries/save_data/save_backup.cpp b/src/core/libraries/save_data/save_backup.cpp index 5261cdb11..f85845f70 100644 --- a/src/core/libraries/save_data/save_backup.cpp +++ b/src/core/libraries/save_data/save_backup.cpp @@ -121,15 +121,17 @@ static void BackupThreadBody() { std::scoped_lock lk{g_backup_queue_mutex}; g_backup_queue.front().done = true; } - std::this_thread::sleep_for(std::chrono::seconds(5)); // Don't backup too often { std::scoped_lock lk{g_backup_queue_mutex}; g_backup_queue.pop_front(); - g_result_queue.push_back(std::move(req)); - if (g_result_queue.size() > 20) { - g_result_queue.pop_front(); + if (req.origin != OrbisSaveDataEventType::__DO_NOT_SAVE) { + g_result_queue.push_back(std::move(req)); + if (g_result_queue.size() > 20) { + g_result_queue.pop_front(); + } } } + std::this_thread::sleep_for(std::chrono::seconds(5)); // Don't backup too often } g_backup_status = WorkerStatus::NotStarted; } @@ -141,6 +143,15 @@ void StartThread() { LOG_DEBUG(Lib_SaveData, "Starting backup thread"); g_backup_status = WorkerStatus::Waiting; g_backup_thread = std::jthread{BackupThreadBody}; + static std::once_flag flag; + std::call_once(flag, [] { + std::at_quick_exit([] { + StopThread(); + while (GetWorkerStatus() != WorkerStatus::NotStarted) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } + }); + }); } void StopThread() { @@ -148,12 +159,12 @@ void StopThread() { return; } LOG_DEBUG(Lib_SaveData, "Stopping backup thread"); + g_backup_status = WorkerStatus::Stopping; { std::scoped_lock lk{g_backup_queue_mutex}; g_backup_queue.emplace_back(BackupRequest{}); } g_backup_thread_semaphore.release(); - g_backup_status = WorkerStatus::Stopping; } bool NewRequest(OrbisUserServiceUserId user_id, std::string_view title_id, diff --git a/src/core/libraries/save_data/save_backup.h b/src/core/libraries/save_data/save_backup.h index e49c69f60..83a263c9b 100644 --- a/src/core/libraries/save_data/save_backup.h +++ b/src/core/libraries/save_data/save_backup.h @@ -25,6 +25,8 @@ enum class OrbisSaveDataEventType : u32 { UMOUNT_BACKUP = 1, BACKUP = 2, SAVE_DATA_MEMORY_SYNC = 3, + + __DO_NOT_SAVE = 1000000, // This value is only for the backup thread }; struct BackupRequest { diff --git a/src/core/libraries/save_data/save_instance.cpp b/src/core/libraries/save_data/save_instance.cpp index c2b7dca3c..26708d2d6 100644 --- a/src/core/libraries/save_data/save_instance.cpp +++ b/src/core/libraries/save_data/save_instance.cpp @@ -10,6 +10,7 @@ #include "common/path_util.h" #include "common/singleton.h" #include "core/file_sys/fs.h" +#include "save_backup.h" #include "save_instance.h" constexpr auto OrbisSaveDataBlocksMin2 = 96; // 3MiB @@ -45,14 +46,13 @@ static const std::unordered_map default_title = { namespace Libraries::SaveData { -std::filesystem::path SaveInstance::MakeTitleSavePath(OrbisUserServiceUserId user_id, - std::string_view game_serial) { +fs::path SaveInstance::MakeTitleSavePath(OrbisUserServiceUserId user_id, + std::string_view game_serial) { return Config::GetSaveDataPath() / std::to_string(user_id) / game_serial; } -std::filesystem::path SaveInstance::MakeDirSavePath(OrbisUserServiceUserId user_id, - std::string_view game_serial, - std::string_view dir_name) { +fs::path SaveInstance::MakeDirSavePath(OrbisUserServiceUserId user_id, std::string_view game_serial, + std::string_view dir_name) { return Config::GetSaveDataPath() / std::to_string(user_id) / game_serial / dir_name; } @@ -65,7 +65,7 @@ uint64_t SaveInstance::GetMaxBlockFromSFO(const PSF& psf) { return *(uint64_t*)value.data(); } -std::filesystem::path SaveInstance::GetParamSFOPath(const std::filesystem::path& dir_path) { +fs::path SaveInstance::GetParamSFOPath(const fs::path& dir_path) { return dir_path / sce_sys / "param.sfo"; } @@ -129,7 +129,6 @@ SaveInstance& SaveInstance::operator=(SaveInstance&& other) noexcept { save_path = std::move(other.save_path); param_sfo_path = std::move(other.param_sfo_path); corrupt_file_path = std::move(other.corrupt_file_path); - corrupt_file = std::move(other.corrupt_file); param_sfo = std::move(other.param_sfo); mount_point = std::move(other.mount_point); max_blocks = other.max_blocks; @@ -142,7 +141,8 @@ SaveInstance& SaveInstance::operator=(SaveInstance&& other) noexcept { return *this; } -void SaveInstance::SetupAndMount(bool read_only, bool copy_icon, bool ignore_corrupt) { +void SaveInstance::SetupAndMount(bool read_only, bool copy_icon, bool ignore_corrupt, + bool dont_restore_backup) { if (mounted) { UNREACHABLE_MSG("Save instance is already mounted"); } @@ -161,25 +161,27 @@ void SaveInstance::SetupAndMount(bool read_only, bool copy_icon, bool ignore_cor } exists = true; } else { + std::optional err; if (!ignore_corrupt && fs::exists(corrupt_file_path)) { - throw std::filesystem::filesystem_error( - "Corrupted save data", corrupt_file_path, - std::make_error_code(std::errc::illegal_byte_sequence)); + err = fs::filesystem_error("Corrupted save data", corrupt_file_path, + std::make_error_code(std::errc::illegal_byte_sequence)); + } else if (!param_sfo.Open(param_sfo_path)) { + err = fs::filesystem_error("Failed to read param.sfo", param_sfo_path, + std::make_error_code(std::errc::illegal_byte_sequence)); } - if (!param_sfo.Open(param_sfo_path)) { - throw std::filesystem::filesystem_error( - "Failed to read param.sfo", param_sfo_path, - std::make_error_code(std::errc::illegal_byte_sequence)); + if (err.has_value()) { + if (dont_restore_backup) { + throw err.value(); + } + if (Backup::Restore(save_path)) { + return SetupAndMount(read_only, copy_icon, ignore_corrupt, true); + } } } if (!ignore_corrupt && !read_only) { - int err = corrupt_file.Open(corrupt_file_path, Common::FS::FileAccessMode::Write); - if (err != 0) { - throw std::filesystem::filesystem_error( - "Failed to open corrupted file", corrupt_file_path, - std::make_error_code(std::errc::illegal_byte_sequence)); - } + Common::FS::IOFile f(corrupt_file_path, Common::FS::FileAccessMode::Write); + f.Close(); } max_blocks = static_cast(GetMaxBlockFromSFO(param_sfo)); @@ -197,12 +199,11 @@ void SaveInstance::Umount() { mounted = false; const bool ok = param_sfo.Encode(param_sfo_path); if (!ok) { - throw std::filesystem::filesystem_error("Failed to write param.sfo", param_sfo_path, - std::make_error_code(std::errc::permission_denied)); + throw fs::filesystem_error("Failed to write param.sfo", param_sfo_path, + std::make_error_code(std::errc::permission_denied)); } param_sfo = PSF(); - corrupt_file.Close(); fs::remove(corrupt_file_path); g_mnt->Unmount(save_path, mount_point); } @@ -216,8 +217,8 @@ void SaveInstance::CreateFiles() { const bool ok = param_sfo.Encode(param_sfo_path); if (!ok) { - throw std::filesystem::filesystem_error("Failed to write param.sfo", param_sfo_path, - std::make_error_code(std::errc::permission_denied)); + throw fs::filesystem_error("Failed to write param.sfo", param_sfo_path, + std::make_error_code(std::errc::permission_denied)); } } diff --git a/src/core/libraries/save_data/save_instance.h b/src/core/libraries/save_data/save_instance.h index 3be5c4595..6e7ac8f66 100644 --- a/src/core/libraries/save_data/save_instance.h +++ b/src/core/libraries/save_data/save_instance.h @@ -42,8 +42,6 @@ class SaveInstance { std::filesystem::path param_sfo_path; std::filesystem::path corrupt_file_path; - Common::FS::IOFile corrupt_file; - PSF param_sfo; std::string mount_point; @@ -80,7 +78,8 @@ public: SaveInstance& operator=(const SaveInstance& other) = delete; SaveInstance& operator=(SaveInstance&& other) noexcept; - void SetupAndMount(bool read_only = false, bool copy_icon = false, bool ignore_corrupt = false); + void SetupAndMount(bool read_only = false, bool copy_icon = false, bool ignore_corrupt = false, + bool dont_restore_backup = false); void Umount(); diff --git a/src/core/libraries/save_data/save_memory.cpp b/src/core/libraries/save_data/save_memory.cpp index 84179bc27..13e122c60 100644 --- a/src/core/libraries/save_data/save_memory.cpp +++ b/src/core/libraries/save_data/save_memory.cpp @@ -6,14 +6,16 @@ #include #include #include +#include #include #include #include #include "common/assert.h" +#include "common/elf_info.h" #include "common/logging/log.h" -#include "common/polyfill_thread.h" +#include "common/path_util.h" #include "common/singleton.h" #include "common/thread.h" #include "core/file_sys/fs.h" @@ -23,265 +25,202 @@ using Common::FS::IOFile; namespace fs = std::filesystem; constexpr std::string_view sce_sys = "sce_sys"; // system folder inside save -constexpr std::string_view DirnameSaveDataMemory = "sce_sdmemory"; +constexpr std::string_view StandardDirnameSaveDataMemory = "sce_sdmemory"; constexpr std::string_view FilenameSaveDataMemory = "memory.dat"; +constexpr std::string_view IconName = "icon0.png"; +constexpr std::string_view CorruptFileName = "corrupted"; namespace Libraries::SaveData::SaveMemory { static Core::FileSys::MntPoints* g_mnt = Common::Singleton::Instance(); -static OrbisUserServiceUserId g_user_id{}; -static std::string g_game_serial{}; -static std::filesystem::path g_save_path{}; -static std::filesystem::path g_param_sfo_path{}; -static PSF g_param_sfo; +struct SlotData { + OrbisUserServiceUserId user_id; + std::string game_serial; + std::filesystem::path folder_path; + PSF sfo; + std::vector memory_cache; +}; -static bool g_save_memory_initialized = false; -static std::mutex g_saving_memory_mutex; -static std::vector g_save_memory; +static std::mutex g_slot_mtx; +static std::unordered_map g_attached_slots; -static std::filesystem::path g_icon_path; -static std::vector g_icon_memory; +void PersistMemory(u32 slot_id, bool lock) { + std::unique_lock lck{g_slot_mtx, std::defer_lock}; + if (lock) { + lck.lock(); + } + auto& data = g_attached_slots[slot_id]; + auto memoryPath = data.folder_path / FilenameSaveDataMemory; + fs::create_directories(memoryPath.parent_path()); -static std::condition_variable g_trigger_save_memory; -static std::atomic_bool g_saving_memory = false; -static std::atomic_bool g_save_event = false; -static std::jthread g_save_memory_thread; - -static std::atomic_bool g_memory_dirty = false; -static std::atomic_bool g_param_dirty = false; -static std::atomic_bool g_icon_dirty = false; - -static void SaveFileSafe(void* buf, size_t count, const std::filesystem::path& path) { - const auto& dir = path.parent_path(); - const auto& name = path.filename(); - const auto tmp_path = dir / (name.string() + ".tmp"); - - IOFile file(tmp_path, Common::FS::FileAccessMode::Write); - file.WriteRaw(buf, count); - file.Close(); - - fs::remove(path); - fs::rename(tmp_path, path); -} - -[[noreturn]] void SaveThreadLoop() { - Common::SetCurrentThreadName("shadPS4:SaveData:SaveDataMemoryThread"); - std::mutex mtx; - while (true) { - { - std::unique_lock lk{mtx}; - g_trigger_save_memory.wait(lk); - } - // Save the memory - g_saving_memory = true; - std::scoped_lock lk{g_saving_memory_mutex}; + int n = 0; + std::string errMsg; + while (n++ < 10) { try { - LOG_DEBUG(Lib_SaveData, "Saving save data memory {}", fmt::UTF(g_save_path.u8string())); - - if (g_memory_dirty) { - g_memory_dirty = false; - SaveFileSafe(g_save_memory.data(), g_save_memory.size(), - g_save_path / FilenameSaveDataMemory); + IOFile f; + int r = f.Open(memoryPath, Common::FS::FileAccessMode::Write); + if (f.IsOpen()) { + f.WriteRaw(data.memory_cache.data(), data.memory_cache.size()); + f.Close(); + return; } - if (g_param_dirty) { - g_param_dirty = false; - static std::vector buf; - g_param_sfo.Encode(buf); - SaveFileSafe(buf.data(), buf.size(), g_param_sfo_path); - } - if (g_icon_dirty) { - g_icon_dirty = false; - SaveFileSafe(g_icon_memory.data(), g_icon_memory.size(), g_icon_path); - } - - if (g_save_event) { - Backup::PushBackupEvent(Backup::BackupRequest{ - .user_id = g_user_id, - .title_id = g_game_serial, - .dir_name = std::string{DirnameSaveDataMemory}, - .origin = Backup::OrbisSaveDataEventType::SAVE_DATA_MEMORY_SYNC, - .save_path = g_save_path, - }); - g_save_event = false; - } - } catch (const fs::filesystem_error& e) { - LOG_ERROR(Lib_SaveData, "Failed to save save data memory: {}", e.what()); - MsgDialog::ShowMsgDialog(MsgDialog::MsgDialogState{ - MsgDialog::MsgDialogState::UserState{ - .type = MsgDialog::ButtonType::OK, - .msg = fmt::format("Failed to save save data memory.\nCode: <{}>\n{}", - e.code().message(), e.what()), - }, - }); + const auto err = std::error_code{r, std::iostream_category()}; + throw std::filesystem::filesystem_error{err.message(), err}; + } catch (const std::filesystem::filesystem_error& e) { + errMsg = std::string{e.what()}; + std::this_thread::sleep_for(std::chrono::seconds(1)); } - g_saving_memory = false; } + const MsgDialog::MsgDialogState dialog{MsgDialog::MsgDialogState::UserState{ + .type = MsgDialog::ButtonType::OK, + .msg = "Failed to persist save memory:\n" + errMsg + "\nat " + + Common::FS::PathToUTF8String(memoryPath), + }}; + MsgDialog::ShowMsgDialog(dialog); } -void SetDirectories(OrbisUserServiceUserId user_id, std::string _game_serial) { - g_user_id = user_id; - g_game_serial = std::move(_game_serial); - g_save_path = SaveInstance::MakeDirSavePath(user_id, g_game_serial, DirnameSaveDataMemory); - g_param_sfo_path = SaveInstance::GetParamSFOPath(g_save_path); - g_param_sfo = PSF(); - g_icon_path = g_save_path / sce_sys / "icon0.png"; +std::string GetSaveDir(u32 slot_id) { + std::string dir(StandardDirnameSaveDataMemory); + if (slot_id > 0) { + dir += std::to_string(slot_id); + } + return dir; } -const std::filesystem::path& GetSavePath() { - return g_save_path; +std::filesystem::path GetSavePath(OrbisUserServiceUserId user_id, u32 slot_id, + std::string_view game_serial) { + std::string dir(StandardDirnameSaveDataMemory); + if (slot_id > 0) { + dir += std::to_string(slot_id); + } + return SaveInstance::MakeDirSavePath(user_id, Common::ElfInfo::Instance().GameSerial(), dir); } -size_t CreateSaveMemory(size_t memory_size) { - size_t existed_size = 0; +size_t SetupSaveMemory(OrbisUserServiceUserId user_id, u32 slot_id, std::string_view game_serial) { + std::lock_guard lck{g_slot_mtx}; - static std::once_flag init_save_thread_flag; - std::call_once(init_save_thread_flag, - [] { g_save_memory_thread = std::jthread{SaveThreadLoop}; }); + const auto save_dir = GetSavePath(user_id, slot_id, game_serial); - g_save_memory.resize(memory_size); - SaveInstance::SetupDefaultParamSFO(g_param_sfo, std::string{DirnameSaveDataMemory}, - g_game_serial); + auto& data = g_attached_slots[slot_id]; + data = SlotData{ + .user_id = user_id, + .game_serial = std::string{game_serial}, + .folder_path = save_dir, + .sfo = {}, + .memory_cache = {}, + }; - g_save_memory_initialized = true; + SaveInstance::SetupDefaultParamSFO(data.sfo, GetSaveDir(slot_id), std::string{game_serial}); - if (!fs::exists(g_param_sfo_path)) { - // Create save memory - fs::create_directories(g_save_path / sce_sys); - - IOFile memory_file{g_save_path / FilenameSaveDataMemory, Common::FS::FileAccessMode::Write}; - bool ok = memory_file.SetSize(memory_size); - if (!ok) { - LOG_ERROR(Lib_SaveData, "Failed to set memory size"); - throw std::filesystem::filesystem_error( - "Failed to set save memory size", g_save_path / FilenameSaveDataMemory, - std::make_error_code(std::errc::no_space_on_device)); - } - memory_file.Close(); - } else { - // Load save memory - - bool ok = g_param_sfo.Open(g_param_sfo_path); - if (!ok) { - LOG_ERROR(Lib_SaveData, "Failed to open SFO at {}", - fmt::UTF(g_param_sfo_path.u8string())); - throw std::filesystem::filesystem_error( - "failed to open SFO", g_param_sfo_path, - std::make_error_code(std::errc::illegal_byte_sequence)); - } - - IOFile memory_file{g_save_path / FilenameSaveDataMemory, Common::FS::FileAccessMode::Read}; - if (!memory_file.IsOpen()) { - LOG_ERROR(Lib_SaveData, "Failed to open save memory"); - throw std::filesystem::filesystem_error( - "failed to open save memory", g_save_path / FilenameSaveDataMemory, - std::make_error_code(std::errc::permission_denied)); - } - size_t save_size = memory_file.GetSize(); - existed_size = save_size; - memory_file.Seek(0); - memory_file.ReadRaw(g_save_memory.data(), std::min(save_size, memory_size)); - memory_file.Close(); + auto param_sfo_path = SaveInstance::GetParamSFOPath(save_dir); + if (!fs::exists(param_sfo_path)) { + return 0; } - return existed_size; + if (!data.sfo.Open(param_sfo_path) || fs::exists(save_dir / CorruptFileName)) { + if (!Backup::Restore(save_dir)) { // Could not restore the backup + return 0; + } + } + + const auto memory = save_dir / FilenameSaveDataMemory; + if (fs::exists(memory)) { + return fs::file_size(memory); + } + + return 0; } -void SetIcon(void* buf, size_t buf_size) { +void SetIcon(u32 slot_id, void* buf, size_t buf_size) { + std::lock_guard lck{g_slot_mtx}; + const auto& data = g_attached_slots[slot_id]; + const auto icon_path = data.folder_path / sce_sys / "icon0.png"; if (buf == nullptr) { const auto& src_icon = g_mnt->GetHostPath("/app0/sce_sys/save_data.png"); - if (fs::exists(src_icon)) { - if (fs::exists(g_icon_path)) { - fs::remove(g_icon_path); - } - fs::copy_file(src_icon, g_icon_path); + if (fs::exists(icon_path)) { + fs::remove(icon_path); } - if (fs::exists(g_icon_path)) { - IOFile file(g_icon_path, Common::FS::FileAccessMode::Read); - size_t size = file.GetSize(); - file.Seek(0); - g_icon_memory.resize(size); - file.ReadRaw(g_icon_memory.data(), size); - file.Close(); + if (fs::exists(src_icon)) { + fs::create_directories(icon_path.parent_path()); + fs::copy_file(src_icon, icon_path); } } else { - g_icon_memory.resize(buf_size); - std::memcpy(g_icon_memory.data(), buf, buf_size); - IOFile file(g_icon_path, Common::FS::FileAccessMode::Write); - file.Seek(0); - file.WriteRaw(g_icon_memory.data(), buf_size); + IOFile file(icon_path, Common::FS::FileAccessMode::Write); + file.WriteRaw(buf, buf_size); file.Close(); } } -void WriteIcon(void* buf, size_t buf_size) { - if (buf_size != g_icon_memory.size()) { - g_icon_memory.resize(buf_size); +bool IsSaveMemoryInitialized(u32 slot_id) { + std::lock_guard lck{g_slot_mtx}; + return g_attached_slots.contains(slot_id); +} + +PSF& GetParamSFO(u32 slot_id) { + std::lock_guard lck{g_slot_mtx}; + auto& data = g_attached_slots[slot_id]; + return data.sfo; +} + +std::vector GetIcon(u32 slot_id) { + std::lock_guard lck{g_slot_mtx}; + auto& data = g_attached_slots[slot_id]; + const auto icon_path = data.folder_path / sce_sys / "icon0.png"; + IOFile f{icon_path, Common::FS::FileAccessMode::Read}; + if (!f.IsOpen()) { + return {}; } - std::memcpy(g_icon_memory.data(), buf, buf_size); - g_icon_dirty = true; + const u64 size = f.GetSize(); + std::vector ret; + ret.resize(size); + f.ReadSpan(std::span{ret}); + return ret; } -bool IsSaveMemoryInitialized() { - return g_save_memory_initialized; -} - -PSF& GetParamSFO() { - return g_param_sfo; -} - -std::span GetIcon() { - return {g_icon_memory}; -} - -void SaveSFO(bool sync) { - if (!sync) { - g_param_dirty = true; - return; - } - const bool ok = g_param_sfo.Encode(g_param_sfo_path); +void SaveSFO(u32 slot_id) { + std::lock_guard lck{g_slot_mtx}; + const auto& data = g_attached_slots[slot_id]; + const auto sfo_path = SaveInstance::GetParamSFOPath(data.folder_path); + fs::create_directories(sfo_path.parent_path()); + const bool ok = data.sfo.Encode(sfo_path); if (!ok) { LOG_ERROR(Lib_SaveData, "Failed to encode param.sfo"); - throw std::filesystem::filesystem_error("Failed to write param.sfo", g_param_sfo_path, + throw std::filesystem::filesystem_error("Failed to write param.sfo", sfo_path, std::make_error_code(std::errc::permission_denied)); } } -bool IsSaving() { - return g_saving_memory; + +void ReadMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset) { + std::lock_guard lk{g_slot_mtx}; + auto& data = g_attached_slots[slot_id]; + auto& memory = data.memory_cache; + if (memory.empty()) { // Load file + IOFile f{data.folder_path / FilenameSaveDataMemory, Common::FS::FileAccessMode::Read}; + if (f.IsOpen()) { + memory.resize(f.GetSize()); + f.Seek(0); + f.ReadSpan(std::span{memory}); + } + } + s64 read_size = buf_size; + if (read_size + offset > memory.size()) { + read_size = memory.size() - offset; + } + std::memcpy(buf, memory.data() + offset, read_size); } -bool TriggerSaveWithoutEvent() { - if (g_saving_memory) { - return false; +void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset) { + std::lock_guard lk{g_slot_mtx}; + auto& data = g_attached_slots[slot_id]; + auto& memory = data.memory_cache; + if (offset + buf_size > memory.size()) { + memory.resize(offset + buf_size); } - g_trigger_save_memory.notify_one(); - return true; -} - -bool TriggerSave() { - if (g_saving_memory) { - return false; - } - g_save_event = true; - g_trigger_save_memory.notify_one(); - return true; -} - -void ReadMemory(void* buf, size_t buf_size, int64_t offset) { - std::scoped_lock lk{g_saving_memory_mutex}; - if (offset + buf_size > g_save_memory.size()) { - UNREACHABLE_MSG("ReadMemory out of bounds"); - } - std::memcpy(buf, g_save_memory.data() + offset, buf_size); -} - -void WriteMemory(void* buf, size_t buf_size, int64_t offset) { - std::scoped_lock lk{g_saving_memory_mutex}; - if (offset + buf_size > g_save_memory.size()) { - g_save_memory.resize(offset + buf_size); - } - std::memcpy(g_save_memory.data() + offset, buf, buf_size); - g_memory_dirty = true; + std::memcpy(memory.data() + offset, buf, buf_size); + PersistMemory(slot_id, false); + Backup::NewRequest(data.user_id, data.game_serial, GetSaveDir(slot_id), + Backup::OrbisSaveDataEventType::__DO_NOT_SAVE); } } // namespace Libraries::SaveData::SaveMemory \ No newline at end of file diff --git a/src/core/libraries/save_data/save_memory.h b/src/core/libraries/save_data/save_memory.h index 04eeaa652..681865634 100644 --- a/src/core/libraries/save_data/save_memory.h +++ b/src/core/libraries/save_data/save_memory.h @@ -3,7 +3,7 @@ #pragma once -#include +#include #include "save_backup.h" class PSF; @@ -14,36 +14,30 @@ using OrbisUserServiceUserId = s32; namespace Libraries::SaveData::SaveMemory { -void SetDirectories(OrbisUserServiceUserId user_id, std::string game_serial); +void PersistMemory(u32 slot_id, bool lock = true); -[[nodiscard]] const std::filesystem::path& GetSavePath(); +[[nodiscard]] std::string GetSaveDir(u32 slot_id); -// returns the size of the existed save memory -size_t CreateSaveMemory(size_t memory_size); +[[nodiscard]] std::filesystem::path GetSavePath(OrbisUserServiceUserId user_id, u32 slot_id, + std::string_view game_serial); -// Initialize the icon. Set buf to null to read the standard icon. -void SetIcon(void* buf, size_t buf_size); +// returns the size of the save memory if exists +size_t SetupSaveMemory(OrbisUserServiceUserId user_id, u32 slot_id, std::string_view game_serial); -// Update the icon -void WriteIcon(void* buf, size_t buf_size); +// Write the icon. Set buf to null to read the standard icon. +void SetIcon(u32 slot_id, void* buf = nullptr, size_t buf_size = 0); -[[nodiscard]] bool IsSaveMemoryInitialized(); +[[nodiscard]] bool IsSaveMemoryInitialized(u32 slot_id); -[[nodiscard]] PSF& GetParamSFO(); +[[nodiscard]] PSF& GetParamSFO(u32 slot_id); -[[nodiscard]] std::span GetIcon(); +[[nodiscard]] std::vector GetIcon(u32 slot_id); // Save now or wait for the background thread to save -void SaveSFO(bool sync = false); +void SaveSFO(u32 slot_id); -[[nodiscard]] bool IsSaving(); +void ReadMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset); -bool TriggerSaveWithoutEvent(); - -bool TriggerSave(); - -void ReadMemory(void* buf, size_t buf_size, int64_t offset); - -void WriteMemory(void* buf, size_t buf_size, int64_t offset); +void WriteMemory(u32 slot_id, void* buf, size_t buf_size, int64_t offset); } // namespace Libraries::SaveData::SaveMemory \ No newline at end of file diff --git a/src/core/libraries/save_data/savedata.cpp b/src/core/libraries/save_data/savedata.cpp index b573ded1e..e9ad77d69 100644 --- a/src/core/libraries/save_data/savedata.cpp +++ b/src/core/libraries/save_data/savedata.cpp @@ -177,7 +177,8 @@ struct OrbisSaveDataMemoryGet2 { OrbisSaveDataMemoryData* data; OrbisSaveDataParam* param; OrbisSaveDataIcon* icon; - std::array _reserved; + u32 slotId; + std::array _reserved; }; struct OrbisSaveDataMemorySet2 { @@ -186,6 +187,8 @@ struct OrbisSaveDataMemorySet2 { const OrbisSaveDataMemoryData* data; const OrbisSaveDataParam* param; const OrbisSaveDataIcon* icon; + u32 dataNum; + u32 slotId; std::array _reserved; }; @@ -198,7 +201,8 @@ struct OrbisSaveDataMemorySetup2 { const OrbisSaveDataParam* initParam; // +4.5 const OrbisSaveDataIcon* initIcon; - std::array _reserved; + u32 slotId; + std::array _reserved; }; struct OrbisSaveDataMemorySetupResult { @@ -206,9 +210,16 @@ struct OrbisSaveDataMemorySetupResult { std::array _reserved; }; +enum OrbisSaveDataMemorySyncOption : u32 { + NONE = 0, + BLOCKING = 1, +}; + struct OrbisSaveDataMemorySync { OrbisUserServiceUserId userId; - std::array _reserved; + u32 slotId; + OrbisSaveDataMemorySyncOption option; + std::array _reserved; }; struct OrbisSaveDataMount2 { @@ -327,6 +338,7 @@ static void initialize() { g_initialized = true; g_game_serial = ElfInfo::Instance().GameSerial(); g_fw_ver = ElfInfo::Instance().FirmwareVer(); + Backup::StartThread(); } // game_00other | game*other @@ -558,7 +570,6 @@ Error PS4_SYSV_ABI sceSaveDataBackup(const OrbisSaveDataBackup* backup) { } } - Backup::StartThread(); Backup::NewRequest(backup->userId, title, dir_name, OrbisSaveDataEventType::BACKUP); return Error::OK; @@ -1136,22 +1147,27 @@ Error PS4_SYSV_ABI sceSaveDataGetSaveDataMemory2(OrbisSaveDataMemoryGet2* getPar LOG_INFO(Lib_SaveData, "called with invalid parameter"); return Error::PARAMETER; } - if (!SaveMemory::IsSaveMemoryInitialized()) { + + u32 slot_id = 0; + if (g_fw_ver > ElfInfo::FW_50) { + slot_id = getParam->slotId; + } + if (!SaveMemory::IsSaveMemoryInitialized(slot_id)) { LOG_INFO(Lib_SaveData, "called without save memory initialized"); return Error::MEMORY_NOT_READY; } LOG_DEBUG(Lib_SaveData, "called"); auto data = getParam->data; if (data != nullptr) { - SaveMemory::ReadMemory(data->buf, data->bufSize, data->offset); + SaveMemory::ReadMemory(slot_id, data->buf, data->bufSize, data->offset); } auto param = getParam->param; if (param != nullptr) { - param->FromSFO(SaveMemory::GetParamSFO()); + param->FromSFO(SaveMemory::GetParamSFO(slot_id)); } auto icon = getParam->icon; if (icon != nullptr) { - auto icon_mem = SaveMemory::GetIcon(); + auto icon_mem = SaveMemory::GetIcon(slot_id); size_t total = std::min(icon->bufSize, icon_mem.size()); std::memcpy(icon->buf, icon_mem.data(), total); icon->dataSize = total; @@ -1494,36 +1510,37 @@ Error PS4_SYSV_ABI sceSaveDataSetSaveDataMemory2(const OrbisSaveDataMemorySet2* LOG_INFO(Lib_SaveData, "called with invalid parameter"); return Error::PARAMETER; } - if (!SaveMemory::IsSaveMemoryInitialized()) { + u32 slot_id = 0; + u32 data_num = 1; + if (g_fw_ver > ElfInfo::FW_50) { + slot_id = setParam->slotId; + if (setParam->dataNum > 1) { + data_num = setParam->dataNum; + } + } + if (!SaveMemory::IsSaveMemoryInitialized(slot_id)) { LOG_INFO(Lib_SaveData, "called without save memory initialized"); return Error::MEMORY_NOT_READY; } - if (SaveMemory::IsSaving()) { - int count = 0; - while (++count < 100 && SaveMemory::IsSaving()) { // try for more 10 seconds - std::this_thread::sleep_for(chrono::milliseconds(100)); - } - if (SaveMemory::IsSaving()) { - LOG_TRACE(Lib_SaveData, "called while saving"); - return Error::BUSY_FOR_SAVING; - } - } + LOG_DEBUG(Lib_SaveData, "called"); auto data = setParam->data; if (data != nullptr) { - SaveMemory::WriteMemory(data->buf, data->bufSize, data->offset); + for (int i = 0; i < data_num; i++) { + SaveMemory::WriteMemory(slot_id, data[i].buf, data[i].bufSize, data[i].offset); + } } auto param = setParam->param; if (param != nullptr) { - param->ToSFO(SaveMemory::GetParamSFO()); - SaveMemory::SaveSFO(); - } - auto icon = setParam->icon; - if (icon != nullptr) { - SaveMemory::WriteIcon(icon->buf, icon->bufSize); + param->ToSFO(SaveMemory::GetParamSFO(slot_id)); + SaveMemory::SaveSFO(slot_id); + } + + auto icon = setParam->icon; + if (icon != nullptr) { + SaveMemory::SetIcon(slot_id, icon->buf, icon->bufSize); } - SaveMemory::TriggerSaveWithoutEvent(); return Error::OK; } @@ -1563,9 +1580,12 @@ Error PS4_SYSV_ABI sceSaveDataSetupSaveDataMemory2(const OrbisSaveDataMemorySetu } LOG_DEBUG(Lib_SaveData, "called"); - SaveMemory::SetDirectories(setupParam->userId, g_game_serial); + u32 slot_id = 0; + if (g_fw_ver > ElfInfo::FW_50) { + slot_id = setupParam->slotId; + } - const auto& save_path = SaveMemory::GetSavePath(); + const auto& save_path = SaveMemory::GetSavePath(setupParam->userId, slot_id, g_game_serial); for (const auto& instance : g_mount_slots) { if (instance.has_value() && instance->GetSavePath() == save_path) { return Error::BUSY; @@ -1573,21 +1593,21 @@ Error PS4_SYSV_ABI sceSaveDataSetupSaveDataMemory2(const OrbisSaveDataMemorySetu } try { - size_t existed_size = SaveMemory::CreateSaveMemory(setupParam->memorySize); + size_t existed_size = + SaveMemory::SetupSaveMemory(setupParam->userId, slot_id, g_game_serial); if (existed_size == 0) { // Just created if (g_fw_ver >= ElfInfo::FW_45 && setupParam->initParam != nullptr) { - auto& sfo = SaveMemory::GetParamSFO(); + auto& sfo = SaveMemory::GetParamSFO(slot_id); setupParam->initParam->ToSFO(sfo); } - SaveMemory::SaveSFO(); + SaveMemory::SaveSFO(slot_id); auto init_icon = setupParam->initIcon; if (g_fw_ver >= ElfInfo::FW_45 && init_icon != nullptr) { - SaveMemory::SetIcon(init_icon->buf, init_icon->bufSize); + SaveMemory::SetIcon(slot_id, init_icon->buf, init_icon->bufSize); } else { - SaveMemory::SetIcon(nullptr, 0); + SaveMemory::SetIcon(slot_id); } - SaveMemory::TriggerSaveWithoutEvent(); } if (g_fw_ver >= ElfInfo::FW_45 && result != nullptr) { result->existedMemorySize = existed_size; @@ -1631,15 +1651,23 @@ Error PS4_SYSV_ABI sceSaveDataSyncSaveDataMemory(OrbisSaveDataMemorySync* syncPa LOG_INFO(Lib_SaveData, "called with invalid parameter"); return Error::PARAMETER; } - if (!SaveMemory::IsSaveMemoryInitialized()) { + + u32 slot_id = 0; + if (g_fw_ver > ElfInfo::FW_50) { + slot_id = syncParam->slotId; + } + + if (!SaveMemory::IsSaveMemoryInitialized(slot_id)) { LOG_INFO(Lib_SaveData, "called without save memory initialized"); return Error::MEMORY_NOT_READY; } LOG_DEBUG(Lib_SaveData, "called"); - bool ok = SaveMemory::TriggerSave(); - if (!ok) { - return Error::BUSY_FOR_SAVING; - } + + SaveMemory::PersistMemory(slot_id); + const auto& save_path = SaveMemory::GetSaveDir(slot_id); + Backup::NewRequest(syncParam->userId, g_game_serial, save_path, + OrbisSaveDataEventType::SAVE_DATA_MEMORY_SYNC); + return Error::OK; } diff --git a/src/emulator.cpp b/src/emulator.cpp index 97215c06f..d873b3462 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -33,6 +33,7 @@ #include "core/libraries/ngs2/ngs2.h" #include "core/libraries/np_trophy/np_trophy.h" #include "core/libraries/rtc/rtc.h" +#include "core/libraries/save_data/save_backup.h" #include "core/linker.h" #include "core/memory.h" #include "emulator.h" @@ -271,7 +272,7 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector Date: Thu, 30 Jan 2025 00:09:11 -0800 Subject: [PATCH 13/15] sdl_window: Allow alternate face button keys on any system. (#2275) * sdl_window: Allow alternate face button keys on any system. * readme: Fix typo --- README.md | 55 ++++++++++++++++++++++++---------------------- src/sdl_window.cpp | 27 ++++++++--------------- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index fd40d2d63..89aed29b4 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ For more information on how to test, debug and report issues with the emulator o # Keyboard mapping +> [!NOTE] +> Some keyboards may also require you to hold the Fn key to use the F\* keys. Mac users should use the Command key instead of Control, and need to use Command+F11 for full screen to avoid conflicting with system key bindings. + | Button | Function | |-------------|-------------| F10 | FPS Counter @@ -86,32 +89,32 @@ F12 | Trigger RenderDoc Capture > [!NOTE] > Xbox and DualShock controllers work out of the box. -| Controller button | Keyboard equivelant | Mac alternative | -|-------------|-------------|--------------| -LEFT AXIS UP | W | | -LEFT AXIS DOWN | S | | -LEFT AXIS LEFT | A | | -LEFT AXIS RIGHT | D | | -RIGHT AXIS UP | I | | -RIGHT AXIS DOWN | K | | -RIGHT AXIS LEFT | J | | -RIGHT AXIS RIGHT | L | | -TRIANGLE | Numpad 8 | C | -CIRCLE | Numpad 6 | B | -CROSS | Numpad 2 | N | -SQUARE | Numpad 4 | V | -PAD UP | UP | | -PAD DOWN | DOWN | | -PAD LEFT | LEFT | | -PAD RIGHT | RIGHT | | -OPTIONS | RETURN | | -BACK BUTTON / TOUCH PAD | SPACE | | -L1 | Q | | -R1 | U | | -L2 | E | | -R2 | O | | -L3 | X | | -R3 | M | | +| Controller button | Keyboard equivalent | +|-------------|-------------| +LEFT AXIS UP | W | +LEFT AXIS DOWN | S | +LEFT AXIS LEFT | A | +LEFT AXIS RIGHT | D | +RIGHT AXIS UP | I | +RIGHT AXIS DOWN | K | +RIGHT AXIS LEFT | J | +RIGHT AXIS RIGHT | L | +TRIANGLE | Numpad 8 or C | +CIRCLE | Numpad 6 or B | +CROSS | Numpad 2 or N | +SQUARE | Numpad 4 or V | +PAD UP | UP | +PAD DOWN | DOWN | +PAD LEFT | LEFT | +PAD RIGHT | RIGHT | +OPTIONS | RETURN | +BACK BUTTON / TOUCH PAD | SPACE | +L1 | Q | +R1 | U | +L2 | E | +R2 | O | +L3 | X | +R3 | M | # Main team diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index d1fe6bbab..9b7617925 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -382,20 +382,6 @@ void WindowSDL::OnResize() { } void WindowSDL::OnKeyPress(const SDL_Event* event) { -#ifdef __APPLE__ - // Use keys that are more friendly for keyboards without a keypad. - // Once there are key binding options this won't be necessary. - constexpr SDL_Keycode CrossKey = SDLK_N; - constexpr SDL_Keycode CircleKey = SDLK_B; - constexpr SDL_Keycode SquareKey = SDLK_V; - constexpr SDL_Keycode TriangleKey = SDLK_C; -#else - constexpr SDL_Keycode CrossKey = SDLK_KP_2; - constexpr SDL_Keycode CircleKey = SDLK_KP_6; - constexpr SDL_Keycode SquareKey = SDLK_KP_4; - constexpr SDL_Keycode TriangleKey = SDLK_KP_8; -#endif - auto button = OrbisPadButtonDataOffset::None; Input::Axis axis = Input::Axis::AxisMax; int axisvalue = 0; @@ -414,16 +400,21 @@ void WindowSDL::OnKeyPress(const SDL_Event* event) { case SDLK_RIGHT: button = OrbisPadButtonDataOffset::Right; break; - case TriangleKey: + // Provide alternatives for face buttons for users without a numpad. + case SDLK_KP_8: + case SDLK_C: button = OrbisPadButtonDataOffset::Triangle; break; - case CircleKey: + case SDLK_KP_6: + case SDLK_B: button = OrbisPadButtonDataOffset::Circle; break; - case CrossKey: + case SDLK_KP_2: + case SDLK_N: button = OrbisPadButtonDataOffset::Cross; break; - case SquareKey: + case SDLK_KP_4: + case SDLK_V: button = OrbisPadButtonDataOffset::Square; break; case SDLK_RETURN: From d8b411429638b48db375c03682fd1bcc3efdfd11 Mon Sep 17 00:00:00 2001 From: Bhaal42 Date: Thu, 30 Jan 2025 09:25:29 +0100 Subject: [PATCH 14/15] Patch 1 (#2278) * Update fr.ts Corrected some typos * Update fr.ts forgot plural --- src/qt_gui/translations/fr.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qt_gui/translations/fr.ts b/src/qt_gui/translations/fr.ts index 0f87b087b..250b8f3c3 100644 --- a/src/qt_gui/translations/fr.ts +++ b/src/qt_gui/translations/fr.ts @@ -373,7 +373,7 @@ toolBar - Bare d'outils + Barre d'outils Game List @@ -489,7 +489,7 @@ Game successfully installed at %1 - Jeu installé avec succès à %1 + Jeu installé avec succès dans %1 File doesn't appear to be a valid PKG file @@ -554,7 +554,7 @@ Show Game Size In List - Afficher la taille du jeu dans la liste + Afficher la taille des jeux dans la liste Show Splash @@ -945,7 +945,7 @@ Serial: - Série: + Numéro de série: Version: @@ -1164,7 +1164,7 @@ Serial - Série + Numéro de série Compatibility @@ -1361,4 +1361,4 @@ TB - \ No newline at end of file + From 132a9d7d357727ab7e16e974647890434dfcd0d6 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Thu, 30 Jan 2025 01:38:34 -0800 Subject: [PATCH 15/15] externals: Update MoltenVK (#2280) Small fix for pipeline serialization from last change. --- externals/MoltenVK/MoltenVK | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/externals/MoltenVK/MoltenVK b/externals/MoltenVK/MoltenVK index aba997657..0c090001c 160000 --- a/externals/MoltenVK/MoltenVK +++ b/externals/MoltenVK/MoltenVK @@ -1 +1 @@ -Subproject commit aba997657b94d6de1794ebad36ce5634341252c7 +Subproject commit 0c090001cb42997031cfe43914340e2639944972