diff --git a/Core/HLE/ReplaceTables.cpp b/Core/HLE/ReplaceTables.cpp index 2a14406eb3..31f44f7cc6 100644 --- a/Core/HLE/ReplaceTables.cpp +++ b/Core/HLE/ReplaceTables.cpp @@ -132,6 +132,7 @@ static int Replace_memcpy() { skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes); } } + gpu->NotifyVideoCopy(destPtr, srcPtr, bytes); if (!skip && bytes != 0) { u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes); @@ -193,6 +194,7 @@ static int Replace_memcpy_jak() { skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes); } } + gpu->NotifyVideoCopy(destPtr, srcPtr, bytes); if (!skip && bytes > SLICE_SIZE && bytes != 512 * 272 * 4 && !PSP_CoreParameter().compat.flags().DisableMemcpySlicing) { // This is a very slow func. To avoid thread blocking, do a slice at a time. // Avoiding exactly 512 * 272 * 4 to detect videos, though. @@ -264,6 +266,7 @@ static int Replace_memcpy16() { skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes); } } + gpu->NotifyVideoCopy(destPtr, srcPtr, bytes); if (!skip && bytes != 0) { u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes); @@ -332,6 +335,7 @@ static int Replace_memmove() { skip = gpu->PerformMemoryCopy(destPtr, srcPtr, bytes); } } + gpu->NotifyVideoCopy(destPtr, srcPtr, bytes); if (!skip && bytes != 0) { u8 *dst = Memory::GetPointerWriteRangeOrException(destPtr, bytes); const u8 *src = Memory::GetPointerRangeOrException(srcPtr, bytes); diff --git a/Core/HLE/sceDmac.cpp b/Core/HLE/sceDmac.cpp index 666138208c..c311cf0bc4 100644 --- a/Core/HLE/sceDmac.cpp +++ b/Core/HLE/sceDmac.cpp @@ -51,6 +51,7 @@ static int __DmacMemcpy(MIPSState *mips, u32 dst, u32 src, u32 size) { // We let the GPU deal with invalid range. skip = gpu->PerformMemoryCopy(dst, src, size); } + gpu->NotifyVideoCopy(dst, src, size); if (!skip && size != 0) { mips->InvalidateICacheRangeDeferred(src, size); if (Memory::IsValidRange(dst, size) && Memory::IsValidRange(src, size)) { diff --git a/Core/HLE/sceKernelInterrupt.cpp b/Core/HLE/sceKernelInterrupt.cpp index 517a599a2c..4d79d764d9 100644 --- a/Core/HLE/sceKernelInterrupt.cpp +++ b/Core/HLE/sceKernelInterrupt.cpp @@ -632,6 +632,7 @@ static u32 sceKernelMemcpy(u32 dst, u32 src, u32 size) { if (Memory::IsVRAMAddress(src) || Memory::IsVRAMAddress(dst)) { skip = gpu->PerformMemoryCopy(dst, src, size); } + gpu->NotifyVideoCopy(dst, src, size); // Technically should crash if these are invalid and size > 0... if (!skip && Memory::IsValidAddress(dst) && Memory::IsValidAddress(src) && Memory::IsValidAddress(dst + size - 1) && Memory::IsValidAddress(src + size - 1)) { diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 8331a34324..9b20f3e649 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -1506,19 +1506,35 @@ void TextureCacheCommon::NotifyConfigChanged() { replacer_.NotifyConfigChanged(); } -void TextureCacheCommon::NotifyWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat fmt) { +void TextureCacheCommon::NoteVideoRange(u32 addr, u32 size) { addr &= 0x3FFFFFFF; // A game blits its video frame every displayed frame while waiting for the next one, so the - // same few display buffers arrive over and over. Refresh the one we already have rather than - // stacking a duplicate per frame - IsVideo() scans this linearly. + // same few buffers arrive over and over. Refresh the one we already have rather than stacking + // a duplicate per frame - IsVideo() scans this linearly. for (VideoInfo &info : videos_) { if (info.addr == addr) { - info.size = (u32)size; + info.size = size; info.flips = gpuStats.totals.numFlips; return; } } - videos_.push_back({ addr, (u32)size, gpuStats.totals.numFlips }); + videos_.push_back({ addr, size, gpuStats.totals.numFlips }); +} + +void TextureCacheCommon::NotifyWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat fmt) { + NoteVideoRange(addr, (u32)size); +} + +// A block copy of a video frame is still a video frame, and games do move them around: Dragon Ball +// Z - Shin Budokai: Another Road colour-converts into RAM, sceDmacMemcpy's the result into VRAM and +// textures from there, never sampling the converted buffer itself. Without carrying the status +// across the copy, what we actually sample looks like an ordinary texture that happens to have new +// contents every frame, so we hash it, miss, and rebuild it - forever. +void TextureCacheCommon::NotifyVideoCopy(u32 dst, u32 src, int size) { + if (size <= 0 || !IsVideo(src)) { + return; + } + NoteVideoRange(dst, (u32)size); } void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes, GPURecord::Recorder *recorder) { diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 42a93427f9..ae7d99f30f 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -363,6 +363,7 @@ public: // so that it can invalidate TexCacheEntries pointed at those addresses. void NotifyFramebuffer(VirtualFramebuffer *framebuffer, FramebufferNotification msg); void NotifyWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat fmt); + void NotifyVideoCopy(u32 dst, u32 src, int size); int NumLoadedTextures() const { return (int)cache_.size(); @@ -445,6 +446,7 @@ protected: virtual void BoundFramebufferTexture() {} bool IsVideo(u32 texaddr) const; + void NoteVideoRange(u32 addr, u32 size); static TextureAlpha CheckCLUTAlpha(const uint8_t *pixelData, GEPaletteFormat clutFmt, int w); diff --git a/GPU/GPUCommon.cpp b/GPU/GPUCommon.cpp index 9a3e434ea7..acadf91f3e 100644 --- a/GPU/GPUCommon.cpp +++ b/GPU/GPUCommon.cpp @@ -2004,6 +2004,12 @@ void GPUCommon::DoBlockTransfer(u32 skipDrawReason) { cyclesExecuted += ((height * width * bpp) * 16) / 10; } +void GPUCommon::NotifyVideoCopy(u32 dest, u32 src, int size) { + if (textureCache_) { + textureCache_->NotifyVideoCopy(dest, src, size); + } +} + bool GPUCommon::PerformMemoryCopy(u32 dest, u32 src, int size, GPUCopyFlag flags) { if (size == 0) { _dbg_assert_msg_(false, "Zero-sized PerformMemoryCopy: %08x -> %08x, size %d (flag: %d)", src, dest, size, (int)flags); diff --git a/GPU/GPUCommon.h b/GPU/GPUCommon.h index 4660a9ce71..ff1839c510 100644 --- a/GPU/GPUCommon.h +++ b/GPU/GPUCommon.h @@ -162,6 +162,10 @@ public: virtual void PerformWriteFormattedFromMemory(u32 addr, int size, int width, GEBufferFormat format); virtual bool PerformWriteStencilFromMemory(u32 dest, int size, WriteStencil flags); + // Tells the texture cache that a block copy moved pixels, so it can carry "this is video" from + // the source to the destination. Cheap and safe to call for any copy. + void NotifyVideoCopy(u32 dest, u32 src, int size); + virtual void ExecuteOp(u32 op, u32 diff) = 0; void Execute_OffsetAddr(u32 op, u32 diff);