0
0
Fork 0
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2024-12-23 02:25:45 +00:00

vulkan: Pass Vk instance to VulkanRenderer (#4859)

This will allow possible multiple driver selection without any need of
LD preload. (useful when testing custom version of mesa for example)
This commit is contained in:
Mary 2023-05-08 13:05:37 +02:00 committed by GitHub
parent 162798b026
commit a8950d6ac4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 23 additions and 20 deletions

View file

@ -35,6 +35,7 @@ using Ryujinx.Input.HLE;
using Ryujinx.Ui.Common; using Ryujinx.Ui.Common;
using Ryujinx.Ui.Common.Configuration; using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Helper; using Ryujinx.Ui.Common.Helper;
using Silk.NET.Vulkan;
using SixLabors.ImageSharp; using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Png; using SixLabors.ImageSharp.Formats.Png;
using SixLabors.ImageSharp.PixelFormats; using SixLabors.ImageSharp.PixelFormats;
@ -701,6 +702,7 @@ namespace Ryujinx.Ava
if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Vulkan) if (ConfigurationState.Instance.Graphics.GraphicsBackend.Value == GraphicsBackend.Vulkan)
{ {
renderer = new VulkanRenderer( renderer = new VulkanRenderer(
Vk.GetApi(),
(_rendererHost.EmbeddedWindow as EmbeddedWindowVulkan).CreateSurface, (_rendererHost.EmbeddedWindow as EmbeddedWindowVulkan).CreateSurface,
VulkanHelper.GetRequiredInstanceExtensions, VulkanHelper.GetRequiredInstanceExtensions,
ConfigurationState.Instance.Graphics.PreferredGpu.Value); ConfigurationState.Instance.Graphics.PreferredGpu.Value);

View file

@ -25,6 +25,7 @@ using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Net.NetworkInformation; using System.Net.NetworkInformation;
using TimeZone = Ryujinx.Ava.UI.Models.TimeZone; using TimeZone = Ryujinx.Ava.UI.Models.TimeZone;
using Silk.NET.Vulkan;
namespace Ryujinx.Ava.UI.ViewModels namespace Ryujinx.Ava.UI.ViewModels
{ {
@ -310,7 +311,7 @@ namespace Ryujinx.Ava.UI.ViewModels
{ {
_gpuIds = new List<string>(); _gpuIds = new List<string>();
List<string> names = new(); List<string> names = new();
var devices = VulkanRenderer.GetPhysicalDevices(); var devices = VulkanRenderer.GetPhysicalDevices(Vk.GetApi());
if (devices.Length == 0) if (devices.Length == 0)
{ {

View file

@ -89,11 +89,12 @@ namespace Ryujinx.Graphics.Vulkan
public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured; public event EventHandler<ScreenCaptureImageInfo> ScreenCaptured;
public VulkanRenderer(Func<Instance, Vk, SurfaceKHR> surfaceFunc, Func<string[]> requiredExtensionsFunc, string preferredGpuId) public VulkanRenderer(Vk api, Func<Instance, Vk, SurfaceKHR> surfaceFunc, Func<string[]> requiredExtensionsFunc, string preferredGpuId)
{ {
_getSurface = surfaceFunc; _getSurface = surfaceFunc;
_getRequiredExtensions = requiredExtensionsFunc; _getRequiredExtensions = requiredExtensionsFunc;
_preferredGpuId = preferredGpuId; _preferredGpuId = preferredGpuId;
Api = api;
Shaders = new HashSet<ShaderCollection>(); Shaders = new HashSet<ShaderCollection>();
Textures = new HashSet<ITexture>(); Textures = new HashSet<ITexture>();
Samplers = new HashSet<SamplerHolder>(); Samplers = new HashSet<SamplerHolder>();
@ -345,31 +346,27 @@ namespace Ryujinx.Graphics.Vulkan
private unsafe void SetupContext(GraphicsDebugLevel logLevel) private unsafe void SetupContext(GraphicsDebugLevel logLevel)
{ {
var api = Vk.GetApi(); _instance = VulkanInitialization.CreateInstance(Api, logLevel, _getRequiredExtensions());
_debugMessenger = new VulkanDebugMessenger(Api, _instance.Instance, logLevel);
Api = api; if (Api.TryGetInstanceExtension(_instance.Instance, out KhrSurface surfaceApi))
_instance = VulkanInitialization.CreateInstance(api, logLevel, _getRequiredExtensions());
_debugMessenger = new VulkanDebugMessenger(api, _instance.Instance, logLevel);
if (api.TryGetInstanceExtension(_instance.Instance, out KhrSurface surfaceApi))
{ {
SurfaceApi = surfaceApi; SurfaceApi = surfaceApi;
} }
_surface = _getSurface(_instance.Instance, api); _surface = _getSurface(_instance.Instance, Api);
_physicalDevice = VulkanInitialization.FindSuitablePhysicalDevice(api, _instance, _surface, _preferredGpuId); _physicalDevice = VulkanInitialization.FindSuitablePhysicalDevice(Api, _instance, _surface, _preferredGpuId);
var queueFamilyIndex = VulkanInitialization.FindSuitableQueueFamily(api, _physicalDevice, _surface, out uint maxQueueCount); var queueFamilyIndex = VulkanInitialization.FindSuitableQueueFamily(Api, _physicalDevice, _surface, out uint maxQueueCount);
_device = VulkanInitialization.CreateDevice(api, _physicalDevice, queueFamilyIndex, maxQueueCount); _device = VulkanInitialization.CreateDevice(Api, _physicalDevice, queueFamilyIndex, maxQueueCount);
if (api.TryGetDeviceExtension(_instance.Instance, _device, out KhrSwapchain swapchainApi)) if (Api.TryGetDeviceExtension(_instance.Instance, _device, out KhrSwapchain swapchainApi))
{ {
SwapchainApi = swapchainApi; SwapchainApi = swapchainApi;
} }
api.GetDeviceQueue(_device, queueFamilyIndex, 0, out var queue); Api.GetDeviceQueue(_device, queueFamilyIndex, 0, out var queue);
Queue = queue; Queue = queue;
QueueLock = new object(); QueueLock = new object();
@ -603,11 +600,11 @@ namespace Ryujinx.Graphics.Vulkan
return new HardwareInfo(GpuVendor, GpuRenderer); return new HardwareInfo(GpuVendor, GpuRenderer);
} }
public static DeviceInfo[] GetPhysicalDevices() public static DeviceInfo[] GetPhysicalDevices(Vk api)
{ {
try try
{ {
return VulkanInitialization.GetSuitablePhysicalDevices(Vk.GetApi()); return VulkanInitialization.GetSuitablePhysicalDevices(api);
} }
catch (Exception) catch (Exception)
{ {

View file

@ -487,11 +487,12 @@ namespace Ryujinx.Headless.SDL2
if (options.GraphicsBackend == GraphicsBackend.Vulkan && window is VulkanWindow vulkanWindow) if (options.GraphicsBackend == GraphicsBackend.Vulkan && window is VulkanWindow vulkanWindow)
{ {
string preferredGpuId = string.Empty; string preferredGpuId = string.Empty;
Vk api = Vk.GetApi();
if (!string.IsNullOrEmpty(options.PreferredGpuVendor)) if (!string.IsNullOrEmpty(options.PreferredGpuVendor))
{ {
string preferredGpuVendor = options.PreferredGpuVendor.ToLowerInvariant(); string preferredGpuVendor = options.PreferredGpuVendor.ToLowerInvariant();
var devices = VulkanRenderer.GetPhysicalDevices(); var devices = VulkanRenderer.GetPhysicalDevices(api);
foreach (var device in devices) foreach (var device in devices)
{ {
@ -504,6 +505,7 @@ namespace Ryujinx.Headless.SDL2
} }
return new VulkanRenderer( return new VulkanRenderer(
api,
(instance, vk) => new SurfaceKHR((ulong)(vulkanWindow.CreateWindowSurface(instance.Handle))), (instance, vk) => new SurfaceKHR((ulong)(vulkanWindow.CreateWindowSurface(instance.Handle))),
vulkanWindow.GetRequiredInstanceExtensions, vulkanWindow.GetRequiredInstanceExtensions,
preferredGpuId); preferredGpuId);

View file

@ -426,7 +426,7 @@ namespace Ryujinx.Ui
if (ConfigurationState.Instance.Graphics.GraphicsBackend == GraphicsBackend.Vulkan) if (ConfigurationState.Instance.Graphics.GraphicsBackend == GraphicsBackend.Vulkan)
{ {
string preferredGpu = ConfigurationState.Instance.Graphics.PreferredGpu.Value; string preferredGpu = ConfigurationState.Instance.Graphics.PreferredGpu.Value;
renderer = new VulkanRenderer(CreateVulkanSurface, VulkanHelper.GetRequiredInstanceExtensions, preferredGpu); renderer = new VulkanRenderer(Vk.GetApi(), CreateVulkanSurface, VulkanHelper.GetRequiredInstanceExtensions, preferredGpu);
} }
else else
{ {

View file

@ -13,6 +13,7 @@ using Ryujinx.Ui.Common.Configuration;
using Ryujinx.Ui.Common.Configuration.System; using Ryujinx.Ui.Common.Configuration.System;
using Ryujinx.Ui.Helper; using Ryujinx.Ui.Helper;
using Ryujinx.Ui.Widgets; using Ryujinx.Ui.Widgets;
using Silk.NET.Vulkan;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
@ -477,7 +478,7 @@ namespace Ryujinx.Ui.Windows
if (Enum.Parse<GraphicsBackend>(_graphicsBackend.ActiveId) == GraphicsBackend.Vulkan) if (Enum.Parse<GraphicsBackend>(_graphicsBackend.ActiveId) == GraphicsBackend.Vulkan)
{ {
var devices = VulkanRenderer.GetPhysicalDevices(); var devices = VulkanRenderer.GetPhysicalDevices(Vk.GetApi());
string preferredGpuIdFromConfig = ConfigurationState.Instance.Graphics.PreferredGpu.Value; string preferredGpuIdFromConfig = ConfigurationState.Instance.Graphics.PreferredGpu.Value;
string preferredGpuId = preferredGpuIdFromConfig; string preferredGpuId = preferredGpuIdFromConfig;
bool noGpuId = string.IsNullOrEmpty(preferredGpuIdFromConfig); bool noGpuId = string.IsNullOrEmpty(preferredGpuIdFromConfig);