private unsafe void CreateInstance(IVkSurface vkSurface, string[] requestedExtensions, string[]?validationLayers, out Instance instance) { nint applicationName = Info.ApplicationName.Marshal(); nint engineName = Info.EngineName.Marshal(); ApplicationInfo applicationInfo = new ApplicationInfo { SType = StructureType.ApplicationInfo, PApplicationName = (byte *)applicationName, ApplicationVersion = Info.ApplicationVersion, PEngineName = (byte *)engineName, EngineVersion = Info.EngineVersion, ApiVersion = Info.APIVersion }; string[] requiredExtensions = VKAPI.GetRequiredExtensions(vkSurface, requestedExtensions); nint requiredExtensionsPointer = SilkMarshal.StringArrayToPtr(requiredExtensions); nint enabledLayerNames = 0x0; int enabledLayerCount = 0; InstanceCreateInfo createInfo = new InstanceCreateInfo { SType = StructureType.InstanceCreateInfo, PApplicationInfo = &applicationInfo, PpEnabledExtensionNames = (byte **)requiredExtensionsPointer, EnabledExtensionCount = (uint)requiredExtensions.Length, PpEnabledLayerNames = (byte **)null !, EnabledLayerCount = 0, PNext = (void *)null ! }; if (validationLayers is not null) { VKAPI.VerifyValidationLayerSupport(VK, validationLayers); enabledLayerNames = SilkMarshal.StringArrayToPtr(validationLayers); enabledLayerCount = validationLayers.Length; createInfo.PpEnabledLayerNames = (byte **)enabledLayerNames; createInfo.EnabledLayerCount = (uint)enabledLayerCount; } Log.Information(string.Format(FormatHelper.DEFAULT_LOGGING, nameof(VulkanInstance), "allocating instance.")); Result result = VK.CreateInstance(&createInfo, (AllocationCallbacks *)null !, out instance); if (result is not Result.Success) { throw new VulkanException(result, "Failed to create Vulkan instance."); } SilkMarshal.FreeString(applicationName); SilkMarshal.FreeString(engineName); SilkMarshal.FreeString(requiredExtensionsPointer); if (enabledLayerNames is not 0x0 && enabledLayerCount is not 0) { SilkMarshal.FreeString(enabledLayerNames); } }
public VKImageUploader(string url, VKAPI api, Hashtable postData) { _api = api; _postData = postData; uploadImage(url); }