Skip to content

Switch to wgpu as default backend of eframe? #5889

@emilk

Description

@emilk

Summary

I'd like to switch the default backend of eframe from glow to wgpu, making glow opt-in.

Background

eframe currently has two backends: glow and wgpu (pronounced "wiggipu").

glow is lightweight (few dependencies, compiles quickly), and wgpu is powerful (allows integrating more advanced 3D rendering alongside egui).

Having two backends is annoying for several reasons:

  • Duplicated code
  • Duplicated maintenance burden
  • We're spreading our resources

The last point in particular is what I want to address with this issue.

Why wgpu?

The broader graphics and GUI community is converging on wgpu as the standard graphics library for Rust. Bug fixes and improvements to wgpu makes everyones lives better.

Switching over to wgpu can also become a forcing function to improve the wgpu backend. For instance, if switching to wgpu increases the .wasm binary size, maybe that will motivate someone to fix it.

Worries with using wgpu as the backend

Increased compile times

This one sucks. I like light-weight crates, but it is hard to be light-weight and also powerful. We should measure and see how much worse it gets.

Increased wasm binary size (+2.4 MiB)

wgpu shaders are written in WGSL (pronounces "wixel") and then transpiled to GLSL (never pronounced) when targetting the WebGL backend. This transpiling is done with naga. Naga is a chonky beast, because it has to be able to transpile any shader. This means the wasm binary size increases a lot.

I see two primary remedies:

  • Pre-compile the egui shaders to glsl so we don't need to ship naga
  • Only target WebGPU (no tranpilation needed)

WebGPU support is not yet universal, but its getting there: https://caniuse.com/webgpu

Quick test:

  • ./scripts/build_demo_web.sh --release -> 5.9 MiB
  • ./scripts/build_demo_web.sh --release --wgpu -> 8.3 MiB

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    Status

    In progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions