From fb596e3c0ae760c66c0bc2efbe1ff525554fdfe8 Mon Sep 17 00:00:00 2001 From: PancakeTAS Date: Tue, 23 Dec 2025 20:08:08 +0100 Subject: [PATCH] refactor(cleanup): fill gpu model & fix layout widths --- lsfg-vk-ui/CMakeLists.txt | 6 ++- lsfg-vk-ui/rsc/UI.qml | 16 +++++++- lsfg-vk-ui/rsc/panes/GroupEntry.qml | 46 +++++++++++++++------- lsfg-vk-ui/rsc/widgets/FileEdit.qml | 1 - lsfg-vk-ui/rsc/widgets/FlowSlider.qml | 1 - lsfg-vk-ui/src/backend.cpp | 5 +++ lsfg-vk-ui/src/backend.hpp | 9 ++++- lsfg-vk-ui/src/utils.cpp | 55 +++++++++++++++++++++++++++ lsfg-vk-ui/src/utils.hpp | 12 ++++++ 9 files changed, 130 insertions(+), 21 deletions(-) create mode 100644 lsfg-vk-ui/src/utils.cpp create mode 100644 lsfg-vk-ui/src/utils.hpp diff --git a/lsfg-vk-ui/CMakeLists.txt b/lsfg-vk-ui/CMakeLists.txt index 3b7b8bf..893dbb2 100644 --- a/lsfg-vk-ui/CMakeLists.txt +++ b/lsfg-vk-ui/CMakeLists.txt @@ -2,7 +2,8 @@ find_package(Qt6 REQUIRED COMPONENTS Quick) set(UI_SOURCES "src/backend.cpp" - "src/main.cpp") + "src/main.cpp" + "src/utils.cpp") set(UI_RESOURCES "rsc/panes/CenteredDialog.qml" @@ -31,5 +32,6 @@ target_compile_options(lsfg-vk-ui PRIVATE -Wno-unsafe-buffer-usage) target_link_libraries(lsfg-vk-ui - PUBLIC lsfg-vk-common + PRIVATE lsfg-vk-common + PRIVATE lsfg-vk-backend PRIVATE Qt6::Quick) diff --git a/lsfg-vk-ui/rsc/UI.qml b/lsfg-vk-ui/rsc/UI.qml index 221f0b9..fb92ae2 100644 --- a/lsfg-vk-ui/rsc/UI.qml +++ b/lsfg-vk-ui/rsc/UI.qml @@ -110,6 +110,8 @@ ApplicationWindow { description: "Change the location of Lossless.dll" FileEdit { + Layout.fillWidth: true + title: "Select Lossless.dll" filter: "Dynamic Link Library Files (*.dll)" @@ -123,6 +125,8 @@ ApplicationWindow { description: "Allow acceleration through half-precision" CheckBox { + Layout.alignment: Qt.AlignRight + checked: backend.allow_fp16 onToggled: backend.allow_fp16 = checked } @@ -138,6 +142,8 @@ ApplicationWindow { description: "Control the amount of generated frames" SpinBox { + Layout.alignment: Qt.AlignRight + from: 2 to: 100 @@ -151,6 +157,8 @@ ApplicationWindow { description: "Lower the internal motion estimation resolution" FlowSlider { + Layout.fillWidth: true + from: 0.25 to: 1.00 @@ -164,6 +172,8 @@ ApplicationWindow { description: "Use a significantly lighter frame generation modeln" CheckBox { + Layout.alignment: Qt.AlignRight + checked: backend.performance_mode onToggled: backend.performance_mode = checked } @@ -174,8 +184,9 @@ ApplicationWindow { description: "Change how frames are presented to the display" ComboBox { - model: ["None"] + Layout.fillWidth: true + model: ["None"] currentValue: backend.pacing_mode onActivated: (index) => backend.pacing_mode = model[index] } @@ -186,8 +197,9 @@ ApplicationWindow { description: "Select which GPU to use for frame generation" ComboBox { - model: ["Default"] + Layout.fillWidth: true + model: backend.gpus currentValue: backend.gpu onActivated: (index) => backend.gpu = model[index] } diff --git a/lsfg-vk-ui/rsc/panes/GroupEntry.qml b/lsfg-vk-ui/rsc/panes/GroupEntry.qml index c58983d..6162bbc 100644 --- a/lsfg-vk-ui/rsc/panes/GroupEntry.qml +++ b/lsfg-vk-ui/rsc/panes/GroupEntry.qml @@ -5,30 +5,48 @@ import QtQuick.Layouts RowLayout { property string title property string description + default property alias content: inner.children id: root spacing: 12 + height: 32 - ColumnLayout { - spacing: 0 + Item { + Layout.fillWidth: true + Layout.fillHeight: true + clip: true - Label { - text: root.title - font.bold: true - } + ColumnLayout { + anchors.fill: parent + spacing: 0 - Label { - text: root.description - color: Qt.rgba( - palette.text.r, - palette.text.g, - palette.text.b, - 0.7 - ) + Label { + text: root.title + font.bold: true + } + + Label { + text: root.description + color: Qt.rgba( + palette.text.r, + palette.text.g, + palette.text.b, + 0.7 + ) + } } } Item { Layout.fillWidth: true + Layout.fillHeight: true + + ColumnLayout { + anchors.fill: parent + spacing: 0 + id: inner + } } + + } diff --git a/lsfg-vk-ui/rsc/widgets/FileEdit.qml b/lsfg-vk-ui/rsc/widgets/FileEdit.qml index bedf7bd..0ae580f 100644 --- a/lsfg-vk-ui/rsc/widgets/FileEdit.qml +++ b/lsfg-vk-ui/rsc/widgets/FileEdit.qml @@ -14,7 +14,6 @@ RowLayout { TextField { Layout.fillWidth: true; - Layout.maximumWidth: 450; text: root.text onEditingFinished: root.update(text) diff --git a/lsfg-vk-ui/rsc/widgets/FlowSlider.qml b/lsfg-vk-ui/rsc/widgets/FlowSlider.qml index ef0a276..9830c01 100644 --- a/lsfg-vk-ui/rsc/widgets/FlowSlider.qml +++ b/lsfg-vk-ui/rsc/widgets/FlowSlider.qml @@ -13,7 +13,6 @@ RowLayout { Slider { Layout.fillWidth: true; - Layout.maximumWidth: 450; value: root.value from: root.from diff --git a/lsfg-vk-ui/src/backend.cpp b/lsfg-vk-ui/src/backend.cpp index 2f11337..01dbe25 100644 --- a/lsfg-vk-ui/src/backend.cpp +++ b/lsfg-vk-ui/src/backend.cpp @@ -1,4 +1,5 @@ #include "backend.hpp" +#include "utils.hpp" #include "lsfg-vk-common/configuration/config.hpp" #include @@ -10,6 +11,7 @@ #include #include +using namespace lsfgvk; using namespace lsfgvk::ui; Backend::Backend() { @@ -29,6 +31,9 @@ Backend::Backend() { this->m_global = config.global(); this->m_profiles = config.profiles(); + // create gpu list + this->m_gpu_list = ui::getAvailableGPUs(); + // create profile list model QStringList profiles; // NOLINT (IWYU) for (const auto& profile : this->m_profiles) diff --git a/lsfg-vk-ui/src/backend.hpp b/lsfg-vk-ui/src/backend.hpp index d8b4192..8baaba9 100644 --- a/lsfg-vk-ui/src/backend.hpp +++ b/lsfg-vk-ui/src/backend.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #define getters public @@ -17,6 +18,7 @@ namespace lsfgvk::ui { class Backend : public QObject { Q_OBJECT + Q_PROPERTY(QStringList gpus READ calculateGPUList NOTIFY refreshUI) Q_PROPERTY(QStringListModel* profiles READ calculateProfileListModel NOTIFY refreshUI) Q_PROPERTY(int profile_index READ getProfileIndex WRITE profileSelected NOTIFY refreshUI) Q_PROPERTY(bool available READ isValidProfileIndex NOTIFY refreshUI) @@ -34,6 +36,10 @@ namespace lsfgvk::ui { explicit Backend(); getters: + [[nodiscard]] QStringList calculateGPUList() const { + return this->m_gpu_list; + } + [[nodiscard]] QStringListModel* calculateProfileListModel() const { return this->m_profile_list_model; } @@ -132,7 +138,7 @@ namespace lsfgvk::ui { } void gpuUpdated(const QString& gpu) { VALIDATE_AND_GET_PROFILE() - if (gpu.trimmed().isEmpty()) + if (gpu.trimmed().isEmpty() || gpu == "Default") conf.gpu = std::nullopt; else conf.gpu.emplace(gpu.toStdString()); @@ -183,6 +189,7 @@ namespace lsfgvk::ui { ls::GlobalConf m_global; std::vector m_profiles; + QStringList m_gpu_list; QStringListModel* m_profile_list_model; int m_profile_index{-1}; diff --git a/lsfg-vk-ui/src/utils.cpp b/lsfg-vk-ui/src/utils.cpp new file mode 100644 index 0000000..373ab87 --- /dev/null +++ b/lsfg-vk-ui/src/utils.cpp @@ -0,0 +1,55 @@ +#include "utils.hpp" +#include "lsfg-vk-backend/lsfgvk.hpp" + +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace lsfgvk; +using namespace lsfgvk::ui; + +QStringList ui::getAvailableGPUs() { // NOLINT (IWYU) + // list of found GPUs and their optional PCI IDs + std::vector>> gpus{}; + + // create a backend to query all GPUs + try { + const backend::DevicePicker picker{[&gpus]( + const std::string& deviceName, + std::pair, + const std::optional& 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; +} diff --git a/lsfg-vk-ui/src/utils.hpp b/lsfg-vk-ui/src/utils.hpp new file mode 100644 index 0000000..3a5d504 --- /dev/null +++ b/lsfg-vk-ui/src/utils.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include + +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(); + +}