2023-05-28 23:52:12 +02:00
|
|
|
// SPDX-FileCopyrightText: 2023 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-05-29 05:24:08 +02:00
|
|
|
#include <utility>
|
2023-05-28 23:46:02 +02:00
|
|
|
#include <vector>
|
2023-08-02 00:04:39 +02:00
|
|
|
|
|
|
|
#include "yuzu/qt_common.h"
|
|
|
|
|
2023-05-28 23:46:02 +02:00
|
|
|
#include "common/dynamic_library.h"
|
2023-05-29 05:24:08 +02:00
|
|
|
#include "common/logging/log.h"
|
2023-06-15 22:17:19 +02:00
|
|
|
#include "video_core/vulkan_common/vulkan_device.h"
|
2023-05-28 23:46:02 +02:00
|
|
|
#include "video_core/vulkan_common/vulkan_instance.h"
|
|
|
|
#include "video_core/vulkan_common/vulkan_library.h"
|
|
|
|
#include "video_core/vulkan_common/vulkan_surface.h"
|
|
|
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
2023-06-15 22:17:19 +02:00
|
|
|
#include "vulkan/vulkan_core.h"
|
2023-05-28 23:46:02 +02:00
|
|
|
#include "yuzu/vk_device_info.h"
|
|
|
|
|
2023-05-29 05:24:08 +02:00
|
|
|
class QWindow;
|
|
|
|
|
2023-05-28 23:46:02 +02:00
|
|
|
namespace VkDeviceInfo {
|
|
|
|
Record::Record(std::string_view name_, const std::vector<VkPresentModeKHR>& vsync_modes_,
|
2023-06-15 22:17:19 +02:00
|
|
|
bool has_broken_compute_)
|
|
|
|
: name{name_}, vsync_support{vsync_modes_}, has_broken_compute{has_broken_compute_} {}
|
2023-05-28 23:46:02 +02:00
|
|
|
|
|
|
|
Record::~Record() = default;
|
|
|
|
|
|
|
|
void PopulateRecords(std::vector<Record>& records, QWindow* window) try {
|
|
|
|
using namespace Vulkan;
|
|
|
|
|
2023-07-01 08:35:36 +02:00
|
|
|
// Create a test window with a Vulkan surface type for checking present modes.
|
|
|
|
QWindow test_window(window);
|
|
|
|
test_window.setSurfaceType(QWindow::VulkanSurface);
|
|
|
|
auto wsi = QtCommon::GetWindowSystemInfo(&test_window);
|
2023-05-28 23:46:02 +02:00
|
|
|
|
|
|
|
vk::InstanceDispatch dld;
|
|
|
|
const auto library = OpenLibrary();
|
|
|
|
const vk::Instance instance = CreateInstance(*library, dld, VK_API_VERSION_1_1, wsi.type);
|
|
|
|
const std::vector<VkPhysicalDevice> physical_devices = instance.EnumeratePhysicalDevices();
|
|
|
|
vk::SurfaceKHR surface = CreateSurface(instance, wsi);
|
|
|
|
|
|
|
|
records.clear();
|
|
|
|
records.reserve(physical_devices.size());
|
|
|
|
for (const VkPhysicalDevice device : physical_devices) {
|
|
|
|
const auto physical_device = vk::PhysicalDevice(device, dld);
|
|
|
|
const std::string name = physical_device.GetProperties().deviceName;
|
|
|
|
const std::vector<VkPresentModeKHR> present_modes =
|
|
|
|
physical_device.GetSurfacePresentModesKHR(*surface);
|
|
|
|
|
|
|
|
VkPhysicalDeviceDriverProperties driver_properties{};
|
|
|
|
driver_properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES;
|
|
|
|
driver_properties.pNext = nullptr;
|
|
|
|
VkPhysicalDeviceProperties2 properties{};
|
|
|
|
properties.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
|
|
|
|
properties.pNext = &driver_properties;
|
|
|
|
dld.vkGetPhysicalDeviceProperties2(physical_device, &properties);
|
|
|
|
|
2023-06-15 22:17:19 +02:00
|
|
|
bool has_broken_compute{Vulkan::Device::CheckBrokenCompute(
|
|
|
|
driver_properties.driverID, properties.properties.driverVersion)};
|
|
|
|
|
|
|
|
records.push_back(VkDeviceInfo::Record(name, present_modes, has_broken_compute));
|
2023-05-28 23:46:02 +02:00
|
|
|
}
|
|
|
|
} catch (const Vulkan::vk::Exception& exception) {
|
|
|
|
LOG_ERROR(Frontend, "Failed to enumerate devices with error: {}", exception.what());
|
|
|
|
}
|
|
|
|
} // namespace VkDeviceInfo
|