aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.Cpu
diff options
context:
space:
mode:
Diffstat (limited to 'Ryujinx.Cpu')
-rw-r--r--Ryujinx.Cpu/ICpuContext.cs22
-rw-r--r--Ryujinx.Cpu/IDiskCacheState.cs20
-rw-r--r--Ryujinx.Cpu/Jit/JitCpuContext.cs12
-rw-r--r--Ryujinx.Cpu/Jit/JitDiskCacheLoadState.cs38
-rw-r--r--Ryujinx.Cpu/LoadState.cs12
5 files changed, 104 insertions, 0 deletions
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
/// <param name="address">Address of the region to be invalidated</param>
/// <param name="size">Size of the region to be invalidated</param>
void InvalidateCacheRegion(ulong address, ulong size);
+
+ /// <summary>
+ /// Loads cached code from disk for a given application.
+ /// </summary>
+ /// <remarks>
+ /// If the execution engine is recompiling guest code, this can be used to load cached code from disk.
+ /// </remarks>
+ /// <param name="titleIdText">Title ID of the application in padded hex form</param>
+ /// <param name="displayVersion">Version of the application</param>
+ /// <param name="enabled">True if the cache should be loaded from disk if it exists, false otherwise</param>
+ /// <returns>Disk cache load progress reporter and manager</returns>
+ IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled);
+
+ /// <summary>
+ /// Indicates that code has been loaded into guest memory, and that it might be executed in the future.
+ /// </summary>
+ /// <remarks>
+ /// Some execution engines might use this information to cache recompiled code on disk or to ensure it can be executed.
+ /// </remarks>
+ /// <param name="address">CPU virtual address where the code starts</param>
+ /// <param name="size">Size of the code range in bytes</param>
+ 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
+{
+ /// <summary>
+ /// Disk cache load state report and management interface.
+ /// </summary>
+ public interface IDiskCacheLoadState
+ {
+ /// <summary>
+ /// Event used to report the cache load progress.
+ /// </summary>
+ event Action<LoadState, int, int> StateChanged;
+
+ /// <summary>
+ /// Cancels the disk cache load process.
+ /// </summary>
+ 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);
}
+
+ /// <inheritdoc/>
+ public IDiskCacheLoadState LoadDiskCache(string titleIdText, string displayVersion, bool enabled)
+ {
+ return new JitDiskCacheLoadState(_translator.LoadDiskCache(titleIdText, displayVersion, enabled));
+ }
+
+ /// <inheritdoc/>
+ 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
+ {
+ /// <inheritdoc/>
+ public event Action<LoadState, int, int> 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);
+ }
+
+ /// <inheritdoc/>
+ 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
+{
+ /// <summary>
+ /// Load state.
+ /// </summary>
+ public enum LoadState
+ {
+ Unloaded,
+ Loading,
+ Loaded
+ }
+} \ No newline at end of file