Archived
1
0
Fork 0
forked from Mirror/Ryujinx
This repository has been archived on 2024-10-11. You can view files and clone it, but cannot push or open issues or pull requests.
jinx/Ryujinx.Ava/Ui/Backend/Vulkan/VulkanPlatformInterface.cs
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

70 lines
2 KiB
C#

using Avalonia;
using Ryujinx.Ava.Ui.Vulkan.Surfaces;
using Ryujinx.Graphics.Vulkan;
using Silk.NET.Vulkan;
using System;
namespace Ryujinx.Ava.Ui.Vulkan
{
internal class VulkanPlatformInterface : IDisposable
{
private static VulkanOptions _options;
private VulkanPlatformInterface(VulkanInstance instance)
{
Instance = instance;
Api = instance.Api;
}
public VulkanPhysicalDevice PhysicalDevice { get; private set; }
public VulkanInstance Instance { get; }
public Vk Api { get; private set; }
public VulkanSurfaceRenderTarget MainSurface { get; set; }
public void Dispose()
{
Instance?.Dispose();
Api?.Dispose();
}
private static VulkanPlatformInterface TryCreate()
{
_options = AvaloniaLocator.Current.GetService<VulkanOptions>() ?? new VulkanOptions();
var instance = VulkanInstance.Create(_options);
return new VulkanPlatformInterface(instance);
}
public static bool TryInitialize()
{
var feature = TryCreate();
if (feature != null)
{
AvaloniaLocator.CurrentMutable.Bind<VulkanPlatformInterface>().ToConstant(feature);
return true;
}
return false;
}
public VulkanSurfaceRenderTarget CreateRenderTarget(IVulkanPlatformSurface platformSurface)
{
var surface = VulkanSurface.CreateSurface(Instance, platformSurface);
if (PhysicalDevice == null)
{
PhysicalDevice = VulkanPhysicalDevice.FindSuitablePhysicalDevice(Instance, surface, _options.PreferDiscreteGpu, _options.PreferredDevice);
}
var renderTarget = new VulkanSurfaceRenderTarget(this, surface);
if (MainSurface == null && surface != null)
{
MainSurface = renderTarget;
}
return renderTarget;
}
}
}