vulkan_device.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  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. CollectTelemetryParameters();
  383. CollectToolingInfo();
  384. if (ext_extended_dynamic_state && driver_id == VK_DRIVER_ID_MESA_RADV) {
  385. LOG_WARNING(
  386. Render_Vulkan,
  387. "Blacklisting RADV for VK_EXT_extended_dynamic state, likely due to a bug in yuzu");
  388. ext_extended_dynamic_state = false;
  389. }
  390. if (is_float16_supported && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) {
  391. // Intel's compiler crashes when using fp16 on Astral Chain, disable it for the time being.
  392. LOG_WARNING(Render_Vulkan, "Blacklisting Intel proprietary from float16 math");
  393. is_float16_supported = false;
  394. }
  395. graphics_queue = logical.GetQueue(graphics_family);
  396. present_queue = logical.GetQueue(present_family);
  397. use_asynchronous_shaders = Settings::values.use_asynchronous_shaders.GetValue();
  398. }
  399. Device::~Device() = default;
  400. VkFormat Device::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
  401. FormatType format_type) const {
  402. if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
  403. return wanted_format;
  404. }
  405. // The wanted format is not supported by hardware, search for alternatives
  406. const VkFormat* alternatives = GetFormatAlternatives(wanted_format);
  407. if (alternatives == nullptr) {
  408. UNREACHABLE_MSG("Format={} with usage={} and type={} has no defined alternatives and host "
  409. "hardware does not support it",
  410. wanted_format, wanted_usage, format_type);
  411. return wanted_format;
  412. }
  413. std::size_t i = 0;
  414. for (VkFormat alternative = *alternatives; alternative; alternative = alternatives[++i]) {
  415. if (!IsFormatSupported(alternative, wanted_usage, format_type)) {
  416. continue;
  417. }
  418. LOG_WARNING(Render_Vulkan,
  419. "Emulating format={} with alternative format={} with usage={} and type={}",
  420. wanted_format, alternative, wanted_usage, format_type);
  421. return alternative;
  422. }
  423. // No alternatives found, panic
  424. UNREACHABLE_MSG("Format={} with usage={} and type={} is not supported by the host hardware and "
  425. "doesn't support any of the alternatives",
  426. wanted_format, wanted_usage, format_type);
  427. return wanted_format;
  428. }
  429. void Device::ReportLoss() const {
  430. LOG_CRITICAL(Render_Vulkan, "Device loss occured!");
  431. // Wait for the log to flush and for Nsight Aftermath to dump the results
  432. std::this_thread::sleep_for(std::chrono::seconds{15});
  433. }
  434. void Device::SaveShader(const std::vector<u32>& spirv) const {
  435. if (nsight_aftermath_tracker) {
  436. nsight_aftermath_tracker->SaveShader(spirv);
  437. }
  438. }
  439. bool Device::IsOptimalAstcSupported(const VkPhysicalDeviceFeatures& features) const {
  440. // Disable for now to avoid converting ASTC twice.
  441. static constexpr std::array astc_formats = {
  442. VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
  443. VK_FORMAT_ASTC_5x4_UNORM_BLOCK, VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
  444. VK_FORMAT_ASTC_5x5_UNORM_BLOCK, VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
  445. VK_FORMAT_ASTC_6x5_UNORM_BLOCK, VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
  446. VK_FORMAT_ASTC_6x6_UNORM_BLOCK, VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
  447. VK_FORMAT_ASTC_8x5_UNORM_BLOCK, VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
  448. VK_FORMAT_ASTC_8x6_UNORM_BLOCK, VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
  449. VK_FORMAT_ASTC_8x8_UNORM_BLOCK, VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
  450. VK_FORMAT_ASTC_10x5_UNORM_BLOCK, VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
  451. VK_FORMAT_ASTC_10x6_UNORM_BLOCK, VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
  452. VK_FORMAT_ASTC_10x8_UNORM_BLOCK, VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
  453. VK_FORMAT_ASTC_10x10_UNORM_BLOCK, VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
  454. VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
  455. VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
  456. };
  457. if (!features.textureCompressionASTC_LDR) {
  458. return false;
  459. }
  460. const auto format_feature_usage{
  461. VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT |
  462. VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
  463. VK_FORMAT_FEATURE_TRANSFER_DST_BIT};
  464. for (const auto format : astc_formats) {
  465. const auto physical_format_properties{physical.GetFormatProperties(format)};
  466. if ((physical_format_properties.optimalTilingFeatures & format_feature_usage) == 0) {
  467. return false;
  468. }
  469. }
  470. return true;
  471. }
  472. bool Device::TestDepthStencilBlits() const {
  473. static constexpr VkFormatFeatureFlags required_features =
  474. VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
  475. const auto test_features = [](VkFormatProperties props) {
  476. return (props.optimalTilingFeatures & required_features) == required_features;
  477. };
  478. return test_features(format_properties.at(VK_FORMAT_D32_SFLOAT_S8_UINT)) &&
  479. test_features(format_properties.at(VK_FORMAT_D24_UNORM_S8_UINT));
  480. }
  481. bool Device::IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
  482. FormatType format_type) const {
  483. const auto it = format_properties.find(wanted_format);
  484. if (it == format_properties.end()) {
  485. UNIMPLEMENTED_MSG("Unimplemented format query={}", wanted_format);
  486. return true;
  487. }
  488. const auto supported_usage = GetFormatFeatures(it->second, format_type);
  489. return (supported_usage & wanted_usage) == wanted_usage;
  490. }
  491. std::string Device::GetDriverName() const {
  492. switch (driver_id) {
  493. case VK_DRIVER_ID_AMD_PROPRIETARY:
  494. return "AMD";
  495. case VK_DRIVER_ID_AMD_OPEN_SOURCE:
  496. return "AMDVLK";
  497. case VK_DRIVER_ID_MESA_RADV:
  498. return "RADV";
  499. case VK_DRIVER_ID_NVIDIA_PROPRIETARY:
  500. return "NVIDIA";
  501. case VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS:
  502. return "INTEL";
  503. case VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA:
  504. return "ANV";
  505. case VK_DRIVER_ID_MESA_LLVMPIPE:
  506. return "LAVAPIPE";
  507. default:
  508. return vendor_name;
  509. }
  510. }
  511. void Device::CheckSuitability(bool requires_swapchain) const {
  512. std::bitset<REQUIRED_EXTENSIONS.size()> available_extensions;
  513. bool has_swapchain = false;
  514. for (const VkExtensionProperties& property : physical.EnumerateDeviceExtensionProperties()) {
  515. const std::string_view name{property.extensionName};
  516. for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
  517. if (available_extensions[i]) {
  518. continue;
  519. }
  520. available_extensions[i] = name == REQUIRED_EXTENSIONS[i];
  521. }
  522. has_swapchain = has_swapchain || name == VK_KHR_SWAPCHAIN_EXTENSION_NAME;
  523. }
  524. for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
  525. if (available_extensions[i]) {
  526. continue;
  527. }
  528. LOG_ERROR(Render_Vulkan, "Missing required extension: {}", REQUIRED_EXTENSIONS[i]);
  529. throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
  530. }
  531. if (requires_swapchain && !has_swapchain) {
  532. LOG_ERROR(Render_Vulkan, "Missing required extension: VK_KHR_swapchain");
  533. throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
  534. }
  535. struct LimitTuple {
  536. u32 minimum;
  537. u32 value;
  538. const char* name;
  539. };
  540. const VkPhysicalDeviceLimits& limits{properties.limits};
  541. const std::array limits_report{
  542. LimitTuple{65536, limits.maxUniformBufferRange, "maxUniformBufferRange"},
  543. LimitTuple{16, limits.maxViewports, "maxViewports"},
  544. LimitTuple{8, limits.maxColorAttachments, "maxColorAttachments"},
  545. LimitTuple{8, limits.maxClipDistances, "maxClipDistances"},
  546. };
  547. for (const auto& tuple : limits_report) {
  548. if (tuple.value < tuple.minimum) {
  549. LOG_ERROR(Render_Vulkan, "{} has to be {} or greater but it is {}", tuple.name,
  550. tuple.minimum, tuple.value);
  551. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  552. }
  553. }
  554. VkPhysicalDeviceRobustness2FeaturesEXT robustness2{};
  555. robustness2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
  556. VkPhysicalDeviceFeatures2 features2{};
  557. features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
  558. features2.pNext = &robustness2;
  559. physical.GetFeatures2KHR(features2);
  560. const VkPhysicalDeviceFeatures& features{features2.features};
  561. const std::array feature_report{
  562. std::make_pair(features.robustBufferAccess, "robustBufferAccess"),
  563. std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"),
  564. std::make_pair(features.robustBufferAccess, "robustBufferAccess"),
  565. std::make_pair(features.imageCubeArray, "imageCubeArray"),
  566. std::make_pair(features.independentBlend, "independentBlend"),
  567. std::make_pair(features.depthClamp, "depthClamp"),
  568. std::make_pair(features.samplerAnisotropy, "samplerAnisotropy"),
  569. std::make_pair(features.largePoints, "largePoints"),
  570. std::make_pair(features.multiViewport, "multiViewport"),
  571. std::make_pair(features.depthBiasClamp, "depthBiasClamp"),
  572. std::make_pair(features.geometryShader, "geometryShader"),
  573. std::make_pair(features.tessellationShader, "tessellationShader"),
  574. std::make_pair(features.occlusionQueryPrecise, "occlusionQueryPrecise"),
  575. std::make_pair(features.fragmentStoresAndAtomics, "fragmentStoresAndAtomics"),
  576. std::make_pair(features.shaderImageGatherExtended, "shaderImageGatherExtended"),
  577. std::make_pair(features.shaderStorageImageWriteWithoutFormat,
  578. "shaderStorageImageWriteWithoutFormat"),
  579. std::make_pair(robustness2.robustBufferAccess2, "robustBufferAccess2"),
  580. std::make_pair(robustness2.robustImageAccess2, "robustImageAccess2"),
  581. std::make_pair(robustness2.nullDescriptor, "nullDescriptor"),
  582. };
  583. for (const auto& [is_supported, name] : feature_report) {
  584. if (is_supported) {
  585. continue;
  586. }
  587. LOG_ERROR(Render_Vulkan, "Missing required feature: {}", name);
  588. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  589. }
  590. }
  591. std::vector<const char*> Device::LoadExtensions(bool requires_surface) {
  592. std::vector<const char*> extensions;
  593. extensions.reserve(8 + REQUIRED_EXTENSIONS.size());
  594. extensions.insert(extensions.begin(), REQUIRED_EXTENSIONS.begin(), REQUIRED_EXTENSIONS.end());
  595. if (requires_surface) {
  596. extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
  597. }
  598. bool has_khr_shader_float16_int8{};
  599. bool has_ext_subgroup_size_control{};
  600. bool has_ext_transform_feedback{};
  601. bool has_ext_custom_border_color{};
  602. bool has_ext_extended_dynamic_state{};
  603. for (const VkExtensionProperties& extension : physical.EnumerateDeviceExtensionProperties()) {
  604. const auto test = [&](std::optional<std::reference_wrapper<bool>> status, const char* name,
  605. bool push) {
  606. if (extension.extensionName != std::string_view(name)) {
  607. return;
  608. }
  609. if (push) {
  610. extensions.push_back(name);
  611. }
  612. if (status) {
  613. status->get() = true;
  614. }
  615. };
  616. test(nv_viewport_swizzle, VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME, true);
  617. test(khr_uniform_buffer_standard_layout,
  618. VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true);
  619. test(has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, false);
  620. test(ext_depth_range_unrestricted, VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME, true);
  621. test(ext_index_type_uint8, VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, true);
  622. test(ext_sampler_filter_minmax, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, true);
  623. test(ext_shader_viewport_index_layer, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME,
  624. true);
  625. test(ext_tooling_info, VK_EXT_TOOLING_INFO_EXTENSION_NAME, true);
  626. test(ext_shader_stencil_export, VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME, true);
  627. test(has_ext_transform_feedback, VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME, false);
  628. test(has_ext_custom_border_color, VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME, false);
  629. test(has_ext_extended_dynamic_state, VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME, false);
  630. test(has_ext_subgroup_size_control, VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false);
  631. if (Settings::values.renderer_debug) {
  632. test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME,
  633. true);
  634. }
  635. }
  636. VkPhysicalDeviceFeatures2KHR features;
  637. features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
  638. VkPhysicalDeviceProperties2KHR physical_properties;
  639. physical_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
  640. if (has_khr_shader_float16_int8) {
  641. VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8_features;
  642. float16_int8_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR;
  643. float16_int8_features.pNext = nullptr;
  644. features.pNext = &float16_int8_features;
  645. physical.GetFeatures2KHR(features);
  646. is_float16_supported = float16_int8_features.shaderFloat16;
  647. extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME);
  648. }
  649. if (has_ext_subgroup_size_control) {
  650. VkPhysicalDeviceSubgroupSizeControlFeaturesEXT subgroup_features;
  651. subgroup_features.sType =
  652. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT;
  653. subgroup_features.pNext = nullptr;
  654. features.pNext = &subgroup_features;
  655. physical.GetFeatures2KHR(features);
  656. VkPhysicalDeviceSubgroupSizeControlPropertiesEXT subgroup_properties;
  657. subgroup_properties.sType =
  658. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT;
  659. subgroup_properties.pNext = nullptr;
  660. physical_properties.pNext = &subgroup_properties;
  661. physical.GetProperties2KHR(physical_properties);
  662. is_warp_potentially_bigger = subgroup_properties.maxSubgroupSize > GuestWarpSize;
  663. if (subgroup_features.subgroupSizeControl &&
  664. subgroup_properties.minSubgroupSize <= GuestWarpSize &&
  665. subgroup_properties.maxSubgroupSize >= GuestWarpSize) {
  666. extensions.push_back(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);
  667. guest_warp_stages = subgroup_properties.requiredSubgroupSizeStages;
  668. }
  669. } else {
  670. is_warp_potentially_bigger = true;
  671. }
  672. if (has_ext_transform_feedback) {
  673. VkPhysicalDeviceTransformFeedbackFeaturesEXT tfb_features;
  674. tfb_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT;
  675. tfb_features.pNext = nullptr;
  676. features.pNext = &tfb_features;
  677. physical.GetFeatures2KHR(features);
  678. VkPhysicalDeviceTransformFeedbackPropertiesEXT tfb_properties;
  679. tfb_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT;
  680. tfb_properties.pNext = nullptr;
  681. physical_properties.pNext = &tfb_properties;
  682. physical.GetProperties2KHR(physical_properties);
  683. if (tfb_features.transformFeedback && tfb_features.geometryStreams &&
  684. tfb_properties.maxTransformFeedbackStreams >= 4 &&
  685. tfb_properties.maxTransformFeedbackBuffers && tfb_properties.transformFeedbackQueries &&
  686. tfb_properties.transformFeedbackDraw) {
  687. extensions.push_back(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
  688. ext_transform_feedback = true;
  689. }
  690. }
  691. if (has_ext_custom_border_color) {
  692. VkPhysicalDeviceCustomBorderColorFeaturesEXT border_features;
  693. border_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT;
  694. border_features.pNext = nullptr;
  695. features.pNext = &border_features;
  696. physical.GetFeatures2KHR(features);
  697. if (border_features.customBorderColors && border_features.customBorderColorWithoutFormat) {
  698. extensions.push_back(VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
  699. ext_custom_border_color = true;
  700. }
  701. }
  702. if (has_ext_extended_dynamic_state) {
  703. VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
  704. dynamic_state.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
  705. dynamic_state.pNext = nullptr;
  706. features.pNext = &dynamic_state;
  707. physical.GetFeatures2KHR(features);
  708. if (dynamic_state.extendedDynamicState) {
  709. extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
  710. ext_extended_dynamic_state = true;
  711. }
  712. }
  713. return extensions;
  714. }
  715. void Device::SetupFamilies(VkSurfaceKHR surface) {
  716. const std::vector queue_family_properties = physical.GetQueueFamilyProperties();
  717. std::optional<u32> graphics;
  718. std::optional<u32> present;
  719. for (u32 index = 0; index < static_cast<u32>(queue_family_properties.size()); ++index) {
  720. if (graphics && (present || !surface)) {
  721. break;
  722. }
  723. const VkQueueFamilyProperties& queue_family = queue_family_properties[index];
  724. if (queue_family.queueCount == 0) {
  725. continue;
  726. }
  727. if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
  728. graphics = index;
  729. }
  730. if (surface && physical.GetSurfaceSupportKHR(index, surface)) {
  731. present = index;
  732. }
  733. }
  734. if (!graphics) {
  735. LOG_ERROR(Render_Vulkan, "Device lacks a graphics queue");
  736. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  737. }
  738. if (surface && !present) {
  739. LOG_ERROR(Render_Vulkan, "Device lacks a present queue");
  740. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  741. }
  742. graphics_family = *graphics;
  743. present_family = *present;
  744. }
  745. void Device::SetupFeatures() {
  746. const auto supported_features{physical.GetFeatures()};
  747. is_formatless_image_load_supported = supported_features.shaderStorageImageReadWithoutFormat;
  748. is_shader_storage_image_multisample = supported_features.shaderStorageImageMultisample;
  749. is_blit_depth_stencil_supported = TestDepthStencilBlits();
  750. is_optimal_astc_supported = IsOptimalAstcSupported(supported_features);
  751. }
  752. void Device::CollectTelemetryParameters() {
  753. VkPhysicalDeviceDriverPropertiesKHR driver{
  754. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR,
  755. .pNext = nullptr,
  756. .driverID = {},
  757. .driverName = {},
  758. .driverInfo = {},
  759. .conformanceVersion = {},
  760. };
  761. VkPhysicalDeviceProperties2KHR device_properties{
  762. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
  763. .pNext = &driver,
  764. .properties = {},
  765. };
  766. physical.GetProperties2KHR(device_properties);
  767. driver_id = driver.driverID;
  768. vendor_name = driver.driverName;
  769. const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
  770. reported_extensions.reserve(std::size(extensions));
  771. for (const auto& extension : extensions) {
  772. reported_extensions.emplace_back(extension.extensionName);
  773. }
  774. }
  775. void Device::CollectToolingInfo() {
  776. if (!ext_tooling_info) {
  777. return;
  778. }
  779. const auto vkGetPhysicalDeviceToolPropertiesEXT =
  780. reinterpret_cast<PFN_vkGetPhysicalDeviceToolPropertiesEXT>(
  781. dld.vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceToolPropertiesEXT"));
  782. if (!vkGetPhysicalDeviceToolPropertiesEXT) {
  783. return;
  784. }
  785. u32 tool_count = 0;
  786. if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, nullptr) != VK_SUCCESS) {
  787. return;
  788. }
  789. std::vector<VkPhysicalDeviceToolPropertiesEXT> tools(tool_count);
  790. if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, tools.data()) != VK_SUCCESS) {
  791. return;
  792. }
  793. for (const VkPhysicalDeviceToolPropertiesEXT& tool : tools) {
  794. const std::string_view name = tool.name;
  795. LOG_INFO(Render_Vulkan, "{}", name);
  796. has_renderdoc = has_renderdoc || name == "RenderDoc";
  797. has_nsight_graphics = has_nsight_graphics || name == "NVIDIA Nsight Graphics";
  798. }
  799. }
  800. std::vector<VkDeviceQueueCreateInfo> Device::GetDeviceQueueCreateInfos() const {
  801. static constexpr float QUEUE_PRIORITY = 1.0f;
  802. std::unordered_set<u32> unique_queue_families{graphics_family, present_family};
  803. std::vector<VkDeviceQueueCreateInfo> queue_cis;
  804. queue_cis.reserve(unique_queue_families.size());
  805. for (const u32 queue_family : unique_queue_families) {
  806. auto& ci = queue_cis.emplace_back(VkDeviceQueueCreateInfo{
  807. .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
  808. .pNext = nullptr,
  809. .flags = 0,
  810. .queueFamilyIndex = queue_family,
  811. .queueCount = 1,
  812. .pQueuePriorities = nullptr,
  813. });
  814. ci.pQueuePriorities = &QUEUE_PRIORITY;
  815. }
  816. return queue_cis;
  817. }
  818. } // namespace Vulkan