diff options
author | mageven <62494521+mageven@users.noreply.github.com> | 2021-03-03 06:09:36 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-03 01:39:36 +0100 |
commit | ca5d8e58ddd0c089763645efcc58b5dc6614f8eb (patch) | |
tree | a5bca1cb574a50471d3fb1b6cc397f834ce3374d /Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | |
parent | 31fca432a7274907c46f6ec254d54e96cb6446c6 (diff) |
Add progress reporting to PTC and Shader Cache (#2057)
* UI changes
* Add progress reporting to PTC & ShaderCache
* Account for null events and expand docs
Co-authored-by: Joshi234 <46032261+Joshi234@users.noreply.github.com>
Diffstat (limited to 'Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs')
-rw-r--r-- | Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs index 6a3971df..bf89f29d 100644 --- a/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs +++ b/Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs @@ -9,6 +9,7 @@ using Ryujinx.Graphics.Shader.Translation; using System; using System.Collections.Generic; using System.Diagnostics; +using System.Threading; namespace Ryujinx.Graphics.Gpu.Shader { @@ -36,6 +37,12 @@ namespace Ryujinx.Graphics.Gpu.Shader /// </summary> private const ulong ShaderCodeGenVersion = 1961; + // Progress reporting helpers + private int _shaderCount; + private readonly AutoResetEvent _progressReportEvent; + public event Action<bool> ShaderCacheStateChanged; + public event Action<int, int> ShaderCacheProgressChanged; + /// <summary> /// Creates a new instance of the shader cache. /// </summary> @@ -50,6 +57,8 @@ namespace Ryujinx.Graphics.Gpu.Shader _gpPrograms = new Dictionary<ShaderAddresses, List<ShaderBundle>>(); _gpProgramsDiskCache = new Dictionary<Hash128, ShaderBundle>(); _cpProgramsDiskCache = new Dictionary<Hash128, ShaderBundle>(); + + _progressReportEvent = new AutoResetEvent(false); } /// <summary> @@ -76,12 +85,16 @@ namespace Ryujinx.Graphics.Gpu.Shader ReadOnlySpan<Hash128> guestProgramList = _cacheManager.GetGuestProgramList(); + _progressReportEvent.Reset(); + _shaderCount = 0; + + ShaderCacheStateChanged?.Invoke(true); + ThreadPool.QueueUserWorkItem(ProgressLogger, guestProgramList.Length); + for (int programIndex = 0; programIndex < guestProgramList.Length; programIndex++) { Hash128 key = guestProgramList[programIndex]; - Logger.Info?.Print(LogClass.Gpu, $"Compiling shader {key} ({programIndex + 1} / {guestProgramList.Length})"); - byte[] hostProgramBinary = _cacheManager.GetHostProgramByHash(ref key); bool hasHostCache = hostProgramBinary != null; @@ -304,6 +317,8 @@ namespace Ryujinx.Graphics.Gpu.Shader _gpProgramsDiskCache.Add(key, new ShaderBundle(hostProgram, shaders)); } + + _shaderCount = programIndex; } if (!isReadOnly) @@ -314,8 +329,26 @@ namespace Ryujinx.Graphics.Gpu.Shader _cacheManager.Synchronize(); } - Logger.Info?.Print(LogClass.Gpu, "Shader cache loaded."); + _progressReportEvent.Set(); + ShaderCacheStateChanged?.Invoke(false); + + Logger.Info?.Print(LogClass.Gpu, $"Shader cache loaded {_shaderCount} entries."); + } + } + + /// <summary> + /// Raises ShaderCacheProgressChanged events periodically. + /// </summary> + private void ProgressLogger(object state) + { + const int refreshRate = 100; // ms + + int totalCount = (int)state; + do + { + ShaderCacheProgressChanged?.Invoke(_shaderCount, totalCount); } + while (!_progressReportEvent.WaitOne(refreshRate)); } /// <summary> @@ -787,6 +820,7 @@ namespace Ryujinx.Graphics.Gpu.Shader } } + _progressReportEvent?.Dispose(); _cacheManager?.Dispose(); } } |