Debugger: Use dedicated func to notify mem copy.

This commit is contained in:
Unknown W. Brackets 2023-09-24 18:03:12 -07:00
parent 06a1f0b72c
commit 810d8c0890
7 changed files with 49 additions and 60 deletions

View File

@ -484,6 +484,14 @@ void NotifyMemInfo(MemBlockFlags flags, uint32_t start, uint32_t size, const cha
NotifyMemInfoPC(flags, start, size, currentMIPS->pc, str, strLength);
}
void NotifyMemInfoCopy(uint32_t destPtr, uint32_t srcPtr, uint32_t size, const char *prefix) {
// TODO
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), prefix, srcPtr, size);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, size, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, size, tagData, tagSize);
}
std::vector<MemBlockInfo> FindMemInfo(uint32_t start, uint32_t size) {
start = NormalizeAddress(start);

View File

@ -53,6 +53,7 @@ struct MemBlockInfo {
void NotifyMemInfo(MemBlockFlags flags, uint32_t start, uint32_t size, const char *tag, size_t tagLength);
void NotifyMemInfoPC(MemBlockFlags flags, uint32_t start, uint32_t size, uint32_t pc, const char *tag, size_t tagLength);
void NotifyMemInfoCopy(uint32_t destPtr, uint32_t srcPtr, uint32_t size, const char *prefix);
// This lets us avoid calling strlen on string constants, instead the string length (including null,
// so we have to subtract 1) is computed at compile time.

View File

@ -159,16 +159,19 @@ static int Replace_memcpy() {
RETURN(destPtr);
if (MemBlockInfoDetailed(bytes)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "ReplaceMemcpy/", srcPtr, bytes);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tagData, tagSize);
// It's pretty common that games will copy video data.
if (!strcmp(tagData, "ReplaceMemcpy/VideoDecode") || !strcmp(tagData, "ReplaceMemcpy/VideoDecodeRange")) {
if (bytes == 512 * 272 * 4) {
// Detect that by manually reading the tag when the size looks right.
if (bytes == 512 * 272 * 4) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "ReplaceMemcpy/", srcPtr, bytes);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tagData, tagSize);
if (!strcmp(tagData, "ReplaceMemcpy/VideoDecode") || !strcmp(tagData, "ReplaceMemcpy/VideoDecodeRange")) {
gpu->PerformWriteFormattedFromMemory(destPtr, bytes, 512, GE_FORMAT_8888);
}
} else {
NotifyMemInfoCopy(destPtr, srcPtr, bytes, "ReplaceMemcpy/");
}
}
@ -212,16 +215,19 @@ static int Replace_memcpy_jak() {
RETURN(destPtr);
if (MemBlockInfoDetailed(bytes)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "ReplaceMemcpy/", srcPtr, bytes);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tagData, tagSize);
// It's pretty common that games will copy video data.
if (!strcmp(tagData, "ReplaceMemcpy/VideoDecode") || !strcmp(tagData, "ReplaceMemcpy/VideoDecodeRange")) {
if (bytes == 512 * 272 * 4) {
// Detect that by manually reading the tag when the size looks right.
if (bytes == 512 * 272 * 4) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "ReplaceMemcpy/", srcPtr, bytes);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tagData, tagSize);
if (!strcmp(tagData, "ReplaceMemcpy/VideoDecode") || !strcmp(tagData, "ReplaceMemcpy/VideoDecodeRange")) {
gpu->PerformWriteFormattedFromMemory(destPtr, bytes, 512, GE_FORMAT_8888);
}
} else {
NotifyMemInfoCopy(destPtr, srcPtr, bytes, "ReplaceMemcpy/");
}
}
@ -252,10 +258,7 @@ static int Replace_memcpy16() {
RETURN(destPtr);
if (MemBlockInfoDetailed(bytes)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "ReplaceMemcpy16/", srcPtr, bytes);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tagData, tagSize);
NotifyMemInfoCopy(destPtr, srcPtr, bytes, "ReplaceMemcpy16/");
}
return 10 + bytes / 4; // approximation
@ -294,10 +297,7 @@ static int Replace_memcpy_swizzled() {
RETURN(0);
if (MemBlockInfoDetailed(pitch * h)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "ReplaceMemcpySwizzle/", srcPtr, pitch * h);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, pitch * h, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, pitch * h, tagData, tagSize);
NotifyMemInfoCopy(destPtr, srcPtr, pitch * h, "ReplaceMemcpySwizzle/");
}
return 10 + (pitch * h) / 4; // approximation
@ -326,10 +326,7 @@ static int Replace_memmove() {
RETURN(destPtr);
if (MemBlockInfoDetailed(bytes)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "ReplaceMemmove/", srcPtr, bytes);
NotifyMemInfo(MemBlockFlags::READ, srcPtr, bytes, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, destPtr, bytes, tagData, tagSize);
NotifyMemInfoCopy(destPtr, srcPtr, bytes, "ReplaceMemmove/");
}
return 10 + bytes / 4; // approximation

View File

