Repository navigation
fix: use glxinfo -B as VRAM fallback for generic GPU drivers - #958
Open
GongHeng2017 wants to merge 1 commit into
Open
GongHeng2017 wants to merge 1 commit into
GongHeng2017 wants to merge 1 commit into
Conversation
1. Root cause: previous sysfs mem_info_visible_vram_size file is vendor-specific and absent on many GPU drivers, leaving m_GraphicsMemory empty for non-amdgpu/radeon cards 2. Fix: replace sysfs direct-read with a three-level fallback chain: dmesg -> nvidia-settings -> glxinfo -B; add loadGlxInfoForVideoMemory() to parse "Video memory" from glxinfo output, setGlxInfo() converts MB to GB and only fills when m_GraphicsMemory is still empty 3. Impact: GPU VRAM now displays for cards without dmesg/nvidia-settings coverage; existing dmesg and nvidia-settings paths unchanged Log: Fixed GPU VRAM not displayed with generic GPU drivers Influence: 1. Test GPU VRAM display with amdgpu driver (dmesg path, no regression) 2. Test GPU VRAM display with nvidia driver (nvidia-settings path) 3. Test GPU VRAM display with glxinfo fallback when dmesg/nvidia fail 4. Test glxinfo not installed scenario (graceful fallback, no crash) fix: 使用glxinfo -B作为通用显卡驱动的显存兜底方案 1. 根因:此前直接读取sysfs文件mem_info_visible_vram_size,该文件名 仅部分厂商驱动存在,很多显卡驱动无此文件,导致非amdgpu/radeon 显卡的m_GraphicsMemory为空 2. 方案:替换sysfs直读为三级fallback链:dmesg -> nvidia-settings -> glxinfo -B;新增loadGlxInfoForVideoMemory()解析glxinfo输出中 的"Video memory"字段,setGlxInfo()将MB转GB且仅在显存为空时填充 3. 影响:无dmesg/nvidia-settings覆盖的显卡可正常显示显存; 原有dmesg和nvidia-settings路径行为不变 Log: 修复通用显卡驱动下显存不显示的问题 Influence: 1. 测试amdgpu驱动下GPU显存显示(dmesg路径,无回归) 2. 测试nvidia驱动下GPU显存显示(nvidia-settings路径) 3. 测试dmesg/nvidia失败时glxinfo兜底显存显示 4. 测试glxinfo未安装场景(优雅降级,不崩溃) Bug: #380847 PMS: BUG-380847
Reviewer's GuideThe PR replaces the non-portable sysfs VRAM fallback with a dmesg → nvidia-settings → glxinfo -B chain, adding command collection, parsing, unit conversion, and guarded application of the current GL renderer’s memory while preserving higher-priority results. Sequence diagram for GPU VRAM fallback detectionsequenceDiagram
participant Generator as DeviceGenerator
participant Manager as DeviceManager
participant Dmesg as dmesg
participant Nvidia as nvidia-settings
participant Glx as glxinfo
participant GPU as DeviceGpu
Generator->>Manager: cmdInfo(dmesg)
alt dmesg data available
Manager->>GPU: setDmesgInfo(mapInfo)
else dmesg unavailable
Generator->>Manager: cmdInfo(nvidia)
alt nvidia-settings data available
Manager->>GPU: setDmesgInfo(mapInfo)
else nvidia-settings unavailable
Generator->>Manager: cmdInfo(glxinfo)
Manager->>GPU: setGpuSizeFromGlxInfo(mapInfo)
GPU->>GPU: setGlxInfo(mapInfo)
alt Graphics Memory is empty
GPU->>GPU: Store Video memory
else Graphics Memory already set
GPU-->>GPU: Preserve existing value
end
end
end
Flow diagram for glxinfo VRAM parsing and conversionflowchart TD
A[loadGlxInfoForVideoMemory] --> B[Run /usr/bin/glxinfo -B]
B --> C{Process completes}
C -->|No| D[Return without map data]
C -->|Yes| E[Parse Video memory field]
E --> F{Field found}
F -->|No| D
F -->|Yes| G[addMapInfo]
G --> H[setGlxInfo]
H --> I{Graphics Memory already set}
I -->|Yes| J[Preserve existing value]
I -->|No| K{Value is MB and at least 1024}
K -->|Yes| L[Convert MB to GB]
K -->|No| M[Keep parsed value]
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause
DeviceGpu has three VRAM detection paths, all of which fail for many GPU drivers. The primary path reads
/sys/<SysFS_ID>/gpu-info(amdgpu-only); lshw mapsmemoryto address range (not size); dmesg requires aVRAMkeyword absent on many drivers. The previous fix attempted to read DRM sysfsmem_info_visible_vram_size, but that file name is also vendor-specific and absent on many drivers — not universally available.Fix Approach
Replaced the sysfs direct-read fallback with a three-level chain: dmesg → nvidia-settings → glxinfo -B.
CmdTool::loadGlxInfoForVideoMemory()runsglxinfo -B, parses theVideo memoryfield, and stores it viaaddMapInfo().DeviceGpu::setGlxInfo()converts MB→GB and only fillsm_GraphicsMemorywhen still empty (glxinfo reflects the current GL renderer only, so it's a last-resort fallback).DeviceManager::setGpuSizeFromGlxInfo()iterates GPU list callingsetGlxInfo().DeviceGenerator::getGpuSizeFromDmesg()now has early-return three-level fallback.kGraphicsMemoryetc.) moved tocommondefine.h.Also fixed a C++ string literal bug in the regex:
\s→\\s(backslash was dropped by compiler, breaking the whitespace match).Change Safety
QProcess::startfails gracefully, no crashVerification
根因
DeviceGpu 有三条显存检测路径,在很多显卡驱动下全部失效。主路径读取
/sys/<SysFS_ID>/gpu-info(amdgpu 专有);lshw 将memory映射为地址范围(非大小);dmesg 要求VRAM关键字但很多驱动不含。前次修复尝试读取 DRM sysfsmem_info_visible_vram_size,但该文件名同样为部分厂商专有,很多驱动无此文件,不具备通用性。修复方案
将 sysfs 直读替换为三级 fallback 链:dmesg → nvidia-settings → glxinfo -B。
CmdTool::loadGlxInfoForVideoMemory()运行glxinfo -B,解析Video memory字段,通过addMapInfo()存储。DeviceGpu::setGlxInfo()将 MB 转 GB,仅在m_GraphicsMemory为空时填充(glxinfo 仅反映当前 GL 渲染 GPU,作为兜底)。DeviceManager::setGpuSizeFromGlxInfo()遍历 GPU 列表调用setGlxInfo()。DeviceGenerator::getGpuSizeFromDmesg()改为带 early-return 的三级 fallback。kGraphicsMemory等)移至commondefine.h。同时修复了正则表达式中 C++ 字符串字面量的 bug:
\s→\\s(反斜杠被编译器丢弃导致空白匹配失效)。改动安全评估
QProcess::start优雅失败,不崩溃验证建议
Bug: #380847
PMS: BUG-380847
Summary by Sourcery
Improve GPU VRAM detection by adding a graceful glxinfo fallback after dmesg and nvidia-settings sources fail.
New Features:
Bug Fixes:
Enhancements: