Refactor GPU config: move critical Linux flags to main.js
Critical Linux and SteamOS GPU flags are now set immediately after loading Electron in main.js, before app.ready, to ensure proper rendering and compatibility. The GPUConfig class now only applies additional, non-critical settings. Improved SteamOS detection logic and added more detailed logging for GPU environment detection.
This commit is contained in:
+17
-47
@@ -39,7 +39,7 @@ class GPUConfig {
|
|||||||
|
|
||||||
// Apply GPU configuration based on system capabilities
|
// Apply GPU configuration based on system capabilities
|
||||||
configure() {
|
configure() {
|
||||||
console.log('Configuring GPU settings...');
|
console.log('[GPUConfig] Additional GPU configuration...');
|
||||||
|
|
||||||
// Try to detect if we're on a system that supports GPU acceleration
|
// Try to detect if we're on a system that supports GPU acceleration
|
||||||
const platform = process.platform;
|
const platform = process.platform;
|
||||||
@@ -47,67 +47,37 @@ class GPUConfig {
|
|||||||
|
|
||||||
this.isSteamOS = this.detectSteamOS();
|
this.isSteamOS = this.detectSteamOS();
|
||||||
|
|
||||||
console.log(`Platform: ${platform}, Architecture: ${arch}, SteamOS: ${this.isSteamOS}`);
|
console.log(`[GPUConfig] Platform: ${platform}, Architecture: ${arch}, SteamOS: ${this.isSteamOS}`);
|
||||||
|
|
||||||
// Apply Linux/SteamOS specific configuration FIRST (before app ready)
|
// NOTE: Primary Linux/SteamOS GPU flags are now applied in main.js
|
||||||
if (this.isLinux) {
|
// immediately after loading Electron, before app.ready
|
||||||
this.applyLinuxSettings();
|
// This configure() method now only applies additional non-critical settings
|
||||||
}
|
|
||||||
|
|
||||||
// Start with conservative settings that usually work
|
// Start with conservative settings that usually work
|
||||||
this.applyConservativeSettings();
|
this.applyConservativeSettings();
|
||||||
|
|
||||||
// Try to enable GPU features progressively
|
// Try to enable GPU features progressively (skip on SteamOS - already handled)
|
||||||
|
if (!this.isSteamOS) {
|
||||||
this.tryEnableGPU();
|
this.tryEnableGPU();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Linux-specific settings for proper rendering
|
// Linux-specific settings for proper rendering
|
||||||
|
// NOTE: Critical flags are now in main.js - this is for additional settings only
|
||||||
applyLinuxSettings() {
|
applyLinuxSettings() {
|
||||||
console.log('Applying Linux-specific GPU settings...');
|
// Most Linux settings are now applied earlier in main.js
|
||||||
|
// This method is kept for any additional non-critical settings
|
||||||
// Ozone platform selection - critical for rendering on Linux
|
console.log('[GPUConfig] Additional Linux settings (if any)...');
|
||||||
// Check for Wayland vs X11 environment
|
|
||||||
const waylandDisplay = process.env.WAYLAND_DISPLAY;
|
|
||||||
const gamescope = process.env.GAMESCOPE_WAYLAND_DISPLAY;
|
|
||||||
const x11Display = process.env.DISPLAY;
|
|
||||||
|
|
||||||
if (this.isSteamOS || gamescope) {
|
|
||||||
// SteamOS/Gamescope: Force X11 backend for better compatibility
|
|
||||||
// Gamescope provides X11 compatibility layer that works better with Electron
|
|
||||||
console.log('SteamOS/Gamescope detected - using X11 Ozone backend');
|
|
||||||
app.commandLine.appendSwitch('ozone-platform', 'x11');
|
|
||||||
|
|
||||||
// Disable GPU compositing issues on Steam Deck AMD GPU
|
|
||||||
app.commandLine.appendSwitch('disable-gpu-compositing');
|
|
||||||
app.commandLine.appendSwitch('disable-gpu-vsync');
|
|
||||||
|
|
||||||
// Use software rendering for webviews if needed
|
|
||||||
app.commandLine.appendSwitch('disable-accelerated-2d-canvas');
|
|
||||||
|
|
||||||
// Fix for AMD GPU rendering issues
|
|
||||||
app.commandLine.appendSwitch('use-gl', 'desktop');
|
|
||||||
app.commandLine.appendSwitch('enable-features', 'UseOzonePlatform');
|
|
||||||
} else if (waylandDisplay && !x11Display) {
|
|
||||||
// Pure Wayland environment
|
|
||||||
console.log('Wayland detected - using Wayland Ozone backend');
|
|
||||||
app.commandLine.appendSwitch('ozone-platform', 'wayland');
|
|
||||||
app.commandLine.appendSwitch('enable-features', 'UseOzonePlatform,WaylandWindowDecorations');
|
|
||||||
} else if (x11Display) {
|
|
||||||
// X11 environment
|
|
||||||
console.log('X11 detected - using X11 Ozone backend');
|
|
||||||
app.commandLine.appendSwitch('ozone-platform', 'x11');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Common Linux fixes
|
|
||||||
app.commandLine.appendSwitch('disable-features', 'VizDisplayCompositor');
|
|
||||||
app.commandLine.appendSwitch('enable-unsafe-swiftshader');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
applyConservativeSettings() {
|
applyConservativeSettings() {
|
||||||
// Essential switches that usually don't cause issues
|
// Essential switches that usually don't cause issues
|
||||||
|
// Note: no-sandbox and disable-gpu-sandbox are already set in main.js for Linux
|
||||||
|
if (process.platform !== 'linux') {
|
||||||
app.commandLine.appendSwitch('no-sandbox');
|
app.commandLine.appendSwitch('no-sandbox');
|
||||||
app.commandLine.appendSwitch('disable-dev-shm-usage');
|
|
||||||
app.commandLine.appendSwitch('disable-gpu-sandbox');
|
app.commandLine.appendSwitch('disable-gpu-sandbox');
|
||||||
|
}
|
||||||
|
app.commandLine.appendSwitch('disable-dev-shm-usage');
|
||||||
|
|
||||||
// Performance improvements that don't rely on GPU
|
// Performance improvements that don't rely on GPU
|
||||||
app.commandLine.appendSwitch('disable-background-timer-throttling');
|
app.commandLine.appendSwitch('disable-background-timer-throttling');
|
||||||
@@ -121,7 +91,7 @@ class GPUConfig {
|
|||||||
try {
|
try {
|
||||||
// Skip aggressive GPU features on SteamOS - they conflict with Gamescope
|
// Skip aggressive GPU features on SteamOS - they conflict with Gamescope
|
||||||
if (this.isSteamOS) {
|
if (this.isSteamOS) {
|
||||||
console.log('SteamOS detected - skipping aggressive GPU acceleration');
|
console.log('[GPUConfig] SteamOS detected - skipping aggressive GPU acceleration');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,67 +1,100 @@
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
// CRITICAL: GPU flags must be applied BEFORE Electron loads
|
// CRITICAL: Load Electron first, then apply GPU flags IMMEDIATELY
|
||||||
// These must be at the VERY TOP of main.js for packaged apps
|
// app.commandLine.appendSwitch() must be called before app.ready
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
const { app, BrowserWindow, ipcMain, session, screen, shell, dialog, Menu, clipboard, webContents } = require('electron');
|
||||||
|
|
||||||
|
// Apply Linux/SteamOS GPU flags IMMEDIATELY after loading Electron
|
||||||
|
// This MUST happen before app.ready and before any other initialization
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
// Detect SteamOS/Gamescope environment
|
// Detect SteamOS/Gamescope environment
|
||||||
let isSteamOS = false;
|
let isSteamOS = false;
|
||||||
|
let detectionReason = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (fs.existsSync('/etc/steamos-release')) isSteamOS = true;
|
if (fs.existsSync('/etc/steamos-release')) {
|
||||||
else if (fs.existsSync('/usr/share/steamos/steamos.conf')) isSteamOS = true;
|
isSteamOS = true;
|
||||||
else if (process.env.GAMESCOPE_WAYLAND_DISPLAY) isSteamOS = true;
|
detectionReason = '/etc/steamos-release exists';
|
||||||
else if (process.env.SteamDeck) isSteamOS = true;
|
} else if (fs.existsSync('/usr/share/steamos/steamos.conf')) {
|
||||||
else if (process.env.SteamAppId) isSteamOS = true;
|
isSteamOS = true;
|
||||||
else if (fs.existsSync('/etc/os-release')) {
|
detectionReason = '/usr/share/steamos/steamos.conf exists';
|
||||||
|
} else if (process.env.GAMESCOPE_WAYLAND_DISPLAY) {
|
||||||
|
isSteamOS = true;
|
||||||
|
detectionReason = 'GAMESCOPE_WAYLAND_DISPLAY env var set';
|
||||||
|
} else if (process.env.SteamDeck === '1' || process.env.SteamDeck === 'true') {
|
||||||
|
isSteamOS = true;
|
||||||
|
detectionReason = 'SteamDeck env var set';
|
||||||
|
} else if (process.env.SteamAppId) {
|
||||||
|
isSteamOS = true;
|
||||||
|
detectionReason = 'SteamAppId env var set (running from Steam)';
|
||||||
|
} else if (process.env.STEAM_COMPAT_DATA_PATH) {
|
||||||
|
isSteamOS = true;
|
||||||
|
detectionReason = 'STEAM_COMPAT_DATA_PATH set (Proton/Steam environment)';
|
||||||
|
} else if (fs.existsSync('/etc/os-release')) {
|
||||||
const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
|
const osRelease = fs.readFileSync('/etc/os-release', 'utf8');
|
||||||
if (osRelease.includes('SteamOS') || osRelease.includes('steamos')) isSteamOS = true;
|
if (osRelease.toLowerCase().includes('steamos')) {
|
||||||
|
isSteamOS = true;
|
||||||
|
detectionReason = '/etc/os-release contains SteamOS';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {}
|
|
||||||
|
|
||||||
// Apply flags via app.commandLine BEFORE requiring electron
|
// Also check for gamescope in display server - common on Steam Deck
|
||||||
// We need to do this via process.argv for packaged apps
|
if (!isSteamOS && process.env.XDG_CURRENT_DESKTOP) {
|
||||||
const linuxFlags = [
|
const desktop = process.env.XDG_CURRENT_DESKTOP.toLowerCase();
|
||||||
'--disable-gpu-sandbox',
|
if (desktop.includes('gamescope')) {
|
||||||
'--no-sandbox',
|
isSteamOS = true;
|
||||||
'--disable-dev-shm-usage'
|
detectionReason = 'XDG_CURRENT_DESKTOP contains gamescope';
|
||||||
];
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log('[GPU] SteamOS detection error:', e.message);
|
||||||
|
}
|
||||||
|
|
||||||
if (isSteamOS || process.env.GAMESCOPE_WAYLAND_DISPLAY) {
|
// Always apply basic Linux sandbox fixes
|
||||||
console.log('[GPU] SteamOS/Gamescope detected at startup - applying critical flags');
|
app.commandLine.appendSwitch('no-sandbox');
|
||||||
linuxFlags.push(
|
app.commandLine.appendSwitch('disable-gpu-sandbox');
|
||||||
'--ozone-platform=x11',
|
app.commandLine.appendSwitch('disable-dev-shm-usage');
|
||||||
'--disable-gpu-compositing',
|
|
||||||
'--disable-gpu-vsync',
|
if (isSteamOS) {
|
||||||
'--disable-accelerated-2d-canvas',
|
console.log(`[GPU] SteamOS/Gamescope DETECTED: ${detectionReason}`);
|
||||||
'--use-gl=desktop',
|
console.log('[GPU] Applying SteamOS-specific GPU flags for webview rendering...');
|
||||||
'--disable-features=VizDisplayCompositor',
|
|
||||||
'--enable-features=UseOzonePlatform'
|
// Critical flags for SteamOS/Gamescope webview rendering
|
||||||
);
|
app.commandLine.appendSwitch('ozone-platform', 'x11');
|
||||||
|
app.commandLine.appendSwitch('disable-gpu-compositing');
|
||||||
|
app.commandLine.appendSwitch('disable-gpu-vsync');
|
||||||
|
app.commandLine.appendSwitch('disable-accelerated-2d-canvas');
|
||||||
|
app.commandLine.appendSwitch('use-gl', 'desktop');
|
||||||
|
app.commandLine.appendSwitch('disable-features', 'VizDisplayCompositor');
|
||||||
|
app.commandLine.appendSwitch('enable-features', 'UseOzonePlatform');
|
||||||
|
app.commandLine.appendSwitch('enable-unsafe-swiftshader');
|
||||||
|
|
||||||
|
// Additional flags that help with AMD GPU under Gamescope
|
||||||
|
app.commandLine.appendSwitch('disable-background-networking');
|
||||||
|
app.commandLine.appendSwitch('in-process-gpu');
|
||||||
} else {
|
} else {
|
||||||
|
console.log('[GPU] Standard Linux environment detected');
|
||||||
|
|
||||||
// General Linux - detect Wayland vs X11
|
// General Linux - detect Wayland vs X11
|
||||||
const waylandDisplay = process.env.WAYLAND_DISPLAY;
|
const waylandDisplay = process.env.WAYLAND_DISPLAY;
|
||||||
const x11Display = process.env.DISPLAY;
|
const x11Display = process.env.DISPLAY;
|
||||||
|
|
||||||
if (waylandDisplay && !x11Display) {
|
if (waylandDisplay && !x11Display) {
|
||||||
linuxFlags.push('--ozone-platform=wayland', '--enable-features=UseOzonePlatform,WaylandWindowDecorations');
|
console.log('[GPU] Pure Wayland environment - using wayland backend');
|
||||||
|
app.commandLine.appendSwitch('ozone-platform', 'wayland');
|
||||||
|
app.commandLine.appendSwitch('enable-features', 'UseOzonePlatform,WaylandWindowDecorations');
|
||||||
} else if (x11Display) {
|
} else if (x11Display) {
|
||||||
linuxFlags.push('--ozone-platform=x11');
|
console.log('[GPU] X11 environment detected');
|
||||||
}
|
app.commandLine.appendSwitch('ozone-platform', 'x11');
|
||||||
linuxFlags.push('--disable-features=VizDisplayCompositor');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add flags that aren't already present
|
app.commandLine.appendSwitch('disable-features', 'VizDisplayCompositor');
|
||||||
linuxFlags.forEach(flag => {
|
|
||||||
const flagName = flag.split('=')[0];
|
|
||||||
if (!process.argv.some(arg => arg.startsWith(flagName))) {
|
|
||||||
process.argv.push(flag);
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
const { app, BrowserWindow, ipcMain, session, screen, shell, dialog, Menu, clipboard, webContents } = require('electron');
|
|
||||||
const { autoUpdater } = require('electron-updater');
|
const { autoUpdater } = require('electron-updater');
|
||||||
const { pathToFileURL } = require('url');
|
const { pathToFileURL } = require('url');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
@@ -90,7 +123,7 @@ try {
|
|||||||
// Non-fatal: some environments may not allow commandLine changes at this time.
|
// Non-fatal: some environments may not allow commandLine changes at this time.
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure GPU settings before app is ready
|
// Configure GPU settings before app is ready (additional platform-specific settings)
|
||||||
gpuConfig.configure();
|
gpuConfig.configure();
|
||||||
|
|
||||||
// Set a custom application name
|
// Set a custom application name
|
||||||
|
|||||||
Reference in New Issue
Block a user