Change shader cache init wait method (#6131)

* Change shader cache init wait method

* Make field readonly
This commit is contained in:
gdkchan 2024-01-18 14:17:38 -03:00 committed by GitHub
parent 2dbbc9bc05
commit 870d9599cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 20 additions and 23 deletions

View File

@ -57,9 +57,6 @@ namespace ARMeilleure.Translation
private Thread[] _backgroundTranslationThreads;
private volatile int _threadCount;
// FIXME: Remove this once the init logic of the emulator will be redone.
public static readonly ManualResetEvent IsReadyForTranslation = new(false);
public Translator(IJitMemoryAllocator allocator, IMemoryManager memory, bool for64Bits)
{
_allocator = allocator;
@ -100,8 +97,6 @@ namespace ARMeilleure.Translation
{
if (Interlocked.Increment(ref _threadCount) == 1)
{
IsReadyForTranslation.WaitOne();
if (_ptc.State == PtcState.Enabled)
{
Debug.Assert(Functions.Count == 0);

View File

@ -1,4 +1,3 @@
using ARMeilleure.Translation;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
@ -916,7 +915,6 @@ namespace Ryujinx.Ava
{
Device.Gpu.SetGpuThread();
Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
Translator.IsReadyForTranslation.Set();
_renderer.Window.ChangeVSyncMode(Device.EnableDeviceVsync);

View File

@ -106,6 +106,8 @@ namespace Ryujinx.Graphics.Gpu
private long _modifiedSequence;
private readonly ulong _firstTimestamp;
private readonly ManualResetEvent _gpuReadyEvent;
/// <summary>
/// Creates a new instance of the GPU emulation context.
/// </summary>
@ -121,6 +123,7 @@ namespace Ryujinx.Graphics.Gpu
Window = new Window(this);
HostInitalized = new ManualResetEvent(false);
_gpuReadyEvent = new ManualResetEvent(false);
SyncActions = new List<ISyncActionHandler>();
SyncpointActions = new List<ISyncActionHandler>();
@ -216,7 +219,7 @@ namespace Ryujinx.Graphics.Gpu
/// Gets a sequence number for resource modification ordering. This increments on each call.
/// </summary>
/// <returns>A sequence number for resource modification ordering</returns>
public long GetModifiedSequence()
internal long GetModifiedSequence()
{
return _modifiedSequence++;
}
@ -225,7 +228,7 @@ namespace Ryujinx.Graphics.Gpu
/// Gets the value of the GPU timer.
/// </summary>
/// <returns>The current GPU timestamp</returns>
public ulong GetTimestamp()
internal ulong GetTimestamp()
{
// Guest timestamp will start at 0, instead of host value.
ulong ticks = ConvertNanosecondsToTicks((ulong)PerformanceCounter.ElapsedNanoseconds) - _firstTimestamp;
@ -262,6 +265,16 @@ namespace Ryujinx.Graphics.Gpu
{
physicalMemory.ShaderCache.Initialize(cancellationToken);
}
_gpuReadyEvent.Set();
}
/// <summary>
/// Waits until the GPU is ready to receive commands.
/// </summary>
public void WaitUntilGpuReady()
{
_gpuReadyEvent.WaitOne();
}
/// <summary>
@ -399,6 +412,7 @@ namespace Ryujinx.Graphics.Gpu
{
GPFifo.Dispose();
HostInitalized.Dispose();
_gpuReadyEvent.Dispose();
// Has to be disposed before processing deferred actions, as it will produce some.
foreach (var physicalMemory in PhysicalMemoryRegistry.Values)

View File

@ -161,7 +161,8 @@ namespace Ryujinx.Graphics.Gpu.Shader
_graphicsShaderCache,
_computeShaderCache,
_diskCacheHostStorage,
ShaderCacheStateUpdate, cancellationToken);
ShaderCacheStateUpdate,
cancellationToken);
loader.LoadShaders();

View File

@ -57,6 +57,8 @@ namespace Ryujinx.HLE.HOS
public void Execute(IExecutionContext context, ulong codeAddress)
{
// We must wait until shader cache is loaded, among other things, before executing CPU code.
_gpuContext.WaitUntilGpuReady();
_cpuContext.Execute(context, codeAddress);
}

View File

@ -1,4 +1,3 @@
using ARMeilleure.Translation;
using CommandLine;
using LibHac.Tools.FsSystem;
using Ryujinx.Audio.Backends.SDL2;
@ -710,9 +709,6 @@ namespace Ryujinx.Headless.SDL2
}
SetupProgressHandler();
Translator.IsReadyForTranslation.Reset();
ExecutionEntrypoint();
return true;

View File

@ -1,4 +1,3 @@
using ARMeilleure.Translation;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Configuration.Hid;
using Ryujinx.Common.Logging;
@ -276,7 +275,6 @@ namespace Ryujinx.Headless.SDL2
{
Device.Gpu.SetGpuThread();
Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
Translator.IsReadyForTranslation.Set();
while (_isActive)
{

View File

@ -61,7 +61,6 @@ namespace Ryujinx.Tests.Cpu
_memory.Map(DataBaseAddress, Size, Size, MemoryMapFlags.Private);
_context = CpuContext.CreateExecutionContext();
Translator.IsReadyForTranslation.Set();
_cpuContext = new CpuContext(_memory, for64Bit: true);

View File

@ -56,7 +56,6 @@ namespace Ryujinx.Tests.Cpu
_context = CpuContext.CreateExecutionContext();
_context.IsAarch32 = true;
Translator.IsReadyForTranslation.Set();
_cpuContext = new CpuContext(_memory, for64Bit: false);

View File

@ -1,4 +1,3 @@
using ARMeilleure.Translation;
using Gtk;
using LibHac.Common;
using LibHac.Common.Keys;
@ -931,8 +930,6 @@ namespace Ryujinx.Ui
_deviceExitStatus.Reset();
Translator.IsReadyForTranslation.Reset();
Thread windowThread = new(CreateGameWindow)
{
Name = "GUI.WindowThread",

View File

@ -1,4 +1,3 @@
using ARMeilleure.Translation;
using Gdk;
using Gtk;
using Ryujinx.Common;
@ -450,7 +449,6 @@ namespace Ryujinx.Ui
{
Device.Gpu.SetGpuThread();
Device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
Translator.IsReadyForTranslation.Set();
Renderer.Window.ChangeVSyncMode(Device.EnableDeviceVsync);