From ca5d8e58ddd0c089763645efcc58b5dc6614f8eb Mon Sep 17 00:00:00 2001 From: mageven <62494521+mageven@users.noreply.github.com> Date: Wed, 3 Mar 2021 06:09:36 +0530 Subject: 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> --- Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs | 40 +++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'Ryujinx.Graphics.Gpu/Shader/ShaderCache.cs') 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 /// private const ulong ShaderCodeGenVersion = 1961; + // Progress reporting helpers + private int _shaderCount; + private readonly AutoResetEvent _progressReportEvent; + public event Action ShaderCacheStateChanged; + public event Action ShaderCacheProgressChanged; + /// /// Creates a new instance of the shader cache. /// @@ -50,6 +57,8 @@ namespace Ryujinx.Graphics.Gpu.Shader _gpPrograms = new Dictionary>(); _gpProgramsDiskCache = new Dictionary(); _cpProgramsDiskCache = new Dictionary(); + + _progressReportEvent = new AutoResetEvent(false); } /// @@ -76,12 +85,16 @@ namespace Ryujinx.Graphics.Gpu.Shader ReadOnlySpan 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."); + } + } + + /// + /// Raises ShaderCacheProgressChanged events periodically. + /// + private void ProgressLogger(object state) + { + const int refreshRate = 100; // ms + + int totalCount = (int)state; + do + { + ShaderCacheProgressChanged?.Invoke(_shaderCount, totalCount); } + while (!_progressReportEvent.WaitOne(refreshRate)); } /// @@ -787,6 +820,7 @@ namespace Ryujinx.Graphics.Gpu.Shader } } + _progressReportEvent?.Dispose(); _cacheManager?.Dispose(); } } -- cgit v1.2.3