From 7c7d04133e54818cbfdd589ef1e0ccda447db56c Mon Sep 17 00:00:00 2001 From: Exhigh Date: Mon, 26 Aug 2024 19:34:35 +0400 Subject: [PATCH 01/36] savedata: Handle another missed case in saveDataMount This should potentially fix (CUSA01019) - The Walking Dead: The Complete First Season. --- src/core/libraries/save_data/savedata.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/libraries/save_data/savedata.cpp b/src/core/libraries/save_data/savedata.cpp index d62e39f8..a6117cba 100644 --- a/src/core/libraries/save_data/savedata.cpp +++ b/src/core/libraries/save_data/savedata.cpp @@ -506,7 +506,9 @@ s32 saveDataMount(u32 user_id, char* dir_name, u32 mount_mode, case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_RDWR | ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_DESTRUCT_OFF | - ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: { + ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: + case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_RDWR | + ORBIS_SAVE_DATA_MOUNT_MODE_DESTRUCT_OFF | ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: { if (std::filesystem::exists(mount_dir)) { return ORBIS_SAVE_DATA_ERROR_EXISTS; } From 3e94b533b6c9840c038e529fb95118ec0dd16c0e Mon Sep 17 00:00:00 2001 From: psucien <168137814+psucien@users.noreply.github.com> Date: Mon, 26 Aug 2024 23:14:22 +0200 Subject: [PATCH 02/36] libraries: kernel: skip for protection op; processing logic fixes (#602) --- .../libraries/kernel/memory_management.cpp | 56 +++++++++++-------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/core/libraries/kernel/memory_management.cpp b/src/core/libraries/kernel/memory_management.cpp index fbc45795..05c6e689 100644 --- a/src/core/libraries/kernel/memory_management.cpp +++ b/src/core/libraries/kernel/memory_management.cpp @@ -254,46 +254,54 @@ int PS4_SYSV_ABI sceKernelMunmap(void* addr, size_t len); s32 PS4_SYSV_ABI sceKernelBatchMap2(OrbisKernelBatchMapEntry* entries, int numEntries, int* numEntriesOut, int flags) { + int result = ORBIS_OK; int processed = 0; - int result = 0; - for (int i = 0; i < numEntries; i++) { + for (int i = 0; i < numEntries; i++, processed++) { if (entries == nullptr || entries[i].length == 0 || entries[i].operation > 4) { result = ORBIS_KERNEL_ERROR_EINVAL; break; // break and assign a value to numEntriesOut. } - if (entries[i].operation == MemoryOpTypes::ORBIS_KERNEL_MAP_OP_MAP_DIRECT) { + switch (entries[i].operation) { + case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_MAP_DIRECT: { result = sceKernelMapNamedDirectMemory(&entries[i].start, entries[i].length, entries[i].protection, flags, static_cast(entries[i].offset), 0, ""); - LOG_INFO( - Kernel_Vmm, - "BatchMap: entry = {}, operation = {}, len = {:#x}, offset = {:#x}, type = {}, " - "result = {}", - i, entries[i].operation, entries[i].length, entries[i].offset, (u8)entries[i].type, - result); - - if (result == 0) - processed++; - } else if (entries[i].operation == MemoryOpTypes::ORBIS_KERNEL_MAP_OP_UNMAP) { + LOG_INFO(Kernel_Vmm, + "entry = {}, operation = {}, len = {:#x}, offset = {:#x}, type = {}, " + "result = {}", + i, entries[i].operation, entries[i].length, entries[i].offset, + (u8)entries[i].type, result); + break; + } + case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_UNMAP: { result = sceKernelMunmap(entries[i].start, entries[i].length); - LOG_INFO(Kernel_Vmm, "BatchMap: entry = {}, operation = {}, len = {:#x}, result = {}", - i, entries[i].operation, entries[i].length, result); - - if (result == 0) - processed++; - } else if (entries[i].operation == MemoryOpTypes::ORBIS_KERNEL_MAP_OP_MAP_FLEXIBLE) { + LOG_INFO(Kernel_Vmm, "entry = {}, operation = {}, len = {:#x}, result = {}", i, + entries[i].operation, entries[i].length, result); + break; + } + case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_MAP_FLEXIBLE: { result = sceKernelMapNamedFlexibleMemory(&entries[i].start, entries[i].length, entries[i].protection, flags, ""); LOG_INFO(Kernel_Vmm, - "BatchMap: entry = {}, operation = {}, len = {:#x}, type = {}, " + "entry = {}, operation = {}, len = {:#x}, type = {}, " "result = {}", i, entries[i].operation, entries[i].length, (u8)entries[i].type, result); + break; + } + case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_TYPE_PROTECT: { + // By now, ignore protection and log it instead + LOG_WARNING(Kernel_Vmm, "entry = {}, operation = {}, len = {:#x}, type = {} " + "is UNSUPPORTED and skipped"); + break; + } + default: { + UNREACHABLE(); + } + } - if (result == 0) - processed++; - } else { - UNREACHABLE_MSG("called: Unimplemented Operation = {}", entries[i].operation); + if (result != ORBIS_OK) { + break; } } if (numEntriesOut != NULL) { // can be zero. do not return an error code. From af4356bfe1c58ee596f29b17ecb79ddb3132596d Mon Sep 17 00:00:00 2001 From: psucien Date: Mon, 26 Aug 2024 23:49:36 +0200 Subject: [PATCH 03/36] shader_recompiler: fix for pattern detection in `TryDisableAnisoLod0` Also fix for forgotten log message params. --- src/core/libraries/kernel/memory_management.cpp | 6 ++++-- src/shader_recompiler/ir/passes/resource_tracking_pass.cpp | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/libraries/kernel/memory_management.cpp b/src/core/libraries/kernel/memory_management.cpp index 05c6e689..ab6aa398 100644 --- a/src/core/libraries/kernel/memory_management.cpp +++ b/src/core/libraries/kernel/memory_management.cpp @@ -291,8 +291,10 @@ s32 PS4_SYSV_ABI sceKernelBatchMap2(OrbisKernelBatchMapEntry* entries, int numEn } case MemoryOpTypes::ORBIS_KERNEL_MAP_OP_TYPE_PROTECT: { // By now, ignore protection and log it instead - LOG_WARNING(Kernel_Vmm, "entry = {}, operation = {}, len = {:#x}, type = {} " - "is UNSUPPORTED and skipped"); + LOG_WARNING(Kernel_Vmm, + "entry = {}, operation = {}, len = {:#x}, type = {} " + "is UNSUPPORTED and skipped", + i, entries[i].operation, entries[i].length, (u8)entries[i].type); break; } default: { diff --git a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp index ccdcfc6e..ace6a37d 100644 --- a/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp +++ b/src/shader_recompiler/ir/passes/resource_tracking_pass.cpp @@ -293,10 +293,11 @@ std::pair TryDisableAnisoLod0(const IR::Inst* inst) { return not_found; } - // The bits range is for lods + // The bits range is for lods (note that constants are changed after constant propagation pass) const auto* prod0_arg0 = prod0->Arg(0).InstRecursive(); if (prod0_arg0->GetOpcode() != IR::Opcode::BitFieldUExtract || - prod0_arg0->Arg(1).InstRecursive()->Arg(0).U32() != 0x0008000cu) { + !(prod0_arg0->Arg(1).IsIdentity() && prod0_arg0->Arg(1).U32() == 12) || + !(prod0_arg0->Arg(2).IsIdentity() && prod0_arg0->Arg(2).U32() == 8)) { return not_found; } From 7ecc1d3be0ec13b7370b8c72c80097d2b9c482b1 Mon Sep 17 00:00:00 2001 From: SolidStateDj Date: Mon, 26 Aug 2024 18:27:31 -0400 Subject: [PATCH 04/36] Add a toggle fullscreen button Assigns F11 as the key for toggling fullscreen. --- src/sdl_window.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index eec31c90..ff44e6c3 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -273,6 +273,15 @@ void WindowSDL::onKeyPress(const SDL_Event* event) { case SDLK_SPACE: button = OrbisPadButtonDataOffset::ORBIS_PAD_BUTTON_TOUCH_PAD; break; + case SDLK_F11: + if (event->type == SDL_EVENT_KEY_DOWN) { + { + SDL_WindowFlags flag = SDL_GetWindowFlags(window); + bool is_fullscreen = flag & SDL_WINDOW_FULLSCREEN; + SDL_SetWindowFullscreen(window, !is_fullscreen); + } + } + break; default: break; } From 2d354a095ae41cf58d72cf8ec88fffcd84dd4d68 Mon Sep 17 00:00:00 2001 From: Vladislav Mikhalin Date: Tue, 27 Aug 2024 09:32:42 +0300 Subject: [PATCH 05/36] AvPlayer: Handle Initialization errors --- .../avplayer/avplayer_data_streamer.h | 3 + .../avplayer/avplayer_file_streamer.cpp | 30 +++++---- .../avplayer/avplayer_file_streamer.h | 4 +- src/core/libraries/avplayer/avplayer_impl.cpp | 9 ++- .../libraries/avplayer/avplayer_source.cpp | 64 +++++++++++-------- src/core/libraries/avplayer/avplayer_source.h | 8 +-- .../libraries/avplayer/avplayer_state.cpp | 37 +++++++---- src/core/libraries/avplayer/avplayer_state.h | 6 +- 8 files changed, 95 insertions(+), 66 deletions(-) diff --git a/src/core/libraries/avplayer/avplayer_data_streamer.h b/src/core/libraries/avplayer/avplayer_data_streamer.h index 04097bb4..319c88a9 100644 --- a/src/core/libraries/avplayer/avplayer_data_streamer.h +++ b/src/core/libraries/avplayer/avplayer_data_streamer.h @@ -7,6 +7,8 @@ #include "common/types.h" +#include + struct AVIOContext; namespace Libraries::AvPlayer { @@ -14,6 +16,7 @@ namespace Libraries::AvPlayer { class IDataStreamer { public: virtual ~IDataStreamer() = default; + virtual bool Init(std::string_view path) = 0; virtual AVIOContext* GetContext() = 0; }; diff --git a/src/core/libraries/avplayer/avplayer_file_streamer.cpp b/src/core/libraries/avplayer/avplayer_file_streamer.cpp index dc1386a4..c7bd5b5d 100644 --- a/src/core/libraries/avplayer/avplayer_file_streamer.cpp +++ b/src/core/libraries/avplayer/avplayer_file_streamer.cpp @@ -18,19 +18,8 @@ extern "C" { namespace Libraries::AvPlayer { -AvPlayerFileStreamer::AvPlayerFileStreamer(const SceAvPlayerFileReplacement& file_replacement, - std::string_view path) - : m_file_replacement(file_replacement) { - const auto ptr = m_file_replacement.object_ptr; - m_fd = m_file_replacement.open(ptr, path.data()); - ASSERT(m_fd >= 0); - m_file_size = m_file_replacement.size(ptr); - // avio_buffer is deallocated in `avio_context_free` - const auto avio_buffer = reinterpret_cast(av_malloc(AVPLAYER_AVIO_BUFFER_SIZE)); - m_avio_context = - avio_alloc_context(avio_buffer, AVPLAYER_AVIO_BUFFER_SIZE, 0, this, - &AvPlayerFileStreamer::ReadPacket, nullptr, &AvPlayerFileStreamer::Seek); -} +AvPlayerFileStreamer::AvPlayerFileStreamer(const SceAvPlayerFileReplacement& file_replacement) + : m_file_replacement(file_replacement) {} AvPlayerFileStreamer::~AvPlayerFileStreamer() { if (m_avio_context != nullptr) { @@ -43,6 +32,21 @@ AvPlayerFileStreamer::~AvPlayerFileStreamer() { } } +bool AvPlayerFileStreamer::Init(std::string_view path) { + const auto ptr = m_file_replacement.object_ptr; + m_fd = m_file_replacement.open(ptr, path.data()); + if (m_fd < 0) { + return false; + } + m_file_size = m_file_replacement.size(ptr); + // avio_buffer is deallocated in `avio_context_free` + const auto avio_buffer = reinterpret_cast(av_malloc(AVPLAYER_AVIO_BUFFER_SIZE)); + m_avio_context = + avio_alloc_context(avio_buffer, AVPLAYER_AVIO_BUFFER_SIZE, 0, this, + &AvPlayerFileStreamer::ReadPacket, nullptr, &AvPlayerFileStreamer::Seek); + return true; +} + s32 AvPlayerFileStreamer::ReadPacket(void* opaque, u8* buffer, s32 size) { const auto self = reinterpret_cast(opaque); if (self->m_position >= self->m_file_size) { diff --git a/src/core/libraries/avplayer/avplayer_file_streamer.h b/src/core/libraries/avplayer/avplayer_file_streamer.h index 658ce8c1..034e40dd 100644 --- a/src/core/libraries/avplayer/avplayer_file_streamer.h +++ b/src/core/libraries/avplayer/avplayer_file_streamer.h @@ -15,9 +15,11 @@ namespace Libraries::AvPlayer { class AvPlayerFileStreamer : public IDataStreamer { public: - AvPlayerFileStreamer(const SceAvPlayerFileReplacement& file_replacement, std::string_view path); + AvPlayerFileStreamer(const SceAvPlayerFileReplacement& file_replacement); ~AvPlayerFileStreamer(); + bool Init(std::string_view path) override; + AVIOContext* GetContext() override { return m_avio_context; } diff --git a/src/core/libraries/avplayer/avplayer_impl.cpp b/src/core/libraries/avplayer/avplayer_impl.cpp index cdfff827..6de7b4c2 100644 --- a/src/core/libraries/avplayer/avplayer_impl.cpp +++ b/src/core/libraries/avplayer/avplayer_impl.cpp @@ -110,7 +110,7 @@ s32 AvPlayer::AddSource(std::string_view path) { if (path.empty()) { return ORBIS_AVPLAYER_ERROR_INVALID_PARAMS; } - if (AVPLAYER_IS_ERROR(m_state->AddSource(path, GetSourceType(path)))) { + if (!m_state->AddSource(path, GetSourceType(path))) { return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED; } return ORBIS_OK; @@ -128,7 +128,7 @@ s32 AvPlayer::GetStreamCount() { } s32 AvPlayer::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) { - if (AVPLAYER_IS_ERROR(m_state->GetStreamInfo(stream_index, info))) { + if (!m_state->GetStreamInfo(stream_index, info)) { return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED; } return ORBIS_OK; @@ -145,7 +145,10 @@ s32 AvPlayer::EnableStream(u32 stream_index) { } s32 AvPlayer::Start() { - return m_state->Start(); + if (!m_state->Start()) { + return ORBIS_AVPLAYER_ERROR_OPERATION_FAILED; + } + return ORBIS_OK; } bool AvPlayer::GetVideoData(SceAvPlayerFrameInfo& video_info) { diff --git a/src/core/libraries/avplayer/avplayer_source.cpp b/src/core/libraries/avplayer/avplayer_source.cpp index 2e4ea8aa..99ba2e8b 100644 --- a/src/core/libraries/avplayer/avplayer_source.cpp +++ b/src/core/libraries/avplayer/avplayer_source.cpp @@ -24,31 +24,39 @@ namespace Libraries::AvPlayer { using namespace Kernel; -AvPlayerSource::AvPlayerSource(AvPlayerStateCallback& state, std::string_view path, - const SceAvPlayerInitData& init_data, - SceAvPlayerSourceType source_type) - : m_state(state), m_memory_replacement(init_data.memory_replacement), - m_num_output_video_framebuffers( - std::min(std::max(2, init_data.num_output_video_framebuffers), 16)) { - AVFormatContext* context = avformat_alloc_context(); - if (init_data.file_replacement.open != nullptr) { - m_up_data_streamer = - std::make_unique(init_data.file_replacement, path); - context->pb = m_up_data_streamer->GetContext(); - ASSERT(!AVPLAYER_IS_ERROR(avformat_open_input(&context, nullptr, nullptr, nullptr))); - } else { - const auto mnt = Common::Singleton::Instance(); - const auto filepath = mnt->GetHostPath(path); - ASSERT(!AVPLAYER_IS_ERROR( - avformat_open_input(&context, filepath.string().c_str(), nullptr, nullptr))); - } - m_avformat_context = AVFormatContextPtr(context, &ReleaseAVFormatContext); -} +AvPlayerSource::AvPlayerSource(AvPlayerStateCallback& state) : m_state(state) {} AvPlayerSource::~AvPlayerSource() { Stop(); } +bool AvPlayerSource::Init(const SceAvPlayerInitData& init_data, std::string_view path) { + m_memory_replacement = init_data.memory_replacement, + m_num_output_video_framebuffers = + std::min(std::max(2, init_data.num_output_video_framebuffers), 16); + + AVFormatContext* context = avformat_alloc_context(); + if (init_data.file_replacement.open != nullptr) { + m_up_data_streamer = std::make_unique(init_data.file_replacement); + if (!m_up_data_streamer->Init(path)) { + return false; + } + context->pb = m_up_data_streamer->GetContext(); + if (AVPLAYER_IS_ERROR(avformat_open_input(&context, nullptr, nullptr, nullptr))) { + return false; + } + } else { + const auto mnt = Common::Singleton::Instance(); + const auto filepath = mnt->GetHostPath(path); + if (AVPLAYER_IS_ERROR( + avformat_open_input(&context, filepath.string().c_str(), nullptr, nullptr))) { + return false; + } + } + m_avformat_context = AVFormatContextPtr(context, &ReleaseAVFormatContext); + return true; +} + bool AvPlayerSource::FindStreamInfo() { if (m_avformat_context == nullptr) { LOG_ERROR(Lib_AvPlayer, "Could not find stream info. NULL context."); @@ -87,16 +95,16 @@ static f32 AVRationalToF32(const AVRational rational) { return f32(rational.num) / rational.den; } -s32 AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) { +bool AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) { info = {}; if (m_avformat_context == nullptr || stream_index >= m_avformat_context->nb_streams) { LOG_ERROR(Lib_AvPlayer, "Could not get stream {} info.", stream_index); - return -1; + return false; } const auto p_stream = m_avformat_context->streams[stream_index]; if (p_stream == nullptr || p_stream->codecpar == nullptr) { LOG_ERROR(Lib_AvPlayer, "Could not get stream {} info. NULL stream.", stream_index); - return -1; + return false; } info.type = CodecTypeToStreamType(p_stream->codecpar->codec_type); info.start_time = p_stream->start_time; @@ -140,9 +148,9 @@ s32 AvPlayerSource::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) break; default: LOG_ERROR(Lib_AvPlayer, "Stream {} type is unknown: {}.", stream_index, info.type); - return -1; + return false; } - return 0; + return true; } bool AvPlayerSource::EnableStream(u32 stream_index) { @@ -215,12 +223,12 @@ std::optional AvPlayerSource::HasFrames(u32 num_frames) { return m_video_packets.Size() > num_frames || m_is_eof; } -s32 AvPlayerSource::Start() { +bool AvPlayerSource::Start() { std::unique_lock lock(m_state_mutex); if (m_audio_codec_context == nullptr && m_video_codec_context == nullptr) { LOG_ERROR(Lib_AvPlayer, "Could not start playback. NULL context."); - return -1; + return false; } m_demuxer_thread = std::jthread([this](std::stop_token stop) { this->DemuxerThread(stop); }); m_video_decoder_thread = @@ -228,7 +236,7 @@ s32 AvPlayerSource::Start() { m_audio_decoder_thread = std::jthread([this](std::stop_token stop) { this->AudioDecoderThread(stop); }); m_start_time = std::chrono::high_resolution_clock::now(); - return 0; + return true; } bool AvPlayerSource::Stop() { diff --git a/src/core/libraries/avplayer/avplayer_source.h b/src/core/libraries/avplayer/avplayer_source.h index 7144e7ee..90612214 100644 --- a/src/core/libraries/avplayer/avplayer_source.h +++ b/src/core/libraries/avplayer/avplayer_source.h @@ -120,17 +120,17 @@ private: class AvPlayerSource { public: - AvPlayerSource(AvPlayerStateCallback& state, std::string_view path, - const SceAvPlayerInitData& init_data, SceAvPlayerSourceType source_type); + AvPlayerSource(AvPlayerStateCallback& state); ~AvPlayerSource(); + bool Init(const SceAvPlayerInitData& init_data, std::string_view path); bool FindStreamInfo(); s32 GetStreamCount(); - s32 GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info); + bool GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info); bool EnableStream(u32 stream_index); void SetLooping(bool is_looping); std::optional HasFrames(u32 num_frames); - s32 Start(); + bool Start(); bool Stop(); bool GetAudioData(SceAvPlayerFrameInfo& audio_info); bool GetVideoData(SceAvPlayerFrameInfo& video_info); diff --git a/src/core/libraries/avplayer/avplayer_state.cpp b/src/core/libraries/avplayer/avplayer_state.cpp index cb3be2f5..a512063f 100644 --- a/src/core/libraries/avplayer/avplayer_state.cpp +++ b/src/core/libraries/avplayer/avplayer_state.cpp @@ -24,6 +24,7 @@ void PS4_SYSV_ABI AvPlayerState::AutoPlayEventCallback(void* opaque, s32 event_i s32 timedtext_stream_index = -1; const s32 stream_count = self->GetStreamCount(); if (AVPLAYER_IS_ERROR(stream_count)) { + self->Stop(); return; } if (stream_count == 0) { @@ -32,7 +33,10 @@ void PS4_SYSV_ABI AvPlayerState::AutoPlayEventCallback(void* opaque, s32 event_i } for (u32 stream_index = 0; stream_index < stream_count; ++stream_index) { SceAvPlayerStreamInfo info{}; - self->GetStreamInfo(stream_index, info); + if (!self->GetStreamInfo(stream_index, info)) { + self->Stop(); + return; + } const std::string_view default_language( reinterpret_cast(self->m_default_language)); @@ -116,23 +120,28 @@ AvPlayerState::~AvPlayerState() { } // Called inside GAME thread -s32 AvPlayerState::AddSource(std::string_view path, SceAvPlayerSourceType source_type) { +bool AvPlayerState::AddSource(std::string_view path, SceAvPlayerSourceType source_type) { if (path.empty()) { LOG_ERROR(Lib_AvPlayer, "File path is empty."); - return -1; + return false; } { std::unique_lock lock(m_source_mutex); if (m_up_source != nullptr) { LOG_ERROR(Lib_AvPlayer, "Only one source is supported."); - return -1; + return false; } - m_up_source = std::make_unique(*this, path, m_init_data, source_type); + m_up_source = std::make_unique(*this); + if (!m_up_source->Init(m_init_data, path)) { + SetState(AvState::Error); + m_up_source.reset(); + return false; + } } AddSourceEvent(); - return 0; + return true; } // Called inside GAME thread @@ -146,25 +155,25 @@ s32 AvPlayerState::GetStreamCount() { } // Called inside GAME thread -s32 AvPlayerState::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) { +bool AvPlayerState::GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info) { std::shared_lock lock(m_source_mutex); if (m_up_source == nullptr) { LOG_ERROR(Lib_AvPlayer, "Could not get stream {} info. No source.", stream_index); - return -1; + return false; } return m_up_source->GetStreamInfo(stream_index, info); } // Called inside GAME thread -s32 AvPlayerState::Start() { +bool AvPlayerState::Start() { std::shared_lock lock(m_source_mutex); - if (m_up_source == nullptr || m_up_source->Start() < 0) { + if (m_up_source == nullptr || !m_up_source->Start()) { LOG_ERROR(Lib_AvPlayer, "Could not start playback."); - return -1; + return false; } SetState(AvState::Play); OnPlaybackStateChanged(AvState::Play); - return 0; + return true; } void AvPlayerState::AvControllerThread(std::stop_token stop) { @@ -219,10 +228,10 @@ bool AvPlayerState::Stop() { if (m_up_source == nullptr || m_current_state == AvState::Stop) { return false; } - if (!SetState(AvState::Stop)) { + if (!m_up_source->Stop()) { return false; } - if (!m_up_source->Stop()) { + if (!SetState(AvState::Stop)) { return false; } OnPlaybackStateChanged(AvState::Stop); diff --git a/src/core/libraries/avplayer/avplayer_state.h b/src/core/libraries/avplayer/avplayer_state.h index ff80b6ce..a5a3bd68 100644 --- a/src/core/libraries/avplayer/avplayer_state.h +++ b/src/core/libraries/avplayer/avplayer_state.h @@ -24,11 +24,11 @@ public: AvPlayerState(const SceAvPlayerInitData& init_data); ~AvPlayerState(); - s32 AddSource(std::string_view filename, SceAvPlayerSourceType source_type); + bool AddSource(std::string_view filename, SceAvPlayerSourceType source_type); s32 GetStreamCount(); - s32 GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info); + bool GetStreamInfo(u32 stream_index, SceAvPlayerStreamInfo& info); bool EnableStream(u32 stream_index); - s32 Start(); + bool Start(); bool Stop(); bool GetAudioData(SceAvPlayerFrameInfo& audio_info); bool GetVideoData(SceAvPlayerFrameInfo& video_info); From 288db9a0cfe2d34041f6f1e5cc0029efa4681de5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Hage?= <33609333+greggameplayer@users.noreply.github.com> Date: Tue, 27 Aug 2024 13:15:32 +0200 Subject: [PATCH 06/36] Implement V_LSHL_B64 (#608) --- src/shader_recompiler/frontend/translate/translate.h | 1 + .../frontend/translate/vector_alu.cpp | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/shader_recompiler/frontend/translate/translate.h b/src/shader_recompiler/frontend/translate/translate.h index 6de5e367..cde9e58e 100644 --- a/src/shader_recompiler/frontend/translate/translate.h +++ b/src/shader_recompiler/frontend/translate/translate.h @@ -117,6 +117,7 @@ public: void V_AND_B32(const GcnInst& inst); void V_LSHLREV_B32(const GcnInst& inst); void V_LSHL_B32(const GcnInst& inst); + void V_LSHL_B64(const GcnInst& inst); void V_ADD_I32(const GcnInst& inst); void V_ADDC_U32(const GcnInst& inst); void V_CVT_F32_I32(const GcnInst& inst); diff --git a/src/shader_recompiler/frontend/translate/vector_alu.cpp b/src/shader_recompiler/frontend/translate/vector_alu.cpp index 99543a20..274dcff1 100644 --- a/src/shader_recompiler/frontend/translate/vector_alu.cpp +++ b/src/shader_recompiler/frontend/translate/vector_alu.cpp @@ -11,6 +11,8 @@ void Translator::EmitVectorAlu(const GcnInst& inst) { return V_LSHLREV_B32(inst); case Opcode::V_LSHL_B32: return V_LSHL_B32(inst); + case Opcode::V_LSHL_B64: + return V_LSHL_B64(inst); case Opcode::V_BFREV_B32: return V_BFREV_B32(inst); case Opcode::V_BFE_U32: @@ -390,6 +392,16 @@ void Translator::V_LSHL_B32(const GcnInst& inst) { SetDst(inst.dst[0], ir.ShiftLeftLogical(src0, ir.BitwiseAnd(src1, ir.Imm32(0x1F)))); } +void Translator::V_LSHL_B64(const GcnInst& inst) { + const IR::U64 src0{GetSrc64(inst.src[0])}; + const IR::U64 src1{GetSrc64(inst.src[1])}; + const IR::VectorReg dst_reg{inst.dst[0].code}; + ASSERT_MSG(src0.IsImmediate() && src0.U64() == 0 && src1.IsImmediate() && src1.U64() == 0, + "V_LSHL_B64 with non-zero src0 or src1 is not supported"); + ir.SetVectorReg(dst_reg, ir.Imm32(0)); + ir.SetVectorReg(dst_reg + 1, ir.Imm32(0)); +} + void Translator::V_ADD_I32(const GcnInst& inst) { const IR::U32 src0{GetSrc(inst.src[0])}; const IR::U32 src1{ir.GetVectorReg(IR::VectorReg(inst.src[1].code))}; From 59b651be07dd83217f63843a1bbfe149ea6f54e1 Mon Sep 17 00:00:00 2001 From: Lizardy <6063922+lzardy@users.noreply.github.com> Date: Tue, 27 Aug 2024 08:53:38 -0400 Subject: [PATCH 07/36] [Libs] Error Codes (#612) * ngs2: all errors w/ official names * ajm errors * gnm errors * random errors * clang * random error * linux --------- Co-authored-by: microsoftv <6063922+microsoftv@users.noreply.github.com> --- CMakeLists.txt | 3 + src/core/libraries/ajm/ajm.cpp | 5 +- src/core/libraries/ajm/ajm_error.h | 28 +++++ src/core/libraries/error_codes.h | 11 -- src/core/libraries/gnmdriver/gnm_error.h | 85 ++++++++++++++ src/core/libraries/gnmdriver/gnmdriver.cpp | 4 +- src/core/libraries/ngs2/ngs2_error.h | 124 +++++++++++++++------ src/core/libraries/ngs2/ngs2_impl.cpp | 4 +- src/core/libraries/random/random.cpp | 6 +- src/core/libraries/random/random.h | 2 +- src/core/libraries/random/random_error.h | 8 ++ 11 files changed, 230 insertions(+), 50 deletions(-) create mode 100644 src/core/libraries/ajm/ajm_error.h create mode 100644 src/core/libraries/gnmdriver/gnm_error.h create mode 100644 src/core/libraries/random/random_error.h diff --git a/CMakeLists.txt b/CMakeLists.txt index decc27b1..6450eaf1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -152,6 +152,7 @@ set(AUDIO_LIB src/core/libraries/audio/audioin.cpp set(GNM_LIB src/core/libraries/gnmdriver/gnmdriver.cpp src/core/libraries/gnmdriver/gnmdriver.h + src/core/libraries/gnmdriver/gnm_error.h ) set(KERNEL_LIB @@ -233,6 +234,7 @@ set(SYSTEM_LIBS src/core/libraries/system/commondialog.cpp src/core/libraries/ngs2/ngs2_error.h src/core/libraries/ngs2/ngs2_impl.cpp src/core/libraries/ngs2/ngs2_impl.h + src/core/libraries/ajm/ajm_error.h ) set(VIDEOOUT_LIB src/core/libraries/videoout/buffer.h @@ -268,6 +270,7 @@ set(PLAYGO_LIB src/core/libraries/playgo/playgo.cpp set(RANDOM_LIB src/core/libraries/random/random.cpp src/core/libraries/random/random.h + src/core/libraries/random/random_error.h ) set(USBD_LIB src/core/libraries/usbd/usbd.cpp diff --git a/src/core/libraries/ajm/ajm.cpp b/src/core/libraries/ajm/ajm.cpp index d8d8304a..441a07f6 100644 --- a/src/core/libraries/ajm/ajm.cpp +++ b/src/core/libraries/ajm/ajm.cpp @@ -1,9 +1,10 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -// Generated By moduleGenerator +#include "ajm.h" +#include "ajm_error.h" + #include "common/logging/log.h" -#include "core/libraries/ajm/ajm.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" diff --git a/src/core/libraries/ajm/ajm_error.h b/src/core/libraries/ajm/ajm_error.h new file mode 100644 index 00000000..64129554 --- /dev/null +++ b/src/core/libraries/ajm/ajm_error.h @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +constexpr int ORBIS_AJM_ERROR_UNKNOWN = 0x80930001; +constexpr int ORBIS_AJM_ERROR_INVALID_CONTEXT = 0x80930002; +constexpr int ORBIS_AJM_ERROR_INVALID_INSTANCE = 0x80930003; +constexpr int ORBIS_AJM_ERROR_INVALID_BATCH = 0x80930004; +constexpr int ORBIS_AJM_ERROR_INVALID_PARAMETER = 0x80930005; +constexpr int ORBIS_AJM_ERROR_OUT_OF_MEMORY = 0x80930006; +constexpr int ORBIS_AJM_ERROR_OUT_OF_RESOURCES = 0x80930007; +constexpr int ORBIS_AJM_ERROR_CODEC_NOT_SUPPORTED = 0x80930008; +constexpr int ORBIS_AJM_ERROR_CODEC_ALREADY_REGISTERED = 0x80930009; +constexpr int ORBIS_AJM_ERROR_CODEC_NOT_REGISTERED = 0x8093000A; +constexpr int ORBIS_AJM_ERROR_WRONG_REVISION_FLAG = 0x8093000B; +constexpr int ORBIS_AJM_ERROR_FLAG_NOT_SUPPORTED = 0x8093000C; +constexpr int ORBIS_AJM_ERROR_BUSY = 0x8093000D; +constexpr int ORBIS_AJM_ERROR_BAD_PRIORITY = 0x8093000E; +constexpr int ORBIS_AJM_ERROR_IN_PROGRESS = 0x8093000F; +constexpr int ORBIS_AJM_ERROR_RETRY = 0x80930010; +constexpr int ORBIS_AJM_ERROR_MALFORMED_BATCH = 0x80930011; +constexpr int ORBIS_AJM_ERROR_JOB_CREATION = 0x80930012; +constexpr int ORBIS_AJM_ERROR_INVALID_OPCODE = 0x80930013; +constexpr int ORBIS_AJM_ERROR_PRIORITY_VIOLATION = 0x80930014; +constexpr int ORBIS_AJM_ERROR_BUFFER_TOO_BIG = 0x80930015; +constexpr int ORBIS_AJM_ERROR_INVALID_ADDRESS = 0x80930016; +constexpr int ORBIS_AJM_ERROR_CANCELLED = 0x80930017; diff --git a/src/core/libraries/error_codes.h b/src/core/libraries/error_codes.h index 123edcee..1453b0a8 100644 --- a/src/core/libraries/error_codes.h +++ b/src/core/libraries/error_codes.h @@ -233,9 +233,6 @@ constexpr int SCE_KERNEL_ERROR_ESDKVERSION = 0x80020063; constexpr int SCE_KERNEL_ERROR_ESTART = 0x80020064; constexpr int SCE_KERNEL_ERROR_ESTOP = 0x80020065; -// libSceRandom error codes -constexpr int SCE_RANDOM_ERROR_INVALID = 0x817C0016; - // videoOut constexpr int SCE_VIDEO_OUT_ERROR_INVALID_VALUE = 0x80290001; // invalid argument constexpr int SCE_VIDEO_OUT_ERROR_INVALID_ADDRESS = 0x80290002; // invalid addresses @@ -249,14 +246,6 @@ constexpr int SCE_VIDEO_OUT_ERROR_SLOT_OCCUPIED = 0x80290010; // slot alr constexpr int SCE_VIDEO_OUT_ERROR_FLIP_QUEUE_FULL = 0x80290012; // flip queue is full constexpr int SCE_VIDEO_OUT_ERROR_INVALID_OPTION = 0x8029001A; // Invalid buffer attribute option -// GnmDriver -constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_PIPE_ID = 0x80D17000; -constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_QUEUE_ID = 0x80D17001; -constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_BASE_ADDR = 0x80D17003; -constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_SIZE = 0x80D17002; -constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_READ_PTR_ADDR = 0x80D17004; -constexpr int ORBIS_GNM_ERROR_FAILURE = 0x8EEE00FF; - // Generic constexpr int ORBIS_OK = 0x00000000; constexpr int ORBIS_FAIL = 0xFFFFFFFF; diff --git a/src/core/libraries/gnmdriver/gnm_error.h b/src/core/libraries/gnmdriver/gnm_error.h new file mode 100644 index 00000000..eab684a2 --- /dev/null +++ b/src/core/libraries/gnmdriver/gnm_error.h @@ -0,0 +1,85 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +constexpr int ORBIS_GNM_ERROR_SUBMISSION_FAILED_INVALID_ARGUMENT = 0x80D11000; +constexpr int ORBIS_GNM_ERROR_SUBMISSION_NOT_ENOUGH_RESOURCES = 0x80D11001; +constexpr int ORBIS_GNM_ERROR_SUBMISSION_AND_FLIP_FAILED_INVALID_COMMAND_BUFFER = 0x80D11080; +constexpr int ORBIS_GNM_ERROR_SUBMISSION_AND_FLIP_FAILED_INVALID_QUEUE_FULL = 0x80D11081; +constexpr int ORBIS_GNM_ERROR_SUBMISSION_AND_FLIP_FAILED_REQUEST_FAILED = 0x80D11082; +constexpr int ORBIS_GNM_ERROR_SUBMISSION_FAILED_INTERNAL_ERROR = 0x80D110FF; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING = 0x80D12000; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_RWBUFFER_ROTYPE = 0x80D12001; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_BLENDING = 0x80D12002; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_DRAW_CU_MASK = 0x80D12003; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_MRT_SETUP = 0x80D12004; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_DEPTH_RT_SETUP = 0x80D12005; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WARNING_PS_AND_MRT_FORMAT = 0x80D1200F; +constexpr int ORBIS_GNM_ERROR_VALIDATION_ERROR = 0x80D13000; +constexpr int ORBIS_GNM_ERROR_VALIDATION_VSHARP = 0x80D13001; +constexpr int ORBIS_GNM_ERROR_VALIDATION_TSHARP = 0x80D13002; +constexpr int ORBIS_GNM_ERROR_VALIDATION_RESOURCE = 0x80D13003; +constexpr int ORBIS_GNM_ERROR_VALIDATION_TABLE_MEMORY = 0x80D13004; +constexpr int ORBIS_GNM_ERROR_VALIDATION_WRITE_EVENT_OP = 0x80D13005; +constexpr int ORBIS_GNM_ERROR_VALIDATION_INDEX_BUFFER = 0x80D13006; +constexpr int ORBIS_GNM_ERROR_VALIDATION_TESS_FACTOR_BUFFER = 0x80D13007; +constexpr int ORBIS_GNM_ERROR_VALIDATION_SCRATCH_RING = 0x80D13008; +constexpr int ORBIS_GNM_ERROR_VALIDATION_PRIMITIVE_TYPE = 0x80D13009; +constexpr int ORBIS_GNM_ERROR_VALIDATION_INDEX_SIZE = 0x80D1300A; +constexpr int ORBIS_GNM_ERROR_VALIDATION_INLINE_DRAW_SIZE = 0x80D1300B; +constexpr int ORBIS_GNM_ERROR_VALIDATION_NUM_INPUT_PATCHES = 0x80D1300C; +constexpr int ORBIS_GNM_ERROR_VALIDATION_GS_MODE = 0x80D1300D; +constexpr int ORBIS_GNM_ERROR_VALIDATION_SHADER_ADDRESS = 0x80D1300E; +constexpr int ORBIS_GNM_ERROR_VALIDATION_BORDER_COLOR_TABLE = 0x80D1300F; +constexpr int ORBIS_GNM_ERROR_VALIDATION_SSHARP = 0x80D13010; +constexpr int ORBIS_GNM_ERROR_VALIDATION_DISPATCH_DRAW = 0x80D13011; +constexpr int ORBIS_GNM_ERROR_VALIDATION_ACTIVE_SHADER_STAGE = 0x80D13012; +constexpr int ORBIS_GNM_ERROR_VALIDATION_DCB = 0x80D13013; +constexpr int ORBIS_GNM_ERROR_VALIDATION_MISMATCH_SHADER_STAGE = 0x80D13014; +constexpr int ORBIS_GNM_ERROR_VALIDATION_MRT_SETUP = 0x80D13015; +constexpr int ORBIS_GNM_ERROR_VALIDATION_BAD_OP_CODE = 0x80D13016; +constexpr int ORBIS_GNM_ERROR_VALIDATION_DEPTH_RT_SETUP = 0x80D13017; +constexpr int ORBIS_GNM_ERROR_VALIDATION_NUM_INSTANCES = 0x80D13018; +constexpr int ORBIS_GNM_ERROR_VALIDATION_SRT = 0x80D13019; +constexpr int ORBIS_GNM_ERROR_VALIDATION_INVALID_ARGUMENT = 0x80D13FFD; +constexpr int ORBIS_GNM_ERROR_VALIDATION_FAILED_INTERNAL_ERROR = 0x80D13FFE; +constexpr int ORBIS_GNM_ERROR_VALIDATION_NOT_ENABLED = 0x80D13FFF; +constexpr int ORBIS_GNM_ERROR_CAPTURE_FILE_IO = 0x80D15000; +constexpr int ORBIS_GNM_ERROR_CAPTURE_RAZOR_NOT_LOADED = 0x80D15001; +constexpr int ORBIS_GNM_ERROR_CAPTURE_NOTHING_TO_CAPTURE = 0x80D15002; +constexpr int ORBIS_GNM_ERROR_CAPTURE_FAILED_INTERNAL = 0x80D1500F; +constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_PIPE_ID = 0x80D17000; +constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_QUEUE_ID = 0x80D17001; +constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_SIZE = 0x80D17002; +constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_RING_BASE_ADDR = 0x80D17003; +constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_READ_PTR_ADDR = 0x80D17004; +constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INVALID_PIPE_PRIORITY = 0x80D17005; +constexpr int ORBIS_GNM_ERROR_COMPUTEQUEUE_INTERNAL = 0x80D170FF; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_ARGUMENT = 0x80D19000; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_SHADER = 0x80D19001; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_STALE_HANDLE = 0x80D19002; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_FULL = 0x80D19003; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_NOT_PERMITTED = 0x80D19004; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_OUTPUT_ARGUMENT_IS_NULL = 0x80D19005; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_OWNER_HANDLE_INVALID = 0x80D19006; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_HANDLE_INVALID = 0x80D19007; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_TYPE_INVALID = 0x80D19008; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_GDS_RESOURCE_TYPE_INVALID = 0x80D19009; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_SIZE_INVALID = 0x80D1900A; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_ADDRESS_IS_NULL = 0x80D1900B; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_GDS_OFFSET_INVALID = 0x80D1900C; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_NAME_IS_NULL = 0x80D1900D; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_OWNER_NAME_IS_NULL = 0x80D1900E; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_FIND_CALLBACK_IS_NULL = 0x80D1900F; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_RESOURCE_IS_NOT_SHADER = 0x80D19010; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_USER_MEMORY_PARAM_IS_NULL = 0x80D19011; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_USER_MEMORY_PARAM_NOT_ALIGNED = 0x80D19012; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_NAME_LENGTH_PARAM = 0x80D19013; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_SIZE_PARAM = 0x80D19014; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INVALID_NUM_RESOURCES_PARAM = 0x80D19015; +constexpr int ORBIS_GNM_ERROR_RESOURCE_REGISTRATION_INTERNAL = 0x80D19FFF; +constexpr int ORBIS_GNM_ERROR_GET_GPU_INFO_PARAMETER_NULL = 0x80D1B000; +constexpr int ORBIS_GNM_ERROR_GET_GPU_INFO_FAILED = 0x80D1B001; +constexpr int ORBIS_GNM_ERROR_GET_GPU_INFO_PARAMETER_INVALID = 0x80D1B002; +constexpr int ORBIS_GNM_ERROR_FAILURE = 0x8EEE00FF; diff --git a/src/core/libraries/gnmdriver/gnmdriver.cpp b/src/core/libraries/gnmdriver/gnmdriver.cpp index 95821a03..6b8b070b 100644 --- a/src/core/libraries/gnmdriver/gnmdriver.cpp +++ b/src/core/libraries/gnmdriver/gnmdriver.cpp @@ -1,6 +1,9 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "gnm_error.h" +#include "gnmdriver.h" + #include "common/assert.h" #include "common/config.h" #include "common/debug.h" @@ -9,7 +12,6 @@ #include "common/slot_vector.h" #include "core/address_space.h" #include "core/libraries/error_codes.h" -#include "core/libraries/gnmdriver/gnmdriver.h" #include "core/libraries/kernel/libkernel.h" #include "core/libraries/libs.h" #include "core/libraries/videoout/video_out.h" diff --git a/src/core/libraries/ngs2/ngs2_error.h b/src/core/libraries/ngs2/ngs2_error.h index 254ae26e..2773168e 100644 --- a/src/core/libraries/ngs2/ngs2_error.h +++ b/src/core/libraries/ngs2/ngs2_error.h @@ -3,54 +3,116 @@ #pragma once -constexpr int ORBIS_NGS2_ERROR_INVALID_PARAMETERS = 0x804A0001; -constexpr int ORBIS_NGS2_ERROR_INVALID_MAXIMUM_GRAIN_SAMPLES = 0x804A0050; -constexpr int ORBIS_NGS2_ERROR_INVALID_GRAIN_SAMPLES = 0x804A0051; -constexpr int ORBIS_NGS2_ERROR_INVALID_CHANNELS = 0x804A0052; -constexpr int ORBIS_NGS2_ERROR_INVALD_ADDRESS = 0x804A0053; -constexpr int ORBIS_NGS2_ERROR_INVALD_SIZE = 0x804A0054; +constexpr int ORBIS_NGS2_ERROR_FAIL = 0x804A0001; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_GRAIN_SAMPLES = 0x804A0050; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_GRAIN_SAMPLES = 0x804A0051; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_CHANNELS = 0x804A0052; +constexpr int ORBIS_NGS2_ERROR_INVALID_OUT_ADDRESS = 0x804A0053; +constexpr int ORBIS_NGS2_ERROR_INVALID_OUT_SIZE = 0x804A0054; +constexpr int ORBIS_NGS2_ERROR_INVALID_OPTION_ADDRESS = 0x804A0080; constexpr int ORBIS_NGS2_ERROR_INVALID_OPTION_SIZE = 0x804A0081; -constexpr int ORBIS_NGS2_ERROR_INVALID_RACK_OPTION_MAX_MATRICES = 0x804A0100; -constexpr int ORBIS_NGS2_ERROR_INVALID_RACK_OPTION_MAX_PORTS = 0x804A0101; -constexpr int ORBIS_NGS2_ERROR_INVALID_RACK_OPTION_MAX_INPUT_DELAY_BLOCKS = 0x804A0102; -constexpr int ORBIS_NGS2_ERROR_INVALID_MATRIX_LEVELS = 0x804A0150; -constexpr int ORBIS_NGS2_ERROR_SAMPLER_WAVEFORM_TERMINATED = 0x804A0151; -constexpr int ORBIS_NGS2_ERROR_INVALID_ENVELOPE_POINTS = 0x804A0152; +constexpr int ORBIS_NGS2_ERROR_INVALID_OPTION_FLAG = 0x804A0082; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_MATRICES = 0x804A0100; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_PORTS = 0x804A0101; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_INPUT_DELAY_BLOCKS = 0x804A0102; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_VOICES = 0x804A0103; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_CHANNELS = 0x804A0104; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_CHANNEL_WORKS = 0x804A0105; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_WAVEFORM_BLOCKS = 0x804A0106; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_ENVELOPE_POINTS = 0x804A0107; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_FILTERS = 0x804A0108; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_CODEC_CACHES = 0x804A0109; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_ATRAC9_DECODERS = 0x804A010A; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_ATRAC9_CHANNEL_WORKS = 0x804A010B; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_INPUTS = 0x804A010C; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_MATRIX_LEVELS = 0x804A0150; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_WAVEFORM_BLOCKS = 0x804A0151; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_ENVELOPE_POINTS = 0x804A0152; constexpr int ORBIS_NGS2_ERROR_INVALID_MATRIX_LEVEL_ADDRESS = 0x804A0153; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_WAVEFORM_BLOCK_ADDRESS = 0x804A0154; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_BLOCK_ADDRESS = 0x804A0154; constexpr int ORBIS_NGS2_ERROR_INVALID_ENVELOPE_POINT_ADDRESS = 0x804A0155; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_PEAKMETER_BLOCKS = 0x804A0156; constexpr int ORBIS_NGS2_ERROR_INVALID_HANDLE = 0x804A0200; constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLE_RATE = 0x804A0201; +constexpr int ORBIS_NGS2_ERROR_INVALID_REPORT_TYPE = 0x804A0202; +constexpr int ORBIS_NGS2_ERROR_INVALID_REPORT_HANDLER = 0x804A0203; constexpr int ORBIS_NGS2_ERROR_INVALID_REPORT_HANDLE = 0x804A0204; +constexpr int ORBIS_NGS2_ERROR_EMPTY_REPORT_HANDLE = 0x804A0205; constexpr int ORBIS_NGS2_ERROR_INVALID_BUFFER_INFO = 0x804A0206; constexpr int ORBIS_NGS2_ERROR_INVALID_BUFFER_ADDRESS = 0x804A0207; -constexpr int ORBIS_NGS2_ERROR_INVALID_BUFFER_ALIGNMENT = 0x804A0208; +constexpr int ORBIS_NGS2_ERROR_INVALID_BUFFER_ALIGN = 0x804A0208; constexpr int ORBIS_NGS2_ERROR_INVALID_BUFFER_SIZE = 0x804A0209; constexpr int ORBIS_NGS2_ERROR_INVALID_BUFFER_ALLOCATOR = 0x804A020A; -constexpr int ORBIS_NGS2_ERROR_BUFFER_VERIFY_FAILED = 0x804A020B; -constexpr int ORBIS_NGS2_ERROR_MODULE_PLAYER_DATA_EMPTY = 0x804A020C; +constexpr int ORBIS_NGS2_ERROR_BUFFER_BROKEN = 0x804A020B; +constexpr int ORBIS_NGS2_ERROR_EMPTY_BUFFER = 0x804A020C; constexpr int ORBIS_NGS2_ERROR_INVALID_SYSTEM_HANDLE = 0x804A0230; constexpr int ORBIS_NGS2_ERROR_INVALID_RACK_ID = 0x804A0260; constexpr int ORBIS_NGS2_ERROR_INVALID_RACK_HANDLE = 0x804A0261; constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_HANDLE = 0x804A0300; +constexpr int ORBIS_NGS2_ERROR_UNINIT_VOICE = 0x804A0301; constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_INDEX = 0x804A0302; -constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_EVENT = 0x804A0303; -constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_PORT_INDEX = 0x804A0304; -constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_INPUT_OR_RACK_OCCUPIED = 0x804A0305; -constexpr int ORBIS_NGS2_ERROR_INVALID_CONTROL_ID = 0x804A0308; -constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_CONTROL_PARAMETER = 0x804A0309; -constexpr int ORBIS_NGS2_ERROR_INVALID_PARAMETER_SIZE = 0x804A030A; +constexpr int ORBIS_NGS2_ERROR_INVALID_EVENT_TYPE = 0x804A0303; +constexpr int ORBIS_NGS2_ERROR_INVALID_PORT_INDEX = 0x804A0304; +constexpr int ORBIS_NGS2_ERROR_INVALID_PATCH = 0x804A0305; +constexpr int ORBIS_NGS2_ERROR_EMPTY_CHANNEL_WORK = 0x804A0306; +constexpr int ORBIS_NGS2_ERROR_EMPTY_CODEC_DECODER = 0x804A0307; +constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_CONTROL_ID = 0x804A0308; +constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_CONTROL_ADDRESS = 0x804A0309; +constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_CONTROL_SIZE = 0x804A030A; constexpr int ORBIS_NGS2_ERROR_DETECTED_CIRCULAR_VOICE_CONTROL = 0x804A030B; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_WAVEFORM_DATA = 0x804A0400; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_WAVEFORM_FORMAT = 0x804A0401; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_WAVEFORM_TYPE_NO_ATRAC9_DECODERS = 0x804A0402; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_ATRAC9_CONFIG_DATA = 0x804A0403; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_WAVEFORM_SAMPLE_RATE = 0x804A0404; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_WAVEFORM_FRAME = 0x804A0405; -constexpr int ORBIS_NGS2_ERROR_INVALID_SAMPLER_WAVEFORM_ADDRESS = 0x804A0406; +constexpr int ORBIS_NGS2_ERROR_UNABLE_CALLBACK = 0x804A030C; +constexpr int ORBIS_NGS2_ERROR_INVALID_CALLBACK_FLAG = 0x804A030D; +constexpr int ORBIS_NGS2_ERROR_INVALID_CALLBACK_HANDLER = 0x804A030E; +constexpr int ORBIS_NGS2_ERROR_INVALID_OPERATION = 0x804A030F; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_FORMAT = 0x804A0400; +constexpr int ORBIS_NGS2_ERROR_UNKNOWN_WAVEFORM_FORMAT = 0x804A0401; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_TYPE = 0x804A0402; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_CONFIG = 0x804A0403; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_SAMPLE_RATE = 0x804A0404; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_FRAME = 0x804A0405; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_ADDRESS = 0x804A0406; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_SIZE = 0x804A0407; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_DATA = 0x804A0408; +constexpr int ORBIS_NGS2_ERROR_INVALID_WAVEFORM_BLOCK_NUM_REPEATS = 0x804A0409; constexpr int ORBIS_NGS2_ERROR_INVALID_ENVELOPE_CURVE = 0x804A0500; +constexpr int ORBIS_NGS2_ERROR_INVALID_PEAKMETER_FLAG = 0x804A0510; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_CHORUS_PHASES = 0x804A0520; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_CHORUS_PHASES = 0x804A0521; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_DELAY_LENGTH = 0x804A0530; +constexpr int ORBIS_NGS2_ERROR_INVALID_MAX_DELAY_TAPS = 0x804A0531; +constexpr int ORBIS_NGS2_ERROR_INVALID_DELAY_TYPE = 0x804A0532; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_DELAY_TAPS = 0x804A0533; +constexpr int ORBIS_NGS2_ERROR_INVALID_DELAY_TAP_INFO = 0x804A0534; +constexpr int ORBIS_NGS2_ERROR_INVALID_PITCH_SHIFT_QUALITY = 0x804A0540; constexpr int ORBIS_NGS2_ERROR_INVALID_FILTER_INDEX = 0x804A0600; constexpr int ORBIS_NGS2_ERROR_INVALID_FILTER_TYPE = 0x804A0601; constexpr int ORBIS_NGS2_ERROR_INVALID_FILTER_LOCATION = 0x804A0602; -constexpr int ORBIS_NGS2_ERROR_INVALID_LFE_CUT_OFF_FREQUENCY = 0x804A0603; -constexpr int ORBIS_NGS2_ERROR_INVALID_MATRIX_INDEX_OR_TYPE = 0x804A0700; \ No newline at end of file +constexpr int ORBIS_NGS2_ERROR_INVALID_LFE_FC = 0x804A0603; +constexpr int ORBIS_NGS2_ERROR_INVALID_USER_FX_PARAM_SIZE = 0x804A0650; +constexpr int ORBIS_NGS2_ERROR_INVALID_MATRIX_INDEX = 0x804A0700; +constexpr int ORBIS_NGS2_ERROR_CODEC_UNKNOWN_WAVEFORM = 0x804A0800; +constexpr int ORBIS_NGS2_ERROR_CODEC_EMPTY_INSTANCE = 0x804A0801; +constexpr int ORBIS_NGS2_ERROR_CODEC_EMPTY_CHANNEL = 0x804A0802; +constexpr int ORBIS_NGS2_ERROR_CODEC_SETUP_FAIL = 0x804A0803; +constexpr int ORBIS_NGS2_ERROR_CODEC_RESET_FAIL = 0x804A0804; +constexpr int ORBIS_NGS2_ERROR_CODEC_DECODE_FAIL = 0x804A0805; +constexpr int ORBIS_NGS2_ERROR_INVALID_REVERB_SIZE = 0x804A0900; +constexpr int ORBIS_NGS2_ERROR_INVALID_PAN_UNIT_ANGLE = 0x804A0910; +constexpr int ORBIS_NGS2_ERROR_INVALID_PAN_SPEAKER = 0x804A0911; +constexpr int ORBIS_NGS2_ERROR_INVALID_PAN_MATRIX_FORMAT = 0x804A0912; +constexpr int ORBIS_NGS2_ERROR_INVALID_PAN_WORK = 0x804A0913; +constexpr int ORBIS_NGS2_ERROR_INVALID_PAN_PARAM = 0x804A0914; +constexpr int ORBIS_NGS2_ERROR_INVALID_GEOM_DISTANCE = 0x804A0920; +constexpr int ORBIS_NGS2_ERROR_INVALID_GEOM_LISTENER_ADDRESS = 0x804A0921; +constexpr int ORBIS_NGS2_ERROR_INVALID_GEOM_SOURCE_ADDRESS = 0x804A0922; +constexpr int ORBIS_NGS2_ERROR_INVALID_GEOM_FLAG = 0x804A0923; +constexpr int ORBIS_NGS2_ERROR_INVALID_GEOM_CONE = 0x804A0924; +constexpr int ORBIS_NGS2_ERROR_INVALID_MODULE_ID = 0x804A0A00; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_MODULES = 0x804A0A01; +constexpr int ORBIS_NGS2_ERROR_INVALID_NUM_MODULE_BUFFERS = 0x804A0A02; +constexpr int ORBIS_NGS2_ERROR_INVALID_MODULE_BUFFER_ID = 0x804A0A03; +constexpr int ORBIS_NGS2_ERROR_INVALID_MODULE_STATE_OFFSET = 0x804A0A04; +constexpr int ORBIS_NGS2_ERROR_INVALID_MODULE_STATE_SIZE = 0x804A0A05; +constexpr int ORBIS_NGS2_ERROR_INVALID_VOICE_STATE_SIZE = 0x804A0A06; +constexpr int ORBIS_NGS2_ERROR_INVALID_MODULE_INDEX = 0x804A0B00; +constexpr int ORBIS_NGS2_ERROR_INVALID_MODULE_INFO_SIZE = 0x804A0B01; \ No newline at end of file diff --git a/src/core/libraries/ngs2/ngs2_impl.cpp b/src/core/libraries/ngs2/ngs2_impl.cpp index 50c62f5e..793435d8 100644 --- a/src/core/libraries/ngs2/ngs2_impl.cpp +++ b/src/core/libraries/ngs2/ngs2_impl.cpp @@ -138,13 +138,13 @@ s32 Ngs2::SystemSetupCore(StackBuffer* buf, SystemOptions* options, Ngs2Handle** // Validate maxGrainSamples if (maxGrainSamples < 64 || maxGrainSamples > 1024 || (maxGrainSamples & 0x3F) != 0) { LOG_ERROR(Lib_Ngs2, "Invalid system option (maxGrainSamples={},x64)", maxGrainSamples); - return ORBIS_NGS2_ERROR_INVALID_MAXIMUM_GRAIN_SAMPLES; + return ORBIS_NGS2_ERROR_INVALID_MAX_GRAIN_SAMPLES; } // Validate numGrainSamples if (numGrainSamples < 64 || numGrainSamples > 1024 || (numGrainSamples & 0x3F) != 0) { LOG_ERROR(Lib_Ngs2, "Invalid system option (numGrainSamples={},x64)", numGrainSamples); - return ORBIS_NGS2_ERROR_INVALID_GRAIN_SAMPLES; + return ORBIS_NGS2_ERROR_INVALID_NUM_GRAIN_SAMPLES; } // Validate sampleRate diff --git a/src/core/libraries/random/random.cpp b/src/core/libraries/random/random.cpp index 8147c518..f7cc3fd2 100644 --- a/src/core/libraries/random/random.cpp +++ b/src/core/libraries/random/random.cpp @@ -1,14 +1,16 @@ // SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later +#include "random.h" +#include "random_error.h" + #include "common/logging/log.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" -#include "random.h" namespace Libraries::Random { -s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, size_t size) { +s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, std::size_t size) { LOG_TRACE(Lib_Random, "called"); if (size > SCE_RANDOM_MAX_SIZE) { return SCE_RANDOM_ERROR_INVALID; diff --git a/src/core/libraries/random/random.h b/src/core/libraries/random/random.h index b5f87f87..7bb41f01 100644 --- a/src/core/libraries/random/random.h +++ b/src/core/libraries/random/random.h @@ -11,7 +11,7 @@ class SymbolsResolver; namespace Libraries::Random { constexpr int32_t SCE_RANDOM_MAX_SIZE = 64; -s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, size_t size); +s32 PS4_SYSV_ABI sceRandomGetRandomNumber(u8* buf, std::size_t size); void RegisterlibSceRandom(Core::Loader::SymbolsResolver* sym); } // namespace Libraries::Random \ No newline at end of file diff --git a/src/core/libraries/random/random_error.h b/src/core/libraries/random/random_error.h new file mode 100644 index 00000000..772316ae --- /dev/null +++ b/src/core/libraries/random/random_error.h @@ -0,0 +1,8 @@ +// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +constexpr int SCE_RANDOM_ERROR_INVALID = 0x817C0016; +constexpr int SCE_RANDOM_ERROR_OUT_OF_RESOURCES = 0x817C001C; +constexpr int SCE_RANDOM_ERROR_FATAL = 0x817C00FF; \ No newline at end of file From 371d1d009aa936d9c3d7b022e616714f2ae762be Mon Sep 17 00:00:00 2001 From: psucien Date: Tue, 27 Aug 2024 19:17:23 +0200 Subject: [PATCH 08/36] Added missing headers and 2D MSAA image type --- src/shader_recompiler/frontend/structured_control_flow.cpp | 1 + src/video_core/buffer_cache/buffer.h | 1 + src/video_core/texture_cache/image_info.cpp | 1 + src/video_core/texture_cache/image_view.cpp | 1 + 4 files changed, 4 insertions(+) diff --git a/src/shader_recompiler/frontend/structured_control_flow.cpp b/src/shader_recompiler/frontend/structured_control_flow.cpp index b50205d4..fefc623f 100644 --- a/src/shader_recompiler/frontend/structured_control_flow.cpp +++ b/src/shader_recompiler/frontend/structured_control_flow.cpp @@ -3,6 +3,7 @@ #include #include +#include #include #include #include diff --git a/src/video_core/buffer_cache/buffer.h b/src/video_core/buffer_cache/buffer.h index 5c64ba65..87293c76 100644 --- a/src/video_core/buffer_cache/buffer.h +++ b/src/video_core/buffer_cache/buffer.h @@ -4,6 +4,7 @@ #pragma once #include +#include #include #include #include "common/types.h" diff --git a/src/video_core/texture_cache/image_info.cpp b/src/video_core/texture_cache/image_info.cpp index a073d046..4ac4aee8 100644 --- a/src/video_core/texture_cache/image_info.cpp +++ b/src/video_core/texture_cache/image_info.cpp @@ -34,6 +34,7 @@ static vk::ImageType ConvertImageType(AmdGpu::ImageType type) noexcept { case AmdGpu::ImageType::Color1DArray: return vk::ImageType::e1D; case AmdGpu::ImageType::Color2D: + case AmdGpu::ImageType::Color2DMsaa: case AmdGpu::ImageType::Cube: case AmdGpu::ImageType::Color2DArray: return vk::ImageType::e2D; diff --git a/src/video_core/texture_cache/image_view.cpp b/src/video_core/texture_cache/image_view.cpp index 08be6bdc..00c3833f 100644 --- a/src/video_core/texture_cache/image_view.cpp +++ b/src/video_core/texture_cache/image_view.cpp @@ -17,6 +17,7 @@ vk::ImageViewType ConvertImageViewType(AmdGpu::ImageType type) { case AmdGpu::ImageType::Color1DArray: return vk::ImageViewType::e1DArray; case AmdGpu::ImageType::Color2D: + case AmdGpu::ImageType::Color2DMsaa: return vk::ImageViewType::e2D; case AmdGpu::ImageType::Cube: return vk::ImageViewType::eCube; From 3eb47226d99d49f8750238b085d5b11adfe6f963 Mon Sep 17 00:00:00 2001 From: psucien Date: Tue, 27 Aug 2024 22:24:26 +0200 Subject: [PATCH 09/36] libraries: kernel: fix `scePthreadMutexattrSettype` error value return --- src/core/libraries/kernel/thread_management.cpp | 13 +++++++------ src/core/libraries/kernel/thread_management.h | 5 +++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/core/libraries/kernel/thread_management.cpp b/src/core/libraries/kernel/thread_management.cpp index 567fff18..567ac867 100644 --- a/src/core/libraries/kernel/thread_management.cpp +++ b/src/core/libraries/kernel/thread_management.cpp @@ -510,23 +510,24 @@ int PS4_SYSV_ABI scePthreadMutexattrInit(ScePthreadMutexattr* attr) { int PS4_SYSV_ABI scePthreadMutexattrSettype(ScePthreadMutexattr* attr, int type) { int ptype = PTHREAD_MUTEX_DEFAULT; switch (type) { - case 1: + case ORBIS_PTHREAD_MUTEX_ERRORCHECK: ptype = PTHREAD_MUTEX_ERRORCHECK; break; - case 2: + case ORBIS_PTHREAD_MUTEX_RECURSIVE: ptype = PTHREAD_MUTEX_RECURSIVE; break; - case 3: - case 4: + case ORBIS_PTHREAD_MUTEX_NORMAL: + case ORBIS_PTHREAD_MUTEX_ADAPTIVE: ptype = PTHREAD_MUTEX_NORMAL; break; default: - UNREACHABLE_MSG("Invalid type: {}", type); + return SCE_KERNEL_ERROR_EINVAL; } int result = pthread_mutexattr_settype(&(*attr)->pth_mutex_attr, ptype); + ASSERT(result == 0); - return result == 0 ? SCE_OK : SCE_KERNEL_ERROR_EINVAL; + return SCE_OK; } int PS4_SYSV_ABI scePthreadMutexattrSetprotocol(ScePthreadMutexattr* attr, int protocol) { diff --git a/src/core/libraries/kernel/thread_management.h b/src/core/libraries/kernel/thread_management.h index c5935275..3679af84 100644 --- a/src/core/libraries/kernel/thread_management.h +++ b/src/core/libraries/kernel/thread_management.h @@ -20,6 +20,11 @@ constexpr int ORBIS_KERNEL_PRIO_FIFO_DEFAULT = 700; constexpr int ORBIS_KERNEL_PRIO_FIFO_HIGHEST = 256; constexpr int ORBIS_KERNEL_PRIO_FIFO_LOWEST = 767; +constexpr int ORBIS_PTHREAD_MUTEX_ERRORCHECK = 1; +constexpr int ORBIS_PTHREAD_MUTEX_RECURSIVE = 2; +constexpr int ORBIS_PTHREAD_MUTEX_NORMAL = 3; +constexpr int ORBIS_PTHREAD_MUTEX_ADAPTIVE = 4; + struct PthreadInternal; struct PthreadAttrInternal; struct PthreadMutexInternal; From 659e7a467549ebca374acc859c8a0e3d47c0e0b6 Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Tue, 27 Aug 2024 23:16:14 +0200 Subject: [PATCH 10/36] video_core: Added copyGPUCmdBuffers option --- src/common/config.cpp | 11 +++++++++ src/common/config.h | 2 ++ src/video_core/amdgpu/liverpool.cpp | 37 +++++++++++++++++++++++++++++ src/video_core/amdgpu/liverpool.h | 8 +++++++ 4 files changed, 58 insertions(+) diff --git a/src/common/config.cpp b/src/common/config.cpp index 9f55cbd4..04d67d44 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -20,6 +20,7 @@ static std::string userName = "shadPS4"; static bool isDebugDump = false; static bool isShowSplash = false; static bool isNullGpu = false; +static bool shouldCopyGPUBuffers = false; static bool shouldDumpShaders = false; static bool shouldDumpPM4 = false; static u32 vblankDivider = 1; @@ -93,6 +94,10 @@ bool nullGpu() { return isNullGpu; } +bool copyGPUCmdBuffers() { + return shouldCopyGPUBuffers; +} + bool dumpShaders() { return shouldDumpShaders; } @@ -149,6 +154,10 @@ void setNullGpu(bool enable) { isNullGpu = enable; } +void setCopyGPUCmdBuffers(bool enable) { + shouldCopyGPUBuffers = enable; +} + void setDumpShaders(bool enable) { shouldDumpShaders = enable; } @@ -336,6 +345,7 @@ void load(const std::filesystem::path& path) { screenWidth = toml::find_or(gpu, "screenWidth", screenWidth); screenHeight = toml::find_or(gpu, "screenHeight", screenHeight); isNullGpu = toml::find_or(gpu, "nullGpu", false); + shouldCopyGPUBuffers = toml::find_or(gpu, "copyGPUBuffers", false); shouldDumpShaders = toml::find_or(gpu, "dumpShaders", false); shouldDumpPM4 = toml::find_or(gpu, "dumpPM4", false); vblankDivider = toml::find_or(gpu, "vblankDivider", 1); @@ -414,6 +424,7 @@ void save(const std::filesystem::path& path) { data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenHeight"] = screenHeight; data["GPU"]["nullGpu"] = isNullGpu; + data["GPU"]["copyGPUBuffers"] = shouldCopyGPUBuffers; data["GPU"]["dumpShaders"] = shouldDumpShaders; data["GPU"]["dumpPM4"] = shouldDumpPM4; data["GPU"]["vblankDivider"] = vblankDivider; diff --git a/src/common/config.h b/src/common/config.h index 554515a4..f1347b07 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -24,6 +24,7 @@ s32 getGpuId(); bool debugDump(); bool showSplash(); bool nullGpu(); +bool copyGPUCmdBuffers(); bool dumpShaders(); bool dumpPM4(); bool isRdocEnabled(); @@ -33,6 +34,7 @@ u32 vblankDiv(); void setDebugDump(bool enable); void setShowSplash(bool enable); void setNullGpu(bool enable); +void setCopyGPUCmdBuffers(bool enable); void setDumpShaders(bool enable); void setDumpPM4(bool enable); void setVblankDiv(u32 value); diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 5b3db603..cec3b06b 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -5,6 +5,7 @@ #include "common/debug.h" #include "common/polyfill_thread.h" #include "common/thread.h" +#include "common/config.h" #include "core/libraries/videoout/driver.h" #include "video_core/amdgpu/liverpool.h" #include "video_core/amdgpu/pm4_cmds.h" @@ -568,9 +569,45 @@ Liverpool::Task Liverpool::ProcessCompute(std::span acb, int vqid) { TracyFiberLeave; } +void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& ccb) { + auto& queue = mapped_queues[GfxQueueId]; + + // This is fine because resize doesn't reallocate the buffer on shrink + queue.dcb_buffer.resize(queue.dcb_buffer_offset + dcb.size()); + queue.ccb_buffer.resize(queue.ccb_buffer_offset + dcb.size()); + + u32 prev_dcb_buffer_offset = queue.dcb_buffer_offset; + u32 prev_ccb_buffer_offset = queue.ccb_buffer_offset; + if (!dcb.empty()) { + std::memcpy(queue.dcb_buffer.data() + queue.dcb_buffer_offset, dcb.data(), + dcb.size_bytes()); + queue.dcb_buffer_offset += dcb.size(); + } + + if (!ccb.empty()) { + std::memcpy(queue.ccb_buffer.data() + queue.ccb_buffer_offset, ccb.data(), + ccb.size_bytes()); + queue.ccb_buffer_offset += dcb.size(); + } + + if (!queue.dcb_buffer.empty()) { + dcb = std::span{queue.dcb_buffer.begin() + prev_dcb_buffer_offset, + queue.dcb_buffer.begin() + queue.dcb_buffer_offset}; + } + + if (!queue.ccb_buffer.empty()) { + ccb = std::span{queue.ccb_buffer.begin() + prev_ccb_buffer_offset, + queue.ccb_buffer.begin() + queue.ccb_buffer_offset}; + } +} + void Liverpool::SubmitGfx(std::span dcb, std::span ccb) { auto& queue = mapped_queues[GfxQueueId]; + if (Config::copyGPUCmdBuffers()) { + CopyCmdBuffers(dcb, ccb); + } + auto task = ProcessGraphics(dcb, ccb); { std::scoped_lock lock{queue.m_access}; diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index 2806f330..a4e61c92 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -11,6 +11,7 @@ #include #include #include +#include #include "common/assert.h" #include "common/bit_field.h" @@ -1047,6 +1048,8 @@ public: void SubmitDone() noexcept { std::scoped_lock lk{submit_mutex}; + mapped_queues[GfxQueueId].ccb_buffer_offset = 0; + mapped_queues[GfxQueueId].dcb_buffer_offset = 0; submit_done = true; submit_cv.notify_one(); } @@ -1108,6 +1111,7 @@ private: Handle handle; }; + void CopyCmdBuffers(std::span& dcb, std::span& ccb); Task ProcessGraphics(std::span dcb, std::span ccb); Task ProcessCeUpdate(std::span ccb); Task ProcessCompute(std::span acb, int vqid); @@ -1116,6 +1120,10 @@ private: struct GpuQueue { std::mutex m_access{}; + std::atomic_uint32_t dcb_buffer_offset; + std::atomic_uint32_t ccb_buffer_offset; + std::vector dcb_buffer; + std::vector ccb_buffer; std::queue submits{}; ComputeProgram cs_state{}; }; From 595b845df0f6776cb44201217a7cdc2f7cb679d3 Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Tue, 27 Aug 2024 23:31:04 +0200 Subject: [PATCH 11/36] clang-format fix --- src/video_core/amdgpu/liverpool.cpp | 4 ++-- src/video_core/amdgpu/liverpool.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index cec3b06b..4b8a8315 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -593,8 +593,8 @@ void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& if (!queue.dcb_buffer.empty()) { dcb = std::span{queue.dcb_buffer.begin() + prev_dcb_buffer_offset, queue.dcb_buffer.begin() + queue.dcb_buffer_offset}; - } - + } + if (!queue.ccb_buffer.empty()) { ccb = std::span{queue.ccb_buffer.begin() + prev_ccb_buffer_offset, queue.ccb_buffer.begin() + queue.ccb_buffer_offset}; diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index a4e61c92..c12c8fdb 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -10,8 +10,8 @@ #include #include #include -#include #include +#include #include "common/assert.h" #include "common/bit_field.h" From 3d46a5d4920fdf5ab04fb20e6f86bde87235d77c Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Tue, 27 Aug 2024 23:33:24 +0200 Subject: [PATCH 12/36] Do not shrink buffer's size on submit --- src/video_core/amdgpu/liverpool.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 4b8a8315..93099266 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -573,8 +573,10 @@ void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& auto& queue = mapped_queues[GfxQueueId]; // This is fine because resize doesn't reallocate the buffer on shrink - queue.dcb_buffer.resize(queue.dcb_buffer_offset + dcb.size()); - queue.ccb_buffer.resize(queue.ccb_buffer_offset + dcb.size()); + queue.dcb_buffer.resize( + std::max(queue.dcb_buffer.size(), queue.dcb_buffer_offset + dcb.size())); + queue.ccb_buffer.resize( + std::max(queue.ccb_buffer.size(), queue.ccb_buffer_offset + dcb.size())); u32 prev_dcb_buffer_offset = queue.dcb_buffer_offset; u32 prev_ccb_buffer_offset = queue.ccb_buffer_offset; From 3842993a4310e5f6c392f0898c795a50e5a731a2 Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Wed, 28 Aug 2024 00:21:12 +0200 Subject: [PATCH 13/36] Use input dcb and ccb instead of copy --- src/video_core/amdgpu/liverpool.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 93099266..3db9ff0d 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -572,7 +572,6 @@ Liverpool::Task Liverpool::ProcessCompute(std::span acb, int vqid) { void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& ccb) { auto& queue = mapped_queues[GfxQueueId]; - // This is fine because resize doesn't reallocate the buffer on shrink queue.dcb_buffer.resize( std::max(queue.dcb_buffer.size(), queue.dcb_buffer_offset + dcb.size())); queue.ccb_buffer.resize( @@ -584,20 +583,14 @@ void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& std::memcpy(queue.dcb_buffer.data() + queue.dcb_buffer_offset, dcb.data(), dcb.size_bytes()); queue.dcb_buffer_offset += dcb.size(); + dcb = std::span{queue.dcb_buffer.begin() + prev_dcb_buffer_offset, + queue.dcb_buffer.begin() + queue.dcb_buffer_offset}; } if (!ccb.empty()) { std::memcpy(queue.ccb_buffer.data() + queue.ccb_buffer_offset, ccb.data(), ccb.size_bytes()); queue.ccb_buffer_offset += dcb.size(); - } - - if (!queue.dcb_buffer.empty()) { - dcb = std::span{queue.dcb_buffer.begin() + prev_dcb_buffer_offset, - queue.dcb_buffer.begin() + queue.dcb_buffer_offset}; - } - - if (!queue.ccb_buffer.empty()) { ccb = std::span{queue.ccb_buffer.begin() + prev_ccb_buffer_offset, queue.ccb_buffer.begin() + queue.ccb_buffer_offset}; } From 860b93505423dffed0e2abeb0e278aee2d759210 Mon Sep 17 00:00:00 2001 From: Semenov Herman Date: Wed, 28 Aug 2024 01:32:14 +0300 Subject: [PATCH 14/36] crypto: added destructors fix memleak FakeKeyset, DebugRifKeyset, PkgDerivedKey3Keyset --- src/core/crypto/keys.h | 43 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/src/core/crypto/keys.h b/src/core/crypto/keys.h index 37b66bd0..58466b76 100644 --- a/src/core/crypto/keys.h +++ b/src/core/crypto/keys.h @@ -132,11 +132,22 @@ public: 0x79, 0x9E, 0x7D, 0x8D, 0xCA, 0x18, 0x6D, 0xBD, 0x9E, 0xA1, 0x80, 0x28, 0x6B, 0x2A, 0xFE, 0x51, 0x24, 0x9B, 0x6F, 0x4D, 0x84, 0x77, 0x80, 0x23}; }; + + // Destructor + ~FakeKeyset() { + delete[] PrivateExponent; + delete[] Exponent1; + delete[] Exponent2; + delete[] PublicExponent; + delete[] Coefficient; + delete[] Modulus; + delete[] Prime1; + delete[] Prime2; + }; }; class DebugRifKeyset { public: - // Constructor // std::uint8_t* PrivateExponent; const CryptoPP::byte* Exponent1; // exponent2 = d mod (q - 1) @@ -263,14 +274,22 @@ public: 0x81, 0x1F, 0xDE, 0x5E, 0xA8, 0x6E, 0x3E, 0x87, 0xEC, 0x44, 0xD2, 0x69, 0xC6, 0x54, 0x91, 0x6B, 0x5E, 0x13, 0x8A, 0x03, 0x87, 0x05, 0x31, 0x8D}; }; + + // Destructor + ~DebugRifKeyset() { + delete[] PrivateExponent; + delete[] Exponent1; + delete[] Exponent2; + delete[] PublicExponent; + delete[] Coefficient; + delete[] Modulus; + delete[] Prime1; + delete[] Prime2; + }; }; class PkgDerivedKey3Keyset { public: - // PkgDerivedKey3Keyset(); - //~PkgDerivedKey3Keyset(); - - // Constructor // std::uint8_t* PrivateExponent; const CryptoPP::byte* Exponent1; // exponent2 = d mod (q - 1) @@ -287,8 +306,8 @@ public: const CryptoPP::byte* Prime2; const CryptoPP::byte* PrivateExponent; + // Constructor PkgDerivedKey3Keyset() { - Prime1 = new CryptoPP::byte[0x80]{ 0xF9, 0x67, 0xAD, 0x99, 0x12, 0x31, 0x0C, 0x56, 0xA2, 0x2E, 0x16, 0x1C, 0x46, 0xB3, 0x4D, 0x5B, 0x43, 0xBE, 0x42, 0xA2, 0xF6, 0x86, 0x96, 0x80, 0x42, 0xC3, @@ -387,4 +406,16 @@ public: 0xf9, 0xc9, 0xa3, 0xc1}; PublicExponent = new CryptoPP::byte[4]{0, 1, 0, 1}; }; + + // Destructor + ~PkgDerivedKey3Keyset() { + delete[] Prime1; + delete[] Prime2; + delete[] PrivateExponent; + delete[] Exponent1; + delete[] Exponent2; + delete[] Coefficient; + delete[] Modulus; + delete[] PublicExponent; + }; }; \ No newline at end of file From 1a02efbd156ff7b07bfa306cd94c39862cba8d56 Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Wed, 28 Aug 2024 05:42:48 +0200 Subject: [PATCH 15/36] clang-format style fix --- src/video_core/amdgpu/liverpool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 3db9ff0d..6e49aec4 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -2,10 +2,10 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/assert.h" +#include "common/config.h" #include "common/debug.h" #include "common/polyfill_thread.h" #include "common/thread.h" -#include "common/config.h" #include "core/libraries/videoout/driver.h" #include "video_core/amdgpu/liverpool.h" #include "video_core/amdgpu/pm4_cmds.h" From ed42db47af3ab0cbe92be922110023eda895d34a Mon Sep 17 00:00:00 2001 From: Exhigh Date: Wed, 28 Aug 2024 08:52:20 +0400 Subject: [PATCH 16/36] savedata: Add another missed case in saveDataMount This should potentially fix Deadpool (CUSA03528) #554. --- src/core/libraries/save_data/savedata.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/libraries/save_data/savedata.cpp b/src/core/libraries/save_data/savedata.cpp index a6117cba..eb309183 100644 --- a/src/core/libraries/save_data/savedata.cpp +++ b/src/core/libraries/save_data/savedata.cpp @@ -505,6 +505,7 @@ s32 saveDataMount(u32 user_id, char* dir_name, u32 mount_mode, ORBIS_SAVE_DATA_MOUNT_MODE_DESTRUCT_OFF: case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_RDWR | ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: + case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_DESTRUCT_OFF | ORBIS_SAVE_DATA_MOUNT_MODE_COPY_ICON: case ORBIS_SAVE_DATA_MOUNT_MODE_CREATE | ORBIS_SAVE_DATA_MOUNT_MODE_RDWR | From 87ccfdfbbdb7b98ba1169174096baffcd1d93729 Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Wed, 28 Aug 2024 09:42:31 +0200 Subject: [PATCH 17/36] Fixed type on function --- src/video_core/amdgpu/liverpool.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 6e49aec4..931b5ea8 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -575,7 +575,7 @@ void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& queue.dcb_buffer.resize( std::max(queue.dcb_buffer.size(), queue.dcb_buffer_offset + dcb.size())); queue.ccb_buffer.resize( - std::max(queue.ccb_buffer.size(), queue.ccb_buffer_offset + dcb.size())); + std::max(queue.ccb_buffer.size(), queue.ccb_buffer_offset + ccb.size())); u32 prev_dcb_buffer_offset = queue.dcb_buffer_offset; u32 prev_ccb_buffer_offset = queue.ccb_buffer_offset; @@ -590,7 +590,7 @@ void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& if (!ccb.empty()) { std::memcpy(queue.ccb_buffer.data() + queue.ccb_buffer_offset, ccb.data(), ccb.size_bytes()); - queue.ccb_buffer_offset += dcb.size(); + queue.ccb_buffer_offset += ccb.size(); ccb = std::span{queue.ccb_buffer.begin() + prev_ccb_buffer_offset, queue.ccb_buffer.begin() + queue.ccb_buffer_offset}; } From c37679154eeb59e6bfe73ec2ff99b15096094942 Mon Sep 17 00:00:00 2001 From: Random <28494085+Random06457@users.noreply.github.com> Date: Wed, 28 Aug 2024 09:53:27 +0200 Subject: [PATCH 18/36] Handle PM4 type-2 packets (#556) * video_core: handle PM4 type-2 packets * video_core: rewrite pm4 comand type handling into a switch statement --- src/video_core/amdgpu/liverpool.cpp | 563 ++++++++++++++-------------- 1 file changed, 287 insertions(+), 276 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 5b3db603..7e6ca14d 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -175,294 +175,305 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span dcb, std::span(dcb.data()); const u32 type = header->type; - if (type != 3) { - // No other types of packets were spotted so far - UNREACHABLE_MSG("Invalid PM4 type {}", type); - } - const u32 count = header->type3.NumWords(); - const PM4ItOpcode opcode = header->type3.opcode; - switch (opcode) { - case PM4ItOpcode::Nop: { - const auto* nop = reinterpret_cast(header); - if (nop->header.count.Value() == 0) { - break; - } + switch (type) { + case 0: + case 1: + UNREACHABLE_MSG("Unsupported PM4 type {}", type); + break; + case 2: + // Type-2 packet are used for padding purposes + dcb = dcb.subspan(1); + continue; + case 3: + const u32 count = header->type3.NumWords(); + const PM4ItOpcode opcode = header->type3.opcode; + switch (opcode) { + case PM4ItOpcode::Nop: { + const auto* nop = reinterpret_cast(header); + if (nop->header.count.Value() == 0) { + break; + } - switch (nop->data_block[0]) { - case PM4CmdNop::PayloadType::PatchedFlip: { - // There is no evidence that GPU CP drives flip events by parsing - // special NOP packets. For convenience lets assume that it does. - Platform::IrqC::Instance()->Signal(Platform::InterruptId::GfxFlip); + switch (nop->data_block[0]) { + case PM4CmdNop::PayloadType::PatchedFlip: { + // There is no evidence that GPU CP drives flip events by parsing + // special NOP packets. For convenience lets assume that it does. + Platform::IrqC::Instance()->Signal(Platform::InterruptId::GfxFlip); + break; + } + case PM4CmdNop::PayloadType::DebugMarkerPush: { + const auto marker_sz = nop->header.count.Value() * 2; + const std::string_view label{reinterpret_cast(&nop->data_block[1]), + marker_sz}; + rasterizer->ScopeMarkerBegin(label); + break; + } + case PM4CmdNop::PayloadType::DebugMarkerPop: { + rasterizer->ScopeMarkerEnd(); + break; + } + default: + break; + } break; } - case PM4CmdNop::PayloadType::DebugMarkerPush: { - const auto marker_sz = nop->header.count.Value() * 2; - const std::string_view label{reinterpret_cast(&nop->data_block[1]), - marker_sz}; - rasterizer->ScopeMarkerBegin(label); + case PM4ItOpcode::ContextControl: { break; } - case PM4CmdNop::PayloadType::DebugMarkerPop: { - rasterizer->ScopeMarkerEnd(); + case PM4ItOpcode::ClearState: { + regs.SetDefaults(); + break; + } + case PM4ItOpcode::SetConfigReg: { + const auto* set_data = reinterpret_cast(header); + const auto reg_addr = ConfigRegWordOffset + set_data->reg_offset; + const auto* payload = reinterpret_cast(header + 2); + std::memcpy(®s.reg_array[reg_addr], payload, (count - 1) * sizeof(u32)); + break; + } + case PM4ItOpcode::SetContextReg: { + const auto* set_data = reinterpret_cast(header); + const auto reg_addr = ContextRegWordOffset + set_data->reg_offset; + const auto* payload = reinterpret_cast(header + 2); + + std::memcpy(®s.reg_array[reg_addr], payload, (count - 1) * sizeof(u32)); + + // In the case of HW, render target memory has alignment as color block operates on + // tiles. There is no information of actual resource extents stored in CB context + // regs, so any deduction of it from slices/pitch will lead to a larger surface + // created. The same applies to the depth targets. Fortunately, the guest always + // sends a trailing NOP packet right after the context regs setup, so we can use the + // heuristic below and extract the hint to determine actual resource dims. + + switch (reg_addr) { + case ContextRegs::CbColor0Base: + case ContextRegs::CbColor1Base: + case ContextRegs::CbColor2Base: + case ContextRegs::CbColor3Base: + case ContextRegs::CbColor4Base: + case ContextRegs::CbColor5Base: + case ContextRegs::CbColor6Base: + case ContextRegs::CbColor7Base: { + const auto col_buf_id = (reg_addr - ContextRegs::CbColor0Base) / + (ContextRegs::CbColor1Base - ContextRegs::CbColor0Base); + ASSERT(col_buf_id < NumColorBuffers); + + const auto nop_offset = header->type3.count; + if (nop_offset == 0x0e || nop_offset == 0x0d || nop_offset == 0x0b) { + ASSERT_MSG(payload[nop_offset] == 0xc0001000, + "NOP hint is missing in CB setup sequence"); + last_cb_extent[col_buf_id].raw = payload[nop_offset + 1]; + } else { + last_cb_extent[col_buf_id].raw = 0; + } + break; + } + case ContextRegs::CbColor0Cmask: + case ContextRegs::CbColor1Cmask: + case ContextRegs::CbColor2Cmask: + case ContextRegs::CbColor3Cmask: + case ContextRegs::CbColor4Cmask: + case ContextRegs::CbColor5Cmask: + case ContextRegs::CbColor6Cmask: + case ContextRegs::CbColor7Cmask: { + const auto col_buf_id = + (reg_addr - ContextRegs::CbColor0Cmask) / + (ContextRegs::CbColor1Cmask - ContextRegs::CbColor0Cmask); + ASSERT(col_buf_id < NumColorBuffers); + + const auto nop_offset = header->type3.count; + if (nop_offset == 0x04) { + ASSERT_MSG(payload[nop_offset] == 0xc0001000, + "NOP hint is missing in CB setup sequence"); + last_cb_extent[col_buf_id].raw = payload[nop_offset + 1]; + } + break; + } + case ContextRegs::DbZInfo: { + if (header->type3.count == 8) { + ASSERT_MSG(payload[20] == 0xc0001000, + "NOP hint is missing in DB setup sequence"); + last_db_extent.raw = payload[21]; + } else { + last_db_extent.raw = 0; + } + break; + } + default: + break; + } + break; + } + case PM4ItOpcode::SetShReg: { + const auto* set_data = reinterpret_cast(header); + std::memcpy(®s.reg_array[ShRegWordOffset + set_data->reg_offset], header + 2, + (count - 1) * sizeof(u32)); + break; + } + case PM4ItOpcode::SetUconfigReg: { + const auto* set_data = reinterpret_cast(header); + std::memcpy(®s.reg_array[UconfigRegWordOffset + set_data->reg_offset], + header + 2, (count - 1) * sizeof(u32)); + break; + } + case PM4ItOpcode::IndexType: { + const auto* index_type = reinterpret_cast(header); + regs.index_buffer_type.raw = index_type->raw; + break; + } + case PM4ItOpcode::DrawIndex2: { + const auto* draw_index = reinterpret_cast(header); + regs.max_index_size = draw_index->max_size; + regs.index_base_address.base_addr_lo = draw_index->index_base_lo; + regs.index_base_address.base_addr_hi.Assign(draw_index->index_base_hi); + regs.num_indices = draw_index->index_count; + regs.draw_initiator = draw_index->draw_initiator; + if (rasterizer) { + const auto cmd_address = reinterpret_cast(header); + rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndex2", cmd_address)); + rasterizer->Breadcrumb(u64(cmd_address)); + rasterizer->Draw(true); + rasterizer->ScopeMarkerEnd(); + } + break; + } + case PM4ItOpcode::DrawIndexOffset2: { + const auto* draw_index_off = + reinterpret_cast(header); + regs.max_index_size = draw_index_off->max_size; + regs.num_indices = draw_index_off->index_count; + regs.draw_initiator = draw_index_off->draw_initiator; + if (rasterizer) { + const auto cmd_address = reinterpret_cast(header); + rasterizer->ScopeMarkerBegin( + fmt::format("dcb:{}:DrawIndexOffset2", cmd_address)); + rasterizer->Breadcrumb(u64(cmd_address)); + rasterizer->Draw(true, draw_index_off->index_offset); + rasterizer->ScopeMarkerEnd(); + } + break; + } + case PM4ItOpcode::DrawIndexAuto: { + const auto* draw_index = reinterpret_cast(header); + regs.num_indices = draw_index->index_count; + regs.draw_initiator = draw_index->draw_initiator; + if (rasterizer) { + const auto cmd_address = reinterpret_cast(header); + rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndexAuto", cmd_address)); + rasterizer->Breadcrumb(u64(cmd_address)); + rasterizer->Draw(false); + rasterizer->ScopeMarkerEnd(); + } + break; + } + case PM4ItOpcode::DispatchDirect: { + const auto* dispatch_direct = reinterpret_cast(header); + regs.cs_program.dim_x = dispatch_direct->dim_x; + regs.cs_program.dim_y = dispatch_direct->dim_y; + regs.cs_program.dim_z = dispatch_direct->dim_z; + regs.cs_program.dispatch_initiator = dispatch_direct->dispatch_initiator; + if (rasterizer && (regs.cs_program.dispatch_initiator & 1)) { + const auto cmd_address = reinterpret_cast(header); + rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:Dispatch", cmd_address)); + rasterizer->Breadcrumb(u64(cmd_address)); + rasterizer->DispatchDirect(); + rasterizer->ScopeMarkerEnd(); + } + break; + } + case PM4ItOpcode::NumInstances: { + const auto* num_instances = reinterpret_cast(header); + regs.num_instances.num_instances = num_instances->num_instances; + break; + } + case PM4ItOpcode::IndexBase: { + const auto* index_base = reinterpret_cast(header); + regs.index_base_address.base_addr_lo = index_base->addr_lo; + regs.index_base_address.base_addr_hi.Assign(index_base->addr_hi); + break; + } + case PM4ItOpcode::IndexBufferSize: { + const auto* index_size = reinterpret_cast(header); + regs.num_indices = index_size->num_indices; + break; + } + case PM4ItOpcode::EventWrite: { + // const auto* event = reinterpret_cast(header); + break; + } + case PM4ItOpcode::EventWriteEos: { + const auto* event_eos = reinterpret_cast(header); + event_eos->SignalFence(); + break; + } + case PM4ItOpcode::EventWriteEop: { + const auto* event_eop = reinterpret_cast(header); + event_eop->SignalFence(); + break; + } + case PM4ItOpcode::DmaData: { + const auto* dma_data = reinterpret_cast(header); + break; + } + case PM4ItOpcode::WriteData: { + const auto* write_data = reinterpret_cast(header); + ASSERT(write_data->dst_sel.Value() == 2 || write_data->dst_sel.Value() == 5); + const u32 data_size = (header->type3.count.Value() - 2) * 4; + u64* address = write_data->Address(); + if (!write_data->wr_one_addr.Value()) { + std::memcpy(address, write_data->data, data_size); + } else { + UNREACHABLE(); + } + break; + } + case PM4ItOpcode::AcquireMem: { + // const auto* acquire_mem = reinterpret_cast(header); + break; + } + case PM4ItOpcode::WaitRegMem: { + const auto* wait_reg_mem = reinterpret_cast(header); + // ASSERT(wait_reg_mem->engine.Value() == PM4CmdWaitRegMem::Engine::Me); + // Optimization: VO label waits are special because the emulator + // will write to the label when presentation is finished. So if + // there are no other submits to yield to we can sleep the thread + // instead and allow other tasks to run. + const u64* wait_addr = wait_reg_mem->Address(); + if (vo_port->IsVoLabel(wait_addr) && num_submits == 1) { + vo_port->WaitVoLabel([&] { return wait_reg_mem->Test(); }); + } + while (!wait_reg_mem->Test()) { + mapped_queues[GfxQueueId].cs_state = regs.cs_program; + TracyFiberLeave; + co_yield {}; + TracyFiberEnter(dcb_task_name); + regs.cs_program = mapped_queues[GfxQueueId].cs_state; + } + break; + } + case PM4ItOpcode::IncrementDeCounter: { + ++cblock.de_count; + break; + } + case PM4ItOpcode::WaitOnCeCounter: { + while (cblock.ce_count <= cblock.de_count) { + TracyFiberLeave; + ce_task.handle.resume(); + TracyFiberEnter(dcb_task_name); + } + break; + } + case PM4ItOpcode::PfpSyncMe: { break; } default: - break; + UNREACHABLE_MSG("Unknown PM4 type 3 opcode {:#x} with count {}", + static_cast(opcode), count); } + dcb = dcb.subspan(header->type3.NumWords() + 1); break; } - case PM4ItOpcode::ContextControl: { - break; - } - case PM4ItOpcode::ClearState: { - regs.SetDefaults(); - break; - } - case PM4ItOpcode::SetConfigReg: { - const auto* set_data = reinterpret_cast(header); - const auto reg_addr = ConfigRegWordOffset + set_data->reg_offset; - const auto* payload = reinterpret_cast(header + 2); - std::memcpy(®s.reg_array[reg_addr], payload, (count - 1) * sizeof(u32)); - break; - } - case PM4ItOpcode::SetContextReg: { - const auto* set_data = reinterpret_cast(header); - const auto reg_addr = ContextRegWordOffset + set_data->reg_offset; - const auto* payload = reinterpret_cast(header + 2); - - std::memcpy(®s.reg_array[reg_addr], payload, (count - 1) * sizeof(u32)); - - // In the case of HW, render target memory has alignment as color block operates on - // tiles. There is no information of actual resource extents stored in CB context - // regs, so any deduction of it from slices/pitch will lead to a larger surface created. - // The same applies to the depth targets. Fortunately, the guest always sends - // a trailing NOP packet right after the context regs setup, so we can use the heuristic - // below and extract the hint to determine actual resource dims. - - switch (reg_addr) { - case ContextRegs::CbColor0Base: - case ContextRegs::CbColor1Base: - case ContextRegs::CbColor2Base: - case ContextRegs::CbColor3Base: - case ContextRegs::CbColor4Base: - case ContextRegs::CbColor5Base: - case ContextRegs::CbColor6Base: - case ContextRegs::CbColor7Base: { - const auto col_buf_id = (reg_addr - ContextRegs::CbColor0Base) / - (ContextRegs::CbColor1Base - ContextRegs::CbColor0Base); - ASSERT(col_buf_id < NumColorBuffers); - - const auto nop_offset = header->type3.count; - if (nop_offset == 0x0e || nop_offset == 0x0d || nop_offset == 0x0b) { - ASSERT_MSG(payload[nop_offset] == 0xc0001000, - "NOP hint is missing in CB setup sequence"); - last_cb_extent[col_buf_id].raw = payload[nop_offset + 1]; - } else { - last_cb_extent[col_buf_id].raw = 0; - } - break; - } - case ContextRegs::CbColor0Cmask: - case ContextRegs::CbColor1Cmask: - case ContextRegs::CbColor2Cmask: - case ContextRegs::CbColor3Cmask: - case ContextRegs::CbColor4Cmask: - case ContextRegs::CbColor5Cmask: - case ContextRegs::CbColor6Cmask: - case ContextRegs::CbColor7Cmask: { - const auto col_buf_id = (reg_addr - ContextRegs::CbColor0Cmask) / - (ContextRegs::CbColor1Cmask - ContextRegs::CbColor0Cmask); - ASSERT(col_buf_id < NumColorBuffers); - - const auto nop_offset = header->type3.count; - if (nop_offset == 0x04) { - ASSERT_MSG(payload[nop_offset] == 0xc0001000, - "NOP hint is missing in CB setup sequence"); - last_cb_extent[col_buf_id].raw = payload[nop_offset + 1]; - } - break; - } - case ContextRegs::DbZInfo: { - if (header->type3.count == 8) { - ASSERT_MSG(payload[20] == 0xc0001000, - "NOP hint is missing in DB setup sequence"); - last_db_extent.raw = payload[21]; - } else { - last_db_extent.raw = 0; - } - break; - } - default: - break; - } - break; - } - case PM4ItOpcode::SetShReg: { - const auto* set_data = reinterpret_cast(header); - std::memcpy(®s.reg_array[ShRegWordOffset + set_data->reg_offset], header + 2, - (count - 1) * sizeof(u32)); - break; - } - case PM4ItOpcode::SetUconfigReg: { - const auto* set_data = reinterpret_cast(header); - std::memcpy(®s.reg_array[UconfigRegWordOffset + set_data->reg_offset], header + 2, - (count - 1) * sizeof(u32)); - break; - } - case PM4ItOpcode::IndexType: { - const auto* index_type = reinterpret_cast(header); - regs.index_buffer_type.raw = index_type->raw; - break; - } - case PM4ItOpcode::DrawIndex2: { - const auto* draw_index = reinterpret_cast(header); - regs.max_index_size = draw_index->max_size; - regs.index_base_address.base_addr_lo = draw_index->index_base_lo; - regs.index_base_address.base_addr_hi.Assign(draw_index->index_base_hi); - regs.num_indices = draw_index->index_count; - regs.draw_initiator = draw_index->draw_initiator; - if (rasterizer) { - const auto cmd_address = reinterpret_cast(header); - rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndex2", cmd_address)); - rasterizer->Breadcrumb(u64(cmd_address)); - rasterizer->Draw(true); - rasterizer->ScopeMarkerEnd(); - } - break; - } - case PM4ItOpcode::DrawIndexOffset2: { - const auto* draw_index_off = reinterpret_cast(header); - regs.max_index_size = draw_index_off->max_size; - regs.num_indices = draw_index_off->index_count; - regs.draw_initiator = draw_index_off->draw_initiator; - if (rasterizer) { - const auto cmd_address = reinterpret_cast(header); - rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndexOffset2", cmd_address)); - rasterizer->Breadcrumb(u64(cmd_address)); - rasterizer->Draw(true, draw_index_off->index_offset); - rasterizer->ScopeMarkerEnd(); - } - break; - } - case PM4ItOpcode::DrawIndexAuto: { - const auto* draw_index = reinterpret_cast(header); - regs.num_indices = draw_index->index_count; - regs.draw_initiator = draw_index->draw_initiator; - if (rasterizer) { - const auto cmd_address = reinterpret_cast(header); - rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:DrawIndexAuto", cmd_address)); - rasterizer->Breadcrumb(u64(cmd_address)); - rasterizer->Draw(false); - rasterizer->ScopeMarkerEnd(); - } - break; - } - case PM4ItOpcode::DispatchDirect: { - const auto* dispatch_direct = reinterpret_cast(header); - regs.cs_program.dim_x = dispatch_direct->dim_x; - regs.cs_program.dim_y = dispatch_direct->dim_y; - regs.cs_program.dim_z = dispatch_direct->dim_z; - regs.cs_program.dispatch_initiator = dispatch_direct->dispatch_initiator; - if (rasterizer && (regs.cs_program.dispatch_initiator & 1)) { - const auto cmd_address = reinterpret_cast(header); - rasterizer->ScopeMarkerBegin(fmt::format("dcb:{}:Dispatch", cmd_address)); - rasterizer->Breadcrumb(u64(cmd_address)); - rasterizer->DispatchDirect(); - rasterizer->ScopeMarkerEnd(); - } - break; - } - case PM4ItOpcode::NumInstances: { - const auto* num_instances = reinterpret_cast(header); - regs.num_instances.num_instances = num_instances->num_instances; - break; - } - case PM4ItOpcode::IndexBase: { - const auto* index_base = reinterpret_cast(header); - regs.index_base_address.base_addr_lo = index_base->addr_lo; - regs.index_base_address.base_addr_hi.Assign(index_base->addr_hi); - break; - } - case PM4ItOpcode::IndexBufferSize: { - const auto* index_size = reinterpret_cast(header); - regs.num_indices = index_size->num_indices; - break; - } - case PM4ItOpcode::EventWrite: { - // const auto* event = reinterpret_cast(header); - break; - } - case PM4ItOpcode::EventWriteEos: { - const auto* event_eos = reinterpret_cast(header); - event_eos->SignalFence(); - break; - } - case PM4ItOpcode::EventWriteEop: { - const auto* event_eop = reinterpret_cast(header); - event_eop->SignalFence(); - break; - } - case PM4ItOpcode::DmaData: { - const auto* dma_data = reinterpret_cast(header); - break; - } - case PM4ItOpcode::WriteData: { - const auto* write_data = reinterpret_cast(header); - ASSERT(write_data->dst_sel.Value() == 2 || write_data->dst_sel.Value() == 5); - const u32 data_size = (header->type3.count.Value() - 2) * 4; - u64* address = write_data->Address(); - if (!write_data->wr_one_addr.Value()) { - std::memcpy(address, write_data->data, data_size); - } else { - UNREACHABLE(); - } - break; - } - case PM4ItOpcode::AcquireMem: { - // const auto* acquire_mem = reinterpret_cast(header); - break; - } - case PM4ItOpcode::WaitRegMem: { - const auto* wait_reg_mem = reinterpret_cast(header); - // ASSERT(wait_reg_mem->engine.Value() == PM4CmdWaitRegMem::Engine::Me); - // Optimization: VO label waits are special because the emulator - // will write to the label when presentation is finished. So if - // there are no other submits to yield to we can sleep the thread - // instead and allow other tasks to run. - const u64* wait_addr = wait_reg_mem->Address(); - if (vo_port->IsVoLabel(wait_addr) && num_submits == 1) { - vo_port->WaitVoLabel([&] { return wait_reg_mem->Test(); }); - } - while (!wait_reg_mem->Test()) { - mapped_queues[GfxQueueId].cs_state = regs.cs_program; - TracyFiberLeave; - co_yield {}; - TracyFiberEnter(dcb_task_name); - regs.cs_program = mapped_queues[GfxQueueId].cs_state; - } - break; - } - case PM4ItOpcode::IncrementDeCounter: { - ++cblock.de_count; - break; - } - case PM4ItOpcode::WaitOnCeCounter: { - while (cblock.ce_count <= cblock.de_count) { - TracyFiberLeave; - ce_task.handle.resume(); - TracyFiberEnter(dcb_task_name); - } - break; - } - case PM4ItOpcode::PfpSyncMe: { - break; - } - default: - UNREACHABLE_MSG("Unknown PM4 type 3 opcode {:#x} with count {}", - static_cast(opcode), count); - } - dcb = dcb.subspan(header->type3.NumWords() + 1); } if (ce_task.handle) { From dfb30ea955279e82f3c86cf9f0f8a0b59c2dcdfd Mon Sep 17 00:00:00 2001 From: Anton Kovalev Date: Wed, 28 Aug 2024 11:24:15 +0200 Subject: [PATCH 19/36] Use pair of spans instead of references in copy command buffers function --- src/video_core/amdgpu/liverpool.cpp | 7 +++++-- src/video_core/amdgpu/liverpool.h | 7 ++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/video_core/amdgpu/liverpool.cpp b/src/video_core/amdgpu/liverpool.cpp index 931b5ea8..a3e64b7c 100644 --- a/src/video_core/amdgpu/liverpool.cpp +++ b/src/video_core/amdgpu/liverpool.cpp @@ -569,7 +569,8 @@ Liverpool::Task Liverpool::ProcessCompute(std::span acb, int vqid) { TracyFiberLeave; } -void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& ccb) { +std::pair, std::span> Liverpool::CopyCmdBuffers( + std::span dcb, std::span ccb) { auto& queue = mapped_queues[GfxQueueId]; queue.dcb_buffer.resize( @@ -594,13 +595,15 @@ void Liverpool::CopyCmdBuffers(std::span& dcb, std::span& ccb = std::span{queue.ccb_buffer.begin() + prev_ccb_buffer_offset, queue.ccb_buffer.begin() + queue.ccb_buffer_offset}; } + + return std::make_pair(dcb, ccb); } void Liverpool::SubmitGfx(std::span dcb, std::span ccb) { auto& queue = mapped_queues[GfxQueueId]; if (Config::copyGPUCmdBuffers()) { - CopyCmdBuffers(dcb, ccb); + std::tie(dcb, ccb) = CopyCmdBuffers(dcb, ccb); } auto task = ProcessGraphics(dcb, ccb); diff --git a/src/video_core/amdgpu/liverpool.h b/src/video_core/amdgpu/liverpool.h index c12c8fdb..14284bbc 100644 --- a/src/video_core/amdgpu/liverpool.h +++ b/src/video_core/amdgpu/liverpool.h @@ -1111,7 +1111,8 @@ private: Handle handle; }; - void CopyCmdBuffers(std::span& dcb, std::span& ccb); + std::pair, std::span> CopyCmdBuffers(std::span dcb, + std::span ccb); Task ProcessGraphics(std::span dcb, std::span ccb); Task ProcessCeUpdate(std::span ccb); Task ProcessCompute(std::span acb, int vqid); @@ -1120,8 +1121,8 @@ private: struct GpuQueue { std::mutex m_access{}; - std::atomic_uint32_t dcb_buffer_offset; - std::atomic_uint32_t ccb_buffer_offset; + std::atomic dcb_buffer_offset; + std::atomic ccb_buffer_offset; std::vector dcb_buffer; std::vector ccb_buffer; std::queue submits{}; From 79e86a39fcc022f38104986c10252340025cfeda Mon Sep 17 00:00:00 2001 From: InvoxiPlayGames Date: Wed, 28 Aug 2024 10:27:51 +0100 Subject: [PATCH 20/36] add support for configurable special pad type --- src/common/config.cpp | 29 +++++++++++++++++++++++++++++ src/common/config.h | 6 ++++++ src/core/libraries/pad/pad.cpp | 24 +++++++++++++++++++++++- src/core/libraries/pad/pad.h | 9 ++++++++- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/common/config.cpp b/src/common/config.cpp index 9f55cbd4..824a70da 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -17,6 +17,8 @@ static s32 gpuId = -1; // Vulkan physical device index. Set to negative for auto static std::string logFilter; static std::string logType = "async"; static std::string userName = "shadPS4"; +static bool useSpecialPad = false; +static int specialPadClass = 1; static bool isDebugDump = false; static bool isShowSplash = false; static bool isNullGpu = false; @@ -81,6 +83,14 @@ std::string getUserName() { return userName; } +bool getUseSpecialPad() { + return useSpecialPad; +} + +int getSpecialPadClass() { + return specialPadClass; +} + bool debugDump() { return isDebugDump; } @@ -197,6 +207,14 @@ void setUserName(const std::string& type) { userName = type; } +void setUseSpecialPad(bool use) { + useSpecialPad = use; +} + +void setSpecialPadClass(int type) { + specialPadClass = type; +} + void setMainWindowGeometry(u32 x, u32 y, u32 w, u32 h) { main_window_geometry_x = x; main_window_geometry_y = y; @@ -330,6 +348,13 @@ void load(const std::filesystem::path& path) { isShowSplash = toml::find_or(general, "showSplash", true); } + if (data.contains("Input")) { + const toml::value& input = data.at("Input"); + + useSpecialPad = toml::find_or(input, "useSpecialPad", false); + specialPadClass = toml::find_or(input, "specialPadClass", 1); + } + if (data.contains("GPU")) { const toml::value& gpu = data.at("GPU"); @@ -411,6 +436,8 @@ void save(const std::filesystem::path& path) { data["General"]["logType"] = logType; data["General"]["userName"] = userName; data["General"]["showSplash"] = isShowSplash; + data["Input"]["useSpecialPad"] = useSpecialPad; + data["Input"]["specialPadClass"] = specialPadClass; data["GPU"]["screenWidth"] = screenWidth; data["GPU"]["screenHeight"] = screenHeight; data["GPU"]["nullGpu"] = isNullGpu; @@ -457,6 +484,8 @@ void setDefaultValues() { logFilter = ""; logType = "async"; userName = "shadPS4"; + useSpecialPad = false; + specialPadClass = 1; isDebugDump = false; isShowSplash = false; isNullGpu = false; diff --git a/src/common/config.h b/src/common/config.h index 554515a4..f5140bc9 100644 --- a/src/common/config.h +++ b/src/common/config.h @@ -17,6 +17,9 @@ std::string getLogFilter(); std::string getLogType(); std::string getUserName(); +bool getUseSpecialPad(); +int getSpecialPadClass(); + u32 getScreenWidth(); u32 getScreenHeight(); s32 getGpuId(); @@ -44,6 +47,9 @@ void setLanguage(u32 language); void setNeoMode(bool enable); void setUserName(const std::string& type); +void setUseSpecialPad(bool use); +void setSpecialPadClass(int type); + void setLogType(const std::string& type); void setLogFilter(const std::string& type); diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index 305b20bd..c4735c9a 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -4,6 +4,7 @@ // Generated By moduleGenerator #include #include +#include "common/config.h" #include "common/logging/log.h" #include "core/libraries/error_codes.h" #include "core/libraries/libs.h" @@ -25,6 +26,9 @@ int PS4_SYSV_ABI scePadConnectPort() { int PS4_SYSV_ABI scePadDeviceClassGetExtendedInformation( s32 handle, OrbisPadDeviceClassExtendedInformation* pExtInfo) { LOG_ERROR(Lib_Pad, "(STUBBED) called"); + if (Config::getUseSpecialPad()) { + pExtInfo->deviceClass = (OrbisPadDeviceClass)Config::getSpecialPadClass(); + } return ORBIS_OK; } @@ -107,6 +111,10 @@ int PS4_SYSV_ABI scePadGetControllerInformation(s32 handle, OrbisPadControllerIn pInfo->connectedCount = 1; pInfo->connected = true; pInfo->deviceClass = ORBIS_PAD_DEVICE_CLASS_STANDARD; + if (Config::getUseSpecialPad()) { + pInfo->connectionType = ORBIS_PAD_PORT_TYPE_SPECIAL; + pInfo->deviceClass = (OrbisPadDeviceClass)Config::getSpecialPadClass(); + } return SCE_OK; } @@ -239,11 +247,25 @@ int PS4_SYSV_ABI scePadMbusTerm() { int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenParam* pParam) { LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", userId, type, index); + if (Config::getUseSpecialPad()) { + if (type != ORBIS_PAD_PORT_TYPE_SPECIAL) + return -1; + } else { + if (type != ORBIS_PAD_PORT_TYPE_STANDARD) + return -1; + } return 1; // dummy } -int PS4_SYSV_ABI scePadOpenExt() { +int PS4_SYSV_ABI scePadOpenExt(s32 userId, s32 type, s32 index, const OrbisPadOpenExtParam* pParam) { LOG_ERROR(Lib_Pad, "(STUBBED) called"); + if (Config::getUseSpecialPad()) { + if (type != ORBIS_PAD_PORT_TYPE_SPECIAL) + return -1; + } else { + if (type != ORBIS_PAD_PORT_TYPE_STANDARD) + return -1; + } return 1; // dummy } diff --git a/src/core/libraries/pad/pad.h b/src/core/libraries/pad/pad.h index 3e9c14a1..b18bbc35 100644 --- a/src/core/libraries/pad/pad.h +++ b/src/core/libraries/pad/pad.h @@ -229,6 +229,13 @@ struct OrbisPadOpenParam { u8 reserve[8]; }; +struct OrbisPadOpenExtParam { + u16 vendorId; + u16 productId; + u16 productId_2; + u8 reserve[10]; +}; + struct OrbisPadLightBarParam { u8 r; u8 g; @@ -284,7 +291,7 @@ int PS4_SYSV_ABI scePadIsValidHandle(); int PS4_SYSV_ABI scePadMbusInit(); int PS4_SYSV_ABI scePadMbusTerm(); int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenParam* pParam); -int PS4_SYSV_ABI scePadOpenExt(); +int PS4_SYSV_ABI scePadOpenExt(s32 userId, s32 type, s32 index, const OrbisPadOpenExtParam* pParam); int PS4_SYSV_ABI scePadOpenExt2(); int PS4_SYSV_ABI scePadOutputReport(); int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num); From 550cf0188d40e20df71d99b76237287be63ba13e Mon Sep 17 00:00:00 2001 From: InvoxiPlayGames Date: Wed, 28 Aug 2024 10:51:30 +0100 Subject: [PATCH 21/36] return proper error code for scePadOpen failure --- src/core/libraries/pad/pad.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index c4735c9a..c75e71df 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -249,10 +249,10 @@ int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenP LOG_INFO(Lib_Pad, "(DUMMY) called user_id = {} type = {} index = {}", userId, type, index); if (Config::getUseSpecialPad()) { if (type != ORBIS_PAD_PORT_TYPE_SPECIAL) - return -1; + return ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED; } else { if (type != ORBIS_PAD_PORT_TYPE_STANDARD) - return -1; + return ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED; } return 1; // dummy } @@ -261,10 +261,10 @@ int PS4_SYSV_ABI scePadOpenExt(s32 userId, s32 type, s32 index, const OrbisPadOp LOG_ERROR(Lib_Pad, "(STUBBED) called"); if (Config::getUseSpecialPad()) { if (type != ORBIS_PAD_PORT_TYPE_SPECIAL) - return -1; + return ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED; } else { if (type != ORBIS_PAD_PORT_TYPE_STANDARD) - return -1; + return ORBIS_PAD_ERROR_DEVICE_NOT_CONNECTED; } return 1; // dummy } From 990da7edcc62cae5800bafc8abd92dae91f092cb Mon Sep 17 00:00:00 2001 From: tGecko Date: Wed, 28 Aug 2024 12:10:04 +0200 Subject: [PATCH 22/36] DOCS: Correct and expand windows build instructions (#617) * correct and expand windows build instructions * fix numbering * remove instructions to clone a different branch --- documents/building-windows.md | 39 ++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/documents/building-windows.md b/documents/building-windows.md index 684e5fe9..21fd8715 100644 --- a/documents/building-windows.md +++ b/documents/building-windows.md @@ -17,34 +17,53 @@ Note: **ARM64 is not supported!** As of writing, it will not build nor run. The Once you are within the installer: 1. Select `Desktop development with C++` 2. Go to "Individual Components" tab -3. Make sure `C++ Clang Compiler for Windows`, `MSBuild support for LLVM` and `C++ CMake Tools for Windows` are selected +3. Search and select `C++ Clang Compiler for Windows` and `MSBuild support for LLVM` 4. Continue the installation ### (Prerequisite) Download [**Qt**](https://doc.qt.io/qt-6/get-and-install-qt.html) Beware, this requires you to create a Qt account. If you do not want to do this, please follow the MSYS2/MinGW compilation method instead. -1. Select Qt for Visual Studio plugin -2. Select `msvc2019_64` option or similar. If you are on Windows on ARM / Qualcomm Snapdragon Elite X, select `msvc2019_arm64` +1. Under the current, non beta version of Qt (at the time of writing 6.7.2), select the option `MSVC 2019 64-bit` or similar. + If you are on Windows on ARM / Qualcomm Snapdragon Elite X, select `MSVC 2019 ARM64` instead. -Go through the installation normally. If you do not know what components to select, just select the newest Qt version it gives you. -If you know what you are doing, you may unselect individual components that eat up too much disk space. + Go through the installation normally. If you know what you are doing, you may unselect individual components that eat up too much disk space. +2. Download and install [Qt Visual Studio Tools](https://marketplace.visualstudio.com/items?itemName=TheQtCompany.QtVisualStudioTools2022) + Once you are finished, you will have to configure Qt within Visual Studio: 1. Tools -> Options -> Qt -> Versions -2. Add a new Qt version and navigate it to the correct folder. Should look like so: `C:\Qt\6.7.1\msvc2019_64` +2. Add a new Qt version and navigate it to the correct folder. Should look like so: `C:\Qt\6.7.2\msvc2019_64` 3. Enable the default checkmark on the new version you just created. ### (Prerequisite) Download [**Git for Windows**](https://git-scm.com/download/win) Go through the Git for Windows installation as normal -### Compiling with Visual Studio GUI +### Cloning the source code 1. Open Git for Windows, navigate to a place where you want to store the shadPS4 source code folder -2. Run `git clone --depth 1 --recursive https://github.com/shadps4-emu/shadPS4` -3. Open up Visual Studio, select `Open a local folder` and select the folder with the shadPS4 source code. The folder should contain `CMakeLists.txt` -4. Build -> Build All +2. Clone the repository by running + `git clone --depth 1 --recursive https://github.com/shadps4-emu/shadPS4` + +### Compiling with Visual Studio GUI + +1. Open up Visual Studio, select `Open a local folder` and select the folder with the shadPS4 source code. The folder should contain `CMakeLists.txt` +2. Change x64-Clang-Debug to x64-Clang-Release if you want a regular, non-debug build. +3. If you want to build shadPS4 with the Qt Gui: + 1. Click x64-Clang-Release and select "Manage Configurations" + 2. Look for "CMake command arguments" and add to the text field + `-DENABLE_QT_GUI=ON -DCMAKE_PREFIX_PATH=C:\Qt\6.7.2\msvc2019_64` + (Change Qt path if you've installed it to non-default path) + 3. Press CTRL+S to save and wait a moment for CMake generation +4. Change the project to build to shadps4.exe +5. Build -> Build All + +Your shadps4.exe will be in `c:\path\to\source\Build\x64-Clang-Release\` + +To automatically populate the necessary files to run shadPS4.exe, run in a command prompt or terminal: +`C:\Qt\6.7.2\msvc2019_64\bin\windeployqt.exe c:\path\to\shadps4.exe` +(Change Qt path if you've installed it to non-default path) ## Option 2: MSYS2/MinGW From 9d59ea06c784cef14c62fc79170c66995e90d410 Mon Sep 17 00:00:00 2001 From: InvoxiPlayGames Date: Wed, 28 Aug 2024 11:10:20 +0100 Subject: [PATCH 23/36] clang-format fix: scePadOpenExt --- src/core/libraries/pad/pad.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index c75e71df..5bf9c3af 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -257,7 +257,8 @@ int PS4_SYSV_ABI scePadOpen(s32 userId, s32 type, s32 index, const OrbisPadOpenP return 1; // dummy } -int PS4_SYSV_ABI scePadOpenExt(s32 userId, s32 type, s32 index, const OrbisPadOpenExtParam* pParam) { +int PS4_SYSV_ABI scePadOpenExt(s32 userId, s32 type, s32 index, + const OrbisPadOpenExtParam* pParam) { LOG_ERROR(Lib_Pad, "(STUBBED) called"); if (Config::getUseSpecialPad()) { if (type != ORBIS_PAD_PORT_TYPE_SPECIAL) From 9f4e55a8e7caf5c2127f1da366b36fdf6aa6df08 Mon Sep 17 00:00:00 2001 From: 0xsegf4ult Date: Wed, 28 Aug 2024 12:10:21 +0200 Subject: [PATCH 24/36] shader_recompiler: constant propagation bitwise operations + S_CMPK_EQ_U32 fix (#613) * rebase on main branch impl of V_LSHL_B64 * remove V_LSHR_B64 * fix S_CMPK_EQ_u32 * fix conflicts * fix broken merge * remove duplicate cases * remove duplicate declaration --- .../backend/spirv/emit_spirv_instructions.h | 1 + .../backend/spirv/emit_spirv_integer.cpp | 7 +++++++ .../frontend/translate/scalar_alu.cpp | 2 +- src/shader_recompiler/ir/ir_emitter.cpp | 14 ++++++++++++-- src/shader_recompiler/ir/ir_emitter.h | 2 +- src/shader_recompiler/ir/opcodes.inc | 1 + .../ir/passes/constant_propagation_pass.cpp | 6 ++++++ 7 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index dd3d8fae..ce4d3f13 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h @@ -286,6 +286,7 @@ Id EmitShiftRightLogical64(EmitContext& ctx, Id base, Id shift); Id EmitShiftRightArithmetic32(EmitContext& ctx, Id base, Id shift); Id EmitShiftRightArithmetic64(EmitContext& ctx, Id base, Id shift); Id EmitBitwiseAnd32(EmitContext& ctx, IR::Inst* inst, Id a, Id b); +Id EmitBitwiseAnd64(EmitContext& ctx, IR::Inst* inst, Id a, Id b); Id EmitBitwiseOr32(EmitContext& ctx, IR::Inst* inst, Id a, Id b); Id EmitBitwiseOr64(EmitContext& ctx, IR::Inst* inst, Id a, Id b); Id EmitBitwiseXor32(EmitContext& ctx, IR::Inst* inst, Id a, Id b); diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp index f20c4fac..a9becb1e 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_integer.cpp @@ -139,6 +139,13 @@ Id EmitBitwiseAnd32(EmitContext& ctx, IR::Inst* inst, Id a, Id b) { return result; } +Id EmitBitwiseAnd64(EmitContext& ctx, IR::Inst* inst, Id a, Id b) { + const Id result{ctx.OpBitwiseAnd(ctx.U64, a, b)}; + SetZeroFlag(ctx, inst, result); + SetSignFlag(ctx, inst, result); + return result; +} + Id EmitBitwiseOr32(EmitContext& ctx, IR::Inst* inst, Id a, Id b) { const Id result{ctx.OpBitwiseOr(ctx.U32[1], a, b)}; SetZeroFlag(ctx, inst, result); diff --git a/src/shader_recompiler/frontend/translate/scalar_alu.cpp b/src/shader_recompiler/frontend/translate/scalar_alu.cpp index 50a550d4..7914726f 100644 --- a/src/shader_recompiler/frontend/translate/scalar_alu.cpp +++ b/src/shader_recompiler/frontend/translate/scalar_alu.cpp @@ -472,7 +472,7 @@ void Translator::S_MIN_U32(const GcnInst& inst) { void Translator::S_CMPK_EQ_U32(const GcnInst& inst) { const s32 simm16 = inst.control.sopk.simm; - const IR::U32 src0{GetSrc(inst.src[0])}; + const IR::U32 src0{GetSrc(inst.dst[0])}; const IR::U32 src1{ir.Imm32(simm16)}; ir.SetScc(ir.IEqual(src0, src1)); } diff --git a/src/shader_recompiler/ir/ir_emitter.cpp b/src/shader_recompiler/ir/ir_emitter.cpp index a65e538c..65de98b7 100644 --- a/src/shader_recompiler/ir/ir_emitter.cpp +++ b/src/shader_recompiler/ir/ir_emitter.cpp @@ -1115,8 +1115,18 @@ U32U64 IREmitter::ShiftRightArithmetic(const U32U64& base, const U32& shift) { } } -U32 IREmitter::BitwiseAnd(const U32& a, const U32& b) { - return Inst(Opcode::BitwiseAnd32, a, b); +U32U64 IREmitter::BitwiseAnd(const U32U64& a, const U32U64& b) { + if (a.Type() != b.Type()) { + UNREACHABLE_MSG("Mismatching types {} and {}", a.Type(), b.Type()); + } + switch (a.Type()) { + case Type::U32: + return Inst(Opcode::BitwiseAnd32, a, b); + case Type::U64: + return Inst(Opcode::BitwiseAnd64, a, b); + default: + ThrowInvalidType(a.Type()); + } } U32U64 IREmitter::BitwiseOr(const U32U64& a, const U32U64& b) { diff --git a/src/shader_recompiler/ir/ir_emitter.h b/src/shader_recompiler/ir/ir_emitter.h index 8f806eb5..a60f4c28 100644 --- a/src/shader_recompiler/ir/ir_emitter.h +++ b/src/shader_recompiler/ir/ir_emitter.h @@ -195,7 +195,7 @@ public: [[nodiscard]] U32U64 ShiftLeftLogical(const U32U64& base, const U32& shift); [[nodiscard]] U32U64 ShiftRightLogical(const U32U64& base, const U32& shift); [[nodiscard]] U32U64 ShiftRightArithmetic(const U32U64& base, const U32& shift); - [[nodiscard]] U32 BitwiseAnd(const U32& a, const U32& b); + [[nodiscard]] U32U64 BitwiseAnd(const U32U64& a, const U32U64& b); [[nodiscard]] U32U64 BitwiseOr(const U32U64& a, const U32U64& b); [[nodiscard]] U32 BitwiseXor(const U32& a, const U32& b); [[nodiscard]] U32 BitFieldInsert(const U32& base, const U32& insert, const U32& offset, diff --git a/src/shader_recompiler/ir/opcodes.inc b/src/shader_recompiler/ir/opcodes.inc index 26da00bb..a49ea1c7 100644 --- a/src/shader_recompiler/ir/opcodes.inc +++ b/src/shader_recompiler/ir/opcodes.inc @@ -260,6 +260,7 @@ OPCODE(ShiftRightLogical64, U64, U64, OPCODE(ShiftRightArithmetic32, U32, U32, U32, ) OPCODE(ShiftRightArithmetic64, U64, U64, U32, ) OPCODE(BitwiseAnd32, U32, U32, U32, ) +OPCODE(BitwiseAnd64, U64, U64, U64, ) OPCODE(BitwiseOr32, U32, U32, U32, ) OPCODE(BitwiseOr64, U64, U64, U64, ) OPCODE(BitwiseXor32, U32, U32, U32, ) diff --git a/src/shader_recompiler/ir/passes/constant_propagation_pass.cpp b/src/shader_recompiler/ir/passes/constant_propagation_pass.cpp index b0d9dcc4..87a06933 100644 --- a/src/shader_recompiler/ir/passes/constant_propagation_pass.cpp +++ b/src/shader_recompiler/ir/passes/constant_propagation_pass.cpp @@ -352,9 +352,15 @@ void ConstantPropagation(IR::Block& block, IR::Inst& inst) { case IR::Opcode::BitwiseAnd32: FoldWhenAllImmediates(inst, [](u32 a, u32 b) { return a & b; }); return; + case IR::Opcode::BitwiseAnd64: + FoldWhenAllImmediates(inst, [](u64 a, u64 b) { return a & b; }); + return; case IR::Opcode::BitwiseOr32: FoldWhenAllImmediates(inst, [](u32 a, u32 b) { return a | b; }); return; + case IR::Opcode::BitwiseOr64: + FoldWhenAllImmediates(inst, [](u64 a, u64 b) { return a | b; }); + return; case IR::Opcode::BitwiseXor32: FoldWhenAllImmediates(inst, [](u32 a, u32 b) { return a ^ b; }); return; From 8192eaa668d6a1ba4b70dd3be01fbf6378ea136e Mon Sep 17 00:00:00 2001 From: Vinicius Rangel Date: Wed, 28 Aug 2024 07:11:55 -0300 Subject: [PATCH 25/36] video_core: re-enable culling (#551) --- src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp index 95d3a4b2..5623e431 100644 --- a/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp +++ b/src/video_core/renderer_vulkan/vk_graphics_pipeline.cpp @@ -94,7 +94,7 @@ GraphicsPipeline::GraphicsPipeline(const Instance& instance_, Scheduler& schedul .depthClampEnable = false, .rasterizerDiscardEnable = false, .polygonMode = LiverpoolToVK::PolygonMode(key.polygon_mode), - .cullMode = vk::CullModeFlagBits::eNone /*LiverpoolToVK::CullMode(key.cull_mode)*/, + .cullMode = LiverpoolToVK::CullMode(key.cull_mode), .frontFace = key.front_face == Liverpool::FrontFace::Clockwise ? vk::FrontFace::eClockwise : vk::FrontFace::eCounterClockwise, From da966bedfdffb039069b496c0274e4b0bfbaf6e4 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Wed, 28 Aug 2024 03:13:33 -0700 Subject: [PATCH 26/36] kernel: Reimplement POSIX semaphores using std::counting_semaphore. (#600) --- CMakeLists.txt | 4 - .../libraries/kernel/thread_management.cpp | 135 +++++++++--------- src/core/libraries/kernel/thread_management.h | 7 + 3 files changed, 78 insertions(+), 68 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6450eaf1..04740784 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -95,10 +95,6 @@ check_symbol_exists(pthread_mutex_timedlock "pthread.h" HAVE_PTHREAD_MUTEX_TIMED if(HAVE_PTHREAD_MUTEX_TIMEDLOCK OR WIN32) add_compile_options(-DHAVE_PTHREAD_MUTEX_TIMEDLOCK) endif() -check_symbol_exists(sem_timedwait "semaphore.h" HAVE_SEM_TIMEDWAIT) -if(HAVE_SEM_TIMEDWAIT OR WIN32) - add_compile_options(-DHAVE_SEM_TIMEDWAIT) -endif() if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") # libc++ requires -fexperimental-library to enable std::jthread and std::stop_token support. diff --git a/src/core/libraries/kernel/thread_management.cpp b/src/core/libraries/kernel/thread_management.cpp index 567ac867..605d0d29 100644 --- a/src/core/libraries/kernel/thread_management.cpp +++ b/src/core/libraries/kernel/thread_management.cpp @@ -2,8 +2,8 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include +#include #include -#include #include "common/alignment.h" #include "common/assert.h" #include "common/error.h" @@ -1374,90 +1374,97 @@ int PS4_SYSV_ABI posix_pthread_detach(ScePthread thread) { return pthread_detach(thread->pth); } -int PS4_SYSV_ABI posix_sem_init(sem_t* sem, int pshared, unsigned int value) { - int result = sem_init(sem, pshared, value); - if (result == -1) { - SetPosixErrno(errno); +int PS4_SYSV_ABI posix_sem_init(PthreadSemInternal** sem, int pshared, unsigned int value) { + if (value > ORBIS_KERNEL_SEM_VALUE_MAX) { + SetPosixErrno(EINVAL); + return -1; } - return result; + if (sem != nullptr) { + *sem = new PthreadSemInternal{ + .semaphore = std::counting_semaphore{value}, + .value = {static_cast(value)}, + }; + } + return 0; } -int PS4_SYSV_ABI posix_sem_wait(sem_t* sem) { - int result = sem_wait(sem); - if (result == -1) { - SetPosixErrno(errno); +int PS4_SYSV_ABI posix_sem_wait(PthreadSemInternal** sem) { + if (sem == nullptr || *sem == nullptr) { + SetPosixErrno(EINVAL); + return -1; } - return result; + (*sem)->semaphore.acquire(); + --(*sem)->value; + return 0; } -int PS4_SYSV_ABI posix_sem_trywait(sem_t* sem) { - int result = sem_trywait(sem); - if (result == -1) { - SetPosixErrno(errno); +int PS4_SYSV_ABI posix_sem_trywait(PthreadSemInternal** sem) { + if (sem == nullptr || *sem == nullptr) { + SetPosixErrno(EINVAL); + return -1; } - return result; + if (!(*sem)->semaphore.try_acquire()) { + SetPosixErrno(EAGAIN); + return -1; + } + --(*sem)->value; + return 0; } -#ifndef HAVE_SEM_TIMEDWAIT -int sem_timedwait(sem_t* sem, const struct timespec* abstime) { - int rc; - while ((rc = sem_trywait(sem)) == EAGAIN) { - struct timespec curr_time; - clock_gettime(CLOCK_REALTIME, &curr_time); - - s64 remaining_ns = 0; - remaining_ns += - (static_cast(abstime->tv_sec) - static_cast(curr_time.tv_sec)) * 1000000000L; - remaining_ns += static_cast(abstime->tv_nsec) - static_cast(curr_time.tv_nsec); - - if (remaining_ns <= 0) { - return ETIMEDOUT; - } - - struct timespec sleep_time; - sleep_time.tv_sec = 0; - if (remaining_ns < 5000000L) { - sleep_time.tv_nsec = remaining_ns; - } else { - sleep_time.tv_nsec = 5000000; - } - - nanosleep(&sleep_time, nullptr); +int PS4_SYSV_ABI posix_sem_timedwait(PthreadSemInternal** sem, const timespec* t) { + if (sem == nullptr || *sem == nullptr) { + SetPosixErrno(EINVAL); + return -1; } - return rc; -} -#endif -int PS4_SYSV_ABI posix_sem_timedwait(sem_t* sem, const timespec* t) { - int result = sem_timedwait(sem, t); - if (result == -1) { - SetPosixErrno(errno); + using std::chrono::duration_cast; + using std::chrono::nanoseconds; + using std::chrono::seconds; + using std::chrono::system_clock; + + const system_clock::time_point time{ + duration_cast(seconds{t->tv_sec} + nanoseconds{t->tv_nsec})}; + if (!(*sem)->semaphore.try_acquire_until(time)) { + SetPosixErrno(ETIMEDOUT); + return -1; } - return result; + --(*sem)->value; + return 0; } -int PS4_SYSV_ABI posix_sem_post(sem_t* sem) { - int result = sem_post(sem); - if (result == -1) { - SetPosixErrno(errno); +int PS4_SYSV_ABI posix_sem_post(PthreadSemInternal** sem) { + if (sem == nullptr || *sem == nullptr) { + SetPosixErrno(EINVAL); + return -1; } - return result; + if ((*sem)->value == ORBIS_KERNEL_SEM_VALUE_MAX) { + SetPosixErrno(EOVERFLOW); + return -1; + } + ++(*sem)->value; + (*sem)->semaphore.release(); + return 0; } -int PS4_SYSV_ABI posix_sem_destroy(sem_t* sem) { - int result = sem_destroy(sem); - if (result == -1) { - SetPosixErrno(errno); +int PS4_SYSV_ABI posix_sem_destroy(PthreadSemInternal** sem) { + if (sem == nullptr || *sem == nullptr) { + SetPosixErrno(EINVAL); + return -1; } - return result; + delete *sem; + *sem = nullptr; + return 0; } -int PS4_SYSV_ABI posix_sem_getvalue(sem_t* sem, int* sval) { - int result = sem_getvalue(sem, sval); - if (result == -1) { - SetPosixErrno(errno); +int PS4_SYSV_ABI posix_sem_getvalue(PthreadSemInternal** sem, int* sval) { + if (sem == nullptr || *sem == nullptr) { + SetPosixErrno(EINVAL); + return -1; } - return result; + if (sval) { + *sval = (*sem)->value; + } + return 0; } int PS4_SYSV_ABI posix_pthread_attr_getstacksize(const pthread_attr_t* attr, size_t* size) { diff --git a/src/core/libraries/kernel/thread_management.h b/src/core/libraries/kernel/thread_management.h index 3679af84..27cd7929 100644 --- a/src/core/libraries/kernel/thread_management.h +++ b/src/core/libraries/kernel/thread_management.h @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -19,6 +20,7 @@ namespace Libraries::Kernel { constexpr int ORBIS_KERNEL_PRIO_FIFO_DEFAULT = 700; constexpr int ORBIS_KERNEL_PRIO_FIFO_HIGHEST = 256; constexpr int ORBIS_KERNEL_PRIO_FIFO_LOWEST = 767; +constexpr int ORBIS_KERNEL_SEM_VALUE_MAX = 0x7FFFFFFF; constexpr int ORBIS_PTHREAD_MUTEX_ERRORCHECK = 1; constexpr int ORBIS_PTHREAD_MUTEX_RECURSIVE = 2; @@ -109,6 +111,11 @@ struct PthreadRwInternal { std::string name; }; +struct PthreadSemInternal { + std::counting_semaphore semaphore; + std::atomic value; +}; + class PThreadPool { public: ScePthread Create(); From 4a6ce1e0d6e3cc7497a600dd9a62d68cbbe3422f Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Wed, 28 Aug 2024 03:36:15 -0700 Subject: [PATCH 27/36] crypto: Fix deallocation of key data while in use. --- src/core/crypto/crypto.cpp | 61 ++-- src/core/crypto/crypto.h | 4 - src/core/crypto/keys.h | 650 +++++++++++++++---------------------- 3 files changed, 296 insertions(+), 419 deletions(-) diff --git a/src/core/crypto/crypto.cpp b/src/core/crypto/crypto.cpp index fc64edc2..aa1c9672 100644 --- a/src/core/crypto/crypto.cpp +++ b/src/core/crypto/crypto.cpp @@ -6,18 +6,18 @@ CryptoPP::RSA::PrivateKey Crypto::key_pkg_derived_key3_keyset_init() { CryptoPP::InvertibleRSAFunction params; - params.SetPrime1(CryptoPP::Integer(pkg_derived_key3_keyset.Prime1, 0x80)); - params.SetPrime2(CryptoPP::Integer(pkg_derived_key3_keyset.Prime2, 0x80)); + params.SetPrime1(CryptoPP::Integer(PkgDerivedKey3Keyset::Prime1, 0x80)); + params.SetPrime2(CryptoPP::Integer(PkgDerivedKey3Keyset::Prime2, 0x80)); - params.SetPublicExponent(CryptoPP::Integer(pkg_derived_key3_keyset.PublicExponent, 4)); - params.SetPrivateExponent(CryptoPP::Integer(pkg_derived_key3_keyset.PrivateExponent, 0x100)); + params.SetPublicExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::PublicExponent, 4)); + params.SetPrivateExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::PrivateExponent, 0x100)); - params.SetModPrime1PrivateExponent(CryptoPP::Integer(pkg_derived_key3_keyset.Exponent1, 0x80)); - params.SetModPrime2PrivateExponent(CryptoPP::Integer(pkg_derived_key3_keyset.Exponent2, 0x80)); + params.SetModPrime1PrivateExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::Exponent1, 0x80)); + params.SetModPrime2PrivateExponent(CryptoPP::Integer(PkgDerivedKey3Keyset::Exponent2, 0x80)); - params.SetModulus(CryptoPP::Integer(pkg_derived_key3_keyset.Modulus, 0x100)); + params.SetModulus(CryptoPP::Integer(PkgDerivedKey3Keyset::Modulus, 0x100)); params.SetMultiplicativeInverseOfPrime2ModPrime1( - CryptoPP::Integer(pkg_derived_key3_keyset.Coefficient, 0x80)); + CryptoPP::Integer(PkgDerivedKey3Keyset::Coefficient, 0x80)); CryptoPP::RSA::PrivateKey privateKey(params); @@ -26,18 +26,18 @@ CryptoPP::RSA::PrivateKey Crypto::key_pkg_derived_key3_keyset_init() { CryptoPP::RSA::PrivateKey Crypto::FakeKeyset_keyset_init() { CryptoPP::InvertibleRSAFunction params; - params.SetPrime1(CryptoPP::Integer(FakeKeyset_keyset.Prime1, 0x80)); - params.SetPrime2(CryptoPP::Integer(FakeKeyset_keyset.Prime2, 0x80)); + params.SetPrime1(CryptoPP::Integer(FakeKeyset::Prime1, 0x80)); + params.SetPrime2(CryptoPP::Integer(FakeKeyset::Prime2, 0x80)); - params.SetPublicExponent(CryptoPP::Integer(FakeKeyset_keyset.PublicExponent, 4)); - params.SetPrivateExponent(CryptoPP::Integer(FakeKeyset_keyset.PrivateExponent, 0x100)); + params.SetPublicExponent(CryptoPP::Integer(FakeKeyset::PublicExponent, 4)); + params.SetPrivateExponent(CryptoPP::Integer(FakeKeyset::PrivateExponent, 0x100)); - params.SetModPrime1PrivateExponent(CryptoPP::Integer(FakeKeyset_keyset.Exponent1, 0x80)); - params.SetModPrime2PrivateExponent(CryptoPP::Integer(FakeKeyset_keyset.Exponent2, 0x80)); + params.SetModPrime1PrivateExponent(CryptoPP::Integer(FakeKeyset::Exponent1, 0x80)); + params.SetModPrime2PrivateExponent(CryptoPP::Integer(FakeKeyset::Exponent2, 0x80)); - params.SetModulus(CryptoPP::Integer(FakeKeyset_keyset.Modulus, 0x100)); + params.SetModulus(CryptoPP::Integer(FakeKeyset::Modulus, 0x100)); params.SetMultiplicativeInverseOfPrime2ModPrime1( - CryptoPP::Integer(FakeKeyset_keyset.Coefficient, 0x80)); + CryptoPP::Integer(FakeKeyset::Coefficient, 0x80)); CryptoPP::RSA::PrivateKey privateKey(params); @@ -46,25 +46,22 @@ CryptoPP::RSA::PrivateKey Crypto::FakeKeyset_keyset_init() { CryptoPP::RSA::PrivateKey Crypto::DebugRifKeyset_init() { CryptoPP::InvertibleRSAFunction params; - params.SetPrime1( - CryptoPP::Integer(DebugRifKeyset_keyset.Prime1, sizeof(DebugRifKeyset_keyset.Prime1))); - params.SetPrime2( - CryptoPP::Integer(DebugRifKeyset_keyset.Prime2, sizeof(DebugRifKeyset_keyset.Prime2))); + params.SetPrime1(CryptoPP::Integer(DebugRifKeyset::Prime1, sizeof(DebugRifKeyset::Prime1))); + params.SetPrime2(CryptoPP::Integer(DebugRifKeyset::Prime2, sizeof(DebugRifKeyset::Prime2))); - params.SetPublicExponent(CryptoPP::Integer(DebugRifKeyset_keyset.PublicExponent, - sizeof(DebugRifKeyset_keyset.PublicExponent))); - params.SetPrivateExponent(CryptoPP::Integer(DebugRifKeyset_keyset.PrivateExponent, - sizeof(DebugRifKeyset_keyset.PrivateExponent))); + params.SetPublicExponent( + CryptoPP::Integer(DebugRifKeyset::PublicExponent, sizeof(DebugRifKeyset::PublicExponent))); + params.SetPrivateExponent(CryptoPP::Integer(DebugRifKeyset::PrivateExponent, + sizeof(DebugRifKeyset::PrivateExponent))); - params.SetModPrime1PrivateExponent(CryptoPP::Integer(DebugRifKeyset_keyset.Exponent1, - sizeof(DebugRifKeyset_keyset.Exponent1))); - params.SetModPrime2PrivateExponent(CryptoPP::Integer(DebugRifKeyset_keyset.Exponent2, - sizeof(DebugRifKeyset_keyset.Exponent2))); + params.SetModPrime1PrivateExponent( + CryptoPP::Integer(DebugRifKeyset::Exponent1, sizeof(DebugRifKeyset::Exponent1))); + params.SetModPrime2PrivateExponent( + CryptoPP::Integer(DebugRifKeyset::Exponent2, sizeof(DebugRifKeyset::Exponent2))); - params.SetModulus( - CryptoPP::Integer(DebugRifKeyset_keyset.Modulus, sizeof(DebugRifKeyset_keyset.Modulus))); - params.SetMultiplicativeInverseOfPrime2ModPrime1(CryptoPP::Integer( - DebugRifKeyset_keyset.Coefficient, sizeof(DebugRifKeyset_keyset.Coefficient))); + params.SetModulus(CryptoPP::Integer(DebugRifKeyset::Modulus, sizeof(DebugRifKeyset::Modulus))); + params.SetMultiplicativeInverseOfPrime2ModPrime1( + CryptoPP::Integer(DebugRifKeyset::Coefficient, sizeof(DebugRifKeyset::Coefficient))); CryptoPP::RSA::PrivateKey privateKey(params); diff --git a/src/core/crypto/crypto.h b/src/core/crypto/crypto.h index 0c5bc995..83249bd7 100644 --- a/src/core/crypto/crypto.h +++ b/src/core/crypto/crypto.h @@ -17,10 +17,6 @@ class Crypto { public: - PkgDerivedKey3Keyset pkg_derived_key3_keyset; - FakeKeyset FakeKeyset_keyset; - DebugRifKeyset DebugRifKeyset_keyset; - CryptoPP::RSA::PrivateKey key_pkg_derived_key3_keyset_init(); CryptoPP::RSA::PrivateKey FakeKeyset_keyset_init(); CryptoPP::RSA::PrivateKey DebugRifKeyset_init(); diff --git a/src/core/crypto/keys.h b/src/core/crypto/keys.h index 58466b76..44108248 100644 --- a/src/core/crypto/keys.h +++ b/src/core/crypto/keys.h @@ -7,415 +7,299 @@ class FakeKeyset { public: // Constructor - const CryptoPP::byte* Exponent1; + static constexpr CryptoPP::byte Exponent1[] = { + 0x6D, 0x48, 0xE0, 0x54, 0x40, 0x25, 0xC8, 0x41, 0x29, 0x52, 0x42, 0x27, 0xEB, 0xD2, 0xC7, + 0xAB, 0x6B, 0x9C, 0x27, 0x0A, 0xB4, 0x1F, 0x94, 0x4E, 0xFA, 0x42, 0x1D, 0xB7, 0xBC, 0xB9, + 0xAE, 0xBC, 0x04, 0x6F, 0x75, 0x8F, 0x10, 0x5F, 0x89, 0xAC, 0xAB, 0x9C, 0xD2, 0xFA, 0xE6, + 0xA4, 0x13, 0x83, 0x68, 0xD4, 0x56, 0x38, 0xFE, 0xE5, 0x2B, 0x78, 0x44, 0x9C, 0x34, 0xE6, + 0x5A, 0xA0, 0xBE, 0x05, 0x70, 0xAD, 0x15, 0xC3, 0x2D, 0x31, 0xAC, 0x97, 0x5D, 0x88, 0xFC, + 0xC1, 0x62, 0x3D, 0xE2, 0xED, 0x11, 0xDB, 0xB6, 0x9E, 0xFC, 0x5A, 0x5A, 0x03, 0xF6, 0xCF, + 0x08, 0xD4, 0x5D, 0x90, 0xC9, 0x2A, 0xB9, 0x9B, 0xCF, 0xC8, 0x1A, 0x65, 0xF3, 0x5B, 0xE8, + 0x7F, 0xCF, 0xA5, 0xA6, 0x4C, 0x5C, 0x2A, 0x12, 0x0F, 0x92, 0xA5, 0xE3, 0xF0, 0x17, 0x1E, + 0x9A, 0x97, 0x45, 0x86, 0xFD, 0xDB, 0x54, 0x25}; // exponent2 = d mod (q - 1) - const CryptoPP::byte* Exponent2; + static constexpr CryptoPP::byte Exponent2[] = { + 0x2A, 0x51, 0xCE, 0x02, 0x44, 0x28, 0x50, 0xE8, 0x30, 0x20, 0x7C, 0x9C, 0x55, 0xBF, 0x60, + 0x39, 0xBC, 0xD1, 0xF0, 0xE7, 0x68, 0xF8, 0x08, 0x5B, 0x61, 0x1F, 0xA7, 0xBF, 0xD0, 0xE8, + 0x8B, 0xB5, 0xB1, 0xD5, 0xD9, 0x16, 0xAC, 0x75, 0x0C, 0x6D, 0xF2, 0xE0, 0xB5, 0x97, 0x75, + 0xD2, 0x68, 0x16, 0x1F, 0x00, 0x7D, 0x8B, 0x17, 0xE8, 0x78, 0x48, 0x41, 0x71, 0x2B, 0x18, + 0x96, 0x80, 0x11, 0xDB, 0x68, 0x39, 0x9C, 0xD6, 0xE0, 0x72, 0x42, 0x86, 0xF0, 0x1B, 0x16, + 0x0D, 0x3E, 0x12, 0x94, 0x3D, 0x25, 0xA8, 0xA9, 0x30, 0x9E, 0x54, 0x5A, 0xD6, 0x36, 0x6C, + 0xD6, 0x8C, 0x20, 0x62, 0x8F, 0xA1, 0x6B, 0x1F, 0x7C, 0x6D, 0xB2, 0xB1, 0xC1, 0x2E, 0xAD, + 0x36, 0x02, 0x9C, 0x3A, 0xCA, 0x2F, 0x09, 0xD2, 0x45, 0x9E, 0xEB, 0xF2, 0xBC, 0x6C, 0xAA, + 0x3B, 0x3E, 0x90, 0xBC, 0x38, 0x67, 0x35, 0x4D}; // e - const CryptoPP::byte* PublicExponent; + static constexpr CryptoPP::byte PublicExponent[] = {0, 1, 0, 1}; // (InverseQ)(q) = 1 mod p - const CryptoPP::byte* Coefficient; + static constexpr CryptoPP::byte Coefficient[] = { + 0x0B, 0x67, 0x1C, 0x0D, 0x6C, 0x57, 0xD3, 0xE7, 0x05, 0x65, 0x94, 0x31, 0x56, 0x55, 0xFD, + 0x28, 0x08, 0xFA, 0x05, 0x8A, 0xCC, 0x55, 0x39, 0x61, 0x97, 0x63, 0xA0, 0x16, 0x27, 0x3D, + 0xED, 0xC1, 0x16, 0x40, 0x2A, 0x12, 0xEA, 0x6F, 0xD9, 0xD8, 0x58, 0x56, 0xA8, 0x56, 0x8B, + 0x0D, 0x38, 0x5E, 0x1E, 0x80, 0x3B, 0x5F, 0x40, 0x80, 0x6F, 0x62, 0x4F, 0x28, 0xA2, 0x69, + 0xF3, 0xD3, 0xF7, 0xFD, 0xB2, 0xC3, 0x52, 0x43, 0x20, 0x92, 0x9D, 0x97, 0x8D, 0xA0, 0x15, + 0x07, 0x15, 0x6E, 0xA4, 0x0D, 0x56, 0xD3, 0x37, 0x1A, 0xC4, 0x9E, 0xDF, 0x02, 0x49, 0xB8, + 0x0A, 0x84, 0x62, 0xF5, 0xFA, 0xB9, 0x3F, 0xA4, 0x09, 0x76, 0xCC, 0xAA, 0xB9, 0x9B, 0xA6, + 0x4F, 0xC1, 0x6A, 0x64, 0xCE, 0xD8, 0x77, 0xAB, 0x4B, 0xF9, 0xA0, 0xAE, 0xDA, 0xF1, 0x67, + 0x87, 0x7C, 0x98, 0x5C, 0x7E, 0xB8, 0x73, 0xF5}; // n = p * q - const CryptoPP::byte* Modulus; + static constexpr CryptoPP::byte Modulus[] = { + 0xC6, 0xCF, 0x71, 0xE7, 0xE5, 0x9A, 0xF0, 0xD1, 0x2A, 0x2C, 0x45, 0x8B, 0xF9, 0x2A, 0x0E, + 0xC1, 0x43, 0x05, 0x8B, 0xC3, 0x71, 0x17, 0x80, 0x1D, 0xCD, 0x49, 0x7D, 0xDE, 0x35, 0x9D, + 0x25, 0x9B, 0xA0, 0xD7, 0xA0, 0xF2, 0x7D, 0x6C, 0x08, 0x7E, 0xAA, 0x55, 0x02, 0x68, 0x2B, + 0x23, 0xC6, 0x44, 0xB8, 0x44, 0x18, 0xEB, 0x56, 0xCF, 0x16, 0xA2, 0x48, 0x03, 0xC9, 0xE7, + 0x4F, 0x87, 0xEB, 0x3D, 0x30, 0xC3, 0x15, 0x88, 0xBF, 0x20, 0xE7, 0x9D, 0xFF, 0x77, 0x0C, + 0xDE, 0x1D, 0x24, 0x1E, 0x63, 0xA9, 0x4F, 0x8A, 0xBF, 0x5B, 0xBE, 0x60, 0x19, 0x68, 0x33, + 0x3B, 0xFC, 0xED, 0x9F, 0x47, 0x4E, 0x5F, 0xF8, 0xEA, 0xCB, 0x3D, 0x00, 0xBD, 0x67, 0x01, + 0xF9, 0x2C, 0x6D, 0xC6, 0xAC, 0x13, 0x64, 0xE7, 0x67, 0x14, 0xF3, 0xDC, 0x52, 0x69, 0x6A, + 0xB9, 0x83, 0x2C, 0x42, 0x30, 0x13, 0x1B, 0xB2, 0xD8, 0xA5, 0x02, 0x0D, 0x79, 0xED, 0x96, + 0xB1, 0x0D, 0xF8, 0xCC, 0x0C, 0xDF, 0x81, 0x95, 0x4F, 0x03, 0x58, 0x09, 0x57, 0x0E, 0x80, + 0x69, 0x2E, 0xFE, 0xFF, 0x52, 0x77, 0xEA, 0x75, 0x28, 0xA8, 0xFB, 0xC9, 0xBE, 0xBF, 0x9F, + 0xBB, 0xB7, 0x79, 0x8E, 0x18, 0x05, 0xE1, 0x80, 0xBD, 0x50, 0x34, 0x94, 0x81, 0xD3, 0x53, + 0xC2, 0x69, 0xA2, 0xD2, 0x4C, 0xCF, 0x6C, 0xF4, 0x57, 0x2C, 0x10, 0x4A, 0x3F, 0xFB, 0x22, + 0xFD, 0x8B, 0x97, 0xE2, 0xC9, 0x5B, 0xA6, 0x2B, 0xCD, 0xD6, 0x1B, 0x6B, 0xDB, 0x68, 0x7F, + 0x4B, 0xC2, 0xA0, 0x50, 0x34, 0xC0, 0x05, 0xE5, 0x8D, 0xEF, 0x24, 0x67, 0xFF, 0x93, 0x40, + 0xCF, 0x2D, 0x62, 0xA2, 0xA0, 0x50, 0xB1, 0xF1, 0x3A, 0xA8, 0x3D, 0xFD, 0x80, 0xD1, 0xF9, + 0xB8, 0x05, 0x22, 0xAF, 0xC8, 0x35, 0x45, 0x90, 0x58, 0x8E, 0xE3, 0x3A, 0x7C, 0xBD, 0x3E, + 0x27}; // p - const CryptoPP::byte* Prime1; + static constexpr CryptoPP::byte Prime1[] = { + 0xFE, 0xF6, 0xBF, 0x1D, 0x69, 0xAB, 0x16, 0x25, 0x08, 0x47, 0x55, 0x6B, 0x86, 0xE4, 0x35, + 0x88, 0x72, 0x2A, 0xB1, 0x3D, 0xF8, 0xB6, 0x44, 0xCA, 0xB3, 0xAB, 0x19, 0xD1, 0x04, 0x24, + 0x28, 0x0A, 0x74, 0x55, 0xB8, 0x15, 0x45, 0x09, 0xCC, 0x13, 0x1C, 0xF2, 0xBA, 0x37, 0xA9, + 0x03, 0x90, 0x8F, 0x02, 0x10, 0xFF, 0x25, 0x79, 0x86, 0xCC, 0x18, 0x50, 0x9A, 0x10, 0x5F, + 0x5B, 0x4C, 0x1C, 0x4E, 0xB0, 0xA7, 0xE3, 0x59, 0xB1, 0x2D, 0xA0, 0xC6, 0xB0, 0x20, 0x2C, + 0x21, 0x33, 0x12, 0xB3, 0xAF, 0x72, 0x34, 0x83, 0xCD, 0x52, 0x2F, 0xAF, 0x0F, 0x20, 0x5A, + 0x1B, 0xC0, 0xE2, 0xA3, 0x76, 0x34, 0x0F, 0xD7, 0xFC, 0xC1, 0x41, 0xC9, 0xF9, 0x79, 0x40, + 0x17, 0x42, 0x21, 0x3E, 0x9D, 0xFD, 0xC7, 0xC1, 0x50, 0xDE, 0x44, 0x5A, 0xC9, 0x31, 0x89, + 0x6A, 0x78, 0x05, 0xBE, 0x65, 0xB4, 0xE8, 0x2D}; // q - const CryptoPP::byte* Prime2; - const CryptoPP::byte* PrivateExponent; - - // Constructor - FakeKeyset() { - // Initialize PrivateExponent - PrivateExponent = new CryptoPP::byte[0x100]{ - 0x7F, 0x76, 0xCD, 0x0E, 0xE2, 0xD4, 0xDE, 0x05, 0x1C, 0xC6, 0xD9, 0xA8, 0x0E, 0x8D, - 0xFA, 0x7B, 0xCA, 0x1E, 0xAA, 0x27, 0x1A, 0x40, 0xF8, 0xF1, 0x22, 0x87, 0x35, 0xDD, - 0xDB, 0xFD, 0xEE, 0xF8, 0xC2, 0xBC, 0xBD, 0x01, 0xFB, 0x8B, 0xE2, 0x3E, 0x63, 0xB2, - 0xB1, 0x22, 0x5C, 0x56, 0x49, 0x6E, 0x11, 0xBE, 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, 0xF5, 0x4D, 0x1F, 0x37, 0x83, 0x40, 0x4A, - 0xEC, 0x39, 0x37, 0xA6, 0x80, 0x92, 0x7D, 0xC5, 0x80, 0xC7, 0xD6, 0x6F, 0xFE, 0x8A, - 0x79, 0x89, 0xC6, 0xB1}; - - // Initialize Exponent1 - Exponent1 = new CryptoPP::byte[0x80]{ - 0x6D, 0x48, 0xE0, 0x54, 0x40, 0x25, 0xC8, 0x41, 0x29, 0x52, 0x42, 0x27, 0xEB, - 0xD2, 0xC7, 0xAB, 0x6B, 0x9C, 0x27, 0x0A, 0xB4, 0x1F, 0x94, 0x4E, 0xFA, 0x42, - 0x1D, 0xB7, 0xBC, 0xB9, 0xAE, 0xBC, 0x04, 0x6F, 0x75, 0x8F, 0x10, 0x5F, 0x89, - 0xAC, 0xAB, 0x9C, 0xD2, 0xFA, 0xE6, 0xA4, 0x13, 0x83, 0x68, 0xD4, 0x56, 0x38, - 0xFE, 0xE5, 0x2B, 0x78, 0x44, 0x9C, 0x34, 0xE6, 0x5A, 0xA0, 0xBE, 0x05, 0x70, - 0xAD, 0x15, 0xC3, 0x2D, 0x31, 0xAC, 0x97, 0x5D, 0x88, 0xFC, 0xC1, 0x62, 0x3D, - 0xE2, 0xED, 0x11, 0xDB, 0xB6, 0x9E, 0xFC, 0x5A, 0x5A, 0x03, 0xF6, 0xCF, 0x08, - 0xD4, 0x5D, 0x90, 0xC9, 0x2A, 0xB9, 0x9B, 0xCF, 0xC8, 0x1A, 0x65, 0xF3, 0x5B, - 0xE8, 0x7F, 0xCF, 0xA5, 0xA6, 0x4C, 0x5C, 0x2A, 0x12, 0x0F, 0x92, 0xA5, 0xE3, - 0xF0, 0x17, 0x1E, 0x9A, 0x97, 0x45, 0x86, 0xFD, 0xDB, 0x54, 0x25 - - }; - - Exponent2 = new CryptoPP::byte[0x80]{ - 0x2A, 0x51, 0xCE, 0x02, 0x44, 0x28, 0x50, 0xE8, 0x30, 0x20, 0x7C, 0x9C, 0x55, - 0xBF, 0x60, 0x39, 0xBC, 0xD1, 0xF0, 0xE7, 0x68, 0xF8, 0x08, 0x5B, 0x61, 0x1F, - 0xA7, 0xBF, 0xD0, 0xE8, 0x8B, 0xB5, 0xB1, 0xD5, 0xD9, 0x16, 0xAC, 0x75, 0x0C, - 0x6D, 0xF2, 0xE0, 0xB5, 0x97, 0x75, 0xD2, 0x68, 0x16, 0x1F, 0x00, 0x7D, 0x8B, - 0x17, 0xE8, 0x78, 0x48, 0x41, 0x71, 0x2B, 0x18, 0x96, 0x80, 0x11, 0xDB, 0x68, - 0x39, 0x9C, 0xD6, 0xE0, 0x72, 0x42, 0x86, 0xF0, 0x1B, 0x16, 0x0D, 0x3E, 0x12, - 0x94, 0x3D, 0x25, 0xA8, 0xA9, 0x30, 0x9E, 0x54, 0x5A, 0xD6, 0x36, 0x6C, 0xD6, - 0x8C, 0x20, 0x62, 0x8F, 0xA1, 0x6B, 0x1F, 0x7C, 0x6D, 0xB2, 0xB1, 0xC1, 0x2E, - 0xAD, 0x36, 0x02, 0x9C, 0x3A, 0xCA, 0x2F, 0x09, 0xD2, 0x45, 0x9E, 0xEB, 0xF2, - 0xBC, 0x6C, 0xAA, 0x3B, 0x3E, 0x90, 0xBC, 0x38, 0x67, 0x35, 0x4D}; - - PublicExponent = new CryptoPP::byte[4]{0, 1, 0, 1}; - - Coefficient = new CryptoPP::byte[0x80]{ - 0x0B, 0x67, 0x1C, 0x0D, 0x6C, 0x57, 0xD3, 0xE7, 0x05, 0x65, 0x94, 0x31, 0x56, - 0x55, 0xFD, 0x28, 0x08, 0xFA, 0x05, 0x8A, 0xCC, 0x55, 0x39, 0x61, 0x97, 0x63, - 0xA0, 0x16, 0x27, 0x3D, 0xED, 0xC1, 0x16, 0x40, 0x2A, 0x12, 0xEA, 0x6F, 0xD9, - 0xD8, 0x58, 0x56, 0xA8, 0x56, 0x8B, 0x0D, 0x38, 0x5E, 0x1E, 0x80, 0x3B, 0x5F, - 0x40, 0x80, 0x6F, 0x62, 0x4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0xCA, 0xB3, 0xAB, - 0x19, 0xD1, 0x04, 0x24, 0x28, 0x0A, 0x74, 0x55, 0xB8, 0x15, 0x45, 0x09, 0xCC, - 0x13, 0x1C, 0xF2, 0xBA, 0x37, 0xA9, 0x03, 0x90, 0x8F, 0x02, 0x10, 0xFF, 0x25, - 0x79, 0x86, 0xCC, 0x18, 0x50, 0x9A, 0x10, 0x5F, 0x5B, 0x4C, 0x1C, 0x4E, 0xB0, - 0xA7, 0xE3, 0x59, 0xB1, 0x2D, 0xA0, 0xC6, 0xB0, 0x20, 0x2C, 0x21, 0x33, 0x12, - 0xB3, 0xAF, 0x72, 0x34, 0x83, 0xCD, 0x52, 0x2F, 0xAF, 0x0F, 0x20, 0x5A, 0x1B, - 0xC0, 0xE2, 0xA3, 0x76, 0x34, 0x0F, 0xD7, 0xFC, 0xC1, 0x41, 0xC9, 0xF9, 0x79, - 0x40, 0x17, 0x42, 0x21, 0x3E, 0x9D, 0xFD, 0xC7, 0xC1, 0x50, 0xDE, 0x44, 0x5A, - 0xC9, 0x31, 0x89, 0x6A, 0x78, 0x05, 0xBE, 0x65, 0xB4, 0xE8, 0x2D}; - - Prime2 = new CryptoPP::byte[0x80]{ - 0xC7, 0x9E, 0x47, 0x58, 0x00, 0x7D, 0x62, 0x82, 0xB0, 0xD2, 0x22, 0x81, 0xD4, - 0xA8, 0x97, 0x1B, 0x79, 0x0C, 0x3A, 0xB0, 0xD7, 0xC9, 0x30, 0xE3, 0xC3, 0x53, - 0x8E, 0x57, 0xEF, 0xF0, 0x9B, 0x9F, 0xB3, 0x90, 0x52, 0xC6, 0x94, 0x22, 0x36, - 0xAA, 0xE6, 0x4A, 0x5F, 0x72, 0x1D, 0x70, 0xE8, 0x76, 0x58, 0xC8, 0xB2, 0x91, - 0xCE, 0x9C, 0xC3, 0xE9, 0x09, 0x7F, 0x2E, 0x47, 0x97, 0xCC, 0x90, 0x39, 0x15, - 0x35, 0x31, 0xDE, 0x1F, 0x0C, 0x8C, 0x0D, 0xC1, 0xC2, 0x92, 0xBE, 0x97, 0xBF, - 0x2F, 0x91, 0xA1, 0x8C, 0x7D, 0x50, 0xA8, 0x21, 0x2F, 0xD7, 0xA2, 0x9A, 0x7E, - 0xB5, 0xA7, 0x2A, 0x90, 0x02, 0xD9, 0xF3, 0x3D, 0xD1, 0xEB, 0xB8, 0xE0, 0x5A, - 0x79, 0x9E, 0x7D, 0x8D, 0xCA, 0x18, 0x6D, 0xBD, 0x9E, 0xA1, 0x80, 0x28, 0x6B, - 0x2A, 0xFE, 0x51, 0x24, 0x9B, 0x6F, 0x4D, 0x84, 0x77, 0x80, 0x23}; - }; - - // Destructor - ~FakeKeyset() { - delete[] PrivateExponent; - delete[] Exponent1; - delete[] Exponent2; - delete[] PublicExponent; - delete[] Coefficient; - delete[] Modulus; - delete[] Prime1; - delete[] Prime2; - }; + static constexpr CryptoPP::byte Prime2[] = { + 0xC7, 0x9E, 0x47, 0x58, 0x00, 0x7D, 0x62, 0x82, 0xB0, 0xD2, 0x22, 0x81, 0xD4, 0xA8, 0x97, + 0x1B, 0x79, 0x0C, 0x3A, 0xB0, 0xD7, 0xC9, 0x30, 0xE3, 0xC3, 0x53, 0x8E, 0x57, 0xEF, 0xF0, + 0x9B, 0x9F, 0xB3, 0x90, 0x52, 0xC6, 0x94, 0x22, 0x36, 0xAA, 0xE6, 0x4A, 0x5F, 0x72, 0x1D, + 0x70, 0xE8, 0x76, 0x58, 0xC8, 0xB2, 0x91, 0xCE, 0x9C, 0xC3, 0xE9, 0x09, 0x7F, 0x2E, 0x47, + 0x97, 0xCC, 0x90, 0x39, 0x15, 0x35, 0x31, 0xDE, 0x1F, 0x0C, 0x8C, 0x0D, 0xC1, 0xC2, 0x92, + 0xBE, 0x97, 0xBF, 0x2F, 0x91, 0xA1, 0x8C, 0x7D, 0x50, 0xA8, 0x21, 0x2F, 0xD7, 0xA2, 0x9A, + 0x7E, 0xB5, 0xA7, 0x2A, 0x90, 0x02, 0xD9, 0xF3, 0x3D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xC5, 0x8C, 0xA5, 0xB0, 0x09, 0xE0, + 0xCE, 0x3D, 0xDF, 0xF4, 0x9D, 0x3C, 0x97, 0x15, 0xE2, 0x6A, 0xC7, 0x2B, 0x3C, 0x50, 0x93, + 0x23, 0xDB, 0xBA, 0x4A, 0x22, 0x66, 0x44, 0xAC, 0x78, 0xBB, 0x0E, 0x1A, 0x27, 0x43, 0xB5, + 0x71, 0x67, 0xAF, 0xF4, 0xAB, 0x48, 0x46, 0x93, 0x73, 0xD0, 0x42, 0xAB, 0x93, 0x63, 0xE5, + 0x6C, 0x9A, 0xDE, 0x50, 0x24, 0xC0, 0x23, 0x7D, 0x99, 0x79, 0x3F, 0x22, 0x07, 0xE0, 0xC1, + 0x48, 0x56, 0x1B, 0xDF, 0x83, 0x09, 0x12, 0xB4, 0x2D, 0x45, 0x6B, 0xC9, 0xC0, 0x68, 0x85, + 0x99, 0x90, 0x79, 0x96, 0x1A, 0xD7, 0xF5, 0x4D, 0x1F, 0x37, 0x83, 0x40, 0x4A, 0xEC, 0x39, + 0x37, 0xA6, 0x80, 0x92, 0x7D, 0xC5, 0x80, 0xC7, 0xD6, 0x6F, 0xFE, 0x8A, 0x79, 0x89, 0xC6, + 0xB1}; }; class DebugRifKeyset { public: // std::uint8_t* PrivateExponent; - const CryptoPP::byte* Exponent1; + static constexpr CryptoPP::byte Exponent1[] = { + 0xCD, 0x9A, 0x61, 0xB0, 0xB8, 0xD5, 0xB4, 0xE4, 0xE4, 0xF6, 0xAB, 0xF7, 0x27, 0xB7, 0x56, + 0x59, 0x6B, 0xB9, 0x11, 0xE7, 0xF4, 0x83, 0xAF, 0xB9, 0x73, 0x99, 0x7F, 0x49, 0xA2, 0x9C, + 0xF0, 0xB5, 0x6D, 0x37, 0x82, 0x14, 0x15, 0xF1, 0x04, 0x8A, 0xD4, 0x8E, 0xEB, 0x2E, 0x1F, + 0xE2, 0x81, 0xA9, 0x62, 0x6E, 0xB1, 0x68, 0x75, 0x62, 0xF3, 0x0F, 0xFE, 0xD4, 0x91, 0x87, + 0x98, 0x78, 0xBF, 0x26, 0xB5, 0x07, 0x58, 0xD0, 0xEE, 0x3F, 0x21, 0xE8, 0xC8, 0x0F, 0x5F, + 0xFA, 0x1C, 0x64, 0x74, 0x49, 0x52, 0xEB, 0xE7, 0xEE, 0xDE, 0xBA, 0x23, 0x26, 0x4A, 0xF6, + 0x9C, 0x1A, 0x09, 0x3F, 0xB9, 0x0B, 0x36, 0x26, 0x1A, 0xBE, 0xA9, 0x76, 0xE6, 0xF2, 0x69, + 0xDE, 0xFF, 0xAF, 0xCC, 0x0C, 0x9A, 0x66, 0x03, 0x86, 0x0A, 0x1F, 0x49, 0xA4, 0x10, 0xB6, + 0xBC, 0xC3, 0x7C, 0x88, 0xE8, 0xCE, 0x4B, 0xD9}; // exponent2 = d mod (q - 1) - const CryptoPP::byte* Exponent2; + static constexpr CryptoPP::byte Exponent2[] = { + 0xB3, 0x73, 0xA3, 0x59, 0xE6, 0x97, 0xC0, 0xAB, 0x3B, 0x68, 0xFC, 0x39, 0xAC, 0xDB, 0x44, + 0xB1, 0xB4, 0x9E, 0x35, 0x4D, 0xBE, 0xC5, 0x36, 0x69, 0x6C, 0x3D, 0xC5, 0xFC, 0xFE, 0x4B, + 0x2F, 0xDC, 0x86, 0x80, 0x46, 0x96, 0x40, 0x1A, 0x0D, 0x6E, 0xFA, 0x8C, 0xE0, 0x47, 0x91, + 0xAC, 0xAD, 0x95, 0x2B, 0x8E, 0x1F, 0xF2, 0x0A, 0x45, 0xF8, 0x29, 0x95, 0x70, 0xC6, 0x88, + 0x5F, 0x71, 0x03, 0x99, 0x79, 0xBC, 0x84, 0x71, 0xBD, 0xE8, 0x84, 0x8C, 0x0E, 0xD4, 0x7B, + 0x30, 0x74, 0x57, 0x1A, 0x95, 0xE7, 0x90, 0x19, 0x8D, 0xAD, 0x8B, 0x4C, 0x4E, 0xC3, 0xE7, + 0x6B, 0x23, 0x86, 0x01, 0xEE, 0x9B, 0xE0, 0x2F, 0x15, 0xA2, 0x2C, 0x4C, 0x39, 0xD3, 0xDF, + 0x9C, 0x39, 0x01, 0xF1, 0x8C, 0x44, 0x4A, 0x15, 0x44, 0xDC, 0x51, 0xF7, 0x22, 0xD7, 0x7F, + 0x41, 0x7F, 0x68, 0xFA, 0xEE, 0x56, 0xE8, 0x05}; // e - const CryptoPP::byte* PublicExponent; + static constexpr CryptoPP::byte PublicExponent[] = {0x00, 0x01, 0x00, 0x01}; // (InverseQ)(q) = 1 mod p - const CryptoPP::byte* Coefficient; + static constexpr CryptoPP::byte Coefficient[] = { + 0xC0, 0x32, 0x43, 0xD3, 0x8C, 0x3D, 0xB4, 0xD2, 0x48, 0x8C, 0x42, 0x41, 0x24, 0x94, 0x6C, + 0x80, 0xC9, 0xC1, 0x79, 0x36, 0x7F, 0xAC, 0xC3, 0xFF, 0x6A, 0x25, 0xEB, 0x2C, 0xFB, 0xD4, + 0x2B, 0xA0, 0xEB, 0xFE, 0x25, 0xE9, 0xC6, 0x77, 0xCE, 0xFE, 0x2D, 0x23, 0xFE, 0xD0, 0xF4, + 0x0F, 0xD9, 0x7E, 0xD5, 0xA5, 0x7D, 0x1F, 0xC0, 0xE8, 0xE8, 0xEC, 0x80, 0x5B, 0xC7, 0xFD, + 0xE2, 0xBD, 0x94, 0xA6, 0x2B, 0xDD, 0x6A, 0x60, 0x45, 0x54, 0xAB, 0xCA, 0x42, 0x9C, 0x6A, + 0x6C, 0xBF, 0x3C, 0x84, 0xF9, 0xA5, 0x0E, 0x63, 0x0C, 0x51, 0x58, 0x62, 0x6D, 0x5A, 0xB7, + 0x3C, 0x3F, 0x49, 0x1A, 0xD0, 0x93, 0xB8, 0x4F, 0x1A, 0x6C, 0x5F, 0xC5, 0xE5, 0xA9, 0x75, + 0xD4, 0x86, 0x9E, 0xDF, 0x87, 0x0F, 0x27, 0xB0, 0x26, 0x78, 0x4E, 0xFB, 0xC1, 0x8A, 0x4A, + 0x24, 0x3F, 0x7F, 0x8F, 0x9A, 0x12, 0x51, 0xCB}; // n = p * q - const CryptoPP::byte* Modulus; + static constexpr CryptoPP::byte Modulus[] = { + 0xC2, 0xD2, 0x44, 0xBC, 0xDD, 0x84, 0x3F, 0xD9, 0xC5, 0x22, 0xAF, 0xF7, 0xFC, 0x88, 0x8A, + 0x33, 0x80, 0xED, 0x8E, 0xE2, 0xCC, 0x81, 0xF7, 0xEC, 0xF8, 0x1C, 0x79, 0xBF, 0x02, 0xBB, + 0x12, 0x8E, 0x61, 0x68, 0x29, 0x1B, 0x15, 0xB6, 0x5E, 0xC6, 0xF8, 0xBF, 0x5A, 0xE0, 0x3B, + 0x6A, 0x6C, 0xD9, 0xD6, 0xF5, 0x75, 0xAB, 0xA0, 0x6F, 0x34, 0x81, 0x34, 0x9A, 0x5B, 0xAD, + 0xED, 0x31, 0xE3, 0xC6, 0xEA, 0x1A, 0xD1, 0x13, 0x22, 0xBB, 0xB3, 0xDA, 0xB3, 0xB2, 0x53, + 0xBD, 0x45, 0x79, 0x87, 0xAD, 0x0A, 0x01, 0x72, 0x18, 0x10, 0x29, 0x49, 0xF4, 0x41, 0x7F, + 0xD6, 0x47, 0x0C, 0x72, 0x92, 0x9E, 0xE9, 0xBB, 0x95, 0xA9, 0x5D, 0x79, 0xEB, 0xE4, 0x30, + 0x76, 0x90, 0x45, 0x4B, 0x9D, 0x9C, 0xCF, 0x92, 0x03, 0x60, 0x8C, 0x4B, 0x6C, 0xB3, 0x7A, + 0x3A, 0x05, 0x39, 0xA0, 0x66, 0xA9, 0x35, 0xCF, 0xB9, 0xFA, 0xAD, 0x9C, 0xAB, 0xEB, 0xE4, + 0x6A, 0x8C, 0xE9, 0x3B, 0xCC, 0x72, 0x12, 0x62, 0x63, 0xBD, 0x80, 0xC4, 0xEE, 0x37, 0x2B, + 0x32, 0x03, 0xA3, 0x09, 0xF7, 0xA0, 0x61, 0x57, 0xAD, 0x0D, 0xCF, 0x15, 0x98, 0x9E, 0x4E, + 0x49, 0xF8, 0xB5, 0xA3, 0x5C, 0x27, 0xEE, 0x45, 0x04, 0xEA, 0xE4, 0x4B, 0xBC, 0x8F, 0x87, + 0xED, 0x19, 0x1E, 0x46, 0x75, 0x63, 0xC4, 0x5B, 0xD5, 0xBC, 0x09, 0x2F, 0x02, 0x73, 0x19, + 0x3C, 0x58, 0x55, 0x49, 0x66, 0x4C, 0x11, 0xEC, 0x0F, 0x09, 0xFA, 0xA5, 0x56, 0x0A, 0x5A, + 0x63, 0x56, 0xAD, 0xA0, 0x0D, 0x86, 0x08, 0xC1, 0xE6, 0xB6, 0x13, 0x22, 0x49, 0x2F, 0x7C, + 0xDB, 0x4C, 0x56, 0x97, 0x0E, 0xC2, 0xD9, 0x2E, 0x87, 0xBC, 0x0E, 0x67, 0xC0, 0x1B, 0x58, + 0xBC, 0x64, 0x2B, 0xC2, 0x6E, 0xE2, 0x93, 0x2E, 0xB5, 0x6B, 0x70, 0xA4, 0x42, 0x9F, 0x64, + 0xC1}; // p - const CryptoPP::byte* Prime1; + static constexpr CryptoPP::byte Prime1[] = { + 0xE5, 0x62, 0xE1, 0x7F, 0x9F, 0x86, 0x08, 0xE2, 0x61, 0xD3, 0xD0, 0x42, 0xE2, 0xC4, 0xB6, + 0xA8, 0x51, 0x09, 0x19, 0x14, 0xA4, 0x3A, 0x11, 0x4C, 0x33, 0xA5, 0x9C, 0x01, 0x5E, 0x34, + 0xB6, 0x3F, 0x02, 0x1A, 0xCA, 0x47, 0xF1, 0x4F, 0x3B, 0x35, 0x2A, 0x07, 0x20, 0xEC, 0xD8, + 0xC1, 0x15, 0xD9, 0xCA, 0x03, 0x4F, 0xB8, 0xE8, 0x09, 0x73, 0x3F, 0x85, 0xB7, 0x41, 0xD5, + 0x51, 0x3E, 0x7B, 0xE3, 0x53, 0x2B, 0x48, 0x8B, 0x8E, 0xCB, 0xBA, 0xF7, 0xE0, 0x60, 0xF5, + 0x35, 0x0E, 0x6F, 0xB0, 0xD9, 0x2A, 0x99, 0xD0, 0xFF, 0x60, 0x14, 0xED, 0x40, 0xEA, 0xF8, + 0xD7, 0x0B, 0xC3, 0x8D, 0x8C, 0xE8, 0x81, 0xB3, 0x75, 0x93, 0x15, 0xB3, 0x7D, 0xF6, 0x39, + 0x60, 0x1A, 0x00, 0xE7, 0xC3, 0x27, 0xAD, 0xA4, 0x33, 0xD5, 0x3E, 0xA4, 0x35, 0x48, 0x6F, + 0x22, 0xEF, 0x5D, 0xDD, 0x7D, 0x7B, 0x61, 0x05}; // q - const CryptoPP::byte* Prime2; - const CryptoPP::byte* PrivateExponent; - - // Constructor - DebugRifKeyset() { - // Initialize PrivateExponent - PrivateExponent = new CryptoPP::byte[0x100]{ - 0x01, 0x61, 0xAD, 0xD8, 0x9C, 0x06, 0x89, 0xD0, 0x60, 0xC8, 0x41, 0xF0, 0xB3, 0x83, - 0x01, 0x5D, 0xE3, 0xA2, 0x6B, 0xA2, 0xBA, 0x9A, 0x0A, 0x58, 0xCD, 0x1A, 0xA0, 0x97, - 0x64, 0xEC, 0xD0, 0x31, 0x1F, 0xCA, 0x36, 0x0E, 0x69, 0xDD, 0x40, 0xF7, 0x4E, 0xC0, - 0xC6, 0xA3, 0x73, 0xF0, 0x69, 0x84, 0xB2, 0xF4, 0x4B, 0x29, 0x14, 0x2A, 0x6D, 0xB8, - 0x23, 0xD8, 0x1B, 0x61, 0xD4, 0x9E, 0x87, 0xB3, 0xBB, 0xA9, 0xC4, 0x85, 0x4A, 0xF8, - 0x03, 0x4A, 0xBF, 0xFE, 0xF9, 0xFE, 0x8B, 0xDD, 0x54, 0x83, 0xBA, 0xE0, 0x2F, 0x3F, - 0xB1, 0xEF, 0xA5, 0x05, 0x5D, 0x28, 0x8B, 0xAB, 0xB5, 0xD0, 0x23, 0x2F, 0x8A, 0xCF, - 0x48, 0x7C, 0xAA, 0xBB, 0xC8, 0x5B, 0x36, 0x27, 0xC5, 0x16, 0xA4, 0xB6, 0x61, 0xAC, - 0x0C, 0x28, 0x47, 0x79, 0x3F, 0x38, 0xAE, 0x5E, 0x25, 0xC6, 0xAF, 0x35, 0xAE, 0xBC, - 0xB0, 0xF3, 0xBC, 0xBD, 0xFD, 0xA4, 0x87, 0x0D, 0x14, 0x3D, 0x90, 0xE4, 0xDE, 0x5D, - 0x1D, 0x46, 0x81, 0xF1, 0x28, 0x6D, 0x2F, 0x2C, 0x5E, 0x97, 0x2D, 0x89, 0x2A, 0x51, - 0x72, 0x3C, 0x20, 0x02, 0x59, 0xB1, 0x98, 0x93, 0x05, 0x1E, 0x3F, 0xA1, 0x8A, 0x69, - 0x30, 0x0E, 0x70, 0x84, 0x8B, 0xAE, 0x97, 0xA1, 0x08, 0x95, 0x63, 0x4C, 0xC7, 0xE8, - 0x5D, 0x59, 0xCA, 0x78, 0x2A, 0x23, 0x87, 0xAC, 0x6F, 0x04, 0x33, 0xB1, 0x61, 0xB9, - 0xF0, 0x95, 0xDA, 0x33, 0xCC, 0xE0, 0x4C, 0x82, 0x68, 0x82, 0x14, 0x51, 0xBE, 0x49, - 0x1C, 0x58, 0xA2, 0x8B, 0x05, 0x4E, 0x98, 0x37, 0xEB, 0x94, 0x0B, 0x01, 0x22, 0xDC, - 0xB3, 0x19, 0xCA, 0x77, 0xA6, 0x6E, 0x97, 0xFF, 0x8A, 0x53, 0x5A, 0xC5, 0x24, 0xE4, - 0xAF, 0x6E, 0xA8, 0x2B, 0x53, 0xA4, 0xBE, 0x96, 0xA5, 0x7B, 0xCE, 0x22, 0x56, 0xA3, - 0xF1, 0xCF, 0x14, 0xA5}; - - // Initialize Exponent1 - Exponent1 = new CryptoPP::byte[0x80]{ - 0xCD, 0x9A, 0x61, 0xB0, 0xB8, 0xD5, 0xB4, 0xE4, 0xE4, 0xF6, 0xAB, 0xF7, 0x27, - 0xB7, 0x56, 0x59, 0x6B, 0xB9, 0x11, 0xE7, 0xF4, 0x83, 0xAF, 0xB9, 0x73, 0x99, - 0x7F, 0x49, 0xA2, 0x9C, 0xF0, 0xB5, 0x6D, 0x37, 0x82, 0x14, 0x15,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x8D, 0xAD, 0x8B, 0x4C, 0x4E, 0xC3, 0xE7, 0x6B, - 0x23, 0x86, 0x01, 0xEE, 0x9B, 0xE0, 0x2F, 0x15, 0xA2, 0x2C, 0x4C, 0x39, 0xD3, - 0xDF, 0x9C, 0x39, 0x01, 0xF1, 0x8C, 0x44, 0x4A, 0x15, 0x44, 0xDC, 0x51, 0xF7, - 0x22, 0xD7, 0x7F, 0x41, 0x7F, 0x68, 0xFA, 0xEE, 0x56, 0xE8, 0x05}; - - PublicExponent = new CryptoPP::byte[4]{0x00, 0x01, 0x00, 0x01}; - - Coefficient = new CryptoPP::byte[0x80]{ - 0xC0, 0x32, 0x43, 0xD3, 0x8C, 0x3D, 0xB4, 0xD2, 0x48, 0x8C, 0x42, 0x41, 0x24, - 0x94, 0x6C, 0x80, 0xC9, 0xC1, 0x79, 0x36, 0x7F, 0xAC, 0xC3, 0xFF, 0x6A, 0x25, - 0xEB, 0x2C, 0xFB, 0xD4, 0x2B, 0xA0, 0xEB, 0xFE, 0x25, 0xE9, 0xC6, 0x77, 0xCE, - 0xFE, 0x2D, 0x23, 0xFE, 0xD0, 0xF4, 0x0F, 0xD9, 0x7E, 0xD5, 0xA5, 0x7D, 0x1F, - 0xC0, 0xE8, 0xE8, 0xEC, 0x80, 0x5B, 0xC7, 0xFD, 0xE2, 0xBD, 0x94, 0xA6, 0x2B, - 0xDD, 0x6A, 0x60, 0x45, 0x54, 0xAB, 0xCA, 0x42, 0x9C, 0x6A, 0x6C, 0xBF, 0x3C, - 0x84, 0xF9, 0xA5, 0x0E, 0x63, 0x0C, 0x51, 0x58, 0x62, 0x6D, 0x5A, 0xB7, 0x3C, - 0x3F, 0x49, 0x1A, 0xD0, 0x93, 0xB8, 0x4F, 0x1A, 0x6C, 0x5F, 0xC5, 0xE5, 0xA9, - 0x75, 0xD4, 0x86, 0x9E, 0xDF, 0x87, 0x0F, 0x27, 0xB0, 0x26, 0x78, 0x4E, 0xFB, - 0xC1, 0x8A, 0x4A, 0x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 0xEA, 0xF8, 0xD7, - 0x0B, 0xC3, 0x8D, 0x8C, 0xE8, 0x81, 0xB3, 0x75, 0x93, 0x15, 0xB3, 0x7D, 0xF6, - 0x39, 0x60, 0x1A, 0x00, 0xE7, 0xC3, 0x27, 0xAD, 0xA4, 0x33, 0xD5, 0x3E, 0xA4, - 0x35, 0x48, 0x6F, 0x22, 0xEF, 0x5D, 0xDD, 0x7D, 0x7B, 0x61, 0x05}; - - Prime2 = new CryptoPP::byte[0x80]{ - 0xD9, 0x6C, 0xC2, 0x0C, 0xF7, 0xAE, 0xD1, 0xF3, 0x3B, 0x3B, 0x49, 0x1E, 0x9F, - 0x12, 0x9C, 0xA1, 0x78, 0x1F, 0x35, 0x1D, 0x98, 0x26, 0x13, 0x71, 0xF9, 0x09, - 0xFD, 0xF0, 0xAD, 0x38, 0x55, 0xB7, 0xEE, 0x61, 0x04, 0x72, 0x51, 0x87, 0x2E, - 0x05, 0x84, 0xB1, 0x1D, 0x0C, 0x0D, 0xDB, 0xD4, 0x25, 0x3E, 0x26, 0xED, 0xEA, - 0xB8, 0xF7, 0x49, 0xFE, 0xA2, 0x94, 0xE6, 0xF2, 0x08, 0x92, 0xA7, 0x85, 0xF5, - 0x30, 0xB9, 0x84, 0x22, 0xBF, 0xCA, 0xF0, 0x5F, 0xCB, 0x31, 0x20, 0x34, 0x49, - 0x16, 0x76, 0x34, 0xCC, 0x7A, 0xCB, 0x96, 0xFE, 0x78, 0x7A, 0x41, 0xFE, 0x9A, - 0xA2, 0x23, 0xF7, 0x68, 0x80, 0xD6, 0xCE, 0x4A, 0x78, 0xA5, 0xB7, 0x05, 0x77, - 0x81, 0x1F, 0xDE, 0x5E, 0xA8, 0x6E, 0x3E, 0x87, 0xEC, 0x44, 0xD2, 0x69, 0xC6, - 0x54, 0x91, 0x6B, 0x5E, 0x13, 0x8A, 0x03, 0x87, 0x05, 0x31, 0x8D}; - }; - - // Destructor - ~DebugRifKeyset() { - delete[] PrivateExponent; - delete[] Exponent1; - delete[] Exponent2; - delete[] PublicExponent; - delete[] Coefficient; - delete[] Modulus; - delete[] Prime1; - delete[] Prime2; - }; + static constexpr CryptoPP::byte Prime2[] = { + 0xD9, 0x6C, 0xC2, 0x0C, 0xF7, 0xAE, 0xD1, 0xF3, 0x3B, 0x3B, 0x49, 0x1E, 0x9F, 0x12, 0x9C, + 0xA1, 0x78, 0x1F, 0x35, 0x1D, 0x98, 0x26, 0x13, 0x71, 0xF9, 0x09, 0xFD, 0xF0, 0xAD, 0x38, + 0x55, 0xB7, 0xEE, 0x61, 0x04, 0x72, 0x51, 0x87, 0x2E, 0x05, 0x84, 0xB1, 0x1D, 0x0C, 0x0D, + 0xDB, 0xD4, 0x25, 0x3E, 0x26, 0xED, 0xEA, 0xB8, 0xF7, 0x49, 0xFE, 0xA2, 0x94, 0xE6, 0xF2, + 0x08, 0x92, 0xA7, 0x85, 0xF5, 0x30, 0xB9, 0x84, 0x22, 0xBF, 0xCA, 0xF0, 0x5F, 0xCB, 0x31, + 0x20, 0x34, 0x49, 0x16, 0x76, 0x34, 0xCC, 0x7A, 0xCB, 0x96, 0xFE, 0x78, 0x7A, 0x41, 0xFE, + 0x9A, 0xA2, 0x23, 0xF7, 0x68, 0x80, 0xD6, 0xCE, 0x4A, 0x78, 0xA5, 0xB7, 0x05, 0x77, 0x81, + 0x1F, 0xDE, 0x5E, 0xA8, 0x6E, 0x3E, 0x87, 0xEC, 0x44, 0xD2, 0x69, 0xC6, 0x54, 0x91, 0x6B, + 0x5E, 0x13, 0x8A, 0x03, 0x87, 0x05, 0x31, 0x8D}; + static constexpr CryptoPP::byte PrivateExponent[] = { + 0x01, 0x61, 0xAD, 0xD8, 0x9C, 0x06, 0x89, 0xD0, 0x60, 0xC8, 0x41, 0xF0, 0xB3, 0x83, 0x01, + 0x5D, 0xE3, 0xA2, 0x6B, 0xA2, 0xBA, 0x9A, 0x0A, 0x58, 0xCD, 0x1A, 0xA0, 0x97, 0x64, 0xEC, + 0xD0, 0x31, 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xA2, 0x8B, 0x05, 0x4E, 0x98, 0x37, 0xEB, 0x94, 0x0B, 0x01, 0x22, 0xDC, 0xB3, + 0x19, 0xCA, 0x77, 0xA6, 0x6E, 0x97, 0xFF, 0x8A, 0x53, 0x5A, 0xC5, 0x24, 0xE4, 0xAF, 0x6E, + 0xA8, 0x2B, 0x53, 0xA4, 0xBE, 0x96, 0xA5, 0x7B, 0xCE, 0x22, 0x56, 0xA3, 0xF1, 0xCF, 0x14, + 0xA5}; }; class PkgDerivedKey3Keyset { public: // std::uint8_t* PrivateExponent; - const CryptoPP::byte* Exponent1; + static constexpr CryptoPP::byte Exponent1[] = { + 0x52, 0xCC, 0x2D, 0xA0, 0x9C, 0x9E, 0x75, 0xE7, 0x28, 0xEE, 0x3D, 0xDE, 0xE3, 0x45, 0xD1, + 0x4F, 0x94, 0x1C, 0xCC, 0xC8, 0x87, 0x29, 0x45, 0x3B, 0x8D, 0x6E, 0xAB, 0x6E, 0x2A, 0xA7, + 0xC7, 0x15, 0x43, 0xA3, 0x04, 0x8F, 0x90, 0x5F, 0xEB, 0xF3, 0x38, 0x4A, 0x77, 0xFA, 0x36, + 0xB7, 0x15, 0x76, 0xB6, 0x01, 0x1A, 0x8E, 0x25, 0x87, 0x82, 0xF1, 0x55, 0xD8, 0xC6, 0x43, + 0x2A, 0xC0, 0xE5, 0x98, 0xC9, 0x32, 0xD1, 0x94, 0x6F, 0xD9, 0x01, 0xBA, 0x06, 0x81, 0xE0, + 0x6D, 0x88, 0xF2, 0x24, 0x2A, 0x25, 0x01, 0x64, 0x5C, 0xBF, 0xF2, 0xD9, 0x99, 0x67, 0x3E, + 0xF6, 0x72, 0xEE, 0xE4, 0xE2, 0x33, 0x5C, 0xF8, 0x00, 0x40, 0xE3, 0x2A, 0x9A, 0xF4, 0x3D, + 0x22, 0x86, 0x44, 0x3C, 0xFB, 0x0A, 0xA5, 0x7C, 0x3F, 0xCC, 0xF5, 0xF1, 0x16, 0xC4, 0xAC, + 0x88, 0xB4, 0xDE, 0x62, 0x94, 0x92, 0x6A, 0x13}; // exponent2 = d mod (q - 1) - const CryptoPP::byte* Exponent2; + static constexpr CryptoPP::byte Exponent2[] = { + 0x7C, 0x9D, 0xAD, 0x39, 0xE0, 0xD5, 0x60, 0x14, 0x94, 0x48, 0x19, 0x7F, 0x88, 0x95, 0xD5, + 0x8B, 0x80, 0xAD, 0x85, 0x8A, 0x4B, 0x77, 0x37, 0x85, 0xD0, 0x77, 0xBB, 0xBF, 0x89, 0x71, + 0x4A, 0x72, 0xCB, 0x72, 0x68, 0x38, 0xEC, 0x02, 0xC6, 0x7D, 0xC6, 0x44, 0x06, 0x33, 0x51, + 0x1C, 0xC0, 0xFF, 0x95, 0x8F, 0x0D, 0x75, 0xDC, 0x25, 0xBB, 0x0B, 0x73, 0x91, 0xA9, 0x6D, + 0x42, 0xD8, 0x03, 0xB7, 0x68, 0xD4, 0x1E, 0x75, 0x62, 0xA3, 0x70, 0x35, 0x79, 0x78, 0x00, + 0xC8, 0xF5, 0xEF, 0x15, 0xB9, 0xFC, 0x4E, 0x47, 0x5A, 0xC8, 0x70, 0x70, 0x5B, 0x52, 0x98, + 0xC0, 0xC2, 0x58, 0x4A, 0x70, 0x96, 0xCC, 0xB8, 0x10, 0xE1, 0x2F, 0x78, 0x8B, 0x2B, 0xA1, + 0x7F, 0xF9, 0xAC, 0xDE, 0xF0, 0xBB, 0x2B, 0xE2, 0x66, 0xE3, 0x22, 0x92, 0x31, 0x21, 0x57, + 0x92, 0xC4, 0xB8, 0xF2, 0x3E, 0x76, 0x20, 0x37}; // e - const CryptoPP::byte* PublicExponent; + static constexpr CryptoPP::byte PublicExponent[] = {0, 1, 0, 1}; // (InverseQ)(q) = 1 mod p - const CryptoPP::byte* Coefficient; + static constexpr CryptoPP::byte Coefficient[] = { + 0x45, 0x97, 0x55, 0xD4, 0x22, 0x08, 0x5E, 0xF3, 0x5C, 0xB4, 0x05, 0x7A, 0xFD, 0xAA, 0x42, + 0x42, 0xAD, 0x9A, 0x8C, 0xA0, 0x6C, 0xBB, 0x1D, 0x68, 0x54, 0x54, 0x6E, 0x3E, 0x32, 0xE3, + 0x53, 0x73, 0x76, 0xF1, 0x3E, 0x01, 0xEA, 0xD3, 0xCF, 0xEB, 0xEB, 0x23, 0x3E, 0xC0, 0xBE, + 0xCE, 0xEC, 0x2C, 0x89, 0x5F, 0xA8, 0x27, 0x3A, 0x4C, 0xB7, 0xE6, 0x74, 0xBC, 0x45, 0x4C, + 0x26, 0xC8, 0x25, 0xFF, 0x34, 0x63, 0x25, 0x37, 0xE1, 0x48, 0x10, 0xC1, 0x93, 0xA6, 0xAF, + 0xEB, 0xBA, 0xE3, 0xA2, 0xF1, 0x3D, 0xEF, 0x63, 0xD8, 0xF4, 0xFD, 0xD3, 0xEE, 0xE2, 0x5D, + 0xE9, 0x33, 0xCC, 0xAD, 0xBA, 0x75, 0x5C, 0x85, 0xAF, 0xCE, 0xA9, 0x3D, 0xD1, 0xA2, 0x17, + 0xF3, 0xF6, 0x98, 0xB3, 0x50, 0x8E, 0x5E, 0xF6, 0xEB, 0x02, 0x8E, 0xA1, 0x62, 0xA7, 0xD6, + 0x2C, 0xEC, 0x91, 0xFF, 0x15, 0x40, 0xD2, 0xE3}; // n = p * q - const CryptoPP::byte* Modulus; + static constexpr CryptoPP::byte Modulus[] = { + 0xd2, 0x12, 0xfc, 0x33, 0x5f, 0x6d, 0xdb, 0x83, 0x16, 0x09, 0x62, 0x8b, 0x03, 0x56, 0x27, + 0x37, 0x82, 0xd4, 0x77, 0x85, 0x35, 0x29, 0x39, 0x2d, 0x52, 0x6b, 0x8c, 0x4c, 0x8c, 0xfb, + 0x06, 0xc1, 0x84, 0x5b, 0xe7, 0xd4, 0xf7, 0xbc, 0xd2, 0x4e, 0x62, 0x45, 0xcd, 0x2a, 0xbb, + 0xd7, 0x77, 0x76, 0x45, 0x36, 0x55, 0x27, 0x3f, 0xb3, 0xf5, 0xf9, 0x8e, 0xda, 0x4b, 0xef, + 0x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30, 0xfd, 0xdc, 0x39, 0x13, 0xd0, 0x7c, 0xdc, 0x8f, 0xed, 0xf9, 0xc9, 0xa3, + 0xc1}; // p - const CryptoPP::byte* Prime1; + static constexpr CryptoPP::byte Prime1[] = { + 0xF9, 0x67, 0xAD, 0x99, 0x12, 0x31, 0x0C, 0x56, 0xA2, 0x2E, 0x16, 0x1C, 0x46, 0xB3, 0x4D, + 0x5B, 0x43, 0xBE, 0x42, 0xA2, 0xF6, 0x86, 0x96, 0x80, 0x42, 0xC3, 0xC7, 0x3F, 0xC3, 0x42, + 0xF5, 0x87, 0x49, 0x33, 0x9F, 0x07, 0x5D, 0x6E, 0x2C, 0x04, 0xFD, 0xE3, 0xE1, 0xB2, 0xAE, + 0x0A, 0x0C, 0xF0, 0xC7, 0xA6, 0x1C, 0xA1, 0x63, 0x50, 0xC8, 0x09, 0x9C, 0x51, 0x24, 0x52, + 0x6C, 0x5E, 0x5E, 0xBD, 0x1E, 0x27, 0x06, 0xBB, 0xBC, 0x9E, 0x94, 0xE1, 0x35, 0xD4, 0x6D, + 0xB3, 0xCB, 0x3C, 0x68, 0xDD, 0x68, 0xB3, 0xFE, 0x6C, 0xCB, 0x8D, 0x82, 0x20, 0x76, 0x23, + 0x63, 0xB7, 0xE9, 0x68, 0x10, 0x01, 0x4E, 0xDC, 0xBA, 0x27, 0x5D, 0x01, 0xC1, 0x2D, 0x80, + 0x5E, 0x2B, 0xAF, 0x82, 0x6B, 0xD8, 0x84, 0xB6, 0x10, 0x52, 0x86, 0xA7, 0x89, 0x8E, 0xAE, + 0x9A, 0xE2, 0x89, 0xC6, 0xF7, 0xD5, 0x87, 0xFB}; // q - const CryptoPP::byte* Prime2; - const CryptoPP::byte* PrivateExponent; - - // Constructor - PkgDerivedKey3Keyset() { - Prime1 = new CryptoPP::byte[0x80]{ - 0xF9, 0x67, 0xAD, 0x99, 0x12, 0x31, 0x0C, 0x56, 0xA2, 0x2E, 0x16, 0x1C, 0x46, - 0xB3, 0x4D, 0x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B, 0x6E, 0x2A, 0xA7, 0xC7, 0x15, 0x43, 0xA3, 0x04, 0x8F, 0x90, 0x5F, 0xEB, - 0xF3, 0x38, 0x4A, 0x77, 0xFA, 0x36, 0xB7, 0x15, 0x76, 0xB6, 0x01, 0x1A, 0x8E, - 0x25, 0x87, 0x82, 0xF1, 0x55, 0xD8, 0xC6, 0x43, 0x2A, 0xC0, 0xE5, 0x98, 0xC9, - 0x32, 0xD1, 0x94, 0x6F, 0xD9, 0x01, 0xBA, 0x06, 0x81, 0xE0, 0x6D, 0x88, 0xF2, - 0x24, 0x2A, 0x25, 0x01, 0x64, 0x5C, 0xBF, 0xF2, 0xD9, 0x99, 0x67, 0x3E, 0xF6, - 0x72, 0xEE, 0xE4, 0xE2, 0x33, 0x5C, 0xF8, 0x00, 0x40, 0xE3, 0x2A, 0x9A, 0xF4, - 0x3D, 0x22, 0x86, 0x44, 0x3C, 0xFB, 0x0A, 0xA5, 0x7C, 0x3F, 0xCC, 0xF5, 0xF1, - 0x16, 0xC4, 0xAC, 0x88, 0xB4, 0xDE, 0x62, 0x94, 0x92, 0x6A, 0x13}; - Exponent2 = new CryptoPP::byte[0x80]{ - 0x7C, 0x9D, 0xAD, 0x39, 0xE0, 0xD5, 0x60, 0x14, 0x94, 0x48, 0x19, 0x7F, 0x88, - 0x95, 0xD5, 0x8B, 0x80, 0xAD, 0x85, 0x8A, 0x4B, 0x77, 0x37, 0x85, 0xD0, 0x77, - 0xBB, 0xBF, 0x89, 0x71, 0x4A, 0x72, 0xCB, 0x72, 0x68, 0x38, 0xEC, 0x02, 0xC6, - 0x7D, 0xC6, 0x44, 0x06, 0x33, 0x51, 0x1C, 0xC0, 0xFF, 0x95, 0x8F, 0x0D, 0x75, - 0xDC, 0x25, 0xBB, 0x0B, 0x73, 0x91, 0xA9, 0x6D, 0x42, 0xD8, 0x03, 0xB7, 0x68, - 0xD4, 0x1E, 0x75, 0x62, 0xA3, 0x70, 0x35, 0x79, 0x78, 0x00, 0xC8, 0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91, 0xFF, 0x15, 0x40, 0xD2, 0xE3}; - Modulus = new CryptoPP::byte[0x100]{ - 0xd2, 0x12, 0xfc, 0x33, 0x5f, 0x6d, 0xdb, 0x83, 0x16, 0x09, 0x62, 0x8b, 0x03, 0x56, - 0x27, 0x37, 0x82, 0xd4, 0x77, 0x85, 0x35, 0x29, 0x39, 0x2d, 0x52, 0x6b, 0x8c, 0x4c, - 0x8c, 0xfb, 0x06, 0xc1, 0x84, 0x5b, 0xe7, 0xd4, 0xf7, 0xbc, 0xd2, 0x4e, 0x62, 0x45, - 0xcd, 0x2a, 0xbb, 0xd7, 0x77, 0x76, 0x45, 0x36, 0x55, 0x27, 0x3f, 0xb3, 0xf5, 0xf9, - 0x8e, 0xda, 0x4b, 0xef, 0xaa, 0x59, 0xae, 0xb3, 0x9b, 0xea, 0x54, 0x98, 0xd2, 0x06, - 0x32, 0x6a, 0x58, 0x31, 0x2a, 0xe0, 0xd4, 0x4f, 0x90, 0xb5, 0x0a, 0x7d, 0xec, 0xf4, - 0x3a, 0x9c, 0x52, 0x67, 0x2d, 0x99, 0x31, 0x8e, 0x0c, 0x43, 0xe6, 0x82, 0xfe, 0x07, - 0x46, 0xe1, 0x2e, 0x50, 0xd4, 0x1f, 0x2d, 0x2f, 0x7e, 0xd9, 0x08, 0xba, 0x06, 0xb3, - 0xbf, 0x2e, 0x20, 0x3f, 0x4e, 0x3f, 0xfe, 0x44, 0xff, 0xaa, 0x50, 0x43, 0x57, 0x91, - 0x69, 0x94, 0x49, 0x15, 0x82, 0x82, 0xe4, 0x0f, 0x4c, 0x8d, 0x9d, 0x2c, 0xc9, 0x5b, - 0x1d, 0x64, 0xbf, 0x88, 0x8b, 0xd4, 0xc5, 0x94, 0xe7, 0x65, 0x47, 0x84, 0x1e, 0xe5, - 0x79, 0x10, 0xfb, 0x98, 0x93, 0x47, 0xb9, 0x7d, 0x85, 0x12, 0xa6, 0x40, 0x98, 0x2c, - 0xf7, 0x92, 0xbc, 0x95, 0x19, 0x32, 0xed, 0xe8, 0x90, 0x56, 0x0d, 0x65, 0xc1, 0xaa, - 0x78, 0xc6, 0x2e, 0x54, 0xfd, 0x5f, 0x54, 0xa1, 0xf6, 0x7e, 0xe5, 0xe0, 0x5f, 0x61, - 0xc1, 0x20, 0xb4, 0xb9, 0xb4, 0x33, 0x08, 0x70, 0xe4, 0xdf, 0x89, 0x56, 0xed, 0x01, - 0x29, 0x46, 0x77, 0x5f, 0x8c, 0xb8, 0xa9, 0xf5, 0x1e, 0x2e, 0xb3, 0xb9, 0xbf, 0xe0, - 0x09, 0xb7, 0x8d, 0x28, 0xd4, 0xa6, 0xc3, 0xb8, 0x1e, 0x1f, 0x07, 0xeb, 0xb4, 0x12, - 0x0b, 0x95, 0xb8, 0x85, 0x30, 0xfd, 0xdc, 0x39, 0x13, 0xd0, 0x7c, 0xdc, 0x8f, 0xed, - 0xf9, 0xc9, 0xa3, 0xc1}; - PublicExponent = new CryptoPP::byte[4]{0, 1, 0, 1}; - }; - - // Destructor - ~PkgDerivedKey3Keyset() { - delete[] Prime1; - delete[] Prime2; - delete[] PrivateExponent; - delete[] Exponent1; - delete[] Exponent2; - delete[] Coefficient; - delete[] Modulus; - delete[] PublicExponent; - }; + static constexpr CryptoPP::byte Prime2[] = { + 0xD7, 0xA1, 0x0F, 0x9A, 0x8B, 0xF2, 0xC9, 0x11, 0x95, 0x32, 0x9A, 0x8C, 0xF0, 0xD9, 0x40, + 0x47, 0xF5, 0x68, 0xA0, 0x0D, 0xBD, 0xC1, 0xFC, 0x43, 0x2F, 0x65, 0xF9, 0xC3, 0x61, 0x0F, + 0x25, 0x77, 0x54, 0xAD, 0xD7, 0x58, 0xAC, 0x84, 0x40, 0x60, 0x8D, 0x3F, 0xF3, 0x65, 0x89, + 0x75, 0xB5, 0xC6, 0x2C, 0x51, 0x1A, 0x2F, 0x1F, 0x22, 0xE4, 0x43, 0x11, 0x54, 0xBE, 0xC9, + 0xB4, 0xC7, 0xB5, 0x1B, 0x05, 0x0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, 0xFB, 0x90, 0xFF, 0xE2, 0x30, 0x50, 0x89, 0x6E, 0xCB, + 0x56, 0xB2, 0xEB, 0xC0, 0x91, 0x16, 0x92, 0x5E, 0x30, 0x8E, 0xAE, 0xC7, 0x94, 0x5D, 0xFD, + 0x35, 0xE1, 0x20, 0xF8, 0xAD, 0x3E, 0xBC, 0x08, 0xBF, 0xC0, 0x36, 0x74, 0x9F, 0xD5, 0xBB, + 0x52, 0x08, 0xFD, 0x06, 0x66, 0xF3, 0x7A, 0xB3, 0x04, 0xF4, 0x75, 0x29, 0x5D, 0xE9, 0x5F, + 0xAA, 0x10, 0x30, 0xB2, 0x0F, 0x5A, 0x1A, 0xC1, 0x2A, 0xB3, 0xFE, 0xCB, 0x21, 0xAD, 0x80, + 0xEC, 0x8F, 0x20, 0x09, 0x1C, 0xDB, 0xC5, 0x58, 0x94, 0xC2, 0x9C, 0xC6, 0xCE, 0x82, 0x65, + 0x3E, 0x57, 0x90, 0xBC, 0xA9, 0x8B, 0x06, 0xB4, 0xF0, 0x72, 0xF6, 0x77, 0xDF, 0x98, 0x64, + 0xF1, 0xEC, 0xFE, 0x37, 0x2D, 0xBC, 0xAE, 0x8C, 0x08, 0x81, 0x1F, 0xC3, 0xC9, 0x89, 0x1A, + 0xC7, 0x42, 0x82, 0x4B, 0x2E, 0xDC, 0x8E, 0x8D, 0x73, 0xCE, 0xB1, 0xCC, 0x01, 0xD9, 0x08, + 0x70, 0x87, 0x3C, 0x44, 0x08, 0xEC, 0x49, 0x8F, 0x81, 0x5A, 0xE2, 0x40, 0xFF, 0x77, 0xFC, + 0x0D}; }; \ No newline at end of file From 905d49fd9691cab31e0a66eb94e3e0181679dbb1 Mon Sep 17 00:00:00 2001 From: squidbus <175574877+squidbus@users.noreply.github.com> Date: Wed, 28 Aug 2024 03:42:53 -0700 Subject: [PATCH 28/36] memory: Fixes for direct memory allocation. (#615) * memory: Size direct memory based on requested flexible memory. * memory: Guard against OrbisProcParam without an OrbisKernelMemParam. * memory: Account for alignment in direct memory suitability checks and add more debugging. --- .../libraries/kernel/memory_management.cpp | 9 ++-- src/core/libraries/kernel/memory_management.h | 2 +- src/core/linker.cpp | 18 +++++--- src/core/memory.cpp | 44 +++++++++++++++---- src/core/memory.h | 9 ++-- 5 files changed, 60 insertions(+), 22 deletions(-) diff --git a/src/core/libraries/kernel/memory_management.cpp b/src/core/libraries/kernel/memory_management.cpp index ab6aa398..3fc837d9 100644 --- a/src/core/libraries/kernel/memory_management.cpp +++ b/src/core/libraries/kernel/memory_management.cpp @@ -15,7 +15,8 @@ namespace Libraries::Kernel { u64 PS4_SYSV_ABI sceKernelGetDirectMemorySize() { LOG_WARNING(Kernel_Vmm, "called"); - return SCE_KERNEL_MAIN_DMEM_SIZE; + const auto* memory = Core::Memory::Instance(); + return memory->GetTotalDirectSize(); } int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u64 len, @@ -52,8 +53,8 @@ int PS4_SYSV_ABI sceKernelAllocateDirectMemory(s64 searchStart, s64 searchEnd, u s32 PS4_SYSV_ABI sceKernelAllocateMainDirectMemory(size_t len, size_t alignment, int memoryType, s64* physAddrOut) { - return sceKernelAllocateDirectMemory(0, SCE_KERNEL_MAIN_DMEM_SIZE, len, alignment, memoryType, - physAddrOut); + const auto searchEnd = static_cast(sceKernelGetDirectMemorySize()); + return sceKernelAllocateDirectMemory(0, searchEnd, len, alignment, memoryType, physAddrOut); } s32 PS4_SYSV_ABI sceKernelCheckedReleaseDirectMemory(u64 start, size_t len) { @@ -78,7 +79,7 @@ s32 PS4_SYSV_ABI sceKernelAvailableDirectMemorySize(u64 searchStart, u64 searchE if (physAddrOut == nullptr || sizeOut == nullptr) { return ORBIS_KERNEL_ERROR_EINVAL; } - if (searchEnd > SCE_KERNEL_MAIN_DMEM_SIZE) { + if (searchEnd > sceKernelGetDirectMemorySize()) { return ORBIS_KERNEL_ERROR_EINVAL; } if (searchEnd <= searchStart) { diff --git a/src/core/libraries/kernel/memory_management.h b/src/core/libraries/kernel/memory_management.h index c9dd86e1..9a447fe8 100644 --- a/src/core/libraries/kernel/memory_management.h +++ b/src/core/libraries/kernel/memory_management.h @@ -6,7 +6,7 @@ #include "common/bit_field.h" #include "common/types.h" -constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 4608_MB; // ~ 4.5GB +constexpr u64 SCE_KERNEL_MAIN_DMEM_SIZE = 5056_MB; // ~ 5GB namespace Libraries::Kernel { diff --git a/src/core/linker.cpp b/src/core/linker.cpp index 6f46fdbe..9783ad96 100644 --- a/src/core/linker.cpp +++ b/src/core/linker.cpp @@ -68,11 +68,19 @@ void Linker::Execute() { } // Configure used flexible memory size. - // if (auto* mem_param = GetProcParam()->mem_param) { - // if (u64* flexible_size = mem_param->flexible_memory_size) { - // memory->SetTotalFlexibleSize(*flexible_size); - // } - // } + if (const auto* proc_param = GetProcParam()) { + if (proc_param->size >= + offsetof(OrbisProcParam, mem_param) + sizeof(OrbisKernelMemParam*)) { + if (const auto* mem_param = proc_param->mem_param) { + if (mem_param->size >= + offsetof(OrbisKernelMemParam, flexible_memory_size) + sizeof(u64*)) { + if (const auto* flexible_size = mem_param->flexible_memory_size) { + memory->SetupMemoryRegions(*flexible_size); + } + } + } + } + } // Init primary thread. Common::SetCurrentThreadName("GAME_MainThread"); diff --git a/src/core/memory.cpp b/src/core/memory.cpp index 0feef260..2722c68a 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -11,9 +11,11 @@ namespace Core { +constexpr u64 SCE_DEFAULT_FLEXIBLE_MEMORY_SIZE = 448_MB; + MemoryManager::MemoryManager() { - // Insert an area that covers direct memory physical block. - dmem_map.emplace(0, DirectMemoryArea{0, SCE_KERNEL_MAIN_DMEM_SIZE}); + // Set up the direct and flexible memory regions. + SetupMemoryRegions(SCE_DEFAULT_FLEXIBLE_MEMORY_SIZE); // Insert a virtual memory area that covers the entire area we manage. const VAddr system_managed_base = impl.SystemManagedVirtualBase(); @@ -35,6 +37,19 @@ MemoryManager::MemoryManager() { MemoryManager::~MemoryManager() = default; +void MemoryManager::SetupMemoryRegions(u64 flexible_size) { + total_flexible_size = flexible_size; + total_direct_size = SCE_KERNEL_MAIN_DMEM_SIZE - flexible_size; + + // Insert an area that covers direct memory physical block. + // Note that this should never be called after direct memory allocations have been made. + dmem_map.clear(); + dmem_map.emplace(0, DirectMemoryArea{0, total_direct_size}); + + LOG_INFO(Kernel_Vmm, "Configured memory regions: flexible size = {:#x}, direct size = {:#x}", + total_flexible_size, total_direct_size); +} + PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size, u64 alignment, int memory_type) { std::scoped_lock lk{mutex}; @@ -42,12 +57,17 @@ PAddr MemoryManager::Allocate(PAddr search_start, PAddr search_end, size_t size, auto dmem_area = FindDmemArea(search_start); const auto is_suitable = [&] { - return dmem_area->second.is_free && dmem_area->second.size >= size; + const auto aligned_base = alignment > 0 ? Common::AlignUp(dmem_area->second.base, alignment) + : dmem_area->second.base; + const auto alignment_size = aligned_base - dmem_area->second.base; + const auto remaining_size = + dmem_area->second.size >= alignment_size ? dmem_area->second.size - alignment_size : 0; + return dmem_area->second.is_free && remaining_size >= size; }; while (!is_suitable() && dmem_area->second.GetEnd() <= search_end) { dmem_area++; } - ASSERT_MSG(is_suitable(), "Unable to find free direct memory area"); + ASSERT_MSG(is_suitable(), "Unable to find free direct memory area: size = {:#x}", size); // Align free position PAddr free_addr = dmem_area->second.base; @@ -333,14 +353,19 @@ int MemoryManager::DirectQueryAvailable(PAddr search_start, PAddr search_end, si continue; } - if (dmem_area->second.size > max_size) { - paddr = dmem_area->second.base; - max_size = dmem_area->second.size; + const auto aligned_base = alignment > 0 ? Common::AlignUp(dmem_area->second.base, alignment) + : dmem_area->second.base; + const auto alignment_size = aligned_base - dmem_area->second.base; + const auto remaining_size = + dmem_area->second.size >= alignment_size ? dmem_area->second.size - alignment_size : 0; + if (remaining_size > max_size) { + paddr = aligned_base; + max_size = remaining_size; } dmem_area++; } - *phys_addr_out = alignment > 0 ? Common::AlignUp(paddr, alignment) : paddr; + *phys_addr_out = paddr; *size_out = max_size; return ORBIS_OK; } @@ -418,7 +443,8 @@ MemoryManager::DMemHandle MemoryManager::CarveDmemArea(PAddr addr, size_t size) const PAddr start_in_area = addr - area.base; const PAddr end_in_vma = start_in_area + size; - ASSERT_MSG(end_in_vma <= area.size, "Mapping cannot fit inside free region"); + ASSERT_MSG(end_in_vma <= area.size, "Mapping cannot fit inside free region: size = {:#x}", + size); if (end_in_vma != area.size) { // Split VMA at the end of the allocated region diff --git a/src/core/memory.h b/src/core/memory.h index d5826967..c8638626 100644 --- a/src/core/memory.h +++ b/src/core/memory.h @@ -130,8 +130,8 @@ public: rasterizer = rasterizer_; } - void SetTotalFlexibleSize(u64 size) { - total_flexible_size = size; + u64 GetTotalDirectSize() const { + return total_direct_size; } u64 GetAvailableFlexibleSize() const { @@ -142,6 +142,8 @@ public: return impl.SystemReservedVirtualBase(); } + void SetupMemoryRegions(u64 flexible_size); + PAddr Allocate(PAddr search_start, PAddr search_end, size_t size, u64 alignment, int memory_type); @@ -217,7 +219,8 @@ private: DMemMap dmem_map; VMAMap vma_map; std::recursive_mutex mutex; - size_t total_flexible_size = 448_MB; + size_t total_direct_size{}; + size_t total_flexible_size{}; size_t flexible_usage{}; Vulkan::Rasterizer* rasterizer{}; }; From 4e6e90dfb9c42151ef9d79493d694068eabc629d Mon Sep 17 00:00:00 2001 From: counter185 <33550839+counter185@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:48:50 +0200 Subject: [PATCH 29/36] add touchpad support, auto reconnect --- src/core/libraries/pad/pad.cpp | 11 ++++++----- src/input/controller.cpp | 16 ++++++++++++++-- src/input/controller.h | 8 ++++++++ src/sdl_window.cpp | 16 ++++++++++++++++ 4 files changed, 44 insertions(+), 7 deletions(-) diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index 5bf9c3af..b617f735 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -309,12 +309,13 @@ int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) { pData[i].angularVelocity.x = 0.0f; pData[i].angularVelocity.y = 0.0f; pData[i].angularVelocity.z = 0.0f; - pData[i].touchData.touchNum = 0; - pData[i].touchData.touch[0].x = 0; - pData[i].touchData.touch[0].y = 0; + pData[i].touchData.touchNum = (states[i].touchpad[0].state ? 1 : 0) + + (states[i].touchpad[1].state ? 1 : 0); + pData[i].touchData.touch[0].x = states[i].touchpad[0].x; + pData[i].touchData.touch[0].y = states[i].touchpad[0].y; pData[i].touchData.touch[0].id = 1; - pData[i].touchData.touch[1].x = 0; - pData[i].touchData.touch[1].y = 0; + pData[i].touchData.touch[1].x = states[i].touchpad[1].x; + pData[i].touchData.touch[1].y = states[i].touchpad[1].y; pData[i].touchData.touch[1].id = 2; pData[i].connected = connected; pData[i].timestamp = states[i].time; diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 4a3db163..cb4529a7 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -132,15 +132,27 @@ bool GameController::SetVibration(u8 smallMotor, u8 largeMotor) { return true; } +void GameController::SetTouchpadState(int touchIndex, bool touchDown, float x, float y) { + if (touchIndex < 2) { // DS4 has 2-point multitouch + auto state = GetLastState(); + + state.time = Libraries::Kernel::sceKernelGetProcessTime(); + state.touchpad[touchIndex].state = touchDown; + state.touchpad[touchIndex].x = static_cast(x * 1920); + state.touchpad[touchIndex].y = static_cast(y * 1080); + AddState(state); + } +} + void GameController::TryOpenSDLController() { if (m_sdl_gamepad == nullptr || !SDL_GamepadConnected(m_sdl_gamepad)) { int gamepad_count; SDL_JoystickID* gamepads = SDL_GetGamepads(&gamepad_count); m_sdl_gamepad = gamepad_count > 0 ? SDL_OpenGamepad(gamepads[0]) : nullptr; SDL_free(gamepads); - } - SetLightBarRGB(0, 0, 255); + SetLightBarRGB(0, 0, 255); + } } } // namespace Input diff --git a/src/input/controller.h b/src/input/controller.h index ef099156..cb9fe172 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -21,10 +21,17 @@ enum class Axis { AxisMax }; +struct TouchpadEntry { + bool state; + u16 x; + u16 y; +}; + struct State { u32 buttonsState = 0; u64 time = 0; int axes[static_cast(Axis::AxisMax)] = {128, 128, 128, 128, 0, 0}; + TouchpadEntry touchpad[2] = {{false, 0, 0}, {false, 0, 0}}; }; inline int GetAxis(int min, int max, int value) { @@ -47,6 +54,7 @@ public: void Axis(int id, Input::Axis axis, int value); void SetLightBarRGB(u8 r, u8 g, u8 b); bool SetVibration(u8 smallMotor, u8 largeMotor); + void SetTouchpadState(int touchIndex, bool touchDown, float x, float y); void TryOpenSDLController(); private: diff --git a/src/sdl_window.cpp b/src/sdl_window.cpp index ff44e6c3..b83afd29 100644 --- a/src/sdl_window.cpp +++ b/src/sdl_window.cpp @@ -98,6 +98,11 @@ void WindowSDL::waitEvent() { case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_UP: case SDL_EVENT_GAMEPAD_AXIS_MOTION: + case SDL_EVENT_GAMEPAD_ADDED: + case SDL_EVENT_GAMEPAD_REMOVED: + case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN: + case SDL_EVENT_GAMEPAD_TOUCHPAD_UP: + case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION: onGamepadEvent(&event); break; case SDL_EVENT_QUIT: @@ -299,6 +304,17 @@ void WindowSDL::onGamepadEvent(const SDL_Event* event) { u32 button = 0; Input::Axis axis = Input::Axis::AxisMax; switch (event->type) { + case SDL_EVENT_GAMEPAD_ADDED: + case SDL_EVENT_GAMEPAD_REMOVED: + controller->TryOpenSDLController(); + break; + case SDL_EVENT_GAMEPAD_TOUCHPAD_DOWN: + case SDL_EVENT_GAMEPAD_TOUCHPAD_UP: + case SDL_EVENT_GAMEPAD_TOUCHPAD_MOTION: + controller->SetTouchpadState(event->gtouchpad.finger, + event->type != SDL_EVENT_GAMEPAD_TOUCHPAD_UP, + event->gtouchpad.x, event->gtouchpad.y); + break; case SDL_EVENT_GAMEPAD_BUTTON_DOWN: case SDL_EVENT_GAMEPAD_BUTTON_UP: button = sdlGamepadToOrbisButton(event->gbutton.button); From 698dade8645fdc542409d6ba1a6d2e1110bbfa11 Mon Sep 17 00:00:00 2001 From: counter185 <33550839+counter185@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:53:07 +0200 Subject: [PATCH 30/36] * --- src/input/controller.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/input/controller.cpp b/src/input/controller.cpp index cb4529a7..ed415e23 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -134,12 +134,14 @@ bool GameController::SetVibration(u8 smallMotor, u8 largeMotor) { void GameController::SetTouchpadState(int touchIndex, bool touchDown, float x, float y) { if (touchIndex < 2) { // DS4 has 2-point multitouch + std::scoped_lock lock{m_mutex}; auto state = GetLastState(); - state.time = Libraries::Kernel::sceKernelGetProcessTime(); + state.touchpad[touchIndex].state = touchDown; state.touchpad[touchIndex].x = static_cast(x * 1920); state.touchpad[touchIndex].y = static_cast(y * 1080); + AddState(state); } } From 0b24ac6991b8829f2d2dda8c903b0af81bcfb5b5 Mon Sep 17 00:00:00 2001 From: counter185 <33550839+counter185@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:56:49 +0200 Subject: [PATCH 31/36] actually get rid of that comment --- src/input/controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/controller.cpp b/src/input/controller.cpp index ed415e23..96273555 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -133,7 +133,7 @@ bool GameController::SetVibration(u8 smallMotor, u8 largeMotor) { } void GameController::SetTouchpadState(int touchIndex, bool touchDown, float x, float y) { - if (touchIndex < 2) { // DS4 has 2-point multitouch + if (touchIndex < 2) { std::scoped_lock lock{m_mutex}; auto state = GetLastState(); state.time = Libraries::Kernel::sceKernelGetProcessTime(); From 15fc267f0d8075bbec4c9a68ea878b14dd1c4dda Mon Sep 17 00:00:00 2001 From: counter185 <33550839+counter185@users.noreply.github.com> Date: Wed, 28 Aug 2024 13:58:37 +0200 Subject: [PATCH 32/36] Update controller.h --- src/input/controller.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/input/controller.h b/src/input/controller.h index cb9fe172..0a0d663a 100644 --- a/src/input/controller.h +++ b/src/input/controller.h @@ -22,9 +22,9 @@ enum class Axis { }; struct TouchpadEntry { - bool state; - u16 x; - u16 y; + bool state{}; + u16 x{}; + u16 y{}; }; struct State { From 89bdd3bba20444e1a9627f04b967834d5c8fef02 Mon Sep 17 00:00:00 2001 From: counter185 <33550839+counter185@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:15:01 +0200 Subject: [PATCH 33/36] it's actually 1920x941 --- src/input/controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/input/controller.cpp b/src/input/controller.cpp index 96273555..4de6d83b 100644 --- a/src/input/controller.cpp +++ b/src/input/controller.cpp @@ -140,7 +140,7 @@ void GameController::SetTouchpadState(int touchIndex, bool touchDown, float x, f state.touchpad[touchIndex].state = touchDown; state.touchpad[touchIndex].x = static_cast(x * 1920); - state.touchpad[touchIndex].y = static_cast(y * 1080); + state.touchpad[touchIndex].y = static_cast(y * 941); AddState(state); } From 2e2f3bb2c682d0305a69f94b29db93482b051161 Mon Sep 17 00:00:00 2001 From: counter185 <33550839+counter185@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:22:59 +0200 Subject: [PATCH 34/36] clang format --- src/core/libraries/pad/pad.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index b617f735..01cc85cc 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -309,8 +309,8 @@ int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) { pData[i].angularVelocity.x = 0.0f; pData[i].angularVelocity.y = 0.0f; pData[i].angularVelocity.z = 0.0f; - pData[i].touchData.touchNum = (states[i].touchpad[0].state ? 1 : 0) - + (states[i].touchpad[1].state ? 1 : 0); + pData[i].touchData.touchNum = + (states[i].touchpad[0].state ? 1 : 0) + (states[i].touchpad[1].state ? 1 : 0); pData[i].touchData.touch[0].x = states[i].touchpad[0].x; pData[i].touchData.touch[0].y = states[i].touchpad[0].y; pData[i].touchData.touch[0].id = 1; From bc661039c541d240c7bb2a4cf6bff9dc66c88c71 Mon Sep 17 00:00:00 2001 From: counter185 <33550839+counter185@users.noreply.github.com> Date: Wed, 28 Aug 2024 14:25:07 +0200 Subject: [PATCH 35/36] get rid of one space --- src/core/libraries/pad/pad.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/libraries/pad/pad.cpp b/src/core/libraries/pad/pad.cpp index 01cc85cc..a0abfdf7 100644 --- a/src/core/libraries/pad/pad.cpp +++ b/src/core/libraries/pad/pad.cpp @@ -309,7 +309,7 @@ int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) { pData[i].angularVelocity.x = 0.0f; pData[i].angularVelocity.y = 0.0f; pData[i].angularVelocity.z = 0.0f; - pData[i].touchData.touchNum = + pData[i].touchData.touchNum = (states[i].touchpad[0].state ? 1 : 0) + (states[i].touchpad[1].state ? 1 : 0); pData[i].touchData.touch[0].x = states[i].touchpad[0].x; pData[i].touchData.touch[0].y = states[i].touchpad[0].y; From 365e17f64ea126d19e40dbf4d8f7ad7a37677de2 Mon Sep 17 00:00:00 2001 From: bigol83 <38129260+bigol83@users.noreply.github.com> Date: Wed, 28 Aug 2024 19:14:33 +0200 Subject: [PATCH 36/36] Update it.ts --- src/qt_gui/translations/it.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/qt_gui/translations/it.ts b/src/qt_gui/translations/it.ts index 228d798d..a47d3682 100644 --- a/src/qt_gui/translations/it.ts +++ b/src/qt_gui/translations/it.ts @@ -16,7 +16,7 @@ shadPS4 is an experimental open-source emulator for the PlayStation 4. - shadPS4 è un emulatore sperimentale open source per Playstation 4. + shadPS4 è un emulatore sperimentale open source per PlayStation 4. @@ -176,7 +176,7 @@ Install application from a .pkg file - Installa applicaazione da un .pkg file + Installa applicazione da un file .pkg file @@ -365,7 +365,7 @@ System - Systema + Sistema @@ -450,7 +450,7 @@ Enable Shaders Dumping - Abilita Scaricamento Shader + Abilita Dump Shader @@ -460,7 +460,7 @@ Enable PM4 Dumping - Abilita Scaricamento PM4 + Abilita Dump PM4 @@ -470,7 +470,7 @@ Enable Debug Dumping - Abilita Scaricamento Debug + Abilita Dump Debug