From 74f514ca6b1a4f3b90a8ce94306aff08bbd4eb12 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 21 Mar 2024 16:09:29 -0400 Subject: [PATCH] fix(gles): don't depend on BG{,L} entry order This isn't guaranteed by `wgpu-core`; we should try to match by binding slot index instead. --- CHANGELOG.md | 1 + wgpu-hal/src/gles/device.rs | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c443ecd89c..ca0b07415a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -157,6 +157,7 @@ Bottom level categories: - Fixes for being able to use an OpenGL 4.1 core context provided by macOS with wgpu. By @bes in [#5331](https://github.com/gfx-rs/wgpu/pull/5331). - Don't create a program for shader-clearing if that workaround isn't required. By @Dinnerbone in [#5348](https://github.com/gfx-rs/wgpu/pull/5348). - Fix crash when holding multiple devices on wayland/surfaceless. By @ashdnazg in [#5351](https://github.com/gfx-rs/wgpu/pull/5351). +- Don't depend on bind group and bind group layout entry order in HAL. This caused incorrect severely incorrect command execution and, in some cases, crashes. By @ErichDonGubler in [#5421](https://github.com/gfx-rs/wgpu/pull/5421). #### Vulkan diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 8cc3129d65..50c07f3ff0 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -1125,8 +1125,10 @@ impl crate::Device for super::Device { !0; bg_layout .entries - .last() - .map_or(0, |b| b.binding as usize + 1) + .iter() + .map(|b| b.binding) + .max() + .map_or(0, |idx| idx as usize + 1) ] .into_boxed_slice(); @@ -1179,7 +1181,16 @@ impl crate::Device for super::Device { ) -> Result { let mut contents = Vec::new(); - for (entry, layout) in desc.entries.iter().zip(desc.layout.entries.iter()) { + let layout_and_entry_iter = desc.entries.iter().map(|entry| { + let layout = desc + .layout + .entries + .iter() + .find(|layout_entry| layout_entry.binding == entry.binding) + .expect("internal error: no layout entry found with binding slot"); + (entry, layout) + }); + for (entry, layout) in layout_and_entry_iter { let binding = match layout.ty { wgt::BindingType::Buffer { .. } => { let bb = &desc.buffers[entry.resource_index as usize];