Skip to content

Commit

Permalink
Respect the stride for efb copies when hashing them
Browse files Browse the repository at this point in the history
  • Loading branch information
mimimi085181 committed Sep 13, 2015
1 parent 45c1cfa commit 663bd91
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
24 changes: 22 additions & 2 deletions Source/Core/VideoCommon/TextureCacheBase.cpp
Expand Up @@ -159,7 +159,7 @@ void TextureCache::Cleanup(int _frameCount)
// Only remove EFB copies when they wouldn't be used anymore(changed hash), because EFB copies living on the
// host GPU are unrecoverable. Perform this check only every TEXTURE_KILL_THRESHOLD for performance reasons
if ((_frameCount - iter->second->frameCount) % TEXTURE_KILL_THRESHOLD == 1 &&
iter->second->hash != GetHash64(Memory::GetPointer(iter->second->addr), iter->second->size_in_bytes, g_ActiveConfig.iSafeTextureCache_ColorSamples))
iter->second->hash != iter->second->CalculateHash())
{
iter = FreeTexture(iter);
}
Expand Down Expand Up @@ -1029,7 +1029,7 @@ void TextureCache::CopyRenderTargetToTexture(u32 dstAddr, unsigned int dstFormat

entry->FromRenderTarget(dst, dstFormat, dstStride, srcFormat, srcRect, isIntensity, scaleByHalf, cbufid, colmat);

u64 hash = GetHash64(dst, (int)entry->size_in_bytes, g_ActiveConfig.iSafeTextureCache_ColorSamples);
u64 hash = entry->CalculateHash();
entry->SetHashes(hash, hash);

// Invalidate all textures that overlap the range of our efb copy.
Expand Down Expand Up @@ -1134,3 +1134,23 @@ void TextureCache::TCacheEntryBase::Zero(u8* ptr)
ptr += memory_stride;
}
}

u64 TextureCache::TCacheEntryBase::CalculateHash()
{
u8* ptr = Memory::GetPointer(addr);
if (memory_stride == CacheLinesPerRow() * 32)
{
return GetHash64(ptr, (int)size_in_bytes, g_ActiveConfig.iSafeTextureCache_ColorSamples);
}
else
{
u64 temp_hash = size_in_bytes;
u32 samples = ((size_in_bytes + NumBlocksY() - 1) / NumBlocksY()) * g_ActiveConfig.iSafeTextureCache_ColorSamples;
for (u32 i = 0; i < NumBlocksY(); i++)
{
temp_hash = (temp_hash * 397) ^ GetHash64(ptr, (int)CacheLinesPerRow() * 32, samples);
ptr += memory_stride;
}
return temp_hash;
}
}
2 changes: 2 additions & 0 deletions Source/Core/VideoCommon/TextureCacheBase.h
Expand Up @@ -114,6 +114,8 @@ class TextureCache
u32 CacheLinesPerRow() const;

void Zero(u8* ptr);

u64 CalculateHash();
};

virtual ~TextureCache(); // needs virtual for DX11 dtor
Expand Down

0 comments on commit 663bd91

Please sign in to comment.