Handle WGPUVertexStepMode_Undefined
stepMode defaults to "vertex". https://www.w3.org/TR/webgpu/#dom-gpuvertexbufferlayout-stepmode
@cwfitzgerald good to take that into account!
However, it's not clear to me how these different cases of "no attributes" should be mapped to the API in wgpu-core. And it looks like null is not allowed in the JS API?
@cwfitzgerald good to take that into account!
However, it's not clear to me how these different cases of "no attributes" should be mapped to the API in wgpu-core. And it looks like
nullis not allowed in the JS API?
null is allowed in GPUVertexState.buffers. However, Firefox doesn't appear to handle this quite correctly. null entries are supposed to be skipped during vertex processing and validating draw calls. But the following fails in Firefox (works in Chrome) due to no vertex buffer being bound in slot 1:
let pipeline = device.createRenderPipeline({
vertex: {
buffers: [
{
// Vertex buffer slot 0...
},
null
],
...
}
...
});
...
renderPassEncoder.setPipeline(pipeline);
renderPassEncoder.setVertexBuffer(0, vertexBuffer);
renderPassEncoder.draw();
Can be worked around by binding some dummy vertex buffer to slot 1.
The reason is wgpu-core doesn't handle null entries in VertexState.buffers. Firefox handles it by simply putting default values on null entries. However a null entry is not quite the same as an entry with attributes = []. An entry with attributes = [] still has to have a bound vertex buffer, based on the outcome of https://github.com/gpuweb/gpuweb/issues/4999 .
So I think the proper, long-term solution is to handle null entries in wgpu-core. Short term solution for wgpu-native is either
- Match Firefox behavior and map
WGPUVertexStepMode_Undefined, emptyattributesorWGPUVertexStepMode_VertexBufferNotUsedas default values{ array_stride: 0, step_mode: Vertex, attributes: []}. - Raise an error. Which we already do since we don't handle
WGPUVertexStepMode_UndefinedorWGPUVertexStepMode_VertexBufferNotUsed. But we could handleWGPUVertexStepMode_Undefinedfor the non-emptyattributescase. And i.m.o. current error message is not too helpful as it implies the wrong vertex step mode was used, when in fact the user did nothing wrong.
I've updated my commit to do 2 with an error message telling developers how they can work around the lack of support, but I can change it to 1 if we prefer.
Note: WGPUVertexStepMode_VertexBufferNotUsed will be removed next time we update webgpu-headers.