Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgc/Acb/src/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ std::uint32_t* APS5_VABI sceAgcAcbAtomicGds_0900(CommandBuffer* buf, std::uint32
}

std::uint32_t* APS5_VABI sceAgcAcbJump(CommandBuffer* buf, std::uint8_t cachePolicy, const std::uint32_t* target, std::uint32_t sizeInDwords) {
return Agc::Command::WriteJump(buf, 1, cachePolicy, target, sizeInDwords, __func__);
return Agc::Command::WriteJump(buf, true, 1, cachePolicy, target, sizeInDwords, __func__);
}

uint32_t APS5_VABI sceAgcAcbJumpGetSize(void) {
Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgc/Command/include/Control.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Agc::Command {

std::uint32_t* WriteJump(CommandBuffer* buffer, std::uint8_t chain, std::uint8_t cachePolicy, const std::uint32_t* target, std::uint32_t sizeInDwords, const char* function);
std::uint32_t* WriteJump(CommandBuffer* buffer, bool compute, std::uint8_t chain, std::uint8_t cachePolicy, const std::uint32_t* target, std::uint32_t sizeInDwords, const char* function);
std::uint32_t* WriteRewind(CommandBuffer* buffer, std::uint32_t initialState, const char* function);
std::uint32_t* WritePredication(CommandBuffer* buffer, std::uint8_t condition, std::uint8_t operation, std::uint8_t waitOperation, const volatile void* address, const char* function);
std::uint32_t* WriteMemSemaphore(CommandBuffer* buffer, const volatile void* address, std::uint8_t waitForMailbox, std::uint8_t signalType, std::uint8_t operation, const char* function);
Expand Down
9 changes: 3 additions & 6 deletions core/libs/prx/libSceAgc/Command/src/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@

namespace Agc::Command {

std::uint32_t* WriteJump(CommandBuffer* buffer, std::uint8_t chain, std::uint8_t cachePolicy, const std::uint32_t* target, std::uint32_t sizeInDwords, const char* function) {
std::uint32_t* WriteJump(CommandBuffer* buffer, bool compute, std::uint8_t chain, std::uint8_t cachePolicy, const std::uint32_t* target, std::uint32_t sizeInDwords, const char* function) {
const auto guestAddress = reinterpret_cast<std::uintptr_t>(target);
CheckBits(chain, 1, function);
CheckBits(cachePolicy, 3, function);
CheckBits(sizeInDwords, 0xfffffu, function);
Require((guestAddress & 3u) == 0, function, "misaligned jump target");
return Emit(buffer, 0x3fu, {static_cast<std::uint32_t>(guestAddress) & ~3u, static_cast<std::uint32_t>(guestAddress >> 32u), 0x0f200000u | (static_cast<std::uint32_t>(cachePolicy) << 28u) | (static_cast<std::uint32_t>(chain) << 20u) | sizeInDwords}, function);
const auto control = (compute ? 0x0f800000u : 0x0f200000u) | ((static_cast<std::uint32_t>(cachePolicy) & 3u) << 28u) | ((static_cast<std::uint32_t>(chain) & 1u) << 20u) | (sizeInDwords & 0xfffffu);
return Emit(buffer, 0x3fu, {static_cast<std::uint32_t>(guestAddress) & ~3u, static_cast<std::uint32_t>(guestAddress >> 32u), control}, function);
}

std::uint32_t* WriteRewind(CommandBuffer* buffer, std::uint32_t initialState, const char* function) {
Expand Down
2 changes: 1 addition & 1 deletion core/libs/prx/libSceAgc/DcbFlow/src/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::uint32_t* APS5_VABI sceAgcDcbAtomicGds(CommandBuffer* buf, std::uint32_t en


uint32_t* APS5_VABI sceAgcDcbJump(CommandBuffer* buf, uint8_t mode, uint8_t cache_policy, const uint32_t* target, uint32_t size_in_dwords) {
return Agc::Command::WriteJump(buf, mode, cache_policy, target, size_in_dwords, __func__);
return Agc::Command::WriteJump(buf, false, mode, cache_policy, target, size_in_dwords, __func__);
}

std::uint32_t APS5_VABI sceAgcDcbJumpGetSize() {
Expand Down
37 changes: 24 additions & 13 deletions core/libs/prx/libSceAgc/tests/Commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,19 +616,30 @@ void testFlowPackets() {
check(called.words[3] == 0x0f2fffffu, "unchained INDIRECT_BUFFER control word mismatch");
Storage compute;
sceAgcAcbJump(&compute.buffer, 1, target, 0x10);
check(compute.words[0] == 0xc0023f00u && compute.words[3] == 0x1f300010u, "compute jumps did not chain");
Storage rejected;
rejected.words.fill(0xa5a5a5a5u);
const auto rejectedWords = rejected.words;
const auto* rejectedCursor = rejected.buffer.cursor_up;
expectFailure([&] { sceAgcDcbJump(&rejected.buffer, 2, 0, target, 1); });
check(rejected.words == rejectedWords && rejected.buffer.cursor_up == rejectedCursor, "a refused packet changed the command buffer");
expectFailure([&] { sceAgcDcbJump(&rejected.buffer, 0, 4, target, 1); });
check(rejected.words == rejectedWords && rejected.buffer.cursor_up == rejectedCursor, "a refused packet changed the command buffer");
expectFailure([&] { sceAgcDcbJump(&rejected.buffer, 0, 0, target, 0x100000u); });
check(rejected.words == rejectedWords && rejected.buffer.cursor_up == rejectedCursor, "a refused packet changed the command buffer");
expectFailure([&] { sceAgcAcbJump(&rejected.buffer, 0, reinterpret_cast<const std::uint32_t*>(0x1002ull), 1); });
check(rejected.words == rejectedWords && rejected.buffer.cursor_up == rejectedCursor, "a refused packet changed the command buffer");
check(compute.words[0] == 0xc0023f00u && compute.words[3] == 0x1f900010u, "compute jumps did not chain");
struct ConsoleJump {
bool compute;
std::uint8_t mode;
std::uint8_t cachePolicy;
std::uintptr_t target;
std::uint32_t size;
std::array<std::uint32_t, 3> words;
};
const std::array<ConsoleJump, 6> consoleJumps{{
{true, 1, 0x11, 0x22222222u, 0x33333333u, {0x22222220u, 0u, 0x1f933333u}},
{true, 1, 1, 2u, 3u, {0u, 0u, 0x1f900003u}},
{true, 1, 0x22, 0x3333333344444444ull, 0u, {0x44444444u, 0x33333333u, 0x2f900000u}},
{false, 0x11, 0x22, 0x33333333u, 0x44444444u, {0x33333330u, 0u, 0x2f344444u}},
{false, 1, 2, 3u, 4u, {0u, 0u, 0x2f300004u}},
{false, 0x22, 0x44, 0u, 0u, {0u, 0u, 0x0f200000u}},
}};
for (const auto& item : consoleJumps) {
Storage storage;
const auto* jumpTarget = reinterpret_cast<const std::uint32_t*>(item.target);
const auto* packet = item.compute ? sceAgcAcbJump(&storage.buffer, item.cachePolicy, jumpTarget, item.size) : sceAgcDcbJump(&storage.buffer, item.mode, item.cachePolicy, jumpTarget, item.size);
check(packet == storage.words.data() && packet[0] == 0xc0023f00u && std::equal(item.words.begin(), item.words.end(), packet + 1), "jump packet does not match the console's");
check(storage.buffer.cursor_up == storage.words.data() + 4, "jump cursor mismatch");
}
check(sceAgcDcbJumpGetSize() == 16 && sceAgcAcbJumpGetSize() == 16, "jump packet sizes");
Storage stall;
sceAgcDcbStallCommandBufferParser(&stall.buffer);
Expand Down
1 change: 1 addition & 0 deletions docs/dev/debt/libSceAgc.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- [sceAgcGetRegisterDefaults](../../../core/libs/prx/libSceAgc/Misc/src/RegisterDefaults.cpp) (libSceAgc) - returns the version 13 public table (137 keyed entries over 84 context blocks) because the console returns the running system software's table: [ps5-vulkan](https://github.com/mpereiraesaa/ps5-vulkan/blob/4bb0c8b1423698a7369efc22b829bf16a99e7128/src/color_runtime_defaults.h) measured 128 entries over 79 blocks on 10.x and 137 over 84 on 12.02 and 13.x, the shapes of the version 10 and version 11/13 tables here, and PPSA99011 refuses the version 0 table. The [type table](../../../core/libs/prx/libSceAgc/Command/src/RegisterDefaults.cpp) is handed out as 8-byte `{key, index << 2 | bank}` pairs, the layout ps5-vulkan and the homebrew sharing its `ps5_agc_registers.h` read; the compact 12-byte entries also pack the block's register count and stride above bit 10, and those bits are dropped. `sceAgcGetRegisterDefaults2`, `sceAgcGetRegisterDefaults2Internal`, `sceAgcGetRegisterDefaultsInternal` and `sceAgcInit` hand out the compact 12-byte entries (`RegisterDefaultsTypeLayout::Compact`): SDK-built code walks the tables of the first two with a 12-byte stride, reads the key at +0 and the bank and index from the low 10 bits of the word at +4, and keeps an all-ones sentinel for a key it does not find. Which layout the legacy internal call returns on a console is not known. No console dump of the runtime type table was compared, and AnyPS5 does not choose 10.x or 12.02 by the system software a title targets
- [sceAgcInit](../../../core/libs/prx/libSceAgc/DcbState/src/Init.cpp) (libSceAgc) - versions 0–13 select their register-default tables and return 0; pointer-shaped or otherwise out-of-range values (>=14) return 0 without a register-default lookup. Console probe on firmware 13.60 ([#4808](https://github.com/boykopovar/AnyPS5/issues/4808#issuecomment-6149448503)): `sceAgcInit(&buf, 8)` (NID `kW3GLb7QfPg`) returns 0 and writes nothing; scalar versions 2–13 return `0x8A6C0004` there, while AnyPS5 still returns 0 for those scalars. The probe does not show that table 13 is selected for pointer-shaped calls. [OpenAGC](https://github.com/OpenAGC/OpenAGC/blob/main/src/game_compat.c) returns `0x80890001` above 12 for `sceAgcInit`, and falls back to version 11 in `sceAgcGetRegisterDefaults2`. PPSA99011, PPSA99995, [ps5-vulkan](https://github.com/mpereiraesaa/ps5-vulkan) and [prospero-win](https://github.com/mpereiraesaa/prospero-win) call that NID with a pointer-shaped first argument. `sceAgcInit_0090` (NID `23LRUSvYu1M`) checks the state pointer and then calls `sceAgcInit`, as OpenAGC does
- [sceAgcSetSubmitMode](../../../core/libs/prx/libSceAgc/Misc/src/Suspend.cpp) (libSceAgc) - only 0 is accepted. In the SDK 9.04 modules (module parameter `0x09040001`, from a title's `fakelib`), `libSceAgc` forwards to the `libSceAgcDriver` export `oFb2hMcoJa4`. That export returns `0x8a6d0005` while a driver state word is nonzero; otherwise it sets bit `0x20000` in two submit flag words for any nonzero mode and clears it for 0, then returns 0. What that bit changes in a submit is not traced, so nonzero modes still throw
- [sceAgcDcbJump, sceAgcAcbJump](../../../core/libs/prx/libSceAgc/Command/src/Control.cpp) (libSceAgc) - follow prosper's console measurements (`agcbuild_{Acb,Dcb}Jump_a/b/c`): the target is written with its low two bits cleared (0x44444444 kept bit 2), the mode keeps bit 0, the cache policy its low two bits and the size its low 20 bits. An ACB jump sets bit 23 of the control word where a DCB jump sets bit 21 (0x1f933333 against 0x2f344444); neither bit is read by the driver. The jump patch functions are unchanged and still refuse those values.
- [sceAgcGetGsOversubscription](../../../core/libs/prx/libSceAgc/Shader/src/GsOversubscription.cpp) (libSceAgc) - signature and occupancy formula (base and expanded vertex/export capacities, budget shift, `GE_PC_ALLOC` / `SPI_SHADER_PGM_RSRC4_GS` encoding) follow KytyPS5 only, not confirmed on hardware or a title; a negative or NaN factor that gives a negative target, a missing GS context register or a zero `GE_MAX_OUTPUT_PER_SUBGROUP` throws
- [sceAgcGetGsPrimPayload](../../../core/libs/prx/libSceAgc/Shader/src/GsPrimPayload.cpp) (libSceAgc) - the search does not stop at an `SPI_SHADER_IDX_FORMAT` (0x1C2) entry whose format is not `SPI_SHADER_2COMP`, as the analysis of the library declared in the pull request describes (its origin and firmware version are not identified), while [OpenAGC](https://github.com/OpenAGC/OpenAGC/blob/3c7e8072f0d7684e930454794fd5c02056946d73/src/game_compat.c#L1285-L1310) stops there; not verified on PS5 hardware. A null payload, a null shader or a register count with a null register array throws instead of faulting on the memory access
- [sceAgcCbCondWrite](../../../core/libs/prx/libSceAgc/Cb/src/Branch.cpp) (libSceAgc) - argument order and the 9-dword COND_WRITE layout follow the clean-room [OpenAGC](https://github.com/OpenAGC/OpenAGC/blob/main/src/game_compat.c) and [sharpemu](https://github.com/sharpemu/sharpemu/blob/main/src/SharpEmu.Libs/Agc/AgcExports.CommandPackets.cs), which agree on them; SharpProspero lists another order. The write space is accepted only as 1 (memory), the one value both encode the same way, and other values throw.
Expand Down
6 changes: 0 additions & 6 deletions tools/library-oracle/known.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ agcbuild_AcbEventWrite_c throw AnyPS5 throws for arguments the console encodes
agcbuild_AcbInitializeDefaultHardwareState_a throw AnyPS5 throws for arguments the console encodes
agcbuild_AcbInitializeDefaultHardwareState_b throw AnyPS5 throws for arguments the console encodes
agcbuild_AcbInitializeDefaultHardwareState_c throw AnyPS5 throws for arguments the console encodes
agcbuild_AcbJump_a throw AnyPS5 throws for arguments the console encodes
agcbuild_AcbJump_b throw AnyPS5 throws for arguments the console encodes
agcbuild_AcbJump_c throw AnyPS5 throws for arguments the console encodes
agcbuild_AcbMemSemaphore_a throw the operation argument changes the control word; not modelled
agcbuild_AcbMemSemaphore_b throw the operation argument changes the control word; not modelled
agcbuild_AcbMemSemaphore_c throw the operation argument changes the control word; not modelled
Expand Down Expand Up @@ -93,9 +90,6 @@ agcbuild_DcbDrawIndirect_c throw AnyPS5 throws for arguments the console encodes
agcbuild_DcbGetLodStats_a throw AnyPS5 throws for arguments the console encodes
agcbuild_DcbGetLodStats_b throw AnyPS5 throws for arguments the console encodes
agcbuild_DcbGetLodStats_c throw AnyPS5 throws for arguments the console encodes
agcbuild_DcbJump_a throw AnyPS5 throws for arguments the console encodes
agcbuild_DcbJump_b throw AnyPS5 throws for arguments the console encodes
agcbuild_DcbJump_c throw AnyPS5 throws for arguments the console encodes
agcbuild_DcbMemSemaphore_a throw the operation argument changes the control word; not modelled
agcbuild_DcbMemSemaphore_b throw the operation argument changes the control word; not modelled
agcbuild_DcbMemSemaphore_c throw the operation argument changes the control word; not modelled
Expand Down
Loading