示例#1
0
        private VkResult CreateInstance(bool enableValidation)
        {
            Settings.Validation = enableValidation;

            VkApplicationInfo appInfo = new VkApplicationInfo();

            {
                appInfo.sType      = ApplicationInfo;
                appInfo.apiVersion = VkVersion.Make(1, 0, 0);
                //Name.Set(ref appInfo.pApplicationName);
                appInfo.pApplicationName = Name;
                //Name.Set(ref appInfo.pEngineName);
                appInfo.pEngineName = Name;
            };

            var instanceExtensions = new List <string>();

            instanceExtensions.Add(Strings.VK_KHR_SURFACE_EXTENSION_NAME);
            instanceExtensions.Add(Strings.VK_KHR_WIN32_SURFACE_EXTENSION_NAME);

            VkInstanceCreateInfo instanceCreateInfo = new VkInstanceCreateInfo();

            instanceCreateInfo.sType            = InstanceCreateInfo;
            instanceCreateInfo.pApplicationInfo = &appInfo;

            if (instanceExtensions.Count > 0)
            {
                if (enableValidation)
                {
                    instanceExtensions.Add(Strings.VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
                }
                //instanceExtensions.ToArray().Set(ref instanceCreateInfo.ppEnabledExtensionNames, ref instanceCreateInfo.enabledExtensionCount);
                instanceCreateInfo.EnabledExtensions = instanceExtensions.ToArray();
            }


            if (enableValidation)
            {
                var enabledLayerNames = new List <string>();
                enabledLayerNames.Add(Strings.StandardValidationLayeName);
                //enabledLayerNames.ToArray().Set(ref instanceCreateInfo.ppEnabledLayerNames, ref instanceCreateInfo.enabledLayerCount);
                instanceCreateInfo.EnabledLayers = enabledLayerNames.ToArray();
            }

            VkInstance instance;
            VkResult   result = vkCreateInstance(&instanceCreateInfo, null, &instance);

            Instance = instance;
            return(result);
        }
示例#2
0
        /// <summary>
        /// Create a new data object for the passed instance.
        /// </summary>
        /// <param name="instance">The instance to collate data for.</param>
        public InstanceInfo(VkInstance instance)
        {
            if (!instance)
            {
                throw new ArgumentNullException(nameof(instance), "Cannot pass null instance or null instance handle");
            }
            Instance = instance;

            // Get Data
            ApiVersion = GetApiVersion();
            uint devCount;

            instance.EnumeratePhysicalDevices(&devCount, null).Throw("EnumeratePhysicalDevices");
            var handles = stackalloc VulkanHandle <VkPhysicalDevice> [(int)devCount];

            _devices = new VkPhysicalDevice[devCount];
            instance.EnumeratePhysicalDevices(&devCount, handles).Throw("EnumeratePhysicalDevices");
            for (uint i = 0; i < devCount; ++i)
            {
                _devices[i] = new(handles[i], instance);
            }
        }