mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #62 from oneandonlydean/feat/agc-acb-markers
feat(agc): ACB markers, index buffer unbinding and address in errors - The DCB marker helpers move from an anonymous namespace in `DcbState/src/Marker.cpp` to `Agc::Marker::Push`/`Pop` (declared in `Marker.hpp`). The ACB entry points use the same helpers, so ACB and DCB markers produce the same custom NOP packets. `SetMarker` is a push followed by a pop, and returns the push packet, as on the DCB. The color is ignored on both, as before. - `sceAgcDcbSetIndexBuffer` emits the packet with address 0 instead of rejecting it. A non-null address still has to be 2-byte aligned. - `Agc::Command::CheckAddress` includes the rejected address in its message.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include "prx/libSceAgc/Command/include/Memory.hpp"
|
||||
#include "prx/libSceAgc/Command/include/Packet.hpp"
|
||||
#include "prx/libSceAgc/DcbState/include/Marker.hpp"
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include "SceTypes.hpp"
|
||||
@@ -73,25 +74,19 @@ std::uint32_t* APS5_VABI sceAgcAcbSetFlip(CommandBuffer* buf, std::uint32_t vide
|
||||
}
|
||||
|
||||
uint32_t* APS5_VABI sceAgcAcbPushMarker(CommandBuffer* buf, const char* str, uint32_t color) {
|
||||
(void)buf;
|
||||
(void)str;
|
||||
(void)color;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return nullptr;
|
||||
(void)color;
|
||||
return Agc::Marker::Push(buf, str, __func__);
|
||||
}
|
||||
|
||||
uint32_t* APS5_VABI sceAgcAcbPopMarker(CommandBuffer* buf) {
|
||||
(void)buf;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return nullptr;
|
||||
return Agc::Marker::Pop(buf, __func__);
|
||||
}
|
||||
|
||||
uint32_t* APS5_VABI sceAgcAcbSetMarker(CommandBuffer* buf, const char* str, uint32_t color) {
|
||||
(void)buf;
|
||||
(void)str;
|
||||
(void)color;
|
||||
NotImplemented_nid_no_patch(__func__);
|
||||
return nullptr;
|
||||
(void)color;
|
||||
auto* packet = Agc::Marker::Push(buf, str, __func__);
|
||||
Agc::Marker::Pop(buf, __func__);
|
||||
return packet;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "prx/libSceAgc/Command/include/Packet.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <limits>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -22,7 +23,10 @@ void CheckBits(std::uint64_t value, std::uint64_t mask, const char* function) {
|
||||
}
|
||||
|
||||
void CheckAddress(std::uint64_t address, std::uint32_t alignment, const char* function) {
|
||||
Require(address != 0 && (address & (alignment - 1u)) == 0, function, "null or misaligned address");
|
||||
if (address != 0 && (address & (alignment - 1u)) == 0) return;
|
||||
char message[64];
|
||||
std::snprintf(message, sizeof(message), "null or misaligned address 0x%llx", static_cast<unsigned long long>(address));
|
||||
Require(false, function, message);
|
||||
}
|
||||
|
||||
std::uint32_t Header(std::uint32_t opcode, std::uint32_t count, std::uint32_t flags) {
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
extern "C" {
|
||||
|
||||
std::uint32_t* APS5_VABI sceAgcDcbSetIndexBuffer(CommandBuffer* buf, std::uint64_t indexAddress) {
|
||||
Agc::Command::CheckAddress(indexAddress, 2, __func__);
|
||||
if (indexAddress != 0) Agc::Command::CheckAddress(indexAddress, 2, __func__);
|
||||
return Agc::Command::Emit(buf, 0x26u, {static_cast<std::uint32_t>(indexAddress), static_cast<std::uint32_t>(indexAddress >> 32u)}, __func__);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,14 @@
|
||||
#ifndef CORE_LIBS_PRX_LIBSCEAGC_DCBSTATE_INCLUDE_MARKER_HPP
|
||||
#define CORE_LIBS_PRX_LIBSCEAGC_DCBSTATE_INCLUDE_MARKER_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include "SceTypes.hpp"
|
||||
|
||||
namespace Agc::Marker {
|
||||
|
||||
std::uint32_t* Push(CommandBuffer* buf, const char* str, const char* function);
|
||||
std::uint32_t* Pop(CommandBuffer* buf, const char* function);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -15,7 +15,11 @@ constexpr std::uint32_t OpcodeNop = 0x10;
|
||||
constexpr std::uint32_t CustomPushMarker = 0x0b;
|
||||
constexpr std::uint32_t CustomPopMarker = 0x0c;
|
||||
|
||||
std::uint32_t* PushMarker(CommandBuffer* buf, const char* str, const char* function) {
|
||||
}
|
||||
|
||||
namespace Agc::Marker {
|
||||
|
||||
std::uint32_t* Push(CommandBuffer* buf, const char* str, const char* function) {
|
||||
Agc::Command::Require(buf != nullptr, function, "null command buffer");
|
||||
const char* text = str ? str : "";
|
||||
const std::size_t bytes = std::strlen(text) + 1;
|
||||
@@ -28,7 +32,7 @@ std::uint32_t* PushMarker(CommandBuffer* buf, const char* str, const char* funct
|
||||
return packet;
|
||||
}
|
||||
|
||||
std::uint32_t* PopMarker(CommandBuffer* buf, const char* function) {
|
||||
std::uint32_t* Pop(CommandBuffer* buf, const char* function) {
|
||||
Agc::Command::Require(buf != nullptr, function, "null command buffer");
|
||||
auto* packet = Agc::Command::Allocate(buf, 2, function);
|
||||
packet[0] = Agc::Command::Header(OpcodeNop, 2, CustomPopMarker << 2);
|
||||
@@ -42,18 +46,18 @@ extern "C" {
|
||||
|
||||
uint32_t* APS5_VABI sceAgcDcbSetMarker(CommandBuffer* buf, const char* str, uint32_t color) {
|
||||
(void)color;
|
||||
auto* packet = PushMarker(buf, str, __func__);
|
||||
PopMarker(buf, __func__);
|
||||
auto* packet = Agc::Marker::Push(buf, str, __func__);
|
||||
Agc::Marker::Pop(buf, __func__);
|
||||
return packet;
|
||||
}
|
||||
|
||||
uint32_t* APS5_VABI sceAgcDcbPopMarker(CommandBuffer* buf) {
|
||||
return PopMarker(buf, __func__);
|
||||
return Agc::Marker::Pop(buf, __func__);
|
||||
}
|
||||
|
||||
uint32_t* APS5_VABI sceAgcDcbPushMarker(CommandBuffer* buf, const char* str, uint32_t color) {
|
||||
(void)color;
|
||||
return PushMarker(buf, str, __func__);
|
||||
return Agc::Marker::Push(buf, str, __func__);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <array>
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbResetQueue(CommandBuffer* buf, std::uint32_t op, std::uint32_t state);
|
||||
@@ -20,6 +21,13 @@ extern "C" int APS5_VABI sceAgcWaitRegMemPatchReference(std::uint32_t* cmd, std:
|
||||
extern "C" int APS5_VABI sceAgcGetDataPacketPayloadAddressUnk(std::uint32_t** addr, std::uint32_t* cmd, int type);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcCbSetShRegisterRangeDirect(CommandBuffer* buf, std::uint32_t offset, const std::uint32_t* values, std::uint32_t numValues);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbContextStateAnotherOp(CommandBuffer* buf, std::uint32_t operation);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbPushMarker(CommandBuffer* buf, const char* str, std::uint32_t color);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbPopMarker(CommandBuffer* buf);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcDcbSetMarker(CommandBuffer* buf, const char* str, std::uint32_t color);
|
||||
extern "C" std::uint32_t* APS5_VABI sceAgcAcbPushMarker(CommandBuffer* buf, const char* str, std::uint32_t color);
|
||||
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);
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -116,6 +124,46 @@ void testIndexedIndirectDraws() {
|
||||
check(storage.words == before, "invalid indexed indirect draw modified packet memory");
|
||||
}
|
||||
|
||||
void testMarkers() {
|
||||
Storage dcb;
|
||||
Storage acb;
|
||||
const auto* dcbPush = sceAgcDcbPushMarker(&dcb.buffer, "frame", 0xff0000u);
|
||||
const auto* acbPush = sceAgcAcbPushMarker(&acb.buffer, "frame", 0x00ff00u);
|
||||
check(acbPush == acb.words.data() && acbPush[0] == Agc::Command::Header(0x10, 3, 0x0bu << 2u), "ACB push marker header mismatch");
|
||||
check(std::strcmp(reinterpret_cast<const char*>(acbPush + 1), "frame") == 0, "ACB push marker text mismatch");
|
||||
const auto* acbPop = sceAgcAcbPopMarker(&acb.buffer);
|
||||
check(acbPop == acb.words.data() + 3 && acbPop[0] == Agc::Command::Header(0x10, 2, 0x0cu << 2u) && acbPop[1] == 0, "ACB pop marker mismatch");
|
||||
sceAgcDcbPopMarker(&dcb.buffer);
|
||||
const auto* acbSet = sceAgcAcbSetMarker(&acb.buffer, nullptr, 0);
|
||||
const auto* dcbSet = sceAgcDcbSetMarker(&dcb.buffer, nullptr, 0);
|
||||
check(acbSet == acb.words.data() + 5 && dcbSet == dcb.words.data() + 5, "set marker did not return its push packet");
|
||||
check(acbSet[0] == Agc::Command::Header(0x10, 2, 0x0bu << 2u) && acbSet[1] == 0 && acbSet[2] == Agc::Command::Header(0x10, 2, 0x0cu << 2u), "ACB set marker is not a push and pop pair");
|
||||
check(dcbPush == dcb.words.data() && dcb.words == acb.words, "ACB and DCB markers differ");
|
||||
check(acb.buffer.cursor_up == acb.words.data() + 9, "incorrect ACB marker cursor advance");
|
||||
expectFailure([] { sceAgcAcbPushMarker(nullptr, "frame", 0); });
|
||||
expectFailure([] { sceAgcAcbPopMarker(nullptr); });
|
||||
expectFailure([] { sceAgcAcbSetMarker(nullptr, "frame", 0); });
|
||||
}
|
||||
|
||||
void testIndexBuffer() {
|
||||
Storage storage;
|
||||
alignas(4) std::uint16_t indices[2]{};
|
||||
const auto address = reinterpret_cast<std::uintptr_t>(indices);
|
||||
const auto* bound = sceAgcDcbSetIndexBuffer(&storage.buffer, address);
|
||||
check(bound[1] == static_cast<std::uint32_t>(address) && bound[2] == static_cast<std::uint32_t>(address >> 32u), "index buffer address mismatch");
|
||||
const auto* unbound = sceAgcDcbSetIndexBuffer(&storage.buffer, 0);
|
||||
check(unbound == bound + 3 && unbound[0] == bound[0] && unbound[1] == 0 && unbound[2] == 0, "index buffer was not unbound");
|
||||
const auto before = storage.words;
|
||||
try {
|
||||
sceAgcDcbSetIndexBuffer(&storage.buffer, 0x1001);
|
||||
} catch (const std::runtime_error& error) {
|
||||
check(std::string(error.what()).find("0x1001") != std::string::npos, "misaligned index buffer error omits the address");
|
||||
check(storage.words == before, "misaligned index buffer modified packet memory");
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error("misaligned index buffer was accepted");
|
||||
}
|
||||
|
||||
void testContextState() {
|
||||
const std::array<std::array<std::uint32_t, 6>, 4> sizes{{{5}, {5, 8, 9, 3, 2}, {3, 5, 8, 9, 2}, {5, 8, 9, 3, 2, 5}}};
|
||||
const std::array<std::array<std::uint32_t, 4>, 4> reservations{{{5}, {22, 3, 2}, {3, 22, 2}, {22, 3, 2, 5}}};
|
||||
@@ -293,6 +341,8 @@ int main() {
|
||||
try {
|
||||
testPackets();
|
||||
testIndexedIndirectDraws();
|
||||
testMarkers();
|
||||
testIndexBuffer();
|
||||
testContextState();
|
||||
testFlip();
|
||||
testRegisters();
|
||||
|
||||
Reference in New Issue
Block a user