vk_device_info.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. auto wsi = QtCommon::GetWindowSystemInfo(&test_window);
  27. vk::InstanceDispatch dld;
  28. const auto library = OpenLibrary();
  29. const vk::Instance instance = CreateInstance(*library, dld, VK_API_VERSION_1_1, wsi.type);
  30. const std::vector<VkPhysicalDevice> physical_devices = instance.EnumeratePhysicalDevices();
  31. vk::SurfaceKHR surface = CreateSurface(instance, wsi);
  32. records.clear();
  33. records.reserve(physical_devices.size());
  34. for (const VkPhysicalDevice device : physical_devices) {
  35. const auto physical_device = vk::PhysicalDevice(device, dld);
  36. const std::string name = physical_device.GetProperties().deviceName;
  37. const std::vector<VkPresentModeKHR> present_modes =
  38. physical_device.GetSurfacePresentModesKHR(*surface);
  39. VkPhysicalDeviceDriverProperties driver_properties{};
  40. driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
  41. driver_properties.pNext = nullptr;
  42. VkPhysicalDeviceProperties2 properties{};
  43. properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
  44. properties.pNext = &driver_properties;
  45. dld.vkGetPhysicalDeviceProperties2(physical_device, &properties);
  46. bool has_broken_compute{Vulkan::Device::CheckBrokenCompute(
  47. driver_properties.driverID, properties.properties.driverVersion)};
  48. records.push_back(VkDeviceInfo::Record(name, present_modes, has_broken_compute));
  49. }
  50. } catch (const Vulkan::vk::Exception& exception) {
  51. LOG_ERROR(Frontend, "Failed to enumerate devices with error: {}", exception.what());
  52. }
  53. } // namespace VkDeviceInfo