aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Graphics
diff options
context:
space:
mode:
authorjduncanator <jduncanator@users.noreply.github.com>2018-10-29 09:31:13 +1100
committergdkchan <gab.dark.100@gmail.com>2018-10-28 19:31:13 -0300
commitc1b7340023b42161d55993de2e40baad68915b86 (patch)
tree3b88c6c36b1ba4ae9b4f256cffdf4fb0a5c77648 /Ryujinx.Graphics
parentb956bbc32c7f9fdffebfd9a9416e8e0a2a588abd (diff)
Timing: Optimize Timestamp Aquisition (#479)
* Timing: Optimize Timestamp Aquisition Currently, we make use of Environment.TickCount in a number of places. This has some downsides, mainly being that the TickCount is a signed 32-bit integer, and has an effective limit of ~25 days before overflowing and wrapping around. Due to the signed-ness of the value, this also caused issues with negative numbers. This resolves these issues by using a 64-bit tick count obtained from Performance Counters (via the Stopwatch class). This has a beneficial side effect of being significantly more accurate than the TickCount. * Timing: Rename ElapsedTicks to ElapsedMilliseconds and expose TicksPerX * Timing: Some style changes * Timing: Align static variable initialization
Diffstat (limited to 'Ryujinx.Graphics')
-rw-r--r--Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs21
-rw-r--r--Ryujinx.Graphics/NvGpuEngine3d.cs3
2 files changed, 7 insertions, 17 deletions
diff --git a/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs b/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
index 839915ea..a65ebcbb 100644
--- a/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
+++ b/Ryujinx.Graphics/Gal/OpenGL/OGLCachedResource.cs
@@ -1,3 +1,4 @@
+using Ryujinx.Common;
using System;
using System.Collections.Generic;
@@ -18,7 +19,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
public long DataSize { get; private set; }
- public int Timestamp { get; private set; }
+ public long Timestamp { get; private set; }
public CacheBucket(T Value, long DataSize, LinkedListNode<long> Node)
{
@@ -26,7 +27,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
this.DataSize = DataSize;
this.Node = Node;
- Timestamp = Environment.TickCount;
+ Timestamp = PerformanceCounter.ElapsedMilliseconds;
}
}
@@ -141,7 +142,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
private void ClearCacheIfNeeded()
{
- int Timestamp = Environment.TickCount;
+ long Timestamp = PerformanceCounter.ElapsedMilliseconds;
int Count = 0;
@@ -156,7 +157,7 @@ namespace Ryujinx.Graphics.Gal.OpenGL
CacheBucket Bucket = Cache[Node.Value];
- int TimeDelta = RingDelta(Bucket.Timestamp, Timestamp);
+ long TimeDelta = Bucket.Timestamp - Timestamp;
if ((uint)TimeDelta <= (uint)MaxTimeDelta)
{
@@ -170,17 +171,5 @@ namespace Ryujinx.Graphics.Gal.OpenGL
DeleteValueCallback(Bucket.Value);
}
}
-
- private int RingDelta(int Old, int New)
- {
- if ((uint)New < (uint)Old)
- {
- return New + (~Old + 1);
- }
- else
- {
- return New - Old;
- }
- }
}
} \ No newline at end of file
diff --git a/Ryujinx.Graphics/NvGpuEngine3d.cs b/Ryujinx.Graphics/NvGpuEngine3d.cs
index 7d2b2b43..618d7d9f 100644
--- a/Ryujinx.Graphics/NvGpuEngine3d.cs
+++ b/Ryujinx.Graphics/NvGpuEngine3d.cs
@@ -1,3 +1,4 @@
+using Ryujinx.Common;
using Ryujinx.Graphics.Gal;
using Ryujinx.Graphics.Memory;
using Ryujinx.Graphics.Texture;
@@ -851,7 +852,7 @@ namespace Ryujinx.Graphics
//TODO: Implement counters.
long Counter = 1;
- long Timestamp = (uint)Environment.TickCount;
+ long Timestamp = PerformanceCounter.ElapsedMilliseconds;
Timestamp = (long)(Timestamp * 615384.615385);