Skip to content

Commit

Permalink
Merge branch 'shadps4-emu:main' into mainBB
Browse files Browse the repository at this point in the history
  • Loading branch information
diegolix29 authored Jan 25, 2025
2 parents 05163c2 + a5a1253 commit 68d6d2d
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/core/libraries/app_content/app_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "core/file_sys/fs.h"
#include "core/libraries/app_content/app_content_error.h"
#include "core/libraries/libs.h"
#include "core/libraries/system/systemservice.h"

namespace Libraries::AppContent {

Expand Down Expand Up @@ -262,6 +263,15 @@ int PS4_SYSV_ABI sceAppContentInitialize(const OrbisAppContentInitParam* initPar
entitlement_label.copy(info.entitlement_label, sizeof(info.entitlement_label));
}
}

if (addcont_count > 0) {
SystemService::OrbisSystemServiceEvent event{};
event.event_type = SystemService::OrbisSystemServiceEventType::EntitlementUpdate;
event.service_entitlement_update.user_id = 0;
event.service_entitlement_update.np_service_label = 0;
SystemService::PushSystemServiceEvent(event);
}

return ORBIS_OK;
}

Expand Down
23 changes: 20 additions & 3 deletions src/core/libraries/system/systemservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
namespace Libraries::SystemService {

bool g_splash_status{true};
std::queue<OrbisSystemServiceEvent> g_event_queue;
std::mutex g_event_queue_mutex;

bool IsSplashVisible() {
return Config::showSplash() && g_splash_status;
Expand Down Expand Up @@ -1772,7 +1774,9 @@ s32 PS4_SYSV_ABI sceSystemServiceGetStatus(OrbisSystemServiceStatus* status) {
LOG_ERROR(Lib_SystemService, "OrbisSystemServiceStatus is null");
return ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER;
}
status->event_num = 0;

std::lock_guard<std::mutex> lock(g_event_queue_mutex);
status->event_num = static_cast<s32>(g_event_queue.size());
status->is_system_ui_overlaid = false;
status->is_in_background_execution = false;
status->is_cpu_mode7_cpu_normal = true;
Expand Down Expand Up @@ -1940,11 +1944,19 @@ int PS4_SYSV_ABI sceSystemServiceRaiseExceptionLocalProcess() {
}

s32 PS4_SYSV_ABI sceSystemServiceReceiveEvent(OrbisSystemServiceEvent* event) {
LOG_ERROR(Lib_SystemService, "(STUBBED) called");
LOG_TRACE(Lib_SystemService, "called");
if (event == nullptr) {
return ORBIS_SYSTEM_SERVICE_ERROR_PARAMETER;
}
return ORBIS_SYSTEM_SERVICE_ERROR_NO_EVENT;

std::lock_guard<std::mutex> lock(g_event_queue_mutex);
if (g_event_queue.empty()) {
return ORBIS_SYSTEM_SERVICE_ERROR_NO_EVENT;
}

*event = g_event_queue.front();
g_event_queue.pop();
return ORBIS_OK;
}

int PS4_SYSV_ABI sceSystemServiceReenableMusicPlayer() {
Expand Down Expand Up @@ -2412,6 +2424,11 @@ int PS4_SYSV_ABI Func_CB5E885E225F69F0() {
return ORBIS_OK;
}

void PushSystemServiceEvent(const OrbisSystemServiceEvent& event) {
std::lock_guard<std::mutex> lock(g_event_queue_mutex);
g_event_queue.push(event);
}

void RegisterlibSceSystemService(Core::Loader::SymbolsResolver* sym) {
LIB_FUNCTION("alZfRdr2RP8", "libSceAppMessaging", 1, "libSceSystemService", 1, 1,
sceAppMessagingClearEventFlag);
Expand Down
4 changes: 4 additions & 0 deletions src/core/libraries/system/systemservice.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// https://github.com/OpenOrbis/OpenOrbis-PS4-Toolchain/blob/master/include/orbis/_types/sys_service.h
#pragma once

#include <mutex>
#include <queue>
#include "common/types.h"

namespace Core::Loader {
Expand Down Expand Up @@ -603,5 +605,7 @@ int PS4_SYSV_ABI sceSystemServiceReenableVoiceRecognition();
int PS4_SYSV_ABI Func_6B1CDB955F0EBD65();
int PS4_SYSV_ABI Func_CB5E885E225F69F0();

void PushSystemServiceEvent(const OrbisSystemServiceEvent& event);

void RegisterlibSceSystemService(Core::Loader::SymbolsResolver* sym);
} // namespace Libraries::SystemService
24 changes: 24 additions & 0 deletions src/video_core/amdgpu/liverpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,18 @@ Liverpool::Task Liverpool::ProcessGraphics(std::span<const u32> dcb, std::span<c
}
break;
}
case PM4ItOpcode::MemSemaphore: {
const auto* mem_semaphore = reinterpret_cast<const PM4CmdMemSemaphore*>(header);
if (mem_semaphore->IsSignaling()) {
mem_semaphore->Signal();
} else {
while (!mem_semaphore->Signaled()) {
YIELD_GFX();
}
mem_semaphore->Decrement();
}
break;
}
case PM4ItOpcode::AcquireMem: {
// const auto* acquire_mem = reinterpret_cast<PM4CmdAcquireMem*>(header);
break;
Expand Down Expand Up @@ -850,6 +862,18 @@ Liverpool::Task Liverpool::ProcessCompute(std::span<const u32> acb, u32 vqid) {
}
break;
}
case PM4ItOpcode::MemSemaphore: {
const auto* mem_semaphore = reinterpret_cast<const PM4CmdMemSemaphore*>(header);
if (mem_semaphore->IsSignaling()) {
mem_semaphore->Signal();
} else {
while (!mem_semaphore->Signaled()) {
YIELD_ASC(vqid);
}
mem_semaphore->Decrement();
}
break;
}
case PM4ItOpcode::WaitRegMem: {
const auto* wait_reg_mem = reinterpret_cast<const PM4CmdWaitRegMem*>(header);
ASSERT(wait_reg_mem->engine.Value() == PM4CmdWaitRegMem::Engine::Me);
Expand Down
61 changes: 61 additions & 0 deletions src/video_core/amdgpu/pm4_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -884,4 +884,65 @@ struct PM4CmdDrawIndexIndirectMulti {
u32 draw_initiator; ///< Draw Initiator Register
};

struct PM4CmdMemSemaphore {
enum class ClientCode : u32 {
CommandProcessor = 0u,
CommandBuffer = 1u,
DataBuffer = 2u,
};
enum class Select : u32 {
SignalSemaphore = 6u,
WaitSemaphore = 7u,
};
enum class SignalType : u32 {
Increment = 0u,
Write = 1u,
};

PM4Type3Header header; ///< header
union {
u32 dw1;
BitField<3, 29, u32> addr_lo; ///< Semaphore address bits [31:3]
};
union {
u32 dw2;
BitField<0, 8, u32> addr_hi; ///< Semaphore address bits [39:32]
BitField<16, 1, u32> use_mailbox; ///< Enables waiting until mailbox is written to
BitField<20, 1, SignalType> signal_type; ///< Indicates the type of signal sent
BitField<24, 2, ClientCode> client_code;
BitField<29, 3, Select> sem_sel; ///< Indicates whether to do a signal or wait operation
};

template <typename T>
[[nodiscard]] T Address() const {
return std::bit_cast<T>(u64(addr_lo) << 3 | (u64(addr_hi) << 32));
}

[[nodiscard]] bool IsSignaling() const {
return sem_sel == Select::SignalSemaphore;
}

[[nodiscard]] bool Signaled() const {
return *Address<u64*>() > 0;
}

void Decrement() const {
*Address<u64*>() -= 1;
}

void Signal() const {
auto* ptr = Address<u64*>();
switch (signal_type) {
case SignalType::Increment:
*ptr += 1;
break;
case SignalType::Write:
*ptr = 1;
break;
default:
UNREACHABLE_MSG("Unknown signal type {}", static_cast<u32>(signal_type.Value()));
}
}
};

} // namespace AmdGpu

0 comments on commit 68d6d2d

Please sign in to comment.