public IMgLogicalDevice CreateDevice(IMgPhysicalDevice gpu, IMgSurfaceKHR presentationSurface, MgQueueAllocation requestCount, MgQueueFlagBits requestedQueueType, string[] enabledExtensions) { // Find a queue that supports graphics operations MgQueueFamilyProperties[] queueProps; gpu.GetPhysicalDeviceQueueFamilyProperties(out queueProps); Debug.Assert(queueProps != null); Debug.Assert(queueProps.Length >= 1); uint queueFamilyIndex = 0; queueFamilyIndex = presentationSurface != null ? FindAppropriateQueueFamilyForSurface(gpu, presentationSurface, queueProps, requestedQueueType) : FindAppropriateQueueFamily(queueProps, requestedQueueType); uint noOfQueues = (requestCount == MgQueueAllocation.One) ? 1 : queueProps [queueFamilyIndex].QueueCount; var queuePriorities = new float[noOfQueues]; for (uint i = 0; i < noOfQueues; ++i) { queuePriorities [i] = 0f; } var queueCreateInfo = new MgDeviceQueueCreateInfo { QueueFamilyIndex = queueFamilyIndex, QueueCount = noOfQueues, QueuePriorities = queuePriorities, }; return(CreateDevice(gpu, queueCreateInfo, enabledExtensions)); }
public IMgLogicalDevice CreateLogicalDevice( IMgSurfaceKHR presentationSurface, MgDeviceExtensionOptions option, MgQueueAllocation allocationUsage, MgQueueFlagBits deviceUsage) { string[] extensions = null; IMgPhysicalDevice[] physicalDevices; var errorCode = mInstance.EnumeratePhysicalDevices(out physicalDevices); Debug.Assert(errorCode == Result.SUCCESS, errorCode + " != Result.SUCCESS"); IMgPhysicalDevice firstPhysicalDevice = physicalDevices[0]; if (option == MgDeviceExtensionOptions.ALL) { MgExtensionProperties[] extensionProperties; var err = firstPhysicalDevice.EnumerateDeviceExtensionProperties(null, out extensionProperties); Debug.Assert(err == Result.SUCCESS, err + " != Result.SUCCESS"); var enabledExtensions = new List <string>(); if (extensionProperties != null) { foreach (var ext in extensionProperties) { enabledExtensions.Add(ext.ExtensionName); } } extensions = enabledExtensions.ToArray(); } return(CreateDevice(firstPhysicalDevice, presentationSurface, allocationUsage, deviceUsage, extensions)); }
static uint FindAppropriateQueueFamilyForSurface( IMgPhysicalDevice gpu, IMgSurfaceKHR presentationSurface, MgQueueFamilyProperties[] queueProps, MgQueueFlagBits requestedQueueType) { bool[] supportsPresent = new bool[queueProps.Length]; // Iterate over each queue to learn whether it supports presenting: for (UInt32 i = 0; i < queueProps.Length; ++i) { gpu.GetPhysicalDeviceSurfaceSupportKHR(i, presentationSurface, ref supportsPresent [i]); } // Search for a graphics and a present queue in the array of queue // families, try to find one that supports both UInt32 requestedQueueNodeIndex = UInt32.MaxValue; UInt32 presentQueueNodeIndex = UInt32.MaxValue; for (UInt32 i = 0; i < queueProps.Length; i++) { var queue = queueProps [i]; if ((queue.QueueFlags & requestedQueueType) != 0) { if (requestedQueueNodeIndex == UInt32.MaxValue) { requestedQueueNodeIndex = i; } if (supportsPresent [i]) { requestedQueueNodeIndex = i; presentQueueNodeIndex = i; break; } } } if (presentQueueNodeIndex == UInt32.MaxValue) { // If didn't find a queue that supports both graphics and present, then // find a separate present queue. for (UInt32 i = 0; i < queueProps.Length; ++i) { if (supportsPresent [i]) { presentQueueNodeIndex = i; break; } } } if (requestedQueueNodeIndex == UInt32.MaxValue) { throw new Exception("Could not find queue of requested queue type"); } // Generate error if could not find both a graphics and a present queue if (presentQueueNodeIndex == UInt32.MaxValue) { throw new Exception("Could not find a presentation queue"); } // VERBATIM from cube.c // TODO: Add support for separate queues, including presentation, // synchronization, and appropriate tracking for QueueSubmit. // NOTE: While it is possible for an application to use a separate graphics // and a present queues, this demo program assumes it is only using // one: if (requestedQueueNodeIndex != presentQueueNodeIndex) { throw new Exception("Could not find an common queue"); } return(requestedQueueNodeIndex); }
public Result GetPhysicalDeviceSurfaceFormatsKHR(IMgSurfaceKHR surface, out MgSurfaceFormatKHR[] pSurfaceFormats) { throw new NotImplementedException(); }
public Result GetPhysicalDeviceSurfacePresentModesKHR(IMgSurfaceKHR surface, out MgPresentModeKHR[] pPresentModes) { throw new NotImplementedException(); }
public Result GetPhysicalDeviceSurfaceSupportKHR(uint queueFamilyIndex, IMgSurfaceKHR surface, ref bool pSupported) { throw new NotImplementedException(); }
public Result GetPhysicalDeviceSurfaceCapabilitiesKHR(IMgSurfaceKHR surface, out MgSurfaceCapabilitiesKHR pSurfaceCapabilities) { throw new NotImplementedException(); }
public Result CreateDisplayPlaneSurfaceKHR(MgDisplaySurfaceCreateInfoKHR createInfo, IMgAllocationCallbacks allocator, out IMgSurfaceKHR pSurface) { if (createInfo == null) { throw new ArgumentNullException(nameof(createInfo)); } Debug.Assert(!mIsDisposed); var bDisplayMode = (VkDisplayModeKHR)createInfo.DisplayMode; Debug.Assert(bDisplayMode != null); var pCreateInfo = new VkDisplaySurfaceCreateInfoKHR { sType = VkStructureType.StructureTypeDisplaySurfaceCreateInfoKhr, pNext = IntPtr.Zero, flags = createInfo.Flags, displayMode = bDisplayMode.Handle, planeIndex = createInfo.PlaneIndex, planeStackIndex = createInfo.PlaneStackIndex, transform = (VkSurfaceTransformFlagsKhr)createInfo.Transform, globalAlpha = createInfo.GlobalAlpha, alphaMode = (VkDisplayPlaneAlphaFlagsKhr)createInfo.AlphaMode, imageExtent = createInfo.ImageExtent, }; // MIGHT NEED GetInstanceProcAddr INSTEAD var allocatorHandle = GetAllocatorHandle(allocator); UInt64 handle = 0UL; var result = Interops.vkCreateDisplayPlaneSurfaceKHR(Handle, ref pCreateInfo, allocatorHandle, ref handle); pSurface = new VkSurfaceKHR(handle); return(result); }
public Result CreateWin32SurfaceKHR(MgWin32SurfaceCreateInfoKHR pCreateInfo, IMgAllocationCallbacks allocator, out IMgSurfaceKHR pSurface) { if (pCreateInfo == null) { throw new ArgumentNullException(nameof(pCreateInfo)); } Debug.Assert(!mIsDisposed); var allocatorHandle = GetAllocatorHandle(allocator); var createInfo = new VkWin32SurfaceCreateInfoKHR { sType = VkStructureType.StructureTypeWin32SurfaceCreateInfoKhr, pNext = IntPtr.Zero, flags = pCreateInfo.Flags, hinstance = pCreateInfo.Hinstance, hwnd = pCreateInfo.Hwnd, }; // TODO : MIGHT NEED GetInstanceProcAddr INSTEAD var surfaceHandle = 0UL; var result = Interops.vkCreateWin32SurfaceKHR(Handle, ref createInfo, allocatorHandle, ref surfaceHandle); pSurface = new VkSurfaceKHR(surfaceHandle); return(result); }
public Result CreateAndroidSurfaceKHR(MgAndroidSurfaceCreateInfoKHR pCreateInfo, IMgAllocationCallbacks allocator, out IMgSurfaceKHR pSurface) { throw new NotImplementedException(); }
public void DestroySurfaceKHR(IMgSurfaceKHR surface, IMgAllocationCallbacks allocator) { throw new NotImplementedException(); }
public Result CreateDisplayPlaneSurfaceKHR(MgDisplaySurfaceCreateInfoKHR createInfo, IMgAllocationCallbacks allocator, out IMgSurfaceKHR pSurface) { throw new NotImplementedException(); }