fix(apr): match the guest command buffer object layout

This commit is contained in:
tototomate123 2026-10-08 16:47:53 +02:00 committed by Adrià Franch
parent 68900523c4
commit f514df98de
4 changed files with 11 additions and 8 deletions

View File

@ -398,7 +398,7 @@ int APS5_VABI sceAmprCommandBufferConstructNop(Apr::CommandBufferObject* buffer,
}
int APS5_VABI sceAmprCommandBufferConstructor(Apr::CommandBufferObject* buffer) {
*buffer = {nullptr, 0, 0, 0, Apr::BufferType::Generic};
*buffer = {Apr::BufferType::Generic, 0, 0, 0, 0, nullptr};
return 0;
}

View File

@ -5,7 +5,6 @@
#include <cstdint>
// Shared between libSceAmpr (which records commands) and libkernel (which executes them).
// The guest treats both the command buffer object and its memory as opaque, so the encoding is ours.
namespace Apr {
enum class BufferType : std::uint16_t {
@ -14,15 +13,19 @@ enum class BufferType : std::uint16_t {
};
struct CommandBufferObject {
std::uint8_t* base;
std::uint32_t size;
std::uint32_t offset;
std::uint32_t numCommands;
BufferType type;
std::uint16_t recording;
std::uint32_t offset;
std::uint32_t numCommands;
std::uint32_t size;
std::uint8_t* base;
};
static_assert(sizeof(CommandBufferObject) == 0x18, "guest reserves 0x18 bytes for sce::Ampr::CommandBuffer");
static_assert(offsetof(CommandBufferObject, offset) == 0x04);
static_assert(offsetof(CommandBufferObject, size) == 0x0c);
static_assert(offsetof(CommandBufferObject, base) == 0x10);
inline constexpr std::uint16_t ScatterGatherValid = 1;
inline constexpr std::uint16_t MapActive = 2;

View File

@ -645,7 +645,7 @@ void AmmVirtualAddressRanges_nid_no_patch(std::uint64_t* start, std::uint64_t* e
}
std::uint32_t AmmSubmit_nid_no_patch(void* base, std::uint32_t bytes) {
_execute(Apr::CommandBufferObject{static_cast<std::uint8_t*>(base), bytes, bytes, 0, Apr::BufferType::Generic, 0});
_execute(Apr::CommandBufferObject{Apr::BufferType::Generic, 0, bytes, 0, bytes, static_cast<std::uint8_t*>(base)});
auto& last = _amm().lastSubmit;
std::uint32_t id = last.fetch_add(1) + 1;
while (id == 0) id = last.fetch_add(1) + 1;

View File

@ -980,7 +980,7 @@ void TestAmmPrt() {
Require(sceAmprAmmCommandBufferRemapIntoPrt(&unbound, prt, source, page, cpuReadWrite, 0) == permissionDenied);
Require(sceAmprAmmCommandBufferUnmapToPrt(&unbound, prt, page) == permissionDenied);
std::array<std::uint8_t, 64> loose{};
Apr::CommandBufferObject sized{nullptr, static_cast<std::uint32_t>(loose.size()), 0, 0, Apr::BufferType::Generic, 0};
Apr::CommandBufferObject sized{Apr::BufferType::Generic, 0, 0, 0, static_cast<std::uint32_t>(loose.size()), nullptr};
Require(sceAmprAmmCommandBufferMapAsPrt(&sized, prt, page) == permissionDenied);
Require(sceAmprAmmMeasureAmmCommandSizeMapAsPrt(prt, 0) == ammRejected);
Require(sceAmprAmmMeasureAmmCommandSizeAllocatePaForPrt(prt, page, 0, 0x08) == ammRejected);