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>
This commit is contained in:
mageven 2021-03-03 06:09:36 +05:30 committed by GitHub
parent 31fca432a7
commit ca5d8e58dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 148 additions and 19 deletions

View file

@ -70,6 +70,10 @@ namespace ARMeilleure.Translation.PTC
internal static PtcState State { get; private set; }
// Progress update events
public static event Action<bool> PtcTranslationStateChanged;
public static event Action<int, int> PtcTranslationProgressChanged;
static Ptc()
{
InitializeMemoryStreams();
@ -772,6 +776,8 @@ namespace ARMeilleure.Translation.PTC
ThreadPool.QueueUserWorkItem(TranslationLogger, profiledFuncsToTranslate.Count);
PtcTranslationStateChanged?.Invoke(true);
void TranslateFuncs()
{
while (profiledFuncsToTranslate.TryDequeue(out var item))
@ -820,6 +826,7 @@ namespace ARMeilleure.Translation.PTC
threads.Clear();
_loggerEvent.Set();
PtcTranslationStateChanged?.Invoke(false);
PtcJumpTable.Initialize(jumpTable);
@ -833,15 +840,15 @@ namespace ARMeilleure.Translation.PTC
private static void TranslationLogger(object state)
{
const int refreshRate = 1; // Seconds.
const int refreshRate = 100; // ms
int profiledFuncsToTranslateCount = (int)state;
do
{
Logger.Info?.Print(LogClass.Ptc, $"{_translateCount} of {profiledFuncsToTranslateCount} functions translated");
PtcTranslationProgressChanged?.Invoke(_translateCount, profiledFuncsToTranslateCount);
}
while (!_loggerEvent.WaitOne(refreshRate * 1000));
while (!_loggerEvent.WaitOne(refreshRate));
Logger.Info?.Print(LogClass.Ptc, $"{_translateCount} of {profiledFuncsToTranslateCount} functions translated");
}