From fc4b7cba2c083b3920f2d74e0cb4b08cf7a5a278 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Wed, 4 Jan 2023 20:01:44 -0300 Subject: Make PPTC state non-static (#4157) * Make PPTC state non-static * DiskCacheLoadState can be null --- Ryujinx.Cpu/ICpuContext.cs | 22 ++++++++++++++++++ Ryujinx.Cpu/IDiskCacheState.cs | 20 +++++++++++++++++ Ryujinx.Cpu/Jit/JitCpuContext.cs | 12 ++++++++++ Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs | 38 ++++++++++++++++++++++++++++++++ Ryujinx.Cpu/LoadState.cs | 12 ++++++++++ 5 files changed, 104 insertions(+) create mode 100644 Ryujinx.Cpu/IDiskCacheState.cs create mode 100644 Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs create mode 100644 Ryujinx.Cpu/LoadState.cs (limited to 'Ryujinx.Cpu') diff --git a/Ryujinx.Cpu/ICpuContext.cs b/Ryujinx.Cpu/ICpuContext.cs index 4a73a833..80916d1c 100644 --- a/Ryujinx.Cpu/ICpuContext.cs +++ b/Ryujinx.Cpu/ICpuContext.cs @@ -35,5 +35,27 @@ namespace Ryujinx.Cpu /// Address of the region to be invalidated /// Size of the region to be invalidated void InvalidateCacheRegion(ulong address, ulong size); + + /// + /// Loads cached code from disk for a given application. + /// + /// + /// If the execution engine is recompiling guest code, this can be used to load cached code from disk. + /// + /// Title ID of the application in padded hex form + /// Version of the application + /// True if the cache should be loaded from disk if it exists, false otherwise + /// Disk cache load progress reporter and manager + IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled); + + /// + /// Indicates that code has been loaded into guest memory, and that it might be executed in the future. + /// + /// + /// Some execution engines might use this information to cache recompiled code on disk or to ensure it can be executed. + /// + /// CPU virtual address where the code starts + /// Size of the code range in bytes + void PrepareCodeRange(ulong address, ulong size); } } diff --git a/Ryujinx.Cpu/IDiskCacheState.cs b/Ryujinx.Cpu/IDiskCacheState.cs new file mode 100644 index 00000000..61bbdf92 --- /dev/null +++ b/Ryujinx.Cpu/IDiskCacheState.cs @@ -0,0 +1,20 @@ +using System; + +namespace Ryujinx.Cpu +{ + /// + /// Disk cache load state report and management interface. + /// + public interface IDiskCacheLoadState + { + /// + /// Event used to report the cache load progress. + /// + event Action StateChanged; + + /// + /// Cancels the disk cache load process. + /// + void Cancel(); + } +} diff --git a/Ryujinx.Cpu/Jit/JitCpuContext.cs b/Ryujinx.Cpu/Jit/JitCpuContext.cs index d6892ea7..02465a0b 100644 --- a/Ryujinx.Cpu/Jit/JitCpuContext.cs +++ b/Ryujinx.Cpu/Jit/JitCpuContext.cs @@ -37,5 +37,17 @@ namespace Ryujinx.Cpu.Jit { _translator.InvalidateJitCacheRegion(address, size); } + + /// + public IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled) + { + return new JitDiskCacheLoadState(_translator.LoadDiskCache(titleIdText, displayVersion, enabled)); + } + + /// + public void PrepareCodeRange(ulong address, ulong size) + { + _translator.PrepareCodeRange(address, size); + } } } diff --git a/Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs b/Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs new file mode 100644 index 00000000..7a4b670b --- /dev/null +++ b/Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs @@ -0,0 +1,38 @@ +using ARMeilleure.Translation.PTC; +using System; + +namespace Ryujinx.Cpu.Jit +{ + public class JitDiskCacheLoadState : IDiskCacheLoadState + { + /// + public event Action StateChanged; + + private readonly IPtcLoadState _loadState; + + public JitDiskCacheLoadState(IPtcLoadState loadState) + { + loadState.PtcStateChanged += LoadStateChanged; + _loadState = loadState; + } + + private void LoadStateChanged(PtcLoadingState newState, int current, int total) + { + LoadState state = newState switch + { + PtcLoadingState.Start => LoadState.Unloaded, + PtcLoadingState.Loading => LoadState.Loading, + PtcLoadingState.Loaded => LoadState.Loaded, + _ => throw new ArgumentException($"Invalid load state \"{newState}\".") + }; + + StateChanged?.Invoke(state, current, total); + } + + /// + public void Cancel() + { + _loadState.Continue(); + } + } +} \ No newline at end of file diff --git a/Ryujinx.Cpu/LoadState.cs b/Ryujinx.Cpu/LoadState.cs new file mode 100644 index 00000000..1f2e1ae8 --- /dev/null +++ b/Ryujinx.Cpu/LoadState.cs @@ -0,0 +1,12 @@ +namespace Ryujinx.Cpu +{ + /// + /// Load state. + /// + public enum LoadState + { + Unloaded, + Loading, + Loaded + } +} \ No newline at end of file -- cgit v1.2.3