Example #1
0
        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));
        }
Example #2
0
        static uint FindAppropriateQueueFamily(MgQueueFamilyProperties[] queueProps, MgQueueFlagBits requestedQueueType)
        {
            for (uint i = 0; i < queueProps.Length; ++i)
            {
                // Find a queue that supports gfx
                if ((queueProps [i].QueueFlags & requestedQueueType) == requestedQueueType)
                {
                    return(i);
                }
            }

            throw new Exception("Could not find a queue");
        }
Example #3
0
        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));
        }
Example #4
0
        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);
        }