aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics.Gpu/Image/Texture.cs
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2020-10-25 17:09:45 -0300
committerGitHub <noreply@github.com>2020-10-25 17:09:45 -0300
commitcf0f0fc4e740c774eadaa328dc543ee9a03fbd09 (patch)
tree0a9bc9f24a588da5e34774efa62776fb96ff85bc /Ryujinx.Graphics.Gpu/Image/Texture.cs
parent49f970d5bd9163e2b4e26a33ef8f84529174d5de (diff)
Improve the speed of redundant ASTC texture data updates (#1636)
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Image/Texture.cs')
-rw-r--r--Ryujinx.Graphics.Gpu/Image/Texture.cs31
1 files changed, 30 insertions, 1 deletions
diff --git a/Ryujinx.Graphics.Gpu/Image/Texture.cs b/Ryujinx.Graphics.Gpu/Image/Texture.cs
index 6778567c..2b1aaa0a 100644
--- a/Ryujinx.Graphics.Gpu/Image/Texture.cs
+++ b/Ryujinx.Graphics.Gpu/Image/Texture.cs
@@ -16,6 +16,11 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
class Texture : IRange, IDisposable
{
+ // How many updates we need before switching to the byte-by-byte comparison
+ // modification check method.
+ // This method uses much more memory so we want to avoid it if possible.
+ private const int ByteComparisonSwitchThreshold = 4;
+
private GpuContext _context;
private SizeInfo _sizeInfo;
@@ -51,6 +56,8 @@ namespace Ryujinx.Graphics.Gpu.Image
private int _firstLevel;
private bool _hasData;
+ private int _updateCount;
+ private byte[] _currentData;
private ITexture _arrayViewTexture;
private Target _arrayViewTarget;
@@ -545,7 +552,7 @@ namespace Ryujinx.Graphics.Gpu.Image
}
/// <summary>
- /// Checks if the memory for this texture was modified, and returns true if it was.
+ /// Checks if the memory for this texture was modified, and returns true if it was.
/// The modified flags are consumed as a result.
/// </summary>
/// <remarks>
@@ -591,6 +598,27 @@ namespace Ryujinx.Graphics.Gpu.Image
IsModified = false;
+ // If the host does not support ASTC compression, we need to do the decompression.
+ // The decompression is slow, so we want to avoid it as much as possible.
+ // This does a byte-by-byte check and skips the update if the data is equal in this case.
+ // This improves the speed on applications that overwrites ASTC data without changing anything.
+ if (Info.FormatInfo.Format.IsAstc() && !_context.Capabilities.SupportsAstcCompression)
+ {
+ if (_updateCount < ByteComparisonSwitchThreshold)
+ {
+ _updateCount++;
+ }
+ else
+ {
+ bool dataMatches = _currentData != null && data.SequenceEqual(_currentData);
+ _currentData = data.ToArray();
+ if (dataMatches)
+ {
+ return;
+ }
+ }
+ }
+
data = ConvertToHostCompatibleFormat(data);
HostTexture.SetData(data);
@@ -1132,6 +1160,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// </summary>
private void DisposeTextures()
{
+ _currentData = null;
HostTexture.Release();
_arrayViewTexture?.Release();