// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // Ported from the Vulkan headers and corresponding dependencies. // Original source is Copyright 2015-2023 The Khronos Group Inc. Licensed under the MIT license. using System; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace Silk.NET.Vulkan; [SupportedApiProfile("vulkan")] public static unsafe partial class Vk { private InstanceHandle? _currentInstance; private DeviceHandle? _currentDevice; public InstanceHandle? CurrentInstance { get => _currentInstance; set { if (_currentInstance != null && _currentInstance != value) throw new InvalidOperationException( "CurrentInstance has already been set. Please create a new API instance so that the loaded function pointers can be kept separate." ); _currentInstance = value; } } public DeviceHandle? CurrentDevice { get => _currentDevice; set { if (_currentDevice != null && _currentDevice != value) throw new InvalidOperationException( "CurrentDevice has already been set. Please create a new API instance so that the loaded function pointers can be kept separate." ); _currentDevice = value; } } [DllImport("vulkan", ExactSpelling = true, EntryPoint = "vkCreateDevice")] [SupportedApiProfile( "vulkan", ["VK_VERSION_1_0", "VK_VERSION_1_1", "VK_VERSION_1_2", "VK_VERSION_1_3", "VK_VERSION_1_4"], MinVersion = "1.0" )] private static extern Result CreateDeviceInternal( [NativeTypeName("VkPhysicalDevice")] PhysicalDeviceHandle physicalDevice, [NativeTypeName("const VkDeviceCreateInfo *")] DeviceCreateInfo* pCreateInfo, [NativeTypeName("const VkAllocationCallbacks *")] AllocationCallbacks* pAllocator, [NativeTypeName("VkDevice *")] DeviceHandle* pDevice ); [SupportedApiProfile( "vulkan", ["VK_VERSION_1_0", "VK_VERSION_1_1", "VK_VERSION_1_2", "VK_VERSION_1_3", "VK_VERSION_1_4"], MinVersion = "1.0" )] public static Result CreateDevice( [NativeTypeName("VkPhysicalDevice")] PhysicalDeviceHandle physicalDevice, [NativeTypeName("const VkDeviceCreateInfo *")] DeviceCreateInfo* pCreateInfo, [NativeTypeName("const VkAllocationCallbacks *")] AllocationCallbacks* pAllocator, [NativeTypeName("VkDevice *")] DeviceHandle* pDevice ) { Result result = CreateDeviceInternal(physicalDevice, pCreateInfo, pAllocator, pDevice); if (result == Result.Success) { CurrentDevice = *pDevice; } return result; } [DllImport("vulkan", ExactSpelling = true, EntryPoint = "vkCreateInstance")] [SupportedApiProfile( "vulkan", ["VK_VERSION_1_0", "VK_VERSION_1_1", "VK_VERSION_1_2", "VK_VERSION_1_3", "VK_VERSION_1_4"], MinVersion = "1.0" )] private static extern Result CreateInstanceInternal( [NativeTypeName("const VkInstanceCreateInfo *")] InstanceCreateInfo* pCreateInfo, [NativeTypeName("const VkAllocationCallbacks *")] AllocationCallbacks* pAllocator, [NativeTypeName("VkInstance *")] InstanceHandle* pInstance ); [SupportedApiProfile( "vulkan", ["VK_VERSION_1_0", "VK_VERSION_1_1", "VK_VERSION_1_2", "VK_VERSION_1_3", "VK_VERSION_1_4"], MinVersion = "1.0" )] public static Result CreateInstance( [NativeTypeName("const VkInstanceCreateInfo *")] InstanceCreateInfo* pCreateInfo, [NativeTypeName("const VkAllocationCallbacks *")] AllocationCallbacks* pAllocator, [NativeTypeName("VkInstance *")] InstanceHandle* pInstance ) { Result result = CreateInstanceInternal(pCreateInfo, pAllocator, pInstance); if (result == Result.Success) { CurrentInstance = *pInstance; } return result; } }