diff --git a/README.md b/README.md index 4f063ea6a..4bdcd3b26 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Execution reaches `_start`, stack unwinding and exception handling tables are bu Audio output and video output initialization pass Reaches the `main` function with render loop (deep call chain, ~64KB stack frame function) - init and shader loading from disk fully complete. -Now: `AGC driver: unsupported PM4 opcode 18 at DWORD 0`. +Now: `AGC driver: unsupported PM4 opcode 159 at DWORD 2`. ## Disclaimer diff --git a/core/libs/prx/libSceAgcDriver/Execution/include/QueueState.hpp b/core/libs/prx/libSceAgcDriver/Execution/include/QueueState.hpp new file mode 100644 index 000000000..06ea96277 --- /dev/null +++ b/core/libs/prx/libSceAgcDriver/Execution/include/QueueState.hpp @@ -0,0 +1,23 @@ +#ifndef CORE_LIBS_PRX_LIBSCEAGCDRIVER_EXECUTION_INCLUDE_QUEUESTATE_HPP +#define CORE_LIBS_PRX_LIBSCEAGCDRIVER_EXECUTION_INCLUDE_QUEUESTATE_HPP + +#include +#include + +namespace AgcDriver { + +using Registers = std::map; + +struct QueueState { + Registers shader; + Registers context; + Registers userConfig; + + void ClearContext() { + context.clear(); + } +}; + +} + +#endif diff --git a/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp b/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp index 2dff7b475..eb0a4f509 100644 --- a/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp +++ b/core/libs/prx/libSceAgcDriver/Execution/src/Driver.cpp @@ -1,4 +1,5 @@ #include "prx/libSceAgcDriver/Execution/include/Driver.hpp" +#include "prx/libSceAgcDriver/Execution/include/QueueState.hpp" #include "prx/libSceAgcDriver/Execution/include/VulkanDevice.hpp" #include "prx/libSceAgcDriver/Execution/include/VideoOutput.hpp" #include "prx/libc/include/Shutdown.hpp" @@ -72,14 +73,6 @@ void checkRange(const void* pointer, std::size_t bytes, std::size_t alignment) { #endif } -using Registers = std::map; - -struct QueueState { - Registers shader; - Registers context; - Registers userConfig; -}; - struct ShaderSnapshot { std::uint64_t codeAddress; std::uint64_t headerAddress; @@ -336,6 +329,11 @@ private: const auto packet = commands.subspan(cursor, count); const auto opcode = (header >> 8u) & 0xffu; switch (opcode) { + case 0x12: + require(queue == 0, "CLEAR_STATE in compute queue"); + require(count == 2, "invalid CLEAR_STATE packet size"); + require((packet[1] & ~0xfu) == 0, "unsupported CLEAR_STATE payload bits"); + break; case 0x10: require((packet[1] & 0xffff0000u) != 0x68750000u, "marker NOP is not implemented"); break; @@ -407,6 +405,9 @@ private: const auto count = static_cast((header >> 16u) & 0x3fffu) + 2; const auto packet = std::span(submission.commands).subspan(cursor, count); switch ((header >> 8u) & 0xffu) { + case 0x12: + queue.ClearContext(); + break; case 0x10: if (header == FlipPacketHeader) { { diff --git a/core/libs/prx/libSceAgcDriver/tests/Submit.cpp b/core/libs/prx/libSceAgcDriver/tests/Submit.cpp index b2685e5f5..1f7d112f8 100644 --- a/core/libs/prx/libSceAgcDriver/tests/Submit.cpp +++ b/core/libs/prx/libSceAgcDriver/tests/Submit.cpp @@ -1,4 +1,5 @@ #include "prx/libSceAgcDriver/Execution/include/Driver.hpp" +#include "prx/libSceAgcDriver/Execution/include/QueueState.hpp" #include "prx/libc/include/Shutdown.hpp" #include "prx/libSceAgcDriver/Submit/include/Dcb.hpp" #include "prx/libSceAgcDriver/Submit/include/Acb.hpp" @@ -82,6 +83,40 @@ void testValidation() { AgcDriverWaitIdle_nid_postfix(); } +void testClearState() { + AgcDriver::QueueState graphics{{{0x20c, 1}}, {{0x10, 17}, {0x11, 23}}, {{0x242, 5}}}; + const auto shader = graphics.shader; + const auto userConfig = graphics.userConfig; + graphics.ClearContext(); + check(graphics.context.empty(), "CLEAR_STATE retained context registers"); + check(graphics.shader == shader && graphics.userConfig == userConfig, "CLEAR_STATE reset unrelated registers"); + graphics.context.emplace(0x10, 31); + graphics.ClearContext(); + check(graphics.context.empty(), "repeated CLEAR_STATE retained context registers"); + + std::array words{0xc0001200, 0, 0}; + Packet packet{words.data(), 2, 0, {}}; + expectFailure([&] { sceAgcDriverSubmitAcb(0x20, &packet); }); + words[1] = 0x10; + expectFailure([&] { sceAgcDriverSubmitDcb(&packet); }); + words[1] = 0; + words[0] = 0xc0011200; + packet.dw_num = 3; + expectFailure([&] { sceAgcDriverSubmitDcb(&packet); }); + words[0] = 0xc0001201; + packet.dw_num = 2; + expectFailure([&] { sceAgcDriverSubmitDcb(&packet); }); + words[0] = 0xc0001200; + packet.dw_num = 1; + expectFailure([&] { sceAgcDriverSubmitDcb(&packet); }); + packet.dw_num = 2; + for (std::uint32_t state = 0; state <= 0xf; ++state) { + words[1] = state; + check(sceAgcDriverSubmitDcb(&packet) == 0, "CLEAR_STATE submit failed"); + } + AgcDriverWaitIdle_nid_postfix(); +} + void testSubmissions() { std::vector producers; std::array errors{}; @@ -131,6 +166,7 @@ int main() { try { testEvents(); testValidation(); + testClearState(); testSubmissions(); testWorkerFailure(); check(expectFailure([] { LibcRunShutdown_nid_postfix(); }).find("required shader register") != std::string::npos, "shutdown lost worker failure");