From dd54617a083ae6136015602a46298020f2f20012 Mon Sep 17 00:00:00 2001 From: iwubcode Date: Sat, 4 Nov 2017 12:04:26 -0500 Subject: [PATCH] TextureCacheBase: Set uninitialized XFB memory to fuchsia color --- Source/Core/VideoCommon/TextureCacheBase.cpp | 48 +++++++++++++++++--- Source/Core/VideoCommon/TextureCacheBase.h | 2 + 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/Source/Core/VideoCommon/TextureCacheBase.cpp b/Source/Core/VideoCommon/TextureCacheBase.cpp index 042dbd4e8a..07b6609282 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.cpp +++ b/Source/Core/VideoCommon/TextureCacheBase.cpp @@ -1878,14 +1878,21 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstF } else { - // Hack: Most games don't actually need the correct texture data in RAM - // and we can just keep a copy in VRAM. We zero the memory so we - // can check it hasn't changed before using our copy in VRAM. - u8* ptr = dst; - for (u32 i = 0; i < num_blocks_y; i++) + if (is_xfb_copy) { - memset(ptr, 0, bytes_per_row); - ptr += dstStride; + UninitializeXFBMemory(dst, dstStride, bytes_per_row, num_blocks_y); + } + else + { + // Hack: Most games don't actually need the correct texture data in RAM + // and we can just keep a copy in VRAM. We zero the memory so we + // can check it hasn't changed before using our copy in VRAM. + u8* ptr = dst; + for (u32 i = 0; i < num_blocks_y; i++) + { + memset(ptr, 0, bytes_per_row); + ptr += dstStride; + } } } @@ -2030,6 +2037,33 @@ void TextureCacheBase::CopyRenderTargetToTexture(u32 dstAddr, EFBCopyFormat dstF } } +void TextureCacheBase::UninitializeXFBMemory(u8* dst, u32 stride, u32 bytes_per_row, + u32 num_blocks_y) +{ + // Originally, we planned on using a 'key color' + // for alpha to address partial xfbs (Mario Strikers / Chicken Little). + // This work was removed since it was unfinished but there + // was still a desire to differentiate between the old and the new approach + // which is why we still set uninitialized xfb memory to fuchsia + // (Y=1,U=254,V=254) instead of dark green (Y=0,U=0,V=0) in YUV + // like is done in the EFB path. + for (u32 i = 0; i < num_blocks_y; i++) + { + for (u32 offset = 0; offset < bytes_per_row; offset++) + { + if (offset % 2) + { + dst[offset] = 254; + } + else + { + dst[offset] = 1; + } + } + dst += stride; + } +} + TextureCacheBase::TCacheEntry* TextureCacheBase::AllocateCacheEntry(const TextureConfig& config) { std::unique_ptr texture = AllocateTexture(config); diff --git a/Source/Core/VideoCommon/TextureCacheBase.h b/Source/Core/VideoCommon/TextureCacheBase.h index 5eee06c6d8..a9700ad68c 100644 --- a/Source/Core/VideoCommon/TextureCacheBase.h +++ b/Source/Core/VideoCommon/TextureCacheBase.h @@ -323,6 +323,8 @@ private: // Removes and unlinks texture from texture cache and returns it to the pool TexAddrCache::iterator InvalidateTexture(TexAddrCache::iterator t_iter); + void UninitializeXFBMemory(u8* dst, u32 stride, u32 bytes_per_row, u32 num_blocks_y); + TexAddrCache textures_by_address; TexHashCache textures_by_hash; TexPool texture_pool;