From 0108004691a582f7df8e629c1e68a6bb0e0b90e7 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Fri, 27 Nov 2020 18:46:23 +0000 Subject: Prefer truly perfect texture matches over fomat aliased ones (#1754) --- Ryujinx.Graphics.Gpu/Image/TextureManager.cs | 43 +++++++++++++++++++--------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Image/TextureManager.cs') diff --git a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs index 0834d7ac..6b11a671 100644 --- a/Ryujinx.Graphics.Gpu/Image/TextureManager.cs +++ b/Ryujinx.Graphics.Gpu/Image/TextureManager.cs @@ -682,26 +682,43 @@ namespace Ryujinx.Graphics.Gpu.Image sameAddressOverlapsCount = _textures.FindOverlaps(info.Address, ref _textureOverlaps); } + Texture texture = null; + + TextureMatchQuality bestQuality = TextureMatchQuality.NoMatch; + for (int index = 0; index < sameAddressOverlapsCount; index++) { Texture overlap = _textureOverlaps[index]; - if (overlap.IsPerfectMatch(info, flags)) + TextureMatchQuality matchQuality = overlap.IsExactMatch(info, flags); + + if (matchQuality == TextureMatchQuality.Perfect) { - if (!isSamplerTexture) - { - // If not a sampler texture, it is managed by the auto delete - // cache, ensure that it is on the "top" of the list to avoid - // deletion. - _cache.Lift(overlap); - } + texture = overlap; + break; + } + else if (matchQuality > bestQuality) + { + texture = overlap; + bestQuality = matchQuality; + } + } - ChangeSizeIfNeeded(info, overlap, isSamplerTexture, sizeHint); + if (texture != null) + { + if (!isSamplerTexture) + { + // If not a sampler texture, it is managed by the auto delete + // cache, ensure that it is on the "top" of the list to avoid + // deletion. + _cache.Lift(texture); + } - overlap.SynchronizeMemory(); + ChangeSizeIfNeeded(info, texture, isSamplerTexture, sizeHint); - return overlap; - } + texture.SynchronizeMemory(); + + return texture; } // Calculate texture sizes, used to find all overlapping textures. @@ -743,8 +760,6 @@ namespace Ryujinx.Graphics.Gpu.Image overlapsCount = _textures.FindOverlaps(info.Address, size, ref _textureOverlaps); } - Texture texture = null; - for (int index = 0; index < overlapsCount; index++) { Texture overlap = _textureOverlaps[index]; -- cgit v1.2.3