Esempio n. 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));
        }
Esempio n. 2
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));
        }