From 29a4d4b035281a951f41e2e45e3d1a3633ddd7c5 Mon Sep 17 00:00:00 2001 From: Merijn Date: Tue, 6 Oct 2026 00:00:39 +0200 Subject: [PATCH 1/3] 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 From a089fe16ba89e8a9358cfea612a987c2174b088f Mon Sep 17 00:00:00 2001 From: Merijn Date: Wed, 7 Oct 2026 20:58:21 +0200 Subject: [PATCH 2/3] test(agc): cover the misaligned event and the delivered context id sceAgcDriverGetEqContextId is now checked with a misaligned event like sceAgcDriverGetEqEventType, and on the end-of-pipe events the submit test delivers: a graphics interrupt reports context 0 and a compute interrupt context 0x20, the queues that raised them. The TechnicalDebt line says why ident is returned and that KytyPS5 returns the event's data instead. AI-assisted: yes Co-Authored-By: Claude Opus 5.5 --- core/libs/prx/libSceAgcDriver/tests/Submit.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core/libs/prx/libSceAgcDriver/tests/Submit.cpp b/core/libs/prx/libSceAgcDriver/tests/Submit.cpp index 0ff502037..d4a4e757d 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Submit.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Submit.cpp @@ -71,6 +71,7 @@ void testEvents() { event.filter = -1; expectFailure([&] { sceAgcDriverGetEqContextId(&event); }); expectFailure([] { sceAgcDriverGetEqContextId(nullptr); }); + expectFailure([&] { sceAgcDriverGetEqContextId(reinterpret_cast(reinterpret_cast(&event) + 1)); }); } void testValidation() { @@ -182,10 +183,12 @@ void testEndOfPipeInterrupts() { std::array events{}; check(owner->GetTriggeredEvents(events.data(), 2) == 1, "graphics end-of-pipe interrupt was not delivered to its queue only"); check(events[0].filter == -14 && events[0].udata == &graphicsTag && events[0].data == 2 && sceAgcDriverGetEqEventType(events.data()) == 0, "graphics end-of-pipe event encoding is wrong"); + check(sceAgcDriverGetEqContextId(events.data()) == 0, "graphics end-of-pipe event reports another context"); check(owner->GetTriggeredEvents(events.data(), 2) == 0, "delivered interrupt was not cleared"); check(sceAgcDriverSubmitAcb(0x20, &packet) == 0, "compute interrupt submit failed"); AgcDriverWaitIdle_nid_postfix(); check(owner->GetTriggeredEvents(events.data(), 2) == 1 && events[0].udata == &computeTag && sceAgcDriverGetEqEventType(events.data()) == 0x20, "compute end-of-pipe interrupt missing"); + check(sceAgcDriverGetEqContextId(events.data()) == 0x20, "compute end-of-pipe event reports another context"); words[2] = 0; check(sceAgcDriverSubmitDcb(&packet) == 0, "plain release submit failed"); AgcDriverWaitIdle_nid_postfix(); From b540327c29c4bb1ff433a679f9250c4b8d3a145d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Franch?= Date: Wed, 7 Oct 2026 21:53:35 +0200 Subject: [PATCH 3/3] docs(agc): keep the updated sceAgcDriverGetEqContextId TechnicalDebt entry Co-Authored-By: Claude --- docs/dev/TechnicalDebt.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dev/TechnicalDebt.md b/docs/dev/TechnicalDebt.md index 8d283df09..f421d849e 100644 --- a/docs/dev/TechnicalDebt.md +++ b/docs/dev/TechnicalDebt.md @@ -70,7 +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 +- [sceAgcDriverGetEqContextId](../../core/libs/prx/libSceAgcDriver/Eq/src/Query.cpp) (libSceAgcDriver) - returns `ident`: an end-of-pipe interrupt is delivered only to the registration whose id equals the raising queue, so `ident` is that context's id (titles register 0 or 1 for graphics and `0x20 + 8 * pipe + queue` for compute). The console's value is not known; KytyPS5 returns the event's `data`, which it fills with the interrupt's context id, whereas `data` here is the EV_CLEAR trigger count. 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