protected override void PlatformDispose() { _scFB.Dispose(); vkDestroySurfaceKHR(_instance, _surface, null); if (_debugCallbackFunc != null) { _debugCallbackFunc = null; FixedUtf8String debugExtFnName = "vkDestroyDebugReportCallbackEXT"; IntPtr destroyFuncPtr = vkGetInstanceProcAddr(_instance, debugExtFnName); vkDestroyDebugReportCallbackEXT_d destroyDel = Marshal.GetDelegateForFunctionPointer <vkDestroyDebugReportCallbackEXT_d>(destroyFuncPtr); VkResult debugDestroyResult = destroyDel(_instance, _debugCallbackHandle, null); CheckResult(debugDestroyResult); } vkDestroyDescriptorPool(_device, _descriptorPool, null); vkDestroyCommandPool(_device, _graphicsCommandPool, null); vkDestroyFence(_device, _imageAvailableFence, null); _memoryManager.Dispose(); VkResult result = vkDeviceWaitIdle(_device); CheckResult(result); vkDestroyDevice(_device, null); vkDestroyInstance(_instance, null); }
public void EnableDebugCallback(VkDebugReportFlagsEXT flags = VkDebugReportFlagsEXT.WarningEXT | VkDebugReportFlagsEXT.ErrorEXT) { Debug.WriteLine("Enabling Vulkan Debug callbacks."); _debugCallbackFunc = DebugCallback; IntPtr debugFunctionPtr = Marshal.GetFunctionPointerForDelegate(_debugCallbackFunc); VkDebugReportCallbackCreateInfoEXT debugCallbackCI = VkDebugReportCallbackCreateInfoEXT.New(); debugCallbackCI.flags = flags; debugCallbackCI.pfnCallback = debugFunctionPtr; IntPtr createFnPtr; using (FixedUtf8String debugExtFnName = "vkCreateDebugReportCallbackEXT") { createFnPtr = vkGetInstanceProcAddr(_instance, debugExtFnName); } vkCreateDebugReportCallbackEXT_d createDelegate = Marshal.GetDelegateForFunctionPointer <vkCreateDebugReportCallbackEXT_d>(createFnPtr); VkResult result = createDelegate(_instance, &debugCallbackCI, IntPtr.Zero, out _debugCallbackHandle); CheckResult(result); }
private void CreateLogicalDevice() { GetQueueFamilyIndices(); HashSet <uint> familyIndices = new HashSet <uint> { _graphicsQueueIndex, _presentQueueIndex }; RawList <VkDeviceQueueCreateInfo> queueCreateInfos = new RawList <VkDeviceQueueCreateInfo>(); foreach (uint index in familyIndices) { VkDeviceQueueCreateInfo queueCreateInfo = VkDeviceQueueCreateInfo.New(); queueCreateInfo.queueFamilyIndex = _graphicsQueueIndex; queueCreateInfo.queueCount = 1; float priority = 1f; queueCreateInfo.pQueuePriorities = &priority; queueCreateInfos.Add(queueCreateInfo); } VkPhysicalDeviceFeatures deviceFeatures = new VkPhysicalDeviceFeatures(); deviceFeatures.samplerAnisotropy = true; deviceFeatures.fillModeNonSolid = true; deviceFeatures.geometryShader = true; deviceFeatures.depthClamp = true; bool debugMarkerSupported = false; uint propertyCount = 0; VkResult result = vkEnumerateDeviceExtensionProperties(_physicalDevice, (byte *)null, &propertyCount, null); CheckResult(result); VkExtensionProperties *properties = stackalloc VkExtensionProperties[(int)propertyCount]; result = vkEnumerateDeviceExtensionProperties(_physicalDevice, (byte *)null, &propertyCount, properties); CheckResult(result); for (int i = 0; i < propertyCount; i++) { if (Util.GetString(properties[i].extensionName) == "VK_EXT_debug_marker") { Console.WriteLine("VK_EXT_debug_marker is available."); debugMarkerSupported = true; break; } } VkDeviceCreateInfo deviceCreateInfo = VkDeviceCreateInfo.New(); fixed(VkDeviceQueueCreateInfo *qciPtr = &queueCreateInfos.Items[0]) { deviceCreateInfo.pQueueCreateInfos = qciPtr; deviceCreateInfo.queueCreateInfoCount = queueCreateInfos.Count; deviceCreateInfo.pEnabledFeatures = &deviceFeatures; StackList <IntPtr> layerNames = new StackList <IntPtr>(); layerNames.Add(CommonStrings.StandardValidationLayerName); deviceCreateInfo.enabledLayerCount = layerNames.Count; deviceCreateInfo.ppEnabledLayerNames = (byte **)layerNames.Data; StackList <IntPtr> extensionNames = new StackList <IntPtr>(); extensionNames.Add(CommonStrings.VK_KHR_SWAPCHAIN_EXTENSION_NAME); if (debugMarkerSupported) { extensionNames.Add(CommonStrings.VK_EXT_DEBUG_MARKER_EXTENSION_NAME); _debugMarkerEnabled = true; } deviceCreateInfo.enabledExtensionCount = extensionNames.Count; deviceCreateInfo.ppEnabledExtensionNames = (byte **)extensionNames.Data; result = vkCreateDevice(_physicalDevice, ref deviceCreateInfo, null, out _device); CheckResult(result); } vkGetDeviceQueue(_device, _graphicsQueueIndex, 0, out _graphicsQueue); vkGetDeviceQueue(_device, _presentQueueIndex, 0, out _presentQueue); if (debugMarkerSupported) { IntPtr setObjectNamePtr; using (FixedUtf8String debugExtFnName = "vkDebugMarkerSetObjectNameEXT") { setObjectNamePtr = vkGetInstanceProcAddr(_instance, debugExtFnName); } _setObjectNameDelegate = Marshal.GetDelegateForFunctionPointer <vkDebugMarkerSetObjectNameEXT_d>(setObjectNamePtr); } }