From 810d8c0890a18db0cf143e62562b0401c39e6685 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 24 Sep 2023 18:03:12 -0700 Subject: [PATCH] Debugger: Use dedicated func to notify mem copy. --- Core/Debugger/MemBlockInfo.cpp | 8 ++++++ Core/Debugger/MemBlockInfo.h | 1 + Core/HLE/ReplaceTables.cpp | 49 ++++++++++++++++----------------- Core/HLE/sceDmac.cpp | 9 +++--- Core/HLE/sceKernelInterrupt.cpp | 15 ++-------- Core/MemMapHelpers.h | 9 +++--- GPU/GPUCommon.cpp | 18 ++++-------- 7 files changed, 49 insertions(+), 60 deletions(-) diff --git a/Core/Debugger/MemBlockInfo.cpp b/Core/Debugger/MemBlockInfo.cpp index 93f44f41d0..92242a8126 100644 --- a/Core/Debugger/MemBlockInfo.cpp +++ b/Core/Debugger/MemBlockInfo.cpp @@ -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 FindMemInfo(uint32_t start, uint32_t size) { start = NormalizeAddress(start); diff --git a/Core/Debugger/MemBlockInfo.h b/Core/Debugger/MemBlockInfo.h index 108423d53f..b07c326f82 100644 --- a/Core/Debugger/MemBlockInfo.h +++ b/Core/Debugger/MemBlockInfo.h @@ -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. diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index f71b8b945c..4695d13926 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -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 diff --git a/Core/HLE/sceDmac.cpp b/Core/HLE/sceDmac.cpp index f7bcf0d0f6..8feb1fc89e 100644 --- a/Core/HLE/sceDmac.cpp +++ b/Core/HLE/sceDmac.cpp @@ -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); } diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index ec4b452a64..76e1788e39 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -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; } diff --git a/Core/MemMapHelpers.h b/Core/MemMapHelpers.h index 6f2ceaca63..5f89f60312 100644 --- a/Core/MemMapHelpers.h +++ b/Core/MemMapHelpers.h @@ -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); } } diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index cd8824f2e3..9dfd2cdbbf 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -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))