vk_device.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573
  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 <cstdlib>
  7. #include <optional>
  8. #include <set>
  9. #include <string_view>
  10. #include <thread>
  11. #include <vector>
  12. #include "common/assert.h"
  13. #include "core/settings.h"
  14. #include "video_core/renderer_vulkan/declarations.h"
  15. #include "video_core/renderer_vulkan/vk_device.h"
  16. namespace Vulkan {
  17. namespace {
  18. namespace Alternatives {
  19. constexpr std::array Depth24UnormS8Uint = {vk::Format::eD32SfloatS8Uint,
  20. vk::Format::eD16UnormS8Uint, vk::Format{}};
  21. constexpr std::array Depth16UnormS8Uint = {vk::Format::eD24UnormS8Uint,
  22. vk::Format::eD32SfloatS8Uint, vk::Format{}};
  23. } // namespace Alternatives
  24. template <typename T>
  25. void SetNext(void**& next, T& data) {
  26. *next = &data;
  27. next = &data.pNext;
  28. }
  29. template <typename T>
  30. T GetFeatures(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dldi) {
  31. vk::PhysicalDeviceFeatures2 features;
  32. T extension_features;
  33. features.pNext = &extension_features;
  34. physical.getFeatures2(&features, dldi);
  35. return extension_features;
  36. }
  37. template <typename T>
  38. T GetProperties(vk::PhysicalDevice physical, const vk::DispatchLoaderDynamic& dldi) {
  39. vk::PhysicalDeviceProperties2 properties;
  40. T extension_properties;
  41. properties.pNext = &extension_properties;
  42. physical.getProperties2(&properties, dldi);
  43. return extension_properties;
  44. }
  45. constexpr const vk::Format* GetFormatAlternatives(vk::Format format) {
  46. switch (format) {
  47. case vk::Format::eD24UnormS8Uint:
  48. return Alternatives::Depth24UnormS8Uint.data();
  49. case vk::Format::eD16UnormS8Uint:
  50. return Alternatives::Depth16UnormS8Uint.data();
  51. default:
  52. return nullptr;
  53. }
  54. }
  55. vk::FormatFeatureFlags GetFormatFeatures(vk::FormatProperties properties, FormatType format_type) {
  56. switch (format_type) {
  57. case FormatType::Linear:
  58. return properties.linearTilingFeatures;
  59. case FormatType::Optimal:
  60. return properties.optimalTilingFeatures;
  61. case FormatType::Buffer:
  62. return properties.bufferFeatures;
  63. default:
  64. return {};
  65. }
  66. }
  67. } // Anonymous namespace
  68. VKDevice::VKDevice(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical,
  69. vk::SurfaceKHR surface)
  70. : physical{physical}, properties{physical.getProperties(dldi)},
  71. format_properties{GetFormatProperties(dldi, physical)} {
  72. SetupFamilies(dldi, surface);
  73. SetupFeatures(dldi);
  74. }
  75. VKDevice::~VKDevice() = default;
  76. bool VKDevice::Create(const vk::DispatchLoaderDynamic& dldi, vk::Instance instance) {
  77. const auto queue_cis = GetDeviceQueueCreateInfos();
  78. const std::vector extensions = LoadExtensions(dldi);
  79. vk::PhysicalDeviceFeatures2 features2;
  80. void** next = &features2.pNext;
  81. auto& features = features2.features;
  82. features.vertexPipelineStoresAndAtomics = true;
  83. features.independentBlend = true;
  84. features.depthClamp = true;
  85. features.samplerAnisotropy = true;
  86. features.largePoints = true;
  87. features.multiViewport = true;
  88. features.depthBiasClamp = true;
  89. features.geometryShader = true;
  90. features.tessellationShader = true;
  91. features.occlusionQueryPrecise = true;
  92. features.fragmentStoresAndAtomics = true;
  93. features.shaderImageGatherExtended = true;
  94. features.shaderStorageImageReadWithoutFormat = is_formatless_image_load_supported;
  95. features.shaderStorageImageWriteWithoutFormat = true;
  96. features.textureCompressionASTC_LDR = is_optimal_astc_supported;
  97. vk::PhysicalDevice16BitStorageFeaturesKHR bit16_storage;
  98. bit16_storage.uniformAndStorageBuffer16BitAccess = true;
  99. SetNext(next, bit16_storage);
  100. vk::PhysicalDevice8BitStorageFeaturesKHR bit8_storage;
  101. bit8_storage.uniformAndStorageBuffer8BitAccess = true;
  102. SetNext(next, bit8_storage);
  103. vk::PhysicalDeviceHostQueryResetFeaturesEXT host_query_reset;
  104. host_query_reset.hostQueryReset = true;
  105. SetNext(next, host_query_reset);
  106. vk::PhysicalDeviceFloat16Int8FeaturesKHR float16_int8;
  107. if (is_float16_supported) {
  108. float16_int8.shaderFloat16 = true;
  109. SetNext(next, float16_int8);
  110. } else {
  111. LOG_INFO(Render_Vulkan, "Device doesn't support float16 natively");
  112. }
  113. vk::PhysicalDeviceUniformBufferStandardLayoutFeaturesKHR std430_layout;
  114. if (khr_uniform_buffer_standard_layout) {
  115. std430_layout.uniformBufferStandardLayout = true;
  116. SetNext(next, std430_layout);
  117. } else {
  118. LOG_INFO(Render_Vulkan, "Device doesn't support packed UBOs");
  119. }
  120. vk::PhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8;
  121. if (ext_index_type_uint8) {
  122. index_type_uint8.indexTypeUint8 = true;
  123. SetNext(next, index_type_uint8);
  124. } else {
  125. LOG_INFO(Render_Vulkan, "Device doesn't support uint8 indexes");
  126. }
  127. if (!ext_depth_range_unrestricted) {
  128. LOG_INFO(Render_Vulkan, "Device doesn't support depth range unrestricted");
  129. }
  130. vk::DeviceCreateInfo device_ci({}, static_cast<u32>(queue_cis.size()), queue_cis.data(), 0,
  131. nullptr, static_cast<u32>(extensions.size()), extensions.data(),
  132. nullptr);
  133. device_ci.pNext = &features2;
  134. vk::Device dummy_logical;
  135. if (physical.createDevice(&device_ci, nullptr, &dummy_logical, dldi) != vk::Result::eSuccess) {
  136. LOG_CRITICAL(Render_Vulkan, "Logical device failed to be created!");
  137. return false;
  138. }
  139. dld.init(instance, dldi.vkGetInstanceProcAddr, dummy_logical, dldi.vkGetDeviceProcAddr);
  140. logical = UniqueDevice(
  141. dummy_logical, vk::ObjectDestroy<vk::NoParent, vk::DispatchLoaderDynamic>(nullptr, dld));
  142. CollectTelemetryParameters();
  143. graphics_queue = logical->getQueue(graphics_family, 0, dld);
  144. present_queue = logical->getQueue(present_family, 0, dld);
  145. return true;
  146. }
  147. vk::Format VKDevice::GetSupportedFormat(vk::Format wanted_format,
  148. vk::FormatFeatureFlags wanted_usage,
  149. FormatType format_type) const {
  150. if (IsFormatSupported(wanted_format, wanted_usage, format_type)) {
  151. return wanted_format;
  152. }
  153. // The wanted format is not supported by hardware, search for alternatives
  154. const vk::Format* alternatives = GetFormatAlternatives(wanted_format);
  155. if (alternatives == nullptr) {
  156. UNREACHABLE_MSG("Format={} with usage={} and type={} has no defined alternatives and host "
  157. "hardware does not support it",
  158. vk::to_string(wanted_format), vk::to_string(wanted_usage),
  159. static_cast<u32>(format_type));
  160. return wanted_format;
  161. }
  162. std::size_t i = 0;
  163. for (vk::Format alternative = alternatives[0]; alternative != vk::Format{};
  164. alternative = alternatives[++i]) {
  165. if (!IsFormatSupported(alternative, wanted_usage, format_type)) {
  166. continue;
  167. }
  168. LOG_WARNING(Render_Vulkan,
  169. "Emulating format={} with alternative format={} with usage={} and type={}",
  170. static_cast<u32>(wanted_format), static_cast<u32>(alternative),
  171. static_cast<u32>(wanted_usage), static_cast<u32>(format_type));
  172. return alternative;
  173. }
  174. // No alternatives found, panic
  175. UNREACHABLE_MSG("Format={} with usage={} and type={} is not supported by the host hardware and "
  176. "doesn't support any of the alternatives",
  177. static_cast<u32>(wanted_format), static_cast<u32>(wanted_usage),
  178. static_cast<u32>(format_type));
  179. return wanted_format;
  180. }
  181. void VKDevice::ReportLoss() const {
  182. LOG_CRITICAL(Render_Vulkan, "Device loss occured!");
  183. // Wait some time to let the log flush
  184. std::this_thread::sleep_for(std::chrono::seconds{1});
  185. if (!nv_device_diagnostic_checkpoints) {
  186. return;
  187. }
  188. [[maybe_unused]] const std::vector data = graphics_queue.getCheckpointDataNV(dld);
  189. // Catch here in debug builds (or with optimizations disabled) the last graphics pipeline to be
  190. // executed. It can be done on a debugger by evaluating the expression:
  191. // *(VKGraphicsPipeline*)data[0]
  192. }
  193. bool VKDevice::IsOptimalAstcSupported(const vk::PhysicalDeviceFeatures& features,
  194. const vk::DispatchLoaderDynamic& dldi) const {
  195. // Disable for now to avoid converting ASTC twice.
  196. return false;
  197. static constexpr std::array astc_formats = {
  198. vk::Format::eAstc4x4SrgbBlock, vk::Format::eAstc8x8SrgbBlock,
  199. vk::Format::eAstc8x5SrgbBlock, vk::Format::eAstc5x4SrgbBlock,
  200. vk::Format::eAstc5x5UnormBlock, vk::Format::eAstc5x5SrgbBlock,
  201. vk::Format::eAstc10x8UnormBlock, vk::Format::eAstc10x8SrgbBlock,
  202. vk::Format::eAstc6x6UnormBlock, vk::Format::eAstc6x6SrgbBlock,
  203. vk::Format::eAstc10x10UnormBlock, vk::Format::eAstc10x10SrgbBlock,
  204. vk::Format::eAstc12x12UnormBlock, vk::Format::eAstc12x12SrgbBlock,
  205. vk::Format::eAstc8x6UnormBlock, vk::Format::eAstc8x6SrgbBlock,
  206. vk::Format::eAstc6x5UnormBlock, vk::Format::eAstc6x5SrgbBlock};
  207. if (!features.textureCompressionASTC_LDR) {
  208. return false;
  209. }
  210. const auto format_feature_usage{
  211. vk::FormatFeatureFlagBits::eSampledImage | vk::FormatFeatureFlagBits::eBlitSrc |
  212. vk::FormatFeatureFlagBits::eBlitDst | vk::FormatFeatureFlagBits::eTransferSrc |
  213. vk::FormatFeatureFlagBits::eTransferDst};
  214. for (const auto format : astc_formats) {
  215. const auto format_properties{physical.getFormatProperties(format, dldi)};
  216. if (!(format_properties.optimalTilingFeatures & format_feature_usage)) {
  217. return false;
  218. }
  219. }
  220. return true;
  221. }
  222. bool VKDevice::IsFormatSupported(vk::Format wanted_format, vk::FormatFeatureFlags wanted_usage,
  223. FormatType format_type) const {
  224. const auto it = format_properties.find(wanted_format);
  225. if (it == format_properties.end()) {
  226. UNIMPLEMENTED_MSG("Unimplemented format query={}", vk::to_string(wanted_format));
  227. return true;
  228. }
  229. const auto supported_usage = GetFormatFeatures(it->second, format_type);
  230. return (supported_usage & wanted_usage) == wanted_usage;
  231. }
  232. bool VKDevice::IsSuitable(const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical,
  233. vk::SurfaceKHR surface) {
  234. bool is_suitable = true;
  235. constexpr std::array required_extensions = {
  236. VK_KHR_SWAPCHAIN_EXTENSION_NAME,
  237. VK_KHR_16BIT_STORAGE_EXTENSION_NAME,
  238. VK_KHR_8BIT_STORAGE_EXTENSION_NAME,
  239. VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME,
  240. VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME,
  241. VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME,
  242. VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME,
  243. VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME,
  244. };
  245. std::bitset<required_extensions.size()> available_extensions{};
  246. for (const auto& prop : physical.enumerateDeviceExtensionProperties(nullptr, dldi)) {
  247. for (std::size_t i = 0; i < required_extensions.size(); ++i) {
  248. if (available_extensions[i]) {
  249. continue;
  250. }
  251. available_extensions[i] =
  252. required_extensions[i] == std::string_view{prop.extensionName};
  253. }
  254. }
  255. if (!available_extensions.all()) {
  256. for (std::size_t i = 0; i < required_extensions.size(); ++i) {
  257. if (available_extensions[i]) {
  258. continue;
  259. }
  260. LOG_ERROR(Render_Vulkan, "Missing required extension: {}", required_extensions[i]);
  261. is_suitable = false;
  262. }
  263. }
  264. bool has_graphics{}, has_present{};
  265. const auto queue_family_properties = physical.getQueueFamilyProperties(dldi);
  266. for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) {
  267. const auto& family = queue_family_properties[i];
  268. if (family.queueCount == 0) {
  269. continue;
  270. }
  271. has_graphics |=
  272. (family.queueFlags & vk::QueueFlagBits::eGraphics) != static_cast<vk::QueueFlagBits>(0);
  273. has_present |= physical.getSurfaceSupportKHR(i, surface, dldi) != 0;
  274. }
  275. if (!has_graphics || !has_present) {
  276. LOG_ERROR(Render_Vulkan, "Device lacks a graphics and present queue");
  277. is_suitable = false;
  278. }
  279. // TODO(Rodrigo): Check if the device matches all requeriments.
  280. const auto properties{physical.getProperties(dldi)};
  281. const auto& limits{properties.limits};
  282. constexpr u32 required_ubo_size = 65536;
  283. if (limits.maxUniformBufferRange < required_ubo_size) {
  284. LOG_ERROR(Render_Vulkan, "Device UBO size {} is too small, {} is required",
  285. limits.maxUniformBufferRange, required_ubo_size);
  286. is_suitable = false;
  287. }
  288. constexpr u32 required_num_viewports = 16;
  289. if (limits.maxViewports < required_num_viewports) {
  290. LOG_INFO(Render_Vulkan, "Device number of viewports {} is too small, {} is required",
  291. limits.maxViewports, required_num_viewports);
  292. is_suitable = false;
  293. }
  294. const auto features{physical.getFeatures(dldi)};
  295. const std::array feature_report = {
  296. std::make_pair(features.vertexPipelineStoresAndAtomics, "vertexPipelineStoresAndAtomics"),
  297. std::make_pair(features.independentBlend, "independentBlend"),
  298. std::make_pair(features.depthClamp, "depthClamp"),
  299. std::make_pair(features.samplerAnisotropy, "samplerAnisotropy"),
  300. std::make_pair(features.largePoints, "largePoints"),
  301. std::make_pair(features.multiViewport, "multiViewport"),
  302. std::make_pair(features.depthBiasClamp, "depthBiasClamp"),
  303. std::make_pair(features.geometryShader, "geometryShader"),
  304. std::make_pair(features.tessellationShader, "tessellationShader"),
  305. std::make_pair(features.occlusionQueryPrecise, "occlusionQueryPrecise"),
  306. std::make_pair(features.fragmentStoresAndAtomics, "fragmentStoresAndAtomics"),
  307. std::make_pair(features.shaderImageGatherExtended, "shaderImageGatherExtended"),
  308. std::make_pair(features.shaderStorageImageWriteWithoutFormat,
  309. "shaderStorageImageWriteWithoutFormat"),
  310. };
  311. for (const auto& [supported, name] : feature_report) {
  312. if (supported) {
  313. continue;
  314. }
  315. LOG_ERROR(Render_Vulkan, "Missing required feature: {}", name);
  316. is_suitable = false;
  317. }
  318. if (!is_suitable) {
  319. LOG_ERROR(Render_Vulkan, "{} is not suitable", properties.deviceName);
  320. }
  321. return is_suitable;
  322. }
  323. std::vector<const char*> VKDevice::LoadExtensions(const vk::DispatchLoaderDynamic& dldi) {
  324. std::vector<const char*> extensions;
  325. const auto Test = [&](const vk::ExtensionProperties& extension,
  326. std::optional<std::reference_wrapper<bool>> status, const char* name,
  327. bool push) {
  328. if (extension.extensionName != std::string_view(name)) {
  329. return;
  330. }
  331. if (push) {
  332. extensions.push_back(name);
  333. }
  334. if (status) {
  335. status->get() = true;
  336. }
  337. };
  338. extensions.reserve(14);
  339. extensions.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME);
  340. extensions.push_back(VK_KHR_16BIT_STORAGE_EXTENSION_NAME);
  341. extensions.push_back(VK_KHR_8BIT_STORAGE_EXTENSION_NAME);
  342. extensions.push_back(VK_KHR_DRIVER_PROPERTIES_EXTENSION_NAME);
  343. extensions.push_back(VK_EXT_VERTEX_ATTRIBUTE_DIVISOR_EXTENSION_NAME);
  344. extensions.push_back(VK_EXT_SHADER_SUBGROUP_BALLOT_EXTENSION_NAME);
  345. extensions.push_back(VK_EXT_SHADER_SUBGROUP_VOTE_EXTENSION_NAME);
  346. extensions.push_back(VK_EXT_HOST_QUERY_RESET_EXTENSION_NAME);
  347. [[maybe_unused]] const bool nsight =
  348. std::getenv("NVTX_INJECTION64_PATH") || std::getenv("NSIGHT_LAUNCHED");
  349. bool khr_shader_float16_int8{};
  350. bool ext_subgroup_size_control{};
  351. for (const auto& extension : physical.enumerateDeviceExtensionProperties(nullptr, dldi)) {
  352. Test(extension, khr_uniform_buffer_standard_layout,
  353. VK_KHR_UNIFORM_BUFFER_STANDARD_LAYOUT_EXTENSION_NAME, true);
  354. Test(extension, khr_shader_float16_int8, VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME, false);
  355. Test(extension, ext_depth_range_unrestricted,
  356. VK_EXT_DEPTH_RANGE_UNRESTRICTED_EXTENSION_NAME, true);
  357. Test(extension, ext_index_type_uint8, VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME, true);
  358. Test(extension, ext_shader_viewport_index_layer,
  359. VK_EXT_SHADER_VIEWPORT_INDEX_LAYER_EXTENSION_NAME, true);
  360. Test(extension, ext_subgroup_size_control, VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME,
  361. false);
  362. if (Settings::values.renderer_debug) {
  363. Test(extension, nv_device_diagnostic_checkpoints,
  364. VK_NV_DEVICE_DIAGNOSTIC_CHECKPOINTS_EXTENSION_NAME, true);
  365. }
  366. }
  367. if (khr_shader_float16_int8) {
  368. is_float16_supported =
  369. GetFeatures<vk::PhysicalDeviceFloat16Int8FeaturesKHR>(physical, dldi).shaderFloat16;
  370. extensions.push_back(VK_KHR_SHADER_FLOAT16_INT8_EXTENSION_NAME);
  371. }
  372. if (ext_subgroup_size_control) {
  373. const auto features =
  374. GetFeatures<vk::PhysicalDeviceSubgroupSizeControlFeaturesEXT>(physical, dldi);
  375. const auto properties =
  376. GetProperties<vk::PhysicalDeviceSubgroupSizeControlPropertiesEXT>(physical, dldi);
  377. is_warp_potentially_bigger = properties.maxSubgroupSize > GuestWarpSize;
  378. if (features.subgroupSizeControl && properties.minSubgroupSize <= GuestWarpSize &&
  379. properties.maxSubgroupSize >= GuestWarpSize) {
  380. extensions.push_back(VK_EXT_SUBGROUP_SIZE_CONTROL_EXTENSION_NAME);
  381. guest_warp_stages = properties.requiredSubgroupSizeStages;
  382. }
  383. } else {
  384. is_warp_potentially_bigger = true;
  385. }
  386. return extensions;
  387. }
  388. void VKDevice::SetupFamilies(const vk::DispatchLoaderDynamic& dldi, vk::SurfaceKHR surface) {
  389. std::optional<u32> graphics_family_, present_family_;
  390. const auto queue_family_properties = physical.getQueueFamilyProperties(dldi);
  391. for (u32 i = 0; i < static_cast<u32>(queue_family_properties.size()); ++i) {
  392. if (graphics_family_ && present_family_)
  393. break;
  394. const auto& queue_family = queue_family_properties[i];
  395. if (queue_family.queueCount == 0)
  396. continue;
  397. if (queue_family.queueFlags & vk::QueueFlagBits::eGraphics)
  398. graphics_family_ = i;
  399. if (physical.getSurfaceSupportKHR(i, surface, dldi))
  400. present_family_ = i;
  401. }
  402. ASSERT(graphics_family_ && present_family_);
  403. graphics_family = *graphics_family_;
  404. present_family = *present_family_;
  405. }
  406. void VKDevice::SetupFeatures(const vk::DispatchLoaderDynamic& dldi) {
  407. const auto supported_features{physical.getFeatures(dldi)};
  408. is_formatless_image_load_supported = supported_features.shaderStorageImageReadWithoutFormat;
  409. is_optimal_astc_supported = IsOptimalAstcSupported(supported_features, dldi);
  410. }
  411. void VKDevice::CollectTelemetryParameters() {
  412. const auto driver = GetProperties<vk::PhysicalDeviceDriverPropertiesKHR>(physical, dld);
  413. driver_id = driver.driverID;
  414. vendor_name = driver.driverName;
  415. const auto extensions = physical.enumerateDeviceExtensionProperties(nullptr, dld);
  416. reported_extensions.reserve(std::size(extensions));
  417. for (const auto& extension : extensions) {
  418. reported_extensions.push_back(extension.extensionName);
  419. }
  420. }
  421. std::vector<vk::DeviceQueueCreateInfo> VKDevice::GetDeviceQueueCreateInfos() const {
  422. static const float QUEUE_PRIORITY = 1.0f;
  423. std::set<u32> unique_queue_families = {graphics_family, present_family};
  424. std::vector<vk::DeviceQueueCreateInfo> queue_cis;
  425. for (u32 queue_family : unique_queue_families)
  426. queue_cis.push_back({{}, queue_family, 1, &QUEUE_PRIORITY});
  427. return queue_cis;
  428. }
  429. std::unordered_map<vk::Format, vk::FormatProperties> VKDevice::GetFormatProperties(
  430. const vk::DispatchLoaderDynamic& dldi, vk::PhysicalDevice physical) {
  431. static constexpr std::array formats{vk::Format::eA8B8G8R8UnormPack32,
  432. vk::Format::eA8B8G8R8UintPack32,
  433. vk::Format::eA8B8G8R8SnormPack32,
  434. vk::Format::eA8B8G8R8SrgbPack32,
  435. vk::Format::eB5G6R5UnormPack16,
  436. vk::Format::eA2B10G10R10UnormPack32,
  437. vk::Format::eA1R5G5B5UnormPack16,
  438. vk::Format::eR32G32B32A32Sfloat,
  439. vk::Format::eR32G32B32A32Uint,
  440. vk::Format::eR32G32Sfloat,
  441. vk::Format::eR32G32Uint,
  442. vk::Format::eR16G16B16A16Uint,
  443. vk::Format::eR16G16B16A16Unorm,
  444. vk::Format::eR16G16Unorm,
  445. vk::Format::eR16G16Snorm,
  446. vk::Format::eR16G16Sfloat,
  447. vk::Format::eR16Unorm,
  448. vk::Format::eR8G8B8A8Srgb,
  449. vk::Format::eR8G8Unorm,
  450. vk::Format::eR8G8Snorm,
  451. vk::Format::eR8Unorm,
  452. vk::Format::eR8Uint,
  453. vk::Format::eB10G11R11UfloatPack32,
  454. vk::Format::eR32Sfloat,
  455. vk::Format::eR32Uint,
  456. vk::Format::eR32Sint,
  457. vk::Format::eR16Sfloat,
  458. vk::Format::eR16G16B16A16Sfloat,
  459. vk::Format::eB8G8R8A8Unorm,
  460. vk::Format::eR4G4B4A4UnormPack16,
  461. vk::Format::eD32Sfloat,
  462. vk::Format::eD16Unorm,
  463. vk::Format::eD16UnormS8Uint,
  464. vk::Format::eD24UnormS8Uint,
  465. vk::Format::eD32SfloatS8Uint,
  466. vk::Format::eBc1RgbaUnormBlock,
  467. vk::Format::eBc2UnormBlock,
  468. vk::Format::eBc3UnormBlock,
  469. vk::Format::eBc4UnormBlock,
  470. vk::Format::eBc5UnormBlock,
  471. vk::Format::eBc5SnormBlock,
  472. vk::Format::eBc7UnormBlock,
  473. vk::Format::eBc6HUfloatBlock,
  474. vk::Format::eBc6HSfloatBlock,
  475. vk::Format::eBc1RgbaSrgbBlock,
  476. vk::Format::eBc2SrgbBlock,
  477. vk::Format::eBc3SrgbBlock,
  478. vk::Format::eBc7SrgbBlock,
  479. vk::Format::eAstc4x4SrgbBlock,
  480. vk::Format::eAstc8x8SrgbBlock,
  481. vk::Format::eAstc8x5SrgbBlock,
  482. vk::Format::eAstc5x4SrgbBlock,
  483. vk::Format::eAstc5x5UnormBlock,
  484. vk::Format::eAstc5x5SrgbBlock,
  485. vk::Format::eAstc10x8UnormBlock,
  486. vk::Format::eAstc10x8SrgbBlock,
  487. vk::Format::eAstc6x6UnormBlock,
  488. vk::Format::eAstc6x6SrgbBlock,
  489. vk::Format::eAstc10x10UnormBlock,
  490. vk::Format::eAstc10x10SrgbBlock,
  491. vk::Format::eAstc12x12UnormBlock,
  492. vk::Format::eAstc12x12SrgbBlock,
  493. vk::Format::eAstc8x6UnormBlock,
  494. vk::Format::eAstc8x6SrgbBlock,
  495. vk::Format::eAstc6x5UnormBlock,
  496. vk::Format::eAstc6x5SrgbBlock,
  497. vk::Format::eE5B9G9R9UfloatPack32};
  498. std::unordered_map<vk::Format, vk::FormatProperties> format_properties;
  499. for (const auto format : formats) {
  500. format_properties.emplace(format, physical.getFormatProperties(format, dldi));
  501. }
  502. return format_properties;
  503. }
  504. } // namespace Vulkan