I'm using a simple shader to render a rectangle onto the screen. The vertices are hardcoded into the vertex shader, and it uses the vertex index to find out what vertex to emit.
#version 450
// triangle strip
const vec2 fb_vert[4] = vec2[4](
vec2(1, 1), // top right
vec2(-1, 1), // top left
vec2(1, -1), // bottom right
vec2(-1, -1) // bottom left
);
void main() {
gl_Position = vec4(fb_vert[gl_VertexIndex], 0, 1);
}
Well, on updating from wgpu 0.6.2 to 0.7.0, it started throwing "index buffer must be set" errors, even though it didn't before.
Is this a bug? I don't know what an index buffer is or why I would need one for this use case. I'm not even using draw_indexed:
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: Some("<...> primary render pass descriptor"),
color_attachments: &[
wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.output.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(self.background),
store: true
}
}
],
depth_stencil_attachment: None
});
render_pass.set_pipeline(&self.pipeline);
render_pass.set_bind_group(0, &self.bind_group, &[]);
render_pass.draw(0..4, 0..1);
Seems that this is caused by strip_index_format being set to Some. That's kind of misleading, I thought it decided the format of gl_VertexIndex or something like that... I didn't know it had anything to do with the index buffer.
So the error is expected. If you don't know what the strip index format is, and you find the documentation confusing:
/// The format of index buffers for strip topologies. Should be left
Nonefor non-strip.
then you don't need to set it to anything other than None. Going to close this therefore, but please feel free to continue discussing and/or re-open!
...But I am using triangle strips. It says None for non-strip, but I'm using triangle strips, so I thought it should be Some.
Right, sorry, let's fix this!
Should be easy to fix. There is code we call before each draw call to see if the state is fine, we need to pass a boolean indicating if the index format should be checked.
I also think wgpu should either warn you, or reflect in the documentation that strip_index_format isn't really relevant if you're not actually using draw_indexed. To prevent further confusion... since now setting the field unnecessarily does _not_ cause a panic. :P
@LoganDark we can't warn you, since if you are drawing without indices now, doesn't mean you are doing something wrong. Maybe you will be using indices later.
As for the docs, I amended a change in #1201 that improves them.
I'm gonna go ahead and close this as solved. People having this problem on 0.7.0 can look up the GitHub issue, so everything is in order now. :P
Thanks for the fast resolution!
Please note that a merged PR will automatically close it (because the of "fixes #zzx" syntax used in the description).
Already noted. I still like to leave my thanks. :P