mirror of
https://github.com/PancakeTAS/lsfg-vk.git
synced 2026-02-09 07:15:55 +00:00
refactor(cleanup): fill gpu model & fix layout widths
This commit is contained in:
parent
2a392d6659
commit
fb596e3c0a
9 changed files with 130 additions and 21 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ RowLayout {
|
|||
|
||||
TextField {
|
||||
Layout.fillWidth: true;
|
||||
Layout.maximumWidth: 450;
|
||||
|
||||
text: root.text
|
||||
onEditingFinished: root.update(text)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ RowLayout {
|
|||
|
||||
Slider {
|
||||
Layout.fillWidth: true;
|
||||
Layout.maximumWidth: 450;
|
||||
|
||||
value: root.value
|
||||
from: root.from
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "backend.hpp"
|
||||
#include "utils.hpp"
|
||||
#include "lsfg-vk-common/configuration/config.hpp"
|
||||
|
||||
#include <QStringListModel>
|
||||
|
|
@ -10,6 +11,7 @@
|
|||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
#include <QStringListModel>
|
||||
#include <QString>
|
||||
#include <atomic>
|
||||
#include <qstringlistmodel.h>
|
||||
#include <utility>
|
||||
|
||||
#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<ls::GameConf> m_profiles;
|
||||
|
||||
QStringList m_gpu_list;
|
||||
QStringListModel* m_profile_list_model;
|
||||
int m_profile_index{-1};
|
||||
|
||||
|
|
|
|||
55
lsfg-vk-ui/src/utils.cpp
Normal file
55
lsfg-vk-ui/src/utils.cpp
Normal 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
12
lsfg-vk-ui/src/utils.hpp
Normal 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();
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue