From 29a4d4b035281a951f41e2e45e3d1a3633ddd7c5 Mon Sep 17 00:00:00 2001 From: Merijn Date: Tue, 6 Oct 2026 00:00:39 +0200 Subject: [PATCH] feat(agc): implement sceAgcDriverGetEqContextId Return the id a graphics event was registered with in sceAgcDriverAddEqEvent, which titles derive from their context (PPSA12544: 0 or 1 for graphics, 0x20 + 8 * pipe + queue for compute) and read back to dispatch the event. Other event filters, a null or misaligned event and an id above 32 bits throw. The meaning is an assumption and recorded in the technical debt. Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libSceAgcDriver/Eq/include/Query.hpp | 1 + core/libs/prx/libSceAgcDriver/Eq/src/Query.cpp | 13 ++++++++++--- core/libs/prx/libSceAgcDriver/tests/Submit.cpp | 8 ++++++++ docs/dev/TechnicalDebt.md | 1 + 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/core/libs/prx/libSceAgcDriver/Eq/include/Query.hpp b/core/libs/prx/libSceAgcDriver/Eq/include/Query.hpp index 20828a57c..a1e868393 100644 --- a/core/libs/prx/libSceAgcDriver/Eq/include/Query.hpp +++ b/core/libs/prx/libSceAgcDriver/Eq/include/Query.hpp @@ -4,5 +4,6 @@ #include "SceTypes.hpp" extern "C" int APS5_VABI sceAgcDriverGetEqEventType(const KernelEvent* ev); +extern "C" uint32_t APS5_VABI sceAgcDriverGetEqContextId(const KernelEvent* ev); #endif diff --git a/core/libs/prx/libSceAgcDriver/Eq/src/Query.cpp b/core/libs/prx/libSceAgcDriver/Eq/src/Query.cpp index 9a42d7efb..c0987dc2b 100644 --- a/core/libs/prx/libSceAgcDriver/Eq/src/Query.cpp +++ b/core/libs/prx/libSceAgcDriver/Eq/src/Query.cpp @@ -11,9 +11,16 @@ extern "C" { uint32_t APS5_VABI sceAgcDriverGetEqContextId(const KernelEvent* ev) { - (void)ev; - NotImplemented_nid_no_patch(__func__); - return 0; + if (ev == nullptr || reinterpret_cast(ev) % alignof(KernelEvent) != 0) { + throw std::runtime_error(std::string(__func__) + ": null or misaligned event"); + } + if (ev->filter != -14) { + throw std::runtime_error(std::string(__func__) + ": not a graphics event"); + } + if (ev->ident > std::numeric_limits::max()) { + throw std::runtime_error(std::string(__func__) + ": context id overflow"); + } + return static_cast(ev->ident); } int APS5_VABI sceAgcDriverGetEqEventType(const KernelEvent* ev) { diff --git a/core/libs/prx/libSceAgcDriver/tests/Submit.cpp b/core/libs/prx/libSceAgcDriver/tests/Submit.cpp index d611db473..0ff502037 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Submit.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Submit.cpp @@ -63,6 +63,14 @@ void testEvents() { expectFailure([&] { sceAgcDriverGetEqEventType(&event); }); expectFailure([] { sceAgcDriverGetEqEventType(nullptr); }); expectFailure([&] { sceAgcDriverGetEqEventType(reinterpret_cast(reinterpret_cast(&event) + 1)); }); + event.ident = 0x29; + check(sceAgcDriverGetEqContextId(&event) == 0x29, "graphics event context id uses wrong field"); + event.ident = std::numeric_limits::max(); + expectFailure([&] { sceAgcDriverGetEqContextId(&event); }); + event.ident = 1; + event.filter = -1; + expectFailure([&] { sceAgcDriverGetEqContextId(&event); }); + expectFailure([] { sceAgcDriverGetEqContextId(nullptr); }); } void testValidation() { diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 61a82baf3..8d283df09 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -70,6 +70,7 @@ Throughout the project, every function at every stage either **does exactly what - [sceUserServiceGetUserColor](../../core/libs/prx/libSceUserService/Export.cpp) (libSceUserService) - the default profile colour is assumed to be blue (0) - [kP2L8t3j-aM](../../core/libs/prx/libSceVideoOut/src/Output.cpp) (libSceVideoOut) - unknown name, signature - [LibwuIonIBw](../../core/libs/prx/libSceVideoOut/src/Output.cpp) (libSceVideoOut) - unknown name, signature +- [sceAgcDriverGetEqContextId](../../core/libs/prx/libSceAgcDriver/Eq/src/Query.cpp) (libSceAgcDriver) - assumed to return the id the graphics event was registered with in `sceAgcDriverAddEqEvent` (PPSA12544 derives that id from its context: 0 or 1 for graphics, 0x20 + 8 * pipe + queue for compute); other event filters throw - [sceAgcSetSubmitMode](../../core/libs/prx/libSceAgc/Misc/src/Suspend.cpp) (libSceAgc) - mode values unknown; only 0 is accepted - [User data registers](../../core/libs/prx/libSceAgcDriver/Execution/src/Driver/Diagnostics.cpp) (AGC driver) - a `SPI_SHADER_USER_DATA_*` or `COMPUTE_USER_DATA_*` register the title never wrote reads as 0 when a stage's RSRC2 count covers it, as Kyty (zeroed `UserSgprInfo`) and SharpEmu (missing registers read 0) do, and as AMD PAL and Mesa initialize them; the console's value is not confirmed - [SET_PREDICATION](../../core/libs/prx/libSceAgcDriver/Execution/src/Pm4.cpp) (AGC driver) - boolean predication follows the AMD PM4 encoding [Mesa](https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/amd/common/sid.h) uses: operation 3 reads 64 bits and 4 reads 32 bits, and bit 8 runs predicated packets when the value is non-zero (clear: when it is zero); the bit 12 hint is ignored. The address must have its low 4 bits clear, as `sceAgcDcbSetPredication` writes it. Query predication (Z-pass, primitive count), a predicated COND_EXEC, predicated command buffer chains and flips in predicated command buffers throw