public VulkanSurfaceRenderTarget(VulkanPlatformInterface platformInterface, VulkanSurface surface) { _platformInterface = platformInterface; var device = VulkanInitialization.CreateDevice(platformInterface.Api, 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; // Skia seems to only create surfaces from images with unorm format IsRgba = Display.SurfaceFormat.Format >= Format.R8G8B8A8Unorm && Display.SurfaceFormat.Format <= Format.R8G8B8A8Srgb; _format = IsRgba ? Format.R8G8B8A8Unorm : Format.B8G8R8A8Unorm; }
private VulkanPhysicalDevice(PhysicalDevice apiHandle, Vk api, uint queueCount, uint queueFamilyIndex) { InternalHandle = apiHandle; Api = api; QueueCount = queueCount; QueueFamilyIndex = queueFamilyIndex; api.GetPhysicalDeviceProperties(apiHandle, out var properties); DeviceName = Marshal.PtrToStringAnsi((IntPtr)properties.DeviceName); DeviceId = VulkanInitialization.StringFromIdPair(properties.VendorID, properties.DeviceID); var version = (Version32)properties.ApiVersion; ApiVersion = new Version((int)version.Major, (int)version.Minor, 0, (int)version.Patch); }
internal static VulkanPhysicalDevice FindSuitablePhysicalDevice(VulkanInstance instance, VulkanSurface surface, bool preferDiscreteGpu, string preferredDevice) { SelectAvailableDevices(instance, surface, preferDiscreteGpu, preferredDevice); uint queueFamilyIndex = 0; uint queueCount = 0; if (!string.IsNullOrWhiteSpace(preferredDevice)) { var physicalDevice = SuitableDevices.FirstOrDefault(x => VulkanInitialization.StringFromIdPair(x.Value.VendorID, x.Value.DeviceID) == preferredDevice); queueFamilyIndex = FindSuitableQueueFamily(instance.Api, physicalDevice.Key, surface.ApiHandle, out queueCount); if (queueFamilyIndex != int.MaxValue) { return(new VulkanPhysicalDevice(physicalDevice.Key, instance.Api, queueCount, queueFamilyIndex)); } } if (preferDiscreteGpu) { var discreteGpus = SuitableDevices.Where(p => p.Value.DeviceType == PhysicalDeviceType.DiscreteGpu); foreach (var gpu in discreteGpus) { queueFamilyIndex = FindSuitableQueueFamily(instance.Api, gpu.Key, surface.ApiHandle, out queueCount); if (queueFamilyIndex != int.MaxValue) { return(new VulkanPhysicalDevice(gpu.Key, instance.Api, queueCount, queueFamilyIndex)); } } } foreach (var physicalDevice in SuitableDevices) { queueFamilyIndex = FindSuitableQueueFamily(instance.Api, physicalDevice.Key, surface.ApiHandle, out queueCount); if (queueFamilyIndex != int.MaxValue) { return(new VulkanPhysicalDevice(physicalDevice.Key, instance.Api, queueCount, queueFamilyIndex)); } } throw new Exception("No suitable physical device found"); }