Skip to content

Commit

Permalink
Merge gfx-rs#1080
Browse files Browse the repository at this point in the history
1080: Fix the validation of vertex buffer sizes r=kvark a=JCapucho

**Connections**
None that i know of

**Description**
~~The vertex buffer size (in vertices) was being divided by stride causing the limit to be lower than it was supposed to be.~~
This bug wasn't triggered earlier because if the stride was 0 it wouldn't perform any calculation and the stride was only set when a set pipeline command was received and the `VertexState` `inputs` were already created so the following commands would work:
```
SetPipeline with 1 vertex buffer
SetVertexBuffer with only 4 vertices
Draw 6 vertices
```
This would have passed validation while this wouldn't
```
SetPipeline with 1 vertex buffer of stride 8
SetVertexBuffer with 4 vertices
SetPipeline with 1 vertex buffer of stride 8
SetVertexBuffer with 4 vertices
Draw 3 vertices
```

Now all draw calls have proper vertex validation and not only after the `inputs` are populated

**Testing**
This change was tested after debugging an issue with the draw calls failing in a specific order in [veloren](https://gitlab.com/veloren/veloren/-/tree/imbris/wgpu-master-rebased)

Co-authored-by: Capucho <[email protected]>
  • Loading branch information
bors[bot] and JCapucho committed Dec 7, 2020
2 parents 4846e41 + 713c23b commit 071ccf2
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,14 +1164,17 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {

state.index.pipeline_format = pipeline.index_format;

let vertex_strides_len = pipeline.vertex_strides.len();
while state.vertex.inputs.len() < vertex_strides_len {
state.vertex.inputs.push(VertexBufferState::EMPTY);
}
// Update vertex buffer limits
for (vbs, &(stride, rate)) in
state.vertex.inputs.iter_mut().zip(&pipeline.vertex_strides)
{
vbs.stride = stride;
vbs.rate = rate;
}
let vertex_strides_len = pipeline.vertex_strides.len();
for vbs in state.vertex.inputs.iter_mut().skip(vertex_strides_len) {
vbs.stride = 0;
vbs.rate = InputStepMode::Vertex;
Expand Down

0 comments on commit 071ccf2

Please sign in to comment.