2020-06-16 14:28:02 -04:00
|
|
|
using ARMeilleure.Translation.PTC;
|
2019-09-02 12:03:57 -04:00
|
|
|
using Gtk;
|
2022-01-22 11:56:09 -05:00
|
|
|
using Ryujinx.Common;
|
2020-08-30 12:51:53 -04:00
|
|
|
using Ryujinx.Common.Configuration;
|
2021-04-07 08:19:02 -04:00
|
|
|
using Ryujinx.Common.GraphicsDriver;
|
2018-10-17 13:15:50 -04:00
|
|
|
using Ryujinx.Common.Logging;
|
2021-01-08 03:14:13 -05:00
|
|
|
using Ryujinx.Common.System;
|
2020-05-03 22:15:27 -04:00
|
|
|
using Ryujinx.Common.SystemInfo;
|
2019-12-21 14:52:31 -05:00
|
|
|
using Ryujinx.Configuration;
|
2021-01-08 03:14:13 -05:00
|
|
|
using Ryujinx.Modules;
|
2019-11-28 23:32:51 -05:00
|
|
|
using Ryujinx.Ui;
|
2021-01-08 03:14:13 -05:00
|
|
|
using Ryujinx.Ui.Widgets;
|
2021-04-23 16:26:31 -04:00
|
|
|
using SixLabors.ImageSharp.Formats.Jpeg;
|
2018-02-04 18:08:20 -05:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2020-02-12 08:35:39 -05:00
|
|
|
using System.Reflection;
|
2021-04-14 06:28:43 -04:00
|
|
|
using System.Runtime.InteropServices;
|
2020-09-29 16:05:25 -04:00
|
|
|
using System.Threading.Tasks;
|
2018-02-04 18:08:20 -05:00
|
|
|
|
|
|
|
namespace Ryujinx
|
|
|
|
{
|
|
|
|
class Program
|
|
|
|
{
|
2021-02-19 19:34:41 -05:00
|
|
|
public static double WindowScaleFactor { get; private set; }
|
|
|
|
|
2020-02-12 08:35:39 -05:00
|
|
|
public static string Version { get; private set; }
|
|
|
|
|
2020-02-14 14:19:13 -05:00
|
|
|
public static string ConfigurationPath { get; set; }
|
2020-04-25 09:01:32 -04:00
|
|
|
|
2022-03-02 03:51:37 -05:00
|
|
|
public static string CommandLineProfile { get; set; }
|
|
|
|
|
2021-04-14 06:28:43 -04:00
|
|
|
[DllImport("libX11")]
|
|
|
|
private extern static int XInitThreads();
|
|
|
|
|
2018-02-04 18:08:20 -05:00
|
|
|
static void Main(string[] args)
|
2021-02-19 19:34:41 -05:00
|
|
|
{
|
2021-01-08 03:14:13 -05:00
|
|
|
// Parse Arguments.
|
|
|
|
string launchPathArg = null;
|
|
|
|
string baseDirPathArg = null;
|
|
|
|
bool startFullscreenArg = false;
|
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
for (int i = 0; i < args.Length; ++i)
|
|
|
|
{
|
|
|
|
string arg = args[i];
|
|
|
|
|
|
|
|
if (arg == "-r" || arg == "--root-data-dir")
|
|
|
|
{
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
{
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"Invalid option '{arg}'");
|
2021-01-08 03:14:13 -05:00
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
baseDirPathArg = args[++i];
|
2020-08-30 12:51:53 -04:00
|
|
|
}
|
2022-03-02 03:51:37 -05:00
|
|
|
else if (arg == "-p" || arg == "--profile")
|
|
|
|
{
|
|
|
|
if (i + 1 >= args.Length)
|
|
|
|
{
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"Invalid option '{arg}'");
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
CommandLineProfile = args[++i];
|
|
|
|
}
|
2020-12-01 17:02:27 -05:00
|
|
|
else if (arg == "-f" || arg == "--fullscreen")
|
|
|
|
{
|
2021-01-08 03:14:13 -05:00
|
|
|
startFullscreenArg = true;
|
2020-12-01 17:02:27 -05:00
|
|
|
}
|
2021-01-08 03:14:13 -05:00
|
|
|
else if (launchPathArg == null)
|
2020-08-30 12:51:53 -04:00
|
|
|
{
|
2021-01-08 03:14:13 -05:00
|
|
|
launchPathArg = arg;
|
2020-08-30 12:51:53 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-19 19:34:41 -05:00
|
|
|
// Make process DPI aware for proper window sizing on high-res screens.
|
|
|
|
ForceDpiAware.Windows();
|
|
|
|
WindowScaleFactor = ForceDpiAware.GetWindowScaleFactor();
|
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Delete backup files after updating.
|
2020-09-29 16:05:25 -04:00
|
|
|
Task.Run(Updater.CleanupUpdate);
|
|
|
|
|
2022-01-22 11:56:09 -05:00
|
|
|
Version = ReleaseInformations.GetVersion();
|
2020-02-12 08:35:39 -05:00
|
|
|
|
2020-02-14 05:33:22 -05:00
|
|
|
Console.Title = $"Ryujinx Console {Version}";
|
|
|
|
|
2021-04-14 06:28:43 -04:00
|
|
|
// NOTE: GTK3 doesn't init X11 in a multi threaded way.
|
|
|
|
// This ends up causing race condition and abort of XCB when a context is created by SPB (even if SPB do call XInitThreads).
|
|
|
|
if (OperatingSystem.IsLinux())
|
|
|
|
{
|
|
|
|
XInitThreads();
|
|
|
|
}
|
|
|
|
|
2019-09-02 12:03:57 -04:00
|
|
|
string systemPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine);
|
|
|
|
Environment.SetEnvironmentVariable("Path", $"{Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")};{systemPath}");
|
2019-04-26 00:53:10 -04:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Hook unhandled exception and process exit events.
|
|
|
|
GLib.ExceptionManager.UnhandledException += (GLib.UnhandledExceptionArgs e) => ProcessUnhandledException(e.ExceptionObject as Exception, e.IsTerminating);
|
2020-08-03 19:32:53 -04:00
|
|
|
AppDomain.CurrentDomain.UnhandledException += (object sender, UnhandledExceptionEventArgs e) => ProcessUnhandledException(e.ExceptionObject as Exception, e.IsTerminating);
|
2021-01-08 03:14:13 -05:00
|
|
|
AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs e) => Exit();
|
2019-12-21 14:52:31 -05:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Setup base data directory.
|
|
|
|
AppDataManager.Initialize(baseDirPathArg);
|
2020-08-30 12:51:53 -04:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Initialize the configuration.
|
2019-12-21 14:52:31 -05:00
|
|
|
ConfigurationState.Initialize();
|
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Initialize the logger system.
|
2019-12-21 14:52:31 -05:00
|
|
|
LoggerModule.Initialize();
|
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Initialize Discord integration.
|
2019-12-21 14:52:31 -05:00
|
|
|
DiscordIntegrationModule.Initialize();
|
|
|
|
|
2021-04-23 16:26:31 -04:00
|
|
|
// Sets ImageSharp Jpeg Encoder Quality.
|
|
|
|
SixLabors.ImageSharp.Configuration.Default.ImageFormatsManager.SetEncoder(JpegFormat.Instance, new JpegEncoder()
|
|
|
|
{
|
|
|
|
Quality = 100
|
|
|
|
});
|
|
|
|
|
2020-08-30 12:51:53 -04:00
|
|
|
string localConfigurationPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Config.json");
|
2021-01-08 03:14:13 -05:00
|
|
|
string appDataConfigurationPath = Path.Combine(AppDataManager.BaseDirPath, "Config.json");
|
2019-12-21 14:52:31 -05:00
|
|
|
|
2021-02-09 04:24:37 -05:00
|
|
|
// Now load the configuration as the other subsystems are now registered
|
|
|
|
ConfigurationPath = File.Exists(localConfigurationPath)
|
|
|
|
? localConfigurationPath
|
|
|
|
: File.Exists(appDataConfigurationPath)
|
|
|
|
? appDataConfigurationPath
|
|
|
|
: null;
|
|
|
|
|
|
|
|
if (ConfigurationPath == null)
|
2020-02-14 14:19:13 -05:00
|
|
|
{
|
2021-02-09 04:24:37 -05:00
|
|
|
// No configuration, we load the default values and save it to disk
|
2020-08-30 12:51:53 -04:00
|
|
|
ConfigurationPath = appDataConfigurationPath;
|
2020-02-14 14:19:13 -05:00
|
|
|
|
2021-02-09 04:24:37 -05:00
|
|
|
ConfigurationState.Instance.LoadDefault();
|
|
|
|
ConfigurationState.Instance.ToFileFormat().SaveConfig(ConfigurationPath);
|
2019-12-21 14:52:31 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-09 04:24:37 -05:00
|
|
|
if (ConfigurationFileFormat.TryLoad(ConfigurationPath, out ConfigurationFileFormat configurationFileFormat))
|
|
|
|
{
|
|
|
|
ConfigurationState.Instance.Load(configurationFileFormat, ConfigurationPath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ConfigurationState.Instance.LoadDefault();
|
|
|
|
Logger.Warning?.PrintMsg(LogClass.Application, $"Failed to load config! Loading the default config instead.\nFailed config location {ConfigurationPath}");
|
|
|
|
}
|
2019-12-21 14:52:31 -05:00
|
|
|
}
|
|
|
|
|
2021-02-09 04:24:37 -05:00
|
|
|
// Logging system information.
|
2020-08-03 19:32:53 -04:00
|
|
|
PrintSystemInfo();
|
2020-05-07 09:24:33 -04:00
|
|
|
|
2021-04-07 08:19:02 -04:00
|
|
|
// Enable OGL multithreading on the driver, when available.
|
Add a Multithreading layer for the GAL, multi-thread shader compilation at runtime (#2501)
* Initial Implementation
About as fast as nvidia GL multithreading, can be improved with faster command queuing.
* Struct based command list
Speeds up a bit. Still a lot of time lost to resource copy.
* Do shader init while the render thread is active.
* Introduce circular span pool V1
Ideally should be able to use structs instead of references for storing these spans on commands. Will try that next.
* Refactor SpanRef some more
Use a struct to represent SpanRef, rather than a reference.
* Flush buffers on background thread
* Use a span for UpdateRenderScale.
Much faster than copying the array.
* Calculate command size using reflection
* WIP parallel shaders
* Some minor optimisation
* Only 2 max refs per command now.
The command with 3 refs is gone. :relieved:
* Don't cast on the GPU side
* Remove redundant casts, force sync on window present
* Fix Shader Cache
* Fix host shader save.
* Fixup to work with new renderer stuff
* Make command Run static, use array of delegates as lookup
Profile says this takes less time than the previous way.
* Bring up to date
* Add settings toggle. Fix Muiltithreading Off mode.
* Fix warning.
* Release tracking lock for flushes
* Fix Conditional Render fast path with threaded gal
* Make handle iteration safe when releasing the lock
This is mostly temporary.
* Attempt to set backend threading on driver
Only really works on nvidia before launching a game.
* Fix race condition with BufferModifiedRangeList, exceptions in tracking actions
* Update buffer set commands
* Some cleanup
* Only use stutter workaround when using opengl renderer non-threaded
* Add host-conditional reservation of counter events
There has always been the possibility that conditional rendering could use a query object just as it is disposed by the counter queue. This change makes it so that when the host decides to use host conditional rendering, the query object is reserved so that it cannot be deleted. Counter events can optionally start reserved, as the threaded implementation can reserve them before the backend creates them, and there would otherwise be a short amount of time where the counter queue could dispose the event before a call to reserve it could be made.
* Address Feedback
* Make counter flush tracked again.
Hopefully does not cause any issues this time.
* Wait for FlushTo on the main queue thread.
Currently assumes only one thread will want to FlushTo (in this case, the GPU thread)
* Add SDL2 headless integration
* Add HLE macro commands.
Co-authored-by: Mary <mary@mary.zone>
2021-08-26 18:31:29 -04:00
|
|
|
BackendThreading threadingMode = ConfigurationState.Instance.Graphics.BackendThreading;
|
|
|
|
DriverUtilities.ToggleOGLThreading(threadingMode == BackendThreading.Off);
|
2021-04-07 08:19:02 -04:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Initialize Gtk.
|
2019-09-02 12:03:57 -04:00
|
|
|
Application.Init();
|
2019-04-26 00:53:10 -04:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Check if keys exists.
|
2021-03-15 17:10:36 -04:00
|
|
|
bool hasSystemProdKeys = File.Exists(Path.Combine(AppDataManager.KeysDirPath, "prod.keys"));
|
|
|
|
bool hasCommonProdKeys = AppDataManager.Mode == AppDataManager.LaunchMode.UserProfile && File.Exists(Path.Combine(AppDataManager.KeysDirPathUser, "prod.keys"));
|
|
|
|
if (!hasSystemProdKeys && !hasCommonProdKeys)
|
2019-11-28 23:32:51 -05:00
|
|
|
{
|
2020-09-01 05:09:42 -04:00
|
|
|
UserErrorDialog.CreateUserErrorDialog(UserError.NoKeys);
|
2019-11-28 23:32:51 -05:00
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
// Show the main window UI.
|
2019-11-28 23:32:51 -05:00
|
|
|
MainWindow mainWindow = new MainWindow();
|
2019-09-02 12:03:57 -04:00
|
|
|
mainWindow.Show();
|
2019-05-30 16:27:43 -04:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
if (launchPathArg != null)
|
2019-09-07 21:59:41 -04:00
|
|
|
{
|
2021-07-06 14:04:21 -04:00
|
|
|
mainWindow.LoadApplication(launchPathArg, startFullscreenArg);
|
2019-09-07 21:59:41 -04:00
|
|
|
}
|
|
|
|
|
2020-09-29 16:05:25 -04:00
|
|
|
if (ConfigurationState.Instance.CheckUpdatesOnStart.Value && Updater.CanUpdate(false))
|
|
|
|
{
|
2021-02-23 10:19:02 -05:00
|
|
|
Updater.BeginParse(mainWindow, false).ContinueWith(task =>
|
|
|
|
{
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"Updater Error: {task.Exception}");
|
|
|
|
}, TaskContinuationOptions.OnlyOnFaulted);
|
2020-09-29 16:05:25 -04:00
|
|
|
}
|
|
|
|
|
2019-09-02 12:03:57 -04:00
|
|
|
Application.Run();
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
2018-11-14 21:22:50 -05:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
private static void PrintSystemInfo()
|
2019-11-28 23:32:51 -05:00
|
|
|
{
|
2020-08-03 19:32:53 -04:00
|
|
|
Logger.Notice.Print(LogClass.Application, $"Ryujinx Version: {Version}");
|
2021-02-28 23:22:00 -05:00
|
|
|
SystemInfo.Gather().Print();
|
2019-11-28 23:32:51 -05:00
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
var enabledLogs = Logger.GetEnabledLevels();
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Logs Enabled: {(enabledLogs.Count == 0 ? "<None>" : string.Join(", ", enabledLogs))}");
|
2020-08-30 12:51:53 -04:00
|
|
|
|
2021-03-15 17:10:36 -04:00
|
|
|
if (AppDataManager.Mode == AppDataManager.LaunchMode.Custom)
|
2020-08-30 12:51:53 -04:00
|
|
|
{
|
2021-03-15 17:10:36 -04:00
|
|
|
Logger.Notice.Print(LogClass.Application, $"Launch Mode: Custom Path {AppDataManager.BaseDirPath}");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Launch Mode: {AppDataManager.Mode}");
|
2020-08-30 12:51:53 -04:00
|
|
|
}
|
2020-08-03 19:32:53 -04:00
|
|
|
}
|
2019-11-28 23:32:51 -05:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
private static void ProcessUnhandledException(Exception ex, bool isTerminating)
|
2020-08-03 19:32:53 -04:00
|
|
|
{
|
2020-06-16 14:28:02 -04:00
|
|
|
Ptc.Close();
|
|
|
|
PtcProfiler.Stop();
|
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
string message = $"Unhandled exception caught: {ex}";
|
2020-08-03 19:32:53 -04:00
|
|
|
|
|
|
|
Logger.Error?.PrintMsg(LogClass.Application, message);
|
2020-06-16 14:28:02 -04:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
if (Logger.Error == null)
|
|
|
|
{
|
|
|
|
Logger.Notice.PrintMsg(LogClass.Application, message);
|
|
|
|
}
|
2020-08-03 19:32:53 -04:00
|
|
|
|
|
|
|
if (isTerminating)
|
|
|
|
{
|
2021-01-08 03:14:13 -05:00
|
|
|
Exit();
|
2019-11-28 23:32:51 -05:00
|
|
|
}
|
|
|
|
}
|
2020-08-03 19:32:53 -04:00
|
|
|
|
2021-01-08 03:14:13 -05:00
|
|
|
public static void Exit()
|
2020-08-03 19:32:53 -04:00
|
|
|
{
|
2021-01-08 03:14:13 -05:00
|
|
|
DiscordIntegrationModule.Exit();
|
|
|
|
|
2020-08-03 19:32:53 -04:00
|
|
|
Ptc.Dispose();
|
|
|
|
PtcProfiler.Dispose();
|
|
|
|
|
|
|
|
Logger.Shutdown();
|
|
|
|
}
|
2018-02-04 18:08:20 -05:00
|
|
|
}
|
2020-09-29 16:05:25 -04:00
|
|
|
}
|