Work around the current Metal renderer's broken resolution scaling

This commit is contained in:
Evan Husted
2025-01-29 00:21:12 -06:00
parent 707c9ef748
commit 90fdad2a3b
6 changed files with 45 additions and 14 deletions

View File

@@ -1,3 +1,5 @@
using Ryujinx.Common.Configuration;
namespace Ryujinx.Graphics.Gpu namespace Ryujinx.Graphics.Gpu
{ {
#pragma warning disable CA2211 // Non-constant fields should not be visible #pragma warning disable CA2211 // Non-constant fields should not be visible
@@ -6,10 +8,21 @@ namespace Ryujinx.Graphics.Gpu
/// </summary> /// </summary>
public static class GraphicsConfig public static class GraphicsConfig
{ {
/// <summary>
/// The graphics backend currently in use.
/// </summary>
public static GraphicsBackend CurrentBackend;
private static float _resScale = 1f;
/// <summary> /// <summary>
/// Resolution scale. /// Resolution scale.
/// </summary> /// </summary>
public static float ResScale = 1f; public static float ResScale
{
get => CurrentBackend is GraphicsBackend.Metal ? 1 : _resScale;
set => _resScale = value;
}
/// <summary> /// <summary>
/// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide. /// Max Anisotropy. Values range from 0 - 16. Set to -1 to let the game decide.

View File

@@ -691,7 +691,6 @@ namespace Ryujinx.Ava
DiscordIntegrationModule.GuestAppStartedAt = Timestamps.Now; DiscordIntegrationModule.GuestAppStartedAt = Timestamps.Now;
InitEmulatedSwitch(); InitEmulatedSwitch();
MainWindow.UpdateGraphicsConfig();
SystemVersion firmwareVersion = ContentManager.GetCurrentFirmwareVersion(); SystemVersion firmwareVersion = ContentManager.GetCurrentFirmwareVersion();
@@ -1307,11 +1306,12 @@ namespace Ryujinx.Ava
_viewModel.Volume = Device.GetVolume(); _viewModel.Volume = Device.GetVolume();
break; break;
case KeyboardHotkeyState.ResScaleUp: case KeyboardHotkeyState.ResScaleUp:
GraphicsConfig.ResScale = GraphicsConfig.ResScale % MaxResolutionScale + 1; if (GraphicsConfig.CurrentBackend is not GraphicsBackend.Metal)
GraphicsConfig.ResScale = GraphicsConfig.ResScale % MaxResolutionScale + 1;
break; break;
case KeyboardHotkeyState.ResScaleDown: case KeyboardHotkeyState.ResScaleDown:
GraphicsConfig.ResScale = if (GraphicsConfig.CurrentBackend is not GraphicsBackend.Metal)
(MaxResolutionScale + GraphicsConfig.ResScale - 2) % MaxResolutionScale + 1; GraphicsConfig.ResScale = (MaxResolutionScale + GraphicsConfig.ResScale - 2) % MaxResolutionScale + 1;
break; break;
case KeyboardHotkeyState.VolumeUp: case KeyboardHotkeyState.VolumeUp:
_newVolume = MathF.Round((Device.GetVolume() + VolumeDelta), 2); _newVolume = MathF.Round((Device.GetVolume() + VolumeDelta), 2);

View File

@@ -280,6 +280,7 @@ namespace Ryujinx.Headless
} }
// Setup graphics configuration // Setup graphics configuration
GraphicsConfig.CurrentBackend = option.GraphicsBackend is GraphicsBackend.Auto ? GraphicsBackend.Vulkan : option.GraphicsBackend;
GraphicsConfig.EnableShaderCache = !option.DisableShaderCache; GraphicsConfig.EnableShaderCache = !option.DisableShaderCache;
GraphicsConfig.EnableTextureRecompression = option.EnableTextureRecompression; GraphicsConfig.EnableTextureRecompression = option.EnableTextureRecompression;
GraphicsConfig.ResScale = option.ResScale; GraphicsConfig.ResScale = option.ResScale;
@@ -356,11 +357,15 @@ namespace Ryujinx.Headless
{ {
return options.GraphicsBackend switch return options.GraphicsBackend switch
{ {
GraphicsBackend.Vulkan => new VulkanWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode, options.IgnoreControllerApplet), GraphicsBackend.OpenGl =>
GraphicsBackend.Metal => OperatingSystem.IsMacOS() ? !OperatingSystem.IsMacOS()
new MetalWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableKeyboard, options.HideCursorMode, options.IgnoreControllerApplet) : ? new OpenGLWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode, options.IgnoreControllerApplet)
throw new Exception("Attempted to use Metal renderer on non-macOS platform!"), : throw new InvalidOperationException("Attempted to use OpenGL renderer on macOS platform!"),
_ => new OpenGLWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode, options.IgnoreControllerApplet) GraphicsBackend.Metal =>
OperatingSystem.IsMacOS()
? new MetalWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableKeyboard, options.HideCursorMode, options.IgnoreControllerApplet)
: throw new InvalidOperationException("Attempted to use Metal renderer on non-macOS platform!"),
_ => new VulkanWindow(_inputManager, options.LoggingGraphicsDebugLevel, options.AspectRatio, options.EnableMouse, options.HideCursorMode, options.IgnoreControllerApplet),
}; };
} }

