Compare commits

..

11 Commits

Author SHA1 Message Date
gdkchan
88a0e720cb Use RGBA16 vertex format if RGB16 is not supported on Vulkan (#3552)
* Use RGBA16 vertex format if RGB16 is not supported on Vulkan

* Catch all shader compilation exceptions
2022-08-20 16:20:27 -03:00
EmulationFanatic
53cc9e0561 Change 'Purge PPTC Cache' label & tooltip to reflect function behavior (#3601)
* Change PPTC purge label & tooltip

* Change Avalonia labels
2022-08-19 23:39:59 +00:00
Nicholas Rodine
7defc59b9d A few minor documentation fixes. (#3599)
* A few minor documentation fixes.

* Removed more invalid inheritdoc instances.
2022-08-19 18:21:06 -03:00
Nicholas Rodine
951700fdd8 Removed unused usings. (#3593)
* Removed unused usings.

* Added back using, now that it's used.

* Removed extra whitespace.
2022-08-18 18:04:54 +02:00
Nicholas Rodine
eb6430f103 Skipped over the last "Count" key explicitly, instead of relying on an exception. (#3595) 2022-08-18 02:00:27 +02:00
Nicholas Rodine
80a879cb44 Fix SpirV parse failure (#3597)
* Added .ToString overrides, to help diagnose and debug SpirV generated code.

* Added Spirv to team shared dictionary, so the word will not show up as a warning.

* Fixed bug where we were creating invalid constants (bool 0i and float 0i)

* Update Ryujinx.Graphics.Shader/CodeGen/Spirv/CodeGenContext.cs

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

* Update Spv.Generator/Instruction.cs

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

* Adjusted spacing to match style of the rest of the code.

* Added handler for FP64(double) as well, for undefined aggregate types.

* Made the operand labels a static dictionary, to avoid re-allocation on each call.
Replaced Contains/Get with a TryGetValue, to reduce the number of dictionary lookups.

* Added newline between AllOperands and ToString().

Co-authored-by: gdkchan <gab.dark.100@gmail.com>
2022-08-18 01:49:43 +02:00
Nicholas Rodine
2197f41506 Removed extra semicolons. (#3594) 2022-08-17 09:05:15 +02:00
Emmanuel Hansen
c8f9292bab Avalonia - Couple fixes and improvements to vulkan (#3483)
* drop split devices, rebase

* add fallback to opengl if vulkan is not available

* addressed review

* ensure present image references are incremented and decremented when necessary

* allow changing vsync for vulkan

* fix screenshot on avalonia vulkan

* save favorite when toggled

* improve sync between popups

* use separate devices for each new window

* fix crash when closing window

* addressed review

* don't create the main window with immediate mode

* change skia vk delegate to method

* update vulkan throwonerror

* addressed review
2022-08-16 16:32:37 +00:00
gdkchan
0ec933a615 Vulkan: Add ETC2 texture formats (#3576) 2022-08-16 15:42:42 +02:00
Ac_K
2135b6a51a am: Stub SetWirelessPriorityMode, SetWirelessPriorityMode and GetHdcpAuthenticationState (#3535)
This PR some calls in `am` service:
- ISelfController: SetWirelessPriorityMode, SaveCurrentScreenshot (Partially checked by RE).
- ICommonStateGetter: GetHdcpAuthenticationState

Close #1831 and close #3527
2022-08-15 11:12:08 +00:00
mageven
00e35d9bf6 ControllerApplet: Override player counts when SingleMode is set (#3571) 2022-08-15 09:46:08 +02:00
190 changed files with 935 additions and 627 deletions

View File

@@ -58,7 +58,6 @@ namespace ARMeilleure.CodeGen.Linking
/// <param name="a">First instance</param> /// <param name="a">First instance</param>
/// <param name="b">Second instance</param> /// <param name="b">Second instance</param>
/// <returns><see langword="true"/> if not equal; otherwise <see langword="false"/></returns> /// <returns><see langword="true"/> if not equal; otherwise <see langword="false"/></returns>
/// <inheritdoc/>
public static bool operator !=(Symbol a, Symbol b) public static bool operator !=(Symbol a, Symbol b)
{ {
return !(a == b); return !(a == b);

View File

@@ -1,6 +1,4 @@
using ARMeilleure.Common;
using ARMeilleure.IntermediateRepresentation; using ARMeilleure.IntermediateRepresentation;
using System;
namespace ARMeilleure.CodeGen.RegisterAllocators namespace ARMeilleure.CodeGen.RegisterAllocators
{ {

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Runtime.InteropServices;
namespace ARMeilleure.CodeGen.X86 namespace ARMeilleure.CodeGen.X86
{ {

View File

@@ -206,7 +206,7 @@ namespace ARMeilleure.Common
/// <typeparam name="T">Type of elements</typeparam> /// <typeparam name="T">Type of elements</typeparam>
/// <param name="length">Number of elements</param> /// <param name="length">Number of elements</param>
/// <param name="fill">Fill value</param> /// <param name="fill">Fill value</param>
/// <param name="leaf"><see langword="true"/> if leaf; otherwise <see langword=""="false"/></param> /// <param name="leaf"><see langword="true"/> if leaf; otherwise <see langword="false"/></param>
/// <returns>Allocated block</returns> /// <returns>Allocated block</returns>
private IntPtr Allocate<T>(int length, T fill, bool leaf) where T : unmanaged private IntPtr Allocate<T>(int length, T fill, bool leaf) where T : unmanaged
{ {

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading;
namespace ARMeilleure.Common namespace ARMeilleure.Common
{ {

View File

@@ -9,6 +9,9 @@ namespace ARMeilleure.Common
class Counter<T> : IDisposable where T : unmanaged class Counter<T> : IDisposable where T : unmanaged
{ {
private bool _disposed; private bool _disposed;
/// <summary>
/// Index in the <see cref="EntryTable{T}"/>
/// </summary>
private readonly int _index; private readonly int _index;
private readonly EntryTable<T> _countTable; private readonly EntryTable<T> _countTable;
@@ -17,7 +20,6 @@ namespace ARMeilleure.Common
/// <see cref="EntryTable{T}"/> instance and index. /// <see cref="EntryTable{T}"/> instance and index.
/// </summary> /// </summary>
/// <param name="countTable"><see cref="EntryTable{T}"/> instance</param> /// <param name="countTable"><see cref="EntryTable{T}"/> instance</param>
/// <param name="index">Index in the <see cref="EntryTable{T}"/></param>
/// <exception cref="ArgumentNullException"><paramref name="countTable"/> is <see langword="null"/></exception> /// <exception cref="ArgumentNullException"><paramref name="countTable"/> is <see langword="null"/></exception>
/// <exception cref="ArgumentException"><typeparamref name="T"/> is unsupported</exception> /// <exception cref="ArgumentException"><typeparamref name="T"/> is unsupported</exception>
public Counter(EntryTable<T> countTable) public Counter(EntryTable<T> countTable)
@@ -68,7 +70,7 @@ namespace ARMeilleure.Common
/// <summary> /// <summary>
/// Releases all unmanaged and optionally managed resources used by the <see cref="Counter{T}"/> instance. /// Releases all unmanaged and optionally managed resources used by the <see cref="Counter{T}"/> instance.
/// </summary> /// </summary>
/// <param name="disposing"><see langword="true"/> to dispose managed resources also; otherwise just unmanaged resouces</param> /// <param name="disposing"><see langword="true"/> to dispose managed resources also; otherwise just unmanaged resources</param>
protected virtual void Dispose(bool disposing) protected virtual void Dispose(bool disposing)
{ {
if (!_disposed) if (!_disposed)

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection.Emit;
namespace ARMeilleure.Decoders namespace ARMeilleure.Decoders
{ {

View File

@@ -1,6 +1,4 @@
using ARMeilleure.Instructions; namespace ARMeilleure.Decoders
namespace ARMeilleure.Decoders
{ {
class OpCodeT32BImm20 : OpCodeT32, IOpCode32BImm class OpCodeT32BImm20 : OpCodeT32, IOpCode32BImm
{ {

View File

@@ -1,7 +1,5 @@
using ARMeilleure.Decoders; using ARMeilleure.Decoders;
using ARMeilleure.Translation; using ARMeilleure.Translation;
using static ARMeilleure.Instructions.InstEmitFlowHelper;
using static ARMeilleure.IntermediateRepresentation.Operand.Factory; using static ARMeilleure.IntermediateRepresentation.Operand.Factory;
namespace ARMeilleure.Instructions namespace ARMeilleure.Instructions

View File

@@ -2,8 +2,6 @@
using ARMeilleure.IntermediateRepresentation; using ARMeilleure.IntermediateRepresentation;
using ARMeilleure.Translation; using ARMeilleure.Translation;
using System; using System;
using System.Diagnostics;
using static ARMeilleure.Instructions.InstEmitFlowHelper; using static ARMeilleure.Instructions.InstEmitFlowHelper;
using static ARMeilleure.Instructions.InstEmitHelper; using static ARMeilleure.Instructions.InstEmitHelper;
using static ARMeilleure.Instructions.InstEmitSimdHelper; using static ARMeilleure.Instructions.InstEmitSimdHelper;

View File

@@ -2,8 +2,6 @@ using ARMeilleure.Memory;
using ARMeilleure.State; using ARMeilleure.State;
using ARMeilleure.Translation; using ARMeilleure.Translation;
using System; using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace ARMeilleure.Instructions namespace ARMeilleure.Instructions
{ {

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace ARMeilleure.Signal namespace ARMeilleure.Signal

View File

@@ -344,7 +344,7 @@ namespace ARMeilleure.Translation
} }
/// <summary> /// <summary>
/// Removes the value from the dictionary after searching for it with <paramref name="key">. /// Removes the value from the dictionary after searching for it with <paramref name="key"/>.
/// </summary> /// </summary>
/// <param name="key">Key to search for</param> /// <param name="key">Key to search for</param>
/// <returns>Number of deleted values</returns> /// <returns>Number of deleted values</returns>

View File

@@ -4,7 +4,6 @@ using Ryujinx.Memory;
using Ryujinx.SDL2.Common; using Ryujinx.SDL2.Common;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using static Ryujinx.Audio.Integration.IHardwareDeviceDriver; using static Ryujinx.Audio.Integration.IHardwareDeviceDriver;

View File

@@ -4,7 +4,6 @@ using Ryujinx.Common.Logging;
using Ryujinx.Memory; using Ryujinx.Memory;
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using System.Runtime.InteropServices;
using System.Threading; using System.Threading;
using static SDL2.SDL; using static SDL2.SDL;

View File

@@ -1,5 +1,4 @@
using System; namespace SoundIOSharp
namespace SoundIOSharp
{ {
public struct SoundIOSampleRateRange public struct SoundIOSampleRateRange
{ {

View File

@@ -1,7 +1,6 @@
using Ryujinx.Audio.Renderer.Dsp.State; using Ryujinx.Audio.Renderer.Dsp.State;
using Ryujinx.Audio.Renderer.Parameter; using Ryujinx.Audio.Renderer.Parameter;
using System; using System;
using System.Runtime.CompilerServices;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command
{ {

View File

@@ -1,5 +1,4 @@
using Ryujinx.Audio.Renderer.Dsp.State; using Ryujinx.Audio.Renderer.Dsp.State;
using Ryujinx.Audio.Renderer.Parameter;
using Ryujinx.Memory; using Ryujinx.Memory;
using System; using System;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;

View File

@@ -1,6 +1,5 @@
using Ryujinx.Audio.Renderer.Parameter.Sink; using Ryujinx.Audio.Renderer.Parameter.Sink;
using Ryujinx.Audio.Renderer.Server.MemoryPool; using Ryujinx.Audio.Renderer.Server.MemoryPool;
using System;
using System.Diagnostics; using System.Diagnostics;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command

View File

@@ -6,7 +6,6 @@ using Ryujinx.Memory;
using System; using System;
using System.Buffers; using System.Buffers;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command

View File

@@ -1,5 +1,3 @@
using System;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command
{ {
public class CopyMixBufferCommand : ICommand public class CopyMixBufferCommand : ICommand

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command

View File

@@ -2,7 +2,6 @@ using Ryujinx.Audio.Renderer.Dsp.State;
using Ryujinx.Audio.Renderer.Parameter.Effect; using Ryujinx.Audio.Renderer.Parameter.Effect;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command
{ {

View File

@@ -3,7 +3,6 @@ using Ryujinx.Audio.Renderer.Parameter;
using Ryujinx.Audio.Renderer.Parameter.Effect; using Ryujinx.Audio.Renderer.Parameter.Effect;
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command

View File

@@ -1,6 +1,5 @@
using Ryujinx.Audio.Renderer.Server.Upsampler; using Ryujinx.Audio.Renderer.Server.Upsampler;
using System; using System;
using System.Runtime.CompilerServices;
namespace Ryujinx.Audio.Renderer.Dsp.Command namespace Ryujinx.Audio.Renderer.Dsp.Command
{ {

View File

@@ -7,7 +7,6 @@ using Ryujinx.Audio.Renderer.Server.Performance;
using Ryujinx.Audio.Renderer.Server.Sink; using Ryujinx.Audio.Renderer.Server.Sink;
using Ryujinx.Audio.Renderer.Server.Upsampler; using Ryujinx.Audio.Renderer.Server.Upsampler;
using Ryujinx.Audio.Renderer.Server.Voice; using Ryujinx.Audio.Renderer.Server.Voice;
using Ryujinx.Common.Memory;
using System; using System;
using CpuAddress = System.UInt64; using CpuAddress = System.UInt64;

View File

@@ -1,9 +1,5 @@
using Ryujinx.Audio.Common;
using Ryujinx.Audio.Renderer.Dsp.Command; using Ryujinx.Audio.Renderer.Dsp.Command;
using Ryujinx.Audio.Renderer.Parameter.Effect;
using System;
using System.Diagnostics; using System.Diagnostics;
using static Ryujinx.Audio.Renderer.Parameter.VoiceInParameter;
namespace Ryujinx.Audio.Renderer.Server namespace Ryujinx.Audio.Renderer.Server
{ {

View File

@@ -12,6 +12,7 @@ using Ryujinx.Audio.Integration;
using Ryujinx.Ava.Common; using Ryujinx.Ava.Common;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Input; using Ryujinx.Ava.Input;
using Ryujinx.Ava.Ui.Backend.Vulkan;
using Ryujinx.Ava.Ui.Controls; using Ryujinx.Ava.Ui.Controls;
using Ryujinx.Ava.Ui.Models; using Ryujinx.Ava.Ui.Models;
using Ryujinx.Ava.Ui.Vulkan; using Ryujinx.Ava.Ui.Vulkan;
@@ -334,6 +335,8 @@ namespace Ryujinx.Ava
return; return;
} }
AvaloniaLocator.Current.GetService<VulkanPlatformInterface>()?.MainSurface.Display.ChangeVSyncMode(true);
_isStopped = true; _isStopped = true;
_isActive = false; _isActive = false;
} }
@@ -596,12 +599,13 @@ namespace Ryujinx.Ava
if (Program.UseVulkan) if (Program.UseVulkan)
{ {
var vulkan = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>(); var vulkan = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>();
renderer = new VulkanRenderer(vulkan.Instance.InternalHandle, renderer = new VulkanRenderer(vulkan.Instance.InternalHandle,
vulkan.Device.InternalHandle, vulkan.MainSurface.Device.InternalHandle,
vulkan.PhysicalDevice.InternalHandle, vulkan.PhysicalDevice.InternalHandle,
vulkan.Device.Queue.InternalHandle, vulkan.MainSurface.Device.Queue.InternalHandle,
vulkan.PhysicalDevice.QueueFamilyIndex, vulkan.PhysicalDevice.QueueFamilyIndex,
vulkan.Device.Lock); vulkan.MainSurface.Device.Lock);
} }
else else
{ {
@@ -775,7 +779,10 @@ namespace Ryujinx.Ava
Width = (int)e.Width; Width = (int)e.Width;
Height = (int)e.Height; Height = (int)e.Height;
SetRendererWindowSize(e); if (!Program.UseVulkan)
{
SetRendererWindowSize(e);
}
} }
private void MainLoop() private void MainLoop()
@@ -815,12 +822,11 @@ namespace Ryujinx.Ava
_renderer.ScreenCaptured += Renderer_ScreenCaptured; _renderer.ScreenCaptured += Renderer_ScreenCaptured;
if (!Program.UseVulkan) (_renderer as OpenGLRenderer)?.InitializeBackgroundContext(SPBOpenGLContext.CreateBackgroundContext((Renderer as OpenGLRendererControl).GameContext));
{
(_renderer as OpenGLRenderer).InitializeBackgroundContext(SPBOpenGLContext.CreateBackgroundContext((Renderer as OpenGLRendererControl).GameContext));
Renderer.MakeCurrent(); Renderer.MakeCurrent();
}
AvaloniaLocator.Current.GetService<VulkanPlatformInterface>()?.MainSurface?.Display?.ChangeVSyncMode(Device.EnableDeviceVsync);
Device.Gpu.Renderer.Initialize(_glLogLevel); Device.Gpu.Renderer.Initialize(_glLogLevel);
@@ -837,8 +843,6 @@ namespace Ryujinx.Ava
Renderer.Start(); Renderer.Start();
Renderer.QueueRender();
while (_isActive) while (_isActive)
{ {
if (Device.WaitFifo()) if (Device.WaitFifo())
@@ -889,6 +893,16 @@ namespace Ryujinx.Ava
$"FIFO: {Device.Statistics.GetFifoPercent():00.00} %", $"FIFO: {Device.Statistics.GetFifoPercent():00.00} %",
$"GPU: {_renderer.GetHardwareInfo().GpuVendor}")); $"GPU: {_renderer.GetHardwareInfo().GpuVendor}"));
if (Program.UseVulkan)
{
var platformInterface = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>();
if (platformInterface.MainSurface.Display.IsSurfaceChanged())
{
SetRendererWindowSize(new Size(Width, Height));
return;
}
}
Renderer.Present(image); Renderer.Present(image);
} }
@@ -970,6 +984,9 @@ namespace Ryujinx.Ava
{ {
case KeyboardHotkeyState.ToggleVSync: case KeyboardHotkeyState.ToggleVSync:
Device.EnableDeviceVsync = !Device.EnableDeviceVsync; Device.EnableDeviceVsync = !Device.EnableDeviceVsync;
AvaloniaLocator.Current.GetService<VulkanPlatformInterface>()?.MainSurface?.Display?.ChangeVSyncMode(Device.EnableDeviceVsync);
break; break;
case KeyboardHotkeyState.Screenshot: case KeyboardHotkeyState.Screenshot:
ScreenshotRequested = true; ScreenshotRequested = true;

View File

@@ -52,8 +52,8 @@
"GameListContextMenuOpenModsDirectory": "Open Mods Directory", "GameListContextMenuOpenModsDirectory": "Open Mods Directory",
"GameListContextMenuOpenModsDirectoryToolTip": "Opens the directory which contains Application's Mods", "GameListContextMenuOpenModsDirectoryToolTip": "Opens the directory which contains Application's Mods",
"GameListContextMenuCacheManagement": "Cache Management", "GameListContextMenuCacheManagement": "Cache Management",
"GameListContextMenuCacheManagementPurgePptc": "Purge PPTC Cache", "GameListContextMenuCacheManagementPurgePptc": "Queue PPTC Rebuild",
"GameListContextMenuCacheManagementPurgePptcToolTip": "Deletes Application's PPTC cache", "GameListContextMenuCacheManagementPurgePptcToolTip": "Trigger PPTC to rebuild at boot time on the next game launch",
"GameListContextMenuCacheManagementPurgeShaderCache": "Purge Shader Cache", "GameListContextMenuCacheManagementPurgeShaderCache": "Purge Shader Cache",
"GameListContextMenuCacheManagementPurgeShaderCacheToolTip": "Deletes Application's shader cache", "GameListContextMenuCacheManagementPurgeShaderCacheToolTip": "Deletes Application's shader cache",
"GameListContextMenuCacheManagementOpenPptcDirectory": "Open PPTC Directory", "GameListContextMenuCacheManagementOpenPptcDirectory": "Open PPTC Directory",

View File

@@ -24,7 +24,6 @@ using System.Buffers;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using static LibHac.Fs.ApplicationSaveDataManagement;
using Path = System.IO.Path; using Path = System.IO.Path;
namespace Ryujinx.Ava.Common namespace Ryujinx.Ava.Common

View File

@@ -1,7 +1,6 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Threading;
using Ryujinx.Input; using Ryujinx.Input;
using System; using System;
using System.Numerics; using System.Numerics;

View File

@@ -16,8 +16,6 @@ using Ryujinx.Graphics.Vulkan;
using Ryujinx.Modules; using Ryujinx.Modules;
using Ryujinx.Ui.Common; using Ryujinx.Ui.Common;
using Ryujinx.Ui.Common.Configuration; using Ryujinx.Ui.Common.Configuration;
using Silk.NET.Vulkan.Extensions.EXT;
using Silk.NET.Vulkan.Extensions.KHR;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
@@ -94,7 +92,6 @@ namespace Ryujinx.Ava
.With(new Ui.Vulkan.VulkanOptions() .With(new Ui.Vulkan.VulkanOptions()
{ {
ApplicationName = "Ryujinx.Graphics.Vulkan", ApplicationName = "Ryujinx.Graphics.Vulkan",
VulkanVersion = new Version(1, 2),
MaxQueueCount = 2, MaxQueueCount = 2,
PreferDiscreteGpu = true, PreferDiscreteGpu = true,
PreferredDevice = !PreviewerDetached ? "" : ConfigurationState.Instance.Graphics.PreferredGpu.Value, PreferredDevice = !PreviewerDetached ? "" : ConfigurationState.Instance.Graphics.PreferredGpu.Value,
@@ -181,6 +178,18 @@ namespace Ryujinx.Ava
UseVulkan = PreviewerDetached ? ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Vulkan : false; UseVulkan = PreviewerDetached ? ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Vulkan : false;
if (UseVulkan)
{
if (VulkanRenderer.GetPhysicalDevices().Length == 0)
{
UseVulkan = false;
ConfigurationState.Instance.Graphics.GraphicsBackend.Value = GraphicsBackend.OpenGl;
Logger.Warning?.PrintMsg(LogClass.Application, "A suitable Vulkan physical device is not available. Falling back to OpenGL");
}
}
if (UseVulkan) if (UseVulkan)
{ {
// With a custom gpu backend, avalonia doesn't enable dpi awareness, so the backend must handle it. This isn't so for the opengl backed, // With a custom gpu backend, avalonia doesn't enable dpi awareness, so the backend must handle it. This isn't so for the opengl backed,

View File

@@ -10,7 +10,6 @@ using Ryujinx.HLE.HOS.Services.Am.AppletOE.ApplicationProxyService.ApplicationPr
using Ryujinx.HLE.Ui; using Ryujinx.HLE.Ui;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
namespace Ryujinx.Ava.Ui.Applet namespace Ryujinx.Ava.Ui.Applet
{ {

View File

@@ -1,7 +1,6 @@
using Avalonia; using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Threading; using Avalonia.Threading;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Ui.Windows; using Ryujinx.Ava.Ui.Windows;

View File

@@ -1,7 +1,6 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
using Avalonia.Media; using Avalonia.Media;
using FluentAvalonia.Core; using FluentAvalonia.Core;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;

View File

@@ -7,7 +7,8 @@ namespace Ryujinx.Ava.Ui.Vulkan
{ {
public static void ThrowOnError(this Result result) public static void ThrowOnError(this Result result)
{ {
if (result != Result.Success) // Only negative result codes are errors.
if ((int)result < (int)Result.Success)
{ {
throw new Exception($"Unexpected API error \"{result}\"."); throw new Exception($"Unexpected API error \"{result}\".");
} }

View File

@@ -1,26 +1,90 @@
using System; using System;
using Avalonia;
using Avalonia.Skia; using Avalonia.Skia;
using Ryujinx.Ava.Ui.Vulkan; using Ryujinx.Ava.Ui.Vulkan;
using Ryujinx.Ava.Ui.Vulkan.Surfaces; using Ryujinx.Ava.Ui.Vulkan.Surfaces;
using Silk.NET.Vulkan;
using SkiaSharp; using SkiaSharp;
namespace Ryujinx.Ava.Ui.Backend.Vulkan namespace Ryujinx.Ava.Ui.Backend.Vulkan
{ {
internal class VulkanRenderTarget : ISkiaGpuRenderTarget internal class VulkanRenderTarget : ISkiaGpuRenderTarget
{ {
public GRContext GrContext { get; set; } public GRContext GrContext { get; private set; }
private readonly VulkanSurfaceRenderTarget _surface; private readonly VulkanSurfaceRenderTarget _surface;
private readonly VulkanPlatformInterface _vulkanPlatformInterface;
private readonly IVulkanPlatformSurface _vulkanPlatformSurface; private readonly IVulkanPlatformSurface _vulkanPlatformSurface;
private GRVkBackendContext _grVkBackend;
public VulkanRenderTarget(VulkanPlatformInterface vulkanPlatformInterface, IVulkanPlatformSurface vulkanPlatformSurface) public VulkanRenderTarget(VulkanPlatformInterface vulkanPlatformInterface, IVulkanPlatformSurface vulkanPlatformSurface)
{ {
_surface = vulkanPlatformInterface.CreateRenderTarget(vulkanPlatformSurface); _surface = vulkanPlatformInterface.CreateRenderTarget(vulkanPlatformSurface);
_vulkanPlatformInterface = vulkanPlatformInterface;
_vulkanPlatformSurface = vulkanPlatformSurface; _vulkanPlatformSurface = vulkanPlatformSurface;
Initialize();
}
private void Initialize()
{
GRVkGetProcedureAddressDelegate getProc = GetVulkanProcAddress;
_grVkBackend = new GRVkBackendContext()
{
VkInstance = _surface.Device.Handle,
VkPhysicalDevice = _vulkanPlatformInterface.PhysicalDevice.Handle,
VkDevice = _surface.Device.Handle,
VkQueue = _surface.Device.Queue.Handle,
GraphicsQueueIndex = _vulkanPlatformInterface.PhysicalDevice.QueueFamilyIndex,
GetProcedureAddress = getProc
};
GrContext = GRContext.CreateVulkan(_grVkBackend);
var gpu = AvaloniaLocator.Current.GetService<VulkanSkiaGpu>();
if (gpu.MaxResourceBytes.HasValue)
{
GrContext.SetResourceCacheLimit(gpu.MaxResourceBytes.Value);
}
}
private IntPtr GetVulkanProcAddress(string name, IntPtr instanceHandle, IntPtr deviceHandle)
{
IntPtr addr;
if (deviceHandle != IntPtr.Zero)
{
addr = _vulkanPlatformInterface.Api.GetDeviceProcAddr(new Device(deviceHandle), name);
if (addr != IntPtr.Zero)
{
return addr;
}
addr = _vulkanPlatformInterface.Api.GetDeviceProcAddr(new Device(_surface.Device.Handle), name);
if (addr != IntPtr.Zero)
{
return addr;
}
}
addr = _vulkanPlatformInterface.Api.GetInstanceProcAddr(new Instance(_vulkanPlatformInterface.Instance.Handle), name);
if (addr == IntPtr.Zero)
{
addr = _vulkanPlatformInterface.Api.GetInstanceProcAddr(new Instance(instanceHandle), name);
}
return addr;
} }
public void Dispose() public void Dispose()
{ {
_grVkBackend.Dispose();
GrContext.Dispose();
_surface.Dispose(); _surface.Dispose();
} }
@@ -45,20 +109,22 @@ namespace Ryujinx.Ava.Ui.Backend.Vulkan
{ {
GrContext.ResetContext(); GrContext.ResetContext();
var image = _surface.GetImage();
var imageInfo = new GRVkImageInfo() var imageInfo = new GRVkImageInfo()
{ {
CurrentQueueFamily = disp.QueueFamilyIndex, CurrentQueueFamily = disp.QueueFamilyIndex,
Format = _surface.ImageFormat, Format = (uint)image.Format,
Image = _surface.Image.Handle, Image = image.Handle,
ImageLayout = (uint)_surface.Image.CurrentLayout, ImageLayout = (uint)image.CurrentLayout,
ImageTiling = (uint)_surface.Image.Tiling, ImageTiling = (uint)image.Tiling,
ImageUsageFlags = _surface.UsageFlags, ImageUsageFlags = _surface.UsageFlags,
LevelCount = _surface.MipLevels, LevelCount = _surface.MipLevels,
SampleCount = 1, SampleCount = 1,
Protected = false, Protected = false,
Alloc = new GRVkAlloc() Alloc = new GRVkAlloc()
{ {
Memory = _surface.Image.MemoryHandle, Memory = image.MemoryHandle,
Flags = 0, Flags = 0,
Offset = 0, Offset = 0,
Size = _surface.MemorySize Size = _surface.MemorySize

View File

@@ -13,71 +13,12 @@ namespace Ryujinx.Ava.Ui.Backend.Vulkan
public class VulkanSkiaGpu : ISkiaGpu public class VulkanSkiaGpu : ISkiaGpu
{ {
private readonly VulkanPlatformInterface _vulkan; private readonly VulkanPlatformInterface _vulkan;
private readonly long? _maxResourceBytes; public long? MaxResourceBytes { get; }
private GRVkBackendContext _grVkBackend;
private bool _initialized;
public GRContext GrContext { get; private set; }
public VulkanSkiaGpu(long? maxResourceBytes) public VulkanSkiaGpu(long? maxResourceBytes)
{ {
_vulkan = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>(); _vulkan = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>();
_maxResourceBytes = maxResourceBytes; MaxResourceBytes = maxResourceBytes;
}
private void Initialize()
{
if (_initialized)
{
return;
}
_initialized = true;
GRVkGetProcedureAddressDelegate getProc = (string name, IntPtr instanceHandle, IntPtr deviceHandle) =>
{
IntPtr addr = IntPtr.Zero;
if (deviceHandle != IntPtr.Zero)
{
addr = _vulkan.Device.Api.GetDeviceProcAddr(new Device(deviceHandle), name);
if (addr != IntPtr.Zero)
{
return addr;
}
addr = _vulkan.Device.Api.GetDeviceProcAddr(new Device(_vulkan.Device.Handle), name);
if (addr != IntPtr.Zero)
{
return addr;
}
}
addr = _vulkan.Device.Api.GetInstanceProcAddr(new Instance(_vulkan.Instance.Handle), name);
if (addr == IntPtr.Zero)
{
addr = _vulkan.Device.Api.GetInstanceProcAddr(new Instance(instanceHandle), name);
}
return addr;
};
_grVkBackend = new GRVkBackendContext()
{
VkInstance = _vulkan.Device.Handle,
VkPhysicalDevice = _vulkan.PhysicalDevice.Handle,
VkDevice = _vulkan.Device.Handle,
VkQueue = _vulkan.Device.Queue.Handle,
GraphicsQueueIndex = _vulkan.PhysicalDevice.QueueFamilyIndex,
GetProcedureAddress = getProc
};
GrContext = GRContext.CreateVulkan(_grVkBackend);
if (_maxResourceBytes.HasValue)
{
GrContext.SetResourceCacheLimit(_maxResourceBytes.Value);
}
} }
public ISkiaGpuRenderTarget TryCreateRenderTarget(IEnumerable<object> surfaces) public ISkiaGpuRenderTarget TryCreateRenderTarget(IEnumerable<object> surfaces)
@@ -106,10 +47,6 @@ namespace Ryujinx.Ava.Ui.Backend.Vulkan
VulkanRenderTarget vulkanRenderTarget = new VulkanRenderTarget(_vulkan, window); VulkanRenderTarget vulkanRenderTarget = new VulkanRenderTarget(_vulkan, window);
Initialize();
vulkanRenderTarget.GrContext = GrContext;
return vulkanRenderTarget; return vulkanRenderTarget;
} }

View File

@@ -1,5 +1,6 @@
using System; using System;
using Avalonia; using Avalonia;
using Ryujinx.Graphics.Vulkan;
using Silk.NET.Vulkan; using Silk.NET.Vulkan;
namespace Ryujinx.Ava.Ui.Vulkan.Surfaces namespace Ryujinx.Ava.Ui.Vulkan.Surfaces
@@ -7,24 +8,35 @@ namespace Ryujinx.Ava.Ui.Vulkan.Surfaces
internal class VulkanSurfaceRenderTarget : IDisposable internal class VulkanSurfaceRenderTarget : IDisposable
{ {
private readonly VulkanPlatformInterface _platformInterface; private readonly VulkanPlatformInterface _platformInterface;
private readonly Format _format; private readonly Format _format;
public VulkanImage Image { get; private set; } private VulkanCommandBufferPool.VulkanCommandBuffer _commandBuffer;
public bool IsCorrupted { get; private set; } = true; private VulkanImage Image { get; set; }
private object _lock = new object();
public uint MipLevels => Image.MipLevels; public uint MipLevels => Image.MipLevels;
public VulkanDevice Device { get; }
public VulkanSurfaceRenderTarget(VulkanPlatformInterface platformInterface, VulkanSurface surface) public VulkanSurfaceRenderTarget(VulkanPlatformInterface platformInterface, VulkanSurface surface)
{ {
_platformInterface = platformInterface; _platformInterface = platformInterface;
Display = VulkanDisplay.CreateDisplay(platformInterface.Instance, platformInterface.Device, var device = VulkanInitialization.CreateDevice(platformInterface.Api,
platformInterface.PhysicalDevice, surface); platformInterface.PhysicalDevice.InternalHandle,
platformInterface.PhysicalDevice.QueueFamilyIndex,
VulkanInitialization.GetSupportedExtensions(platformInterface.Api, platformInterface.PhysicalDevice.InternalHandle),
platformInterface.PhysicalDevice.QueueCount);
Device = new VulkanDevice(device, platformInterface.PhysicalDevice, platformInterface.Api);
Display = VulkanDisplay.CreateDisplay(
platformInterface.Instance,
Device,
platformInterface.PhysicalDevice,
surface);
Surface = surface; Surface = surface;
// Skia seems to only create surfaces from images with unorm format // Skia seems to only create surfaces from images with unorm format
IsRgba = Display.SurfaceFormat.Format >= Format.R8G8B8A8Unorm && IsRgba = Display.SurfaceFormat.Format >= Format.R8G8B8A8Unorm &&
Display.SurfaceFormat.Format <= Format.R8G8B8A8Srgb; Display.SurfaceFormat.Format <= Format.R8G8B8A8Srgb;
@@ -33,13 +45,13 @@ namespace Ryujinx.Ava.Ui.Vulkan.Surfaces
public bool IsRgba { get; } public bool IsRgba { get; }
public uint ImageFormat => (uint) _format; public uint ImageFormat => (uint)_format;
public ulong MemorySize => Image.MemorySize; public ulong MemorySize => Image.MemorySize;
public VulkanDisplay Display { get; } public VulkanDisplay Display { get; private set; }
public VulkanSurface Surface { get; } public VulkanSurface Surface { get; private set; }
public uint UsageFlags => Image.UsageFlags; public uint UsageFlags => Image.UsageFlags;
@@ -47,46 +59,76 @@ namespace Ryujinx.Ava.Ui.Vulkan.Surfaces
public void Dispose() public void Dispose()
{ {
_platformInterface.Device.WaitIdle(); lock (_lock)
DestroyImage(); {
Display?.Dispose(); DestroyImage();
Surface?.Dispose(); Display?.Dispose();
Surface?.Dispose();
Device?.Dispose();
Display = null;
Surface = null;
}
} }
public VulkanSurfaceRenderingSession BeginDraw(float scaling) public VulkanSurfaceRenderingSession BeginDraw(float scaling)
{ {
var session = new VulkanSurfaceRenderingSession(Display, _platformInterface.Device, this, scaling); if (Image == null)
{
RecreateImage();
}
if (IsCorrupted) _commandBuffer?.WaitForFence();
{ _commandBuffer = null;
IsCorrupted = false;
DestroyImage(); var session = new VulkanSurfaceRenderingSession(Display, Device, this, scaling);
CreateImage();
} Image.TransitionLayout(ImageLayout.ColorAttachmentOptimal, AccessFlags.AccessNoneKhr);
else
{
Image.TransitionLayout(ImageLayout.ColorAttachmentOptimal, AccessFlags.AccessNoneKhr);
}
return session; return session;
} }
public void Invalidate() public void RecreateImage()
{ {
IsCorrupted = true; DestroyImage();
CreateImage();
} }
private void CreateImage() private void CreateImage()
{ {
Size = Display.Size; Size = Display.Size;
Image = new VulkanImage(_platformInterface.Device, _platformInterface.PhysicalDevice, _platformInterface.Device.CommandBufferPool, ImageFormat, Size); Image = new VulkanImage(Device, _platformInterface.PhysicalDevice, Display.CommandBufferPool, ImageFormat, Size);
} }
private void DestroyImage() private void DestroyImage()
{ {
_platformInterface.Device.WaitIdle(); _commandBuffer?.WaitForFence();
_commandBuffer = null;
Image?.Dispose(); Image?.Dispose();
Image = null;
}
public VulkanImage GetImage()
{
return Image;
}
public void EndDraw()
{
lock (_lock)
{
if (Display == null)
{
return;
}
_commandBuffer = Display.StartPresentation();
Display.BlitImageToCurrentImage(this, _commandBuffer.InternalHandle);
Display.EndPresentation(_commandBuffer);
}
} }
} }
} }

View File

@@ -10,6 +10,7 @@ namespace Ryujinx.Ava.Ui.Vulkan
private readonly CommandPool _commandPool; private readonly CommandPool _commandPool;
private readonly List<VulkanCommandBuffer> _usedCommandBuffers = new(); private readonly List<VulkanCommandBuffer> _usedCommandBuffers = new();
private readonly object _lock = new object();
public unsafe VulkanCommandBufferPool(VulkanDevice device, VulkanPhysicalDevice physicalDevice) public unsafe VulkanCommandBufferPool(VulkanDevice device, VulkanPhysicalDevice physicalDevice)
{ {
@@ -36,9 +37,12 @@ namespace Ryujinx.Ava.Ui.Vulkan
Level = CommandBufferLevel.Primary Level = CommandBufferLevel.Primary
}; };
_device.Api.AllocateCommandBuffers(_device.InternalHandle, commandBufferAllocateInfo, out var commandBuffer); lock (_lock)
{
_device.Api.AllocateCommandBuffers(_device.InternalHandle, commandBufferAllocateInfo, out var commandBuffer);
return commandBuffer; return commandBuffer;
}
} }
public VulkanCommandBuffer CreateCommandBuffer() public VulkanCommandBuffer CreateCommandBuffer()
@@ -48,7 +52,7 @@ namespace Ryujinx.Ava.Ui.Vulkan
public void FreeUsedCommandBuffers() public void FreeUsedCommandBuffers()
{ {
lock (_usedCommandBuffers) lock (_lock)
{ {
foreach (var usedCommandBuffer in _usedCommandBuffers) foreach (var usedCommandBuffer in _usedCommandBuffers)
{ {
@@ -61,7 +65,7 @@ namespace Ryujinx.Ava.Ui.Vulkan
private void DisposeCommandBuffer(VulkanCommandBuffer commandBuffer) private void DisposeCommandBuffer(VulkanCommandBuffer commandBuffer)
{ {
lock (_usedCommandBuffers) lock (_lock)
{ {
_usedCommandBuffers.Add(commandBuffer); _usedCommandBuffers.Add(commandBuffer);
} }
@@ -69,8 +73,11 @@ namespace Ryujinx.Ava.Ui.Vulkan
public void Dispose() public void Dispose()
{ {
FreeUsedCommandBuffers(); lock (_lock)
_device.Api.DestroyCommandPool(_device.InternalHandle, _commandPool, Span<AllocationCallbacks>.Empty); {
FreeUsedCommandBuffers();
_device.Api.DestroyCommandPool(_device.InternalHandle, _commandPool, Span<AllocationCallbacks>.Empty);
}
} }
public class VulkanCommandBuffer : IDisposable public class VulkanCommandBuffer : IDisposable
@@ -80,6 +87,8 @@ namespace Ryujinx.Ava.Ui.Vulkan
private readonly Fence _fence; private readonly Fence _fence;
private bool _hasEnded; private bool _hasEnded;
private bool _hasStarted; private bool _hasStarted;
private bool _isDisposed;
private object _lock = new object();
public IntPtr Handle => InternalHandle.Handle; public IntPtr Handle => InternalHandle.Handle;
@@ -101,6 +110,22 @@ namespace Ryujinx.Ava.Ui.Vulkan
device.Api.CreateFence(device.InternalHandle, fenceCreateInfo, null, out _fence); device.Api.CreateFence(device.InternalHandle, fenceCreateInfo, null, out _fence);
} }
public void WaitForFence()
{
if (_isDisposed)
{
return;
}
lock (_lock)
{
if (!_isDisposed)
{
_device.Api.WaitForFences(_device.InternalHandle, 1, _fence, true, ulong.MaxValue);
}
}
}
public void BeginRecording() public void BeginRecording()
{ {
if (!_hasStarted) if (!_hasStarted)
@@ -173,9 +198,17 @@ namespace Ryujinx.Ava.Ui.Vulkan
public void Dispose() public void Dispose()
{ {
_device.Api.WaitForFences(_device.InternalHandle, 1, _fence, true, ulong.MaxValue); lock (_lock)
_device.Api.FreeCommandBuffers(_device.InternalHandle, _commandBufferPool._commandPool, 1, InternalHandle); {
_device.Api.DestroyFence(_device.InternalHandle, _fence, Span<AllocationCallbacks>.Empty); if (!_isDisposed)
{
_isDisposed = true;
_device.Api.WaitForFences(_device.InternalHandle, 1, _fence, true, ulong.MaxValue);
_device.Api.FreeCommandBuffers(_device.InternalHandle, _commandBufferPool._commandPool, 1, InternalHandle);
_device.Api.DestroyFence(_device.InternalHandle, _fence, Span<AllocationCallbacks>.Empty);
}
}
} }
} }
} }

View File

@@ -14,12 +14,9 @@ namespace Ryujinx.Ava.Ui.Vulkan
api.GetDeviceQueue(apiHandle, physicalDevice.QueueFamilyIndex, 0, out var queue); api.GetDeviceQueue(apiHandle, physicalDevice.QueueFamilyIndex, 0, out var queue);
var vulkanQueue = new VulkanQueue(this, queue); Queue = new VulkanQueue(this, queue);
Queue = vulkanQueue;
PresentQueue = vulkanQueue; PresentQueue = Queue;
CommandBufferPool = new VulkanCommandBufferPool(this, physicalDevice);
} }
public IntPtr Handle => InternalHandle.Handle; public IntPtr Handle => InternalHandle.Handle;
@@ -29,13 +26,12 @@ namespace Ryujinx.Ava.Ui.Vulkan
public VulkanQueue Queue { get; private set; } public VulkanQueue Queue { get; private set; }
public VulkanQueue PresentQueue { get; } public VulkanQueue PresentQueue { get; }
public VulkanCommandBufferPool CommandBufferPool { get; }
public void Dispose() public void Dispose()
{ {
WaitIdle(); WaitIdle();
CommandBufferPool?.Dispose();
Queue = null; Queue = null;
Api.DestroyDevice(InternalHandle, Span<AllocationCallbacks>.Empty);
} }
internal void Submit(SubmitInfo submitInfo, Fence fence = default) internal void Submit(SubmitInfo submitInfo, Fence fence = default)

View File

@@ -3,7 +3,6 @@ using System.Linq;
using System.Threading; using System.Threading;
using Avalonia; using Avalonia;
using Ryujinx.Ava.Ui.Vulkan.Surfaces; using Ryujinx.Ava.Ui.Vulkan.Surfaces;
using Ryujinx.Ui.Common.Configuration;
using Silk.NET.Vulkan; using Silk.NET.Vulkan;
using Silk.NET.Vulkan.Extensions.KHR; using Silk.NET.Vulkan.Extensions.KHR;
@@ -15,16 +14,19 @@ namespace Ryujinx.Ava.Ui.Vulkan
private readonly VulkanInstance _instance; private readonly VulkanInstance _instance;
private readonly VulkanPhysicalDevice _physicalDevice; private readonly VulkanPhysicalDevice _physicalDevice;
private readonly VulkanSemaphorePair _semaphorePair; private readonly VulkanSemaphorePair _semaphorePair;
private readonly VulkanDevice _device;
private uint _nextImage; private uint _nextImage;
private readonly VulkanSurface _surface; private readonly VulkanSurface _surface;
private SurfaceFormatKHR _surfaceFormat; private SurfaceFormatKHR _surfaceFormat;
private SwapchainKHR _swapchain; private SwapchainKHR _swapchain;
private Extent2D _swapchainExtent; private Extent2D _swapchainExtent;
private Image[] _swapchainImages; private Image[] _swapchainImages;
private VulkanDevice _device { get; } private ImageView[] _swapchainImageViews = Array.Empty<ImageView>();
private ImageView[] _swapchainImageViews = new ImageView[0];
private bool _vsyncStateChanged; private bool _vsyncStateChanged;
private bool _vsyncEnabled; private bool _vsyncEnabled;
private bool _surfaceChanged;
public event EventHandler Presented;
public VulkanCommandBufferPool CommandBufferPool { get; set; } public VulkanCommandBufferPool CommandBufferPool { get; set; }
@@ -73,6 +75,14 @@ namespace Ryujinx.Ava.Ui.Vulkan
CommandBufferPool.Dispose(); CommandBufferPool.Dispose();
} }
public bool IsSurfaceChanged()
{
var changed = _surfaceChanged;
_surfaceChanged = false;
return changed;
}
private static unsafe SwapchainKHR CreateSwapchain(VulkanInstance instance, VulkanDevice device, private static unsafe SwapchainKHR CreateSwapchain(VulkanInstance instance, VulkanDevice device,
VulkanPhysicalDevice physicalDevice, VulkanSurface surface, out Extent2D swapchainExtent, VulkanPhysicalDevice physicalDevice, VulkanSurface surface, out Extent2D swapchainExtent,
SwapchainKHR? oldswapchain = null, bool vsyncEnabled = true) SwapchainKHR? oldswapchain = null, bool vsyncEnabled = true)
@@ -193,22 +203,23 @@ namespace Ryujinx.Ava.Ui.Vulkan
} }
var modes = presentModes.ToList(); var modes = presentModes.ToList();
var presentMode = PresentModeKHR.PresentModeFifoKhr;
if (!vsyncEnabled && modes.Contains(PresentModeKHR.PresentModeImmediateKhr)) if (!vsyncEnabled && modes.Contains(PresentModeKHR.PresentModeImmediateKhr))
{ {
presentMode = PresentModeKHR.PresentModeImmediateKhr; return PresentModeKHR.PresentModeImmediateKhr;
} }
else if (modes.Contains(PresentModeKHR.PresentModeMailboxKhr)) else if (modes.Contains(PresentModeKHR.PresentModeMailboxKhr))
{ {
presentMode = PresentModeKHR.PresentModeMailboxKhr; return PresentModeKHR.PresentModeMailboxKhr;
} }
else if (modes.Contains(PresentModeKHR.PresentModeImmediateKhr)) else if (modes.Contains(PresentModeKHR.PresentModeFifoKhr))
{ {
presentMode = PresentModeKHR.PresentModeImmediateKhr; return PresentModeKHR.PresentModeFifoKhr;
}
else
{
return PresentModeKHR.PresentModeImmediateKhr;
} }
return presentMode;
} }
internal static VulkanDisplay CreateDisplay(VulkanInstance instance, VulkanDevice device, internal static VulkanDisplay CreateDisplay(VulkanInstance instance, VulkanDevice device,
@@ -266,6 +277,8 @@ namespace Ryujinx.Ava.Ui.Vulkan
_swapchain = CreateSwapchain(_instance, _device, _physicalDevice, _surface, out _swapchainExtent, _swapchain, _vsyncEnabled); _swapchain = CreateSwapchain(_instance, _device, _physicalDevice, _surface, out _swapchainExtent, _swapchain, _vsyncEnabled);
CreateSwapchainImages(); CreateSwapchainImages();
_surfaceChanged = true;
} }
private unsafe ImageView CreateSwapchainImageView(Image swapchainImage, Format format) private unsafe ImageView CreateSwapchainImageView(Image swapchainImage, Format format)
@@ -306,7 +319,7 @@ namespace Ryujinx.Ava.Ui.Vulkan
return true; return true;
} }
internal VulkanCommandBufferPool.VulkanCommandBuffer StartPresentation(VulkanSurfaceRenderTarget renderTarget) internal VulkanCommandBufferPool.VulkanCommandBuffer StartPresentation()
{ {
_nextImage = 0; _nextImage = 0;
while (true) while (true)
@@ -346,8 +359,10 @@ namespace Ryujinx.Ava.Ui.Vulkan
internal void BlitImageToCurrentImage(VulkanSurfaceRenderTarget renderTarget, CommandBuffer commandBuffer) internal void BlitImageToCurrentImage(VulkanSurfaceRenderTarget renderTarget, CommandBuffer commandBuffer)
{ {
var image = renderTarget.GetImage();
VulkanMemoryHelper.TransitionLayout(_device, commandBuffer, VulkanMemoryHelper.TransitionLayout(_device, commandBuffer,
renderTarget.Image.InternalHandle.Value, (ImageLayout)renderTarget.Image.CurrentLayout, image.InternalHandle.Value, (ImageLayout)image.CurrentLayout,
AccessFlags.AccessNoneKhr, AccessFlags.AccessNoneKhr,
ImageLayout.TransferSrcOptimal, ImageLayout.TransferSrcOptimal,
AccessFlags.AccessTransferReadBit, AccessFlags.AccessTransferReadBit,
@@ -381,7 +396,7 @@ namespace Ryujinx.Ava.Ui.Vulkan
} }
}; };
_device.Api.CmdBlitImage(commandBuffer, renderTarget.Image.InternalHandle.Value, _device.Api.CmdBlitImage(commandBuffer, image.InternalHandle.Value,
ImageLayout.TransferSrcOptimal, ImageLayout.TransferSrcOptimal,
_swapchainImages[_nextImage], _swapchainImages[_nextImage],
ImageLayout.TransferDstOptimal, ImageLayout.TransferDstOptimal,
@@ -390,9 +405,9 @@ namespace Ryujinx.Ava.Ui.Vulkan
Filter.Linear); Filter.Linear);
VulkanMemoryHelper.TransitionLayout(_device, commandBuffer, VulkanMemoryHelper.TransitionLayout(_device, commandBuffer,
renderTarget.Image.InternalHandle.Value, ImageLayout.TransferSrcOptimal, image.InternalHandle.Value, ImageLayout.TransferSrcOptimal,
AccessFlags.AccessTransferReadBit, AccessFlags.AccessTransferReadBit,
(ImageLayout)renderTarget.Image.CurrentLayout, (ImageLayout)image.CurrentLayout,
AccessFlags.AccessNoneKhr, AccessFlags.AccessNoneKhr,
renderTarget.MipLevels); renderTarget.MipLevels);
} }
@@ -434,6 +449,8 @@ namespace Ryujinx.Ava.Ui.Vulkan
} }
CommandBufferPool.FreeUsedCommandBuffers(); CommandBufferPool.FreeUsedCommandBuffers();
Presented?.Invoke(this, null);
} }
} }
} }

View File

@@ -148,20 +148,18 @@ namespace Ryujinx.Ava.Ui.Vulkan
_currentAccessFlags = destinationAccessFlags; _currentAccessFlags = destinationAccessFlags;
} }
public void TransitionLayout(uint destinationLayout, uint destinationAccessFlags) public void Dispose()
{ {
TransitionLayout((ImageLayout)destinationLayout, (AccessFlags)destinationAccessFlags); if (InternalHandle != null)
} {
_device.Api.DestroyImageView(_device.InternalHandle, _imageView.Value, Span<AllocationCallbacks>.Empty);
_device.Api.DestroyImage(_device.InternalHandle, InternalHandle.Value, Span<AllocationCallbacks>.Empty);
_device.Api.FreeMemory(_device.InternalHandle, _imageMemory, Span<AllocationCallbacks>.Empty);
public unsafe void Dispose() _imageView = default;
{ InternalHandle = null;
_device.Api.DestroyImageView(_device.InternalHandle, _imageView.Value, null); _imageMemory = default;
_device.Api.DestroyImage(_device.InternalHandle, InternalHandle.Value, null); }
_device.Api.FreeMemory(_device.InternalHandle, _imageMemory, null);
_imageView = default;
InternalHandle = default;
_imageMemory = default;
} }
} }
} }

View File

@@ -57,8 +57,7 @@ namespace Ryujinx.Ava.Ui.Vulkan
var applicationInfo = new ApplicationInfo var applicationInfo = new ApplicationInfo
{ {
PApplicationName = (byte*)applicationName, PApplicationName = (byte*)applicationName,
ApiVersion = new Version32((uint)options.VulkanVersion.Major, (uint)options.VulkanVersion.Minor, ApiVersion = Vk.Version12.Value,
(uint)options.VulkanVersion.Build),
PEngineName = (byte*)engineName, PEngineName = (byte*)engineName,
EngineVersion = new Version32(1, 0, 0), EngineVersion = new Version32(1, 0, 0),
ApplicationVersion = new Version32(1, 0, 0) ApplicationVersion = new Version32(1, 0, 0)

View File

@@ -11,11 +11,6 @@ namespace Ryujinx.Ava.Ui.Vulkan
/// </summary> /// </summary>
public string ApplicationName { get; set; } public string ApplicationName { get; set; }
/// <summary>
/// Specifies the Vulkan API version to use
/// </summary>
public Version VulkanVersion { get; set; } = new Version(1, 1, 0);
/// <summary> /// <summary>
/// Specifies additional extensions to enable if available on the instance /// Specifies additional extensions to enable if available on the instance
/// </summary> /// </summary>

View File

@@ -18,13 +18,11 @@ namespace Ryujinx.Ava.Ui.Vulkan
public VulkanPhysicalDevice PhysicalDevice { get; private set; } public VulkanPhysicalDevice PhysicalDevice { get; private set; }
public VulkanInstance Instance { get; } public VulkanInstance Instance { get; }
public VulkanDevice Device { get; set; }
public Vk Api { get; private set; } public Vk Api { get; private set; }
public VulkanSurfaceRenderTarget MainSurface { get; set; } public VulkanSurfaceRenderTarget MainSurface { get; set; }
public void Dispose() public void Dispose()
{ {
Device?.Dispose();
Instance?.Dispose(); Instance?.Dispose();
Api?.Dispose(); Api?.Dispose();
} }
@@ -54,16 +52,9 @@ namespace Ryujinx.Ava.Ui.Vulkan
{ {
var surface = VulkanSurface.CreateSurface(Instance, platformSurface); var surface = VulkanSurface.CreateSurface(Instance, platformSurface);
if (Device == null) if (PhysicalDevice == null)
{ {
PhysicalDevice = VulkanPhysicalDevice.FindSuitablePhysicalDevice(Instance, surface, _options.PreferDiscreteGpu, _options.PreferredDevice); PhysicalDevice = VulkanPhysicalDevice.FindSuitablePhysicalDevice(Instance, surface, _options.PreferDiscreteGpu, _options.PreferredDevice);
var device = VulkanInitialization.CreateDevice(Instance.Api,
PhysicalDevice.InternalHandle,
PhysicalDevice.QueueFamilyIndex,
VulkanInitialization.GetSupportedExtensions(Instance.Api, PhysicalDevice.InternalHandle),
PhysicalDevice.QueueCount);
Device = new VulkanDevice(device, PhysicalDevice, Instance.Api);
} }
var renderTarget = new VulkanSurfaceRenderTarget(this, surface); var renderTarget = new VulkanSurfaceRenderTarget(this, surface);
@@ -71,7 +62,6 @@ namespace Ryujinx.Ava.Ui.Vulkan
if (MainSurface == null && surface != null) if (MainSurface == null && surface != null)
{ {
MainSurface = renderTarget; MainSurface = renderTarget;
MainSurface.Display.ChangeVSyncMode(false);
} }
return renderTarget; return renderTarget;

View File

@@ -9,7 +9,6 @@ namespace Ryujinx.Ava.Ui.Vulkan
{ {
private readonly VulkanDevice _device; private readonly VulkanDevice _device;
private readonly VulkanSurfaceRenderTarget _renderTarget; private readonly VulkanSurfaceRenderTarget _renderTarget;
private VulkanCommandBufferPool.VulkanCommandBuffer _commandBuffer;
public VulkanSurfaceRenderingSession(VulkanDisplay display, VulkanDevice device, public VulkanSurfaceRenderingSession(VulkanDisplay display, VulkanDevice device,
VulkanSurfaceRenderTarget renderTarget, float scaling) VulkanSurfaceRenderTarget renderTarget, float scaling)
@@ -32,17 +31,13 @@ namespace Ryujinx.Ava.Ui.Vulkan
{ {
if (!Display.EnsureSwapchainAvailable()) if (!Display.EnsureSwapchainAvailable())
{ {
_renderTarget.Invalidate(); _renderTarget.RecreateImage();
} }
} }
public void Dispose() public void Dispose()
{ {
_commandBuffer = Display.StartPresentation(_renderTarget); _renderTarget.EndDraw();
Display.BlitImageToCurrentImage(_renderTarget, _commandBuffer.InternalHandle);
Display.EndPresentation(_commandBuffer);
} }
} }
} }

View File

@@ -1,9 +1,7 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Ui.Models; using Ryujinx.Ava.Ui.Models;
using Ryujinx.Ava.Ui.Windows;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace Ryujinx.Ava.Ui.Controls namespace Ryujinx.Ava.Ui.Controls

View File

@@ -37,7 +37,7 @@ namespace Ryujinx.Ava.Ui.Controls
public override void DestroyBackgroundContext() public override void DestroyBackgroundContext()
{ {
_image = null; Image = null;
if (_fence != IntPtr.Zero) if (_fence != IntPtr.Zero)
{ {
@@ -57,6 +57,8 @@ namespace Ryujinx.Ava.Ui.Controls
Dispatcher.UIThread.InvokeAsync(() => Dispatcher.UIThread.InvokeAsync(() =>
{ {
Image = (int)image; Image = (int)image;
InvalidateVisual();
}).Wait(); }).Wait();
if (_fence != IntPtr.Zero) if (_fence != IntPtr.Zero)
@@ -66,7 +68,7 @@ namespace Ryujinx.Ava.Ui.Controls
_fence = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None); _fence = GL.FenceSync(SyncCondition.SyncGpuCommandsComplete, WaitSyncFlags.None);
QueueRender(); InvalidateVisual();
_gameBackgroundWindow.SwapBuffers(); _gameBackgroundWindow.SwapBuffers();
} }

View File

@@ -11,25 +11,7 @@ namespace Ryujinx.Ava.Ui.Controls
{ {
internal abstract class RendererControl : Control internal abstract class RendererControl : Control
{ {
protected object _image; protected object Image { get; set; }
static RendererControl()
{
AffectsRender<RendererControl>(ImageProperty);
}
public readonly static StyledProperty<object> ImageProperty =
AvaloniaProperty.Register<RendererControl, object>(
nameof(Image),
0,
inherits: true,
defaultBindingMode: BindingMode.TwoWay);
protected object Image
{
get => _image;
set => SetAndRaise(ImageProperty, ref _image, value);
}
public event EventHandler<EventArgs> RendererInitialized; public event EventHandler<EventArgs> RendererInitialized;
public event EventHandler<Size> SizeChanged; public event EventHandler<Size> SizeChanged;
@@ -60,8 +42,6 @@ namespace Ryujinx.Ava.Ui.Controls
if (!rect.IsEmpty) if (!rect.IsEmpty)
{ {
RenderSize = rect.Size * VisualRoot.RenderScaling; RenderSize = rect.Size * VisualRoot.RenderScaling;
DrawOperation?.Dispose();
DrawOperation = CreateDrawOperation(); DrawOperation = CreateDrawOperation();
} }
} }
@@ -97,17 +77,11 @@ namespace Ryujinx.Ava.Ui.Controls
RendererInitialized?.Invoke(this, EventArgs.Empty); RendererInitialized?.Invoke(this, EventArgs.Empty);
} }
public void QueueRender()
{
Program.RenderTimer.TickNow();
}
internal abstract void Present(object image); internal abstract void Present(object image);
internal void Start() internal void Start()
{ {
IsStarted = true; IsStarted = true;
QueueRender();
} }
internal void Stop() internal void Stop()

View File

@@ -1,6 +1,4 @@
using Avalonia;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Ryujinx.Ava.Ui.Windows; using Ryujinx.Ava.Ui.Windows;
namespace Ryujinx.Ava.Ui.Controls namespace Ryujinx.Ava.Ui.Controls

View File

@@ -1,4 +1,5 @@
using Avalonia; using Avalonia;
using Avalonia.Media;
using Avalonia.Platform; using Avalonia.Platform;
using Avalonia.Rendering.SceneGraph; using Avalonia.Rendering.SceneGraph;
using Avalonia.Skia; using Avalonia.Skia;
@@ -11,20 +12,23 @@ using Silk.NET.Vulkan;
using SkiaSharp; using SkiaSharp;
using SPB.Windowing; using SPB.Windowing;
using System; using System;
using System.Collections.Generic; using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Ryujinx.Ava.Ui.Controls namespace Ryujinx.Ava.Ui.Controls
{ {
internal class VulkanRendererControl : RendererControl internal class VulkanRendererControl : RendererControl
{ {
private const int MaxImagesInFlight = 3;
private VulkanPlatformInterface _platformInterface; private VulkanPlatformInterface _platformInterface;
private ConcurrentQueue<PresentImageInfo> _imagesInFlight;
private PresentImageInfo _currentImage;
public VulkanRendererControl(GraphicsDebugLevel graphicsDebugLevel) : base(graphicsDebugLevel) public VulkanRendererControl(GraphicsDebugLevel graphicsDebugLevel) : base(graphicsDebugLevel)
{ {
_platformInterface = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>(); _platformInterface = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>();
_imagesInFlight = new ConcurrentQueue<PresentImageInfo>();
} }
public override void DestroyBackgroundContext() public override void DestroyBackgroundContext()
@@ -37,6 +41,40 @@ namespace Ryujinx.Ava.Ui.Controls
return new VulkanDrawOperation(this); return new VulkanDrawOperation(this);
} }
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnDetachedFromVisualTree(e);
_imagesInFlight.Clear();
if (_platformInterface.MainSurface.Display != null)
{
_platformInterface.MainSurface.Display.Presented -= Window_Presented;
}
_currentImage?.Put();
_currentImage = null;
}
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
{
base.OnAttachedToVisualTree(e);
_platformInterface.MainSurface.Display.Presented += Window_Presented;
}
private void Window_Presented(object sender, EventArgs e)
{
_platformInterface.MainSurface.Device.QueueWaitIdle();
_currentImage?.Put();
_currentImage = null;
}
public override void Render(DrawingContext context)
{
base.Render(context);
}
protected override void CreateWindow() protected override void CreateWindow()
{ {
} }
@@ -51,12 +89,29 @@ namespace Ryujinx.Ava.Ui.Controls
internal override void Present(object image) internal override void Present(object image)
{ {
Dispatcher.UIThread.InvokeAsync(() => Image = image;
{
Image = image;
}).Wait();
QueueRender(); _imagesInFlight.Enqueue((PresentImageInfo)image);
if (_imagesInFlight.Count > MaxImagesInFlight)
{
_imagesInFlight.TryDequeue(out _);
}
Dispatcher.UIThread.Post(InvalidateVisual);
}
private PresentImageInfo GetImage()
{
lock (_imagesInFlight)
{
if (!_imagesInFlight.TryDequeue(out _currentImage))
{
_currentImage = (PresentImageInfo)Image;
}
return _currentImage;
}
} }
private class VulkanDrawOperation : ICustomDrawOperation private class VulkanDrawOperation : ICustomDrawOperation
@@ -64,6 +119,7 @@ namespace Ryujinx.Ava.Ui.Controls
public Rect Bounds { get; } public Rect Bounds { get; }
private readonly VulkanRendererControl _control; private readonly VulkanRendererControl _control;
private bool _isDestroyed;
public VulkanDrawOperation(VulkanRendererControl control) public VulkanDrawOperation(VulkanRendererControl control)
{ {
@@ -73,7 +129,12 @@ namespace Ryujinx.Ava.Ui.Controls
public void Dispose() public void Dispose()
{ {
if (_isDestroyed)
{
return;
}
_isDestroyed = true;
} }
public bool Equals(ICustomDrawOperation other) public bool Equals(ICustomDrawOperation other)
@@ -86,30 +147,33 @@ namespace Ryujinx.Ava.Ui.Controls
return Bounds.Contains(p); return Bounds.Contains(p);
} }
public void Render(IDrawingContextImpl context) public unsafe void Render(IDrawingContextImpl context)
{ {
if (_control.Image == null || _control.RenderSize.Width == 0 || _control.RenderSize.Height == 0) if (_isDestroyed || _control.Image == null || _control.RenderSize.Width == 0 || _control.RenderSize.Height == 0 ||
context is not ISkiaDrawingContextImpl skiaDrawingContextImpl)
{ {
return; return;
} }
var image = (PresentImageInfo)_control.Image; var image = _control.GetImage();
if (context is not ISkiaDrawingContextImpl skiaDrawingContextImpl) if (!image.State.IsValid)
{ {
_control._currentImage = null;
return; return;
} }
_control._platformInterface.Device.QueueWaitIdle();
var gpu = AvaloniaLocator.Current.GetService<VulkanSkiaGpu>(); var gpu = AvaloniaLocator.Current.GetService<VulkanSkiaGpu>();
image.Get();
var imageInfo = new GRVkImageInfo() var imageInfo = new GRVkImageInfo()
{ {
CurrentQueueFamily = _control._platformInterface.PhysicalDevice.QueueFamilyIndex, CurrentQueueFamily = _control._platformInterface.PhysicalDevice.QueueFamilyIndex,
Format = (uint)Format.R8G8B8A8Unorm, Format = (uint)Format.R8G8B8A8Unorm,
Image = image.Image.Handle, Image = image.Image.Handle,
ImageLayout = (uint)ImageLayout.ColorAttachmentOptimal, ImageLayout = (uint)ImageLayout.TransferSrcOptimal,
ImageTiling = (uint)ImageTiling.Optimal, ImageTiling = (uint)ImageTiling.Optimal,
ImageUsageFlags = (uint)(ImageUsageFlags.ImageUsageColorAttachmentBit ImageUsageFlags = (uint)(ImageUsageFlags.ImageUsageColorAttachmentBit
| ImageUsageFlags.ImageUsageTransferSrcBit | ImageUsageFlags.ImageUsageTransferSrcBit
@@ -127,13 +191,15 @@ namespace Ryujinx.Ava.Ui.Controls
}; };
using var backendTexture = new GRBackendRenderTarget( using var backendTexture = new GRBackendRenderTarget(
(int)_control.RenderSize.Width, (int)image.Extent.Width,
(int)_control.RenderSize.Height, (int)image.Extent.Height,
1, 1,
imageInfo); imageInfo);
var vulkan = AvaloniaLocator.Current.GetService<VulkanPlatformInterface>();
using var surface = SKSurface.Create( using var surface = SKSurface.Create(
gpu.GrContext, skiaDrawingContextImpl.GrContext,
backendTexture, backendTexture,
GRSurfaceOrigin.TopLeft, GRSurfaceOrigin.TopLeft,
SKColorType.Rgba8888); SKColorType.Rgba8888);
@@ -143,10 +209,11 @@ namespace Ryujinx.Ava.Ui.Controls
return; return;
} }
var rect = new Rect(new Point(), _control.RenderSize); var rect = new Rect(new Point(), new Size(image.Extent.Width, image.Extent.Height));
using var snapshot = surface.Snapshot(); using var snapshot = surface.Snapshot();
skiaDrawingContextImpl.SkCanvas.DrawImage(snapshot, rect.ToSKRect(), _control.Bounds.ToSKRect(), new SKPaint()); skiaDrawingContextImpl.SkCanvas.DrawImage(snapshot, rect.ToSKRect(), _control.Bounds.ToSKRect(),
new SKPaint());
} }
} }
} }

View File

@@ -3,7 +3,6 @@ using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Svg.Skia; using Avalonia.Svg.Skia;
using Avalonia.Threading; using Avalonia.Threading;
using Avalonia.VisualTree;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Input; using Ryujinx.Ava.Input;
using Ryujinx.Ava.Ui.Controls; using Ryujinx.Ava.Ui.Controls;
@@ -24,7 +23,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text.Json; using System.Text.Json;
using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId; using ConfigGamepadInputId = Ryujinx.Common.Configuration.Hid.Controller.GamepadInputId;
using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId; using ConfigStickInputId = Ryujinx.Common.Configuration.Hid.Controller.StickInputId;

View File

@@ -38,6 +38,8 @@ namespace Ryujinx.Ava.Ui.ViewModels
{ {
internal class MainWindowViewModel : BaseModel internal class MainWindowViewModel : BaseModel
{ {
private const int HotKeyPressDelayMs = 500;
private readonly MainWindow _owner; private readonly MainWindow _owner;
private ObservableCollection<ApplicationData> _applications; private ObservableCollection<ApplicationData> _applications;
private string _aspectStatusText; private string _aspectStatusText;
@@ -54,6 +56,7 @@ namespace Ryujinx.Ava.Ui.ViewModels
private bool _isLoading; private bool _isLoading;
private int _progressMaximum; private int _progressMaximum;
private int _progressValue; private int _progressValue;
private long _lastFullscreenToggle = Environment.TickCount64;
private bool _showLoadProgress; private bool _showLoadProgress;
private bool _showMenuAndStatusBar = true; private bool _showMenuAndStatusBar = true;
private bool _showStatusSeparator; private bool _showStatusSeparator;
@@ -929,6 +932,13 @@ namespace Ryujinx.Ava.Ui.ViewModels
public void ToggleFullscreen() public void ToggleFullscreen()
{ {
if (Environment.TickCount64 - _lastFullscreenToggle < HotKeyPressDelayMs)
{
return;
}
_lastFullscreenToggle = Environment.TickCount64;
WindowState state = _owner.WindowState; WindowState state = _owner.WindowState;
if (state == WindowState.FullScreen) if (state == WindowState.FullScreen)
@@ -1085,6 +1095,11 @@ namespace Ryujinx.Ava.Ui.ViewModels
{ {
selection.Favorite = !selection.Favorite; selection.Favorite = !selection.Favorite;
_owner.ApplicationLibrary.LoadAndSaveMetaData(selection.TitleId, appMetadata =>
{
appMetadata.Favorite = selection.Favorite;
});
RefreshView(); RefreshView();
} }
} }

View File

@@ -48,6 +48,10 @@ namespace Ryujinx.Ava.Ui.ViewModels
private int _graphicsBackendMultithreadingIndex; private int _graphicsBackendMultithreadingIndex;
private float _previousVolumeLevel; private float _previousVolumeLevel;
private float _volume; private float _volume;
private bool _isVulkanAvailable = true;
private List<string> _gpuIds = new List<string>();
private KeyboardHotkeys _keyboardHotkeys;
private int _graphicsBackendIndex;
public int ResolutionScale public int ResolutionScale
{ {
@@ -97,6 +101,17 @@ namespace Ryujinx.Ava.Ui.ViewModels
} }
} }
public bool IsVulkanAvailable
{
get => _isVulkanAvailable;
set
{
_isVulkanAvailable = value;
OnPropertyChanged();
}
}
public bool EnableDiscordIntegration { get; set; } public bool EnableDiscordIntegration { get; set; }
public bool CheckUpdatesOnStart { get; set; } public bool CheckUpdatesOnStart { get; set; }
public bool ShowConfirmExit { get; set; } public bool ShowConfirmExit { get; set; }
@@ -143,10 +158,10 @@ namespace Ryujinx.Ava.Ui.ViewModels
public int BaseStyleIndex { get; set; } public int BaseStyleIndex { get; set; }
public int GraphicsBackendIndex public int GraphicsBackendIndex
{ {
get => graphicsBackendIndex; get => _graphicsBackendIndex;
set set
{ {
graphicsBackendIndex = value; _graphicsBackendIndex = value;
OnPropertyChanged(); OnPropertyChanged();
OnPropertyChanged(nameof(IsVulkanSelected)); OnPropertyChanged(nameof(IsVulkanSelected));
} }
@@ -170,14 +185,9 @@ namespace Ryujinx.Ava.Ui.ViewModels
public DateTimeOffset DateOffset { get; set; } public DateTimeOffset DateOffset { get; set; }
public TimeSpan TimeOffset { get; set; } public TimeSpan TimeOffset { get; set; }
public AvaloniaList<TimeZone> TimeZones { get; set; } public AvaloniaList<TimeZone> TimeZones { get; set; }
public AvaloniaList<string> GameDirectories { get; set; } public AvaloniaList<string> GameDirectories { get; set; }
public ObservableCollection<ComboBoxItem> AvailableGpus { get; set; } public ObservableCollection<ComboBoxItem> AvailableGpus { get; set; }
private KeyboardHotkeys _keyboardHotkeys;
private int graphicsBackendIndex;
private List<string> _gpuIds = new List<string>();
public KeyboardHotkeys KeyboardHotkeys public KeyboardHotkeys KeyboardHotkeys
{ {
get => _keyboardHotkeys; get => _keyboardHotkeys;
@@ -233,20 +243,31 @@ namespace Ryujinx.Ava.Ui.ViewModels
if (!Program.UseVulkan) if (!Program.UseVulkan)
{ {
var devices = VulkanRenderer.GetPhysicalDevices(); var devices = VulkanRenderer.GetPhysicalDevices();
foreach (var device in devices)
if (devices.Length == 0)
{ {
_gpuIds.Add(device.Id); IsVulkanAvailable = false;
names.Add($"{device.Name} {(device.IsDiscrete ? "(dGpu)" : "")}"); GraphicsBackendIndex = 1;
}
else
{
foreach (var device in devices)
{
_gpuIds.Add(device.Id);
names.Add($"{device.Name} {(device.IsDiscrete ? "(dGPU)" : "")}");
}
} }
} }
else else
{ {
foreach (var device in VulkanPhysicalDevice.SuitableDevices) foreach (var device in VulkanPhysicalDevice.SuitableDevices)
{ {
_gpuIds.Add(VulkanInitialization.StringFromIdPair(device.Value.VendorID, device.Value.DeviceID)); _gpuIds.Add(
VulkanInitialization.StringFromIdPair(device.Value.VendorID, device.Value.DeviceID));
var value = device.Value; var value = device.Value;
var name = value.DeviceName; var name = value.DeviceName;
names.Add($"{Marshal.PtrToStringAnsi((IntPtr)name)} {(device.Value.DeviceType == PhysicalDeviceType.DiscreteGpu ? "(dGpu)" : "")}"); names.Add(
$"{Marshal.PtrToStringAnsi((IntPtr)name)} {(device.Value.DeviceType == PhysicalDeviceType.DiscreteGpu ? "(dGPU)" : "")}");
} }
} }

View File

@@ -1,5 +1,4 @@
using Avalonia; using Avalonia.Controls;
using Avalonia.Controls;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Avalonia.Threading; using Avalonia.Threading;

View File

@@ -1,4 +1,3 @@
using Avalonia;
using Avalonia.Interactivity; using Avalonia.Interactivity;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Ui.Models; using Ryujinx.Ava.Ui.Models;

View File

@@ -1,11 +1,9 @@
using Avalonia; using Avalonia.Collections;
using Avalonia.Collections;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Ava.Ui.Models; using Ryujinx.Ava.Ui.Models;
using Ryujinx.HLE.FileSystem; using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS; using Ryujinx.HLE.HOS;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;

View File

@@ -12,7 +12,6 @@ using Ryujinx.Ava.Ui.Applet;
using Ryujinx.Ava.Ui.Controls; using Ryujinx.Ava.Ui.Controls;
using Ryujinx.Ava.Ui.Models; using Ryujinx.Ava.Ui.Models;
using Ryujinx.Ava.Ui.ViewModels; using Ryujinx.Ava.Ui.ViewModels;
using Ryujinx.Ava.Ui.Vulkan;
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.Graphics.Gpu; using Ryujinx.Graphics.Gpu;
@@ -27,7 +26,6 @@ using Ryujinx.Ui.Common.Configuration;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -656,7 +654,12 @@ namespace Ryujinx.Ava.Ui.Windows
{ {
AppHost = null; AppHost = null;
Dispatcher.UIThread.Post(Close); Dispatcher.UIThread.Post(() =>
{
MainContent = null;
Close();
});
}; };
AppHost?.Stop(); AppHost?.Stop();

View File

@@ -519,7 +519,7 @@
HorizontalContentAlignment="Left" HorizontalContentAlignment="Left"
ToolTip.Tip="{locale:Locale SettingsTabGraphicsBackendTooltip}" ToolTip.Tip="{locale:Locale SettingsTabGraphicsBackendTooltip}"
SelectedIndex="{Binding GraphicsBackendIndex}"> SelectedIndex="{Binding GraphicsBackendIndex}">
<ComboBoxItem> <ComboBoxItem IsVisible="{Binding IsVulkanAvailable}">
<TextBlock Text="Vulkan" /> <TextBlock Text="Vulkan" />
</ComboBoxItem> </ComboBoxItem>
<ComboBoxItem> <ComboBoxItem>

View File

@@ -1,4 +1,3 @@
using Avalonia;
using Avalonia.Collections; using Avalonia.Collections;
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Threading; using Avalonia.Threading;
@@ -18,7 +17,6 @@ using Ryujinx.HLE.FileSystem;
using Ryujinx.HLE.HOS; using Ryujinx.HLE.HOS;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;

View File

@@ -1,5 +1,3 @@
using Avalonia;
using Avalonia.Controls;
using Ryujinx.Ava.Common.Locale; using Ryujinx.Ava.Common.Locale;
using Ryujinx.Modules; using Ryujinx.Modules;
using System; using System;

View File

@@ -1,8 +1,6 @@
using Ryujinx.Common.Configuration.Hid.Controller.Motion; using Ryujinx.Common.Configuration.Hid.Controller.Motion;
using System; using System;
using System.ComponentModel;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using NotImplementedException = System.NotImplementedException;
namespace Ryujinx.Common.Configuration.Hid.Controller namespace Ryujinx.Common.Configuration.Hid.Controller
{ {

View File

@@ -1,5 +1,4 @@
using System; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
namespace Ryujinx.Common.GraphicsDriver.NVAPI namespace Ryujinx.Common.GraphicsDriver.NVAPI
{ {

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Collections.Concurrent;
namespace Ryujinx.Common.Logging namespace Ryujinx.Common.Logging
{ {

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection;
namespace Ryujinx.Common.Logging namespace Ryujinx.Common.Logging
{ {

View File

@@ -3,7 +3,6 @@ using System;
using System.Drawing; using System.Drawing;
using System.Globalization; using System.Globalization;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning;
namespace Ryujinx.Common.System namespace Ryujinx.Common.System
{ {

View File

@@ -24,7 +24,7 @@ namespace Ryujinx.Common.SystemInfo
if (sysctlbyname("hw.memsize", ref totalRAM) != 0) // Bytes if (sysctlbyname("hw.memsize", ref totalRAM) != 0) // Bytes
{ {
totalRAM = 0; totalRAM = 0;
}; }
CpuName = $"{cpuName} ; {LogicalCoreCount} logical"; CpuName = $"{cpuName} ; {LogicalCoreCount} logical";
RamTotal = totalRAM; RamTotal = totalRAM;

View File

@@ -1,5 +1,4 @@
using System; using System;
using System.Globalization;
using System.Management; using System.Management;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Runtime.Versioning; using System.Runtime.Versioning;

View File

@@ -1,4 +1,3 @@
using System;
using System.Numerics; using System.Numerics;
namespace Ryujinx.Common namespace Ryujinx.Common

View File

@@ -82,8 +82,10 @@ namespace Ryujinx.Graphics.GAL
Bc6HUfloat, Bc6HUfloat,
Etc2RgbUnorm, Etc2RgbUnorm,
Etc2RgbaUnorm, Etc2RgbaUnorm,
Etc2RgbPtaUnorm,
Etc2RgbSrgb, Etc2RgbSrgb,
Etc2RgbaSrgb, Etc2RgbaSrgb,
Etc2RgbPtaSrgb,
R8Uscaled, R8Uscaled,
R8Sscaled, R8Sscaled,
R16Uscaled, R16Uscaled,

View File

@@ -1,8 +1,4 @@
using System; namespace Ryujinx.Graphics.GAL
using System.Collections.Generic;
using System.Text;
namespace Ryujinx.Graphics.GAL
{ {
public struct HardwareInfo public struct HardwareInfo
{ {

View File

@@ -1,5 +1,4 @@
using Ryujinx.Common.Configuration; using Ryujinx.Common.Configuration;
using Ryujinx.Graphics.Shader;
using System; using System;
namespace Ryujinx.Graphics.GAL namespace Ryujinx.Graphics.GAL

View File

@@ -7,5 +7,7 @@ namespace Ryujinx.Graphics.GAL
void Present(ITexture texture, ImageCrop crop, Action<object> swapBuffersCallback); void Present(ITexture texture, ImageCrop crop, Action<object> swapBuffersCallback);
void SetSize(int width, int height); void SetSize(int width, int height);
void ChangeVSyncMode(bool vsyncEnabled);
} }
} }

View File

@@ -1,6 +1,5 @@
using Ryujinx.Graphics.GAL.Multithreading.Model; using Ryujinx.Graphics.GAL.Multithreading.Model;
using System; using System;
using System.Buffers;
namespace Ryujinx.Graphics.GAL.Multithreading.Commands namespace Ryujinx.Graphics.GAL.Multithreading.Commands
{ {

View File

@@ -1,6 +1,5 @@
using Ryujinx.Graphics.GAL.Multithreading.Model; using Ryujinx.Graphics.GAL.Multithreading.Model;
using System; using System;
using System.Buffers;
namespace Ryujinx.Graphics.GAL.Multithreading.Commands namespace Ryujinx.Graphics.GAL.Multithreading.Commands
{ {

View File

@@ -1,5 +1,4 @@
using Ryujinx.Graphics.GAL.Multithreading.Model; using Ryujinx.Graphics.GAL.Multithreading.Model;
using Ryujinx.Graphics.Shader;
namespace Ryujinx.Graphics.GAL.Multithreading.Commands namespace Ryujinx.Graphics.GAL.Multithreading.Commands
{ {

View File

@@ -1,6 +1,4 @@
using System.Linq; namespace Ryujinx.Graphics.GAL.Multithreading.Resources.Programs
namespace Ryujinx.Graphics.GAL.Multithreading.Resources.Programs
{ {
class SourceProgramRequest : IProgramRequest class SourceProgramRequest : IProgramRequest
{ {

View File

@@ -30,5 +30,7 @@ namespace Ryujinx.Graphics.GAL.Multithreading
{ {
_impl.Window.SetSize(width, height); _impl.Window.SetSize(width, height);
} }
public void ChangeVSyncMode(bool vsyncEnabled) { }
} }
} }

View File

@@ -1,6 +1,5 @@
using Ryujinx.Graphics.Device; using Ryujinx.Graphics.Device;
using Ryujinx.Graphics.Gpu.Engine.GPFifo; using Ryujinx.Graphics.Gpu.Engine.GPFifo;
using Ryujinx.Graphics.Gpu.Memory;
using System; using System;
namespace Ryujinx.Graphics.Gpu.Engine.MME namespace Ryujinx.Graphics.Gpu.Engine.MME

View File

@@ -1,7 +1,6 @@
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.Types; using Ryujinx.Graphics.Gpu.Engine.Types;
using System; using System;
using System.Text;
namespace Ryujinx.Graphics.Gpu.Engine.Threed namespace Ryujinx.Graphics.Gpu.Engine.Threed
{ {

View File

@@ -1317,10 +1317,12 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
for (int location = 0; location < attributeTypes.Length; location++) for (int location = 0; location < attributeTypes.Length; location++)
{ {
attributeTypes[location] = vertexAttribState[location].UnpackType() switch VertexAttribType type = vertexAttribState[location].UnpackType();
attributeTypes[location] = type switch
{ {
3 => AttributeType.Sint, VertexAttribType.Sint => AttributeType.Sint,
4 => AttributeType.Uint, VertexAttribType.Uint => AttributeType.Uint,
_ => AttributeType.Float _ => AttributeType.Float
}; };
} }

View File

@@ -267,6 +267,41 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
#pragma warning restore CS0649 #pragma warning restore CS0649
} }
/// <summary>
/// Vertex attribute vector and component size.
/// </summary>
enum VertexAttribSize
{
Size32x4 = 1,
Size32x3 = 2,
Size16x4 = 3,
Size32x2 = 4,
Size16x3 = 5,
Size8x4 = 0xa,
Size16x2 = 0xf,
Size32 = 0x12,
Size8x3 = 0x13,
Size8x2 = 0x18,
Size16 = 0x1b,
Size8 = 0x1d,
Rgb10A2 = 0x30,
Rg11B10 = 0x31
}
/// <summary>
/// Vertex attribute component type.
/// </summary>
enum VertexAttribType
{
Snorm = 1,
Unorm = 2,
Sint = 3,
Uint = 4,
Uscaled = 5,
Sscaled = 6,
Float = 7
}
/// <summary> /// <summary>
/// Vertex buffer attribute state. /// Vertex buffer attribute state.
/// </summary> /// </summary>
@@ -312,13 +347,22 @@ namespace Ryujinx.Graphics.Gpu.Engine.Threed
return Attribute & 0x3fe00000; return Attribute & 0x3fe00000;
} }
/// <summary> /// <summary>
/// Unpacks the Maxwell attribute size.
/// </summary>
/// <returns>Attribute size</returns>
public VertexAttribSize UnpackSize()
{
return (VertexAttribSize)((Attribute >> 21) & 0x3f);
}
/// <summary>
/// Unpacks the Maxwell attribute component type. /// Unpacks the Maxwell attribute component type.
/// </summary> /// </summary>
/// <returns>Attribute component type</returns> /// <returns>Attribute component type</returns>
public uint UnpackType() public VertexAttribType UnpackType()
{ {
return (Attribute >> 27) & 7; return (VertexAttribType)((Attribute >> 27) & 7);
} }
} }

View File

@@ -82,7 +82,7 @@ namespace Ryujinx.Graphics.Gpu
/// <summary> /// <summary>
/// Host hardware capabilities. /// Host hardware capabilities.
/// </summary> /// </summary>
internal Capabilities Capabilities { get; private set; } internal Capabilities Capabilities;
/// <summary> /// <summary>
/// Event for signalling shader cache loading progress. /// Event for signalling shader cache loading progress.

View File

@@ -1,4 +1,3 @@
using Ryujinx.Common.Logging;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;

View File

@@ -1,10 +1,8 @@
using Ryujinx.Common; using Ryujinx.Common;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.Gpu.Engine.Dma;
using Ryujinx.Graphics.Gpu.Engine.Threed; using Ryujinx.Graphics.Gpu.Engine.Threed;
using Ryujinx.Graphics.Gpu.Engine.Twod; using Ryujinx.Graphics.Gpu.Engine.Twod;
using Ryujinx.Graphics.Gpu.Engine.Types; using Ryujinx.Graphics.Gpu.Engine.Types;
using Ryujinx.Graphics.Gpu.Image;
using Ryujinx.Graphics.Gpu.Memory; using Ryujinx.Graphics.Gpu.Memory;
using Ryujinx.Graphics.Texture; using Ryujinx.Graphics.Texture;
using Ryujinx.Memory.Range; using Ryujinx.Memory.Range;

View File

@@ -1,4 +1,3 @@
using Ryujinx.Common.Logging;
using Ryujinx.Cpu.Tracking; using Ryujinx.Cpu.Tracking;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Memory.Range; using Ryujinx.Memory.Range;

View File

@@ -1,5 +1,3 @@
using Ryujinx.Graphics.Shader;
namespace Ryujinx.Graphics.Gpu.Shader.DiskCache namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
{ {
/// <summary> /// <summary>

View File

@@ -573,9 +573,9 @@ namespace Ryujinx.Graphics.Gpu.Shader.DiskCache
RecompileGraphicsFromGuestCode(guestShaders, specState, programIndex); RecompileGraphicsFromGuestCode(guestShaders, specState, programIndex);
} }
} }
catch (DiskCacheLoadException diskCacheLoadException) catch (Exception exception)
{ {
Logger.Error?.Print(LogClass.Gpu, $"Error translating guest shader. {diskCacheLoadException.Message}"); Logger.Error?.Print(LogClass.Gpu, $"Error translating guest shader. {exception.Message}");
ErrorCount++; ErrorCount++;
SignalCompiled(); SignalCompiled();

View File

@@ -27,7 +27,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
_stageIndex = stageIndex; _stageIndex = stageIndex;
} }
/// <inheritdoc/>
public int QueryBindingConstantBuffer(int index) public int QueryBindingConstantBuffer(int index)
{ {
if (_context.Capabilities.Api == TargetApi.Vulkan) if (_context.Capabilities.Api == TargetApi.Vulkan)
@@ -41,7 +40,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
} }
} }
/// <inheritdoc/>
public int QueryBindingStorageBuffer(int index) public int QueryBindingStorageBuffer(int index)
{ {
if (_context.Capabilities.Api == TargetApi.Vulkan) if (_context.Capabilities.Api == TargetApi.Vulkan)
@@ -54,7 +52,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
} }
} }
/// <inheritdoc/>
public int QueryBindingTexture(int index, bool isBuffer) public int QueryBindingTexture(int index, bool isBuffer)
{ {
if (_context.Capabilities.Api == TargetApi.Vulkan) if (_context.Capabilities.Api == TargetApi.Vulkan)
@@ -72,7 +69,6 @@ namespace Ryujinx.Graphics.Gpu.Shader
} }
} }
/// <inheritdoc/>
public int QueryBindingImage(int index, bool isBuffer) public int QueryBindingImage(int index, bool isBuffer)
{ {
if (_context.Capabilities.Api == TargetApi.Vulkan) if (_context.Capabilities.Api == TargetApi.Vulkan)
@@ -116,37 +112,26 @@ namespace Ryujinx.Graphics.Gpu.Shader
}; };
} }
/// <inheritdoc/>
public bool QueryHostHasFrontFacingBug() => _context.Capabilities.HasFrontFacingBug; public bool QueryHostHasFrontFacingBug() => _context.Capabilities.HasFrontFacingBug;
/// <inheritdoc/>
public bool QueryHostHasVectorIndexingBug() => _context.Capabilities.HasVectorIndexingBug; public bool QueryHostHasVectorIndexingBug() => _context.Capabilities.HasVectorIndexingBug;
/// <inheritdoc/>
public int QueryHostStorageBufferOffsetAlignment() => _context.Capabilities.StorageBufferOffsetAlignment; public int QueryHostStorageBufferOffsetAlignment() => _context.Capabilities.StorageBufferOffsetAlignment;
/// <inheritdoc/>
public bool QueryHostSupportsBgraFormat() => _context.Capabilities.SupportsBgraFormat; public bool QueryHostSupportsBgraFormat() => _context.Capabilities.SupportsBgraFormat;
/// <inheritdoc/>
public bool QueryHostSupportsFragmentShaderInterlock() => _context.Capabilities.SupportsFragmentShaderInterlock; public bool QueryHostSupportsFragmentShaderInterlock() => _context.Capabilities.SupportsFragmentShaderInterlock;
/// <inheritdoc/>
public bool QueryHostSupportsFragmentShaderOrderingIntel() => _context.Capabilities.SupportsFragmentShaderOrderingIntel; public bool QueryHostSupportsFragmentShaderOrderingIntel() => _context.Capabilities.SupportsFragmentShaderOrderingIntel;
/// <inheritdoc/>
public bool QueryHostSupportsGeometryShaderPassthrough() => _context.Capabilities.SupportsGeometryShaderPassthrough; public bool QueryHostSupportsGeometryShaderPassthrough() => _context.Capabilities.SupportsGeometryShaderPassthrough;
/// <inheritdoc/>
public bool QueryHostSupportsImageLoadFormatted() => _context.Capabilities.SupportsImageLoadFormatted; public bool QueryHostSupportsImageLoadFormatted() => _context.Capabilities.SupportsImageLoadFormatted;
/// <inheritdoc/>
public bool QueryHostSupportsNonConstantTextureOffset() => _context.Capabilities.SupportsNonConstantTextureOffset; public bool QueryHostSupportsNonConstantTextureOffset() => _context.Capabilities.SupportsNonConstantTextureOffset;
/// <inheritdoc/>
public bool QueryHostSupportsShaderBallot() => _context.Capabilities.SupportsShaderBallot; public bool QueryHostSupportsShaderBallot() => _context.Capabilities.SupportsShaderBallot;
/// <inheritdoc/>
public bool QueryHostSupportsTextureShadowLod() => _context.Capabilities.SupportsTextureShadowLod; public bool QueryHostSupportsTextureShadowLod() => _context.Capabilities.SupportsTextureShadowLod;
/// <summary> /// <summary>

View File

@@ -1,6 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Numerics; using System.Numerics;
namespace Ryujinx.Graphics.Gpu.Shader.HashTable namespace Ryujinx.Graphics.Gpu.Shader.HashTable

View File

@@ -1,4 +1,3 @@
using Ryujinx.Graphics.Shader;
using System.IO; using System.IO;
namespace Ryujinx.Graphics.Gpu.Shader namespace Ryujinx.Graphics.Gpu.Shader

View File

@@ -1187,7 +1187,7 @@ namespace Ryujinx.Graphics.Nvdec.Vp9
if (cm.Mb.Corrupted) if (cm.Mb.Corrupted)
{ {
cm.Error.InternalError(CodecErr.CodecCorruptFrame, "Failed to decode tile data"); cm.Error.InternalError(CodecErr.CodecCorruptFrame, "Failed to decode tile data");
}; }
} }
} }
} }

View File

@@ -2,7 +2,6 @@
using Ryujinx.Graphics.Nvdec.Vp9.Common; using Ryujinx.Graphics.Nvdec.Vp9.Common;
using System.Diagnostics; using System.Diagnostics;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics; using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86; using System.Runtime.Intrinsics.X86;
using static Ryujinx.Graphics.Nvdec.Vp9.Dsp.Filter; using static Ryujinx.Graphics.Nvdec.Vp9.Dsp.Filter;

View File

@@ -93,8 +93,12 @@ namespace Ryujinx.Graphics.OpenGL
Add(Format.Bc7Srgb, new FormatInfo(4, false, false, All.CompressedSrgbAlphaBptcUnorm)); Add(Format.Bc7Srgb, new FormatInfo(4, false, false, All.CompressedSrgbAlphaBptcUnorm));
Add(Format.Bc6HSfloat, new FormatInfo(4, false, false, All.CompressedRgbBptcSignedFloat)); Add(Format.Bc6HSfloat, new FormatInfo(4, false, false, All.CompressedRgbBptcSignedFloat));
Add(Format.Bc6HUfloat, new FormatInfo(4, false, false, All.CompressedRgbBptcUnsignedFloat)); Add(Format.Bc6HUfloat, new FormatInfo(4, false, false, All.CompressedRgbBptcUnsignedFloat));
Add(Format.Etc2RgbUnorm, new FormatInfo(4, false, false, All.CompressedRgb8Etc2));
Add(Format.Etc2RgbaUnorm, new FormatInfo(4, false, false, All.CompressedRgba8Etc2Eac)); Add(Format.Etc2RgbaUnorm, new FormatInfo(4, false, false, All.CompressedRgba8Etc2Eac));
Add(Format.Etc2RgbPtaUnorm, new FormatInfo(4, false, false, All.CompressedRgb8PunchthroughAlpha1Etc2));
Add(Format.Etc2RgbSrgb, new FormatInfo(4, false, false, All.CompressedSrgb8Etc2));
Add(Format.Etc2RgbaSrgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Etc2Eac)); Add(Format.Etc2RgbaSrgb, new FormatInfo(4, false, false, All.CompressedSrgb8Alpha8Etc2Eac));
Add(Format.Etc2RgbPtaSrgb, new FormatInfo(4, false, false, All.CompressedSrgb8PunchthroughAlpha1Etc2));
Add(Format.R8Uscaled, new FormatInfo(1, false, true, All.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte)); Add(Format.R8Uscaled, new FormatInfo(1, false, true, All.R8ui, PixelFormat.RedInteger, PixelType.UnsignedByte));
Add(Format.R8Sscaled, new FormatInfo(1, false, true, All.R8i, PixelFormat.RedInteger, PixelType.Byte)); Add(Format.R8Sscaled, new FormatInfo(1, false, true, All.R8i, PixelFormat.RedInteger, PixelType.Byte));
Add(Format.R16Uscaled, new FormatInfo(1, false, true, All.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort)); Add(Format.R16Uscaled, new FormatInfo(1, false, true, All.R16ui, PixelFormat.RedInteger, PixelType.UnsignedShort));

View File

@@ -1,6 +1,5 @@
using OpenTK.Graphics.OpenGL; using OpenTK.Graphics.OpenGL;
using Ryujinx.Graphics.GAL; using Ryujinx.Graphics.GAL;
using Ryujinx.Graphics.OpenGL.Helper;
using Ryujinx.Graphics.OpenGL.Image; using Ryujinx.Graphics.OpenGL.Image;
using System; using System;
@@ -58,6 +57,8 @@ namespace Ryujinx.Graphics.OpenGL
GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4); GL.PixelStore(PixelStoreParameter.UnpackAlignment, 4);
} }
public void ChangeVSyncMode(bool vsyncEnabled) { }
private void CreateStagingFramebuffer() private void CreateStagingFramebuffer()
{ {
_stagingFrameBuffer = GL.GenFramebuffer(); _stagingFrameBuffer = GL.GenFramebuffer();

View File

@@ -1,9 +1,12 @@
using Ryujinx.Graphics.Shader.StructuredIr;
using Ryujinx.Graphics.Shader.Translation;
using System; using System;
namespace Ryujinx.Graphics.Shader namespace Ryujinx.Graphics.Shader
{ {
public enum AttributeType : byte public enum AttributeType : byte
{ {
// Generic types.
Float, Float,
Sint, Sint,
Uint Uint
@@ -11,18 +14,7 @@ namespace Ryujinx.Graphics.Shader
static class AttributeTypeExtensions static class AttributeTypeExtensions
{ {
public static string GetScalarType(this AttributeType type) public static string ToVec4Type(this AttributeType type)
{
return type switch
{
AttributeType.Float => "float",
AttributeType.Sint => "int",
AttributeType.Uint => "uint",
_ => throw new ArgumentException($"Invalid attribute type \"{type}\".")
};
}
public static string GetVec4Type(this AttributeType type)
{ {
return type switch return type switch
{ {
@@ -32,5 +24,27 @@ namespace Ryujinx.Graphics.Shader
_ => throw new ArgumentException($"Invalid attribute type \"{type}\".") _ => throw new ArgumentException($"Invalid attribute type \"{type}\".")
}; };
} }
public static VariableType ToVariableType(this AttributeType type)
{
return type switch
{
AttributeType.Float => VariableType.F32,
AttributeType.Sint => VariableType.S32,
AttributeType.Uint => VariableType.U32,
_ => throw new ArgumentException($"Invalid attribute type \"{type}\".")
};
}
public static AggregateType ToAggregateType(this AttributeType type)
{
return type switch
{
AttributeType.Float => AggregateType.FP32,
AttributeType.Sint => AggregateType.S32,
AttributeType.Uint => AggregateType.U32,
_ => throw new ArgumentException($"Invalid attribute type \"{type}\".")
};
}
} }
} }

View File

@@ -553,11 +553,11 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
if (context.Config.Stage == ShaderStage.Vertex) if (context.Config.Stage == ShaderStage.Vertex)
{ {
type = context.Config.GpuAccessor.QueryAttributeType(attr).GetVec4Type(); type = context.Config.GpuAccessor.QueryAttributeType(attr).ToVec4Type();
} }
else else
{ {
type = AttributeType.Float.GetVec4Type(); type = AttributeType.Float.ToVec4Type();
} }
context.AppendLine($"layout ({pass}location = {attr}) {iq}in {type} {name}{suffix};"); context.AppendLine($"layout ({pass}location = {attr}) {iq}in {type} {name}{suffix};");

View File

@@ -454,12 +454,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Glsl
AttributeType type = context.Config.GpuAccessor.QueryAttributeType(location); AttributeType type = context.Config.GpuAccessor.QueryAttributeType(location);
return type switch return type.ToVariableType();
{
AttributeType.Sint => VariableType.S32,
AttributeType.Uint => VariableType.U32,
_ => VariableType.F32
};
} }
} }

View File

@@ -3,7 +3,6 @@ using Ryujinx.Graphics.Shader.Translation;
using Spv.Generator; using Spv.Generator;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using static Spv.Specification; using static Spv.Specification;
namespace Ryujinx.Graphics.Shader.CodeGen.Spirv namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
@@ -234,7 +233,7 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
IrOperandType.Constant => GetConstant(type, operand), IrOperandType.Constant => GetConstant(type, operand),
IrOperandType.ConstantBuffer => GetConstantBuffer(type, operand), IrOperandType.ConstantBuffer => GetConstantBuffer(type, operand),
IrOperandType.LocalVariable => GetLocal(type, operand), IrOperandType.LocalVariable => GetLocal(type, operand),
IrOperandType.Undefined => Constant(GetType(type), 0), IrOperandType.Undefined => GetUndefined(type),
_ => throw new ArgumentException($"Invalid operand type \"{operand.Type}\".") _ => throw new ArgumentException($"Invalid operand type \"{operand.Type}\".")
}; };
} }
@@ -242,6 +241,17 @@ namespace Ryujinx.Graphics.Shader.CodeGen.Spirv
throw new NotImplementedException(node.GetType().Name); throw new NotImplementedException(node.GetType().Name);
} }
private Instruction GetUndefined(AggregateType type)
{
return type switch
{
AggregateType.Bool => ConstantFalse(TypeBool()),
AggregateType.FP32 => Constant(TypeFP32(), 0f),
AggregateType.FP64 => Constant(TypeFP64(), 0d),
_ => Constant(GetType(type), 0)
};
}
public Instruction GetAttributeElemPointer(int attr, bool isOutAttr, Instruction index, out AggregateType elemType) public Instruction GetAttributeElemPointer(int attr, bool isOutAttr, Instruction index, out AggregateType elemType)
{ {
var storageClass = isOutAttr ? StorageClass.Output : StorageClass.Input; var storageClass = isOutAttr ? StorageClass.Output : StorageClass.Input;

Some files were not shown because too many files have changed in this diff Show More