VulkanInitialization.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596
  1. using Ryujinx.Common.Configuration;
  2. using Ryujinx.Common.Logging;
  3. using Ryujinx.Graphics.GAL;
  4. using Silk.NET.Vulkan;
  5. using Silk.NET.Vulkan.Extensions.EXT;
  6. using Silk.NET.Vulkan.Extensions.KHR;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11. namespace Ryujinx.Graphics.Vulkan
  12. {
  13. public unsafe static class VulkanInitialization
  14. {
  15. private const uint InvalidIndex = uint.MaxValue;
  16. private const string AppName = "Ryujinx.Graphics.Vulkan";
  17. private const int QueuesCount = 2;
  18. public static string[] DesirableExtensions { get; } = new string[]
  19. {
  20. ExtConditionalRendering.ExtensionName,
  21. ExtExtendedDynamicState.ExtensionName,
  22. KhrDrawIndirectCount.ExtensionName,
  23. KhrPushDescriptor.ExtensionName,
  24. "VK_EXT_custom_border_color",
  25. "VK_EXT_descriptor_indexing", // Enabling this works around an issue with disposed buffer bindings on RADV.
  26. "VK_EXT_fragment_shader_interlock",
  27. "VK_EXT_index_type_uint8",
  28. "VK_EXT_robustness2",
  29. "VK_EXT_shader_subgroup_ballot",
  30. "VK_EXT_subgroup_size_control",
  31. "VK_NV_geometry_shader_passthrough"
  32. };
  33. public static string[] RequiredExtensions { get; } = new string[]
  34. {
  35. KhrSwapchain.ExtensionName,
  36. "VK_EXT_shader_subgroup_vote",
  37. ExtTransformFeedback.ExtensionName
  38. };
  39. private static string[] _excludedMessages = new string[]
  40. {
  41. // NOTE: Done on purpose right now.
  42. "UNASSIGNED-CoreValidation-Shader-OutputNotConsumed",
  43. // TODO: Figure out if fixable
  44. "VUID-vkCmdDrawIndexed-None-04584",
  45. // TODO: Might be worth looking into making this happy to possibly optimize copies.
  46. "UNASSIGNED-CoreValidation-DrawState-InvalidImageLayout",
  47. // TODO: Fix this, it's causing too much noise right now.
  48. "VUID-VkSubpassDependency-srcSubpass-00867"
  49. };
  50. internal static Instance CreateInstance(Vk api, GraphicsDebugLevel logLevel, string[] requiredExtensions, out ExtDebugReport debugReport, out DebugReportCallbackEXT debugReportCallback)
  51. {
  52. var enabledLayers = new List<string>();
  53. void AddAvailableLayer(string layerName)
  54. {
  55. uint layerPropertiesCount;
  56. api.EnumerateInstanceLayerProperties(&layerPropertiesCount, null).ThrowOnError();
  57. LayerProperties[] layerProperties = new LayerProperties[layerPropertiesCount];
  58. fixed (LayerProperties* pLayerProperties = layerProperties)
  59. {
  60. api.EnumerateInstanceLayerProperties(&layerPropertiesCount, layerProperties).ThrowOnError();
  61. for (int i = 0; i < layerPropertiesCount; i++)
  62. {
  63. string currentLayerName = Marshal.PtrToStringAnsi((IntPtr)pLayerProperties[i].LayerName);
  64. if (currentLayerName == layerName)
  65. {
  66. enabledLayers.Add(layerName);
  67. return;
  68. }
  69. }
  70. }
  71. Logger.Warning?.Print(LogClass.Gpu, $"Missing layer {layerName}");
  72. }
  73. if (logLevel != GraphicsDebugLevel.None)
  74. {
  75. AddAvailableLayer("VK_LAYER_KHRONOS_validation");
  76. }
  77. var enabledExtensions = requiredExtensions.Append(ExtDebugReport.ExtensionName).ToArray();
  78. var appName = Marshal.StringToHGlobalAnsi(AppName);
  79. var applicationInfo = new ApplicationInfo
  80. {
  81. PApplicationName = (byte*)appName,
  82. ApplicationVersion = 1,
  83. PEngineName = (byte*)appName,
  84. EngineVersion = 1,
  85. ApiVersion = Vk.Version12.Value
  86. };
  87. IntPtr* ppEnabledExtensions = stackalloc IntPtr[enabledExtensions.Length];
  88. IntPtr* ppEnabledLayers = stackalloc IntPtr[enabledLayers.Count];
  89. for (int i = 0; i < enabledExtensions.Length; i++)
  90. {
  91. ppEnabledExtensions[i] = Marshal.StringToHGlobalAnsi(enabledExtensions[i]);
  92. }
  93. for (int i = 0; i < enabledLayers.Count; i++)
  94. {
  95. ppEnabledLayers[i] = Marshal.StringToHGlobalAnsi(enabledLayers[i]);
  96. }
  97. var instanceCreateInfo = new InstanceCreateInfo
  98. {
  99. SType = StructureType.InstanceCreateInfo,
  100. PApplicationInfo = &applicationInfo,
  101. PpEnabledExtensionNames = (byte**)ppEnabledExtensions,
  102. PpEnabledLayerNames = (byte**)ppEnabledLayers,
  103. EnabledExtensionCount = (uint)enabledExtensions.Length,
  104. EnabledLayerCount = (uint)enabledLayers.Count
  105. };
  106. api.CreateInstance(in instanceCreateInfo, null, out var instance).ThrowOnError();
  107. Marshal.FreeHGlobal(appName);
  108. for (int i = 0; i < enabledExtensions.Length; i++)
  109. {
  110. Marshal.FreeHGlobal(ppEnabledExtensions[i]);
  111. }
  112. for (int i = 0; i < enabledLayers.Count; i++)
  113. {
  114. Marshal.FreeHGlobal(ppEnabledLayers[i]);
  115. }
  116. CreateDebugCallbacks(api, logLevel, instance, out debugReport, out debugReportCallback);
  117. return instance;
  118. }
  119. private unsafe static uint DebugReport(
  120. uint flags,
  121. DebugReportObjectTypeEXT objectType,
  122. ulong @object,
  123. nuint location,
  124. int messageCode,
  125. byte* layerPrefix,
  126. byte* message,
  127. void* userData)
  128. {
  129. var msg = Marshal.PtrToStringAnsi((IntPtr)message);
  130. foreach (string excludedMessagePart in _excludedMessages)
  131. {
  132. if (msg.Contains(excludedMessagePart))
  133. {
  134. return 0;
  135. }
  136. }
  137. DebugReportFlagsEXT debugFlags = (DebugReportFlagsEXT)flags;
  138. if (debugFlags.HasFlag(DebugReportFlagsEXT.DebugReportErrorBitExt))
  139. {
  140. Logger.Error?.Print(LogClass.Gpu, msg);
  141. //throw new Exception(msg);
  142. }
  143. else if (debugFlags.HasFlag(DebugReportFlagsEXT.DebugReportWarningBitExt))
  144. {
  145. Logger.Warning?.Print(LogClass.Gpu, msg);
  146. }
  147. else if (debugFlags.HasFlag(DebugReportFlagsEXT.DebugReportInformationBitExt))
  148. {
  149. Logger.Info?.Print(LogClass.Gpu, msg);
  150. }
  151. else if (debugFlags.HasFlag(DebugReportFlagsEXT.DebugReportPerformanceWarningBitExt))
  152. {
  153. Logger.Warning?.Print(LogClass.Gpu, msg);
  154. }
  155. else
  156. {
  157. Logger.Debug?.Print(LogClass.Gpu, msg);
  158. }
  159. return 0;
  160. }
  161. internal static PhysicalDevice FindSuitablePhysicalDevice(Vk api, Instance instance, SurfaceKHR surface, string preferredGpuId)
  162. {
  163. uint physicalDeviceCount;
  164. api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, null).ThrowOnError();
  165. PhysicalDevice[] physicalDevices = new PhysicalDevice[physicalDeviceCount];
  166. fixed (PhysicalDevice* pPhysicalDevices = physicalDevices)
  167. {
  168. api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, pPhysicalDevices).ThrowOnError();
  169. }
  170. // First we try to pick the the user preferred GPU.
  171. for (int i = 0; i < physicalDevices.Length; i++)
  172. {
  173. if (IsPreferredAndSuitableDevice(api, physicalDevices[i], surface, preferredGpuId))
  174. {
  175. return physicalDevices[i];
  176. }
  177. }
  178. // If we fail to do that, just use the first compatible GPU.
  179. for (int i = 0; i < physicalDevices.Length; i++)
  180. {
  181. if (IsSuitableDevice(api, physicalDevices[i], surface))
  182. {
  183. return physicalDevices[i];
  184. }
  185. }
  186. throw new VulkanException("Initialization failed, none of the available GPUs meets the minimum requirements.");
  187. }
  188. internal static DeviceInfo[] GetSuitablePhysicalDevices(Vk api)
  189. {
  190. var appName = Marshal.StringToHGlobalAnsi(AppName);
  191. var applicationInfo = new ApplicationInfo
  192. {
  193. PApplicationName = (byte*)appName,
  194. ApplicationVersion = 1,
  195. PEngineName = (byte*)appName,
  196. EngineVersion = 1,
  197. ApiVersion = Vk.Version12.Value
  198. };
  199. var instanceCreateInfo = new InstanceCreateInfo
  200. {
  201. SType = StructureType.InstanceCreateInfo,
  202. PApplicationInfo = &applicationInfo,
  203. PpEnabledExtensionNames = null,
  204. PpEnabledLayerNames = null,
  205. EnabledExtensionCount = 0,
  206. EnabledLayerCount = 0
  207. };
  208. api.CreateInstance(in instanceCreateInfo, null, out var instance).ThrowOnError();
  209. Marshal.FreeHGlobal(appName);
  210. uint physicalDeviceCount;
  211. api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, null).ThrowOnError();
  212. PhysicalDevice[] physicalDevices = new PhysicalDevice[physicalDeviceCount];
  213. fixed (PhysicalDevice* pPhysicalDevices = physicalDevices)
  214. {
  215. api.EnumeratePhysicalDevices(instance, &physicalDeviceCount, pPhysicalDevices).ThrowOnError();
  216. }
  217. DeviceInfo[] devices = new DeviceInfo[physicalDevices.Length];
  218. for (int i = 0; i < physicalDevices.Length; i++)
  219. {
  220. var physicalDevice = physicalDevices[i];
  221. api.GetPhysicalDeviceProperties(physicalDevice, out var properties);
  222. devices[i] = new DeviceInfo(
  223. StringFromIdPair(properties.VendorID, properties.DeviceID),
  224. VendorUtils.GetNameFromId(properties.VendorID),
  225. Marshal.PtrToStringAnsi((IntPtr)properties.DeviceName),
  226. properties.DeviceType == PhysicalDeviceType.DiscreteGpu);
  227. }
  228. api.DestroyInstance(instance, null);
  229. return devices;
  230. }
  231. public static string StringFromIdPair(uint vendorId, uint deviceId)
  232. {
  233. return $"0x{vendorId:X}_0x{deviceId:X}";
  234. }
  235. private static bool IsPreferredAndSuitableDevice(Vk api, PhysicalDevice physicalDevice, SurfaceKHR surface, string preferredGpuId)
  236. {
  237. api.GetPhysicalDeviceProperties(physicalDevice, out var properties);
  238. if (StringFromIdPair(properties.VendorID, properties.DeviceID) != preferredGpuId)
  239. {
  240. return false;
  241. }
  242. return IsSuitableDevice(api, physicalDevice, surface);
  243. }
  244. private static bool IsSuitableDevice(Vk api, PhysicalDevice physicalDevice, SurfaceKHR surface)
  245. {
  246. int extensionMatches = 0;
  247. uint propertiesCount;
  248. api.EnumerateDeviceExtensionProperties(physicalDevice, (byte*)null, &propertiesCount, null).ThrowOnError();
  249. ExtensionProperties[] extensionProperties = new ExtensionProperties[propertiesCount];
  250. fixed (ExtensionProperties* pExtensionProperties = extensionProperties)
  251. {
  252. api.EnumerateDeviceExtensionProperties(physicalDevice, (byte*)null, &propertiesCount, pExtensionProperties).ThrowOnError();
  253. for (int i = 0; i < propertiesCount; i++)
  254. {
  255. string extensionName = Marshal.PtrToStringAnsi((IntPtr)pExtensionProperties[i].ExtensionName);
  256. if (RequiredExtensions.Contains(extensionName))
  257. {
  258. extensionMatches++;
  259. }
  260. }
  261. }
  262. return extensionMatches == RequiredExtensions.Length && FindSuitableQueueFamily(api, physicalDevice, surface, out _) != InvalidIndex;
  263. }
  264. internal static uint FindSuitableQueueFamily(Vk api, PhysicalDevice physicalDevice, SurfaceKHR surface, out uint queueCount)
  265. {
  266. const QueueFlags RequiredFlags = QueueFlags.QueueGraphicsBit | QueueFlags.QueueComputeBit;
  267. var khrSurface = new KhrSurface(api.Context);
  268. uint propertiesCount;
  269. api.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, &propertiesCount, null);
  270. QueueFamilyProperties[] properties = new QueueFamilyProperties[propertiesCount];
  271. fixed (QueueFamilyProperties* pProperties = properties)
  272. {
  273. api.GetPhysicalDeviceQueueFamilyProperties(physicalDevice, &propertiesCount, pProperties);
  274. }
  275. for (uint index = 0; index < propertiesCount; index++)
  276. {
  277. var queueFlags = properties[index].QueueFlags;
  278. khrSurface.GetPhysicalDeviceSurfaceSupport(physicalDevice, index, surface, out var surfaceSupported).ThrowOnError();
  279. if (queueFlags.HasFlag(RequiredFlags) && surfaceSupported)
  280. {
  281. queueCount = properties[index].QueueCount;
  282. return index;
  283. }
  284. }
  285. queueCount = 0;
  286. return InvalidIndex;
  287. }
  288. public static Device CreateDevice(Vk api, PhysicalDevice physicalDevice, uint queueFamilyIndex, string[] supportedExtensions, uint queueCount)
  289. {
  290. if (queueCount > QueuesCount)
  291. {
  292. queueCount = QueuesCount;
  293. }
  294. float* queuePriorities = stackalloc float[(int)queueCount];
  295. for (int i = 0; i < queueCount; i++)
  296. {
  297. queuePriorities[i] = 1f;
  298. }
  299. var queueCreateInfo = new DeviceQueueCreateInfo()
  300. {
  301. SType = StructureType.DeviceQueueCreateInfo,
  302. QueueFamilyIndex = queueFamilyIndex,
  303. QueueCount = queueCount,
  304. PQueuePriorities = queuePriorities
  305. };
  306. api.GetPhysicalDeviceProperties(physicalDevice, out var properties);
  307. bool useRobustBufferAccess = VendorUtils.FromId(properties.VendorID) == Vendor.Nvidia;
  308. var supportedFeatures = api.GetPhysicalDeviceFeature(physicalDevice);
  309. var features = new PhysicalDeviceFeatures()
  310. {
  311. DepthBiasClamp = true,
  312. DepthClamp = true,
  313. DualSrcBlend = true,
  314. FragmentStoresAndAtomics = true,
  315. GeometryShader = true,
  316. ImageCubeArray = true,
  317. IndependentBlend = true,
  318. LogicOp = true,
  319. MultiViewport = true,
  320. PipelineStatisticsQuery = true,
  321. SamplerAnisotropy = true,
  322. ShaderClipDistance = true,
  323. ShaderFloat64 = supportedFeatures.ShaderFloat64,
  324. ShaderImageGatherExtended = true,
  325. // ShaderStorageImageReadWithoutFormat = true,
  326. // ShaderStorageImageWriteWithoutFormat = true,
  327. TessellationShader = true,
  328. VertexPipelineStoresAndAtomics = true,
  329. RobustBufferAccess = useRobustBufferAccess
  330. };
  331. void* pExtendedFeatures = null;
  332. var featuresTransformFeedback = new PhysicalDeviceTransformFeedbackFeaturesEXT()
  333. {
  334. SType = StructureType.PhysicalDeviceTransformFeedbackFeaturesExt,
  335. PNext = pExtendedFeatures,
  336. TransformFeedback = true
  337. };
  338. pExtendedFeatures = &featuresTransformFeedback;
  339. var featuresRobustness2 = new PhysicalDeviceRobustness2FeaturesEXT()
  340. {
  341. SType = StructureType.PhysicalDeviceRobustness2FeaturesExt,
  342. PNext = pExtendedFeatures,
  343. NullDescriptor = true
  344. };
  345. pExtendedFeatures = &featuresRobustness2;
  346. var featuresExtendedDynamicState = new PhysicalDeviceExtendedDynamicStateFeaturesEXT()
  347. {
  348. SType = StructureType.PhysicalDeviceExtendedDynamicStateFeaturesExt,
  349. PNext = pExtendedFeatures,
  350. ExtendedDynamicState = supportedExtensions.Contains(ExtExtendedDynamicState.ExtensionName)
  351. };
  352. pExtendedFeatures = &featuresExtendedDynamicState;
  353. var featuresVk11 = new PhysicalDeviceVulkan11Features()
  354. {
  355. SType = StructureType.PhysicalDeviceVulkan11Features,
  356. PNext = pExtendedFeatures,
  357. ShaderDrawParameters = true
  358. };
  359. pExtendedFeatures = &featuresVk11;
  360. var featuresVk12 = new PhysicalDeviceVulkan12Features()
  361. {
  362. SType = StructureType.PhysicalDeviceVulkan12Features,
  363. PNext = pExtendedFeatures,
  364. DescriptorIndexing = supportedExtensions.Contains("VK_EXT_descriptor_indexing"),
  365. DrawIndirectCount = supportedExtensions.Contains(KhrDrawIndirectCount.ExtensionName)
  366. };
  367. pExtendedFeatures = &featuresVk12;
  368. PhysicalDeviceIndexTypeUint8FeaturesEXT featuresIndexU8;
  369. if (supportedExtensions.Contains("VK_EXT_index_type_uint8"))
  370. {
  371. featuresIndexU8 = new PhysicalDeviceIndexTypeUint8FeaturesEXT()
  372. {
  373. SType = StructureType.PhysicalDeviceIndexTypeUint8FeaturesExt,
  374. PNext = pExtendedFeatures,
  375. IndexTypeUint8 = true
  376. };
  377. pExtendedFeatures = &featuresIndexU8;
  378. }
  379. PhysicalDeviceFragmentShaderInterlockFeaturesEXT featuresFragmentShaderInterlock;
  380. if (supportedExtensions.Contains("VK_EXT_fragment_shader_interlock"))
  381. {
  382. featuresFragmentShaderInterlock = new PhysicalDeviceFragmentShaderInterlockFeaturesEXT()
  383. {
  384. SType = StructureType.PhysicalDeviceFragmentShaderInterlockFeaturesExt,
  385. PNext = pExtendedFeatures,
  386. FragmentShaderPixelInterlock = true
  387. };
  388. pExtendedFeatures = &featuresFragmentShaderInterlock;
  389. }
  390. PhysicalDeviceSubgroupSizeControlFeaturesEXT featuresSubgroupSizeControl;
  391. if (supportedExtensions.Contains("VK_EXT_subgroup_size_control"))
  392. {
  393. featuresSubgroupSizeControl = new PhysicalDeviceSubgroupSizeControlFeaturesEXT()
  394. {
  395. SType = StructureType.PhysicalDeviceSubgroupSizeControlFeaturesExt,
  396. PNext = pExtendedFeatures,
  397. SubgroupSizeControl = true
  398. };
  399. pExtendedFeatures = &featuresSubgroupSizeControl;
  400. }
  401. var enabledExtensions = RequiredExtensions.Union(DesirableExtensions.Intersect(supportedExtensions)).ToArray();
  402. IntPtr* ppEnabledExtensions = stackalloc IntPtr[enabledExtensions.Length];
  403. for (int i = 0; i < enabledExtensions.Length; i++)
  404. {
  405. ppEnabledExtensions[i] = Marshal.StringToHGlobalAnsi(enabledExtensions[i]);
  406. }
  407. var deviceCreateInfo = new DeviceCreateInfo()
  408. {
  409. SType = StructureType.DeviceCreateInfo,
  410. PNext = pExtendedFeatures,
  411. QueueCreateInfoCount = 1,
  412. PQueueCreateInfos = &queueCreateInfo,
  413. PpEnabledExtensionNames = (byte**)ppEnabledExtensions,
  414. EnabledExtensionCount = (uint)enabledExtensions.Length,
  415. PEnabledFeatures = &features
  416. };
  417. api.CreateDevice(physicalDevice, in deviceCreateInfo, null, out var device).ThrowOnError();
  418. for (int i = 0; i < enabledExtensions.Length; i++)
  419. {
  420. Marshal.FreeHGlobal(ppEnabledExtensions[i]);
  421. }
  422. return device;
  423. }
  424. public static string[] GetSupportedExtensions(Vk api, PhysicalDevice physicalDevice)
  425. {
  426. uint propertiesCount;
  427. api.EnumerateDeviceExtensionProperties(physicalDevice, (byte*)null, &propertiesCount, null).ThrowOnError();
  428. ExtensionProperties[] extensionProperties = new ExtensionProperties[propertiesCount];
  429. fixed (ExtensionProperties* pExtensionProperties = extensionProperties)
  430. {
  431. api.EnumerateDeviceExtensionProperties(physicalDevice, (byte*)null, &propertiesCount, pExtensionProperties).ThrowOnError();
  432. }
  433. return extensionProperties.Select(x => Marshal.PtrToStringAnsi((IntPtr)x.ExtensionName)).ToArray();
  434. }
  435. internal static CommandBufferPool CreateCommandBufferPool(Vk api, Device device, Queue queue, object queueLock, uint queueFamilyIndex)
  436. {
  437. return new CommandBufferPool(api, device, queue, queueLock, queueFamilyIndex);
  438. }
  439. internal unsafe static void CreateDebugCallbacks(
  440. Vk api,
  441. GraphicsDebugLevel logLevel,
  442. Instance instance,
  443. out ExtDebugReport debugReport,
  444. out DebugReportCallbackEXT debugReportCallback)
  445. {
  446. debugReport = default;
  447. if (logLevel != GraphicsDebugLevel.None)
  448. {
  449. if (!api.TryGetInstanceExtension(instance, out debugReport))
  450. {
  451. debugReportCallback = default;
  452. return;
  453. }
  454. var flags = logLevel switch
  455. {
  456. GraphicsDebugLevel.Error => DebugReportFlagsEXT.DebugReportErrorBitExt,
  457. GraphicsDebugLevel.Slowdowns => DebugReportFlagsEXT.DebugReportErrorBitExt | DebugReportFlagsEXT.DebugReportPerformanceWarningBitExt,
  458. GraphicsDebugLevel.All => DebugReportFlagsEXT.DebugReportInformationBitExt |
  459. DebugReportFlagsEXT.DebugReportWarningBitExt |
  460. DebugReportFlagsEXT.DebugReportPerformanceWarningBitExt |
  461. DebugReportFlagsEXT.DebugReportErrorBitExt |
  462. DebugReportFlagsEXT.DebugReportDebugBitExt,
  463. _ => throw new ArgumentException($"Invalid log level \"{logLevel}\".")
  464. };
  465. var debugReportCallbackCreateInfo = new DebugReportCallbackCreateInfoEXT()
  466. {
  467. SType = StructureType.DebugReportCallbackCreateInfoExt,
  468. Flags = flags,
  469. PfnCallback = new PfnDebugReportCallbackEXT(DebugReport)
  470. };
  471. debugReport.CreateDebugReportCallback(instance, in debugReportCallbackCreateInfo, null, out debugReportCallback).ThrowOnError();
  472. }
  473. else
  474. {
  475. debugReportCallback = default;
  476. }
  477. }
  478. }
  479. }