2021-05-04 12:19:04 -04:00
|
|
|
|
using ARMeilleure.Translation;
|
|
|
|
|
using ARMeilleure.Translation.PTC;
|
|
|
|
|
using Gdk;
|
|
|
|
|
using Gtk;
|
|
|
|
|
using Ryujinx.Common;
|
|
|
|
|
using Ryujinx.Common.Configuration;
|
2021-06-28 16:09:43 -04:00
|
|
|
|
using Ryujinx.Common.Logging;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
using Ryujinx.Configuration;
|
|
|
|
|
using Ryujinx.Graphics.GAL;
|
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
|
|
|
|
using Ryujinx.Graphics.GAL.Multithreading;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
using Ryujinx.Input;
|
2021-06-14 02:42:55 -04:00
|
|
|
|
using Ryujinx.Input.GTK3;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
using Ryujinx.Input.HLE;
|
|
|
|
|
using Ryujinx.Ui.Widgets;
|
2021-06-28 16:09:43 -04:00
|
|
|
|
using SixLabors.ImageSharp;
|
|
|
|
|
using SixLabors.ImageSharp.Formats.Png;
|
|
|
|
|
using SixLabors.ImageSharp.PixelFormats;
|
|
|
|
|
using SixLabors.ImageSharp.Processing;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2021-06-28 16:09:43 -04:00
|
|
|
|
using System.IO;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
using System.Threading;
|
2021-06-28 16:09:43 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
|
|
|
|
namespace Ryujinx.Ui
|
|
|
|
|
{
|
2021-06-28 16:09:43 -04:00
|
|
|
|
using Image = SixLabors.ImageSharp.Image;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
using Key = Input.Key;
|
|
|
|
|
using Switch = HLE.Switch;
|
|
|
|
|
|
|
|
|
|
public abstract class RendererWidgetBase : DrawingArea
|
|
|
|
|
{
|
|
|
|
|
private const int SwitchPanelWidth = 1280;
|
|
|
|
|
private const int SwitchPanelHeight = 720;
|
|
|
|
|
private const int TargetFps = 60;
|
|
|
|
|
|
|
|
|
|
public ManualResetEvent WaitEvent { get; set; }
|
|
|
|
|
public NpadManager NpadManager { get; }
|
2021-06-14 02:42:55 -04:00
|
|
|
|
public TouchScreenManager TouchScreenManager { get; }
|
2021-05-04 12:19:04 -04:00
|
|
|
|
public Switch Device { get; private set; }
|
|
|
|
|
public IRenderer Renderer { get; private set; }
|
|
|
|
|
|
2021-06-28 16:09:43 -04:00
|
|
|
|
public bool ScreenshotRequested { get; set; }
|
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
public static event EventHandler<StatusUpdatedEventArgs> StatusUpdatedEvent;
|
|
|
|
|
|
|
|
|
|
private bool _isActive;
|
|
|
|
|
private bool _isStopped;
|
|
|
|
|
|
|
|
|
|
private bool _toggleFullscreen;
|
|
|
|
|
private bool _toggleDockedMode;
|
|
|
|
|
|
|
|
|
|
private readonly long _ticksPerFrame;
|
|
|
|
|
|
|
|
|
|
private long _ticks = 0;
|
|
|
|
|
|
|
|
|
|
private readonly Stopwatch _chrono;
|
|
|
|
|
|
|
|
|
|
private KeyboardHotkeyState _prevHotkeyState;
|
|
|
|
|
|
|
|
|
|
private readonly ManualResetEvent _exitEvent;
|
|
|
|
|
|
|
|
|
|
// Hide Cursor
|
|
|
|
|
const int CursorHideIdleTime = 8; // seconds
|
|
|
|
|
private static readonly Cursor _invisibleCursor = new Cursor(Display.Default, CursorType.BlankCursor);
|
|
|
|
|
private long _lastCursorMoveTime;
|
|
|
|
|
private bool _hideCursorOnIdle;
|
|
|
|
|
private InputManager _inputManager;
|
|
|
|
|
private IKeyboard _keyboardInterface;
|
|
|
|
|
private GraphicsDebugLevel _glLogLevel;
|
|
|
|
|
private string _gpuVendorName;
|
|
|
|
|
|
2021-05-07 12:37:48 -04:00
|
|
|
|
private int _windowHeight;
|
|
|
|
|
private int _windowWidth;
|
2021-06-23 20:09:08 -04:00
|
|
|
|
private bool _isMouseInClient;
|
2021-05-07 12:37:48 -04:00
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
public RendererWidgetBase(InputManager inputManager, GraphicsDebugLevel glLogLevel)
|
|
|
|
|
{
|
2021-06-14 02:42:55 -04:00
|
|
|
|
var mouseDriver = new GTK3MouseDriver(this);
|
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
_inputManager = inputManager;
|
2021-06-14 02:42:55 -04:00
|
|
|
|
_inputManager.SetMouseDriver(mouseDriver);
|
2021-05-04 12:19:04 -04:00
|
|
|
|
NpadManager = _inputManager.CreateNpadManager();
|
2021-06-14 02:42:55 -04:00
|
|
|
|
TouchScreenManager = _inputManager.CreateTouchScreenManager();
|
2021-05-04 12:19:04 -04:00
|
|
|
|
_keyboardInterface = (IKeyboard)_inputManager.KeyboardDriver.GetGamepad("0");
|
|
|
|
|
|
|
|
|
|
WaitEvent = new ManualResetEvent(false);
|
|
|
|
|
|
|
|
|
|
_glLogLevel = glLogLevel;
|
|
|
|
|
|
|
|
|
|
Destroyed += Renderer_Destroyed;
|
|
|
|
|
|
|
|
|
|
_chrono = new Stopwatch();
|
|
|
|
|
|
|
|
|
|
_ticksPerFrame = Stopwatch.Frequency / TargetFps;
|
|
|
|
|
|
|
|
|
|
AddEvents((int)(EventMask.ButtonPressMask
|
|
|
|
|
| EventMask.ButtonReleaseMask
|
|
|
|
|
| EventMask.PointerMotionMask
|
2021-06-23 20:09:08 -04:00
|
|
|
|
| EventMask.ScrollMask
|
|
|
|
|
| EventMask.EnterNotifyMask
|
|
|
|
|
| EventMask.LeaveNotifyMask
|
2021-05-04 12:19:04 -04:00
|
|
|
|
| EventMask.KeyPressMask
|
|
|
|
|
| EventMask.KeyReleaseMask));
|
|
|
|
|
|
|
|
|
|
_exitEvent = new ManualResetEvent(false);
|
|
|
|
|
|
|
|
|
|
_hideCursorOnIdle = ConfigurationState.Instance.HideCursorOnIdle;
|
|
|
|
|
_lastCursorMoveTime = Stopwatch.GetTimestamp();
|
|
|
|
|
|
|
|
|
|
ConfigurationState.Instance.HideCursorOnIdle.Event += HideCursorStateChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract void InitializeRenderer();
|
|
|
|
|
|
|
|
|
|
public abstract void SwapBuffers();
|
|
|
|
|
|
|
|
|
|
public abstract string GetGpuVendorName();
|
|
|
|
|
|
|
|
|
|
private void HideCursorStateChanged(object sender, ReactiveEventArgs<bool> state)
|
|
|
|
|
{
|
|
|
|
|
Gtk.Application.Invoke(delegate
|
|
|
|
|
{
|
|
|
|
|
_hideCursorOnIdle = state.NewValue;
|
|
|
|
|
|
|
|
|
|
if (_hideCursorOnIdle)
|
|
|
|
|
{
|
|
|
|
|
_lastCursorMoveTime = Stopwatch.GetTimestamp();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Window.Cursor = null;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Renderer_Destroyed(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ConfigurationState.Instance.HideCursorOnIdle.Event -= HideCursorStateChanged;
|
|
|
|
|
|
|
|
|
|
NpadManager.Dispose();
|
|
|
|
|
Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnMotionNotifyEvent(EventMotion evnt)
|
|
|
|
|
{
|
|
|
|
|
if (_hideCursorOnIdle)
|
|
|
|
|
{
|
|
|
|
|
_lastCursorMoveTime = Stopwatch.GetTimestamp();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 14:28:33 -04:00
|
|
|
|
if (ConfigurationState.Instance.Hid.EnableMouse)
|
2021-06-23 20:09:08 -04:00
|
|
|
|
{
|
|
|
|
|
Window.Cursor = _invisibleCursor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_isMouseInClient = true;
|
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 20:09:08 -04:00
|
|
|
|
protected override bool OnEnterNotifyEvent(EventCrossing evnt)
|
|
|
|
|
{
|
|
|
|
|
Window.Cursor = ConfigurationState.Instance.Hid.EnableMouse ? _invisibleCursor : null;
|
|
|
|
|
|
|
|
|
|
_isMouseInClient = true;
|
|
|
|
|
|
|
|
|
|
return base.OnEnterNotifyEvent(evnt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnLeaveNotifyEvent(EventCrossing evnt)
|
|
|
|
|
{
|
|
|
|
|
Window.Cursor = null;
|
|
|
|
|
|
|
|
|
|
_isMouseInClient = false;
|
|
|
|
|
|
|
|
|
|
return base.OnLeaveNotifyEvent(evnt);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
protected override void OnGetPreferredHeight(out int minimumHeight, out int naturalHeight)
|
|
|
|
|
{
|
|
|
|
|
Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
|
|
|
|
|
|
|
|
|
|
// If the monitor is at least 1080p, use the Switch panel size as minimal size.
|
|
|
|
|
if (monitor.Geometry.Height >= 1080)
|
|
|
|
|
{
|
|
|
|
|
minimumHeight = SwitchPanelHeight;
|
|
|
|
|
}
|
|
|
|
|
// Otherwise, we default minimal size to 480p 16:9.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
minimumHeight = 480;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
naturalHeight = minimumHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnGetPreferredWidth(out int minimumWidth, out int naturalWidth)
|
|
|
|
|
{
|
|
|
|
|
Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
|
|
|
|
|
|
|
|
|
|
// If the monitor is at least 1080p, use the Switch panel size as minimal size.
|
|
|
|
|
if (monitor.Geometry.Height >= 1080)
|
|
|
|
|
{
|
|
|
|
|
minimumWidth = SwitchPanelWidth;
|
|
|
|
|
}
|
|
|
|
|
// Otherwise, we default minimal size to 480p 16:9.
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
minimumWidth = 854;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
naturalWidth = minimumWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnConfigureEvent(EventConfigure evnt)
|
|
|
|
|
{
|
|
|
|
|
bool result = base.OnConfigureEvent(evnt);
|
|
|
|
|
|
|
|
|
|
Gdk.Monitor monitor = Display.GetMonitorAtWindow(Window);
|
|
|
|
|
|
2021-05-07 12:37:48 -04:00
|
|
|
|
_windowWidth = evnt.Width * monitor.ScaleFactor;
|
|
|
|
|
_windowHeight = evnt.Height * monitor.ScaleFactor;
|
|
|
|
|
|
|
|
|
|
Renderer?.Window.SetSize(_windowWidth, _windowHeight);
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleScreenState(KeyboardStateSnapshot keyboard)
|
|
|
|
|
{
|
|
|
|
|
bool toggleFullscreen = keyboard.IsPressed(Key.F11)
|
|
|
|
|
|| ((keyboard.IsPressed(Key.AltLeft)
|
|
|
|
|
|| keyboard.IsPressed(Key.AltRight))
|
|
|
|
|
&& keyboard.IsPressed(Key.Enter))
|
|
|
|
|
|| keyboard.IsPressed(Key.Escape);
|
|
|
|
|
|
|
|
|
|
bool fullScreenToggled = ParentWindow.State.HasFlag(Gdk.WindowState.Fullscreen);
|
|
|
|
|
|
|
|
|
|
if (toggleFullscreen != _toggleFullscreen)
|
|
|
|
|
{
|
|
|
|
|
if (toggleFullscreen)
|
|
|
|
|
{
|
|
|
|
|
if (fullScreenToggled)
|
|
|
|
|
{
|
|
|
|
|
ParentWindow.Unfullscreen();
|
|
|
|
|
(Toplevel as MainWindow)?.ToggleExtraWidgets(true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (keyboard.IsPressed(Key.Escape))
|
|
|
|
|
{
|
|
|
|
|
if (!ConfigurationState.Instance.ShowConfirmExit || GtkDialog.CreateExitDialog())
|
|
|
|
|
{
|
|
|
|
|
Exit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ParentWindow.Fullscreen();
|
|
|
|
|
(Toplevel as MainWindow)?.ToggleExtraWidgets(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_toggleFullscreen = toggleFullscreen;
|
|
|
|
|
|
|
|
|
|
bool toggleDockedMode = keyboard.IsPressed(Key.F9);
|
|
|
|
|
|
|
|
|
|
if (toggleDockedMode != _toggleDockedMode)
|
|
|
|
|
{
|
|
|
|
|
if (toggleDockedMode)
|
|
|
|
|
{
|
|
|
|
|
ConfigurationState.Instance.System.EnableDockedMode.Value =
|
|
|
|
|
!ConfigurationState.Instance.System.EnableDockedMode.Value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_toggleDockedMode = toggleDockedMode;
|
|
|
|
|
|
2021-06-23 20:09:08 -04:00
|
|
|
|
if (_hideCursorOnIdle && !ConfigurationState.Instance.Hid.EnableMouse)
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
|
|
|
|
long cursorMoveDelta = Stopwatch.GetTimestamp() - _lastCursorMoveTime;
|
|
|
|
|
Window.Cursor = (cursorMoveDelta >= CursorHideIdleTime * Stopwatch.Frequency) ? _invisibleCursor : null;
|
|
|
|
|
}
|
2021-06-23 20:09:08 -04:00
|
|
|
|
|
|
|
|
|
if(ConfigurationState.Instance.Hid.EnableMouse && _isMouseInClient)
|
|
|
|
|
{
|
|
|
|
|
Window.Cursor = _invisibleCursor;
|
|
|
|
|
}
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Initialize(Switch device)
|
|
|
|
|
{
|
|
|
|
|
Device = device;
|
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
|
|
|
|
|
|
|
|
|
IRenderer renderer = Device.Gpu.Renderer;
|
|
|
|
|
|
|
|
|
|
if (renderer is ThreadedRenderer tr)
|
|
|
|
|
{
|
|
|
|
|
renderer = tr.BaseRenderer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Renderer = renderer;
|
2021-05-07 12:37:48 -04:00
|
|
|
|
Renderer?.Window.SetSize(_windowWidth, _windowHeight);
|
2021-05-16 11:12:14 -04:00
|
|
|
|
|
2021-06-28 16:09:43 -04:00
|
|
|
|
if (Renderer != null)
|
|
|
|
|
{
|
|
|
|
|
Renderer.ScreenCaptured += Renderer_ScreenCaptured;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 20:09:08 -04:00
|
|
|
|
NpadManager.Initialize(device, ConfigurationState.Instance.Hid.InputConfig, ConfigurationState.Instance.Hid.EnableKeyboard, ConfigurationState.Instance.Hid.EnableMouse);
|
2021-06-14 02:42:55 -04:00
|
|
|
|
TouchScreenManager.Initialize(device);
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 16:09:43 -04:00
|
|
|
|
private unsafe void Renderer_ScreenCaptured(object sender, ScreenCaptureImageInfo e)
|
|
|
|
|
{
|
2021-07-06 15:07:23 -04:00
|
|
|
|
if (e.Data.Length > 0 && e.Height > 0 && e.Width > 0)
|
2021-06-28 16:09:43 -04:00
|
|
|
|
{
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
lock (this)
|
|
|
|
|
{
|
|
|
|
|
var currentTime = DateTime.Now;
|
|
|
|
|
string filename = $"ryujinx_capture_{currentTime.Year}-{currentTime.Month:D2}-{currentTime.Day:D2}_{currentTime.Hour:D2}-{currentTime.Minute:D2}-{currentTime.Second:D2}.png";
|
2021-07-06 15:07:23 -04:00
|
|
|
|
string directory = AppDataManager.Mode switch
|
|
|
|
|
{
|
|
|
|
|
AppDataManager.LaunchMode.Portable => System.IO.Path.Combine(AppDataManager.BaseDirPath, "screenshots"),
|
|
|
|
|
_ => System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures), "Ryujinx")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
string path = System.IO.Path.Combine(directory, filename);
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(directory);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"Failed to create directory at path {directory}. Error : {ex.GetType().Name}", "Screenshot");
|
2021-06-28 16:09:43 -04:00
|
|
|
|
|
2021-07-06 15:07:23 -04:00
|
|
|
|
return;
|
|
|
|
|
}
|
2021-06-28 16:09:43 -04:00
|
|
|
|
|
|
|
|
|
Image image = e.IsBgra ? Image.LoadPixelData<Bgra32>(e.Data, e.Width, e.Height)
|
|
|
|
|
: Image.LoadPixelData<Rgba32>(e.Data, e.Width, e.Height);
|
|
|
|
|
|
|
|
|
|
if (e.FlipX)
|
|
|
|
|
{
|
|
|
|
|
image.Mutate(x => x.Flip(FlipMode.Horizontal));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.FlipY)
|
|
|
|
|
{
|
|
|
|
|
image.Mutate(x => x.Flip(FlipMode.Vertical));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
image.SaveAsPng(path, new PngEncoder()
|
|
|
|
|
{
|
|
|
|
|
ColorType = PngColorType.Rgb
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
image.Dispose();
|
|
|
|
|
|
|
|
|
|
Logger.Notice.Print(LogClass.Application, $"Screenshot saved to {path}", "Screenshot");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
2021-07-06 15:07:23 -04:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Logger.Error?.Print(LogClass.Application, $"Screenshot is empty. Size : {e.Data.Length} bytes. Resolution : {e.Width}x{e.Height}", "Screenshot");
|
|
|
|
|
}
|
2021-06-28 16:09:43 -04:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
public void Render()
|
|
|
|
|
{
|
|
|
|
|
Gtk.Window parent = Toplevel as Gtk.Window;
|
|
|
|
|
parent.Present();
|
|
|
|
|
|
|
|
|
|
InitializeRenderer();
|
|
|
|
|
|
|
|
|
|
Device.Gpu.Renderer.Initialize(_glLogLevel);
|
|
|
|
|
|
|
|
|
|
_gpuVendorName = GetGpuVendorName();
|
|
|
|
|
|
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
|
|
|
|
Device.Gpu.Renderer.RunLoop(() =>
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
2022-01-09 11:28:48 -05:00
|
|
|
|
Device.Gpu.SetGpuThread();
|
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
|
|
|
|
Device.Gpu.InitializeShaderCache();
|
|
|
|
|
Translator.IsReadyForTranslation.Set();
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
2021-09-11 16:08:25 -04:00
|
|
|
|
(Toplevel as MainWindow)?.ActivatePauseMenu();
|
|
|
|
|
|
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
|
|
|
|
while (_isActive)
|
|
|
|
|
{
|
|
|
|
|
if (_isStopped)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
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
|
|
|
|
_ticks += _chrono.ElapsedTicks;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
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
|
|
|
|
_chrono.Restart();
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
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
|
|
|
|
if (Device.WaitFifo())
|
|
|
|
|
{
|
|
|
|
|
Device.Statistics.RecordFifoStart();
|
|
|
|
|
Device.ProcessFrame();
|
|
|
|
|
Device.Statistics.RecordFifoEnd();
|
|
|
|
|
}
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
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
|
|
|
|
while (Device.ConsumeFrameAvailable())
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
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
|
|
|
|
Device.PresentFrame(SwapBuffers);
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
|
if (_ticks >= _ticksPerFrame)
|
|
|
|
|
{
|
|
|
|
|
string dockedMode = ConfigurationState.Instance.System.EnableDockedMode ? "Docked" : "Handheld";
|
|
|
|
|
float scale = Graphics.Gpu.GraphicsConfig.ResScale;
|
|
|
|
|
if (scale != 1)
|
|
|
|
|
{
|
|
|
|
|
dockedMode += $" ({scale}x)";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StatusUpdatedEvent?.Invoke(this, new StatusUpdatedEventArgs(
|
|
|
|
|
Device.EnableDeviceVsync,
|
2021-12-23 11:33:56 -05:00
|
|
|
|
Device.GetVolume(),
|
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
|
|
|
|
dockedMode,
|
|
|
|
|
ConfigurationState.Instance.Graphics.AspectRatio.Value.ToText(),
|
2021-09-14 20:26:10 -04:00
|
|
|
|
$"Game: {Device.Statistics.GetGameFrameRate():00.00} FPS ({Device.Statistics.GetGameFrameTime():00.00} ms)",
|
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
|
|
|
|
$"FIFO: {Device.Statistics.GetFifoPercent():0.00} %",
|
|
|
|
|
$"GPU: {_gpuVendorName}"));
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
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
|
|
|
|
_ticks = Math.Min(_ticks - _ticksPerFrame, _ticksPerFrame);
|
|
|
|
|
}
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
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
|
|
|
|
});
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
_chrono.Restart();
|
|
|
|
|
|
|
|
|
|
_isActive = true;
|
|
|
|
|
|
2021-06-23 17:44:09 -04:00
|
|
|
|
Gtk.Window parent = Toplevel as Gtk.Window;
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
|
|
|
|
Application.Invoke(delegate
|
|
|
|
|
{
|
|
|
|
|
parent.Present();
|
|
|
|
|
|
|
|
|
|
string titleNameSection = string.IsNullOrWhiteSpace(Device.Application.TitleName) ? string.Empty
|
|
|
|
|
: $" - {Device.Application.TitleName}";
|
|
|
|
|
|
|
|
|
|
string titleVersionSection = string.IsNullOrWhiteSpace(Device.Application.DisplayVersion) ? string.Empty
|
|
|
|
|
: $" v{Device.Application.DisplayVersion}";
|
|
|
|
|
|
|
|
|
|
string titleIdSection = string.IsNullOrWhiteSpace(Device.Application.TitleIdText) ? string.Empty
|
|
|
|
|
: $" ({Device.Application.TitleIdText.ToUpper()})";
|
|
|
|
|
|
|
|
|
|
string titleArchSection = Device.Application.TitleIs64Bit ? " (64-bit)" : " (32-bit)";
|
|
|
|
|
|
|
|
|
|
parent.Title = $"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Thread renderLoopThread = new Thread(Render)
|
|
|
|
|
{
|
|
|
|
|
Name = "GUI.RenderLoop"
|
|
|
|
|
};
|
|
|
|
|
renderLoopThread.Start();
|
|
|
|
|
|
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
|
|
|
|
Thread nvStutterWorkaround = null;
|
|
|
|
|
if (Renderer is Graphics.OpenGL.Renderer)
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
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
|
|
|
|
nvStutterWorkaround = new Thread(NVStutterWorkaround)
|
|
|
|
|
{
|
|
|
|
|
Name = "GUI.NVStutterWorkaround"
|
|
|
|
|
};
|
|
|
|
|
nvStutterWorkaround.Start();
|
|
|
|
|
}
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
|
|
|
|
MainLoop();
|
|
|
|
|
|
|
|
|
|
renderLoopThread.Join();
|
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
|
|
|
|
nvStutterWorkaround?.Join();
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
|
|
|
|
Exit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Exit()
|
|
|
|
|
{
|
2021-06-14 02:42:55 -04:00
|
|
|
|
TouchScreenManager?.Dispose();
|
2021-05-04 12:19:04 -04:00
|
|
|
|
NpadManager?.Dispose();
|
|
|
|
|
|
|
|
|
|
if (_isStopped)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_isStopped = true;
|
|
|
|
|
_isActive = false;
|
|
|
|
|
|
|
|
|
|
_exitEvent.WaitOne();
|
|
|
|
|
_exitEvent.Dispose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NVStutterWorkaround()
|
|
|
|
|
{
|
|
|
|
|
while (_isActive)
|
|
|
|
|
{
|
|
|
|
|
// When NVIDIA Threaded Optimization is on, the driver will snapshot all threads in the system whenever the application creates any new ones.
|
|
|
|
|
// The ThreadPool has something called a "GateThread" which terminates itself after some inactivity.
|
|
|
|
|
// However, it immediately starts up again, since the rules regarding when to terminate and when to start differ.
|
|
|
|
|
// This creates a new thread every second or so.
|
|
|
|
|
// The main problem with this is that the thread snapshot can take 70ms, is on the OpenGL thread and will delay rendering any graphics.
|
|
|
|
|
// This is a little over budget on a frame time of 16ms, so creates a large stutter.
|
|
|
|
|
// The solution is to keep the ThreadPool active so that it never has a reason to terminate the GateThread.
|
|
|
|
|
|
|
|
|
|
// TODO: This should be removed when the issue with the GateThread is resolved.
|
|
|
|
|
|
|
|
|
|
ThreadPool.QueueUserWorkItem((state) => { });
|
|
|
|
|
Thread.Sleep(300);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void MainLoop()
|
|
|
|
|
{
|
|
|
|
|
while (_isActive)
|
|
|
|
|
{
|
|
|
|
|
UpdateFrame();
|
|
|
|
|
|
|
|
|
|
// Polling becomes expensive if it's not slept
|
|
|
|
|
Thread.Sleep(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_exitEvent.Set();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool UpdateFrame()
|
|
|
|
|
{
|
|
|
|
|
if (!_isActive)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (_isStopped)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 17:44:09 -04:00
|
|
|
|
if ((Toplevel as MainWindow).IsFocused)
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
2021-06-23 17:44:09 -04:00
|
|
|
|
Application.Invoke(delegate
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
|
|
|
|
KeyboardStateSnapshot keyboard = _keyboardInterface.GetKeyboardStateSnapshot();
|
|
|
|
|
|
|
|
|
|
HandleScreenState(keyboard);
|
|
|
|
|
|
|
|
|
|
if (keyboard.IsPressed(Key.Delete))
|
|
|
|
|
{
|
|
|
|
|
if (!ParentWindow.State.HasFlag(WindowState.Fullscreen))
|
|
|
|
|
{
|
|
|
|
|
Ptc.Continue();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-23 20:09:08 -04:00
|
|
|
|
NpadManager.Update(ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat());
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
2021-06-23 17:44:09 -04:00
|
|
|
|
if ((Toplevel as MainWindow).IsFocused)
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
|
|
|
|
KeyboardHotkeyState currentHotkeyState = GetHotkeyState();
|
|
|
|
|
|
|
|
|
|
if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync) &&
|
|
|
|
|
!_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleVSync))
|
|
|
|
|
{
|
|
|
|
|
Device.EnableDeviceVsync = !Device.EnableDeviceVsync;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-28 16:09:43 -04:00
|
|
|
|
if ((currentHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot) &&
|
|
|
|
|
!_prevHotkeyState.HasFlag(KeyboardHotkeyState.Screenshot)) || ScreenshotRequested)
|
|
|
|
|
{
|
|
|
|
|
ScreenshotRequested = false;
|
|
|
|
|
|
|
|
|
|
Renderer.Screenshot();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-04 17:28:19 -04:00
|
|
|
|
if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ShowUi) &&
|
|
|
|
|
!_prevHotkeyState.HasFlag(KeyboardHotkeyState.ShowUi))
|
|
|
|
|
{
|
|
|
|
|
(Toplevel as MainWindow).ToggleExtraWidgets(true);
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-11 16:08:25 -04:00
|
|
|
|
if (currentHotkeyState.HasFlag(KeyboardHotkeyState.Pause) &&
|
|
|
|
|
!_prevHotkeyState.HasFlag(KeyboardHotkeyState.Pause))
|
|
|
|
|
{
|
|
|
|
|
(Toplevel as MainWindow)?.TogglePause();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 11:33:56 -05:00
|
|
|
|
if (currentHotkeyState.HasFlag(KeyboardHotkeyState.ToggleMute) &&
|
|
|
|
|
!_prevHotkeyState.HasFlag(KeyboardHotkeyState.ToggleMute))
|
|
|
|
|
{
|
|
|
|
|
if (Device.IsAudioMuted())
|
|
|
|
|
{
|
|
|
|
|
Device.SetVolume(ConfigurationState.Instance.System.AudioVolume);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Device.SetVolume(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
_prevHotkeyState = currentHotkeyState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Touchscreen
|
|
|
|
|
bool hasTouch = false;
|
|
|
|
|
|
2021-06-23 17:44:09 -04:00
|
|
|
|
// Get screen touch position
|
2021-06-23 20:09:08 -04:00
|
|
|
|
if ((Toplevel as MainWindow).IsFocused && !ConfigurationState.Instance.Hid.EnableMouse)
|
2021-05-04 12:19:04 -04:00
|
|
|
|
{
|
2021-06-23 17:44:09 -04:00
|
|
|
|
hasTouch = TouchScreenManager.Update(true, (_inputManager.MouseDriver as GTK3MouseDriver).IsButtonPressed(MouseButton.Button1), ConfigurationState.Instance.Graphics.AspectRatio.Value.ToFloat());
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!hasTouch)
|
|
|
|
|
{
|
2021-06-14 02:42:55 -04:00
|
|
|
|
TouchScreenManager.Update(false);
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Device.Hid.DebugPad.Update();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
private enum KeyboardHotkeyState
|
|
|
|
|
{
|
2021-08-04 17:28:19 -04:00
|
|
|
|
None = 0,
|
|
|
|
|
ToggleVSync = 1 << 0,
|
|
|
|
|
Screenshot = 1 << 1,
|
2021-09-11 16:08:25 -04:00
|
|
|
|
ShowUi = 1 << 2,
|
2021-12-23 11:33:56 -05:00
|
|
|
|
Pause = 1 << 3,
|
|
|
|
|
ToggleMute = 1 << 4
|
2021-05-04 12:19:04 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private KeyboardHotkeyState GetHotkeyState()
|
|
|
|
|
{
|
|
|
|
|
KeyboardHotkeyState state = KeyboardHotkeyState.None;
|
|
|
|
|
|
|
|
|
|
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ToggleVsync))
|
|
|
|
|
{
|
|
|
|
|
state |= KeyboardHotkeyState.ToggleVSync;
|
|
|
|
|
}
|
2021-08-04 14:28:33 -04:00
|
|
|
|
|
2021-06-28 16:09:43 -04:00
|
|
|
|
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Screenshot))
|
|
|
|
|
{
|
|
|
|
|
state |= KeyboardHotkeyState.Screenshot;
|
|
|
|
|
}
|
2021-05-04 12:19:04 -04:00
|
|
|
|
|
2021-08-04 17:28:19 -04:00
|
|
|
|
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ShowUi))
|
|
|
|
|
{
|
|
|
|
|
state |= KeyboardHotkeyState.ShowUi;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-11 16:08:25 -04:00
|
|
|
|
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.Pause))
|
|
|
|
|
{
|
|
|
|
|
state |= KeyboardHotkeyState.Pause;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-23 11:33:56 -05:00
|
|
|
|
if (_keyboardInterface.IsPressed((Key)ConfigurationState.Instance.Hid.Hotkeys.Value.ToggleMute))
|
|
|
|
|
{
|
|
|
|
|
state |= KeyboardHotkeyState.ToggleMute;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 12:19:04 -04:00
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|