vk_device_info.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // SPDX-FileCopyrightText: 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include <utility>
  4. #include <vector>
  5. #include "yuzu/qt_common.h"
  6. #include "common/dynamic_library.h"
  7. #include "common/logging/log.h"
  8. #include "video_core/vulkan_common/vulkan_device.h"
  9. #include "video_core/vulkan_common/vulkan_instance.h"
  10. #include "video_core/vulkan_common/vulkan_library.h"
  11. #include "video_core/vulkan_common/vulkan_surface.h"
  12. #include "video_core/vulkan_common/vulkan_wrapper.h"
  13. #include "vulkan/vulkan_core.h"
  14. #include "yuzu/vk_device_info.h"
  15. class QWindow;
  16. namespace VkDeviceInfo {
  17. Record::Record(std::string_view name_, const std::vector<VkPresentModeKHR>& vsync_modes_,
  18. bool has_broken_compute_)
  19. : name{name_}, vsync_support{vsync_modes_}, has_broken_compute{has_broken_compute_} {}
  20. Record::~Record() = default;
  21. void PopulateRecords(std::vector<Record>& records, QWindow* window) try {
  22. using namespace Vulkan;
  23. // Create a test window with a Vulkan surface type for checking present modes.
  24. QWindow test_window(window);
  25. test_window.setSurfaceType(QWindow::VulkanSurface);
  26. test_window.create();
  27. auto wsi = QtCommon::GetWindowSystemInfo(&test_window);
  28. vk::InstanceDispatch dld;
  29. const auto library = OpenLibrary();
  30. const vk::Instance instance = CreateInstance(*library, dld, VK_API_VERSION_1_1, wsi.type);
  31. const std::vector<VkPhysicalDevice> physical_devices = instance.EnumeratePhysicalDevices();
  32. vk::SurfaceKHR surface = CreateSurface(instance, wsi);
  33. records.clear();
  34. records.reserve(physical_devices.size());
  35. for (const VkPhysicalDevice device : physical_devices) {
  36. const auto physical_device = vk::PhysicalDevice(device, dld);
  37. const std::string name = physical_device.GetProperties().deviceName;
  38. const std::vector<VkPresentModeKHR> present_modes =
  39. physical_device.GetSurfacePresentModesKHR(*surface);
  40. VkPhysicalDeviceDriverProperties driver_properties{};
  41. driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
  42. driver_properties.pNext = nullptr;
  43. VkPhysicalDeviceProperties2 properties{};
  44. properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
  45. properties.pNext = &driver_properties;
  46. dld.vkGetPhysicalDeviceProperties2(physical_device, &properties);
  47. bool has_broken_compute{Vulkan::Device::CheckBrokenCompute(
  48. driver_properties.driverID, properties.properties.driverVersion)};
  49. records.push_back(VkDeviceInfo::Record(name, present_modes, has_broken_compute));
  50. }
  51. } catch (const Vulkan::vk::Exception& exception) {
  52. LOG_ERROR(Frontend, "Failed to enumerate devices with error: {}", exception.what());
  53. }
  54. } // namespace VkDeviceInfo