From 4fa2fbb5aa998cd9e4a43b1601fc4ad7dace086e Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Thu, 21 Mar 2024 16:09:29 -0400 Subject: [PATCH] fix(dx12): 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 | 4 ++++ wgpu-hal/src/dx12/device.rs | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d9102c58b3..c443ecd89c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -162,6 +162,10 @@ Bottom level categories: - Set object labels when the DEBUG flag is set, even if the VALIDATION flag is disabled. By @DJMcNab in [#5345](https://github.com/gfx-rs/wgpu/pull/5345). +#### DX12 + +- 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). + ## v0.19.3 (2024-03-01) This release includes `wgpu`, `wgpu-core`, and `wgpu-hal`. All other crates are unchanged. diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 994126c265..23bd409dc4 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -1100,7 +1100,16 @@ impl crate::Device for super::Device { } let mut dynamic_buffers = Vec::new(); - for (layout, entry) in desc.layout.entries.iter().zip(desc.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"); + (layout, entry) + }); + for (layout, entry) in layout_and_entry_iter { match layout.ty { wgt::BindingType::Buffer { has_dynamic_offset: true,