// Destroys the global vulkan objects
        private void destroyGlobalVulkanObjects(Vk.Instance inst, VkExt.DebugReportCallbackExt debugReport, Vk.Device device)
        {
            device?.Dispose();
            LINFO("Destroyed Vulkan device.");

            if (debugReport != null)
            {
                debugReport.Dispose();
                LINFO("Destroyed Vulkan debug report callback.");
            }

            inst.Dispose();
            LINFO("Destroyed Vulkan instance.");
        }
        // Creates a VkInstance
        private void createVulkanInstance(out Vk.Instance instance, out VkExt.DebugReportCallbackExt debugReport)
        {
            var appVersion = Application.AppParameters.Version;
            var engVersion = Assembly.GetExecutingAssembly().GetName().Version;

            // Build the app info
            Vk.ApplicationInfo aInfo = new Vk.ApplicationInfo(
                Application.AppParameters.Name,
                appVersion.ToVkVersion(),
                "Spectrum",
                new Vk.Version(engVersion.Major, engVersion.Minor, engVersion.Revision),
                new Vk.Version(1, 0, 0)
                );

            // Get available instance extensions, and ensure the required ones are present
            var           availExt = Vk.Instance.EnumerateExtensionProperties().Select(ext => ext.ExtensionName).ToArray();
            List <string> reqExt   = new List <string>();

            reqExt.Add(Vk.Constant.InstanceExtension.KhrSurface);
            switch (Platform.OS)
            {
            case PlatformOS.Windows: reqExt.Add(Vk.Constant.InstanceExtension.KhrWin32Surface); break;

            case PlatformOS.Linux: reqExt.Add(Vk.Constant.InstanceExtension.KhrXlibSurface); break;

            case PlatformOS.OSX: reqExt.Add(Vk.Constant.InstanceExtension.MvkMacOSSurface); break;
            }
            {
                var missingExts = reqExt.FindAll(extName => !availExt.Contains(extName));
                if (missingExts.Count > 0)
                {
                    string msg = $"Required Vulkan extensions are missing: {String.Join(", ", missingExts)}";
                    LFATAL(msg);
                    throw new PlatformNotSupportedException(msg);
                }
            }

            // Check for validation layers, if requested
            bool hasDebug = false;

            if (Application.AppParameters.EnableValidationLayers)
            {
                if (availExt.Contains(Vk.Constant.InstanceExtension.ExtDebugReport))
                {
                    var availLay = Vk.Instance.EnumerateLayerProperties().Select(layer => layer.LayerName).ToArray();

                    hasDebug = availLay.Contains("VK_LAYER_KHRONOS_validation");
                    if (hasDebug)
                    {
                        reqExt.Add(Vk.Constant.InstanceExtension.ExtDebugReport);
                    }
                    else
                    {
                        LERROR("Application requested Vulkan validation layers, but the standard layers are not available.");
                    }
                }
                else
                {
                    LERROR("Application requested Vulkan validation layers, but the debug report extension is not available.");
                }
            }

            // Create the instance
            Vk.InstanceCreateInfo iInfo = new Vk.InstanceCreateInfo(
                aInfo,
                hasDebug ? new[] { "VK_LAYER_KHRONOS_validation" } : null,
                reqExt.ToArray(),
                IntPtr.Zero
                );
            instance = new Vk.Instance(iInfo, null);
            LINFO("Created Vulkan instance.");

            // Create the debug callback if needed
            debugReport = null;
            if (hasDebug)
            {
                VkExt.DebugReportCallbackCreateInfoExt dbInfo = new VkExt.DebugReportCallbackCreateInfoExt(
                    (VkExt.DebugReportFlagsExt.PerformanceWarning | VkExt.DebugReportFlagsExt.Warning | VkExt.DebugReportFlagsExt.Error),
                    _DebugReportCallback,
                    IntPtr.Zero
                    );
                debugReport = VkExt.InstanceExtensions.CreateDebugReportCallbackExt(instance, dbInfo, null);
                LINFO("Created Vulkan debug report callback.");
            }
        }