mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
36caf3a14c
Follow-up on #217. Blind A/B test on NVIDIA + proprietary confirmed the toggle helps, but the detection path had a few rough edges. - Drop lspci and glxinfo fallbacks: the /proc/driver/nvidia/version + sysfs scan catch every realistic case, and spawning subprocesses in main() added startup latency for no win (glxinfo also isn't always installed — mesa-utils isn't a hard dep). - Scan all /sys/class/drm/card* entries via read_dir instead of hardcoded card0/card1 — hybrid laptops and systems where only card1 exists were previously missed. - Remove 0x1022 from the AMD list: that's AMD's host/chipset vendor ID, not GPU. Only 0x1002 (ATI/Radeon) belongs here. - Unknown vendor → leave WEBKIT_DISABLE_DMABUF_RENDERER unset instead of forcing =1. VMs, ARM SBCs and anything exotic keep the WebKitGTK default and do not get regressed by a guess. - Only set the env var for the NVIDIA case. Intel/AMD on Mesa already default to DMA-BUF enabled in current WebKitGTK, so the explicit =0 was redundant. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
91 lines
3.1 KiB
Rust
91 lines
3.1 KiB
Rust
// Prevents additional console window on Windows in release, DO NOT REMOVE!!
|
|
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
|
enum GpuVendor {
|
|
Nvidia,
|
|
Intel,
|
|
Amd,
|
|
}
|
|
|
|
#[cfg(target_os = "linux")]
|
|
fn detect_gpu_vendor() -> Option<GpuVendor> {
|
|
use std::fs;
|
|
|
|
if fs::metadata("/proc/driver/nvidia/version").is_ok() {
|
|
return Some(GpuVendor::Nvidia);
|
|
}
|
|
|
|
// Iterate every `/sys/class/drm/card*` — hybrid laptops expose multiple
|
|
// cards, and some systems have no `card0` at all.
|
|
let entries = fs::read_dir("/sys/class/drm").ok()?;
|
|
for entry in entries.flatten() {
|
|
let name = entry.file_name();
|
|
let Some(name) = name.to_str() else { continue };
|
|
if !name.starts_with("card") || name.contains('-') {
|
|
continue;
|
|
}
|
|
let Ok(vendor_id) = fs::read_to_string(entry.path().join("device/vendor")) else {
|
|
continue;
|
|
};
|
|
match vendor_id.trim() {
|
|
"0x10de" => return Some(GpuVendor::Nvidia),
|
|
"0x8086" => return Some(GpuVendor::Intel),
|
|
"0x1002" => return Some(GpuVendor::Amd),
|
|
_ => {}
|
|
}
|
|
}
|
|
|
|
None
|
|
}
|
|
|
|
fn main() {
|
|
// WebKitGTK on Wayland is unstable — force X11/XWayland on all Linux packages.
|
|
// Users can still override by setting these vars before launch.
|
|
//
|
|
// Safety: set_var modifies global process state. These calls are safe here
|
|
// because we're in main() before the Tauri runtime starts — no other threads
|
|
// exist yet. If this code moves to lazy init or a plugin context, it would
|
|
// need synchronization or marking as unsafe (Rust 2024+).
|
|
#[cfg(target_os = "linux")]
|
|
{
|
|
if std::env::var("GDK_BACKEND").is_err() {
|
|
std::env::set_var("GDK_BACKEND", "x11");
|
|
}
|
|
if std::env::var("WEBKIT_DISABLE_COMPOSITING_MODE").is_err() {
|
|
std::env::set_var("WEBKIT_DISABLE_COMPOSITING_MODE", "1");
|
|
}
|
|
|
|
// NVIDIA proprietary adds a small but reproducible overhead on the
|
|
// DMA-BUF renderer path (blind A/B confirmed on NVIDIA + proprietary).
|
|
// Unknown GPUs keep the WebKitGTK default — VMs, ARM SBCs and anything
|
|
// exotic should not be regressed by a guess.
|
|
if std::env::var("WEBKIT_DISABLE_DMABUF_RENDERER").is_err()
|
|
&& matches!(detect_gpu_vendor(), Some(GpuVendor::Nvidia))
|
|
{
|
|
std::env::set_var("WEBKIT_DISABLE_DMABUF_RENDERER", "1");
|
|
}
|
|
}
|
|
|
|
let args: Vec<String> = std::env::args().collect();
|
|
if psysonic_lib::cli::wants_version(&args) {
|
|
psysonic_lib::cli::print_version();
|
|
return;
|
|
}
|
|
if psysonic_lib::cli::wants_help(&args) {
|
|
psysonic_lib::cli::print_help(
|
|
args.first().map(|s| s.as_str()).unwrap_or("psysonic"),
|
|
);
|
|
return;
|
|
}
|
|
if let Some(code) = psysonic_lib::cli::try_completions_dispatch(&args) {
|
|
std::process::exit(code);
|
|
}
|
|
if psysonic_lib::cli::wants_info(&args) {
|
|
psysonic_lib::cli::run_info_and_exit(&args);
|
|
}
|
|
|
|
psysonic_lib::run();
|
|
}
|