add closing emulation(starting a new one is still broken), disabled audio

This commit is contained in:
Emmanuel Hansen 2023-07-29 09:40:50 +00:00
parent a050e5c6c0
commit 2999275ed2
13 changed files with 194 additions and 33 deletions

View file

@ -72,7 +72,9 @@ namespace LibRyujinx
var init = Initialize(path, enableDebugLogs);
AudioDriver = new OboeHardwareDeviceDriver();
// AudioDriver = new OboeHardwareDeviceDriver();
_surfaceEvent?.Set();
_surfaceEvent = new ManualResetEvent(false);
@ -151,6 +153,18 @@ namespace LibRyujinx
return LoadApplication(path);
}
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceSignalEmulationClose")]
public static void JniSignalEmulationCloseNative(JEnvRef jEnv, JObjectLocalRef jObj)
{
SignalEmulationClose();
}
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceCloseEmulation")]
public static void JniCloseEmulationNative(JEnvRef jEnv, JObjectLocalRef jObj)
{
CloseEmulation();
}
[UnmanagedCallersOnly(EntryPoint = "Java_org_ryujinx_android_RyujinxNative_deviceLoadDescriptor")]
public static JBoolean JniLoadApplicationNative(JEnvRef jEnv, JObjectLocalRef jObj, JInt descriptor, JBoolean isXci)
{

View file

@ -1,6 +1,8 @@
using ARMeilleure.Translation;
using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.SystemState;
using Ryujinx.Input.HLE;
using Silk.NET.Vulkan;
using System;
using System.IO;
using System.Runtime.InteropServices;
@ -168,5 +170,41 @@ namespace LibRyujinx
return true;
}
public static void SignalEmulationClose()
{
_isStopped = true;
_isActive = false;
debug_break(2);
}
public static void CloseEmulation()
{
if (SwitchDevice == null)
return;
_npadManager?.Dispose();
_npadManager = null;
_touchScreenManager?.Dispose();
_touchScreenManager = null;
SwitchDevice?.InputManager?.Dispose();
SwitchDevice.InputManager = null;
_inputManager = null;
_surfaceEvent?.Set();
if (Renderer != null)
{
_gpuDoneEvent.WaitOne();
_gpuDoneEvent.Dispose();
_gpuDoneEvent = null;
SwitchDevice?.DisposeContext();
Renderer = null;
}
}
}
}

View file

@ -3,6 +3,7 @@ using LibRyujinx.Shared;
using OpenTK.Graphics.OpenGL;
using Ryujinx.Common.Configuration;
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.GAL.Multithreading;
using Ryujinx.Graphics.Gpu;
using Ryujinx.Graphics.OpenGL;
using Ryujinx.Graphics.Vulkan;
@ -21,6 +22,7 @@ namespace LibRyujinx
private static CancellationTokenSource _gpuCancellationTokenSource;
private static SwapBuffersCallback? _swapBuffersCallback;
private static NativeGraphicsInterop _nativeGraphicsInterop;
private static ManualResetEvent _gpuDoneEvent;
public delegate void SwapBuffersCallback();
public delegate IntPtr GetProcAddress(string name);
@ -146,12 +148,14 @@ namespace LibRyujinx
return;
}
var device = SwitchDevice!.EmulationContext!;
_gpuDoneEvent = new ManualResetEvent(true);
device.Gpu.Renderer.Initialize(GraphicsDebugLevel.None);
_gpuCancellationTokenSource = new CancellationTokenSource();
device.Gpu.Renderer.RunLoop(() =>
{
_gpuDoneEvent.Reset();
device.Gpu.SetGpuThread();
device.Gpu.InitializeShaderCache(_gpuCancellationTokenSource.Token);
Translator.IsReadyForTranslation.Set();
@ -162,9 +166,11 @@ namespace LibRyujinx
{
if (_isStopped)
{
return;
break;
}
debug_break(1);
if (Ryujinx.Common.SystemInfo.SystemInfo.IsBionic)
{
setRenderingThread();
@ -182,6 +188,13 @@ namespace LibRyujinx
device.PresentFrame(() => _swapBuffersCallback?.Invoke());
}
}
if (device.Gpu.Renderer is ThreadedRenderer threaded)
{
threaded.FlushThreadedCommands();
}
_gpuDoneEvent.Set();
});
}

View file

@ -30,7 +30,7 @@ namespace LibRyujinx
private static VirtualTouchScreenDriver? _touchScreenDriver;
private static TouchScreenManager? _touchScreenManager;
private static InputManager? _inputManager;
private static NpadManager _npadManager;
private static NpadManager? _npadManager;
private static InputConfig[] _configs;
public static void InitializeInput(int width, int height)

View file

@ -641,7 +641,9 @@ namespace LibRyujinx
internal void DisposeContext()
{
EmulationContext?.Dispose();
EmulationContext?.DisposeGpu();
EmulationContext = null;
LibRyujinx.Renderer = null;
}
}