diff --git a/GPU/Common/TextureCacheCommon.cpp b/GPU/Common/TextureCacheCommon.cpp index 67345cd33a..3cd700732e 100644 --- a/GPU/Common/TextureCacheCommon.cpp +++ b/GPU/Common/TextureCacheCommon.cpp @@ -33,6 +33,9 @@ #include #endif +// Videos should be updated every few frames, so we forge quickly. +#define VIDEO_DECIMATE_AGE 4 + // Ugly. extern int g_iNumVideos; @@ -145,6 +148,18 @@ void TextureCacheCommon::UpdateMaxSeenV(bool throughMode) { } } +void TextureCacheCommon::DecimateVideos() { + if (!videos_.empty()) { + for (auto iter = videos_.begin(); iter != videos_.end(); ) { + if (iter->second + VIDEO_DECIMATE_AGE < gpuStats.numFlips) { + videos_.erase(iter++); + } else { + ++iter; + } + } + } +} + void TextureCacheCommon::NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer, FramebufferNotification msg) { // Must be in VRAM so | 0x04000000 it is. Also, ignore memory mirrors. // These checks are mainly to reduce scanning all textures. @@ -293,6 +308,10 @@ void TextureCacheCommon::NotifyConfigChanged() { replacer.NotifyConfigChanged(); } +void TextureCacheCommon::NotifyVideoUpload(u32 addr, int size, int width, GEBufferFormat fmt) { + videos_[addr] = gpuStats.numFlips; +} + void TextureCacheCommon::LoadClut(u32 clutAddr, u32 loadBytes) { clutTotalBytes_ = loadBytes; clutRenderAddress_ = 0xFFFFFFFF; diff --git a/GPU/Common/TextureCacheCommon.h b/GPU/Common/TextureCacheCommon.h index 6dcec60e5b..8e6b5bd110 100644 --- a/GPU/Common/TextureCacheCommon.h +++ b/GPU/Common/TextureCacheCommon.h @@ -55,6 +55,7 @@ public: // FramebufferManager keeps TextureCache updated about what regions of memory are being rendered to. void NotifyFramebuffer(u32 address, VirtualFramebuffer *framebuffer, FramebufferNotification msg); void NotifyConfigChanged(); + void NotifyVideoUpload(u32 addr, int size, int width, GEBufferFormat fmt); int AttachedDrawingHeight(); @@ -155,6 +156,8 @@ protected: virtual void DownloadFramebufferForClut(u32 clutAddr, u32 bytes) = 0; + void DecimateVideos(); + TextureReplacer replacer; TexCache cache; @@ -171,6 +174,8 @@ protected: void AttachFramebufferInvalid(TexCacheEntry *entry, VirtualFramebuffer *framebuffer, const AttachedFramebufferInfo &fbInfo); void DetachFramebuffer(TexCacheEntry *entry, u32 address, VirtualFramebuffer *framebuffer); + std::map videos_; + SimpleBuf tmpTexBuf32; SimpleBuf tmpTexBuf16; SimpleBuf tmpTexBufRearrange; diff --git a/GPU/Directx9/GPU_DX9.cpp b/GPU/Directx9/GPU_DX9.cpp index 190c99d6d9..9e29ad3dd8 100644 --- a/GPU/Directx9/GPU_DX9.cpp +++ b/GPU/Directx9/GPU_DX9.cpp @@ -2006,6 +2006,7 @@ void GPU_DX9::NotifyVideoUpload(u32 addr, int size, int width, int format) { if (Memory::IsVRAMAddress(addr)) { framebufferManager_.NotifyVideoUpload(addr, size, width, (GEBufferFormat)format); } + textureCache_.NotifyVideoUpload(addr, size, width, (GEBufferFormat)format); InvalidateCache(addr, size, GPU_INVALIDATE_SAFE); } diff --git a/GPU/Directx9/TextureCacheDX9.cpp b/GPU/Directx9/TextureCacheDX9.cpp index e9478844c1..af170647f3 100644 --- a/GPU/Directx9/TextureCacheDX9.cpp +++ b/GPU/Directx9/TextureCacheDX9.cpp @@ -112,6 +112,7 @@ void TextureCacheDX9::Clear(bool delete_them) { secondCacheSizeEstimate_ = 0; } fbTexInfo_.clear(); + videos_.clear(); } void TextureCacheDX9::DeleteTexture(TexCache::iterator it) { @@ -170,6 +171,8 @@ void TextureCacheDX9::Decimate() { VERBOSE_LOG(G3D, "Decimated second texture cache, saved %d estimated bytes - now %d bytes", had - secondCacheSizeEstimate_, secondCacheSizeEstimate_); } + + DecimateVideos(); } void TextureCacheDX9::Invalidate(u32 addr, int size, GPUInvalidationType type) { diff --git a/GPU/GLES/GPU_GLES.cpp b/GPU/GLES/GPU_GLES.cpp index 3324f8f815..b542631a0a 100644 --- a/GPU/GLES/GPU_GLES.cpp +++ b/GPU/GLES/GPU_GLES.cpp @@ -2261,6 +2261,7 @@ void GPU_GLES::NotifyVideoUpload(u32 addr, int size, int width, int format) { if (Memory::IsVRAMAddress(addr)) { framebufferManager_.NotifyVideoUpload(addr, size, width, (GEBufferFormat)format); } + textureCache_.NotifyVideoUpload(addr, size, width, (GEBufferFormat)format); InvalidateCache(addr, size, GPU_INVALIDATE_SAFE); } diff --git a/GPU/GLES/TextureCache.cpp b/GPU/GLES/TextureCache.cpp index ed8cf6322c..876276927a 100644 --- a/GPU/GLES/TextureCache.cpp +++ b/GPU/GLES/TextureCache.cpp @@ -114,6 +114,7 @@ void TextureCache::Clear(bool delete_them) { secondCacheSizeEstimate_ = 0; } fbTexInfo_.clear(); + videos_.clear(); } void TextureCache::DeleteTexture(TexCache::iterator it) { @@ -168,6 +169,8 @@ void TextureCache::Decimate() { VERBOSE_LOG(G3D, "Decimated second texture cache, saved %d estimated bytes - now %d bytes", had - secondCacheSizeEstimate_, secondCacheSizeEstimate_); } + + DecimateVideos(); } void TextureCache::Invalidate(u32 addr, int size, GPUInvalidationType type) { diff --git a/GPU/Vulkan/GPU_Vulkan.cpp b/GPU/Vulkan/GPU_Vulkan.cpp index 78111a790a..6f91e2ec7c 100644 --- a/GPU/Vulkan/GPU_Vulkan.cpp +++ b/GPU/Vulkan/GPU_Vulkan.cpp @@ -2167,7 +2167,12 @@ bool GPU_Vulkan::PerformMemorySet(u32 dest, u8 v, int size) { } void GPU_Vulkan::NotifyVideoUpload(u32 addr, int size, int width, int format) { - + if (Memory::IsVRAMAddress(addr)) { + // TODO + //framebufferManager_.NotifyVideoUpload(addr, size, width, (GEBufferFormat)format); + } + textureCache_.NotifyVideoUpload(addr, size, width, (GEBufferFormat)format); + InvalidateCache(addr, size, GPU_INVALIDATE_SAFE); } bool GPU_Vulkan::PerformMemoryDownload(u32 dest, int size) { diff --git a/GPU/Vulkan/TextureCacheVulkan.cpp b/GPU/Vulkan/TextureCacheVulkan.cpp index 60194bd112..3f6741ced3 100644 --- a/GPU/Vulkan/TextureCacheVulkan.cpp +++ b/GPU/Vulkan/TextureCacheVulkan.cpp @@ -177,6 +177,7 @@ void TextureCacheVulkan::Clear(bool delete_them) { secondCacheSizeEstimate_ = 0; } fbTexInfo_.clear(); + videos_.clear(); } void TextureCacheVulkan::DeleteTexture(TexCache::iterator it) { @@ -230,6 +231,8 @@ void TextureCacheVulkan::Decimate() { VERBOSE_LOG(G3D, "Decimated second texture cache, saved %d estimated bytes - now %d bytes", had - secondCacheSizeEstimate_, secondCacheSizeEstimate_); } + + DecimateVideos(); } void TextureCacheVulkan::Invalidate(u32 addr, int size, GPUInvalidationType type) {