fix: add generic gpu vram support

This commit is contained in:
2026-07-03 12:28:54 +02:00
parent 9126b04b10
commit 562770595f
9 changed files with 163 additions and 14 deletions
+1
View File
@@ -17,6 +17,7 @@ JsonObject {
property bool showMemory: true
property bool showNetwork: true
property bool showStorage: true
property bool showVram: true
}
component Sizes: JsonObject {
readonly property int dateTimeWidth: 110
+1 -7
View File
@@ -9,31 +9,25 @@ import qs.Config
Singleton {
id: root
// Private properties
property real _downloadSpeed: 0
property real _downloadTotal: 0
// Initial readings for calculating totals
property real _initialRxBytes: 0
property real _initialTxBytes: 0
property bool _initialized: false
// Previous readings for calculating speed
property real _prevRxBytes: 0
property real _prevTimestamp: 0
property real _prevTxBytes: 0
property real _uploadSpeed: 0
property real _uploadTotal: 0
// History buffers for sparkline
readonly property CircularBuffer downloadBuffer: _downloadBuffer
// Current speeds in bytes per second
readonly property real downloadSpeed: _downloadSpeed
// Total bytes transferred since tracking started
readonly property real downloadTotal: _downloadTotal
readonly property int historyLength: 30
readonly property int historyLength: Config.dashboard.performance.showVram ? 70 : 30
property int refCount: 0
readonly property CircularBuffer uploadBuffer: _uploadBuffer
readonly property real uploadSpeed: _uploadSpeed
+1
View File
@@ -9,6 +9,7 @@ CustomRect {
readonly property color accent: DynamicColors.palette.m3tertiary
Layout.fillWidth: true
color: DynamicColors.tPalette.m3surfaceContainer
implicitHeight: layout.implicitHeight + Appearance.padding.large * 2
implicitWidth: layout.implicitWidth + Appearance.padding.extraLargeIncreased * 2
-3
View File
@@ -1,7 +1,6 @@
import QtQuick
import QtQuick.Layouts
import ZShell.Internal
import qs.Modules.Resources
import qs.Helpers
import qs.Components
import qs.Config
@@ -9,8 +8,6 @@ import qs.Config
CustomRect {
id: root
required property Wrapper wrapper
color: DynamicColors.tPalette.m3surfaceContainer
implicitHeight: 220
implicitWidth: 300
+89
View File
@@ -0,0 +1,89 @@
import QtQuick
import QtQuick.Layouts
import ZShell.Services
import qs.Components
import qs.Config
CustomRect {
id: root
readonly property color accent: DynamicColors.palette.m3tertiary
Layout.fillWidth: true
color: DynamicColors.tPalette.m3surfaceContainer
implicitHeight: layout.implicitHeight + Appearance.padding.large * 2
implicitWidth: layout.implicitWidth + Appearance.padding.extraLargeIncreased
radius: Appearance.rounding.medium
ServiceRef {
service: Gpu
}
ColumnLayout {
id: layout
anchors.centerIn: parent
spacing: Appearance.spacing.extraSmall
RowLayout {
Layout.leftMargin: -Appearance.padding.extraSmall
spacing: Appearance.spacing.small
MaterialIcon {
color: root.accent
fill: 1
text: "memory_alt"
}
CustomText {
text: qsTr("Video memory")
}
}
CircularProgress {
id: circularIndicator
Layout.alignment: Qt.AlignHCenter
Layout.topMargin: Appearance.spacing.large
fgColor: root.accent
implicitSize: usageColumn.implicitHeight + thickness + Appearance.padding.largeIncreased * 2
startAngle: -225
sweepAngle: 270
value: Gpu.memoryUsed / Gpu.memoryTotal
Behavior on clampedVal {
Anim {
}
}
ColumnLayout {
id: usageColumn
anchors.centerIn: parent
anchors.verticalCenterOffset: Appearance.padding.extraSmall
spacing: 0
CustomText {
Layout.alignment: Qt.AlignHCenter
color: root.accent
font.pointSize: Appearance.font.size.large
text: Math.round(circularIndicator.value * 100) + "%"
}
CustomText {
Layout.alignment: Qt.AlignHCenter
color: DynamicColors.palette.m3onSurfaceVariant
text: qsTr("Used")
}
}
}
CustomText {
Layout.alignment: Qt.AlignHCenter
text: {
const fmt = UsageFmt.formatKib(Gpu.memoryUsed, Gpu.memoryTotal);
return `${fmt.value.toFixed(1)} / ${Math.floor(fmt.total)} ${fmt.unit}`;
}
}
}
}
+21 -4
View File
@@ -74,7 +74,7 @@ Item {
RowLayout {
spacing: Appearance.spacing.normal
visible: storageCard.active || networkCard.active || memoryCard.active
visible: storageCard.active || memoryCard.active || vramCard.active || networkCard1.active
WrappedLoader {
id: storageCard
@@ -95,15 +95,32 @@ Item {
}
WrappedLoader {
id: networkCard
id: vramCard
active: Config.dashboard.performance.showNetwork
active: Config.dashboard.performance.showVram
sourceComponent: VramCard {
}
}
WrappedLoader {
id: networkCard1
active: Config.dashboard.performance.showNetwork && !vramCard.active
sourceComponent: NetworkCard {
wrapper: root.wrapper
}
}
}
WrappedLoader {
id: networkCard2
active: Config.dashboard.performance.showNetwork && vramCard.active
sourceComponent: NetworkCard {
}
}
}
WrappedLoader {
@@ -56,6 +56,14 @@ PageBase {
onToggled: Config.dashboard.performance.showGpu = checked
}
ToggleRow {
checked: Config.dashboard.performance.showVram
settingAnchor: "resources-vram"
text: qsTr("Video memory")
onToggled: Config.dashboard.performance.showVram = checked
}
ToggleRow {
checked: Config.dashboard.performance.showCpu
settingAnchor: "resources-cpu"
+41
View File
@@ -3,8 +3,10 @@
#include "sensorslib.hpp"
#include <cmath>
#include <qcontainerfwd.h>
#include <qdir.h>
#include <qfile.h>
#include <qobject.h>
#include <qregularexpression.h>
#include <QJsonDocument>
#include <QJsonObject>
@@ -243,6 +245,45 @@ void Gpu::detectNameOnce() {
{QStringLiteral("-c"), QString::fromLatin1(kNameDetectScript)});
}
void Gpu::readGenericMemory() {
const QStringList paths = QDir(QStringLiteral("/sys/class/drm"))
.entryList(
QStringList() << QStringLiteral("card*"),
QDir::Dirs | QDir::NoDotAndDotDot);
qreal totalMem = 0.0;
qreal usedMem = 0.0;
for (const QString& card : paths) {
QFile total(
QStringLiteral("/sys/class/drm/%1/device/mem_info_vram_total")
.arg(card));
if (!total.open(QIODevice::ReadOnly | QIODevice::Text)) {
continue;
}
bool ok = false;
const qreal v = total.readAll().trimmed().toDouble(&ok);
total.close();
if (ok) {
totalMem += v;
}
QFile used(QStringLiteral("/sys/class/drm/%1/device/mem_info_vram_used")
.arg(card));
if (!used.open(QIODevice::ReadOnly | QIODevice::Text)) {
continue;
}
bool ok1 = false;
const qreal v1 = used.readAll().trimmed().toDouble(&ok1);
used.close();
if (ok1) {
usedMem += v1;
}
}
setMemoryTotal(totalMem);
setMemoryUsed(usedMem);
}
void Gpu::readGenericUsage() {
const QStringList paths = QDir(QStringLiteral("/sys/class/drm"))
.entryList(
+1
View File
@@ -62,6 +62,7 @@ class Gpu : public TickingService {
void readGenericUsage();
void startNvidiaUsage();
void readGpuTemperature();
void readGenericMemory();
void setUserType(Type value);
void setAutoType(Type value);