mirror of
https://git.ryujinx.app/projects/Kenji-NX.git
synced 2026-09-30 17:07:57 +02:00
This PR threads process/program identity into PTC disk cache initialization so cache ownership is selected from the launched process rather than global/shared application state. Previously, the PTC initialization path only propagated loose title/version information into the CPU layer. That was mostly fine for a single launched application, but will introduce many problems once multiple programs can be launched during the same session, given later processes could inherit cache identity from the first loaded application. To address this issue, this PR introduces a `PtcCacheInfo` payload and applies it through the process context, CPU context, translator, and PTC initialization paths. Cache ownership is now resolved once the kernel process PID is known and includes: - PID - Program ID / Title ID - Application ID - Program index - Display version - Process kind - Cache selector `PtcCacheInfo` now owns its default title/application/version values, and `Ptc` uses that cache info directly instead of mirroring title/version fields internally. The persistent cache key itself does remains title/version/selector based rather than PID based, so caches remain reusable across launches while still being selected from the correct process context. PID is only used for diagnostics and ownership tracing in logs. Additional PTC logging has also been added to report cache ownership and selected paths during PTC initialization, Profiling info load/save and translation cache load/save Both the PTC and profiler internal versions were bumped (a bunch of times lol).
72 lines
2.3 KiB
C#
72 lines
2.3 KiB
C#
using ARMeilleure.Common;
|
|
using ARMeilleure.Memory;
|
|
using ARMeilleure.Translation;
|
|
using ARMeilleure.Translation.PTC;
|
|
using Ryujinx.Cpu.Signal;
|
|
|
|
namespace Ryujinx.Cpu.Jit
|
|
{
|
|
class JitCpuContext : ICpuContext
|
|
{
|
|
private readonly ITickSource _tickSource;
|
|
private readonly Translator _translator;
|
|
|
|
public JitCpuContext(ITickSource tickSource, IMemoryManager memory, bool for64Bit)
|
|
{
|
|
_tickSource = tickSource;
|
|
|
|
bool sparse = memory.Type is not MemoryManagerType.SoftwareMmu and not MemoryManagerType.SoftwarePageTable;
|
|
IAddressTable<ulong> functionTable = sparse ? SparseAddressTable<ulong>.CreateForArm(for64Bit) : AddressTable<ulong>.CreateForArm(for64Bit);
|
|
|
|
_translator = new Translator(new JitMemoryAllocator(forJit: true), memory, functionTable);
|
|
|
|
if (memory.Type.IsHostMappedOrTracked())
|
|
{
|
|
NativeSignalHandler.InitializeSignalHandler();
|
|
}
|
|
|
|
memory.UnmapEvent += UnmapHandler;
|
|
}
|
|
|
|
private void UnmapHandler(ulong address, ulong size)
|
|
{
|
|
_translator.InvalidateJitCacheRegion(address, size);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IExecutionContext CreateExecutionContext(ExceptionCallbacks exceptionCallbacks)
|
|
{
|
|
return new JitExecutionContext(new JitMemoryAllocator(), _tickSource, exceptionCallbacks);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void Execute(IExecutionContext context, ulong address)
|
|
{
|
|
_translator.Execute(((JitExecutionContext)context).Impl, address);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void InvalidateCacheRegion(ulong address, ulong size)
|
|
{
|
|
_translator.InvalidateJitCacheRegion(address, size);
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public IDiskCacheLoadState LoadDiskCache(PtcCacheInfo cacheInfo, bool enabled)
|
|
{
|
|
return new JitDiskCacheLoadState(_translator.LoadDiskCache(cacheInfo, enabled));
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
public void PrepareCodeRange(ulong address, ulong size)
|
|
{
|
|
_translator.FunctionTable.SignalCodeRange(address, size);
|
|
_translator.PrepareCodeRange(address, size);
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
}
|
|
}
|
|
}
|