diff --git a/core/libs/prx/libSceAgc/Command/src/Packet.cpp b/core/libs/prx/libSceAgc/Command/src/Packet.cpp index 4a4e9e31841d..4bf5a844f45b 100644 --- a/core/libs/prx/libSceAgc/Command/src/Packet.cpp +++ b/core/libs/prx/libSceAgc/Command/src/Packet.cpp @@ -85,7 +85,7 @@ void ValidatePacket(const std::uint32_t* packet, std::uint32_t opcode, std::uint } std::uint32_t* WriteNop(CommandBuffer* buffer, std::uint32_t count, const char* function) { - const auto header = Header(0x10u, count); + const auto header = count == 1 ? 0xffff1000u : Header(0x10u, count); auto* packet = Allocate(buffer, count, function); packet[0] = header; std::fill_n(packet + 1, count - 1u, 0u); diff --git a/core/libs/prx/libSceAgc/tests/Commands.cpp b/core/libs/prx/libSceAgc/tests/Commands.cpp index 58b9f102628a..1f02cc134a0b 100644 --- a/core/libs/prx/libSceAgc/tests/Commands.cpp +++ b/core/libs/prx/libSceAgc/tests/Commands.cpp @@ -34,6 +34,7 @@ extern "C" std::uint32_t* APS5_VABI sceAgcAcbPushMarker(CommandBuffer* buf, cons extern "C" std::uint32_t* APS5_VABI sceAgcAcbPopMarker(CommandBuffer* buf); extern "C" std::uint32_t* APS5_VABI sceAgcAcbSetMarker(CommandBuffer* buf, const char* str, std::uint32_t color); extern "C" std::uint32_t* APS5_VABI sceAgcDcbSetIndexBuffer(CommandBuffer* buf, std::uint64_t indexAddress); +extern "C" std::uint32_t* APS5_VABI sceAgcSetNop(CommandBuffer* buf, std::uint32_t sizeDw); namespace { @@ -109,6 +110,21 @@ void testPackets() { check(noDown.cursor_up == scratch.data() + 6, "allocation past the top of a buffer without a down cursor advanced its cursor"); } +void testNop() { + Storage storage; + storage.words.fill(0xdeadbeefu); + auto* single = sceAgcSetNop(&storage.buffer, 1); + auto* pair = sceAgcSetNop(&storage.buffer, 2); + auto* triple = sceAgcSetNop(&storage.buffer, 3); + const std::array expected{0xffff1000u, 0xc0001000u, 0, 0xc0011000u, 0, 0, 0xdeadbeefu}; + check(single == storage.words.data() && pair == single + 1 && triple == pair + 2, "incorrect NOP placement"); + check(std::equal(expected.begin(), expected.end(), storage.words.begin()), "incorrect NOP packet"); + check(storage.buffer.cursor_up == storage.words.data() + 6, "incorrect NOP cursor advance"); + expectFailure([&] { sceAgcSetNop(&storage.buffer, 0); }); + expectFailure([&] { sceAgcSetNop(&storage.buffer, 0x4002u); }); + check(storage.buffer.cursor_up == storage.words.data() + 6, "invalid NOP advanced the cursor"); +} + void testClearState() { Storage storage; storage.words.fill(0xdeadbeefu); @@ -404,6 +420,7 @@ int main(int argc, char** argv) { return 0; } testPackets(); + testNop(); testClearState(); testIndexedIndirectDraws(); testMarkers();