Example #1
0
        /// <summary>
        /// Gets the version-aware properties associated with the physical device.
        /// </summary>
        /// <param name="device">The device to get the properties for.</param>
        /// <param name="props">The Vulkan 1.0 properties.</param>
        /// <param name="props11">The Vulkan 1.1 properties.</param>
        /// <param name="props12">The Vulkan 1.2 properties.</param>
        public static void GetProperties(VkPhysicalDevice device,
                                         out VkPhysicalDeviceProperties props,
                                         out VkPhysicalDeviceVulkan11Properties props11,
                                         out VkPhysicalDeviceVulkan12Properties props12)
        {
            if (!device)
            {
                throw new ArgumentNullException(nameof(device), "Cannot pass null device or device handle");
            }

            VkPhysicalDeviceProperties.New(out props);
            VkPhysicalDeviceVulkan11Properties.New(out props11);
            VkPhysicalDeviceVulkan12Properties.New(out props12);
            var version = device.Parent.Functions.CoreVersion;

            // 1.0
            if (version < VkVersion.VK_VERSION_1_1)
            {
                device.GetPhysicalDeviceProperties(out props);
            }
            // 1.1
            else if (version < VkVersion.VK_VERSION_1_2)
            {
                VkPhysicalDeviceProperties2.New(out var props2);
                fixed(VkPhysicalDeviceVulkan11Properties *ptr11 = &props11)
                {
                    props2.pNext = ptr11;
                    device.GetPhysicalDeviceProperties2(&props2);
                    props = props2.Properties;
                }
            }
            // 1.2
            else
            {
                VkPhysicalDeviceProperties2.New(out var props2);
                fixed(VkPhysicalDeviceVulkan11Properties *ptr11 = &props11)
                fixed(VkPhysicalDeviceVulkan12Properties * ptr12 = &props12)
                {
                    props2.pNext = ptr11;
                    ptr11->pNext = ptr12;
                    device.GetPhysicalDeviceProperties2(&props2);
                    props        = props2.Properties;
                    ptr11->pNext = null;
                }
            }
        }
Example #2
0
        internal PhysicalDevice(Instance instance, VkPhysicalDevice handle)
        {
            Instance = instance;
            Handle   = handle;
            unsafe
            {
                var props = Handle.GetPhysicalDeviceProperties();
                _properties = props;
                DeviceName  = Marshal.PtrToStringAnsi(new IntPtr(props.DeviceName));
                {
                    var memProps = Handle.GetPhysicalDeviceMemoryProperties();
                    var heapList = new List <MemoryHeap>((int)memProps.MemoryHeapCount);
                    for (uint i = 0; i < memProps.MemoryHeapCount; i++)
                    {
                        heapList.Add(new MemoryHeap(i, memProps.MemoryHeaps[(int)i]));
                    }
                    MemoryHeaps = heapList;
                    var typeList = new List <MemoryType>((int)memProps.MemoryTypeCount);
                    for (uint i = 0; i < memProps.MemoryTypeCount; i++)
                    {
                        typeList.Add(new MemoryType(i, heapList[(int)memProps.MemoryTypes[(int)i].HeapIndex],
                                                    (VkMemoryPropertyFlag)memProps.MemoryTypes[(int)i].PropertyFlags));
                    }
                    MemoryTypes = typeList;
                }
            }

            {
                ExtensionProperties = new List <VkExtensionProperties>(Handle.EnumerateExtensionProperties(null));
                LayerProperties     = new List <VkLayerProperties>(Handle.EnumerateLayerProperties());
                var availableExt = new HashSet <ExtensionDescriptionAttribute>();
                foreach (var ext in ExtensionProperties)
                {
                    var desc = VkExtensionDatabase.Extension(ext.ExtensionNameString);
                    if (desc != null)
                    {
                        availableExt.Add(desc);
                    }
                }
                AvailableExtensions = availableExt;
            }
        }