refactor(cleanup): fill gpu model & fix layout widths

This commit is contained in:
PancakeTAS 2025-12-23 20:08:08 +01:00
parent 2a392d6659
commit fb596e3c0a
No known key found for this signature in database
9 changed files with 130 additions and 21 deletions

View file

@ -2,7 +2,8 @@ find_package(Qt6 REQUIRED COMPONENTS Quick)
set(UI_SOURCES set(UI_SOURCES
"src/backend.cpp" "src/backend.cpp"
"src/main.cpp") "src/main.cpp"
"src/utils.cpp")
set(UI_RESOURCES set(UI_RESOURCES
"rsc/panes/CenteredDialog.qml" "rsc/panes/CenteredDialog.qml"
@ -31,5 +32,6 @@ target_compile_options(lsfg-vk-ui PRIVATE
-Wno-unsafe-buffer-usage) -Wno-unsafe-buffer-usage)
target_link_libraries(lsfg-vk-ui target_link_libraries(lsfg-vk-ui
PUBLIC lsfg-vk-common PRIVATE lsfg-vk-common
PRIVATE lsfg-vk-backend
PRIVATE Qt6::Quick) PRIVATE Qt6::Quick)

View file

@ -110,6 +110,8 @@ ApplicationWindow {
description: "Change the location of Lossless.dll" description: "Change the location of Lossless.dll"
FileEdit { FileEdit {
Layout.fillWidth: true
title: "Select Lossless.dll" title: "Select Lossless.dll"
filter: "Dynamic Link Library Files (*.dll)" filter: "Dynamic Link Library Files (*.dll)"
@ -123,6 +125,8 @@ ApplicationWindow {
description: "Allow acceleration through half-precision" description: "Allow acceleration through half-precision"
CheckBox { CheckBox {
Layout.alignment: Qt.AlignRight
checked: backend.allow_fp16 checked: backend.allow_fp16
onToggled: backend.allow_fp16 = checked onToggled: backend.allow_fp16 = checked
} }
@ -138,6 +142,8 @@ ApplicationWindow {
description: "Control the amount of generated frames" description: "Control the amount of generated frames"
SpinBox { SpinBox {
Layout.alignment: Qt.AlignRight
from: 2 from: 2
to: 100 to: 100
@ -151,6 +157,8 @@ ApplicationWindow {
description: "Lower the internal motion estimation resolution" description: "Lower the internal motion estimation resolution"
FlowSlider { FlowSlider {
Layout.fillWidth: true
from: 0.25 from: 0.25
to: 1.00 to: 1.00
@ -164,6 +172,8 @@ ApplicationWindow {
description: "Use a significantly lighter frame generation modeln" description: "Use a significantly lighter frame generation modeln"
CheckBox { CheckBox {
Layout.alignment: Qt.AlignRight
checked: backend.performance_mode checked: backend.performance_mode
onToggled: backend.performance_mode = checked onToggled: backend.performance_mode = checked
} }
@ -174,8 +184,9 @@ ApplicationWindow {
description: "Change how frames are presented to the display" description: "Change how frames are presented to the display"
ComboBox { ComboBox {
model: ["None"] Layout.fillWidth: true
model: ["None"]
currentValue: backend.pacing_mode currentValue: backend.pacing_mode
onActivated: (index) => backend.pacing_mode = model[index] onActivated: (index) => backend.pacing_mode = model[index]
} }
@ -186,8 +197,9 @@ ApplicationWindow {
description: "Select which GPU to use for frame generation" description: "Select which GPU to use for frame generation"
ComboBox { ComboBox {
model: ["Default"] Layout.fillWidth: true
model: backend.gpus
currentValue: backend.gpu currentValue: backend.gpu
onActivated: (index) => backend.gpu = model[index] onActivated: (index) => backend.gpu = model[index]
} }

View file

@ -5,30 +5,48 @@ import QtQuick.Layouts
RowLayout { RowLayout {
property string title property string title
property string description property string description
default property alias content: inner.children
id: root id: root
spacing: 12 spacing: 12
height: 32
ColumnLayout { Item {
spacing: 0 Layout.fillWidth: true
Layout.fillHeight: true
clip: true
Label { ColumnLayout {
text: root.title anchors.fill: parent
font.bold: true spacing: 0
}
Label { Label {
text: root.description text: root.title
color: Qt.rgba( font.bold: true
palette.text.r, }
palette.text.g,
palette.text.b, Label {
0.7 text: root.description
) color: Qt.rgba(
palette.text.r,
palette.text.g,
palette.text.b,
0.7
)
}
} }
} }
Item { Item {
Layout.fillWidth: true Layout.fillWidth: true
Layout.fillHeight: true
ColumnLayout {
anchors.fill: parent
spacing: 0
id: inner
}
} }
} }

View file

@ -14,7 +14,6 @@ RowLayout {
TextField { TextField {
Layout.fillWidth: true; Layout.fillWidth: true;
Layout.maximumWidth: 450;
text: root.text text: root.text
onEditingFinished: root.update(text) onEditingFinished: root.update(text)

View file

@ -13,7 +13,6 @@ RowLayout {
Slider { Slider {
Layout.fillWidth: true; Layout.fillWidth: true;
Layout.maximumWidth: 450;
value: root.value value: root.value
from: root.from from: root.from

View file

@ -1,4 +1,5 @@
#include "backend.hpp" #include "backend.hpp"
#include "utils.hpp"
#include "lsfg-vk-common/configuration/config.hpp" #include "lsfg-vk-common/configuration/config.hpp"
#include <QStringListModel> #include <QStringListModel>
@ -10,6 +11,7 @@
#include <iostream> #include <iostream>
#include <thread> #include <thread>
using namespace lsfgvk;
using namespace lsfgvk::ui; using namespace lsfgvk::ui;
Backend::Backend() { Backend::Backend() {
@ -29,6 +31,9 @@ Backend::Backend() {
this->m_global = config.global(); this->m_global = config.global();
this->m_profiles = config.profiles(); this->m_profiles = config.profiles();
// create gpu list
this->m_gpu_list = ui::getAvailableGPUs();
// create profile list model // create profile list model
QStringList profiles; // NOLINT (IWYU) QStringList profiles; // NOLINT (IWYU)
for (const auto& profile : this->m_profiles) for (const auto& profile : this->m_profiles)

View file

@ -6,6 +6,7 @@
#include <QStringListModel> #include <QStringListModel>
#include <QString> #include <QString>
#include <atomic> #include <atomic>
#include <qstringlistmodel.h>
#include <utility> #include <utility>
#define getters public #define getters public
@ -17,6 +18,7 @@ namespace lsfgvk::ui {
class Backend : public QObject { class Backend : public QObject {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QStringList gpus READ calculateGPUList NOTIFY refreshUI)
Q_PROPERTY(QStringListModel* profiles READ calculateProfileListModel NOTIFY refreshUI) Q_PROPERTY(QStringListModel* profiles READ calculateProfileListModel NOTIFY refreshUI)
Q_PROPERTY(int profile_index READ getProfileIndex WRITE profileSelected NOTIFY refreshUI) Q_PROPERTY(int profile_index READ getProfileIndex WRITE profileSelected NOTIFY refreshUI)
Q_PROPERTY(bool available READ isValidProfileIndex NOTIFY refreshUI) Q_PROPERTY(bool available READ isValidProfileIndex NOTIFY refreshUI)
@ -34,6 +36,10 @@ namespace lsfgvk::ui {
explicit Backend(); explicit Backend();
getters: getters:
[[nodiscard]] QStringList calculateGPUList() const {
return this->m_gpu_list;
}
[[nodiscard]] QStringListModel* calculateProfileListModel() const { [[nodiscard]] QStringListModel* calculateProfileListModel() const {
return this->m_profile_list_model; return this->m_profile_list_model;
} }
@ -132,7 +138,7 @@ namespace lsfgvk::ui {
} }
void gpuUpdated(const QString& gpu) { void gpuUpdated(const QString& gpu) {
VALIDATE_AND_GET_PROFILE() VALIDATE_AND_GET_PROFILE()
if (gpu.trimmed().isEmpty()) if (gpu.trimmed().isEmpty() || gpu == "Default")
conf.gpu = std::nullopt; conf.gpu = std::nullopt;
else else
conf.gpu.emplace(gpu.toStdString()); conf.gpu.emplace(gpu.toStdString());
@ -183,6 +189,7 @@ namespace lsfgvk::ui {
ls::GlobalConf m_global; ls::GlobalConf m_global;
std::vector<ls::GameConf> m_profiles; std::vector<ls::GameConf> m_profiles;
QStringList m_gpu_list;
QStringListModel* m_profile_list_model; QStringListModel* m_profile_list_model;
int m_profile_index{-1}; int m_profile_index{-1};

55
lsfg-vk-ui/src/utils.cpp Normal file
View file

@ -0,0 +1,55 @@
#include "utils.hpp"
#include "lsfg-vk-backend/lsfgvk.hpp"
#include <QStringList>
#include <QString>
#include <algorithm>
#include <optional>
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
using namespace lsfgvk;
using namespace lsfgvk::ui;
QStringList ui::getAvailableGPUs() { // NOLINT (IWYU)
// list of found GPUs and their optional PCI IDs
std::vector<std::pair<std::string, std::optional<std::string>>> gpus{};
// create a backend to query all GPUs
try {
const backend::DevicePicker picker{[&gpus](
const std::string& deviceName,
std::pair<const std::string&, const std::string&>,
const std::optional<std::string>& pci
) {
gpus.emplace_back(deviceName, pci);
return false; // always fail
}};
const backend::Instance instance{picker, "/non/existent/path", false};
throw std::runtime_error("???");
} catch (const backend::error&) { // NOLINT
// expected
}
// build the frontend list
QStringList list{"Default"}; // NOLINT (IWYU)
for (const auto& gpu : gpus) {
// check if GPU is in list more than once
auto count = std::count_if(gpus.begin(), gpus.end(),
[&gpu](const auto& other) {
return other.first == gpu.first;
}
);
// add pci id to distinguish, otherwise add just the name
if (count > 1 && gpu.second.has_value())
list.append(QString::fromStdString(*gpu.second));
else
list.append(QString::fromStdString(gpu.first));
}
return list;
}

12
lsfg-vk-ui/src/utils.hpp Normal file
View file

@ -0,0 +1,12 @@
#pragma once
#include <QStringList>
namespace lsfgvk::ui {
/// get the list of available GPUs, automatically
/// switching to PCI IDs if there are duplicates
/// @return list of available GPUs
QStringList getAvailableGPUs();
}