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; return vkValidationGpu;
} }
void setGpuId(s32 selectedGpuId) {
gpuId = selectedGpuId;
}
void setScreenWidth(u32 width) { void setScreenWidth(u32 width) {
screenWidth = width; screenWidth = width;
} }
@ -451,6 +455,7 @@ void setDefaultValues() {
vkValidation = false; vkValidation = false;
rdocEnable = false; rdocEnable = false;
m_language = 1; m_language = 1;
gpuId = -1;
} }
} // namespace Config } // namespace Config

View File

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

View File

@ -16,6 +16,7 @@
#include "game_install_dialog.h" #include "game_install_dialog.h"
#include "main_window.h" #include "main_window.h"
#include "settings_dialog.h" #include "settings_dialog.h"
#include "video_core/renderer_vulkan/vk_instance.h"
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) { MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
ui->setupUi(this); ui->setupUi(this);
@ -39,6 +40,7 @@ bool MainWindow::Init() {
CreateConnects(); CreateConnects();
SetLastUsedTheme(); SetLastUsedTheme();
SetLastIconSizeBullet(); SetLastIconSizeBullet();
GetPhysicalDevices();
// show ui // show ui
setMinimumSize(350, minimumSizeHint().height()); setMinimumSize(350, minimumSizeHint().height());
setWindowTitle(QString::fromStdString("shadPS4 v" + std::string(Common::VERSION))); 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() { void MainWindow::CreateConnects() {
connect(this, &MainWindow::WindowResized, this, &MainWindow::HandleResize); connect(this, &MainWindow::WindowResized, this, &MainWindow::HandleResize);
connect(ui->mw_searchbar, &QLineEdit::textChanged, this, &MainWindow::SearchGameTable); connect(ui->mw_searchbar, &QLineEdit::textChanged, this, &MainWindow::SearchGameTable);
@ -187,7 +202,7 @@ void MainWindow::CreateConnects() {
&MainWindow::StartGame); &MainWindow::StartGame);
connect(ui->settingsButton, &QPushButton::clicked, this, [this]() { connect(ui->settingsButton, &QPushButton::clicked, this, [this]() {
auto settingsDialog = new SettingsDialog(this); auto settingsDialog = new SettingsDialog(m_physical_devices, this);
settingsDialog->exec(); settingsDialog->exec();
}); });

View File

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

View File

@ -4,13 +4,20 @@
#include "settings_dialog.h" #include "settings_dialog.h"
#include "ui_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->setupUi(this);
ui->tabWidgetSettings->setUsesScrollButtons(false); ui->tabWidgetSettings->setUsesScrollButtons(false);
const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir); const auto config_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
ui->buttonBox->button(QDialogButtonBox::StandardButton::Close)->setFocus(); 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(); LoadValuesFromConfig();
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close);
@ -40,7 +47,10 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Se
// GPU TAB // 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, connect(ui->widthSpinBox, &QSpinBox::valueChanged, this,
[](int val) { Config::setScreenWidth(val); }); [](int val) { Config::setScreenWidth(val); });
@ -98,6 +108,7 @@ SettingsDialog::SettingsDialog(QWidget* parent) : QDialog(parent), ui(new Ui::Se
void SettingsDialog::LoadValuesFromConfig() { void SettingsDialog::LoadValuesFromConfig() {
ui->consoleLanguageComboBox->setCurrentIndex(Config::GetLanguage()); ui->consoleLanguageComboBox->setCurrentIndex(Config::GetLanguage());
ui->graphicsAdapterBox->setCurrentIndex(Config::getGpuId() + 1);
ui->widthSpinBox->setValue(Config::getScreenWidth()); ui->widthSpinBox->setValue(Config::getScreenWidth());
ui->heightSpinBox->setValue(Config::getScreenHeight()); ui->heightSpinBox->setValue(Config::getScreenHeight());
ui->vblankSpinBox->setValue(Config::vblankDiv()); ui->vblankSpinBox->setValue(Config::vblankDiv());

View File

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