public static uint FindSuitableQueueFamily(Vk api, PhysicalDevice physicalDevice, SurfaceKHR surface, out uint queueCount) { const QueueFlags RequiredFlags = QueueFlags.QueueGraphicsBit | QueueFlags.QueueComputeBit; var khrSurface = new KhrSurface(api.Context); uint propertiesCount; api.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, &propertiesCount, null); QueueFamilyProperties[] properties = new QueueFamilyProperties[propertiesCount]; fixed(QueueFamilyProperties *pProperties = properties) { api.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, &propertiesCount, pProperties); } for (uint index = 0; index < propertiesCount; index++) { var queueFlags = properties[index].QueueFlags; khrSurface.GetPhysicalDeviceSurfaceSupport(physicalDevice, index, surface, out var surfaceSupported).ThrowOnError(); if (queueFlags.HasFlag(RequiredFlags) && surfaceSupported) { queueCount = properties[index].QueueCount; return(index); } } queueCount = 0; return(InvalidIndex); }
private static unsafe bool FindQueueFamilyIndices(PhysicalDevice physicalDevice, SurfaceKHR surface, out uint?graphicsQueueFamily, out uint?presentQueueFamily) { graphicsQueueFamily = presentQueueFamily = null; uint queueFamilyCount = 0; Vk.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, ref queueFamilyCount, null); Span <QueueFamilyProperties> props = stackalloc QueueFamilyProperties[(int)queueFamilyCount]; Vk.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, ref queueFamilyCount, out props[0]); for (int i = 0; i < queueFamilyCount; i++) { QueueFamilyProperties prop = props[i]; if (prop.QueueFlags.HasFlag(QueueFlags.QueueGraphicsBit) && !graphicsQueueFamily.HasValue) { graphicsQueueFamily = (uint)i; } AssertVulkan(KhrSurface.GetPhysicalDeviceSurfaceSupport(physicalDevice, (uint)i, surface, out Bool32 supported)); if (supported && !presentQueueFamily.HasValue) { presentQueueFamily = (uint)i; } if (graphicsQueueFamily.HasValue && presentQueueFamily.HasValue) { return(true); } } return(false); }
public Api(bool enableDebugLogging, ILogger logger) { DebugLoggingEnabled = enableDebugLogging; _vk = Vk.GetApi(); _khrSurface = new KhrSurface(_vk.Context); Logger = logger; }
internal static VulkanSurface CreateSurface(VulkanInstance instance, IVulkanPlatformSurface vulkanPlatformSurface) { if (SurfaceExtension == null) { instance.Api.TryGetInstanceExtension(instance.InternalHandle, out KhrSurface extension); SurfaceExtension = extension; } return(new VulkanSurface(vulkanPlatformSurface, instance)); }
public QueueManager( Vk vk, KhrSurface khrSurface, Instance instance, PhysicalDevice physicalDevice, Device logicalDevice, SurfaceKHR surface, Span <QueueFamilyProperties> span) { _vk = vk; _khrSurface = khrSurface; _instance = instance; _physicalDevice = physicalDevice; _device = logicalDevice; _surface = surface; var queues = new List <QueueInfo>(); for (uint i = 0; i < span.Length; i++) { var queueFamilyProperties = span[(int)i]; var supportsGraphics = (queueFamilyProperties.QueueFlags & QueueFlags.QueueGraphicsBit) != 0; var supportsCompute = (queueFamilyProperties.QueueFlags & QueueFlags.QueueComputeBit) != 0; var supportsTransfer = supportsGraphics || supportsCompute || (queueFamilyProperties.QueueFlags & QueueFlags.QueueTransferBit) != 0; _khrSurface.GetPhysicalDeviceSurfaceSupport(physicalDevice, i, _surface, out var presentSupported).ThrowCode(); for (uint j = 0; j < queueFamilyProperties.QueueCount; j++) { _vk.GetDeviceQueue(_device, i, j, out var queue); queues.Add(new QueueInfo(i, queue, supportsTransfer, supportsCompute, supportsGraphics, presentSupported)); } } _queues = queues.ToArray(); Console.WriteLine($"Found {_queues.Length} queues"); }
void LoadInstanceLevelEntryPoints() { var instLoad = new VulkanInstanceHandleResolver(vk, vulkan.Instance); khrSurface = new KhrSurface(instLoad); khrW32surface = new KhrWin32Surface(instLoad); if (supportDebugReport) { extDebugReport = new ExtDebugReport(instLoad); debugReportCallback = OnDebugReport; var inf = new DebugReportCallbackCreateInfoEXT() { sType = StructureType.DebugReportCallbackCreateInfoExt, pNext = IntPtr.Zero, flags = DebugReportFlagBitsEXT.InformationBitExt | DebugReportFlagBitsEXT.WarningBitExt | DebugReportFlagBitsEXT.PerformanceWarningBitExt | DebugReportFlagBitsEXT.ErrorExt | DebugReportFlagBitsEXT.DebugBitExt, pfnCallback = Marshal.GetFunctionPointerForDelegate(debugReportCallback), pUserData = IntPtr.Zero, }; extDebugReport.CreateDebugReportCallbackEXT(vulkan.Instance, ref inf, (AllocationCallbacks *)0, out debugReportHandle).CheckError(); } }