Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v0.15] WebGl workaround for drawing single instance #3596

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
87 changes: 37 additions & 50 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down