VulkanInitialization.cs 23 KB

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