Compare commits

...

4 Commits

Author SHA1 Message Date
Theun de Bruijn
eca8808649 Headless: Add support for Scaling Filters, Anti-aliasing and Exclusive Fullscreen (#5412)
* Headless: Added support for fullscreen option

* Headless: cleanup of fullscreen support

* Headless: fullscreen support : implemented proposed changes

* Headless: fullscreen support: cleanup

* Headless: exclusive fullscreen support: wip

* Headless: exclusive fullscreen support: add. windows scale interop

* Headless: exclusive fullscreen support: cleanup

* Headless: exclusive fullscreen support: cleanup

* Headless: fullscreen support: fix for OpenGL scaling

* Headless: fullscreen support: cleanup

* Headless: fullscreen support: cleanup

* Headless: fullscreen support: add. Vulkan fix

* Headless: fullscreen support: add. macOS fullscreen fix

* Headless: fullscreen support: cleanup

* Headless: fullscreen support: cleanup

* Headless: fullscreen support: cleanup

* Headless: exclusive fullscreen support: add. display selection logic

* Headless: exclusive fullscreen support: add. anti-aliasing + scaling-filter logic

* Headless: exclusive fullscreen support: upd. options to be case-insensitive

* Headless: exclusive fullscreen support: force default values for scaling + anti-aliasing options

* Headless: upd. OpenGL --fullscreen window size logic

* Headless: upd. fullscreen logic

* Headless: cleanup

* Headless: refac. DisplayId option naming

* Headless: refac. scaling + anti-aliasing option handling

* Headless: refac. namespace handling

* Headless: upd. imports ordering

* Apply suggestions from code review

Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>

---------

Co-authored-by: Ac_K <Acoustik666@gmail.com>
Co-authored-by: TSRBerry <20988865+TSRBerry@users.noreply.github.com>
2023-09-25 23:40:16 +02:00
riperiperi
f6c3f1cdfd GPU: Discard data when getting texture before full clear (#5719)
* GPU: Discard data when getting texture before full clear

* Fix rules and order of clear checks

* Fix formatting
2023-09-25 23:07:03 +02:00
dependabot[bot]
8026e1c804 nuget: bump Microsoft.NET.Test.Sdk from 17.6.3 to 17.7.2 (#5622)
Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.6.3 to 17.7.2.
- [Release notes](https://github.com/microsoft/vstest/releases)
- [Changelog](https://github.com/microsoft/vstest/blob/main/docs/releases.md)
- [Commits](https://github.com/microsoft/vstest/compare/v17.6.3...v17.7.2)

---
updated-dependencies:
- dependency-name: Microsoft.NET.Test.Sdk
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-25 21:29:09 +02:00
Isaac Marovitz
d9f9bbfaa6 Vulkan: Fix barriers on macOS (#5700)
* Use old method on macOS

* gdk suggestions

* Update src/Ryujinx.Graphics.Vulkan/TextureStorage.cs

Co-authored-by: gdkchan <gab.dark.100@gmail.com>

* Update src/Ryujinx.Graphics.Vulkan/TextureStorage.cs

Co-authored-by: gdkchan <gab.dark.100@gmail.com>

---------

Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2023-09-23 19:32:36 -03:00
17 changed files with 357 additions and 40 deletions

View File

@@ -21,7 +21,7 @@
<PackageVersion Include="LibHac" Version="0.18.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.6.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
<PackageVersion Include="MsgPack.Cli" Version="1.0.1" />
<PackageVersion Include="NUnit" Version="3.13.3" />

View File

@@ -335,6 +335,45 @@ namespace Ryujinx.Graphics.GAL
return 1;
}
/// <summary>
/// Checks if the texture format is a depth or depth-stencil format.
/// </summary>
/// <param name="format">Texture format</param>
/// <returns>True if the format is a depth or depth-stencil format, false otherwise</returns>
public static bool HasDepth(this Format format)
{
switch (format)
{
case Format.D16Unorm:
case Format.D24UnormS8Uint:
case Format.S8UintD24Unorm:
case Format.D32Float:
case Format.D32FloatS8Uint:
return true;
}
return false;
}
/// <summary>
/// Checks if the texture format is a stencil or depth-stencil format.
/// </summary>
/// <param name="format">Texture format</param>
/// <returns>True if the format is a stencil or depth-stencil format, false otherwise</returns>
public static bool HasStencil(this Format format)
{
switch (format)
{
case Format.D24UnormS8Uint:
case Format.S8UintD24Unorm:
case Format.D32FloatS8Uint:
case Format.S8Uint:
return true;
}
return false;
}
/// <summary>
/// Checks if the texture format is valid to use as image format.
/// </summary>

View File

@@ -1,6 +1,7 @@
using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.Threed.ComputeDraw;
using Ryujinx.Graphics.Gpu.Engine.Types;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Memory;
using System;
@@ -806,25 +807,69 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
updateFlags |= RenderTargetUpdateFlags.Layered;
}
if (clearDepth || clearStencil)
bool clearDS = clearDepth || clearStencil;
if (clearDS)
{
updateFlags |= RenderTargetUpdateFlags.UpdateDepthStencil;
}
engine.UpdateRenderTargetState(updateFlags, singleUse: componentMask != 0 ? index : -1);
// If there is a mismatch on the host clip region and the one explicitly defined by the guest
// on the screen scissor state, then we need to force only one texture to be bound to avoid
// host clipping.
var screenScissorState = _state.State.ScreenScissorState;
bool clearAffectedByStencilMask = (_state.State.ClearFlags & 1) != 0;
bool clearAffectedByScissor = (_state.State.ClearFlags & 0x100) != 0;
if (clearDS || componentMask == 15)
{
// A full clear if scissor is disabled, or it matches the screen scissor state.
bool fullClear = screenScissorState.X == 0 && screenScissorState.Y == 0;
if (fullClear && clearAffectedByScissor && _state.State.ScissorState[0].Enable)
{
ref var scissorState = ref _state.State.ScissorState[0];
fullClear = scissorState.X1 == screenScissorState.X &&
scissorState.Y1 == screenScissorState.Y &&
scissorState.X2 >= screenScissorState.X + screenScissorState.Width &&
scissorState.Y2 >= screenScissorState.Y + screenScissorState.Height;
}
if (fullClear && clearDS)
{
// Must clear all aspects of the depth-stencil format.
FormatInfo dsFormat = _state.State.RtDepthStencilState.Format.Convert();
bool hasDepth = dsFormat.Format.HasDepth();
bool hasStencil = dsFormat.Format.HasStencil();
if (hasStencil && (!clearStencil || (clearAffectedByStencilMask && _state.State.StencilTestState.FrontMask != 0xff)))
{
fullClear = false;
}
else if (hasDepth && !clearDepth)
{
fullClear = false;
}
}
if (fullClear)
{
updateFlags |= RenderTargetUpdateFlags.DiscardClip;
}
}
engine.UpdateRenderTargetState(updateFlags, singleUse: componentMask != 0 ? index : -1);
// Must happen after UpdateRenderTargetState to have up-to-date clip region values.
bool clipMismatch = (screenScissorState.X | screenScissorState.Y) != 0 ||
screenScissorState.Width != _channel.TextureManager.ClipRegionWidth ||
screenScissorState.Height != _channel.TextureManager.ClipRegionHeight;
bool clearAffectedByStencilMask = (_state.State.ClearFlags & 1) != 0;
bool clearAffectedByScissor = (_state.State.ClearFlags & 0x100) != 0;
bool needsCustomScissor = !clearAffectedByScissor || clipMismatch;
// Scissor and rasterizer discard also affect clears.

View File

@@ -33,6 +33,11 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
/// </summary>
UpdateDepthStencil = 1 << 3,
/// <summary>
/// Indicates that the data in the clip region can be discarded for the next use.
/// </summary>
DiscardClip = 1 << 4,
/// <summary>
/// Default update flags for draw.
/// </summary>

View File

@@ -447,6 +447,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
bool useControl = updateFlags.HasFlag(RenderTargetUpdateFlags.UseControl);
bool layered = updateFlags.HasFlag(RenderTargetUpdateFlags.Layered);
bool singleColor = updateFlags.HasFlag(RenderTargetUpdateFlags.SingleColor);
bool discard = updateFlags.HasFlag(RenderTargetUpdateFlags.DiscardClip);
int count = useControl ? rtControl.UnpackCount() : Constants.TotalRenderTargets;
@@ -486,6 +487,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
memoryManager,
colorState,
_vtgWritesRtLayer || layered,
discard,
samplesInX,
samplesInY,
sizeHint);
@@ -525,6 +527,7 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
dsState,
dsSize,
_vtgWritesRtLayer || layered,
discard,
samplesInX,
samplesInY,
sizeHint);

View File

@@ -570,6 +570,18 @@ namespace Ryujinx.Graphics.Gpu.Image
return Group.CheckDirty(this, consume);
}
/// <summary>
/// Discards all data for this texture.
/// This clears all dirty flags, modified flags, and pending copies from other textures.
/// It should be used if the texture data will be fully overwritten by the next use.
/// </summary>
public void DiscardData()
{
Group.DiscardData(this);
_dirty = false;
}
/// <summary>
/// Synchronizes guest and host memory.
/// This will overwrite the texture data with the texture data on the guest memory, if a CPU

View File

@@ -311,7 +311,7 @@ namespace Ryujinx.Graphics.Gpu.Image
flags |= TextureSearchFlags.NoCreate;
}
Texture texture = FindOrCreateTexture(memoryManager, flags, info, 0);
Texture texture = FindOrCreateTexture(memoryManager, flags, info, 0, sizeHint: sizeHint);
texture?.SynchronizeMemory();
@@ -324,6 +324,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="memoryManager">GPU memory manager where the texture is mapped</param>
/// <param name="colorState">Color buffer texture to find or create</param>
/// <param name="layered">Indicates if the texture might be accessed with a non-zero layer index</param>
/// <param name="discard">Indicates that the sizeHint region's data will be overwritten</param>
/// <param name="samplesInX">Number of samples in the X direction, for MSAA</param>
/// <param name="samplesInY">Number of samples in the Y direction, for MSAA</param>
/// <param name="sizeHint">A hint indicating the minimum used size for the texture</param>
@@ -332,6 +333,7 @@ namespace Ryujinx.Graphics.Gpu.Image
MemoryManager memoryManager,
RtColorState colorState,
bool layered,
bool discard,
int samplesInX,
int samplesInY,
Size sizeHint)
@@ -398,7 +400,14 @@ namespace Ryujinx.Graphics.Gpu.Image
int layerSize = !isLinear ? colorState.LayerSize * 4 : 0;
Texture texture = FindOrCreateTexture(memoryManager, TextureSearchFlags.WithUpscale, info, layerSize);
var flags = TextureSearchFlags.WithUpscale;
if (discard)
{
flags |= TextureSearchFlags.DiscardData;
}
Texture texture = FindOrCreateTexture(memoryManager, flags, info, layerSize, sizeHint: sizeHint);
texture?.SynchronizeMemory();
@@ -412,6 +421,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="dsState">Depth-stencil buffer texture to find or create</param>
/// <param name="size">Size of the depth-stencil texture</param>
/// <param name="layered">Indicates if the texture might be accessed with a non-zero layer index</param>
/// <param name="discard">Indicates that the sizeHint region's data will be overwritten</param>
/// <param name="samplesInX">Number of samples in the X direction, for MSAA</param>
/// <param name="samplesInY">Number of samples in the Y direction, for MSAA</param>
/// <param name="sizeHint">A hint indicating the minimum used size for the texture</param>
@@ -421,6 +431,7 @@ namespace Ryujinx.Graphics.Gpu.Image
RtDepthStencilState dsState,
Size3D size,
bool layered,
bool discard,
int samplesInX,
int samplesInY,
Size sizeHint)
@@ -465,7 +476,14 @@ namespace Ryujinx.Graphics.Gpu.Image
target,
formatInfo);
Texture texture = FindOrCreateTexture(memoryManager, TextureSearchFlags.WithUpscale, info, dsState.LayerSize * 4);
var flags = TextureSearchFlags.WithUpscale;
if (discard)
{
flags |= TextureSearchFlags.DiscardData;
}
Texture texture = FindOrCreateTexture(memoryManager, flags, info, dsState.LayerSize * 4, sizeHint: sizeHint);
texture?.SynchronizeMemory();
@@ -500,6 +518,37 @@ namespace Ryujinx.Graphics.Gpu.Image
return Math.Clamp(widthAligned - alignment + 1, minimumWidth, widthAligned);
}
/// <summary>
/// Determines if texture data should be fully discarded
/// based on the size hint region and whether it is set to be discarded.
/// </summary>
/// <param name="discard">Whether the size hint region should be discarded</param>
/// <param name="texture">The texture being discarded</param>
/// <param name="sizeHint">A hint indicating the minimum used size for the texture</param>
/// <returns>True if the data should be discarded, false otherwise</returns>
private static bool ShouldDiscard(bool discard, Texture texture, Size? sizeHint)
{
return discard &&
texture.Info.DepthOrLayers == 1 &&
sizeHint != null &&
texture.Width <= sizeHint.Value.Width &&
texture.Height <= sizeHint.Value.Height;
}
/// <summary>
/// Discards texture data if requested and possible.
/// </summary>
/// <param name="discard">Whether the size hint region should be discarded</param>
/// <param name="texture">The texture being discarded</param>
/// <param name="sizeHint">A hint indicating the minimum used size for the texture</param>
private static void DiscardIfNeeded(bool discard, Texture texture, Size? sizeHint)
{
if (ShouldDiscard(discard, texture, sizeHint))
{
texture.DiscardData();
}
}
/// <summary>
/// Tries to find an existing texture, or create a new one if not found.
/// </summary>
@@ -507,6 +556,7 @@ namespace Ryujinx.Graphics.Gpu.Image
/// <param name="flags">The texture search flags, defines texture comparison rules</param>
/// <param name="info">Texture information of the texture to be found or created</param>
/// <param name="layerSize">Size in bytes of a single texture layer</param>
/// <param name="sizeHint">A hint indicating the minimum used size for the texture</param>
/// <param name="range">Optional ranges of physical memory where the texture data is located</param>
/// <returns>The texture</returns>
public Texture FindOrCreateTexture(
@@ -514,9 +564,11 @@ namespace Ryujinx.Graphics.Gpu.Image
TextureSearchFlags flags,
TextureInfo info,
int layerSize = 0,
Size? sizeHint = null,
MultiRange? range = null)
{
bool isSamplerTexture = (flags & TextureSearchFlags.ForSampler) != 0;
bool discard = (flags & TextureSearchFlags.DiscardData) != 0;
TextureScaleMode scaleMode = IsUpscaleCompatible(info, (flags & TextureSearchFlags.WithUpscale) != 0);
@@ -612,6 +664,8 @@ namespace Ryujinx.Graphics.Gpu.Image
if (texture != null)
{
DiscardIfNeeded(discard, texture, sizeHint);
texture.SynchronizeMemory();
return texture;
@@ -907,7 +961,7 @@ namespace Ryujinx.Graphics.Gpu.Image
// We need to synchronize before copying the old view data to the texture,
// otherwise the copied data would be overwritten by a future synchronization.
texture.InitializeData(false, setData);
texture.InitializeData(false, setData && !ShouldDiscard(discard, texture, sizeHint));
texture.Group.InitializeOverlaps();

View File

@@ -278,6 +278,24 @@ namespace Ryujinx.Graphics.Gpu.Image
return dirty;
}
/// <summary>
/// Discards all data for a given texture.
/// This clears all dirty flags, modified flags, and pending copies from other textures.
/// </summary>
/// <param name="texture">The texture being discarded</param>
public void DiscardData(Texture texture)
{
EvaluateRelevantHandles(texture, (baseHandle, regionCount, split) =>
{
for (int i = 0; i < regionCount; i++)
{
TextureGroupHandle group = _handles[baseHandle + i];
group.DiscardData();
}
});
}
/// <summary>
/// Synchronize memory for a given texture.
/// If overlapping tracking handles are dirty, fully or partially synchronize the texture data.

View File

@@ -2,7 +2,6 @@
using Ryujinx.Memory.Tracking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
namespace Ryujinx.Graphics.Gpu.Image
@@ -155,6 +154,24 @@ namespace Ryujinx.Graphics.Gpu.Image
}
}
/// <summary>
/// Discards all data for this handle.
/// This clears all dirty flags, modified flags, and pending copies from other handles.
/// </summary>
public void DiscardData()
{
Modified = false;
DeferredCopy = null;
foreach (RegionHandle handle in Handles)
{
if (handle.Dirty)
{
handle.Reprotect();
}
}
}
/// <summary>
/// Calculate a list of which views overlap this handle.
/// </summary>

