emilk / emilk/egui

wgpu configure surface breaks egui

Open
#7,484 2 comments 0 reactions 0 assignees View on GitHub
bug egui-wgpu
Dominant language
Rust
Stars
30.6k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
72

Description

**Describe the bug**
I've been exploring hdr rendering in wgpu (I'm using egui + egui_winit + egui_wgpu) and stumbled upon a bug when I tried to change surface texture format from `wgpu::TextureFormat::Rgba8Unorm` to `wgpu::TextureFormat::Rgba16Float` at runtime. I also recreated `egui_wgpu::Renderer` with the new texture format, the application turned all black without any errors thrown. After several hours of searching for the cause, I found that the source of the issue could be egui::Context.

As I pass around a `&egui_ctx` reference, calling `egui_ctx.forget_all_images();` on it resulted in some images appear:
Image

I tried other methods on context:
```
egui_ctx.memory_mut(|mem| {
mem.caches = egui::cache::CacheStorage::default();
});
egui_ctx.graphics_mut(|gl| {
*gl = egui::layers::GraphicLayers::default();
});
egui_ctx.request_discard("");
```
But none of these changed anything. Am I missing something or is there a bug?

Temporal workaround turned out recreating `egui_winit::State` completely alongside with the `egui_wgpu::Renderer`. Because it requeries to consume the `egui::Context`, I always clone a new one into it and the application renders now:
Image

IMO I didn't expect to call anything manually on the `egui::Context` to be able to configure the surface in the first place, and even more touching the winit side to fix this. So it seems like a bug.

**To Reproduce**
Steps to reproduce the behavior:
1. In wgpu use `wgpu::TextureFormat::Rgba8Unorm` or `wgpu::TextureFormat::Bgra8Unorm` format for the surface initially
2. When application is running, try to switch to `wgpu::TextureFormat::Rgba16Float` and configure the surface, also recreate `egui_wgpu::Renderer`
3. Egui turns all black

**Expected behavior**
Application is not black

**Desktop (please complete the following information):**
- OS: Win11

**Smartphone (please complete the following information):**
- Device: Samsung Galaxy A52 5G
- OS: Android 14

**Additional context**
The behaviour is the same regardless of backend, both on pc and on a phone.
Dependencies:
```
egui = { version = "0.32", optional = true, default-features = false, features = [] }
egui-wgpu = { version = "0.32", optional = true, default-features = false}
egui-winit = { version = "0.32", optional = true, default-features = false, features = [] }
winit = { version = "0.30", default-features = false, features = ["rwh_06"] }
wgpu = { version = "25.0", default-features = false, features = ["wgsl", "serde", "dx12", "vulkan", "gles"] }
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the surface-format switch with egui::Context, egui_winit::State, and egui_wgpu::Renderer using the listed wgpu formats and dependency versions. Compare the rendering state before and after recreating the renderer; done means the application continues rendering after reconfiguration without manually calling forget_all_images or recreating egui_winit::State.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
computer-graphics, frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.