@ -51,12 +51,11 @@ static int __DmacMemcpy(u32 dst, u32 src, u32 size) {
}
if (!skip && size != 0) {
currentMIPS->InvalidateICache(src, size);
if (Memory::IsValidRange(dst, size) && Memory::IsValidRange(src, size)) {
memcpy(Memory::GetPointerWriteUnchecked(dst), Memory::GetPointerUnchecked(src), size);
}
if (MemBlockInfoDetailed(size)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "DmacMemcpy/", src, size);
Memory::Memcpy(dst, src, size, tagData, tagSize);
} else {
Memory::Memcpy(dst, src, size, "DmacMemcpy");
NotifyMemInfoCopy(dst, src, size, "DmacMemcpy/");
}
currentMIPS->InvalidateICache(dst, size);
}

View File

@ -657,10 +657,7 @@ static u32 sceKernelMemcpy(u32 dst, u32 src, u32 size)
}
if (MemBlockInfoDetailed(size)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "KernelMemcpy/", src, size);
NotifyMemInfo(MemBlockFlags::READ, src, size, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, dst, size, tagData, tagSize);
NotifyMemInfoCopy(dst, src, size, "KernelMemcpy/");
}
return dst;
@ -693,10 +690,7 @@ static u32 sysclib_memcpy(u32 dst, u32 src, u32 size) {
memcpy(Memory::GetPointerWriteUnchecked(dst), Memory::GetPointerUnchecked(src), size);
}
if (MemBlockInfoDetailed(size)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "KernelMemcpy/", src, size);
NotifyMemInfo(MemBlockFlags::READ, src, size, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, dst, size, tagData, tagSize);
NotifyMemInfoCopy(dst, src, size, "KernelMemcpy/");
}
return dst;
}
@ -797,10 +791,7 @@ static u32 sysclib_memmove(u32 dst, u32 src, u32 size) {
memmove(Memory::GetPointerWriteUnchecked(dst), Memory::GetPointerUnchecked(src), size);
}
if (MemBlockInfoDetailed(size)) {
char tagData[128];
size_t tagSize = FormatMemWriteTagAt(tagData, sizeof(tagData), "KernelMemmove/", src, size);
NotifyMemInfo(MemBlockFlags::READ, src, size, tagData, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, dst, size, tagData, tagSize);
NotifyMemInfoCopy(dst, src, size, "KernelMemmove/");
}
return 0;
}

View File

@ -69,13 +69,12 @@ inline void Memcpy(const u32 to_address, const u32 from_address, const u32 len,
memcpy(to, from, len);
if (MemBlockInfoDetailed(len)) {
char tagData[128];
if (!tag) {
tagLen = FormatMemWriteTagAt(tagData, sizeof(tagData), "Memcpy/", from_address, len);
tag = tagData;
NotifyMemInfoCopy(to_address, from_address, len, "Memcpy/");
} else {
NotifyMemInfo(MemBlockFlags::READ, from_address, len, tag, tagLen);
NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, tag, tagLen);
}
NotifyMemInfo(MemBlockFlags::READ, from_address, len, tag, tagLen);
NotifyMemInfo(MemBlockFlags::WRITE, to_address, len, tag, tagLen);
}
}

View File

@ -1704,9 +1704,7 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) {
memcpy(dstp, srcp, bytesToCopy);
if (MemBlockInfoDetailed(bytesToCopy)) {
tagSize = FormatMemWriteTagAt(tag, sizeof(tag), "GPUBlockTransfer/", src, bytesToCopy);
NotifyMemInfo(MemBlockFlags::READ, src, bytesToCopy, tag, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, dst, bytesToCopy, tag, tagSize);
NotifyMemInfoCopy(dst, src, bytesToCopy, "GPUBlockTransfer/");
}
} else if ((srcDstOverlap || srcWraps || dstWraps) && (srcValid || srcWraps) && (dstValid || dstWraps)) {
// This path means we have either src/dst overlap, OR one or both of src and dst wrap.
@ -1862,12 +1860,11 @@ bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags
// We use matching values in PerformReadbackToMemory/PerformWriteColorFromMemory.
// Since they're identical we don't need to copy.
if (dest != src) {
if (Memory::IsValidRange(dest, size) && Memory::IsValidRange(src, size)) {
memcpy(Memory::GetPointerWriteUnchecked(dest), Memory::GetPointerUnchecked(src), size);
}
if (MemBlockInfoDetailed(size)) {
char tag[128];
size_t tagSize = FormatMemWriteTagAt(tag, sizeof(tag), "GPUMemcpy/", src, size);
Memory::Memcpy(dest, src, size, tag, tagSize);
} else {
Memory::Memcpy(dest, src, size, "GPUMemcpy");
NotifyMemInfoCopy(dest, src, size, "GPUMemcpy/");
}
}
}
@ -1876,10 +1873,7 @@ bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags
}
if (MemBlockInfoDetailed(size)) {
char tag[128];
size_t tagSize = FormatMemWriteTagAt(tag, sizeof(tag), "GPUMemcpy/", src, size);
NotifyMemInfo(MemBlockFlags::READ, src, size, tag, tagSize);
NotifyMemInfo(MemBlockFlags::WRITE, dest, size, tag, tagSize);
NotifyMemInfoCopy(dest, src, size, "GPUMemcpy/");
}
InvalidateCache(dest, size, GPU_INVALIDATE_HINT);
if (!(flags & GPUCopyFlag::DEBUG_NOTIFIED))