Merge pull request #187 from MichonGoddijn231849/feat/demons-souls-exports

feat: export the AMPR command buffer waits and writes, sceAgcFuseShaderHalves, sceAgcSetSubmitMode, sceNpSessionSignalingCreateContext and sceNetEpollAbort
This commit is contained in:
boykopovar
2026-09-30 22:03:54 +03:00
committed by GitHub
8 changed files with 172 additions and 0 deletions
@@ -103,6 +103,10 @@ int APS5_VABI sceAgcUnknownFuseShaderHalves(Shader* fused_result, const Shader*
return 0;
}
int APS5_VABI sceAgcFuseShaderHalves_nid_postfix(Shader* fused_result, const Shader* front, const Shader* back, void* scratch_mem) {
return sceAgcUnknownFuseShaderHalves(fused_result, front, back, scratch_mem);
}
APS5_EXPORT("dolOmWH+huQ", sceAgcUnknownGetFusedShaderSize);
int APS5_VABI sceAgcUnknownGetFusedShaderSize(SizeAlign* dst, const Shader* front, const Shader* back) {
if (dst == nullptr || front == nullptr || back == nullptr) APS5_INVALID_ARG_EX;
@@ -13,4 +13,9 @@ int APS5_VABI sceAgcSuspendPoint(void) {
return 0;
}
int APS5_VABI sceAgcSetSubmitMode(std::uint32_t mode) {
if (mode != 0) NotImplemented_nid_no_patch(__func__);
return 0;
}
}
+46
View File
@@ -15,8 +15,54 @@ static int Append(Apr::CommandBufferObject* buffer, const void* command, uint32_
return 0;
}
template<class TCommand>
static int AppendCommand(Apr::CommandBufferObject* buffer, Apr::Opcode opcode, TCommand command) {
if (!buffer) return static_cast<int>(0x80020016);
command.header = {opcode, sizeof(command)};
return Append(buffer, &command, sizeof(command));
}
extern "C" {
int APS5_VABI sceAmprCommandBufferWriteAddressOnCompletion(Apr::CommandBufferObject* buffer, volatile std::uint64_t* address, std::uint64_t value) {
if (!address) return static_cast<int>(0x80020016);
return AppendCommand(buffer, Apr::Opcode::WriteAddress, Apr::WriteAddressCommand{{}, reinterpret_cast<std::uint64_t>(address), value, 0, 0});
}
int APS5_VABI sceAmprCommandBufferWriteCounterOnCompletion(Apr::CommandBufferObject* buffer, std::uint32_t counter, std::uint32_t value) {
return AppendCommand(buffer, Apr::Opcode::WriteCounter, Apr::WriteCounterCommand{{}, counter, value});
}
int APS5_VABI sceAmprCommandBufferWaitOnAddress(Apr::CommandBufferObject* buffer, volatile std::uint64_t* address, std::uint64_t reference, std::uint64_t mask, std::uint32_t compare) {
return AppendCommand(buffer, Apr::Opcode::WaitOnAddress, Apr::WaitCommand{{}, reinterpret_cast<std::uint64_t>(address), reference, mask, 0, compare});
}
int APS5_VABI sceAmprCommandBufferWaitOnCounter(Apr::CommandBufferObject* buffer, std::uint32_t counter, std::uint32_t reference, std::uint32_t compare) {
return AppendCommand(buffer, Apr::Opcode::WaitOnCounter, Apr::WaitCommand{{}, 0, reference, ~0ull, counter, compare});
}
int APS5_VABI sceAmprCommandBufferWriteKernelEventQueueOnCompletion(Apr::CommandBufferObject* buffer, std::uint64_t equeue, std::uint64_t ident, std::uint64_t data, std::uint64_t userData) {
return AppendCommand(buffer, Apr::Opcode::WriteKernelEventQueue, Apr::WriteKernelEventQueueCommand{{}, equeue, ident, data, userData});
}
int APS5_VABI sceAmprCommandBufferWriteAddressFromTimeCounterOnCompletion(Apr::CommandBufferObject* buffer, volatile std::uint64_t* address) {
return AppendCommand(buffer, Apr::Opcode::WriteAddressFromTimeCounter, Apr::WriteAddressFromCounterCommand{{}, reinterpret_cast<std::uint64_t>(address), 0, 0});
}
int APS5_VABI sceAmprCommandBufferWriteAddressFromCounterOnCompletion(Apr::CommandBufferObject* buffer, volatile std::uint64_t* address, std::uint32_t counter) {
return AppendCommand(buffer, Apr::Opcode::WriteAddressFromCounter, Apr::WriteAddressFromCounterCommand{{}, reinterpret_cast<std::uint64_t>(address), counter, 0});
}
int APS5_VABI sceAmprCommandBufferWriteAddressFromCounterPairOnCompletion(Apr::CommandBufferObject* buffer, volatile std::uint64_t* address, std::uint32_t counter0, std::uint32_t counter1) {
return AppendCommand(buffer, Apr::Opcode::WriteAddressFromCounterPair, Apr::WriteAddressFromCounterCommand{{}, reinterpret_cast<std::uint64_t>(address), counter0, counter1});
}
std::uint64_t APS5_VABI sceAmprMeasureCommandSizeWriteAddressOnCompletion() { return sizeof(Apr::WriteAddressCommand); }
std::uint64_t APS5_VABI sceAmprMeasureCommandSizeWriteCounterOnCompletion() { return sizeof(Apr::WriteCounterCommand); }
std::uint64_t APS5_VABI sceAmprMeasureCommandSizeWaitOnAddress() { return sizeof(Apr::WaitCommand); }
std::uint64_t APS5_VABI sceAmprMeasureCommandSizeWaitOnCounter() { return sizeof(Apr::WaitCommand); }
std::uint64_t APS5_VABI sceAmprMeasureCommandSizeWriteKernelEventQueueOnCompletion() { return sizeof(Apr::WriteKernelEventQueueCommand); }
int APS5_VABI sceAmprAprCommandBufferConstructor(Apr::CommandBufferObject* buffer, uint64_t* gatherState, uint64_t* scatterState) {
buffer->type = Apr::BufferType::Apr;
*gatherState = 0;
+10
View File
@@ -438,6 +438,16 @@ int APS5_VABI sceNetEpollDestroy(int eid) {
return 0;
}
int APS5_VABI sceNetEpollAbort(int eid, int flags) {
(void)flags;
std::lock_guard<std::mutex> lk(g_mutex);
if (g_epolls.count(eid) == 0) {
return fail(NET_EBADF);
}
g_cv.notify_all();
return 0;
}
int APS5_VABI sceNetEpollControl(int eid, int op, int id, const NetEpollEvent* event) {
(void)event;
std::lock_guard<std::mutex> lk(g_mutex);
@@ -27,6 +27,10 @@ int APS5_VABI sceNpSessionSignalingCreateContext2(const void* param, uint32_t* c
return 0;
}
int APS5_VABI sceNpSessionSignalingCreateContext(const void* param, uint32_t* context_id) {
return sceNpSessionSignalingCreateContext2(param, context_id);
}
int APS5_VABI sceNpSessionSignalingDeactivate(uint32_t context_id) {
(void)context_id;
return 0;
@@ -26,6 +26,13 @@ enum class Opcode : std::uint32_t {
Nop = 0,
ReadFile = 1,
WriteAddress = 2,
WriteCounter = 3,
WaitOnAddress = 4,
WaitOnCounter = 5,
WriteKernelEventQueue = 6,
WriteAddressFromTimeCounter = 7,
WriteAddressFromCounter = 8,
WriteAddressFromCounterPair = 9,
};
struct CommandHeader {
@@ -50,6 +57,36 @@ struct WriteAddressCommand {
std::uint32_t reserved;
};
struct WriteCounterCommand {
CommandHeader header;
std::uint32_t counter;
std::uint32_t value;
};
struct WaitCommand {
CommandHeader header;
std::uint64_t address;
std::uint64_t reference;
std::uint64_t mask;
std::uint32_t counter;
std::uint32_t compare;
};
struct WriteKernelEventQueueCommand {
CommandHeader header;
std::uint64_t equeue;
std::uint64_t ident;
std::uint64_t data;
std::uint64_t userData;
};
struct WriteAddressFromCounterCommand {
CommandHeader header;
std::uint64_t address;
std::uint32_t counter0;
std::uint32_t counter1;
};
}
#endif
+64
View File
@@ -4,7 +4,11 @@
#include "prx/libc/include/General.hpp"
#include "prx/libkernel/Apr/include/AprCommandBuffer.hpp"
#include "prx/libkernel/File/include/NativeStat.hpp"
#include "prx/libkernel/Equeue/Equeue.hpp"
#include "prx/libkernel/Time/include/Time.hpp"
#include <array>
#include <atomic>
#include <chrono>
#include <cerrno>
#include <cstdio>
#include <cstdlib>
@@ -14,6 +18,7 @@
#include <mutex>
#include <stdexcept>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
#ifdef _WIN32
@@ -132,6 +137,32 @@ void _writeAddress(const Apr::WriteAddressCommand& command) {
std::atomic_ref<std::uint64_t>(*reinterpret_cast<std::uint64_t*>(command.address)).store(command.value, std::memory_order_release);
}
std::array<std::atomic<std::uint32_t>, 256> g_counters{};
std::uint32_t _counter(std::uint32_t index) {
return g_counters[index % g_counters.size()].load(std::memory_order_acquire);
}
bool _waitSatisfied(std::uint32_t compare, std::uint64_t value, std::uint64_t reference) {
switch (compare) {
case 0: return true;
case 1: return value < reference;
case 2: return value <= reference;
case 3: return value == reference;
case 4: return value != reference;
case 5: return value >= reference;
case 6: return value > reference;
default: throw std::runtime_error("APR: wait compare function " + std::to_string(compare) + " not implemented");
}
}
template<class TCommand>
TCommand _read(const Apr::CommandBufferObject& buffer, std::uint32_t cursor) {
TCommand command;
std::memcpy(&command, buffer.base + cursor, sizeof(command));
return command;
}
void _execute(const Apr::CommandBufferObject& buffer) {
std::uint32_t cursor = 0;
for (std::uint32_t index = 0; index < buffer.numCommands; ++index) {
@@ -154,6 +185,39 @@ void _execute(const Apr::CommandBufferObject& buffer) {
_writeAddress(command);
break;
}
case Apr::Opcode::WriteCounter: {
const auto command = _read<Apr::WriteCounterCommand>(buffer, cursor);
g_counters[command.counter % g_counters.size()].store(command.value, std::memory_order_release);
break;
}
case Apr::Opcode::WaitOnAddress:
case Apr::Opcode::WaitOnCounter: {
const auto command = _read<Apr::WaitCommand>(buffer, cursor);
const auto current = [&]() -> std::uint64_t {
if (header.opcode == Apr::Opcode::WaitOnCounter) return _counter(command.counter);
return std::atomic_ref<std::uint64_t>(*reinterpret_cast<std::uint64_t*>(command.address)).load(std::memory_order_acquire);
};
while (!_waitSatisfied(command.compare, current() & command.mask, command.reference & command.mask)) std::this_thread::sleep_for(std::chrono::microseconds(50));
break;
}
case Apr::Opcode::WriteKernelEventQueue: {
const auto command = _read<Apr::WriteKernelEventQueueCommand>(buffer, cursor);
EqueueTriggerEvent_nid_postfix(static_cast<KernelEqueue>(command.equeue), static_cast<uintptr_t>(command.ident), EVFILT_USER, reinterpret_cast<void*>(command.data));
break;
}
case Apr::Opcode::WriteAddressFromTimeCounter: {
const auto command = _read<Apr::WriteAddressFromCounterCommand>(buffer, cursor);
std::atomic_ref<std::uint64_t>(*reinterpret_cast<std::uint64_t*>(command.address)).store(sceKernelGetProcessTimeCounter(), std::memory_order_release);
break;
}
case Apr::Opcode::WriteAddressFromCounter:
case Apr::Opcode::WriteAddressFromCounterPair: {
const auto command = _read<Apr::WriteAddressFromCounterCommand>(buffer, cursor);
std::uint64_t value = _counter(command.counter0);
if (header.opcode == Apr::Opcode::WriteAddressFromCounterPair) value |= static_cast<std::uint64_t>(_counter(command.counter1)) << 32u;
std::atomic_ref<std::uint64_t>(*reinterpret_cast<std::uint64_t*>(command.address)).store(value, std::memory_order_release);
break;
}
default:
throw std::runtime_error("APR: unknown opcode " + std::to_string(static_cast<std::uint32_t>(header.opcode)));
}
+2
View File
@@ -17,6 +17,8 @@ Throughout the project, every function at every stage either **does exactly what
### Unknown function info
- [AMPR WaitOnAddress / WaitOnCounter](../../core/libs/prx/libkernel/Apr/src/Apr.cpp) (libSceAmpr) - compare encoding assumed to be the WAIT_REG_MEM one (0 always, 1 <, 2 <=, 3 ==, 4 !=, 5 >=, 6 >)
- [sceAgcSetSubmitMode](../../core/libs/prx/libSceAgc/Misc/src/Suspend.cpp) (libSceAgc) - mode values unknown; only 0 is accepted
- [zARR5aCmkoY](../../core/libs/prx/libSceAgc/DcbFlow/src/Control.cpp) (libSceAgc) - unknown name, signature
- [qj7QZpgr9Uw](../../core/libs/prx/libSceAgc/DcbState/src/ContextState.cpp) (libSceAgc) - unknown name
- [fd5Bp5tGTgo](../../core/libs/prx/libSceAgc/Misc/src/ShaderFusion.cpp) (libSceAgc) - unknown name