qt-gui: Added GPU device selection functionality (#399)

* qt-gui: Added GPU device selection functionality

* Getting list of GPU only when application starts

* Fixed formatting

* Fixed formatting

* Fixed formatting

* Added warning when GPU doesn't support API version.

* Changed Unsupported Vulkan Version warning

* Removed unused size checking on GetPhysicalDevices

The method is only being called once so this doesn't make sense. It was some left over of me trying to get this done some other way.

* Fix formatting

* Fix formatting

* SettingsDialog: Passing physical devices as span

* Fixed formatting
This commit is contained in:
Samuel Fontes 2024-08-13 18:21:06 -03:00 committed by GitHub
parent d8b9d82ffa
commit ad3b6c793c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 40 additions and 4 deletions

View File

@ -124,6 +124,10 @@ bool vkValidationGpuEnabled() {
return vkValidationGpu;
}
void setGpuId(s32 selectedGpuId) {
gpuId = selectedGpuId;
}
void setScreenWidth(u32 width) {
screenWidth = width;
}
@ -451,6 +455,7 @@ void setDefaultValues() {
vkValidation = false;
rdocEnable = false;
m_language = 1;
gpuId = -1;
}
} // namespace Config

View File

@ -36,6 +36,7 @@ void setNullGpu(bool enable);
void setDumpShaders(bool enable);
void setDumpPM4(bool enable);
void setVblankDiv(u32 value);
void setGpuId(s32 selectedGpuId);
void setScreenWidth(u32 width);
void setScreenHeight(u32 height);
void setFullscreenMode(bool enable);

View File

@ -16,6 +16,7 @@
#include "game_install_dialog.h"
#include "main_window.h"
#include "settings_dialog.h"
#include "video_core/renderer_vulkan/vk_instance.h"
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this);
@ -39,6 +40,7 @@ bool MainWindow::Init() {
CreateConnects();
SetLastUsedTheme();
SetLastIconSizeBullet();
GetPhysicalDevices();
// show ui
setMinimumSize(350, minimumSizeHint().height());
setWindowTitle(QString::fromStdString("shadPS4 v" + std::string(Common::VERSION)));
@ -158,6 +160,19 @@ void MainWindow::LoadGameLists() {
}
}
void MainWindow::GetPhysicalDevices() {
Vulkan::Instance instance(false, false);
auto physical_devices = instance.GetPhysicalDevices();
for (const vk::PhysicalDevice physical_device : physical_devices) {
auto prop = physical_device.getProperties();
QString name = QString::fromUtf8(prop.deviceName, -1);
if (prop.apiVersion < Vulkan::TargetVulkanApiVersion) {
name += " * Unsupported Vulkan Version";
}
m_physical_devices.push_back(name);
}
}
void MainWindow::CreateConnects() {
connect(this, &MainWindow::WindowResized, this, &MainWindow::HandleResize);
connect(ui->mw_searchbar, &QLineEdit::textChanged, this, &MainWindow::SearchGameTable);
@ -187,7 +202,7 @@ void MainWindow::CreateConnects() {
&MainWindow::StartGame);
connect(ui->settingsButton, &QPushButton::clicked, this, [this]() {
auto settingsDialog = new SettingsDialog(this);
auto settingsDialog = new SettingsDialog(m_physical_devices, this);
settingsDialog->exec();
});

View File

@ -54,6 +54,7 @@ private:
void CreateActions();
void CreateRecentGameActions();
void CreateDockWindows();
void GetPhysicalDevices();
void LoadGameLists();
void CreateConnects();
void SetLastUsedTheme();
@ -79,6 +80,8 @@ private:
QScopedPointer<ElfViewer> m_elf_viewer;
// Status Bar.
QScopedPointer<QStatusBar> statusBar;
// Available GPU devices
std::vector<QString> m_physical_devices;
PSF psf;

View File

@ -4,13 +4,20 @@
#include "settings_dialog.h"
#include "ui_settings_dialog.h"
SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::SettingsDialog) {
SettingsDialog::SettingsDialog(std::span<const QString> physical_devices, QWidget* parent)
: QDialog(parent), ui(new Ui::SettingsDialog) {
ui->setupUi(this);
ui->tabWidgetSettings->setUsesScrollButtons(false);
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
ui->buttonBox->button(QDialogButtonBox::StandardButton::Close)->setFocus();
// Add list of available GPUs
ui->graphicsAdapterBox->addItem("Auto Select"); // -1, auto selection
for (const auto& device : physical_devices) {
ui->graphicsAdapterBox->addItem(device);
}
LoadValuesFromConfig();
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
@ -40,7 +47,10 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Se
// GPU TAB
{
// TODO: Implement graphics device changing
// First options is auto selection -1, so gpuId on the GUI will always have to subtract 1
// when setting and add 1 when getting to select the correct gpu in Qt
connect(ui->graphicsAdapterBox, &QComboBox::currentIndexChanged, this,
[](int index) { Config::setGpuId(index - 1); });
connect(ui->widthSpinBox, &QSpinBox::valueChanged, this,
[](int val) { Config::setScreenWidth(val); });
@ -98,6 +108,7 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Se
void SettingsDialog::LoadValuesFromConfig() {
ui->consoleLanguageComboBox->setCurrentIndex(Config::GetLanguage());
ui->graphicsAdapterBox->setCurrentIndex(Config::getGpuId() + 1);
ui->widthSpinBox->setValue(Config::getScreenWidth());
ui->heightSpinBox->setValue(Config::getScreenHeight());
ui->vblankSpinBox->setValue(Config::vblankDiv());

View File

@ -3,6 +3,7 @@
#pragma once
#include <span>
#include <QDialog>
#include <QPushButton>
@ -16,7 +17,7 @@ class SettingsDialog;
class SettingsDialog : public QDialog {
Q_OBJECT
public:
explicit SettingsDialog(QWidget* parent = nullptr);
explicit SettingsDialog(std::span<const QString> physical_devices, QWidget* parent = nullptr);
~SettingsDialog();
int exec() override;