private bool checkValidationLayerSupport() { int layerCount = 0; Vulkan.vkEnumerateInstanceLayerProperties(ref layerCount, null); VkLayerProperties[] availableLayers = new VkLayerProperties[layerCount]; Vulkan.vkEnumerateInstanceLayerProperties(ref layerCount, availableLayers); foreach (var layerName in validationLayers) { bool layerFound = false; foreach (var layerProperties in availableLayers) { if (layerName == layerProperties.layerName) { layerFound = true; break; } } if (!layerFound) { return(false); } } return(true); }
public static string[] EnumerateInstanceLayers() { uint propCount = 0; VkResult result = vkEnumerateInstanceLayerProperties(ref propCount, null); CheckResult(result); if (propCount == 0) { return(Array.Empty <string>()); } VkLayerProperties[] props = new VkLayerProperties[propCount]; vkEnumerateInstanceLayerProperties(ref propCount, ref props[0]); string[] ret = new string[propCount]; for (int i = 0; i < propCount; i++) { fixed(byte *layerNamePtr = props[i].layerName) { ret[i] = Util.GetString(layerNamePtr); } } return(ret); }
internal Layer(VkLayerProperties prop) { unsafe { Name = Interop.GetString(&prop.layerName); Description = Interop.GetString(&prop.description); } SpecVersion = prop.specVersion; ImplementationVersion = prop.implementationVersion; }
public static VkLayerProperties Create(string layerName, string description, uint specVersion, uint implementationVersion) { VkLayerProperties ret = new VkLayerProperties() { layerName = layerName, description = description, specVersion = specVersion, implementationVersion = implementationVersion }; return(ret); }
public static ReadOnlySpan <VkLayerProperties> vkEnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice) { uint propertyCount = 0; vkEnumerateDeviceLayerProperties(physicalDevice, &propertyCount, null).CheckResult(); ReadOnlySpan <VkLayerProperties> properties = new VkLayerProperties[propertyCount]; fixed(VkLayerProperties *propertiesPtr = properties) { vkEnumerateDeviceLayerProperties(physicalDevice, &propertyCount, propertiesPtr).CheckResult(); } return(properties); }
public static ReadOnlySpan <VkLayerProperties> vkEnumerateInstanceLayerProperties() { uint propertyCount = 0; vkEnumerateInstanceLayerProperties(&propertyCount, null).CheckResult(); ReadOnlySpan <VkLayerProperties> properties = new VkLayerProperties[propertyCount]; fixed(VkLayerProperties *propertiesPtr = properties) { vkEnumerateInstanceLayerProperties(&propertyCount, propertiesPtr).CheckResult(); } return(properties); }
/// <summary> /// Gets the debug layers supported by the current system. /// </summary> public static VkLayerProperties[] GetLayers() { uint count = 0; InstanceFunctionTable.EnumerateInstanceLayerProperties(&count, null) .Throw("EnumerateInstanceExtensionProperties"); var props = new VkLayerProperties[count]; fixed(VkLayerProperties *ptr = props) { InstanceFunctionTable.EnumerateInstanceLayerProperties(&count, ptr) .Throw("EnumerateInstanceExtensionProperties"); } return(props); }
/// <summary> /// To enumerate device layers, call: /// </summary> /// <exception cref="VulkanLibrary.Unmanaged.VkErrorOutOfHostMemory"></exception> /// <exception cref="VulkanLibrary.Unmanaged.VkErrorOutOfDeviceMemory"></exception> /// <returns>array of <see cref="VkLayerProperties"/> structures</returns> public VkLayerProperties[] EnumerateLayerProperties() { unsafe { VkLayerProperties[] props; uint count = 0; do { props = new VkLayerProperties[count]; fixed(VkLayerProperties *pptr = props) VkException.Check(vkEnumerateDeviceLayerProperties(this, &count, pptr)); } while (props.Length != count); return(props); } }
public static string GetDescription(this VkLayerProperties properties) { return(Interop.GetString(properties.description)); }
public static string GetLayerName(this VkLayerProperties properties) { return(Interop.GetString(properties.layerName)); }
private IntPtr CreateInstance() { var enabledExtensionCount = 0u; var isSurfaceExtensionSupported = false; var isWin32SurfaceExtensionSupported = false; var isXlibSurfaceExtensionSupported = false; var isDebugReportExtensionSupported = false; var extensionPropertyCount = 0u; ThrowExternalExceptionIfFailed(nameof(vkEnumerateInstanceExtensionProperties), vkEnumerateInstanceExtensionProperties(pLayerName: null, &extensionPropertyCount, pProperties: null)); var extensionProperties = new VkExtensionProperties[extensionPropertyCount]; fixed(VkExtensionProperties *pExtensionProperties = extensionProperties) { ThrowExternalExceptionIfFailed(nameof(vkEnumerateInstanceExtensionProperties), vkEnumerateInstanceExtensionProperties(pLayerName: null, &extensionPropertyCount, pExtensionProperties)); } for (var i = 0; i < extensionProperties.Length; i++) { var extensionName = new ReadOnlySpan <sbyte>(Unsafe.AsPointer(ref extensionProperties[i].extensionName[0]), int.MaxValue); extensionName = extensionName.Slice(0, extensionName.IndexOf((sbyte)'\0') + 1); if (!isSurfaceExtensionSupported && VK_KHR_SURFACE_EXTENSION_NAME.SequenceEqual(extensionName)) { isSurfaceExtensionSupported = true; enabledExtensionCount++; } if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (!isWin32SurfaceExtensionSupported && VK_KHR_WIN32_SURFACE_EXTENSION_NAME.SequenceEqual(extensionName)) { isWin32SurfaceExtensionSupported = true; enabledExtensionCount++; } } else { if (!isXlibSurfaceExtensionSupported && VK_KHR_XLIB_SURFACE_EXTENSION_NAME.SequenceEqual(extensionName)) { isXlibSurfaceExtensionSupported = true; enabledExtensionCount++; } } #if DEBUG if (!isDebugReportExtensionSupported && VK_EXT_DEBUG_REPORT_EXTENSION_NAME.SequenceEqual(extensionName)) { isDebugReportExtensionSupported = true; enabledExtensionCount++; } #endif } var enabledExtensionNames = stackalloc sbyte *[(int)enabledExtensionCount]; if (!isSurfaceExtensionSupported) { ThrowInvalidOperationException(nameof(isSurfaceExtensionSupported), isSurfaceExtensionSupported); } enabledExtensionNames[0] = (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(VK_KHR_SURFACE_EXTENSION_NAME)); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (!isWin32SurfaceExtensionSupported) { ThrowInvalidOperationException(nameof(isWin32SurfaceExtensionSupported), isWin32SurfaceExtensionSupported); } enabledExtensionNames[1] = (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(VK_KHR_WIN32_SURFACE_EXTENSION_NAME)); } else { if (!isXlibSurfaceExtensionSupported) { ThrowInvalidOperationException(nameof(isXlibSurfaceExtensionSupported), isXlibSurfaceExtensionSupported); } enabledExtensionNames[1] = (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(VK_KHR_XLIB_SURFACE_EXTENSION_NAME)); } if (isDebugReportExtensionSupported) { // We don't want to throw if the debug extension isn't available enabledExtensionNames[2] = (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(VK_EXT_DEBUG_REPORT_EXTENSION_NAME)); } var enabledLayerCount = 0u; var isLunarGStandardValidationLayerSupported = false; #if DEBUG var layerPropertyCount = 0u; ThrowExternalExceptionIfFailed(nameof(vkEnumerateInstanceLayerProperties), vkEnumerateInstanceLayerProperties(&layerPropertyCount, pProperties: null)); var layerProperties = new VkLayerProperties[layerPropertyCount]; fixed(VkLayerProperties *pLayerProperties = layerProperties) { ThrowExternalExceptionIfFailed(nameof(vkEnumerateInstanceLayerProperties), vkEnumerateInstanceLayerProperties(&layerPropertyCount, pLayerProperties)); } for (var i = 0; i < layerProperties.Length; i++) { var layerName = new ReadOnlySpan <sbyte>(Unsafe.AsPointer(ref layerProperties[i].layerName[0]), int.MaxValue); layerName = layerName.Slice(0, layerName.IndexOf((sbyte)'\0') + 1); if (!isLunarGStandardValidationLayerSupported && VK_LAYER_LUNARG_STANDARD_VALIDATION_LAYER_NAME.SequenceEqual(layerName)) { isLunarGStandardValidationLayerSupported = true; enabledLayerCount++; } } #endif var enabledLayerNames = stackalloc sbyte *[(int)enabledLayerCount]; if (isLunarGStandardValidationLayerSupported) { enabledLayerNames[0] = (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(VK_LAYER_LUNARG_STANDARD_VALIDATION_LAYER_NAME)); } var applicationInfo = new VkApplicationInfo { sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, pNext = null, pApplicationName = null, applicationVersion = 1, pEngineName = (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(s_engineName)), engineVersion = VK_MAKE_VERSION(0, 1, 0), apiVersion = VK_API_VERSION_1_0, }; var createInfo = new VkInstanceCreateInfo { sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, pNext = null, flags = 0, pApplicationInfo = &applicationInfo, enabledLayerCount = enabledLayerCount, ppEnabledLayerNames = enabledLayerNames, enabledExtensionCount = enabledExtensionCount, ppEnabledExtensionNames = enabledExtensionNames, }; IntPtr instance; var result = vkCreateInstance(&createInfo, null, &instance); if (result != VK_SUCCESS) { ThrowExternalException(nameof(vkCreateInstance), (int)result); } if (isDebugReportExtensionSupported && isLunarGStandardValidationLayerSupported) { #if DEBUG ulong debugReportCallbackExt; _debugReportCallback = new NativeDelegate <PFN_vkDebugReportCallbackEXT>(DebugReportCallback); var debugReportCallbackCreateInfo = new VkDebugReportCallbackCreateInfoEXT { sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT, pNext = null, flags = (uint)(VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT | VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT), pfnCallback = _debugReportCallback, pUserData = null, }; // We don't want to fail if creating the debug report callback failed var vkCreateDebugReportCallbackEXT = vkGetInstanceProcAddr(instance, (sbyte *)Unsafe.AsPointer(ref MemoryMarshal.GetReference(VKCREATEDEBUGREPORTCALLBACKEXT_FUNCTION_NAME))); _ = Marshal.GetDelegateForFunctionPointer <PFN_vkCreateDebugReportCallbackEXT>(vkCreateDebugReportCallbackEXT)(instance, &debugReportCallbackCreateInfo, pAllocator : null, &debugReportCallbackExt); _debugReportCallbackExt = debugReportCallbackExt; #endif } return(instance); }