From 15e7fe3ac940a1768a25326e66683ad0f23127e0 Mon Sep 17 00:00:00 2001 From: riperiperi Date: Sun, 29 Aug 2021 20:22:13 +0100 Subject: Avoid deleting textures when their data does not overlap. (#2601) * Avoid deleting textures when their data does not overlap. It's possible that while two textures start and end addresses indicate an overlap, that the actual data contained within them is sparse due to a layer stride. One such possibility is array slices of a cubemap at different mip levels - they overlap on a whole, but the actual texture data fills the gaps between each other's layers rather than actually overlapping. This fixes issues with UE4 games having incorrect lighting (solid white screen or really dark shadows). There are still remaining issues with games that use the 3D texture prebaked lighting, such as THPS1+2. This PR also fixes a bug with TexturePool's resized texture handling where the base level in the descriptor was not considered. * AllRegions granularity for 3d textures is now by level rather than by slice. * Address feedback --- Ryujinx.Graphics.Texture/Region.cs | 14 ++++++++++++++ Ryujinx.Graphics.Texture/SizeInfo.cs | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 Ryujinx.Graphics.Texture/Region.cs (limited to 'Ryujinx.Graphics.Texture') diff --git a/Ryujinx.Graphics.Texture/Region.cs b/Ryujinx.Graphics.Texture/Region.cs new file mode 100644 index 00000000..a60951e3 --- /dev/null +++ b/Ryujinx.Graphics.Texture/Region.cs @@ -0,0 +1,14 @@ +namespace Ryujinx.Graphics.Texture +{ + public struct Region + { + public int Offset { get; } + public int Size { get; } + + public Region(int offset, int size) + { + Offset = offset; + Size = size; + } + } +} diff --git a/Ryujinx.Graphics.Texture/SizeInfo.cs b/Ryujinx.Graphics.Texture/SizeInfo.cs index f518ee4b..880d677b 100644 --- a/Ryujinx.Graphics.Texture/SizeInfo.cs +++ b/Ryujinx.Graphics.Texture/SizeInfo.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Ryujinx.Graphics.Texture { @@ -91,5 +92,23 @@ namespace Ryujinx.Graphics.Texture return true; } + + public IEnumerable AllRegions() + { + if (_is3D) + { + for (int i = 0; i < _mipOffsets.Length; i++) + { + yield return new Region(_mipOffsets[i], SliceSizes[i]); + } + } + else + { + for (int i = 0; i < AllOffsets.Length; i++) + { + yield return new Region(AllOffsets[i], SliceSizes[i % _levels]); + } + } + } } } \ No newline at end of file -- cgit v1.2.3