View File

@@ -1,6 +1,7 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Media; using Avalonia.Media;
using Ryujinx.Ava.UI.Windows;
using Ryujinx.Ava.Utilities.Configuration; using Ryujinx.Ava.Utilities.Configuration;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
@@ -43,6 +44,8 @@ namespace Ryujinx.Ava.UI.Renderer
public RendererHost(string titleId) public RendererHost(string titleId)
{ {
MainWindow.UpdateGraphicsConfig(titleId);
switch (TitleIDs.SelectGraphicsBackend(titleId, ConfigurationState.Instance.Graphics.GraphicsBackend)) switch (TitleIDs.SelectGraphicsBackend(titleId, ConfigurationState.Instance.Graphics.GraphicsBackend))
{ {
case GraphicsBackend.OpenGl: case GraphicsBackend.OpenGl:

View File

@@ -20,6 +20,7 @@ using Ryujinx.Ava.Utilities;
using Ryujinx.Ava.Utilities.AppLibrary; using Ryujinx.Ava.Utilities.AppLibrary;
using Ryujinx.Ava.Utilities.Configuration; using Ryujinx.Ava.Utilities.Configuration;
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Common.Configuration;
using Ryujinx.Common.Helper; using Ryujinx.Common.Helper;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Common.UI; using Ryujinx.Common.UI;
@@ -541,12 +542,11 @@ namespace Ryujinx.Ava.UI.Windows
} }
} }
public static void UpdateGraphicsConfig() public static void UpdateGraphicsConfig(string titleId = null)
{ {
#pragma warning disable IDE0055 // Disable formatting #pragma warning disable IDE0055 // Disable formatting
GraphicsConfig.ResScale = ConfigurationState.Instance.Graphics.ResScale == -1 GraphicsConfig.CurrentBackend = TitleIDs.SelectGraphicsBackend(titleId, ConfigurationState.Instance.Graphics.GraphicsBackend);
? ConfigurationState.Instance.Graphics.ResScaleCustom GraphicsConfig.ResScale = ConfigurationState.Instance.Graphics.GetScalingFactor(titleId);
: ConfigurationState.Instance.Graphics.ResScale;
GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy; GraphicsConfig.MaxAnisotropy = ConfigurationState.Instance.Graphics.MaxAnisotropy;
GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath; GraphicsConfig.ShadersDumpPath = ConfigurationState.Instance.Graphics.ShadersDumpPath;
GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache; GraphicsConfig.EnableShaderCache = ConfigurationState.Instance.Graphics.EnableShaderCache;

View File

@@ -479,6 +479,16 @@ namespace Ryujinx.Ava.Utilities.Configuration
/// </summary> /// </summary>
public ReactiveObject<int> ResScale { get; private set; } public ReactiveObject<int> ResScale { get; private set; }
public float GetScalingFactor(string titleId = null)
{
if (titleId is null) return 1;
if (TitleIDs.SelectGraphicsBackend(titleId, GraphicsBackend) is Ryujinx.Common.Configuration.GraphicsBackend.Metal)
return 1;
return ResScale == -1 ? ResScaleCustom : ResScale;
}
/// <summary> /// <summary>
/// Custom Resolution Scale. A custom floating point scale applied to applicable render targets. Only active when Resolution Scale is -1. /// Custom Resolution Scale. A custom floating point scale applied to applicable render targets. Only active when Resolution Scale is -1.
/// </summary> /// </summary>