Skip to main content

WebGPU vs WebGL

Browsers expose two GPU APIs that matter to luma.gl applications: WebGPU and WebGL 2. WebGPU is the modern API and the direction browser GPU programming is moving. WebGL 2 is the older, widely deployed compatibility path. luma.gl supports both through the same Device API so applications can adopt WebGPU without giving up WebGL reach where it still matters.

For most applications, register both backends and let luma.gl choose the best available device. luma.gl prefers WebGPU when the browser can create a WebGPU device, then falls back to WebGL.

import {luma} from '@luma.gl/core';
import {webglAdapter} from '@luma.gl/webgl';
import {webgpuAdapter} from '@luma.gl/webgpu';

const device = await luma.createDevice({
type: 'best-available',
adapters: [webgpuAdapter, webglAdapter],
createCanvasContext: true
});

Use device.type, device.features, and device.limits when an application needs to choose a backend-specific path.

Choosing a Backend

NeedRecommendation
New applicationPrefer WebGPU.
Broadest reachUse type: 'best-available'.
Compute or storage buffersRequire WebGPU.
Existing GLSL or WebGL codeKeep WebGL first, then add WebGPU deliberately.
Portable renderingStay inside luma.gl Device, Model, pipeline, binding, feature, and limit APIs.

WebGPU

WebGPU is the successor to WebGL. It is designed around the same generation of GPU APIs as Vulkan, Metal, and Direct3D 12, and it adds first-class support for general GPU computation as well as rendering.

For luma.gl users, WebGPU is the preferred backend when available:

AdvantageWhy it matters
Lower CPU and driver overheadBetter scaling for complex scenes and repeated work.
Compute shaders and storage buffersModern GPU data work does not need WebGL workarounds.
Modern resource modelClosely matches luma.gl resources, pipelines, bindings, and commands.
Better multi-canvas supportOne device can present to multiple canvases directly.

WebGPU also has practical constraints:

LimitationWhat to do in luma.gl
Browser, OS, and GPU support variesFeature detect and keep a WebGL fallback when reach matters.
Secure context requiredServe production apps over HTTPS.
Shaders use WGSLKeep WGSL, or matching WGSL and GLSL sources for portable apps.
More explicit setupDescribe pipelines, bindings, and buffer layouts up front.
Stricter formats and limitsCheck device.features and device.limits.
Portable baseline differs from adapter maximumKeep the default featureLevel: 'core' for portability; request 'max' only when the app needs optional WebGPU features or limits. Apps that fit compatibility restrictions can request 'compatibility', or 'best-available' to upgrade that request to core when possible.

WebGL 2

WebGL 2 is the well-established browser GPU API based on OpenGL ES 3.0. It remains important because it is widely available and because many applications already have GLSL and WebGL rendering code.

For luma.gl users, WebGL 2 is the compatibility backend:

AdvantageWhy it matters
Broad deploymentSafest path for older browsers, devices, and managed environments.
Existing GLSL ecosystemWebGL shaders can move into luma.gl incrementally.
Familiar state modelSmall apps can change draw state with less up-front setup.
Mature debugging pathExisting WebGL tools and knowledge still help.

WebGL 2 has the limits that motivate the transition to WebGPU:

LimitationWhat to do in luma.gl
No compute shaders or storage buffersUse WebGPU, or keep WebGL-specific transform or texture fallbacks.
Stateful context modelPrefer luma.gl pipelines and bindings.
One GPU-backed canvas per deviceUse WebGPU for direct shared-resource multi-canvas workflows.
Extension and implementation varianceQuery luma.gl features and limits.
Expensive readback and synchronizationKeep data on the GPU where possible.

WebGL 1

luma.gl v9 intentionally removed WebGL 1 support. Maintaining a third backend path would add implementation and testing cost without serving enough users to justify it: the remaining audience is mostly older devices and browsers that expose WebGL 1 but not WebGL 2, such as Internet Explorer. Applications that still need WebGL 1 should stay on an older luma.gl release or use another WebGL 1 capable stack.

Differences That Matter in luma.gl

TopicWebGPUWebGL 2Guidance
DefaultPreferredReach fallbackUse type: 'best-available'.
CanvasMultiple direct contextsOne GPU-backed canvasUse portable presentation APIs; require WebGPU for direct multi-canvas rendering.
ShadersWGSLGLSL ES 3.00Keep shader sources explicit.
BindingsBind groupsUniform blocks and texturesUse luma.gl binding layouts.
ComputeCompute and storageTransform or texture fallbackUse WebGPU for modern compute.
StateExplicit pipelinesMutable contextLet Model and pipelines own setup.
FormatsMore explicitMore extension varianceQuery features and limits.
CommandsRecorded and submittedImmediate underneathUse luma.gl command APIs.

Condensed Developer Notes

Underlying API differenceVisible effect for luma.gl users
WebGPU descriptions are more static.Reuse or create pipelines instead of mutating context state.
WebGPU has uniform buffers.Use luma.gl binding and shader layout APIs.
WebGPU has no transform feedback.Use compute on WebGPU; keep transform feedback only for WebGL paths.
WebGPU owns vertex layouts in pipelines.Describe formats and layouts up front.
Optional capabilities differ.Treat device.features and device.limits as the portability boundary.

Further Reading