Fix Linux terminal WebGL glyph corruption

(cherry picked from commit 86eff20e3b14255befc519c5bd2398ae5bdc447c)
This commit is contained in:
Neil
2026-05-15 23:51:12 -07:00
parent 7b182bef5e
commit 2a3e2cd55f
8 changed files with 72 additions and 12 deletions
@@ -453,7 +453,7 @@ export function TerminalPane({
<SearchableSetting
title="GPU Acceleration"
description="Controls whether the terminal uses xterm.js WebGL rendering. Auto mirrors VS Code: try GPU and fall back to DOM if WebGL fails."
description="Controls whether the terminal uses xterm.js WebGL rendering. Auto uses DOM on Linux to avoid driver glyph corruption, and otherwise tries WebGL with DOM fallback."
keywords={[
'terminal',
'gpu',
@@ -489,7 +489,7 @@ export function TerminalPane({
? 'WebGL is disabled; xterm uses the DOM renderer for maximum compatibility.'
: settings.terminalGpuAcceleration === 'on'
? 'WebGL is always attempted for terminal panes.'
: 'Auto tries WebGL for performance and falls back to the DOM renderer if WebGL fails, matching VS Code.'}
: 'Auto uses the DOM renderer on Linux to avoid GPU glyph corruption, and otherwise tries WebGL with DOM fallback.'}
</p>
</SearchableSetting>
</section>
@@ -45,7 +45,7 @@ export const TERMINAL_RENDERING_SEARCH_ENTRIES: SettingsSearchEntry[] = [
{
title: 'GPU Acceleration',
description:
'Controls whether the terminal uses xterm.js WebGL rendering. Auto mirrors VS Code: try GPU and fall back to DOM if WebGL fails.',
'Controls whether the terminal uses xterm.js WebGL rendering. Auto uses DOM on Linux to avoid driver glyph corruption, and otherwise tries WebGL with DOM fallback.',
keywords: [
'terminal',
'gpu',
@@ -80,6 +80,10 @@ describe('attachWebgl', () => {
webglMock.dispose.mockClear()
vi.mocked(WebglAddon).mockClear()
resetTerminalWebglSuggestion()
vi.stubGlobal('navigator', {
platform: 'MacIntel',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)'
})
vi.stubGlobal('requestAnimationFrame', (callback: FrameRequestCallback) => {
callback(16)
return 1
@@ -129,6 +133,32 @@ describe('attachWebgl', () => {
expect(pane.terminal.loadAddon).not.toHaveBeenCalled()
})
it('uses DOM rendering for auto GPU acceleration on Linux', () => {
vi.stubGlobal('navigator', {
platform: 'Linux x86_64',
userAgent: 'Mozilla/5.0 (X11; Linux x86_64)'
})
const pane = createPane()
attachWebgl(pane)
expect(pane.webglAddon).toBeNull()
expect(pane.terminal.loadAddon).not.toHaveBeenCalled()
})
it('still allows forced WebGL on Linux', () => {
vi.stubGlobal('navigator', {
platform: 'Linux x86_64',
userAgent: 'Mozilla/5.0 (X11; Linux x86_64)'
})
const pane = createPane()
pane.terminalGpuAcceleration = 'on'
attachWebgl(pane)
expect(pane.terminal.loadAddon).toHaveBeenCalledTimes(1)
})
it('uses DOM for later auto panes after WebGL attach fails until the suggestion resets', () => {
const firstPane = createPane()
vi.mocked(WebglAddon).mockImplementationOnce(() => {
@@ -69,4 +69,18 @@ describe('applyTerminalGpuAcceleration', () => {
expect(pane.webglAddon).toBeNull()
expect(pane.fitAddon.fit).toHaveBeenCalledTimes(1)
})
it('returns Linux panes to DOM when switching from forced WebGL back to auto', () => {
vi.stubGlobal('navigator', {
platform: 'Linux x86_64',
userAgent: 'Mozilla/5.0 (X11; Linux x86_64)'
})
const pane = createPane()
const options: PaneManagerOptions = { terminalGpuAcceleration: 'on' }
applyTerminalGpuAcceleration([pane], options, 'auto')
expect(pane.webglAddon).toBeNull()
expect(pane.fitAddon.fit).toHaveBeenCalledTimes(1)
})
})
@@ -1,5 +1,10 @@
import type { ManagedPaneInternal, PaneManagerOptions } from './pane-manager-types'
import { attachWebgl, disposeWebgl, resetTerminalWebglSuggestion } from './pane-webgl-renderer'
import {
attachWebgl,
disposeWebgl,
resetTerminalWebglSuggestion,
shouldUseTerminalWebgl
} from './pane-webgl-renderer'
import { safeFit } from './pane-tree-ops'
export function applyTerminalGpuAcceleration(
@@ -15,7 +20,7 @@ export function applyTerminalGpuAcceleration(
}
for (const pane of panes) {
pane.terminalGpuAcceleration = nextMode
if (nextMode === 'off' || (nextMode === 'auto' && pane.hasComplexScriptOutput)) {
if (!shouldUseTerminalWebgl(pane)) {
disposeWebgl(pane, { refreshDimensions: true })
continue
}
@@ -23,8 +28,7 @@ export function applyTerminalGpuAcceleration(
pane.gpuRenderingEnabled &&
!pane.webglAddon &&
!pane.webglAttachmentDeferred &&
!pane.webglDisabledAfterContextLoss &&
(nextMode === 'on' || !pane.hasComplexScriptOutput)
!pane.webglDisabledAfterContextLoss
) {
attachWebgl(pane)
safeFit(pane)
@@ -10,10 +10,22 @@ export function resetTerminalWebglSuggestion(): void {
suggestedRendererType = undefined
}
function shouldUseWebgl(pane: ManagedPaneInternal): boolean {
function isLinuxRenderer(): boolean {
if (typeof navigator === 'undefined') {
return false
}
return navigator.platform.includes('Linux') || navigator.userAgent.includes('Linux')
}
export function shouldUseTerminalWebgl(pane: ManagedPaneInternal): boolean {
if (pane.terminalGpuAcceleration === 'on') {
return true
}
if (isLinuxRenderer()) {
// Why: multiple Linux/Wayland GPU stacks corrupt xterm's WebGL glyph atlas
// without raising context loss; tab switching only masks it by rebuilding WebGL.
return false
}
return (
pane.terminalGpuAcceleration === 'auto' &&
suggestedRendererType === undefined &&
@@ -61,7 +73,7 @@ export function attachWebgl(pane: ManagedPaneInternal): void {
if (
!ENABLE_WEBGL_RENDERER ||
!pane.gpuRenderingEnabled ||
!shouldUseWebgl(pane) ||
!shouldUseTerminalWebgl(pane) ||
pane.webglAttachmentDeferred ||
pane.webglDisabledAfterContextLoss
) {
+2 -2
View File
@@ -164,8 +164,8 @@ export function getDefaultSettings(homedir: string): GlobalSettings {
terminalFontFamily: defaultTerminalFontFamily(),
terminalFontWeight: DEFAULT_TERMINAL_FONT_WEIGHT,
terminalLineHeight: 1,
// Why: VS Code defaults terminal GPU acceleration to "auto": prefer
// xterm WebGL for performance, but allow renderer failure to choose DOM.
// Why: keep the setting on "auto" so explicit user choices stay available,
// but renderer policy maps Linux auto to DOM to avoid GPU glyph corruption.
terminalGpuAcceleration: 'auto',
// Why 'auto': when the user has picked a known ligature font we want the
// feature enabled by default, but we never force it if they pick a font
+1 -1
View File
@@ -1113,7 +1113,7 @@ export type GlobalSettings = {
terminalFontWeight: number
terminalLineHeight: number
/** Mirrors VS Code's terminal.integrated.gpuAcceleration shape.
* - 'auto': try xterm WebGL and fall back to DOM if the renderer fails.
* - 'auto': use DOM on Linux; otherwise try xterm WebGL and fall back to DOM if the renderer fails.
* - 'on': always try xterm WebGL.
* - 'off': keep terminal rendering on xterm's DOM renderer. */
terminalGpuAcceleration: 'auto' | 'on' | 'off'