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
9 changes: 6 additions & 3 deletions core/libs/prx/libSceAgc/Command/src/Memory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "prx/libSceAgc/Command/include/Memory.hpp"

#include <algorithm>
#include <array>
#include <cstring>
#include <vector>

Expand Down Expand Up @@ -62,15 +63,17 @@ std::uint32_t* WriteData(CommandBuffer* buffer, bool compute, std::uint8_t dst,
CheckBits(writeConfirm, 1, function);
Require(compute || (address & 3u) == 0, function, "misaligned write address");
Require(dst != 0 || writeConfirm == 0, function, "register writes do not support write confirmation");
std::vector<std::uint32_t> snapshot(count);
std::memcpy(snapshot.data(), data, count * sizeof(std::uint32_t));
std::array<std::uint32_t, 64> inlineSnapshot;
std::vector<std::uint32_t> heapSnapshot(count > inlineSnapshot.size() ? count : 0u);
auto* snapshot = count > inlineSnapshot.size() ? heapSnapshot.data() : inlineSnapshot.data();
std::memcpy(snapshot, data, count * sizeof(std::uint32_t));
const auto destination = compute ? static_cast<std::uint32_t>(dst) << 8u : ((dst & 1u) << 30u) | ((dst & 0x1eu) << 7u);
auto* packet = Allocate(buffer, count + 4u, function);
packet[0] = Header(0x37u, count + 4u);
packet[1] = destination | (static_cast<std::uint32_t>(increment) << 16u) | (static_cast<std::uint32_t>(writeConfirm) << 20u) | (static_cast<std::uint32_t>(cachePolicy) << 25u);
packet[2] = static_cast<std::uint32_t>(address);
packet[3] = static_cast<std::uint32_t>(address >> 32u);
std::copy(snapshot.begin(), snapshot.end(), packet + 4);
std::copy_n(snapshot, count, packet + 4);
return packet;
}

Expand Down
34 changes: 34 additions & 0 deletions core/libs/prx/libSceAgc/tests/CopyData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,47 @@ void testWriteDataSize() {
check(sceAgcDcbWriteDataGetSize(1) == 20 && sceAgcDcbWriteDataGetSize(0x3ffd) == 0x3ffd * 4 + 16, "DCB WRITE_DATA size is not four header words plus the payload");
}

struct LargeStorage {
std::array<std::uint32_t, 256> words{};
CommandBuffer buffer{words.data(), words.data() + words.size(), words.data(), words.data() + words.size(), nullptr, nullptr, 0};
};

bool APS5_VABI clobberAndMove(CommandBuffer* buffer, std::uint32_t, void* userData) {
auto& spare = *static_cast<LargeStorage*>(userData);
std::fill(buffer->bottom, buffer->top, 0xdeadbeefu);
buffer->bottom = spare.words.data();
buffer->top = spare.words.data() + spare.words.size();
buffer->cursor_up = buffer->bottom;
buffer->cursor_down = buffer->top;
return true;
}

void testWriteDataReadsPayloadBeforeCallback() {
for (const auto writer : {sceAgcDcbWriteData, sceAgcAcbWriteData}) {
for (const std::uint32_t count : {4u, 64u, 65u, 100u}) {
LargeStorage full;
LargeStorage spare;
for (std::uint32_t i = 0; i < count; ++i) full.words[i] = 0x1000u + i;
full.buffer.cursor_up = full.words.data() + count;
full.buffer.cursor_down = full.buffer.cursor_up + 1;
full.buffer.callback = clobberAndMove;
full.buffer.user_data = &spare;
const auto* packet = writer(&full.buffer, 5, 0, 0x2000, full.words.data(), count, 1, 0);
check(packet == spare.words.data() && packet[0] == (0xc0003700u | ((count + 2u) << 16u)) && packet[2] == 0x2000u, "WRITE_DATA header mismatch after the allocation callback");
for (std::uint32_t i = 0; i < count; ++i) check(packet[4 + i] == 0x1000u + i, "WRITE_DATA payload was not read before the allocation callback");
check(full.buffer.cursor_up == packet + count + 4u, "WRITE_DATA cursor mismatch after the allocation callback");
}
}
}

}

int main() {
try {
testDrawQueueCopy();
testComputeQueueCopy();
testWriteDataSize();
testWriteDataReadsPayloadBeforeCallback();
} catch (const std::exception& error) {
std::fprintf(stderr, "%s\n", error.what());
return 1;
Expand Down
Loading