vulkan_device.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <bitset>
  5. #include <chrono>
  6. #include <optional>
  7. #include <string_view>
  8. #include <thread>
  9. #include <unordered_set>
  10. #include <utility>
  11. #include <vector>
  12. #include "common/assert.h"
  13. #include "common/settings.h"
  14. #include "video_core/vulkan_common/nsight_aftermath_tracker.h"
  15. #include "video_core/vulkan_common/vulkan_device.h"
  16. #include "video_core/vulkan_common/vulkan_wrapper.h"
  17. namespace Vulkan {
  18. namespace {
  19. namespace Alternatives {
  20. constexpr std::array DEPTH24_UNORM_STENCIL8_UINT{
  21. VK_FORMAT_D32_SFLOAT_S8_UINT,
  22. VK_FORMAT_D16_UNORM_S8_UINT,
  23. VK_FORMAT_UNDEFINED,
  24. };
  25. constexpr std::array DEPTH16_UNORM_STENCIL8_UINT{
  26. VK_FORMAT_D24_UNORM_S8_UINT,
  27. VK_FORMAT_D32_SFLOAT_S8_UINT,
  28. VK_FORMAT_UNDEFINED,
  29. };
  30. } // namespace Alternatives
  31. constexpr std::array REQUIRED_EXTENSIONS{
  32. VK_KHR_MAINTENANCE1_EXTENSION_NAME,
  33. VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME,
  34. VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME,
  35. VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
  36. VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
  37. VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME,
  38. VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME,
  39. VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME,
  40. VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME,
  41. VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME,
  42. VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME,
  43. VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME,
  44. VK_EXT_ROBUSTNESS_2_EXTENSION_NAME,
  45. VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME,
  46. #ifdef _WIN32
  47. VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME,
  48. #endif
  49. #ifdef __unix__
  50. VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,
  51. #endif
  52. };
  53. template <typename T>
  54. void SetNext(void**& next, T& data) {
  55. *next = &data;
  56. next = &data.pNext;
  57. }
  58. constexpr const VkFormat* GetFormatAlternatives(VkFormat format) {
  59. switch (format) {
  60. case VK_FORMAT_D24_UNORM_S8_UINT:
  61. return Alternatives::DEPTH24_UNORM_STENCIL8_UINT.data();
  62. case VK_FORMAT_D16_UNORM_S8_UINT:
  63. return Alternatives::DEPTH16_UNORM_STENCIL8_UINT.data();
  64. default:
  65. return nullptr;
  66. }
  67. }
  68. VkFormatFeatureFlags GetFormatFeatures(VkFormatProperties properties, FormatType format_type) {
  69. switch (format_type) {
  70. case FormatType::Linear:
  71. return properties.linearTilingFeatures;
  72. case FormatType::Optimal:
  73. return properties.optimalTilingFeatures;
  74. case FormatType::Buffer:
  75. return properties.bufferFeatures;
  76. default:
  77. return {};
  78. }
  79. }
  80. std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties(vk::PhysicalDevice physical) {
  81. static constexpr std::array formats{
  82. VK_FORMAT_A8B8G8R8_UNORM_PACK32,
  83. VK_FORMAT_A8B8G8R8_UINT_PACK32,
  84. VK_FORMAT_A8B8G8R8_SNORM_PACK32,
  85. VK_FORMAT_A8B8G8R8_SINT_PACK32,
  86. VK_FORMAT_A8B8G8R8_SRGB_PACK32,
  87. VK_FORMAT_B5G6R5_UNORM_PACK16,
  88. VK_FORMAT_A2B10G10R10_UNORM_PACK32,
  89. VK_FORMAT_A2B10G10R10_UINT_PACK32,
  90. VK_FORMAT_A1R5G5B5_UNORM_PACK16,
  91. VK_FORMAT_R32G32B32A32_SFLOAT,
  92. VK_FORMAT_R32G32B32A32_SINT,
  93. VK_FORMAT_R32G32B32A32_UINT,
  94. VK_FORMAT_R32G32_SFLOAT,
  95. VK_FORMAT_R32G32_SINT,
  96. VK_FORMAT_R32G32_UINT,
  97. VK_FORMAT_R16G16B16A16_SINT,
  98. VK_FORMAT_R16G16B16A16_UINT,
  99. VK_FORMAT_R16G16B16A16_SNORM,
  100. VK_FORMAT_R16G16B16A16_UNORM,
  101. VK_FORMAT_R16G16_UNORM,
  102. VK_FORMAT_R16G16_SNORM,
  103. VK_FORMAT_R16G16_SFLOAT,
  104. VK_FORMAT_R16G16_SINT,
  105. VK_FORMAT_R16_UNORM,
  106. VK_FORMAT_R16_UINT,
  107. VK_FORMAT_R8G8B8A8_SRGB,
  108. VK_FORMAT_R8G8_UNORM,
  109. VK_FORMAT_R8G8_SNORM,
  110. VK_FORMAT_R8G8_SINT,
  111. VK_FORMAT_R8G8_UINT,
  112. VK_FORMAT_R8_UNORM,
  113. VK_FORMAT_R8_SNORM,
  114. VK_FORMAT_R8_SINT,
  115. VK_FORMAT_R8_UINT,
  116. VK_FORMAT_B10G11R11_UFLOAT_PACK32,
  117. VK_FORMAT_R32_SFLOAT,
  118. VK_FORMAT_R32_UINT,
  119. VK_FORMAT_R32_SINT,
  120. VK_FORMAT_R16_SFLOAT,
  121. VK_FORMAT_R16G16B16A16_SFLOAT,
  122. VK_FORMAT_B8G8R8A8_UNORM,
  123. VK_FORMAT_B8G8R8A8_SRGB,
  124. VK_FORMAT_R4G4B4A4_UNORM_PACK16,
  125. VK_FORMAT_D32_SFLOAT,
  126. VK_FORMAT_D16_UNORM,
  127. VK_FORMAT_D16_UNORM_S8_UINT,
  128. VK_FORMAT_D24_UNORM_S8_UINT,
  129. VK_FORMAT_D32_SFLOAT_S8_UINT,
  130. VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
  131. VK_FORMAT_BC2_UNORM_BLOCK,
  132. VK_FORMAT_BC3_UNORM_BLOCK,
  133. VK_FORMAT_BC4_UNORM_BLOCK,
  134. VK_FORMAT_BC4_SNORM_BLOCK,
  135. VK_FORMAT_BC5_UNORM_BLOCK,
  136. VK_FORMAT_BC5_SNORM_BLOCK,
  137. VK_FORMAT_BC7_UNORM_BLOCK,
  138. VK_FORMAT_BC6H_UFLOAT_BLOCK,
  139. VK_FORMAT_BC6H_SFLOAT_BLOCK,
  140. VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
  141. VK_FORMAT_BC2_SRGB_BLOCK,
  142. VK_FORMAT_BC3_SRGB_BLOCK,
  143. VK_FORMAT_BC7_SRGB_BLOCK,
  144. VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
  145. VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
  146. VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
  147. VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
  148. VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
  149. VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
  150. VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
  151. VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
  152. VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
  153. VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
  154. VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
  155. VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
  156. VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
  157. VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
  158. VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
  159. VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
  160. VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
  161. VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
  162. VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
  163. VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
  164. VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
  165. VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
  166. VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
  167. VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
  168. VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
  169. VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
  170. VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
  171. VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
  172. VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
  173. VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
  174. VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
  175. VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
  176. VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
  177. };
  178. std::unordered_map<VkFormat, VkFormatProperties> format_properties;
  179. for (const auto format : formats) {
  180. format_properties.emplace(format, physical.GetFormatProperties(format));
  181. }
  182. return format_properties;
  183. }
  184. } // Anonymous namespace
  185. Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR surface,
  186. const vk::InstanceDispatch& dld_)
  187. : instance{instance_}, dld{dld_}, physical{physical_}, properties{physical.GetProperties()},
  188. format_properties{GetFormatProperties(physical)} {
  189. CheckSuitability(surface != nullptr);
  190. SetupFamilies(surface);
  191. SetupFeatures();
  192. const auto queue_cis = GetDeviceQueueCreateInfos();
  193. const std::vector extensions = LoadExtensions(surface != nullptr);
  194. VkPhysicalDeviceFeatures2 features2{
  195. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
  196. .pNext = nullptr,
  197. .features{
  198. .robustBufferAccess = true,
  199. .fullDrawIndexUint32 = false,
  200. .imageCubeArray = true,
  201. .independentBlend = true,
  202. .geometryShader = true,
  203. .tessellationShader = true,
  204. .sampleRateShading = false,
  205. .dualSrcBlend = false,
  206. .logicOp = false,
  207. .multiDrawIndirect = false,
  208. .drawIndirectFirstInstance = false,
  209. .depthClamp = true,
  210. .depthBiasClamp = true,
  211. .fillModeNonSolid = false,
  212. .depthBounds = false,
  213. .wideLines = false,
  214. .largePoints = true,
  215. .alphaToOne = false,
  216. .multiViewport = true,
  217. .samplerAnisotropy = true,
  218. .textureCompressionETC2 = false,
  219. .textureCompressionASTC_LDR = is_optimal_astc_supported,
  220. .textureCompressionBC = false,
  221. .occlusionQueryPrecise = true,
  222. .pipelineStatisticsQuery = false,
  223. .vertexPipelineStoresAndAtomics = true,
  224. .fragmentStoresAndAtomics = true,
  225. .shaderTessellationAndGeometryPointSize = false,
  226. .shaderImageGatherExtended = true,
  227. .shaderStorageImageExtendedFormats = false,
  228. .shaderStorageImageMultisample = is_shader_storage_image_multisample,
  229. .shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported,
  230. .shaderStorageImageWriteWithoutFormat = true,
  231. .shaderUniformBufferArrayDynamicIndexing = false,
  232. .shaderSampledImageArrayDynamicIndexing = false,
  233. .shaderStorageBufferArrayDynamicIndexing = false,
  234. .shaderStorageImageArrayDynamicIndexing = false,
  235. .shaderClipDistance = false,
  236. .shaderCullDistance = false,
  237. .shaderFloat64 = false,
  238. .shaderInt64 = false,
  239. .shaderInt16 = false,
  240. .shaderResourceResidency = false,
  241. .shaderResourceMinLod = false,
  242. .sparseBinding = false,
  243. .sparseResidencyBuffer = false,
  244. .sparseResidencyImage2D = false,
  245. .sparseResidencyImage3D = false,
  246. .sparseResidency2Samples = false,
  247. .sparseResidency4Samples = false,
  248. .sparseResidency8Samples = false,
  249. .sparseResidency16Samples = false,
  250. .sparseResidencyAliased = false,
  251. .variableMultisampleRate = false,
  252. .inheritedQueries = false,
  253. },
  254. };
  255. const void* first_next = &features2;
  256. void** next = &features2.pNext;
  257. VkPhysicalDeviceTimelineSemaphoreFeaturesKHR timeline_semaphore{
  258. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR,
  259. .pNext = nullptr,
  260. .timelineSemaphore = true,
  261. };
  262. SetNext(next, timeline_semaphore);
  263. VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage{
  264. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR,
  265. .pNext = nullptr,
  266. .storageBuffer16BitAccess = false,
  267. .uniformAndStorageBuffer16BitAccess = true,
  268. .storagePushConstant16 = false,
  269. .storageInputOutput16 = false,
  270. };
  271. SetNext(next, bit16_storage);
  272. VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage{
  273. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR,
  274. .pNext = nullptr,
  275. .storageBuffer8BitAccess = false,
  276. .uniformAndStorageBuffer8BitAccess = true,
  277. .storagePushConstant8 = false,
  278. };
  279. SetNext(next, bit8_storage);
  280. VkPhysicalDeviceRobustness2FeaturesEXT robustness2{
  281. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT,
  282. .pNext = nullptr,
  283. .robustBufferAccess2 = true,
  284. .robustImageAccess2 = true,
  285. .nullDescriptor = true,
  286. };
  287. SetNext(next, robustness2);
  288. VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset{
  289. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT,
  290. .pNext = nullptr,
  291. .hostQueryReset = true,
  292. };
  293. SetNext(next, host_query_reset);
  294. VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
  295. if (is_float16_supported) {
  296. float16_int8 = {
  297. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
  298. .pNext = nullptr,
  299. .shaderFloat16 = true,
  300. .shaderInt8 = false,
  301. };
  302. SetNext(next, float16_int8);
  303. } else {
  304. LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
  305. }
  306. if (!nv_viewport_swizzle) {
  307. LOG_INFO(Render_Vulkan, "Device doesn't support viewport swizzles");
  308. }
  309. VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
  310. if (khr_uniform_buffer_standard_layout) {
  311. std430_layout = {
  312. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR,
  313. .pNext = nullptr,
  314. .uniformBufferStandardLayout = true,
  315. };
  316. SetNext(next, std430_layout);
  317. } else {
  318. LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs");
  319. }
  320. VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
  321. if (ext_index_type_uint8) {
  322. index_type_uint8 = {
  323. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT,
  324. .pNext = nullptr,
  325. .indexTypeUint8 = true,
  326. };
  327. SetNext(next, index_type_uint8);
  328. } else {
  329. LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes");
  330. }
  331. VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback;
  332. if (ext_transform_feedback) {
  333. transform_feedback = {
  334. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT,
  335. .pNext = nullptr,
  336. .transformFeedback = true,
  337. .geometryStreams = true,
  338. };
  339. SetNext(next, transform_feedback);
  340. } else {
  341. LOG_INFO(Render_Vulkan, "Device doesn't support transform feedbacks");
  342. }
  343. VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border;
  344. if (ext_custom_border_color) {
  345. custom_border = {
  346. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT,
  347. .pNext = nullptr,
  348. .customBorderColors = VK_TRUE,
  349. .customBorderColorWithoutFormat = VK_TRUE,
  350. };
  351. SetNext(next, custom_border);
  352. } else {
  353. LOG_INFO(Render_Vulkan, "Device doesn't support custom border colors");
  354. }
  355. VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
  356. if (ext_extended_dynamic_state) {
  357. dynamic_state = {
  358. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT,
  359. .pNext = nullptr,
  360. .extendedDynamicState = VK_TRUE,
  361. };
  362. SetNext(next, dynamic_state);
  363. } else {
  364. LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state");
  365. }
  366. if (!ext_depth_range_unrestricted) {
  367. LOG_INFO(Render_Vulkan, "Device doesn't support depth range unrestricted");
  368. }
  369. VkDeviceDiagnosticsConfigCreateInfoNV diagnostics_nv;
  370. if (nv_device_diagnostics_config) {
  371. nsight_aftermath_tracker = std::make_unique<NsightAftermathTracker>();
  372. diagnostics_nv = {
  373. .sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV,
  374. .pNext = &features2,
  375. .flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV |
  376. VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
  377. VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV,
  378. };
  379. first_next = &diagnostics_nv;
  380. }
  381. logical = vk::Device::Create(physical, queue_cis, extensions, first_next, dld);
  382. CollectPhysicalMemoryInfo();
  383. CollectTelemetryParameters();
  384. CollectToolingInfo();
  385. if (ext_extended_dynamic_state && driver_id == VK_DRIVER_ID_MESA_RADV) {
  386. LOG_WARNING(
  387. Render_Vulkan,
  388. "Blacklisting RADV for VK_EXT_extended_dynamic state, likely due to a bug in yuzu");
  389. ext_extended_dynamic_state = false;
  390. }
  391. if (is_float16_supported && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) {
  392. // Intel's compiler crashes when using fp16 on Astral Chain, disable it for the time being.
  393. LOG_WARNING(Render_Vulkan, "Blacklisting Intel proprietary from float16 math");
  394. is_float16_supported = false;
  395. }
  396. graphics_queue = logical.GetQueue(graphics_family);
  397. present_queue = logical.GetQueue(present_family);
  398. use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue();
  399. }
  400. Device::~Device() = default;
  401. VkFormat Device::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
  402. FormatType format_type) const {
  403. if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
  404. return wanted_format;
  405. }
  406. // The wanted format is not supported by hardware, search for alternatives
  407. const VkFormat* alternatives = GetFormatAlternatives(wanted_format);
  408. if (alternatives == nullptr) {
  409. UNREACHABLE_MSG("Format={} with usage={} and type={} has no defined alternatives and host "
  410. "hardware does not support it",
  411. wanted_format, wanted_usage, format_type);
  412. return wanted_format;
  413. }
  414. std::size_t i = 0;
  415. for (VkFormat alternative = *alternatives; alternative; alternative = alternatives[++i]) {
  416. if (!IsFormatSupported(alternative, wanted_usage, format_type)) {
  417. continue;
  418. }
  419. LOG_WARNING(Render_Vulkan,
  420. "Emulating format={} with alternative format={} with usage={} and type={}",
  421. wanted_format, alternative, wanted_usage, format_type);
  422. return alternative;
  423. }
  424. // No alternatives found, panic
  425. UNREACHABLE_MSG("Format={} with usage={} and type={} is not supported by the host hardware and "
  426. "doesn't support any of the alternatives",
  427. wanted_format, wanted_usage, format_type);
  428. return wanted_format;
  429. }
  430. void Device::ReportLoss() const {
  431. LOG_CRITICAL(Render_Vulkan, "Device loss occured!");
  432. // Wait for the log to flush and for Nsight Aftermath to dump the results
  433. std::this_thread::sleep_for(std::chrono::seconds{15});
  434. }
  435. void Device::SaveShader(const std::vector<u32>& spirv) const {
  436. if (nsight_aftermath_tracker) {
  437. nsight_aftermath_tracker->SaveShader(spirv);
  438. }
  439. }
  440. bool Device::IsOptimalAstcSupported(const VkPhysicalDeviceFeatures& features) const {
  441. // Disable for now to avoid converting ASTC twice.
  442. static constexpr std::array astc_formats = {
  443. VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
  444. VK_FORMAT_ASTC_5x4_UNORM_BLOCK, VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
  445. VK_FORMAT_ASTC_5x5_UNORM_BLOCK, VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
  446. VK_FORMAT_ASTC_6x5_UNORM_BLOCK, VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
  447. VK_FORMAT_ASTC_6x6_UNORM_BLOCK, VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
  448. VK_FORMAT_ASTC_8x5_UNORM_BLOCK, VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
  449. VK_FORMAT_ASTC_8x6_UNORM_BLOCK, VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
  450. VK_FORMAT_ASTC_8x8_UNORM_BLOCK, VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
  451. VK_FORMAT_ASTC_10x5_UNORM_BLOCK, VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
  452. VK_FORMAT_ASTC_10x6_UNORM_BLOCK, VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
  453. VK_FORMAT_ASTC_10x8_UNORM_BLOCK, VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
  454. VK_FORMAT_ASTC_10x10_UNORM_BLOCK, VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
  455. VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
  456. VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
  457. };
  458. if (!features.textureCompressionASTC_LDR) {
  459. return false;
  460. }
  461. const auto format_feature_usage{
  462. VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT |
  463. VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
  464. VK_FORMAT_FEATURE_TRANSFER_DST_BIT};
  465. for (const auto format : astc_formats) {
  466. const auto physical_format_properties{physical.GetFormatProperties(format)};
  467. if ((physical_format_properties.optimalTilingFeatures & format_feature_usage) == 0) {
  468. return false;
  469. }
  470. }
  471. return true;
  472. }
  473. bool Device::TestDepthStencilBlits() const {
  474. static constexpr VkFormatFeatureFlags required_features =
  475. VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
  476. const auto test_features = [](VkFormatProperties props) {
  477. return (props.optimalTilingFeatures & required_features) == required_features;
  478. };
  479. return test_features(format_properties.at(VK_FORMAT_D32_SFLOAT_S8_UINT)) &&
  480. test_features(format_properties.at(VK_FORMAT_D24_UNORM_S8_UINT));
  481. }
  482. bool Device::IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
  483. FormatType format_type) const {
  484. const auto it = format_properties.find(wanted_format);
  485. if (it == format_properties.end()) {
  486. UNIMPLEMENTED_MSG("Unimplemented format query={}", wanted_format);
  487. return true;
  488. }
  489. const auto supported_usage = GetFormatFeatures(it->second, format_type);
  490. return (supported_usage & wanted_usage) == wanted_usage;
  491. }
  492. void Device::CheckSuitability(bool requires_swapchain) const {
  493. std::bitset<REQUIRED_EXTENSIONS.size()> available_extensions;
  494. bool has_swapchain = false;
  495. for (const VkExtensionProperties& property : physical.EnumerateDeviceExtensionProperties()) {
  496. const std::string_view name{property.extensionName};
  497. for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
  498. if (available_extensions[i]) {
  499. continue;
  500. }
  501. available_extensions[i] = name == REQUIRED_EXTENSIONS[i];
  502. }
  503. has_swapchain = has_swapchain || name == VK_KHR_SWAPCHAIN_EXTENSION_NAME;
  504. }
  505. for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
  506. if (available_extensions[i]) {
  507. continue;
  508. }
  509. LOG_ERROR(Render_Vulkan, "Missing required extension: {}", REQUIRED_EXTENSIONS[i]);
  510. throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
  511. }
  512. if (requires_swapchain && !has_swapchain) {
  513. LOG_ERROR(Render_Vulkan, "Missing required extension: VK_KHR_swapchain");
  514. throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
  515. }
  516. struct LimitTuple {
  517. u32 minimum;
  518. u32 value;
  519. const char* name;
  520. };
  521. const VkPhysicalDeviceLimits& limits{properties.limits};
  522. const std::array limits_report{
  523. LimitTuple{65536, limits.maxUniformBufferRange, "maxUniformBufferRange"},
  524. LimitTuple{16, limits.maxViewports, "maxViewports"},
  525. LimitTuple{8, limits.maxColorAttachments, "maxColorAttachments"},
  526. LimitTuple{8, limits.maxClipDistances, "maxClipDistances"},
  527. };
  528. for (const auto& tuple : limits_report) {
  529. if (tuple.value < tuple.minimum) {
  530. LOG_ERROR(Render_Vulkan, "{} has to be {} or greater but it is {}", tuple.name,
  531. tuple.minimum, tuple.value);
  532. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  533. }
  534. }
  535. VkPhysicalDeviceRobustness2FeaturesEXT robustness2{};
  536. robustness2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
  537. VkPhysicalDeviceFeatures2 features2{};
  538. features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
  539. features2.pNext = &robustness2;
  540. physical.GetFeatures2KHR(features2);
  541. const VkPhysicalDeviceFeatures& features{features2.features};
  542. const std::array feature_report{
  543. std::make_pair(features.robustBufferAccess, "robustBufferAccess"),
  544. std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"),
  545. std::make_pair(features.robustBufferAccess, "robustBufferAccess"),
  546. std::make_pair(features.imageCubeArray, "imageCubeArray"),
  547. std::make_pair(features.independentBlend, "independentBlend"),
  548. std::make_pair(features.depthClamp, "depthClamp"),
  549. std::make_pair(features.samplerAnisotropy, "samplerAnisotropy"),
  550. std::make_pair(features.largePoints, "largePoints"),
  551. std::make_pair(features.multiViewport, "multiViewport"),
  552. std::make_pair(features.depthBiasClamp, "depthBiasClamp"),
  553. std::make_pair(features.geometryShader, "geometryShader"),
  554. std::make_pair(features.tessellationShader, "tessellationShader"),
  555. std::make_pair(features.occlusionQueryPrecise, "occlusionQueryPrecise"),
  556. std::make_pair(features.fragmentStoresAndAtomics, "fragmentStoresAndAtomics"),
  557. std::make_pair(features.shaderImageGatherExtended, "shaderImageGatherExtended"),
  558. std::make_pair(features.shaderStorageImageWriteWithoutFormat,
  559. "shaderStorageImageWriteWithoutFormat"),
  560. std::make_pair(robustness2.robustBufferAccess2, "robustBufferAccess2"),
  561. std::make_pair(robustness2.robustImageAccess2, "robustImageAccess2"),
  562. std::make_pair(robustness2.nullDescriptor, "nullDescriptor"),
  563. };
  564. for (const auto& [is_supported, name] : feature_report) {
  565. if (is_supported) {
  566. continue;
  567. }
  568. LOG_ERROR(Render_Vulkan, "Missing required feature: {}", name);
  569. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  570. }
  571. }
  572. std::vector<const char*> Device::LoadExtensions(bool requires_surface) {
  573. std::vector<const char*> extensions;
  574. extensions.reserve(8 + REQUIRED_EXTENSIONS.size());
  575. extensions.insert(extensions.begin(), REQUIRED_EXTENSIONS.begin(), REQUIRED_EXTENSIONS.end());
  576. if (requires_surface) {
  577. extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
  578. }
  579. bool has_khr_shader_float16_int8{};
  580. bool has_ext_subgroup_size_control{};
  581. bool has_ext_transform_feedback{};
  582. bool has_ext_custom_border_color{};
  583. bool has_ext_extended_dynamic_state{};
  584. for (const VkExtensionProperties& extension : physical.EnumerateDeviceExtensionProperties()) {
  585. const auto test = [&](std::optional<std::reference_wrapper<bool>> status, const char* name,
  586. bool push) {
  587. if (extension.extensionName != std::string_view(name)) {
  588. return;
  589. }
  590. if (push) {
  591. extensions.push_back(name);
  592. }
  593. if (status) {
  594. status->get() = true;
  595. }
  596. };
  597. test(nv_viewport_swizzle, VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME, true);
  598. test(khr_uniform_buffer_standard_layout,
  599. VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true);
  600. test(has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, false);
  601. test(ext_depth_range_unrestricted, VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME, true);
  602. test(ext_index_type_uint8, VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, true);
  603. test(ext_sampler_filter_minmax, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, true);
  604. test(ext_shader_viewport_index_layer, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME,
  605. true);
  606. test(ext_tooling_info, VK_EXT_TOOLING_INFO_EXTENSION_NAME, true);
  607. test(ext_shader_stencil_export, VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME, true);
  608. test(has_ext_transform_feedback, VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME, false);
  609. test(has_ext_custom_border_color, VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME, false);
  610. test(has_ext_extended_dynamic_state, VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME, false);
  611. test(has_ext_subgroup_size_control, VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false);
  612. if (Settings::values.renderer_debug) {
  613. test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME,
  614. true);
  615. }
  616. }
  617. VkPhysicalDeviceFeatures2KHR features;
  618. features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
  619. VkPhysicalDeviceProperties2KHR physical_properties;
  620. physical_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
  621. if (has_khr_shader_float16_int8) {
  622. VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8_features;
  623. float16_int8_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR;
  624. float16_int8_features.pNext = nullptr;
  625. features.pNext = &float16_int8_features;
  626. physical.GetFeatures2KHR(features);
  627. is_float16_supported = float16_int8_features.shaderFloat16;
  628. extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME);
  629. }
  630. if (has_ext_subgroup_size_control) {
  631. VkPhysicalDeviceSubgroupSizeControlFeaturesEXT subgroup_features;
  632. subgroup_features.sType =
  633. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT;
  634. subgroup_features.pNext = nullptr;
  635. features.pNext = &subgroup_features;
  636. physical.GetFeatures2KHR(features);
  637. VkPhysicalDeviceSubgroupSizeControlPropertiesEXT subgroup_properties;
  638. subgroup_properties.sType =
  639. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT;
  640. subgroup_properties.pNext = nullptr;
  641. physical_properties.pNext = &subgroup_properties;
  642. physical.GetProperties2KHR(physical_properties);
  643. is_warp_potentially_bigger = subgroup_properties.maxSubgroupSize > GuestWarpSize;
  644. if (subgroup_features.subgroupSizeControl &&
  645. subgroup_properties.minSubgroupSize <= GuestWarpSize &&
  646. subgroup_properties.maxSubgroupSize >= GuestWarpSize) {
  647. extensions.push_back(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);
  648. guest_warp_stages = subgroup_properties.requiredSubgroupSizeStages;
  649. }
  650. } else {
  651. is_warp_potentially_bigger = true;
  652. }
  653. if (has_ext_transform_feedback) {
  654. VkPhysicalDeviceTransformFeedbackFeaturesEXT tfb_features;
  655. tfb_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT;
  656. tfb_features.pNext = nullptr;
  657. features.pNext = &tfb_features;
  658. physical.GetFeatures2KHR(features);
  659. VkPhysicalDeviceTransformFeedbackPropertiesEXT tfb_properties;
  660. tfb_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT;
  661. tfb_properties.pNext = nullptr;
  662. physical_properties.pNext = &tfb_properties;
  663. physical.GetProperties2KHR(physical_properties);
  664. if (tfb_features.transformFeedback && tfb_features.geometryStreams &&
  665. tfb_properties.maxTransformFeedbackStreams >= 4 &&
  666. tfb_properties.maxTransformFeedbackBuffers && tfb_properties.transformFeedbackQueries &&
  667. tfb_properties.transformFeedbackDraw) {
  668. extensions.push_back(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
  669. ext_transform_feedback = true;
  670. }
  671. }
  672. if (has_ext_custom_border_color) {
  673. VkPhysicalDeviceCustomBorderColorFeaturesEXT border_features;
  674. border_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT;
  675. border_features.pNext = nullptr;
  676. features.pNext = &border_features;
  677. physical.GetFeatures2KHR(features);
  678. if (border_features.customBorderColors && border_features.customBorderColorWithoutFormat) {
  679. extensions.push_back(VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
  680. ext_custom_border_color = true;
  681. }
  682. }
  683. if (has_ext_extended_dynamic_state) {
  684. VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
  685. dynamic_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
  686. dynamic_state.pNext = nullptr;
  687. features.pNext = &dynamic_state;
  688. physical.GetFeatures2KHR(features);
  689. if (dynamic_state.extendedDynamicState) {
  690. extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
  691. ext_extended_dynamic_state = true;
  692. }
  693. }
  694. return extensions;
  695. }
  696. void Device::SetupFamilies(VkSurfaceKHR surface) {
  697. const std::vector queue_family_properties = physical.GetQueueFamilyProperties();
  698. std::optional<u32> graphics;
  699. std::optional<u32> present;
  700. for (u32 index = 0; index < static_cast<u32>(queue_family_properties.size()); ++index) {
  701. if (graphics && (present || !surface)) {
  702. break;
  703. }
  704. const VkQueueFamilyProperties& queue_family = queue_family_properties[index];
  705. if (queue_family.queueCount == 0) {
  706. continue;
  707. }
  708. if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
  709. graphics = index;
  710. }
  711. if (surface && physical.GetSurfaceSupportKHR(index, surface)) {
  712. present = index;
  713. }
  714. }
  715. if (!graphics) {
  716. LOG_ERROR(Render_Vulkan, "Device lacks a graphics queue");
  717. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  718. }
  719. if (surface && !present) {
  720. LOG_ERROR(Render_Vulkan, "Device lacks a present queue");
  721. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  722. }
  723. graphics_family = *graphics;
  724. present_family = *present;
  725. }
  726. void Device::SetupFeatures() {
  727. const auto supported_features{physical.GetFeatures()};
  728. is_formatless_image_load_supported = supported_features.shaderStorageImageReadWithoutFormat;
  729. is_shader_storage_image_multisample = supported_features.shaderStorageImageMultisample;
  730. is_blit_depth_stencil_supported = TestDepthStencilBlits();
  731. is_optimal_astc_supported = IsOptimalAstcSupported(supported_features);
  732. }
  733. void Device::CollectTelemetryParameters() {
  734. VkPhysicalDeviceDriverPropertiesKHR driver{
  735. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR,
  736. .pNext = nullptr,
  737. .driverID = {},
  738. .driverName = {},
  739. .driverInfo = {},
  740. .conformanceVersion = {},
  741. };
  742. VkPhysicalDeviceProperties2KHR device_properties{
  743. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
  744. .pNext = &driver,
  745. .properties = {},
  746. };
  747. physical.GetProperties2KHR(device_properties);
  748. driver_id = driver.driverID;
  749. vendor_name = driver.driverName;
  750. const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
  751. reported_extensions.reserve(std::size(extensions));
  752. for (const auto& extension : extensions) {
  753. reported_extensions.emplace_back(extension.extensionName);
  754. }
  755. }
  756. void Device::CollectPhysicalMemoryInfo() {
  757. const auto mem_properties = physical.GetMemoryProperties();
  758. const size_t num_properties = mem_properties.memoryHeapCount;
  759. device_access_memory = 0;
  760. for (size_t element = 0; element < num_properties; ++element) {
  761. if ((mem_properties.memoryHeaps[element].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) {
  762. device_access_memory += mem_properties.memoryHeaps[element].size;
  763. }
  764. }
  765. }
  766. void Device::CollectToolingInfo() {
  767. if (!ext_tooling_info) {
  768. return;
  769. }
  770. const auto vkGetPhysicalDeviceToolPropertiesEXT =
  771. reinterpret_cast<PFN_vkGetPhysicalDeviceToolPropertiesEXT>(
  772. dld.vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceToolPropertiesEXT"));
  773. if (!vkGetPhysicalDeviceToolPropertiesEXT) {
  774. return;
  775. }
  776. u32 tool_count = 0;
  777. if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, nullptr) != VK_SUCCESS) {
  778. return;
  779. }
  780. std::vector<VkPhysicalDeviceToolPropertiesEXT> tools(tool_count);
  781. if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, tools.data()) != VK_SUCCESS) {
  782. return;
  783. }
  784. for (const VkPhysicalDeviceToolPropertiesEXT& tool : tools) {
  785. const std::string_view name = tool.name;
  786. LOG_INFO(Render_Vulkan, "{}", name);
  787. has_renderdoc = has_renderdoc || name == "RenderDoc";
  788. has_nsight_graphics = has_nsight_graphics || name == "NVIDIA Nsight Graphics";
  789. }
  790. }
  791. std::vector<VkDeviceQueueCreateInfo> Device::GetDeviceQueueCreateInfos() const {
  792. static constexpr float QUEUE_PRIORITY = 1.0f;
  793. std::unordered_set<u32> unique_queue_families{graphics_family, present_family};
  794. std::vector<VkDeviceQueueCreateInfo> queue_cis;
  795. queue_cis.reserve(unique_queue_families.size());
  796. for (const u32 queue_family : unique_queue_families) {
  797. auto& ci = queue_cis.emplace_back(VkDeviceQueueCreateInfo{
  798. .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
  799. .pNext = nullptr,
  800. .flags = 0,
  801. .queueFamilyIndex = queue_family,
  802. .queueCount = 1,
  803. .pQueuePriorities = nullptr,
  804. });
  805. ci.pQueuePriorities = &QUEUE_PRIORITY;
  806. }
  807. return queue_cis;
  808. }
  809. } // namespace Vulkan