1
0
mirror of https://github.com/emilk/egui.git synced 2026-09-01 22:30:03 -04:00

Fix wgpu padding (#8448)

The Egui web example was throwing an error in WGPU. In this case, the
error was
```
panicked at /home/runner/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/wgpu-30.0.0/src/backend/wgpu_core.rs:1414:26: wgpu error: Validation Error Caused by: In Device::create_render_pipeline, label = ‘egui_pipeline’ In the provided shader, the type given for group 1 binding 2 has a size of 4. Since the device does not support DownlevelFlags::BUFFER_BINDINGS_NOT_16_BYTE_ALIGNED`, the type must have a size that is a multiple of 16 bytes
```

One reference I used was the following Pull Request:
<https://github.com/viridia/quill/pull/14>

The biggest change I made was in `egui-wgpu` to
`r_tex_nearest_filtering`

Shader (`egui.wgsl`)
```wgsl
// Old 
@group(1) @binding(2) var<uniform> r_tex_nearest_filtering: u32;

// New
@group(1) @binding(2) var<uniform> r_tex_nearest_filtering: vec4<u32>;
```

And with the corresponding changes in `renderer.rs`, I ran it locally
and it worked perfectly in Firefox 149 and Chromium 151 (Both fail when
attempting to access https://www.egui.rs/#demo, returning the error
described above)

* Closes <https://github.com/emilk/egui/issues/8446>
* Fixes <https://github.com/emilk/egui/issues/8446>
* [X] I have followed the instructions in the PR template

---------

Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Juanperias
2026-08-26 02:09:32 -04:00
committed by GitHub
parent 35b069585d
commit caea233a47
2 changed files with 9 additions and 5 deletions

View File

@@ -357,7 +357,9 @@ impl Renderer {
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Buffer {
has_dynamic_offset: false,
min_binding_size: NonZeroU64::new(core::mem::size_of::<u32>() as _),
min_binding_size: NonZeroU64::new(
(core::mem::size_of::<u32>() * 4) as _,
),
ty: wgpu::BufferBindingType::Uniform,
},
count: None,
@@ -370,7 +372,7 @@ impl Renderer {
let flag = flag as u32;
device.create_buffer_init(&wgpu::util::BufferInitDescriptor {
label: Some(&format!("egui_texture_flags_{flag}")),
contents: bytemuck::bytes_of(&flag),
contents: bytemuck::bytes_of(&[flag, 0, 0, 0]),
usage: wgpu::BufferUsages::UNIFORM,
})
});