From c86f9773caf0596345aea1c8cc98278d710e75ef Mon Sep 17 00:00:00 2001 From: Alix Bott Date: Wed, 19 Apr 2023 23:14:45 +0200 Subject: [PATCH] Fix unsetting vertex attributes in gles backend (#3706) Co-authored-by: Connor Fitzgerald --- CHANGELOG.md | 1 + wgpu-hal/src/gles/command.rs | 8 ++++---- wgpu/tests/regression/issue_3457.rs | 5 ++++- wgpu/tests/regression/issue_3457.wgsl | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ff05881b0..0cc4bb118 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -185,6 +185,7 @@ By @cwfitzgerald in [#3671](https://github.com/gfx-rs/wgpu/pull/3671). - Reset the state of `SAMPLE_ALPHA_TO_COVERAGE` on queue reset. By @jleibs [#3589](https://github.com/gfx-rs/wgpu/pull/3589) - Fix `Vertex buffer is not big enough for the draw call.` for ANGLE/Web when rendering with instance attributes on a single instance. By @wumpf in [#3597](https://github.com/gfx-rs/wgpu/pull/3597) - Fix `copy_external_image_to_texture`, `copy_texture_to_texture` and `copy_buffer_to_texture` not taking the specified index into account if the target texture is a cube map, 2D texture array or cube map array. By @daxpedda [#3641](https://github.com/gfx-rs/wgpu/pull/3641) +- Fix disabling of vertex attributes with non-consecutive locations [#3706](https://github.com/gfx-rs/wgpu/pull/3706) #### Metal diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 23cf8a36b..5e3a1c52c 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -620,10 +620,10 @@ impl crate::CommandEncoder for super::CommandEncoder { self.state.dirty_vbuf_mask = 0; self.state.active_first_instance = 0; self.state.color_targets.clear(); - for index in 0..self.state.vertex_attributes.len() { + for vat in &self.state.vertex_attributes { self.cmd_buffer .commands - .push(C::UnsetVertexAttribute(index as u32)); + .push(C::UnsetVertexAttribute(vat.location)); } self.state.vertex_attributes.clear(); self.state.primitive = super::PrimitiveState::default(); @@ -761,10 +761,10 @@ impl crate::CommandEncoder for super::CommandEncoder { }); } } else { - for index in 0..self.state.vertex_attributes.len() { + for vat in &self.state.vertex_attributes { self.cmd_buffer .commands - .push(C::UnsetVertexAttribute(index as u32)); + .push(C::UnsetVertexAttribute(vat.location)); } self.state.vertex_attributes.clear(); diff --git a/wgpu/tests/regression/issue_3457.rs b/wgpu/tests/regression/issue_3457.rs index f4359fb93..2fb010103 100644 --- a/wgpu/tests/regression/issue_3457.rs +++ b/wgpu/tests/regression/issue_3457.rs @@ -12,6 +12,9 @@ use wgpu::*; /// submit, delete the second vertex buffer and `poll(Wait)`. Because we maintained the device, /// the actual underlying buffer for the second vertex buffer is deleted, causing a draw call /// that is invalid if the second attribute is still enabled. +/// +/// We use non-consecutive vertex attribute locations (0 and 5) in order to also test +/// that we unset the correct locations (see PR #3706). #[wasm_bindgen_test] #[test] fn pass_reset_vertex_buffer() { @@ -60,7 +63,7 @@ fn pass_reset_vertex_buffer() { VertexBufferLayout { array_stride: 4, step_mode: VertexStepMode::Vertex, - attributes: &vertex_attr_array![1 => Float32], + attributes: &vertex_attr_array![5 => Float32], }, ], }, diff --git a/wgpu/tests/regression/issue_3457.wgsl b/wgpu/tests/regression/issue_3457.wgsl index f02aaa1bb..52f3d3740 100644 --- a/wgpu/tests/regression/issue_3457.wgsl +++ b/wgpu/tests/regression/issue_3457.wgsl @@ -1,6 +1,6 @@ struct DoubleVertexIn { @location(0) position: vec4, - @location(1) value: f32, + @location(5) value: f32, } struct DoubleVertexOut {