vulkan_device.cpp 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <algorithm>
  5. #include <bitset>
  6. #include <chrono>
  7. #include <optional>
  8. #include <string_view>
  9. #include <thread>
  10. #include <unordered_set>
  11. #include <utility>
  12. #include <vector>
  13. #include "common/assert.h"
  14. #include "common/settings.h"
  15. #include "video_core/vulkan_common/nsight_aftermath_tracker.h"
  16. #include "video_core/vulkan_common/vulkan_device.h"
  17. #include "video_core/vulkan_common/vulkan_wrapper.h"
  18. namespace Vulkan {
  19. namespace {
  20. namespace Alternatives {
  21. constexpr std::array STENCIL8_UINT{
  22. VK_FORMAT_D16_UNORM_S8_UINT,
  23. VK_FORMAT_D24_UNORM_S8_UINT,
  24. VK_FORMAT_D32_SFLOAT_S8_UINT,
  25. VK_FORMAT_UNDEFINED,
  26. };
  27. constexpr std::array DEPTH24_UNORM_STENCIL8_UINT{
  28. VK_FORMAT_D32_SFLOAT_S8_UINT,
  29. VK_FORMAT_D16_UNORM_S8_UINT,
  30. VK_FORMAT_UNDEFINED,
  31. };
  32. constexpr std::array DEPTH16_UNORM_STENCIL8_UINT{
  33. VK_FORMAT_D24_UNORM_S8_UINT,
  34. VK_FORMAT_D32_SFLOAT_S8_UINT,
  35. VK_FORMAT_UNDEFINED,
  36. };
  37. } // namespace Alternatives
  38. enum class NvidiaArchitecture {
  39. AmpereOrNewer,
  40. Turing,
  41. VoltaOrOlder,
  42. };
  43. constexpr std::array REQUIRED_EXTENSIONS{
  44. VK_KHR_MAINTENANCE1_EXTENSION_NAME,
  45. VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME,
  46. VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME,
  47. VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
  48. VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
  49. VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME,
  50. VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME,
  51. VK_KHR_TIMELINE_SEMAPHORE_EXTENSION_NAME,
  52. VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME,
  53. VK_KHR_SHADER_FLOAT_CONTROLS_EXTENSION_NAME,
  54. VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME,
  55. VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME,
  56. VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME,
  57. VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME,
  58. VK_EXT_ROBUSTNESS_2_EXTENSION_NAME,
  59. VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME,
  60. VK_EXT_SHADER_DEMOTE_TO_HELPER_INVOCATION_EXTENSION_NAME,
  61. #ifdef _WIN32
  62. VK_KHR_EXTERNAL_MEMORY_WIN32_EXTENSION_NAME,
  63. #endif
  64. #ifdef __unix__
  65. VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME,
  66. #endif
  67. };
  68. template <typename T>
  69. void SetNext(void**& next, T& data) {
  70. *next = &data;
  71. next = &data.pNext;
  72. }
  73. constexpr const VkFormat* GetFormatAlternatives(VkFormat format) {
  74. switch (format) {
  75. case VK_FORMAT_S8_UINT:
  76. return Alternatives::STENCIL8_UINT.data();
  77. case VK_FORMAT_D24_UNORM_S8_UINT:
  78. return Alternatives::DEPTH24_UNORM_STENCIL8_UINT.data();
  79. case VK_FORMAT_D16_UNORM_S8_UINT:
  80. return Alternatives::DEPTH16_UNORM_STENCIL8_UINT.data();
  81. default:
  82. return nullptr;
  83. }
  84. }
  85. VkFormatFeatureFlags GetFormatFeatures(VkFormatProperties properties, FormatType format_type) {
  86. switch (format_type) {
  87. case FormatType::Linear:
  88. return properties.linearTilingFeatures;
  89. case FormatType::Optimal:
  90. return properties.optimalTilingFeatures;
  91. case FormatType::Buffer:
  92. return properties.bufferFeatures;
  93. default:
  94. return {};
  95. }
  96. }
  97. std::unordered_map<VkFormat, VkFormatProperties> GetFormatProperties(vk::PhysicalDevice physical) {
  98. static constexpr std::array formats{
  99. VK_FORMAT_A8B8G8R8_UNORM_PACK32,
  100. VK_FORMAT_A8B8G8R8_UINT_PACK32,
  101. VK_FORMAT_A8B8G8R8_SNORM_PACK32,
  102. VK_FORMAT_A8B8G8R8_SINT_PACK32,
  103. VK_FORMAT_A8B8G8R8_SRGB_PACK32,
  104. VK_FORMAT_R5G6B5_UNORM_PACK16,
  105. VK_FORMAT_B5G6R5_UNORM_PACK16,
  106. VK_FORMAT_A2B10G10R10_UNORM_PACK32,
  107. VK_FORMAT_A2B10G10R10_UINT_PACK32,
  108. VK_FORMAT_A1R5G5B5_UNORM_PACK16,
  109. VK_FORMAT_R32G32B32A32_SFLOAT,
  110. VK_FORMAT_R32G32B32A32_SINT,
  111. VK_FORMAT_R32G32B32A32_UINT,
  112. VK_FORMAT_R32G32_SFLOAT,
  113. VK_FORMAT_R32G32_SINT,
  114. VK_FORMAT_R32G32_UINT,
  115. VK_FORMAT_R16G16B16A16_SINT,
  116. VK_FORMAT_R16G16B16A16_UINT,
  117. VK_FORMAT_R16G16B16A16_SNORM,
  118. VK_FORMAT_R16G16B16A16_UNORM,
  119. VK_FORMAT_R16G16_UNORM,
  120. VK_FORMAT_R16G16_SNORM,
  121. VK_FORMAT_R16G16_SFLOAT,
  122. VK_FORMAT_R16G16_UINT,
  123. VK_FORMAT_R16G16_SINT,
  124. VK_FORMAT_R16_UNORM,
  125. VK_FORMAT_R16_SNORM,
  126. VK_FORMAT_R16_UINT,
  127. VK_FORMAT_R8G8B8A8_SRGB,
  128. VK_FORMAT_R8G8_UNORM,
  129. VK_FORMAT_R8G8_SNORM,
  130. VK_FORMAT_R8G8_SINT,
  131. VK_FORMAT_R8G8_UINT,
  132. VK_FORMAT_R8_UNORM,
  133. VK_FORMAT_R8_SNORM,
  134. VK_FORMAT_R8_SINT,
  135. VK_FORMAT_R8_UINT,
  136. VK_FORMAT_B10G11R11_UFLOAT_PACK32,
  137. VK_FORMAT_R32_SFLOAT,
  138. VK_FORMAT_R32_UINT,
  139. VK_FORMAT_R32_SINT,
  140. VK_FORMAT_R16_SFLOAT,
  141. VK_FORMAT_R16G16B16A16_SFLOAT,
  142. VK_FORMAT_B8G8R8A8_UNORM,
  143. VK_FORMAT_B8G8R8A8_SRGB,
  144. VK_FORMAT_R4G4B4A4_UNORM_PACK16,
  145. VK_FORMAT_D32_SFLOAT,
  146. VK_FORMAT_D16_UNORM,
  147. VK_FORMAT_S8_UINT,
  148. VK_FORMAT_D16_UNORM_S8_UINT,
  149. VK_FORMAT_D24_UNORM_S8_UINT,
  150. VK_FORMAT_D32_SFLOAT_S8_UINT,
  151. VK_FORMAT_BC1_RGBA_UNORM_BLOCK,
  152. VK_FORMAT_BC2_UNORM_BLOCK,
  153. VK_FORMAT_BC3_UNORM_BLOCK,
  154. VK_FORMAT_BC4_UNORM_BLOCK,
  155. VK_FORMAT_BC4_SNORM_BLOCK,
  156. VK_FORMAT_BC5_UNORM_BLOCK,
  157. VK_FORMAT_BC5_SNORM_BLOCK,
  158. VK_FORMAT_BC7_UNORM_BLOCK,
  159. VK_FORMAT_BC6H_UFLOAT_BLOCK,
  160. VK_FORMAT_BC6H_SFLOAT_BLOCK,
  161. VK_FORMAT_BC1_RGBA_SRGB_BLOCK,
  162. VK_FORMAT_BC2_SRGB_BLOCK,
  163. VK_FORMAT_BC3_SRGB_BLOCK,
  164. VK_FORMAT_BC7_SRGB_BLOCK,
  165. VK_FORMAT_ASTC_4x4_UNORM_BLOCK,
  166. VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
  167. VK_FORMAT_ASTC_5x4_UNORM_BLOCK,
  168. VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
  169. VK_FORMAT_ASTC_5x5_UNORM_BLOCK,
  170. VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
  171. VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
  172. VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
  173. VK_FORMAT_ASTC_6x6_UNORM_BLOCK,
  174. VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
  175. VK_FORMAT_ASTC_8x5_UNORM_BLOCK,
  176. VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
  177. VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
  178. VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
  179. VK_FORMAT_ASTC_8x8_UNORM_BLOCK,
  180. VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
  181. VK_FORMAT_ASTC_10x5_UNORM_BLOCK,
  182. VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
  183. VK_FORMAT_ASTC_10x6_UNORM_BLOCK,
  184. VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
  185. VK_FORMAT_ASTC_10x8_UNORM_BLOCK,
  186. VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
  187. VK_FORMAT_ASTC_10x10_UNORM_BLOCK,
  188. VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
  189. VK_FORMAT_ASTC_12x10_UNORM_BLOCK,
  190. VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
  191. VK_FORMAT_ASTC_12x12_UNORM_BLOCK,
  192. VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
  193. VK_FORMAT_ASTC_8x6_UNORM_BLOCK,
  194. VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
  195. VK_FORMAT_ASTC_6x5_UNORM_BLOCK,
  196. VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
  197. VK_FORMAT_E5B9G9R9_UFLOAT_PACK32,
  198. };
  199. std::unordered_map<VkFormat, VkFormatProperties> format_properties;
  200. for (const auto format : formats) {
  201. format_properties.emplace(format, physical.GetFormatProperties(format));
  202. }
  203. return format_properties;
  204. }
  205. std::vector<std::string> GetSupportedExtensions(vk::PhysicalDevice physical) {
  206. const std::vector extensions = physical.EnumerateDeviceExtensionProperties();
  207. std::vector<std::string> supported_extensions;
  208. supported_extensions.reserve(extensions.size());
  209. for (const auto& extension : extensions) {
  210. supported_extensions.emplace_back(extension.extensionName);
  211. }
  212. return supported_extensions;
  213. }
  214. NvidiaArchitecture GetNvidiaArchitecture(vk::PhysicalDevice physical,
  215. std::span<const std::string> exts) {
  216. if (std::ranges::find(exts, VK_KHR_FRAGMENT_SHADING_RATE_EXTENSION_NAME) != exts.end()) {
  217. VkPhysicalDeviceFragmentShadingRatePropertiesKHR shading_rate_props{};
  218. shading_rate_props.sType =
  219. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_SHADING_RATE_PROPERTIES_KHR;
  220. VkPhysicalDeviceProperties2KHR physical_properties{};
  221. physical_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
  222. physical_properties.pNext = &shading_rate_props;
  223. physical.GetProperties2KHR(physical_properties);
  224. if (shading_rate_props.primitiveFragmentShadingRateWithMultipleViewports) {
  225. // Only Ampere and newer support this feature
  226. return NvidiaArchitecture::AmpereOrNewer;
  227. }
  228. }
  229. if (std::ranges::find(exts, VK_NV_SHADING_RATE_IMAGE_EXTENSION_NAME) != exts.end()) {
  230. return NvidiaArchitecture::Turing;
  231. }
  232. return NvidiaArchitecture::VoltaOrOlder;
  233. }
  234. } // Anonymous namespace
  235. Device::Device(VkInstance instance_, vk::PhysicalDevice physical_, VkSurfaceKHR surface,
  236. const vk::InstanceDispatch& dld_)
  237. : instance{instance_}, dld{dld_}, physical{physical_}, properties{physical.GetProperties()},
  238. supported_extensions{GetSupportedExtensions(physical)},
  239. format_properties(GetFormatProperties(physical)) {
  240. CheckSuitability(surface != nullptr);
  241. SetupFamilies(surface);
  242. SetupFeatures();
  243. SetupProperties();
  244. const auto queue_cis = GetDeviceQueueCreateInfos();
  245. const std::vector extensions = LoadExtensions(surface != nullptr);
  246. VkPhysicalDeviceFeatures2 features2{
  247. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2,
  248. .pNext = nullptr,
  249. .features{
  250. .robustBufferAccess = true,
  251. .fullDrawIndexUint32 = false,
  252. .imageCubeArray = true,
  253. .independentBlend = true,
  254. .geometryShader = true,
  255. .tessellationShader = true,
  256. .sampleRateShading = true,
  257. .dualSrcBlend = true,
  258. .logicOp = true,
  259. .multiDrawIndirect = false,
  260. .drawIndirectFirstInstance = false,
  261. .depthClamp = true,
  262. .depthBiasClamp = true,
  263. .fillModeNonSolid = true,
  264. .depthBounds = is_depth_bounds_supported,
  265. .wideLines = true,
  266. .largePoints = true,
  267. .alphaToOne = false,
  268. .multiViewport = true,
  269. .samplerAnisotropy = true,
  270. .textureCompressionETC2 = false,
  271. .textureCompressionASTC_LDR = is_optimal_astc_supported,
  272. .textureCompressionBC = false,
  273. .occlusionQueryPrecise = true,
  274. .pipelineStatisticsQuery = false,
  275. .vertexPipelineStoresAndAtomics = true,
  276. .fragmentStoresAndAtomics = true,
  277. .shaderTessellationAndGeometryPointSize = false,
  278. .shaderImageGatherExtended = true,
  279. .shaderStorageImageExtendedFormats = false,
  280. .shaderStorageImageMultisample = is_shader_storage_image_multisample,
  281. .shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported,
  282. .shaderStorageImageWriteWithoutFormat = true,
  283. .shaderUniformBufferArrayDynamicIndexing = false,
  284. .shaderSampledImageArrayDynamicIndexing = false,
  285. .shaderStorageBufferArrayDynamicIndexing = false,
  286. .shaderStorageImageArrayDynamicIndexing = false,
  287. .shaderClipDistance = true,
  288. .shaderCullDistance = true,
  289. .shaderFloat64 = is_shader_float64_supported,
  290. .shaderInt64 = is_shader_int64_supported,
  291. .shaderInt16 = is_shader_int16_supported,
  292. .shaderResourceResidency = false,
  293. .shaderResourceMinLod = false,
  294. .sparseBinding = false,
  295. .sparseResidencyBuffer = false,
  296. .sparseResidencyImage2D = false,
  297. .sparseResidencyImage3D = false,
  298. .sparseResidency2Samples = false,
  299. .sparseResidency4Samples = false,
  300. .sparseResidency8Samples = false,
  301. .sparseResidency16Samples = false,
  302. .sparseResidencyAliased = false,
  303. .variableMultisampleRate = false,
  304. .inheritedQueries = false,
  305. },
  306. };
  307. const void* first_next = &features2;
  308. void** next = &features2.pNext;
  309. VkPhysicalDeviceTimelineSemaphoreFeaturesKHR timeline_semaphore{
  310. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TIMELINE_SEMAPHORE_FEATURES_KHR,
  311. .pNext = nullptr,
  312. .timelineSemaphore = true,
  313. };
  314. SetNext(next, timeline_semaphore);
  315. VkPhysicalDevice16BitStorageFeaturesKHR bit16_storage{
  316. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR,
  317. .pNext = nullptr,
  318. .storageBuffer16BitAccess = true,
  319. .uniformAndStorageBuffer16BitAccess = true,
  320. .storagePushConstant16 = false,
  321. .storageInputOutput16 = false,
  322. };
  323. SetNext(next, bit16_storage);
  324. VkPhysicalDevice8BitStorageFeaturesKHR bit8_storage{
  325. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR,
  326. .pNext = nullptr,
  327. .storageBuffer8BitAccess = false,
  328. .uniformAndStorageBuffer8BitAccess = true,
  329. .storagePushConstant8 = false,
  330. };
  331. SetNext(next, bit8_storage);
  332. VkPhysicalDeviceRobustness2FeaturesEXT robustness2{
  333. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT,
  334. .pNext = nullptr,
  335. .robustBufferAccess2 = true,
  336. .robustImageAccess2 = true,
  337. .nullDescriptor = true,
  338. };
  339. SetNext(next, robustness2);
  340. VkPhysicalDeviceHostQueryResetFeaturesEXT host_query_reset{
  341. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT,
  342. .pNext = nullptr,
  343. .hostQueryReset = true,
  344. };
  345. SetNext(next, host_query_reset);
  346. VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointers{
  347. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES_KHR,
  348. .pNext = nullptr,
  349. .variablePointersStorageBuffer = VK_TRUE,
  350. .variablePointers = VK_TRUE,
  351. };
  352. SetNext(next, variable_pointers);
  353. VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT demote{
  354. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT,
  355. .pNext = nullptr,
  356. .shaderDemoteToHelperInvocation = true,
  357. };
  358. SetNext(next, demote);
  359. VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
  360. if (is_int8_supported || is_float16_supported) {
  361. float16_int8 = {
  362. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
  363. .pNext = nullptr,
  364. .shaderFloat16 = is_float16_supported,
  365. .shaderInt8 = is_int8_supported,
  366. };
  367. SetNext(next, float16_int8);
  368. }
  369. if (!is_float16_supported) {
  370. LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
  371. }
  372. if (!is_int8_supported) {
  373. LOG_INFO(Render_Vulkan, "Device doesn't support int8 natively");
  374. }
  375. if (!nv_viewport_swizzle) {
  376. LOG_INFO(Render_Vulkan, "Device doesn't support viewport swizzles");
  377. }
  378. if (!nv_viewport_array2) {
  379. LOG_INFO(Render_Vulkan, "Device doesn't support viewport masks");
  380. }
  381. if (!nv_geometry_shader_passthrough) {
  382. LOG_INFO(Render_Vulkan, "Device doesn't support passthrough geometry shaders");
  383. }
  384. VkPhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
  385. if (khr_uniform_buffer_standard_layout) {
  386. std430_layout = {
  387. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_UNIFORM_BUFFER_STANDARD_LAYOUT_FEATURES_KHR,
  388. .pNext = nullptr,
  389. .uniformBufferStandardLayout = true,
  390. };
  391. SetNext(next, std430_layout);
  392. } else {
  393. LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs");
  394. }
  395. VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
  396. if (ext_index_type_uint8) {
  397. index_type_uint8 = {
  398. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT,
  399. .pNext = nullptr,
  400. .indexTypeUint8 = true,
  401. };
  402. SetNext(next, index_type_uint8);
  403. } else {
  404. LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes");
  405. }
  406. VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT primitive_topology_list_restart;
  407. if (is_topology_list_restart_supported || is_patch_list_restart_supported) {
  408. primitive_topology_list_restart = {
  409. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT,
  410. .pNext = nullptr,
  411. .primitiveTopologyListRestart = is_topology_list_restart_supported,
  412. .primitiveTopologyPatchListRestart = is_patch_list_restart_supported,
  413. };
  414. SetNext(next, primitive_topology_list_restart);
  415. } else {
  416. LOG_INFO(Render_Vulkan, "Device doesn't support list topology primitive restart");
  417. }
  418. VkPhysicalDeviceTransformFeedbackFeaturesEXT transform_feedback;
  419. if (ext_transform_feedback) {
  420. transform_feedback = {
  421. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT,
  422. .pNext = nullptr,
  423. .transformFeedback = true,
  424. .geometryStreams = true,
  425. };
  426. SetNext(next, transform_feedback);
  427. } else {
  428. LOG_INFO(Render_Vulkan, "Device doesn't support transform feedbacks");
  429. }
  430. VkPhysicalDeviceCustomBorderColorFeaturesEXT custom_border;
  431. if (ext_custom_border_color) {
  432. custom_border = {
  433. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT,
  434. .pNext = nullptr,
  435. .customBorderColors = VK_TRUE,
  436. .customBorderColorWithoutFormat = VK_TRUE,
  437. };
  438. SetNext(next, custom_border);
  439. } else {
  440. LOG_INFO(Render_Vulkan, "Device doesn't support custom border colors");
  441. }
  442. VkPhysicalDeviceExtendedDynamicStateFeaturesEXT dynamic_state;
  443. if (ext_extended_dynamic_state) {
  444. dynamic_state = {
  445. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT,
  446. .pNext = nullptr,
  447. .extendedDynamicState = VK_TRUE,
  448. };
  449. SetNext(next, dynamic_state);
  450. } else {
  451. LOG_INFO(Render_Vulkan, "Device doesn't support extended dynamic state");
  452. }
  453. VkPhysicalDeviceLineRasterizationFeaturesEXT line_raster;
  454. if (ext_line_rasterization) {
  455. line_raster = {
  456. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT,
  457. .pNext = nullptr,
  458. .rectangularLines = VK_TRUE,
  459. .bresenhamLines = VK_FALSE,
  460. .smoothLines = VK_TRUE,
  461. .stippledRectangularLines = VK_FALSE,
  462. .stippledBresenhamLines = VK_FALSE,
  463. .stippledSmoothLines = VK_FALSE,
  464. };
  465. SetNext(next, line_raster);
  466. } else {
  467. LOG_INFO(Render_Vulkan, "Device doesn't support smooth lines");
  468. }
  469. if (!ext_conservative_rasterization) {
  470. LOG_INFO(Render_Vulkan, "Device doesn't support conservative rasterization");
  471. }
  472. VkPhysicalDeviceProvokingVertexFeaturesEXT provoking_vertex;
  473. if (ext_provoking_vertex) {
  474. provoking_vertex = {
  475. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT,
  476. .pNext = nullptr,
  477. .provokingVertexLast = VK_TRUE,
  478. .transformFeedbackPreservesProvokingVertex = VK_TRUE,
  479. };
  480. SetNext(next, provoking_vertex);
  481. } else {
  482. LOG_INFO(Render_Vulkan, "Device doesn't support provoking vertex last");
  483. }
  484. VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT vertex_input_dynamic;
  485. if (ext_vertex_input_dynamic_state) {
  486. vertex_input_dynamic = {
  487. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT,
  488. .pNext = nullptr,
  489. .vertexInputDynamicState = VK_TRUE,
  490. };
  491. SetNext(next, vertex_input_dynamic);
  492. } else {
  493. LOG_INFO(Render_Vulkan, "Device doesn't support vertex input dynamic state");
  494. }
  495. VkPhysicalDeviceShaderAtomicInt64FeaturesKHR atomic_int64;
  496. if (ext_shader_atomic_int64) {
  497. atomic_int64 = {
  498. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR,
  499. .pNext = nullptr,
  500. .shaderBufferInt64Atomics = VK_TRUE,
  501. .shaderSharedInt64Atomics = VK_TRUE,
  502. };
  503. SetNext(next, atomic_int64);
  504. }
  505. VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR workgroup_layout;
  506. if (khr_workgroup_memory_explicit_layout) {
  507. workgroup_layout = {
  508. .sType =
  509. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR,
  510. .pNext = nullptr,
  511. .workgroupMemoryExplicitLayout = VK_TRUE,
  512. .workgroupMemoryExplicitLayoutScalarBlockLayout = VK_TRUE,
  513. .workgroupMemoryExplicitLayout8BitAccess = VK_TRUE,
  514. .workgroupMemoryExplicitLayout16BitAccess = VK_TRUE,
  515. };
  516. SetNext(next, workgroup_layout);
  517. }
  518. VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR executable_properties;
  519. if (khr_pipeline_executable_properties) {
  520. LOG_INFO(Render_Vulkan, "Enabling shader feedback, expect slower shader build times");
  521. executable_properties = {
  522. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR,
  523. .pNext = nullptr,
  524. .pipelineExecutableInfo = VK_TRUE,
  525. };
  526. SetNext(next, executable_properties);
  527. }
  528. if (!ext_depth_range_unrestricted) {
  529. LOG_INFO(Render_Vulkan, "Device doesn't support depth range unrestricted");
  530. }
  531. VkDeviceDiagnosticsConfigCreateInfoNV diagnostics_nv;
  532. if (Settings::values.enable_nsight_aftermath && nv_device_diagnostics_config) {
  533. nsight_aftermath_tracker = std::make_unique<NsightAftermathTracker>();
  534. diagnostics_nv = {
  535. .sType = VK_STRUCTURE_TYPE_DEVICE_DIAGNOSTICS_CONFIG_CREATE_INFO_NV,
  536. .pNext = &features2,
  537. .flags = VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_SHADER_DEBUG_INFO_BIT_NV |
  538. VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_RESOURCE_TRACKING_BIT_NV |
  539. VK_DEVICE_DIAGNOSTICS_CONFIG_ENABLE_AUTOMATIC_CHECKPOINTS_BIT_NV,
  540. };
  541. first_next = &diagnostics_nv;
  542. }
  543. logical = vk::Device::Create(physical, queue_cis, extensions, first_next, dld);
  544. CollectPhysicalMemoryInfo();
  545. CollectTelemetryParameters();
  546. CollectToolingInfo();
  547. if (driver_id == VK_DRIVER_ID_NVIDIA_PROPRIETARY_KHR) {
  548. const auto arch = GetNvidiaArchitecture(physical, supported_extensions);
  549. switch (arch) {
  550. case NvidiaArchitecture::AmpereOrNewer:
  551. LOG_WARNING(Render_Vulkan, "Blacklisting Ampere devices from float16 math");
  552. is_float16_supported = false;
  553. break;
  554. case NvidiaArchitecture::Turing:
  555. break;
  556. case NvidiaArchitecture::VoltaOrOlder:
  557. LOG_WARNING(Render_Vulkan, "Blacklisting Volta and older from VK_KHR_push_descriptor");
  558. khr_push_descriptor = false;
  559. break;
  560. }
  561. }
  562. if (ext_extended_dynamic_state && driver_id == VK_DRIVER_ID_MESA_RADV) {
  563. // Mask driver version variant
  564. const u32 version = (properties.driverVersion << 3) >> 3;
  565. if (version < VK_MAKE_API_VERSION(0, 21, 2, 0)) {
  566. LOG_WARNING(Render_Vulkan,
  567. "RADV versions older than 21.2 have broken VK_EXT_extended_dynamic_state");
  568. ext_extended_dynamic_state = false;
  569. }
  570. }
  571. sets_per_pool = 64;
  572. const bool is_amd =
  573. driver_id == VK_DRIVER_ID_AMD_PROPRIETARY || driver_id == VK_DRIVER_ID_AMD_OPEN_SOURCE;
  574. if (is_amd) {
  575. // AMD drivers need a higher amount of Sets per Pool in certain circunstances like in XC2.
  576. sets_per_pool = 96;
  577. // Disable VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT on AMD GCN4 and lower as it is broken.
  578. if (!is_float16_supported) {
  579. LOG_WARNING(
  580. Render_Vulkan,
  581. "AMD GCN4 and earlier do not properly support VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT");
  582. has_broken_cube_compatibility = true;
  583. }
  584. }
  585. const bool is_amd_or_radv = is_amd || driver_id == VK_DRIVER_ID_MESA_RADV;
  586. if (ext_sampler_filter_minmax && is_amd_or_radv) {
  587. // Disable ext_sampler_filter_minmax on AMD GCN4 and lower as it is broken.
  588. if (!is_float16_supported) {
  589. LOG_WARNING(Render_Vulkan,
  590. "Blacklisting AMD GCN4 and earlier for VK_EXT_sampler_filter_minmax");
  591. ext_sampler_filter_minmax = false;
  592. }
  593. }
  594. if (ext_vertex_input_dynamic_state && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) {
  595. LOG_WARNING(Render_Vulkan, "Blacklisting Intel for VK_EXT_vertex_input_dynamic_state");
  596. ext_vertex_input_dynamic_state = false;
  597. }
  598. if (is_float16_supported && driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS) {
  599. // Intel's compiler crashes when using fp16 on Astral Chain, disable it for the time being.
  600. LOG_WARNING(Render_Vulkan, "Blacklisting Intel proprietary from float16 math");
  601. is_float16_supported = false;
  602. }
  603. supports_d24_depth =
  604. IsFormatSupported(VK_FORMAT_D24_UNORM_S8_UINT,
  605. VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT, FormatType::Optimal);
  606. graphics_queue = logical.GetQueue(graphics_family);
  607. present_queue = logical.GetQueue(present_family);
  608. }
  609. Device::~Device() = default;
  610. VkFormat Device::GetSupportedFormat(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
  611. FormatType format_type) const {
  612. if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
  613. return wanted_format;
  614. }
  615. // The wanted format is not supported by hardware, search for alternatives
  616. const VkFormat* alternatives = GetFormatAlternatives(wanted_format);
  617. if (alternatives == nullptr) {
  618. UNREACHABLE_MSG("Format={} with usage={} and type={} has no defined alternatives and host "
  619. "hardware does not support it",
  620. wanted_format, wanted_usage, format_type);
  621. return wanted_format;
  622. }
  623. std::size_t i = 0;
  624. for (VkFormat alternative = *alternatives; alternative; alternative = alternatives[++i]) {
  625. if (!IsFormatSupported(alternative, wanted_usage, format_type)) {
  626. continue;
  627. }
  628. LOG_WARNING(Render_Vulkan,
  629. "Emulating format={} with alternative format={} with usage={} and type={}",
  630. wanted_format, alternative, wanted_usage, format_type);
  631. return alternative;
  632. }
  633. // No alternatives found, panic
  634. UNREACHABLE_MSG("Format={} with usage={} and type={} is not supported by the host hardware and "
  635. "doesn't support any of the alternatives",
  636. wanted_format, wanted_usage, format_type);
  637. return wanted_format;
  638. }
  639. void Device::ReportLoss() const {
  640. LOG_CRITICAL(Render_Vulkan, "Device loss occured!");
  641. // Wait for the log to flush and for Nsight Aftermath to dump the results
  642. std::this_thread::sleep_for(std::chrono::seconds{15});
  643. }
  644. void Device::SaveShader(std::span<const u32> spirv) const {
  645. if (nsight_aftermath_tracker) {
  646. nsight_aftermath_tracker->SaveShader(spirv);
  647. }
  648. }
  649. bool Device::IsOptimalAstcSupported(const VkPhysicalDeviceFeatures& features) const {
  650. // Disable for now to avoid converting ASTC twice.
  651. static constexpr std::array astc_formats = {
  652. VK_FORMAT_ASTC_4x4_UNORM_BLOCK, VK_FORMAT_ASTC_4x4_SRGB_BLOCK,
  653. VK_FORMAT_ASTC_5x4_UNORM_BLOCK, VK_FORMAT_ASTC_5x4_SRGB_BLOCK,
  654. VK_FORMAT_ASTC_5x5_UNORM_BLOCK, VK_FORMAT_ASTC_5x5_SRGB_BLOCK,
  655. VK_FORMAT_ASTC_6x5_UNORM_BLOCK, VK_FORMAT_ASTC_6x5_SRGB_BLOCK,
  656. VK_FORMAT_ASTC_6x6_UNORM_BLOCK, VK_FORMAT_ASTC_6x6_SRGB_BLOCK,
  657. VK_FORMAT_ASTC_8x5_UNORM_BLOCK, VK_FORMAT_ASTC_8x5_SRGB_BLOCK,
  658. VK_FORMAT_ASTC_8x6_UNORM_BLOCK, VK_FORMAT_ASTC_8x6_SRGB_BLOCK,
  659. VK_FORMAT_ASTC_8x8_UNORM_BLOCK, VK_FORMAT_ASTC_8x8_SRGB_BLOCK,
  660. VK_FORMAT_ASTC_10x5_UNORM_BLOCK, VK_FORMAT_ASTC_10x5_SRGB_BLOCK,
  661. VK_FORMAT_ASTC_10x6_UNORM_BLOCK, VK_FORMAT_ASTC_10x6_SRGB_BLOCK,
  662. VK_FORMAT_ASTC_10x8_UNORM_BLOCK, VK_FORMAT_ASTC_10x8_SRGB_BLOCK,
  663. VK_FORMAT_ASTC_10x10_UNORM_BLOCK, VK_FORMAT_ASTC_10x10_SRGB_BLOCK,
  664. VK_FORMAT_ASTC_12x10_UNORM_BLOCK, VK_FORMAT_ASTC_12x10_SRGB_BLOCK,
  665. VK_FORMAT_ASTC_12x12_UNORM_BLOCK, VK_FORMAT_ASTC_12x12_SRGB_BLOCK,
  666. };
  667. if (!features.textureCompressionASTC_LDR) {
  668. return false;
  669. }
  670. const auto format_feature_usage{
  671. VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT | VK_FORMAT_FEATURE_BLIT_SRC_BIT |
  672. VK_FORMAT_FEATURE_BLIT_DST_BIT | VK_FORMAT_FEATURE_TRANSFER_SRC_BIT |
  673. VK_FORMAT_FEATURE_TRANSFER_DST_BIT};
  674. for (const auto format : astc_formats) {
  675. const auto physical_format_properties{physical.GetFormatProperties(format)};
  676. if ((physical_format_properties.optimalTilingFeatures & format_feature_usage) == 0) {
  677. return false;
  678. }
  679. }
  680. return true;
  681. }
  682. bool Device::TestDepthStencilBlits() const {
  683. static constexpr VkFormatFeatureFlags required_features =
  684. VK_FORMAT_FEATURE_BLIT_SRC_BIT | VK_FORMAT_FEATURE_BLIT_DST_BIT;
  685. const auto test_features = [](VkFormatProperties props) {
  686. return (props.optimalTilingFeatures & required_features) == required_features;
  687. };
  688. return test_features(format_properties.at(VK_FORMAT_D32_SFLOAT_S8_UINT)) &&
  689. test_features(format_properties.at(VK_FORMAT_D24_UNORM_S8_UINT));
  690. }
  691. bool Device::IsFormatSupported(VkFormat wanted_format, VkFormatFeatureFlags wanted_usage,
  692. FormatType format_type) const {
  693. const auto it = format_properties.find(wanted_format);
  694. if (it == format_properties.end()) {
  695. UNIMPLEMENTED_MSG("Unimplemented format query={}", wanted_format);
  696. return true;
  697. }
  698. const auto supported_usage = GetFormatFeatures(it->second, format_type);
  699. return (supported_usage & wanted_usage) == wanted_usage;
  700. }
  701. std::string Device::GetDriverName() const {
  702. switch (driver_id) {
  703. case VK_DRIVER_ID_AMD_PROPRIETARY:
  704. return "AMD";
  705. case VK_DRIVER_ID_AMD_OPEN_SOURCE:
  706. return "AMDVLK";
  707. case VK_DRIVER_ID_MESA_RADV:
  708. return "RADV";
  709. case VK_DRIVER_ID_NVIDIA_PROPRIETARY:
  710. return "NVIDIA";
  711. case VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS:
  712. return "INTEL";
  713. case VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA:
  714. return "ANV";
  715. case VK_DRIVER_ID_MESA_LLVMPIPE:
  716. return "LAVAPIPE";
  717. default:
  718. return vendor_name;
  719. }
  720. }
  721. void Device::CheckSuitability(bool requires_swapchain) const {
  722. std::bitset<REQUIRED_EXTENSIONS.size()> available_extensions;
  723. bool has_swapchain = false;
  724. for (const VkExtensionProperties& property : physical.EnumerateDeviceExtensionProperties()) {
  725. const std::string_view name{property.extensionName};
  726. for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
  727. if (available_extensions[i]) {
  728. continue;
  729. }
  730. available_extensions[i] = name == REQUIRED_EXTENSIONS[i];
  731. }
  732. has_swapchain = has_swapchain || name == VK_KHR_SWAPCHAIN_EXTENSION_NAME;
  733. }
  734. for (size_t i = 0; i < REQUIRED_EXTENSIONS.size(); ++i) {
  735. if (available_extensions[i]) {
  736. continue;
  737. }
  738. LOG_ERROR(Render_Vulkan, "Missing required extension: {}", REQUIRED_EXTENSIONS[i]);
  739. throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
  740. }
  741. if (requires_swapchain && !has_swapchain) {
  742. LOG_ERROR(Render_Vulkan, "Missing required extension: VK_KHR_swapchain");
  743. throw vk::Exception(VK_ERROR_EXTENSION_NOT_PRESENT);
  744. }
  745. struct LimitTuple {
  746. u32 minimum;
  747. u32 value;
  748. const char* name;
  749. };
  750. const VkPhysicalDeviceLimits& limits{properties.limits};
  751. const std::array limits_report{
  752. LimitTuple{65536, limits.maxUniformBufferRange, "maxUniformBufferRange"},
  753. LimitTuple{16, limits.maxViewports, "maxViewports"},
  754. LimitTuple{8, limits.maxColorAttachments, "maxColorAttachments"},
  755. LimitTuple{8, limits.maxClipDistances, "maxClipDistances"},
  756. };
  757. for (const auto& tuple : limits_report) {
  758. if (tuple.value < tuple.minimum) {
  759. LOG_ERROR(Render_Vulkan, "{} has to be {} or greater but it is {}", tuple.name,
  760. tuple.minimum, tuple.value);
  761. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  762. }
  763. }
  764. VkPhysicalDeviceShaderDemoteToHelperInvocationFeaturesEXT demote{};
  765. demote.sType =
  766. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_DEMOTE_TO_HELPER_INVOCATION_FEATURES_EXT;
  767. demote.pNext = nullptr;
  768. VkPhysicalDeviceVariablePointerFeaturesKHR variable_pointers{};
  769. variable_pointers.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTERS_FEATURES_KHR;
  770. variable_pointers.pNext = &demote;
  771. VkPhysicalDeviceRobustness2FeaturesEXT robustness2{};
  772. robustness2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ROBUSTNESS_2_FEATURES_EXT;
  773. robustness2.pNext = &variable_pointers;
  774. VkPhysicalDeviceFeatures2KHR features2{};
  775. features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2;
  776. features2.pNext = &robustness2;
  777. physical.GetFeatures2KHR(features2);
  778. const VkPhysicalDeviceFeatures& features{features2.features};
  779. const std::array feature_report{
  780. std::make_pair(features.robustBufferAccess, "robustBufferAccess"),
  781. std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"),
  782. std::make_pair(features.imageCubeArray, "imageCubeArray"),
  783. std::make_pair(features.independentBlend, "independentBlend"),
  784. std::make_pair(features.depthClamp, "depthClamp"),
  785. std::make_pair(features.samplerAnisotropy, "samplerAnisotropy"),
  786. std::make_pair(features.largePoints, "largePoints"),
  787. std::make_pair(features.multiViewport, "multiViewport"),
  788. std::make_pair(features.depthBiasClamp, "depthBiasClamp"),
  789. std::make_pair(features.fillModeNonSolid, "fillModeNonSolid"),
  790. std::make_pair(features.wideLines, "wideLines"),
  791. std::make_pair(features.geometryShader, "geometryShader"),
  792. std::make_pair(features.tessellationShader, "tessellationShader"),
  793. std::make_pair(features.sampleRateShading, "sampleRateShading"),
  794. std::make_pair(features.dualSrcBlend, "dualSrcBlend"),
  795. std::make_pair(features.occlusionQueryPrecise, "occlusionQueryPrecise"),
  796. std::make_pair(features.fragmentStoresAndAtomics, "fragmentStoresAndAtomics"),
  797. std::make_pair(features.shaderImageGatherExtended, "shaderImageGatherExtended"),
  798. std::make_pair(features.shaderStorageImageWriteWithoutFormat,
  799. "shaderStorageImageWriteWithoutFormat"),
  800. std::make_pair(features.shaderClipDistance, "shaderClipDistance"),
  801. std::make_pair(features.shaderCullDistance, "shaderCullDistance"),
  802. std::make_pair(demote.shaderDemoteToHelperInvocation, "shaderDemoteToHelperInvocation"),
  803. std::make_pair(variable_pointers.variablePointers, "variablePointers"),
  804. std::make_pair(variable_pointers.variablePointersStorageBuffer,
  805. "variablePointersStorageBuffer"),
  806. std::make_pair(robustness2.robustBufferAccess2, "robustBufferAccess2"),
  807. std::make_pair(robustness2.robustImageAccess2, "robustImageAccess2"),
  808. std::make_pair(robustness2.nullDescriptor, "nullDescriptor"),
  809. };
  810. for (const auto& [is_supported, name] : feature_report) {
  811. if (is_supported) {
  812. continue;
  813. }
  814. LOG_ERROR(Render_Vulkan, "Missing required feature: {}", name);
  815. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  816. }
  817. }
  818. std::vector<const char*> Device::LoadExtensions(bool requires_surface) {
  819. std::vector<const char*> extensions;
  820. extensions.reserve(8 + REQUIRED_EXTENSIONS.size());
  821. extensions.insert(extensions.begin(), REQUIRED_EXTENSIONS.begin(), REQUIRED_EXTENSIONS.end());
  822. if (requires_surface) {
  823. extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
  824. }
  825. bool has_khr_shader_float16_int8{};
  826. bool has_khr_workgroup_memory_explicit_layout{};
  827. bool has_khr_pipeline_executable_properties{};
  828. bool has_khr_image_format_list{};
  829. bool has_khr_swapchain_mutable_format{};
  830. bool has_ext_subgroup_size_control{};
  831. bool has_ext_transform_feedback{};
  832. bool has_ext_custom_border_color{};
  833. bool has_ext_extended_dynamic_state{};
  834. bool has_ext_shader_atomic_int64{};
  835. bool has_ext_provoking_vertex{};
  836. bool has_ext_vertex_input_dynamic_state{};
  837. bool has_ext_line_rasterization{};
  838. bool has_ext_primitive_topology_list_restart{};
  839. for (const std::string& extension : supported_extensions) {
  840. const auto test = [&](std::optional<std::reference_wrapper<bool>> status, const char* name,
  841. bool push) {
  842. if (extension != name) {
  843. return;
  844. }
  845. if (push) {
  846. extensions.push_back(name);
  847. }
  848. if (status) {
  849. status->get() = true;
  850. }
  851. };
  852. test(nv_viewport_swizzle, VK_NV_VIEWPORT_SWIZZLE_EXTENSION_NAME, true);
  853. test(nv_viewport_array2, VK_NV_VIEWPORT_ARRAY2_EXTENSION_NAME, true);
  854. test(nv_geometry_shader_passthrough, VK_NV_GEOMETRY_SHADER_PASSTHROUGH_EXTENSION_NAME,
  855. true);
  856. test(khr_uniform_buffer_standard_layout,
  857. VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true);
  858. test(khr_spirv_1_4, VK_KHR_SPIRV_1_4_EXTENSION_NAME, true);
  859. test(khr_push_descriptor, VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME, true);
  860. test(has_khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, false);
  861. test(ext_depth_range_unrestricted, VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME, true);
  862. test(ext_index_type_uint8, VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, true);
  863. test(has_ext_primitive_topology_list_restart,
  864. VK_EXT_PRIMITIVE_TOPOLOGY_LIST_RESTART_EXTENSION_NAME, true);
  865. test(ext_sampler_filter_minmax, VK_EXT_SAMPLER_FILTER_MINMAX_EXTENSION_NAME, true);
  866. test(ext_shader_viewport_index_layer, VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME,
  867. true);
  868. test(ext_tooling_info, VK_EXT_TOOLING_INFO_EXTENSION_NAME, true);
  869. test(ext_shader_stencil_export, VK_EXT_SHADER_STENCIL_EXPORT_EXTENSION_NAME, true);
  870. test(ext_conservative_rasterization, VK_EXT_CONSERVATIVE_RASTERIZATION_EXTENSION_NAME,
  871. true);
  872. test(has_ext_transform_feedback, VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME, false);
  873. test(has_ext_custom_border_color, VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME, false);
  874. test(has_ext_extended_dynamic_state, VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME, false);
  875. test(has_ext_subgroup_size_control, VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME, false);
  876. test(has_ext_provoking_vertex, VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME, false);
  877. test(has_ext_vertex_input_dynamic_state, VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME,
  878. false);
  879. test(has_ext_shader_atomic_int64, VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME, false);
  880. test(has_khr_workgroup_memory_explicit_layout,
  881. VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME, false);
  882. test(has_khr_image_format_list, VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME, false);
  883. test(has_khr_swapchain_mutable_format, VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME,
  884. false);
  885. test(has_ext_line_rasterization, VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME, false);
  886. if (Settings::values.enable_nsight_aftermath) {
  887. test(nv_device_diagnostics_config, VK_NV_DEVICE_DIAGNOSTICS_CONFIG_EXTENSION_NAME,
  888. true);
  889. }
  890. if (Settings::values.renderer_shader_feedback) {
  891. test(has_khr_pipeline_executable_properties,
  892. VK_KHR_PIPELINE_EXECUTABLE_PROPERTIES_EXTENSION_NAME, false);
  893. }
  894. }
  895. VkPhysicalDeviceFeatures2KHR features{};
  896. features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
  897. VkPhysicalDeviceProperties2KHR physical_properties;
  898. physical_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
  899. if (has_khr_shader_float16_int8) {
  900. VkPhysicalDeviceFloat16Int8FeaturesKHR float16_int8_features;
  901. float16_int8_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR;
  902. float16_int8_features.pNext = nullptr;
  903. features.pNext = &float16_int8_features;
  904. physical.GetFeatures2KHR(features);
  905. is_float16_supported = float16_int8_features.shaderFloat16;
  906. is_int8_supported = float16_int8_features.shaderInt8;
  907. extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME);
  908. }
  909. if (has_ext_subgroup_size_control) {
  910. VkPhysicalDeviceSubgroupSizeControlFeaturesEXT subgroup_features;
  911. subgroup_features.sType =
  912. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_FEATURES_EXT;
  913. subgroup_features.pNext = nullptr;
  914. features.pNext = &subgroup_features;
  915. physical.GetFeatures2KHR(features);
  916. VkPhysicalDeviceSubgroupSizeControlPropertiesEXT subgroup_properties;
  917. subgroup_properties.sType =
  918. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SUBGROUP_SIZE_CONTROL_PROPERTIES_EXT;
  919. subgroup_properties.pNext = nullptr;
  920. physical_properties.pNext = &subgroup_properties;
  921. physical.GetProperties2KHR(physical_properties);
  922. is_warp_potentially_bigger = subgroup_properties.maxSubgroupSize > GuestWarpSize;
  923. if (subgroup_features.subgroupSizeControl &&
  924. subgroup_properties.minSubgroupSize <= GuestWarpSize &&
  925. subgroup_properties.maxSubgroupSize >= GuestWarpSize) {
  926. extensions.push_back(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);
  927. guest_warp_stages = subgroup_properties.requiredSubgroupSizeStages;
  928. ext_subgroup_size_control = true;
  929. }
  930. } else {
  931. is_warp_potentially_bigger = true;
  932. }
  933. if (has_ext_provoking_vertex) {
  934. VkPhysicalDeviceProvokingVertexFeaturesEXT provoking_vertex;
  935. provoking_vertex.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROVOKING_VERTEX_FEATURES_EXT;
  936. provoking_vertex.pNext = nullptr;
  937. features.pNext = &provoking_vertex;
  938. physical.GetFeatures2KHR(features);
  939. if (provoking_vertex.provokingVertexLast &&
  940. provoking_vertex.transformFeedbackPreservesProvokingVertex) {
  941. extensions.push_back(VK_EXT_PROVOKING_VERTEX_EXTENSION_NAME);
  942. ext_provoking_vertex = true;
  943. }
  944. }
  945. if (has_ext_vertex_input_dynamic_state) {
  946. VkPhysicalDeviceVertexInputDynamicStateFeaturesEXT vertex_input;
  947. vertex_input.sType =
  948. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VERTEX_INPUT_DYNAMIC_STATE_FEATURES_EXT;
  949. vertex_input.pNext = nullptr;
  950. features.pNext = &vertex_input;
  951. physical.GetFeatures2KHR(features);
  952. if (vertex_input.vertexInputDynamicState) {
  953. extensions.push_back(VK_EXT_VERTEX_INPUT_DYNAMIC_STATE_EXTENSION_NAME);
  954. ext_vertex_input_dynamic_state = true;
  955. }
  956. }
  957. if (has_ext_shader_atomic_int64) {
  958. VkPhysicalDeviceShaderAtomicInt64Features atomic_int64;
  959. atomic_int64.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
  960. atomic_int64.pNext = nullptr;
  961. features.pNext = &atomic_int64;
  962. physical.GetFeatures2KHR(features);
  963. if (atomic_int64.shaderBufferInt64Atomics && atomic_int64.shaderSharedInt64Atomics) {
  964. extensions.push_back(VK_KHR_SHADER_ATOMIC_INT64_EXTENSION_NAME);
  965. ext_shader_atomic_int64 = true;
  966. }
  967. }
  968. if (has_ext_transform_feedback) {
  969. VkPhysicalDeviceTransformFeedbackFeaturesEXT tfb_features;
  970. tfb_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT;
  971. tfb_features.pNext = nullptr;
  972. features.pNext = &tfb_features;
  973. physical.GetFeatures2KHR(features);
  974. VkPhysicalDeviceTransformFeedbackPropertiesEXT tfb_properties;
  975. tfb_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT;
  976. tfb_properties.pNext = nullptr;
  977. physical_properties.pNext = &tfb_properties;
  978. physical.GetProperties2KHR(physical_properties);
  979. if (tfb_features.transformFeedback && tfb_features.geometryStreams &&
  980. tfb_properties.maxTransformFeedbackStreams >= 4 &&
  981. tfb_properties.maxTransformFeedbackBuffers && tfb_properties.transformFeedbackQueries &&
  982. tfb_properties.transformFeedbackDraw) {
  983. extensions.push_back(VK_EXT_TRANSFORM_FEEDBACK_EXTENSION_NAME);
  984. ext_transform_feedback = true;
  985. }
  986. }
  987. if (has_ext_custom_border_color) {
  988. VkPhysicalDeviceCustomBorderColorFeaturesEXT border_features;
  989. border_features.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_CUSTOM_BORDER_COLOR_FEATURES_EXT;
  990. border_features.pNext = nullptr;
  991. features.pNext = &border_features;
  992. physical.GetFeatures2KHR(features);
  993. if (border_features.customBorderColors && border_features.customBorderColorWithoutFormat) {
  994. extensions.push_back(VK_EXT_CUSTOM_BORDER_COLOR_EXTENSION_NAME);
  995. ext_custom_border_color = true;
  996. }
  997. }
  998. if (has_ext_extended_dynamic_state) {
  999. VkPhysicalDeviceExtendedDynamicStateFeaturesEXT extended_dynamic_state;
  1000. extended_dynamic_state.sType =
  1001. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTENDED_DYNAMIC_STATE_FEATURES_EXT;
  1002. extended_dynamic_state.pNext = nullptr;
  1003. features.pNext = &extended_dynamic_state;
  1004. physical.GetFeatures2KHR(features);
  1005. if (extended_dynamic_state.extendedDynamicState) {
  1006. extensions.push_back(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
  1007. ext_extended_dynamic_state = true;
  1008. }
  1009. }
  1010. if (has_ext_line_rasterization) {
  1011. VkPhysicalDeviceLineRasterizationFeaturesEXT line_raster;
  1012. line_raster.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_LINE_RASTERIZATION_FEATURES_EXT;
  1013. line_raster.pNext = nullptr;
  1014. features.pNext = &line_raster;
  1015. physical.GetFeatures2KHR(features);
  1016. if (line_raster.rectangularLines && line_raster.smoothLines) {
  1017. extensions.push_back(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
  1018. ext_line_rasterization = true;
  1019. }
  1020. }
  1021. if (has_khr_workgroup_memory_explicit_layout) {
  1022. VkPhysicalDeviceWorkgroupMemoryExplicitLayoutFeaturesKHR layout;
  1023. layout.sType =
  1024. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_FEATURES_KHR;
  1025. layout.pNext = nullptr;
  1026. features.pNext = &layout;
  1027. physical.GetFeatures2KHR(features);
  1028. if (layout.workgroupMemoryExplicitLayout &&
  1029. layout.workgroupMemoryExplicitLayout8BitAccess &&
  1030. layout.workgroupMemoryExplicitLayout16BitAccess &&
  1031. layout.workgroupMemoryExplicitLayoutScalarBlockLayout) {
  1032. extensions.push_back(VK_KHR_WORKGROUP_MEMORY_EXPLICIT_LAYOUT_EXTENSION_NAME);
  1033. khr_workgroup_memory_explicit_layout = true;
  1034. }
  1035. }
  1036. if (has_khr_pipeline_executable_properties) {
  1037. VkPhysicalDevicePipelineExecutablePropertiesFeaturesKHR executable_properties;
  1038. executable_properties.sType =
  1039. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_EXECUTABLE_PROPERTIES_FEATURES_KHR;
  1040. executable_properties.pNext = nullptr;
  1041. features.pNext = &executable_properties;
  1042. physical.GetFeatures2KHR(features);
  1043. if (executable_properties.pipelineExecutableInfo) {
  1044. extensions.push_back(VK_KHR_PIPELINE_EXECUTABLE_PROPERTIES_EXTENSION_NAME);
  1045. khr_pipeline_executable_properties = true;
  1046. }
  1047. }
  1048. if (has_khr_image_format_list && has_khr_swapchain_mutable_format) {
  1049. extensions.push_back(VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME);
  1050. extensions.push_back(VK_KHR_SWAPCHAIN_MUTABLE_FORMAT_EXTENSION_NAME);
  1051. khr_swapchain_mutable_format = true;
  1052. }
  1053. if (khr_push_descriptor) {
  1054. VkPhysicalDevicePushDescriptorPropertiesKHR push_descriptor;
  1055. push_descriptor.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR;
  1056. push_descriptor.pNext = nullptr;
  1057. physical_properties.pNext = &push_descriptor;
  1058. physical.GetProperties2KHR(physical_properties);
  1059. max_push_descriptors = push_descriptor.maxPushDescriptors;
  1060. }
  1061. if (has_ext_primitive_topology_list_restart) {
  1062. VkPhysicalDevicePrimitiveTopologyListRestartFeaturesEXT primitive_topology_list_restart{};
  1063. primitive_topology_list_restart.sType =
  1064. VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRIMITIVE_TOPOLOGY_LIST_RESTART_FEATURES_EXT;
  1065. primitive_topology_list_restart.pNext = nullptr;
  1066. physical_properties.pNext = &primitive_topology_list_restart;
  1067. physical.GetProperties2KHR(physical_properties);
  1068. is_topology_list_restart_supported =
  1069. primitive_topology_list_restart.primitiveTopologyListRestart;
  1070. is_patch_list_restart_supported =
  1071. primitive_topology_list_restart.primitiveTopologyPatchListRestart;
  1072. }
  1073. return extensions;
  1074. }
  1075. void Device::SetupFamilies(VkSurfaceKHR surface) {
  1076. const std::vector queue_family_properties = physical.GetQueueFamilyProperties();
  1077. std::optional<u32> graphics;
  1078. std::optional<u32> present;
  1079. for (u32 index = 0; index < static_cast<u32>(queue_family_properties.size()); ++index) {
  1080. if (graphics && (present || !surface)) {
  1081. break;
  1082. }
  1083. const VkQueueFamilyProperties& queue_family = queue_family_properties[index];
  1084. if (queue_family.queueCount == 0) {
  1085. continue;
  1086. }
  1087. if (queue_family.queueFlags & VK_QUEUE_GRAPHICS_BIT) {
  1088. graphics = index;
  1089. }
  1090. if (surface && physical.GetSurfaceSupportKHR(index, surface)) {
  1091. present = index;
  1092. }
  1093. }
  1094. if (!graphics) {
  1095. LOG_ERROR(Render_Vulkan, "Device lacks a graphics queue");
  1096. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  1097. }
  1098. if (surface && !present) {
  1099. LOG_ERROR(Render_Vulkan, "Device lacks a present queue");
  1100. throw vk::Exception(VK_ERROR_FEATURE_NOT_PRESENT);
  1101. }
  1102. graphics_family = *graphics;
  1103. present_family = *present;
  1104. }
  1105. void Device::SetupFeatures() {
  1106. const VkPhysicalDeviceFeatures features{physical.GetFeatures()};
  1107. is_depth_bounds_supported = features.depthBounds;
  1108. is_formatless_image_load_supported = features.shaderStorageImageReadWithoutFormat;
  1109. is_shader_float64_supported = features.shaderFloat64;
  1110. is_shader_int64_supported = features.shaderInt64;
  1111. is_shader_int16_supported = features.shaderInt16;
  1112. is_shader_storage_image_multisample = features.shaderStorageImageMultisample;
  1113. is_blit_depth_stencil_supported = TestDepthStencilBlits();
  1114. is_optimal_astc_supported = IsOptimalAstcSupported(features);
  1115. }
  1116. void Device::SetupProperties() {
  1117. float_controls.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR;
  1118. VkPhysicalDeviceProperties2KHR properties2{};
  1119. properties2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
  1120. properties2.pNext = &float_controls;
  1121. physical.GetProperties2KHR(properties2);
  1122. }
  1123. void Device::CollectTelemetryParameters() {
  1124. VkPhysicalDeviceDriverPropertiesKHR driver{
  1125. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR,
  1126. .pNext = nullptr,
  1127. .driverID = {},
  1128. .driverName = {},
  1129. .driverInfo = {},
  1130. .conformanceVersion = {},
  1131. };
  1132. VkPhysicalDeviceProperties2KHR device_properties{
  1133. .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR,
  1134. .pNext = &driver,
  1135. .properties = {},
  1136. };
  1137. physical.GetProperties2KHR(device_properties);
  1138. driver_id = driver.driverID;
  1139. vendor_name = driver.driverName;
  1140. }
  1141. void Device::CollectPhysicalMemoryInfo() {
  1142. const auto mem_properties = physical.GetMemoryProperties();
  1143. const size_t num_properties = mem_properties.memoryHeapCount;
  1144. device_access_memory = 0;
  1145. for (size_t element = 0; element < num_properties; ++element) {
  1146. if ((mem_properties.memoryHeaps[element].flags & VK_MEMORY_HEAP_DEVICE_LOCAL_BIT) != 0) {
  1147. device_access_memory += mem_properties.memoryHeaps[element].size;
  1148. }
  1149. }
  1150. }
  1151. void Device::CollectToolingInfo() {
  1152. if (!ext_tooling_info) {
  1153. return;
  1154. }
  1155. const auto vkGetPhysicalDeviceToolPropertiesEXT =
  1156. reinterpret_cast<PFN_vkGetPhysicalDeviceToolPropertiesEXT>(
  1157. dld.vkGetInstanceProcAddr(instance, "vkGetPhysicalDeviceToolPropertiesEXT"));
  1158. if (!vkGetPhysicalDeviceToolPropertiesEXT) {
  1159. return;
  1160. }
  1161. u32 tool_count = 0;
  1162. if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, nullptr) != VK_SUCCESS) {
  1163. return;
  1164. }
  1165. std::vector<VkPhysicalDeviceToolPropertiesEXT> tools(tool_count);
  1166. if (vkGetPhysicalDeviceToolPropertiesEXT(physical, &tool_count, tools.data()) != VK_SUCCESS) {
  1167. return;
  1168. }
  1169. for (const VkPhysicalDeviceToolPropertiesEXT& tool : tools) {
  1170. const std::string_view name = tool.name;
  1171. LOG_INFO(Render_Vulkan, "{}", name);
  1172. has_renderdoc = has_renderdoc || name == "RenderDoc";
  1173. has_nsight_graphics = has_nsight_graphics || name == "NVIDIA Nsight Graphics";
  1174. }
  1175. }
  1176. std::vector<VkDeviceQueueCreateInfo> Device::GetDeviceQueueCreateInfos() const {
  1177. static constexpr float QUEUE_PRIORITY = 1.0f;
  1178. std::unordered_set<u32> unique_queue_families{graphics_family, present_family};
  1179. std::vector<VkDeviceQueueCreateInfo> queue_cis;
  1180. queue_cis.reserve(unique_queue_families.size());
  1181. for (const u32 queue_family : unique_queue_families) {
  1182. auto& ci = queue_cis.emplace_back(VkDeviceQueueCreateInfo{
  1183. .sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
  1184. .pNext = nullptr,
  1185. .flags = 0,
  1186. .queueFamilyIndex = queue_family,
  1187. .queueCount = 1,
  1188. .pQueuePriorities = nullptr,
  1189. });
  1190. ci.pQueuePriorities = &QUEUE_PRIORITY;
  1191. }
  1192. return queue_cis;
  1193. }
  1194. } // namespace Vulkan