mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-01-29 00:35:38 +08:00
feat(linux): disable WebKit DMABUF renderer on NVIDIA GPUs at startup #5921
This commit is contained in:
@@ -229,6 +229,9 @@ pub fn run() {
|
||||
return;
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
utils::workarounds::apply_nvidia_dmabuf_renderer_workaround();
|
||||
|
||||
let _ = utils::dirs::init_portable_flag();
|
||||
|
||||
let builder = app_init::setup_plugins(tauri::Builder::default())
|
||||
|
||||
@@ -13,3 +13,5 @@ pub mod server;
|
||||
pub mod singleton;
|
||||
pub mod tmpl;
|
||||
pub mod window_manager;
|
||||
#[cfg(target_os = "linux")]
|
||||
pub mod workarounds;
|
||||
|
||||
55
src-tauri/src/utils/workarounds.rs
Normal file
55
src-tauri/src/utils/workarounds.rs
Normal file
@@ -0,0 +1,55 @@
|
||||
//! Best-effort platform workarounds for known upstream issues.
|
||||
//!
|
||||
//! NOTE:
|
||||
//! These helpers are not fixes and may stop working as environments change.
|
||||
|
||||
use clash_verge_logging::{Type, logging};
|
||||
use std::{fs, path::Path};
|
||||
|
||||
pub fn apply_nvidia_dmabuf_renderer_workaround() {
|
||||
if std::env::var_os("WEBKIT_DISABLE_DMABUF_RENDERER").is_some() {
|
||||
return;
|
||||
}
|
||||
|
||||
if has_nvidia_gpu() {
|
||||
unsafe {
|
||||
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
||||
}
|
||||
logging!(
|
||||
info,
|
||||
Type::Setup,
|
||||
"Detected NVIDIA GPU, set WEBKIT_DISABLE_DMABUF_RENDERER=1"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn has_nvidia_gpu() -> bool {
|
||||
if Path::new("/proc/driver/nvidia/version").exists()
|
||||
|| Path::new("/sys/module/nvidia").exists()
|
||||
|| Path::new("/sys/module/nvidia_drm").exists()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
let Ok(entries) = fs::read_dir("/sys/class/drm") else {
|
||||
return false;
|
||||
};
|
||||
|
||||
for entry in entries.flatten() {
|
||||
let name = entry.file_name();
|
||||
let name = name.to_string_lossy();
|
||||
if !name.starts_with("card") || name.contains('-') {
|
||||
continue;
|
||||
}
|
||||
|
||||
let vendor_path = entry.path().join("device/vendor");
|
||||
let Ok(vendor) = fs::read_to_string(vendor_path) else {
|
||||
continue;
|
||||
};
|
||||
if vendor.trim().eq_ignore_ascii_case("0x10de") {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
Reference in New Issue
Block a user