Skip to content

Commit 9d579e8

Browse files
authored
Merge branch 'shadps4-emu:main' into knack2-menu-fixes
2 parents c1f7665 + e29cf71 commit 9d579e8

79 files changed

Lines changed: 2846 additions & 1102 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,9 @@ set(NP_LIBS src/core/libraries/np/np_error.h
694694
src/core/libraries/np/np_tus/np_tus.cpp
695695
src/core/libraries/np/np_tus/np_tus.h
696696
src/core/libraries/np/np_tus/np_tus_ctx.h
697+
src/core/libraries/np/np_utility/np_utility.cpp
698+
src/core/libraries/np/np_utility/np_utility.h
699+
src/core/libraries/np/np_utility/np_utility_ctx.h
697700
)
698701

699702
set(ZLIB_LIB src/core/libraries/zlib/zlib.cpp
@@ -1020,7 +1023,6 @@ set(SHADER_RECOMPILER src/shader_recompiler/profile.h
10201023
src/shader_recompiler/ir/passes/dead_code_elimination_pass.cpp
10211024
src/shader_recompiler/ir/passes/flatten_extended_userdata_pass.cpp
10221025
src/shader_recompiler/ir/passes/hull_shader_transform.cpp
1023-
src/shader_recompiler/ir/passes/identity_removal_pass.cpp
10241026
src/shader_recompiler/ir/passes/inject_clip_distance_attributes.cpp
10251027
src/shader_recompiler/ir/passes/ir_passes.h
10261028
src/shader_recompiler/ir/passes/lower_buffer_format_to_raw.cpp
@@ -1033,6 +1035,8 @@ set(SHADER_RECOMPILER src/shader_recompiler/profile.h
10331035
src/shader_recompiler/ir/passes/shared_memory_barrier_pass.cpp
10341036
src/shader_recompiler/ir/passes/shared_memory_simplify_pass.cpp
10351037
src/shader_recompiler/ir/passes/shared_memory_to_storage_pass.cpp
1038+
src/shader_recompiler/ir/passes/lower_phis_to_regs_pass.cpp
1039+
src/shader_recompiler/ir/passes/ssa_repair_pass.cpp
10361040
src/shader_recompiler/ir/passes/ssa_rewrite_pass.cpp
10371041
src/shader_recompiler/ir/abstract_syntax_list.cpp
10381042
src/shader_recompiler/ir/abstract_syntax_list.h
@@ -1042,9 +1046,12 @@ set(SHADER_RECOMPILER src/shader_recompiler/profile.h
10421046
src/shader_recompiler/ir/basic_block.h
10431047
src/shader_recompiler/ir/breadth_first_search.h
10441048
src/shader_recompiler/ir/condition.h
1049+
src/shader_recompiler/ir/dominance.cpp
1050+
src/shader_recompiler/ir/dominance.h
10451051
src/shader_recompiler/ir/ir_emitter.cpp
10461052
src/shader_recompiler/ir/ir_emitter.h
10471053
src/shader_recompiler/ir/microinstruction.cpp
1054+
src/shader_recompiler/ir/microinstruction.h
10481055
src/shader_recompiler/ir/opcodes.cpp
10491056
src/shader_recompiler/ir/opcodes.h
10501057
src/shader_recompiler/ir/opcodes.inc
@@ -1057,6 +1064,8 @@ set(SHADER_RECOMPILER src/shader_recompiler/profile.h
10571064
src/shader_recompiler/ir/program.cpp
10581065
src/shader_recompiler/ir/program.h
10591066
src/shader_recompiler/ir/reinterpret.h
1067+
src/shader_recompiler/ir/srt_gvn_table.h
1068+
src/shader_recompiler/ir/ssa.h
10601069
src/shader_recompiler/ir/reg.h
10611070
src/shader_recompiler/ir/type.cpp
10621071
src/shader_recompiler/ir/type.h

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ The following firmware modules are supported and must be placed in shadPS4's `sy
160160
| libSceFreeTypeOt.sprx | libSceJpegDec.sprx | libSceJpegEnc.sprx | libSceJson.sprx |
161161
| libSceJson2.sprx | libSceLibcInternal.sprx | libSceNgs2.sprx | libScePngEnc.sprx |
162162
| libScePsmKitSystem.sprx | libSceRtc.sprx | libSceRudp.sprx | libSceSystemGesture.sprx |
163-
| libSceUlt.sprx | libSceWkFontConfig.sprx | libSceXml.sprx |
163+
| libSceUlt.sprx | libSceWkFontConfig.sprx | libSceXml.sprx | libSceDepth.sprx |
164+
| libScePadTracker.sprx | libSceMoveTracker.sprx |
164165
</div>
165166

166167
> [!Caution]

documents/Debugging/Debugging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ This section will provide some preliminary steps to take and tips on what to do
131131
- **Logs aren't always accurate in determining the reason for a crash.**\
132132
Some log entries are reported as errors but may not be fatal for the execution to stop. `Critical` entries are most likely to be the cause for crashes.
133133

134-
- Pinpoint the area of the emulator where the crash occured\
134+
- Pinpoint the area of the emulator where the crash occurred\
135135
If the stack trace ends with functions that are relevant to rendering, it is safe to assume that the issue is with **rendering**.\
136136
Similarly, if a crash is in a library responsible for playing videos, your issue can be narrowed down to the scope of video playback in the emulator.
137137

src/common/logging/classes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ constexpr auto Lib_NpScore = "Lib.NpScore"; ///< The Lib
7575
constexpr auto Lib_NpSnsFacebookDialog = "Lib.NpSnsFacebookDialog"; ///< The LibSceNpSnsFacebookDialog implementation
7676
constexpr auto Lib_NpTrophy = "Lib.NpTrophy"; ///< The LibSceNpTrophy implementation
7777
constexpr auto Lib_NpTus = "Lib.NpTus"; ///< The LibSceNpTus implementation
78+
constexpr auto Lib_NpUtility = "Lib.NpUtility"; ///< The LibSceNpUtility implementation
7879
constexpr auto Lib_NpWebApi = "Lib.NpWebApi"; ///< The LibSceWebApi implementation
7980
constexpr auto Lib_NpWebApi2 = "Lib.NpWebApi2"; ///< The LibSceWebApi2 implementation
8081
constexpr auto Lib_Pad = "Lib.Pad"; ///< The LibScePad implementation.

src/common/logging/log.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ std::unordered_map<std::string_view, std::shared_ptr<spdlog::logger>> ALL_LOGGER
9999
{Class::Lib_NpSnsFacebookDialog, nullptr},
100100
{Class::Lib_NpTrophy, nullptr},
101101
{Class::Lib_NpTus, nullptr},
102+
{Class::Lib_NpUtility, nullptr},
102103
{Class::Lib_NpWebApi, nullptr},
103104
{Class::Lib_NpWebApi2, nullptr},
104105
{Class::Lib_Pad, nullptr},

src/common/logging/log.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ static constexpr std::array level_string_views{"Trace", "Debug", "Info", "War
5353
// Define the fmt lib macros
5454
#define LOG_GENERIC(log_class, log_level, format, ...) \
5555
do { \
56-
if (auto logger = Common::Log::ALL_LOGGERS[log_class]) { \
56+
if (auto logger = Common::Log::ALL_LOGGERS[log_class]; \
57+
logger && logger->should_log(log_level)) { \
5758
logger->log(log_level, "[{}] <{}> ({}) {}:{} {}: " format, log_class, \
5859
Common::Log::to_string_view(log_level), Common::GetCurrentThreadName(), \
5960
spdlog::source_loc::basename(__FILE__), __LINE__, \

src/common/memory_patcher.cpp

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,31 @@ void OnGameLoaded() {
230230
if (!repo.is_directory()) {
231231
continue;
232232
}
233-
std::ifstream json_file{repo.path() / "files.json"};
234-
nlohmann::json available_patches = nlohmann::json::parse(json_file);
233+
234+
const auto files_json_path = repo.path() / "files.json";
235+
236+
if (!std::filesystem::is_regular_file(files_json_path)) {
237+
LOG_ERROR(Loader, "The folder '{}' does not contain the files.json file.",
238+
repo.path().filename().string());
239+
continue;
240+
}
241+
242+
std::ifstream json_file{files_json_path};
243+
nlohmann::json available_patches;
244+
245+
if (!json_file.is_open()) {
246+
LOG_ERROR(Loader, "Could not open patch index: {}", files_json_path.string());
247+
continue;
248+
}
249+
250+
try {
251+
available_patches = nlohmann::json::parse(json_file);
252+
} catch (const nlohmann::json::parse_error& e) {
253+
LOG_ERROR(Loader, "Could not parse patch index {}: {}", files_json_path.string(),
254+
e.what());
255+
continue;
256+
}
257+
235258
std::filesystem::path game_patch_file;
236259
for (auto const& [filename, serials] : available_patches.items()) {
237260
if (std::find(serials.begin(), serials.end(), g_game_serial) != serials.end()) {

src/core/libraries/camera/camera.cpp

Lines changed: 72 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
#include "core/libraries/camera/camera.h"
88
#include "core/libraries/camera/camera_error.h"
99
#include "core/libraries/error_codes.h"
10+
#include "core/libraries/kernel/memory.h"
1011
#include "core/libraries/kernel/process.h"
1112
#include "core/libraries/libs.h"
13+
#include "core/memory.h"
1214

1315
#include <utility>
1416

@@ -22,6 +24,9 @@ static s32 g_firmware_version = 0;
2224
static s32 g_handles = 0;
2325
static constexpr s32 c_width = 1280, c_height = 800;
2426

27+
static u16 *raw16_buffer1{}, *raw16_buffer2{};
28+
static u8 *raw8_buffer1{}, *raw8_buffer2{};
29+
2530
SDL_Camera* sdl_camera = nullptr;
2631
OrbisCameraConfigExtention output_config0, output_config1;
2732

@@ -180,9 +185,37 @@ s32 PS4_SYSV_ABI sceCameraGetAutoWhiteBalance(s32 handle, OrbisCameraChannel cha
180185
return ORBIS_OK;
181186
}
182187

183-
s32 PS4_SYSV_ABI sceCameraGetCalibData() {
184-
LOG_ERROR(Lib_Camera, "(STUBBED) called");
185-
return ORBIS_CAMERA_ERROR_NOT_CONNECTED;
188+
s32 PS4_SYSV_ABI sceCameraGetCalibData(s32 id, void* calib_data, void* maybe_reserved) {
189+
LOG_WARNING(Lib_Camera, "(DUMMY) called, id: {}", id);
190+
if (calib_data == nullptr) {
191+
return ORBIS_CAMERA_ERROR_PARAM;
192+
}
193+
if (id != 1 && id != 2) {
194+
return ORBIS_OK;
195+
}
196+
static constexpr u64 dumped_calib_data1[32]{
197+
0x000000000b0b0200, 0x00000000bc128639, 0x000000003de79766, 0x00000000be6e2869,
198+
0x3ca0ce1f3e30521c, 0x4452d55e3d0160b6, 0x3cf7fdaa4453abf1, 0x000000003ce3f40f,
199+
0x000000003cdbcaa6, 0x000000003d635f4e, 0x00000000be299439, 0xbb98ddc23e1159b4,
200+
0x44523b6c3c87d83c, 0x3c8d1c46445308a2, 0xbbb83fe03c9bcc40, 0xbab0ed65b8fe93b0,
201+
0xba677004bb598091, 0x3c0eb61e3b49d173, 0xba1bac9f3c67af0b, 0x00000000b9d0e64d,
202+
0x0000000000000000, 0x0000000000000000, 0xb97653e400000000, 0x00000000ba95460e,
203+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
204+
0x0000000000000000, 0x0000000000000000, 0xbab5330000000000, 0x000001013b07a47f,
205+
};
206+
static constexpr u64 dumped_calib_data2[32]{
207+
0x002d000000ff0009, 0x002d0ff70ffd0f14, 0x002d0efe00010008, 0x002f0ffe0f020008,
208+
0x002f000800060105, 0x002e00fc0001000a, 0x0000000000000000, 0x0000000000000000,
209+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
210+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
211+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
212+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
213+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
214+
0x0000000000000000, 0x0000000000000000, 0x0000000000000000, 0x0000000000000000,
215+
};
216+
std::memcpy(calib_data, id == 1 ? dumped_calib_data1 : dumped_calib_data2,
217+
sizeof(dumped_calib_data1));
218+
return ORBIS_OK;
186219
}
187220

188221
s32 PS4_SYSV_ABI sceCameraGetCalibDataFromDevice() {
@@ -335,9 +368,6 @@ s32 PS4_SYSV_ABI sceCameraGetExposureGain(s32 handle, OrbisCameraChannel channel
335368
return ORBIS_OK;
336369
}
337370

338-
static std::vector<u16> raw16_buffer1, raw16_buffer2;
339-
static std::vector<u8> raw8_buffer1, raw8_buffer2;
340-
341371
static void ConvertRGBA8888ToRAW16(const u8* src, u16* dst, int width, int height) {
342372
for (int y = 0; y < height; ++y) {
343373
const u8* row = src + y * width * 4;
@@ -446,30 +476,32 @@ s32 PS4_SYSV_ABI sceCameraGetFrameData(s32 handle, OrbisCameraFrameData* frame_d
446476

447477
switch (output_config0.format.formatLevel0) {
448478
case ORBIS_CAMERA_FORMAT_YUV422:
449-
frame_data->pFramePointerList[0][0] = frame->pixels;
479+
std::memcpy(raw16_buffer1, frame->pixels, c_width * c_height * sizeof(u16));
480+
frame_data->pFramePointerList[0][0] = raw16_buffer1;
450481
break;
451482
case ORBIS_CAMERA_FORMAT_RAW16:
452-
ConvertRGBA8888ToRAW16((u8*)frame->pixels, raw16_buffer1.data(), c_width, c_height);
453-
frame_data->pFramePointerList[0][0] = raw16_buffer1.data();
483+
ConvertRGBA8888ToRAW16((u8*)frame->pixels, raw16_buffer1, c_width, c_height);
484+
frame_data->pFramePointerList[0][0] = raw16_buffer1;
454485
break;
455486
case ORBIS_CAMERA_FORMAT_RAW8:
456-
ConvertRGBA8888ToRAW8((u8*)frame->pixels, raw8_buffer1.data(), c_width, c_height);
457-
frame_data->pFramePointerList[0][0] = raw8_buffer1.data();
487+
ConvertRGBA8888ToRAW8((u8*)frame->pixels, raw8_buffer1, c_width, c_height);
488+
frame_data->pFramePointerList[0][0] = raw8_buffer1;
458489
break;
459490
default:
460491
UNREACHABLE();
461492
}
462493
switch (output_config1.format.formatLevel0) {
463494
case ORBIS_CAMERA_FORMAT_YUV422:
464-
frame_data->pFramePointerList[1][0] = frame->pixels;
495+
std::memcpy(raw16_buffer2, frame->pixels, c_width * c_height * sizeof(u16));
496+
frame_data->pFramePointerList[1][0] = raw16_buffer2;
465497
break;
466498
case ORBIS_CAMERA_FORMAT_RAW16:
467-
ConvertRGBA8888ToRAW16((u8*)frame->pixels, raw16_buffer2.data(), c_width, c_height);
468-
frame_data->pFramePointerList[1][0] = raw16_buffer2.data();
499+
ConvertRGBA8888ToRAW16((u8*)frame->pixels, raw16_buffer2, c_width, c_height);
500+
frame_data->pFramePointerList[1][0] = raw16_buffer2;
469501
break;
470502
case ORBIS_CAMERA_FORMAT_RAW8:
471-
ConvertRGBA8888ToRAW8((u8*)frame->pixels, raw8_buffer2.data(), c_width, c_height);
472-
frame_data->pFramePointerList[1][0] = raw8_buffer2.data();
503+
ConvertRGBA8888ToRAW8((u8*)frame->pixels, raw8_buffer2, c_width, c_height);
504+
frame_data->pFramePointerList[1][0] = raw8_buffer2;
473505
break;
474506
default:
475507
UNREACHABLE();
@@ -688,6 +720,30 @@ s32 PS4_SYSV_ABI sceCameraOpen(Libraries::UserService::OrbisUserServiceUserId us
688720
return ORBIS_CAMERA_ERROR_PARAM;
689721
}
690722

723+
constexpr s32 camera_system_mem_size = 0xfd0000;
724+
void* camera_garlic_pool = (void*)0xfd0000000;
725+
726+
s32 ret = Libraries::Kernel::sceKernelMapNamedSystemFlexibleMemory(
727+
&camera_garlic_pool, camera_system_mem_size,
728+
(s32)(Core::MemoryProt::CpuReadWrite | Core::MemoryProt::GpuRead), 0,
729+
"SceCameraGpuGarlicPool");
730+
ASSERT(ret == ORBIS_OK);
731+
732+
constexpr s32 raw8_buffer_size = c_width * c_height * sizeof(u8);
733+
constexpr s32 raw16_buffer_size = c_width * c_height * sizeof(u16);
734+
735+
u8* remaining_camera_buf = (u8*)camera_garlic_pool;
736+
737+
raw8_buffer1 = remaining_camera_buf += raw8_buffer_size;
738+
raw8_buffer2 = remaining_camera_buf += raw8_buffer_size;
739+
raw16_buffer1 = (u16*)(remaining_camera_buf += raw16_buffer_size);
740+
raw16_buffer2 = (u16*)(remaining_camera_buf += raw16_buffer_size);
741+
742+
ASSERT(remaining_camera_buf <= (u8*)camera_garlic_pool + camera_system_mem_size);
743+
744+
ASSERT(Core::Memory::Instance()->IsValidGpuMapping((VAddr)camera_garlic_pool,
745+
camera_system_mem_size));
746+
691747
g_library_opened = true;
692748
return ++g_handles;
693749
}
@@ -1075,10 +1131,6 @@ s32 PS4_SYSV_ABI sceCameraStart(s32 handle, OrbisCameraStartParameter* param) {
10751131
LOG_INFO(Lib_Camera, "No camera devices connected");
10761132
return ORBIS_CAMERA_ERROR_NOT_CONNECTED;
10771133
}
1078-
raw8_buffer1.resize(c_width * c_height);
1079-
raw16_buffer1.resize(c_width * c_height);
1080-
raw8_buffer2.resize(c_width * c_height);
1081-
raw16_buffer2.resize(c_width * c_height);
10821134
SDL_CameraSpec cam_spec{};
10831135
switch (output_config0.format.formatLevel0) {
10841136
case ORBIS_CAMERA_FORMAT_YUV422:

src/core/libraries/camera/camera.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ s32 PS4_SYSV_ABI sceCameraGetAutoExposureGain(s32 handle, OrbisCameraChannel cha
367367
OrbisCameraAutoExposureGainTarget* option);
368368
s32 PS4_SYSV_ABI sceCameraGetAutoWhiteBalance(s32 handle, OrbisCameraChannel channel, u32* enable,
369369
void* option);
370-
s32 PS4_SYSV_ABI sceCameraGetCalibData();
370+
s32 PS4_SYSV_ABI sceCameraGetCalibData(s32 handle, void* calib_data, void* maybe_reserved);
371371
s32 PS4_SYSV_ABI sceCameraGetCalibDataFromDevice();
372372
s32 PS4_SYSV_ABI sceCameraGetCalibrationData(const OrbisCameraGetCalibrationDataParameter* param,
373373
OrbisCameraCalibrationData* calibration_data);

src/core/libraries/kernel/memory.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ s32 PS4_SYSV_ABI sceKernelReserveVirtualRange(void** addr, u64 len, s32 flags, u
152152
s32 PS4_SYSV_ABI sceKernelMapNamedFlexibleMemory(void** addr_in_out, u64 len, s32 prot, s32 flags,
153153
const char* name);
154154
s32 PS4_SYSV_ABI sceKernelMapFlexibleMemory(void** addr_in_out, u64 len, s32 prot, s32 flags);
155+
s32 PS4_SYSV_ABI sceKernelMapNamedSystemFlexibleMemory(void** addr_in_out, u64 len, s32 prot,
156+
s32 flags, const char* name);
155157
s32 PS4_SYSV_ABI sceKernelQueryMemoryProtection(void* addr, void** start, void** end, u32* prot);
156158

157159
s32 PS4_SYSV_ABI sceKernelMprotect(const void* addr, u64 size, s32 prot);

0 commit comments

Comments
 (0)