private unsafe void CreateInstance() { _vk = Vk.GetApi(); if (EnableValidationLayers && !CheckValidationLayerSupport()) { throw new NotSupportedException("Validation layers requested but not available!"); } var appInfo = new ApplicationInfo { SType = StructureType.ApplicationInfo, PApplicationName = (byte *)Marshal.StringToHGlobalAnsi("Hello Triangle"), ApplicationVersion = Vk.MakeVersion(1, 0), PEngineName = (byte *)Marshal.StringToHGlobalAnsi("No Engine"), EngineVersion = Vk.MakeVersion(1, 0), ApiVersion = Vk.Version11 }; var extensions = (byte **)_window.VkSurface.GetRequiredExtensions(out var extCount); byte **newExtensions = stackalloc byte *[(int)(extCount + _instanceExtensions.Length)]; for (int i = 0; i < extCount; i++) { newExtensions[i] = extensions[i]; } for (var i = 0; i < _instanceExtensions.Length; i++) { newExtensions[extCount + i] = (byte *)SilkMarshal.MarshalStringToPtr(_instanceExtensions[i]); } extCount += (uint)_instanceExtensions.Length; var createInfo = new InstanceCreateInfo { SType = StructureType.InstanceCreateInfo, PApplicationInfo = &appInfo, EnabledExtensionCount = extCount, PpEnabledExtensionNames = newExtensions }; // debug info is here to make sure it doesnt get destroyed before vk.CreateInstance var debugCreateInfo = new DebugUtilsMessengerCreateInfoEXT(); if (EnableValidationLayers) { createInfo.EnabledLayerCount = (uint)_validationLayers.Length; createInfo.PpEnabledLayerNames = (byte **)SilkMarshal.MarshalStringArrayToPtr(_validationLayers); createInfo.PNext = &debugCreateInfo; } else { createInfo.EnabledLayerCount = 0; createInfo.PNext = null; } fixed(Instance *instance = &_instance) { Result result = _vk.CreateInstance(&createInfo, null, instance); if (result != Result.Success) { throw new Exception("Failed to create instance!"); } } _vk.CurrentInstance = _instance; if (!_vk.TryGetInstanceExtension(_instance, out _vkSurface)) { throw new NotSupportedException("KHR_surface extensions not found"); } }