diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index efccd43dee..e4f6d5bb96 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -104,7 +104,11 @@ static int Replace_memcpy() { u32 destPtr = PARAM(0); u32 srcPtr = PARAM(1); u32 bytes = PARAM(2); - if (bytes != 0) { + bool skip = false; + if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(srcPtr)) { + skip = gpu->UpdateMemory(destPtr, srcPtr, bytes); + } + if (!skip && bytes != 0) { u8 *dst = Memory::GetPointerUnchecked(destPtr); u8 *src = Memory::GetPointerUnchecked(srcPtr); memmove(dst, src, bytes); @@ -114,9 +118,6 @@ static int Replace_memcpy() { CBreakPoints::ExecMemCheck(srcPtr, false, bytes, currentMIPS->pc); CBreakPoints::ExecMemCheck(destPtr, true, bytes, currentMIPS->pc); #endif - if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(srcPtr)) { - gpu->UpdateMemory(destPtr, srcPtr, bytes); - } return 10 + bytes / 4; // approximation } @@ -124,7 +125,11 @@ static int Replace_memcpy16() { u32 destPtr = PARAM(0); u32 srcPtr = PARAM(1); u32 bytes = PARAM(2) * 16; - if (bytes != 0) { + bool skip = false; + if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(srcPtr)) { + skip = gpu->UpdateMemory(destPtr, srcPtr, bytes); + } + if (!skip && bytes != 0) { u8 *dst = Memory::GetPointerUnchecked(destPtr); u8 *src = Memory::GetPointerUnchecked(srcPtr); memmove(dst, src, bytes); @@ -134,9 +139,6 @@ static int Replace_memcpy16() { CBreakPoints::ExecMemCheck(srcPtr, false, bytes, currentMIPS->pc); CBreakPoints::ExecMemCheck(destPtr, true, bytes, currentMIPS->pc); #endif - if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(srcPtr)) { - gpu->UpdateMemory(destPtr, srcPtr, bytes); - } return 10 + bytes / 4; // approximation } @@ -144,7 +146,11 @@ static int Replace_memmove() { u32 destPtr = PARAM(0); u32 srcPtr = PARAM(1); u32 bytes = PARAM(2); - if (bytes != 0) { + bool skip = false; + if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(srcPtr)) { + skip = gpu->UpdateMemory(destPtr, srcPtr, bytes); + } + if (!skip && bytes != 0) { u8 *dst = Memory::GetPointerUnchecked(destPtr); u8 *src = Memory::GetPointerUnchecked(srcPtr); memmove(dst, src, bytes); @@ -154,9 +160,6 @@ static int Replace_memmove() { CBreakPoints::ExecMemCheck(srcPtr, false, bytes, currentMIPS->pc); CBreakPoints::ExecMemCheck(destPtr, true, bytes, currentMIPS->pc); #endif - if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(srcPtr)) { - gpu->UpdateMemory(destPtr, srcPtr, bytes); - } return 10 + bytes / 4; // approximation } @@ -165,14 +168,17 @@ static int Replace_memset() { u8 *dst = Memory::GetPointerUnchecked(destPtr); u8 value = PARAM(1); u32 bytes = PARAM(2); - memset(dst, value, bytes); + bool skip = false; + if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(destPtr)) { + skip = gpu->UpdateMemory(destPtr, destPtr, bytes); + } + if (!skip) { + memset(dst, value, bytes); + } RETURN(destPtr); #ifndef MOBILE_DEVICE CBreakPoints::ExecMemCheck(destPtr, true, bytes, currentMIPS->pc); #endif - if (Memory::IsVRAMAddress(destPtr) || Memory::IsVRAMAddress(destPtr)) { - gpu->UpdateMemory(destPtr, destPtr, bytes); - } return 10 + bytes / 4; // approximation } diff --git a/Core/HLE/sceDmac.cpp b/Core/HLE/sceDmac.cpp index 7c6d1dafd8..4fd89dffbb 100644 --- a/Core/HLE/sceDmac.cpp +++ b/Core/HLE/sceDmac.cpp @@ -43,16 +43,17 @@ void __DmacDoState(PointerWrap &p) { } int __DmacMemcpy(u32 dst, u32 src, u32 size) { - Memory::Memcpy(dst, Memory::GetPointer(src), size); #ifndef MOBILE_DEVICE CBreakPoints::ExecMemCheck(src, false, size, currentMIPS->pc); CBreakPoints::ExecMemCheck(dst, true, size, currentMIPS->pc); #endif - src &= ~0x40000000; - dst &= ~0x40000000; + bool skip = false; if (Memory::IsVRAMAddress(src) || Memory::IsVRAMAddress(dst)) { - gpu->UpdateMemory(dst, src, size); + skip = gpu->UpdateMemory(dst, src, size); + } + if (!skip) { + Memory::Memcpy(dst, Memory::GetPointer(src), size); } // This number seems strangely reproducible. diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 0a23d33097..36e57208e3 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -559,11 +559,14 @@ u32 sceKernelMemset(u32 addr, u32 fillc, u32 n) u32 sceKernelMemcpy(u32 dst, u32 src, u32 size) { DEBUG_LOG(SCEKERNEL, "sceKernelMemcpy(dest=%08x, src=%08x, size=%i)", dst, src, size); - // Hm, sceDmacMemcpy seems to be the popular one for this. Ignoring for now. - // gpu->UpdateMemory(dst, src, size); + + bool skip = false; + if (Memory::IsVRAMAddress(src) || Memory::IsVRAMAddress(dst)) { + skip = gpu->UpdateMemory(dst, src, size); + } // Technically should crash if these are invalid and size > 0... - if (Memory::IsValidAddress(dst) && Memory::IsValidAddress(src) && Memory::IsValidAddress(dst + size - 1) && Memory::IsValidAddress(src + size - 1)) + if (!skip && Memory::IsValidAddress(dst) && Memory::IsValidAddress(src) && Memory::IsValidAddress(dst + size - 1) && Memory::IsValidAddress(src + size - 1)) { u8 *dstp = Memory::GetPointer(dst); u8 *srcp = Memory::GetPointer(src); diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 1e26d074ce..1749b11def 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -1315,8 +1315,9 @@ void DIRECTX9_GPU::InvalidateCacheInternal(u32 addr, int size, GPUInvalidationTy framebufferManager_.UpdateFromMemory(addr, size); } -void DIRECTX9_GPU::UpdateMemory(u32 dest, u32 src, int size) { +bool DIRECTX9_GPU::UpdateMemory(u32 dest, u32 src, int size) { InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + return false; } void DIRECTX9_GPU::ClearCacheNextFrame() { diff --git a/GPU/Directx9/GPU_DX9.h b/GPU/Directx9/GPU_DX9.h index e0de3b4318..9f6cb86253 100644 --- a/GPU/Directx9/GPU_DX9.h +++ b/GPU/Directx9/GPU_DX9.h @@ -46,7 +46,7 @@ public: virtual void BeginFrame(); virtual void UpdateStats(); virtual void InvalidateCache(u32 addr, int size, GPUInvalidationType type); - virtual void UpdateMemory(u32 dest, u32 src, int size); + virtual bool UpdateMemory(u32 dest, u32 src, int size); virtual void ClearCacheNextFrame(); virtual void DeviceLost(); // Only happens on Android. Drop all textures and shaders. diff --git a/GPU/GLES/GLES_GPU.cpp b/GPU/GLES/GLES_GPU.cpp index 0d4bc08e19..20772d038a 100644 --- a/GPU/GLES/GLES_GPU.cpp +++ b/GPU/GLES/GLES_GPU.cpp @@ -1960,13 +1960,18 @@ void GLES_GPU::InvalidateCacheInternal(u32 addr, int size, GPUInvalidationType t } } -void GLES_GPU::UpdateMemory(u32 dest, u32 src, int size) { - InvalidateCache(dest, size, GPU_INVALIDATE_HINT); - +bool GLES_GPU::UpdateMemory(u32 dest, u32 src, int size) { // Track stray copies of a framebuffer in RAM. MotoGP does this. if (framebufferManager_.MayIntersectFramebuffer(src) || framebufferManager_.MayIntersectFramebuffer(dest)) { + // TODO: Copy in the right order. + Memory::Memcpy(dest, Memory::GetPointer(src), size); framebufferManager_.NotifyFramebufferCopy(src, dest, size); + InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + return true; } + + InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + return false; } void GLES_GPU::ClearCacheNextFrame() { diff --git a/GPU/GLES/GLES_GPU.h b/GPU/GLES/GLES_GPU.h index 930b5153c6..fcfd771d40 100644 --- a/GPU/GLES/GLES_GPU.h +++ b/GPU/GLES/GLES_GPU.h @@ -44,7 +44,7 @@ public: virtual void BeginFrame(); virtual void UpdateStats(); virtual void InvalidateCache(u32 addr, int size, GPUInvalidationType type); - virtual void UpdateMemory(u32 dest, u32 src, int size); + virtual bool UpdateMemory(u32 dest, u32 src, int size); virtual void ClearCacheNextFrame(); virtual void DeviceLost(); // Only happens on Android. Drop all textures and shaders. diff --git a/GPU/GPUInterface.h b/GPU/GPUInterface.h index 62d9bae30a..f069022bae 100644 --- a/GPU/GPUInterface.h +++ b/GPU/GPUInterface.h @@ -227,7 +227,7 @@ public: // If size = -1, invalidate everything. virtual void InvalidateCache(u32 addr, int size, GPUInvalidationType type) = 0; // Update either RAM from VRAM, or VRAM from RAM... or even VRAM from VRAM. - virtual void UpdateMemory(u32 dest, u32 src, int size) = 0; + virtual bool UpdateMemory(u32 dest, u32 src, int size) = 0; // Will cause the texture cache to be cleared at the start of the next frame. virtual void ClearCacheNextFrame() = 0; diff --git a/GPU/Null/NullGpu.cpp b/GPU/Null/NullGpu.cpp index bfb5f2167a..5b881e86e4 100644 --- a/GPU/Null/NullGpu.cpp +++ b/GPU/Null/NullGpu.cpp @@ -657,7 +657,8 @@ void NullGPU::InvalidateCache(u32 addr, int size, GPUInvalidationType type) { // Nothing to invalidate. } -void NullGPU::UpdateMemory(u32 dest, u32 src, int size) { +bool NullGPU::UpdateMemory(u32 dest, u32 src, int size) { // Nothing to update. InvalidateCache(dest, size, GPU_INVALIDATE_HINT); + return false; } diff --git a/GPU/Null/NullGpu.h b/GPU/Null/NullGpu.h index 050588cdd8..db236f002c 100644 --- a/GPU/Null/NullGpu.h +++ b/GPU/Null/NullGpu.h @@ -34,7 +34,7 @@ public: virtual void CopyDisplayToOutput() {} virtual void UpdateStats(); virtual void InvalidateCache(u32 addr, int size, GPUInvalidationType type); - virtual void UpdateMemory(u32 dest, u32 src, int size); + virtual bool UpdateMemory(u32 dest, u32 src, int size); virtual void ClearCacheNextFrame() {}; virtual void DeviceLost() {} diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 5e13362ff1..994a9dc307 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -851,12 +851,13 @@ void SoftGPU::InvalidateCache(u32 addr, int size, GPUInvalidationType type) // Nothing to invalidate. } -void SoftGPU::UpdateMemory(u32 dest, u32 src, int size) +bool SoftGPU::UpdateMemory(u32 dest, u32 src, int size) { // Nothing to update. InvalidateCache(dest, size, GPU_INVALIDATE_HINT); // Let's just be safe. framebufferDirty_ = true; + return false; } bool SoftGPU::FramebufferDirty() { diff --git a/GPU/Software/SoftGpu.h b/GPU/Software/SoftGpu.h index 940fd1669c..038d79e9bd 100644 --- a/GPU/Software/SoftGpu.h +++ b/GPU/Software/SoftGpu.h @@ -59,7 +59,7 @@ public: virtual void CopyDisplayToOutput(); virtual void UpdateStats(); virtual void InvalidateCache(u32 addr, int size, GPUInvalidationType type); - virtual void UpdateMemory(u32 dest, u32 src, int size); + virtual bool UpdateMemory(u32 dest, u32 src, int size); virtual void ClearCacheNextFrame() {}; virtual void DeviceLost() {}