VulkanInitialization.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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 static readonly uint _minimalVulkanVersion = Vk.Version11.Value;
  17. private static readonly uint _minimalInstanceVulkanVersion = Vk.Version12.Value;
  18. private static readonly uint _maximumVulkanVersion = Vk.Version12.Value;
  19. private const string AppName = "Ryujinx.Graphics.Vulkan";
  20. private const int QueuesCount = 2;
  21. private static readonly string[] _desirableExtensions = {
  22. ExtConditionalRendering.ExtensionName,
  23. ExtExtendedDynamicState.ExtensionName,
  24. ExtTransformFeedback.ExtensionName,
  25. KhrDrawIndirectCount.ExtensionName,
  26. KhrPushDescriptor.ExtensionName,
  27. ExtExternalMemoryHost.ExtensionName,
  28. "VK_EXT_blend_operation_advanced",
  29. "VK_EXT_custom_border_color",
  30. "VK_EXT_descriptor_indexing", // Enabling this works around an issue with disposed buffer bindings on RADV.
  31. "VK_EXT_fragment_shader_interlock",
  32. "VK_EXT_index_type_uint8",
  33. "VK_EXT_primitive_topology_list_restart",
  34. "VK_EXT_robustness2",
  35. "VK_EXT_shader_stencil_export",
  36. "VK_KHR_shader_float16_int8",
  37. "VK_EXT_shader_subgroup_ballot",
  38. "VK_NV_geometry_shader_passthrough",
  39. "VK_NV_viewport_array2",
  40. "VK_EXT_depth_clip_control",
  41. "VK_KHR_portability_subset", // As per spec, we should enable this if present.
  42. "VK_EXT_4444_formats",
  43. };
  44. private static readonly string[] _requiredExtensions = {
  45. KhrSwapchain.ExtensionName,
  46. };
  47. internal static VulkanInstance CreateInstance(Vk api, GraphicsDebugLevel logLevel, string[] requiredExtensions)
  48. {
  49. var enabledLayers = new List<string>();
  50. var instanceExtensions = VulkanInstance.GetInstanceExtensions(api);
  51. var instanceLayers = VulkanInstance.GetInstanceLayers(api);
  52. void AddAvailableLayer(string layerName)
  53. {
  54. if (instanceLayers.Contains(layerName))
  55. {
  56. enabledLayers.Add(layerName);
  57. }
  58. else
  59. {
  60. Logger.Warning?.Print(LogClass.Gpu, $"Missing layer {layerName}");
  61. }
  62. }
  63. if (logLevel != GraphicsDebugLevel.None)
  64. {
  65. AddAvailableLayer("VK_LAYER_KHRONOS_validation");
  66. }
  67. var enabledExtensions = requiredExtensions;
  68. if (instanceExtensions.Contains("VK_EXT_debug_utils"))
  69. {
  70. enabledExtensions = enabledExtensions.Append(ExtDebugUtils.ExtensionName).ToArray();
  71. }
  72. var appName = Marshal.StringToHGlobalAnsi(AppName);
  73. var applicationInfo = new ApplicationInfo
  74. {
  75. PApplicationName = (byte*)appName,
  76. ApplicationVersion = 1,
  77. PEngineName = (byte*)appName,
  78. EngineVersion = 1,
  79. ApiVersion = _maximumVulkanVersion,
  80. };
  81. IntPtr* ppEnabledExtensions = stackalloc IntPtr[enabledExtensions.Length];
  82. IntPtr* ppEnabledLayers = stackalloc IntPtr[enabledLayers.Count];
  83. for (int i = 0; i < enabledExtensions.Length; i++)
  84. {
  85. ppEnabledExtensions[i] = Marshal.StringToHGlobalAnsi(enabledExtensions[i]);
  86. }
  87. for (int i = 0; i < enabledLayers.Count; i++)
  88. {
  89. ppEnabledLayers[i] = Marshal.StringToHGlobalAnsi(enabledLayers[i]);
  90. }
  91. var instanceCreateInfo = new InstanceCreateInfo
  92. {
  93. SType = StructureType.InstanceCreateInfo,
  94. PApplicationInfo = &applicationInfo,
  95. PpEnabledExtensionNames = (byte**)ppEnabledExtensions,
  96. PpEnabledLayerNames = (byte**)ppEnabledLayers,
  97. EnabledExtensionCount = (uint)enabledExtensions.Length,
  98. EnabledLayerCount = (uint)enabledLayers.Count,
  99. };
  100. Result result = VulkanInstance.Create(api, ref instanceCreateInfo, out var instance);
  101. Marshal.FreeHGlobal(appName);
  102. for (int i = 0; i < enabledExtensions.Length; i++)
  103. {
  104. Marshal.FreeHGlobal(ppEnabledExtensions[i]);
  105. }
  106. for (int i = 0; i < enabledLayers.Count; i++)
  107. {
  108. Marshal.FreeHGlobal(ppEnabledLayers[i]);
  109. }
  110. result.ThrowOnError();
  111. return instance;
  112. }
  113. internal static VulkanPhysicalDevice FindSuitablePhysicalDevice(Vk api, VulkanInstance instance, SurfaceKHR surface, string preferredGpuId)
  114. {
  115. instance.EnumeratePhysicalDevices(out var physicalDevices).ThrowOnError();
  116. // First we try to pick the the user preferred GPU.
  117. for (int i = 0; i < physicalDevices.Length; i++)
  118. {
  119. if (IsPreferredAndSuitableDevice(api, physicalDevices[i], surface, preferredGpuId))
  120. {
  121. return physicalDevices[i];
  122. }
  123. }
  124. // If we fail to do that, just use the first compatible GPU.
  125. for (int i = 0; i < physicalDevices.Length; i++)
  126. {
  127. if (IsSuitableDevice(api, physicalDevices[i], surface))
  128. {
  129. return physicalDevices[i];
  130. }
  131. }
  132. throw new VulkanException("Initialization failed, none of the available GPUs meets the minimum requirements.");
  133. }
  134. internal static DeviceInfo[] GetSuitablePhysicalDevices(Vk api)
  135. {
  136. var appName = Marshal.StringToHGlobalAnsi(AppName);
  137. var applicationInfo = new ApplicationInfo
  138. {
  139. PApplicationName = (byte*)appName,
  140. ApplicationVersion = 1,
  141. PEngineName = (byte*)appName,
  142. EngineVersion = 1,
  143. ApiVersion = _maximumVulkanVersion,
  144. };
  145. var instanceCreateInfo = new InstanceCreateInfo
  146. {
  147. SType = StructureType.InstanceCreateInfo,
  148. PApplicationInfo = &applicationInfo,
  149. PpEnabledExtensionNames = null,
  150. PpEnabledLayerNames = null,
  151. EnabledExtensionCount = 0,
  152. EnabledLayerCount = 0,
  153. };
  154. Result result = VulkanInstance.Create(api, ref instanceCreateInfo, out var rawInstance);
  155. Marshal.FreeHGlobal(appName);
  156. result.ThrowOnError();
  157. using VulkanInstance instance = rawInstance;
  158. // We currently assume that the instance is compatible with Vulkan 1.2
  159. // TODO: Remove this once we relax our initialization codepaths.
  160. if (instance.InstanceVersion < _minimalInstanceVulkanVersion)
  161. {
  162. return Array.Empty<DeviceInfo>();
  163. }
  164. instance.EnumeratePhysicalDevices(out VulkanPhysicalDevice[] physicalDevices).ThrowOnError();
  165. List<DeviceInfo> deviceInfos = new();
  166. foreach (VulkanPhysicalDevice physicalDevice in physicalDevices)
  167. {
  168. if (physicalDevice.PhysicalDeviceProperties.ApiVersion < _minimalVulkanVersion)
  169. {
  170. continue;
  171. }
  172. deviceInfos.Add(physicalDevice.ToDeviceInfo());
  173. }
  174. return deviceInfos.ToArray();
  175. }
  176. private static bool IsPreferredAndSuitableDevice(Vk api, VulkanPhysicalDevice physicalDevice, SurfaceKHR surface, string preferredGpuId)
  177. {
  178. if (physicalDevice.Id != preferredGpuId)
  179. {
  180. return false;
  181. }
  182. return IsSuitableDevice(api, physicalDevice, surface);
  183. }
  184. private static bool IsSuitableDevice(Vk api, VulkanPhysicalDevice physicalDevice, SurfaceKHR surface)
  185. {
  186. int extensionMatches = 0;
  187. foreach (string requiredExtension in _requiredExtensions)
  188. {
  189. if (physicalDevice.IsDeviceExtensionPresent(requiredExtension))
  190. {
  191. extensionMatches++;
  192. }
  193. }
  194. return extensionMatches == _requiredExtensions.Length && FindSuitableQueueFamily(api, physicalDevice, surface, out _) != InvalidIndex;
  195. }
  196. internal static uint FindSuitableQueueFamily(Vk api, VulkanPhysicalDevice physicalDevice, SurfaceKHR surface, out uint queueCount)
  197. {
  198. const QueueFlags RequiredFlags = QueueFlags.GraphicsBit | QueueFlags.ComputeBit;
  199. var khrSurface = new KhrSurface(api.Context);
  200. for (uint index = 0; index < physicalDevice.QueueFamilyProperties.Length; index++)
  201. {
  202. ref QueueFamilyProperties property = ref physicalDevice.QueueFamilyProperties[index];
  203. khrSurface.GetPhysicalDeviceSurfaceSupport(physicalDevice.PhysicalDevice, index, surface, out var surfaceSupported).ThrowOnError();
  204. if (property.QueueFlags.HasFlag(RequiredFlags) && surfaceSupported)
  205. {
  206. queueCount = property.QueueCount;
  207. return index;
  208. }
  209. }
  210. queueCount = 0;
  211. return InvalidIndex;
  212. }
  213. internal static Device CreateDevice(Vk api, VulkanPhysicalDevice physicalDevice, uint queueFamilyIndex, uint queueCount)
  214. {
  215. if (queueCount > QueuesCount)
  216. {
  217. queueCount = QueuesCount;
  218. }
  219. float* queuePriorities = stackalloc float[(int)queueCount];
  220. for (int i = 0; i < queueCount; i++)
  221. {
  222. queuePriorities[i] = 1f;
  223. }
  224. var queueCreateInfo = new DeviceQueueCreateInfo
  225. {
  226. SType = StructureType.DeviceQueueCreateInfo,
  227. QueueFamilyIndex = queueFamilyIndex,
  228. QueueCount = queueCount,
  229. PQueuePriorities = queuePriorities,
  230. };
  231. bool useRobustBufferAccess = VendorUtils.FromId(physicalDevice.PhysicalDeviceProperties.VendorID) == Vendor.Nvidia;
  232. PhysicalDeviceFeatures2 features2 = new()
  233. {
  234. SType = StructureType.PhysicalDeviceFeatures2,
  235. };
  236. PhysicalDeviceVulkan11Features supportedFeaturesVk11 = new()
  237. {
  238. SType = StructureType.PhysicalDeviceVulkan11Features,
  239. PNext = features2.PNext,
  240. };
  241. features2.PNext = &supportedFeaturesVk11;
  242. PhysicalDeviceCustomBorderColorFeaturesEXT supportedFeaturesCustomBorderColor = new()
  243. {
  244. SType = StructureType.PhysicalDeviceCustomBorderColorFeaturesExt,
  245. PNext = features2.PNext,
  246. };
  247. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_custom_border_color"))
  248. {
  249. features2.PNext = &supportedFeaturesCustomBorderColor;
  250. }
  251. PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT supportedFeaturesPrimitiveTopologyListRestart = new()
  252. {
  253. SType = StructureType.PhysicalDevicePrimitiveTopologyListRestartFeaturesExt,
  254. PNext = features2.PNext,
  255. };
  256. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_primitive_topology_list_restart"))
  257. {
  258. features2.PNext = &supportedFeaturesPrimitiveTopologyListRestart;
  259. }
  260. PhysicalDeviceTransformFeedbackFeaturesEXT supportedFeaturesTransformFeedback = new()
  261. {
  262. SType = StructureType.PhysicalDeviceTransformFeedbackFeaturesExt,
  263. PNext = features2.PNext,
  264. };
  265. if (physicalDevice.IsDeviceExtensionPresent(ExtTransformFeedback.ExtensionName))
  266. {
  267. features2.PNext = &supportedFeaturesTransformFeedback;
  268. }
  269. PhysicalDeviceRobustness2FeaturesEXT supportedFeaturesRobustness2 = new()
  270. {
  271. SType = StructureType.PhysicalDeviceRobustness2FeaturesExt,
  272. };
  273. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_robustness2"))
  274. {
  275. supportedFeaturesRobustness2.PNext = features2.PNext;
  276. features2.PNext = &supportedFeaturesRobustness2;
  277. }
  278. PhysicalDeviceDepthClipControlFeaturesEXT supportedFeaturesDepthClipControl = new()
  279. {
  280. SType = StructureType.PhysicalDeviceDepthClipControlFeaturesExt,
  281. PNext = features2.PNext,
  282. };
  283. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_depth_clip_control"))
  284. {
  285. features2.PNext = &supportedFeaturesDepthClipControl;
  286. }
  287. api.GetPhysicalDeviceFeatures2(physicalDevice.PhysicalDevice, &features2);
  288. var supportedFeatures = features2.Features;
  289. var features = new PhysicalDeviceFeatures
  290. {
  291. DepthBiasClamp = supportedFeatures.DepthBiasClamp,
  292. DepthClamp = supportedFeatures.DepthClamp,
  293. DualSrcBlend = supportedFeatures.DualSrcBlend,
  294. FragmentStoresAndAtomics = supportedFeatures.FragmentStoresAndAtomics,
  295. GeometryShader = supportedFeatures.GeometryShader,
  296. ImageCubeArray = supportedFeatures.ImageCubeArray,
  297. IndependentBlend = supportedFeatures.IndependentBlend,
  298. LogicOp = supportedFeatures.LogicOp,
  299. OcclusionQueryPrecise = supportedFeatures.OcclusionQueryPrecise,
  300. MultiViewport = supportedFeatures.MultiViewport,
  301. PipelineStatisticsQuery = supportedFeatures.PipelineStatisticsQuery,
  302. SamplerAnisotropy = supportedFeatures.SamplerAnisotropy,
  303. ShaderClipDistance = supportedFeatures.ShaderClipDistance,
  304. ShaderFloat64 = supportedFeatures.ShaderFloat64,
  305. ShaderImageGatherExtended = supportedFeatures.ShaderImageGatherExtended,
  306. ShaderStorageImageMultisample = supportedFeatures.ShaderStorageImageMultisample,
  307. ShaderStorageImageReadWithoutFormat = supportedFeatures.ShaderStorageImageReadWithoutFormat,
  308. ShaderStorageImageWriteWithoutFormat = supportedFeatures.ShaderStorageImageWriteWithoutFormat,
  309. TessellationShader = supportedFeatures.TessellationShader,
  310. VertexPipelineStoresAndAtomics = supportedFeatures.VertexPipelineStoresAndAtomics,
  311. RobustBufferAccess = useRobustBufferAccess,
  312. };
  313. void* pExtendedFeatures = null;
  314. PhysicalDeviceTransformFeedbackFeaturesEXT featuresTransformFeedback;
  315. if (physicalDevice.IsDeviceExtensionPresent(ExtTransformFeedback.ExtensionName))
  316. {
  317. featuresTransformFeedback = new PhysicalDeviceTransformFeedbackFeaturesEXT
  318. {
  319. SType = StructureType.PhysicalDeviceTransformFeedbackFeaturesExt,
  320. PNext = pExtendedFeatures,
  321. TransformFeedback = supportedFeaturesTransformFeedback.TransformFeedback,
  322. };
  323. pExtendedFeatures = &featuresTransformFeedback;
  324. }
  325. PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT featuresPrimitiveTopologyListRestart;
  326. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_primitive_topology_list_restart"))
  327. {
  328. featuresPrimitiveTopologyListRestart = new PhysicalDevicePrimitiveTopologyListRestartFeaturesEXT
  329. {
  330. SType = StructureType.PhysicalDevicePrimitiveTopologyListRestartFeaturesExt,
  331. PNext = pExtendedFeatures,
  332. PrimitiveTopologyListRestart = supportedFeaturesPrimitiveTopologyListRestart.PrimitiveTopologyListRestart,
  333. PrimitiveTopologyPatchListRestart = supportedFeaturesPrimitiveTopologyListRestart.PrimitiveTopologyPatchListRestart,
  334. };
  335. pExtendedFeatures = &featuresPrimitiveTopologyListRestart;
  336. }
  337. PhysicalDeviceRobustness2FeaturesEXT featuresRobustness2;
  338. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_robustness2"))
  339. {
  340. featuresRobustness2 = new PhysicalDeviceRobustness2FeaturesEXT
  341. {
  342. SType = StructureType.PhysicalDeviceRobustness2FeaturesExt,
  343. PNext = pExtendedFeatures,
  344. NullDescriptor = supportedFeaturesRobustness2.NullDescriptor,
  345. };
  346. pExtendedFeatures = &featuresRobustness2;
  347. }
  348. var featuresExtendedDynamicState = new PhysicalDeviceExtendedDynamicStateFeaturesEXT
  349. {
  350. SType = StructureType.PhysicalDeviceExtendedDynamicStateFeaturesExt,
  351. PNext = pExtendedFeatures,
  352. ExtendedDynamicState = physicalDevice.IsDeviceExtensionPresent(ExtExtendedDynamicState.ExtensionName),
  353. };
  354. pExtendedFeatures = &featuresExtendedDynamicState;
  355. var featuresVk11 = new PhysicalDeviceVulkan11Features
  356. {
  357. SType = StructureType.PhysicalDeviceVulkan11Features,
  358. PNext = pExtendedFeatures,
  359. ShaderDrawParameters = supportedFeaturesVk11.ShaderDrawParameters,
  360. };
  361. pExtendedFeatures = &featuresVk11;
  362. var featuresVk12 = new PhysicalDeviceVulkan12Features
  363. {
  364. SType = StructureType.PhysicalDeviceVulkan12Features,
  365. PNext = pExtendedFeatures,
  366. DescriptorIndexing = physicalDevice.IsDeviceExtensionPresent("VK_EXT_descriptor_indexing"),
  367. DrawIndirectCount = physicalDevice.IsDeviceExtensionPresent(KhrDrawIndirectCount.ExtensionName),
  368. UniformBufferStandardLayout = physicalDevice.IsDeviceExtensionPresent("VK_KHR_uniform_buffer_standard_layout"),
  369. };
  370. pExtendedFeatures = &featuresVk12;
  371. PhysicalDeviceIndexTypeUint8FeaturesEXT featuresIndexU8;
  372. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_index_type_uint8"))
  373. {
  374. featuresIndexU8 = new PhysicalDeviceIndexTypeUint8FeaturesEXT
  375. {
  376. SType = StructureType.PhysicalDeviceIndexTypeUint8FeaturesExt,
  377. PNext = pExtendedFeatures,
  378. IndexTypeUint8 = true,
  379. };
  380. pExtendedFeatures = &featuresIndexU8;
  381. }
  382. PhysicalDeviceFragmentShaderInterlockFeaturesEXT featuresFragmentShaderInterlock;
  383. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_fragment_shader_interlock"))
  384. {
  385. featuresFragmentShaderInterlock = new PhysicalDeviceFragmentShaderInterlockFeaturesEXT
  386. {
  387. SType = StructureType.PhysicalDeviceFragmentShaderInterlockFeaturesExt,
  388. PNext = pExtendedFeatures,
  389. FragmentShaderPixelInterlock = true,
  390. };
  391. pExtendedFeatures = &featuresFragmentShaderInterlock;
  392. }
  393. PhysicalDeviceCustomBorderColorFeaturesEXT featuresCustomBorderColor;
  394. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_custom_border_color") &&
  395. supportedFeaturesCustomBorderColor.CustomBorderColors &&
  396. supportedFeaturesCustomBorderColor.CustomBorderColorWithoutFormat)
  397. {
  398. featuresCustomBorderColor = new PhysicalDeviceCustomBorderColorFeaturesEXT
  399. {
  400. SType = StructureType.PhysicalDeviceCustomBorderColorFeaturesExt,
  401. PNext = pExtendedFeatures,
  402. CustomBorderColors = true,
  403. CustomBorderColorWithoutFormat = true,
  404. };
  405. pExtendedFeatures = &featuresCustomBorderColor;
  406. }
  407. PhysicalDeviceDepthClipControlFeaturesEXT featuresDepthClipControl;
  408. if (physicalDevice.IsDeviceExtensionPresent("VK_EXT_depth_clip_control") &&
  409. supportedFeaturesDepthClipControl.DepthClipControl)
  410. {
  411. featuresDepthClipControl = new PhysicalDeviceDepthClipControlFeaturesEXT
  412. {
  413. SType = StructureType.PhysicalDeviceDepthClipControlFeaturesExt,
  414. PNext = pExtendedFeatures,
  415. DepthClipControl = true,
  416. };
  417. pExtendedFeatures = &featuresDepthClipControl;
  418. }
  419. var enabledExtensions = _requiredExtensions.Union(_desirableExtensions.Intersect(physicalDevice.DeviceExtensions)).ToArray();
  420. IntPtr* ppEnabledExtensions = stackalloc IntPtr[enabledExtensions.Length];
  421. for (int i = 0; i < enabledExtensions.Length; i++)
  422. {
  423. ppEnabledExtensions[i] = Marshal.StringToHGlobalAnsi(enabledExtensions[i]);
  424. }
  425. var deviceCreateInfo = new DeviceCreateInfo
  426. {
  427. SType = StructureType.DeviceCreateInfo,
  428. PNext = pExtendedFeatures,
  429. QueueCreateInfoCount = 1,
  430. PQueueCreateInfos = &queueCreateInfo,
  431. PpEnabledExtensionNames = (byte**)ppEnabledExtensions,
  432. EnabledExtensionCount = (uint)enabledExtensions.Length,
  433. PEnabledFeatures = &features,
  434. };
  435. api.CreateDevice(physicalDevice.PhysicalDevice, in deviceCreateInfo, null, out var device).ThrowOnError();
  436. for (int i = 0; i < enabledExtensions.Length; i++)
  437. {
  438. Marshal.FreeHGlobal(ppEnabledExtensions[i]);
  439. }
  440. return device;
  441. }
  442. }
  443. }