From b6fe59c7851e5afdef8757341cf213ba3210c47d Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Thu, 16 Mar 2023 18:03:50 +0100 Subject: [PATCH 1/2] added changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a275dbaf0e..7d15194aef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,9 @@ Bottom level categories: --> ## Unreleased +### Bug Fixes +#### GLES +- 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 [#3596](https://github.com/gfx-rs/wgpu/pull/3596) ## wgpu-0.15.2 (2023-03-08) From 43b6cc7816f4fbbaa26dc0d58a54d3f62557458c Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sat, 18 Mar 2023 16:50:44 +0100 Subject: [PATCH 2/2] [GLES] Always use instanced methods to workaround for instance attributes when rendering a single instance --- wgpu-hal/src/gles/queue.rs | 87 ++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 50 deletions(-) diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index add1daeb74..fc444382a6 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -164,18 +164,17 @@ impl super::Queue { vertex_count, instance_count, } => { - if instance_count == 1 { - unsafe { gl.draw_arrays(topology, start_vertex as i32, vertex_count as i32) }; - } else { - unsafe { - gl.draw_arrays_instanced( - topology, - start_vertex as i32, - vertex_count as i32, - instance_count as i32, - ) - }; - } + // Don't use `gl.draw_arrays` for `instance_count == 1`. + // Angle has a bug where it doesn't consider the instance divisor when `DYNAMIC_DRAW` is used in `draw_arrays`. + // See https://github.com/gfx-rs/wgpu/issues/3578 + unsafe { + gl.draw_arrays_instanced( + topology, + start_vertex as i32, + vertex_count as i32, + instance_count as i32, + ) + }; } C::DrawIndexed { topology, @@ -184,44 +183,32 @@ impl super::Queue { index_offset, base_vertex, instance_count, - } => match (base_vertex, instance_count) { - (0, 1) => unsafe { - gl.draw_elements( - topology, - index_count as i32, - index_type, - index_offset as i32, - ) - }, - (0, _) => unsafe { - gl.draw_elements_instanced( - topology, - index_count as i32, - index_type, - index_offset as i32, - instance_count as i32, - ) - }, - (_, 1) => unsafe { - gl.draw_elements_base_vertex( - topology, - index_count as i32, - index_type, - index_offset as i32, - base_vertex, - ) - }, - (_, _) => unsafe { - gl.draw_elements_instanced_base_vertex( - topology, - index_count as _, - index_type, - index_offset as i32, - instance_count as i32, - base_vertex, - ) - }, - }, + } => { + match base_vertex { + // Don't use `gl.draw_elements`/`gl.draw_elements_base_vertex` for `instance_count == 1`. + // Angle has a bug where it doesn't consider the instance divisor when `DYNAMIC_DRAW` is used in `gl.draw_elements`/`gl.draw_elements_base_vertex`. + // See https://github.com/gfx-rs/wgpu/issues/3578 + 0 => unsafe { + gl.draw_elements_instanced( + topology, + index_count as i32, + index_type, + index_offset as i32, + instance_count as i32, + ) + }, + _ => unsafe { + gl.draw_elements_instanced_base_vertex( + topology, + index_count as _, + index_type, + index_offset as i32, + instance_count as i32, + base_vertex, + ) + }, + } + } C::DrawIndirect { topology, indirect_buf,