View File

@@ -14,5 +14,6 @@ namespace Ryujinx.Graphics.Gpu.Image
DepthAlias = 1 << 3,
WithUpscale = 1 << 4,
NoCreate = 1 << 5,
DiscardData = 1 << 6,
}
}

View File

@@ -200,7 +200,7 @@ namespace Ryujinx.Graphics.Gpu
{
pt.AcquireCallback(_context, pt.UserObj);
Image.Texture texture = pt.Cache.FindOrCreateTexture(null, TextureSearchFlags.WithUpscale, pt.Info, 0, pt.Range);
Image.Texture texture = pt.Cache.FindOrCreateTexture(null, TextureSearchFlags.WithUpscale, pt.Info, 0, range: pt.Range);
pt.Cache.Tick();

View File

@@ -454,13 +454,36 @@ namespace Ryujinx.Graphics.Vulkan
if (lastReadStage != PipelineStageFlags.None)
{
TextureView.InsertMemoryBarrier(
_gd.Api,
cbs.CommandBuffer,
_lastReadAccess,
dstAccessFlags,
lastReadStage,
dstStageFlags);
// This would result in a validation error, but is
// required on MoltenVK as the generic barrier results in
// severe texture flickering in some scenarios.
if (_gd.IsMoltenVk)
{
ImageAspectFlags aspectFlags = Info.Format.ConvertAspectFlags();
TextureView.InsertImageBarrier(
_gd.Api,
cbs.CommandBuffer,
_imageAuto.Get(cbs).Value,
_lastReadAccess,
dstAccessFlags,
_lastReadStage,
dstStageFlags,
aspectFlags,
0,
0,
_info.GetLayers(),
_info.Levels);
}
else
{
TextureView.InsertMemoryBarrier(
_gd.Api,
cbs.CommandBuffer,
_lastReadAccess,
dstAccessFlags,
lastReadStage,
dstStageFlags);
}
_lastReadAccess = AccessFlags.None;
_lastReadStage = PipelineStageFlags.None;
@@ -474,13 +497,36 @@ namespace Ryujinx.Graphics.Vulkan
if (_lastModificationAccess != AccessFlags.None)
{
TextureView.InsertMemoryBarrier(
_gd.Api,
cbs.CommandBuffer,
_lastModificationAccess,
dstAccessFlags,
_lastModificationStage,
dstStageFlags);
// This would result in a validation error, but is
// required on MoltenVK as the generic barrier results in
// severe texture flickering in some scenarios.
if (_gd.IsMoltenVk)
{
ImageAspectFlags aspectFlags = Info.Format.ConvertAspectFlags();
TextureView.InsertImageBarrier(
_gd.Api,
cbs.CommandBuffer,
_imageAuto.Get(cbs).Value,
_lastModificationAccess,
dstAccessFlags,
_lastModificationStage,
dstStageFlags,
aspectFlags,
0,
0,
_info.GetLayers(),
_info.Levels);
}
else
{
TextureView.InsertMemoryBarrier(
_gd.Api,
cbs.CommandBuffer,
_lastModificationAccess,
dstAccessFlags,
_lastModificationStage,
dstStageFlags);
}
_lastModificationAccess = AccessFlags.None;
}

View File

@@ -151,11 +151,15 @@ namespace Ryujinx.Headless.SDL2.OpenGL
GL.Clear(ClearBufferMask.ColorBufferBit);
SwapBuffers();
if (IsFullscreen)
if (IsExclusiveFullscreen)
{
Renderer?.Window.SetSize(ExclusiveFullscreenWidth, ExclusiveFullscreenHeight);
MouseDriver.SetClientSize(ExclusiveFullscreenWidth, ExclusiveFullscreenHeight);
}
else if (IsFullscreen)
{
// NOTE: grabbing the main display's dimensions directly as OpenGL doesn't scale along like the VulkanWindow.
// we might have to amend this if people run this on a non-primary display set to a different resolution.
if (SDL_GetDisplayBounds(0, out SDL_Rect displayBounds) < 0)
if (SDL_GetDisplayBounds(DisplayId, out SDL_Rect displayBounds) < 0)
{
Logger.Warning?.Print(LogClass.Application, $"Could not retrieve display bounds: {SDL_GetError()}");

View File

@@ -14,9 +14,21 @@ namespace Ryujinx.Headless.SDL2
[Option("profile", Required = false, HelpText = "Set the user profile to launch the game with.")]
public string UserProfile { get; set; }
[Option("fullscreen", Required = false, HelpText = "Launch the game in fullscreen mode.")]
[Option("display-id", Required = false, Default = 0, HelpText = "Set the display to use - especially helpful for fullscreen mode. [0-n]")]
public int DisplayId { get; set; }
[Option("fullscreen", Required = false, Default = false, HelpText = "Launch the game in fullscreen mode.")]
public bool IsFullscreen { get; set; }
[Option("exclusive-fullscreen", Required = false, Default = false, HelpText = "Launch the game in exclusive fullscreen mode.")]
public bool IsExclusiveFullscreen { get; set; }
[Option("exclusive-fullscreen-width", Required = false, Default = 1920, HelpText = "Set horizontal resolution for exclusive fullscreen mode.")]
public int ExclusiveFullscreenWidth { get; set; }
[Option("exclusive-fullscreen-height", Required = false, Default = 1080, HelpText = "Set vertical resolution for exclusive fullscreen mode.")]
public int ExclusiveFullscreenHeight { get; set; }
// Input
[Option("input-profile-1", Required = false, HelpText = "Set the input profile in use for Player 1.")]
@@ -196,6 +208,15 @@ namespace Ryujinx.Headless.SDL2
[Option("preferred-gpu-vendor", Required = false, Default = "", HelpText = "When using the Vulkan backend, prefer using the GPU from the specified vendor.")]
public string PreferredGPUVendor { get; set; }
[Option("anti-aliasing", Required = false, Default = AntiAliasing.None, HelpText = "Set the type of anti aliasing being used. [None|Fxaa|SmaaLow|SmaaMedium|SmaaHigh|SmaaUltra]")]
public AntiAliasing AntiAliasing { get; set; }
[Option("scaling-filter", Required = false, Default = ScalingFilter.Bilinear, HelpText = "Set the scaling filter. [Bilinear|Nearest|Fsr]")]
public ScalingFilter ScalingFilter { get; set; }
[Option("scaling-filter-level", Required = false, Default = 0, HelpText = "Set the scaling filter intensity (currently only applies to FSR). [0-100]")]
public int ScalingFilterLevel { get; set; }
// Hacks
[Option("expand-ram", Required = false, Default = false, HelpText = "Expands the RAM amount on the emulated system from 4GiB to 6GiB.")]

View File

@@ -596,6 +596,13 @@ namespace Ryujinx.Headless.SDL2
_window = window;
_window.IsFullscreen = options.IsFullscreen;
_window.DisplayId = options.DisplayId;
_window.IsExclusiveFullscreen = options.IsExclusiveFullscreen;
_window.ExclusiveFullscreenWidth = options.ExclusiveFullscreenWidth;
_window.ExclusiveFullscreenHeight = options.ExclusiveFullscreenHeight;
_window.AntiAliasing = options.AntiAliasing;
_window.ScalingFilter = options.ScalingFilter;
_window.ScalingFilterLevel = options.ScalingFilterLevel;
_emulationContext = InitializeEmulationContext(window, renderer, options);

View File

@@ -29,8 +29,16 @@ namespace Ryujinx.Headless.SDL2.Vulkan
protected override void InitializeRenderer()
{
Renderer?.Window.SetSize(DefaultWidth, DefaultHeight);
MouseDriver.SetClientSize(DefaultWidth, DefaultHeight);
if (IsExclusiveFullscreen)
{
Renderer?.Window.SetSize(ExclusiveFullscreenWidth, ExclusiveFullscreenHeight);
MouseDriver.SetClientSize(ExclusiveFullscreenWidth, ExclusiveFullscreenHeight);
}
else
{
Renderer?.Window.SetSize(DefaultWidth, DefaultHeight);
MouseDriver.SetClientSize(DefaultWidth, DefaultHeight);
}
}
private static void BasicInvoke(Action action)

View File

@@ -20,6 +20,8 @@ using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using static SDL2.SDL;
using AntiAliasing = Ryujinx.Common.Configuration.AntiAliasing;
using ScalingFilter = Ryujinx.Common.Configuration.ScalingFilter;
using Switch = Ryujinx.HLE.Switch;
namespace Ryujinx.Headless.SDL2
@@ -28,8 +30,9 @@ namespace Ryujinx.Headless.SDL2
{
protected const int DefaultWidth = 1280;
protected const int DefaultHeight = 720;
private const SDL_WindowFlags DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL_WindowFlags.SDL_WINDOW_SHOWN;
private const int TargetFps = 60;
private SDL_WindowFlags DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI | SDL_WindowFlags.SDL_WINDOW_RESIZABLE | SDL_WindowFlags.SDL_WINDOW_INPUT_FOCUS | SDL_WindowFlags.SDL_WINDOW_SHOWN;
private SDL_WindowFlags FullscreenFlag = 0;
private static readonly ConcurrentQueue<Action> _mainThreadActions = new();
@@ -54,7 +57,14 @@ namespace Ryujinx.Headless.SDL2
public IHostUiTheme HostUiTheme { get; }
public int Width { get; private set; }
public int Height { get; private set; }
public int DisplayId { get; set; }
public bool IsFullscreen { get; set; }
public bool IsExclusiveFullscreen { get; set; }
public int ExclusiveFullscreenWidth { get; set; }
public int ExclusiveFullscreenHeight { get; set; }
public AntiAliasing AntiAliasing { get; set; }
public ScalingFilter ScalingFilter { get; set; }
public int ScalingFilterLevel { get; set; }
protected SDL2MouseDriver MouseDriver;
private readonly InputManager _inputManager;
@@ -158,9 +168,24 @@ namespace Ryujinx.Headless.SDL2
string titleIdSection = string.IsNullOrWhiteSpace(activeProcess.ProgramIdText) ? string.Empty : $" ({activeProcess.ProgramIdText.ToUpper()})";
string titleArchSection = activeProcess.Is64Bit ? " (64-bit)" : " (32-bit)";
SDL_WindowFlags fullscreenFlag = IsFullscreen ? SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP : 0;
Width = DefaultWidth;
Height = DefaultHeight;
WindowHandle = SDL_CreateWindow($"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, DefaultWidth, DefaultHeight, DefaultFlags | fullscreenFlag | GetWindowFlags());
if (IsExclusiveFullscreen)
{
Width = ExclusiveFullscreenWidth;
Height = ExclusiveFullscreenHeight;
DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI;
FullscreenFlag = SDL_WindowFlags.SDL_WINDOW_FULLSCREEN;
}
else if (IsFullscreen)
{
DefaultFlags = SDL_WindowFlags.SDL_WINDOW_ALLOW_HIGHDPI;
FullscreenFlag = SDL_WindowFlags.SDL_WINDOW_FULLSCREEN_DESKTOP;
}
WindowHandle = SDL_CreateWindow($"Ryujinx {Program.Version}{titleNameSection}{titleVersionSection}{titleIdSection}{titleArchSection}", SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), SDL_WINDOWPOS_CENTERED_DISPLAY(DisplayId), Width, Height, DefaultFlags | FullscreenFlag | GetWindowFlags());
if (WindowHandle == IntPtr.Zero)
{
@@ -175,9 +200,6 @@ namespace Ryujinx.Headless.SDL2
_windowId = SDL_GetWindowID(WindowHandle);
SDL2Driver.Instance.RegisterWindow(_windowId, HandleWindowEvent);
Width = DefaultWidth;
Height = DefaultHeight;
}
private void HandleWindowEvent(SDL_Event evnt)
@@ -189,8 +211,8 @@ namespace Ryujinx.Headless.SDL2
case SDL_WindowEventID.SDL_WINDOWEVENT_SIZE_CHANGED:
// Unlike on Windows, this event fires on macOS when triggering fullscreen mode.
// And promptly crashes the process because `Renderer?.window.SetSize` is undefined.
// As we don't need this to fire in either case we can test for isFullscreen.
if (!IsFullscreen)
// As we don't need this to fire in either case we can test for fullscreen.
if (!IsFullscreen && !IsExclusiveFullscreen)
{
Width = evnt.window.data1;
Height = evnt.window.data2;
@@ -225,6 +247,17 @@ namespace Ryujinx.Headless.SDL2
return Renderer.GetHardwareInfo().GpuVendor;
}
private void SetAntiAliasing()
{
Renderer?.Window.SetAntiAliasing((Graphics.GAL.AntiAliasing)AntiAliasing);
}
private void SetScalingFilter()
{
Renderer?.Window.SetScalingFilter((Graphics.GAL.ScalingFilter)ScalingFilter);
Renderer?.Window.SetScalingFilterLevel(ScalingFilterLevel);
}
public void Render()
{
InitializeWindowRenderer();
@@ -233,6 +266,10 @@ namespace Ryujinx.Headless.SDL2
InitializeRenderer();
SetAntiAliasing();
SetScalingFilter();
_gpuVendorName = GetGpuVendorName();
Device.Gpu.Renderer.RunLoop(() =>